String scaleDownActionName = generateAutoScaleScaleDownActionName(vmGroupIdentifier);
String scaleUpActionName = generateAutoScaleScaleUpActionName(vmGroupIdentifier);
String mtName = generateSnmpMetricTableName(vmGroupIdentifier);
String monitorName = generateSnmpMonitorName(vmGroupIdentifier);
AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO();
AutoScaleVmProfileTO profileTO = vmGroupTO.getProfile();
List<AutoScalePolicyTO> policies = vmGroupTO.getPolicies();
int interval = vmGroupTO.getInterval();
List<Pair<String, String>> counterParams = profileTO.getCounterParamList();
String snmpCommunity = null;
int snmpPort = DEFAULT_SNMP_PORT;
long cur_prirotiy = 1;
// get the session persistence parameters
List<Pair<String, String>> paramsList = profileTO.getCounterParamList();
for(Pair<String,String> param : paramsList) {
if ("snmpcommunity".equalsIgnoreCase(param.first())) {
snmpCommunity = param.second();
} else if ("snmpport".equalsIgnoreCase(param.first())) {
snmpPort = Integer.parseInt(param.second());
}
}
try
{
// Set min and max autoscale members;
// add lb vserver lb http 10.102.31.100 80 -minAutoscaleMinMembers 3 -maxAutoscaleMembers 10
int minAutoScaleMembers = vmGroupTO.getMinMembers();
int maxAutoScaleMembers = vmGroupTO.getMaxMembers();
lbvserver vserver = new lbvserver();
try {
vserver.set_name(nsVirtualServerName);
vserver.set_minautoscalemembers(minAutoScaleMembers);
vserver.set_maxautoscalemembers(maxAutoScaleMembers);
vserver.update(_netscalerService, vserver);
} catch (Exception e) {
// Ignore Exception on cleanup
if (!isCleanUp)
throw e;
}
/* AutoScale Config */
// Add AutoScale Profile
// add autoscale profile lb_asprofile CLOUDSTACK -url -http:// 10.102.31.34:8080/client/api- -apiKey abcdef
// -sharedSecret xyzabc
String apiKey = profileTO.getAutoScaleUserApiKey();
String secretKey = profileTO.getAutoScaleUserSecretKey();
String url = profileTO.getCloudStackApiUrl();
autoscaleprofile autoscaleProfile = new autoscaleprofile();
try {
autoscaleProfile.set_name(profileName);
autoscaleProfile.set_type("CLOUDSTACK");
autoscaleProfile.set_apikey(apiKey);
autoscaleProfile.set_sharedsecret(secretKey);
autoscaleProfile.set_url(url);
autoscaleProfile.add(_netscalerService, autoscaleProfile);
} catch (Exception e) {
// Ignore Exception on cleanup
if (!isCleanUp)
throw e;
}
// Add Timer
nstimer timer = new nstimer();
try {
timer.set_name(timerName);
timer.set_interval(interval);
timer.add(_netscalerService, timer);
} catch (Exception e) {
// Ignore Exception on cleanup
if (!isCleanUp)
throw e;
}
// AutoScale Actions
Integer scaleUpQuietTime = null;
Integer scaleDownQuietTime = null;
for (AutoScalePolicyTO autoScalePolicyTO : policies) {
if(scaleUpQuietTime == null) {
if(isScaleUpPolicy(autoScalePolicyTO)) {
scaleUpQuietTime = autoScalePolicyTO.getQuietTime();
if(scaleDownQuietTime != null) {
break;
}
}
}
if(scaleDownQuietTime == null) {
if(isScaleDownPolicy(autoScalePolicyTO)) {
scaleDownQuietTime = autoScalePolicyTO.getQuietTime();
if(scaleUpQuietTime != null) {
break;
}
}
}
}
// Add AutoScale ScaleUp action
// add autoscale action lb_scaleUpAction provision -vserver lb -profilename lb_asprofile -params
// -lbruleid=1234&command=deployvm&zoneid=10&templateid=5&serviceofferingid=3- -quiettime 300
com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction scaleUpAction = new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
try {
scaleUpAction.set_name(scaleUpActionName);
scaleUpAction.set_type("SCALE_UP"); // TODO: will this be called provision?
scaleUpAction.set_vserver(nsVirtualServerName); // Actions Vserver, the one that is autoscaled, with CS
// now both are same. Not exposed in API.
scaleUpAction.set_profilename(profileName);
scaleUpAction.set_quiettime(scaleUpQuietTime);
String scaleUpParameters = "command=deployVirtualMachine" + "&" +
ApiConstants.ZONE_ID + "=" + profileTO.getZoneId()+ "&" +
ApiConstants.SERVICE_OFFERING_ID + "=" + profileTO.getServiceOfferingId()+ "&" +
ApiConstants.TEMPLATE_ID + "=" + profileTO.getTemplateId()+ "&" +
ApiConstants.DISPLAY_NAME + "=" + profileTO.getVmName()+ "&" +
((profileTO.getNetworkId() == null)? "" : (ApiConstants.NETWORK_IDS + "=" + profileTO.getNetworkId()+ "&")) +
((profileTO.getOtherDeployParams() == null)? "" : (profileTO.getOtherDeployParams() + "&")) +
"lbruleid=" + loadBalancerTO.getUuid();
scaleUpAction.set_parameters(scaleUpParameters);
scaleUpAction.add(_netscalerService, scaleUpAction);
} catch (Exception e) {
// Ignore Exception on cleanup
if (!isCleanUp)
throw e;
}
com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction scaleDownAction = new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
Integer destroyVmGracePeriod = profileTO.getDestroyVmGraceperiod();
try {
scaleDownAction.set_name(scaleDownActionName);
scaleDownAction.set_type("SCALE_DOWN"); // TODO: will this be called de-provision?
scaleDownAction.set_vserver(nsVirtualServerName); // TODO: no global option as of now through Nitro.
// Testing cannot be done.