Search in sources :

Example 1 with LoadBalancerRules

use of com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRules in project cosmic by MissionCriticalCloud.

the class ConfigHelperTest method testGenerateCommandCfgLoadBalancer.

@Test
public void testGenerateCommandCfgLoadBalancer() {
    final LoadBalancerConfigCommand command = generateLoadBalancerConfigCommand();
    final AbstractConfigItemFacade configItemFacade = AbstractConfigItemFacade.getInstance(command.getClass());
    final List<ConfigItem> config = configItemFacade.generateConfig(command);
    assertTrue(config.size() > 0);
    final ConfigItem fileConfig = config.get(0);
    assertNotNull(fileConfig);
    assertTrue(fileConfig instanceof FileConfigItem);
    final String fileContents = ((FileConfigItem) fileConfig).getFileContents();
    assertNotNull(fileContents);
    final LoadBalancerRules jsonClass = gson.fromJson(fileContents, LoadBalancerRules.class);
    assertNotNull(jsonClass);
    assertEquals(jsonClass.getType(), "loadbalancer");
    final List<LoadBalancerRule> rules = jsonClass.getRules();
    assertNotNull(rules);
    assertTrue(rules.size() == 1);
    assertEquals(rules.get(0).getRouterIp(), "10.1.10.2");
    final ConfigItem scriptConfig = config.get(1);
    assertNotNull(scriptConfig);
    assertTrue(scriptConfig instanceof ScriptConfigItem);
}
Also used : LoadBalancerRule(com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRule) AbstractConfigItemFacade(com.cloud.agent.resource.virtualnetwork.facade.AbstractConfigItemFacade) LoadBalancerRules(com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRules) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) Test(org.junit.Test)

Example 2 with LoadBalancerRules

use of com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRules in project cloudstack by apache.

the class ConfigHelperTest method testGenerateCommandCfgLoadBalancer.

@Test
public void testGenerateCommandCfgLoadBalancer() {
    final LoadBalancerConfigCommand command = generateLoadBalancerConfigCommand();
    final AbstractConfigItemFacade configItemFacade = AbstractConfigItemFacade.getInstance(command.getClass());
    final List<ConfigItem> config = configItemFacade.generateConfig(command);
    assertTrue(config.size() > 0);
    final ConfigItem fileConfig = config.get(0);
    assertNotNull(fileConfig);
    assertTrue(fileConfig instanceof FileConfigItem);
    final String fileContents = ((FileConfigItem) fileConfig).getFileContents();
    assertNotNull(fileContents);
    final LoadBalancerRules jsonClass = gson.fromJson(fileContents, LoadBalancerRules.class);
    assertNotNull(jsonClass);
    assertEquals(jsonClass.getType(), "loadbalancer");
    final List<LoadBalancerRule> rules = jsonClass.getRules();
    assertNotNull(rules);
    assertTrue(rules.size() == 1);
    assertEquals(rules.get(0).getRouterIp(), "10.1.10.2");
    final ConfigItem scriptConfig = config.get(1);
    assertNotNull(scriptConfig);
    assertTrue(scriptConfig instanceof ScriptConfigItem);
}
Also used : LoadBalancerRule(com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRule) AbstractConfigItemFacade(com.cloud.agent.resource.virtualnetwork.facade.AbstractConfigItemFacade) LoadBalancerRules(com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRules) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) Test(org.junit.Test)

Example 3 with LoadBalancerRules

use of com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRules in project cloudstack by apache.

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<LoadBalancerRule>();
    rules.add(loadBalancerRule);
    final LoadBalancerRules configRules = new LoadBalancerRules(rules);
    return generateConfigItems(configRules);
}
Also used : HAProxyConfigurator(com.cloud.network.HAProxyConfigurator) LoadBalancerRule(com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRule) LoadBalancerRules(com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRules) LoadBalancerConfigurator(com.cloud.network.LoadBalancerConfigurator) LinkedList(java.util.LinkedList) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand)

Example 4 with LoadBalancerRules

use of com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRules 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.network.HAProxyConfigurator) LoadBalancerRule(com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRule) LoadBalancerRules(com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRules) LoadBalancerConfigurator(com.cloud.network.LoadBalancerConfigurator) LinkedList(java.util.LinkedList) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand)

Aggregations

LoadBalancerConfigCommand (com.cloud.agent.api.routing.LoadBalancerConfigCommand)4 LoadBalancerRule (com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRule)4 LoadBalancerRules (com.cloud.agent.resource.virtualnetwork.model.LoadBalancerRules)4 AbstractConfigItemFacade (com.cloud.agent.resource.virtualnetwork.facade.AbstractConfigItemFacade)2 HAProxyConfigurator (com.cloud.network.HAProxyConfigurator)2 LoadBalancerConfigurator (com.cloud.network.LoadBalancerConfigurator)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2