use of com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand 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
}
use of com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand in project cosmic by MissionCriticalCloud.
the class CommandSetupHelper method createApplyLoadBalancingRulesCommands.
public void createApplyLoadBalancingRulesCommands(final List<LoadBalancingRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
final LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
int i = 0;
// We don't support VR to be inline currently
final boolean inline = false;
for (final LoadBalancingRule rule : rules) {
final boolean revoked = rule.getState().equals(FirewallRule.State.Revoke);
final String protocol = rule.getProtocol();
final String lb_protocol = rule.getLbProtocol();
final String algorithm = rule.getAlgorithm();
final String uuid = rule.getUuid();
final String srcIp = rule.getSourceIp().addr();
final int srcPort = rule.getSourcePortStart();
final List<LbDestination> destinations = rule.getDestinations();
final List<LbStickinessPolicy> stickinessPolicies = rule.getStickinessPolicies();
// Load default values and fallback to hardcoded if not available
final Integer defaultClientTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.DefaultLoadBalancerClientTimeout.key()), 60000);
final Integer defaultServerTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.DefaultLoadBalancerServerTimeout.key()), 60000);
// set timeouts, use defaults if not available
Integer clientTimeout = rule.getClientTimeout();
if (clientTimeout != null) {
clientTimeout = NumbersUtil.parseInt(clientTimeout.toString(), defaultClientTimeout);
} else {
clientTimeout = defaultClientTimeout;
}
Integer serverTimeout = rule.getServerTimeout();
if (serverTimeout != null) {
serverTimeout = NumbersUtil.parseInt(serverTimeout.toString(), defaultServerTimeout);
} else {
serverTimeout = defaultServerTimeout;
}
final LoadBalancerTO lb = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, stickinessPolicies, clientTimeout, serverTimeout);
lb.setLbProtocol(lb_protocol);
lbs[i++] = lb;
}
String routerPublicIp = null;
if (router instanceof DomainRouterVO) {
final DomainRouterVO domr = _routerDao.findById(router.getId());
routerPublicIp = domr.getPublicIpAddress();
if (routerPublicIp == null) {
routerPublicIp = router.getPublicIpAddress();
}
}
final Network guestNetwork = _networkModel.getNetwork(guestNetworkId);
final Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), router.getId());
final NicProfile nicProfile = new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(guestNetwork.getId(), router.getId()), _networkModel.getNetworkTag(router.getHypervisorType(), guestNetwork));
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();
}
final LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs, routerPublicIp, _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()), router.getPrivateIpAddress(), _itMgr.toNicTO(nicProfile, router.getHypervisorType()), router.getVpcId(), maxconn, offering.isKeepAliveEnabled());
cmd.lbStatsVisibility = _configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key());
cmd.lbStatsUri = _configDao.getValue(Config.NetworkLBHaproxyStatsUri.key());
cmd.lbStatsAuth = _configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key());
cmd.lbStatsPort = _configDao.getValue(Config.NetworkLBHaproxyStatsPort.key());
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
final Zone zone = zoneRepository.findById(router.getDataCenterId()).orElse(null);
cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, zone.getNetworkType().toString());
cmds.addCommand(cmd);
}
use of com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand 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.communication.command.LoadBalancerConfigCommand 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;
}
use of com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand 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