-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmanifest.yml
247 lines (230 loc) · 7.89 KB
/
manifest.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
246
247
type: update
id: start-stop-scheduler
jpsVersion: 0.2
logo: /images/logo.png
baseUrl: https://raw.githubusercontent.com/jelastic-jps/start-stop-scheduler/v2.0.0
description:
text: "A simple weekly scheduler to automatically start and stop the environment within the specified Time Zone"
short: The scheduler for automatic environment hibernation and wake-up
name: Env Start/Stop Scheduler
targetNodes:
nodeGroup: '*'
onBeforeInit: |
import java.util.TimeZone;
var zones = toNative(TimeZone.getAvailableIDs());
var values = {};
for (var i = 0, n = zones.length; i < n; i++) {
var offset = TimeZone.getTimeZone(zones[i]).getRawOffset()/3600000;
var m = offset % 1;
if (m != 0) m = Math.abs(m * 60);
if (m < 10) m = "0" + m;
var h = Math.floor(offset);
if (Math.abs(h) < 10) h = h < 0 ? "-0" + Math.abs(h) : "+0" + h; else if (h >= 0) h = "+" + h;
values[zones[i]] = zones[i] + (zones[i] == "GMT" ? "" : " (GMT" + h + ":" + m + ")");
}
jps.settings.fields.push({
name: "tz",
caption: "Time Zone",
type: "list",
required: true,
width: 250,
editable: true,
values: values
})
return jps;
settings:
fields:
- caption: Stop
type: toggle
name: stopCron
default: false
showIf:
true:
- type: string
name: stopTime
caption: Time
inputType: time
default: "19:00"
cls: x-form-text
width: 120
required: true
- caption: Days
type: compositefield
name: cf1
defaultMargins: 0 12 0 0
items:
- name: sun1
value: true
type: checkbox
caption: Su
- name: mon1
value: true
type: checkbox
caption: Mo
- name: tue1
value: true
type: checkbox
caption: Tu
- name: wed1
value: true
type: checkbox
caption: We
- name: thu1
value: true
type: checkbox
caption: Th
- name: fri1
value: true
type: checkbox
caption: Fr
- name: sat1
value: true
type: checkbox
caption: Sa
- type: spacer
- caption: Start
type: toggle
name: startCron
default: false
showIf:
true:
- type: string
name: startTime
caption: Time
inputType: time
default: "09:00"
cls: x-form-text
width: 120
required: true
- caption: Days
type: compositefield
name: cf3
defaultMargins: 0 12 0 0
items:
- name: sun2
value: true
type: checkbox
caption: Su
- name: mon2
value: true
type: checkbox
caption: Mo
- name: tue2
value: true
type: checkbox
caption: Tu
- name: wed2
value: true
type: checkbox
caption: We
- name: thu2
value: true
type: checkbox
caption: Th
- name: fri2
value: true
type: checkbox
caption: Fr
- name: sat2
value: true
type: checkbox
caption: Sa
- type: spacer
onInstall:
- script: |
var targetAppid = (${fn.compareEngine(8.6.1)} >= 0) ? "${env.appid}" : appid;
return { result: 0, onAfterReturn: { setGlobals: { appid: targetAppid }}}
- create
onUninstall: uninstall
onBeforeDelete: uninstall
actions:
convert:
- script: |
var resp = {result:0, onAfterReturn: {setGlobals:{start: "", stop: "", daysStart: "", daysStop: ""}}}, offset = java.util.TimeZone.getTimeZone("${settings.tz}").getRawOffset(),
setGlobals = resp.onAfterReturn.setGlobals,
dayNames = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
stopCron = ${settings.stopCron:false}, startCron = ${settings.startCron:false},
daysStart = [], daysStop = [], success;
if (stopCron) {
var time = "${settings.stopTime}".split(":"),
d1 = new Date(2020, 1, 10, parseInt(time[0],10), parseInt(time[1],10)),
d2 = new Date(d1.getTime() - offset),
dd = d2.getDate() - d1.getDate(),
days = getDays([${settings.sun1:0}, ${settings.mon1:0}, ${settings.tue1:0}, ${settings.wed1:0}, ${settings.thu1:0}, ${settings.fri1:0}, ${settings.sat1:0}], dd);
for (var i = 0; i < days.length; i++) daysStop.push(dayNames[days[i]]);
stopCron = (daysStop.length != 0);
if (stopCron) {
setGlobals.stop = d2.getMinutes() + " " + d2.getHours() + " * * " + days.join(",");
setGlobals.daysStop = daysStop.join(", ");
}
}
if (startCron) {
var time = "${settings.startTime}".split(":"),
d1 = new Date(2020, 1, 10, parseInt(time[0],10), parseInt(time[1],10)),
d2 = new Date(d1.getTime() - offset),
dd = d2.getDate() - d1.getDate(),
days = getDays([${settings.sun2:0}, ${settings.mon2:0}, ${settings.tue2:0}, ${settings.wed2:0}, ${settings.thu2:0}, ${settings.fri2:0}, ${settings.sat2:0}], dd);
for (var i = 0; i < days.length; i++) daysStart.push(dayNames[days[i]]);
startCron = (daysStart.length != 0);
if (startCron) {
setGlobals.start = d2.getMinutes() + " " + d2.getHours() + " * * " + days.join(",");
setGlobals.daysStart = daysStart.join(", ");
}
}
if (stopCron && !startCron) {
success = "success-nostart.md";
} else if (startCron && !stopCron) {
success = "success-nostop.md";
} else if (!stopCron && !startCron) {
success = "success-start-stop-disabled.md"
}
setGlobals.success = success || "success.md";
function getDays(settings, dd) {
var days = [];
for (var i = 0, n = settings.length; i < n; i++) {
if (settings[i]) {
var day = i + dd;
if (day < 0) day +=7; else if (day > 6) day -=7;
days.push(day);
}
}
days.sort();
return days;
}
return resp;
create:
- convert
- execScript: "${baseUrl}/scripts/start-stop.js?r_${fn.random}"
- script: |
import com.hivext.api.core.utils.Transport;
var url = "${baseUrl}/scripts/uninstall.js?r_${fn.random}"
var body = new Transport().get(url);
return api.dev.scripting.CreateScript({appid: "${globals.appid}", session: session, name: 'uninstall-${env.envName}-start-stop', type: 'js', code: body});
update:
- convert
- execScript
execScript:
- script: "/scripts/create-service.js?r_${fn.random}"
params:
url: ${this:}
name: "${env.envName}-start-stop"
start: "${globals.start:}"
stop: "${globals.stop:}"
uninstall:
script: |
return jelastic.utils.scheduler.CreateEnvTask({
appid: "${globals.appid}",
session: session,
envName: "${env.envName}",
script: "uninstall-${env.envName}-start-stop",
trigger: "once_delay:1000",
description: "uninstall start-stop addon tasks for ${env.envName}",
params: {name: "${env.envName}-start-stop"}
})
buttons:
settings: main
caption: Configure
loadingText: Updating...
action: update
successText: The scheduler has been successfully updated.
success: /text/${globals.success}