forked from JointCloud/pcm-hpc
ac adaptor implement
This commit is contained in:
parent
23935f817f
commit
aa180ee16d
|
@ -0,0 +1,22 @@
|
|||
package paratera
|
||||
|
||||
type ClientOptions struct {
|
||||
ClusterUrl string `json:"ClusterUrl"`
|
||||
TokenUrl string `json:"TokenUrl"`
|
||||
StateUrl string `json:"StateUrl"`
|
||||
User string `json:"User"`
|
||||
Password string `json:"Password"`
|
||||
OrgId string `json:"OrgId"`
|
||||
EndPoint string `json:"EndPoint"`
|
||||
Token string `json:"Token"`
|
||||
ClusterID string `json:"ClusterID"`
|
||||
BaseEndpoint string `json:"BaseEndpoint"`
|
||||
}
|
||||
type Client interface {
|
||||
Job(JobOptions) (Job, error)
|
||||
Token(options ClientOptions) (Token, error)
|
||||
}
|
||||
|
||||
func NewClient(options ClientOptions) (Client, error) {
|
||||
return newClient(options)
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package paratera
|
||||
|
||||
type client struct {
|
||||
clusterUrl string
|
||||
tokenUrl string
|
||||
stateUrl string
|
||||
user string
|
||||
password string
|
||||
orgId string
|
||||
endPoint string
|
||||
token string
|
||||
clusterID string
|
||||
baseEndpoint string
|
||||
acStatus map[string]string
|
||||
}
|
||||
|
||||
func (c *client) Token(options ClientOptions) (Token, error) {
|
||||
token, _ := newToken(c, &options)
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func (c *client) Job(options JobOptions) (Job, error) {
|
||||
job, _ := newJob(c, &options)
|
||||
return job, nil
|
||||
}
|
||||
|
||||
func newClient(options ClientOptions) (Client, error) {
|
||||
status := map[string]string{
|
||||
"statQ": "Pending",
|
||||
"statR": "Running",
|
||||
"statE": "Pending",
|
||||
"statC": "Completed",
|
||||
"statH": "Pending",
|
||||
"statS": "Pending",
|
||||
"statW": "Pending",
|
||||
"statX": "Other",
|
||||
}
|
||||
|
||||
c := &client{
|
||||
clusterUrl: options.ClusterUrl,
|
||||
tokenUrl: options.TokenUrl,
|
||||
stateUrl: options.StateUrl,
|
||||
user: options.User,
|
||||
password: options.Password,
|
||||
orgId: options.OrgId,
|
||||
endPoint: options.EndPoint,
|
||||
token: "",
|
||||
clusterID: options.ClusterID,
|
||||
baseEndpoint: options.BaseEndpoint,
|
||||
acStatus: status,
|
||||
}
|
||||
t, _ := newToken(c, &options)
|
||||
|
||||
tokenString := t.GetToken(options)
|
||||
c.token = tokenString
|
||||
return c, nil
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package paratera
|
||||
|
||||
type JobOptions struct {
|
||||
listHistoryJobReq ListHistoryJobReq
|
||||
submitJobReq SubmitJobReq
|
||||
}
|
||||
|
||||
type SubmitJobReq struct {
|
||||
Apptype string `json:"apptype,omitempty"`
|
||||
Appname string `json:"appname,omitempty"`
|
||||
StrJobManagerID int64 `json:"strJobManagerID,omitempty"`
|
||||
MapAppJobInfo *MapAppJobInfo `json:"mapAppJobInfo,omitempty"`
|
||||
}
|
||||
|
||||
type MapAppJobInfo struct {
|
||||
GapCmdFile string `json:"GAP_CMD_FILE,omitempty"` //命令行内容
|
||||
GapNnode string `json:"GAP_NNODE,omitempty"` //节点个数(当指定该参数时,GAP_NODE_STRING必须为"")
|
||||
GapNodeString string `json:"GAP_NODE_STRING,omitempty"` //指定节点(当指定该参数时,GAP_NNODE必须为"")
|
||||
GapSubmitType string `json:"GAP_SUBMIT_TYPE,omitempty"` //cmd(命令行模式)
|
||||
GapJobName string `json:"GAP_JOB_NAME,omitempty"` //作业名称
|
||||
GapWorkDir string `json:"GAP_WORK_DIR,omitempty"` //工作路径
|
||||
GapQueue string `json:"GAP_QUEUE,omitempty"` ///队列名称
|
||||
GapNproc string `json:"GAP_NPROC,omitempty"` ///总核心数(GAP_NPROC和GAP_PPN选其一填写)
|
||||
GapPpn string `json:"GAP_PPN,omitempty"` //CPU核心/节点(GAP_NPROC和GAP_PPN选其一填写)
|
||||
GapNgpu string `json:"GAP_NGPU,omitempty"` //GPU卡数/节点
|
||||
GapNdcu string `json:"GAP_NDCU,omitempty"` //DCU卡数/节点
|
||||
GapJobMem string `json:"GAP_JOB_MEM,omitempty"` //每个节点内存值,单位为MB/GB
|
||||
GapWallTime string `json:"GAP_WALL_TIME,omitempty"` //最大运行时长(HH:MM:ss)
|
||||
GapExclusive string `json:"GAP_EXCLUSIVE,omitempty"` // 是否独占节点,1为独占,空为非独占
|
||||
GapAppname string `json:"GAP_APPNAME,omitempty"` //BASE(基础应用),支持填写具体的应用英文名称
|
||||
GapMultiSub string `json:"GAP_MULTI_SUB,omitempty"` //作业组长度,建议为小于等于50的正整数
|
||||
GapStdOutFile string `json:"GAP_STD_OUT_FILE,omitempty"` //工作路径/std.out.%j
|
||||
GapStdErrFile string `json:"GAP_STD_ERR_FILE,omitempty"` //工作路径/std.err.%j
|
||||
}
|
||||
|
||||
type ListHistoryJobReq struct {
|
||||
StrClusterNameList string `json:"strClusterNameList,omitempty"` //调度器ID 示例:1638523853
|
||||
StartTime string `json:"startTime,omitempty"` //开始时间 示例:2021-11-23 01:01:01
|
||||
EndTime string `json:"endTime,omitempty"` //结束时间 示例:2021-12-23 01:01:01
|
||||
TimeType string `json:"timeType,omitempty"` //CUSTOM 示例:CUSTOM
|
||||
Queue string `json:"queue,omitempty"` //队列名称 示例:debug
|
||||
AppType string `json:"appType,omitempty"` //应用名称 示例:fluent
|
||||
Sort string `json:"sort,omitempty"` //排序规则 示例:DESC/ASC
|
||||
OrderBy string `json:"orderBy,omitempty"` //排序字段 示例:jobId
|
||||
JobId string `json:"jobId,omitempty"` //作业ID 示例:12
|
||||
JobState string `json:"jobState,omitempty"` //'statR(运行)','statQ(排队)','statH(保留)','statS(挂起)','statE(退出)','statC(完成)','statW(等待)','statX(其他)' 示例:statQ
|
||||
HostName string `json:"hostName,omitempty"` //节点名称 示例:h04r3n07
|
||||
StrUser string `json:"strUser,omitempty"` //用户名称 示例:test
|
||||
JobName string `json:"jobName,omitempty"` //作业名称 示例:STDIN_1208_173644
|
||||
Start int32 `json:"start,omitempty"` //起始坐标 示例:0
|
||||
Limit int32 `json:"limit,omitempty"` //请求一次获取数据的数目 示例:25
|
||||
IsQueryByQueueTime string `json:"isQueryByQueueTime,omitempty"` //按照结束时间查询false/按照入队时间查询true(推荐false) 示例:false
|
||||
}
|
||||
|
||||
// ListJobReq 作业列表请求体
|
||||
type ListJobReq struct {
|
||||
}
|
||||
|
||||
// GetJobReq 作业详情请求体
|
||||
type GetJobReq struct {
|
||||
jobId string //作业id
|
||||
}
|
||||
|
||||
// CancelJobReq 作业取消请求体
|
||||
type CancelJobReq struct {
|
||||
jobId string //作业id
|
||||
}
|
||||
|
||||
type Job interface {
|
||||
ListJob(listJobReq ListJobReq) string
|
||||
GetJob(getJobReq GetJobReq) string
|
||||
SubmitJob(submitJobReq SubmitJobReq) string
|
||||
CancelJob(cancelJobReq CancelJobReq) string
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package paratera
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type job struct {
|
||||
sync.RWMutex
|
||||
client *client
|
||||
options *JobOptions
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func newJob(client *client, options *JobOptions) (*job, error) {
|
||||
job := &job{
|
||||
RWMutex: sync.RWMutex{},
|
||||
client: client,
|
||||
options: options,
|
||||
log: log.Logger{},
|
||||
}
|
||||
return job, nil
|
||||
}
|
||||
|
||||
func (j *job) ListJob(listJobReq ListJobReq) string {
|
||||
jobUrl := "/hpc/openapi/v2/jobs?"
|
||||
clusterId := 1638523853
|
||||
params := map[string]string{
|
||||
"strClusterIDList": strconv.FormatInt(int64(clusterId), 10),
|
||||
}
|
||||
|
||||
httpClient := resty.New().R()
|
||||
result, _ := httpClient.SetHeader("token", j.client.token).SetQueryParams(params).Get(j.client.baseEndpoint + jobUrl)
|
||||
return string(result.Body())
|
||||
}
|
||||
|
||||
func (j *job) GetJob(getJobReq GetJobReq) string {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (j *job) CancelJob(cancelJobReq CancelJobReq) string {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (j *job) SubmitJob(submitJobReq SubmitJobReq) string {
|
||||
jobSubmitUrl := "/hpc/openapi/v2/apptemplates/{apptype}/{appname}/job"
|
||||
jobSubmitUrl = strings.Replace(jobSubmitUrl, "{apptype}", submitJobReq.Apptype, -1)
|
||||
jobSubmitUrl = strings.Replace(jobSubmitUrl, "{appname}", submitJobReq.Appname, -1)
|
||||
httpClient := resty.New().R()
|
||||
jsonStr, _ := json.Marshal(submitJobReq)
|
||||
params := map[string]string{
|
||||
"content-type": "application/json",
|
||||
"token": j.client.token,
|
||||
}
|
||||
result, _ := httpClient.SetHeaders(params).SetBody(jsonStr).Post(j.client.baseEndpoint + jobSubmitUrl)
|
||||
|
||||
return string(result.Body())
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package paratera
|
||||
|
||||
type TokenOptions struct {
|
||||
}
|
||||
|
||||
type Token interface {
|
||||
GetToken(options ClientOptions) string
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package paratera
|
||||
|
||||
import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-ac/hpcAC"
|
||||
"log"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type token struct {
|
||||
sync.RWMutex
|
||||
client *client
|
||||
options *JobOptions
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
type ACTokenResp struct {
|
||||
Msg string
|
||||
Code string
|
||||
Data []*ACTokenData
|
||||
}
|
||||
type ACTokenData struct {
|
||||
ClusterName string
|
||||
ClusterId string
|
||||
Token string
|
||||
}
|
||||
|
||||
func newToken(client *client, options *ClientOptions) (*token, error) {
|
||||
token := &token{
|
||||
RWMutex: sync.RWMutex{},
|
||||
client: nil,
|
||||
options: nil,
|
||||
log: log.Logger{},
|
||||
}
|
||||
return token, nil
|
||||
}
|
||||
func (t *token) GetToken(options ClientOptions) string {
|
||||
var respAC hpcAC.ACTokenResp
|
||||
var tokenString string
|
||||
httpClient := resty.New().R()
|
||||
params := map[string]string{
|
||||
"user": options.User,
|
||||
"password": options.Password,
|
||||
"orgId": options.OrgId,
|
||||
}
|
||||
|
||||
httpClient.SetHeaders(params).SetResult(&respAC).Post(options.TokenUrl)
|
||||
for _, dt := range respAC.Data {
|
||||
if dt.ClusterId == "11276" {
|
||||
tokenString = dt.Token
|
||||
}
|
||||
}
|
||||
return tokenString
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package paratera
|
||||
|
||||
import "github.com/go-resty/resty/v2"
|
||||
import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type client struct {
|
||||
url string
|
||||
|
@ -25,12 +27,13 @@ func (c *client) Job(options JobOptions) (Job, error) {
|
|||
func newClient(options ClientOptions) (Client, error) {
|
||||
|
||||
httpClient := resty.New().R()
|
||||
params := make(map[string]string)
|
||||
params["token_type"] = options.TokenType
|
||||
params["third_party"] = options.ThirdParty
|
||||
params["email"] = options.Email
|
||||
params["phone"] = options.Phone
|
||||
params["password"] = options.Password
|
||||
params := map[string]string{
|
||||
"token_type": options.TokenType,
|
||||
"third_party": options.ThirdParty,
|
||||
"email": options.Email,
|
||||
"phone": options.Phone,
|
||||
"password": options.Password,
|
||||
}
|
||||
|
||||
result, _ := httpClient.SetHeader("Content-Type", "x-www-form-urlencoded").
|
||||
SetQueryParams(params).Post("https://user.paratera.com/user/api/login")
|
||||
|
|
12
slurm/job.go
12
slurm/job.go
|
@ -1,5 +1,11 @@
|
|||
package slurm
|
||||
|
||||
type JobOptions struct {
|
||||
Script string
|
||||
Job *JobProperties
|
||||
Jobs *JobProperties
|
||||
}
|
||||
|
||||
type JobProperties struct {
|
||||
Account string
|
||||
AccountGatherFrequency string
|
||||
|
@ -74,12 +80,6 @@ type JobProperties struct {
|
|||
Wckey string
|
||||
}
|
||||
|
||||
type JobOptions struct {
|
||||
Script string
|
||||
Job *JobProperties
|
||||
Jobs *JobProperties
|
||||
}
|
||||
|
||||
type Job interface {
|
||||
ListJob() string
|
||||
ListDbJob() string
|
||||
|
|
Loading…
Reference in New Issue