use of com.citrix.netscaler.nitro.resource.config.lb.lbmonitor in project cloudstack by apache.
the class NetscalerResource method disableAutoScaleConfig.
private synchronized boolean disableAutoScaleConfig(final LoadBalancerTO loadBalancerTO, final boolean isCleanUp) throws Exception {
final String vmGroupIdentifier = generateAutoScaleVmGroupIdentifier(loadBalancerTO);
final String profileName = generateAutoScaleProfileName(vmGroupIdentifier);
final String timerName = generateAutoScaleTimerName(vmGroupIdentifier);
final String scaleDownActionName = generateAutoScaleScaleDownActionName(vmGroupIdentifier);
final String scaleUpActionName = generateAutoScaleScaleUpActionName(vmGroupIdentifier);
final String mtName = generateSnmpMetricTableName(vmGroupIdentifier);
final String monitorName = generateSnmpMonitorName(vmGroupIdentifier);
final String serviceGroupName = generateAutoScaleServiceGroupName(loadBalancerTO);
final AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO();
final List<AutoScalePolicyTO> policies = vmGroupTO.getPolicies();
final String minMemberPolicyName = generateAutoScaleMinPolicyName(vmGroupIdentifier);
final String maxMemberPolicyName = generateAutoScaleMaxPolicyName(vmGroupIdentifier);
try {
/* Delete min/max member policies */
removeAutoScalePolicy(timerName, minMemberPolicyName, isCleanUp);
removeAutoScalePolicy(timerName, maxMemberPolicyName, isCleanUp);
boolean isSnmp = false;
/* Create Counters */
for (final AutoScalePolicyTO autoScalePolicyTO : policies) {
final List<ConditionTO> conditions = autoScalePolicyTO.getConditions();
for (final ConditionTO conditionTO : conditions) {
final CounterTO counterTO = conditionTO.getCounter();
if (counterTO.getSource().equals("snmp")) {
isSnmp = true;
break;
}
}
final String policyId = Long.toString(autoScalePolicyTO.getId());
final String policyName = generateAutoScalePolicyName(vmGroupIdentifier, policyId);
// Removing Timer policy
removeAutoScalePolicy(timerName, policyName, isCleanUp);
}
/* Delete AutoScale Config */
// Delete AutoScale ScaleDown action
final com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction scaleDownAction = new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
try {
scaleDownAction.set_name(scaleDownActionName);
autoscaleaction.delete(_netscalerService, scaleDownAction);
} catch (final Exception e) {
// Ignore Exception on cleanup
if (!isCleanUp) {
throw e;
}
}
// Delete AutoScale ScaleUp action
final com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction scaleUpAction = new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
try {
scaleUpAction.set_name(scaleUpActionName);
autoscaleaction.delete(_netscalerService, scaleUpAction);
} catch (final Exception e) {
// Ignore Exception on cleanup
if (!isCleanUp) {
throw e;
}
}
// Delete Timer
final nstimer timer = new nstimer();
try {
timer.set_name(timerName);
nstimer.delete(_netscalerService, timer);
} catch (final Exception e) {
// Ignore Exception on cleanup
if (!isCleanUp) {
throw e;
}
}
// Delete AutoScale Profile
final autoscaleprofile autoscaleProfile = new autoscaleprofile();
try {
autoscaleProfile.set_name(profileName);
autoscaleprofile.delete(_netscalerService, autoscaleProfile);
} catch (final Exception e) {
// Ignore Exception on cleanup
if (!isCleanUp) {
throw e;
}
}
if (isSnmp) {
final servicegroup_lbmonitor_binding servicegroup_monitor_binding = new servicegroup_lbmonitor_binding();
try {
servicegroup_monitor_binding.set_monitor_name(monitorName);
servicegroup_monitor_binding.set_servicegroupname(serviceGroupName);
servicegroup_lbmonitor_binding.delete(_netscalerService, servicegroup_monitor_binding);
} catch (final Exception e) {
// Ignore Exception on cleanup
if (!isCleanUp) {
throw e;
}
}
// Delete Monitor
// rm lb monitor lb_metric_table_mon
final com.citrix.netscaler.nitro.resource.config.lb.lbmonitor monitor = new com.citrix.netscaler.nitro.resource.config.lb.lbmonitor();
try {
monitor.set_monitorname(monitorName);
monitor.set_type("LOAD");
lbmonitor.delete(_netscalerService, monitor);
} catch (final Exception e) {
// Ignore Exception on cleanup
if (!isCleanUp) {
throw e;
}
}
// Delete Metric Table
final com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable metricTable = new com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable();
try {
metricTable.set_metrictable(mtName);
lbmetrictable.delete(_netscalerService, metricTable);
} catch (final Exception e) {
// Ignore Exception on cleanup
if (!isCleanUp) {
throw e;
}
}
}
} catch (final Exception ex) {
if (!isCleanUp) {
// Normal course, exception has occurred
enableAutoScaleConfig(loadBalancerTO, true);
throw ex;
} else {
// Programming error
throw ex;
}
}
return true;
}
Aggregations