Updated Branches:
  refs/heads/master b86ab5393 -> 926dae62f

refactoring ClusterCreatedEvent as it wraps Cluster object and implement 
toString method of Cluster


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

Branch: refs/heads/master
Commit: b061f78728cb04ea33e209866e4e087b154c3dc9
Parents: b86ab53
Author: Nirmal Fernando <[email protected]>
Authored: Sun Dec 15 00:31:47 2013 +0530
Committer: Nirmal Fernando <[email protected]>
Committed: Sun Dec 15 00:31:47 2013 +0530

----------------------------------------------------------------------
 .../messaging/domain/topology/Cluster.java      |  9 +++
 .../event/topology/ClusterCreatedEvent.java     | 68 ++++++--------------
 .../ClusterCreatedMessageProcessor.java         | 19 +++---
 3 files changed, 39 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b061f787/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
index 6b94e34..4816715 100644
--- 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
+++ 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
@@ -48,6 +48,7 @@ public class Cluster implements Serializable {
     // Key: Member.memberId
     @XmlJavaTypeAdapter(MapAdapter.class)
     private Map<String, Member> memberMap;
+
     private String loadBalanceAlgorithmName;
     @XmlJavaTypeAdapter(MapAdapter.class)
     private Properties properties;
@@ -137,6 +138,14 @@ public class Cluster implements Serializable {
     public void setLbCluster(boolean isLbCluster) {
         this.isLbCluster = isLbCluster;
     }
+    
+    @Override
+    public String toString() {
+        return "Cluster [serviceName=" + serviceName + ", clusterId=" + 
clusterId +
+                ", autoscalePolicyName=" + autoscalePolicyName + ", 
deploymentPolicyName=" +
+                deploymentPolicyName + ", hostNames=" + hostNames + ", 
tenantRange=" + tenantRange +
+                ", isLbCluster=" + isLbCluster + ", properties=" + properties 
+ "]";
+    }
 
     /**
      * Check whether a given tenant id is in tenant range of the cluster.

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b061f787/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterCreatedEvent.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterCreatedEvent.java
 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterCreatedEvent.java
index 4ed54cf..5d51ab8 100644
--- 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterCreatedEvent.java
+++ 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterCreatedEvent.java
@@ -19,10 +19,8 @@
 
 package org.apache.stratos.messaging.event.topology;
 
-import org.apache.stratos.messaging.util.Util;
-
+import org.apache.stratos.messaging.domain.topology.Cluster;
 import java.io.Serializable;
-import java.util.Properties;
 
 /**
  * This event is fired by Cloud Controller when a cluster is created for a 
service.
@@ -31,62 +29,34 @@ public class ClusterCreatedEvent extends TopologyEvent 
implements Serializable {
     private static final long serialVersionUID = 2080623816272047762L;
 
        private final String serviceName;
-    private final String clusterId;
-    private final String hostName;
-    private String tenantRange;
-    private String autoscalingPolicyName;
-    private String deploymentPolicyName;
-    private Properties properties;
+       private final String clusterId;
+    private Cluster cluster;
+
 
-    public ClusterCreatedEvent(String serviceName, String clusterId, String 
hostName) {
+    public ClusterCreatedEvent(String serviceName, String clusterId, Cluster 
cluster) {
         this.serviceName = serviceName;
         this.clusterId = clusterId;
-        this.hostName = hostName;
+        this.cluster = cluster;
     }
 
+    public Cluster getCluster() {
+        return cluster;
+    }
+    
+    public void setCluster(Cluster cluster) {
+        this.cluster = cluster;
+    }
+    
     public String getServiceName() {
         return serviceName;
     }
+    
+    @Override
+    public String toString() {
+        return "ClusterCreatedEvent [serviceName=" + serviceName + ", 
cluster=" + cluster + "]";
+    }
 
     public String getClusterId() {
         return clusterId;
     }
-
-    public String getHostName() {
-        return hostName;
-    }
-
-    public String getTenantRange() {
-        return tenantRange;
-    }
-
-    public void setTenantRange(String tenantRange) {
-        Util.validateTenantRange(tenantRange);
-        this.tenantRange = tenantRange;
-    }
-
-
-    public Properties getProperties() {
-        return properties;
-    }
-
-    public void setProperties(Properties properties) {
-        this.properties = properties;
-    }
-
-    public String getAutoscalingPolicyName() {
-        return autoscalingPolicyName;
-    }
-
-    public void setAutoscalingPolicyName(String autoscalingPolicyName) {
-        this.autoscalingPolicyName = autoscalingPolicyName;
-    }
-
-    public String getDeploymentPolicyName() {
-        return deploymentPolicyName;
-    }
-
-    public void setDeploymentPolicyName(String deploymentPolicyName) {
-        this.deploymentPolicyName = deploymentPolicyName;
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b061f787/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedMessageProcessor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedMessageProcessor.java
 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedMessageProcessor.java
index 19ad02e..89b51d4 100644
--- 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedMessageProcessor.java
+++ 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedMessageProcessor.java
@@ -73,10 +73,18 @@ public class ClusterCreatedMessageProcessor extends 
MessageProcessor {
                     return false;
                 }
             }
+            
+            Cluster cluster = event.getCluster();
+            
+            if(cluster == null) {
+                String msg = "Cluster object of Cluster Created Event is 
null.";
+                log.error(msg);
+                throw new RuntimeException(msg);
+            }
 
             // Validate event properties
-            if (StringUtils.isBlank(event.getHostName())) {
-                throw new RuntimeException("Hostname not found in cluster 
created event");
+            if (cluster.getHostNames().isEmpty()) {
+                throw new RuntimeException("Host name/s not found in cluster 
created event");
             }
             // Validate event against the existing topology
             Service service = topology.getService(event.getServiceName());
@@ -96,14 +104,9 @@ public class ClusterCreatedMessageProcessor extends 
MessageProcessor {
             }
 
             // Apply changes to the topology
-            Cluster cluster = new Cluster(event.getServiceName(), 
event.getClusterId(), event.getDeploymentPolicyName(), 
event.getAutoscalingPolicyName());
-            cluster.addHostName(event.getHostName());
-            cluster.setTenantRange(event.getTenantRange());
-
             service.addCluster(cluster);
             if (log.isInfoEnabled()) {
-                log.info(String.format("Cluster created: [service] %s 
[cluster] %s [hostname] %s",
-                        event.getServiceName(), event.getClusterId(), 
event.getHostName()));
+                log.info("Cluster created: "+cluster.toString());
             }
 
             // Notify event listeners

Reply via email to