goctl生成代码

Former-commit-id: ac8a60ae04326314ea2b61e1135d37adbd40080d
This commit is contained in:
zhangwei 2023-09-15 10:04:08 +08:00
parent bd7b0cee71
commit a91b93ad73
11 changed files with 246 additions and 22 deletions

View File

@ -170,6 +170,10 @@ type (
} }
) )
type deleteTaskReq {
Id int64 `path:"id"`
}
type ( type (
scheduleTaskByYamlReq { scheduleTaskByYamlReq {

View File

@ -24,13 +24,15 @@ info(
group : core group : core
) )
service pcm { service pcm {
@handler participantListHandler @handler participantListHandler
get /core/participantList returns (participantListResp) get /core/participantList returns (participantListResp)
@handler scheduleTaskByYamlHandler @handler scheduleTaskByYamlHandler
post /core/scheduleTaskByYaml (scheduleTaskByYamlReq) post /core/scheduleTaskByYaml (scheduleTaskByYamlReq)
@handler deleteTaskHandler
delete /core/deleteTask/:id (deleteTaskReq)
@handler scheduleTaskHandler @handler scheduleTaskHandler
post /core/scheduleTask (scheduleTaskReq) post /core/scheduleTask (scheduleTaskReq)

View File

@ -0,0 +1,25 @@
package core
import (
"gitlink.org.cn/jcce-pcm/utils/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/core"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
)
func DeleteTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteTaskReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := core.NewDeleteTaskLogic(r.Context(), svcCtx)
err := l.DeleteTask(&req)
result.HttpResult(r, w, nil, err)
}
}

View File

@ -30,6 +30,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/core/scheduleTaskByYaml", Path: "/core/scheduleTaskByYaml",
Handler: core.ScheduleTaskByYamlHandler(serverCtx), Handler: core.ScheduleTaskByYamlHandler(serverCtx),
}, },
{
Method: http.MethodDelete,
Path: "/core/deleteTask/:id",
Handler: core.DeleteTaskHandler(serverCtx),
},
{ {
Method: http.MethodPost, Method: http.MethodPost,
Path: "/core/scheduleTask", Path: "/core/scheduleTask",
@ -474,22 +479,22 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
}, },
{ {
Method: http.MethodDelete, Method: http.MethodDelete,
Path: "/storelink/deleteImageList", Path: "/storelink/deleteImage",
Handler: storelink.DeleteLinkImageHandler(serverCtx), Handler: storelink.DeleteLinkImageHandler(serverCtx),
}, },
{ {
Method: http.MethodPost, Method: http.MethodPost,
Path: "/storelink/submitLinkTask", Path: "/storelink/submitTask",
Handler: storelink.SubmitLinkTaskHandler(serverCtx), Handler: storelink.SubmitLinkTaskHandler(serverCtx),
}, },
{ {
Method: http.MethodGet, Method: http.MethodGet,
Path: "/storelink/getLinkTask", Path: "/storelink/getTask",
Handler: storelink.GetLinkTaskHandler(serverCtx), Handler: storelink.GetLinkTaskHandler(serverCtx),
}, },
{ {
Method: http.MethodDelete, Method: http.MethodDelete,
Path: "/storelink/deleteLinkTask", Path: "/storelink/deleteTask",
Handler: storelink.DeleteLinkTaskHandler(serverCtx), Handler: storelink.DeleteLinkTaskHandler(serverCtx),
}, },
}, },

View File

@ -0,0 +1,34 @@
package core
import (
"context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/model"
"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"
)
type DeleteTaskLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteTaskLogic {
return &DeleteTaskLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteTaskLogic) DeleteTask(req *types.DeleteTaskReq) error {
// todo: add your logic here and delete this line
tx := l.svcCtx.DbEngin.Delete(&model.Task{}, req.Id)
if tx.Error != nil {
return tx.Error
}
return nil
}

View File

@ -0,0 +1,65 @@
package fifo
const (
ADD = "add"
UPDATE = "update"
DELETE = "delete"
RETRY = "retry"
)
type Data struct {
Event string
TaskType string
Data interface{}
}
type IData interface {
}
type Cloud struct {
Id int64 `db:"id"` // id
TaskId int64 `db:"task_id"` // 任务id
ParticipantId int64 `db:"participant_id"` // 集群静态信息id
ApiVersion string `db:"api_version"` //api版本
Name string `db:"name"` // 名称
Namespace string `db:"namespace"` // 命名空间
Kind string `db:"kind"` // 种类
Status string `db:"status"` // 状态
StartTime string `db:"start_time"` // 开始时间
RunningTime int64 `db:"running_time"` // 运行时长
YamlString string `db:"yaml_string"`
Result string `db:"result"` // 运行结果
}
type Hpc struct {
Id int64 `db:"id"` // id
TaskId int64 `db:"task_id"` // 任务id
ParticipantId int64 `db:"participant_id"` // 集群静态信息id
JobId string `db:"job_id"` // 作业id
Name string `db:"name"` // 名称
Status string `db:"status"` // 状态
StartTime string `db:"start_time"` // 开始时间
RunningTime int64 `db:"running_time"` // 运行时间
CardCount int64 `db:"card_count"` // 卡数
WorkDir string `db:"work_dir"`
WallTime string `db:"wall_time"`
Result string `db:"result"`
YamlString string `db:"yaml_string"`
CmdScript string `db:"cmd_script"`
//DerivedEs string `db:"derived_es"`
//Cluster string `db:"cluster"`
//BlockId string `db:"block_id"`
//AllocNodes uint32 `db:"alloc_nodes"`
//AllocCpu uint32 `db:"alloc_cpu"`
//Version string `db:"version"`
//Account string `db:"account"`
//ExitCode uint32 `db:"exit_code"`
//AssocId uint32 `db:"assoc_id"`
AppType string `db:"app_type"`
AppName string `db:"app_name"`
Queue string `db:"queue"`
SubmitType string `db:"submit_type"`
NNode string `db:"n_node"`
StdOutFile string `db:"std_out_file"`
StdErrFile string `db:"std_err_file"`
}

