forked from akvorado/akvorado
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot.go
67 lines (54 loc) · 1.96 KB
/
root.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
61
62
63
64
65
66
67
// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
// Package orchestrator synchronizes the different internal services.
package orchestrator
import (
"sync"
"akvorado/common/http"
"akvorado/common/reporter"
)
// Component represents the broker.
type Component struct {
r *reporter.Reporter
d *Dependencies
config Configuration
serviceLock sync.Mutex
serviceConfigurations map[ServiceType][]interface{}
}
// Dependencies define the dependencies of the broker.
type Dependencies struct {
HTTP *http.Component
}
// ServiceType describes the different internal services
type ServiceType string
var (
// InletService represents the inlet service type
InletService ServiceType = "inlet"
// OrchestratorService represents the orchestrator service type
OrchestratorService ServiceType = "orchestrator"
// ConsoleService represents the console service type
ConsoleService ServiceType = "console"
// DemoExporterService represents the demo exporter service type
DemoExporterService ServiceType = "demo-exporter"
)
// New creates a new broker component.
func New(r *reporter.Reporter, configuration Configuration, dependencies Dependencies) (*Component, error) {
c := Component{
r: r,
d: &dependencies,
config: configuration,
serviceConfigurations: map[ServiceType][]interface{}{},
}
c.d.HTTP.GinRouter.GET("/api/v0/orchestrator/configuration/:service", c.configurationHandlerFunc)
c.d.HTTP.GinRouter.GET("/api/v0/orchestrator/configuration/:service/:index", c.configurationHandlerFunc)
return &c, nil
}
// RegisterConfiguration registers the configuration for a service.
func (c *Component) RegisterConfiguration(service ServiceType, configuration interface{}) {
c.serviceLock.Lock()
if _, ok := c.serviceConfigurations[service]; !ok {
c.serviceConfigurations[service] = []interface{}{}
}
c.serviceConfigurations[service] = append(c.serviceConfigurations[service], configuration)
c.serviceLock.Unlock()
}