stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject stratos git commit: Make schedule algorithms as a configurable value
Date Thu, 04 Jun 2015 06:07:14 GMT
Repository: stratos
Updated Branches:
  refs/heads/lvs_extension 04aea8a61 -> 999ffd7f4


Make schedule algorithms as a configurable value


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/999ffd7f
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/999ffd7f
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/999ffd7f

Branch: refs/heads/lvs_extension
Commit: 999ffd7f459c68860d8022bc7dcf1af01eb74808
Parents: 04aea8a
Author: Gayan Gunarathne <gayang@wso2.com>
Authored: Thu Jun 4 11:36:51 2015 +0530
Committer: Gayan Gunarathne <gayang@wso2.com>
Committed: Thu Jun 4 11:36:51 2015 +0530

----------------------------------------------------------------------
 .../lvs-extension/src/main/bin/lvs-extension.sh |   1 +
 .../apache/stratos/lvs/extension/Constants.java |   1 +
 .../org/apache/stratos/lvs/extension/LVS.java   |   4 +-
 .../stratos/lvs/extension/LVSConfigWriter.java  | 298 ++++++++++---------
 .../stratos/lvs/extension/LVSContext.java       |  15 +-
 .../lvs/extension/LVSStatisticsReader.java      |   3 +-
 6 files changed, 172 insertions(+), 150 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/999ffd7f/extensions/load-balancer/lvs-extension/src/main/bin/lvs-extension.sh
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/lvs-extension/src/main/bin/lvs-extension.sh b/extensions/load-balancer/lvs-extension/src/main/bin/lvs-extension.sh
index 659addd..c276cd2 100755
--- a/extensions/load-balancer/lvs-extension/src/main/bin/lvs-extension.sh
+++ b/extensions/load-balancer/lvs-extension/src/main/bin/lvs-extension.sh
@@ -43,6 +43,7 @@ properties="-Dlvs.private.ip=127.0.0.1
             -Dcluster.id=cluster-1
             -Dservice.name=service-1
             -Dlvs.service.virtualip.set=tomcat2|192.168.56.40,tomcat1|192.168.56.41
