Search in sources :

Example 1 with LocalLBPersistenceMode

use of iControl.LocalLBPersistenceMode 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)

Aggregations

StickinessPolicyTO (com.cloud.agent.api.to.LoadBalancerTO.StickinessPolicyTO)1 Pair (com.cloud.utils.Pair)1 ExecutionException (com.cloud.utils.exception.ExecutionException)1 LocalLBPersistenceMode (iControl.LocalLBPersistenceMode)1 LocalLBProfileULong (iControl.LocalLBProfileULong)1 RemoteException (java.rmi.RemoteException)1