Signed-off-by: jagger <cossjie@foxmail.com>
Former-commit-id: b3cd5cb160
pull/128/head
| @@ -59,9 +59,9 @@ type ( | |||
| Type int64 `json:"type"` // 租户所属(0数算,1超算,2智算) | |||
| DeletedFlag int64 `json:"deletedFlag"` // 是否删除 | |||
| CreatedBy int64 `json:"createdBy"` // 创建人 | |||
| CreatedTime string `json:"createdTime"` // 创建时间 | |||
| CreateTime string `json:"createdTime"` // 创建时间 | |||
| UpdatedBy int64 `json:"updatedBy"` // 更新人 | |||
| UpdatedTime string `json:"updated_time"` // 更新时间 | |||
| UpdateTime string `json:"updated_time"` // 更新时间 | |||
| } | |||
| UpdateTenantReq { | |||
| @@ -115,6 +115,6 @@ type Cloud { | |||
| StartTime string `json:"startTime"` // 开始时间 | |||
| RunningTime int64 `json:"runningTime"` // 运行时长 | |||
| CreatedBy int64 `json:"createdBy"` // 创建人 | |||
| CreatedTime string `json:"createdTime"` // 创建时间 | |||
| CreateTime string `json:"createdTime"` // 创建时间 | |||
| Result string `json:"result"` | |||
| } | |||
| @@ -95,24 +95,13 @@ type ( | |||
| type ( | |||
| GeneralTaskReq { | |||
| Name string `json:"name"` | |||
| ComputeType string `json:"computeType"` | |||
| TemplateId string `json:"templateId"` | |||
| AdapterId string `json:"adapterId"` | |||
| ClusterIds []string `json:"clusterIds"` | |||
| Strategy Strategy `json:"strategy"` | |||
| Name string `json:"name"` | |||
| AdapterIds []string `json:"adapterIds"` | |||
| ClusterIds []string `json:"clusterIds"` | |||
| Strategy string `json:"strategy"` | |||
| StaticWeightMap map[string]int32 `json:"staticWeightMap,optional"` | |||
| ReqBody []string `json:"reqBody"` | |||
| } | |||
| Strategy { | |||
| Name string `json:"name"` | |||
| StaticWeightList []StaticWeightList `json:"staticWeightList"` | |||
| } | |||
| StaticWeightList { | |||
| ClusterName string `json:"clusterName"` | |||
| Weight int `json:"weight"` | |||
| } | |||
| ) | |||
| type deleteTaskReq { | |||
| @@ -941,9 +930,9 @@ type ( | |||
| Environment string `json:"environment"` | |||
| DeletedFlag int64 `json:"deleted_flag"` // 是否删除(0-否,1-是) | |||
| CreatedBy int64 `json:"created_by"` // 创建人 | |||
| CreatedTime string `json:"created_time"` // 创建时间 | |||
| CreateTime string `json:"created_time"` // 创建时间 | |||
| UpdatedBy int64 `json:"updated_by"` // 更新人 | |||
| UpdatedTime string `json:"updated_time"` // 更新时间 | |||
| UpdateTime string `json:"updated_time"` // 更新时间 | |||
| } | |||
| CloudInfo { | |||
| @@ -136,7 +136,11 @@ service pcm { | |||
| @doc "Statistical task status" | |||
| @handler countTaskStatus | |||
| get /core/task/countTaskStatus () returns (TaskStatusResp) | |||
| get /core/task/countTaskStatus () returns(TaskStatusResp) | |||
| @doc "task details" | |||
| @handler taskDetails | |||
| get /core/task/details (CId) returns(TaskStatusResp) | |||
| } | |||
| //hpc二级接口 | |||
| @@ -5,7 +5,7 @@ Port: 8999 | |||
| Timeout: 50000 | |||
| DB: | |||
| DataSource: root:uJpLd6u-J?HC1@(10.206.0.12:3306)/pcm?parseTime=true&loc=Local | |||
| DataSource: root:uJpLd6u-J?HC1@(47.92.88.143:3306)/pcm?parseTime=true&loc=Local | |||
| # DataSource: root:uJpLd6u-J?HC1@(47.92.88.143:3306)/pcm?parseTime=true&loc=Local | |||
| Redis: | |||
| Host: 10.206.0.12:6379 | |||
| @@ -0,0 +1,24 @@ | |||
| package core | |||
| import ( | |||
| "github.com/zeromicro/go-zero/rest/httpx" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/core" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" | |||
| "net/http" | |||
| ) | |||
| func TaskDetailsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||
| return func(w http.ResponseWriter, r *http.Request) { | |||
| var req types.CId | |||
| if err := httpx.Parse(r, &req); err != nil { | |||
| result.ParamErrorResult(r, w, err) | |||
| return | |||
| } | |||
| l := core.NewTaskDetailsLogic(r.Context(), svcCtx) | |||
| resp, err := l.TaskDetails(&req) | |||
| result.HttpResult(r, w, resp, err) | |||
| } | |||
| } | |||
| @@ -165,6 +165,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | |||
| Path: "/core/task/countTaskStatus", | |||
| Handler: core.CountTaskStatusHandler(serverCtx), | |||
| }, | |||
| { | |||
| Method: http.MethodGet, | |||
| Path: "/core/task/details", | |||
| Handler: core.TaskDetailsHandler(serverCtx), | |||
| }, | |||
| }, | |||
| rest.WithPrefix("/pcm/v1"), | |||
| ) | |||
| @@ -7,6 +7,7 @@ import ( | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models/cloud" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" | |||
| "io" | |||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | |||
| "k8s.io/apimachinery/pkg/runtime" | |||
| @@ -52,7 +53,6 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er | |||
| Status: constants.Saved, | |||
| Name: req.Name, | |||
| CommitTime: time.Now(), | |||
| NsID: "ns-admin", | |||
| YamlString: "[" + result + "]", | |||
| } | |||
| // Save the task data to the database | |||
| @@ -62,7 +62,7 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er | |||
| } | |||
| var clusters []*models.CloudModel | |||
| err := l.svcCtx.DbEngin.Raw("SELECT * FROM `t_cluster` where adapter_id = ? and id in ?", req.AdapterId, req.ClusterIds).Scan(&clusters).Error | |||
| err := l.svcCtx.DbEngin.Raw("SELECT * FROM `t_cluster` where adapter_id in ? and id in ?", req.AdapterIds, req.ClusterIds).Scan(&clusters).Error | |||
| if err != nil { | |||
| logx.Errorf("CommitGeneralTask() => sql execution error: %v", err) | |||
| return errors.Errorf("the cluster does not match the drive resources. Check the data") | |||
| @@ -73,11 +73,12 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er | |||
| for _, s := range req.ReqBody { | |||
| sStruct := UnMarshalK8sStruct(s) | |||
| unString, _ := sStruct.MarshalJSON() | |||
| taskCloud.Id = utils.GenSnowflakeIDUint() | |||
| taskCloud.TaskId = uint(taskModel.Id) | |||
| taskCloud.AdapterId = c.AdapterId | |||
| taskCloud.ClusterId = c.Id | |||
| taskCloud.ClusterName = c.Name | |||
| taskCloud.Status = "Saved" | |||
| taskCloud.Status = "Pending" | |||
| taskCloud.YamlString = string(unString) | |||
| taskCloud.Kind = sStruct.GetKind() | |||
| taskCloud.Namespace = sStruct.GetNamespace() | |||
| @@ -113,6 +114,14 @@ func UnMarshalK8sStruct(yamlString string) *unstructured.Unstructured { | |||
| if len(unstructuredObj.GetNamespace()) == 0 { | |||
| unstructuredObj.SetNamespace("default") | |||
| } | |||
| //设置副本数 | |||
| if unstructuredObj.GetKind() == "Deployment" || unstructuredObj.GetKind() == "StatefulSet" { | |||
| unstructured.SetNestedField( | |||
| unstructuredObj.Object, | |||
| int64(6), | |||
| "spec", "replicas", | |||
| ) | |||
| } | |||
| } | |||
| return unstructuredObj | |||
| } | |||
| @@ -0,0 +1,36 @@ | |||
| package core | |||
| import ( | |||
| "context" | |||
| "github.com/pkg/errors" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" | |||
| "gorm.io/gorm" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" | |||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" | |||
| "github.com/zeromicro/go-zero/core/logx" | |||
| ) | |||
| type TaskDetailsLogic struct { | |||
| logx.Logger | |||
| ctx context.Context | |||
| svcCtx *svc.ServiceContext | |||
| } | |||
| func NewTaskDetailsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TaskDetailsLogic { | |||
| return &TaskDetailsLogic{ | |||
| Logger: logx.WithContext(ctx), | |||
| ctx: ctx, | |||
| svcCtx: svcCtx, | |||
| } | |||
| } | |||
| func (l *TaskDetailsLogic) TaskDetails(req *types.CId) (resp *types.TaskStatusResp, err error) { | |||
| var task models.Task | |||
| if errors.Is(l.svcCtx.DbEngin.Where("id", req.Id).First(&task).Error, gorm.ErrRecordNotFound) { | |||
| return nil, errors.New("记录不存在") | |||
| } | |||
| return | |||
| } | |||
| @@ -83,23 +83,12 @@ type Region struct { | |||
| } | |||
| type GeneralTaskReq struct { | |||
| Name string `json:"name"` | |||
| ComputeType string `json:"computeType"` | |||
| TemplateId string `json:"templateId"` | |||
| AdapterId string `json:"adapterId"` | |||
| ClusterIds []string `json:"clusterIds"` | |||
| Strategy Strategy `json:"strategy"` | |||
| ReqBody []string `json:"reqBody"` | |||
| } | |||
| type Strategy struct { | |||
| Name string `json:"name"` | |||
| StaticWeightList []StaticWeightList `json:"staticWeightList"` | |||
| } | |||
| type StaticWeightList struct { | |||
| ClusterName string `json:"clusterName"` | |||
| Weight int `json:"weight"` | |||
| Name string `json:"name"` | |||
| AdapterIds []string `json:"adapterIds"` | |||
| ClusterIds []string `json:"clusterIds"` | |||
| Strategy string `json:"strategy"` | |||
| StaticWeightMap map[string]int32 `json:"staticWeightMap,optional"` | |||
| ReqBody []string `json:"reqBody"` | |||
| } | |||
| type DeleteTaskReq struct { | |||
| @@ -912,9 +901,9 @@ type HpcInfo struct { | |||
| Environment string `json:"environment"` | |||
| DeletedFlag int64 `json:"deleted_flag"` // 是否删除(0-否,1-是) | |||
| CreatedBy int64 `json:"created_by"` // 创建人 | |||
| CreatedTime string `json:"created_time"` // 创建时间 | |||
| CreateTime string `json:"created_time"` // 创建时间 | |||
| UpdatedBy int64 `json:"updated_by"` // 更新人 | |||
| UpdatedTime string `json:"updated_time"` // 更新时间 | |||
| UpdateTime string `json:"updated_time"` // 更新时间 | |||
| } | |||
| type CloudInfo struct { | |||
| @@ -5289,9 +5278,9 @@ type TenantInfo struct { | |||
| Type int64 `json:"type"` // 租户所属(0数算,1超算,2智算) | |||
| DeletedFlag int64 `json:"deletedFlag"` // 是否删除 | |||
| CreatedBy int64 `json:"createdBy"` // 创建人 | |||
| CreatedTime string `json:"createdTime"` // 创建时间 | |||
| CreateTime string `json:"createdTime"` // 创建时间 | |||
| UpdatedBy int64 `json:"updatedBy"` // 更新人 | |||
| UpdatedTime string `json:"updated_time"` // 更新时间 | |||
| UpdateTime string `json:"updated_time"` // 更新时间 | |||
| } | |||
| type UpdateTenantReq struct { | |||
| @@ -5345,7 +5334,7 @@ type Cloud struct { | |||
| StartTime string `json:"startTime"` // 开始时间 | |||
| RunningTime int64 `json:"runningTime"` // 运行时长 | |||
| CreatedBy int64 `json:"createdBy"` // 创建人 | |||
| CreatedTime string `json:"createdTime"` // 创建时间 | |||
| CreateTime string `json:"createdTime"` // 创建时间 | |||
| Result string `json:"result"` | |||
| } | |||
| @@ -6,9 +6,9 @@ import ( | |||
| ) | |||
| type BaseModel struct { | |||
| DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` // 删除时间 | |||
| CreatedBy uint `gorm:"created_by;comment:创建人" json:"createdBy"` //创建人 | |||
| CreatedTime time.Time `gorm:"comment:创建时间" json:"-"` // 创建时间 | |||
| UpdatedBy uint `gorm:"updated_by;comment:更新人" json:"UpdatedBy"` //创建人 | |||
| UpdatedTime time.Time `gorm:"comment:更新时间" json:"-"` // 更新时间 | |||
| DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` // 删除时间 | |||
| CreatedBy uint `gorm:"created_by;comment:创建人" json:"createdBy"` //创建人 | |||
| CreateTime time.Time `gorm:"autoCreateTime:nano;comment:创建时间" json:"-"` // 创建时间 | |||
| UpdatedBy uint `gorm:"updated_by;comment:更新人" json:"UpdatedBy"` //创建人 | |||
| UpdateTime time.Time `gorm:"autoUpdateTime:nano;;comment:更新时间" json:"-"` // 更新时间 | |||
| } | |||
| @@ -37,9 +37,9 @@ type File struct { | |||
| Status string `gorm:"column:status" json:"Status"` //type:string comment:hash version:2023-05-06 09:58 | |||
| DeletedFlag *int `gorm:"column:deleted_flag" json:"DeletedFlag"` //type:*int comment:是否删除 version:2023-05-06 09:58 | |||
| CreatedBy *int `gorm:"column:created_by" json:"CreatedBy"` //type:*int comment:创建人 version:2023-05-06 09:58 | |||
| CreatedTime *time.Time `gorm:"column:created_time" json:"CreatedTime"` //type:*time.Time comment:创建时间 version:2023-05-06 09:58 | |||
| CreatedTime *time.Time `gorm:"column:created_time" json:"CreateTime"` //type:*time.Time comment:创建时间 version:2023-05-06 09:58 | |||
| UpdatedBy *int `gorm:"column:updated_by" json:"UpdatedBy"` //type:*int comment:更新人 version:2023-05-06 09:58 | |||
| UpdatedTime *time.Time `gorm:"column:updated_time" json:"UpdatedTime"` //type:*time.Time comment:更新时间 version:2023-05-06 09:58 | |||
| UpdatedTime *time.Time `gorm:"column:updated_time" json:"UpdateTime"` //type:*time.Time comment:更新时间 version:2023-05-06 09:58 | |||
| } | |||
| // TableName 表名:data_set,。 | |||
| @@ -41,3 +41,8 @@ func GenSnowflakeID() int64 { | |||
| func GenSnowflakeIDStr() string { | |||
| return node.Generate().String() | |||
| } | |||
| // GenSnowflakeIDStr 工作id | |||
| func GenSnowflakeIDUint() uint { | |||
| return uint(node.Generate().Int64()) | |||
| } | |||