diff --git a/pkg/api_gateway.go b/pkg/api_gateway.go index ba6f6b1c1..58ce6df10 100644 --- a/pkg/api_gateway.go +++ b/pkg/api_gateway.go @@ -10,7 +10,7 @@ import ( type SubstrateGateway interface { CreateNode(node substrate.Node) (uint32, error) CreateTwin(relay string, pk []byte) (uint32, error) - EnsureAccount(activationURL string, termsAndConditionsLink string, termsAndConditionsHash string) (info substrate.AccountInfo, err error) + EnsureAccount(activationURL []string, termsAndConditionsLink string, termsAndConditionsHash string) (info substrate.AccountInfo, err error) GetContract(id uint64) (substrate.Contract, SubstrateError) GetContractIDByNameRegistration(name string) (uint64, SubstrateError) GetFarm(id uint32) (substrate.Farm, error) diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index d03a514aa..50fca3f6f 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -48,7 +48,7 @@ type Environment struct { // SINCE RELAYS FOR A NODE IS STORED ON THE CHAIN IN A LIMITED SPACE // PLEASE MAKE SURE THAT ANY ENV HAS NO MORE THAN FOUR RELAYS CONFIGURED RelayURL []string - ActivationURL string + ActivationURL []string GraphQL []string // private vlan to join @@ -108,14 +108,18 @@ var ( RunningMode: RunningDev, SubstrateURL: []string{ "wss://tfchain.dev.grid.tf/", + "wss://tfchain.02.dev.grid.tf", }, RelayURL: []string{ "wss://relay.dev.grid.tf", "wss://relay.02.dev.grid.tf", }, - ActivationURL: "https://activation.dev.grid.tf/activation/activate", - FlistURL: "redis://hub.grid.tf:9900", - BinRepo: "tf-zos-v3-bins.dev", + ActivationURL: []string{ + "https://activation.dev.grid.tf/activation/activate", + "https://activation.02.dev.grid.tf/activation/activate", + }, + FlistURL: "redis://hub.grid.tf:9900", + BinRepo: "tf-zos-v3-bins.dev", GraphQL: []string{ "https://graphql.dev.grid.tf/graphql", "https://graphql.02.dev.grid.tf/graphql", @@ -126,14 +130,18 @@ var ( RunningMode: RunningTest, SubstrateURL: []string{ "wss://tfchain.test.grid.tf/", + "wss://tfchain.02.test.grid.tf", }, RelayURL: []string{ "wss://relay.test.grid.tf", "wss://relay.02.test.grid.tf", }, - ActivationURL: "https://activation.test.grid.tf/activation/activate", - FlistURL: "redis://hub.grid.tf:9900", - BinRepo: "tf-zos-v3-bins.test", + ActivationURL: []string{ + "https://activation.test.grid.tf/activation/activate", + "https://activation.02.test.grid.tf/activation/activate", + }, + FlistURL: "redis://hub.grid.tf:9900", + BinRepo: "tf-zos-v3-bins.test", GraphQL: []string{ "https://graphql.test.grid.tf/graphql", "https://graphql.02.test.grid.tf/graphql", @@ -148,10 +156,14 @@ var ( }, RelayURL: []string{ "wss://relay.qa.grid.tf", + "wss://relay.02.qa.grid.tf", }, - ActivationURL: "https://activation.qa.grid.tf/activation/activate", - FlistURL: "redis://hub.grid.tf:9900", - BinRepo: "tf-zos-v3-bins.qanet", + ActivationURL: []string{ + "https://activation.qa.grid.tf/activation/activate", + "https://activation.02.qa.grid.tf/activation/activate", + }, + FlistURL: "redis://hub.grid.tf:9900", + BinRepo: "tf-zos-v3-bins.qanet", GraphQL: []string{ "https://graphql.qa.grid.tf/graphql", "https://graphql.02.qa.grid.tf/graphql", @@ -162,6 +174,7 @@ var ( RunningMode: RunningMain, SubstrateURL: []string{ "wss://tfchain.grid.tf/", + "wss://tfchain.02.grid.tf", "wss://02.tfchain.grid.tf/", "wss://03.tfchain.grid.tf/", "wss://04.tfchain.grid.tf/", @@ -170,9 +183,12 @@ var ( "wss://relay.grid.tf", "wss://relay.02.grid.tf", }, - ActivationURL: "https://activation.grid.tf/activation/activate", - FlistURL: "redis://hub.grid.tf:9900", - BinRepo: "tf-zos-v3-bins", + ActivationURL: []string{ + "https://activation.grid.tf/activation/activate", + "https://activation.02.grid.tf/activation/activate", + }, + FlistURL: "redis://hub.grid.tf:9900", + BinRepo: "tf-zos-v3-bins", GraphQL: []string{ "https://graphql.grid.tf/graphql", "https://graphql.02.grid.tf/graphql", @@ -253,7 +269,7 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) { if activation, ok := params.Get("activation"); ok { if len(activation) > 0 { - env.ActivationURL = activation[len(activation)-1] + env.ActivationURL = activation } } diff --git a/pkg/perf/healthcheck/network.go b/pkg/perf/healthcheck/network.go index ab1c56067..9a99eb49a 100644 --- a/pkg/perf/healthcheck/network.go +++ b/pkg/perf/healthcheck/network.go @@ -17,11 +17,10 @@ const defaultRequestTimeout = 5 * time.Second func networkCheck(ctx context.Context) []error { env := environment.MustGet() - servicesUrl := []string{ - env.ActivationURL, env.FlistURL, - } + servicesUrl := []string{env.FlistURL} + servicesUrl = append(append(servicesUrl, env.SubstrateURL...), env.RelayURL...) - servicesUrl = append(servicesUrl, env.GraphQL...) + servicesUrl = append(append(servicesUrl, env.ActivationURL...), env.GraphQL...) var errors []error diff --git a/pkg/stubs/api_gateway_stub.go b/pkg/stubs/api_gateway_stub.go index 1fbdf0984..dbd340cfa 100644 --- a/pkg/stubs/api_gateway_stub.go +++ b/pkg/stubs/api_gateway_stub.go @@ -63,7 +63,7 @@ func (s *SubstrateGatewayStub) CreateTwin(ctx context.Context, arg0 string, arg1 return } -func (s *SubstrateGatewayStub) EnsureAccount(ctx context.Context, arg0 string, arg1 string, arg2 string) (ret0 tfchainclientgo.AccountInfo, ret1 error) { +func (s *SubstrateGatewayStub) EnsureAccount(ctx context.Context, arg0 []string, arg1 string, arg2 string) (ret0 tfchainclientgo.AccountInfo, ret1 error) { args := []interface{}{arg0, arg1, arg2} result, err := s.client.RequestContext(ctx, s.module, s.object, "EnsureAccount", args...) if err != nil { diff --git a/pkg/substrate_gateway/substrate_gateway.go b/pkg/substrate_gateway/substrate_gateway.go index 7bd936970..8a7d7fe7e 100644 --- a/pkg/substrate_gateway/substrate_gateway.go +++ b/pkg/substrate_gateway/substrate_gateway.go @@ -48,16 +48,25 @@ func (g *substrateGateway) CreateTwin(relay string, pk []byte) (uint32, error) { return g.sub.CreateTwin(g.identity, relay, pk) } -func (g *substrateGateway) EnsureAccount(activationURL string, termsAndConditionsLink string, termsAndConditionsHash string) (info substrate.AccountInfo, err error) { +func (g *substrateGateway) EnsureAccount(activationURL []string, termsAndConditionsLink string, termsAndConditionsHash string) (info substrate.AccountInfo, err error) { log.Debug(). Str("method", "EnsureAccount"). - Str("activation url", activationURL). + Strs("activation url", activationURL). Str("terms and conditions link", termsAndConditionsLink). Str("terms and conditions hash", termsAndConditionsHash). Msg("method called") g.mu.Lock() defer g.mu.Unlock() - return g.sub.EnsureAccount(g.identity, activationURL, termsAndConditionsLink, termsAndConditionsHash) + + for _, url := range activationURL { + info, err = g.sub.EnsureAccount(g.identity, url, termsAndConditionsLink, termsAndConditionsHash) + // check other activationURL only if EnsureAccount failed with ActivationServiceError + if err == nil || !errors.As(err, &substrate.ActivationServiceError{}) { + return + } + log.Debug().Str("activation url", url).Err(err).Msg("failed to EnsureAccount with ActivationServiceError") + } + return } func (g *substrateGateway) GetContract(id uint64) (result substrate.Contract, serr pkg.SubstrateError) {