discovery

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package discovery provides cluster discovery functionality. Package discovery 提供集群发现功能。

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAgentOffline      = errors.New("agent is offline / Agent 离线")
	ErrAgentNotInstalled = errors.New("agent not installed / Agent 未安装")
	ErrDiscoveryFailed   = errors.New("cluster discovery failed / 集群发现失败")
	ErrClusterConflict   = errors.New("cluster already exists / 集群已存在")
	ErrHostNotFound      = errors.New("host not found / 主机未找到")
)

Error definitions for discovery package. 发现包的错误定义。

Functions

This section is empty.

Types

type AgentDiscoverer

type AgentDiscoverer interface {
	TriggerDiscovery(ctx context.Context, agentID string) ([]*DiscoveredCluster, error)
	DiscoverProcesses(ctx context.Context, agentID string) ([]*DiscoveredProcess, error)
}

AgentDiscoverer defines the interface for triggering agent discovery. AgentDiscoverer 定义触发 Agent 发现的接口。

type ClusterMatcher

type ClusterMatcher interface {
	FindClusterByInstallDir(ctx context.Context, hostID uint, installDir string) (clusterID uint, nodeID uint, found bool, err error)
	CreateClusterFromDiscovery(ctx context.Context, hostID uint, cluster *DiscoveredCluster) (uint, error)
	UpdateNodeFromDiscovery(ctx context.Context, nodeID uint, node *DiscoveredNode) error
}

ClusterMatcher defines the interface for matching discovered clusters. ClusterMatcher 定义匹配发现集群的接口。

type ConfirmDiscoveryRequest

type ConfirmDiscoveryRequest struct {
	HostID      uint     `json:"host_id" binding:"required"`
	ClusterIDs  []string `json:"cluster_ids"`  // 要纳管的集群标识 / Cluster identifiers to manage
	InstallDirs []string `json:"install_dirs"` // 要纳管的安装目录 / Install directories to manage
	// JavaHomes 按安装目录指定节点 JDK;空值表示自动探测(AC1e)。
	// JavaHomes maps install directories to node JDKs; empty means auto detection (AC1e).
	JavaHomes map[string]string `json:"java_homes,omitempty"`
}

ConfirmDiscoveryRequest represents a request to confirm discovered clusters. ConfirmDiscoveryRequest 表示确认发现集群的请求。

type DiscoveredCluster

type DiscoveredCluster struct {
	Name           string                 `json:"name"`
	InstallDir     string                 `json:"install_dir"`
	Version        string                 `json:"version"`
	DeploymentMode string                 `json:"deployment_mode"`
	Nodes          []*DiscoveredNode      `json:"nodes"`
	Config         map[string]interface{} `json:"config"`
	DiscoveredAt   time.Time              `json:"discovered_at"`
	IsNew          bool                   `json:"is_new"`      // 是否为新发现的集群 / Whether it's a newly discovered cluster
	ExistingID     uint                   `json:"existing_id"` // 如果已存在,关联的集群 ID / If exists, the associated cluster ID
	// JavaHome 是纳管时用户选定的节点 JDK;空表示自动探测(AC1e)。实现 CreateClusterFromDiscovery 时应写入节点。
	// JavaHome is the node JDK chosen at import; empty means auto detection (AC1e). CreateClusterFromDiscovery should persist it.
	JavaHome string `json:"java_home,omitempty"`
}

DiscoveredCluster represents a discovered SeaTunnel cluster. DiscoveredCluster 表示发现的 SeaTunnel 集群。

func BuildClustersFromProcesses added in v1.3.0

func BuildClustersFromProcesses(processes []*DiscoveredProcess) []*DiscoveredCluster

BuildClustersFromProcesses 按安装目录把进程发现结果聚合成集群列表(主机「发现集群」用)。 BuildClustersFromProcesses groups process discovery results into clusters by install directory (used by host 「发现集群」).

