Former-commit-id: 3fda1514b5
pull/161/head
| @@ -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) { | |||
| // todo: add your logic here and delete this line | |||
| /*var ImageRef string | |||
| var FlavorRef string | |||
| var NetworkRef string*/ | |||
| resp = &types.CommitVmTaskResp{} | |||
| tx := l.svcCtx.DbEngin.Begin() | |||
| //Building the main task structure | |||
| @@ -53,25 +50,11 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type | |||
| }() | |||
| //TODO adapter | |||
| 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 | |||
| 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 { | |||
| 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{} | |||
| //TODO 执行策略返回集群跟 Replica | |||
| opt := &option.VmOption{} | |||
| @@ -81,20 +64,17 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| // 3、Return scheduling results | |||
| results, err := l.svcCtx.Scheduler.AssignAndSchedule(vmSchdl) | |||
| if err != nil { | |||
| logx.Errorf("AssignAndSchedule() => execution error: %v", err) | |||
| return nil, err | |||
| } | |||
| rs := (results).([]*schedulers.VmResult) | |||
| var synergyStatus int64 | |||
| if len(rs) > 1 { | |||
| synergyStatus = 1 | |||
| } | |||
| var strategy int64 | |||
| sqlStr := `select t_dict_item.item_value | |||
| from t_dict | |||
| @@ -113,7 +93,7 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type | |||
| SynergyStatus: synergyStatus, | |||
| Strategy: strategy, | |||
| } | |||
| var taskVms models.TaskVm | |||
| //var taskVms models.TaskVm | |||
| var VmObject types.TaskVm | |||
| for _, r := range rs { | |||
| 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) | |||
| //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.StartTime = time.Now().String() | |||
| taskVm.MinCount = req.MinCount | |||
| @@ -168,25 +148,6 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type | |||
| if tx.Error != nil { | |||
| 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(), | |||
| } | |||
| 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) | |||
| if db.Error != nil { | |||
| logx.Errorf("Task creation failure, err: %v", db.Error) | |||
| } | |||
| //db = tx.Table("t_notice").Create(¬iceInfo) | |||
| // 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) | |||
| //if tn.Error != nil { | |||
| // return nil, tn.Error | |||
| @@ -35,19 +35,18 @@ type ( | |||
| } | |||
| TaskVm struct { | |||
| Id int64 `db:"id"` // id | |||
| ParticipantId int64 `db:"participant_id"` // p端id | |||
| TaskId int64 `db:"task_id"` // 任务id | |||
| Name string `db:"name"` // 虚拟机名称 | |||
| AdapterId int64 `db:"adapter_id"` // 适配器id | |||
| AdapterName string `db:"adapter_name"` //适配器名称 | |||
| ClusterId int64 `db:"cluster_id"` //集群id | |||
| ClusterName string `db:"cluster_name"` //集群名称 | |||
| FlavorRef string `db:"flavor_ref"` // 规格索引 | |||
| ImageRef string `db:"image_ref"` // 镜像索引 | |||
| Status string `db:"status"` // 状态 | |||
| Platform string `db:"platform"` // 平台 | |||
| Description string `db:"description"` // 描述 | |||
| Id int64 `db:"id"` // id | |||
| TaskId int64 `db:"task_id"` // 任务id | |||
| Name string `db:"name"` // 虚拟机名称 | |||
| AdapterId int64 `db:"adapter_id"` // 执行任务的适配器id | |||
| AdapterName string `db:"adapter_name"` // 适配器名称 | |||
| ClusterId int64 `db:"cluster_id"` // 执行任务的集群id | |||
| ClusterName string `db:"cluster_name"` // 集群名称 | |||
| FlavorRef string `db:"flavor_ref"` // 规格索引 | |||
| ImageRef string `db:"image_ref"` // 镜像索引 | |||
| Status string `db:"status"` // 状态 | |||
| Platform string `db:"platform"` // 平台 | |||
| Description string `db:"description"` // 描述 | |||
| AvailabilityZone string `db:"availability_zone"` | |||
| MinCount int64 `db:"min_count"` // 数量 | |||
| Uuid string `db:"uuid"` // 网络id | |||
| @@ -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) { | |||
| 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) | |||
| query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, taskVmRowsExpectAutoSet) | |||
| 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 | |||
| } | |||
| func (m *defaultTaskVmModel) Update(ctx context.Context, data *TaskVm) error { | |||
| 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 | |||
| } | |||