Skip to content

Commit 66f89ed

Browse files
committed
update zos-api-light to get farmer id from the caller
1 parent 4465cd7 commit 66f89ed

File tree

2 files changed

+10
-27
lines changed

2 files changed

+10
-27
lines changed

pkg/monitord/system.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/threefoldtech/zosbase/pkg"
1414
"github.com/threefoldtech/zosbase/pkg/gridtypes/zos"
1515
"github.com/threefoldtech/zosbase/pkg/kernel"
16-
"github.com/threefoldtech/zosbase/pkg/stubs"
16+
"github.com/threefoldtech/zosbase/pkg/stubs"
1717
)
1818

1919
var _ pkg.SystemMonitor = (*systemMonitor)(nil)
@@ -22,7 +22,7 @@ var _ pkg.SystemMonitor = (*systemMonitor)(nil)
2222
type systemMonitor struct {
2323
duration time.Duration
2424
node uint32
25-
cl zbus.Client
25+
cl zbus.Client
2626
}
2727

2828
// NewSystemMonitor creates new system of system monitor
@@ -31,7 +31,7 @@ func NewSystemMonitor(node uint32, duration time.Duration, cl zbus.Client) (pkg.
3131
duration = 2 * time.Second
3232
}
3333

34-
return &systemMonitor{duration: duration, node: node, cl: cl}, nil
34+
return &systemMonitor{duration: duration, node: node, cl: cl}, nil
3535
}
3636

3737
func (m *systemMonitor) NodeID() uint32 {
@@ -219,11 +219,11 @@ func (n *systemMonitor) GetNodeFeatures() []pkg.NodeFeature {
219219
}
220220
feat = append(feat, zosLightFeat...)
221221

222-
netStub := stubs.NewNetworkerLightStub(n.cl)
223-
config, err := netStub.LoadPublicConfig(context.Background())
224-
if err == nil && config.Domain != "" {
225-
feat = append(feat, "gateway-name-proxy")
226-
feat = append(feat, "gateway-fqdn-proxy")
222+
netStub := stubs.NewNetworkerLightStub(n.cl)
223+
config, err := netStub.LoadPublicConfig(context.Background())
224+
if err == nil && config.Domain != "" {
225+
feat = append(feat, "gateway-name-proxy")
226+
feat = append(feat, "gateway-fqdn-proxy")
227227
}
228228
return feat
229229
}

pkg/zos_api_light/zos_api.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package zosapi
22

33
import (
4-
"fmt"
54
"time"
65

76
"github.com/patrickmn/go-cache"
8-
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
97
"github.com/threefoldtech/zbus"
108
"github.com/threefoldtech/zosbase/pkg/capacity"
119
"github.com/threefoldtech/zosbase/pkg/diagnostics"
12-
"github.com/threefoldtech/zosbase/pkg/environment"
1310
"github.com/threefoldtech/zosbase/pkg/stubs"
1411
)
1512

@@ -32,12 +29,7 @@ type ZosAPI struct {
3229
inMemCache *cache.Cache
3330
}
3431

35-
func NewZosAPI(manager substrate.Manager, client zbus.Client, msgBrokerCon string) (ZosAPI, error) {
36-
sub, err := manager.Substrate()
37-
if err != nil {
38-
return ZosAPI{}, err
39-
}
40-
defer sub.Close()
32+
func NewZosAPI(client zbus.Client, farmerID uint32, msgBrokerCon string) (ZosAPI, error) {
4133
diagnosticsManager, err := diagnostics.NewDiagnosticsManager(msgBrokerCon, client)
4234
if err != nil {
4335
return ZosAPI{}, err
@@ -54,16 +46,7 @@ func NewZosAPI(manager substrate.Manager, client zbus.Client, msgBrokerCon strin
5446
performanceMonitorStub: stubs.NewPerformanceMonitorStub(client),
5547
diagnosticsManager: diagnosticsManager,
5648
}
57-
farm, err := sub.GetFarm(uint32(environment.MustGet().FarmID))
58-
if err != nil {
59-
return ZosAPI{}, fmt.Errorf("failed to get farm: %w", err)
60-
}
61-
62-
farmer, err := sub.GetTwin(uint32(farm.TwinID))
63-
if err != nil {
64-
return ZosAPI{}, err
65-
}
66-
api.farmerID = uint32(farmer.ID)
49+
api.farmerID = farmerID
6750
api.inMemCache = cache.New(cacheDefaultExpiration, cacheDefaultCleanup)
6851
return api, nil
6952
}

0 commit comments

Comments
 (0)