type DiscoveredNode

type DiscoveredNode struct {
	PID           int       `json:"pid"`
	Role          string    `json:"role"`
	HazelcastPort int       `json:"hazelcast_port"`
	APIPort       int       `json:"api_port"`
	StartTime     time.Time `json:"start_time"`
	// JavaHome 是进程实际 JDK(AC1f)/ Process actual JDK (AC1f)
	JavaHome string `json:"java_home,omitempty"`
}

DiscoveredNode represents a discovered SeaTunnel node. DiscoveredNode 表示发现的 SeaTunnel 节点。

type DiscoveredProcess

type DiscoveredProcess struct {
	PID           int    `json:"pid"`
	Role          string `json:"role"`                   // master, worker, or hybrid
	InstallDir    string `json:"install_dir"`            // SeaTunnel installation directory / SeaTunnel 安装目录
	Version       string `json:"version"`                // SeaTunnel version / SeaTunnel 版本
	HazelcastPort int    `json:"hazelcast_port"`         // Hazelcast cluster port / Hazelcast 集群端口
	APIPort       int    `json:"api_port"`               // REST API port / REST API 端口
	ClusterName   string `json:"cluster_name,omitempty"` // Hazelcast cluster-name / Hazelcast 集群标识
	// JavaHome 是进程实际使用的 JDK(由 Agent 从 /proc/<pid>/exe 解析);解析不到为空(AC1f)。
	// JavaHome is the JDK the process actually uses (resolved by the Agent from /proc/<pid>/exe); empty when unresolved (AC1f).
	JavaHome string `json:"java_home,omitempty"`
}

DiscoveredProcess represents a discovered SeaTunnel process (simplified). DiscoveredProcess 表示发现的 SeaTunnel 进程(简化版)。

type DiscoveryResult

type DiscoveryResult struct {
	Success    bool                 `json:"success"`
	Message    string               `json:"message"`
	Clusters   []*DiscoveredCluster `json:"clusters"`
	NewCount   int                  `json:"new_count"`
	ExistCount int                  `json:"exist_count"`
}

DiscoveryResult represents the result of a discovery operation. DiscoveryResult 表示发现操作的结果。

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler handles HTTP requests for cluster discovery. Handler 处理集群发现的 HTTP 请求。

func NewHandler

func NewHandler(service *Service) *Handler

NewHandler creates a new discovery handler. NewHandler 创建新的发现处理器。

func (*Handler) ConfirmDiscovery

func (h *Handler) ConfirmDiscovery(c *gin.Context)

ConfirmDiscovery handles POST /api/v1/hosts/:id/discover/confirm ConfirmDiscovery 处理 POST /api/v1/hosts/:id/discover/confirm @Summary Confirm and import discovered clusters @Description Confirm discovered clusters and import them into the system @Tags Discovery @Accept json @Produce json @Param id path int true "Host ID" @Param request body ConfirmDiscoveryRequest true "Confirm request" @Success 200 {object} map[string]interface{} @Failure 400 {object} map[string]string @Failure 500 {object} map[string]string @Router /api/v1/hosts/{id}/discover/confirm [post]

func (*Handler) DiscoverProcesses

func (h *Handler) DiscoverProcesses(c *gin.Context)

DiscoverProcesses handles POST /api/v1/hosts/:id/discover-processes DiscoverProcesses 处理 POST /api/v1/hosts/:id/discover-processes @Summary Discover SeaTunnel processes on a host (simplified) @Description Scan for running SeaTunnel processes, returns PID, role, install_dir only @Tags Discovery @Accept json @Produce json @Param id path int true "Host ID" @Success 200 {object} ProcessDiscoveryResult @Failure 400 {object} map[string]string @Failure 404 {object} map[string]string @Failure 500 {object} map[string]string @Router /api/v1/hosts/{id}/discover-processes [post]

func (*Handler) TriggerDiscovery

