Search in sources :

Example 1 with com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable

use of com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable 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;
}
Also used : com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction(com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction) com.citrix.netscaler.nitro.resource.config.basic.servicegroup_lbmonitor_binding(com.citrix.netscaler.nitro.resource.config.basic.servicegroup_lbmonitor_binding) com.citrix.netscaler.nitro.resource.config.lb.lbmonitor(com.citrix.netscaler.nitro.resource.config.lb.lbmonitor) com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable(com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable) ConditionTO(com.cloud.agent.api.to.LoadBalancerTO.ConditionTO) AutoScaleVmGroupTO(com.cloud.agent.api.to.LoadBalancerTO.AutoScaleVmGroupTO) CounterTO(com.cloud.agent.api.to.LoadBalancerTO.CounterTO) com.citrix.netscaler.nitro.resource.config.ns.nstimer(com.citrix.netscaler.nitro.resource.config.ns.nstimer) com.citrix.netscaler.nitro.resource.config.lb.lbmonitor(com.citrix.netscaler.nitro.resource.config.lb.lbmonitor) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException) AutoScalePolicyTO(com.cloud.agent.api.to.LoadBalancerTO.AutoScalePolicyTO) com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable(com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable) com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction(com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction) com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleprofile(com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleprofile) com.citrix.netscaler.nitro.resource.config.ns.nsconfig(com.citrix.netscaler.nitro.resource.config.ns.nsconfig)

Aggregations

com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction (com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction)1 com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleprofile (com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleprofile)1 com.citrix.netscaler.nitro.resource.config.basic.servicegroup_lbmonitor_binding (com.citrix.netscaler.nitro.resource.config.basic.servicegroup_lbmonitor_binding)1 com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable (com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable)1 com.citrix.netscaler.nitro.resource.config.lb.lbmonitor (com.citrix.netscaler.nitro.resource.config.lb.lbmonitor)1 com.citrix.netscaler.nitro.resource.config.ns.nsconfig (com.citrix.netscaler.nitro.resource.config.ns.nsconfig)1 com.citrix.netscaler.nitro.resource.config.ns.nstimer (com.citrix.netscaler.nitro.resource.config.ns.nstimer)1 AutoScalePolicyTO (com.cloud.agent.api.to.LoadBalancerTO.AutoScalePolicyTO)1 AutoScaleVmGroupTO (com.cloud.agent.api.to.LoadBalancerTO.AutoScaleVmGroupTO)1 ConditionTO (com.cloud.agent.api.to.LoadBalancerTO.ConditionTO)1 CounterTO (com.cloud.agent.api.to.LoadBalancerTO.CounterTO)1 ExecutionException (com.cloud.utils.exception.ExecutionException)1 IOException (java.io.IOException)1 ConfigurationException (javax.naming.ConfigurationException)1