View File

@ -0,0 +1,31 @@
package fifo
import (
"sync"
)
type Queue struct {
DataList []*IData
mutex sync.Mutex
ResourceType string
}
func (q *Queue) Push(data IData) {
q.mutex.Lock()
defer q.mutex.Unlock()
q.DataList = append(q.DataList, &data)
}
func (q *Queue) Pop() IData {
q.mutex.Lock()
defer q.mutex.Unlock()
if len(q.DataList) <= 0 {
return nil
}
var data = q.DataList[0]
q.DataList = q.DataList[1:]
return data
}

View File

@ -0,0 +1,57 @@
package fifo
import "strings"
const (
CLOUD string = "Cloud"
AI string = "Ai"
HPC string = "Hpc"
)
type TaskFIFO struct {
Queues []*Queue
}
// NewChannel 初始化队列
func NewChannel() *TaskFIFO {
channel := TaskFIFO{
Queues: []*Queue{
{
ResourceType: CLOUD,
},
{
ResourceType: AI,
},
{
ResourceType: HPC,
},
},
}
return &channel
}
// SelectQueue 根据资源类型查询队列数组
func (c *TaskFIFO) SelectQueue(resourceType string) *Queue {
for _, queue := range c.Queues {
if strings.EqualFold(queue.ResourceType, resourceType) {
return queue
}
}
return nil
}
func main() {
channel := NewChannel()
cloudQueue := channel.SelectQueue("cloud")
dataList := []IData{
&Data{
TaskType: "cloud",
Data: &Cloud{}},
}
cloudQueue.Push(&dataList)
println(len(dataList))
}

View File

@ -152,6 +152,10 @@ type Region struct {
RunningJobs int64 `json:"runningJobs"` RunningJobs int64 `json:"runningJobs"`
} }
type DeleteTaskReq struct {
Id int64 `path:"id"`
}
type ScheduleTaskByYamlReq struct { type ScheduleTaskByYamlReq struct {
Name string `yaml:"name"` Name string `yaml:"name"`
Synergy string `yaml:"synergy"` Synergy string `yaml:"synergy"`

View File

@ -34,23 +34,19 @@ type (
} }
Cloud struct { Cloud struct {
Id int64 `db:"id"` // id Id int64 `db:"id"` // id
TaskId int64 `db:"task_id"` // 任务id TaskId int64 `db:"task_id"` // 任务id
ParticipantId int64 `db:"participant_id"` // 集群静态信息id ParticipantId int64 `db:"participant_id"` // 集群静态信息id
ApiVersion string `db:"api_version"` //api版本 ApiVersion string `db:"api_version"` //api版本
Name string `db:"name"` // 名称 Name string `db:"name"` // 名称
Namespace string `db:"namespace"` // 命名空间 Namespace string `db:"namespace"` // 命名空间
Kind string `db:"kind"` // 种类 Kind string `db:"kind"` // 种类
Status string `db:"status"` // 状态 Status string `db:"status"` // 状态
StartTime string `db:"start_time"` // 开始时间 StartTime string `db:"start_time"` // 开始时间
RunningTime int64 `db:"running_time"` // 运行时长 RunningTime int64 `db:"running_time"` // 运行时长
CreatedBy int64 `db:"created_by"` // 创建人 DeletedFlag int64 `db:"deleted_flag"` // 是否删除0-否1-是)
CreatedTime sql.NullTime `db:"created_time"` // 创建时间 YamlString string `db:"yaml_string"`
UpdatedBy int64 `db:"updated_by"` // 更新人 Result string `db:"result"` // 运行结果
UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间
DeletedFlag int64 `db:"deleted_flag"` // 是否删除0-否1-是)
YamlString string `db:"yaml_string"`
Result string `db:"result"` // 运行结果
} }
) )

View File

@ -45,6 +45,7 @@ type (
RunningTime int64 `db:"running_time"` // 已运行时间(单位秒) RunningTime int64 `db:"running_time"` // 已运行时间(单位秒)
YamlString string `db:"yaml_string"` YamlString string `db:"yaml_string"`
Result string `db:"result"` // 作业结果 Result string `db:"result"` // 作业结果
Deleted_flag int64 `gorm:"softDelete:flag"`
} }
) )