Search in sources :

Example 31 with ExecutionException

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

the class CiscoVnmcConnectionImpl method sendRequest.

private String sendRequest(String service, String xmlRequest) throws ExecutionException {
    HttpClient client = new HttpClient();
    String response = null;
    PostMethod method = new PostMethod("/xmlIM/" + service);
    method.setRequestBody(xmlRequest);
    try {
        org.apache.commons.httpclient.protocol.Protocol myhttps = new org.apache.commons.httpclient.protocol.Protocol("https", new EasySSLProtocolSocketFactory(), 443);
        client.getHostConfiguration().setHost(_ip, 443, myhttps);
        int statusCode = client.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            throw new Exception("Error code : " + statusCode);
        }
        response = method.getResponseBodyAsString();
    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new ExecutionException(e.getMessage());
    }
    System.out.println(response);
    return response;
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) ExecutionException(com.cloud.utils.exception.ExecutionException) EasySSLProtocolSocketFactory(org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory) HttpClient(org.apache.commons.httpclient.HttpClient) ExecutionException(com.cloud.utils.exception.ExecutionException)

Example 32 with ExecutionException

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

the class CiscoVnmcConnectionImpl method getDocument.

/*
     * XML utils
     */
private Document getDocument(String xml) throws ExecutionException {
    StringReader xmlReader = new StringReader("<?xml version=\"1.0\"?> \n" + xml.trim());
    InputSource xmlSource = new InputSource(xmlReader);
    Document doc = null;
    try {
        doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlSource);
    } catch (Exception e) {
        s_logger.error(e);
        throw new ExecutionException(e.getMessage());
    }
    if (doc == null) {
        throw new ExecutionException("Failed to parse xml " + xml);
    } else {
        return doc;
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) ExecutionException(com.cloud.utils.exception.ExecutionException) ExecutionException(com.cloud.utils.exception.ExecutionException)

Example 33 with ExecutionException

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

the class NetscalerResource method createAutoScaleConfig.

private synchronized boolean createAutoScaleConfig(final LoadBalancerTO loadBalancerTO) throws ExecutionException, Exception {
    final String srcIp = loadBalancerTO.getSrcIp();
    final int srcPort = loadBalancerTO.getSrcPort();
    final String lbProtocol = getNetScalerProtocol(loadBalancerTO);
    final String lbAlgorithm = loadBalancerTO.getAlgorithm();
    generateAutoScaleVmGroupIdentifier(loadBalancerTO);
    final String nsVirtualServerName = generateNSVirtualServerName(srcIp, srcPort);
    final AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Created load balancing virtual server " + nsVirtualServerName + " on the Netscaler device");
    }
    addLBVirtualServer(nsVirtualServerName, srcIp, srcPort, lbAlgorithm, lbProtocol, loadBalancerTO.getStickinessPolicies(), vmGroupTO);
    final String serviceGroupName = generateAutoScaleServiceGroupName(loadBalancerTO);
    if (!nsServiceGroupExists(serviceGroupName)) {
        // add servicegroup lb_autoscaleGroup -autoscale POLICY -memberPort 80
        final int memberPort = vmGroupTO.getMemberPort();
        try {
            final servicegroup serviceGroup = new servicegroup();
            serviceGroup.set_servicegroupname(serviceGroupName);
            serviceGroup.set_servicetype(lbProtocol);
            serviceGroup.set_autoscale("POLICY");
            serviceGroup.set_memberport(memberPort);
            servicegroup.add(_netscalerService, serviceGroup);
        } catch (final Exception e) {
            throw e;
        }
    }
    if (!isServiceGroupBoundToVirtualServer(nsVirtualServerName, serviceGroupName)) {
        // Bind autoscale service group
        // bind lb vserver lb lb_autoscaleGroup
        final lbvserver_servicegroup_binding vserver_servicegroup_binding = new lbvserver_servicegroup_binding();
        try {
            vserver_servicegroup_binding.set_name(nsVirtualServerName);
            vserver_servicegroup_binding.set_servicegroupname(serviceGroupName);
            lbvserver_servicegroup_binding.add(_netscalerService, vserver_servicegroup_binding);
        } catch (final Exception e) {
            throw e;
        }
    }
    // Create the autoscale config
    if (!loadBalancerTO.getAutoScaleVmGroupTO().getState().equals("disabled")) {
        // on restart of network, there might be vmgrps in disabled state, no need to create autoscale config for them
        enableAutoScaleConfig(loadBalancerTO, false);
    } else if (loadBalancerTO.getAutoScaleVmGroupTO().getState().equals("disabled")) {
        disableAutoScaleConfig(loadBalancerTO, false);
    }
    return true;
}
Also used : AutoScaleVmGroupTO(com.cloud.agent.api.to.LoadBalancerTO.AutoScaleVmGroupTO) com.citrix.netscaler.nitro.resource.config.basic.servicegroup(com.citrix.netscaler.nitro.resource.config.basic.servicegroup) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException) com.citrix.netscaler.nitro.resource.config.lb.lbvserver_servicegroup_binding(com.citrix.netscaler.nitro.resource.config.lb.lbvserver_servicegroup_binding)

Example 34 with ExecutionException

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

the class NetscalerResource method validateInterfaces.

private void validateInterfaces(final String publicInterface, final String privateInterface) throws ExecutionException {
    try {
        if (!_isSdx && !_cloudManaged) {
            final Interface publicIf = Interface.get(_netscalerService, publicInterface);
            final Interface privateIf = Interface.get(_netscalerService, privateInterface);
            if (publicIf != null || privateIf != null) {
                return;
            } else {
                throw new ExecutionException("Invalid interface name specified for public/private interfaces.");
            }
        }
    } catch (final nitro_exception e) {
        if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
            throw new ExecutionException("Invalid interface name specified for public and private interfaces.");
        } else {
            throw new ExecutionException("Failed to verify public interface and private intefaces are valid due to " + e.getMessage());
        }
    } catch (final Exception e) {
        throw new ExecutionException("Failed to verify public interface and private intefaces are valid 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) Interface(com.citrix.netscaler.nitro.resource.config.network.Interface) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException)

Example 35 with ExecutionException

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

the class NetscalerResource method nsSnipExists.

private boolean nsSnipExists(final String subnetIp) throws ExecutionException {
    try {
        final nsip tmpSubnetIp = new nsip();
        tmpSubnetIp.set_ipaddress(subnetIp);
        final nsip snip = nsip.get(_netscalerService, tmpSubnetIp);
        return snip != null;
    } catch (final nitro_exception e) {
        if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
            return false;
        } else {
            throw new ExecutionException("Failed to verify if SNIP exists on the NetScaler device due to " + e.getMessage());
        }
    } catch (final Exception e) {
        throw new ExecutionException("Failed to verify if SNIP exists 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)

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