添加gin

This commit is contained in:
zhangwei 2024-11-25 19:55:54 +08:00
parent 45af53d484
commit e6bfed35e5
16 changed files with 242 additions and 106 deletions

View File

@ -25,7 +25,7 @@ type AuthService struct {
func NewAuthService() *AuthService {
cfg := config.Config{}
configFile := flag.String("c", "etc/hpc.yaml", "the config file")
configFile := flag.String("c", "etc/config.yaml", "the config file")
conf.MustLoad(*configFile, &cfg)
flag.Parse()
token, clusterId := getTokenAndClusterId(&cfg)

View File

@ -4,7 +4,7 @@ import (
"github.com/go-resty/resty/v2"
coreClient "gitlink.org.cn/JointCloud/pcm-coordinator/client"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/httputils"
confHpc "gitlink.org.cn/JointCloud/pcm-hpc/config"
"gitlink.org.cn/JointCloud/pcm-hpc/global"
"log"
"math"
"strconv"
@ -147,7 +147,7 @@ func (r *resource) GetResourceStats(options ClientOptions) (getResourceStatsResp
}
cards = append(cards, &dcu)
resourceStats := coreClient.ResourceStats{
Name: confHpc.ConfigHpc.CoreUrl,
Name: global.PCM_CONFIG.System.CoreServerUrl,
Balance: balance,
CpuCoreTotal: totalCpu,
CpuCoreAvail: CpuCoreAvail,

View File

@ -62,3 +62,9 @@ ACConfig:
GetUserInfo: "/ac/openapi/v2/user"
GetGroupMembers: "/ac/openapi/v2/groupmembers" #查询成员信息
GetMemberJobs: "/ac/openapi/v2/clusters/{clusterId}/groups/{groupId}/clusterUserNames/{clusterUserName}/jobs"
system:
host: '0.0.0.0'
port: 2001
adapter-id: 1752857389213683712
core-server-url: http://localhost:8999

View File

@ -5,14 +5,11 @@ import (
"github.com/zeromicro/go-zero/zrpc"
)
type Config struct {
AdapterId string `yaml:"AdapterId"`
CoreUrl string `yaml:"CoreUrl"`
ACConfig ACConfig `yaml:"ACConfig"`
type Server struct {
ACConfig ACConfig `yaml:"ACConfig"`
System System `mapstructure:"system" json:"system" yaml:"system"`
}
var ConfigHpc Config
type ACConfig struct {
zrpc.RpcServerConf
ShuguangConf

8
config/system.go Normal file
View File

@ -0,0 +1,8 @@
package config
type System struct {
Host string `mapstructure:"host" json:"host" yaml:"host"` // IP地址
Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口号
AdapterId int64 `mapstructure:"adapter-id" json:"adapter-id" yaml:"adapter-id"` //驱动器id
CoreServerUrl string `mapstructure:"core-server-url" json:"core-server-url" yaml:"core-server-url"` //服务地址
}

View File

@ -3,6 +3,7 @@ package core
import (
"context"
"fmt"
"gitlink.org.cn/JointCloud/pcm-hpc/global"
"gitlink.org.cn/JointCloud/pcm-hpc/routers"
"net/http"
"os"
@ -11,7 +12,7 @@ import (
)
func RunServer() {
addr := fmt.Sprintf("%s:%d", "0.0.0.0", 2001)
addr := fmt.Sprintf("%s:%d", global.PCM_CONFIG.System.Host, global.PCM_CONFIG.System.Port)
router := routers.InitRouter()
srv := http.Server{
Addr: addr,

33
core/viper.go Normal file
View File

@ -0,0 +1,33 @@
package core
import (
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"gitlink.org.cn/JointCloud/pcm-hpc/global"
)
func Viper() *viper.Viper {
v := viper.New()
v.SetConfigFile("config.yaml")
v.SetConfigType("yaml")
err := v.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
v.WatchConfig()
v.OnConfigChange(func(e fsnotify.Event) {
fmt.Println("config file changed:", e.Name)
if err = v.Unmarshal(&global.PCM_CONFIG); err != nil {
fmt.Println(err)
}
})
if err = v.Unmarshal(&global.PCM_CONFIG); err != nil {
fmt.Println(err)
}
return v
}

11
global/global.go Normal file
View File

@ -0,0 +1,11 @@
package global
import (
"github.com/spf13/viper"
"gitlink.org.cn/JointCloud/pcm-hpc/config"
)
var (
PCM_VP *viper.Viper
PCM_CONFIG *config.Server
)

18
go.mod
View File

@ -3,16 +3,16 @@ module gitlink.org.cn/JointCloud/pcm-hpc
go 1.23.0
require (
github.com/fsnotify/fsnotify v1.7.0
github.com/gin-gonic/gin v1.10.0
github.com/go-resty/resty/v2 v2.15.3
github.com/pkg/errors v0.9.1
github.com/robfig/cron v1.2.0
github.com/rs/zerolog v1.28.0
github.com/spf13/viper v1.19.0
github.com/zeromicro/go-zero v1.7.3
gitlink.org.cn/JointCloud/pcm-coordinator v0.0.0-20241101054624-a7ad691c878a
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.28.0
gopkg.in/yaml.v2 v2.4.0
)
require (
@ -51,6 +51,7 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
@ -58,9 +59,11 @@ require (
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
@ -71,7 +74,14 @@ require (
github.com/prometheus/common v0.60.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/redis/go-redis/v9 v9.7.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/x448/float16 v0.8.4 // indirect
@ -91,7 +101,9 @@ require (
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sys v0.26.0 // indirect
@ -103,6 +115,8 @@ require (
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.5.7 // indirect
gorm.io/gorm v1.25.12 // indirect

28
go.sum
View File

@ -37,6 +37,10 @@ github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtz
github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
@ -97,6 +101,8 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjw
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
@ -121,6 +127,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
@ -130,6 +138,8 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@ -169,10 +179,22 @@ github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWN
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@ -185,6 +207,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
@ -244,6 +268,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
@ -308,6 +334,8 @@ gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

155
main.go
View File

@ -1,104 +1,81 @@
package main
import (
"encoding/json"
"github.com/go-resty/resty/v2"
"github.com/robfig/cron"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-hpc/ac"
confHpc "gitlink.org.cn/JointCloud/pcm-hpc/config"
"gitlink.org.cn/JointCloud/pcm-hpc/core"
cronPCM "gitlink.org.cn/JointCloud/pcm-hpc/cron"
"gitlink.org.cn/JointCloud/pcm-hpc/paratera"
"gitlink.org.cn/JointCloud/pcm-hpc/slurm"
"gitlink.org.cn/JointCloud/pcm-hpc/types"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"strconv"
"gitlink.org.cn/JointCloud/pcm-hpc/global"
)
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, &confHpc.ConfigHpc)
if err != nil {
log.Fatalf("error: %v", err)
}
httpClient := resty.New().R()
params := map[string]string{
"type": "2",
"pageNum": "1",
"pageSize": "10",
"adapterId": confHpc.ConfigHpc.AdapterId,
}
result, _ := httpClient.SetHeader("Content-Type", "application/json").
SetQueryParams(params).Get(confHpc.ConfigHpc.CoreUrl + "/pcm/v1/adapter/cluster/list")
cronPCM.CoreUrl = confHpc.ConfigHpc.CoreUrl
adapterId, _ := strconv.ParseInt(confHpc.ConfigHpc.AdapterId, 10, 64)
cronPCM.AdapterId = adapterId
var resp types.ClusterResp
json.Unmarshal(result.Body(), &resp)
for _, cluster := range resp.Data.List {
switch cluster.Label {
case "slurm":
slurmClient, _ := slurm.NewClient(slurm.ClientOptions{
AdapterId: cluster.AdapterId,
ClusterId: cluster.Id,
RestUserName: cluster.Username,
CmdUserName: cluster.Username,
Password: cluster.Password,
Token: cluster.Token,
URL: cluster.Server,
AdaptMode: cluster.AuthType,
ClientVersion: cluster.Version,
})
cronPCM.SlurmClients = append(cronPCM.SlurmClients, slurmClient)
case "ac":
acClient, _ := ac.NewClient(ac.ClientOptions{
AdapterId: cluster.AdapterId,
ClusterId: cluster.Id,
ClusterUrl: confHpc.ConfigHpc.ACConfig.ClusterUrl,
TokenUrl: confHpc.ConfigHpc.ACConfig.TokenUrl,
StateUrl: confHpc.ConfigHpc.ACConfig.StateUrl,
User: cluster.Username,
Password: cluster.Password,
OrgId: cluster.OwnerId,
EndPoint: confHpc.ConfigHpc.ACConfig.AcBaseUrl,
ClusterIdAC: cluster.ProjectId,
BaseEndpoint: confHpc.ConfigHpc.ACConfig.AcBaseUrl})
cronPCM.AcClients = append(cronPCM.AcClients, acClient)
case "paratera":
parateraClient, _ := paratera.NewClient(paratera.ClientOptions{
AdapterId: cluster.AdapterId,
ClusterId: cluster.Id,
Url: cluster.Server,
TokenType: "TOKEN",
ThirdParty: cluster.ProjectId,
Phone: cluster.Username,
Password: cluster.Password})
cronPCM.ParateraClients = append(cronPCM.ParateraClients, parateraClient)
}
}
}
//
//func init() {
// var resp types.ClusterResp
// httpClient := resty.New().R()
// params := map[string]string{
// "type": "2",
// "pageNum": "1",
// "pageSize": "10",
// "adapterId": strconv.FormatInt(global.System.AdapterId, 10),
// }
//
// _, err := httpClient.SetHeader("Content-Type", "application/json").
// SetQueryParams(params).
// SetResult(&resp).
// Get(global.System.CoreServerUrl + "/pcm/v1/core/clusterList")
// if err != nil {
// log.Fatal(err)
// }
// for _, cluster := range resp.Data.List {
// switch cluster.Label {
// case "slurm":
// slurmClient, _ := slurm.NewClient(slurm.ClientOptions{
// AdapterId: cluster.AdapterId,
// ClusterId: cluster.Id,
// RestUserName: cluster.Username,
// CmdUserName: cluster.Username,
// Password: cluster.Password,
// Token: cluster.Token,
// URL: cluster.Server,
// AdaptMode: cluster.AuthType,
// ClientVersion: cluster.Version,
// })
// cronPCM.SlurmClients = append(cronPCM.SlurmClients, slurmClient)
// case "ac":
//
// acClient, _ := ac.NewClient(ac.ClientOptions{
// AdapterId: cluster.AdapterId,
// ClusterId: cluster.Id,
// ClusterUrl: confHpc.ConfigHpc.ACConfig.ClusterUrl,
// TokenUrl: confHpc.ConfigHpc.ACConfig.TokenUrl,
// StateUrl: confHpc.ConfigHpc.ACConfig.StateUrl,
// User: cluster.Username,
// Password: cluster.Password,
// OrgId: cluster.OwnerId,
// EndPoint: confHpc.ConfigHpc.ACConfig.AcBaseUrl,
// ClusterIdAC: cluster.ProjectId,
// BaseEndpoint: confHpc.ConfigHpc.ACConfig.AcBaseUrl})
// cronPCM.AcClients = append(cronPCM.AcClients, acClient)
//
// case "paratera":
// parateraClient, _ := paratera.NewClient(paratera.ClientOptions{
// AdapterId: cluster.AdapterId,
// ClusterId: cluster.Id,
// Url: cluster.Server,
// TokenType: "TOKEN",
// ThirdParty: cluster.ProjectId,
// Phone: cluster.Username,
// Password: cluster.Password})
// cronPCM.ParateraClients = append(cronPCM.ParateraClients, parateraClient)
// }
// }
//}
func main() {
global.PCM_VP = core.Viper()
c := cron.New()
// pull task list from coordinator
c.AddFunc("*/5 * * * * ?", func() {
cronPCM.PullTaskInfo()
c.AddFunc("*/30 * * * * ?", func() {
//cronPCM.PullTaskInfo()
})
c.AddFunc("*/60 * * * * ?", func() {
//cronPCM.updateTaskStatus()

View File

@ -4,7 +4,7 @@ import (
"encoding/json"
"github.com/go-resty/resty/v2"
coreClient "gitlink.org.cn/JointCloud/pcm-coordinator/client"
confHpc "gitlink.org.cn/JointCloud/pcm-hpc/config"
"gitlink.org.cn/JointCloud/pcm-hpc/global"
"log"
"strconv"
"sync"
@ -60,7 +60,7 @@ func (r *resource) GetResourceStats(options ClientOptions) (getResourceStatsResp
}
resourceStats := coreClient.ResourceStats{
Name: confHpc.ConfigHpc.CoreUrl,
Name: global.PCM_CONFIG.System.CoreServerUrl,
CpuCoreAvail: int64(coresRemaining),
CpuCoreTotal: int64(coresTotal),
MemAvail: 0,

View File

@ -15,6 +15,7 @@ func InitRouter() *gin.Engine {
{
namespace := apiv1.Group("job")
namespace.POST("/submit", v1.SubmitJob)
namespace.GET("/info", v1.JobInfo)
}
return r

View File

@ -1,10 +1,14 @@
package v1
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/go-resty/resty/v2"
"github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-hpc/slurm"
"io/ioutil"
"net/http"
)
@ -16,6 +20,14 @@ type SubmitJobReq struct {
JobOptions JobOptions
}
type JobInfoReq 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 {
Meta struct {
Plugin struct {
@ -85,3 +97,51 @@ func SubmitJob(ctx *gin.Context) {
}
Response(ctx, http.StatusOK, "success", resp)
}
func JobInfo(ctx *gin.Context) {
var req JobInfoReq
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("GET", url, nil)
if err != nil {
return
}
if err != nil {
fmt.Println(err)
return
}
request.Header.Add("Accept", "*/*")
request.Header.Add("Host", "192.168.87.196:6820")
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 {
fmt.Println(err)
return
}
fmt.Println(string(body))
var resp slurm.GetJobResp
bytes, err := json.Marshal(res)
if err != nil {
return
}
json.Unmarshal(bytes, &resp)
logx.Info("调用rest api接口完成")
if err != nil {
Response(ctx, http.StatusInternalServerError, "rest api error.", err)
}
Response(ctx, http.StatusOK, "success", resp)
}

View File

@ -73,7 +73,7 @@ func (j *job) SubmitJob(jobOptions JobOptions) (submitJobResp SubmitJobResp, err
url := j.client.url + "/slurm/" + j.client.clientVersion + "/job/submit"
httpClient := resty.New().R()
httpResp, err := httpClient.SetHeader("Content-Type", "application/json").
httpResp, err := httpClient.
SetHeader("Accept", "application/json").
SetHeader("X-SLURM-USER-NAME", j.client.restUsername).
SetHeader("X-SLURM-USER-TOKEN", j.client.token).

View File

@ -3,7 +3,7 @@ package slurm
import (
"github.com/go-resty/resty/v2"
coreClient "gitlink.org.cn/JointCloud/pcm-coordinator/client"
confHpc "gitlink.org.cn/JointCloud/pcm-hpc/config"
"gitlink.org.cn/JointCloud/pcm-hpc/global"
"log"
"sync"
)
@ -44,7 +44,7 @@ func (r *resource) GetResourceStats(options ClientOptions) (getResourceStatsResp
memTotal += node.RealMemory
}
resourceStats := coreClient.ResourceStats{
Name: confHpc.ConfigHpc.CoreUrl,
Name: global.PCM_CONFIG.System.CoreServerUrl,
CpuCoreAvail: int64(coresRemaining),
CpuCoreTotal: int64(coresTotal),
MemAvail: float64(memRemaining),