-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcacheclusters.go
117 lines (105 loc) · 4.65 KB
/
cacheclusters.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"encoding/json"
"log"
"github.com/aws/aws-sdk-go/service/elasticache"
)
type cacheClusterList struct {
*elasticache.DescribeCacheClustersOutput
}
type cacheClusterNodes []cacheClusterNode
type cacheClusterNode struct {
UID string `json:"uid,omitempty"`
Type []string `json:"dgraph.type,omitempty"`
Name string `json:"name,omitempty"` // This field is only for Ratel Viz
OwnerID string `json:"OwnerId,omitempty"`
OwnerName string `json:"OwnerName,omitempty"`
Region string `json:"Region,omitempty"`
Service string `json:"Service,omitempty"`
CacheClusterID string `json:"CacheClusterId,omitempty"`
Engine string `json:"Engine,omitempty"`
EngineVersion string `json:"EngineVersion,omitempty"`
AuthTokenEnabled bool `json:"AuthTokenEnabled,omitempty"`
Endpoint string `json:"Endpoint,omitempty"`
Port int64 `json:"Port,omitempty"`
AutoMinorVersionUpgrade bool `json:"AutoMinorVersionUpgrade,omitempty"`
Status string `json:"CacheClusterStatus,omitempty"`
NumCacheNodes int64 `json:"NumCacheNodes,omitempty"`
TransitEncryptionEnabled bool `json:"TransitEncryptionEnabled,omitempty"`
PreferredMaintenanceWindow string `json:"PreferredMaintenanceWindow,omitempty"`
CacheNodeType string `json:"CacheNodeType,omitempty"`
AvailabilityZone availabilityZoneNodes `json:"_AvailabilityZone,omitempty"`
SecurityGroup securityGroupNodes `json:"_SecurityGroup,omitempty"`
CacheSubnetGroup cacheSubnetGroupNodes `json:"_CacheSubnetGroup,omitempty"`
// CacheParameterGroup cacheParameterGroupNode `json:"_CacheParameterGroup,omitempty"`
}
func (c *connector) listCacheClusters() cacheClusterList {
defer c.waitGroup.Done()
log.Println("List CacheClusters")
response, err := elasticache.New(c.awsSession).DescribeCacheClusters(&elasticache.DescribeCacheClustersInput{})
if err != nil {
log.Fatal(err)
}
return cacheClusterList{response}
}
func (list cacheClusterList) addNodes(c *connector) {
defer c.waitGroup.Done()
if len(list.CacheClusters) == 0 {
return
}
log.Println("Add CacheCluster Nodes")
a := make(cacheClusterNodes, 0, len(list.CacheClusters))
for _, i := range list.CacheClusters {
var b cacheClusterNode
b.Service = "elasticache"
b.Type = []string{"CacheCluster"}
b.OwnerID = c.awsAccountID
b.OwnerName = c.awsAccountName
b.Region = c.awsRegion
b.Name = *i.CacheClusterId
b.CacheClusterID = *i.CacheClusterId
b.Engine = *i.Engine
b.EngineVersion = *i.EngineVersion
b.AuthTokenEnabled = *i.AuthTokenEnabled
if i.ConfigurationEndpoint != nil {
b.Endpoint = *i.ConfigurationEndpoint.Address
b.Port = *i.ConfigurationEndpoint.Port
}
b.AutoMinorVersionUpgrade = *i.AutoMinorVersionUpgrade
b.Status = *i.CacheClusterStatus
b.NumCacheNodes = *i.NumCacheNodes
b.TransitEncryptionEnabled = *i.TransitEncryptionEnabled
b.PreferredMaintenanceWindow = *i.PreferredMaintenanceWindow
b.CacheNodeType = *i.CacheNodeType
a = append(a, b)
}
c.dgraphAddNodes(a)
m := make(map[string]cacheClusterNodes)
n := make(map[string]string)
json.Unmarshal(c.dgraphQuery("CacheCluster"), &m)
for _, i := range m["list"] {
n[i.CacheClusterID] = i.UID
}
c.ressources["CacheClusters"] = n
}
func (list cacheClusterList) addEdges(c *connector) {
defer c.waitGroup.Done()
if len(list.CacheClusters) == 0 {
return
}
log.Println("Add CacheCluster Edges")
a := cacheClusterNodes{}
for _, i := range list.CacheClusters {
b := cacheClusterNode{
UID: c.ressources["CacheClusters"][*i.CacheClusterId],
CacheSubnetGroup: cacheSubnetGroupNodes{cacheSubnetGroupNode{UID: c.ressources["CacheSubnetGroups"][*i.CacheSubnetGroupName]}},
AvailabilityZone: availabilityZoneNodes{availabilityZoneNode{UID: c.ressources["AvailabilityZones"][*i.PreferredAvailabilityZone]}},
}
for _, j := range i.SecurityGroups {
b.SecurityGroup = append(b.SecurityGroup, securityGroupNode{UID: c.ressources["SecurityGroups"][*j.SecurityGroupId]})
}
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)
}