Change command a bit, change debug command parameter
This commit is contained in:
parent
c13a6e1d5f
commit
861e126ab4
@ -50,7 +50,7 @@ func (s *service) Init(a *app.App) (err error) {
|
||||
|
||||
func (s *service) Run(ctx context.Context) (err error) {
|
||||
rootCmd := &cobra.Command{Use: "debug", PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
cfgPath, err := cmd.Flags().GetString("config")
|
||||
cfgPath, err := cmd.Flags().GetString("nodemap")
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("no config flag is registered: %s", err.Error()))
|
||||
}
|
||||
@ -59,7 +59,7 @@ func (s *service) Run(ctx context.Context) (err error) {
|
||||
panic(fmt.Sprintf("couldn't load config with addresses of nodes: %s", err.Error()))
|
||||
}
|
||||
}}
|
||||
rootCmd.PersistentFlags().String("config", "util/cmd/nodesgen/nodemap.yml", "nodes configuration")
|
||||
rootCmd.PersistentFlags().String("nodemap", "util/cmd/nodesgen/nodemap.yml", "nodes configuration")
|
||||
|
||||
clientCmd := &cobra.Command{Use: "client commands to be executed on a specified client"}
|
||||
clientCmd.PersistentFlags().StringP("client", "c", "", "the alias of the client")
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
|
||||
"github.com/spf13/cobra"
|
||||
@ -41,23 +42,8 @@ const (
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "deploy",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
absolute := absolutePaths{}
|
||||
// saving working directory
|
||||
wd, _ := os.Getwd()
|
||||
absolute.initialPath, _ = filepath.Abs(wd)
|
||||
|
||||
// checking number of nodes to deploy
|
||||
numNodes, err := cmd.Flags().GetUint("n")
|
||||
if err != nil {
|
||||
log.With(zap.Error(err)).Fatal("number of nodes is not specified")
|
||||
}
|
||||
|
||||
// checking number of clients to deploy
|
||||
numClients, err := cmd.Flags().GetUint("c")
|
||||
if err != nil {
|
||||
log.With(zap.Error(err)).Fatal("number of clients is not specified")
|
||||
}
|
||||
|
||||
// checking package names
|
||||
nodePkgName, err := cmd.Flags().GetString("node-pkg")
|
||||
@ -83,22 +69,6 @@ var rootCmd = &cobra.Command{
|
||||
}
|
||||
absolute.configPath, _ = filepath.Abs(cfgPath)
|
||||
|
||||
// check if all configs really exist for nodes and clients to be deployed
|
||||
for i := 0; i < int(numNodes); i++ {
|
||||
configName := fmt.Sprintf("node%d.yml", i+1)
|
||||
configPath := path.Join(absolute.configPath, configName)
|
||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
log.With(zap.Error(err)).Fatal("not enough node configs are generated")
|
||||
}
|
||||
}
|
||||
for i := 0; i < int(numClients); i++ {
|
||||
configName := fmt.Sprintf("client%d.yml", i+1)
|
||||
configPath := path.Join(absolute.configPath, configName)
|
||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
log.With(zap.Error(err)).Fatal("not enough client configs are generated")
|
||||
}
|
||||
}
|
||||
|
||||
// checking node package
|
||||
nodePath, err := cmd.Flags().GetString("node-path")
|
||||
if err != nil {
|
||||
@ -127,7 +97,10 @@ var rootCmd = &cobra.Command{
|
||||
log.With(zap.Error(err)).Fatal("no bin flag is registered")
|
||||
}
|
||||
|
||||
createDirectoryIfNotExists(binaryPath)
|
||||
err = createDirectoryIfNotExists(binaryPath)
|
||||
if err != nil {
|
||||
log.With(zap.Error(err)).Fatal("failed to create directory")
|
||||
}
|
||||
absoluteBinPath, _ := filepath.Abs(binaryPath)
|
||||
absolute.clientBinaryPath = path.Join(absoluteBinPath, anytypeClientBinaryName)
|
||||
absolute.nodeBinaryPath = path.Join(absoluteBinPath, anytypeNodeBinaryName)
|
||||
@ -137,11 +110,40 @@ var rootCmd = &cobra.Command{
|
||||
if err != nil {
|
||||
log.With(zap.Error(err)).Fatal("no db-path flag is registered")
|
||||
}
|
||||
createDirectoryIfNotExists(dbPath)
|
||||
err = createDirectoryIfNotExists(dbPath)
|
||||
if err != nil {
|
||||
log.With(zap.Error(err)).Fatal("failed to create directory")
|
||||
}
|
||||
absolute.dbPath, _ = filepath.Abs(dbPath)
|
||||
|
||||
ctx := context.WithValue(context.Background(), "paths", absolute)
|
||||
cmd.SetContext(ctx)
|
||||
},
|
||||
}
|
||||
|
||||
var runCmd = &cobra.Command{
|
||||
Use: "build-and-run",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
paths, ok := cmd.Context().Value("paths").(absolutePaths)
|
||||
if !ok {
|
||||
log.Fatal("did not get parent context")
|
||||
}
|
||||
|
||||
// checking number of nodes to deploy
|
||||
numNodes, err := cmd.Flags().GetUint("nodes")
|
||||
if err != nil {
|
||||
log.With(zap.Error(err)).Fatal("number of nodes is not specified")
|
||||
}
|
||||
|
||||
// checking number of clients to deploy
|
||||
numClients, err := cmd.Flags().GetUint("clients")
|
||||
if err != nil {
|
||||
log.With(zap.Error(err)).Fatal("number of clients is not specified")
|
||||
}
|
||||
|
||||
// running the script
|
||||
err = runAll(absolute, numClients, numNodes)
|
||||
err = runAll(paths, numClients, numNodes)
|
||||
|
||||
if err != nil {
|
||||
log.With(zap.Error(err)).Fatal("failed to run the command")
|
||||
}
|
||||
@ -149,15 +151,17 @@ var rootCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.Flags().String("config-dir", "etc/configs", "generated configs")
|
||||
rootCmd.Flags().Uint("n", 3, "number of nodes to be generated")
|
||||
rootCmd.Flags().Uint("c", 2, "number of clients to be generated")
|
||||
rootCmd.Flags().String("node-pkg", "github.com/anytypeio/go-anytype-infrastructure-experiments/node/cmd", "node package")
|
||||
rootCmd.Flags().String("client-pkg", "github.com/anytypeio/go-anytype-infrastructure-experiments/client/cmd", "client package")
|
||||
rootCmd.Flags().String("node-path", "node", "path to node go.mod")
|
||||
rootCmd.Flags().String("client-path", "client", "path to client go.mod")
|
||||
rootCmd.Flags().String("bin", "bin", "path to folder where all the binaries are")
|
||||
rootCmd.Flags().String("db-path", "db", "path to folder where the working directories should be placed")
|
||||
rootCmd.PersistentFlags().String("config-dir", "etc/configs", "generated configs")
|
||||
rootCmd.PersistentFlags().String("node-pkg", "github.com/anytypeio/go-anytype-infrastructure-experiments/node/cmd", "node package")
|
||||
rootCmd.PersistentFlags().String("client-pkg", "github.com/anytypeio/go-anytype-infrastructure-experiments/client/cmd", "client package")
|
||||
rootCmd.PersistentFlags().String("node-path", "node", "path to node go.mod")
|
||||
rootCmd.PersistentFlags().String("client-path", "client", "path to client go.mod")
|
||||
rootCmd.PersistentFlags().String("bin", "bin", "path to folder where all the binaries are")
|
||||
rootCmd.PersistentFlags().String("db-path", "db", "path to folder where the working directories should be placed")
|
||||
|
||||
runCmd.Flags().UintP("nodes", "n", 3, "number of nodes to be generated")
|
||||
runCmd.Flags().UintP("clients", "c", 2, "number of clients to be generated")
|
||||
rootCmd.AddCommand(runCmd)
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -167,42 +171,39 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func createDirectoryIfNotExists(dirPath string) {
|
||||
if _, err := os.Stat(dirPath); !os.IsNotExist(err) {
|
||||
func createDirectoryIfNotExists(dirPath string) (err error) {
|
||||
if _, err = os.Stat(dirPath); !os.IsNotExist(err) {
|
||||
return
|
||||
}
|
||||
err := os.Mkdir(dirPath, os.ModePerm)
|
||||
return os.Mkdir(dirPath, os.ModePerm)
|
||||
}
|
||||
|
||||
func createAppPaths(paths absolutePaths, binaryPath, appName string, num int) (appPaths []appPath, err error) {
|
||||
appTypePath := path.Join(paths.dbPath, appName)
|
||||
err = createDirectoryIfNotExists(appTypePath)
|
||||
if err != nil {
|
||||
log.With(zap.Error(err)).Fatal("failed to create directory")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func createNodePaths(paths absolutePaths, num int) (appPaths []appPath, err error) {
|
||||
prefixPath := path.Join(paths.dbPath, "node")
|
||||
createDirectoryIfNotExists(prefixPath)
|
||||
for i := 0; i < num; i++ {
|
||||
resPath := path.Join(prefixPath, fmt.Sprintf("%d", i+1))
|
||||
createDirectoryIfNotExists(resPath)
|
||||
// creating directory for each app
|
||||
resPath := path.Join(appTypePath, fmt.Sprintf("%d", i+1))
|
||||
err = createDirectoryIfNotExists(resPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// checking if relevant config exists
|
||||
cfgPath := path.Join(paths.configPath, fmt.Sprintf("%s%d.yml", appName, i+1))
|
||||
if _, err = os.Stat(cfgPath); os.IsNotExist(err) {
|
||||
err = fmt.Errorf("not enough %s configs are generated: %w", appName, err)
|
||||
return
|
||||
}
|
||||
|
||||
appPaths = append(appPaths, appPath{
|
||||
wdPath: resPath,
|
||||
binaryPath: paths.nodeBinaryPath,
|
||||
configPath: path.Join(paths.configPath, fmt.Sprintf("node%d.yml", i+1)),
|
||||
logPath: path.Join(resPath, "app.log"),
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func createClientPaths(paths absolutePaths, num int) (appPaths []appPath, err error) {
|
||||
prefixPath := path.Join(paths.dbPath, "client")
|
||||
createDirectoryIfNotExists(prefixPath)
|
||||
for i := 0; i < num; i++ {
|
||||
resPath := path.Join(prefixPath, fmt.Sprintf("%d", i+1))
|
||||
createDirectoryIfNotExists(resPath)
|
||||
appPaths = append(appPaths, appPath{
|
||||
wdPath: resPath,
|
||||
binaryPath: paths.clientBinaryPath,
|
||||
configPath: path.Join(paths.configPath, fmt.Sprintf("client%d.yml", i+1)),
|
||||
binaryPath: binaryPath,
|
||||
configPath: cfgPath,
|
||||
logPath: path.Join(resPath, "app.log"),
|
||||
})
|
||||
}
|
||||
@ -222,13 +223,13 @@ func runAll(paths absolutePaths, numClients, numNodes uint) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
nodePaths, err := createNodePaths(paths, int(numNodes))
|
||||
nodePaths, err := createAppPaths(paths, paths.nodeBinaryPath, "node", int(numNodes))
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to create working directories for nodes: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
clientPaths, err := createClientPaths(paths, int(numClients))
|
||||
clientPaths, err := createAppPaths(paths, paths.clientBinaryPath, "client", int(numClients))
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to create working directories for clients: %w", err)
|
||||
return
|
||||
@ -253,12 +254,10 @@ func runAll(paths absolutePaths, numClients, numNodes uint) (err error) {
|
||||
}(clientPath)
|
||||
}
|
||||
wg.Wait()
|
||||
log.Info("running finished")
|
||||
return
|
||||
}
|
||||
|
||||
func build(dirPath, binaryPath, packageName string) (err error) {
|
||||
fmt.Println(dirPath, binaryPath, packageName)
|
||||
cmd := exec.Command("go", "build", "-v", "-o", binaryPath, packageName)
|
||||
cmd.Dir = dirPath
|
||||
cmd.Stdout = os.Stdout
|
||||
@ -267,6 +266,7 @@ func build(dirPath, binaryPath, packageName string) (err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
log.With(zap.String("binary path", binaryPath), zap.String("package name", packageName)).Info("building the app")
|
||||
return cmd.Wait()
|
||||
}
|
||||
|
||||
@ -281,7 +281,7 @@ func runApp(app appPath, wg *sync.WaitGroup) (err error) {
|
||||
cmd.Stdout = file
|
||||
cmd.Stderr = file
|
||||
err = cmd.Start()
|
||||
log.With(zap.String("working directory", app.wdPath)).Info("run the app")
|
||||
log.With(zap.String("working directory", app.wdPath), zap.String("log path", app.logPath)).Info("running the app")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ require (
|
||||
github.com/anytypeio/go-anytype-infrastructure-experiments/consensus v0.0.0-00010101000000-000000000000
|
||||
github.com/anytypeio/go-anytype-infrastructure-experiments/node v0.0.0-20221217135026-4eba413631b3
|
||||
github.com/dgraph-io/badger/v3 v3.2103.3
|
||||
github.com/spf13/cobra v0.0.5
|
||||
github.com/spf13/cobra v1.6.1
|
||||
github.com/zeebo/errs v1.3.0
|
||||
go.uber.org/zap v1.23.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
@ -33,7 +33,7 @@ require (
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/snappy v0.0.3 // indirect
|
||||
github.com/google/flatbuffers v1.12.1 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.1 // indirect
|
||||
github.com/ipfs/go-cid v0.3.2 // indirect
|
||||
github.com/klauspost/compress v1.15.10 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.1.1 // indirect
|
||||
@ -58,7 +58,7 @@ require (
|
||||
github.com/prometheus/procfs v0.8.0 // indirect
|
||||
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
|
||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
github.com/spf13/pflag v1.0.3 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
go.opencensus.io v0.23.0 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.8.0 // indirect
|
||||
|
||||
11
util/go.sum
11
util/go.sum
@ -67,6 +67,7 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
|
||||
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
|
||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@ -166,8 +167,9 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
|
||||
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/ipfs/go-cid v0.3.2 h1:OGgOd+JCFM+y1DjWPmVH+2/4POtpDzwcr7VgnB7mZXc=
|
||||
github.com/ipfs/go-cid v0.3.2/go.mod h1:gQ8pKqT/sUxGY+tIwy1RPpAojYu7jAyCp5Tz1svoupw=
|
||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||
@ -268,6 +270,7 @@ github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5
|
||||
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
@ -278,11 +281,13 @@ github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0b
|
||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
|
||||
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
|
||||
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
|
||||
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
|
||||
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
||||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user