pcm-openstack/pcmopenstack.go

100 lines
3.1 KiB
Go

package main
import (
"context"
"flag"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gitlink.org.cn/JointCloud/pcm-coordinator/rpc/client/participantservice"
"gitlink.org.cn/JointCloud/pcm-coordinator/rpc/pcmCore"
"gitlink.org.cn/JointCloud/pcm-openstack/internal/common"
"gitlink.org.cn/JointCloud/pcm-openstack/internal/config"
"gitlink.org.cn/JointCloud/pcm-openstack/internal/pkg/cron"
"gitlink.org.cn/JointCloud/pcm-openstack/internal/server"
"gitlink.org.cn/JointCloud/pcm-openstack/internal/svc"
"gitlink.org.cn/JointCloud/pcm-openstack/openstack"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"strconv"
)
// var configFile = flag.String("f", "etc/pcmopenstack.yaml", "the config file")
func main() {
flag.StringVar(&common.FileName, "f", "etc/pcmopenstack.yaml", "the config file")
flag.Parse()
conf.MustLoad(common.FileName, &common.C)
ctx := svc.NewServiceContext(common.C)
//解析业务配置
//var c config.Config
//conf.MustLoad(*configFile, &c)
//ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(common.C.RpcServerConf, func(grpcServer *grpc.Server) {
openstack.RegisterOpenstackServer(grpcServer, server.NewOpenstackServer(ctx))
if common.C.Mode == service.DevMode || common.C.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
// 启动并添加定时任务
ctx.Cron.Start()
cron.AddCronGroup(ctx)
// 推送p端静态信息
PushParticipantInfo(ctx.Config, ctx.ParticipantRpc)
logx.Infof("Starting rpc server at %s...\n", common.C.ListenOn)
s.Start()
//var bootstrapConfig commonConfig.BootstrapConfig
//nacosConfig := bootstrapConfig.NacosConfig
/* serviceConfigContent := nacosConfig.InitConfig(func(data string) {
err := conf.LoadFromYamlBytes([]byte(data), &c)
if err != nil {
panic(err)
}
})*/
//err := conf.LoadFromYamlBytes([]byte(serviceConfigContent), &c)
/*if err != nil {
panic(err)
}*/
// start log component
//logx.MustSetup(c.LogConf)
// 注册到nacos
// nacosConfig.Discovery(&c.RpcServerConf)
//rpc log
//s.AddUnaryInterceptors(rpcserver.LoggerInterceptor)
//logic.InitCron(ctx)
}
// PushParticipantInfo 推送p端静态信息
func PushParticipantInfo(config config.Config, participantService participantservice.ParticipantService) {
participantId, err := utils.GetParticipantId(*&common.FileName)
if err != nil {
return
}
// 从配置文件中读取participant标签信息
var labels []*pcmCore.ParticipantLabel
for k, v := range config.Participant.Labels {
labels = append(labels, &pcmCore.ParticipantLabel{
Key: k,
Value: v,
})
}
req := participantservice.ParticipantPhyReq{}
utils.Convert(config.Participant, &req)
req.ParticipantId = participantId
req.LabelInfo = labels
//
resp, err := participantService.RegisterParticipant(context.Background(), &req)
if err != nil {
return
}
// 更新本地配置文件ParticipantId
utils.UpdateParticipantId(*&common.FileName, strconv.FormatInt(resp.ParticipantId, 10))
}