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);
}
}
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 ");
}
}
}
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;
}
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);
}
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;
}
Aggregations