func (h *Handler) TriggerDiscovery(c *gin.Context)

TriggerDiscovery handles POST /api/v1/hosts/:id/discover TriggerDiscovery 处理 POST /api/v1/hosts/:id/discover @Summary Trigger cluster discovery on a host @Description Trigger SeaTunnel cluster discovery on a specific host via Agent @Tags Discovery @Accept json @Produce json @Param id path int true "Host ID" @Success 200 {object} DiscoveryResult @Failure 400 {object} map[string]string @Failure 404 {object} map[string]string @Failure 500 {object} map[string]string @Router /api/v1/hosts/{id}/discover [post]

type HostInfo

type HostInfo struct {
	ID          uint
	Name        string
	IPAddress   string
	AgentID     string
	AgentStatus string
}

HostInfo represents host information for discovery. HostInfo 表示用于发现的主机信息。

type HostProvider

type HostProvider interface {
	GetHostByID(ctx context.Context, hostID uint) (*HostInfo, error)
	GetHostByAgentID(ctx context.Context, agentID string) (*HostInfo, error)
}

HostProvider defines the interface for getting host information. HostProvider 定义获取主机信息的接口。

type ProcessDiscoveryResult

type ProcessDiscoveryResult struct {
	Success   bool                 `json:"success"`
	Message   string               `json:"message"`
	Processes []*DiscoveredProcess `json:"processes"`
}

ProcessDiscoveryResult represents the result of process discovery. ProcessDiscoveryResult 表示进程发现的结果。

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides cluster discovery functionality. Service 提供集群发现功能。

func NewService

func NewService() *Service

NewService creates a new discovery service. NewService 创建新的发现服务。

func (*Service) ConfirmDiscovery

func (s *Service) ConfirmDiscovery(ctx context.Context, req *ConfirmDiscoveryRequest) ([]uint, error)

ConfirmDiscovery confirms and imports discovered clusters. ConfirmDiscovery 确认并导入发现的集群。 Requirements: 1.9, 9.4 - Confirm cluster import

func (*Service) DiscoverProcesses

func (s *Service) DiscoverProcesses(ctx context.Context, hostID uint) (*ProcessDiscoveryResult, error)

DiscoverProcesses discovers SeaTunnel processes on a host (simplified). DiscoverProcesses 在主机上发现 SeaTunnel 进程(简化版)。 Only returns PID, role, and install_dir - no config parsing. 只返回 PID、角色和安装目录 - 不解析配置。

func (*Service) ProcessDiscoveryResult

func (s *Service) ProcessDiscoveryResult(ctx context.Context, hostID uint, clusters []*DiscoveredCluster) error

ProcessDiscoveryResult processes discovery results from agent. ProcessDiscoveryResult 处理来自 Agent 的发现结果。 Requirements: 2.5 - Process matching and status update **Feature: seatunnel-process-monitor, Property 15: 进程匹配更新状态** **Validates: Requirements 2.5**

func (*Service) SetAgentDiscoverer

func (s *Service) SetAgentDiscoverer(discoverer AgentDiscoverer)

SetAgentDiscoverer sets the agent discoverer. SetAgentDiscoverer 设置 Agent 发现器。

func (*Service) SetClusterMatcher

func (s *Service) SetClusterMatcher(matcher ClusterMatcher)

SetClusterMatcher sets the cluster matcher. SetClusterMatcher 设置集群匹配器。

func (*Service) SetHostProvider

func (s *Service) SetHostProvider(provider HostProvider)

SetHostProvider sets the host provider. SetHostProvider 设置主机提供者。

func (*Service) TriggerDiscovery

func (s *Service) TriggerDiscovery(ctx context.Context, hostID uint) (*DiscoveryResult, error)

TriggerDiscovery triggers cluster discovery on a host. TriggerDiscovery 在主机上触发集群发现。 Requirements: 1.3, 1.7 - Trigger agent discovery

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL