| @@ -8,6 +8,7 @@ import ( | |||||
| "context" | "context" | ||||
| "github.com/jinzhu/copier" | "github.com/jinzhu/copier" | ||||
| "github.com/pkg/errors" | "github.com/pkg/errors" | ||||
| "strconv" | |||||
| "PCM/adaptor/slurm/slurmCore/api/internal/svc" | "PCM/adaptor/slurm/slurmCore/api/internal/svc" | ||||
| "PCM/adaptor/slurm/slurmCore/api/internal/types" | "PCM/adaptor/slurm/slurmCore/api/internal/types" | ||||
| @@ -57,9 +58,9 @@ func (l *SubmitJobLogic) SubmitJob(req *types.SubmitJobReq) (resp *types.SubmitJ | |||||
| return nil, errors.Wrapf(xerr.NewErrMsg("Failed to submit job to Tianhe"), "Failed to submit job to Tianhe err : %v ,req:%+v", err, req) | return nil, errors.Wrapf(xerr.NewErrMsg("Failed to submit job to Tianhe"), "Failed to submit job to Tianhe err : %v ,req:%+v", err, req) | ||||
| } | } | ||||
| coreResp.Msg = string(tianheResp.SubmitResponseMsg[0].ErrorCode) | |||||
| //coreResp.Code = tianheResp.SubmitResponseMsg[0].ErrorCode | |||||
| //coreResp.Data = tianheResp.SubmitResponseMsg[0].JobId | |||||
| coreResp.Msg = "success" | |||||
| coreResp.Code = strconv.Itoa(int(tianheResp.SubmitResponseMsg[0].ErrorCode)) | |||||
| coreResp.Data = strconv.Itoa(int(tianheResp.SubmitResponseMsg[0].JobId)) | |||||
| } | } | ||||
| return coreResp, nil | return coreResp, nil | ||||
| @@ -266,12 +266,9 @@ type SubmitJobReq struct { | |||||
| } | } | ||||
| type SubmitJobResp struct { | type SubmitJobResp struct { | ||||
| Job_id int32 `json:"job_id"` | |||||
| Step_id int32 `json:"step_id"` | |||||
| Error_code int32 `json:"error_code"` | |||||
| Code string `json:"code"` | |||||
| Msg string `json:"msg"` | |||||
| Data string `json:"data"` | |||||
| Code string `json:"code"` //Error_code 返回码 in Tianhe | |||||
| Msg string `json:"msg"` | |||||
| Data string `json:"data"` //Job_id 作业id in Tianhe | |||||
| } | } | ||||
| type MapAppJobInfo struct { | type MapAppJobInfo struct { | ||||
| @@ -190,11 +190,14 @@ type ( | |||||
| type ( | type ( | ||||
| submitJobReq { | submitJobReq { | ||||
| SlurmVersion string `json:"slurmVersion"` | |||||
| SlurmVersion string `json:"slurmVersion"` | |||||
| /****************parmas from shuguang********************/ | |||||
| Apptype string `json:"apptype"` | Apptype string `json:"apptype"` | ||||
| Appname string `json:"appname"` | Appname string `json:"appname"` | ||||
| StrJobManagerID int64 `json:"strJobManagerID"` | StrJobManagerID int64 `json:"strJobManagerID"` | ||||
| MapAppJobInfo MapAppJobInfo `json:"mapAppJobInfo"` | MapAppJobInfo MapAppJobInfo `json:"mapAppJobInfo"` | ||||
| /****************parmas from shuguang********************/ | |||||
| Account string `json:"account,omitempty"` | Account string `json:"account,omitempty"` | ||||
| Acctg_freq string `json:"acctg_freq,omitempty"` | Acctg_freq string `json:"acctg_freq,omitempty"` | ||||
| @@ -282,13 +285,13 @@ type ( | |||||
| } | } | ||||
| submitJobResp { | submitJobResp { | ||||
| Job_id int32 `json:"job_id"` | |||||
| Step_id int32 `json:"step_id"` | |||||
| Error_code int32 `json:"error_code"` | |||||
| //Job_id int32 `json:"job_id"` | |||||
| //Step_id int32 `json:"step_id"` | |||||
| //Error_code int32 `json:"error_code"` | |||||
| Code string `json:"code"` | |||||
| Code string `json:"code"` //Error_code 返回码 in Tianhe | |||||
| Msg string `json:"msg"` | Msg string `json:"msg"` | ||||
| Data string `json:"data"` | |||||
| Data string `json:"data"` //Job_id 作业id in Tianhe | |||||
| } | } | ||||
| MapAppJobInfo { | MapAppJobInfo { | ||||
| @@ -351,7 +354,7 @@ service slurmcore-api { | |||||
| post /scheduleTask (scheduleTaskReq) returns (scheduleTaskResp) | post /scheduleTask (scheduleTaskReq) returns (scheduleTaskResp) | ||||
| @handler submitJobHandler | @handler submitJobHandler | ||||
| post /submitJob (listHistoryJobReq) returns (listHistoryJobResp) | |||||
| post /submitJob (submitJobReq) returns (submitJobResp) | |||||
| @handler getRegionHandler | @handler getRegionHandler | ||||
| get /getRegion () returns (getRegionResp) | get /getRegion () returns (getRegionResp) | ||||
| @@ -1,7 +1,15 @@ | |||||
| package logic | package logic | ||||
| import ( | import ( | ||||
| "PCM/adaptor/slurm/slurmShuguang/rpc/internal/util" | |||||
| "bytes" | |||||
| "context" | "context" | ||||
| "encoding/json" | |||||
| "io/ioutil" | |||||
| "log" | |||||
| "net/http" | |||||
| "strings" | |||||
| "time" | |||||
| "PCM/adaptor/slurm/slurmShuguang/rpc/internal/svc" | "PCM/adaptor/slurm/slurmShuguang/rpc/internal/svc" | ||||
| "PCM/adaptor/slurm/slurmShuguang/rpc/slurmShuguang" | "PCM/adaptor/slurm/slurmShuguang/rpc/slurmShuguang" | ||||
| @@ -26,9 +34,42 @@ func NewSubmitJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubmitJ | |||||
| func (l *SubmitJobLogic) SubmitJob(in *slurmShuguang.SubmitJobReq) (*slurmShuguang.SubmitJobResp, error) { | func (l *SubmitJobLogic) SubmitJob(in *slurmShuguang.SubmitJobReq) (*slurmShuguang.SubmitJobResp, error) { | ||||
| resp := &slurmShuguang.SubmitJobResp{} | resp := &slurmShuguang.SubmitJobResp{} | ||||
| resp.Msg = in.Appname | |||||
| resp.Code = in.Appname | |||||
| resp.Data = in.Appname | |||||
| jobSubmitUrl := "hpc/openapi/v2/apptemplates/{apptype}/{appname}/job" | |||||
| jobSubmitUrl = strings.Replace(jobSubmitUrl, "{apptype}", in.Apptype, -1) | |||||
| jobSubmitUrl = strings.Replace(jobSubmitUrl, "{appname}", in.Appname, -1) | |||||
| jsonStr, _ := json.Marshal(in) | |||||
| req_url, err := http.NewRequest("POST", "https://api01.hpccube.com:65106/"+jobSubmitUrl, bytes.NewBuffer(jsonStr)) | |||||
| Gtoken := util.GetToken() | |||||
| var token string | |||||
| if util.GetTokenState(Gtoken) { | |||||
| token = Gtoken | |||||
| } else { | |||||
| token = util.GetToken() | |||||
| Gtoken = token | |||||
| } | |||||
| req_url.Header.Add("content-type", "application/json") | |||||
| req_url.Header.Add("token", token) | |||||
| if err != nil { | |||||
| log.Fatal(err) | |||||
| } | |||||
| defer req_url.Body.Close() | |||||
| c := http.Client{Timeout: time.Duration(3) * time.Second} | |||||
| //c := &http.Client{Timeout: 5 * time.Second} | |||||
| respUrl, err := c.Do(req_url) | |||||
| defer respUrl.Body.Close() | |||||
| if err != nil { | |||||
| log.Fatal(err) | |||||
| } | |||||
| result, _ := ioutil.ReadAll(respUrl.Body) | |||||
| json.Unmarshal([]byte(string(result)), &resp) | |||||
| return resp, nil | return resp, nil | ||||
| } | } | ||||