Merge pull request '取消任务添加api接口' (#25) from zhangweiii/pcm-hpc:master into master
This commit is contained in:
commit
2271dfabaf
|
@ -16,6 +16,7 @@ func InitRouter() *gin.Engine {
|
||||||
namespace := apiv1.Group("job")
|
namespace := apiv1.Group("job")
|
||||||
namespace.POST("/submit", v1.SubmitJob)
|
namespace.POST("/submit", v1.SubmitJob)
|
||||||
namespace.GET("/info", v1.JobInfo)
|
namespace.GET("/info", v1.JobInfo)
|
||||||
|
namespace.DELETE("/cancel", v1.CancelJob)
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
|
@ -28,6 +28,14 @@ type JobInfoReq struct {
|
||||||
JobId string `json:"jobId" form:"jobId"`
|
JobId string `json:"jobId" form:"jobId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type JobCancelReq struct {
|
||||||
|
Server string `json:"server" form:"server""`
|
||||||
|
Version string `json:"version" form:"version""`
|
||||||
|
Username string `json:"username" form:"username"`
|
||||||
|
Token string `json:"token" form:"token"`
|
||||||
|
JobId string `json:"jobId" form:"jobId"`
|
||||||
|
}
|
||||||
|
|
||||||
type SubmitJobResp struct {
|
type SubmitJobResp struct {
|
||||||
Meta struct {
|
Meta struct {
|
||||||
Plugin struct {
|
Plugin struct {
|
||||||
|
@ -49,6 +57,24 @@ type SubmitJobResp struct {
|
||||||
JobSubmitUserMsg string `json:"job_submit_user_msg"`
|
JobSubmitUserMsg string `json:"job_submit_user_msg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Job struct {
|
||||||
|
Meta struct {
|
||||||
|
Plugin struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"plugin"`
|
||||||
|
Slurm struct {
|
||||||
|
Version struct {
|
||||||
|
Major int `json:"major"`
|
||||||
|
Micro int `json:"micro"`
|
||||||
|
Minor int `json:"minor"`
|
||||||
|
} `json:"version"`
|
||||||
|
Release string `json:"release"`
|
||||||
|
} `json:"Slurm"`
|
||||||
|
} `json:"meta"`
|
||||||
|
Errors []interface{} `json:"errors"`
|
||||||
|
}
|
||||||
|
|
||||||
type JobOptions struct {
|
type JobOptions struct {
|
||||||
Script string `json:"script"`
|
Script string `json:"script"`
|
||||||
Job *JobProperties `json:"job"`
|
Job *JobProperties `json:"job"`
|
||||||
|
@ -136,3 +162,42 @@ func JobInfo(ctx *gin.Context) {
|
||||||
json.Unmarshal(body, &resp)
|
json.Unmarshal(body, &resp)
|
||||||
ResponseData(ctx, &resp)
|
ResponseData(ctx, &resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CancelJob(ctx *gin.Context) {
|
||||||
|
var req JobCancelReq
|
||||||
|
if err := ctx.ShouldBindQuery(&req); err != nil {
|
||||||
|
Response(ctx, http.StatusBadRequest, "invalid request params.", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
url := req.Server + "/slurm/" + req.Version + "/job/" + req.JobId
|
||||||
|
client := &http.Client{}
|
||||||
|
request, err := http.NewRequest("DELETE", url, nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
request.Header.Add("Accept", "*/*")
|
||||||
|
request.Header.Add("Host", req.Server)
|
||||||
|
request.Header.Add("X-SLURM-USER-NAME", req.Username)
|
||||||
|
request.Header.Add("X-SLURM-USER-TOKEN", req.Token)
|
||||||
|
request.Header.Add("Cookie", "X-SLURM-USER-NAME=;X-SLURM-USER-TOKEN=")
|
||||||
|
request.Header.Add("Content-Type", "application/json")
|
||||||
|
|
||||||
|
res, err := client.Do(request)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
Response(ctx, http.StatusInternalServerError, "rest api error.", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var job Job
|
||||||
|
json.Unmarshal(body, &job)
|
||||||
|
ResponseData(ctx, &job)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue