Browse Source

提交yaml转struct 等待完成

pull/9/head
zw 2 years ago
parent
commit
f0e1b80e31
6 changed files with 115 additions and 0 deletions
  1. +5
    -0
      adaptor/slurm/slurmCore/api/internal/handler/routes.go
  2. +30
    -0
      adaptor/slurm/slurmCore/api/internal/handler/scheduletaskhandler.go
  3. +33
    -0
      adaptor/slurm/slurmCore/api/internal/logic/scheduletasklogic.go
  4. +11
    -0
      adaptor/slurm/slurmCore/api/internal/types/types.go
  5. +16
    -0
      adaptor/slurm/slurmCore/api/slurmCore.api
  6. +20
    -0
      common/tool/file.go

+ 5
- 0
adaptor/slurm/slurmCore/api/internal/handler/routes.go View File

@@ -22,6 +22,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/listHistoryJob",
Handler: listHistoryJobHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/scheduleTask",
Handler: scheduleTaskHandler(serverCtx),
},
},
)
}

+ 30
- 0
adaptor/slurm/slurmCore/api/internal/handler/scheduletaskhandler.go View File

@@ -0,0 +1,30 @@
package handler

import (
"PCM/adaptor/slurm/slurmCore/api/internal/logic"
"PCM/adaptor/slurm/slurmCore/api/internal/svc"
"PCM/adaptor/slurm/slurmCore/api/internal/types"
"PCM/common/tool"
"github.com/zeromicro/go-zero/rest/httpx"
"net/http"
)

func scheduleTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ScheduleTaskReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewScheduleTaskLogic(r.Context(), svcCtx)
// 解析yaml文件
_, fileHeader, err := r.FormFile("file")
err = tool.Yaml2struct(fileHeader, &req)
resp, err := l.ScheduleTask(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

+ 33
- 0
adaptor/slurm/slurmCore/api/internal/logic/scheduletasklogic.go View File

@@ -0,0 +1,33 @@
package logic

import (
"context"

"PCM/adaptor/slurm/slurmCore/api/internal/svc"
"PCM/adaptor/slurm/slurmCore/api/internal/types"

"github.com/zeromicro/go-zero/core/logx"
)

type ScheduleTaskLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}

func NewScheduleTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScheduleTaskLogic {
return &ScheduleTaskLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}

func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (resp *types.ScheduleTaskResp, err error) {
// todo
switch req.Kind {

}
println(req.Metadata)
return resp, err
}

+ 11
- 0
adaptor/slurm/slurmCore/api/internal/types/types.go View File

@@ -162,3 +162,14 @@ type ListHistoryJobResp struct {
RecordCount int32 `json:"recordCount"`
HistoryJobs []HistoryJob `json:"historyJobs"`
}

type ScheduleTaskReq struct {
Operate string `yaml:"operate"`
Kind string `yaml:"kind"`
Metadata string `yaml:"metadata"`
}

type ScheduleTaskResp struct {
Code int32 `json:"code"`
Msg string `json:"msg"`
}

+ 16
- 0
adaptor/slurm/slurmCore/api/slurmCore.api View File

@@ -176,6 +176,18 @@ type (
}
)

type (
scheduleTaskReq {
Operate string `yaml:"operate"`
Kind string `yaml:"kind"`
Metadata string `yaml:"metadata"`
}
scheduleTaskResp {
Code int32 `json:"code"`
Msg string `json:"msg"`
}
)

service slurmcore-api {
@handler listJobHandler
@@ -183,4 +195,8 @@ service slurmcore-api {
@handler listHistoryJobHandler
get /listHistoryJob (listHistoryJobReq) returns (listHistoryJobResp)
@handler scheduleTaskHandler
post /scheduleTask (scheduleTaskReq) returns (scheduleTaskResp)
}

+ 20
- 0
common/tool/file.go View File

@@ -0,0 +1,20 @@
package tool

import (
"io"
"mime/multipart"
"sigs.k8s.io/yaml"
)

func Yaml2struct(fileHeader *multipart.FileHeader, req interface{}) error {
file, err := fileHeader.Open()
if err != nil {
return err
}
fileByte, err := io.ReadAll(file)
if err != nil {
return err
}
yaml.Unmarshal(fileByte, &req)
return nil
}

Loading…
Cancel
Save