stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject stratos git commit: LVS extension updates with the configuration generation and add the lvsvirtualip to the payload
Date Tue, 19 May 2015 08:07:00 GMT
Repository: stratos
Updated Branches:
  refs/heads/lvs_extension 617397e12 -> 6f12fafec


LVS extension updates with the configuration generation and add the lvsvirtualip to the payload


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

Branch: refs/heads/lvs_extension
Commit: 6f12fafecec9f77304de94c5ed3a8635392af552
Parents: 617397e
Author: Gayan Gunarathne <gayang@wso2.com>
Authored: Tue May 19 13:36:00 2015 +0530
Committer: Gayan Gunarathne <gayang@wso2.com>
Committed: Tue May 19 13:36:00 2015 +0530

----------------------------------------------------------------------
 .../applications/ApplicationUtils.java          |  7 +-
 .../parser/DefaultApplicationParser.java        |  6 +-
 .../applications/payload/BasicPayloadData.java  | 13 +++
 .../pojo/SubscribableInfoContext.java           | 10 +++
 .../extension/api/LoadBalancerExtension.java    |  2 +-
 .../lvs-extension/src/main/assembly/bin.xml     |  2 +-
 .../lvs-extension/src/main/bin/lvs-extension.sh |  8 +-
 .../apache/stratos/lvs/extension/Constants.java |  3 +
 .../org/apache/stratos/lvs/extension/LVS.java   | 33 ++++---
 .../stratos/lvs/extension/LVSConfigWriter.java  | 90 +++++++++++++-------
 .../stratos/lvs/extension/LVSContext.java       | 31 +++++++
 .../src/main/templates/keepalived.conf.template | 29 +------
 .../src/main/templates/nginx.cfg.template       |  8 --
 extensions/load-balancer/pom.xml                |  1 +
 .../templates/bin/haproxy-extension.sh.erb      |  2 +-
 15 files changed, 154 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java
index 85f5331..6e68aae 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java
@@ -133,12 +133,12 @@ public class ApplicationUtils {
     public static PayloadData createPayload(String appId, String groupName, Cartridge cartridge,
String subscriptionKey, int tenantId, String clusterId,
                                             String hostName, String repoUrl, String alias,
Map<String, String> customPayloadEntries, String[] dependencyAliases,
                                             org.apache.stratos.common.Properties properties,
String oauthToken, String[] dependencyClusterIDs,
-                                            String[] exportMetadata, String[] importMetadata)
+                                            String[] exportMetadata, String[] importMetadata,String
lvsVirtualIP)
             throws ApplicationDefinitionException {
 
         //Create the payload
         BasicPayloadData basicPayloadData = createBasicPayload(appId, groupName, cartridge,
subscriptionKey,
-                clusterId, hostName, repoUrl, alias, tenantId, dependencyAliases, dependencyClusterIDs,
exportMetadata, importMetadata);
+                clusterId, hostName, repoUrl, alias, tenantId, dependencyAliases, dependencyClusterIDs,
exportMetadata, importMetadata,lvsVirtualIP);
         //Populate the basic payload details
         basicPayloadData.populatePayload();
 
