82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/conf"
|
|
"github.com/zeromicro/go-zero/core/service"
|
|
"github.com/zeromicro/go-zero/zrpc"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/client/participantservice"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/pcmCore"
|
|
"gitlink.org.cn/jcce-pcm/pcm-slurm/internal/config"
|
|
"gitlink.org.cn/jcce-pcm/pcm-slurm/internal/pkg/cron"
|
|
"gitlink.org.cn/jcce-pcm/pcm-slurm/internal/pkg/utils"
|
|
"gitlink.org.cn/jcce-pcm/pcm-slurm/internal/server"
|
|
"gitlink.org.cn/jcce-pcm/pcm-slurm/internal/svc"
|
|
"gitlink.org.cn/jcce-pcm/pcm-slurm/slurm"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/reflection"
|
|
"strconv"
|
|
)
|
|
|
|
var configFile = flag.String("f", "etc/slurm.yaml", "the config file")
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
//解析业务配置
|
|
var c config.Config
|
|
conf.MustLoad(*configFile, &c)
|
|
ctx := svc.NewServiceContext(c)
|
|
|
|
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
|
slurm.RegisterSlurmServer(grpcServer, server.NewSlurmServer(ctx))
|
|
|
|
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
|
reflection.Register(grpcServer)
|
|
}
|
|
})
|
|
defer s.Stop()
|
|
// 启动并添加定时任务
|
|
ctx.Cron.Start()
|
|
cron.AddCronGroup(ctx)
|
|
// 推送p端静态信息
|
|
PushParticipantInfo(ctx.Config.RestUrl, ctx.ParticipantRpc)
|
|
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
|
s.Start()
|
|
}
|
|
|
|
// PushParticipantInfo 推送p端静态信息
|
|
func PushParticipantInfo(address string, participantService participantservice.ParticipantService) {
|
|
// 服务注册到core端 同步静态信息
|
|
participantId, err := utils.GetParticipantId(*configFile)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
// 注册到core端
|
|
var labels []*pcmCore.ParticipantLabel
|
|
labels = append(labels, &pcmCore.ParticipantLabel{
|
|
Key: "hpc",
|
|
Value: "slurm",
|
|
})
|
|
|
|
req := participantservice.ParticipantPhyReq{
|
|
ParticipantId: participantId,
|
|
Address: address,
|
|
Type: "HPC",
|
|
TenantId: 2,
|
|
TenantName: "slurm-cs",
|
|
LabelInfo: labels,
|
|
}
|
|
resp, err := participantService.RegisterParticipant(context.Background(), &req)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
// 更新本地配置文件ParticipantId
|
|
utils.UpdateParticipantId(*configFile, strconv.FormatInt(resp.ParticipantId, 10))
|
|
}
|