use of com.cloud.legacymodel.to.LoadBalancerTO in project cosmic by MissionCriticalCloud.
the class CommandSetupHelper method createNetworkOverviewFromRouter.
public NetworkOverviewTO createNetworkOverviewFromRouter(final VirtualRouter router, final List<Nic> nicsToExclude, final List<Ip> ipsToExclude, final List<StaticRouteProfile> staticRoutesToExclude, final RemoteAccessVpn remoteAccessVpnToExclude, final Site2SiteVpnConnection site2siteVpnToExclude, final LoadBalancer loadBalancerExclude) {
final NetworkOverviewTO networkOverviewTO = new NetworkOverviewTO();
final List<NetworkOverviewTO.InterfaceTO> interfacesTO = new ArrayList<>();
final NetworkOverviewTO.ServiceTO servicesTO = new NetworkOverviewTO.ServiceTO();
final List<NetworkOverviewTO.ServiceTO.ServiceSourceNatTO> serviceSourceNatsTO = new ArrayList<>();
configureInterfacesAndIps(router, nicsToExclude, ipsToExclude, networkOverviewTO, interfacesTO, serviceSourceNatsTO);
configureStaticRoutes(router, staticRoutesToExclude, networkOverviewTO);
servicesTO.setSourceNat(serviceSourceNatsTO.toArray(new NetworkOverviewTO.ServiceTO.ServiceSourceNatTO[serviceSourceNatsTO.size()]));
networkOverviewTO.setServices(servicesTO);
final NetworkOverviewTO.VPNTO vpnTO = new NetworkOverviewTO.VPNTO();
configureRemoteAccessVpn(router, remoteAccessVpnToExclude, vpnTO);
configureSite2SiteVpn(router, site2siteVpnToExclude, vpnTO);
networkOverviewTO.setVpn(vpnTO);
configureSyslog(router, networkOverviewTO);
final NetworkOverviewTO.LoadBalancerTO loadBalancerTO = new NetworkOverviewTO.LoadBalancerTO();
configureLoadBalancer(router, loadBalancerTO);
networkOverviewTO.setLoadbalancer(loadBalancerTO);
return networkOverviewTO;
}
use of com.cloud.legacymodel.to.LoadBalancerTO in project cosmic by MissionCriticalCloud.
the class ConfigHelperTest method generateLoadBalancerConfigCommand.
protected LoadBalancerConfigCommand generateLoadBalancerConfigCommand() {
final List<LoadBalancerTO> lbs = new ArrayList<>();
final List<LbDestination> dests = new ArrayList<>();
dests.add(new LbDestination(80, 8080, "10.1.10.2", false));
dests.add(new LbDestination(80, 8080, "10.1.10.2", true));
lbs.add(new LoadBalancerTO(UUID.randomUUID().toString(), "64.10.1.10", 80, "tcp", "algo", false, false, false, dests, 60000, 60000));
final LoadBalancerTO[] arrayLbs = new LoadBalancerTO[lbs.size()];
lbs.toArray(arrayLbs);
final NicTO nic = new NicTO();
final LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(arrayLbs, "64.10.2.10", "10.1.10.2", "192.168.1.2", nic, null, "1000", false);
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, "10.1.10.2");
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, this.ROUTERNAME);
return cmd;
}
use of com.cloud.legacymodel.to.LoadBalancerTO in project cosmic by MissionCriticalCloud.
the class HAProxyConfiguratorTest method testGenerateConfigurationLoadBalancerProxyProtocolConfigCommand.
/**
* Test method for {@link HAProxyConfigurator#generateConfiguration(LoadBalancerConfigCommand)}.
*/
@Test
public void testGenerateConfigurationLoadBalancerProxyProtocolConfigCommand() {
final List<LbDestination> dests = new ArrayList<>();
dests.add(new LbDestination(443, 8443, "10.1.10.2", false));
dests.add(new LbDestination(443, 8443, "10.1.10.2", true));
final LoadBalancerTO lb = new LoadBalancerTO("1", "10.2.0.1", 443, "tcp", "http", false, false, false, dests, 60000, 60000);
lb.setLbProtocol("tcp-proxy");
final LoadBalancerTO[] lba = new LoadBalancerTO[1];
lba[0] = lb;
final HAProxyConfigurator hpg = new HAProxyConfigurator();
final LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lba, "10.0.0.1", "10.1.0.1", "10.1.1.1", null, 1L, "12", false);
final String result = genConfig(hpg, cmd);
assertTrue("'send-proxy' should result if protocol is 'tcp-proxy'", result.contains("send-proxy"));
}
use of com.cloud.legacymodel.to.LoadBalancerTO 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]));
}
Aggregations