Skip to content

Commit

Permalink
Support multiple roles for banyand
Browse files Browse the repository at this point in the history
Signed-off-by: Gao Hongtao <[email protected]>
  • Loading branch information
hanahmily committed Jul 19, 2023
1 parent 056624a commit 0f0966c
Show file tree
Hide file tree
Showing 17 changed files with 470 additions and 64 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Release Notes.
- List all properties in a group.
- Implement Write-ahead Logging
- Document the clustering.
- Support multiple roles for banyand server.

### Bugs

Expand Down
108 changes: 108 additions & 0 deletions banyand/internal/cmd/liaison.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Licensed to 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. Apache Software Foundation (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 (
"context"
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/apache/skywalking-banyandb/banyand/discovery"
"github.com/apache/skywalking-banyandb/banyand/liaison"
"github.com/apache/skywalking-banyandb/banyand/liaison/http"
"github.com/apache/skywalking-banyandb/banyand/metadata"
"github.com/apache/skywalking-banyandb/banyand/observability"
"github.com/apache/skywalking-banyandb/banyand/queue"
"github.com/apache/skywalking-banyandb/pkg/config"
"github.com/apache/skywalking-banyandb/pkg/logger"
"github.com/apache/skywalking-banyandb/pkg/run"
"github.com/apache/skywalking-banyandb/pkg/signal"
"github.com/apache/skywalking-banyandb/pkg/version"
)

var liaisonGroup = run.NewGroup("liaison")

func newLiaisonCmd() *cobra.Command {
l := logger.GetLogger("bootstrap")
ctx := context.Background()
repo, err := discovery.NewServiceRepo(ctx)
if err != nil {
l.Fatal().Err(err).Msg("failed to initiate service repository")
}
// nolint: staticcheck
pipeline, err := queue.NewQueue(ctx, repo)
if err != nil {
l.Fatal().Err(err).Msg("failed to initiate data pipeline")
}
metaSvc, err := metadata.NewClient(ctx)
if err != nil {
l.Fatal().Err(err).Msg("failed to initiate metadata service")
}
tcp, err := liaison.NewEndpoint(ctx, pipeline, repo, metaSvc)
if err != nil {
l.Fatal().Err(err).Msg("failed to initiate Endpoint transport layer")
}
profSvc := observability.NewProfService()
metricSvc := observability.NewMetricService()
httpServer := http.NewService()

units := []run.Unit{
new(signal.Handler),
repo,
pipeline,
tcp,
httpServer,
profSvc,
}
if metricSvc != nil {
units = append(units, metricSvc)
}
// Meta the run Group units.
liaisonGroup.Register(units...)
logging := logger.Logging{}
liaisonCmd := &cobra.Command{
Use: "liaison",
Version: version.Build(),
Short: "Run as the liaison server",
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
if err = config.Load("logging", cmd.Flags()); err != nil {
return err
}
return logger.Init(logging)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
fmt.Print(logo)
logger.GetLogger().Info().Msg("starting as a liaison server")
// Spawn our go routines and wait for shutdown.
if err := liaisonGroup.Run(); err != nil {
logger.GetLogger().Error().Err(err).Stack().Str("name", liaisonGroup.Name()).Msg("Exit")
os.Exit(-1)
}
return nil
},
}

liaisonCmd.Flags().StringVar(&logging.Env, "logging-env", "prod", "the logging")
liaisonCmd.Flags().StringVar(&logging.Level, "logging-level", "info", "the root level of logging")
liaisonCmd.Flags().StringArrayVar(&logging.Modules, "logging-modules", nil, "the specific module")
liaisonCmd.Flags().StringArrayVar(&logging.Levels, "logging-levels", nil, "the level logging of logging")
liaisonCmd.Flags().AddFlagSet(liaisonGroup.RegisterFlags().FlagSet)
return liaisonCmd
}
87 changes: 87 additions & 0 deletions banyand/internal/cmd/meta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Licensed to 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. Apache Software Foundation (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 (
"context"
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/apache/skywalking-banyandb/banyand/metadata"
"github.com/apache/skywalking-banyandb/banyand/observability"
"github.com/apache/skywalking-banyandb/pkg/config"
"github.com/apache/skywalking-banyandb/pkg/logger"
"github.com/apache/skywalking-banyandb/pkg/run"
"github.com/apache/skywalking-banyandb/pkg/signal"
"github.com/apache/skywalking-banyandb/pkg/version"
)

var metaGroup = run.NewGroup("meta")

func newMetaCmd() *cobra.Command {
l := logger.GetLogger("bootstrap")
ctx := context.Background()
metaSvc, err := metadata.NewService(ctx)
if err != nil {
l.Fatal().Err(err).Msg("failed to initiate metadata service")
}
profSvc := observability.NewProfService()
metricSvc := observability.NewMetricService()

units := []run.Unit{
new(signal.Handler),
metaSvc,
profSvc,
}
if metricSvc != nil {
units = append(units, metricSvc)
}
// Meta the run Group units.
metaGroup.Register(units...)
logging := logger.Logging{}
metaCmd := &cobra.Command{
Use: "meta",
Version: version.Build(),
Short: "Run as the meta server",
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
if err = config.Load("logging", cmd.Flags()); err != nil {
return err
}
return logger.Init(logging)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
fmt.Print(logo)
logger.GetLogger().Info().Msg("starting as a meta server")
// Spawn our go routines and wait for shutdown.
if err := metaGroup.Run(); err != nil {
logger.GetLogger().Error().Err(err).Stack().Str("name", metaGroup.Name()).Msg("Exit")
os.Exit(-1)
}
return nil
},
}

metaCmd.Flags().StringVar(&logging.Env, "logging-env", "prod", "the logging")
metaCmd.Flags().StringVar(&logging.Level, "logging-level", "info", "the root level of logging")
metaCmd.Flags().StringArrayVar(&logging.Modules, "logging-modules", nil, "the specific module")
metaCmd.Flags().StringArrayVar(&logging.Levels, "logging-levels", nil, "the level logging of logging")
metaCmd.Flags().AddFlagSet(metaGroup.RegisterFlags().FlagSet)
return metaCmd
}
3 changes: 3 additions & 0 deletions banyand/internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ BanyanDB, as an observability database, aims to ingest, analyze and store Metric
`,
}
cmd.AddCommand(newStandaloneCmd())
cmd.AddCommand(newMetaCmd())
cmd.AddCommand(newStorageCmd())
cmd.AddCommand(newLiaisonCmd())
return cmd
}
14 changes: 7 additions & 7 deletions banyand/internal/cmd/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
"github.com/apache/skywalking-banyandb/pkg/version"
)

var g = run.NewGroup("standalone")
var standaloneGroup = run.NewGroup("standalone")

func newStandaloneCmd() *cobra.Command {
l := logger.GetLogger("bootstrap")
Expand All @@ -65,7 +65,7 @@ func newStandaloneCmd() *cobra.Command {
if err != nil {
l.Fatal().Err(err).Msg("failed to initiate measure service")
}
q, err := query.NewService(ctx, streamSvc, measureSvc, metaSvc, repo, pipeline)
q, err := query.NewService(ctx, streamSvc, measureSvc, metaSvc, pipeline)
if err != nil {
l.Fatal().Err(err).Msg("failed to initiate query processor")
}
Expand Down Expand Up @@ -93,12 +93,12 @@ func newStandaloneCmd() *cobra.Command {
units = append(units, metricSvc)
}
// Meta the run Group units.
g.Register(units...)
standaloneGroup.Register(units...)
logging := logger.Logging{}
standaloneCmd := &cobra.Command{
Use: "standalone",
Version: version.Build(),
Short: "Run as the standalone mode",
Short: "Run as the standalone server",
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
if err = config.Load("logging", cmd.Flags()); err != nil {
return err
Expand All @@ -109,8 +109,8 @@ func newStandaloneCmd() *cobra.Command {
fmt.Print(logo)
logger.GetLogger().Info().Msg("starting as a standalone server")
// Spawn our go routines and wait for shutdown.
if err := g.Run(); err != nil {
logger.GetLogger().Error().Err(err).Stack().Str("name", g.Name()).Msg("Exit")
if err := standaloneGroup.Run(); err != nil {
logger.GetLogger().Error().Err(err).Stack().Str("name", standaloneGroup.Name()).Msg("Exit")
os.Exit(-1)
}
return nil
Expand All @@ -121,6 +121,6 @@ func newStandaloneCmd() *cobra.Command {
standaloneCmd.Flags().StringVar(&logging.Level, "logging-level", "info", "the root level of logging")
standaloneCmd.Flags().StringArrayVar(&logging.Modules, "logging-modules", nil, "the specific module")
standaloneCmd.Flags().StringArrayVar(&logging.Levels, "logging-levels", nil, "the level logging of logging")
standaloneCmd.Flags().AddFlagSet(g.RegisterFlags().FlagSet)
standaloneCmd.Flags().AddFlagSet(standaloneGroup.RegisterFlags().FlagSet)
return standaloneCmd
}
Loading

0 comments on commit 0f0966c

Please sign in to comment.