Search in sources :

Example 1 with LoadBalancingServiceProvider

use of com.cloud.network.element.LoadBalancingServiceProvider in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method isLbServiceSupportedInNetwork.

@Override
public void isLbServiceSupportedInNetwork(long networkId, Scheme scheme) {
    Network network = _networkDao.findById(networkId);
    //1) Check if the LB service is supported
    if (!_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb)) {
        InvalidParameterValueException ex = new InvalidParameterValueException("LB service is not supported in specified network id");
        ex.addProxyObject(network.getUuid(), "networkId");
        throw ex;
    }
    //2) Check if the Scheme is supported\
    NetworkOffering off = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
    if (scheme == Scheme.Public) {
        if (!off.getPublicLb()) {
            throw new InvalidParameterValueException("Scheme " + scheme + " is not supported by the network offering " + off);
        }
    } else {
        if (!off.getInternalLb()) {
            throw new InvalidParameterValueException("Scheme " + scheme + " is not supported by the network offering " + off);
        }
    }
    //3) Check if the provider supports the scheme
    LoadBalancingServiceProvider lbProvider = _networkMgr.getLoadBalancingProviderForNetwork(network, scheme);
    if (lbProvider == null) {
        throw new InvalidParameterValueException("Lb rule with scheme " + scheme.toString() + " is not supported by lb providers in network " + network);
    }
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider)

Example 2 with LoadBalancingServiceProvider

use of com.cloud.network.element.LoadBalancingServiceProvider in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method updateLBHealthChecks.

// This method will check the status of services which has monitors created
// by CloudStack and update them in lbvmmap table
@DB
@Override
public void updateLBHealthChecks(Scheme scheme) throws ResourceUnavailableException {
    List<LoadBalancerVO> rules = _lbDao.listAll();
    List<NetworkVO> networks = _networkDao.listAll();
    List<LoadBalancerTO> stateRules = null;
    boolean isHandled = false;
    for (NetworkVO ntwk : networks) {
        Network network = _networkDao.findById(ntwk.getId());
        String capability = getLBCapability(network.getId(), Capability.HealthCheckPolicy.getName());
        if (capability != null && capability.equalsIgnoreCase("true")) {
            /*
                 * s_logger.debug(
                 * "HealthCheck Manager :: LB Provider in the Network has the Healthcheck policy capability :: "
                 * + provider.get(0).getName());
                 */
            rules = _lbDao.listByNetworkIdAndScheme(network.getId(), scheme);
            if (rules != null && rules.size() > 0) {
                List<LoadBalancingRule> lbrules = new ArrayList<LoadBalancingRule>();
                for (LoadBalancerVO lb : rules) {
                    List<LbDestination> dstList = getExistingDestinations(lb.getId());
                    List<LbHealthCheckPolicy> hcPolicyList = getHealthCheckPolicies(lb.getId());
                    // hashealtChecks
                    if (hcPolicyList != null && hcPolicyList.size() > 0) {
                        Ip sourceIp = getSourceIp(lb);
                        LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, null, hcPolicyList, sourceIp, null, lb.getLbProtocol());
                        lbrules.add(loadBalancing);
                    }
                }
                if (lbrules.size() > 0) {
                    isHandled = false;
                    for (LoadBalancingServiceProvider lbElement : _lbProviders) {
                        stateRules = lbElement.updateHealthChecks(network, lbrules);
                        if (stateRules != null && stateRules.size() > 0) {
                            for (LoadBalancerTO lbto : stateRules) {
                                LoadBalancerVO ulb = _lbDao.findByUuid(lbto.getUuid());
                                List<LoadBalancerVMMapVO> lbVmMaps = _lb2VmMapDao.listByLoadBalancerId(ulb.getId());
                                for (LoadBalancerVMMapVO lbVmMap : lbVmMaps) {
                                    UserVm vm = _vmDao.findById(lbVmMap.getInstanceId());
                                    Nic nic = _nicDao.findByInstanceIdAndNetworkIdIncludingRemoved(ulb.getNetworkId(), vm.getId());
                                    String dstIp = lbVmMap.getInstanceIp() == null ? nic.getIPv4Address() : lbVmMap.getInstanceIp();
                                    for (int i = 0; i < lbto.getDestinations().length; i++) {
                                        LoadBalancerTO.DestinationTO des = lbto.getDestinations()[i];
                                        if (dstIp.equalsIgnoreCase(lbto.getDestinations()[i].getDestIp())) {
                                            lbVmMap.setState(des.getMonitorState());
                                            _lb2VmMapDao.persist(lbVmMap);
                                            s_logger.debug("Updating the LB VM Map table with the service state");
                                        }
                                    }
                                }
                            }
                            isHandled = true;
                        }
                        if (isHandled) {
                            break;
                        }
                    }
                }
            }
        } else {
        // s_logger.debug("HealthCheck Manager :: LB Provider in the Network DNOT the Healthcheck policy capability ");
        }
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) UserVm(com.cloud.uservm.UserVm) Network(com.cloud.network.Network) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) LoadBalancerVMMapVO(com.cloud.network.dao.LoadBalancerVMMapVO) DB(com.cloud.utils.db.DB)

Example 3 with LoadBalancingServiceProvider

