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

simple refactoring #1199

Merged
merged 3 commits into from
Jul 17, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion pkg/authority/v1alpha1/ca.pb.go → api/mesh/ca.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
10 changes: 5 additions & 5 deletions pkg/authority/v1alpha1/ca_grpc.pb.go → api/mesh/ca_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
90 changes: 90 additions & 0 deletions app/dubbo-cp/cmd/console.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cmd

import (
"fmt"
"github.com/apache/dubbo-admin/pkg/admin"
"github.com/apache/dubbo-admin/pkg/config"
dubbo_cp "github.com/apache/dubbo-admin/pkg/config/app/dubbo-cp"
"github.com/apache/dubbo-admin/pkg/core/bootstrap"
"github.com/apache/dubbo-admin/pkg/core/cmd"
"github.com/apache/dubbo-admin/pkg/core/logger"
"github.com/spf13/cobra"
"time"
)

func newConsoleCmdWithOpts(opts cmd.RunCmdOpts) *cobra.Command {
args := struct {
configPath string
}{}

cmd := &cobra.Command{
Use: "console",
Short: "Launch Dubbo Admin console server.",
Long: `Launch Dubbo Admin console server.`,
RunE: func(cmd *cobra.Command, _ []string) error {
cfg := dubbo_cp.DefaultConfig()
err := config.Load(args.configPath, &cfg)
if err != nil {
logger.Sugar().Error(err, "could not load the configuration")
return err
}
gracefulCtx, ctx := opts.SetupSignalHandler()

rt, err := bootstrap.Bootstrap(gracefulCtx, &cfg)
if err != nil {
logger.Sugar().Error(err, "unable to set up Control Plane runtime")
return err
}
cfgForDisplay, err := config.ConfigForDisplay(&cfg)
if err != nil {
logger.Sugar().Error(err, "unable to prepare config for display")
return err
}
cfgBytes, err := config.ToJson(cfgForDisplay)
if err != nil {
logger.Sugar().Error(err, "unable to convert config to json")
return err
}
logger.Sugar().Info(fmt.Sprintf("Current config %s", cfgBytes))

if err := admin.Setup(rt); err != nil {
logger.Sugar().Error(err, "unable to set up Metrics")
}
logger.Sugar().Info("starting Control Plane")
if err := rt.Start(gracefulCtx.Done()); err != nil {
logger.Sugar().Error(err, "problem running Control Plane")
return err
}

logger.Sugar().Info("Stop signal received. Waiting 3 seconds for components to stop gracefully...")
select {
case <-ctx.Done():
case <-time.After(gracefullyShutdownDuration):
}
logger.Sugar().Info("Stopping Control Plane")
return nil
},
}

// flags
cmd.PersistentFlags().StringVarP(&args.configPath, "config-file", "c", "", "configuration file")

return cmd
}
28 changes: 22 additions & 6 deletions cmd/admin/cmd/root.go → app/dubbo-cp/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cmd

