This repository has been archived by the owner on May 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
region_migrate.yml
245 lines (211 loc) · 7.86 KB
/
region_migrate.yml
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
type: update
baseUrl: https://raw.githubusercontent.com/Jahia/paas_jelastic_dx_universal/master
name: Jahia - Region Migrate
id: jahia-region-migrate
description:
short: Jahia - Region Migrate
mixins:
- database/galera_actions.yml
- database/proxysql_actions.yml
globals:
- maxtry: 10
onInstall:
- checkMigrationPossibility
- disableTomcat
- if (nodes.sqldb.length > 1):
- disableGalera
- getEnvLinked
- if (${globals.unomi_env_linked}):
- getCurrentIps
- setGlobals:
ips_before_migration: "${response.ips}"
- stopEnvironment
- waitForState:
state: stopped
- migrateEnvironment
- startEnvironment
- waitForState:
state: running
- if (${globals.unomi_env_linked}):
- getCurrentIps
- setGlobals:
ips_after_migration: "${response.ips}"
- getUnomiAllowedIps
- updateAllowedIpsList
- updateUnomiContainerVars
- reloadUnomiService
- if (nodes.sqldb.length > 1):
- setupSeeds: sqldb
- enableGalera
- refreshProxysqlInstancesList
- enableTomcat
- resetHaproxyBackends: bl
actions:
checkMigrationPossibility:
- api:
- method: environment.control.CheckMigrationPossibility
params:
envname: ${env.envName}
hardwareNodeGroup: ${settings.targetRegion}
stopEnvironment:
- api:
- method: environment.control.StopEnv
params:
envName: ${env.envName}
migrateEnvironment:
- api:
- method: environment.control.Migrate
params:
isOnline: false
envName: ${env.envName}
hardwareNodeGroup: ${settings.targetRegion}
startEnvironment:
- api:
- method: environment.control.StartEnv
params:
envName: ${env.envName}
disableGalera:
- cmd[sqldb]: |-
chkconfig mysql off
user: root
enableGalera:
- cmd[sqldb]: |-
service mysql start &&\
chkconfig --level 3 mysql on
user: root
disableTomcat:
- cmd[proc, cp]: |-
chkconfig tomcat off
user: root
enableTomcat:
- cmd[proc, cp]: |-
service tomcat start &&\
chkconfig tomcat on
user: root
resetHaproxyBackends:
- cmd[bl]: |-
sed -e "/$server.*:80 check cookie/d" \
-i /etc/haproxy/haproxy.cfg.d/{10-jahia,11-proc}.cfg
echo " server ${env.appid}-${nodes.proc.first.id} ${nodes.proc.first.intIP}:80 check cookie s${nodes.proc.first.id}" \
>> /etc/haproxy/haproxy.cfg.d/11-proc.cfg
- forEach(nodes.cp):
cmd[${this}]: |-
echo " server ${env.appid}-${@i.id} ${@i.intIP}:80 check cookie s${@i.id}" >> /etc/haproxy/haproxy.cfg.d/10-jahia.cfg
sudo service haproxy reload
user: haproxy
getEnvLinked:
- script: |
const envName = "${env.envName}";
envs = jelastic.env.control.GetEnvInfo(envName, session);
unomi_linked = envs.nodeGroups.filter(function (nodeGroup) {
return nodeGroup.name == "cp";
})
.pop()
.envLink;
return unomi_linked?
{"result": 0, value: unomi_linked, "is_linked": true, "out": "Found a linked env"} :
{"result": 0, value: "none", "is_linked": false, "out": "No unomi env linked"};
- setGlobals:
unomi_env_name: ${response.value}
unomi_env_linked: ${response.is_linked}
getUnomiAllowedIps:
- script: |
const unomi_env_name = "${globals.unomi_env_name}";
const nodes_infos = jelastic.env.control.GetEnvInfo(
unomi_env_name,
session
)
.nodes;
node_id = nodes_infos.filter(function (node) {
return node.nodeGroup == "cp";
})
.pop()
.id
container_env_vars = jelastic.env.control.GetContainerEnvVars(
unomi_env_name,
session,
node_id
);
allowed_ips = container_env_vars
.object
.get("UNOMI_THIRDPARTY_PROVIDER1_IPADDRESSES");
return {"result": 0, "value": allowed_ips};
- setGlobals:
unomi_allowed_ips: ${response.value}
getCurrentIps:
- script: |
const envName = "${env.envName}";
nodes_infos = jelastic.env.control.GetEnvInfo(
envName,
session
)
.nodes;
current_ips = nodes_infos
.filter(function (node) {
return node.nodeGroup == "cp" ||
node.nodeGroup == "proc";
})
.map(function (node) {
return node.intIP;
});
return {"result": 0, "ips": current_ips.join(",")};
updateAllowedIpsList:
- script: |
const unomi_allowed_ips = ("${globals.unomi_allowed_ips}").split(',');
jahia_current_ips = ("${globals.ips_after_migration}").split(',');
jahia_previous_ips = "${globals.ips_before_migration}";
unomi_foreign_ips = unomi_allowed_ips.filter(function(allowed_ip){
return jahia_previous_ips.indexOf(allowed_ip) < 0;
});
unomi_ips_to_allow = unomi_foreign_ips.concat(jahia_current_ips);
return {"result": 0, "value": unomi_ips_to_allow.join(",")};
- setGlobals:
unomi_ips_to_allow: ${response.value}
updateUnomiContainerVars:
- script: |
const unomi_linked_env_name = "${globals.unomi_env_name}";
unomi_ip_to_allow = "${globals.unomi_ips_to_allow}";
return add_container_env_vars = jelastic.env.control.AddContainerEnvVars(
unomi_linked_env_name,
session,
nodeGroup='cp',
vars={'UNOMI_THIRDPARTY_PROVIDER1_IPADDRESSES': unomi_ip_to_allow}
);
reloadUnomiService:
- script: |
const unomi_linked_env_name = "${globals.unomi_env_name}";
return restart_cp_node_group = jelastic.env.control.RestartServices(
unomi_linked_env_name,
session,
nodeGroup='cp'
);
waitForState:
- if("${this.state}" == "running"):
- set:
state_int: 1
- else:
- set:
state_int: 2
- api: environment.control.getenvinfo
- if (${response.env.status} != ${this.state_int}):
- log: "not yet ${this.state} (${global.maxtry} try remaining)"
- sleep: 1000
- script: |-
return {"result": 0, "maxtry": ${globals.maxtry} - 1};
- if (${response.maxtry} == 0):
- return:
type: error
message: "WAITING FOR RUNNING TIMEOUT, LAST KNOWN ENV STATUS IS: ${response.env.status}"
- else:
- setGlobals:
maxtry: ${response.maxtry}
- waitForState:
state: ${this.state}
- else:
- log: "${env.envName} have reached the ${this.state} state :)"
settings:
fields:
- name: targetRegion
type: regionlist
caption: Targeted Region
required: true