Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Pixiu cmd files in /cmd/pixiu to pkg/cmd #596

Merged
merged 6 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 0 additions & 70 deletions cmd/pixiu/gateway.go

This file was deleted.

146 changes: 5 additions & 141 deletions cmd/pixiu/pixiu.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
package main

import (
"fmt"
_ "net/http/pprof"
"runtime"
"strconv"
"time"
)
Expand All @@ -30,45 +28,15 @@ import (
)

import (
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/common/constant"
pxruntime "github.com/apache/dubbo-go-pixiu/pixiu/pkg/common/runtime"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/config"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/logger"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/model"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/cmd"
_ "github.com/apache/dubbo-go-pixiu/pixiu/pkg/pluginregistry"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/server"
)

var (
const (
// Version pixiu version
Version = "0.6.0"

flagToLogLevel = map[string]string{
"trace": "TRACE",
"debug": "DEBUG",
"info": "INFO",
"warning": "WARN",
"error": "ERROR",
"critical": "FATAL",
}

configPath string
apiConfigPath string
logConfigPath string
logLevel string

// CURRENTLY USELESS
logFormat string

limitCpus string

// Currently default set to false, wait for up coming support
initFromRemote = false
Version = "1.0.0"
)

// deploy server deployment
var deploy = &DefaultDeployer{}

// main pixiu run method
func main() {
app := getRootCmd()
Expand All @@ -88,112 +56,8 @@ func getRootCmd() *cobra.Command {
Version: Version,
}

rootCmd.AddCommand(gatewayCmd)
rootCmd.AddCommand(sideCarCmd)
rootCmd.AddCommand(cmd.GatewayCmd)
rootCmd.AddCommand(cmd.SideCarCmd)

return rootCmd
}

type DefaultDeployer struct {
bootstrap *model.Bootstrap
configManger *config.ConfigManager
}

func (d *DefaultDeployer) initialize() error {

err := initLog()
if err != nil {
logger.Warnf("[startGatewayCmd] failed to init logger, %s", err.Error())
}

// load Bootstrap config
d.bootstrap = d.configManger.LoadBootConfig(configPath)
if err != nil {
panic(fmt.Errorf("[startGatewayCmd] failed to get api meta config, %s", err.Error()))
}

err = initLimitCpus()
if err != nil {
logger.Errorf("[startCmd] failed to get limit cpu number, %s", err.Error())
}

return err
}

func (d *DefaultDeployer) start() error {
server.Start(d.bootstrap)
return nil
}

func (d *DefaultDeployer) stop() error {
//TODO implement me
panic("implement me")
}

// initDefaultValue If not set both in args and env, set default values
func initDefaultValue() {
if configPath == "" {
configPath = constant.DefaultConfigPath
}

if apiConfigPath == "" {
apiConfigPath = constant.DefaultApiConfigPath
}

if logConfigPath == "" {
logConfigPath = constant.DefaultLogConfigPath
}

if logLevel == "" {
logLevel = constant.DefaultLogLevel
}

if limitCpus == "" {
limitCpus = constant.DefaultLimitCpus
}

if logFormat == "" {
logFormat = constant.DefaultLogFormat
}
}

// initLog
func initLog() error {
err := logger.InitLog(logConfigPath)
if err != nil {
// cause `logger.InitLog` already handle init failed, so just use logger to log
return err
}

if level, ok := flagToLogLevel[logLevel]; ok {
logger.SetLoggerLevel(level)
} else {
logger.SetLoggerLevel(flagToLogLevel[constant.DefaultLogLevel])
return fmt.Errorf("logLevel is invalid, set log level to default: %s", constant.DefaultLogLevel)
}
return nil
}

// initApiConfig return value of the bool is for the judgment of whether is a api meta data error, a kind of silly (?)
func initApiConfig() (*model.Bootstrap, error) {
bootstrap := config.Load(configPath)
return bootstrap, nil
}

func initLimitCpus() error {
limitCpuNumberFromEnv, err := strconv.ParseInt(limitCpus, 10, 64)
if err != nil {
return err
}
limitCpuNumber := int(limitCpuNumberFromEnv)
if limitCpuNumber <= 0 {
limitCpuNumber = pxruntime.GetCPUNum()
}
runtime.GOMAXPROCS(limitCpuNumber)
logger.Infof("GOMAXPROCS set to %v", limitCpuNumber)
return nil
}

func init() {
deploy.configManger = config.NewConfigManger()
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,4 @@ require (
)

replace google.golang.org/protobuf v1.28.1 => google.golang.org/protobuf v1.28.0

2 changes: 1 addition & 1 deletion cmd/pixiu/deployer.go → pixiu/pkg/cmd/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package main
package cmd

type Deployer interface {
initialize() error
Expand Down
Loading
Loading