import (
"github.com/apache/dubbo-admin/pkg/logger"
"github.com/apache/dubbo-admin/pkg/version"

corecmd "github.com/apache/dubbo-admin/pkg/core/cmd"

cmd2 "github.com/apache/dubbo-admin/pkg/core/cmd"
"github.com/apache/dubbo-admin/pkg/core/cmd/version"
"github.com/apache/dubbo-admin/pkg/core/logger"
"github.com/spf13/cobra"
"os"
)
Expand Down Expand Up @@ -38,7 +53,8 @@ func GetRootCmd(args []string) *cobra.Command {
//cmd.PersistentFlags().IntVar(&args.maxAge, "log-max-age", 30, "maximum number of days to retain old log files based on the timestamp encoded in their filename")

// sub-commands
cmd.AddCommand(newRunCmdWithOpts(corecmd.DefaultRunCmdOpts))
cmd.AddCommand(newRunCmdWithOpts(cmd2.DefaultRunCmdOpts))
cmd.AddCommand(newConsoleCmdWithOpts(cmd2.DefaultRunCmdOpts))
cmd.AddCommand(version.NewVersionCmd())

return cmd
Expand Down
116 changes: 116 additions & 0 deletions app/dubbo-cp/cmd/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cmd

import (
"fmt"
"github.com/apache/dubbo-admin/pkg/admin"
"github.com/apache/dubbo-admin/pkg/authority"
"github.com/apache/dubbo-admin/pkg/config"
dubbo_cp "github.com/apache/dubbo-admin/pkg/config/app/dubbo-cp"
"github.com/apache/dubbo-admin/pkg/core/bootstrap"
"github.com/apache/dubbo-admin/pkg/core/cert"
"github.com/apache/dubbo-admin/pkg/core/cmd"
"github.com/apache/dubbo-admin/pkg/core/logger"
"github.com/apache/dubbo-admin/pkg/cp-server"
"github.com/apache/dubbo-admin/pkg/rule"
"github.com/spf13/cobra"
"time"
)

const gracefullyShutdownDuration = 3 * time.Second

// This is the open file limit below which the control plane may not
// reasonably have enough descriptors to accept all its clients.
const minOpenFileLimit = 4096

func newRunCmdWithOpts(opts cmd.RunCmdOpts) *cobra.Command {
args := struct {
configPath string
}{}
cmd := &cobra.Command{
Use: "run",
Short: "Launch Dubbo Admin",
Long: `Launch Dubbo Admin.`,
RunE: func(cmd *cobra.Command, _ []string) error {
cfg := dubbo_cp.DefaultConfig()
err := config.Load(args.configPath, &cfg)
if err != nil {
logger.Sugar().Error(err, "could not load the configuration")
return err
}
gracefulCtx, ctx := opts.SetupSignalHandler()

rt, err := bootstrap.Bootstrap(gracefulCtx, &cfg)
if err != nil {
logger.Sugar().Error(err, "unable to set up Control Plane runtime")
return err
}
cfgForDisplay, err := config.ConfigForDisplay(&cfg)
if err != nil {
logger.Sugar().Error(err, "unable to prepare config for display")
return err
}
cfgBytes, err := config.ToJson(cfgForDisplay)
if err != nil {
logger.Sugar().Error(err, "unable to convert config to json")
return err
}
logger.Sugar().Info(fmt.Sprintf("Current config %s", cfgBytes))

if err := admin.Setup(rt); err != nil {
logger.Sugar().Error(err, "unable to set up Metrics")
}

if err := cert.Setup(rt); err != nil {
logger.Sugar().Error(err, "unable to set up certProvider")
}

if err := authority.Setup(rt); err != nil {
logger.Sugar().Error(err, "unable to set up authority")
}

if err := rule.Setup(rt); err != nil {
logger.Sugar().Error(err, "unable to set up rule")
}

if err := cp_server.Setup(rt); err != nil {
logger.Sugar().Error(err, "unable to set up grpc server")
}

logger.Sugar().Info("starting Control Plane")
if err := rt.Start(gracefulCtx.Done()); err != nil {
logger.Sugar().Error(err, "problem running Control Plane")
return err
}

logger.Sugar().Info("Stop signal received. Waiting 3 seconds for components to stop gracefully...")
select {
case <-ctx.Done():
case <-time.After(gracefullyShutdownDuration):
}
logger.Sugar().Info("Stopping Control Plane")
return nil
},
}

// flags
cmd.PersistentFlags().StringVarP(&args.configPath, "config-file", "c", "", "configuration file")

return cmd
}
3 changes: 2 additions & 1 deletion cmd/admin/main.go → app/dubbo-cp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ package main

import (
"fmt"
"github.com/apache/dubbo-admin/cmd/admin/cmd"
"os"

"github.com/apache/dubbo-admin/app/dubbo-cp/cmd"
)

func main() {
Expand Down
File renamed without changes.
File renamed without changes.

Large diffs are not rendered by default.

File renamed without changes.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package cmd

import (
subcmd "github.com/apache/dubbo-admin/pkg/dubboctl/cmd/subcmd"
subcmd "github.com/apache/dubbo-admin/app/dubboctl/cmd/subcmd"
"github.com/spf13/cobra"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strings"
"testing"

"github.com/apache/dubbo-admin/pkg/dubboctl/cmd/subcmd"
"github.com/apache/dubbo-admin/app/dubboctl/cmd/subcmd"

"sigs.k8s.io/controller-runtime/pkg/client/fake"
)
Expand All @@ -38,15 +38,15 @@ func TestManifestGenerate(t *testing.T) {
cmd: "manifest generate",
},
{
desc: "setting specification of built-in component",
desc: "setting specification of built-in bootstrap",
cmd: "manifest generate --set spec.components.nacos.replicas=3",
},
{
desc: "setting specification of add-on component",
desc: "setting specification of add-on bootstrap",
cmd: "manifest generate --set spec.components.grafana.replicas=3",
},
{
desc: "disabling component",
desc: "disabling bootstrap",
cmd: "manifest generate --set spec.componentsMeta.nacos.enabled=false",
},
{
Expand All @@ -55,11 +55,11 @@ func TestManifestGenerate(t *testing.T) {
" --set spec.componentsMeta.grafana.version=6.31.0",
},
{
desc: "setting specification of built-in component with wrong path",
desc: "setting specification of built-in bootstrap with wrong path",
cmd: "manifest generate --set components.nacos.replicas=3",
},
{
desc: "setting specification of built-in component with wrong path",
desc: "setting specification of built-in bootstrap with wrong path",
cmd: "manifest generate --set components.grafana.replicas=3",
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package cmd

import (
"github.com/apache/dubbo-admin/pkg/dubboctl/cmd/subcmd"
"github.com/apache/dubbo-admin/app/dubboctl/cmd/subcmd"
"github.com/spf13/cobra"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package subcmd
import (
"errors"
"fmt"
"github.com/apache/dubbo-admin/pkg/core/logger"
"os"
"path/filepath"
"strings"

"github.com/apache/dubbo-admin/pkg/dubboctl/internal/kube"
"github.com/apache/dubbo-admin/pkg/logger"
"github.com/apache/dubbo-admin/app/dubboctl/internal/kube"
"github.com/spf13/cobra"
"go.uber.org/zap/zapcore"
)
Expand Down
Loading
Loading