Files
MyGoNavi/internal/jvm/diagnostic_transport.go
Syngnat 6f14e827ab feat(jvm): 完成资源治理与诊断增强
- 新增 JMX/Endpoint/Agent 三种 JVM 连接模式与配置归一化链路
- 支持资源浏览、变更预览、写入应用、审计记录与只读约束
- 接入 AI 结构化写入计划与诊断计划回填能力
- 新增 Agent Bridge、Arthas Tunnel、JMX Helper 诊断传输实现
- 增加诊断控制台、命令模板、输出历史与自动补全交互
- 补齐前后端契约、运行夹具与 JVM 相关回归测试
2026-04-24 16:45:34 +08:00

72 lines
2.9 KiB
Go

package jvm
import (
"context"
"fmt"
"strings"
"GoNavi-Wails/internal/connection"
)
type DiagnosticTransport interface {
Mode() string
TestConnection(ctx context.Context, cfg connection.ConnectionConfig) error
ProbeCapabilities(ctx context.Context, cfg connection.ConnectionConfig) ([]DiagnosticCapability, error)
StartSession(ctx context.Context, cfg connection.ConnectionConfig, req DiagnosticSessionRequest) (DiagnosticSessionHandle, error)
ExecuteCommand(ctx context.Context, cfg connection.ConnectionConfig, req DiagnosticCommandRequest) error
CancelCommand(ctx context.Context, cfg connection.ConnectionConfig, sessionID string, commandID string) error
CloseSession(ctx context.Context, cfg connection.ConnectionConfig, sessionID string) error
}
type diagnosticTransportNotImplemented struct {
mode string
}
func (t diagnosticTransportNotImplemented) Mode() string { return t.mode }
func (t diagnosticTransportNotImplemented) TestConnection(context.Context, connection.ConnectionConfig) error {
return errDiagnosticTransportNotImplemented(t.mode, "test connection")
}
func (t diagnosticTransportNotImplemented) ProbeCapabilities(context.Context, connection.ConnectionConfig) ([]DiagnosticCapability, error) {
return nil, errDiagnosticTransportNotImplemented(t.mode, "probe capabilities")
}
func (t diagnosticTransportNotImplemented) StartSession(context.Context, connection.ConnectionConfig, DiagnosticSessionRequest) (DiagnosticSessionHandle, error) {
return DiagnosticSessionHandle{}, errDiagnosticTransportNotImplemented(t.mode, "start session")
}
func (t diagnosticTransportNotImplemented) ExecuteCommand(context.Context, connection.ConnectionConfig, DiagnosticCommandRequest) error {
return errDiagnosticTransportNotImplemented(t.mode, "execute command")
}
func (t diagnosticTransportNotImplemented) CancelCommand(context.Context, connection.ConnectionConfig, string, string) error {
return errDiagnosticTransportNotImplemented(t.mode, "cancel command")
}
func (t diagnosticTransportNotImplemented) CloseSession(context.Context, connection.ConnectionConfig, string) error {
return errDiagnosticTransportNotImplemented(t.mode, "close session")
}
var diagnosticTransportFactories = map[string]func() DiagnosticTransport{
DiagnosticTransportAgentBridge: func() DiagnosticTransport {
return NewDiagnosticAgentBridgeTransport()
},
DiagnosticTransportArthasTunnel: func() DiagnosticTransport {
return NewDiagnosticArthasTunnelTransport()
},
}
func NewDiagnosticTransport(mode string) (DiagnosticTransport, error) {
normalizedMode := strings.ToLower(strings.TrimSpace(mode))
factory, ok := diagnosticTransportFactories[normalizedMode]
if !ok {
return nil, fmt.Errorf("unsupported diagnostic transport: %s", mode)
}
return factory(), nil
}
func errDiagnosticTransportNotImplemented(mode string, action string) error {
return fmt.Errorf("%s diagnostic transport does not implement %s yet", strings.TrimSpace(mode), action)
}