diff --git a/cmd/elasticindexer/flags.go b/cmd/elasticindexer/flags.go index 084f3b3e..b09106c0 100644 --- a/cmd/elasticindexer/flags.go +++ b/cmd/elasticindexer/flags.go @@ -47,9 +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 what run type components should use + // sovereign defines a flag that specifies if the es instance should run for a sovereign chain sovereign = cli.BoolFlag{ - Name: "sovereign-config", + 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 4c3e9366..3cbf2657 100644 --- a/cmd/elasticindexer/main.go +++ b/cmd/elasticindexer/main.go @@ -88,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 { @@ -100,7 +101,7 @@ func startIndexer(ctx *cli.Context) error { } statusMetrics := metrics.NewStatusMetrics() - wsHost, err := factory.CreateWsIndexer(cfg, clusterCfg, statusMetrics, ctx.App.Version, ctx.GlobalBool(sovereign.Name)) + wsHost, err := factory.CreateWsIndexer(cfg, clusterCfg, statusMetrics, ctx.App.Version) if err != nil { return fmt.Errorf("%w while creating the indexer", err) } 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 5b41359c..96735a9c 100644 --- a/factory/wsIndexerFactory.go +++ b/factory/wsIndexerFactory.go @@ -18,13 +18,13 @@ import ( var log = logger.GetOrCreate("elasticindexer") // CreateWsIndexer will create a new instance of wsindexer.WSClient -func CreateWsIndexer(cfg config.Config, clusterCfg config.ClusterConfig, statusMetrics core.StatusMetricsHandler, version string, isSovereignType bool) (wsindexer.WSClient, error) { +func CreateWsIndexer(cfg config.Config, clusterCfg config.ClusterConfig, statusMetrics core.StatusMetricsHandler, version string) (wsindexer.WSClient, error) { wsMarshaller, err := factoryMarshaller.NewMarshalizer(clusterCfg.Config.WebSocket.DataMarshallerType) if err != nil { return nil, err } - dataIndexer, err := createDataIndexer(cfg, clusterCfg, wsMarshaller, statusMetrics, version, isSovereignType) + dataIndexer, err := createDataIndexer(cfg, clusterCfg, wsMarshaller, statusMetrics, version) if err != nil { return nil, err } @@ -58,7 +58,6 @@ func createDataIndexer( wsMarshaller marshal.Marshalizer, statusMetrics core.StatusMetricsHandler, version string, - isSovereignConfig bool, ) (wsindexer.DataIndexer, error) { marshaller, err := factoryMarshaller.NewMarshalizer(cfg.Config.Marshaller.Type) if err != nil { @@ -78,7 +77,7 @@ func createDataIndexer( } return factory.NewIndexer(factory.ArgsIndexerFactory{ - SovereignConfig: isSovereignConfig, + 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 027dc651..911bf8f5 100644 --- a/process/factory/indexerFactory.go +++ b/process/factory/indexerFactory.go @@ -32,7 +32,7 @@ type ArgsIndexerFactory struct { Enabled bool UseKibana bool ImportDB bool - SovereignConfig bool + SovereignType bool Denomination int BulkRequestMaxSize int Url string @@ -57,7 +57,7 @@ func NewIndexer(args ArgsIndexerFactory) (dataindexer.Indexer, error) { return nil, err } - if args.SovereignConfig { + if args.SovereignType { args.RunTypeComponents, err = createManagedRunTypeComponents(runType.NewSovereignRunTypeComponentsFactory()) } else { args.RunTypeComponents, err = createManagedRunTypeComponents(runType.NewRunTypeComponentsFactory())