mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-13 00:13:33 +08:00
- 补齐 DataGrid、DataViewer、DefinitionViewer、JVM 等模块多语言文案与回归测试 - 收口 JVM 前后端展示、诊断、监控和资源呈现相关多语言路径 - 更新六语言共享词典并保留 raw 边界
95 lines
3.1 KiB
Go
95 lines
3.1 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"GoNavi-Wails/internal/connection"
|
|
"GoNavi-Wails/internal/jvm"
|
|
)
|
|
|
|
type jvmMonitoringService interface {
|
|
Start(ctx context.Context, cfg connection.ConnectionConfig, requestedMode string) (jvm.MonitoringSessionSnapshot, error)
|
|
GetHistory(connectionID string, providerMode string) (jvm.MonitoringSessionSnapshot, error)
|
|
Stop(connectionID string, providerMode string) error
|
|
}
|
|
|
|
var currentJVMMonitoringManager jvmMonitoringService = jvm.NewMonitoringManager()
|
|
|
|
func (a *App) JVMStartMonitoring(cfg connection.ConnectionConfig) connection.QueryResult {
|
|
snapshot, err := currentJVMMonitoringManager.Start(a.ctx, cfg, "")
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: a.localizeJVMError(err)}
|
|
}
|
|
return connection.QueryResult{Success: true, Data: a.localizeJVMMonitoringSnapshot(snapshot)}
|
|
}
|
|
|
|
func (a *App) JVMGetMonitoringHistory(cfg connection.ConnectionConfig, providerMode string) connection.QueryResult {
|
|
connectionID, resolvedMode, err := resolveJVMMonitoringLookup(cfg, providerMode)
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: a.localizeJVMError(err)}
|
|
}
|
|
|
|
snapshot, err := currentJVMMonitoringManager.GetHistory(connectionID, resolvedMode)
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: a.localizeJVMError(err)}
|
|
}
|
|
return connection.QueryResult{Success: true, Data: a.localizeJVMMonitoringSnapshot(snapshot)}
|
|
}
|
|
|
|
func (a *App) JVMStopMonitoring(cfg connection.ConnectionConfig, providerMode string) connection.QueryResult {
|
|
connectionID, resolvedMode, err := resolveJVMMonitoringLookup(cfg, providerMode)
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: a.localizeJVMError(err)}
|
|
}
|
|
|
|
if err := currentJVMMonitoringManager.Stop(connectionID, resolvedMode); err != nil {
|
|
return connection.QueryResult{Success: false, Message: a.localizeJVMError(err)}
|
|
}
|
|
return connection.QueryResult{Success: true, Data: map[string]any{
|
|
"connectionId": connectionID,
|
|
"providerMode": resolvedMode,
|
|
"status": "stopped",
|
|
}}
|
|
}
|
|
|
|
func (a *App) localizeJVMMonitoringSnapshot(snapshot jvm.MonitoringSessionSnapshot) jvm.MonitoringSessionSnapshot {
|
|
if len(snapshot.ProviderWarnings) == 0 {
|
|
return snapshot
|
|
}
|
|
|
|
warnings := append([]string(nil), snapshot.ProviderWarnings...)
|
|
for index, warning := range warnings {
|
|
key, params, ok := jvm.ParseMonitoringProviderWarning(warning)
|
|
if !ok {
|
|
continue
|
|
}
|
|
warnings[index] = a.appText(key, params)
|
|
}
|
|
snapshot.ProviderWarnings = warnings
|
|
return snapshot
|
|
}
|
|
|
|
func resolveJVMMonitoringLookup(cfg connection.ConnectionConfig, requestedMode string) (string, string, error) {
|
|
normalized, resolvedMode, err := jvm.ResolveProviderMode(cfg, requestedMode)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
return resolveJVMMonitoringConnectionID(normalized), resolvedMode, nil
|
|
}
|
|
|
|
func resolveJVMMonitoringConnectionID(cfg connection.ConnectionConfig) string {
|
|
if trimmed := strings.TrimSpace(cfg.ID); trimmed != "" {
|
|
return trimmed
|
|
}
|
|
host := strings.TrimSpace(cfg.Host)
|
|
if host == "" {
|
|
host = "unknown"
|
|
}
|
|
if cfg.Port > 0 {
|
|
return fmt.Sprintf("%s:%d", host, cfg.Port)
|
|
}
|
|
return host
|
|
}
|