+            -Dschedule.algorithm=rr
             -Dserver.state=MASTER"
 
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/999ffd7f/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/Constants.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/Constants.java
b/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/Constants.java
index 715798f..ce0f267 100644
--- a/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/Constants.java
+++ b/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/Constants.java
@@ -39,4 +39,5 @@ public class Constants {
 	public static final String VIRTUALIPS_FOR_SERVICES = "lvs.service.virtualip.set" ;
 	public static final String KEEPALIVED_START_COMMAND = "service keepalived restart";
 	public static final String SERVER_STATE ="server.state" ;
+	public static final String LVS_SCHEDULE_ALGO = "schedule.algorithm";
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/999ffd7f/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVS.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVS.java
b/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVS.java
index 257a60e..6470a13 100644
--- a/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVS.java
+++ b/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVS.java
@@ -44,6 +44,7 @@ public class LVS implements LoadBalancer {
 	private String virtualIPsForServices;
 	private String keepAlivedStartCommand;
 	private String serverState;
+	private String scheduleAlgo;
 
     public LVS() {
         this.executableFilePath = LVSContext.getInstance().getExecutableFilePath();
@@ -55,6 +56,7 @@ public class LVS implements LoadBalancer {
 	    this.virtualIPsForServices= LVSContext.getInstance().getVirtualIPsForServices();
 	    this.keepAlivedStartCommand=LVSContext.getInstance().getKeepAlivedStartCommand();
 	    this.serverState=LVSContext.getInstance().getServerState();
+	    this.scheduleAlgo=LVSContext.getInstance().getLvsScheduleAlgo();
     }
 
     /**
@@ -66,7 +68,7 @@ public class LVS implements LoadBalancer {
         try {
             log.info("Generating lvs configuration...");
             LVSConfigWriter writer = new LVSConfigWriter(templatePath, templateName, confFilePath,
statsSocketFilePath,
-                                                         virtualIPsForServices,serverState);
+                                                         virtualIPsForServices,serverState,scheduleAlgo);
             if(writer.write(topology)) {
                 return true;
             }

http://git-wip-us.apache.org/repos/asf/stratos/blob/999ffd7f/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSConfigWriter.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSConfigWriter.java
b/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSConfigWriter.java
index 4d6d3f3..3a2f8cc 100644
--- a/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSConfigWriter.java
+++ b/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSConfigWriter.java
@@ -38,158 +38,164 @@ import java.util.Collection;
  */
 public class LVSConfigWriter {
 
-    private static final Log log = LogFactory.getLog(Main.class);
-    private static final String NEW_LINE = System.getProperty("line.separator");
-    private static final String TAB = "    ";
-
-    private String templatePath;
-    private String templateName;
-    private String confFilePath;
-    private String statsSocketFilePath;
+	private static final Log log = LogFactory.getLog(Main.class);
+	private static final String NEW_LINE = System.getProperty("line.separator");
+	private static final String TAB = "    ";
+
+	private String templatePath;
+	private String templateName;
+	private String confFilePath;
+	private String statsSocketFilePath;
 	private String virtualIPsForServices;
 	private String serverState;
+	private String scheduleAlgo;
 
-    public LVSConfigWriter(String templatePath, String templateName, String confFilePath,
-                           String statsSocketFilePath,String virtualIPsForServices,String
serverState) {
+	public LVSConfigWriter(String templatePath, String templateName, String confFilePath,
+	                       String statsSocketFilePath, String virtualIPsForServices, String
serverState,
+	                       String scheduleAlgo) {
 
-        this.templatePath = templatePath;
-        this.templateName = templateName;
-        this.confFilePath = confFilePath;
-        this.statsSocketFilePath = statsSocketFilePath;
-	    this.virtualIPsForServices=virtualIPsForServices;
-	    this.serverState=serverState;
-    }
+		this.templatePath = templatePath;
+		this.templateName = templateName;
+		this.confFilePath = confFilePath;
+		this.statsSocketFilePath = statsSocketFilePath;
+		this.virtualIPsForServices = virtualIPsForServices;
+		this.serverState = serverState;
+		this.scheduleAlgo = scheduleAlgo;
+	}
 
-    public boolean write(Topology topology) {
+	public boolean write(Topology topology) {
 
-        StringBuilder configurationBuilder = new StringBuilder();
-	    StringBuilder virtualIPBuilder=new StringBuilder();
+		StringBuilder configurationBuilder = new StringBuilder();
+		StringBuilder virtualIPBuilder = new StringBuilder();
 		String state;
-        for (Service service : topology.getServices()) {
-            for (Cluster cluster : service.getClusters()) {
-                if ((service.getPorts() == null) || (service.getPorts().size() == 0)) {
-                    throw new RuntimeException(String.format("No ports found in service:
%s", service.getServiceName()));
-                }
-                generateConfigurationForCluster(cluster, service.getPorts(), configurationBuilder,virtualIPBuilder,virtualIPsForServices);
-            }
-        }
-
-        // Start velocity engine
-        VelocityEngine ve = new VelocityEngine();
-        ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath);
-        ve.init();
-
-        // Open the template
-        Template t = ve.getTemplate(templateName);
-
-        // Insert strings into the template
-        VelocityContext context = new VelocityContext();
-        context.put("configuration", configurationBuilder.toString());
-	    context.put("virtualips", virtualIPBuilder.toString());
-	    context.put("state", serverState);
-
-        // Create a new string from the template
-        StringWriter stringWriter = new StringWriter();
-        t.merge(context, stringWriter);
-        String configuration = stringWriter.toString();
-
-        // Write configuration file
-        try {
-            BufferedWriter writer = new BufferedWriter(new FileWriter(confFilePath));
-            writer.write(configuration);
-            writer.close();
-
-            if (log.isInfoEnabled()) {
-                log.info(String.format("Configuration written to file: %s", confFilePath));
-            }
-            return true;
-        } catch (IOException e) {
-            if (log.isErrorEnabled()) {
-                log.error(String.format("Could not write configuration file: %s", confFilePath));
-            }
-            throw new RuntimeException(e);
-        }
-    }
-
-
-    /**
-     * Generate configuration for a cluster with the following format:
-     *
-     * virtual_server 10.10.10.10 80 {
-     *      delay_loop 10
-     *      lvs_sched wlc
-     *      lvs_method DR
-     *      persistence_timeout 5
-     *      protocol TCP
-
-     *      real_server 10.10.10.41 80 {
-     *          weight 50
-     *          TCP_CHECK {
-     *              connect_timeout 3
-     *          }
-     *      }
+		for (Service service : topology.getServices()) {
+			for (Cluster cluster : service.getClusters()) {
+				if ((service.getPorts() == null) || (service.getPorts().size() == 0)) {
+					throw new RuntimeException(
+							String.format("No ports found in service: %s", service.getServiceName()));
+				}
+				generateConfigurationForCluster(cluster, service.getPorts(), configurationBuilder, virtualIPBuilder,
+				                                virtualIPsForServices, scheduleAlgo);
+			}
+		}
+
+		// Start velocity engine
+		VelocityEngine ve = new VelocityEngine();
+		ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath);
+		ve.init();
+
+		// Open the template
+		Template t = ve.getTemplate(templateName);
+
+		// Insert strings into the template
+		VelocityContext context = new VelocityContext();
+		context.put("configuration", configurationBuilder.toString());
+		context.put("virtualips", virtualIPBuilder.toString());
+		context.put("state", serverState);
+
+		// Create a new string from the template
+		StringWriter stringWriter = new StringWriter();
+		t.merge(context, stringWriter);
+		String configuration = stringWriter.toString();
+
+		// Write configuration file
+		try {
+			BufferedWriter writer = new BufferedWriter(new FileWriter(confFilePath));
+			writer.write(configuration);
+			writer.close();
+
+			if (log.isInfoEnabled()) {
+				log.info(String.format("Configuration written to file: %s", confFilePath));
+			}
+			return true;
+		} catch (IOException e) {
+			if (log.isErrorEnabled()) {
+				log.error(String.format("Could not write configuration file: %s", confFilePath));
+			}
+			throw new RuntimeException(e);
+		}
+	}
+
+	/**
+	 * Generate configuration for a cluster with the following format:
+	 * <p/>
+	 * virtual_server 10.10.10.10 80 {
+	 * delay_loop 10
+	 * lvs_sched wlc
+	 * lvs_method DR
+	 * persistence_timeout 5
+	 * protocol TCP
+	 * <p/>
+	 * real_server 10.10.10.41 80 {
+	 * weight 50
+	 * TCP_CHECK {
+	 * connect_timeout 3
+	 * }
+	 * }
+	 * <p/>
+	 * real_server 10.10.10.42 80 {
+	 * weight 50
+	 * TCP_CHECK {
+	 * connect_timeout 3
+	 * }
+	 * }
+	 * }
 	 *
-     *      real_server 10.10.10.42 80 {
-     *          weight 50
-     *          TCP_CHECK {
-     *              connect_timeout 3
-     *           }
-     *      }
-     * }
-     *
-     * @param cluster
-     * @param ports
-     * @param text
-     */
-    private void generateConfigurationForCluster(Cluster cluster, Collection<Port>
ports, StringBuilder text,StringBuilder virtualIPs,String virtualIPsForServices) {
-
-	    String[] virtualIPForServiceArray;
-	    if (virtualIPsForServices.contains(",")) {
-		    virtualIPForServiceArray = virtualIPsForServices.split(",");
-	    } else {
-		    virtualIPForServiceArray = new String[1];
-		    virtualIPForServiceArray[0] = virtualIPsForServices;
-	    }
-	    boolean isServiceAvailable = false;
-	    for (int i = 0; i < virtualIPForServiceArray.length; i++) {
-		    String[] virtualIpForService = virtualIPForServiceArray[i].split("\\|");
-		    for (Port port : ports) {
-			    for (String hostname : cluster.getHostNames()) {
-				    if (virtualIpForService[0].equals(cluster.getServiceName())) {
-
-					    text.append("virtual_server ").append(virtualIpForService[1]).append(" ").append(port.getValue()).append(
-							    " {").append(
-							    NEW_LINE);
-					    text.append(TAB).append("delay_loop 10").append(NEW_LINE);
-					    text.append(TAB).append("lvs_sched wlc").append(NEW_LINE);
-					    text.append(TAB).append("lvs_method DR").append(NEW_LINE);
-					    text.append(TAB).append("persistence_timeout 5").append(NEW_LINE);
-					    text.append(TAB).append("protocol TCP").append(NEW_LINE).append(NEW_LINE);
-
-					    //Start real servers block
-
-					    for (Member member : cluster.getMembers()) {
-						    // Start upstream server block
-						    text.append(TAB).append("real_server ").append(member.getHostName()).append(" ")
-						        .append(port.getValue()).append(" {")
-						        .append(NEW_LINE);
-						    text.append(TAB).append(TAB).append("weight 50").append(NEW_LINE);
-						    text.append(TAB).append(TAB).append("TCP_CHECK {").append(NEW_LINE);
-						    text.append(TAB).append(TAB).append(TAB).append("connect_timeout 3").append(NEW_LINE);
-						    text.append(TAB).append(TAB).append("}").append(NEW_LINE);
-						    text.append(TAB).append("}").append(NEW_LINE);
-					    }
-					    text.append("}").append(NEW_LINE);
-					    isServiceAvailable = true;
-					    virtualIPs.append(TAB).append(TAB).append(virtualIpForService[1]).append(NEW_LINE);
-				    }
-			    }
-		    }
-		    if (!isServiceAvailable) {
-			    log.warn(String.format("Given service is not available in the topology %s", virtualIpForService[0]));
-		    }
-	    }
-
-
-    }
+	 * @param cluster
+	 * @param ports
+	 * @param text
+	 */
+	private void generateConfigurationForCluster(Cluster cluster, Collection<Port> ports,
StringBuilder text,
+	                                             StringBuilder virtualIPs, String virtualIPsForServices,
+	                                             String scheduleAlgo) {
+
+		String[] virtualIPForServiceArray;
+		if (virtualIPsForServices.contains(",")) {
+			virtualIPForServiceArray = virtualIPsForServices.split(",");
+		} else {
+			virtualIPForServiceArray = new String[1];
+			virtualIPForServiceArray[0] = virtualIPsForServices;
+		}
+		boolean isServiceAvailable = false;
+		for (int i = 0; i < virtualIPForServiceArray.length; i++) {
+			String[] virtualIpForService = virtualIPForServiceArray[i].split("\\|");
+			for (Port port : ports) {
+				for (String hostname : cluster.getHostNames()) {
+					if (virtualIpForService[0].equals(cluster.getServiceName())) {
+
+						text.append("virtual_server ").append(virtualIpForService[1]).append(" ")
+						    .append(port.getValue()).append(
+								" {").append(
+								NEW_LINE);
+						text.append(TAB).append("delay_loop 10").append(NEW_LINE);
+						text.append(TAB).append("lvs_sched ").append(scheduleAlgo).append(NEW_LINE);
+						text.append(TAB).append("lvs_method DR").append(NEW_LINE);
+						text.append(TAB).append("persistence_timeout 5").append(NEW_LINE);
+						text.append(TAB).append("protocol TCP").append(NEW_LINE).append(NEW_LINE);
+
+						//Start real servers block
+
+						for (Member member : cluster.getMembers()) {
+							// Start upstream server block
+							text.append(TAB).append("real_server ").append(member.getHostName()).append(" ")
+							    .append(port.getValue()).append(" {")
+							    .append(NEW_LINE);
+							text.append(TAB).append(TAB).append("weight 50").append(NEW_LINE);
+							text.append(TAB).append(TAB).append("TCP_CHECK {").append(NEW_LINE);
+							text.append(TAB).append(TAB).append(TAB).append("connect_timeout 3").append(NEW_LINE);
+							text.append(TAB).append(TAB).append("}").append(NEW_LINE);
+							text.append(TAB).append("}").append(NEW_LINE);
+						}
+						text.append("}").append(NEW_LINE);
+						isServiceAvailable = true;
+						virtualIPs.append(TAB).append(TAB).append(virtualIpForService[1]).append(NEW_LINE);
+					}
+				}
+			}
+			if (!isServiceAvailable) {
+				log.warn(String.format("Given service is not available in the topology %s", virtualIpForService[0]));
+			}
+		}
+
+	}
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/999ffd7f/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSContext.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSContext.java
b/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSContext.java
index 228c455..1307473 100644
--- a/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSContext.java
+++ b/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSContext.java
@@ -46,6 +46,7 @@ public class LVSContext {
 	private String virtualIPsForServices;
 	private String keepAlivedStartCommand;
 	private String serverState;
+	private String lvsScheduleAlgo;
 
     private LVSContext() {
         this.lvsPrivateIp = System.getProperty(Constants.LVS_PRIVATE_IP);
@@ -63,7 +64,8 @@ public class LVSContext {
         this.serviceName = System.getProperty(Constants.SERVICE_NAME);
 	    this.virtualIPsForServices=System.getProperty(Constants.VIRTUALIPS_FOR_SERVICES);
 	    this.keepAlivedStartCommand=Constants.KEEPALIVED_START_COMMAND;
-	    this.setServerState(System.getProperty(Constants.SERVER_STATE));
+	    this.serverState=System.getProperty(Constants.SERVER_STATE);
+	    this.lvsScheduleAlgo = System.getProperty(Constants.LVS_SCHEDULE_ALGO);
 
         if (log.isDebugEnabled()) {
             log.debug(Constants.LVS_PRIVATE_IP + " = " + lvsPrivateIp);
@@ -78,7 +80,8 @@ public class LVSContext {
             log.debug(Constants.THRIFT_RECEIVER_PORT + " = " + thriftReceiverPort);
             log.debug(Constants.NETWORK_PARTITION_ID + " = " + networkPartitionId);
             log.debug(Constants.CLUSTER_ID + " = " + clusterId);
-	        log.debug(Constants.VIRTUALIPS_FOR_SERVICES + " = " + getVirtualIPsForServices());
+	        log.debug(Constants.VIRTUALIPS_FOR_SERVICES + " = " + virtualIPsForServices);
+	        log.debug(Constants.LVS_SCHEDULE_ALGO + " = " + lvsScheduleAlgo);
         }
     }
 
@@ -185,4 +188,12 @@ public class LVSContext {
 	public void setServerState(String serverState) {
 		this.serverState = serverState;
 	}
+
+	public String getLvsScheduleAlgo() {
+		return lvsScheduleAlgo;
+	}
+
+	public void setLvsScheduleAlgo(String lvsScheduleAlgo) {
+		this.lvsScheduleAlgo = lvsScheduleAlgo;
+	}
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/999ffd7f/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSStatisticsReader.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSStatisticsReader.java
b/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSStatisticsReader.java
index cfb3435..2bf9003 100644
--- a/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSStatisticsReader.java
+++ b/extensions/load-balancer/lvs-extension/src/main/java/org/apache/stratos/lvs/extension/LVSStatisticsReader.java
@@ -34,7 +34,8 @@ import java.io.IOException;
 public class LVSStatisticsReader implements LoadBalancerStatisticsReader {
 
 	private static final Log log = LogFactory.getLog(LVSStatisticsReader.class);
-	private static final String IPVSADM_STATS_COMMAND = "sudo ipvsadm -L -n |grep Route"; //"ipvsadm
-l --stats | grep TCP"
+	private static final String IPVSADM_STATS_COMMAND = "sudo ipvsadm -L -n |grep Route";
+			//"ipvsadm -l --stats | grep TCP"
 
 	private TopologyProvider topologyProvider;
 


Mime
View raw message