cmd/multinode: create schema command added, run command bug fixed
Change-Id: Ief76fc4a878441e5f112bd79810c66e8d85d7acb
This commit is contained in:
parent
f8d3a977fa
commit
e6967720cd
@ -36,6 +36,11 @@ var (
|
||||
Short: "Run the multinode dashboard",
|
||||
RunE: cmdRun,
|
||||
}
|
||||
createSchemaCmd = &cobra.Command{
|
||||
Use: "create-schema",
|
||||
Short: "Create schemas for multinode dashboard databases",
|
||||
RunE: cmdCreateSchema,
|
||||
}
|
||||
setupCmd = &cobra.Command{
|
||||
Use: "setup",
|
||||
Short: "Create config files",
|
||||
@ -60,43 +65,15 @@ func init() {
|
||||
cfgstruct.SetupFlag(zap.L(), rootCmd, &identityDir, "identity-dir", defaultIdentityDir, "main directory for multinode identity credentials")
|
||||
defaults := cfgstruct.DefaultsFlag(rootCmd)
|
||||
|
||||
rootCmd.AddCommand(runCmd)
|
||||
rootCmd.AddCommand(setupCmd)
|
||||
rootCmd.AddCommand(runCmd)
|
||||
rootCmd.AddCommand(createSchemaCmd)
|
||||
|
||||
process.Bind(runCmd, &runCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
||||
process.Bind(createSchemaCmd, &runCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
||||
process.Bind(setupCmd, &setupCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir), cfgstruct.SetupMode())
|
||||
}
|
||||
|
||||
func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
log := zap.L()
|
||||
|
||||
runCfg.Debug.Address = *process.DebugAddrFlag
|
||||
|
||||
identity, err := runCfg.Identity.Load()
|
||||
if err != nil {
|
||||
log.Error("Failed to load identity.", zap.Error(err))
|
||||
return errs.New("Failed to load identity: %+v", err)
|
||||
}
|
||||
|
||||
db, err := multinodedb.Open(ctx, log.Named("db"), runCfg.Database)
|
||||
if err != nil {
|
||||
return errs.New("Error starting master database on multinode: %+v", err)
|
||||
}
|
||||
defer func() {
|
||||
err = errs.Combine(err, db.Close())
|
||||
}()
|
||||
|
||||
peer, err := multinode.New(log, identity, runCfg.Config, db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
runError := peer.Run(ctx)
|
||||
closeError := peer.Close()
|
||||
return errs.Combine(runError, closeError)
|
||||
}
|
||||
|
||||
func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
setupDir, err := filepath.Abs(confDir)
|
||||
if err != nil {
|
||||
@ -115,3 +92,53 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
|
||||
return process.SaveConfig(cmd, filepath.Join(setupDir, "config.yaml"))
|
||||
}
|
||||
|
||||
func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
log := zap.L()
|
||||
|
||||
runCfg.Debug.Address = *process.DebugAddrFlag
|
||||
|
||||
identity, err := runCfg.Identity.Load()
|
||||
if err != nil {
|
||||
log.Error("failed to load identity", zap.Error(err))
|
||||
return errs.New("failed to load identity: %+v", err)
|
||||
}
|
||||
|
||||
db, err := multinodedb.Open(ctx, log.Named("db"), runCfg.Database)
|
||||
if err != nil {
|
||||
return errs.New("error connecting to master database on multinode: %+v", err)
|
||||
}
|
||||
defer func() {
|
||||
err = errs.Combine(err, db.Close())
|
||||
}()
|
||||
|
||||
peer, err := multinode.New(log, identity, runCfg.Config, db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
runError := peer.Run(ctx)
|
||||
closeError := peer.Close()
|
||||
return errs.Combine(runError, closeError)
|
||||
}
|
||||
|
||||
func cmdCreateSchema(cmd *cobra.Command, args []string) (err error) {
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
log := zap.L()
|
||||
|
||||
db, err := multinodedb.Open(ctx, log.Named("db"), runCfg.Database)
|
||||
if err != nil {
|
||||
return errs.New("error connecting to master database on multinode: %+v", err)
|
||||
}
|
||||
defer func() {
|
||||
err = errs.Combine(err, db.Close())
|
||||
}()
|
||||
|
||||
err = db.CreateSchema(ctx)
|
||||
if err != nil {
|
||||
return errs.New("error creating database schemas for multinode dashboard db: %+v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ func New(log *zap.Logger, full *identity.FullIdentity, config Config, db DB) (_
|
||||
Log: log,
|
||||
Identity: full,
|
||||
DB: db,
|
||||
Servers: lifecycle.NewGroup(log.Named("servers")),
|
||||
}
|
||||
|
||||
{ // console setup
|
||||
|
Loading…
Reference in New Issue
Block a user