Search in sources :

Example 11 with LoadBalancerTO

use of com.cloud.agent.api.to.LoadBalancerTO in project cloudstack by apache.

the class VirtualRoutingResourceTest method generateLoadBalancerConfigCommand2.

protected LoadBalancerConfigCommand generateLoadBalancerConfigCommand2() {
    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));
    final LoadBalancerTO[] arrayLbs = new LoadBalancerTO[lbs.size()];
    lbs.toArray(arrayLbs);
    final NicTO nic = new NicTO();
    nic.setIp("10.1.10.2");
    final LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(arrayLbs, "64.10.2.10", "10.1.10.2", "192.168.1.2", nic, Long.valueOf(1), "1000", false);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, "10.1.10.2");
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME);
    return cmd;
}
Also used : ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) NicTO(com.cloud.agent.api.to.NicTO) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand)

Example 12 with LoadBalancerTO

use of com.cloud.agent.api.to.LoadBalancerTO in project cloudstack by apache.

the class VirtualRoutingResourceTest method generateLoadBalancerConfigCommand1.

protected LoadBalancerConfigCommand generateLoadBalancerConfigCommand1() {
    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));
    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, ROUTERNAME);
    return cmd;
}
Also used : ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) NicTO(com.cloud.agent.api.to.NicTO) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand)

Example 13 with LoadBalancerTO

use of com.cloud.agent.api.to.LoadBalancerTO in project cloudstack by apache.

the class HAProxyConfiguratorTest method testGenerateConfigurationLoadBalancerConfigCommand.

/**
     * Test method for {@link com.cloud.network.HAProxyConfigurator#generateConfiguration(com.cloud.agent.api.routing.LoadBalancerConfigCommand)}.
     */
@Test
public void testGenerateConfigurationLoadBalancerConfigCommand() {
    LoadBalancerTO lb = new LoadBalancerTO("1", "10.2.0.1", 80, "http", "bla", false, false, false, null);
    LoadBalancerTO[] lba = new LoadBalancerTO[1];
    lba[0] = lb;
    HAProxyConfigurator hpg = new HAProxyConfigurator();
    LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lba, "10.0.0.1", "10.1.0.1", "10.1.1.1", null, 1L, "12", false);
    String result = genConfig(hpg, cmd);
    assertTrue("keepalive disabled should result in 'mode http' in the resulting haproxy config", result.contains("mode http"));
    cmd = new LoadBalancerConfigCommand(lba, "10.0.0.1", "10.1.0.1", "10.1.1.1", null, 1L, "4", true);
    result = genConfig(hpg, cmd);
    assertTrue("keepalive enabled should not result in 'mode http' in the resulting haproxy config", !result.contains("mode http"));
// TODO
// create lb command
// setup tests for
// maxconn (test for maxpipes as well)
// httpmode
}
Also used : LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) Test(org.junit.Test)

Example 14 with LoadBalancerTO

use of com.cloud.agent.api.to.LoadBalancerTO in project cloudstack by apache.

the class HAProxyConfigurator method generateFwRules.

@Override
public String[][] generateFwRules(final LoadBalancerConfigCommand lbCmd) {
    final String[][] result = new String[3][];
    final Set<String> toAdd = new HashSet<String>();
    final Set<String> toRemove = new HashSet<String>();
    final Set<String> toStats = new HashSet<String>();
    for (final LoadBalancerTO lbTO : lbCmd.getLoadBalancers()) {
        final StringBuilder sb = new StringBuilder();
        sb.append(lbTO.getSrcIp()).append(":");
        sb.append(lbTO.getSrcPort()).append(":");
        final String lbRuleEntry = sb.toString();
        if (!lbTO.isRevoked()) {
            toAdd.add(lbRuleEntry);
        } else {
            toRemove.add(lbRuleEntry);
        }
    }
    StringBuilder sb = new StringBuilder("");
    if (lbCmd.lbStatsVisibility.equals("guest-network")) {
        sb = new StringBuilder(lbCmd.lbStatsGuestIP).append(":").append(lbCmd.lbStatsPort).append(":").append(lbCmd.lbStatsSrcCidrs).append(":,");
    } else if (lbCmd.lbStatsVisibility.equals("link-local")) {
        sb = new StringBuilder(lbCmd.lbStatsPrivateIP).append(":").append(lbCmd.lbStatsPort).append(":").append(lbCmd.lbStatsSrcCidrs).append(":,");
    } else if (lbCmd.lbStatsVisibility.equals("global")) {
        sb = new StringBuilder(lbCmd.lbStatsPublicIP).append(":").append(lbCmd.lbStatsPort).append(":").append(lbCmd.lbStatsSrcCidrs).append(":,");
    } else if (lbCmd.lbStatsVisibility.equals("all")) {
        sb = new StringBuilder("0.0.0.0/0").append(":").append(lbCmd.lbStatsPort).append(":").append(lbCmd.lbStatsSrcCidrs).append(":,");
    }
    toStats.add(sb.toString());
    toRemove.removeAll(toAdd);
    result[ADD] = toAdd.toArray(new String[toAdd.size()]);
    result[REMOVE] = toRemove.toArray(new String[toRemove.size()]);
    result[STATS] = toStats.toArray(new String[toStats.size()]);
    return result;
}
Also used : LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) HashSet(java.util.HashSet)

