Search in sources :

Example 26 with ExecutionException

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

the class NetscalerResource method removeLBMonitor.

private void removeLBMonitor(final String nsMonitorName) throws ExecutionException {
    try {
        if (nsMonitorExist(nsMonitorName)) {
            final lbmonitor monitorObj = lbmonitor.get(_netscalerService, nsMonitorName);
            monitorObj.set_respcode(null);
            lbmonitor.delete(_netscalerService, monitorObj);
            s_logger.info("Successfully deleted monitor : " + nsMonitorName);
        }
    } catch (final nitro_exception e) {
        if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
            return;
        } else {
            throw new ExecutionException("Failed to delete monitor :" + nsMonitorName + " due to " + e.getMessage());
        }
    } catch (final Exception e) {
        throw new ExecutionException("Failed to delete monitor :" + nsMonitorName + " 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.lb.lbmonitor(com.citrix.netscaler.nitro.resource.config.lb.lbmonitor) ExecutionException(com.cloud.utils.exception.ExecutionException) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException)

Example 27 with ExecutionException

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

the class NetscalerResource method addGuestVlanAndSubnet.

private void addGuestVlanAndSubnet(final long vlanTag, final String vlanSelfIp, final String vlanNetmask, final boolean guestVlan) throws ExecutionException {
    try {
        // add vlan object for guest VLAN
        if (!nsVlanExists(vlanTag)) {
            try {
                final vlan vlanObj = new vlan();
                vlanObj.set_id(vlanTag);
                apiCallResult = vlan.add(_netscalerService, vlanObj);
                if (apiCallResult.errorcode != 0) {
                    throw new ExecutionException("Failed to add new vlan with tag:" + vlanTag + "on the NetScaler device due to " + apiCallResult.message);
                }
            } catch (final nitro_exception e) {
                throw new ExecutionException("Failed to add new vlan with tag:" + vlanTag + "on the NetScaler device due to " + e.getMessage());
            }
        }
        // add subnet IP object for this guest network
        if (!nsSnipExists(vlanSelfIp)) {
            try {
                final nsip selfIp = new nsip();
                selfIp.set_ipaddress(vlanSelfIp);
                selfIp.set_netmask(vlanNetmask);
                selfIp.set_type("SNIP");
                apiCallResult = nsip.add(_netscalerService, selfIp);
                if (apiCallResult.errorcode != 0) {
                    throw new ExecutionException("Failed to add SNIP object for the guest network on the Netscaler device due to " + apiCallResult.message);
                }
            } catch (final nitro_exception e) {
                throw new ExecutionException("Failed to add SNIP object for the guest network on the Netscaler device due to " + e.getMessage());
            }
        }
        // bind the vlan object to subnet IP object
        if (!nsVlanNsipBindingExists(vlanTag, vlanSelfIp)) {
            try {
                final vlan_nsip_binding ipVlanBinding = new vlan_nsip_binding();
                ipVlanBinding.set_id(vlanTag);
                ipVlanBinding.set_ipaddress(vlanSelfIp);
                ipVlanBinding.set_netmask(vlanNetmask);
                apiCallResult = vlan_nsip_binding.add(_netscalerService, ipVlanBinding);
                if (apiCallResult.errorcode != 0) {
                    throw new ExecutionException("Failed to bind VLAN with tag:" + vlanTag + " to the subnet due to " + apiCallResult.message);
                }
            } catch (final nitro_exception e) {
                throw new ExecutionException("Failed to bind VLAN with tage:" + vlanTag + " to the subnet due to " + e.getMessage());
            }
        }
        // bind vlan object to the private interface
        try {
            final vlan_interface_binding vlanBinding = new vlan_interface_binding();
            if (guestVlan) {
                vlanBinding.set_ifnum(_privateInterface);
            } else {
                vlanBinding.set_ifnum(_publicInterface);
            }
            vlanBinding.set_tagged(true);
            vlanBinding.set_id(vlanTag);
            apiCallResult = vlan_interface_binding.add(_netscalerService, vlanBinding);
            if (apiCallResult.errorcode != 0) {
                final String vlanInterface = guestVlan ? _privateInterface : _publicInterface;
                throw new ExecutionException("Failed to bind vlan with tag:" + vlanTag + " with the interface " + vlanInterface + " due to " + apiCallResult.message);
            }
        } catch (final nitro_exception e) {
            if (!(e.getErrorCode() == NitroError.NS_INTERFACE_ALREADY_BOUND_TO_VLAN)) {
                throw new ExecutionException("Failed to bind VLAN " + vlanTag + " with interface on the Netscaler device due to " + e.getMessage());
            }
        }
    } catch (final nitro_exception e) {
        throw new ExecutionException("Failed to implement guest network on the Netscaler device due to " + e.getMessage());
    } catch (final Exception e) {
        throw new ExecutionException("Failed to implement guest 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(com.citrix.netscaler.nitro.resource.config.network.vlan) 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 28 with ExecutionException

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

the class NetscalerResource method getPublicIpBytesSentAndReceived.

private ExternalNetworkResourceUsageAnswer getPublicIpBytesSentAndReceived(final ExternalNetworkResourceUsageCommand cmd) throws ExecutionException {
    final ExternalNetworkResourceUsageAnswer answer = new ExternalNetworkResourceUsageAnswer(cmd);
    try {
        final lbvserver_stats[] stats = lbvserver_stats.get(_netscalerService);
        if (stats == null || stats.length == 0) {
            return answer;
        }
        for (final lbvserver_stats stat_entry : stats) {
            final String lbvserverName = stat_entry.get_name();
            final lbvserver vserver = lbvserver.get(_netscalerService, lbvserverName);
            if (vserver != null) {
                final String lbVirtualServerIp = vserver.get_ipv46();
                long[] bytesSentAndReceived = answer.ipBytes.get(lbVirtualServerIp);
                if (bytesSentAndReceived == null) {
                    bytesSentAndReceived = new long[] { 0, 0 };
                }
                bytesSentAndReceived[0] += stat_entry.get_totalrequestbytes();
                bytesSentAndReceived[1] += stat_entry.get_totalresponsebytes();
                if (bytesSentAndReceived[0] >= 0 && bytesSentAndReceived[1] >= 0) {
                    answer.ipBytes.put(lbVirtualServerIp, bytesSentAndReceived);
                }
            }
        }
    } catch (final Exception e) {
        s_logger.error("Failed to get bytes sent and recived statistics due to " + e);
        throw new ExecutionException(e.getMessage());
    }
    return answer;
}
Also used : com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver(com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver) com.citrix.netscaler.nitro.resource.config.lb.lbvserver(com.citrix.netscaler.nitro.resource.config.lb.lbvserver) ExternalNetworkResourceUsageAnswer(com.cloud.agent.api.ExternalNetworkResourceUsageAnswer) com.citrix.netscaler.nitro.resource.stat.lb.lbvserver_stats(com.citrix.netscaler.nitro.resource.stat.lb.lbvserver_stats) ExecutionException(com.cloud.utils.exception.ExecutionException) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException)

Example 29 with ExecutionException

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

the class NetscalerResource method execute.

private Answer execute(final HealthCheckLBConfigCommand cmd, final int numRetries) {
    final List<LoadBalancerTO> hcLB = new ArrayList<LoadBalancerTO>();
    try {
        if (_isSdx) {
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
        final LoadBalancerTO[] loadBalancers = cmd.getLoadBalancers();
        if (loadBalancers == null) {
            return new HealthCheckLBConfigAnswer(hcLB);
        }
        for (final LoadBalancerTO loadBalancer : loadBalancers) {
            final HealthCheckPolicyTO[] healthCheckPolicies = loadBalancer.getHealthCheckPolicies();
            if (healthCheckPolicies != null && healthCheckPolicies.length > 0 && healthCheckPolicies[0] != null) {
                final String nsVirtualServerName = generateNSVirtualServerName(loadBalancer.getSrcIp(), loadBalancer.getSrcPort());
                final com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding[] serviceBindings = com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.get(_netscalerService, nsVirtualServerName);
                if (serviceBindings != null) {
                    for (final DestinationTO destination : loadBalancer.getDestinations()) {
                        final String nsServiceName = generateNSServiceName(destination.getDestIp(), destination.getDestPort());
                        for (final com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding binding : serviceBindings) {
                            if (nsServiceName.equalsIgnoreCase(binding.get_servicename())) {
                                destination.setMonitorState(binding.get_curstate());
                                break;
                            }
                        }
                    }
                    hcLB.add(loadBalancer);
                }
            }
        }
    } catch (final ExecutionException e) {
        s_logger.error("Failed to execute HealthCheckLBConfigCommand due to ", e);
        if (shouldRetry(numRetries)) {
            return retry(cmd, numRetries);
        } else {
            return new HealthCheckLBConfigAnswer(hcLB);
        }
    } catch (final Exception e) {
        s_logger.error("Failed to execute HealthCheckLBConfigCommand due to ", e);
        if (shouldRetry(numRetries)) {
            return retry(cmd, numRetries);
        } else {
            return new HealthCheckLBConfigAnswer(hcLB);
        }
    }
    return new HealthCheckLBConfigAnswer(hcLB);
}
Also used : ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) DestinationTO(com.cloud.agent.api.to.LoadBalancerTO.DestinationTO) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException) HealthCheckPolicyTO(com.cloud.agent.api.to.LoadBalancerTO.HealthCheckPolicyTO) com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding(com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) ExecutionException(com.cloud.utils.exception.ExecutionException) com.citrix.netscaler.nitro.resource.config.ns.nsconfig(com.citrix.netscaler.nitro.resource.config.ns.nsconfig) com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding(com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding)

Example 30 with ExecutionException

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

the class StartVMCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
    try {
        CallContext.current().setEventDetails("Vm Id: " + getId());
        UserVm result;
        result = _userVmService.startVirtualMachine(this);
        if (result != null) {
            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start a vm");
        }
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ExecutionException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (InsufficientCapacityException ex) {
        StringBuilder message = new StringBuilder(ex.getMessage());
        if (ex instanceof InsufficientServerCapacityException) {
            if (((InsufficientServerCapacityException) ex).isAffinityApplied()) {
                message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
            }
        }
        s_logger.info(ex);
        s_logger.info(message.toString(), ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) ExecutionException(com.cloud.utils.exception.ExecutionException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

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