@@ -206,7 +206,7 @@ public class ApplicationUtils {
                                                        String subscriptionKey, String clusterId,
                                                        String hostName, String repoUrl, String
alias,
                                                        int tenantId, String[] dependencyAliases,
String[] dependencyCLusterIDs,
-                                                       String[] exportMetadata, String[]
importMetadata) {
+                                                       String[] exportMetadata, String[]
importMetadata,String lvsVirtualIP) {
 
         BasicPayloadData basicPayloadData = new BasicPayloadData();
         basicPayloadData.setAppId(appId);
@@ -218,6 +218,7 @@ public class ApplicationUtils {
         basicPayloadData.setPortMappings(createPortMappingPayloadString(cartridge));
         basicPayloadData.setServiceName(cartridge.getType());
         basicPayloadData.setProvider(cartridge.getProvider());
+	    basicPayloadData.setLvsVirtualIP(lvsVirtualIP);
 
         if (repoUrl != null) {
             basicPayloadData.setGitRepositoryUrl(repoUrl);

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
index fd88d06..ea3e7b7 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
@@ -448,7 +448,7 @@ public class DefaultApplicationParser implements ApplicationParser {
                     subscribableInfoContext.getDeploymentPolicy(), isLB,
                     tenantRange, subscribableInfoContext.getDependencyAliases(),
                     subscribableInfoContext.getProperties(), arrDependencyClusterIDs, arrExportMetadata,
-                    arrImportMetadata);
+                    arrImportMetadata,subscribableInfoContext.getLvsVirtualIP());
 
             appClusterCtxt.setAutoscalePolicyName(subscribableInfoContext.getAutoscalingPolicy());
             appClusterCtxt.setProperties(subscribableInfoContext.getProperties());
@@ -928,12 +928,12 @@ public class DefaultApplicationParser implements ApplicationParser {
                                                                       String alias, String
clusterId, String hostname,
                                                                       String deploymentPolicy,
boolean isLB, String tenantRange,
                                                                       String[] dependencyAliases,
Properties properties, String[] dependencyClustorIDs,
-                                                                      String[] exportMetadata,
String[] importMetadata)
+                                                                      String[] exportMetadata,
String[] importMetadata,String lvsVirtualIP)
             throws ApplicationDefinitionException {
 
         // Create text payload
         PayloadData payloadData = ApplicationUtils.createPayload(appId, groupName, cartridge,
subscriptionKey, tenantId, clusterId,
-                hostname, repoUrl, alias, null, dependencyAliases, properties, oauthToken,
dependencyClustorIDs, exportMetadata, importMetadata);
+                hostname, repoUrl, alias, null, dependencyAliases, properties, oauthToken,
dependencyClustorIDs, exportMetadata, importMetadata,lvsVirtualIP);
 
         String textPayload = payloadData.toString();
         if (log.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java
index 89eed10..ddf70ab 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java
@@ -56,6 +56,7 @@ public class BasicPayloadData implements Serializable {
     private String[] dependencyClusterIDs;
     private String[] exportMetadataKeys;
     private String[] importMetadataKeys;
+	private String lvsVirtualIP;
 
     protected StringBuilder payloadBuilder;
 
@@ -128,6 +129,10 @@ public class BasicPayloadData implements Serializable {
         if (getExportMetadataKeys() != null) {
             payloadBuilder.append("IMPORT_METADATA_KEYS=" + getImportMetadataKeys());
         }
+	    payloadBuilder.append(",");
+	    if(!getLvsVirtualIP().equals("")){
+		    payloadBuilder.append("LVS_VIRTUAL_IP=" +getLvsVirtualIP());
+	    }
     }
 
     public String getServiceName() {
@@ -388,4 +393,12 @@ public class BasicPayloadData implements Serializable {
     public void setImportMetadataKeys(String[] importMetadataKeys) {
         this.importMetadataKeys = importMetadataKeys;
     }
+
+	public String getLvsVirtualIP() {
+		return lvsVirtualIP;
+	}
+
+	public void setLvsVirtualIP(String lvsVirtualIP) {
+		this.lvsVirtualIP = lvsVirtualIP;
+	}
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java
index 50951ca..4ecb4fa 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java
@@ -36,6 +36,8 @@ public class SubscribableInfoContext implements Serializable {
     private ArtifactRepositoryContext artifactRepositoryContext;
     private Properties properties;
     private PersistenceContext persistenceContext;
+	//This is the virtual IP that we need to pass for use LVS as Load Balancer
+	private String lvsVirtualIP;
 
     public String getAlias() {
         return alias;
@@ -108,4 +110,12 @@ public class SubscribableInfoContext implements Serializable {
     public void setPersistenceContext(PersistenceContext persistenceContext) {
         this.persistenceContext = persistenceContext;
     }
+
+	public String getLvsVirtualIP() {
+		return lvsVirtualIP;
+	}
+
+	public void setLvsVirtualIP(String lvsVirtualIP) {
+		this.lvsVirtualIP = lvsVirtualIP;
+	}
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java
b/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java
index 585aace..f3557bf 100644
--- a/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java
+++ b/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java
@@ -176,7 +176,7 @@ public class LoadBalancerExtension {
             @Override
             protected void onEvent(Event event) {
                 try {
-                    if (!loadBalancerStarted) {
+                  if (!loadBalancerStarted) {
                         configureAndStart();
                     }
                 } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/extensions/load-balancer/lvs-extension/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/lvs-extension/src/main/assembly/bin.xml b/extensions/load-balancer/lvs-extension/src/main/assembly/bin.xml
index 0beb98c..5569074 100644
--- a/extensions/load-balancer/lvs-extension/src/main/assembly/bin.xml
+++ b/extensions/load-balancer/lvs-extension/src/main/assembly/bin.xml
@@ -56,7 +56,7 @@
             <outputDirectory>/templates</outputDirectory>
             <fileMode>0600</fileMode>
             <includes>
-                <include>nginx.cfg.template</include>
+                <include>keepalived.conf.template</include>
             </includes>
         </fileSet>
         <fileSet>

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/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 67a9c09..659addd 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
@@ -28,9 +28,9 @@ properties="-Dlvs.private.ip=127.0.0.1
             -Dexecutable.file.path=lvs
             -Djndi.properties.dir=${script_path}/../conf
             -Dtemplates.path=${script_path}/../templates
-            -Dtemplates.name=nginx.cfg.template
+            -Dtemplates.name=keepalived.conf.template
             -Dscripts.path=${script_path}/../scripts
-            -Dconf.file.path=/tmp/nginx.cfg
+            -Dconf.file.path=/tmp/keepalived.conf
             -Dstats.socket.file.path=/tmp/nginx-stats.socket
             -Dlog4j.properties.file.path=${script_path}/../conf/log4j.properties
             -Djavax.net.ssl.trustStore=${script_path}/../security/client-truststore.jks
@@ -41,7 +41,9 @@ properties="-Dlvs.private.ip=127.0.0.1
             -Dthrift.receiver.port=7615
             -Dnetwork.partition.id=network-partition-1
             -Dcluster.id=cluster-1
-            -Dservice.name=service-1"
+            -Dservice.name=service-1
+            -Dlvs.service.virtualip.set=tomcat2|192.168.56.40,tomcat1|192.168.56.41
+            -Dserver.state=MASTER"
 
 
 # Uncomment below line to enable remote debugging

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/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 9a9242c..715798f 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
@@ -36,4 +36,7 @@ public class Constants {
     public static final String NETWORK_PARTITION_ID = "network.partition.id";
     public static final String CLUSTER_ID = "cluster.id";
     public static final String SERVICE_NAME = "service.name";
+	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" ;
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/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 74170f8..3dce7e7 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
@@ -41,6 +41,9 @@ public class LVS implements LoadBalancer {
     private String templateName;
     private String confFilePath;
     private String statsSocketFilePath;
+	private String virtualIPsForServices;
+	private String keepAlivedStartCommand;
+	private String serverState;
 
     public LVS() {
         this.executableFilePath = LVSContext.getInstance().getExecutableFilePath();
@@ -49,6 +52,9 @@ public class LVS implements LoadBalancer {
         this.confFilePath = LVSContext.getInstance().getConfFilePath();
         this.processIdFilePath = confFilePath.replace(".cfg", ".pid");
         this.statsSocketFilePath = LVSContext.getInstance().getStatsSocketFilePath();
+	    this.virtualIPsForServices= LVSContext.getInstance().getVirtualIPsForServices();
+	    this.keepAlivedStartCommand=LVSContext.getInstance().getKeepAlivedStartCommand();
+	    this.serverState=LVSContext.getInstance().getServerState();
     }
 
     /**
@@ -59,7 +65,8 @@ public class LVS implements LoadBalancer {
     public boolean configure(Topology topology) throws LoadBalancerExtensionException {
         try {
             log.info("Generating nginx configuration...");
-            LVSConfigWriter writer = new LVSConfigWriter(templatePath, templateName, confFilePath,
statsSocketFilePath);
+            LVSConfigWriter writer = new LVSConfigWriter(templatePath, templateName, confFilePath,
statsSocketFilePath,
+                                                         virtualIPsForServices,serverState);
             if(writer.write(topology)) {
                 return true;
             }
@@ -75,26 +82,26 @@ public class LVS implements LoadBalancer {
      * @throws LoadBalancerExtensionException
      */
     public void start() throws LoadBalancerExtensionException {
-        log.info("Starting nginx instance...");
+        log.info("Starting lvs instance...");
         // Check for configuration file
         File conf = new File(confFilePath);
         if (!conf.exists()) {
-            throw new LoadBalancerExtensionException("Could not find nginx configuration
file");
+            throw new LoadBalancerExtensionException("Could not find lvs configuration file");
         }
 
         // Start nginx and write pid to processIdFilePath
         try {
-           // String command = executableFilePath + " -c " + confFilePath;
-            //CommandUtils.executeCommand(command);
-            log.info("nginx instance started");
+            String command = keepAlivedStartCommand;
+            CommandUtils.executeCommand(command);
+            log.info("lvs instance started");
         } catch (Exception e) {
-            log.error("Could not start nginx instance");
+            log.error("Could not start lvs instance");
             throw new LoadBalancerExtensionException(e);
         }
     }
 
     /**
-     * Reload nginx instance according to the configuration written in configure() method.
+     * Reload lvs instance according to the configuration written in configure() method.
      * @throws LoadBalancerExtensionException
      */
     public void reload() throws LoadBalancerExtensionException {
@@ -102,7 +109,7 @@ public class LVS implements LoadBalancer {
             log.info("Reloading configuration...");
 
             // Execute hot configuration deployment
-            String command = executableFilePath + " -c " + confFilePath + " -s reload";
+            String command = "service keepalived restart";
             CommandUtils.executeCommand(command);
             if (log.isInfoEnabled()) {
                 log.info("Configuration done");
@@ -122,17 +129,17 @@ public class LVS implements LoadBalancer {
     public void stop() throws LoadBalancerExtensionException {
 
         try {
-            log.info("Stopping nginx...");
+            log.info("Stopping lvs...");
 
             // Execute hot configuration deployment
-            String command = executableFilePath + " -s stop";
-            CommandUtils.executeCommand(command);
+            String command = "service keepalived stop";
+	        CommandUtils.executeCommand(command);
             if (log.isInfoEnabled()) {
                 log.info("LVS stopped");
             }
         } catch (Exception e) {
             if (log.isErrorEnabled()) {
-                log.error("Could not stop nginx");
+                log.error("Could not stop lvs");
             }
             throw new LoadBalancerExtensionException(e);
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/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 6d8346c..4d6d3f3 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
@@ -46,26 +46,31 @@ public class LVSConfigWriter {
     private String templateName;
     private String confFilePath;
     private String statsSocketFilePath;
+	private String virtualIPsForServices;
+	private String serverState;
 
     public LVSConfigWriter(String templatePath, String templateName, String confFilePath,
-                           String statsSocketFilePath) {
+                           String statsSocketFilePath,String virtualIPsForServices,String
serverState) {
 
         this.templatePath = templatePath;
         this.templateName = templateName;
         this.confFilePath = confFilePath;
         this.statsSocketFilePath = statsSocketFilePath;
+	    this.virtualIPsForServices=virtualIPsForServices;
+	    this.serverState=serverState;
     }
 
     public boolean write(Topology topology) {
 
         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);
+                generateConfigurationForCluster(cluster, service.getPorts(), configurationBuilder,virtualIPBuilder,virtualIPsForServices);
             }
         }
 
@@ -80,6 +85,8 @@ public class LVSConfigWriter {
         // 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();
@@ -134,34 +141,55 @@ public class LVSConfigWriter {
      * @param ports
      * @param text
      */
-    private void generateConfigurationForCluster(Cluster cluster, Collection<Port>
ports, StringBuilder text) {
-
-        for (Port port : ports) {
-            for (String hostname : cluster.getHostNames()) {
-
-	            text.append("virtual_server ").append("dummyvirtualip").append(" ").append(port).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.getMemberId()).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("}");
+    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]));
+		    }
+	    }
+
 
-            }
-        }
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/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 ea19213..228c455 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
@@ -43,6 +43,9 @@ public class LVSContext {
     private String networkPartitionId;
     private String clusterId;
     private String serviceName;
+	private String virtualIPsForServices;
+	private String keepAlivedStartCommand;
+	private String serverState;
 
     private LVSContext() {
         this.lvsPrivateIp = System.getProperty(Constants.LVS_PRIVATE_IP);
@@ -58,6 +61,9 @@ public class LVSContext {
         this.networkPartitionId = System.getProperty(Constants.NETWORK_PARTITION_ID);
         this.clusterId = System.getProperty(Constants.CLUSTER_ID);
         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));
 
         if (log.isDebugEnabled()) {
             log.debug(Constants.LVS_PRIVATE_IP + " = " + lvsPrivateIp);
@@ -72,6 +78,7 @@ 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());
         }
     }
 
@@ -154,4 +161,28 @@ public class LVSContext {
     public String getServiceName() {
         return serviceName;
     }
+
+	public String getVirtualIPsForServices() {
+		return virtualIPsForServices;
+	}
+
+	public void setVirtualIPsForServices(String virtualIPsForServices) {
+		this.virtualIPsForServices = virtualIPsForServices;
+	}
+
+	public String getKeepAlivedStartCommand() {
+		return keepAlivedStartCommand;
+	}
+
+	public void setKeepAlivedStartCommand(String keepAlivedStartCommand) {
+		this.keepAlivedStartCommand = keepAlivedStartCommand;
+	}
+
+	public String getServerState() {
+		return serverState;
+	}
+
+	public void setServerState(String serverState) {
+		this.serverState = serverState;
+	}
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/extensions/load-balancer/lvs-extension/src/main/templates/keepalived.conf.template
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/lvs-extension/src/main/templates/keepalived.conf.template
b/extensions/load-balancer/lvs-extension/src/main/templates/keepalived.conf.template
index ecd58ee..9cba1fb 100644
--- a/extensions/load-balancer/lvs-extension/src/main/templates/keepalived.conf.template
+++ b/extensions/load-balancer/lvs-extension/src/main/templates/keepalived.conf.template
@@ -27,36 +27,11 @@ vrrp_instance VirtIP_10 {
         auth_pass MY_PASS
     }
     virtual_ipaddress {
-        10.10.10.10
+$virtualips
     }
 
     lvs_sync_daemon_interface eth0
 }
 
-! ************************   WEB SERVERS  **************************
-
-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
-        }
-    }
-
-    real_server 10.10.10.42 80 {
-        weight 50
-        TCP_CHECK {
-            connect_timeout 3
-        }
-    }
-
-}
-
-
 
+$configuration
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/extensions/load-balancer/lvs-extension/src/main/templates/nginx.cfg.template
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/lvs-extension/src/main/templates/nginx.cfg.template
b/extensions/load-balancer/lvs-extension/src/main/templates/nginx.cfg.template
deleted file mode 100644
index 54f9648..0000000
--- a/extensions/load-balancer/lvs-extension/src/main/templates/nginx.cfg.template
+++ /dev/null
@@ -1,8 +0,0 @@
-events {
-    worker_connections  1024;
-}
-
-$configuration
-
-
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/extensions/load-balancer/pom.xml
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/pom.xml b/extensions/load-balancer/pom.xml
index ff89360..d854321 100644
--- a/extensions/load-balancer/pom.xml
+++ b/extensions/load-balancer/pom.xml
@@ -36,6 +36,7 @@
     <modules>
         <module>haproxy-extension</module>
         <module>nginx-extension</module>
+        <module>lvs-extension</module>
     </modules>
 </project>
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/6f12fafe/tools/puppet3/modules/haproxy/templates/bin/haproxy-extension.sh.erb
----------------------------------------------------------------------
diff --git a/tools/puppet3/modules/haproxy/templates/bin/haproxy-extension.sh.erb b/tools/puppet3/modules/haproxy/templates/bin/haproxy-extension.sh.erb
index 47ea03a..db2db78 100755
--- a/tools/puppet3/modules/haproxy/templates/bin/haproxy-extension.sh.erb
+++ b/tools/puppet3/modules/haproxy/templates/bin/haproxy-extension.sh.erb
@@ -31,7 +31,7 @@ properties="-Dhaproxy.private.ip=0.0.0.0
             -Dtemplates.path=${script_path}/../templates
             -Dtemplates.name=haproxy.cfg.template
             -Dscripts.path=${script_path}/../scripts
-            -Dconf.file.path=/tmp/haproxy.cfg
+            -Dconf.file.path=/etc/keepalived/keepalived.conf
             -Dstats.socket.file.path=/tmp/haproxy-stats.socket
             -Dlog4j.properties.file.path=${script_path}/../conf/log4j.properties
             -Djavax.net.ssl.trustStore=${script_path}/../security/client-truststore.jks


Mime
View raw message