Search in sources :

Example 66 with ExecutionException

use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.

the class NetscalerResource method deleteGuestVlan.

private void deleteGuestVlan(final long vlanTag, final String vlanSelfIp, final String vlanNetmask) throws ExecutionException {
    try {
        // Delete all servers and associated services from this guest VLAN
        deleteServersInGuestVlan(vlanTag, vlanSelfIp, vlanNetmask);
        // unbind vlan to the private interface
        try {
            final vlan_interface_binding vlanIfBinding = new vlan_interface_binding();
            vlanIfBinding.set_id(vlanTag);
            vlanIfBinding.set_ifnum(_privateInterface);
            vlanIfBinding.set_tagged(true);
            apiCallResult = vlan_interface_binding.delete(_netscalerService, vlanIfBinding);
            if (apiCallResult.errorcode != 0) {
                throw new ExecutionException("Failed to unbind vlan:" + vlanTag + " with the private interface due to " + apiCallResult.message);
            }
        } catch (final nitro_exception e) {
            // if Vlan to interface binding does not exist then ignore the exception and proceed
            if (!(e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS)) {
                throw new ExecutionException("Failed to unbind vlan from the interface while shutdown of guest network on the Netscaler device due to " + e.getMessage());
            }
        }
        // unbind the vlan to subnet
        try {
            final vlan_nsip_binding vlanSnipBinding = new vlan_nsip_binding();
            vlanSnipBinding.set_netmask(vlanNetmask);
            vlanSnipBinding.set_ipaddress(vlanSelfIp);
            vlanSnipBinding.set_id(vlanTag);
            apiCallResult = vlan_nsip_binding.delete(_netscalerService, vlanSnipBinding);
            if (apiCallResult.errorcode != 0) {
                throw new ExecutionException("Failed to unbind vlan:" + vlanTag + " with the subnet due to " + apiCallResult.message);
            }
        } catch (final nitro_exception e) {
            // if Vlan to subnet binding does not exist then ignore the exception and proceed
            if (!(e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS)) {
                throw new ExecutionException("Failed to unbind vlan:" + vlanTag + " with the subnet due to " + e.getMessage());
            }
        }
        // remove subnet IP
        try {
            final nsip tmpVlanSelfIp = new nsip();
            tmpVlanSelfIp.set_ipaddress(vlanSelfIp);
            final nsip subnetIp = nsip.get(_netscalerService, tmpVlanSelfIp);
            apiCallResult = nsip.delete(_netscalerService, subnetIp);
            if (apiCallResult.errorcode != 0) {
                throw new ExecutionException("Failed to remove subnet ip:" + vlanSelfIp + " from the NetScaler device due to" + apiCallResult.message);
            }
        } catch (final nitro_exception e) {
            // if subnet SNIP does not exist then ignore the exception and proceed
            if (!(e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS)) {
                throw new ExecutionException("Failed to remove subnet ip:" + vlanSelfIp + " from the NetScaler device due to" + e.getMessage());
            }
        }
        // remove the vlan from the NetScaler device
        if (nsVlanExists(vlanTag)) {
            // remove vlan
            apiCallResult = com.citrix.netscaler.nitro.resource.config.network.vlan.delete(_netscalerService, vlanTag);
            if (apiCallResult.errorcode != 0) {
                throw new ExecutionException("Failed to remove vlan with tag:" + vlanTag + "due to" + apiCallResult.message);
            }
        }
    } catch (final nitro_exception e) {
        throw new ExecutionException("Failed to delete guest vlan network on the Netscaler device due to " + e.getMessage());
    } catch (final Exception e) {
        throw new ExecutionException("Failed to delete guest vlan network on the Netscaler device due to " + e.getMessage());
    }
}
Also used : com.citrix.netscaler.nitro.exception.nitro_exception(com.citrix.netscaler.nitro.exception.nitro_exception) com.citrix.netscaler.nitro.resource.config.network.vlan_interface_binding(com.citrix.netscaler.nitro.resource.config.network.vlan_interface_binding) ExecutionException(com.cloud.utils.exception.ExecutionException) com.citrix.netscaler.nitro.resource.config.network.vlan_nsip_binding(com.citrix.netscaler.nitro.resource.config.network.vlan_nsip_binding) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException) com.citrix.netscaler.nitro.resource.config.ns.nsip(com.citrix.netscaler.nitro.resource.config.ns.nsip)

