| @@ -199,7 +199,7 @@ type ( | |||||
| TaskId int64 `json:"taskId,optional"` | TaskId int64 `json:"taskId,optional"` | ||||
| TaskType string `json:"taskType,optional"` | TaskType string `json:"taskType,optional"` | ||||
| matchLabels map[string]string `json:"matchLabels"` | matchLabels map[string]string `json:"matchLabels"` | ||||
| serviceName string `json:"serviceName"` | |||||
| participantId string `json:"participantId"` | |||||
| metadata interface{} `json:"metadata"` | metadata interface{} `json:"metadata"` | ||||
| } | } | ||||
| ) | ) | ||||
| @@ -214,7 +214,7 @@ type ( | |||||
| TrainJob { | TrainJob { | ||||
| Name string `json:"name"` | Name string `json:"name"` | ||||
| Status string `json:"status"` | Status string `json:"status"` | ||||
| ServiceName string `json:"serviceName"` | |||||
| ParticipantName string `json:"participantName"` | |||||
| SynergyStatus string `json:"synergyStatus"` | SynergyStatus string `json:"synergyStatus"` | ||||
| Strategy int `json:"strategy"` | Strategy int `json:"strategy"` | ||||
| } | } | ||||
| @@ -231,7 +231,7 @@ type ( | |||||
| Name string `json:"name"` | Name string `json:"name"` | ||||
| Status string `json:"status"` | Status string `json:"status"` | ||||
| Strategy int `json:"strategy"` | Strategy int `json:"strategy"` | ||||
| ServiceName string `json:"serviceName"` | |||||
| ParticipantName string `json:"participantName"` | |||||
| SynergyStatus string `json:"synergyStatus"` | SynergyStatus string `json:"synergyStatus"` | ||||
| } | } | ||||
| ) | ) | ||||
| @@ -2,14 +2,12 @@ package core | |||||
| import ( | import ( | ||||
| "context" | "context" | ||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" | |||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" | |||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" | "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" | ||||
| "gitlink.org.cn/jcce-pcm/utils/enum" | "gitlink.org.cn/jcce-pcm/utils/enum" | ||||
| "gitlink.org.cn/jcce-pcm/utils/tool" | "gitlink.org.cn/jcce-pcm/utils/tool" | ||||
| "k8s.io/apimachinery/pkg/util/json" | "k8s.io/apimachinery/pkg/util/json" | ||||
| "strings" | |||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" | |||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" | |||||
| "github.com/zeromicro/go-zero/core/logx" | "github.com/zeromicro/go-zero/core/logx" | ||||
| ) | ) | ||||
| @@ -68,7 +66,7 @@ func (l *JobTotalLogic) JobTotal() (resp *types.JobTotalResp, err error) { | |||||
| SynergyStatus: "未协同", | SynergyStatus: "未协同", | ||||
| } | } | ||||
| if job.Tasks[0].CenterName != nil { | if job.Tasks[0].CenterName != nil { | ||||
| trainJob.ServiceName = job.Tasks[0].CenterName[0] | |||||
| trainJob.ParticipantName = job.Tasks[0].CenterName[0] | |||||
| } | } | ||||
| resp.TrainJobs = append(resp.TrainJobs, trainJob) | resp.TrainJobs = append(resp.TrainJobs, trainJob) | ||||
| } | } | ||||
| @@ -83,26 +81,18 @@ func (l *JobTotalLogic) JobTotal() (resp *types.JobTotalResp, err error) { | |||||
| return nil, nil | return nil, nil | ||||
| } | } | ||||
| for _, task := range tasks { | for _, task := range tasks { | ||||
| tx := l.svcCtx.DbEngin.Raw("SELECT CONCAT_WS(',',GROUP_CONCAT(DISTINCT h.service_name) ,GROUP_CONCAT(DISTINCT a.service_name) ,GROUP_CONCAT(DISTINCT c.service_name))as service_name from task t left join hpc h on t.id = h.task_id left join cloud c on t.id = c.task_id left join ai a on t.id = a.task_id where t.id = ?", task.Id).Scan(&task.ServiceName) | |||||
| tx := l.svcCtx.DbEngin.Raw("SELECT name from sc_participant_phy_info where id in (SELECT CONCAT_WS(',',GROUP_CONCAT(DISTINCT h.participant_id) ,GROUP_CONCAT(DISTINCT a.participant_id) ,GROUP_CONCAT(DISTINCT c.participant_id))as service_name from task t left join hpc h on t.id = h.task_id left join cloud c on t.id = c.task_id left join ai a on t.id = a.task_id where t.id = ?)", task.Id).Scan(&task.ParticipantName) | |||||
| if tx.Error != nil { | if tx.Error != nil { | ||||
| logx.Error(err) | logx.Error(err) | ||||
| return nil, tx.Error | return nil, tx.Error | ||||
| } | } | ||||
| // 承接方转义 | // 承接方转义 | ||||
| if task.ServiceName != "" { | |||||
| var names []string | |||||
| servicesName := strings.Split(task.ServiceName, ",") | |||||
| for _, name := range servicesName { | |||||
| names = append(names, enum.Partner(name).String()) | |||||
| } | |||||
| task.ServiceName = strings.Join(names, ",") | |||||
| } | |||||
| resp.TrainJobs = append(resp.TrainJobs, types.TrainJob{ | resp.TrainJobs = append(resp.TrainJobs, types.TrainJob{ | ||||
| ServiceName: task.ServiceName, | |||||
| Name: task.Name, | |||||
| Strategy: int(task.Strategy), | |||||
| SynergyStatus: enum.SynergyStatus(task.SynergyStatus).String(), | |||||
| Status: task.Status, | |||||
| ParticipantName: task.ParticipantName, | |||||
| Name: task.Name, | |||||
| Strategy: int(task.Strategy), | |||||
| SynergyStatus: enum.SynergyStatus(task.SynergyStatus).String(), | |||||
| Status: task.Status, | |||||
| }) | }) | ||||
| } | } | ||||
| @@ -2,12 +2,10 @@ package core | |||||
| import ( | import ( | ||||
| "context" | "context" | ||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" | |||||
| "gitlink.org.cn/jcce-pcm/utils/enum" | |||||
| "strings" | |||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" | "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" | ||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" | "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" | ||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" | |||||
| "gitlink.org.cn/jcce-pcm/utils/enum" | |||||
| "github.com/zeromicro/go-zero/core/logx" | "github.com/zeromicro/go-zero/core/logx" | ||||
| ) | ) | ||||
| @@ -40,26 +38,19 @@ func (l *TaskListLogic) TaskList() (resp *types.TaskListResp, err error) { | |||||
| return nil, nil | return nil, nil | ||||
| } | } | ||||
| for _, task := range tasks { | for _, task := range tasks { | ||||
| tx := l.svcCtx.DbEngin.Raw("SELECT CONCAT_WS(',',GROUP_CONCAT(DISTINCT h.service_name) ,GROUP_CONCAT(DISTINCT a.service_name) ,GROUP_CONCAT(DISTINCT c.service_name))as service_name from task t left join hpc h on t.id = h.task_id left join cloud c on t.id = c.task_id left join ai a on t.id = a.task_id where t.id = ?", task.Id).Scan(&task.ServiceName) | |||||
| tx := l.svcCtx.DbEngin.Raw("SELECT name from sc_participant_phy_info where id in (SELECT CONCAT_WS(',',GROUP_CONCAT(DISTINCT h.participant_id) ,GROUP_CONCAT(DISTINCT a.participant_id) ,GROUP_CONCAT(DISTINCT c.participant_id))as service_name from task t left join hpc h on t.id = h.task_id left join cloud c on t.id = c.task_id left join ai a on t.id = a.task_id where t.id = ?)", task.Id).Scan(&task.ParticipantName) | |||||
| if tx.Error != nil { | if tx.Error != nil { | ||||
| logx.Error(err) | logx.Error(err) | ||||
| return nil, tx.Error | return nil, tx.Error | ||||
| } | } | ||||
| // 承接方转义 | // 承接方转义 | ||||
| if task.ServiceName != "" { | |||||
| var names []string | |||||
| servicesName := strings.Split(task.ServiceName, ",") | |||||
| for _, name := range servicesName { | |||||
| names = append(names, enum.Partner(name).String()) | |||||
| } | |||||
| task.ServiceName = strings.Join(names, ",") | |||||
| } | |||||
| resp.Tasks = append(resp.Tasks, types.Task{ | resp.Tasks = append(resp.Tasks, types.Task{ | ||||
| ServiceName: task.ServiceName, | |||||
| Name: task.Name, | |||||
| Strategy: int(task.Strategy), | |||||
| SynergyStatus: enum.SynergyStatus(task.SynergyStatus).String(), | |||||
| Status: task.Status, | |||||
| ParticipantName: task.ParticipantName, | |||||
| Name: task.Name, | |||||
| Strategy: int(task.Strategy), | |||||
| SynergyStatus: enum.SynergyStatus(task.SynergyStatus).String(), | |||||
| Status: task.Status, | |||||
| }) | }) | ||||
| } | } | ||||
| @@ -3,6 +3,7 @@ package kq | |||||
| import ( | import ( | ||||
| "context" | "context" | ||||
| "encoding/json" | "encoding/json" | ||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/pkg/scheduler" | |||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" | "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" | ||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" | "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" | ||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" | "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" | ||||
| @@ -29,10 +30,16 @@ func (l *ScheduleAiMq) Consume(_, val string) error { | |||||
| // 接受消息 | // 接受消息 | ||||
| var task *types.TaskInfo | var task *types.TaskInfo | ||||
| json.Unmarshal([]byte(val), &task) | json.Unmarshal([]byte(val), &task) | ||||
| participantId, err := scheduler.MatchLabels(l.svcCtx.DbEngin, task) | |||||
| if err != nil { | |||||
| return err | |||||
| } | |||||
| ai := model.Ai{ | ai := model.Ai{ | ||||
| TaskId: task.TaskId, | |||||
| Status: "Saved", | |||||
| YamlString: val, | |||||
| ParticipantId: participantId[0], | |||||
| TaskId: task.TaskId, | |||||
| Status: "Saved", | |||||
| YamlString: val, | |||||
| } | } | ||||
| tool.Convert(task.Metadata, &ai) | tool.Convert(task.Metadata, &ai) | ||||
| // 存储数据 | // 存储数据 | ||||
| @@ -4,6 +4,7 @@ import ( | |||||
| "context" | "context" | ||||
| "encoding/json" | "encoding/json" | ||||
| "github.com/zeromicro/go-zero/core/logx" | "github.com/zeromicro/go-zero/core/logx" | ||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/pkg/scheduler" | |||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" | "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" | ||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" | "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" | ||||
| "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" | "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" | ||||
| @@ -30,11 +31,15 @@ func (l *ScheduleHpcMq) Consume(_, val string) error { | |||||
| // 接受消息 | // 接受消息 | ||||
| var task *types.TaskInfo | var task *types.TaskInfo | ||||
| json.Unmarshal([]byte(val), &task) | json.Unmarshal([]byte(val), &task) | ||||
| participantId, err := scheduler.MatchLabels(l.svcCtx.DbEngin, task) | |||||
| if err != nil { | |||||
| return err | |||||
| } | |||||
| hpc := model.Hpc{ | hpc := model.Hpc{ | ||||
| TaskId: task.TaskId, | |||||
| Status: "Saved", | |||||
| ServiceName: task.TaskType, | |||||
| YamlString: val, | |||||
| TaskId: task.TaskId, | |||||
| Status: "Saved", | |||||
| ParticipantId: participantId[0], | |||||
| YamlString: val, | |||||
| } | } | ||||
| tool.Convert(task.Metadata, &hpc) | tool.Convert(task.Metadata, &hpc) | ||||
| // 存储数据 | // 存储数据 | ||||
| @@ -176,11 +176,11 @@ type ScheduleTaskReq struct { | |||||
| } | } | ||||
| type TaskInfo struct { | type TaskInfo struct { | ||||
| TaskId int64 `json:"taskId,optional"` | |||||
| TaskType string `json:"taskType,optional"` | |||||
| MatchLabels map[string]string `json:"matchLabels"` | |||||
| ServiceName string `json:"serviceName"` | |||||
| Metadata interface{} `json:"metadata"` | |||||
| TaskId int64 `json:"taskId,optional"` | |||||
| TaskType string `json:"taskType,optional"` | |||||
| MatchLabels map[string]string `json:"matchLabels"` | |||||
| ParticipantId string `json:"participantId"` | |||||
| Metadata interface{} `json:"metadata"` | |||||
| } | } | ||||
| type JobTotalResp struct { | type JobTotalResp struct { | ||||
| @@ -191,11 +191,11 @@ type JobTotalResp struct { | |||||
| } | } | ||||
| type TrainJob struct { | type TrainJob struct { | ||||
| Name string `json:"name"` | |||||
| Status string `json:"status"` | |||||
| ServiceName string `json:"serviceName"` | |||||
| SynergyStatus string `json:"synergyStatus"` | |||||
| Strategy int `json:"strategy"` | |||||
| Name string `json:"name"` | |||||
| Status string `json:"status"` | |||||
| ParticipantName string `json:"participantName"` | |||||
| SynergyStatus string `json:"synergyStatus"` | |||||
| Strategy int `json:"strategy"` | |||||
| } | } | ||||
| type TaskListResp struct { | type TaskListResp struct { | ||||
| @@ -206,11 +206,11 @@ type TaskListResp struct { | |||||
| } | } | ||||
| type Task struct { | type Task struct { | ||||
| Name string `json:"name"` | |||||
| Status string `json:"status"` | |||||
| Strategy int `json:"strategy"` | |||||
| ServiceName string `json:"serviceName"` | |||||
| SynergyStatus string `json:"synergyStatus"` | |||||
| Name string `json:"name"` | |||||
| Status string `json:"status"` | |||||
| Strategy int `json:"strategy"` | |||||
| ParticipantName string `json:"participantName"` | |||||
| SynergyStatus string `json:"synergyStatus"` | |||||
| } | } | ||||
| type ListCenterResp struct { | type ListCenterResp struct { | ||||
| @@ -1,12 +1,5 @@ | |||||
| package model | package model | ||||
| import ( | |||||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||||
| ) | |||||
| var _ AiModel = (*customAiModel)(nil) | |||||
| type ( | type ( | ||||
| // AiModel is an interface to be customized, add more methods here, | // AiModel is an interface to be customized, add more methods here, | ||||
| // and implement the added methods in customAiModel. | // and implement the added methods in customAiModel. | ||||
| @@ -18,10 +11,3 @@ type ( | |||||
| *defaultAiModel | *defaultAiModel | ||||
| } | } | ||||
| ) | ) | ||||
| // NewAiModel returns a model for the database table. | |||||
| func NewAiModel(conn sqlx.SqlConn, c cache.CacheConf) AiModel { | |||||
| return &customAiModel{ | |||||
| defaultAiModel: newAiModel(conn), | |||||
| } | |||||
| } | |||||
| @@ -49,7 +49,6 @@ type ( | |||||
| UpdatedBy int64 `db:"updated_by"` // 更新人 | UpdatedBy int64 `db:"updated_by"` // 更新人 | ||||
| UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间 | UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间 | ||||
| DeletedFlag int64 `db:"deleted_flag"` // 是否删除(0-否,1-是) | DeletedFlag int64 `db:"deleted_flag"` // 是否删除(0-否,1-是) | ||||
| ServiceName string `db:"service_name"` | |||||
| Result string `db:"result"` | Result string `db:"result"` | ||||
| YamlString string `db:"yaml_string"` | YamlString string `db:"yaml_string"` | ||||
| JobId string `db:"job_id"` | JobId string `db:"job_id"` | ||||
| @@ -102,18 +101,6 @@ func (m *defaultAiModel) FindOneByServiceNameProjectIdName(ctx context.Context, | |||||
| } | } | ||||
| } | } | ||||
| func (m *defaultAiModel) Insert(ctx context.Context, data *Ai) (sql.Result, error) { | |||||
| query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, aiRowsExpectAutoSet) | |||||
| ret, err := m.conn.ExecCtx(ctx, query, data.TaskId, data.ProjectId, data.Name, data.Status, data.StartTime, data.RunningTime, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.DeletedFlag, data.ServiceName, data.Result, data.YamlString) | |||||
| return ret, err | |||||
| } | |||||
| func (m *defaultAiModel) Update(ctx context.Context, newData *Ai) error { | |||||
| query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, aiRowsWithPlaceHolder) | |||||
| _, err := m.conn.ExecCtx(ctx, query, newData.TaskId, newData.ProjectId, newData.Name, newData.Status, newData.StartTime, newData.RunningTime, newData.CreatedBy, newData.CreatedTime, newData.UpdatedBy, newData.UpdatedTime, newData.DeletedFlag, newData.ServiceName, newData.Result, newData.YamlString, newData.Id) | |||||
| return err | |||||
| } | |||||
| func (m *defaultAiModel) tableName() string { | func (m *defaultAiModel) tableName() string { | ||||
| return m.table | return m.table | ||||
| } | } | ||||
| @@ -1,12 +1,5 @@ | |||||
| package model | package model | ||||
| import ( | |||||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||||
| ) | |||||
| var _ HpcModel = (*customHpcModel)(nil) | |||||
| type ( | type ( | ||||
| // HpcModel is an interface to be customized, add more methods here, | // HpcModel is an interface to be customized, add more methods here, | ||||
| // and implement the added methods in customHpcModel. | // and implement the added methods in customHpcModel. | ||||
| @@ -18,10 +11,3 @@ type ( | |||||
| *defaultHpcModel | *defaultHpcModel | ||||
| } | } | ||||
| ) | ) | ||||
| // NewHpcModel returns a model for the database table. | |||||
| func NewHpcModel(conn sqlx.SqlConn, c cache.CacheConf) HpcModel { | |||||
| return &customHpcModel{ | |||||
| defaultHpcModel: newHpcModel(conn), | |||||
| } | |||||
| } | |||||
| @@ -40,7 +40,6 @@ type ( | |||||
| TaskId int64 `db:"task_id"` // 任务id | TaskId int64 `db:"task_id"` // 任务id | ||||
| ParticipantId int64 `db:"participant_id"` // 集群静态信息id | ParticipantId int64 `db:"participant_id"` // 集群静态信息id | ||||
| JobId string `db:"job_id"` // 作业id | JobId string `db:"job_id"` // 作业id | ||||
| ServiceName string `db:"service_name"` // 服务名称 | |||||
| Name string `db:"name"` // 名称 | Name string `db:"name"` // 名称 | ||||
| Status string `db:"status"` // 状态 | Status string `db:"status"` // 状态 | ||||
| StartTime string `db:"start_time"` // 开始时间 | StartTime string `db:"start_time"` // 开始时间 | ||||
| @@ -109,18 +108,6 @@ func (m *defaultHpcModel) FindOneByServiceNameName(ctx context.Context, serviceN | |||||
| } | } | ||||
| } | } | ||||
| func (m *defaultHpcModel) Insert(ctx context.Context, data *Hpc) (sql.Result, error) { | |||||
| query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, hpcRowsExpectAutoSet) | |||||
| ret, err := m.conn.ExecCtx(ctx, query, data.TaskId, data.JobId, data.ServiceName, data.Name, data.Status, data.StartTime, data.RunningTime, data.CardCount, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.DeletedFlag, data.WorkDir, data.WallTime, data.Result, data.YamlString) | |||||
| return ret, err | |||||
| } | |||||
| func (m *defaultHpcModel) Update(ctx context.Context, newData *Hpc) error { | |||||
| query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, hpcRowsWithPlaceHolder) | |||||
| _, err := m.conn.ExecCtx(ctx, query, newData.TaskId, newData.JobId, newData.ServiceName, newData.Name, newData.Status, newData.StartTime, newData.RunningTime, newData.CardCount, newData.CreatedBy, newData.CreatedTime, newData.UpdatedBy, newData.UpdatedTime, newData.DeletedFlag, newData.WorkDir, newData.WallTime, newData.Result, newData.YamlString, newData.Id) | |||||
| return err | |||||
| } | |||||
| func (m *defaultHpcModel) tableName() string { | func (m *defaultHpcModel) tableName() string { | ||||
| return m.table | return m.table | ||||
| } | } | ||||
| @@ -1,12 +1,5 @@ | |||||
| package model | package model | ||||
| import ( | |||||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||||
| ) | |||||
| var _ TaskModel = (*customTaskModel)(nil) | |||||
| type ( | type ( | ||||
| // TaskModel is an interface to be customized, add more methods here, | // TaskModel is an interface to be customized, add more methods here, | ||||
| // and implement the added methods in customTaskModel. | // and implement the added methods in customTaskModel. | ||||
| @@ -18,10 +11,3 @@ type ( | |||||
| *defaultTaskModel | *defaultTaskModel | ||||
| } | } | ||||
| ) | ) | ||||
| // NewTaskModel returns a model for the database table. | |||||
| func NewTaskModel(conn sqlx.SqlConn, c cache.CacheConf) TaskModel { | |||||
| return &customTaskModel{ | |||||
| defaultTaskModel: newTaskModel(conn), | |||||
| } | |||||
| } | |||||
| @@ -5,12 +5,10 @@ package model | |||||
| import ( | import ( | ||||
| "context" | "context" | ||||
| "database/sql" | "database/sql" | ||||
| "fmt" | |||||
| "strings" | "strings" | ||||
| "time" | "time" | ||||
| "github.com/zeromicro/go-zero/core/stores/builder" | "github.com/zeromicro/go-zero/core/stores/builder" | ||||
| "github.com/zeromicro/go-zero/core/stores/sqlc" | |||||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | "github.com/zeromicro/go-zero/core/stores/sqlx" | ||||
| "github.com/zeromicro/go-zero/core/stringx" | "github.com/zeromicro/go-zero/core/stringx" | ||||
| ) | ) | ||||
| @@ -36,23 +34,23 @@ type ( | |||||
| } | } | ||||
| Task struct { | Task struct { | ||||
| Id int64 `db:"id"` // id | |||||
| Name string `db:"name"` // 作业名称 | |||||
| Description string `db:"description"` // 作业描述 | |||||
| Status string `db:"status"` // 作业状态 | |||||
| Strategy int64 `db:"strategy"` // 策略 | |||||
| SynergyStatus int64 `db:"synergy_status"` // 协同状态(0-未协同、1-已协同) | |||||
| StartTime time.Time `db:"start_time"` // 开始运行时间 | |||||
| EndTime string `db:"end_time"` // 结束运行时间 | |||||
| RunningTime int64 `db:"running_time"` // 已运行时间(单位秒) | |||||
| YamlString string `db:"yaml_string"` | |||||
| Result string `db:"result"` // 作业结果 | |||||
| CreatedBy int64 `db:"created_by"` // 创建人 | |||||
| CreatedTime time.Time `db:"created_time"` // 创建时间 | |||||
| UpdatedBy int64 `db:"updated_by"` // 更新人 | |||||
| UpdatedTime time.Time `db:"updated_time"` // 更新时间 | |||||
| DeletedFlag int64 `db:"deleted_flag"` // 是否删除(0-否,1-是) | |||||
| ServiceName string `db:"service_name"` | |||||
| Id int64 `db:"id"` // id | |||||
| Name string `db:"name"` // 作业名称 | |||||
| Description string `db:"description"` // 作业描述 | |||||
| Status string `db:"status"` // 作业状态 | |||||
| Strategy int64 `db:"strategy"` // 策略 | |||||
| SynergyStatus int64 `db:"synergy_status"` // 协同状态(0-未协同、1-已协同) | |||||
| StartTime time.Time `db:"start_time"` // 开始运行时间 | |||||
| EndTime string `db:"end_time"` // 结束运行时间 | |||||
| RunningTime int64 `db:"running_time"` // 已运行时间(单位秒) | |||||
| YamlString string `db:"yaml_string"` | |||||
| Result string `db:"result"` // 作业结果 | |||||
| CreatedBy int64 `db:"created_by"` // 创建人 | |||||
| CreatedTime time.Time `db:"created_time"` // 创建时间 | |||||
| UpdatedBy int64 `db:"updated_by"` // 更新人 | |||||
| UpdatedTime time.Time `db:"updated_time"` // 更新时间 | |||||
| DeletedFlag int64 `db:"deleted_flag"` // 是否删除(0-否,1-是) | |||||
| ParticipantName string `db:"participant_name"` | |||||
| } | } | ||||
| ) | ) | ||||
| @@ -63,38 +61,6 @@ func newTaskModel(conn sqlx.SqlConn) *defaultTaskModel { | |||||
| } | } | ||||
| } | } | ||||
| func (m *defaultTaskModel) Delete(ctx context.Context, id int64) error { | |||||
| query := fmt.Sprintf("delete from %s where `id` = ?", m.table) | |||||
| _, err := m.conn.ExecCtx(ctx, query, id) | |||||
| return err | |||||
| } | |||||
| func (m *defaultTaskModel) FindOne(ctx context.Context, id int64) (*Task, error) { | |||||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", taskRows, m.table) | |||||
| var resp Task | |||||
| err := m.conn.QueryRowCtx(ctx, &resp, query, id) | |||||
| switch err { | |||||
| case nil: | |||||
| return &resp, nil | |||||
| case sqlc.ErrNotFound: | |||||
| return nil, ErrNotFound | |||||
| default: | |||||
| return nil, err | |||||
| } | |||||
| } | |||||
| func (m *defaultTaskModel) Insert(ctx context.Context, data *Task) (sql.Result, error) { | |||||
| query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, taskRowsExpectAutoSet) | |||||
| ret, err := m.conn.ExecCtx(ctx, query, data.Name, data.Description, data.Status, data.Strategy, data.SynergyStatus, data.StartTime, data.EndTime, data.RunningTime, data.YamlString, data.Result, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.DeletedFlag, data.ServiceName) | |||||
| return ret, err | |||||
| } | |||||
| func (m *defaultTaskModel) Update(ctx context.Context, data *Task) error { | |||||
| query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, taskRowsWithPlaceHolder) | |||||
| _, err := m.conn.ExecCtx(ctx, query, data.Name, data.Description, data.Status, data.Strategy, data.SynergyStatus, data.StartTime, data.EndTime, data.RunningTime, data.YamlString, data.Result, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.DeletedFlag, data.ServiceName, data.Id) | |||||
| return err | |||||
| } | |||||
| func (m *defaultTaskModel) tableName() string { | func (m *defaultTaskModel) tableName() string { | ||||
| return m.table | return m.table | ||||
| } | } | ||||
| @@ -31,7 +31,7 @@ func (l *InfoListLogic) InfoList(in *pcmCore.InfoListReq) (*pcmCore.InfoListResp | |||||
| switch in.Kind { | switch in.Kind { | ||||
| case "hpc": | case "hpc": | ||||
| var hpcModelList []model.Hpc | var hpcModelList []model.Hpc | ||||
| tx := l.svcCtx.DbEngin.Where("service_name = ? AND status NOT IN ?", in.ParticipantId, []string{"Succeed", "Completed"}).Find(&hpcModelList) | |||||
| tx := l.svcCtx.DbEngin.Where("participant_id = ? AND status NOT IN ?", in.ParticipantId, []string{"Succeed", "Completed"}).Find(&hpcModelList) | |||||
| if tx.Error != nil { | if tx.Error != nil { | ||||
| return nil, tx.Error | return nil, tx.Error | ||||
| } | } | ||||
| @@ -40,7 +40,7 @@ func (l *InfoListLogic) InfoList(in *pcmCore.InfoListReq) (*pcmCore.InfoListResp | |||||
| result.HpcInfoList = hpcInfoList | result.HpcInfoList = hpcInfoList | ||||
| case "cloud": | case "cloud": | ||||
| var cloudModelList []model.Cloud | var cloudModelList []model.Cloud | ||||
| tx := l.svcCtx.DbEngin.Where("service_name = ? AND status NOT IN ?", in.ParticipantId, []string{"Succeed", "Completed"}).Find(&cloudModelList) | |||||
| tx := l.svcCtx.DbEngin.Where("participant_id = ? AND status NOT IN ?", in.ParticipantId, []string{"Succeed", "Completed"}).Find(&cloudModelList) | |||||
| if tx.Error != nil { | if tx.Error != nil { | ||||
| return nil, tx.Error | return nil, tx.Error | ||||
| } | } | ||||
| @@ -49,7 +49,7 @@ func (l *InfoListLogic) InfoList(in *pcmCore.InfoListReq) (*pcmCore.InfoListResp | |||||
| result.CloudInfoList = cloudInfoList | result.CloudInfoList = cloudInfoList | ||||
| case "ai": | case "ai": | ||||
| var aiModelList []model.Ai | var aiModelList []model.Ai | ||||
| tx := l.svcCtx.DbEngin.Where("service_name = ? AND status NOT IN ?", in.ParticipantId, []string{"Succeed", "Completed"}).Find(&aiModelList) | |||||
| tx := l.svcCtx.DbEngin.Where("participant_id = ? AND status NOT IN ?", in.ParticipantId, []string{"Succeed", "Completed"}).Find(&aiModelList) | |||||
| if tx.Error != nil { | if tx.Error != nil { | ||||
| return nil, tx.Error | return nil, tx.Error | ||||
| } | } | ||||