|
|
|
@@ -21,7 +21,12 @@ import ( |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant/cloud" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" |
|
|
|
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" |
|
|
|
cloud2 "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models/cloud" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" |
|
|
|
"net/http" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
type ContainerCreateLogic struct { |
|
|
|
@@ -39,8 +44,10 @@ func NewContainerCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C |
|
|
|
} |
|
|
|
|
|
|
|
func (l *ContainerCreateLogic) ContainerCreate(req *container.CreateParam) (resp interface{}, err error) { |
|
|
|
|
|
|
|
param := &cloud.CreateParam{ |
|
|
|
Name: req.Name, |
|
|
|
Description: req.Description, |
|
|
|
Port: req.Port, |
|
|
|
Cpu: req.Cpu, |
|
|
|
Memory: req.Memory, |
|
|
|
@@ -59,6 +66,38 @@ func (l *ContainerCreateLogic) ContainerCreate(req *container.CreateParam) (resp |
|
|
|
if create.Code != http.StatusOK { |
|
|
|
return nil, errors.New(create.Message) |
|
|
|
} |
|
|
|
resp = create.Data |
|
|
|
// 构建主任务结构体 |
|
|
|
taskModel := models.Task{ |
|
|
|
Id: utils.GenSnowflakeID(), |
|
|
|
Status: constants.Saved, |
|
|
|
Description: req.Description, |
|
|
|
Name: req.Name, |
|
|
|
UserId: req.UserId, |
|
|
|
AdapterTypeDict: "0", |
|
|
|
CommitTime: time.Now(), |
|
|
|
} |
|
|
|
// 保存任务数据到数据库 |
|
|
|
tx := l.svcCtx.DbEngin.Create(&taskModel) |
|
|
|
if tx.Error != nil { |
|
|
|
|
|
|
|
} |
|
|
|
var adapterId int64 |
|
|
|
tx.Table("t_cluster").Select("adapter_id").Where("id=?", req.ClusterId).Find(&adapterId) |
|
|
|
// 构建cloud任务结构体 |
|
|
|
cloudTaskModel := cloud2.TaskCloudModel{ |
|
|
|
Id: utils.GenSnowflakeID(), |
|
|
|
TaskId: taskModel.Id, |
|
|
|
Name: req.Name, |
|
|
|
AdapterId: adapterId, |
|
|
|
Status: constants.Saved, |
|
|
|
Namespace: "default", |
|
|
|
UserId: req.UserId, |
|
|
|
} |
|
|
|
// 保存任务数据到数据库 |
|
|
|
tx = l.svcCtx.DbEngin.Create(&cloudTaskModel) |
|
|
|
if tx.Error != nil { |
|
|
|
|
|
|
|
} |
|
|
|
resp = taskModel.Id |
|
|
|
return |
|
|
|
} |