Example 67 with ExecutionException

use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.

the class NetscalerResource method isServiceBoundToMonitor.

private boolean isServiceBoundToMonitor(final String nsServiceName, final String nsMonitorName) throws ExecutionException {
    final filtervalue[] filter = new filtervalue[1];
    filter[0] = new filtervalue("monitor_name", nsMonitorName);
    service_lbmonitor_binding[] result;
    try {
        result = service_lbmonitor_binding.get_filtered(_netscalerService, nsServiceName, filter);
        if (result != null && result.length > 0) {
            return true;
        }
    } catch (final Exception e) {
        throw new ExecutionException("Failed to verify service " + nsServiceName + " is bound to any monitor due to " + e.getMessage());
    }
    return false;
}
Also used : com.citrix.netscaler.nitro.resource.config.gslb.gslbservice_lbmonitor_binding(com.citrix.netscaler.nitro.resource.config.gslb.gslbservice_lbmonitor_binding) com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding(com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding) com.citrix.netscaler.nitro.util.filtervalue(com.citrix.netscaler.nitro.util.filtervalue) ExecutionException(com.cloud.utils.exception.ExecutionException) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException)

Example 68 with ExecutionException

use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.

the class NetscalerResource method addSubnetIP.

private void addSubnetIP(final String snip, final String netmask) throws ExecutionException {
    try {
        final nsip selfIp = new nsip();
        selfIp.set_ipaddress(snip);
        selfIp.set_netmask(netmask);
        selfIp.set_type("SNIP");
        apiCallResult = nsip.add(_netscalerService, selfIp);
        if (apiCallResult.errorcode != 0) {
            throw new ExecutionException("Failed to add SNIP object on the Netscaler device due to " + apiCallResult.message);
        }
    } catch (final nitro_exception e) {
        throw new ExecutionException("Failed to add SNIP object on the Netscaler device due to " + e.getMessage());
    } catch (final Exception e) {
        throw new ExecutionException("Failed to add SNIP object on the Netscaler device due to " + e.getMessage());
    }
}
Also used : com.citrix.netscaler.nitro.exception.nitro_exception(com.citrix.netscaler.nitro.exception.nitro_exception) ExecutionException(com.cloud.utils.exception.ExecutionException) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException) com.citrix.netscaler.nitro.resource.config.ns.nsip(com.citrix.netscaler.nitro.resource.config.ns.nsip)

Example 69 with ExecutionException

use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.

the class NetscalerResource method enableLoadBalancingFeature.

private void enableLoadBalancingFeature() throws ExecutionException {
    if (_isSdx) {
        return;
    }
    try {
        final String[] features = _netscalerService.get_enabled_features();
        if (features != null) {
            for (final String feature : features) {
                if (feature.equalsIgnoreCase("LB")) {
                    return;
                }
            }
        }
        // enable load balancing on the device
        final String[] feature = new String[1];
        feature[0] = "LB";
        apiCallResult = _netscalerService.enable_features(feature);
        if (apiCallResult.errorcode != 0) {
            throw new ExecutionException("Enabling load balancing feature on the device failed.");
        }
    } catch (final nitro_exception e) {
        throw new ExecutionException("Enabling load balancing feature on the device failed  due to " + e.getMessage());
    } catch (final Exception e) {
        throw new ExecutionException("Enabling load balancing feature on the device failed due to " + e.getMessage());
    }
}
Also used : com.citrix.netscaler.nitro.exception.nitro_exception(com.citrix.netscaler.nitro.exception.nitro_exception) ExecutionException(com.cloud.utils.exception.ExecutionException) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException)

Example 70 with ExecutionException

use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.

the class NetscalerResource method execute.

