use of com.cloud.legacymodel.network.LoadBalancingRule.LbStickinessPolicy in project cosmic by MissionCriticalCloud.
the class LoadBalancingRules method accept.
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
_router = router;
final LoadBalancerDao loadBalancerDao = visitor.getVirtualNetworkApplianceFactory().getLoadBalancerDao();
// For load balancer we have to resend all lb rules for the network
final List<LoadBalancerVO> lbs = loadBalancerDao.listByNetworkIdAndScheme(_network.getId(), Scheme.Public);
// We are cleaning it before because all the rules have to be sent to the router.
_rules.clear();
final LoadBalancingRulesManager lbMgr = visitor.getVirtualNetworkApplianceFactory().getLbMgr();
final NetworkModel networkModel = visitor.getVirtualNetworkApplianceFactory().getNetworkModel();
for (final LoadBalancerVO 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 LbSslCert sslCert = lbMgr.getLbSslCert(lb.getId());
final Ip sourceIp = networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol());
_rules.add(loadBalancing);
}
return visitor.visit(this);
}
use of com.cloud.legacymodel.network.LoadBalancingRule.LbStickinessPolicy in project cosmic by MissionCriticalCloud.
the class LoadBalancingRulesManagerImpl method getLoadBalancerRuleToApply.
private LoadBalancingRule getLoadBalancerRuleToApply(final LoadBalancerVO lb) {
final List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
final Ip sourceIp = getSourceIp(lb);
final LbSslCert sslCert = getLbSslCert(lb.getId());
final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, null, policyList, null, sourceIp, sslCert, lb.getLbProtocol());
final List<LbDestination> dstList = getExistingDestinations(lb.getId());
loadBalancing.setDestinations(dstList);
final List<LbHealthCheckPolicy> hcPolicyList = getHealthCheckPolicies(lb.getId());
loadBalancing.setHealthCheckPolicies(hcPolicyList);
return loadBalancing;
}
use of com.cloud.legacymodel.network.LoadBalancingRule.LbStickinessPolicy in project cosmic by MissionCriticalCloud.
the class CommandSetupHelper method configureLoadBalancer.
private void configureLoadBalancer(final VirtualRouter router, final NetworkOverviewTO.LoadBalancerTO loadBalancerTO) {
ArrayList<NetworkOverviewTO.LoadBalancerTO.LoadBalancersTO> loadBalancers = new ArrayList<>();
final List<NetworkVO> networks = _networkDao.listByVpc(router.getVpcId());
List<Long> networkIds = networks.stream().map(NetworkVO::getId).collect(Collectors.toList());
List<LoadBalancerVO> loadBalancerVO = _loadBalancerDao.listAll().stream().filter(lb -> networkIds.contains(lb.getNetworkId())).collect(Collectors.toList());
List<FirewallRuleVO> loadBalancingRuleList = _rulesDao.listAll().stream().filter(rule -> networkIds.contains(rule.getNetworkId()) && rule.getPurpose().toString().equals("LoadBalancing") && (rule.getState().equals(FirewallRule.State.Active) || rule.getState().equals(FirewallRule.State.Add))).collect(Collectors.toList());
loadBalancingRuleList.forEach(rule -> {
final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
final Optional<LoadBalancerVO> ruleVO = loadBalancerVO.stream().filter(r -> r.getId() == rule.getId()).findFirst();
ruleVO.ifPresent(balancerVO -> {
final NetworkOverviewTO.LoadBalancerTO.StickinessPolicy lbStickinessPolicy = _lbStickinessPolicyDao.listByLoadBalancerId(balancerVO.getId(), false).stream().map(policy -> new NetworkOverviewTO.LoadBalancerTO.StickinessPolicy(policy.getMethodName(), policy.getParams())).findFirst().orElse(null);
final List<NetworkOverviewTO.LoadBalancerTO.LBDestinations> lbDestinationList = _loadBalancerVMMapDao.listByLoadBalancerId(balancerVO.getId(), false).stream().map(vm -> new NetworkOverviewTO.LoadBalancerTO.LBDestinations(vm.getInstanceIp(), balancerVO.getDefaultPortStart())).collect(Collectors.toList());
if (_loadBalancerVMMapDao.listByLoadBalancerId(balancerVO.getId()).size() > 0) {
loadBalancers.add(new NetworkOverviewTO.LoadBalancerTO.LoadBalancersTO(rule.getUuid(), balancerVO.getName(), sourceIp.getAddress().addr(), rule.getSourcePortStart(), rule.getProtocol(), balancerVO.getLbProtocol(), balancerVO.getAlgorithm(), lbDestinationList, lbStickinessPolicy, balancerVO.getClientTimeout(), balancerVO.getServerTimeout()));
}
});
});
String routerPublicIp = null;
if (router instanceof DomainRouterVO) {
final DomainRouterVO domr = _routerDao.findById(router.getId());
routerPublicIp = domr.getPublicIpAddress();
if (routerPublicIp == null) {
routerPublicIp = router.getPublicIpAddress();
}
}
if (networkIds.size() > 0) {
final Network guestNetwork = _networkModel.getNetwork(networkIds.get(0));
final NetworkOffering offering = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId());
final String maxconn;
if (offering.getConcurrentConnections() == null) {
maxconn = _configDao.getValue(Config.NetworkLBHaproxyMaxConn.key());
} else {
maxconn = offering.getConcurrentConnections().toString();
}
loadBalancerTO.setMaxconn(maxconn);
loadBalancerTO.setLbStatsGuestIp(_routerControlHelper.getRouterIpInNetwork(networkIds.get(0), router.getId()));
}
loadBalancerTO.setLbStatsVisibility(_configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key()));
loadBalancerTO.setLbStatsUri(_configDao.getValue(Config.NetworkLBHaproxyStatsUri.key()));
loadBalancerTO.setLbStatsAuth(_configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key()));
loadBalancerTO.setLbStatsPort(_configDao.getValue(Config.NetworkLBHaproxyStatsPort.key()));
loadBalancerTO.setLbStatsPublicIp(routerPublicIp);
loadBalancerTO.setLbStatsPrivateIp(router.getPrivateIpAddress());
loadBalancerTO.setLoadBalancers(loadBalancers.toArray(new NetworkOverviewTO.LoadBalancerTO.LoadBalancersTO[0]));
}
use of com.cloud.legacymodel.network.LoadBalancingRule.LbStickinessPolicy in project cosmic by MissionCriticalCloud.
the class VirtualRouterElement method validateHAProxyLBRule.
public static boolean validateHAProxyLBRule(final LoadBalancingRule rule) {
final String timeEndChar = "dhms";
if (rule.getSourcePortStart() == NetUtils.HAPROXY_STATS_PORT) {
s_logger.debug("Can't create LB on port 8081, haproxy is listening for LB stats on this port");
return false;
}
for (final LbStickinessPolicy stickinessPolicy : rule.getStickinessPolicies()) {
final List<Pair<String, String>> paramsList = stickinessPolicy.getParams();
if (StickinessMethodType.LBCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
} else if (StickinessMethodType.SourceBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
// optional
String tablesize = "200k";
// optional
String expire = "30m";
/* overwrite default values with the stick parameters */
for (final Pair<String, String> paramKV : paramsList) {
final String key = paramKV.first();
final String value = paramKV.second();
if ("tablesize".equalsIgnoreCase(key)) {
tablesize = value;
}
if ("expire".equalsIgnoreCase(key)) {
expire = value;
}
}
if (expire != null && !containsOnlyNumbers(expire, timeEndChar)) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: expire is not in timeformat: " + expire);
}
if (tablesize != null && !containsOnlyNumbers(tablesize, "kmg")) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: tablesize is not in size format: " + tablesize);
}
} else if (StickinessMethodType.AppCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
// optional
String length = null;
// optional
String holdTime = null;
for (final Pair<String, String> paramKV : paramsList) {
final String key = paramKV.first();
final String value = paramKV.second();
if ("length".equalsIgnoreCase(key)) {
length = value;
}
if ("holdtime".equalsIgnoreCase(key)) {
holdTime = value;
}
}
if (length != null && !containsOnlyNumbers(length, null)) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: length is not a number: " + length);
}
if (holdTime != null && !containsOnlyNumbers(holdTime, timeEndChar) && !containsOnlyNumbers(holdTime, null)) {
throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: holdtime is not in timeformat: " + holdTime);
}
}
}
return true;
}
Aggregations