-
Notifications
You must be signed in to change notification settings - Fork 9
/
enableAutoScaling.js
101 lines (84 loc) · 2.14 KB
/
enableAutoScaling.js
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
var APPID = getParam("TARGET_APPID"),
QUOTA_MAX_NODES = "environment.maxsamenodescount",
VALUE_TYPE = "PERCENTAGES",
RESOURCE_TYPE = "CPU",
NODE_GROUP = "cp",
oTriggerActions,
nMaxNodesCount,
oRespTurnOn,
aQuotas,
oData,
oResp;
oTriggerActions = {
add: "ADD_NODE",
remove: "REMOVE_NODE"
};
oResp = jelastic.billing.account.GetQuotas(appid, session);
if (oResp.result != 0) {
return oResp;
}
aQuotas = oResp.array;
for (var i = 0, n = aQuotas.length; i < n; i += 1) {
if (aQuotas[i].quota && aQuotas[i].quota.name == QUOTA_MAX_NODES) {
nMaxNodesCount = aQuotas[i].value;
break;
}
}
oResp = jelastic.env.trigger.GetTriggers(APPID, session, oTriggerActions.add);
if (oResp.array.length > 0) {
oResp = jelastic.env.trigger.DeleteTrigger(APPID, session, oResp.array[0].id);
}
oData = {
isEnabled: true,
name: "hs-add",
nodeGroup: NODE_GROUP,
period: 5,
condition: {
type: "GREATER",
value: 80,
resourceType: RESOURCE_TYPE,
valueType: VALUE_TYPE
},
actions: [
{
type: oTriggerActions.add,
customData: {
limit: nMaxNodesCount || 3,
count: 1,
notify: false
}
}
]
};
oRespTurnOn = jelastic.env.trigger.AddTrigger(APPID, session, oData);
if (oRespTurnOn.result != 0) {
return oRespTurnOn;
}
oResp = jelastic.env.trigger.GetTriggers(APPID, session, oTriggerActions.remove);
if (oResp.array.length > 0) {
oResp = jelastic.env.trigger.DeleteTrigger(APPID, session, oResp.array[0].id);
}
oData = {
isEnabled: true,
name: "hs-remove",
nodeGroup: NODE_GROUP,
period: 15,
condition: {
type: "LESS",
value: 5,
resourceType: RESOURCE_TYPE,
valueType: VALUE_TYPE
},
actions: [
{
type: oTriggerActions.remove,
customData: {
limit: 2,
count: 1,
notify: false
}
}
]
};
oRespTurnOff = jelastic.env.trigger.AddTrigger(APPID, session, oData);
return oRespTurnOff;