This repository has been archived by the owner on Jul 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
diego_database.go
130 lines (120 loc) · 3.53 KB
/
diego_database.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
118
119
120
121
122
123
124
125
126
127
128
129
130
package cloudfoundry
import (
"github.com/enaml-ops/enaml"
"github.com/enaml-ops/omg-product-bundle/products/oss_cf/enaml-gen/bbs"
"github.com/enaml-ops/omg-product-bundle/products/oss_cf/enaml-gen/etcd"
"github.com/enaml-ops/omg-product-bundle/products/oss_cf/plugin/config"
)
const diegoDatabaseIGName = "diego_database-partition"
type diegoDatabase struct {
Config *config.Config
ConsulAgent *ConsulAgent
StatsdInjector *StatsdInjector
Metron *Metron
}
func NewDiegoDatabasePartition(config *config.Config) InstanceGroupCreator {
return &diegoDatabase{
Config: config,
ConsulAgent: NewConsulAgent([]string{"etcd"}, config),
Metron: NewMetron(config),
StatsdInjector: NewStatsdInjector(nil),
}
}
func (s *diegoDatabase) ToInstanceGroup() (ig *enaml.InstanceGroup) {
ig = &enaml.InstanceGroup{
Name: diegoDatabaseIGName,
Lifecycle: "service",
Instances: len(s.Config.DiegoDBIPs),
VMType: s.Config.DiegoDBVMType,
AZs: s.Config.AZs,
PersistentDiskType: s.Config.DiegoDBPersistentDiskType,
Stemcell: s.Config.StemcellName,
Networks: []enaml.Network{
{Name: s.Config.NetworkName, StaticIPs: s.Config.DiegoDBIPs},
},
Update: enaml.Update{
MaxInFlight: 1,
Serial: true,
},
}
ig.AddJob(&enaml.InstanceJob{
Name: "etcd",
Release: EtcdReleaseName,
Properties: s.newEtcd(),
})
ig.AddJob(&enaml.InstanceJob{
Name: "bbs",
Release: DiegoReleaseName,
Properties: s.newBBS(),
})
ig.AddJob(&enaml.InstanceJob{
Name: "consul_agent",
Release: CFReleaseName,
Properties: s.ConsulAgent.CreateJob().Properties,
})
ig.AddJob(&enaml.InstanceJob{
Name: "statsd-injector",
Release: CFReleaseName,
Properties: s.StatsdInjector.CreateJob().Properties,
})
ig.AddJob(&enaml.InstanceJob{
Name: "metron_agent",
Release: CFReleaseName,
Properties: s.Metron.CreateJob().Properties,
})
return
}
func (s *diegoDatabase) newBBS() (dbdiego *bbs.BbsJob) {
var keyname = "key1"
return &bbs.BbsJob{
Diego: &bbs.Diego{
Bbs: &bbs.Bbs{
CaCert: s.Config.BBSCACert,
ServerCert: s.Config.BBSServerCert,
ServerKey: s.Config.BBSServerKey,
ActiveKeyLabel: keyname,
EncryptionKeys: []map[string]string{
{
"label": keyname,
"passphrase": s.Config.DiegoDBPassphrase,
},
},
Auctioneer: &bbs.Auctioneer{
ApiUrl: "http://auctioneer.service.cf.internal:9016",
},
Etcd: s.newBBSEtcd(),
},
},
}
}
func (s *diegoDatabase) newEtcd() *etcd.EtcdJob {
return &etcd.EtcdJob{
Etcd: &etcd.Etcd{
CaCert: s.Config.BBSCACert,
ServerCert: s.Config.EtcdServerCert,
ServerKey: s.Config.EtcdServerKey,
ClientCert: s.Config.EtcdClientCert,
ClientKey: s.Config.EtcdClientKey,
PeerCaCert: s.Config.BBSCACert,
PeerCert: s.Config.EtcdPeerCert,
PeerKey: s.Config.EtcdPeerKey,
AdvertiseUrlsDnsSuffix: "etcd.service.cf.internal",
Machines: []string{"etcd.service.cf.internal"},
Cluster: []map[string]interface{}{
{
"name": diegoDatabaseIGName,
"instances": len(s.Config.DiegoDBIPs),
},
},
},
}
}
func (s *diegoDatabase) newBBSEtcd() (dbetcd *bbs.Etcd) {
dbetcd = &bbs.Etcd{
CaCert: s.Config.BBSCACert,
ClientCert: s.Config.EtcdClientCert,
ClientKey: s.Config.EtcdClientKey,
Machines: []string{"etcd.service.cf.internal"},
}
return
}