Search in sources :

Example 36 with ExecutionException

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

the class NetscalerResource method bindServiceToMonitor.

private void bindServiceToMonitor(final String nsServiceName, final String nsMonitorName) throws ExecutionException {
    try {
        com.citrix.netscaler.nitro.resource.config.basic.service serviceObject = new com.citrix.netscaler.nitro.resource.config.basic.service();
        serviceObject = com.citrix.netscaler.nitro.resource.config.basic.service.get(_netscalerService, nsServiceName);
        if (serviceObject != null) {
            final com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding serviceMonitor = new com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding();
            serviceMonitor.set_monitor_name(nsMonitorName);
            serviceMonitor.set_name(nsServiceName);
            serviceMonitor.set_monstate("ENABLED");
            s_logger.debug("Trying to bind  the monitor :" + nsMonitorName + " to the service :" + nsServiceName);
            com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding.add(_netscalerService, serviceMonitor);
            s_logger.debug("Successfully binded the monitor :" + nsMonitorName + " to the service :" + nsServiceName);
        }
    } catch (final nitro_exception e) {
        throw new ExecutionException("Failed to create new monitor :" + nsMonitorName + " due to " + e.getMessage());
    } catch (final Exception e) {
        throw new ExecutionException("Failed to create new monitor :" + nsMonitorName + " due to " + e.getMessage());
    }
}
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) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException) com.citrix.netscaler.nitro.exception.nitro_exception(com.citrix.netscaler.nitro.exception.nitro_exception) com.citrix.netscaler.nitro.service.nitro_service(com.citrix.netscaler.nitro.service.nitro_service) com.citrix.netscaler.nitro.resource.config.gslb.gslbservice(com.citrix.netscaler.nitro.resource.config.gslb.gslbservice) 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.basic.service_lbmonitor_binding(com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding)

Example 37 with ExecutionException

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

the class PaloAltoResource method execute.

private Answer execute(IpAssocCommand cmd, int numRetries) {
    String[] results = new String[cmd.getIpAddresses().length];
    int i = 0;
    try {
        IpAddressTO ip;
        if (cmd.getIpAddresses().length != 1) {
            throw new ExecutionException("Received an invalid number of guest IPs to associate.");
        } else {
            ip = cmd.getIpAddresses()[0];
        }
        String sourceNatIpAddress = null;
        GuestNetworkType type = GuestNetworkType.INTERFACE_NAT;
        if (ip.isSourceNat()) {
            type = GuestNetworkType.SOURCE_NAT;
            if (ip.getPublicIp() == null) {
                throw new ExecutionException("Source NAT IP address must not be null.");
            } else {
                sourceNatIpAddress = ip.getPublicIp();
            }
        }
        long guestVlanTag = Long.parseLong(cmd.getAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG));
        String guestVlanGateway = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY);
        String cidr = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_CIDR);
        long cidrSize = NetUtils.cidrToLong(cidr)[1];
        String guestVlanSubnet = NetUtils.getCidrSubNet(guestVlanGateway, cidrSize);
        Long publicVlanTag = null;
        if (ip.getBroadcastUri() != null) {
            String parsedVlanTag = parsePublicVlanTag(ip.getBroadcastUri());
            if (!parsedVlanTag.equals("untagged")) {
                try {
                    publicVlanTag = Long.parseLong(parsedVlanTag);
                } catch (Exception e) {
                    throw new ExecutionException("Could not parse public VLAN tag: " + parsedVlanTag);
                }
            }
        }
        ArrayList<IPaloAltoCommand> commandList = new ArrayList<IPaloAltoCommand>();
        if (ip.isAdd()) {
            // Implement the guest network for this VLAN
            implementGuestNetwork(commandList, type, publicVlanTag, sourceNatIpAddress, guestVlanTag, guestVlanGateway, guestVlanSubnet, cidrSize);
        } else {
            // Remove the guest network:
            shutdownGuestNetwork(commandList, type, publicVlanTag, sourceNatIpAddress, guestVlanTag, guestVlanGateway, guestVlanSubnet, cidrSize);
        }
        boolean status = requestWithCommit(commandList);
        results[i++] = ip.getPublicIp() + " - success";
    } catch (ExecutionException e) {
        s_logger.error(e);
        if (numRetries > 0 && refreshPaloAltoConnection()) {
            int numRetriesRemaining = numRetries - 1;
            s_logger.debug("Retrying IPAssocCommand. Number of retries remaining: " + numRetriesRemaining);
            return execute(cmd, numRetriesRemaining);
        } else {
            results[i++] = IpAssocAnswer.errorResult;
        }
    }
    return new IpAssocAnswer(cmd, results);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) ArrayList(java.util.ArrayList) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ExecutionException(com.cloud.utils.exception.ExecutionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) IOException(java.io.IOException) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) ExecutionException(com.cloud.utils.exception.ExecutionException)

Example 38 with ExecutionException

use of com.cloud.utils.exception.ExecutionException in project CloudStack-archive by CloudStack-extras.

the class StartVMCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
    try {
        UserContext.current().setEventDetails("Vm Id: " + getId());
        UserVm result;
        if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
            result = _bareMetalVmService.startVirtualMachine(this);
        } else {
            result = _userVmService.startVirtualMachine(this);
        }
        if (result != null) {
            UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start a vm");
        }
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    } catch (StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ExecutionException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) ExecutionException(com.cloud.utils.exception.ExecutionException) UserVmResponse(com.cloud.api.response.UserVmResponse) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 39 with ExecutionException

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

the class CiscoVnmcResource method execute.

private Answer execute(SetStaticNatRulesCommand cmd, int numRetries) {
    String vlanId = cmd.getContextParam(NetworkElementCommand.GUEST_VLAN_TAG);
    String tenant = "vlan-" + vlanId;
    StaticNatRuleTO[] rules = cmd.getRules();
    Map<String, List<StaticNatRuleTO>> publicIpRulesMap = new HashMap<String, List<StaticNatRuleTO>>();
    for (StaticNatRuleTO rule : rules) {
        String publicIp = rule.getSrcIp();
        if (!publicIpRulesMap.containsKey(publicIp)) {
            List<StaticNatRuleTO> publicIpRulesList = new ArrayList<StaticNatRuleTO>();
            publicIpRulesMap.put(publicIp, publicIpRulesList);
        }
        publicIpRulesMap.get(publicIp).add(rule);
    }
    try {
        if (!_connection.createTenantVDCNatPolicySet(tenant)) {
            throw new ExecutionException("Failed to create NAT policy set in VNMC for guest network with vlan " + vlanId);
        }
        if (!_connection.createTenantVDCAclPolicySet(tenant, true)) {
            throw new ExecutionException("Failed to create ACL ingress policy set in VNMC for guest network with vlan " + vlanId);
        }
        if (!_connection.createTenantVDCAclPolicySet(tenant, false)) {
            throw new ExecutionException("Failed to create ACL egress policy set in VNMC for guest network with vlan " + vlanId);
        }
        for (String publicIp : publicIpRulesMap.keySet()) {
            String policyIdentifier = publicIp.replace('.', '-');
            if (!_connection.createTenantVDCDNatPolicy(tenant, policyIdentifier)) {
                throw new ExecutionException("Failed to create DNAT policy in VNMC for guest network with vlan " + vlanId);
            }
            if (!_connection.createTenantVDCDNatPolicyRef(tenant, policyIdentifier)) {
                throw new ExecutionException("Failed to associate DNAT policy with NAT policy set in VNMC for guest network with vlan " + vlanId);
            }
            if (!_connection.createTenantVDCAclPolicy(tenant, policyIdentifier)) {
                throw new ExecutionException("Failed to create ACL policy in VNMC for guest network with vlan " + vlanId);
            }
            if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, true)) {
                throw new ExecutionException("Failed to associate ACL policy with ACL ingress policy set in VNMC for guest network with vlan " + vlanId);
            }
            if (!_connection.createTenantVDCAclPolicyRef(tenant, policyIdentifier, false)) {
                throw new ExecutionException("Failed to associate ACL policy with ACL egress policy set in VNMC for guest network with vlan " + vlanId);
            }
            for (StaticNatRuleTO rule : publicIpRulesMap.get(publicIp)) {
                if (rule.revoked()) {
                    if (!_connection.deleteTenantVDCDNatRule(tenant, rule.getId(), policyIdentifier)) {
                        throw new ExecutionException("Failed to delete DNAT rule in VNMC for guest network with vlan " + vlanId);
                    }
                } else {
                    if (!_connection.createTenantVDCDNatIpPool(tenant, Long.toString(rule.getId()), rule.getDstIp())) {
                        throw new ExecutionException("Failed to create DNAT ip pool in VNMC for guest network with vlan " + vlanId);
                    }
                    if (!_connection.createTenantVDCDNatRule(tenant, rule.getId(), policyIdentifier, rule.getSrcIp())) {
                        throw new ExecutionException("Failed to create DNAT rule in VNMC for guest network with vlan " + vlanId);
                    }
                }
            }
        }
        if (!_connection.associateAclPolicySet(tenant)) {
            throw new ExecutionException("Failed to associate source NAT policy set with edge security profile in VNMC for guest network with vlan " + vlanId);
        }
    } catch (ExecutionException e) {
        String msg = "SetStaticNatRulesCommand failed due to " + e.getMessage();
        s_logger.error(msg, e);
        return new Answer(cmd, false, msg);
    }
    return new Answer(cmd, true, "Success");
}
Also used : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) Answer(com.cloud.agent.api.Answer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) ExternalNetworkResourceUsageAnswer(com.cloud.agent.api.ExternalNetworkResourceUsageAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(com.cloud.utils.exception.ExecutionException)

Example 40 with ExecutionException

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

the class CiscoVnmcResource method execute.

private Answer execute(AssociateAsaWithLogicalEdgeFirewallCommand cmd, int numRetries) {
    String tenant = "vlan-" + cmd.getVlanId();
    try {
        Map<String, String> availableAsaAppliances = _connection.listUnAssocAsa1000v();
        if (availableAsaAppliances.isEmpty()) {
            throw new ExecutionException("No ASA 1000v available to associate with logical edge firewall for guest vlan " + cmd.getVlanId());
        }
        String asaInstanceDn = availableAsaAppliances.get(cmd.getAsaMgmtIp());
        if (asaInstanceDn == null) {
            throw new ExecutionException("Requested ASA 1000v (" + cmd.getAsaMgmtIp() + ") is not available");
        }
        if (!_connection.assignAsa1000v(tenant, asaInstanceDn)) {
            throw new ExecutionException("Failed to associate ASA 1000v (" + cmd.getAsaMgmtIp() + ") with logical edge firewall for guest vlan " + cmd.getVlanId());
        }
    } catch (ExecutionException e) {
        String msg = "AssociateAsaWithLogicalEdgeFirewallCommand failed due to " + e.getMessage();
        s_logger.error(msg, e);
        return new Answer(cmd, false, msg);
    }
    return new Answer(cmd, true, "Success");
}
Also used : ReadyAnswer(com.cloud.agent.api.ReadyAnswer) Answer(com.cloud.agent.api.Answer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) ExternalNetworkResourceUsageAnswer(com.cloud.agent.api.ExternalNetworkResourceUsageAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) 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