private synchronized Answer execute(final CreateLoadBalancerApplianceCommand cmd, final int numRetries) {
    if (!_isSdx) {
        return Answer.createUnsupportedCommandAnswer(cmd);
    }
    try {
        final String vpxName = "Cloud-VPX-" + cmd.getLoadBalancerIP();
        final String username = "admin";
        final String password = "admin";
        final ns ns_obj = new ns();
        ns_obj.set_name(vpxName);
        ns_obj.set_ip_address(cmd.getLoadBalancerIP());
        ns_obj.set_netmask(cmd.getNetmask());
        ns_obj.set_gateway(cmd.getGateway());
        ns_obj.set_username(username);
        ns_obj.set_password(password);
        // configure VPX instances with defaults
        ns_obj.set_license("Standard");
        ns_obj.set_vm_memory_total(new Double(2048));
        ns_obj.set_throughput(new Double(1000));
        ns_obj.set_pps(new Double(1000000));
        ns_obj.set_number_of_ssl_cores(0);
        ns_obj.set_profile_name("ns_nsroot_profile");
        // use the first VPX image of the available VPX images on the SDX to create an instance of VPX
        // TODO: should enable the option to choose the template while adding the SDX device in to CloudStack
        final xen_nsvpx_image[] vpxImages = xen_nsvpx_image.get(_netscalerSdxService);
        if (!(vpxImages != null && vpxImages.length >= 1)) {
            new Answer(cmd, new ExecutionException("Failed to create VPX instance on the netscaler SDX device " + _ip + " as there are no VPX images on SDX to use for creating VPX."));
        }
        final String imageName = vpxImages[0].get_file_name();
        ns_obj.set_image_name(imageName);
        String publicIf = _publicInterface;
        String privateIf = _privateInterface;
        // enable only the interfaces that will be used by VPX
        enableVPXInterfaces(_publicInterface, _privateInterface, ns_obj);
        // create new VPX instance
        ns newVpx = ns.add(_netscalerSdxService, ns_obj);
        if (newVpx == null) {
            return new Answer(cmd, new ExecutionException("Failed to create VPX instance on the netscaler SDX device " + _ip));
        }
        // wait for VPX instance to start-up
        long startTick = System.currentTimeMillis();
        final long startWaitMilliSeconds = 600000;
        while (!newVpx.get_instance_state().equalsIgnoreCase("up") && System.currentTimeMillis() - startTick < startWaitMilliSeconds) {
            try {
                Thread.sleep(10000);
            } catch (final InterruptedException e) {
                s_logger.debug("[ignored] interupted while waiting for netscaler to be 'up'.");
            }
            final ns refreshNsObj = new ns();
            refreshNsObj.set_id(newVpx.get_id());
            newVpx = ns.get(_netscalerSdxService, refreshNsObj);
        }
        // if vpx instance never came up then error out
        if (!newVpx.get_instance_state().equalsIgnoreCase("up")) {
            return new Answer(cmd, new ExecutionException("Failed to start VPX instance " + vpxName + " created on the netscaler SDX device " + _ip));
        }
        // wait till NS service in side VPX is actually ready
        startTick = System.currentTimeMillis();
        boolean nsServiceUp = false;
        final long nsServiceWaitMilliSeconds = 60000;
        while (System.currentTimeMillis() - startTick < nsServiceWaitMilliSeconds) {
            try {
                final nitro_service netscalerService = new nitro_service(cmd.getLoadBalancerIP(), "https");
                netscalerService.set_certvalidation(false);
                netscalerService.set_hostnameverification(false);
                netscalerService.set_credential(username, password);
                apiCallResult = netscalerService.login();
                if (apiCallResult.errorcode == 0) {
                    nsServiceUp = true;
                    break;
                }
            } catch (final Exception e) {
                Thread.sleep(10000);
                continue;
            }
        }
        if (!nsServiceUp) {
            return new Answer(cmd, new ExecutionException("Failed to create VPX instance " + vpxName + " on the netscaler SDX device " + _ip));
        }
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Successfully provisioned VPX instance " + vpxName + " on the Netscaler SDX device " + _ip);
        }
        // physical interfaces on the SDX range from 10/1 to 10/8 & 1/1 to 1/8 of which two different port or same port can be used for public and private interfaces
        // However the VPX instances created will have interface range start from 10/1 but will only have as many interfaces enabled while creating the VPX instance
        // So due to this, we need to map public & private interface on SDX to correct public & private interface of VPX
        final int publicIfnum = Integer.parseInt(_publicInterface.substring(_publicInterface.lastIndexOf("/") + 1));
        final int privateIfnum = Integer.parseInt(_privateInterface.substring(_privateInterface.lastIndexOf("/") + 1));
        if (_publicInterface.startsWith("10/") && _privateInterface.startsWith("10/")) {
            if (publicIfnum == privateIfnum) {
                publicIf = "10/1";
                privateIf = "10/1";
            } else if (publicIfnum > privateIfnum) {
                privateIf = "10/1";
                publicIf = "10/2";
            } else {
                publicIf = "10/1";
                privateIf = "10/2";
            }
        } else if (_publicInterface.startsWith("1/") && _privateInterface.startsWith("1/")) {
            if (publicIfnum == privateIfnum) {
                publicIf = "1/1";
                privateIf = "1/1";
            } else if (publicIfnum > privateIfnum) {
                privateIf = "1/1";
                publicIf = "1/2";
            } else {
                publicIf = "1/1";
                privateIf = "1/2";
            }
        } else if (_publicInterface.startsWith("1/") && _privateInterface.startsWith("10/")) {
            publicIf = "1/1";
            privateIf = "10/1";
        } else if (_publicInterface.startsWith("10/") && _privateInterface.startsWith("1/")) {
            publicIf = "10/1";
            privateIf = "1/1";
        }
        return new CreateLoadBalancerApplianceAnswer(cmd, true, "provisioned VPX instance", "NetscalerVPXLoadBalancer", "Netscaler", new NetscalerResource(), publicIf, privateIf, _username, _password);
    } catch (final Exception e) {
        if (shouldRetry(numRetries)) {
            return retry(cmd, numRetries);
        }
        return new CreateLoadBalancerApplianceAnswer(cmd, false, "failed to provisioned VPX instance due to " + e.getMessage(), null, null, null, null, null, null, null);
    }
}
Also used : com.citrix.sdx.nitro.resource.config.ns.ns(com.citrix.sdx.nitro.resource.config.ns.ns) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException) com.citrix.sdx.nitro.resource.config.xen.xen_nsvpx_image(com.citrix.sdx.nitro.resource.config.xen.xen_nsvpx_image) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GlobalLoadBalancerConfigAnswer(com.cloud.agent.api.routing.GlobalLoadBalancerConfigAnswer) Answer(com.cloud.agent.api.Answer) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) ExternalNetworkResourceUsageAnswer(com.cloud.agent.api.ExternalNetworkResourceUsageAnswer) com.citrix.netscaler.nitro.service.nitro_service(com.citrix.netscaler.nitro.service.nitro_service) ExecutionException(com.cloud.utils.exception.ExecutionException)

