-
Notifications
You must be signed in to change notification settings - Fork 2
/
manifest.jps
227 lines (192 loc) · 8.65 KB
/
manifest.jps
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
type: install
name: Wait For Dependency Before Starting Environment
jpsVersion: 7.3.1
description: |
This add-on will pause when trying to start the target environment if the associated environment is not started or is not operational.
If you need to confirm that the associated environment not only started but is fully operational also, select "Run Additional Script" and implement your custom wait condition.
This wait condition will run as a shell script on the first node of the associated environment, either if it is already running or as soon as it enters the running state.\
You can install the add-on several times if you need to enable the dependency between more than one environment
settings:
fields:
- type: compositefield
hideCaption: true
align: middle
defaultMargins: 0 10 0 0
items:
- type: displayfield
value: Environment
- name: targetEnvName
type: envlist
editable: true
required: true
valueField: shortdomain
flex: 1
- type: displayfield
cls: x-form-item-label
value: depends on
- name: dependsOnEnvName
type: envlist
editable: true
required: true
margins: 0 0 0 0
valueField: shortdomain
disableInactive: false
flex: 1
- type: separator
- type: list
name: nodeGroup
caption: Attach Add-On To
width: 230
required: true
tooltip: |
The add-on will be attached to the selected node group of the target environment.
To remove the dependency between environments, simply remove the add-on using the "Add-ons" panel or through the "Uninstall" API
dependsOn:
envName: {}
- type: compositefield
align: middle
defaultMargins: 0 10 0 0
caption: Max Attempts
tooltip: |
The add-on will check the environment status based on the selected maximum attempts and interval settings.
Please note that these settings are not taken into account while running the additional script
items:
- type: spinner
name: maxRetries
width: 70
min: 1
max: 360
default: 100
- type: displayfield
value: with a
- type: spinner
name: retryInterval
width: 60
min: 1
max: 5
default: 3
- type: displayfield
value: sec interval
- caption: Run Additional Script
name: useAdditionalWaitCondition
type: toggle
default: false
tooltip: |
Activates an additional wait condition.
A shell script will run on the first node of the associated environment, either if it is already running or as soon as it enters the running state.
The placeholder ${DEPENDS_ON_DOMAIN} can be used to refer to the domain of the associated environment.
The default value sets a 5-minute timeout to check that the associated environment responds from the external endpoint with an HTTP status code of 200
showIf:
true:
- type: text
name: waitCmd
hideCaption: true
height: 160
required: true
default: |
timeout 300 bash -c 'envip=$(dig +short "${DEPENDS_ON_DOMAIN}" @8.8.8.8 | tail -n1); while [[ "$(curl -I ''http://${DEPENDS_ON_DOMAIN}/'' --resolve ${DEPENDS_ON_DOMAIN}:80:$envip -s -o /dev/null -w ''%{http_code}'')" != "200" ]]; do sleep 3; done' || false
- caption: Start Despite Failure
name: startDespiteFailure
type: toggle
default: true
tooltip: |
Start the target environment even if all wait conditions have failed and the associated environment is non-operational.
Please note that disabling this option may result in the inability to run the target environment. In such cases, use the "Uninstall" API to remove the add-on
onBeforeInit: |
let resp = api.env.control.GetBasicEnvsInfo();
if (resp.result !== 0) return resp;
let envInfos = resp.infos, envs = [], nodes = {};
for (let envInfo of envInfos) {
let env = envInfo.env;
if (env.status == 1)
for (let node of envInfo.nodes) {
nodes[env.envName] = nodes[env.envName] || [];
nodes[env.envName].groups = nodes[env.envName].groups || {};
if (!nodes[env.envName].groups[node.nodeGroup])
nodes[env.envName].push({
value: node.nodeGroup,
caption: (node.displayName || node.name) + ' (' + node.nodeGroup + ')'
});
nodes[env.envName].groups[node.nodeGroup] = true;
}
}
jps.settings.fields[2].dependsOn.targetEnvName = nodes;
return { result: 0, settings: jps.settings };
onInstall:
- if ('${settings.targetEnvName}' == '${settings.dependsOnEnvName}'):
return:
type: warning
message: The environment '${settings.targetEnvName}' cannot depend on itself
- env.control.GetEnvInfo:
envName: ${settings.dependsOnEnvName}
lazy: true
- setGlobals:
DEPENDS_ON_DOMAIN: ${response.env.domain}
- install:
envName: ${settings.targetEnvName}
nodeGroup: ${settings.nodeGroup}
jps:
type: update
name: Wait Before Start
description: Wait For '${settings.dependsOnEnvName}'
onBeforeStart:
- waitForEnvRunningStatus:
envName: ${settings.dependsOnEnvName}
logPrefix: ${settings.targetEnvName}
maxRetries: ${settings.maxRetries}
interval: ${settings.retryInterval}
- switch (response.status):
0:
if (!${settings.startDespiteFailure}):
stopEvent:
type: warning
message: The associated environment, ${settings.dependsOnEnvName}, does not exist
1:
if (${settings.useAdditionalWaitCondition}):
- waitOnCustomCondition:
waitCondition: |-
${settings.waitCmd}
targetEnvName: ${settings.dependsOnEnvName}
variables:
DEPENDS_ON_DOMAIN: ${globals.DEPENDS_ON_DOMAIN}
- if ('${response.exitStatus}' != '0'):
if (!${settings.startDespiteFailure}):
stopEvent:
type: warning
message: The associated environment, ${settings.dependsOnEnvName}, is currently unresponsive
- else:
log: The associated environment, ${settings.dependsOnEnvName}, is operational
default:
if (!${settings.startDespiteFailure}):
stopEvent:
type: warning
message: The associated environment, ${settings.dependsOnEnvName}, is not running
actions:
waitForEnvRunningStatus:
- envName: ${this.envName}
maxRetries: ${this.maxRetries}
interval: ${this.interval} # seconds
logPrefix: ${this.logPrefix}
script: |
import com.hivext.api.Response;
let retries = 0, waitInterval = (interval * 1000), resp
do {
java.lang.Thread.sleep(retries ? waitInterval : 0)
resp = api.env.control.GetEnvInfo({ envName: envName, lazy: true })
if (resp.result != 0 && resp.result != Response.APPLICATION_NOT_EXIST) return resp;
api.marketplace.console.WriteLog(logPrefix + " [" + (retries + 1) + "/"+ maxRetries + "] checking " + envName + " status result: " + (resp.env ? resp.env.status : resp ));
} while (resp.result != Response.APPLICATION_NOT_EXIST && resp.env.status != 1 && (++retries < maxRetries))
return { result: 0, status: (resp.env || {}).status || 0, retries: retries }
waitOnCustomCondition:
- env.control.GetEnvInfo:
envName: ${this.targetEnvName}
- set:
nodeId: ${response.nodes[0].id}
- waitCondition: ${this.waitCondition}
variables: ${this.variables}
script: |
import org.apache.commons.lang3.text.StrSubstitutor
waitCondition = new StrSubstitutor(JSON.parse(variables || '{}'), "${", "}").replace(waitCondition).trim()
api.marketplace.console.WriteLog(waitCondition)
let resp = api.env.control.ExecCmdById({ envName: '${this.targetEnvName}', nodeId: '${this.nodeId}', commandList: [{ command: waitCondition }] })
return { result: 0, exitStatus: (resp.responses || [{}])[0].exitStatus, data: resp }