Search in sources :

Example 61 with ExecutionException

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

the class F5BigIpResource method deleteVirtualServerAndDefaultPool.

private void deleteVirtualServerAndDefaultPool(String virtualServerName) throws ExecutionException {
    try {
        if (virtualServerExists(virtualServerName)) {
            // Delete the default pool's members
            List<String> poolMembers = getMembers(virtualServerName);
            for (String poolMember : poolMembers) {
                String[] destIpAndPort = getIpAndPort(poolMember);
                deletePoolMember(virtualServerName, destIpAndPort[0], Integer.parseInt(destIpAndPort[1]));
            }
            // Delete the virtual server
            s_logger.debug("Deleting virtual server " + virtualServerName);
            _virtualServerApi.delete_virtual_server(genStringArray(virtualServerName));
            if (getStrippedVirtualServers().contains(virtualServerName)) {
                throw new ExecutionException("Failed to delete virtual server " + virtualServerName);
            }
            // Delete the default pool
            deletePool(virtualServerName);
        }
    } catch (RemoteException e) {
        throw new ExecutionException(e.getMessage());
    }
}
Also used : ExecutionException(com.cloud.utils.exception.ExecutionException) RemoteException(java.rmi.RemoteException)

Example 62 with ExecutionException

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

the class F5BigIpResource method addGuestVlan.

private void addGuestVlan(long vlanTag, String vlanSelfIp, String vlanNetmask, boolean inline) throws ExecutionException {
    try {
        String vlanName = genVlanName(vlanTag);
        List<String> allVlans = getStrippedVlans();
        if (!allVlans.contains(vlanName)) {
            String[] vlanNames = genStringArray(vlanName);
            long[] vlanTags = genLongArray(vlanTag);
            CommonEnabledState[] commonEnabledState = { CommonEnabledState.STATE_DISABLED };
            // Create the interface name
            NetworkingVLANMemberEntry[][] vlanMemberEntries = { { new NetworkingVLANMemberEntry() } };
            vlanMemberEntries[0][0].setMember_type(NetworkingMemberType.MEMBER_INTERFACE);
            vlanMemberEntries[0][0].setTag_state(NetworkingMemberTagType.MEMBER_TAGGED);
            vlanMemberEntries[0][0].setMember_name(_privateInterface);
            s_logger.debug("Creating a guest VLAN with tag " + vlanTag);
            _vlanApi.create(vlanNames, vlanTags, vlanMemberEntries, commonEnabledState, new long[] { 10L }, new String[] { "00:00:00:00:00:00" });
            s_logger.debug("vlanName " + vlanName);
            s_logger.debug("getStrippedVlans " + getStrippedVlans());
            if (!getStrippedVlans().contains(vlanName)) {
                throw new ExecutionException("Failed to create vlan with tag " + vlanTag);
            }
        }
        if (inline) {
            List<Long> allRouteDomains = getRouteDomains();
            if (!allRouteDomains.contains(vlanTag)) {
                long[] routeDomainIds = genLongArray(vlanTag);
                String[][] vlanNames = new String[][] { genStringArray(genVlanName(vlanTag)) };
                s_logger.debug("Creating route domain " + vlanTag);
                _routeDomainApi.create(routeDomainIds, vlanNames);
                if (!getRouteDomains().contains(vlanTag)) {
                    throw new ExecutionException("Failed to create route domain " + vlanTag);
                }
            }
        }
        List<String> allSelfIps = getSelfIps();
        if (!allSelfIps.contains(vlanSelfIp)) {
            String[] selfIpsToCreate = genStringArray(vlanSelfIp);
            String[] vlans = genStringArray(vlanName);
            String[] netmasks = genStringArray(vlanNetmask);
            long[] unitIds = genLongArray(0L);
            CommonEnabledState[] enabledStates = new CommonEnabledState[] { CommonEnabledState.STATE_DISABLED };
            s_logger.debug("Creating self IP " + vlanSelfIp);
            _selfIpApi.create(selfIpsToCreate, vlans, netmasks, unitIds, enabledStates);
            if (!getSelfIps().contains(vlanSelfIp)) {
                throw new ExecutionException("Failed to create self IP " + vlanSelfIp);
            }
        }
    } catch (RemoteException e) {
        s_logger.error(e);
        throw new ExecutionException(e.getMessage());
    }
}
Also used : NetworkingVLANMemberEntry(iControl.NetworkingVLANMemberEntry) LocalLBProfileULong(iControl.LocalLBProfileULong) CommonEnabledState(iControl.CommonEnabledState) ExecutionException(com.cloud.utils.exception.ExecutionException) RemoteException(java.rmi.RemoteException)