Aggregations

ExecutionException (com.cloud.utils.exception.ExecutionException)83 ConfigurationException (javax.naming.ConfigurationException)31 IOException (java.io.IOException)30 ArrayList (java.util.ArrayList)23 IpAssocAnswer (com.cloud.agent.api.routing.IpAssocAnswer)20 RemoteException (java.rmi.RemoteException)20 ExternalNetworkResourceUsageAnswer (com.cloud.agent.api.ExternalNetworkResourceUsageAnswer)19 Answer (com.cloud.agent.api.Answer)17 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)16 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)16 com.citrix.netscaler.nitro.exception.nitro_exception (com.citrix.netscaler.nitro.exception.nitro_exception)13 Document (org.w3c.dom.Document)12 XPathExpressionException (javax.xml.xpath.XPathExpressionException)11 HashMap (java.util.HashMap)10 XPath (javax.xml.xpath.XPath)8 XPathExpression (javax.xml.xpath.XPathExpression)8 NodeList (org.w3c.dom.NodeList)7 com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver (com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver)5 com.citrix.netscaler.nitro.resource.config.lb.lbvserver (com.citrix.netscaler.nitro.resource.config.lb.lbvserver)5 com.citrix.netscaler.nitro.resource.config.ns.nsconfig (com.citrix.netscaler.nitro.resource.config.ns.nsconfig)5