mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-19 02:59:31 +08:00
- 新增 JMX/Endpoint/Agent 三种 JVM 连接模式与配置归一化链路 - 支持资源浏览、变更预览、写入应用、审计记录与只读约束 - 接入 AI 结构化写入计划与诊断计划回填能力 - 新增 Agent Bridge、Arthas Tunnel、JMX Helper 诊断传输实现 - 增加诊断控制台、命令模板、输出历史与自动补全交互 - 补齐前后端契约、运行夹具与 JVM 相关回归测试
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package jvm
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"GoNavi-Wails/internal/connection"
|
|
)
|
|
|
|
type Provider interface {
|
|
Mode() string
|
|
TestConnection(ctx context.Context, cfg connection.ConnectionConfig) error
|
|
ProbeCapabilities(ctx context.Context, cfg connection.ConnectionConfig) ([]Capability, error)
|
|
ListResources(ctx context.Context, cfg connection.ConnectionConfig, parentPath string) ([]ResourceSummary, error)
|
|
GetValue(ctx context.Context, cfg connection.ConnectionConfig, resourcePath string) (ValueSnapshot, error)
|
|
PreviewChange(ctx context.Context, cfg connection.ConnectionConfig, req ChangeRequest) (ChangePreview, error)
|
|
ApplyChange(ctx context.Context, cfg connection.ConnectionConfig, req ChangeRequest) (ApplyResult, error)
|
|
}
|
|
|
|
var providerFactories = map[string]func() Provider{
|
|
ModeJMX: func() Provider { return NewJMXProvider() },
|
|
ModeEndpoint: func() Provider { return NewHTTPProvider() },
|
|
ModeAgent: func() Provider { return NewAgentProvider() },
|
|
}
|
|
|
|
func NewProvider(mode string) (Provider, error) {
|
|
normalized := strings.ToLower(strings.TrimSpace(mode))
|
|
factory, ok := providerFactories[normalized]
|
|
if !ok {
|
|
return nil, fmt.Errorf("unsupported jvm provider mode: %s", mode)
|
|
}
|
|
return factory(), nil
|
|
}
|
|
|
|
func ModeDisplayLabel(mode string) string {
|
|
switch strings.ToLower(strings.TrimSpace(mode)) {
|
|
case ModeJMX:
|
|
return "JMX"
|
|
case ModeEndpoint:
|
|
return "Endpoint"
|
|
case ModeAgent:
|
|
return "Agent"
|
|
default:
|
|
normalized := strings.TrimSpace(mode)
|
|
if normalized == "" {
|
|
return "Unknown"
|
|
}
|
|
if len(normalized) == 1 {
|
|
return strings.ToUpper(normalized)
|
|
}
|
|
return strings.ToUpper(normalized[:1]) + strings.ToLower(normalized[1:])
|
|
}
|
|
}
|
|
|
|
func errProviderNotImplemented(mode string, action string) error {
|
|
return fmt.Errorf("%s provider does not implement %s yet", ModeDisplayLabel(mode), action)
|
|
}
|