Skip to content

Commit

Permalink
fixes after review, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
axenteoctavian committed Dec 6, 2024
1 parent 92a42d0 commit 5c50ac4
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 41 deletions.
4 changes: 2 additions & 2 deletions cmd/elasticindexer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
)
3 changes: 2 additions & 1 deletion cmd/elasticindexer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 0 additions & 24 deletions factory/interface.go

This file was deleted.

23 changes: 23 additions & 0 deletions factory/runType/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 3 additions & 5 deletions factory/runType/runTypeComponentsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions factory/runType/runTypeComponentsHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 3 additions & 4 deletions factory/wsIndexerFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions process/factory/indexerFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ArgsIndexerFactory struct {
Enabled bool
UseKibana bool
ImportDB bool
SovereignConfig bool
SovereignType bool
Denomination int
BulkRequestMaxSize int
Url string
Expand All @@ -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())
Expand Down

0 comments on commit 5c50ac4

Please sign in to comment.