forked from JointCloud/pcm-hpc
178 lines
5.3 KiB
Go
178 lines
5.3 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/go-resty/resty/v2"
|
|
"github.com/robfig/cron"
|
|
"gitlink.org.cn/JointCloud/pcm-hpc/ac"
|
|
confHpc "gitlink.org.cn/JointCloud/pcm-hpc/config"
|
|
cronPCM "gitlink.org.cn/JointCloud/pcm-hpc/cron"
|
|
"gitlink.org.cn/JointCloud/pcm-hpc/paratera"
|
|
"gitlink.org.cn/JointCloud/pcm-hpc/slurm"
|
|
"gopkg.in/yaml.v2"
|
|
"io/ioutil"
|
|
"log"
|
|
"strconv"
|
|
)
|
|
|
|
func init() {
|
|
//load yaml file to get coreUrl and adapterId
|
|
yamlFile, err := ioutil.ReadFile("etc/hpc.yaml")
|
|
if err != nil {
|
|
log.Fatalf("error: %v", err)
|
|
}
|
|
|
|
var config confHpc.Config
|
|
err = yaml.Unmarshal(yamlFile, &config)
|
|
if err != nil {
|
|
log.Fatalf("error: %v", err)
|
|
}
|
|
|
|
httpClient := resty.New().R()
|
|
params := map[string]string{
|
|
"type": "2",
|
|
"pageNum": "1",
|
|
"pageSize": "10",
|
|
"adapterId": config.AdapterId,
|
|
}
|
|
|
|
result, _ := httpClient.SetHeader("Content-Type", "application/json").
|
|
SetQueryParams(params).Get(config.CoreUrl + "/pcm/v1/adapter/cluster/list")
|
|
|
|
cronPCM.CoreUrl = config.CoreUrl
|
|
adapterId, _ := strconv.ParseInt(config.AdapterId, 10, 64)
|
|
cronPCM.AdapterId = adapterId
|
|
var resp cronPCM.ClusterResp
|
|
json.Unmarshal(result.Body(), &resp)
|
|
|
|
for _, cluster := range resp.Data.List {
|
|
switch cluster.Label {
|
|
case "slurm":
|
|
cronPCM.SlurmClient, _ = slurm.NewClient(slurm.ClientOptions{
|
|
RestUserName: cluster.Username,
|
|
CmdUserName: cluster.Username,
|
|
Password: cluster.Password,
|
|
Token: cluster.Token,
|
|
URL: cluster.Server,
|
|
AdaptMode: cluster.AuthType,
|
|
ClientVersion: cluster.Version,
|
|
})
|
|
case "ac":
|
|
cronPCM.AcClient, _ = ac.NewClient(ac.ClientOptions{
|
|
ClusterUrl: "https://wuzh02.hpccube.com:65051/hpc/openapi/v2/cluster",
|
|
TokenUrl: "https://ac.sugon.com/ac/openapi/v2/tokens",
|
|
StateUrl: "https://ac.sugon.com/ac/openapi/v2/tokens/state",
|
|
User: cluster.Username,
|
|
Password: cluster.Password,
|
|
OrgId: "c8befbc1301665ba2dc5b2826f8dca1e",
|
|
EndPoint: "https://api01.hpccube.com:65106",
|
|
Token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb21wdXRlVXNlciI6ImFjZ25ubWZid28iLCJhY2NvdW50U3RhdHVzIjoiVHJpYWwiLCJjcmVhdG9yIjoiYWMiLCJyb2xlIjoiMSIsImV4cGlyZVRpbWUiOiIxNzEwOTkwNjUyNzYwIiwiY2x1c3RlcklkIjoiMTEyNzYiLCJpbnZva2VyIjoiYzhiZWZiYzEzMDE2NjViYTJkYzViMjgyNmY4ZGNhMWUiLCJ1c2VyIjoiYWNnbm5tZmJ3byIsInVzZXJJZCI6IjExNzkxMTQ4MjAwIn0.OKASpJvVetAqhEQPhxcpDEeUbir5bJjCYDrPBbPyXbs",
|
|
ClusterID: cluster.AdapterId,
|
|
BaseEndpoint: "https://wuzh02.hpccube.com:65051"})
|
|
|
|
case "paratera":
|
|
cronPCM.ParateraClient, _ = paratera.NewClient(paratera.ClientOptions{
|
|
Url: cluster.Server,
|
|
TokenType: "TOKEN",
|
|
ThirdParty: cluster.ProjectId,
|
|
Phone: cluster.Username,
|
|
Password: cluster.Password})
|
|
}
|
|
}
|
|
}
|
|
func main() {
|
|
|
|
c := cron.New()
|
|
// pull task list from coordinator
|
|
c.AddFunc("*/5 * * * * ?", func() {
|
|
cronPCM.PullTaskInfo()
|
|
})
|
|
// 启动定时任务
|
|
c.Start()
|
|
// 阻塞主线程,否则主线程退出后定时任务也会停止
|
|
select {}
|
|
|
|
//slurm test
|
|
/****
|
|
start := time.Now().UnixNano() / int64(time.Millisecond)
|
|
cli, _ := slurm.NewClient(slurm.ClientOptions{
|
|
RestUserName: "slurmrestd",
|
|
CmdUserName: "root",
|
|
Password: "",
|
|
Token: "",
|
|
URL: "",
|
|
AdaptMode: "rest",
|
|
ClientVersion: "v0.0.38",
|
|
})
|
|
jober, _ := cli.Job(slurm.JobOptions{})
|
|
|
|
jobProp := slurm.JobProperties{}
|
|
opt := slurm.JobOptions{
|
|
Script: "srun sleep 200",
|
|
Job: &jobProp,
|
|
Jobs: nil,
|
|
}
|
|
result := jober.SubmitJob(opt)
|
|
str := fmt.Sprintf("%v", result)
|
|
fmt.Println(str)
|
|
end := time.Now().UnixNano() / int64(time.Millisecond)
|
|
|
|
duration := end - start
|
|
fmt.Printf("方法调用时间为 %d 毫秒\n", duration)
|
|
****/
|
|
|
|
//start := time.Now().UnixNano() / int64(time.Millisecond)
|
|
//cli, _ := paratera.NewClient(paratera.ClientOptions{
|
|
// Url: "https://cloud.paratera.com",
|
|
// TokenType: "TOKEN",
|
|
// ThirdParty: "NMPHONE",
|
|
// Phone: "13278887558",
|
|
// Password: "eb78bbb29cfb2b31a54751873c3dab5f",
|
|
//})
|
|
//
|
|
//job, _ := cli.Job(paratera.JobOptions{})
|
|
//
|
|
////sbs job submit
|
|
//sbs := paratera.Sbs{
|
|
// JobGroupName: "vasp",
|
|
// JobName: "sbsjob",
|
|
// SubmitProfile: paratera.SubmitProfile{
|
|
// BootScript: "jobsubmit.sh",
|
|
// WorkingDir: "prn:pcs:sftp:CSTC9:CSTC9:sc30314:file:/public4/home/sc56516/jobs/VNCView_20240203180350",
|
|
// },
|
|
//}
|
|
//
|
|
//result := job.SubmitSbsJob(sbs)
|
|
|
|
//abs job submit
|
|
/*submitProfiles := make([]paratera.SubmitProfiles, 0)
|
|
addtionalParams := make([]paratera.AddtionalParams, 0)
|
|
addtionalParam := paratera.AddtionalParams{
|
|
Key: "input",
|
|
Value: "prn:pcs:sftp:CSTC9:CSTC9:pp214:file:/WORK/pp214/jobs/Flow_F0.sim",
|
|
}
|
|
addtionalParams = append(addtionalParams, addtionalParam)
|
|
submitProfile := paratera.SubmitProfiles{
|
|
Queue: "prn:pcs:hpc:CSTC9:CSTC9:pp214:queue:paratera",
|
|
SubmissionParameters: paratera.SubmissionParameters{
|
|
AddtionalParams: addtionalParams,
|
|
Cores: 24,
|
|
Nodes: 1,
|
|
},
|
|
}
|
|
submitProfiles = append(submitProfiles, submitProfile)
|
|
queueAbs := paratera.QueueAbs{
|
|
App: "starccm/12.02.010-R8",
|
|
JobName: "starccm",
|
|
SubmitProfiles: submitProfiles,
|
|
}
|
|
result := job.SubmitQueueAbsJob(queueAbs)*/
|
|
//
|
|
//str := fmt.Sprintf("%v", result)
|
|
//fmt.Println(str)
|
|
//end := time.Now().UnixNano() / int64(time.Millisecond)
|
|
//
|
|
//duration := end - start
|
|
//fmt.Printf("方法调用时间为 %d 毫秒\n", duration)
|
|
}
|