forked from JointCloud/pcm-openstack
97 lines
2.6 KiB
Go
97 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"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-participant-openstack/internal/config"
|
|
"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/interceptor/rpcserver"
|
|
commonConfig "gitlink.org.cn/jcce-pcm/utils/nacos"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/reflection"
|
|
)
|
|
|
|
var configFile = flag.String("f", "etc/pcmopenstack.yaml", "the config file")
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
var bootstrapConfig commonConfig.BootstrapConfig
|
|
conf.MustLoad(*configFile, &bootstrapConfig)
|
|
|
|
//解析业务配置
|
|
var c config.Config
|
|
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)
|
|
|
|
ctx := svc.NewServiceContext(c)
|
|
ctx.Cron.Start()
|
|
|
|
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
|
openstack.RegisterOpenstackServer(grpcServer, server.NewOpenstackServer(ctx))
|
|
|
|
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
|
reflection.Register(grpcServer)
|
|
}
|
|
})
|
|
|
|
//rpc log
|
|
s.AddUnaryInterceptors(rpcserver.LoggerInterceptor)
|
|
|
|
defer s.Stop()
|
|
|
|
logx.Infof("Starting rpc server at %s...\n", c.ListenOn)
|
|
//logic.InitCron(ctx)
|
|
s.Start()
|
|
|
|
}
|
|
|
|
/*// PushParticipantInfo 推送p端静态信息
|
|
func PushParticipantInfo(config config.Config, participantService participantservice.ParticipantService) {
|
|
participantId, err := tool.GetParticipantId(*configFile)
|
|
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(*configFile, strconv.FormatInt(resp.ParticipantId, 10))
|
|
}*/
|