Example 63 with ExecutionException

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

the class F5BigIpResource method getAllStrippedLbPools.

//Big IP 11.x
//getAllLbPools retuns LbPools without user partition information
//ex: if LbPools is vs-tcp-10.147.44.8-22 then the get_list() will return /Common/vs-tcp-10.147.44.8-22
//This method will strip the partition information and only returns a list with LbPools (vs-tcp-10.147.44.8-22)
public List<String> getAllStrippedLbPools() throws ExecutionException {
    try {
        List<String> lbPools = new ArrayList<String>();
        String[] pools = _loadbalancerApi.get_list();
        for (String pool : pools) {
            if (pool.contains("/")) {
                lbPools.add(pool.substring(pool.lastIndexOf("/") + 1));
            } else {
                lbPools.add(pool);
            }
        }
        return lbPools;
    } 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 64 with ExecutionException

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

the class NetscalerResource method addLBVirtualServer.

private void addLBVirtualServer(final String virtualServerName, final String publicIp, final int publicPort, final String lbAlgorithm, final String protocol, final StickinessPolicyTO[] stickyPolicies, final AutoScaleVmGroupTO vmGroupTO) throws ExecutionException {
    try {
        String lbMethod;
        if ("roundrobin".equalsIgnoreCase(lbAlgorithm)) {
            lbMethod = "ROUNDROBIN";
        } else if ("leastconn".equalsIgnoreCase(lbAlgorithm)) {
            lbMethod = "LEASTCONNECTION";
        } else if ("source".equalsIgnoreCase(lbAlgorithm)) {
            lbMethod = "SOURCEIPHASH";
        } else {
            throw new ExecutionException("Got invalid load balancing algorithm: " + lbAlgorithm + " in the load balancing rule");
        }
        boolean vserverExisis = false;
        lbvserver vserver = getVirtualServerIfExisits(virtualServerName);
        if (vserver != null) {
            if (!vserver.get_servicetype().equalsIgnoreCase(protocol)) {
                throw new ExecutionException("Can not update virtual server:" + virtualServerName + " as current protocol:" + vserver.get_servicetype() + " of virtual server is different from the " + " intended protocol:" + protocol);
            }
            vserverExisis = true;
        }
        // Use new vserver always for configuration
        vserver = new lbvserver();
        vserver.set_name(virtualServerName);
        vserver.set_ipv46(publicIp);
        vserver.set_port(publicPort);
        vserver.set_servicetype(protocol);
        vserver.set_lbmethod(lbMethod);
        // netmask can only be set for source IP load balancer algorithm
        if (!lbMethod.equalsIgnoreCase("SOURCEIPHASH")) {
            vserver.set_netmask(null);
            vserver.set_v6netmasklen(null);
        }
        if (stickyPolicies != null && stickyPolicies.length > 0 && stickyPolicies[0] != null) {
            // netscaler default 2 min
            long timeout = 2;
            String cookieName = null;
            final StickinessPolicyTO stickinessPolicy = stickyPolicies[0];
            // get the session persistence parameters
            final List<Pair<String, String>> paramsList = stickinessPolicy.getParams();
            for (final Pair<String, String> param : paramsList) {
                if ("holdtime".equalsIgnoreCase(param.first())) {
                    timeout = Long.parseLong(param.second());
                } else if ("name".equalsIgnoreCase(param.first())) {
                    cookieName = param.second();
                }
            }
            // configure virtual server based on the persistence method
            if (StickinessMethodType.LBCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
                vserver.set_persistencetype("COOKIEINSERT");
            } else if (StickinessMethodType.SourceBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
                vserver.set_persistencetype("SOURCEIP");
            } else if (StickinessMethodType.AppCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
                vserver.set_persistencetype("RULE");
                vserver.set_rule("HTTP.REQ.HEADER(\"COOKIE\").VALUE(0).typecast_nvlist_t('=',';').value(\"" + cookieName + "\")");
                vserver.set_resrule("HTTP.RES.HEADER(\"SET-COOKIE\").VALUE(0).typecast_nvlist_t('=',';').value(\"" + cookieName + "\")");
            } else {
                throw new ExecutionException("Got invalid session persistence method: " + stickinessPolicy.getMethodName() + " in the load balancing rule");
            }
            // set session persistence timeout
            vserver.set_timeout(timeout);
        } else {
            // delete the LB stickyness policy
            vserver.set_persistencetype("NONE");
        }
        if (vserverExisis) {
            apiCallResult = lbvserver.update(_netscalerService, vserver);
        } else {
            apiCallResult = lbvserver.add(_netscalerService, vserver);
        }
        if (apiCallResult.errorcode != 0) {
            throw new ExecutionException("Failed to create new load balancing virtual server:" + virtualServerName + " due to " + apiCallResult.message);
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Created load balancing virtual server " + virtualServerName + " on the Netscaler device");
        }
    } catch (final nitro_exception e) {
        throw new ExecutionException("Failed to create new virtual server:" + virtualServerName + " due to " + e.getMessage());
    } catch (final Exception e) {
        throw new ExecutionException("Failed to create new virtual server:" + virtualServerName + " due to " + e.getMessage());
    }
}
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) 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) StickinessPolicyTO(com.cloud.agent.api.to.LoadBalancerTO.StickinessPolicyTO) Pair(com.cloud.utils.Pair)

