Skip to content

Commit 2250f38

Browse files
committed
feat: 初始化发布系统基础模块和模型定义
添加发布系统核心模块,包括: - 服务信息仓储接口定义 - 发布任务仓储接口定义 - 部署任务和服务信息模型 - 外部系统适配器接口
1 parent 8fd98a7 commit 2250f38

File tree

7 files changed

+364
-0
lines changed

7 files changed

+364
-0
lines changed

release-system/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module release-system
2+
3+
go 1.24
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package adapter
2+
3+
import "time"
4+
5+
// ExternalDeploySystem 公司发布系统接口定义
6+
type ExternalDeploySystem interface {
7+
// CreateDeployment 调用公司发布系统创建发布任务
8+
CreateDeployment(req *ExternalDeployRequest) (*ExternalDeployResponse, error)
9+
10+
// PauseDeployment 暂停发布任务
11+
PauseDeployment(deployID string) error
12+
13+
// ContinueDeployment 继续发布任务
14+
ContinueDeployment(deployID string) error
15+
16+
// RollbackDeployment 回滚发布任务
17+
RollbackDeployment(deployID string) error
18+
19+
// GetDeploymentStatus 获取发布状态
20+
GetDeploymentStatus(deployID string) (*ExternalDeployStatus, error)
21+
}
22+
23+
// ExternalAlertSystem 公司告警系统接口定义
24+
type ExternalAlertSystem interface {
25+
// SendAlert 发送告警
26+
SendAlert(alert *AlertRequest) error
27+
28+
// GetAlerts 获取告警列表
29+
GetAlerts(query *AlertQuery) (*AlertResponse, error)
30+
}
31+
32+
// ExternalDeployRequest 公司发布系统请求
33+
type ExternalDeployRequest struct {
34+
Service string `json:"service"`
35+
Version string `json:"version"`
36+
ScheduleTime *time.Time `json:"scheduleTime,omitempty"`
37+
Config map[string]any `json:"config,omitempty"`
38+
}
39+
40+
// ExternalDeployResponse 公司发布系统响应
41+
type ExternalDeployResponse struct {
42+
DeployID string `json:"deployId"`
43+
Status string `json:"status"`
44+
Message string `json:"message,omitempty"`
45+
}
46+
47+
// ExternalDeployStatus 公司发布状态
48+
type ExternalDeployStatus struct {
49+
DeployID string `json:"deployId"`
50+
Service string `json:"service"`
51+
Version string `json:"version"`
52+
Status string `json:"status"`
53+
Progress float64 `json:"progress"` // 发布进度 0-100
54+
StartTime *time.Time `json:"startTime,omitempty"`
55+
FinishTime *time.Time `json:"finishTime,omitempty"`
56+
ErrorMessage string `json:"errorMessage,omitempty"`
57+
}
58+
59+
// AlertRequest 告警请求
60+
type AlertRequest struct {
61+
Title string `json:"title"`
62+
Content string `json:"content"`
63+
Level string `json:"level"` // Info/Warning/Error/Critical
64+
Service string `json:"service"`
65+
DeployID string `json:"deployId,omitempty"`
66+
Labels map[string]string `json:"labels,omitempty"`
67+
Annotations map[string]any `json:"annotations,omitempty"`
68+
}
69+
70+
// AlertQuery 告警查询参数
71+
type AlertQuery struct {
72+
Service string `json:"service,omitempty"`
73+
Level string `json:"level,omitempty"`
74+
Start *time.Time `json:"start,omitempty"`
75+
End *time.Time `json:"end,omitempty"`
76+
Limit int `json:"limit,omitempty"`
77+
}
78+
79+
// AlertResponse 告警响应
80+
type AlertResponse struct {
81+
Items []Alert `json:"items"`
82+
Total int `json:"total"`
83+
}
84+
85+
// Alert 告警信息
86+
type Alert struct {
87+
ID string `json:"id"`
88+
Title string `json:"title"`
89+
Content string `json:"content"`
90+
Level string `json:"level"`
91+
Service string `json:"service"`
92+
Status string `json:"status"` // Active/Resolved
93+
CreatedAt time.Time `json:"createdAt"`
94+
ResolvedAt *time.Time `json:"resolvedAt,omitempty"`
95+
Labels map[string]string `json:"labels,omitempty"`
96+
Annotations map[string]any `json:"annotations,omitempty"`
97+
}
98+
99+
// ===== 数据库模型(对应ER图中的表) =====
100+
101+
// EventLog 事件日志数据库模型(对应event_logs表)
102+
type EventLog struct {
103+
ID int `json:"id" db:"id"` // bigint - 主键
104+
SourceSystem string `json:"sourceSystem" db:"source_system"` // varchar(255)
105+
SourceID string `json:"sourceId" db:"source_id"` // varchar(255)
106+
SourceName string `json:"sourceName" db:"source_name"` // varchar(255)
107+
Timestamp time.Time `json:"timestamp" db:"timestamp"` // datetime
108+
Actor string `json:"actor" db:"actor"` // varchar(255)
109+
Severity string `json:"severity" db:"severity"` // varchar(255)
110+
CorrelationID string `json:"correlationId" db:"correlation_id"` // varchar(255)
111+
Payload string `json:"payload" db:"payload"` // text - JSON格式
112+
}
113+
114+
// MetricAlertChange 指标告警变更数据库模型(对应metric_alert_changes表)
115+
type MetricAlertChange struct {
116+
ID int `json:"id" db:"id"` // bigint - 主键
117+
ChangeTime time.Time `json:"changeTime" db:"change_time"` // datetime
118+
AlertName string `json:"alertName" db:"alert_name"` // varchar(255)
119+
ChangeItem string `json:"changeItem" db:"change_item"` // text - 变更项内容
120+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package deploy_task
2+
3+
import "time"
4+
5+
// DeployState 发布状态枚举
6+
type DeployState string
7+
8+
const (
9+
StatusDeploying DeployState = "deploying"
10+
StatusStop DeployState = "stop"
11+
StatusRollback DeployState = "rollback"
12+
StatusCompleted DeployState = "completed"
13+
)
14+
15+
// DeployBatch 部署批次信息
16+
type DeployBatch struct {
17+
ID int `json:"id" db:"id"` // bigint - 主键
18+
DeployID int `json:"deployId" db:"deploy_id"` // bigint - 外键
19+
BatchID string `json:"batchId" db:"batch_id"` // varchar(255) - 批次ID
20+
StartTime *time.Time `json:"startTime" db:"start_time"` // datetime
21+
EndTime *time.Time `json:"endTime" db:"end_time"` // datetime
22+
TargetRatio float64 `json:"targetRatio" db:"target_ratio"` // double
23+
NodeIDs []string `json:"nodeIds" db:"node_ids"` // 数组格式的节点ID列表
24+
}
25+
26+
// ServiceDeployTask 服务部署任务信息
27+
type ServiceDeployTask struct {
28+
ID int `json:"id" db:"id"` // bigint - 主键
29+
Service string `json:"service" db:"service"` // varchar(255) - 外键引用services.name
30+
Version string `json:"version" db:"version"` // varchar(255) - 外键引用service_versions.version
31+
TaskCreator string `json:"taskCreator" db:"task_creator"` // varchar(255)
32+
DeployBeginTime *time.Time `json:"deployBeginTime" db:"deploy_begin_time"` // datetime
33+
DeployEndTime *time.Time `json:"deployEndTime" db:"deploy_end_time"` // datetime
34+
DeployState DeployState `json:"deployState" db:"deploy_state"` // 部署状态
35+
CorrelationID string `json:"correlationId" db:"correlation_id"` // varchar(255)
36+
}
37+
38+
// ===== API请求响应结构体 =====
39+
40+
// Deployment API响应用的发布任务
41+
type Deployment struct {
42+
ID string `json:"id"`
43+
Service string `json:"service"`
44+
Version string `json:"version"`
45+
Status DeployState `json:"status"`
46+
ScheduleTime *time.Time `json:"scheduleTime,omitempty"`
47+
FinishTime *time.Time `json:"finishTime,omitempty"`
48+
}
49+
50+
// CreateDeploymentRequest 创建发布任务请求
51+
type CreateDeploymentRequest struct {
52+
Service string `json:"service" binding:"required"`
53+
Version string `json:"version" binding:"required"`
54+
ScheduleTime *time.Time `json:"scheduleTime,omitempty"` // 可选参数,不填为立即发布
55+
}
56+
57+
// UpdateDeploymentRequest 修改发布任务请求
58+
type UpdateDeploymentRequest struct {
59+
Version string `json:"version,omitempty"`
60+
ScheduleTime *time.Time `json:"scheduleTime,omitempty"` // 新的计划发布时间
61+
}
62+
63+
// DeploymentQuery 发布任务查询参数
64+
type DeploymentQuery struct {
65+
Type DeployState `form:"type"` // deploying/stop/rollback/completed
66+
Service string `form:"service"` // 服务名称过滤
67+
Start string `form:"start"` // 分页起始
68+
Limit int `form:"limit"` // 分页大小
69+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package service_info
2+
3+
import "time"
4+
5+
// ExceptionStatus 异常处理状态枚举
6+
type ExceptionStatus string
7+
8+
const (
9+
ExceptionStatusNew ExceptionStatus = "new"
10+
ExceptionStatusAnalyzing ExceptionStatus = "analyzing"
11+
ExceptionStatusProcessing ExceptionStatus = "processing"
12+
ExceptionStatusResolved ExceptionStatus = "resolved"
13+
)
14+
15+
// HealthStatus 健康状态枚举
16+
type HealthStatus string
17+
18+
const (
19+
HealthStatusNormal HealthStatus = "Normal"
20+
HealthStatusWarning HealthStatus = "Warning"
21+
HealthStatusError HealthStatus = "Error"
22+
)
23+
24+
// DeployStatus 部署状态枚举
25+
type DeployStatus string
26+
27+
const (
28+
DeployStatusInDeploying DeployStatus = "InDeploying"
29+
DeployStatusAllDeployFinish DeployStatus = "AllDeployFinish"
30+
)
31+
32+
// Service 服务基础信息
33+
type Service struct {
34+
Name string `json:"name" db:"name"` // varchar(255) - 主键
35+
Deps []string `json:"deps" db:"deps"` // 依赖关系
36+
}
37+
38+
// ServiceInstance 服务实例信息
39+
type ServiceInstance struct {
40+
ID string `json:"id" db:"id"` // 主键
41+
Service string `json:"service" db:"service"` // varchar(255) - 外键引用services.name
42+
Version string `json:"version" db:"version"` // varchar(255) - 外键引用service_versions.version
43+
}
44+
45+
// ServiceVersion 服务版本信息
46+
type ServiceVersion struct {
47+
Version string `json:"version" db:"version"` // varchar(255) - 主键
48+
Service string `json:"service" db:"service"` // varchar(255) - 外键引用services.name
49+
CreateTime time.Time `json:"createTime" db:"create_time"` // 时间戳字段
50+
}
51+
52+
// ServiceState 服务状态信息
53+
type ServiceState struct {
54+
Service string `json:"service" db:"service"` // varchar(255) - 外键引用services.name
55+
Version string `json:"version" db:"version"` // varchar(255) - 外键引用service_versions.version
56+
Level string `json:"level" db:"level"` // varchar(255) - 异常级别
57+
ReportAt time.Time `json:"reportAt" db:"report_at"` // datetime - 报告时间
58+
ResolvedAt *time.Time `json:"resolvedAt" db:"resolved_at"` // datetime - 解决时间(可为null)
59+
HealthStatus HealthStatus `json:"healthStatus" db:"health_status"` // varchar(255) - 健康状态
60+
ExceptionStatus ExceptionStatus `json:"exceptionStatus" db:"exception_status"` // varchar(255) - 异常处理状态
61+
Details string `json:"details" db:"details"` // text - JSON格式的详细信息
62+
}
63+
64+
// ===== API响应结构体 =====
65+
66+
// ServiceItem API响应用的服务信息(对应/v1/services接口items格式)
67+
type ServiceItem struct {
68+
Name string `json:"name"` // 服务名称
69+
DeployState DeployStatus `json:"deployState"` // 发布状态:InDeploying|AllDeployFinish
70+
Health HealthStatus `json:"health"` // 健康状态:Normal/Warning/Error
71+
Deps []string `json:"deps"` // 依赖关系(直接使用Service.Deps)
72+
}
73+
74+
// ServicesResponse 服务列表API响应(对应/v1/services接口)
75+
type ServicesResponse struct {
76+
Items []ServiceItem `json:"items"`
77+
Relation map[string][]string `json:"relation"` // 树形关系描述,有向无环图
78+
}
79+
80+
// ActiveVersionItem 活跃版本项目
81+
type ActiveVersionItem struct {
82+
Version string `json:"version"` // v1.0.1
83+
DeployID string `json:"deployID"` // 1001
84+
StartTime time.Time `json:"startTime"` // 开始时间
85+
EstimatedCompletionTime time.Time `json:"estimatedCompletionTime"` // 预估完成时间
86+
Instances int `json:"instances"` // 实例个数
87+
Health HealthStatus `json:"health"` // 健康状态:Normal/Warning/Error
88+
}
89+
90+
// MetricStats 服务指标统计(对应/v1/services/:service/metricStats接口)
91+
type MetricStats struct {
92+
Summary MetricSummary `json:"summary"` // 所有实例的聚合值
93+
Items []MetricVersionItem `json:"items"` // 各版本的指标内容
94+
}
95+
96+
// MetricSummary 指标汇总
97+
type MetricSummary struct {
98+
Metrics []Metric `json:"metrics"` // 此版本发布的metric指标内容
99+
}
100+
101+
// MetricVersionItem 版本指标项
102+
type MetricVersionItem struct {
103+
Version string `json:"version"` // v1.0.1
104+
Metrics []Metric `json:"metrics"` // 此版本发布的metric指标内容
105+
}
106+
107+
// Metric 指标
108+
type Metric struct {
109+
Name string `json:"name"` // latency/traffic/errorRatio/saturation
110+
Value any `json:"value"` // 指标值(ms/Qps/百分比)
111+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package repository
2+
3+
import (
4+
"context"
5+
"release-system/internal/model/deploy_task"
6+
)
7+
8+
// DeploymentRepository 发布任务仓储接口
9+
type DeploymentRepository interface {
10+
// ===== API方法 =====
11+
12+
// CreateDeployment 创建发布任务(POST /v1/deployments)
13+
// 直接返回部署任务ID
14+
CreateDeployment(ctx context.Context, req *deploy_task.CreateDeploymentRequest) (string, error)
15+
16+
// GetDeploymentByID 根据ID获取发布任务详情(GET /v1/deployments/:deployID)
17+
GetDeploymentByID(ctx context.Context, deployID string) (*deploy_task.Deployment, error)
18+
19+
// GetDeployments 获取发布任务列表(GET /v1/deployments?type=Schedule&service=xxx)
20+
GetDeployments(ctx context.Context, query *deploy_task.DeploymentQuery) ([]deploy_task.Deployment, error)
21+
22+
// UpdateDeployment 修改未开始的发布任务(POST /v1/deployments/:deployID)
23+
UpdateDeployment(ctx context.Context, deployID string, req *deploy_task.UpdateDeploymentRequest) error
24+
25+
// DeleteDeployment 删除未开始的发布任务(DELETE /v1/deployments/:deployID)
26+
DeleteDeployment(ctx context.Context, deployID string) error
27+
28+
// PauseDeployment 暂停正在灰度的发布任务(POST /v1/deployments/:deployID/pause)
29+
PauseDeployment(ctx context.Context, deployID string) error
30+
31+
// ContinueDeployment 继续发布(POST /v1/deployments/:deployID/continue)
32+
ContinueDeployment(ctx context.Context, deployID string) error
33+
34+
// RollbackDeployment 回滚发布任务(POST /v1/deployments/:deployID/rollback)
35+
RollbackDeployment(ctx context.Context, deployID string) error
36+
37+
// CheckDeploymentConflict 检查发布冲突(同一服务同一版本是否已在发布)
38+
CheckDeploymentConflict(ctx context.Context, service, version string) (bool, error)
39+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package repository
2+
3+
import (
4+
"context"
5+
"release-system/internal/model/service_info"
6+
)
7+
8+
// ServiceRepository 服务信息仓储接口
9+
type ServiceRepository interface {
10+
// GetServicesForAPI 获取所有服务列表(GET /v1/services)
11+
GetServicesForAPI(ctx context.Context) (*service_info.ServicesResponse, error)
12+
13+
// GetServiceActiveVersionsForAPI 获取服务活跃版本(GET /v1/services/:service/activeVersions)
14+
GetServiceActiveVersionsForAPI(ctx context.Context, serviceName string) ([]service_info.ActiveVersionItem, error)
15+
16+
// GetServiceAvailableVersions 获取可用服务版本(GET /v1/services/:service/availableVersions?type=unrelease)
17+
// 直接返回ServiceVersion列表,API层负责包装响应格式
18+
GetServiceAvailableVersions(ctx context.Context, serviceName string, versionType string) ([]service_info.ServiceVersion, error)
19+
20+
// GetServiceMetrics 获取服务指标数据(GET /v1/services/:service/metricStats)
21+
GetServiceMetrics(ctx context.Context, serviceName string) (*service_info.MetricStats, error)
22+
}

release-system/internal/service/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)