Skip to content

Commit

Permalink
refactor multiple activation service url
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Sep 8, 2024
1 parent 29660a7 commit 88fae6c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkg/api_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/perf/iperf/iperf_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (t *IperfTest) Run(ctx context.Context) (interface{}, error) {
return nil, err
}

// get public up nodes
freeFarmNodes, err := g.GetUpNodes(ctx, 0, 1, 0, true, true)
if err != nil {
return nil, errors.Wrap(err, "failed to list freefarm nodes from graphql")
Expand Down
2 changes: 1 addition & 1 deletion pkg/perf/publicip/publicip_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ func isLeastValidNode(ctx context.Context, farmID uint32, substrateGateway *stub
if err != nil {
return false, err
}

nodes, err := gql.GetUpNodes(ctx, 0, farmID, 0, false, false)
if err != nil {
return false, fmt.Errorf("failed to get farm %d nodes: %w", farmID, err)
}

cl := perf.GetZbusClient(ctx)
registrar := stubs.NewRegistrarStub(cl)
var nodeID uint32
Expand Down
7 changes: 1 addition & 6 deletions pkg/registrar/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,7 @@ func registerNode(

sk := ed25519.PrivateKey(mgr.PrivateKey(ctx))

for _, url := range env.ActivationURL {
if _, err = substrateGateway.EnsureAccount(ctx, url, tcUrl, tcHash); err == nil {
break
}
}
if err != nil {
if _, err := substrateGateway.EnsureAccount(ctx, env.ActivationURL, tcUrl, tcHash); err != nil {
return 0, 0, errors.Wrap(err, "failed to ensure account")
}

Expand Down
7 changes: 1 addition & 6 deletions pkg/registrar/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,8 @@ func (r *Registrar) register(ctx context.Context, cl zbus.Client, env environmen

func (r *Registrar) reActivate(ctx context.Context, cl zbus.Client, env environment.Environment) error {
substrateGateway := stubs.NewSubstrateGatewayStub(cl)
var err error

for _, url := range env.ActivationURL {
if _, err = substrateGateway.EnsureAccount(ctx, url, tcUrl, tcHash); err == nil {
break
}
}
_, err := substrateGateway.EnsureAccount(ctx, env.ActivationURL, tcUrl, tcHash)

return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/stubs/api_gateway_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 8 additions & 3 deletions pkg/substrate_gateway/substrate_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,21 @@ 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 {
if info, err = g.sub.EnsureAccount(g.identity, url, termsAndConditionsLink, termsAndConditionsHash); err == nil {
return
}
}
return
}

func (g *substrateGateway) GetContract(id uint64) (result substrate.Contract, serr pkg.SubstrateError) {
Expand Down

0 comments on commit 88fae6c

Please sign in to comment.