Example 65 with ExecutionException

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

the class NetscalerResource method removeAutoScaleConfig.

private synchronized boolean removeAutoScaleConfig(final LoadBalancerTO loadBalancerTO) throws Exception, ExecutionException {
    final String srcIp = loadBalancerTO.getSrcIp();
    final int srcPort = loadBalancerTO.getSrcPort();
    generateAutoScaleVmGroupIdentifier(loadBalancerTO);
    final String nsVirtualServerName = generateNSVirtualServerName(srcIp, srcPort);
    final String serviceGroupName = generateAutoScaleServiceGroupName(loadBalancerTO);
    if (loadBalancerTO.getAutoScaleVmGroupTO().getCurrentState().equals("enabled")) {
        disableAutoScaleConfig(loadBalancerTO, false);
    }
    if (isServiceGroupBoundToVirtualServer(nsVirtualServerName, serviceGroupName)) {
        // UnBind autoscale service group
        // unbind 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.delete(_netscalerService, vserver_servicegroup_binding);
        } catch (final Exception e) {
            throw e;
        }
    }
    if (nsServiceGroupExists(serviceGroupName)) {
        // Remove autoscale service group
        final com.citrix.netscaler.nitro.resource.config.basic.servicegroup serviceGroup = new com.citrix.netscaler.nitro.resource.config.basic.servicegroup();
        try {
            serviceGroup.set_servicegroupname(serviceGroupName);
            servicegroup.delete(_netscalerService, serviceGroup);
        } catch (final Exception e) {
            throw e;
        }
    }
    removeLBVirtualServer(nsVirtualServerName);
    return true;
}
Also used : com.citrix.netscaler.nitro.resource.config.basic.servicegroup(com.citrix.netscaler.nitro.resource.config.basic.servicegroup) 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) com.citrix.netscaler.nitro.resource.config.ns.nsconfig(com.citrix.netscaler.nitro.resource.config.ns.nsconfig)

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