private boolean canHandleLbRules(final List<LoadBalancingRule> rules) { final Map<Capability, String> lbCaps = getCapabilities().get(Service.Lb); if (!lbCaps.isEmpty()) { final String schemeCaps = lbCaps.get(Capability.LbSchemes); if (schemeCaps != null) { for (final LoadBalancingRule rule : rules) { if (!schemeCaps.contains(rule.getScheme().toString())) { s_logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + getName()); return false; } } } } return true; }
for (int i = 0; i < loadBalancingRules.size(); i++) { LoadBalancingRule rule = loadBalancingRules.get(i); boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke)); String protocol = rule.getProtocol(); String algorithm = rule.getAlgorithm(); String lbUuid = rule.getUuid(); String srcIp = rule.getSourceIp().addr(); int srcPort = rule.getSourcePortStart(); List<LbDestination> destinations = rule.getDestinations(); if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) { LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, false, destinations, null, rule.getHealthCheckPolicies(), rule.getLbSslCert(), rule.getLbProtocol()); loadBalancersToApply.add(loadBalancer);
private boolean applyAutoScaleConfig(LoadBalancerVO lb, AutoScaleVmGroupVO vmGroup, String currentState) throws ResourceUnavailableException { LbAutoScaleVmGroup lbAutoScaleVmGroup = getLbAutoScaleVmGroup(vmGroup, currentState, lb); /* * Regular config like destinations need not be packed for applying * autoscale config as of today. */ List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId()); Ip sourceIp = getSourceIp(lb); LoadBalancingRule rule = new LoadBalancingRule(lb, null, policyList, null, sourceIp, null, lb.getLbProtocol()); rule.setAutoScaleVmGroup(lbAutoScaleVmGroup); if (!isRollBackAllowedForProvider(lb)) { // this is for Netscaler type of devices. if their is failure the db // entries will be rollbacked. return false; } List<LoadBalancingRule> rules = Arrays.asList(rule); if (!applyLbRules(rules, false)) { s_logger.debug("LB rules' autoscale config are not completely applied"); return false; } return true; }
protected Map<Ip, List<LoadBalancingRule>> groupBySourceIp(List<LoadBalancingRule> rules) { Map<Ip, List<LoadBalancingRule>> groupedRules = new HashMap<Ip, List<LoadBalancingRule>>(); for (LoadBalancingRule rule : rules) { if (rule.getDestinations() != null && !rule.getDestinations().isEmpty()) { Ip sourceIp = rule.getSourceIp(); if (!groupedRules.containsKey(sourceIp)) { groupedRules.put(sourceIp, null); } List<LoadBalancingRule> rulesToApply = groupedRules.get(sourceIp); if (rulesToApply == null) { rulesToApply = new ArrayList<LoadBalancingRule>(); } rulesToApply.add(rule); groupedRules.put(sourceIp, rulesToApply); } else { s_logger.debug("Internal lb rule " + rule + " doesn't have any vms assigned, skipping"); } } return groupedRules; }
int i = 0; for (LoadBalancingRule rule : rules) { boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke)); String protocol = rule.getProtocol(); String algorithm = rule.getAlgorithm(); String elbIp = rule.getSourceIp().addr(); int srcPort = rule.getSourcePortStart(); String uuid = rule.getUuid(); List<LbDestination> destinations = rule.getDestinations(); LoadBalancerTO lb = new LoadBalancerTO(uuid, elbIp, srcPort, protocol, algorithm, revoked, false, false, destinations); lbs[i++] = lb;
final String timeEndChar = "dhms"; int haproxy_stats_port = Integer.parseInt(_configDao.getValue(Config.NetworkLBHaproxyStatsPort.key())); if (rule.getSourcePortStart() == haproxy_stats_port) { if (s_logger.isDebugEnabled()) { s_logger.debug("Can't create LB on port "+ haproxy_stats_port +", haproxy is listening for LB stats on this port"); for (final LoadBalancingRule.LbStickinessPolicy stickinessPolicy : rule.getStickinessPolicies()) { final List<Pair<String, String>> paramsList = stickinessPolicy.getParams(); throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: expire is not in timeformat: " + expire); throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: tablesize is not in size format: " + tablesize); throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: length is not a number: " + length); throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: holdtime is not in timeformat: " + holdTime);
protected void finalizeLbRulesForIp(final Commands cmds, final DomainRouterVO internalLbVm, final Provider provider, final Ip sourceIp, final long guestNtwkId) { s_logger.debug("Resending load balancing rules as a part of start for " + internalLbVm); final List<ApplicationLoadBalancerRuleVO> lbs = _lbDao.listBySrcIpSrcNtwkId(sourceIp, guestNtwkId); final List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>(); if (_ntwkModel.isProviderSupportServiceInNetwork(guestNtwkId, Service.Lb, provider)) { // Re-apply load balancing rules for (final ApplicationLoadBalancerRuleVO lb : lbs) { final List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId()); final List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId()); final List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId()); final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp); lbRules.add(loadBalancing); } } s_logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of Intenrnal LB vm" + internalLbVm + " start."); if (!lbRules.isEmpty()) { createApplyLoadBalancingRulesCommands(lbRules, internalLbVm, cmds, guestNtwkId); } }
long sourceIpId = _networkModel.getPublicIpAddress(rules.get(0).getSourceIp().addr(), network.getDataCenterId()).getId(); List<LoadBalancerVO> lbs = _lbDao.listByIpAddress(sourceIpId); List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>(); Ip sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress(); LbSslCert sslCert = _lbMgr.getLbSslCert(lb.getId()); LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol()); lbRules.add(loadBalancing);
protected DomainRouterVO findElbVmForLb(LoadBalancingRule lb) {//TODO: use a table to lookup Network ntwk = _networkModel.getNetwork(lb.getNetworkId()); long sourceIpId = _networkModel.getPublicIpAddress(lb.getSourceIp().addr(), ntwk.getDataCenterId()).getId(); ElasticLbVmMapVO map = _elbVmMapDao.findOneByIp(sourceIpId); if (map == null) { return null; } DomainRouterVO elbVm = _routerDao.findById(map.getElbVmId()); return elbVm; }
private LoadBalancingRule getLoadBalancerRuleToApply(LoadBalancerVO lb) { List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId()); Ip sourceIp = getSourceIp(lb); LbSslCert sslCert = getLbSslCert(lb.getId()); LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, null, policyList, null, sourceIp, sslCert, lb.getLbProtocol()); if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(lb.getId())) { // Get the associated VmGroup AutoScaleVmGroupVO vmGroup = _autoScaleVmGroupDao.listByAll(lb.getId(), null).get(0); LbAutoScaleVmGroup lbAutoScaleVmGroup = getLbAutoScaleVmGroup(vmGroup, vmGroup.getState(), lb); loadBalancing.setAutoScaleVmGroup(lbAutoScaleVmGroup); } else { List<LbDestination> dstList = getExistingDestinations(lb.getId()); loadBalancing.setDestinations(dstList); List<LbHealthCheckPolicy> hcPolicyList = getHealthCheckPolicies(lb.getId()); loadBalancing.setHealthCheckPolicies(hcPolicyList); } return loadBalancing; }
public static boolean validateHAProxyLBRule(final LoadBalancingRule rule) { final String timeEndChar = "dhms"; for (final LbStickinessPolicy stickinessPolicy : rule.getStickinessPolicies()) { final List<Pair<String, String>> paramsList = stickinessPolicy .getParams(); && !containsOnlyNumbers(expire, timeEndChar)) { throw new InvalidParameterValueException( "Failed LB in validation rule id: " + rule.getId() + " Cause: expire is not in timeformat: " + expire); throw new InvalidParameterValueException( "Failed LB in validation rule id: " + rule.getId() + " Cause: tablesize is not in size format: " + tablesize); "Failed LB in validation rule id: " + rule.getId() + " Cause: length is not a number: " + length); holdTime, null)) { throw new InvalidParameterValueException( "Failed LB in validation rule id: " + rule.getId() + " Cause: holdtime is not in timeformat: " + holdTime);
@Override public boolean validateLBRule(Network network, LoadBalancingRule rule) { if (canHandle(network, Service.Lb)) { String algo = rule.getAlgorithm(); return (algo.equals("roundrobin") || algo.equals("leastconn") || algo.equals("source")); } return true; }
protected Set<Ip> getVmsToDestroy(Network network, List<LoadBalancingRule> rules) { //1) Group rules by the source ip address as NetworkManager always passes the entire network lb config to the element Set<Ip> lbPublicIps = new HashSet<Ip>(); Set<Ip> vmsToDestroy = new HashSet<Ip>(); for (LoadBalancingRule rule : rules) { lbPublicIps.add(rule.getSourceIp()); } for (Ip sourceIp : lbPublicIps) { //2) Check if there are non revoked rules for the source ip address if (_appLbDao.countBySourceIpAndNotRevoked(sourceIp, network.getId()) == 0) { s_logger.debug("Have to destroy internal lb vm for source ip " + sourceIp + " as it has 0 rules in non-Revoke state"); vmsToDestroy.add(sourceIp); } } return vmsToDestroy; }
final boolean inline = false; for (final LoadBalancingRule rule : rules) { final boolean revoked = rule.getState().equals(FirewallRule.State.Revoke); final String protocol = rule.getProtocol(); final String algorithm = rule.getAlgorithm(); final String uuid = rule.getUuid(); final String srcIp = rule.getSourceIp().addr(); final int srcPort = rule.getSourcePortStart(); final List<LbDestination> destinations = rule.getDestinations(); final List<LbStickinessPolicy> stickinessPolicies = rule.getStickinessPolicies(); final LoadBalancerTO lb = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, stickinessPolicies); lbs[i++] = lb;
protected ApplicationLoadBalancerRule createApplicationLoadBalancer(String name, String description, Scheme scheme, Network sourceIpNtwk, String sourceIp, int sourcePort, int instancePort, String algorithm, Account lbOwner, Network guestNtwk, Boolean forDisplay) throws NetworkRuleConflictException, InsufficientVirtualNetworkCapacityException { //Only Internal scheme is supported in this release if (scheme != Scheme.Internal) { throw new UnsupportedServiceException("Only scheme of type " + Scheme.Internal + " is supported"); } //1) Validate LB rule's parameters validateLbRule(sourcePort, instancePort, algorithm, guestNtwk, scheme); //2) Validate source network validateSourceIpNtwkForLbRule(sourceIpNtwk, scheme); //3) Get source ip address Ip sourceIpAddr = getSourceIp(scheme, sourceIpNtwk, sourceIp); ApplicationLoadBalancerRuleVO newRule = new ApplicationLoadBalancerRuleVO(name, description, sourcePort, instancePort, algorithm, guestNtwk.getId(), lbOwner.getId(), lbOwner.getDomainId(), sourceIpAddr, sourceIpNtwk.getId(), scheme); if (forDisplay != null) { newRule.setDisplay(forDisplay); } //4) Validate Load Balancing rule on the providers LoadBalancingRule loadBalancing = new LoadBalancingRule(newRule, new ArrayList<LbDestination>(), new ArrayList<LbStickinessPolicy>(), new ArrayList<LbHealthCheckPolicy>(), sourceIpAddr, null, null); if (!_lbMgr.validateLbRule(loadBalancing)) { throw new InvalidParameterValueException("LB service provider cannot support this rule"); } //5) Persist Load Balancer rule return persistLbRule(newRule); }
for (int i = 0; i < loadBalancingRules.size(); i++) { LoadBalancingRule rule = loadBalancingRules.get(i); boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke)); String protocol = rule.getProtocol(); String algorithm = rule.getAlgorithm(); String lbUuid = rule.getUuid(); String srcIp = rule.getSourceIp().addr(); int srcPort = rule.getSourcePortStart(); List<LbDestination> destinations = rule.getDestinations(); if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) { LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, false, destinations, rule.getStickinessPolicies(), rule.getHealthCheckPolicies(), rule.getLbSslCert(), rule.getLbProtocol()); if (rule.isAutoScaleConfig()) { loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
final boolean revoked = rule.getState().equals(FirewallRule.State.Revoke); final String protocol = rule.getProtocol(); final String lb_protocol = rule.getLbProtocol(); final String algorithm = rule.getAlgorithm(); final String uuid = rule.getUuid(); final String srcIp = rule.getSourceIp().addr(); final int srcPort = rule.getSourcePortStart(); final List<LbDestination> destinations = rule.getDestinations(); final List<LbStickinessPolicy> stickinessPolicies = rule.getStickinessPolicies(); final LoadBalancerTO lb = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, stickinessPolicies); lb.setLbProtocol(lb_protocol);
private boolean canHandleLbRules(List<LoadBalancingRule> rules) { Map<Capability, String> lbCaps = getCapabilities().get(Service.Lb); if (!lbCaps.isEmpty()) { String schemeCaps = lbCaps.get(Capability.LbSchemes); if (schemeCaps != null) { for (LoadBalancingRule rule : rules) { if (!schemeCaps.contains(rule.getScheme().toString())) { s_logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + getName()); return false; } } } } return true; }
final Ip sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress(); final LbSslCert sslCert = _lbMgr.getLbSslCert(lb.getId()); final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol()); lbRules.add(loadBalancing);
List<MappingState> mappingStates = new ArrayList<MappingState>(); for (final LoadBalancingRule rule : loadBalancingRules) { boolean revoked = (FirewallRule.State.Revoke.equals(rule.getState())); String protocol = rule.getProtocol(); String algorithm = rule.getAlgorithm(); String uuid = rule.getUuid(); String srcIp = rule.getSourceIp().addr(); int srcPort = rule.getSourcePortStart(); List<LbDestination> destinations = rule.getDestinations(); long sourceIpId = _networkModel.getPublicIpAddress(rule.getSourceIp().addr(), network.getDataCenterId()).getId(); MappingNic nic = getLoadBalancingIpNic(zone, network, sourceIpId, revoked, null); mappingStates.add(nic.getState()); if ((destinations != null && !destinations.isEmpty()) || !rule.isAutoScaleConfig()) { boolean inline = _networkMgr.isNetworkInlineMode(network); LoadBalancerTO loadBalancer = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, rule.getStickinessPolicies(), rule.getHealthCheckPolicies(), rule.getLbSslCert(), rule.getLbProtocol()); loadBalancersToApply.add(loadBalancer);