-
Notifications
You must be signed in to change notification settings - Fork 16
/
zos_api.go
60 lines (55 loc) · 2 KB
/
zos_api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package zosapi
import (
"fmt"
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
"github.com/threefoldtech/zbus"
"github.com/threefoldtech/zos/pkg/capacity"
"github.com/threefoldtech/zos/pkg/diagnostics"
"github.com/threefoldtech/zos/pkg/environment"
"github.com/threefoldtech/zos/pkg/stubs"
)
type ZosAPI struct {
oracle *capacity.ResourceOracle
versionMonitorStub *stubs.VersionMonitorStub
systemMonitorStub *stubs.SystemMonitorStub
provisionStub *stubs.ProvisionStub
networkerStub *stubs.NetworkerStub
statisticsStub *stubs.StatisticsStub
storageStub *stubs.StorageModuleStub
performanceMonitorStub *stubs.PerformanceMonitorStub
diagnosticsManager *diagnostics.DiagnosticsManager
farmerID uint32
}
func NewZosAPI(manager substrate.Manager, client zbus.Client, msgBrokerCon string) (ZosAPI, error) {
sub, err := manager.Substrate()
if err != nil {
return ZosAPI{}, err
}
defer sub.Close()
diagnosticsManager, err := diagnostics.NewDiagnosticsManager(msgBrokerCon, client)
if err != nil {
return ZosAPI{}, err
}
storageModuleStub := stubs.NewStorageModuleStub(client)
api := ZosAPI{
oracle: capacity.NewResourceOracle(storageModuleStub),
versionMonitorStub: stubs.NewVersionMonitorStub(client),
systemMonitorStub: stubs.NewSystemMonitorStub(client),
provisionStub: stubs.NewProvisionStub(client),
networkerStub: stubs.NewNetworkerStub(client),
statisticsStub: stubs.NewStatisticsStub(client),
storageStub: storageModuleStub,
performanceMonitorStub: stubs.NewPerformanceMonitorStub(client),
diagnosticsManager: diagnosticsManager,
}
farm, err := sub.GetFarm(uint32(environment.MustGet().FarmID))
if err != nil {
return ZosAPI{}, fmt.Errorf("failed to get farm: %w", err)
}
farmer, err := sub.GetTwin(uint32(farm.TwinID))
if err != nil {
return ZosAPI{}, err
}
api.farmerID = uint32(farmer.ID)
return api, nil
}