use of com.cloud.network.element.LoadBalancingServiceProvider in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method applyLbRules.

protected boolean applyLbRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
    boolean handled = false;
    for (LoadBalancingServiceProvider lbElement : _lbProviders) {
        Provider provider = lbElement.getProvider();
        boolean isLbProvider = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Lb, provider);
        if (!isLbProvider) {
            continue;
        }
        handled = lbElement.applyLBRules(network, rules);
        if (handled)
            break;
    }
    return handled;
}
Also used : LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 4 with LoadBalancingServiceProvider

use of com.cloud.network.element.LoadBalancingServiceProvider in project cloudstack by apache.

the class UpdateLoadBalancerTest method setUp.

@Before
public void setUp() {
    _lbMgr._accountMgr = new MockAccountManagerImpl();
    _lbMgr._autoScaleVmGroupDao = Mockito.mock(AutoScaleVmGroupDao.class);
    _lbMgr._networkDao = netDao;
    _lbMgr._networkModel = netModel;
    _lbMgr._lb2healthcheckDao = Mockito.mock(LBHealthCheckPolicyDao.class);
    _lbMgr._lb2stickinesspoliciesDao = Mockito.mock(LBStickinessPolicyDao.class);
    _lbMgr._lb2VmMapDao = Mockito.mock(LoadBalancerVMMapDao.class);
    _lbMgr._lbCertMapDao = Mockito.mock(LoadBalancerCertMapDao.class);
    _lbMgr._lbDao = lbDao;
    _lbMgr._lbProviders = new ArrayList<LoadBalancingServiceProvider>();
    _lbMgr._lbProviders.add(lbServiceProvider);
    updateLbRuleCmd = new UpdateLoadBalancerRuleCmd();
    AccountVO account = new AccountVO(accountName, domainId, "networkDomain", Account.ACCOUNT_TYPE_NORMAL, "uuid");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
}
Also used : LBHealthCheckPolicyDao(com.cloud.network.dao.LBHealthCheckPolicyDao) UserVO(com.cloud.user.UserVO) LoadBalancerCertMapDao(com.cloud.network.dao.LoadBalancerCertMapDao) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) UpdateLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRuleCmd) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) AutoScaleVmGroupDao(com.cloud.network.as.dao.AutoScaleVmGroupDao) LBStickinessPolicyDao(com.cloud.network.dao.LBStickinessPolicyDao) AccountVO(com.cloud.user.AccountVO) MockAccountManagerImpl(com.cloud.user.MockAccountManagerImpl) Before(org.junit.Before)

Example 5 with LoadBalancingServiceProvider

use of com.cloud.network.element.LoadBalancingServiceProvider in project cloudstack by apache.

the class NetworkOrchestrator method getLoadBalancingProviderForNetwork.

@Override
public LoadBalancingServiceProvider getLoadBalancingProviderForNetwork(final Network network, final Scheme lbScheme) {
    final List<NetworkElement> lbElements = getElementForServiceInNetwork(network, Service.Lb);
    NetworkElement lbElement = null;
    if (lbElements.size() > 1) {
        String providerName = null;
        //get network offering details
        final NetworkOffering off = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
        if (lbScheme == Scheme.Public) {
            providerName = _ntwkOffDetailsDao.getDetail(off.getId(), NetworkOffering.Detail.PublicLbProvider);
        } else {
            providerName = _ntwkOffDetailsDao.getDetail(off.getId(), NetworkOffering.Detail.InternalLbProvider);
        }
        if (providerName == null) {
            throw new InvalidParameterValueException("Can't find Lb provider supporting scheme " + lbScheme.toString() + " in network " + network);
        }
        lbElement = _networkModel.getElementImplementingProvider(providerName);
    } else if (lbElements.size() == 1) {
        lbElement = lbElements.get(0);
    }
    assert lbElement != null;
    assert lbElement instanceof LoadBalancingServiceProvider;
    return (LoadBalancingServiceProvider) lbElement;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) NetworkOffering(com.cloud.offering.NetworkOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider)

Aggregations

LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)7 Network (com.cloud.network.Network)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 Provider (com.cloud.network.Network.Provider)2 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)2 NetworkOffering (com.cloud.offering.NetworkOffering)2 LoadBalancerTO (com.cloud.agent.api.to.LoadBalancerTO)1 PublicIp (com.cloud.network.addr.PublicIp)1 AutoScaleVmGroupDao (com.cloud.network.as.dao.AutoScaleVmGroupDao)1 LBHealthCheckPolicyDao (com.cloud.network.dao.LBHealthCheckPolicyDao)1 LBStickinessPolicyDao (com.cloud.network.dao.LBStickinessPolicyDao)1 LoadBalancerCertMapDao (com.cloud.network.dao.LoadBalancerCertMapDao)1 LoadBalancerVMMapDao (com.cloud.network.dao.LoadBalancerVMMapDao)1 LoadBalancerVMMapVO (com.cloud.network.dao.LoadBalancerVMMapVO)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 NetworkElement (com.cloud.network.element.NetworkElement)1 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)1 LbHealthCheckPolicy (com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)1 Purpose (com.cloud.network.rules.FirewallRule.Purpose)1 AccountVO (com.cloud.user.AccountVO)1