|
|
@ -16,11 +16,14 @@ package cmd
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/OpenIMSDK/protocol/constant"
|
|
|
|
"github.com/OpenIMSDK/protocol/constant"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/OpenIMSDK/tools/errs"
|
|
|
|
|
|
|
|
|
|
|
|
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/OpenIMSDK/tools/discoveryregistry"
|
|
|
|
"github.com/OpenIMSDK/tools/discoveryregistry"
|
|
|
@ -40,77 +43,81 @@ func NewRpcCmd(name string) *RpcCmd {
|
|
|
|
|
|
|
|
|
|
|
|
func (a *RpcCmd) Exec() error {
|
|
|
|
func (a *RpcCmd) Exec() error {
|
|
|
|
a.Command.Run = func(cmd *cobra.Command, args []string) {
|
|
|
|
a.Command.Run = func(cmd *cobra.Command, args []string) {
|
|
|
|
a.port = a.getPortFlag(cmd)
|
|
|
|
portFlag, err := a.getPortFlag(cmd)
|
|
|
|
a.prometheusPort = a.getPrometheusPortFlag(cmd)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
a.port = portFlag
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var prometheusPort, err = a.getPrometheusPortFlag(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return errs.Wrap(err, "Failed to get Prometheus port")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a.prometheusPort = prometheusPort
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return a.Execute()
|
|
|
|
return a.Execute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (a *RpcCmd) StartSvr(name string, rpcFn func(discov discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error) error {
|
|
|
|
func (a *RpcCmd) StartSvr(name string, rpcFn func(discov discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error) error {
|
|
|
|
if a.GetPortFlag() == 0 {
|
|
|
|
portFlag, err := a.GetPortFlag()
|
|
|
|
return errors.New("port is required")
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return errs.Wrap(err, "error getting port flag")
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
a.port = portFlag
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
portFlag, err = a.GetPortFlag()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return startrpc.Start(a.GetPortFlag(), name, a.GetPrometheusPortFlag(), rpcFn)
|
|
|
|
return startrpc.Start(a.GetPortFlag(), name, a.GetPrometheusPortFlag(), rpcFn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (a *RpcCmd) GetPortFromConfig(portType string) int {
|
|
|
|
func (a *RpcCmd) GetPortFromConfig(portType string) (int, error) {
|
|
|
|
switch a.Name {
|
|
|
|
portConfigMap := map[string]map[string]int{
|
|
|
|
case RpcPushServer:
|
|
|
|
RpcPushServer: {
|
|
|
|
if portType == constant.FlagPort {
|
|
|
|
constant.FlagPort: config2.Config.RpcPort.OpenImPushPort[0],
|
|
|
|
return config2.Config.RpcPort.OpenImPushPort[0]
|
|
|
|
constant.FlagPrometheusPort: config2.Config.Prometheus.PushPrometheusPort[0],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
if portType == constant.FlagPrometheusPort {
|
|
|
|
RpcAuthServer: {
|
|
|
|
return config2.Config.Prometheus.PushPrometheusPort[0]
|
|
|
|
constant.FlagPort: config2.Config.RpcPort.OpenImAuthPort[0],
|
|
|
|
}
|
|
|
|
constant.FlagPrometheusPort: config2.Config.Prometheus.AuthPrometheusPort[0],
|
|
|
|
case RpcAuthServer:
|
|
|
|
},
|
|
|
|
if portType == constant.FlagPort {
|
|
|
|
RpcConversationServer: {
|
|
|
|
return config2.Config.RpcPort.OpenImAuthPort[0]
|
|
|
|
constant.FlagPort: config2.Config.RpcPort.OpenImConversationPort[0],
|
|
|
|
}
|
|
|
|
constant.FlagPrometheusPort: config2.Config.Prometheus.ConversationPrometheusPort[0],
|
|
|
|
if portType == constant.FlagPrometheusPort {
|
|
|
|
},
|
|
|
|
return config2.Config.Prometheus.AuthPrometheusPort[0]
|
|
|
|
RpcFriendServer: {
|
|
|
|
}
|
|
|
|
constant.FlagPort: config2.Config.RpcPort.OpenImFriendPort[0],
|
|
|
|
case RpcConversationServer:
|
|
|
|
constant.FlagPrometheusPort: config2.Config.Prometheus.FriendPrometheusPort[0],
|
|
|
|
if portType == constant.FlagPort {
|
|
|
|
},
|
|
|
|
return config2.Config.RpcPort.OpenImConversationPort[0]
|
|
|
|
RpcGroupServer: {
|
|
|
|
}
|
|
|
|
constant.FlagPort: config2.Config.RpcPort.OpenImGroupPort[0],
|
|
|
|
if portType == constant.FlagPrometheusPort {
|
|
|
|
constant.FlagPrometheusPort: config2.Config.Prometheus.GroupPrometheusPort[0],
|
|
|
|
return config2.Config.Prometheus.ConversationPrometheusPort[0]
|
|
|
|
},
|
|
|
|
}
|
|
|
|
RpcMsgServer: {
|
|
|
|
case RpcFriendServer:
|
|
|
|
constant.FlagPort: config2.Config.RpcPort.OpenImMessagePort[0],
|
|
|
|
if portType == constant.FlagPort {
|
|
|
|
constant.FlagPrometheusPort: config2.Config.Prometheus.MessagePrometheusPort[0],
|
|
|
|
return config2.Config.RpcPort.OpenImFriendPort[0]
|
|
|
|
},
|
|
|
|
}
|
|
|
|
RpcThirdServer: {
|
|
|
|
if portType == constant.FlagPrometheusPort {
|
|
|
|
constant.FlagPort: config2.Config.RpcPort.OpenImThirdPort[0],
|
|
|
|
return config2.Config.Prometheus.FriendPrometheusPort[0]
|
|
|
|
constant.FlagPrometheusPort: config2.Config.Prometheus.ThirdPrometheusPort[0],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
case RpcGroupServer:
|
|
|
|
RpcUserServer: {
|
|
|
|
if portType == constant.FlagPort {
|
|
|
|
constant.FlagPort: config2.Config.RpcPort.OpenImUserPort[0],
|
|
|
|
return config2.Config.RpcPort.OpenImGroupPort[0]
|
|
|
|
constant.FlagPrometheusPort: config2.Config.Prometheus.UserPrometheusPort[0],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
if portType == constant.FlagPrometheusPort {
|
|
|
|
}
|
|
|
|
return config2.Config.Prometheus.GroupPrometheusPort[0]
|
|
|
|
|
|
|
|
}
|
|
|
|
if portMap, ok := portConfigMap[a.Name]; ok {
|
|
|
|
case RpcMsgServer:
|
|
|
|
if port, ok := portMap[portType]; ok {
|
|
|
|
if portType == constant.FlagPort {
|
|
|
|
return port, nil
|
|
|
|
return config2.Config.RpcPort.OpenImMessagePort[0]
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
return 0, errs.Wrap(errs.New("port type '%s' not found", portType), fmt.Sprintf("Failed to get port for %s", a.Name))
|
|
|
|
if portType == constant.FlagPrometheusPort {
|
|
|
|
|
|
|
|
return config2.Config.Prometheus.MessagePrometheusPort[0]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case RpcThirdServer:
|
|
|
|
|
|
|
|
if portType == constant.FlagPort {
|
|
|
|
|
|
|
|
return config2.Config.RpcPort.OpenImThirdPort[0]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if portType == constant.FlagPrometheusPort {
|
|
|
|
|
|
|
|
return config2.Config.Prometheus.ThirdPrometheusPort[0]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case RpcUserServer:
|
|
|
|
|
|
|
|
if portType == constant.FlagPort {
|
|
|
|
|
|
|
|
return config2.Config.RpcPort.OpenImUserPort[0]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if portType == constant.FlagPrometheusPort {
|
|
|
|
|
|
|
|
return config2.Config.Prometheus.UserPrometheusPort[0]
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
return 0, errs.Wrap(fmt.Errorf("server name '%s' not found", a.Name), "Failed to get port configuration")
|
|
|
|
}
|
|
|
|
}
|
|
|
|