-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
58 lines (53 loc) · 1.46 KB
/
service.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
package drpmesh
// Service is used to define a DRP service
type Service struct {
ServiceName string
drpNode *Node
Type string
InstanceID string
Sticky bool
Priority uint
Weight uint
Zone string
Scope string
Dependencies []string
Streams []string
Status int
ClientCmds map[string]EndpointMethod
Classes map[string]UMLClass
}
// AddClass add a new UMLClass to a Service
func (ds Service) AddClass(newClass UMLClass) {
ds.Classes[newClass.Name] = newClass
}
// GetDefinition returns information about this Service for discovery
func (ds Service) GetDefinition() ServiceDefinition {
classList := GetKeys(ds.Classes)
clientCmdList := GetKeys(ds.ClientCmds)
returnDef := ServiceDefinition{
ds.InstanceID,
ds.ServiceName,
ds.Type,
classList,
clientCmdList,
ds.Streams,
}
return returnDef
}
// PeerBroadcast sends a message to service peers
func (ds Service) PeerBroadcast(method string, params interface{}) {
// Get list of peer service IDs
var peerServiceIDList = ds.drpNode.TopologyTracker.FindServicePeers(ds.InstanceID)
for _, peerServiceID := range peerServiceIDList {
ds.drpNode.ServiceCmd(ds.ServiceName, method, params, nil, &peerServiceID, false, false, nil)
}
}
// ServiceDefinition is used for advertising service definitions
type ServiceDefinition struct {
InstanceID string
Name string
Type string
Classes []string
ClientCmds []string
Streams []string
}