forked from jcce-pcm/pcm-openstack
100 lines
3.2 KiB
Go
100 lines
3.2 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/jcce-pcm/pcm-coordinator/rpc/client/participantservice"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/pcmCore"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/common"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/config"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/pkg/cron"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/server"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/svc"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/openstack"
|
|
"gitlink.org.cn/jcce-pcm/utils/tool"
|
|
"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)
|
|
//common.GenerateToken()
|
|
//解析业务配置
|
|
//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 := tool.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{}
|
|
tool.Convert(config.Participant, &req)
|
|
req.ParticipantId = participantId
|
|
req.LabelInfo = labels
|
|
//
|
|
resp, err := participantService.RegisterParticipant(context.Background(), &req)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
// 更新本地配置文件ParticipantId
|
|
tool.UpdateParticipantId(*&common.FileName, strconv.FormatInt(resp.ParticipantId, 10))
|
|
}
|