diff --git a/cmd/elasticindexer/flags.go b/cmd/elasticindexer/flags.go index d7e84b70..b09106c0 100644 --- a/cmd/elasticindexer/flags.go +++ b/cmd/elasticindexer/flags.go @@ -47,4 +47,9 @@ var ( Name: "disable-ansi-color", Usage: "Boolean option for disabling ANSI colors in the logging system.", } + // sovereign defines a flag that specifies if the es instance should run for a sovereign chain + sovereign = cli.BoolFlag{ + Name: "sovereign", + Usage: "If set to true, will use sovereign run type components", + } ) diff --git a/cmd/elasticindexer/main.go b/cmd/elasticindexer/main.go index 85246d13..3cbf2657 100644 --- a/cmd/elasticindexer/main.go +++ b/cmd/elasticindexer/main.go @@ -11,13 +11,14 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/core/closing" "github.com/multiversx/mx-chain-core-go/data/outport" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-logger-go/file" + "github.com/urfave/cli" + "github.com/multiversx/mx-chain-es-indexer-go/config" "github.com/multiversx/mx-chain-es-indexer-go/factory" "github.com/multiversx/mx-chain-es-indexer-go/metrics" "github.com/multiversx/mx-chain-es-indexer-go/process/wsindexer" - logger "github.com/multiversx/mx-chain-logger-go" - "github.com/multiversx/mx-chain-logger-go/file" - "github.com/urfave/cli" ) var ( @@ -63,6 +64,7 @@ func main() { logLevel, logSaveFile, disableAnsiColor, + sovereign, } app.Authors = []cli.Author{ { @@ -86,6 +88,7 @@ func startIndexer(ctx *cli.Context) error { if err != nil { return fmt.Errorf("%w while loading the config file", err) } + cfg.SovereignType = ctx.GlobalBool(sovereign.Name) clusterCfg, err := loadClusterConfig(ctx.GlobalString(configurationPreferencesFile.Name)) if err != nil { diff --git a/config/config.go b/config/config.go index dc1ab2cb..2f3ef7be 100644 --- a/config/config.go +++ b/config/config.go @@ -29,6 +29,7 @@ type Config struct { LogsPath string `toml:"logs-path"` } `toml:"logs"` } `toml:"config"` + SovereignType bool } // ClusterConfig will hold the config for the Elasticsearch cluster diff --git a/factory/interface.go b/factory/interface.go deleted file mode 100644 index ae3435e6..00000000 --- a/factory/interface.go +++ /dev/null @@ -1,24 +0,0 @@ -package factory - -// ComponentHandler defines the actions common to all component handlers -type ComponentHandler interface { - Create() error - Close() error - CheckSubcomponents() error - String() string -} - -// RunTypeComponentsHandler defines the run type components handler actions -type RunTypeComponentsHandler interface { - ComponentHandler - RunTypeComponentsHolder -} - -// RunTypeComponentsHolder holds the run type components -type RunTypeComponentsHolder interface { - Create() error - Close() error - CheckSubcomponents() error - String() string - IsInterfaceNil() bool -} diff --git a/factory/runType/interface.go b/factory/runType/interface.go index 37448d92..44298c6f 100644 --- a/factory/runType/interface.go +++ b/factory/runType/interface.go @@ -5,3 +5,26 @@ type RunTypeComponentsCreator interface { Create() *runTypeComponents IsInterfaceNil() bool } + +// ComponentHandler defines the actions common to all component handlers +type ComponentHandler interface { + Create() error + Close() error + CheckSubcomponents() error + String() string +} + +// RunTypeComponentsHandler defines the run type components handler actions +type RunTypeComponentsHandler interface { + ComponentHandler + RunTypeComponentsHolder +} + +// RunTypeComponentsHolder holds the run type components +type RunTypeComponentsHolder interface { + Create() error + Close() error + CheckSubcomponents() error + String() string + IsInterfaceNil() bool +} diff --git a/factory/runType/runTypeComponentsHandler.go b/factory/runType/runTypeComponentsHandler.go index 9b25b92b..2421fd9d 100644 --- a/factory/runType/runTypeComponentsHandler.go +++ b/factory/runType/runTypeComponentsHandler.go @@ -4,15 +4,13 @@ import ( "sync" "github.com/multiversx/mx-chain-core-go/core/check" - - "github.com/multiversx/mx-chain-es-indexer-go/factory" ) const runTypeComponentsName = "managedRunTypeComponents" -var _ factory.ComponentHandler = (*managedRunTypeComponents)(nil) -var _ factory.RunTypeComponentsHandler = (*managedRunTypeComponents)(nil) -var _ factory.RunTypeComponentsHolder = (*managedRunTypeComponents)(nil) +var _ ComponentHandler = (*managedRunTypeComponents)(nil) +var _ RunTypeComponentsHandler = (*managedRunTypeComponents)(nil) +var _ RunTypeComponentsHolder = (*managedRunTypeComponents)(nil) type managedRunTypeComponents struct { *runTypeComponents diff --git a/factory/runType/runTypeComponentsHandler_test.go b/factory/runType/runTypeComponentsHandler_test.go index 573a73ff..b9b23b08 100644 --- a/factory/runType/runTypeComponentsHandler_test.go +++ b/factory/runType/runTypeComponentsHandler_test.go @@ -4,11 +4,9 @@ import ( "testing" "github.com/stretchr/testify/require" - - "github.com/multiversx/mx-chain-es-indexer-go/factory" ) -func createComponents() (factory.RunTypeComponentsHandler, error) { +func createComponents() (RunTypeComponentsHandler, error) { rtcf := NewRunTypeComponentsFactory() return NewManagedRunTypeComponents(rtcf) } diff --git a/factory/wsIndexerFactory.go b/factory/wsIndexerFactory.go index 90beb5a9..96735a9c 100644 --- a/factory/wsIndexerFactory.go +++ b/factory/wsIndexerFactory.go @@ -7,11 +7,12 @@ import ( factoryHasher "github.com/multiversx/mx-chain-core-go/hashing/factory" "github.com/multiversx/mx-chain-core-go/marshal" factoryMarshaller "github.com/multiversx/mx-chain-core-go/marshal/factory" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-es-indexer-go/config" "github.com/multiversx/mx-chain-es-indexer-go/core" "github.com/multiversx/mx-chain-es-indexer-go/process/factory" "github.com/multiversx/mx-chain-es-indexer-go/process/wsindexer" - logger "github.com/multiversx/mx-chain-logger-go" ) var log = logger.GetOrCreate("elasticindexer") @@ -76,6 +77,7 @@ func createDataIndexer( } return factory.NewIndexer(factory.ArgsIndexerFactory{ + SovereignType: cfg.SovereignType, UseKibana: clusterCfg.Config.ElasticCluster.UseKibana, Denomination: cfg.Config.Economics.Denomination, BulkRequestMaxSize: clusterCfg.Config.ElasticCluster.BulkRequestMaxSizeInBytes, diff --git a/process/factory/indexerFactory.go b/process/factory/indexerFactory.go index 5da830f1..911bf8f5 100644 --- a/process/factory/indexerFactory.go +++ b/process/factory/indexerFactory.go @@ -12,14 +12,16 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-es-indexer-go/client" "github.com/multiversx/mx-chain-es-indexer-go/client/logging" "github.com/multiversx/mx-chain-es-indexer-go/client/transport" indexerCore "github.com/multiversx/mx-chain-es-indexer-go/core" + "github.com/multiversx/mx-chain-es-indexer-go/factory/runType" "github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer" "github.com/multiversx/mx-chain-es-indexer-go/process/elasticproc" "github.com/multiversx/mx-chain-es-indexer-go/process/elasticproc/factory" - logger "github.com/multiversx/mx-chain-logger-go" ) var log = logger.GetOrCreate("indexer/factory") @@ -30,6 +32,7 @@ type ArgsIndexerFactory struct { Enabled bool UseKibana bool ImportDB bool + SovereignType bool Denomination int BulkRequestMaxSize int Url string @@ -44,6 +47,7 @@ type ArgsIndexerFactory struct { AddressPubkeyConverter core.PubkeyConverter ValidatorPubkeyConverter core.PubkeyConverter StatusMetrics indexerCore.StatusMetricsHandler + RunTypeComponents runType.RunTypeComponentsHandler } // NewIndexer will create a new instance of Indexer @@ -53,6 +57,15 @@ func NewIndexer(args ArgsIndexerFactory) (dataindexer.Indexer, error) { return nil, err } + if args.SovereignType { + args.RunTypeComponents, err = createManagedRunTypeComponents(runType.NewSovereignRunTypeComponentsFactory()) + } else { + args.RunTypeComponents, err = createManagedRunTypeComponents(runType.NewRunTypeComponentsFactory()) + } + if err != nil { + return nil, err + } + elasticProcessor, err := createElasticProcessor(args) if err != nil { return nil, err @@ -72,6 +85,20 @@ func NewIndexer(args ArgsIndexerFactory) (dataindexer.Indexer, error) { return dataindexer.NewDataIndexer(arguments) } +func createManagedRunTypeComponents(factory runType.RunTypeComponentsCreator) (runType.RunTypeComponentsHandler, error) { + managedRunTypeComponents, err := runType.NewManagedRunTypeComponents(factory) + if err != nil { + return nil, err + } + + err = managedRunTypeComponents.Create() + if err != nil { + return nil, err + } + + return managedRunTypeComponents, nil +} + func retryBackOff(attempt int) time.Duration { d := time.Duration(math.Exp2(float64(attempt))) * time.Second log.Debug("elastic: retry backoff", "attempt", attempt, "sleep duration", d)