Updated Branches:
  refs/heads/master 395636f1e -> edcee0321

adding a property to keep lb cluster id per service in service aware 
loadbalancing


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

Branch: refs/heads/master
Commit: a2719b4181c1b020d4a76b48dec2373dd67f5baa
Parents: 9e064c8
Author: Isuru <[email protected]>
Authored: Wed Jan 15 12:22:09 2014 +0530
Committer: Isuru <[email protected]>
Committed: Wed Jan 15 12:22:09 2014 +0530

----------------------------------------------------------------------
 .../stratos/autoscaler/util/AutoscalerUtil.java | 22 +++++++++++++++-----
 .../stratos/messaging/util/Constants.java       |  1 +
 .../rest/endpoint/services/ServiceUtils.java    | 11 ++++++++++
 3 files changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a2719b41/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
index e030156..50877dd 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
@@ -22,7 +22,9 @@ package org.apache.stratos.autoscaler.util;
 import org.apache.axiom.om.OMElement;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.*;
+import org.apache.stratos.autoscaler.MemberStatsContext;
+import org.apache.stratos.autoscaler.NetworkPartitionContext;
+import org.apache.stratos.autoscaler.PartitionContext;
 import 
org.apache.stratos.autoscaler.client.cloud.controller.CloudControllerClient;
 import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
 import org.apache.stratos.autoscaler.exception.PartitionValidationException;
@@ -43,10 +45,7 @@ import 
org.apache.stratos.messaging.domain.topology.MemberStatus;
 import org.apache.stratos.messaging.util.Constants;
 
 import javax.xml.namespace.QName;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Random;
+import java.util.*;
 
 /**
  * This class contains utility methods used by Autoscaler.
@@ -258,21 +257,34 @@ public class AutoscalerUtil {
             
             // populate lb cluster id in network partition context.
             java.util.Properties props = cluster.getProperties();
+
+            // get service type of load balanced cluster
+            String loadBalancedServiceType = 
props.getProperty(Constants.LOAD_BALANCED_SERVICE_TYPE);
             
             if(props.containsKey(Constants.LOAD_BALANCER_REF)) {
                 String value = props.getProperty(Constants.LOAD_BALANCER_REF);
                 
                 if 
(value.equals(org.apache.stratos.messaging.util.Constants.DEFAULT_LOAD_BALANCER))
 {
                     networkPartitionContext.setDefaultLbClusterId(clusterId);
+
                 } else if 
(value.equals(org.apache.stratos.messaging.util.Constants.SERVICE_AWARE_LOAD_BALANCER))
 {
                     String serviceName = cluster.getServiceName();
+                    // TODO: check if this is correct
                     networkPartitionContext.addServiceLB(serviceName, 
clusterId);
+
+                    if (loadBalancedServiceType != null && 
!loadBalancedServiceType.isEmpty()) {
+                        
networkPartitionContext.addServiceLB(loadBalancedServiceType, clusterId);
+                        if (log.isDebugEnabled()) {
+                            log.debug("Added cluster id " + clusterId + " as 
the LB cluster id for service type " + loadBalancedServiceType);
+                        }
+                    }
                 }
             }
 
             clusterMonitor.addNetworkPartitionCtxt(networkPartitionContext);
         }
 
+        log.info("LB Cluster monitor created: "+clusterMonitor.toString());
         return clusterMonitor;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a2719b41/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Constants.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Constants.java
 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Constants.java
index 346101e..f087d0b 100644
--- 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Constants.java
+++ 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Constants.java
@@ -50,4 +50,5 @@ public class Constants {
     public static final String DEFAULT_LOAD_BALANCER = "default.load.balancer";
     public static final String NO_LOAD_BALANCER = "no.load.balancer";
     public static final String EXISTING_LOAD_BALANCERS = 
"existing.load.balancers";
+    public static final String LOAD_BALANCED_SERVICE_TYPE = 
"load.balanced.service.type";
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a2719b41/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
index c82ddf1..513bf2b 100644
--- 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
+++ 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
@@ -766,7 +766,14 @@ public class ServiceUtils {
 
                 } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) 
{
                     if ("true".equals(value)) {
+
+                        // add a property for the service type
+                        Property loadBalancedServiceTypeProperty = new 
Property();
+                        
loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
+
                         property.setValue(name);
+                        // set the load balanced service type
+                        
loadBalancedServiceTypeProperty.setValue(cartridgeType);
                         if (log.isDebugEnabled()) {
                             log.debug("This cartridge uses a service aware 
load balancer. " +
                                     "[Type] " + cartridgeType);
@@ -789,7 +796,11 @@ public class ServiceUtils {
                                             String lbAlias =
                                                     "lb" + cartridgeType +
                                                             new 
Random().nextInt();
+
+
                                             
lbCartridgeInfo.addProperties(property);
+                                            
lbCartridgeInfo.addProperties(loadBalancedServiceTypeProperty);
+
                                             subscribeToLb(lbCartridgeType,
                                                     lbAlias,
                                                     
lbCartridgeInfo.getDefaultAutoscalingPolicy(),

Reply via email to