提交任务返回任务id
Former-commit-id: b7bfd3191c1a749539bfad66949019c446177c8e
This commit is contained in:
parent
84ec1cbadc
commit
ae89886da2
|
@ -191,7 +191,11 @@ type (
|
|||
metadata interface{} `yaml:"metadata"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
scheduleTaskByYamlResp {
|
||||
TaskId int64 `json:"taskId"`
|
||||
}
|
||||
)
|
||||
type (
|
||||
scheduleTaskReq {
|
||||
Name string `json:"name"`
|
||||
|
@ -470,8 +474,8 @@ type SaveHashcatReq {
|
|||
CrackEstimatedTime string `json:"crackEstimatedTime"` // 预计时间
|
||||
CrackProgress string `json:"crackProgress"` // 进度
|
||||
CrackResult string `json:"crackResult"` // 结果
|
||||
Started string `json:"started"` // 开始时间
|
||||
Stoped string `json:"stoped"` // 结束时间
|
||||
Started string `json:"started"` // 开始时间
|
||||
Stopped string `json:"stopped"` // 结束时间
|
||||
}
|
||||
|
||||
type getHashcatHandlerReq {
|
||||
|
@ -490,8 +494,8 @@ type HashCat {
|
|||
CrackEstimatedTime string `json:"crackEstimatedTime"` // 预计时间
|
||||
CrackProgress string `json:"crackProgress"` // 进度
|
||||
CrackResult string `json:"crackResult"` // 结果
|
||||
Started string `json:"started"` // 开始时间
|
||||
Stoped string `json:"stoped"` // 结束时间
|
||||
Started string `json:"started"` // 开始时间
|
||||
Stopped string `json:"stopped"` // 结束时间
|
||||
}
|
||||
|
||||
type participantListResp {
|
||||
|
|
|
@ -28,7 +28,7 @@ service pcm {
|
|||
get /core/participantList returns (participantListResp)
|
||||
|
||||
@handler scheduleTaskByYamlHandler
|
||||
post /core/scheduleTaskByYaml (scheduleTaskByYamlReq)
|
||||
post /core/scheduleTaskByYaml (scheduleTaskByYamlReq) returns (scheduleTaskByYamlResp)
|
||||
|
||||
@handler deleteTaskHandler
|
||||
delete /core/deleteTask/:id (deleteTaskReq)
|
||||
|
@ -321,9 +321,9 @@ service pcm {
|
|||
|
||||
// Bare Metal
|
||||
@handler ListNodesHandler
|
||||
get /vm/listNodes (ListNodesReq) returns (ListNodesResp)
|
||||
get /vm/listNodes (ListNodesReq) returns (ListNodesResp)
|
||||
@handler CreateNodeHandler
|
||||
post /vm/createNode (CreateNodeReq) returns (CreateNodeResp)
|
||||
post /vm/createNode (CreateNodeReq) returns (CreateNodeResp)
|
||||
@handler DeleteNodeHandler
|
||||
delete /vm/deleteNode (DeleteNodeReq) returns (DeleteNodeResp)
|
||||
@handler ShowNodeDetailsHandler
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"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"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
|
||||
"gitlink.org.cn/jcce-pcm/utils/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ScheduleTaskByYamlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ScheduleTaskByYamlReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
// 解析yaml文件
|
||||
_, fileHeader, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
err = utils.Yaml2struct(fileHeader, &req)
|
||||
if err != nil {
|
||||
result.HttpResult(r, w, nil, err)
|
||||
return
|
||||
}
|
||||
l := core.NewScheduleTaskByYamlLogic(r.Context(), svcCtx)
|
||||
err = l.ScheduleTaskByYaml(&req)
|
||||
result.HttpResult(r, w, nil, err)
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/constants"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
||||
"k8s.io/apimachinery/pkg/util/json"
|
||||
"time"
|
||||
|
||||
"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 ScheduleTaskByYamlLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewScheduleTaskByYamlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScheduleTaskByYamlLogic {
|
||||
return &ScheduleTaskByYamlLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ScheduleTaskByYamlLogic) ScheduleTaskByYaml(req *types.ScheduleTaskByYamlReq) error {
|
||||
|
||||
bytes, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 构建主任务结构体
|
||||
taskModel := models.Task{
|
||||
Status: constants.Saved,
|
||||
Description: req.Description,
|
||||
Name: req.Name,
|
||||
YamlString: string(bytes),
|
||||
CommitTime: time.Now(),
|
||||
}
|
||||
// 保存任务数据到数据库
|
||||
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
// 遍历子任务放入任务队列中
|
||||
for _, task := range req.Tasks {
|
||||
task.TaskId = taskModel.Id
|
||||
// 将任务数据转换成消息体
|
||||
reqMessage, err := json.Marshal(task)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return err
|
||||
}
|
||||
l.svcCtx.RedisClient.Publish(context.Background(), task.TaskType, reqMessage)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -172,6 +172,10 @@ type TaskYaml struct {
|
|||
Metadata interface{} `yaml:"metadata"`
|
||||
}
|
||||
|
||||
type ScheduleTaskByYamlResp struct {
|
||||
TaskId int64 `json:"taskId"`
|
||||
}
|
||||
|
||||
type ScheduleTaskReq struct {
|
||||
Name string `json:"name"`
|
||||
Synergy string `json:"synergy"`
|
||||
|
@ -440,7 +444,7 @@ type SaveHashcatReq struct {
|
|||
CrackProgress string `json:"crackProgress"` // 进度
|
||||
CrackResult string `json:"crackResult"` // 结果
|
||||
Started string `json:"started"` // 开始时间
|
||||
Stoped string `json:"stoped"` // 结束时间
|
||||
Stopped string `json:"stopped"` // 结束时间
|
||||
}
|
||||
|
||||
type GetHashcatHandlerReq struct {
|
||||
|
@ -460,7 +464,7 @@ type HashCat struct {
|
|||
CrackProgress string `json:"crackProgress"` // 进度
|
||||
CrackResult string `json:"crackResult"` // 结果
|
||||
Started string `json:"started"` // 开始时间
|
||||
Stoped string `json:"stoped"` // 结束时间
|
||||
Stopped string `json:"stopped"` // 结束时间
|
||||
}
|
||||
|
||||
type ParticipantListResp struct {
|
||||
|
|
|
@ -22,7 +22,7 @@ type (
|
|||
CrackProgress string `db:"crack_progress"` // 进度
|
||||
CrackResult string `db:"crack_result"` // 结果
|
||||
Started string `db:"started"` // 开始时间
|
||||
Stoped string `db:"started"` // 结束时间
|
||||
Stopped string `db:"stopped"` // 结束时间
|
||||
CreatedBy int64 `db:"created_by"` // 创建人
|
||||
UpdatedBy int64 `db:"updated_by"` // 更新人
|
||||
DeletedFlag int64 `db:"deleted_flag"` // 是否删除(0-否,1-是)
|
||||
|
|
Loading…
Reference in New Issue