mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-06 04:49:48 -06:00
added command categories (extensions, fullstack) + reduce complexity metrics hopefully
This commit is contained in:
@@ -17,9 +17,10 @@ import (
|
||||
// GraphCommand is the entrypoint for the graph command.
|
||||
func GraphCommand(cfg *config.Config) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "graph",
|
||||
Usage: "Start graph server",
|
||||
Flags: flagset.ServerWithConfig(cfg.Graph),
|
||||
Name: "graph",
|
||||
Usage: "Start graph server",
|
||||
Flags: flagset.ServerWithConfig(cfg.Graph),
|
||||
Category: "Extensions",
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureGraph(cfg)
|
||||
|
||||
|
||||
@@ -18,9 +18,10 @@ import (
|
||||
// HelloCommand is the entrypoint for the hello command.
|
||||
func HelloCommand(cfg *config.Config) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "hello",
|
||||
Usage: "Start hello server",
|
||||
Flags: flagset.ServerWithConfig(cfg.Hello),
|
||||
Name: "hello",
|
||||
Usage: "Start hello server",
|
||||
Flags: flagset.ServerWithConfig(cfg.Hello),
|
||||
Category: "Extensions",
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureHello(cfg)
|
||||
|
||||
|
||||
@@ -17,9 +17,10 @@ import (
|
||||
// KonnectdCommand is the entrypoint for the konnectd command.
|
||||
func KonnectdCommand(cfg *config.Config) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "konnectd",
|
||||
Usage: "Start konnectd server",
|
||||
Flags: flagset.ServerWithConfig(cfg.Konnectd),
|
||||
Name: "konnectd",
|
||||
Usage: "Start konnectd server",
|
||||
Category: "Extensions",
|
||||
Flags: flagset.ServerWithConfig(cfg.Konnectd),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureKonnectd(cfg)
|
||||
|
||||
|
||||
@@ -17,9 +17,10 @@ import (
|
||||
// OCSCommand is the entrypoint for the ocs command.
|
||||
func OCSCommand(cfg *config.Config) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "ocs",
|
||||
Usage: "Start ocs server",
|
||||
Flags: flagset.ServerWithConfig(cfg.OCS),
|
||||
Name: "ocs",
|
||||
Usage: "Start ocs server",
|
||||
Category: "Extensions",
|
||||
Flags: flagset.ServerWithConfig(cfg.OCS),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureOCS(cfg)
|
||||
|
||||
|
||||
@@ -17,9 +17,10 @@ import (
|
||||
// PhoenixCommand is the entrypoint for the phoenix command.
|
||||
func PhoenixCommand(cfg *config.Config) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "phoenix",
|
||||
Usage: "Start phoenix server",
|
||||
Flags: flagset.ServerWithConfig(cfg.Phoenix),
|
||||
Name: "phoenix",
|
||||
Usage: "Start phoenix server",
|
||||
Flags: flagset.ServerWithConfig(cfg.Phoenix),
|
||||
Category: "Extensions",
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configurePhoenix(cfg)
|
||||
|
||||
|
||||
@@ -99,28 +99,6 @@ func Execute() error {
|
||||
},
|
||||
}
|
||||
|
||||
// register micro runtime services.
|
||||
// TODO(refs) use the registry? Some interfaces would need to be tweaked
|
||||
app.Commands = append(app.Commands, api.Commands()...)
|
||||
app.Commands = append(app.Commands, bot.Commands()...)
|
||||
app.Commands = append(app.Commands, broker.Commands()...)
|
||||
app.Commands = append(app.Commands, health.Commands()...)
|
||||
app.Commands = append(app.Commands, proxy.Commands()...)
|
||||
app.Commands = append(app.Commands, monitor.Commands()...)
|
||||
app.Commands = append(app.Commands, router.Commands()...)
|
||||
app.Commands = append(app.Commands, tunnel.Commands()...)
|
||||
app.Commands = append(app.Commands, network.Commands()...)
|
||||
app.Commands = append(app.Commands, registry.Commands()...)
|
||||
app.Commands = append(app.Commands, runtime.Commands()...)
|
||||
app.Commands = append(app.Commands, debug.Commands()...)
|
||||
app.Commands = append(app.Commands, server.Commands()...)
|
||||
app.Commands = append(app.Commands, service.Commands()...)
|
||||
app.Commands = append(app.Commands, store.Commands()...)
|
||||
app.Commands = append(app.Commands, token.Commands()...)
|
||||
app.Commands = append(app.Commands, new.Commands()...)
|
||||
app.Commands = append(app.Commands, build.Commands()...)
|
||||
app.Commands = append(app.Commands, web.Commands()...)
|
||||
|
||||
for _, fn := range register.Commands {
|
||||
app.Commands = append(
|
||||
app.Commands,
|
||||
@@ -128,6 +106,9 @@ func Execute() error {
|
||||
)
|
||||
}
|
||||
|
||||
// adds micro runtime specific set of commands
|
||||
addRuntime(app)
|
||||
|
||||
cli.HelpFlag = &cli.BoolFlag{
|
||||
Name: "help,h",
|
||||
Usage: "Show the help",
|
||||
@@ -150,3 +131,25 @@ func NewLogger(cfg *config.Config) log.Logger {
|
||||
log.Color(cfg.Log.Color),
|
||||
)
|
||||
}
|
||||
|
||||
func addRuntime(app *cli.App) {
|
||||
app.Commands = append(app.Commands, api.Commands()...)
|
||||
app.Commands = append(app.Commands, bot.Commands()...)
|
||||
app.Commands = append(app.Commands, broker.Commands()...)
|
||||
app.Commands = append(app.Commands, health.Commands()...)
|
||||
app.Commands = append(app.Commands, proxy.Commands()...)
|
||||
app.Commands = append(app.Commands, monitor.Commands()...)
|
||||
app.Commands = append(app.Commands, router.Commands()...)
|
||||
app.Commands = append(app.Commands, tunnel.Commands()...)
|
||||
app.Commands = append(app.Commands, network.Commands()...)
|
||||
app.Commands = append(app.Commands, registry.Commands()...)
|
||||
app.Commands = append(app.Commands, runtime.Commands()...)
|
||||
app.Commands = append(app.Commands, debug.Commands()...)
|
||||
app.Commands = append(app.Commands, server.Commands()...)
|
||||
app.Commands = append(app.Commands, service.Commands()...)
|
||||
app.Commands = append(app.Commands, store.Commands()...)
|
||||
app.Commands = append(app.Commands, token.Commands()...)
|
||||
app.Commands = append(app.Commands, new.Commands()...)
|
||||
app.Commands = append(app.Commands, build.Commands()...)
|
||||
app.Commands = append(app.Commands, web.Commands()...)
|
||||
}
|
||||
|
||||
@@ -15,18 +15,44 @@ import (
|
||||
gorun "github.com/micro/go-micro/runtime"
|
||||
openzipkin "github.com/openzipkin/zipkin-go"
|
||||
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
|
||||
"github.com/owncloud/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/pkg/config"
|
||||
"github.com/owncloud/ocis/pkg/flagset"
|
||||
"go.opencensus.io/stats/view"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
// Services to start as part of the fullstack option
|
||||
var services = []string{
|
||||
"network", // :8085
|
||||
"runtime", // :8088
|
||||
"registry", // :8000
|
||||
"broker", // :8001
|
||||
"store", // :8002
|
||||
"tunnel", // :8083
|
||||
"router", // :8084
|
||||
"monitor", // :????
|
||||
"debug", // :????
|
||||
"proxy", // :8081
|
||||
"api", // :8080
|
||||
"web", // :8082
|
||||
"bot", // :????
|
||||
|
||||
// extensions
|
||||
"hello",
|
||||
"phoenix",
|
||||
"graph",
|
||||
"ocs",
|
||||
"webdav",
|
||||
}
|
||||
|
||||
// Server is the entrypoint for the server command.
|
||||
func Server(cfg *config.Config) cli.Command {
|
||||
app := cli.Command{
|
||||
Name: "server",
|
||||
Usage: "Start fullstack server",
|
||||
Flags: flagset.ServerWithConfig(cfg),
|
||||
Name: "server",
|
||||
Usage: "Start fullstack server",
|
||||
Category: "Fullstack",
|
||||
Flags: flagset.ServerWithConfig(cfg),
|
||||
Before: func(c *cli.Context) error {
|
||||
if cfg.HTTP.Root != "/" {
|
||||
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
|
||||
@@ -121,77 +147,59 @@ func Server(cfg *config.Config) cli.Command {
|
||||
Msg("Tracing is not enabled")
|
||||
}
|
||||
|
||||
// by the time we reach this point, all micro runtime services subcommands
|
||||
// should be available for being initialized
|
||||
muRuntime := cmd.DefaultCmd.Options().Runtime
|
||||
env := os.Environ()
|
||||
mruntime := cmd.DefaultCmd.Options().Runtime
|
||||
|
||||
services := []string{
|
||||
"network", // :8085
|
||||
"runtime", // :8088
|
||||
"registry", // :8000
|
||||
"broker", // :8001
|
||||
"store", // :8002
|
||||
"tunnel", // :8083
|
||||
"router", // :8084
|
||||
"monitor", // :????
|
||||
"debug", // :????
|
||||
"proxy", // :8081
|
||||
"api", // :8080
|
||||
"web", // :8082
|
||||
"bot", // :????
|
||||
|
||||
// ocis extensions
|
||||
"hello",
|
||||
"phoenix",
|
||||
"graph",
|
||||
"ocs",
|
||||
"webdav",
|
||||
}
|
||||
|
||||
for _, service := range services {
|
||||
args := []gorun.CreateOption{
|
||||
gorun.WithCommand(os.Args[0], service),
|
||||
gorun.WithEnv(env),
|
||||
gorun.WithOutput(os.Stdout),
|
||||
}
|
||||
|
||||
muService := &gorun.Service{Name: service}
|
||||
if err := (*muRuntime).Create(muService, args...); err != nil {
|
||||
logger.Error().Msgf("Failed to create runtime enviroment: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
shutdown := make(chan os.Signal, 1)
|
||||
signal.Notify(shutdown, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
|
||||
|
||||
logger.Info().Msg("Starting service runtime")
|
||||
|
||||
// start the runtime
|
||||
if err := (*muRuntime).Start(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger.Info().Msgf("Service runtime started")
|
||||
|
||||
select {
|
||||
case <-shutdown:
|
||||
logger.Info().Msg("shutdown signal received")
|
||||
logger.Info().Msg("stopping service runtime")
|
||||
}
|
||||
|
||||
// stop all the things
|
||||
if err := (*muRuntime).Stop(); err != nil {
|
||||
logger.Err(err)
|
||||
}
|
||||
|
||||
logger.Info().Msgf("Service runtime shutdown")
|
||||
|
||||
// exit success
|
||||
os.Exit(0)
|
||||
// fork uses the micro runtime to fork go-micro services
|
||||
forkServices(logger, mruntime)
|
||||
|
||||
// trap blocks until a kill signal is sent
|
||||
trap(logger, mruntime)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
func trap(logger log.Logger, runtime *gorun.Runtime) {
|
||||
shutdown := make(chan os.Signal, 1)
|
||||
signal.Notify(shutdown, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
|
||||
|
||||
logger.Info().Msg("Starting service runtime")
|
||||
if err := (*runtime).Start(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger.Info().Msgf("Service runtime started")
|
||||
|
||||
select {
|
||||
case <-shutdown:
|
||||
logger.Info().Msg("shutdown signal received")
|
||||
logger.Info().Msg("stopping service runtime")
|
||||
}
|
||||
|
||||
if err := (*runtime).Stop(); err != nil {
|
||||
logger.Err(err)
|
||||
}
|
||||
|
||||
logger.Info().Msgf("Service runtime shutdown")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func forkServices(logger log.Logger, runtime *gorun.Runtime) {
|
||||
env := os.Environ()
|
||||
|
||||
for _, service := range services {
|
||||
args := []gorun.CreateOption{
|
||||
// the binary calls itself with the micro service as a subcommand as first argument
|
||||
gorun.WithCommand(os.Args[0], service),
|
||||
gorun.WithEnv(env),
|
||||
// and logs to STDOUT. Perhaps this can be overridden to use a log.Logger
|
||||
gorun.WithOutput(os.Stdout),
|
||||
}
|
||||
|
||||
muService := &gorun.Service{Name: service}
|
||||
if err := (*runtime).Create(muService, args...); err != nil {
|
||||
logger.Error().Msgf("Failed to create runtime enviroment: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,10 @@ import (
|
||||
// WebDAVCommand is the entrypoint for the webdav command.
|
||||
func WebDAVCommand(cfg *config.Config) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "webdav",
|
||||
Usage: "Start webdav server",
|
||||
Flags: flagset.ServerWithConfig(cfg.WebDAV),
|
||||
Name: "webdav",
|
||||
Usage: "Start webdav server",
|
||||
Category: "Extensions",
|
||||
Flags: flagset.ServerWithConfig(cfg.WebDAV),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureWebDAV(cfg)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user