Search in sources :

Example 6 with LoadBalancerTO

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;
}
Also used : NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.legacymodel.to.LoadBalancerTO)

Example 7 with LoadBalancerTO

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;
}
Also used : ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.legacymodel.to.LoadBalancerTO) LbDestination(com.cloud.legacymodel.network.LoadBalancingRule.LbDestination) NicTO(com.cloud.legacymodel.to.NicTO) LoadBalancerConfigCommand(com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand)

Example 8 with LoadBalancerTO

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"));
}
Also used : HAProxyConfigurator(com.cloud.common.virtualnetwork.lb.HAProxyConfigurator) ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.legacymodel.to.LoadBalancerTO) LbDestination(com.cloud.legacymodel.network.LoadBalancingRule.LbDestination) LoadBalancerConfigCommand(com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand) Test(org.junit.Test)

Example 9 with LoadBalancerTO

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]));
}
Also used : LbStickinessPolicy(com.cloud.legacymodel.network.LoadBalancingRule.LbStickinessPolicy) NetworkModel(com.cloud.network.NetworkModel) VpnUser(com.cloud.legacymodel.network.VpnUser) Nic(com.cloud.legacymodel.network.Nic) StaticRouteProfile(com.cloud.legacymodel.network.vpc.StaticRouteProfile) NetworkACLTO(com.cloud.legacymodel.to.NetworkACLTO) ServiceOfferingDao(com.cloud.service.dao.ServiceOfferingDao) VlanDao(com.cloud.dc.dao.VlanDao) Map(java.util.Map) ZoneRepository(com.cloud.db.repository.ZoneRepository) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) FirewallRule(com.cloud.legacymodel.network.FirewallRule) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) NicTO(com.cloud.legacymodel.to.NicTO) LoadBalancingRule(com.cloud.legacymodel.network.LoadBalancingRule) RemoteAccessVpnVO(com.cloud.network.dao.RemoteAccessVpnVO) StaticNatRule(com.cloud.legacymodel.network.StaticNatRule) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) SetPublicIpACLCommand(com.cloud.legacymodel.communication.command.SetPublicIpACLCommand) VpcGateway(com.cloud.legacymodel.network.vpc.VpcGateway) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) SetStaticNatRulesCommand(com.cloud.legacymodel.communication.command.SetStaticNatRulesCommand) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) VpnUserDao(com.cloud.network.dao.VpnUserDao) NumbersUtil(com.cloud.utils.NumbersUtil) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) Ip(com.cloud.legacymodel.network.Ip) Zone(com.cloud.db.model.Zone) UpdateVmOverviewCommand(com.cloud.legacymodel.communication.command.UpdateVmOverviewCommand) NicProfile(com.cloud.vm.NicProfile) ArrayList(java.util.ArrayList) Purpose(com.cloud.legacymodel.network.FirewallRule.Purpose) VlanVO(com.cloud.dc.VlanVO) ConfigurationDao(com.cloud.framework.config.dao.ConfigurationDao) DomainRouterVO(com.cloud.vm.DomainRouterVO) UpdateNetworkOverviewCommand(com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand) BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) Site2SiteVpnConnection(com.cloud.network.Site2SiteVpnConnection) PortForwardingRule(com.cloud.legacymodel.network.PortForwardingRule) DomainRouterDao(com.cloud.vm.dao.DomainRouterDao) SavePasswordCommand(com.cloud.legacymodel.communication.command.SavePasswordCommand) LbDestination(com.cloud.legacymodel.network.LoadBalancingRule.LbDestination) PublicIpACLTO(com.cloud.legacymodel.to.PublicIpACLTO) Site2SiteVpnConnectionDao(com.cloud.network.dao.Site2SiteVpnConnectionDao) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) UserVmDao(com.cloud.vm.dao.UserVmDao) NetworkElementCommand(com.cloud.legacymodel.communication.command.NetworkElementCommand) NicDao(com.cloud.vm.dao.NicDao) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) Site2SiteCustomerGatewayDao(com.cloud.network.dao.Site2SiteCustomerGatewayDao) StaticRouteDao(com.cloud.network.vpc.dao.StaticRouteDao) SetPortForwardingRulesVpcCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesVpcCommand) FirewallRuleTO(com.cloud.legacymodel.to.FirewallRuleTO) PortForwardingRuleTO(com.cloud.legacymodel.to.PortForwardingRuleTO) SetPortForwardingRulesCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesCommand) Site2SiteVpnGatewayDao(com.cloud.network.dao.Site2SiteVpnGatewayDao) Site2SiteVpnGatewayVO(com.cloud.network.dao.Site2SiteVpnGatewayVO) StaticNatRuleTO(com.cloud.legacymodel.to.StaticNatRuleTO) URI(java.net.URI) Config(com.cloud.configuration.Config) SetFirewallRulesCommand(com.cloud.legacymodel.communication.command.SetFirewallRulesCommand) StringUtils(com.cloud.utils.StringUtils) SetNetworkACLCommand(com.cloud.legacymodel.communication.command.SetNetworkACLCommand) TrafficType(com.cloud.model.enumeration.TrafficType) LBStickinessPolicyDao(com.cloud.network.dao.LBStickinessPolicyDao) Commands(com.cloud.agent.manager.Commands) IpAddress(com.cloud.network.IpAddress) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) NicVO(com.cloud.vm.NicVO) Site2SiteCustomerGatewayVO(com.cloud.network.dao.Site2SiteCustomerGatewayVO) Collectors(java.util.stream.Collectors) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) List(java.util.List) LoadBalancerTO(com.cloud.legacymodel.to.LoadBalancerTO) NetworkACLItem(com.cloud.legacymodel.network.vpc.NetworkACLItem) RemoteAccessVpnDao(com.cloud.network.dao.RemoteAccessVpnDao) VirtualMachineManager(com.cloud.vm.VirtualMachineManager) Optional(java.util.Optional) NetUtils(com.cloud.utils.net.NetUtils) LoadBalancerConfigCommand(com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) StaticNat(com.cloud.network.rules.StaticNat) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter) HashMap(java.util.HashMap) NetworkDao(com.cloud.network.dao.NetworkDao) Inject(javax.inject.Inject) IPAddressVO(com.cloud.network.dao.IPAddressVO) NetworkVO(com.cloud.network.dao.NetworkVO) Qualifier(org.springframework.beans.factory.annotation.Qualifier) IPAddressDao(com.cloud.network.dao.IPAddressDao) VMOverviewTO(com.cloud.legacymodel.to.VMOverviewTO) GuestType(com.cloud.model.enumeration.GuestType) FirewallRulesDao(com.cloud.network.dao.FirewallRulesDao) Network(com.cloud.legacymodel.network.Network) NetworkACLItemDao(com.cloud.network.vpc.NetworkACLItemDao) SetupVRCommand(com.cloud.legacymodel.communication.command.SetupVRCommand) PublicIpAddress(com.cloud.network.PublicIpAddress) NetworkOffering(com.cloud.offering.NetworkOffering) UserVmVO(com.cloud.vm.UserVmVO) VpcDao(com.cloud.network.vpc.dao.VpcDao) NetworkOfferingDao(com.cloud.offerings.dao.NetworkOfferingDao) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) Vpc(com.cloud.legacymodel.network.vpc.Vpc) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) ArrayList(java.util.ArrayList) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LoadBalancerTO(com.cloud.legacymodel.to.LoadBalancerTO) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) Network(com.cloud.legacymodel.network.Network) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

