forked from JointCloud/pcm-hpc
C端通信
This commit is contained in:
parent
e3da4b76fe
commit
b0e0b3a31c
|
|
@ -1,7 +1,10 @@
|
|||
Name: slurm.rpc
|
||||
Name: pcm.slurm.rpc
|
||||
ListenOn: 0.0.0.0:2007
|
||||
# core rpc
|
||||
PcmCoreRpcConf:
|
||||
Endpoints:
|
||||
- 10.101.15.170:32456
|
||||
NonBlock: true
|
||||
- 0.0.0.0:2004
|
||||
NonBlock: true
|
||||
ClusterUrl: localhost
|
||||
|
||||
ParticipantId: 0
|
||||
|
|
@ -9,4 +9,10 @@ type Config struct {
|
|||
zrpc.RpcServerConf
|
||||
LogConf logx.LogConf
|
||||
PcmCoreRpcConf zrpc.RpcClientConf
|
||||
SlurmConf
|
||||
}
|
||||
|
||||
// SlurmConf slurm 相关URL配置
|
||||
type SlurmConf struct {
|
||||
ClusterUrl string `json:"ClusterUrl"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,9 @@ type ServiceContext struct {
|
|||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Cron: cron.New(cron.WithSeconds()),
|
||||
Config: c,
|
||||
PcmCoreRpc: pcmcore.NewPcmCore(zrpc.MustNewClient(c.PcmCoreRpcConf)),
|
||||
Cron: cron.New(cron.WithSeconds()),
|
||||
Config: c,
|
||||
PcmCoreRpc: pcmcore.NewPcmCore(zrpc.MustNewClient(c.PcmCoreRpcConf)),
|
||||
ParticipantRpc: participantservice.NewParticipantService(zrpc.MustNewClient(c.PcmCoreRpcConf)),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
44
slurm.go
44
slurm.go
|
|
@ -1,17 +1,23 @@
|
|||
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-participant-slurm/internal/config"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-participant-slurm/internal/pkg/cron"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-participant-slurm/internal/server"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-participant-slurm/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-participant-slurm/slurm"
|
||||
"gitlink.org.cn/jcce-pcm/utils/tool"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/slurm.yaml", "the config file")
|
||||
|
|
@ -34,10 +40,42 @@ func main() {
|
|||
})
|
||||
defer s.Stop()
|
||||
// 启动并添加定时任务
|
||||
//ctx.Cron.Start()
|
||||
//cron.AddCronGroup(ctx)
|
||||
ctx.Cron.Start()
|
||||
cron.AddCronGroup(ctx)
|
||||
// 推送p端静态信息
|
||||
//PushParticipantInfo(ctx.Config, ctx.ParticipantRpc, ctx.ClientSet)
|
||||
PushParticipantInfo(ctx.Config.ClusterUrl, 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 := tool.GetParticipantId(*configFile)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 注册到core端
|
||||
var labels []*pcmCore.ParticipantLabel
|
||||
labels = append(labels, &pcmCore.ParticipantLabel{
|
||||
Key: "nudt",
|
||||
Value: "light",
|
||||
})
|
||||
|
||||
req := participantservice.ParticipantPhyReq{
|
||||
ParticipantId: participantId,
|
||||
Address: address,
|
||||
Type: "2",
|
||||
TenantId: 2,
|
||||
TenantName: "slurm-cs",
|
||||
LabelInfo: labels,
|
||||
}
|
||||
resp, err := participantService.RegisterParticipant(context.Background(), &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 更新本地配置文件ParticipantId
|
||||
tool.UpdateParticipantId(*configFile, strconv.FormatInt(resp.ParticipantId, 10))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue