Search in sources :

Example 1 with HAProxyConfigurator

use of com.cloud.common.virtualnetwork.lb.HAProxyConfigurator in project cosmic by MissionCriticalCloud.

the class HAProxyConfiguratorTest method testGenerateConfigurationLoadBalancerConfigCommand.

/**
 * Test method for {@link HAProxyConfigurator#generateConfiguration(LoadBalancerConfigCommand)}.
 */
@Test
public void testGenerateConfigurationLoadBalancerConfigCommand() {
    final LoadBalancerTO lb = new LoadBalancerTO("1", "10.2.0.1", 80, "http", "bla", false, false, false, null, 60000, 60000);
    final LoadBalancerTO[] lba = new LoadBalancerTO[1];
    lba[0] = lb;
    final 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 : HAProxyConfigurator(com.cloud.common.virtualnetwork.lb.HAProxyConfigurator) LoadBalancerTO(com.cloud.legacymodel.to.LoadBalancerTO) LoadBalancerConfigCommand(com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand) Test(org.junit.Test)

Example 2 with HAProxyConfigurator

use of com.cloud.common.virtualnetwork.lb.HAProxyConfigurator in project cosmic by MissionCriticalCloud.

the class LoadBalancerConfigItem method generateConfig.

@Override
public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
    final LoadBalancerConfigCommand command = (LoadBalancerConfigCommand) cmd;
    final LoadBalancerConfigurator cfgtr = new HAProxyConfigurator();
    final String[] configuration = cfgtr.generateConfiguration(command);
    String routerIp = command.getNic().getIp();
    if (command.getVpcId() == null) {
        routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
    }
    final String tmpCfgFilePath = "/etc/haproxy/";
    final String tmpCfgFileName = "haproxy.cfg.new." + String.valueOf(System.currentTimeMillis());
    final String[][] allRules = cfgtr.generateFwRules(command);
    final String[] addRules = allRules[LoadBalancerConfigurator.ADD];
    final String[] removeRules = allRules[LoadBalancerConfigurator.REMOVE];
    final String[] statRules = allRules[LoadBalancerConfigurator.STATS];
    final LoadBalancerRule loadBalancerRule = new LoadBalancerRule(configuration, tmpCfgFilePath, tmpCfgFileName, addRules, removeRules, statRules, routerIp);
    final List<LoadBalancerRule> rules = new LinkedList<>();
    rules.add(loadBalancerRule);
    final LoadBalancerRules configRules = new LoadBalancerRules(rules);
    return generateConfigItems(configRules);
}
Also used : HAProxyConfigurator(com.cloud.common.virtualnetwork.lb.HAProxyConfigurator) LoadBalancerRule(com.cloud.legacymodel.network.rules.LoadBalancerRule) LoadBalancerRules(com.cloud.legacymodel.network.rules.LoadBalancerRules) LoadBalancerConfigurator(com.cloud.common.virtualnetwork.lb.LoadBalancerConfigurator) LinkedList(java.util.LinkedList) LoadBalancerConfigCommand(com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand)

Example 3 with HAProxyConfigurator

use of com.cloud.common.virtualnetwork.lb.HAProxyConfigurator 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)

Aggregations

HAProxyConfigurator (com.cloud.common.virtualnetwork.lb.HAProxyConfigurator)3 LoadBalancerConfigCommand (com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand)3 LoadBalancerTO (com.cloud.legacymodel.to.LoadBalancerTO)2 Test (org.junit.Test)2 LoadBalancerConfigurator (com.cloud.common.virtualnetwork.lb.LoadBalancerConfigurator)1 LbDestination (com.cloud.legacymodel.network.LoadBalancingRule.LbDestination)1 LoadBalancerRule (com.cloud.legacymodel.network.rules.LoadBalancerRule)1 LoadBalancerRules (com.cloud.legacymodel.network.rules.LoadBalancerRules)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1