Bug:10557

This commit is contained in:
Naredula Janardhana Reddy 2011-07-25 17:39:34 +05:30
parent 69d928b3d1
commit 96bacb85f8
4 changed files with 55 additions and 4 deletions

View File

@ -25,6 +25,9 @@ import com.cloud.agent.api.to.LoadBalancerTO;
*/
public class LoadBalancerConfigCommand extends NetworkElementCommand {
LoadBalancerTO[] loadBalancers;
public String lbStatsAccessbility;
public String lbStatsIp; /* load balancer listen on this ip for stats */
public String lbStatsPort="8080"; /* load balancer listen on this ip for stats */
protected LoadBalancerConfigCommand() {

View File

@ -37,6 +37,7 @@ import com.cloud.utils.net.NetUtils;
*
*/
public class HAProxyConfigurator implements LoadBalancerConfigurator {
private static String [] globalSection = {"global",
"\tlog 127.0.0.1:3914 local0 warning",
"\tmaxconn 4096",
@ -46,6 +47,17 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
"\tdaemon"
};
private static String [] statsSubrule = {
"\tmode http",
"\toption httpclose",
"\tstats enable",
"\tstats uri /admin?stats",
"\tstats realm Haproxy\\ Statistics",
"\tstats auth admin1:AdMiN123"
};
private static String [] defaultsSection = {"defaults",
"\tlog global",
"\tmode tcp",
@ -63,6 +75,19 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
"\ttimeout server 50000"
};
private static String [] defaultsSectionWithoutStats = {"defaults",
"\tlog global",
"\tmode tcp",
"\toption dontlognull",
"\tretries 3",
"\toption redispatch",
"\toption forwardfor",
"\toption forceclose",
"\ttimeout connect 5000",
"\ttimeout client 50000",
"\ttimeout server 50000"
};
private static String [] defaultListen = {"listen vmops 0.0.0.0:9",
"\toption transparent"
};
@ -86,7 +111,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
}
List<String> result = new ArrayList<String>();
result.addAll(Arrays.asList(globalSection));
result.add(getBlankLine());
result.addAll(Arrays.asList(defaultsSection));
@ -198,8 +223,29 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
result.addAll(Arrays.asList(globalSection));
result.add(getBlankLine());
result.addAll(Arrays.asList(defaultsSection));
result.add(getBlankLine());
if (lbCmd.lbStatsAccessbility.equals("accessible"))
{
result.addAll(Arrays.asList(defaultsSection));
result.add(getBlankLine());
}
else
{
result.addAll(Arrays.asList(defaultsSectionWithoutStats));
result.add(getBlankLine());
if (lbCmd.lbStatsAccessbility.equals("only-to-guest"))
{
String rule="listen admin_page ";
rule=rule.concat(lbCmd.lbStatsIp);
rule=rule.concat(":");
rule=rule.concat(lbCmd.lbStatsPort);
/*listen admin_page guestip:8081 */
result.add(rule);
result.addAll(Arrays.asList(statsSubrule));
result.add(getBlankLine());
}
}
if (lbCmd.getLoadBalancers().length == 0){
//haproxy cannot handle empty listen / frontend or backend, so add a dummy listener

View File

@ -56,7 +56,7 @@ public enum Config {
TotalRetries("Storage", AgentManager.class, Integer.class, "total.retries", "4", "The number of times each command sent to a host should be retried in case of failure.", null),
// Network
LoadBalancerStats("Network", ManagementServer.class, String.class, "loadbalancer.stats", "accessible", "lb stats accessibility, it can accessible,unaccessible or only-to-guest", null),
GuestVlanBits("Network", ManagementServer.class, Integer.class, "guest.vlan.bits", "12", "The number of bits to reserve for the VLAN identifier in the guest subnet.", null),
//MulticastThrottlingRate("Network", ManagementServer.class, Integer.class, "multicast.throttling.rate", "10", "Default multicast rate in megabits per second allowed.", null),
NetworkThrottlingRate("Network", ManagementServer.class, Integer.class, "network.throttling.rate", "200", "Default data transfer rate in megabits per second allowed in network.", null),

View File

@ -1858,6 +1858,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs);
cmd.lbStatsAccessbility = _configDao.getValue(Config.LoadBalancerStats.key());
cmd.lbStatsIp = router.getGuestIpAddress();
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, router.getPrivateIpAddress());
cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress());
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());