fix:update vm network
Former-commit-id: 4220ea329aea451d15df4b786bbe3403166e2ba0
This commit is contained in:
parent
4047bc98dd
commit
ce25b1da6b
|
@ -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").Create(&taskModel)
|
||||||
db = tx.Table("task_cloud").Create(&taskVm)
|
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)
|
tf := l.svcCtx.DbEngin.Create(&taskModel)
|
||||||
//if tf.Error != nil {
|
if tf.Error != nil {
|
||||||
// return nil, tf.Error
|
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
|
||||||
|
|
|
@ -36,13 +36,12 @@ type (
|
||||||
|
|
||||||
TaskVm struct {
|
TaskVm struct {
|
||||||
Id int64 `db:"id"` // id
|
Id int64 `db:"id"` // id
|
||||||
ParticipantId int64 `db:"participant_id"` // p端id
|
|
||||||
TaskId int64 `db:"task_id"` // 任务id
|
TaskId int64 `db:"task_id"` // 任务id
|
||||||
Name string `db:"name"` // 虚拟机名称
|
Name string `db:"name"` // 虚拟机名称
|
||||||
AdapterId int64 `db:"adapter_id"` // 适配器id
|
AdapterId int64 `db:"adapter_id"` // 执行任务的适配器id
|
||||||
AdapterName string `db:"adapter_name"` //适配器名称
|
AdapterName string `db:"adapter_name"` // 适配器名称
|
||||||
ClusterId int64 `db:"cluster_id"` //集群id
|
ClusterId int64 `db:"cluster_id"` // 执行任务的集群id
|
||||||
ClusterName string `db:"cluster_name"` //集群名称
|
ClusterName string `db:"cluster_name"` // 集群名称
|
||||||
FlavorRef string `db:"flavor_ref"` // 规格索引
|
FlavorRef string `db:"flavor_ref"` // 规格索引
|
||||||
ImageRef string `db:"image_ref"` // 镜像索引
|
ImageRef string `db:"image_ref"` // 镜像索引
|
||||||
Status string `db:"status"` // 状态
|
Status string `db:"status"` // 状态
|
||||||
|
@ -93,14 +92,14 @@ func (m *defaultTaskVmModel) FindOne(ctx context.Context, id int64) (*TaskVm, er
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultTaskVmModel) Insert(ctx context.Context, data *TaskVm) (sql.Result, error) {
|
func (m *defaultTaskVmModel) Insert(ctx context.Context, data *TaskVm) (sql.Result, error) {
|
||||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, taskVmRowsExpectAutoSet)
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, taskVmRowsExpectAutoSet)
|
||||||
ret, err := m.conn.ExecCtx(ctx, query, data.ParticipantId, data.TaskId, data.Name, data.AdapterId, data.ClusterId, data.FlavorRef, data.ImageRef, data.Status, data.Platform, data.Description, data.AvailabilityZone, data.MinCount, data.Uuid, data.StartTime, data.RunningTime, data.Result, data.DeletedAt)
|
ret, err := m.conn.ExecCtx(ctx, query, data.TaskId, data.Name, data.AdapterId, data.AdapterName, data.ClusterId, data.ClusterName, data.FlavorRef, data.ImageRef, data.Status, data.Platform, data.Description, data.AvailabilityZone, data.MinCount, data.Uuid, data.StartTime, data.RunningTime, data.Result, data.DeletedAt)
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultTaskVmModel) Update(ctx context.Context, data *TaskVm) error {
|
func (m *defaultTaskVmModel) Update(ctx context.Context, data *TaskVm) error {
|
||||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, taskVmRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, taskVmRowsWithPlaceHolder)
|
||||||
_, err := m.conn.ExecCtx(ctx, query, data.ParticipantId, data.TaskId, data.Name, data.AdapterId, data.ClusterId, data.FlavorRef, data.ImageRef, data.Status, data.Platform, data.Description, data.AvailabilityZone, data.MinCount, data.Uuid, data.StartTime, data.RunningTime, data.Result, data.DeletedAt, data.Id)
|
_, err := m.conn.ExecCtx(ctx, query, data.TaskId, data.Name, data.AdapterId, data.AdapterName, data.ClusterId, data.ClusterName, data.FlavorRef, data.ImageRef, data.Status, data.Platform, data.Description, data.AvailabilityZone, data.MinCount, data.Uuid, data.StartTime, data.RunningTime, data.Result, data.DeletedAt, data.Id)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue