Search in sources :

Example 51 with ExecutionException

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

the class PaloAltoResource method validResponse.

/* A default response handler to validate that the request was successful. */
public boolean validResponse(String response) throws ExecutionException {
    NodeList response_body;
    Document doc = getDocument(response);
    XPath xpath = XPathFactory.newInstance().newXPath();
    try {
        XPathExpression expr = xpath.compile("/response[@status='success']");
        response_body = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
        throw new ExecutionException(e.getCause().getMessage());
    }
    if (response_body.getLength() > 0) {
        return true;
    } else {
        NodeList error_details;
        try {
            XPathExpression expr = xpath.compile("/response/msg/line/line");
            error_details = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
        } catch (XPathExpressionException e) {
            throw new ExecutionException(e.getCause().getMessage());
        }
        if (error_details.getLength() == 0) {
            try {
                XPathExpression expr = xpath.compile("/response/msg/line");
                error_details = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
            } catch (XPathExpressionException e) {
                throw new ExecutionException(e.getCause().getMessage());
            }
            if (error_details.getLength() == 0) {
                try {
                    XPathExpression expr = xpath.compile("/response/result/msg");
                    error_details = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
                } catch (XPathExpressionException e) {
                    throw new ExecutionException(e.getCause().getMessage());
                }
            }
        }
        String error = "";
        for (int i = 0; i < error_details.getLength(); i++) {
            error = error + error_details.item(i).getTextContent() + "\n";
        }
        throw new ExecutionException(error);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) ExecutionException(com.cloud.utils.exception.ExecutionException)

Example 52 with ExecutionException

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

the class F5BigIpResource method addVirtualServer.

// Virtual server methods
private void addVirtualServer(String virtualServerName, LbProtocol protocol, String srcIp, int srcPort, StickinessPolicyTO[] stickyPolicies) throws ExecutionException {
    try {
        if (!virtualServerExists(virtualServerName)) {
            s_logger.debug("Adding virtual server " + virtualServerName);
            _virtualServerApi.create(genVirtualServerDefinition(virtualServerName, protocol, srcIp, srcPort), new String[] { "255.255.255.255" }, genVirtualServerResource(virtualServerName), genVirtualServerProfile(protocol));
            _virtualServerApi.set_snat_automap(genStringArray(virtualServerName));
            if (!virtualServerExists(virtualServerName)) {
                throw new ExecutionException("Failed to add virtual server " + virtualServerName);
            }
        }
        if ((stickyPolicies != null) && (stickyPolicies.length > 0) && (stickyPolicies[0] != null)) {
            StickinessPolicyTO stickinessPolicy = stickyPolicies[0];
            if (StickinessMethodType.LBCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
                String[] profileNames = genStringArray("Cookie-profile-" + virtualServerName);
                if (!persistenceProfileExists(profileNames[0])) {
                    LocalLBPersistenceMode[] lbPersistenceMode = new iControl.LocalLBPersistenceMode[1];
                    lbPersistenceMode[0] = iControl.LocalLBPersistenceMode.PERSISTENCE_MODE_COOKIE;
                    _persistenceProfileApi.create(profileNames, lbPersistenceMode);
                    _virtualServerApi.add_persistence_profile(genStringArray(virtualServerName), genPersistenceProfile(profileNames[0]));
                }
                List<Pair<String, String>> paramsList = stickinessPolicy.getParams();
                for (Pair<String, String> param : paramsList) {
                    if ("holdtime".equalsIgnoreCase(param.first())) {
                        //F5 default
                        long timeout = 180;
                        if (param.second() != null) {
                            timeout = Long.parseLong(param.second());
                        }
                        LocalLBProfileULong[] cookieTimeout = new LocalLBProfileULong[1];
                        cookieTimeout[0] = new LocalLBProfileULong();
                        cookieTimeout[0].setValue(timeout);
                        _persistenceProfileApi.set_cookie_expiration(profileNames, cookieTimeout);
                    }
                }
            }
        } else {
            _virtualServerApi.remove_all_persistence_profiles(genStringArray(virtualServerName));
        }
    } catch (RemoteException e) {
        throw new ExecutionException(e.getMessage());
    }
}
Also used : LocalLBPersistenceMode(iControl.LocalLBPersistenceMode) LocalLBProfileULong(iControl.LocalLBProfileULong) ExecutionException(com.cloud.utils.exception.ExecutionException) RemoteException(java.rmi.RemoteException) StickinessPolicyTO(com.cloud.agent.api.to.LoadBalancerTO.StickinessPolicyTO) Pair(com.cloud.utils.Pair)

Example 53 with ExecutionException

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

the class F5BigIpResource method getIpBytesSentAndReceived.

// Stats methods
private ExternalNetworkResourceUsageAnswer getIpBytesSentAndReceived(ExternalNetworkResourceUsageCommand cmd) throws ExecutionException {
    ExternalNetworkResourceUsageAnswer answer = new ExternalNetworkResourceUsageAnswer(cmd);
    try {
        LocalLBVirtualServerVirtualServerStatistics stats = _virtualServerApi.get_all_statistics();
        for (LocalLBVirtualServerVirtualServerStatisticEntry entry : stats.getStatistics()) {
            String virtualServerIp = entry.getVirtual_server().getAddress();
            virtualServerIp = stripRouteDomainFromAddress(virtualServerIp);
            long[] bytesSentAndReceived = answer.ipBytes.get(virtualServerIp);
            if (bytesSentAndReceived == null) {
                bytesSentAndReceived = new long[] { 0, 0 };
            }
            for (CommonStatistic stat : entry.getStatistics()) {
                int index;
                if (stat.getType().equals(CommonStatisticType.STATISTIC_CLIENT_SIDE_BYTES_OUT)) {
                    // Add to the outgoing bytes
                    index = 0;
                } else if (stat.getType().equals(CommonStatisticType.STATISTIC_CLIENT_SIDE_BYTES_IN)) {
                    // Add to the incoming bytes
                    index = 1;
                } else {
                    continue;
                }
                long high = stat.getValue().getHigh();
                long low = stat.getValue().getLow();
                long full = getFullUsage(high, low);
                bytesSentAndReceived[index] += full;
            }
            if (bytesSentAndReceived[0] >= 0 && bytesSentAndReceived[1] >= 0) {
                answer.ipBytes.put(virtualServerIp, bytesSentAndReceived);
            }
        }
    } catch (Exception e) {
        s_logger.error(e);
        throw new ExecutionException(e.getMessage());
    }
    return answer;
}
Also used : ExternalNetworkResourceUsageAnswer(com.cloud.agent.api.ExternalNetworkResourceUsageAnswer) CommonStatistic(iControl.CommonStatistic) ExecutionException(com.cloud.utils.exception.ExecutionException) LocalLBVirtualServerVirtualServerStatistics(iControl.LocalLBVirtualServerVirtualServerStatistics) ExecutionException(com.cloud.utils.exception.ExecutionException) RemoteException(java.rmi.RemoteException) ConfigurationException(javax.naming.ConfigurationException) LocalLBVirtualServerVirtualServerStatisticEntry(iControl.LocalLBVirtualServerVirtualServerStatisticEntry)

Example 54 with ExecutionException

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

the class F5BigIpResource method getStrippedVlans.

//getVlans retuns vlan names without user partition information
//ex: if vlanname is vlan-100 then the get_list() will return /Common/vlan-100
// This method will strip the partition information and only returns a list with vlan name (vlan-100)
private List<String> getStrippedVlans() throws ExecutionException {
    try {
        List<String> vlans = new ArrayList<String>();
        String[] vlansArray = _vlanApi.get_list();
        for (String vlan : vlansArray) {
            if (vlan.contains("/")) {
                vlans.add(vlan.substring(vlan.lastIndexOf("/") + 1));
            } else {
                vlans.add(vlan);
            }
        }
        return vlans;
    } catch (RemoteException e) {
        throw new ExecutionException(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) RemoteException(java.rmi.RemoteException) ExecutionException(com.cloud.utils.exception.ExecutionException)

Example 55 with ExecutionException

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

the class F5BigIpResource method deletePoolMember.

private void deletePoolMember(String virtualServerName, String destIp, int destPort) throws ExecutionException {
    try {
        String memberIdentifier = destIp + "-" + destPort;
        List<String> lbPools = getAllStrippedLbPools();
        if (lbPools.contains(virtualServerName) && memberExists(virtualServerName, memberIdentifier)) {
            s_logger.debug("Deleting member " + memberIdentifier + " from pool for virtual server " + virtualServerName);
            _loadbalancerApi.remove_member(genStringArray(virtualServerName), genMembers(destIp, destPort));
            if (memberExists(virtualServerName, memberIdentifier)) {
                throw new ExecutionException("Failed to delete member " + memberIdentifier + " from pool for virtual server " + virtualServerName);
            }
            if (nodeExists(destIp)) {
                boolean nodeNeeded = false;
                done: for (String poolToCheck : lbPools) {
                    for (String memberInPool : getMembers(poolToCheck)) {
                        if (getIpAndPort(memberInPool)[0].equals(destIp)) {
                            nodeNeeded = true;
                            break done;
                        }
                    }
                }
                if (!nodeNeeded) {
                    s_logger.debug("Deleting node " + destIp);
                    _nodeApi.delete_node_address(genStringArray(destIp));
                    if (nodeExists(destIp)) {
                        throw new ExecutionException("Failed to delete node " + destIp);
                    }
                }
            }
        }
    } catch (RemoteException e) {
        throw new ExecutionException(e.getMessage());
    }
}
Also used : ExecutionException(com.cloud.utils.exception.ExecutionException) RemoteException(java.rmi.RemoteException)

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