use of com.cloud.legacymodel.network.rules.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);
}
use of com.cloud.legacymodel.network.rules.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);
}
Aggregations