Repository navigation
Expand file tree
/
Copy pathLoadBalancerTO.java
More file actions
584 lines (482 loc) · 19.5 KB
/
Copy pathLoadBalancerTO.java
File metadata and controls
584 lines (482 loc) · 19.5 KB
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.agent.api.to;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.cloud.network.as.AutoScalePolicy;
import com.cloud.network.as.AutoScaleVmGroup;
import com.cloud.network.as.AutoScaleVmProfile;
import com.cloud.network.as.Condition;
import com.cloud.network.as.Counter;
import com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy;
import com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup;
import com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile;
import com.cloud.network.lb.LoadBalancingRule.LbCondition;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
import com.cloud.network.lb.LoadBalancingRule.LbSslCert;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.utils.Pair;
public class LoadBalancerTO {
String uuid;
String srcIp;
int srcPort;
String protocol;
String lbProtocol;
String algorithm;
boolean revoked;
boolean alreadyAdded;
boolean inline;
DestinationTO[] destinations;
private StickinessPolicyTO[] stickinessPolicies;
private HealthCheckPolicyTO[] healthCheckPolicies;
private LbSslCert sslCert; /* XXX: Should this be SslCertTO? */
private AutoScaleVmGroupTO autoScaleVmGroupTO;
final static int MAX_STICKINESS_POLICIES = 1;
final static int MAX_HEALTHCHECK_POLICIES = 1;
public LoadBalancerTO(String uuid, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, boolean inline,
List<LbDestination> destinations) {
if (destinations == null) { // for autoscaleconfig destinations will be null;
destinations = new ArrayList<LbDestination>();
}
this.uuid = uuid;
this.srcIp = srcIp;
this.srcPort = srcPort;
this.protocol = protocol;
this.algorithm = algorithm;
this.revoked = revoked;
this.alreadyAdded = alreadyAdded;
this.inline = inline;
this.destinations = new DestinationTO[destinations.size()];
this.stickinessPolicies = null;
this.sslCert = null;
this.lbProtocol = null;
int i = 0;
for (LbDestination destination : destinations) {
this.destinations[i++] = new DestinationTO(destination.getIpAddress(), destination.getDestinationPortStart(), destination.isRevoked(), false);
}
}
public LoadBalancerTO(String id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, boolean inline,
List<LbDestination> argDestinations, List<LbStickinessPolicy> stickinessPolicies) {
this(id, srcIp, srcPort, protocol, algorithm, revoked, alreadyAdded, inline, argDestinations, stickinessPolicies, null, null, null);
}
public LoadBalancerTO(String id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, boolean inline,
List<LbDestination> argDestinations, List<LbStickinessPolicy> stickinessPolicies, List<LbHealthCheckPolicy> healthCheckPolicies, LbSslCert sslCert,
String lbProtocol) {
this(id, srcIp, srcPort, protocol, algorithm, revoked, alreadyAdded, inline, argDestinations);
this.stickinessPolicies = null;
this.healthCheckPolicies = null;
if (stickinessPolicies != null && stickinessPolicies.size() > 0) {
this.stickinessPolicies = new StickinessPolicyTO[MAX_STICKINESS_POLICIES];
int index = 0;
for (LbStickinessPolicy stickinesspolicy : stickinessPolicies) {
if (!stickinesspolicy.isRevoked()) {
this.stickinessPolicies[index] = new StickinessPolicyTO(stickinesspolicy.getMethodName(), stickinesspolicy.getParams());
index++;
if (index == MAX_STICKINESS_POLICIES)
break;
}
}
if (index == 0)
this.stickinessPolicies = null;
}
if (healthCheckPolicies != null && healthCheckPolicies.size() > 0) {
this.healthCheckPolicies = new HealthCheckPolicyTO[MAX_HEALTHCHECK_POLICIES];
int index = 0;
for (LbHealthCheckPolicy hcp : healthCheckPolicies) {
this.healthCheckPolicies[0] =
new HealthCheckPolicyTO(hcp.getpingpath(), hcp.getDescription(), hcp.getResponseTime(), hcp.getHealthcheckInterval(), hcp.getHealthcheckThresshold(),
hcp.getUnhealthThresshold(), hcp.isRevoked());
index++;
if (index == MAX_HEALTHCHECK_POLICIES)
break;
}
if (index == 0)
this.healthCheckPolicies = null;
}
this.sslCert = sslCert;
this.lbProtocol = lbProtocol;
}
protected LoadBalancerTO() {
}
public String getUuid() {
return uuid;
}
public String getSrcIp() {
return srcIp;
}
public int getSrcPort() {
return srcPort;
}
public String getAlgorithm() {
return algorithm;
}
public String getProtocol() {
return protocol;
}
public String getLbProtocol() {
return lbProtocol;
}
public void setLbProtocol(String lbProtocol) {
this.lbProtocol = lbProtocol;
}
public boolean isRevoked() {
return revoked;
}
public boolean isAlreadyAdded() {
return alreadyAdded;
}
public boolean isInline() {
return inline;
}
public StickinessPolicyTO[] getStickinessPolicies() {
return stickinessPolicies;
}
public HealthCheckPolicyTO[] getHealthCheckPolicies() {
return healthCheckPolicies;
}
public DestinationTO[] getDestinations() {
return destinations;
}
public AutoScaleVmGroupTO getAutoScaleVmGroupTO() {
return autoScaleVmGroupTO;
}
public void setAutoScaleVmGroupTO(AutoScaleVmGroupTO autoScaleVmGroupTO) {
this.autoScaleVmGroupTO = autoScaleVmGroupTO;
}
public boolean isAutoScaleVmGroupTO() {
return this.autoScaleVmGroupTO != null;
}
public LbSslCert getSslCert() {
return this.sslCert;
}
public static class StickinessPolicyTO {
private String _methodName;
private List<Pair<String, String>> _paramsList;
public String getMethodName() {
return _methodName;
}
public List<Pair<String, String>> getParams() {
return _paramsList;
}
public StickinessPolicyTO(String methodName, List<Pair<String, String>> paramsList) {
this._methodName = methodName;
this._paramsList = paramsList;
}
}
public static class HealthCheckPolicyTO {
private String pingPath;
private String description;
private int responseTime;
private int healthcheckInterval;
private int healthcheckThresshold;
private int unhealthThresshold;
private boolean revoke = false;
public HealthCheckPolicyTO(String pingPath, String description, int responseTime, int healthcheckInterval, int healthcheckThresshold, int unhealthThresshold,
boolean revoke) {
this.description = description;
this.pingPath = pingPath;
this.responseTime = responseTime;
this.healthcheckInterval = healthcheckInterval;
this.healthcheckThresshold = healthcheckThresshold;
this.unhealthThresshold = unhealthThresshold;
this.revoke = revoke;
}
public HealthCheckPolicyTO() {
}
public String getpingPath() {
return pingPath;
}
public String getDescription() {
return description;
}
public int getResponseTime() {
return responseTime;
}
public int getHealthcheckInterval() {
return healthcheckInterval;
}
public int getHealthcheckThresshold() {
return healthcheckThresshold;
}
public int getUnhealthThresshold() {
return unhealthThresshold;
}
public void setRevoke(boolean revoke) {
this.revoke = revoke;
}
public boolean isRevoked() {
return revoke;
}
}
public static class DestinationTO {
String destIp;
int destPort;
boolean revoked;
boolean alreadyAdded;
String monitorState;
public DestinationTO(String destIp, int destPort, boolean revoked, boolean alreadyAdded) {
this.destIp = destIp;
this.destPort = destPort;
this.revoked = revoked;
this.alreadyAdded = alreadyAdded;
}
protected DestinationTO() {
}
public String getDestIp() {
return destIp;
}
public int getDestPort() {
return destPort;
}
public boolean isRevoked() {
return revoked;
}
public boolean isAlreadyAdded() {
return alreadyAdded;
}
public void setMonitorState(String state) {
this.monitorState = state;
}
public String getMonitorState() {
return monitorState;
}
}
public static class CounterTO implements Serializable {
private static final long serialVersionUID = 2L;
private final String name;
private final String source;
private final String value;
public CounterTO(String name, String source, String value) {
this.name = name;
this.source = source;
this.value = value;
}
public String getName() {
return name;
}
public String getSource() {
return source;
}
public String getValue() {
return value;
}
}
public static class ConditionTO implements Serializable {
private static final long serialVersionUID = 2L;
private final long threshold;
private final String relationalOperator;
private final CounterTO counter;
public ConditionTO(long threshold, String relationalOperator, CounterTO counter) {
this.threshold = threshold;
this.relationalOperator = relationalOperator;
this.counter = counter;
}
public long getThreshold() {
return threshold;
}
public String getRelationalOperator() {
return relationalOperator;
}
public CounterTO getCounter() {
return counter;
}
}
public static class AutoScalePolicyTO implements Serializable {
private static final long serialVersionUID = 2L;
private final long id;
private final int duration;
private final int quietTime;
private String action;
boolean revoked;
private final List<ConditionTO> conditions;
public AutoScalePolicyTO(long id, int duration, int quietTime, String action, List<ConditionTO> conditions, boolean revoked) {
this.id = id;
this.duration = duration;
this.quietTime = quietTime;
this.conditions = conditions;
this.action = action;
this.revoked = revoked;
}
public long getId() {
return id;
}
public int getDuration() {
return duration;
}
public int getQuietTime() {
return quietTime;
}
public String getAction() {
return action;
}
public boolean isRevoked() {
return revoked;
}
public List<ConditionTO> getConditions() {
return conditions;
}
}
public static class AutoScaleVmProfileTO implements Serializable {
private static final long serialVersionUID = 2L;
private final String zoneId;
private final String domainId;
private final String serviceOfferingId;
private final String templateId;
private final String otherDeployParams;
private final List<Pair<String, String>> counterParamList;
private final Integer destroyVmGraceperiod;
private final String cloudStackApiUrl;
private final String autoScaleUserApiKey;
private final String autoScaleUserSecretKey;
private final String vmName;
private final String networkId;
public AutoScaleVmProfileTO(String zoneId, String domainId, String cloudStackApiUrl, String autoScaleUserApiKey, String autoScaleUserSecretKey,
String serviceOfferingId, String templateId, String vmName, String networkId, String otherDeployParams, List<Pair<String, String>> counterParamList,
Integer destroyVmGraceperiod) {
this.zoneId = zoneId;
this.domainId = domainId;
this.serviceOfferingId = serviceOfferingId;
this.templateId = templateId;
this.otherDeployParams = otherDeployParams;
this.counterParamList = counterParamList;
this.destroyVmGraceperiod = destroyVmGraceperiod;
this.cloudStackApiUrl = cloudStackApiUrl;
this.autoScaleUserApiKey = autoScaleUserApiKey;
this.autoScaleUserSecretKey = autoScaleUserSecretKey;
this.vmName = vmName;
this.networkId = networkId;
}
public String getZoneId() {
return zoneId;
}
public String getDomainId() {
return domainId;
}
public String getServiceOfferingId() {
return serviceOfferingId;
}
public String getTemplateId() {
return templateId;
}
public String getOtherDeployParams() {
return otherDeployParams;
}
public List<Pair<String, String>> getCounterParamList() {
return counterParamList;
}
public Integer getDestroyVmGraceperiod() {
return destroyVmGraceperiod;
}
public String getCloudStackApiUrl() {
return cloudStackApiUrl;
}
public String getAutoScaleUserApiKey() {
return autoScaleUserApiKey;
}
public String getAutoScaleUserSecretKey() {
return autoScaleUserSecretKey;
}
public String getVmName() {
return vmName;
}
public String getNetworkId() {
return networkId;
}
}
public static class AutoScaleVmGroupTO implements Serializable {
private static final long serialVersionUID = 2L;
private final String uuid;
private final int minMembers;
private final int maxMembers;
private final int memberPort;
private final int interval;
private final List<AutoScalePolicyTO> policies;
private final AutoScaleVmProfileTO profile;
private final String state;
private final String currentState;
AutoScaleVmGroupTO(String uuid, int minMembers, int maxMembers, int memberPort, int interval, List<AutoScalePolicyTO> policies, AutoScaleVmProfileTO profile,
String state, String currentState) {
this.uuid = uuid;
this.minMembers = minMembers;
this.maxMembers = maxMembers;
this.memberPort = memberPort;
this.interval = interval;
this.policies = policies;
this.profile = profile;
this.state = state;
this.currentState = currentState;
}
public String getUuid() {
return uuid;
}
public int getMinMembers() {
return minMembers;
}
public int getMaxMembers() {
return maxMembers;
}
public int getMemberPort() {
return memberPort;
}
public int getInterval() {
return interval;
}
public List<AutoScalePolicyTO> getPolicies() {
return policies;
}
public AutoScaleVmProfileTO getProfile() {
return profile;
}
public String getState() {
return state;
}
public String getCurrentState() {
return currentState;
}
}
public void setAutoScaleVmGroup(LbAutoScaleVmGroup lbAutoScaleVmGroup) {
List<LbAutoScalePolicy> lbAutoScalePolicies = lbAutoScaleVmGroup.getPolicies();
List<AutoScalePolicyTO> autoScalePolicyTOs = new ArrayList<AutoScalePolicyTO>(lbAutoScalePolicies.size());
for (LbAutoScalePolicy lbAutoScalePolicy : lbAutoScalePolicies) {
List<LbCondition> lbConditions = lbAutoScalePolicy.getConditions();
List<ConditionTO> conditionTOs = new ArrayList<ConditionTO>(lbConditions.size());
for (LbCondition lbCondition : lbConditions) {
Counter counter = lbCondition.getCounter();
CounterTO counterTO = new CounterTO(counter.getName(), counter.getSource().toString(), "" + counter.getValue());
Condition condition = lbCondition.getCondition();
ConditionTO conditionTO = new ConditionTO(condition.getThreshold(), condition.getRelationalOperator().toString(), counterTO);
conditionTOs.add(conditionTO);
}
AutoScalePolicy autoScalePolicy = lbAutoScalePolicy.getPolicy();
autoScalePolicyTOs.add(new AutoScalePolicyTO(autoScalePolicy.getId(), autoScalePolicy.getDuration(), autoScalePolicy.getQuietTime(),
autoScalePolicy.getAction(), conditionTOs, lbAutoScalePolicy.isRevoked()));
}
LbAutoScaleVmProfile lbAutoScaleVmProfile = lbAutoScaleVmGroup.getProfile();
AutoScaleVmProfile autoScaleVmProfile = lbAutoScaleVmProfile.getProfile();
AutoScaleVmProfileTO autoScaleVmProfileTO =
new AutoScaleVmProfileTO(lbAutoScaleVmProfile.getZoneId(), lbAutoScaleVmProfile.getDomainId(), lbAutoScaleVmProfile.getCsUrl(),
lbAutoScaleVmProfile.getAutoScaleUserApiKey(), lbAutoScaleVmProfile.getAutoScaleUserSecretKey(), lbAutoScaleVmProfile.getServiceOfferingId(),
lbAutoScaleVmProfile.getTemplateId(), lbAutoScaleVmProfile.getVmName(), lbAutoScaleVmProfile.getNetworkId(), autoScaleVmProfile.getOtherDeployParams(),
autoScaleVmProfile.getCounterParams(), autoScaleVmProfile.getDestroyVmGraceperiod());
AutoScaleVmGroup autoScaleVmGroup = lbAutoScaleVmGroup.getVmGroup();
autoScaleVmGroupTO =
new AutoScaleVmGroupTO(autoScaleVmGroup.getUuid(), autoScaleVmGroup.getMinMembers(), autoScaleVmGroup.getMaxMembers(), autoScaleVmGroup.getMemberPort(),
autoScaleVmGroup.getInterval(), autoScalePolicyTOs, autoScaleVmProfileTO, autoScaleVmGroup.getState(), lbAutoScaleVmGroup.getCurrentState());
}
}