Documentation
¶
Overview ¶
Package config provides cluster configuration file management. config 包提供集群配置文件管理功能。
Index ¶
- Variables
- func GetConfigFilePath(configType ConfigType) string
- func IsMemberListConfigType(configType ConfigType) bool
- func PatchMemberListContent(content string, members []string) (string, bool, error)
- func ReadMemberList(content string) ([]string, error)
- func RegisterRoutes(router *gin.RouterGroup, handler *Handler)
- func SyncResultMessage(result *SyncAllResult) string
- type AgentClient
- type Config
- type ConfigChangeItem
- type ConfigChangeResult
- type ConfigChangeStatus
- type ConfigFilter
- type ConfigInfo
- type ConfigSyncStatus
- type ConfigType
- type ConfigVersion
- type ConfigVersionInfo
- type CreateConfigRequest
- type Handler
- func (h *Handler) GetClusterConfigs(c *gin.Context)
- func (h *Handler) GetConfig(c *gin.Context)
- func (h *Handler) GetConfigVersions(c *gin.Context)
- func (h *Handler) InitClusterConfigs(c *gin.Context)
- func (h *Handler) NormalizeConfig(c *gin.Context)
- func (h *Handler) PromoteConfig(c *gin.Context)
- func (h *Handler) PushConfigToNode(c *gin.Context)
- func (h *Handler) RollbackConfig(c *gin.Context)
- func (h *Handler) SetExecutionService(service *executionapp.Service)
- func (h *Handler) SyncFromTemplate(c *gin.Context)
- func (h *Handler) SyncTemplateToAllNodes(c *gin.Context)
- func (h *Handler) UpdateConfig(c *gin.Context)
- type HostInfo
- type HostProvider
- type InitClusterConfigsRequest
- type MemberListPatchResult
- type NodeInfoProvider
- type NodeSyncResult
- type NormalizeConfigRequest
- type PortMetadataUpdater
- type PromoteConfigRequest
- type PushConfigRequest
- type PushError
- type Repository
- func (r *Repository) Create(ctx context.Context, config *Config) error
- func (r *Repository) CreateVersion(ctx context.Context, version *ConfigVersion) error
- func (r *Repository) Delete(ctx context.Context, id uint) error
- func (r *Repository) DeleteByCluster(ctx context.Context, clusterID uint) error
- func (r *Repository) DeleteVersionsByConfig(ctx context.Context, configID uint) error
- func (r *Repository) GetByID(ctx context.Context, id uint) (*Config, error)
- func (r *Repository) GetNodeConfig(ctx context.Context, clusterID uint, hostID uint, configType ConfigType) (*Config, error)
- func (r *Repository) GetTemplate(ctx context.Context, clusterID uint, configType ConfigType) (*Config, error)
- func (r *Repository) GetVersion(ctx context.Context, configID uint, version int) (*ConfigVersion, error)
- func (r *Repository) GetVersionByID(ctx context.Context, id uint) (*ConfigVersion, error)
- func (r *Repository) List(ctx context.Context, filter *ConfigFilter) ([]*Config, error)
- func (r *Repository) ListByCluster(ctx context.Context, clusterID uint) ([]*Config, error)
- func (r *Repository) ListNodeConfigs(ctx context.Context, clusterID uint, configType ConfigType) ([]*Config, error)
- func (r *Repository) ListPendingPushByHost(ctx context.Context, hostID uint) ([]*Config, error)
- func (r *Repository) ListUpdatedByClusterBetween(ctx context.Context, clusterID uint, start, end time.Time) ([]*Config, error)
- func (r *Repository) ListVersions(ctx context.Context, configID uint) ([]*ConfigVersion, error)
- func (r *Repository) Transaction(ctx context.Context, fn func(tx *Repository) error) error
- func (r *Repository) Update(ctx context.Context, config *Config) error
- type Response
- type RollbackConfigRequest
- type Service
- func (s *Service) ApplyTemplatesToHost(ctx context.Context, clusterID uint, hostID uint, deploymentMode string, ...) (*ConfigChangeResult, error)
- func (s *Service) Create(ctx context.Context, req *CreateConfigRequest, userID uint) (*ConfigInfo, error)
- func (s *Service) DeleteConfigsByHost(ctx context.Context, hostID uint) (int, error)
- func (s *Service) DeleteHostConfigs(ctx context.Context, clusterID uint, hostID uint) (int, error)
- func (s *Service) EnsureClusterConfigsForHost(ctx context.Context, clusterID uint, hostID uint, installDir string, ...) error
- func (s *Service) Get(ctx context.Context, id uint) (*ConfigInfo, error)
- func (s *Service) GetByCluster(ctx context.Context, clusterID uint) ([]*ConfigInfo, error)
- func (s *Service) GetVersions(ctx context.Context, configID uint) ([]*ConfigVersionInfo, error)
- func (s *Service) InitClusterConfigs(ctx context.Context, clusterID uint, hostID uint, installDir string, ...) error
- func (s *Service) NormalizeContent(_ context.Context, req *NormalizeConfigRequest) (string, error)
- func (s *Service) PatchMemberList(ctx context.Context, clusterID uint, deploymentMode string, members []string, ...) (*MemberListPatchResult, error)
- func (s *Service) Promote(ctx context.Context, id uint, req *PromoteConfigRequest, userID uint) (*SyncAllResult, error)
- func (s *Service) PushConfigToNode(ctx context.Context, id uint, installDir string) error
- func (s *Service) RegisterHostConfigsFromNode(ctx context.Context, clusterID uint, hostID uint, installDir string, ...) (*ConfigChangeResult, error)
- func (s *Service) RetryPendingPushes(ctx context.Context, hostID uint) (int, error)
- func (s *Service) Rollback(ctx context.Context, id uint, req *RollbackConfigRequest, userID uint) (*ConfigInfo, error)
- func (s *Service) SetPortMetadataUpdater(updater PortMetadataUpdater)
- func (s *Service) SyncFromTemplate(ctx context.Context, id uint, req *SyncConfigRequest, userID uint) (*ConfigInfo, error)
- func (s *Service) SyncTemplateToAllNodes(ctx context.Context, clusterID uint, configType ConfigType, userID uint) (*SyncAllResult, error)
- func (s *Service) Update(ctx context.Context, id uint, req *UpdateConfigRequest, userID uint) (*ConfigInfo, error)
- type SyncAllResult
- type SyncConfigRequest
- type SyncTemplateToAllNodesRequest
- type UpdateConfigRequest
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMemberListNotFound 配置中没有 hazelcast.network.join.tcp-ip.member-list。 // ErrMemberListNotFound means the config has no hazelcast.network.join.tcp-ip.member-list. ErrMemberListNotFound = errors.New("hazelcast.network.join.tcp-ip.member-list not found / 未找到 hazelcast.network.join.tcp-ip.member-list") // ErrEmptyMemberList 拒绝写入空成员列表。 // ErrEmptyMemberList refuses to write an empty member list. ErrEmptyMemberList = errors.New("member list must not be empty / 成员列表不能为空") )
var ( ErrConfigNotFound = errors.New("config not found") ErrVersionNotFound = errors.New("config version not found") )
var ( ErrTemplateNotFound = errors.New("configuration template not found") ErrCannotPromoteTemplate = errors.New("cannot promote template config") ErrCannotSyncTemplate = errors.New("cannot sync template config from itself") )
ErrNodeConfigAccessUnavailable 未配置 Agent 客户端或节点信息提供者,无法读写节点文件。 ErrNodeConfigAccessUnavailable means no Agent client or node info provider is configured, so node files cannot be read or written.
var HybridConfigTypes = []ConfigType{ ConfigTypeSeatunnel, ConfigTypeHazelcast, ConfigTypeHazelcastClient, ConfigTypeJVMOptions, ConfigTypeLog4j2, ConfigTypeSeatunnelEnv, }
HybridConfigTypes Hybrid 模式支持的配置文件类型
var SeparatedConfigTypes = []ConfigType{ ConfigTypeSeatunnel, ConfigTypeHazelcastMaster, ConfigTypeHazelcastWorker, ConfigTypeHazelcastClient, ConfigTypeJVMMasterOptions, ConfigTypeJVMWorkerOptions, ConfigTypeLog4j2, ConfigTypeSeatunnelEnv, }
SeparatedConfigTypes Separated 模式支持的配置文件类型
var SupportedConfigTypes = []ConfigType{ ConfigTypeSeatunnel, ConfigTypeHazelcast, ConfigTypeHazelcastClient, ConfigTypeJVMOptions, ConfigTypeLog4j2, ConfigTypeSeatunnelEnv, ConfigTypeHazelcastMaster, ConfigTypeHazelcastWorker, ConfigTypeJVMMasterOptions, ConfigTypeJVMWorkerOptions, }
SupportedConfigTypes 支持的配置文件类型列表(所有类型)
Functions ¶
func GetConfigFilePath ¶
func GetConfigFilePath(configType ConfigType) string
GetConfigFilePath 获取配置文件相对于 SEATUNNEL_HOME 的路径
func IsMemberListConfigType ¶ added in v1.2.0
func IsMemberListConfigType(configType ConfigType) bool
IsMemberListConfigType 判断配置类型是否包含 Hazelcast member-list。 IsMemberListConfigType reports whether a config type carries a Hazelcast member-list.
func PatchMemberListContent ¶ added in v1.2.0
PatchMemberListContent 只替换 hazelcast.network.join.tcp-ip.member-list,其余内容(注释、空行、缩进、顺序)保持原样。 成员已一致时原样返回且 changed=false。优先按行精确替换;无法安全替换时退回到 YAML 节点重写, 两种方式都会重新解析校验:除 member-list 外的语义必须与原文完全一致。 PatchMemberListContent replaces only hazelcast.network.join.tcp-ip.member-list and keeps everything else (comments, blank lines, indentation, order) unchanged. When members already match it returns the input with changed=false. It prefers an exact line splice and falls back to a YAML node rewrite when the splice is not safe; both are re-parsed and verified so that everything except member-list stays semantically equal.
func ReadMemberList ¶ added in v1.2.0
ReadMemberList 读取配置中的 member-list;值为空时返回空切片。 ReadMemberList reads the member-list from a config; an empty value yields an empty slice.
func RegisterRoutes ¶
func RegisterRoutes(router *gin.RouterGroup, handler *Handler)
RegisterRoutes 注册配置管理路由
func SyncResultMessage ¶ added in v1.2.0
func SyncResultMessage(result *SyncAllResult) string
SyncResultMessage 生成与逐节点结果一致的汇总说明。 SyncResultMessage builds a summary message consistent with the per-node results.
Types ¶
type AgentClient ¶
type AgentClient interface {
PullConfig(ctx context.Context, hostID uint, installDir string, configType ConfigType) (string, error)
PushConfig(ctx context.Context, hostID uint, installDir string, configType ConfigType, content string) error
}
AgentClient Agent 客户端接口
type Config ¶
type Config struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
ClusterID uint `json:"cluster_id" gorm:"index;not null"`
HostID *uint `json:"host_id" gorm:"index"` // NULL = 集群模板
ConfigType ConfigType `json:"config_type" gorm:"size:50;not null"` // 配置类型
FilePath string `json:"file_path" gorm:"size:255"` // 节点上的实际路径
Content db.ScriptText `json:"content"` // 配置内容;MySQL MEDIUMTEXT / PG·SQLite TEXT
Version int `json:"version" gorm:"default:1"` // 当前版本号
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
UpdatedBy uint `json:"updated_by"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
// 节点同步状态:节点配置只有在推送到节点成功后才会提交为新版本;推送失败时新内容暂存为待推送,
// 版本号与当前内容保持节点上的真实值,Agent 重连后自动重推。
// Node sync state: a node config is committed as a new version only after it was pushed to the node.
// When the push fails the new content is parked as pending, version/content keep the node's real value,
// and the push is retried automatically once the Agent reconnects.
SyncStatus ConfigSyncStatus `json:"sync_status" gorm:"size:20"`
SyncError string `json:"sync_error" gorm:"size:1024"`
PendingContent db.ScriptText `json:"-"`
PendingComment string `json:"-" gorm:"size:255"`
PendingBy uint `json:"-"`
PendingSince *time.Time `json:"pending_since"`
}
Config 配置文件表 HostID 为 NULL 表示集群模板配置,否则为节点级配置
func (*Config) HasPendingPush ¶ added in v1.2.0
HasPendingPush 判断是否存在待推送内容。 HasPendingPush reports whether pending content is waiting to be pushed.
type ConfigChangeItem ¶ added in v1.2.0
type ConfigChangeItem struct {
ConfigID uint `json:"config_id,omitempty"`
ConfigType ConfigType `json:"config_type"`
HostID *uint `json:"host_id,omitempty"`
IsTemplate bool `json:"is_template"`
Status ConfigChangeStatus `json:"status"`
Version int `json:"version,omitempty"`
Message string `json:"message,omitempty"`
}
ConfigChangeItem 是单个配置的处理结果。 ConfigChangeItem is the result of one config.
type ConfigChangeResult ¶ added in v1.2.0
type ConfigChangeResult struct {
Items []*ConfigChangeItem `json:"items"`
CreatedCount int `json:"created_count"`
UpdatedCount int `json:"updated_count"`
UnchangedCount int `json:"unchanged_count"`
PendingCount int `json:"pending_count"`
FailedCount int `json:"failed_count"`
}
ConfigChangeResult 汇总一次扩缩容配置操作的逐配置结果;Items 永不为 nil。 ConfigChangeResult aggregates per-config results of a scaling config operation; Items is never nil.
func (*ConfigChangeResult) Partial ¶ added in v1.2.0
func (r *ConfigChangeResult) Partial() bool
Partial 表示存在待推送或失败的配置,调用方应把步骤标记为 partial 并允许重试。 Partial reports pending or failed configs; callers should mark the step partial and allow retry.
type ConfigChangeStatus ¶ added in v1.2.0
type ConfigChangeStatus string
ConfigChangeStatus 是扩缩容配置操作中单个配置的处理结果。 ConfigChangeStatus is the outcome of one config in a scaling config operation.
const ( // ConfigChangeCreated 新建了配置记录。 // ConfigChangeCreated means a config record was created. ConfigChangeCreated ConfigChangeStatus = "created" // ConfigChangeUpdated 内容已更新(节点配置已推送并提交)。 // ConfigChangeUpdated means the content was updated (node configs pushed and committed). ConfigChangeUpdated ConfigChangeStatus = "updated" // ConfigChangeUnchanged 内容已一致,未产生新版本。 // ConfigChangeUnchanged means the content already matched and no version was created. ConfigChangeUnchanged ConfigChangeStatus = "unchanged" // ConfigChangePendingPush 推送失败,新内容已暂存为待推送(Agent 重连后自动重推)。 // ConfigChangePendingPush means the push failed and the content is parked for retry on reconnect. ConfigChangePendingPush ConfigChangeStatus = "pending_push" // ConfigChangeFailed 该配置处理失败(解析、校验或推送失败且未建立记录)。 // ConfigChangeFailed means this config failed (parse, validation, or push failed without a record). ConfigChangeFailed ConfigChangeStatus = "failed" )
type ConfigFilter ¶
type ConfigFilter struct {
ClusterID uint `json:"cluster_id"`
HostID *uint `json:"host_id"`
ConfigType ConfigType `json:"config_type"`
OnlyTemplate bool `json:"only_template"`
}
ConfigFilter 配置过滤条件
type ConfigInfo ¶
type ConfigInfo struct {
ID uint `json:"id"`
ClusterID uint `json:"cluster_id"`
HostID *uint `json:"host_id"`
HostName string `json:"host_name,omitempty"`
HostIP string `json:"host_ip,omitempty"`
ConfigType ConfigType `json:"config_type"`
FilePath string `json:"file_path"`
Content string `json:"content"`
Version int `json:"version"`
IsTemplate bool `json:"is_template"`
MatchTemplate bool `json:"match_template"` // 是否与模板一致
UpdatedAt time.Time `json:"updated_at"`
UpdatedBy uint `json:"updated_by"`
PushError string `json:"push_error,omitempty"` // 推送到节点的错误信息
// SyncStatus 节点同步状态:synced / pending_push。
// SyncStatus is the node sync state: synced / pending_push.
SyncStatus ConfigSyncStatus `json:"sync_status,omitempty"`
// SyncError 最近一次推送失败原因。
// SyncError is the reason of the last failed push.
SyncError string `json:"sync_error,omitempty"`
// PendingContent 待推送的新内容(仅 pending_push 时返回)。
// PendingContent is the new content waiting to be pushed (only when pending_push).
PendingContent string `json:"pending_content,omitempty"`
// PendingSince 开始待推送的时间。
// PendingSince is when the content became pending.
PendingSince *time.Time `json:"pending_since,omitempty"`
}
ConfigInfo 配置信息(用于 API 响应)
type ConfigSyncStatus ¶ added in v1.2.0
type ConfigSyncStatus string
ConfigSyncStatus 节点配置与节点文件的同步状态。 ConfigSyncStatus is the sync state between a node config record and the file on the node.
const ( // ConfigSyncStatusSynced 记录与节点文件一致(空值等同于 synced,兼容历史数据)。 // ConfigSyncStatusSynced means the record matches the node file (empty means synced for legacy rows). ConfigSyncStatusSynced ConfigSyncStatus = "synced" // ConfigSyncStatusPendingPush 有新内容尚未成功推送到节点。 // ConfigSyncStatusPendingPush means newer content has not been pushed to the node yet. ConfigSyncStatusPendingPush ConfigSyncStatus = "pending_push" )
const ConfigSyncStatusUnchanged ConfigSyncStatus = "unchanged"
ConfigSyncStatusUnchanged 仅用于同步结果:节点内容已与目标一致。 ConfigSyncStatusUnchanged is used only in sync results: node content already matches the target.
type ConfigType ¶
type ConfigType string
ConfigType 配置文件类型
const ( // 通用配置(Hybrid 模式) ConfigTypeSeatunnel ConfigType = "seatunnel.yaml" ConfigTypeHazelcast ConfigType = "hazelcast.yaml" ConfigTypeHazelcastClient ConfigType = "hazelcast-client.yaml" ConfigTypeJVMOptions ConfigType = "jvm_options" ConfigTypeLog4j2 ConfigType = "log4j2.properties" // 环境变量配置 // Environment variable configuration ConfigTypeSeatunnelEnv ConfigType = "seatunnel-env.sh" // 分离模式配置(Separated 模式) ConfigTypeHazelcastMaster ConfigType = "hazelcast-master.yaml" ConfigTypeHazelcastWorker ConfigType = "hazelcast-worker.yaml" ConfigTypeJVMMasterOptions ConfigType = "jvm_master_options" ConfigTypeJVMWorkerOptions ConfigType = "jvm_worker_options" )
func GetConfigTypesForMode ¶
func GetConfigTypesForMode(deploymentMode string) []ConfigType
GetConfigTypesForMode 根据部署模式获取支持的配置类型
func MemberListConfigTypes ¶ added in v1.2.0
func MemberListConfigTypes(deploymentMode string) []ConfigType
MemberListConfigTypes 返回指定部署模式下需要修补 member-list 的配置类型:混合模式只有 hazelcast.yaml; 分离模式为 hazelcast-master.yaml、hazelcast-worker.yaml,若存在 hazelcast.yaml 也一并修补;模式未知时三者都修补。 MemberListConfigTypes returns the config types whose member-list must be patched for a deployment mode: hybrid only hazelcast.yaml; separated hazelcast-master.yaml and hazelcast-worker.yaml plus hazelcast.yaml when present; an unknown mode patches all three.
type ConfigVersion ¶
type ConfigVersion struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
ConfigID uint `json:"config_id" gorm:"index;not null"`
Version int `json:"version" gorm:"not null"`
Content db.ScriptText `json:"content"` // 配置版本正文;MySQL MEDIUMTEXT / PG·SQLite TEXT
Comment string `json:"comment" gorm:"size:255"` // 修改说明
CreatedBy uint `json:"created_by"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
}
ConfigVersion 配置版本表
type ConfigVersionInfo ¶
type ConfigVersionInfo struct {
ID uint `json:"id"`
ConfigID uint `json:"config_id"`
Version int `json:"version"`
Content string `json:"content"`
Comment string `json:"comment"`
CreatedBy uint `json:"created_by"`
CreatedAt time.Time `json:"created_at"`
}
ConfigVersionInfo 版本信息(用于 API 响应)
type CreateConfigRequest ¶
type CreateConfigRequest struct {
ClusterID uint `json:"cluster_id" binding:"required"`
HostID *uint `json:"host_id"`
ConfigType ConfigType `json:"config_type" binding:"required"`
Content string `json:"content"`
Comment string `json:"comment"`
}
CreateConfigRequest 创建配置请求
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler 配置管理 HTTP 处理器
func (*Handler) GetClusterConfigs ¶
GetClusterConfigs 获取集群所有配置 @Summary 获取集群配置列表 @Tags Config @Produce json @Param id path int true "集群ID" @Success 200 {object} Response @Router /api/v1/clusters/{id}/configs [get]
func (*Handler) GetConfig ¶
GetConfig 获取配置详情 @Summary 获取配置详情 @Tags Config @Produce json @Param id path int true "配置ID" @Success 200 {object} Response @Router /api/v1/configs/{id} [get]
func (*Handler) GetConfigVersions ¶
GetConfigVersions 获取配置版本历史 @Summary 获取配置版本历史 @Tags Config @Produce json @Param id path int true "配置ID" @Success 200 {object} Response @Router /api/v1/configs/{id}/versions [get]
func (*Handler) InitClusterConfigs ¶
InitClusterConfigs 初始化集群配置(从节点拉取) @Summary 初始化集群配置 @Tags Config @Accept json @Produce json @Param id path int true "集群ID" @Param body body InitClusterConfigsRequest true "初始化请求" @Success 200 {object} Response @Router /api/v1/clusters/{id}/configs/init [post]
func (*Handler) NormalizeConfig ¶
NormalizeConfig 智能修复(规范化)配置内容 @Summary 规范化配置内容 @Tags Config @Accept json @Produce json @Param body body NormalizeConfigRequest true "规范化请求" @Success 200 {object} Response @Router /api/v1/configs/normalize [post]
func (*Handler) PromoteConfig ¶
PromoteConfig 推广配置到集群 @Summary 推广配置到集群 @Tags Config @Accept json @Produce json @Param id path int true "配置ID" @Param body body PromoteConfigRequest true "推广请求" @Success 200 {object} Response @Router /api/v1/configs/{id}/promote [post]
func (*Handler) PushConfigToNode ¶
PushConfigToNode 推送配置到节点 @Summary 推送配置到节点 @Tags Config @Accept json @Produce json @Param id path int true "配置ID" @Param body body PushConfigRequest true "推送请求" @Success 200 {object} Response @Router /api/v1/configs/{id}/push [post]
func (*Handler) RollbackConfig ¶
RollbackConfig 回滚配置到指定版本 @Summary 回滚配置 @Tags Config @Accept json @Produce json @Param id path int true "配置ID" @Param body body RollbackConfigRequest true "回滚请求" @Success 200 {object} Response @Router /api/v1/configs/{id}/rollback [post]
func (*Handler) SetExecutionService ¶ added in v1.0.0
func (h *Handler) SetExecutionService(service *executionapp.Service)
SetExecutionService 设置 CLI 和直接 API 写请求使用的公共执行服务。 SetExecutionService sets the shared execution service used by CLI and direct API writes.
func (*Handler) SyncFromTemplate ¶
SyncFromTemplate 从集群模板同步 @Summary 从集群模板同步配置 @Tags Config @Accept json @Produce json @Param id path int true "配置ID" @Param body body SyncConfigRequest true "同步请求" @Success 200 {object} Response @Router /api/v1/configs/{id}/sync [post]
func (*Handler) SyncTemplateToAllNodes ¶
SyncTemplateToAllNodes 将集群模板同步到所有节点 @Summary 同步模板到所有节点 @Tags Config @Accept json @Produce json @Param id path int true "集群ID" @Param body body SyncTemplateToAllNodesRequest true "同步请求" @Success 200 {object} Response @Router /api/v1/clusters/{id}/configs/sync-all [post]
func (*Handler) UpdateConfig ¶
UpdateConfig 更新配置 @Summary 更新配置 @Tags Config @Accept json @Produce json @Param id path int true "配置ID" @Param body body UpdateConfigRequest true "更新内容" @Success 200 {object} Response @Router /api/v1/configs/{id} [put]
type HostProvider ¶
HostProvider 主机信息提供者接口
type InitClusterConfigsRequest ¶
type InitClusterConfigsRequest struct {
HostID uint `json:"host_id" binding:"required"`
InstallDir string `json:"install_dir" binding:"required"`
}
InitClusterConfigsRequest 初始化集群配置请求
type MemberListPatchResult ¶ added in v1.2.0
type MemberListPatchResult struct {
Members []string `json:"members"`
ConfigChangeResult
}
MemberListPatchResult 是 PatchMemberList 的结果,包含写入的完整成员列表。 MemberListPatchResult is the result of PatchMemberList, including the full member list written.
type NodeInfoProvider ¶
type NodeInfoProvider interface {
GetNodeInstallDir(ctx context.Context, clusterID uint, hostID uint) (string, error)
}
NodeInfoProvider 节点信息提供者接口
type NodeSyncResult ¶ added in v1.2.0
type NodeSyncResult struct {
ConfigID uint `json:"config_id"`
HostID uint `json:"host_id"`
HostName string `json:"host_name,omitempty"`
HostIP string `json:"host_ip,omitempty"`
Status ConfigSyncStatus `json:"status"` // synced / pending_push / unchanged
Version int `json:"version"`
Message string `json:"message,omitempty"`
}
NodeSyncResult 单个节点的同步结果。 NodeSyncResult is the sync result of one node.
type NormalizeConfigRequest ¶
type NormalizeConfigRequest struct {
ConfigType ConfigType `json:"config_type" binding:"required"`
Content string `json:"content" binding:"required"`
}
NormalizeConfigRequest 配置规范化请求
type PortMetadataUpdater ¶
type PortMetadataUpdater interface {
UpdateSeatunnelAPIPortByHost(ctx context.Context, clusterID uint, hostID uint, port int) error
UpdateHazelcastPortByHost(ctx context.Context, clusterID uint, hostID uint, configType ConfigType, port int) error
UpdateClusterJobLogMode(ctx context.Context, clusterID uint, mode string) error
}
PortMetadataUpdater updates cluster node API port metadata after config changes. PortMetadataUpdater 在配置变更后更新集群节点 API 端口元数据。
type PromoteConfigRequest ¶
type PromoteConfigRequest struct {
Comment string `json:"comment"`
}
PromoteConfigRequest 推广配置到集群请求
type PushConfigRequest ¶
type PushConfigRequest struct {
InstallDir string `json:"install_dir" binding:"required"`
}
PushConfigRequest 推送配置请求
type PushError ¶
type PushError struct {
HostID uint `json:"host_id"`
HostIP string `json:"host_ip,omitempty"`
Message string `json:"message"`
}
PushError 推送错误信息
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository 配置数据仓库
func (*Repository) Create ¶
func (r *Repository) Create(ctx context.Context, config *Config) error
Create 创建配置
func (*Repository) CreateVersion ¶
func (r *Repository) CreateVersion(ctx context.Context, version *ConfigVersion) error
CreateVersion 创建配置版本
func (*Repository) Delete ¶
func (r *Repository) Delete(ctx context.Context, id uint) error
Delete 删除配置
func (*Repository) DeleteByCluster ¶
func (r *Repository) DeleteByCluster(ctx context.Context, clusterID uint) error
DeleteByCluster 删除集群所有配置
func (*Repository) DeleteVersionsByConfig ¶
func (r *Repository) DeleteVersionsByConfig(ctx context.Context, configID uint) error
DeleteVersionsByConfig 删除配置的所有版本
func (*Repository) GetNodeConfig ¶
func (r *Repository) GetNodeConfig(ctx context.Context, clusterID uint, hostID uint, configType ConfigType) (*Config, error)
GetNodeConfig 获取节点配置
func (*Repository) GetTemplate ¶
func (r *Repository) GetTemplate(ctx context.Context, clusterID uint, configType ConfigType) (*Config, error)
GetTemplate 获取集群模板配置
func (*Repository) GetVersion ¶
func (r *Repository) GetVersion(ctx context.Context, configID uint, version int) (*ConfigVersion, error)
GetVersion 获取指定版本
func (*Repository) GetVersionByID ¶
func (r *Repository) GetVersionByID(ctx context.Context, id uint) (*ConfigVersion, error)
GetVersionByID 根据 ID 获取版本
func (*Repository) List ¶
func (r *Repository) List(ctx context.Context, filter *ConfigFilter) ([]*Config, error)
List 获取配置列表
func (*Repository) ListByCluster ¶
ListByCluster 获取集群所有配置(包括模板和节点配置)
func (*Repository) ListNodeConfigs ¶
func (r *Repository) ListNodeConfigs(ctx context.Context, clusterID uint, configType ConfigType) ([]*Config, error)
ListNodeConfigs 获取集群某类型的所有节点配置
func (*Repository) ListPendingPushByHost ¶ added in v1.2.0
ListPendingPushByHost 获取某主机上所有待推送的节点配置。 ListPendingPushByHost lists every node config of a host that has a pending push.
func (*Repository) ListUpdatedByClusterBetween ¶
func (r *Repository) ListUpdatedByClusterBetween(ctx context.Context, clusterID uint, start, end time.Time) ([]*Config, error)
ListUpdatedByClusterBetween returns configs updated within the given time window. ListUpdatedByClusterBetween 返回指定时间窗口内更新过的配置记录。
func (*Repository) ListVersions ¶
func (r *Repository) ListVersions(ctx context.Context, configID uint) ([]*ConfigVersion, error)
ListVersions 获取配置的版本历史
func (*Repository) Transaction ¶
func (r *Repository) Transaction(ctx context.Context, fn func(tx *Repository) error) error
Transaction 执行事务
type Response ¶
type Response struct {
ErrorMsg string `json:"error_msg"`
Data interface{} `json:"data"`
}
Response 标准响应格式
type RollbackConfigRequest ¶
type RollbackConfigRequest struct {
Version int `json:"version" binding:"required"`
Comment string `json:"comment"`
}
RollbackConfigRequest 回滚配置请求
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 配置管理服务
func NewService ¶
func NewService(repo *Repository, hostProvider HostProvider, nodeInfoProvider NodeInfoProvider, agentClient AgentClient) *Service
NewService 创建配置服务实例
func (*Service) ApplyTemplatesToHost ¶ added in v1.2.0
func (s *Service) ApplyTemplatesToHost(ctx context.Context, clusterID uint, hostID uint, deploymentMode string, members []string, opRef string, userID uint) (*ConfigChangeResult, error)
ApplyTemplatesToHost 安装模式:以集群模板为该主机生成配置并推送写盘(节点启动前调用)。members 非空时, 部署模式对应的 hazelcast*.yaml(与 PatchMemberList 相同的类型集合)的 member-list 先替换为该完整列表。主机尚无记录时先导入节点现有文件作为版本 1(保留真实历史), 再按“先推送后提交”应用模板;节点上也没有该文件时直接推送,成功后建立记录。调用前节点必须已登记(用于解析安装目录)。 ApplyTemplatesToHost (install mode) renders this host's configs from the cluster templates and pushes them to disk before the node starts. When members is non-empty, the member-list of hazelcast*.yaml is replaced with that full list first. A host without a record first imports the node's current file as version 1 (keeping the real history) and then applies the template push-then-commit; when the node has no such file the template is pushed directly and the record is created on success. The node must already be registered so its install directory can be resolved. Only the member-list types of the deployment mode (the same set as PatchMemberList) get the member list replaced.
func (*Service) Create ¶
func (s *Service) Create(ctx context.Context, req *CreateConfigRequest, userID uint) (*ConfigInfo, error)
Create 创建配置
func (*Service) DeleteConfigsByHost ¶ added in v1.2.0
DeleteConfigsByHost 删除某主机在所有集群中的配置记录及其版本(主机被删除时调用:只有不再属于任何集群的主机才允许删除, 其配置记录均为孤儿,否则 sync-all 会永远把它们标记为待推送)。模板不受影响。 DeleteConfigsByHost deletes a host's config records and versions across all clusters (called when the host is deleted: only hosts that no longer belong to any cluster can be deleted, so these records are orphans that sync-all would otherwise keep marking as pending push). Templates are untouched.
func (*Service) DeleteHostConfigs ¶ added in v1.2.0
DeleteHostConfigs 删除某主机在集群中的全部配置记录及其版本(缩容后该主机已无本集群节点时调用),不触碰集群模板与节点磁盘文件。 返回删除的配置记录数;主机没有记录时返回 0。 DeleteHostConfigs deletes every config record of a host in a cluster together with its versions (called after scale-in once the host has no node of the cluster left); templates and files on the node are untouched. It returns how many config records were deleted, 0 when the host had none.
func (*Service) EnsureClusterConfigsForHost ¶ added in v1.2.0
func (s *Service) EnsureClusterConfigsForHost(ctx context.Context, clusterID uint, hostID uint, installDir string, userID uint) error
EnsureClusterConfigsForHost 安装完成后登记节点配置:模板不存在时才由节点文件创建模板;模板已存在时只创建/刷新 该主机的配置记录,绝不覆盖模板(修复后续节点安装反向覆盖集群模板的问题)。 EnsureClusterConfigsForHost registers node configs after installation: a template is created from the node file only when missing; when it exists only this host's config records are created/refreshed and the template is never overwritten (fixes later installs overwriting the cluster template).
func (*Service) GetByCluster ¶
GetByCluster 获取集群所有配置
func (*Service) GetVersions ¶
GetVersions 获取版本历史
func (*Service) InitClusterConfigs ¶
func (s *Service) InitClusterConfigs(ctx context.Context, clusterID uint, hostID uint, installDir string, userID uint) error
InitClusterConfigs 从节点初始化集群配置:以节点内容创建或覆盖集群模板,并建立/刷新该主机的配置记录。 这是配置管理页“从节点初始化”的显式语义;安装器路径请使用 EnsureClusterConfigsForHost(不覆盖已有模板)。 InitClusterConfigs initializes cluster configs from a node: templates are created or overwritten with the node content and this host's records are created/refreshed. This is the explicit "init from node" semantics of the config page; the installer path uses EnsureClusterConfigsForHost, which never overwrites templates.
func (*Service) NormalizeContent ¶
NormalizeContent normalizes one config content when it is parseable and valid. NormalizeContent 对可解析且合法的配置内容做规范化处理。
func (*Service) PatchMemberList ¶ added in v1.2.0
func (s *Service) PatchMemberList(ctx context.Context, clusterID uint, deploymentMode string, members []string, opRef string, userID uint) (*MemberListPatchResult, error)
PatchMemberList 按部署模式对集群模板与每个主机配置分别只修补 hazelcast.network.join.tcp-ip.member-list, 内容变化才生成新版本(comment 带 opRef),主机配置按“先推送后提交”写入节点磁盘,不重启任何节点。 deploymentMode 为空时修补全部 hazelcast*.yaml。推送失败的配置标记待推送,结果 Partial() 为 true,可重试。 PatchMemberList patches only hazelcast.network.join.tcp-ip.member-list of the cluster templates and of every host config for the deployment mode; a new version (comment carries opRef) is created only when the content changes, host configs are written to disk push-then-commit, and no node is restarted. An empty deploymentMode patches every hazelcast*.yaml. Failed pushes are parked as pending, Partial() is true and the call can be retried.
func (*Service) Promote ¶
func (s *Service) Promote(ctx context.Context, id uint, req *PromoteConfigRequest, userID uint) (*SyncAllResult, error)
Promote 推广配置到集群(节点配置 → 集群模板 → 所有节点)。 模板在事务内更新;各节点按“先推送后提交”同步,推送失败的节点标记待推送。 Promote promotes a node config to the cluster (node config → template → all nodes). The template is updated in a transaction; nodes are synced push-then-commit, and nodes whose push fails are marked pending.
func (*Service) PushConfigToNode ¶
PushConfigToNode 推送配置到节点;若存在待推送内容则推送待推送内容,成功后提交为新版本。 PushConfigToNode pushes the config to its node; when a pending change exists it pushes that change and commits it as a new version on success.
func (*Service) RegisterHostConfigsFromNode ¶ added in v1.2.0
func (s *Service) RegisterHostConfigsFromNode(ctx context.Context, clusterID uint, hostID uint, installDir string, userID uint) (*ConfigChangeResult, error)
RegisterHostConfigsFromNode 纳管已运行节点:拉取节点现有配置建立该主机的配置记录,不写节点磁盘、不改集群模板; 与模板的差异通过 match_template=false 呈现。 RegisterHostConfigsFromNode registers an already running node: it pulls the node's current configs into this host's config records without writing to the node or touching templates; differences from the template show up as match_template=false.
func (*Service) RetryPendingPushes ¶ added in v1.2.0
RetryPendingPushes 重推某主机上所有待推送的节点配置(Agent 重连后调用)。返回成功提交的数量。 RetryPendingPushes re-pushes every pending node config of a host (called after the Agent reconnects) and returns how many were committed.
func (*Service) Rollback ¶
func (s *Service) Rollback(ctx context.Context, id uint, req *RollbackConfigRequest, userID uint) (*ConfigInfo, error)
Rollback 回滚到指定版本(节点配置先推送后提交) Rollback rolls back to a version (node configs: push first, then commit).
func (*Service) SetPortMetadataUpdater ¶
func (s *Service) SetPortMetadataUpdater(updater PortMetadataUpdater)
SetPortMetadataUpdater sets the cluster port metadata updater. SetPortMetadataUpdater 设置集群端口元数据更新器。
func (*Service) SyncFromTemplate ¶
func (s *Service) SyncFromTemplate(ctx context.Context, id uint, req *SyncConfigRequest, userID uint) (*ConfigInfo, error)
SyncFromTemplate 从集群模板同步到节点(先推送后提交) SyncFromTemplate syncs a node config from the cluster template (push first, then commit).
func (*Service) SyncTemplateToAllNodes ¶
func (s *Service) SyncTemplateToAllNodes(ctx context.Context, clusterID uint, configType ConfigType, userID uint) (*SyncAllResult, error)
SyncTemplateToAllNodes 将集群模板同步到所有节点配置:逐节点先推送后提交,推送失败的节点标记待推送且版本不变。 SyncTemplateToAllNodes syncs the cluster template to every node config: push-then-commit per node; nodes whose push fails are marked pending and keep their version.
func (*Service) Update ¶
func (s *Service) Update(ctx context.Context, id uint, req *UpdateConfigRequest, userID uint) (*ConfigInfo, error)
Update 更新配置。节点配置先推送到节点,推送成功才提交新版本;推送失败时新内容标记为待推送, 版本与当前内容保持节点上的真实值,Agent 重连后自动重推。 Update updates a config. Node configs are pushed first and committed as a new version only on success; on push failure the new content is marked pending, version/content keep the node's real value, and the push is retried when the Agent reconnects.
type SyncAllResult ¶
type SyncAllResult struct {
SyncedCount int `json:"synced_count"` // 已推送到节点并提交新版本的数量 / pushed and committed
PendingCount int `json:"pending_count"` // 推送失败、已标记待推送的数量 / push failed, marked pending
UnchangedCount int `json:"unchanged_count"` // 内容已一致无需变更的数量 / already up to date
NodeResults []*NodeSyncResult `json:"node_results"` // 逐节点结果 / per-node results
PushErrors []*PushError `json:"push_errors"` // 推送失败的节点列表(兼容字段)/ failed pushes (compat)
}
SyncAllResult 批量同步结果
type SyncConfigRequest ¶
type SyncConfigRequest struct {
Comment string `json:"comment"`
}
SyncConfigRequest 从集群模板同步请求
type SyncTemplateToAllNodesRequest ¶
type SyncTemplateToAllNodesRequest struct {
ConfigType string `json:"config_type" binding:"required"`
}
SyncTemplateToAllNodesRequest 同步模板到所有节点请求
type UpdateConfigRequest ¶
type UpdateConfigRequest struct {
Content string `json:"content" binding:"required"`
Comment string `json:"comment"`
}
UpdateConfigRequest 更新配置请求
type ValidationError ¶
type ValidationError struct {
ConfigType ConfigType
Message string
}
ValidationError represents one user-correctable config validation failure.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string