|
|
@@ -33,9 +33,6 @@ func NewCommitVmTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Comm |
|
|
|
|
|
|
|
|
func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *types.CommitVmTaskResp, err error) { |
|
|
func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *types.CommitVmTaskResp, err error) { |
|
|
// todo: add your logic here and delete this line |
|
|
// todo: add your logic here and delete this line |
|
|
/*var ImageRef string |
|
|
|
|
|
var FlavorRef string |
|
|
|
|
|
var NetworkRef string*/ |
|
|
|
|
|
resp = &types.CommitVmTaskResp{} |
|
|
resp = &types.CommitVmTaskResp{} |
|
|
tx := l.svcCtx.DbEngin.Begin() |
|
|
tx := l.svcCtx.DbEngin.Begin() |
|
|
//Building the main task structure |
|
|
//Building the main task structure |
|
|
@@ -53,25 +50,11 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type |
|
|
}() |
|
|
}() |
|
|
//TODO adapter |
|
|
//TODO adapter |
|
|
adapterId, _ := strconv.ParseUint(req.AdapterIds[0], 10, 64) |
|
|
adapterId, _ := strconv.ParseUint(req.AdapterIds[0], 10, 64) |
|
|
/* opt := &option.VmOption{ |
|
|
|
|
|
AdapterId: req.VmOption.AdapterId, |
|
|
|
|
|
Replicas: req.VmOption.Replicas, |
|
|
|
|
|
Strategy: req.VmOption.Strategy, |
|
|
|
|
|
ClusterToStaticWeight: req.VmOption.StaticWeightMap, |
|
|
|
|
|
Status: constants.Saved, |
|
|
|
|
|
MatchLabels: req.VmOption.MatchLabels, |
|
|
|
|
|
StaticWeightMap: req.VmOption.StaticWeightMap, |
|
|
|
|
|
Name: req.VmOption.Name, |
|
|
|
|
|
CommitTime: time.Now(), |
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
var clusters []*models.VmModel |
|
|
var clusters []*models.VmModel |
|
|
err2 := l.svcCtx.DbEngin.Raw("SELECT * FROM `t_cluster` where adapter_id in ? and id in ?", req.AdapterIds, req.ClusterIds).Scan(&clusters).Error |
|
|
err2 := l.svcCtx.DbEngin.Raw("SELECT * FROM `t_cluster` where adapter_id in ? and id in ?", req.AdapterIds, req.ClusterIds).Scan(&clusters).Error |
|
|
if err2 != nil { |
|
|
if err2 != nil { |
|
|
logx.Errorf("CommitGeneralTask() => sql execution error: %v", err) |
|
|
logx.Errorf("CommitGeneralTask() => sql execution error: %v", err) |
|
|
//return errors.Errorf("the cluster does not match the drive resources. Check the data"), nil |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
taskVm := models.TaskVm{} |
|
|
taskVm := models.TaskVm{} |
|
|
//TODO 执行策略返回集群跟 Replica |
|
|
//TODO 执行策略返回集群跟 Replica |
|
|
opt := &option.VmOption{} |
|
|
opt := &option.VmOption{} |
|
|
@@ -81,20 +64,17 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 3、Return scheduling results |
|
|
// 3、Return scheduling results |
|
|
results, err := l.svcCtx.Scheduler.AssignAndSchedule(vmSchdl) |
|
|
results, err := l.svcCtx.Scheduler.AssignAndSchedule(vmSchdl) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
logx.Errorf("AssignAndSchedule() => execution error: %v", err) |
|
|
logx.Errorf("AssignAndSchedule() => execution error: %v", err) |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
rs := (results).([]*schedulers.VmResult) |
|
|
rs := (results).([]*schedulers.VmResult) |
|
|
var synergyStatus int64 |
|
|
var synergyStatus int64 |
|
|
if len(rs) > 1 { |
|
|
if len(rs) > 1 { |
|
|
synergyStatus = 1 |
|
|
synergyStatus = 1 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var strategy int64 |
|
|
var strategy int64 |
|
|
sqlStr := `select t_dict_item.item_value |
|
|
sqlStr := `select t_dict_item.item_value |
|
|
from t_dict |
|
|
from t_dict |
|
|
@@ -113,7 +93,7 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type |
|
|
SynergyStatus: synergyStatus, |
|
|
SynergyStatus: synergyStatus, |
|
|
Strategy: strategy, |
|
|
Strategy: strategy, |
|
|
} |
|
|
} |
|
|
var taskVms models.TaskVm |
|
|
|
|
|
|
|
|
//var taskVms models.TaskVm |
|
|
var VmObject types.TaskVm |
|
|
var VmObject types.TaskVm |
|
|
for _, r := range rs { |
|
|
for _, r := range rs { |
|
|
for _, clusterId := range req.ClusterIds { |
|
|
for _, clusterId := range req.ClusterIds { |
|
|
@@ -138,7 +118,7 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type |
|
|
logx.Errorf("CommitGeneralTask() => sql execution error: %v", err) |
|
|
logx.Errorf("CommitGeneralTask() => sql execution error: %v", err) |
|
|
//return errors.Errorf("the cluster does not match the drive resources. Check the data"), nil |
|
|
//return errors.Errorf("the cluster does not match the drive resources. Check the data"), nil |
|
|
} |
|
|
} |
|
|
taskVms.Name = req.Name |
|
|
|
|
|
|
|
|
taskVm.Name = req.VmName |
|
|
taskVm.Status = "Saved" |
|
|
taskVm.Status = "Saved" |
|
|
taskVm.StartTime = time.Now().String() |
|
|
taskVm.StartTime = time.Now().String() |
|
|
taskVm.MinCount = req.MinCount |
|
|
taskVm.MinCount = req.MinCount |
|
|
@@ -168,25 +148,6 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type |
|
|
if tx.Error != nil { |
|
|
if tx.Error != nil { |
|
|
return nil, tx.Error |
|
|
return nil, tx.Error |
|
|
} |
|
|
} |
|
|
//var clusterIds []int64 |
|
|
|
|
|
//l.svcCtx.DbEngin.Raw("SELECT id FROM `t_cluster` where adapter_id = ? ", req.VmOption.AdapterId).Scan(&clusterIds) |
|
|
|
|
|
//if len(clusterIds) == 0 || clusterIds == nil { |
|
|
|
|
|
// return nil, nil |
|
|
|
|
|
//} |
|
|
|
|
|
//adapterId, _ := strconv.ParseUint(req.VmOption.AdapterId, 10, 64) |
|
|
|
|
|
//taskVm.AdapterId = int64(adapterId) |
|
|
|
|
|
//clusterId, _ = strconv.ParseUint(r.ClusterId, 10, 64) |
|
|
|
|
|
//taskVm.ClusterId = int64(clusterId) |
|
|
|
|
|
//taskVm.Status = "Saved" |
|
|
|
|
|
//taskVm.StartTime = time.Now().String() |
|
|
|
|
|
//taskVm.ImageRef = CreateMulServer.ImageRef |
|
|
|
|
|
//taskVm.FlavorRef = CreateMulServer.FlavorRef |
|
|
|
|
|
//taskVm.Uuid = CreateMulServer.Uuid |
|
|
|
|
|
//taskVm.Platform = CreateMulServer.Platform |
|
|
|
|
|
//tx = l.svcCtx.DbEngin.Create(&taskVm) |
|
|
|
|
|
//if tx.Error != nil { |
|
|
|
|
|
// return nil, tx.Error |
|
|
|
|
|
//} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@@ -201,18 +162,18 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type |
|
|
CreatedTime: time.Now(), |
|
|
CreatedTime: time.Now(), |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
db := tx.Table("task").Create(&taskModel) |
|
|
|
|
|
db = tx.Table("task_cloud").Create(&taskVm) |
|
|
|
|
|
|
|
|
//db := tx.Table("task").Create(&taskModel) |
|
|
|
|
|
db := tx.Table("task_vm").Create(&taskVm) |
|
|
db = tx.Table("t_notice").Create(¬iceInfo) |
|
|
db = tx.Table("t_notice").Create(¬iceInfo) |
|
|
if db.Error != nil { |
|
|
if db.Error != nil { |
|
|
logx.Errorf("Task creation failure, err: %v", db.Error) |
|
|
logx.Errorf("Task creation failure, err: %v", db.Error) |
|
|
} |
|
|
} |
|
|
//db = tx.Table("t_notice").Create(¬iceInfo) |
|
|
//db = tx.Table("t_notice").Create(¬iceInfo) |
|
|
// Save task data to database |
|
|
// Save task data to database |
|
|
//tf := l.svcCtx.DbEngin.Create(&taskModel) |
|
|
|
|
|
//if tf.Error != nil { |
|
|
|
|
|
// return nil, tf.Error |
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
tf := l.svcCtx.DbEngin.Create(&taskModel) |
|
|
|
|
|
if tf.Error != nil { |
|
|
|
|
|
return nil, tf.Error |
|
|
|
|
|
} |
|
|
//tn := l.svcCtx.DbEngin.Create(¬iceInfo) |
|
|
//tn := l.svcCtx.DbEngin.Create(¬iceInfo) |
|
|
//if tn.Error != nil { |
|
|
//if tn.Error != nil { |
|
|
// return nil, tn.Error |
|
|
// return nil, tn.Error |
|
|
|