LoadBalancerTO (com.cloud.legacymodel.to.LoadBalancerTO)9 ArrayList (java.util.ArrayList)6 LoadBalancerConfigCommand (com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand)5 LbDestination (com.cloud.legacymodel.network.LoadBalancingRule.LbDestination)5 LoadBalancingRule (com.cloud.legacymodel.network.LoadBalancingRule)3 Network (com.cloud.legacymodel.network.Network)3 Nic (com.cloud.legacymodel.network.Nic)3 HAProxyConfigurator (com.cloud.common.virtualnetwork.lb.HAProxyConfigurator)2 Zone (com.cloud.db.model.Zone)2 Ip (com.cloud.legacymodel.network.Ip)2 LbStickinessPolicy (com.cloud.legacymodel.network.LoadBalancingRule.LbStickinessPolicy)2 NicTO (com.cloud.legacymodel.to.NicTO)2 Commands (com.cloud.agent.manager.Commands)1 Config (com.cloud.configuration.Config)1 ZoneRepository (com.cloud.db.repository.ZoneRepository)1 VlanVO (com.cloud.dc.VlanVO)1 VlanDao (com.cloud.dc.dao.VlanDao)1 ConfigurationDao (com.cloud.framework.config.dao.ConfigurationDao)1 NetworkElementCommand (com.cloud.legacymodel.communication.command.NetworkElementCommand)1 SavePasswordCommand (com.cloud.legacymodel.communication.command.SavePasswordCommand)1