You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2013/11/27 19:55:08 UTC

[11/26] CC refactoring, API cleaning r1

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java
index 6ad5841..1412e32 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java
@@ -18,6 +18,8 @@
  */
 package org.apache.stratos.cloud.controller.runtime;
 
+import org.apache.stratos.cloud.controller.pojo.ClusterContext;
+import org.apache.stratos.cloud.controller.pojo.MemberContext;
 import org.apache.stratos.cloud.controller.registry.RegistryManager;
 import org.apache.stratos.cloud.controller.util.*;
 import org.apache.stratos.messaging.broker.publish.EventPublisher;
@@ -37,10 +39,32 @@ public class FasterLookUpDataHolder implements Serializable{
 	private static volatile FasterLookUpDataHolder ctxt;
 
 	/* We keep following maps in order to make the look up time, small. */
+	
+	/**
+     * Key - cluster id
+     * Value - list of {@link MemberContext}
+     */
+    private Map<String, List<MemberContext>> clusterIdToMemberContext = new HashMap<String, List<MemberContext>>();
+    
+	/**
+	 * Key - member id
+	 * Value - {@link MemberContext}
+	 */
+	private Map<String, MemberContext> memberIdToContext = new HashMap<String, MemberContext>();
+	
+	/**
+	 * Key - cluster id
+	 * Value - {@link ClusterContext}
+	 */
+	private Map<String, ClusterContext> clusterIdToContext = new HashMap<String, ClusterContext>();
+	
+	/**
+	 * Key - member id
+	 * Value - node id
+	 */
+	private Map<String, String> memberIdToNodeId;
 
 	/**
-	 * Map of maps.
-	 * Map 1:
 	 * Key - domain
 	 * value - {@link ServiceContext}
 	 */
@@ -74,14 +98,10 @@ public class FasterLookUpDataHolder implements Serializable{
 
 	private String serializationDir;
 	private boolean enableBAMDataPublisher;
+	private DataPublisherConfig dataPubConfig;
 	private boolean enableTopologySync;
 	private TopologyConfig topologyConfig;
-	private String bamUsername = CloudControllerConstants.DEFAULT_BAM_SERVER_USER_NAME;
-	private String bamPassword = CloudControllerConstants.DEFAULT_BAM_SERVER_PASSWORD;
-	private String dataPublisherCron = CloudControllerConstants.PUB_CRON_EXPRESSION;
-	private String cassandraConnUrl = CloudControllerConstants.DEFAULT_CASSANDRA_URL;
-	private String cassandraUser = CloudControllerConstants.DEFAULT_CASSANDRA_USER;
-	private String cassandraPassword = CloudControllerConstants.DEFAULT_CASSANDRA_PASSWORD;
+	
 	/**
 	 * Key - node id 
 	 * Value - Status of the instance
@@ -141,6 +161,7 @@ public class FasterLookUpDataHolder implements Serializable{
 		serviceCtxts = new ConcurrentHashMap<String,ServiceContext>();
 		nodeIdToServiceCtxt = new LinkedHashMap<String, ServiceContext>();
 		cartridges = new ArrayList<Cartridge>();
+		setMemberIdToNodeId(new ConcurrentHashMap<String, String>());
 
 	}
 
@@ -276,6 +297,19 @@ public class FasterLookUpDataHolder implements Serializable{
 		}
 
 	}
+	
+	public IaasProvider getIaasProvider(String type) {
+	    if(type == null) {
+	        return null;
+	    }
+	    
+	    for (IaasProvider iaasProvider : iaasProviders) {
+            if(type.equals(iaasProvider.getType())) {
+                return iaasProvider;
+            }
+        }
+	    return null;
+	}
 
 	public List<IaasProvider> getIaasProviders() {
 		return iaasProviders;
@@ -293,29 +327,7 @@ public class FasterLookUpDataHolder implements Serializable{
 		this.serializationDir = serializationDir;
 	}
 
-	public String getBamUsername() {
-		return bamUsername;
-	}
-
-	public void setBamUsername(String bamUsername) {
-		this.bamUsername = bamUsername;
-	}
-
-	public String getBamPassword() {
-		return bamPassword;
-	}
-
-	public void setBamPassword(String bamPassword) {
-		this.bamPassword = bamPassword;
-	}
-
-	public String getDataPublisherCron() {
-		return dataPublisherCron;
-	}
-
-	public void setDataPublisherCron(String dataPublisherCron) {
-		this.dataPublisherCron = dataPublisherCron;
-	}
+	
 
 	public Map<String, String> getNodeIdToStatusMap() {
 		return nodeIdToStatusMap;
@@ -349,29 +361,7 @@ public class FasterLookUpDataHolder implements Serializable{
 		this.enableBAMDataPublisher = enableBAMDataPublisher;
 	}
 
-	public String getCassandraConnUrl() {
-		return cassandraConnUrl;
-	}
-
-	public void setCassandraConnUrl(String cassandraHostAddr) {
-		this.cassandraConnUrl = cassandraHostAddr;
-	}
-
-	public String getCassandraUser() {
-		return cassandraUser;
-	}
-
-	public void setCassandraUser(String cassandraUser) {
-		this.cassandraUser = cassandraUser;
-	}
-
-	public String getCassandraPassword() {
-		return cassandraPassword;
-	}
-
-	public void setCassandraPassword(String cassandraPassword) {
-		this.cassandraPassword = cassandraPassword;
-	}
+	
 
 	public boolean isPublisherRunning() {
 		return isPublisherRunning;
@@ -416,4 +406,86 @@ public class FasterLookUpDataHolder implements Serializable{
     public void addEventPublisher(EventPublisher publisher, String topicName) {
         topicToPublisherMap.put(topicName, publisher);
     }
-}
+
+    public DataPublisherConfig getDataPubConfig() {
+        return dataPubConfig;
+    }
+
+    public void setDataPubConfig(DataPublisherConfig dataPubConfig) {
+        this.dataPubConfig = dataPubConfig;
+    }
+    
+    public void addMemberContext(MemberContext ctxt) {
+        memberIdToContext.put(ctxt.getMemberId(), ctxt);
+        
+        List<MemberContext> ctxts;
+        
+        if((ctxts = clusterIdToMemberContext.get(ctxt)) == null) {
+            ctxts = new ArrayList<MemberContext>();
+        } 
+        ctxts.add(ctxt);
+        clusterIdToMemberContext.put(ctxt.getClusterId(), ctxts);
+    }
+    
+    public void removeMemberContext(String clusterId) {
+        List<MemberContext> ctxts = clusterIdToMemberContext.remove(clusterId);
+        
+        for (MemberContext memberContext : ctxts) {
+            String memberId = memberContext.getMemberId();
+            memberIdToContext.remove(memberId);
+        }
+    }
+    
+    public MemberContext getMemberContextOfMemberId(String memberId) {
+        return memberIdToContext.get(memberId);
+    }
+    
+    public List<MemberContext> getMemberContextsOfClusterId(String clusterId) {
+        return clusterIdToMemberContext.get(clusterId);
+    }
+
+    public void addNodeId(String memberId, String nodeId) {
+        memberIdToNodeId.put(memberId, nodeId);
+    }
+    
+    public String getNodeId(String memberId) {
+        return memberIdToNodeId.get(memberId);
+    }
+    
+    public Map<String, String> getMemberIdToNodeId() {
+        return memberIdToNodeId;
+    }
+
+    public void setMemberIdToNodeId(Map<String, String> memberIdToNodeId) {
+        this.memberIdToNodeId = memberIdToNodeId;
+    }
+
+    public Map<String, MemberContext> getMemberIdToContext() {
+        return memberIdToContext;
+    }
+
+    public void setMemberIdToContext(Map<String, MemberContext> memberIdToContext) {
+        this.memberIdToContext = memberIdToContext;
+    }
+
+    public void addClusterContext(ClusterContext ctxt) {
+        clusterIdToContext.put(ctxt.getClusterId(), ctxt);
+    }
+    
+    public ClusterContext getClusterContext(String clusterId) {
+        return clusterIdToContext.get(clusterId);
+    }
+    
+    public ClusterContext removeClusterContext(String clusterId) {
+        return clusterIdToContext.remove(clusterId);
+    }
+    
+    public Map<String, ClusterContext> getClusterIdToContext() {
+        return clusterIdToContext;
+    }
+
+    public void setClusterIdToContext(Map<String, ClusterContext> clusterIdToContext) {
+        this.clusterIdToContext = clusterIdToContext;
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
index bf50c42..69c0171 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
@@ -20,15 +20,20 @@ package org.apache.stratos.cloud.controller.topology;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.pojo.ClusterContext;
+import org.apache.stratos.cloud.controller.pojo.Registrant;
 import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
 import org.apache.stratos.cloud.controller.util.Cartridge;
+import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
 import org.apache.stratos.cloud.controller.util.PortMapping;
 import org.apache.stratos.cloud.controller.util.ServiceContext;
+import org.apache.stratos.messaging.domain.policy.Partition;
 import org.apache.stratos.messaging.domain.topology.*;
 import org.apache.stratos.messaging.event.instance.status.MemberActivatedEvent;
 import org.apache.stratos.messaging.event.instance.status.MemberStartedEvent;
 
 import java.util.List;
+import java.util.Properties;
 
 /**
  * this is to manipulate the received events by cloud controller
@@ -87,39 +92,39 @@ public class TopologyBuilder {
 
     }
 
-    public static void handlePartitionUpdated(Partition newPartition, Partition oldPartition) {
-
-        Topology topology = TopologyManager.getInstance().getTopology();
-        if (newPartition == null || oldPartition == null) {
-            throw new RuntimeException(String.format("Partition is empty"));
-        }
-        try {
-            TopologyManager.getInstance().acquireWriteLock();
-            topology.removePartition(oldPartition);
-            topology.addPartition(newPartition);
-            TopologyManager.getInstance().updateTopology(topology);
-        } finally {
-            TopologyManager.getInstance().releaseWriteLock();
-        }
-        TopologyEventSender.sendPartitionUpdatedEvent(newPartition, oldPartition.getId());
-
-    }
-
-    public static void handlePartitionRemoved(Partition partition) {
-
-        Topology topology = TopologyManager.getInstance().getTopology();
-        if (partition == null) {
-            throw new RuntimeException(String.format("Partition is empty"));
-        }
-        try {
-            TopologyManager.getInstance().acquireWriteLock();
-            topology.removePartition(partition);
-            TopologyManager.getInstance().updateTopology(topology);
-        } finally {
-            TopologyManager.getInstance().releaseWriteLock();
-        }
-        TopologyEventSender.sendPartitionRemovedEvent(partition);
-    }
+//    public static void handlePartitionUpdated(Partition newPartition, Partition oldPartition) {
+//
+//        Topology topology = TopologyManager.getInstance().getTopology();
+//        if (newPartition == null || oldPartition == null) {
+//            throw new RuntimeException(String.format("Partition is empty"));
+//        }
+//        try {
+//            TopologyManager.getInstance().acquireWriteLock();
+//            topology.removePartition(oldPartition);
+//            topology.addPartition(newPartition);
+//            TopologyManager.getInstance().updateTopology(topology);
+//        } finally {
+//            TopologyManager.getInstance().releaseWriteLock();
+//        }
+//        TopologyEventSender.sendPartitionUpdatedEvent(newPartition, oldPartition.getId());
+//
+//    }
+//
+//    public static void handlePartitionRemoved(Partition partition) {
+//
+//        Topology topology = TopologyManager.getInstance().getTopology();
+//        if (partition == null) {
+//            throw new RuntimeException(String.format("Partition is empty"));
+//        }
+//        try {
+//            TopologyManager.getInstance().acquireWriteLock();
+//            topology.removePartition(partition);
+//            TopologyManager.getInstance().updateTopology(topology);
+//        } finally {
+//            TopologyManager.getInstance().releaseWriteLock();
+//        }
+//        TopologyEventSender.sendPartitionRemovedEvent(partition);
+//    }
 
 
     public static void handleServiceRemoved(List<Cartridge> cartridgeList) {
@@ -146,71 +151,77 @@ public class TopologyBuilder {
         }
     }
 
-    public static void handleClusterCreated(ServiceContext serviceContext) {
+    public static void handleClusterCreated(Registrant registrant) {
         Topology topology = TopologyManager.getInstance().getTopology();
         Service service;
         try {
             TopologyManager.getInstance().acquireWriteLock();
-            service = topology.getService(serviceContext.getCartridgeType());
-            if (service == null) {
-                service = new Service(serviceContext.getClusterId());
-                Cluster cluster = new Cluster(serviceContext.getCartridgeType(),
-                        serviceContext.getClusterId(),
-                        serviceContext.getAutoScalerPolicyName());
-                cluster.setHostName(serviceContext.getHostName());
-                cluster.setTenantRange(serviceContext.getTenantRange());
-                cluster.setAutoscalePolicyName(serviceContext.getAutoScalerPolicyName());
-                service.addCluster(cluster);
-                topology.addService(service);
-            } else {
-                if (service.clusterExists(serviceContext.getClusterId())) {
+            service = topology.getService(registrant.getCartridgeType());
+//            if (service == null) {
+//                service = new Service(registrant.getClusterId());
+//                Cluster cluster = new Cluster(registrant.getCartridgeType(),
+//                                              registrant.getClusterId(),
+//                                              registrant.getAutoScalerPolicyName());
+//                cluster.setHostName(registrant.getHostName());
+//                cluster.setTenantRange(registrant.getTenantRange());
+//                cluster.setAutoscalePolicyName(registrant.getAutoScalerPolicyName());
+//                service.addCluster(cluster);
+//                topology.addService(service);
+//            } else {
+            Properties props = CloudControllerUtil.toJavaUtilProperties(registrant.getProperties());
+            
+            Cluster cluster;
+                if (service.clusterExists(registrant.getClusterId())) {
                     //update the cluster
-                    service.getCluster(serviceContext.getClusterId()).
-                            setHostName(serviceContext.getHostName());
-                    service.getCluster(serviceContext.getClusterId()).
-                            setAutoscalePolicyName(serviceContext.getAutoScalerPolicyName());
-                    service.getCluster(serviceContext.getClusterId()).
-                            setTenantRange(serviceContext.getTenantRange());
+                    cluster = service.getCluster(registrant.getClusterId());
+                    cluster.
+                            setHostName(registrant.getHostName());
+                    cluster.
+                            setAutoscalePolicyName(registrant.getAutoScalerPolicyName());
+                    cluster.
+                            setTenantRange(registrant.getTenantRange());
+                    cluster.setProperties(props);
                 } else {
-                    Cluster cluster = new Cluster(serviceContext.getCartridgeType(),
-                            serviceContext.getClusterId(),
-                            serviceContext.getAutoScalerPolicyName());
-                    cluster.setHostName(serviceContext.getHostName());
-                    cluster.setTenantRange(serviceContext.getTenantRange());
-                    cluster.setAutoscalePolicyName(serviceContext.getAutoScalerPolicyName());
+                    cluster = new Cluster(registrant.getCartridgeType(),
+                            registrant.getClusterId(),
+                            registrant.getAutoScalerPolicyName());
+                    cluster.setHostName(registrant.getHostName());
+                    cluster.setTenantRange(registrant.getTenantRange());
+                    cluster.setAutoscalePolicyName(registrant.getAutoScalerPolicyName());
+                    cluster.setProperties(props);
                     service.addCluster(cluster);
                 }
-            }
+//            }
             TopologyManager.getInstance().updateTopology(topology);
-            TopologyEventSender.sendClusterCreatedEvent(serviceContext);
+            TopologyEventSender.sendClusterCreatedEvent(registrant);
 
         } finally {
             TopologyManager.getInstance().releaseWriteLock();
         }
     }
 
-    public static void handleClusterRemoved(ServiceContext serviceContext) {
+    public static void handleClusterRemoved(ClusterContext ctxt) {
         Topology topology = TopologyManager.getInstance().getTopology();
-        Service service = topology.getService(serviceContext.getCartridgeType());
+        Service service = topology.getService(ctxt.getCartridgeType());
         if (service == null) {
             throw new RuntimeException(String.format("Service %s does not exist",
-                    serviceContext.getCartridgeType()));
+                    ctxt.getCartridgeType()));
         }
 
-        if (!service.clusterExists(serviceContext.getClusterId())) {
+        if (!service.clusterExists(ctxt.getClusterId())) {
             throw new RuntimeException(String.format("Cluster %s does not exist for service %s",
-                    serviceContext.getClusterId(),
-                    serviceContext.getCartridgeType()));
+                    ctxt.getClusterId(),
+                    ctxt.getCartridgeType()));
         }
 
         try {
             TopologyManager.getInstance().acquireWriteLock();
-            service.removeCluster(serviceContext.getClusterId());
+            service.removeCluster(ctxt.getClusterId());
             TopologyManager.getInstance().updateTopology(topology);
         } finally {
             TopologyManager.getInstance().releaseWriteLock();
         }
-        TopologyEventSender.sendClusterRemovedEvent(serviceContext);
+        TopologyEventSender.sendClusterRemovedEvent(ctxt);
     }
 
     public static void handleMemberSpawned(String memberId, String serviceName, String clusterId,

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventSender.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventSender.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventSender.java
index c4fd954..f1329cd 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventSender.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventSender.java
@@ -19,18 +19,22 @@ package org.apache.stratos.cloud.controller.topology;
  */
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.pojo.ClusterContext;
+import org.apache.stratos.cloud.controller.pojo.Registrant;
 import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
 import org.apache.stratos.cloud.controller.util.Cartridge;
+import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
 import org.apache.stratos.cloud.controller.util.PortMapping;
 import org.apache.stratos.cloud.controller.util.ServiceContext;
 import org.apache.stratos.messaging.broker.publish.EventPublisher;
-import org.apache.stratos.messaging.domain.topology.Partition;
+import org.apache.stratos.messaging.domain.policy.Partition;
 import org.apache.stratos.messaging.domain.topology.Port;
 import org.apache.stratos.messaging.domain.topology.Topology;
 import org.apache.stratos.messaging.event.Event;
 import org.apache.stratos.messaging.event.topology.*;
 
 import java.util.List;
+import java.util.Properties;
 
 /**
  * this is to send the relevant events from cloud controller to topology topic
@@ -63,9 +67,7 @@ public class TopologyEventSender {
 
      public static void sendPartitionCreatedEvent(Partition partition) {
          PartitionCreatedEvent partitionCreatedEvent =
-                 new PartitionCreatedEvent(partition.getId(),
-                                           partition.getScope());
-         partitionCreatedEvent.setProperties(partition.getProperties());
+                 new PartitionCreatedEvent(partition);
 
          if(log.isInfoEnabled()) {
              log.info(String.format("Publishing partition created event: [partition] %s", partition.getId()));
@@ -73,27 +75,27 @@ public class TopologyEventSender {
          publishEvent(partitionCreatedEvent);
      }
 
-    public static void sendPartitionUpdatedEvent(Partition partition, String oldPartitionId) {
-        PartitionUpdatedEvent partitionUpdatedEvent =
-                new PartitionUpdatedEvent(partition.getId(),
-                                          partition.getScope(),
-                                          oldPartitionId);
-        partitionUpdatedEvent.setProperties(partition.getProperties());
-
-        if(log.isInfoEnabled()) {
-            log.info(String.format("Publishing partition updated event: [partition] %s", partition.getId()));
-        }
-        publishEvent(partitionUpdatedEvent);
-    }
-
-    public static void sendPartitionRemovedEvent(Partition partition) {
-        PartitionRemovedEvent partitionRemovedEvent = new PartitionRemovedEvent(partition.getId());
-
-        if(log.isInfoEnabled()) {
-            log.info(String.format("Publishing partition removed event: [partition] %s", partition.getId()));
-        }
-        publishEvent(partitionRemovedEvent);
-    }
+//    public static void sendPartitionUpdatedEvent(Partition partition, String oldPartitionId) {
+//        PartitionUpdatedEvent partitionUpdatedEvent =
+//                new PartitionUpdatedEvent(partition.getId(),
+//                                          partition.getScope(),
+//                                          oldPartitionId);
+//        partitionUpdatedEvent.setProperties(partition.getProperties());
+//
+//        if(log.isInfoEnabled()) {
+//            log.info(String.format("Publishing partition updated event: [partition] %s", partition.getId()));
+//        }
+//        publishEvent(partitionUpdatedEvent);
+//    }
+//
+//    public static void sendPartitionRemovedEvent(Partition partition) {
+//        PartitionRemovedEvent partitionRemovedEvent = new PartitionRemovedEvent(partition.getId());
+//
+//        if(log.isInfoEnabled()) {
+//            log.info(String.format("Publishing partition removed event: [partition] %s", partition.getId()));
+//        }
+//        publishEvent(partitionRemovedEvent);
+//    }
 
     public static void sendServiceRemovedEvent(List<Cartridge> cartridgeList) {
         ServiceRemovedEvent serviceRemovedEvent;
@@ -107,28 +109,32 @@ public class TopologyEventSender {
         }
     }
 
-    public static void sendClusterCreatedEvent(ServiceContext serviceContext) {
-        ClusterCreatedEvent clusterCreatedEvent = new ClusterCreatedEvent(serviceContext.getCartridgeType(),
-                                                                          serviceContext.getClusterId());
-        clusterCreatedEvent.setHostName(serviceContext.getHostName());
-        clusterCreatedEvent.setTenantRange(serviceContext.getTenantRange());
-        clusterCreatedEvent.setAutoscalingPolicyName(serviceContext.getAutoScalerPolicyName());
+    public static void sendClusterCreatedEvent(Registrant registrant) {
+        Properties props = CloudControllerUtil.toJavaUtilProperties(registrant.getProperties());
+        ClusterCreatedEvent clusterCreatedEvent = new ClusterCreatedEvent(registrant.getCartridgeType(),
+                                                                          registrant.getClusterId());
+        clusterCreatedEvent.setHostName(registrant.getHostName());
+        clusterCreatedEvent.setTenantRange(registrant.getTenantRange());
+        clusterCreatedEvent.setAutoscalingPolicyName(registrant.getAutoScalerPolicyName());
+        clusterCreatedEvent.setProperties(props);
 
         if(log.isInfoEnabled()) {
-            log.info(String.format("Publishing cluster created event: [service] %s [cluster] %s [host] %s [tenant-range] %s [autoscaling-policy] %s",
-                    serviceContext.getCartridgeType(), serviceContext.getClusterId(), serviceContext.getHostName(), serviceContext.getTenantRange(), serviceContext.getAutoScalerPolicyName()));
+            log.info(String.format("Publishing cluster created event: " +
+                    "[service] %s [cluster] %s [host] %s [tenant-range] %s [autoscaling-policy] %s",
+                                   registrant.getCartridgeType(), registrant.getClusterId(), 
+                                   registrant.getHostName(), registrant.getTenantRange(), registrant.getAutoScalerPolicyName()));
         }
         publishEvent(clusterCreatedEvent);
 
     }
 
-    public static void sendClusterRemovedEvent(ServiceContext serviceContext) {
+    public static void sendClusterRemovedEvent(ClusterContext ctxt) {
         ClusterRemovedEvent clusterRemovedEvent = new ClusterRemovedEvent();
-        clusterRemovedEvent.setClusterId(serviceContext.getClusterId());
-        clusterRemovedEvent.setServiceName(serviceContext.getCartridgeType());
+        clusterRemovedEvent.setClusterId(ctxt.getClusterId());
+        clusterRemovedEvent.setServiceName(ctxt.getCartridgeType());
 
         if(log.isInfoEnabled()) {
-            log.info(String.format("Publishing cluster removed event: [service] %s [cluster] %s", serviceContext.getCartridgeType(), serviceContext.getClusterId()));
+            log.info(String.format("Publishing cluster removed event: [service] %s [cluster] %s", ctxt.getCartridgeType(), ctxt.getClusterId()));
         }
         publishEvent(clusterRemovedEvent);
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Cartridge.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Cartridge.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Cartridge.java
index ca31886..fe864b9 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Cartridge.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Cartridge.java
@@ -21,8 +21,10 @@ package org.apache.stratos.cloud.controller.util;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.commons.lang.builder.HashCodeBuilder;
 
@@ -67,6 +69,12 @@ public class Cartridge implements Serializable{
     
     private IaasProvider lastlyUsedIaas;
     
+    /**
+     * Key - partition id
+     * Value - Corresponding IaasProvider.
+     */
+    private Map<String, IaasProvider> partitionToIaasProvider = new ConcurrentHashMap<String, IaasProvider>();
+    
     public Cartridge(){}
     
     public Cartridge(String type, String host, String provider, String version, boolean multiTenant) {
@@ -84,6 +92,23 @@ public class Cartridge implements Serializable{
     public void setType(String type) {
         this.type = type;
     }
+    
+    public void addIaasProvider(String partitionId, IaasProvider iaasProvider) {
+        partitionToIaasProvider.put(partitionId, iaasProvider);
+    }
+    
+    public void addIaasProviders(Map<String, IaasProvider> map) {
+        for (Iterator<String> iterator = map.keySet().iterator(); iterator.hasNext();) {
+            String key = (String) iterator.next();
+            IaasProvider value = map.get(key);
+            
+            partitionToIaasProvider.put(key, value);
+        }
+    }
+    
+    public IaasProvider getIaasProviderOfPartition(String partitionId) {
+        return partitionToIaasProvider.get(partitionId);
+    }
 
     public Map<String, String> getProperties() {
         return properties;
@@ -251,5 +276,13 @@ public class Cartridge implements Serializable{
 	public void setAppTypeMappings(List<AppType> appTypeMappings) {
     	this.appTypeMappings = appTypeMappings;
     }
+
+    public Map<String, IaasProvider> getPartitionToIaasProvider() {
+        return partitionToIaasProvider;
+    }
+
+    public void setPartitionToIaasProvider(Map<String, IaasProvider> partitionToIaasProvider) {
+        this.partitionToIaasProvider = partitionToIaasProvider;
+    }
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInfo.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInfo.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInfo.java
index 522e3ed..a9bc054 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInfo.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInfo.java
@@ -21,6 +21,8 @@ package org.apache.stratos.cloud.controller.util;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.stratos.messaging.util.Property;
+
 /**
  * Holds useful information for externals, regarding a Cartridge.
  */

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
index bc91670..ee135de 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
@@ -237,6 +237,14 @@ public final class CloudControllerConstants {
 	public static final String CLOUD_CONTROLLER_RESOURCE = "/cloud.controller";
 	public static final String DATA_RESOURCE = "/data";
     public static final String TOPOLOGY_RESOURCE = "/topology";
+    public static final String AVAILABILITY_ZONE = "availabilityZone";
+    public static final String KEY_PAIR = "keyPair";
+    public static final String HOST = "host";
+    public static final String SECURITY_GROUP_IDS = "securityGroupIds";
+    public static final String SECURITY_GROUPS = "securityGroups";
+    public static final String SUBNET_ID = "subnetId";
+    public static final String AUTO_ASSIGN_IP = "autoAssignIp";
+    public static final String INSTANCE_TYPE = "instanceType";
 
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
index f308d1f..8eeef23 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
@@ -21,12 +21,14 @@ package org.apache.stratos.cloud.controller.util;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.cloud.controller.exception.CloudControllerException;
+import org.apache.stratos.messaging.util.Property;
 
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Properties;
 
 public class CloudControllerUtil {
 	private static final Log log = LogFactory.getLog(CloudControllerUtil.class);
@@ -83,6 +85,26 @@ public class CloudControllerUtil {
     	
     }
 	
+	/**
+	 * Converts org.apache.stratos.messaging.util.Properties to java.util.Properties
+	 * @param properties org.apache.stratos.messaging.util.Properties
+	 * @return java.util.Properties
+	 */
+    public static Properties toJavaUtilProperties(
+        org.apache.stratos.messaging.util.Properties properties) {
+        Properties javaProps = new Properties();
+
+        if (properties != null && properties.getProperties() != null) {
+
+            for (org.apache.stratos.messaging.util.Property property : properties.getProperties()) {
+                javaProps.put(property.getName(), property.getValue());
+            }
+
+        }
+
+        return javaProps;
+    }
+	
 	public static void handleException(String msg, Exception e){
 		log.error(msg, e);
 		throw new CloudControllerException(msg, e);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/DataPublisherConfig.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/DataPublisherConfig.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/DataPublisherConfig.java
new file mode 100644
index 0000000..3c2a27b
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/DataPublisherConfig.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one 
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
+ * KIND, either express or implied.  See the License for the 
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.cloud.controller.util;
+
+/**
+ * @author nirmal
+ *
+ */
+public class DataPublisherConfig {
+
+    private String bamUsername = CloudControllerConstants.DEFAULT_BAM_SERVER_USER_NAME;
+    private String bamPassword = CloudControllerConstants.DEFAULT_BAM_SERVER_PASSWORD;
+    private String dataPublisherCron = CloudControllerConstants.PUB_CRON_EXPRESSION;
+    private String cassandraConnUrl = CloudControllerConstants.DEFAULT_CASSANDRA_URL;
+    private String cassandraUser = CloudControllerConstants.DEFAULT_CASSANDRA_USER;
+    private String cassandraPassword = CloudControllerConstants.DEFAULT_CASSANDRA_PASSWORD;
+    
+    public String getBamUsername() {
+        return bamUsername;
+    }
+
+    public void setBamUsername(String bamUsername) {
+        this.bamUsername = bamUsername;
+    }
+
+    public String getBamPassword() {
+        return bamPassword;
+    }
+
+    public void setBamPassword(String bamPassword) {
+        this.bamPassword = bamPassword;
+    }
+
+    public String getDataPublisherCron() {
+        return dataPublisherCron;
+    }
+
+    public void setDataPublisherCron(String dataPublisherCron) {
+        this.dataPublisherCron = dataPublisherCron;
+    }
+    public String getCassandraConnUrl() {
+        return cassandraConnUrl;
+    }
+
+    public void setCassandraConnUrl(String cassandraHostAddr) {
+        this.cassandraConnUrl = cassandraHostAddr;
+    }
+
+    public String getCassandraUser() {
+        return cassandraUser;
+    }
+
+    public void setCassandraUser(String cassandraUser) {
+        this.cassandraUser = cassandraUser;
+    }
+
+    public String getCassandraPassword() {
+        return cassandraPassword;
+    }
+
+    public void setCassandraPassword(String cassandraPassword) {
+        this.cassandraPassword = cassandraPassword;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasProvider.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasProvider.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasProvider.java
index 7f7de1f..81f4c4b 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasProvider.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasProvider.java
@@ -37,7 +37,7 @@ public class IaasProvider implements Serializable{
     private static final long serialVersionUID = -940288190885166118L;
 
 	/**
-     * IaaS provider + Region should be unique for a IaasProvider.
+     * Type of the IaasProvider.
      */
     private String type;
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Properties.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Properties.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Properties.java
deleted file mode 100644
index eb02b22..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Properties.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one 
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
- * KIND, either express or implied.  See the License for the 
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.cloud.controller.util;
-
-/**
- * Had to wrap {@link Property} array using a class, since there's a bug in current 
- * stub generation.
- */
-public class Properties {
-
-	private Property[] properties;
-
-	public Property[] getProperties() {
-	    return properties;
-    }
-
-	public void setProperties(Property[] properties) {
-	    this.properties = properties;
-    }
-	
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Property.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Property.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Property.java
deleted file mode 100644
index a17d30b..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Property.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one 
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
- * KIND, either express or implied.  See the License for the 
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.cloud.controller.util;
-/**
- * Holds a property 
- */
-public class Property {
-	
-	private String name;
-	private String value;
-	
-	public Property(){
-		
-	}
-	
-	public Property(String name, String value){
-		this.setName(name);
-		this.setValue(value);
-	}
-
-	public String getName() {
-	    return name;
-    }
-
-	public void setName(String name) {
-	    this.name = name;
-    }
-
-	public String getValue() {
-	    return value;
-    }
-
-	public void setValue(String value) {
-	    this.value = value;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceContext.java
index 887ca15..0b4c4a2 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceContext.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceContext.java
@@ -22,7 +22,7 @@ import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.cloud.controller.exception.CloudControllerException;
-import org.apache.stratos.messaging.domain.topology.Partition;
+import org.apache.stratos.messaging.domain.policy.Partition;
 import org.wso2.carbon.utils.CarbonUtils;
 
 import java.io.*;

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/AWSEC2PartitionValidator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/AWSEC2PartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/AWSEC2PartitionValidator.java
index 037e23d..0431193 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/AWSEC2PartitionValidator.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/AWSEC2PartitionValidator.java
@@ -19,7 +19,12 @@
 package org.apache.stratos.cloud.controller.validate;
 
 import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
 import org.apache.stratos.cloud.controller.interfaces.Iaas;
+import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
 import org.apache.stratos.cloud.controller.util.IaasProvider;
 import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator;
 import org.apache.stratos.messaging.domain.topology.Scope;
@@ -32,30 +37,52 @@ import org.apache.stratos.messaging.domain.topology.Scope;
  */
 public class AWSEC2PartitionValidator implements PartitionValidator {
     
-    private static final String NAME = "ec2";
+    private static final Log log = LogFactory.getLog(AWSEC2PartitionValidator.class);
     private IaasProvider iaasProvider;
     private Iaas iaas;
 
     @Override
-    public String getName() {
-        return NAME;
-    }
-
-    @Override
-    public boolean validate(Properties properties) {
+    public IaasProvider validate(String partitionId, Properties properties) throws InvalidPartitionException {
         // validate the existence of the region and zone properties.
-        if (properties.containsKey(Scope.REGION.toString())) {
-            String region = properties.getProperty(Scope.REGION.name());
-            if (iaas.isValidRegion(iaasProvider, region)) {
-                if (properties.containsKey(Scope.ZONE.toString())) {
-                    String zone = properties.getProperty(Scope.ZONE.name());
-                    return iaas.isValidZone(iaasProvider, region, zone);
-                } else {
-                    return true;
-                }
+        try {
+            if (properties.containsKey(Scope.region.toString())) {
+                String region = properties.getProperty(Scope.region.toString());
+                
+                if (iaasProvider.getImage() != null && !iaasProvider.getImage().contains(region)) {
+
+                    String msg =
+                                 "Invalid Partition Detected : " + partitionId +
+                                         " - Cause: Invalid Region: " + region;
+                    log.error(msg);
+                    throw new InvalidPartitionException(msg);
+                } 
+                
+                iaas.isValidRegion(iaasProvider, region);
+                
+                IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider);
+                Iaas updatedIaas = updatedIaasProvider.getIaas();
+                
+                if (properties.containsKey(Scope.zone.toString())) {
+                    String zone = properties.getProperty(Scope.zone.toString());
+                    iaas.isValidZone(iaasProvider, region, zone);
+                    updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, zone);
+                    updatedIaas.buildTemplate(updatedIaasProvider);
+                } 
+                
+                return updatedIaasProvider;
+                
+            } else {
+                
+                String msg = "Invalid Partition Detected : "+partitionId+". - "+Scope.region.toString()+" Property is not defined.";
+                log.error(msg);
+                throw new InvalidPartitionException(msg);
             }
+        } catch (Exception ex) {
+            String msg = "Invalid Partition Detected : "+partitionId;
+            log.error(msg, ex);
+            throw new InvalidPartitionException(msg, ex);
         }
-        return false;
+        
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/OpenstackNovaPartitionValidator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/OpenstackNovaPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/OpenstackNovaPartitionValidator.java
index 88e4be2..2bf0dc9 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/OpenstackNovaPartitionValidator.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/OpenstackNovaPartitionValidator.java
@@ -19,7 +19,12 @@
 package org.apache.stratos.cloud.controller.validate;
 
 import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
 import org.apache.stratos.cloud.controller.interfaces.Iaas;
+import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
 import org.apache.stratos.cloud.controller.util.IaasProvider;
 import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator;
 import org.apache.stratos.messaging.domain.topology.Scope;
@@ -32,30 +37,55 @@ import org.apache.stratos.messaging.domain.topology.Scope;
  */
 public class OpenstackNovaPartitionValidator implements PartitionValidator {
     
-    private static final String NAME = "openstack";
+    private static final Log log = LogFactory.getLog(OpenstackNovaPartitionValidator.class);
     private IaasProvider iaasProvider;
     private Iaas iaas;
 
     @Override
-    public String getName() {
-        return NAME;
-    }
+    public IaasProvider validate(String partitionId, Properties properties) throws InvalidPartitionException {
+        try {
+            // validate the existence of the zone and hosts properties.
+            if (properties.containsKey(Scope.region.toString())) {
+                String region = properties.getProperty(Scope.region.toString());
+                
+                if (iaasProvider.getImage() != null && !iaasProvider.getImage().contains(region)) {
 
-    @Override
-    public boolean validate(Properties properties) {
-        // validate the existence of the zone and hosts properties.
-        if (properties.containsKey(Scope.ZONE.toString())) {
-            String zone = properties.getProperty(Scope.ZONE.toString());
-            if (iaas.isValidZone(iaasProvider, null, zone)) {
-                if (properties.containsKey(Scope.HOST.toString())) {
-                    String host = properties.getProperty(Scope.HOST.toString());
-                    return iaas.isValidHost(iaasProvider, zone, host);
-                } else {
-                    return true;
-                }
+                    String msg =
+                                 "Invalid Partition Detected : " + partitionId +
+                                         " - Cause: Invalid Region: " + region;
+                    log.error(msg);
+                    throw new InvalidPartitionException(msg);
+                } 
+                
+                iaas.isValidRegion(iaasProvider, region);
+                
+                IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider);
+                Iaas updatedIaas = updatedIaasProvider.getIaas();
+                
+                if (properties.containsKey(Scope.host.toString())) {
+                    String host = properties.getProperty(Scope.host.toString());
+                    iaas.isValidHost(iaasProvider, region, host);
+                    
+                    updatedIaasProvider.setProperty(CloudControllerConstants.HOST, host);
+                    updatedIaas.buildTemplate(updatedIaasProvider);
+                } 
+                
+                return updatedIaasProvider;
+                
+                
+            } else {
+
+                String msg =
+                        "Invalid Partition Detected : "+partitionId+". - "+Scope.zone.toString() +
+                                     " Property is not defined.";
+                log.error(msg);
+                throw new InvalidPartitionException(msg);
             }
+        } catch (Exception ex) {
+            String msg = "Invalid Partition Detected : "+partitionId;
+            log.error(msg, ex);
+            throw new InvalidPartitionException(msg, ex);
         }
-        return false;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/interfaces/PartitionValidator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/interfaces/PartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/interfaces/PartitionValidator.java
index 7279bab..eaa1862 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/interfaces/PartitionValidator.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/interfaces/PartitionValidator.java
@@ -20,7 +20,7 @@ package org.apache.stratos.cloud.controller.validate.interfaces;
 
 import java.util.Properties;
 
-import org.apache.stratos.cloud.controller.interfaces.Iaas;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
 import org.apache.stratos.cloud.controller.util.IaasProvider;
 
 /**
@@ -37,16 +37,11 @@ public interface PartitionValidator {
     public void setIaasProvider(IaasProvider iaas);
 
     /**
-     * Should return the name of this validator.
-     * @return name.
-     */
-    public String getName();
-    
-    
-    /**
      * Validate the given properties for its existent in this partition.
+     * @param partitionId partition id.
      * @param properties set of properties to be validated.
-     * @return whether it's validated to true or not.
+     * @return cloned and modified {@link IaasProvider} which maps to the given partition. 
+     * @throws InvalidPartitionException if at least one property is evaluated to be invalid.
      */
-    public boolean validate(Properties properties);
+    public IaasProvider validate(String partitionId, Properties properties) throws InvalidPartitionException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/resources/META-INF/component.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/resources/META-INF/component.xml b/components/org.apache.stratos.cloud.controller/src/main/resources/META-INF/component.xml
index 0946d80..f41dec9 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/resources/META-INF/component.xml
+++ b/components/org.apache.stratos.cloud.controller/src/main/resources/META-INF/component.xml
@@ -28,10 +28,10 @@
             <extension>xml</extension>
             <class>org.apache.stratos.cloud.controller.deployers.CartridgeDeployer</class>
         </deployer>
-        <deployer>
+        <!-- >deployer>
             <directory>services</directory>
             <extension>xml</extension>
             <class>org.apache.stratos.cloud.controller.deployers.ServiceDeployer</class>
-        </deployer>
+        </deployer-->
     </deployers>
 </component>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomValidationTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomValidationTest.java b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomValidationTest.java
index 6069b91..42f5230 100644
--- a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomValidationTest.java
+++ b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomValidationTest.java
@@ -20,7 +20,9 @@ package org.apache.cartridge.autoscaler.service.axiom;
 
 import java.io.File;
 
+import org.apache.axiom.om.OMElement;
 import org.apache.stratos.cloud.controller.axiom.AxiomXpathParser;
+import org.apache.stratos.cloud.controller.axiom.AxiomXpathParserUtil;
 import org.xml.sax.SAXParseException;
 
 import junit.framework.TestCase;
@@ -38,63 +40,56 @@ public class AxiomValidationTest extends TestCase {
     
     protected void setUp() throws Exception {
         super.setUp();
-        util1 = new AxiomXpathParser(new File(dir+"cartridges-1.xml"));
-        util2 = new AxiomXpathParser(new File(dir+"cartridges-2.xml"));
-        util3 = new AxiomXpathParser(new File(dir+"cartridges-3.xml"));
-        util4 = new AxiomXpathParser(new File(dir+"cartridges-4.xml"));
-        util5 = new AxiomXpathParser(new File(dir+"cartridges-5.xml"));
-        util6 = new AxiomXpathParser(new File(dir+"cartridges-6.xml"));
-        util7 = new AxiomXpathParser(new File(dir+"cartridges-7.xml"));
-        util8 = new AxiomXpathParser(new File(dir+"cartridges-8.xml"));
-        util9 = new AxiomXpathParser(new File(dir+"cartridges-9.xml"));
-        util1.parse();
-        util2.parse();
-        util3.parse();
-        util4.parse();
-        util5.parse();
-        util6.parse();
-        util7.parse();
-        util8.parse();
-        util9.parse();
     }
 
     public final void testCartridgeValidation() throws Exception {
+        OMElement elt = AxiomXpathParserUtil.parse(new File(dir+"cartridges-1.xml"));
         
         // schema 1 - cartridges 
-        assertEquals(true, util1.validate(xmlSchemaCartridges));
+        AxiomXpathParserUtil.validate(elt, xmlSchemaCartridges);
         
-        assertEquals(true, util5.validate(xmlSchemaCartridges));
+        elt = AxiomXpathParserUtil.parse(new File(dir+"cartridges-5.xml"));
+        AxiomXpathParserUtil.validate(elt, xmlSchemaCartridges);
         
-        assertEquals(true, util6.validate(xmlSchemaCartridges));
+        elt = AxiomXpathParserUtil.parse(new File(dir+"cartridges-6.xml"));
+        AxiomXpathParserUtil.validate(elt, xmlSchemaCartridges);
         
-        assertEquals(true, util7.validate(xmlSchemaCartridges));
+        elt = AxiomXpathParserUtil.parse(new File(dir+"cartridges-7.xml"));
+        AxiomXpathParserUtil.validate(elt, xmlSchemaCartridges);
         
-        assertEquals(true, util9.validate(xmlSchemaCartridges));
+        elt = AxiomXpathParserUtil.parse(new File(dir+"cartridges-9.xml"));
+        AxiomXpathParserUtil.validate(elt, xmlSchemaCartridges);
         
+        elt = AxiomXpathParserUtil.parse(new File(dir+"cartridges-2.xml"));
         // schema 2 - cartridge
-        assertEquals(true, util2.validate(xmlSchemaCartridge));
+        AxiomXpathParserUtil.validate(elt, xmlSchemaCartridge);
         
-        assertEquals(true, util8.validate(xmlSchemaCartridge));
+        elt = AxiomXpathParserUtil.parse(new File(dir+"cartridges-8.xml"));
+        AxiomXpathParserUtil.validate(elt, xmlSchemaCartridge);
     }
     
     public final void testCartridgeInvalidation() {
+        OMElement elt1 = AxiomXpathParserUtil.parse(new File(dir+"cartridges-1.xml"));
+        OMElement elt2 = AxiomXpathParserUtil.parse(new File(dir+"cartridges-2.xml"));
+        OMElement elt3 = AxiomXpathParserUtil.parse(new File(dir+"cartridges-3.xml"));
+        OMElement elt4 = AxiomXpathParserUtil.parse(new File(dir+"cartridges-4.xml"));
         
      // schema 1 - cartridges 
         try {
-            util2.validate(xmlSchemaCartridges);
+            AxiomXpathParserUtil.validate(elt2, xmlSchemaCartridges);
         } catch (Exception e) {
             assertEquals(SAXParseException.class, e.getClass());
         }
         
         try {
-            util3.validate(xmlSchemaCartridges);
+            AxiomXpathParserUtil.validate(elt3, xmlSchemaCartridges);
         } catch (Exception e) {
 
             assertEquals(SAXParseException.class, e.getClass());
         }
         
         try {
-            util4.validate(xmlSchemaCartridges);
+            AxiomXpathParserUtil.validate(elt4, xmlSchemaCartridges);
         } catch (Exception e) {
 
             assertEquals(SAXParseException.class, e.getClass());
@@ -103,21 +98,21 @@ public class AxiomValidationTest extends TestCase {
         // schema 2 - cartridge
         
         try {
-            util1.validate(xmlSchemaCartridge);
+            AxiomXpathParserUtil.validate(elt1, xmlSchemaCartridge);
         } catch (Exception e) {
 
             assertEquals(SAXParseException.class, e.getClass());
         }
         
         try {
-            util3.validate(xmlSchemaCartridge);
+            AxiomXpathParserUtil.validate(elt3, xmlSchemaCartridge);
         } catch (Exception e) {
 
             assertEquals(SAXParseException.class, e.getClass());
         }
         
         try {
-            util4.validate(xmlSchemaCartridge);
+            AxiomXpathParserUtil.validate(elt4, xmlSchemaCartridge);
         } catch (Exception e) {
 
             assertEquals(SAXParseException.class, e.getClass());

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomXpathParserTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomXpathParserTest.java b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomXpathParserTest.java
index 389a511..016a9f9 100644
--- a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomXpathParserTest.java
+++ b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomXpathParserTest.java
@@ -19,16 +19,19 @@
 package org.apache.cartridge.autoscaler.service.axiom;
 
 import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNode;
-import org.apache.stratos.cloud.controller.axiom.AxiomXpathParser;
+import org.apache.stratos.cloud.controller.axiom.AxiomXpathParserUtil;
+import org.apache.stratos.cloud.controller.axiom.parser.CloudControllerConfigParser;
 import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
 
 import java.io.File;
 import java.util.List;
 
 public class AxiomXpathParserTest extends TestCase {
-    AxiomXpathParser parser;
     File xmlFile = new File("src/test/resources/cloud-controller.xml");
+    OMElement docElt;
 
     public AxiomXpathParserTest(String name) {
         super(name);
@@ -36,26 +39,24 @@ public class AxiomXpathParserTest extends TestCase {
 
     protected void setUp() throws Exception {
         super.setUp();
-        parser = new AxiomXpathParser(xmlFile);
-        parser.parse();
+        docElt = AxiomXpathParserUtil.parse(xmlFile);
+
+        CloudControllerConfigParser.parse(docElt);
     }
     
     public void testGetMatchingNodes(){
-        List<OMNode> list = parser.getMatchingNodes("/cloudController/iaasProviders/iaasProvider/provider");
+        List<OMNode> list = AxiomXpathParserUtil.getMatchingNodes("/cloudController/iaasProviders/iaasProvider/provider", docElt);
         assertEquals(1, list.size());
-        parser.setIaasProvidersList();
         assertEquals(1, FasterLookUpDataHolder.getInstance().getIaasProviders().size());
     }
     
     public void testDataPublisherConfig() {
-		parser.setDataPublisherRelatedData();
 		assertEquals(true, FasterLookUpDataHolder.getInstance().getEnableBAMDataPublisher());
-		assertEquals("nirmal", FasterLookUpDataHolder.getInstance().getBamUsername());
-		assertEquals("nirmal", FasterLookUpDataHolder.getInstance().getBamPassword());
+		assertEquals("nirmal", FasterLookUpDataHolder.getInstance().getDataPubConfig().getBamUsername());
+		assertEquals("nirmal", FasterLookUpDataHolder.getInstance().getDataPubConfig().getBamPassword());
 	}
     
     public void testTopologySynchParser() {
-		parser.setTopologySyncRelatedData();
 		assertNotNull(FasterLookUpDataHolder.getInstance().getTopologyConfig());
 		assertEquals("1 * * * * ? *", FasterLookUpDataHolder.getInstance().getTopologyConfig().getProperty("cron"));
 	}