|
|
|
@@ -43,7 +43,9 @@ func NewCommitGeneralTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) error { |
|
|
|
func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) (resp *types.GeneralTaskResp, err error) { |
|
|
|
// todo: add your logic here and delete this line |
|
|
|
resp = &types.GeneralTaskResp{} |
|
|
|
tx := l.svcCtx.DbEngin.Begin() |
|
|
|
// 执行回滚或者提交操作 |
|
|
|
defer func() { |
|
|
|
@@ -60,10 +62,10 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er |
|
|
|
}() |
|
|
|
adapterId, _ := strconv.ParseUint(req.AdapterIds[0], 10, 64) |
|
|
|
var clusters []*models.CloudModel |
|
|
|
err := tx.Raw("SELECT * FROM `t_cluster` where adapter_id in ? and id in ?", req.AdapterIds, req.ClusterIds).Scan(&clusters).Error |
|
|
|
err = tx.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") |
|
|
|
return nil, errors.Errorf("the cluster does not match the drive resources. Check the data") |
|
|
|
} |
|
|
|
taskCloud := cloud.TaskCloudModel{} |
|
|
|
opt := &option.CloudOption{} |
|
|
|
@@ -73,7 +75,7 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er |
|
|
|
results, err := l.svcCtx.Scheduler.AssignAndSchedule(sc, executor.SUBMIT_MODE_JOINT_CLOUD, nil) |
|
|
|
if err != nil { |
|
|
|
logx.Errorf("AssignAndSchedule() => execution error: %v", err) |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
rs := (results).([]*schedulers.CloudResult) |
|
|
|
@@ -101,6 +103,7 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er |
|
|
|
Strategy: strategy, |
|
|
|
UserId: req.UserId, |
|
|
|
} |
|
|
|
resp.TaskId = taskModel.Id |
|
|
|
var taskClouds []cloud.TaskCloudModel |
|
|
|
adapterName := "" |
|
|
|
tx.Table("t_adapter").Select("name").Where("id=?", adapterId).Find(&adapterName) |
|
|
|
@@ -138,12 +141,12 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er |
|
|
|
|
|
|
|
if db.Error != nil { |
|
|
|
logx.Errorf("Task creation failure, err: %v", db.Error) |
|
|
|
return errors.New("task creation failure") |
|
|
|
return nil, errors.New("task creation failure") |
|
|
|
} |
|
|
|
// 数据上链 |
|
|
|
bytes, _ := json.Marshal(taskModel) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
// 查询资源价格 |
|
|
|
var price int64 |
|
|
|
@@ -163,7 +166,7 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er |
|
|
|
Amount: price, |
|
|
|
Args: []string{strconv.FormatInt(taskModel.Id, 10), string(bytes)}, |
|
|
|
}) |
|
|
|
return nil |
|
|
|
return resp, nil |
|
|
|
} |
|
|
|
|
|
|
|
func UnMarshalK8sStruct(yamlString string, replica int64) *unstructured.Unstructured { |
|
|
|
|