Example 15 with LoadBalancerTO

use of com.cloud.agent.api.to.LoadBalancerTO in project cloudstack by apache.

the class ExternalLoadBalancerDeviceManagerImpl method getLBHealthChecks.

@Override
public List<LoadBalancerTO> getLBHealthChecks(Network network, List<LoadBalancingRule> loadBalancingRules) throws ResourceUnavailableException {
    // Find the external load balancer in this zone
    long zoneId = network.getDataCenterId();
    DataCenterVO zone = _dcDao.findById(zoneId);
    if (loadBalancingRules == null || loadBalancingRules.isEmpty()) {
        return null;
    }
    ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(network);
    if (lbDeviceVO == null) {
        s_logger.warn("There is no external load balancer device assigned to this network either network is not implement are already shutdown so just returning");
        return null;
    }
    HostVO externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
    boolean externalLoadBalancerIsInline = _networkMgr.isNetworkInlineMode(network);
    if (network.getState() == Network.State.Allocated) {
        s_logger.debug("External load balancer was asked to apply LB rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands.");
        return null;
    }
    List<LoadBalancerTO> loadBalancersToApply = new ArrayList<LoadBalancerTO>();
    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();
        if (externalLoadBalancerIsInline) {
            long sourceIpId = _networkModel.getPublicIpAddress(rule.getSourceIp().addr(), network.getDataCenterId()).getId();
            MappingNic nic = getLoadBalancingIpNic(zone, network, sourceIpId, revoked, null);
            mappingStates.add(nic.getState());
            Nic loadBalancingIpNic = nic.getNic();
            if (loadBalancingIpNic == null) {
                continue;
            }
            // Change the source IP address for the load balancing rule to
            // be the load balancing IP address
            srcIp = loadBalancingIpNic.getIPv4Address();
        }
        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);
        }
    }
    try {
        if (loadBalancersToApply.size() > 0) {
            int numLoadBalancersForCommand = loadBalancersToApply.size();
            LoadBalancerTO[] loadBalancersForCommand = loadBalancersToApply.toArray(new LoadBalancerTO[numLoadBalancersForCommand]);
            // LoadBalancerConfigCommand cmd = new
            // LoadBalancerConfigCommand(loadBalancersForCommand, null);
            HealthCheckLBConfigCommand cmd = new HealthCheckLBConfigCommand(loadBalancersForCommand);
            long guestVlanTag = Integer.parseInt(BroadcastDomainType.getValue(network.getBroadcastUri()));
            cmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag));
            HealthCheckLBConfigAnswer answer = (HealthCheckLBConfigAnswer) _agentMgr.easySend(externalLoadBalancer.getId(), cmd);
            // easySend will return null on error
            return answer == null ? null : answer.getLoadBalancers();
        }
    } catch (Exception ex) {
        s_logger.error("Exception Occured ", ex);
    }
    //null return is handled by clients
    return null;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) HealthCheckLBConfigCommand(com.cloud.agent.api.routing.HealthCheckLBConfigCommand) HostVO(com.cloud.host.HostVO) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) URISyntaxException(java.net.URISyntaxException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer)

Aggregations

LoadBalancerTO (com.cloud.agent.api.to.LoadBalancerTO)19 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)12 ArrayList (java.util.ArrayList)12 LoadBalancerConfigCommand (com.cloud.agent.api.routing.LoadBalancerConfigCommand)10 LoadBalancingRule (com.cloud.network.lb.LoadBalancingRule)7 HealthCheckLBConfigAnswer (com.cloud.agent.api.routing.HealthCheckLBConfigAnswer)6 Nic (com.cloud.vm.Nic)5 Answer (com.cloud.agent.api.Answer)4 DataCenterVO (com.cloud.dc.DataCenterVO)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 HostVO (com.cloud.host.HostVO)4 ExternalLoadBalancerDeviceVO (com.cloud.network.dao.ExternalLoadBalancerDeviceVO)4 ConfigurationException (javax.naming.ConfigurationException)4 DestinationTO (com.cloud.agent.api.to.LoadBalancerTO.DestinationTO)3 NicTO (com.cloud.agent.api.to.NicTO)3 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)3 InsufficientNetworkCapacityException (com.cloud.exception.InsufficientNetworkCapacityException)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 Network (com.cloud.network.Network)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3