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:09 UTC

[12/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/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
index 67b7aea..bc6877a 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
@@ -18,16 +18,21 @@
  */
 package org.apache.stratos.cloud.controller.impl;
 
-import com.google.common.collect.Lists;
-
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.concurrent.ThreadExecutor;
 import org.apache.stratos.cloud.controller.exception.CloudControllerException;
+import org.apache.stratos.cloud.controller.exception.InvalidCartridgeTypeException;
+import org.apache.stratos.cloud.controller.exception.InvalidClusterException;
+import org.apache.stratos.cloud.controller.exception.InvalidMemberException;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
 import org.apache.stratos.cloud.controller.exception.UnregisteredCartridgeException;
-import org.apache.stratos.cloud.controller.exception.UnregisteredServiceException;
+import org.apache.stratos.cloud.controller.exception.UnregisteredClusterException;
 import org.apache.stratos.cloud.controller.interfaces.CloudControllerService;
+import org.apache.stratos.cloud.controller.interfaces.Iaas;
 import org.apache.stratos.cloud.controller.persist.Deserializer;
+import org.apache.stratos.cloud.controller.pojo.ClusterContext;
+import org.apache.stratos.cloud.controller.pojo.MemberContext;
 import org.apache.stratos.cloud.controller.pojo.Registrant;
 import org.apache.stratos.cloud.controller.publisher.CartridgeInstanceDataPublisherTask;
 import org.apache.stratos.cloud.controller.registry.RegistryManager;
@@ -35,11 +40,11 @@ import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
 import org.apache.stratos.cloud.controller.topic.TopologySynchronizerTask;
 import org.apache.stratos.cloud.controller.topology.TopologyBuilder;
 import org.apache.stratos.cloud.controller.topology.TopologyEventMessageDelegator;
-import org.apache.stratos.cloud.controller.topology.TopologyManager;
 import org.apache.stratos.cloud.controller.util.*;
-import org.apache.stratos.cloud.controller.util.Properties;
-import org.apache.stratos.messaging.domain.topology.Partition;
-import org.apache.stratos.messaging.domain.topology.Scope;
+import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator;
+import org.apache.stratos.messaging.domain.policy.DeploymentPolicy;
+import org.apache.stratos.messaging.domain.policy.Partition;
+import org.apache.stratos.messaging.domain.policy.PartitionGroup;
 import org.jclouds.compute.ComputeService;
 import org.jclouds.compute.domain.ComputeMetadata;
 import org.jclouds.compute.domain.NodeMetadata;
@@ -53,9 +58,8 @@ import org.wso2.carbon.ntask.core.TaskManager;
 import org.wso2.carbon.ntask.core.service.TaskService;
 import org.wso2.carbon.registry.core.exceptions.RegistryException;
 
-import java.io.File;
-import java.io.IOException;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -164,8 +168,7 @@ public class CloudControllerServiceImpl implements CloudControllerService {
 				if (!tm.isTaskScheduled(CloudControllerConstants.DATA_PUB_TASK_NAME)) {
 
 					TriggerInfo triggerInfo = new TriggerInfo(
-							dataHolder
-									.getDataPublisherCron());
+							dataHolder.getDataPubConfig().getDataPublisherCron());
 					taskInfo = new TaskInfo(
 							CloudControllerConstants.DATA_PUB_TASK_NAME,
 							CartridgeInstanceDataPublisherTask.class.getName(),
@@ -196,179 +199,210 @@ public class CloudControllerServiceImpl implements CloudControllerService {
 
 	private void acquireData() {
 
-		Object obj = RegistryManager.getInstance().retrieve();
-		if (obj != null) {
-			try {
-				Object dataObj = Deserializer
-						.deserializeFromByteArray((byte[]) obj);
-				if (dataObj instanceof FasterLookUpDataHolder) {
-					FasterLookUpDataHolder serializedObj = (FasterLookUpDataHolder) dataObj;
-					FasterLookUpDataHolder currentData = FasterLookUpDataHolder
-							.getInstance();
-
-					// assign necessary data
-					currentData.setNodeIdToServiceContextMap(serializedObj
-							.getNodeIdToServiceContextMap());
-
-					// traverse through current Service Contexts
-					for (ServiceContext ctxt : currentData.getServiceCtxtList()) {
-						// traverse through serialized Service Contexts
-						for (ServiceContext serializedCtxt : serializedObj
-								.getServiceCtxtList()) {
-							// if a matching Service Context found
-							if (ctxt.equals(serializedCtxt)) {
-								// persisted node ids of this Service Context
-								List<Object> nodeIds = serializedObj
-										.getNodeIdsOfServiceCtxt(serializedCtxt);
-								for (Object nodeIdObj : nodeIds) {
-									String nodeId = (String) nodeIdObj;
-
-									// assign persisted data
-									currentData.addNodeId(nodeId, ctxt);
-
-								}
-
-								ctxt.setIaasContextMap(serializedCtxt
-										.getIaasCtxts());
-								appendToPublicIpProperty(
-										serializedCtxt
-												.getProperty(CloudControllerConstants.PUBLIC_IP_PROPERTY),
-										ctxt);
-
-								// assign lastly used IaaS
-								if (serializedCtxt.getCartridge() != null
-										&& serializedCtxt.getCartridge()
-												.getLastlyUsedIaas() != null) {
-
-									if (ctxt.getCartridge() == null) {
-										// load Cartridge
-										ctxt.setCartridge(loadCartridge(
-												ctxt.getCartridgeType(),
-												serializedObj.getCartridges()));
-									}
-
-									IaasProvider serializedIaas = serializedCtxt
-											.getCartridge().getLastlyUsedIaas();
-									ctxt.getCartridge().setLastlyUsedIaas(
-											serializedIaas);
-
-								}
-							}
-						}
-					}
-
-					log.debug("Data is retrieved from registry.");
-				} else {
-					log.debug("No data is persisted in registry.");
-				}
-			} catch (Exception e) {
-
-				String msg = "Unable to acquire data from Registry. Hence, any historical data will not get reflected.";
-				log.warn(msg, e);
-			}
-
-		}
+//		Object obj = RegistryManager.getInstance().retrieve();
+//		if (obj != null) {
+//			try {
+//				Object dataObj = Deserializer
+//						.deserializeFromByteArray((byte[]) obj);
+//				if (dataObj instanceof FasterLookUpDataHolder) {
+//					FasterLookUpDataHolder serializedObj = (FasterLookUpDataHolder) dataObj;
+//					FasterLookUpDataHolder currentData = FasterLookUpDataHolder
+//							.getInstance();
+//
+//					// assign necessary data
+//					currentData.setNodeIdToServiceContextMap(serializedObj
+//							.getNodeIdToServiceContextMap());
+//
+//					// traverse through current Service Contexts
+//					for (ServiceContext ctxt : currentData.getServiceCtxtList()) {
+//						// traverse through serialized Service Contexts
+//						for (ServiceContext serializedCtxt : serializedObj
+//								.getServiceCtxtList()) {
+//							// if a matching Service Context found
+//							if (ctxt.equals(serializedCtxt)) {
+//								// persisted node ids of this Service Context
+//								List<Object> nodeIds = serializedObj
+//										.getNodeIdsOfServiceCtxt(serializedCtxt);
+//								for (Object nodeIdObj : nodeIds) {
+//									String nodeId = (String) nodeIdObj;
+//
+//									// assign persisted data
+//									currentData.addNodeId(nodeId, ctxt);
+//
+//								}
+//
+//								ctxt.setIaasContextMap(serializedCtxt
+//										.getIaasCtxts());
+//								appendToPublicIpProperty(
+//										serializedCtxt
+//												.getProperty(CloudControllerConstants.PUBLIC_IP_PROPERTY),
+//										ctxt);
+//
+//								// assign lastly used IaaS
+//								if (serializedCtxt.getCartridge() != null
+//										&& serializedCtxt.getCartridge()
+//												.getLastlyUsedIaas() != null) {
+//
+//									if (ctxt.getCartridge() == null) {
+//										// load Cartridge
+//										ctxt.setCartridge(loadCartridge(
+//												ctxt.getCartridgeType(),
+//												serializedObj.getCartridges()));
+//									}
+//
+//									IaasProvider serializedIaas = serializedCtxt
+//											.getCartridge().getLastlyUsedIaas();
+//									ctxt.getCartridge().setLastlyUsedIaas(
+//											serializedIaas);
+//
+//								}
+//							}
+//						}
+//					}
+//
+//					log.debug("Data is retrieved from registry.");
+//				} else {
+//					log.debug("No data is persisted in registry.");
+//				}
+//			} catch (Exception e) {
+//
+//				String msg = "Unable to acquire data from Registry. Hence, any historical data will not get reflected.";
+//				log.warn(msg, e);
+//			}
+
+//		}
 	}
 
-    @Override()
-	public String startInstance(String clusterId, Partition partition) {
+    @Override
+	public String startInstance(String clusterId, Partition partition) throws IllegalArgumentException, UnregisteredCartridgeException {
 
-        log.info("Starting new instance of domain : " + clusterId);
+        log.info("Starting new instance of cluster : " + clusterId);
 
 		ComputeService computeService = null;
 		Template template = null;
 		String ip;
+		
+		if(partition == null) {
+		    String msg = "Instance start-up failed. Specified Partition is null. Cluster id: "+clusterId;
+            log.error(msg);
+            throw new IllegalArgumentException(msg);
+		}
+		
         String partitionId = partition.getId();
-        Partition partition_ = TopologyManager.getInstance().getTopology().getPartition(partitionId);
-        Scope scope = partition_.getScope();
-        String provider = partition_.getProperty("provider");
+        ClusterContext ctxt = dataHolder.getClusterContext(clusterId);
+        
+        if(ctxt == null) {
+            String msg = "Instance start-up failed. Invalid cluster id: "+clusterId;
+            log.error(msg);
+            throw new IllegalArgumentException(msg);
+        }
+        
+        String cartridgeType = ctxt.getCartridgeType();
+        
+        Cartridge cartridge = dataHolder.getCartridge(cartridgeType);
+        
+        if(cartridge == null) {
+            String msg = "Instance start-up failed. No valid Cartridge found for type: "+cartridgeType;
+            log.error(msg);
+            throw new UnregisteredCartridgeException(msg);
+        }
+        
+        
+//        Partition partition_ = TopologyManager.getInstance().getTopology().getPartition(partitionId);
+//        Scope scope = partition_.getScope();
+//        String provider = partition_.getProperty("provider");
 		final Lock lock = new ReentrantLock();
 
 		// get the subjected ServiceContext
-		ServiceContext serviceCtxt = dataHolder
-				.getServiceContextFromDomain(clusterId);
-
-		if (serviceCtxt == null) {
-			String msg = "Not a registered service: domain - " + clusterId;
-			log.fatal(msg);
-			throw new CloudControllerException(msg);
-		}
-
-		// load Cartridge
-		serviceCtxt.setCartridge(loadCartridge(serviceCtxt.getCartridgeType(),
-				 dataHolder
-						.getCartridges()));
-
-		if (serviceCtxt.getCartridge() == null) {
-			String msg = "There's no registered Cartridge found. Domain - "
-					+ clusterId;
-			log.fatal(msg);
-			throw new CloudControllerException(msg);
-		}
-
-		if (serviceCtxt.getCartridge().getIaases().isEmpty()) {
-			String msg = "There's no registered IaaSes found for Cartridge type: "
-					+ serviceCtxt.getCartridge().getType();
-			log.fatal(msg);
-			throw new CloudControllerException(msg);
-		}
-
-
-		for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) {
-
-            if(provider == null) {
-                String msg = "There's no IaaS provided for the cluster: "
-					+ clusterId + " to start an instance";
+//		ServiceContext serviceCtxt = dataHolder
+//				.getServiceContextFromDomain(clusterId);
+//
+//		if (serviceCtxt == null) {
+//			String msg = "Not a registered service: domain - " + clusterId;
+//			log.fatal(msg);
+//			throw new CloudControllerException(msg);
+//		}
+//
+//		// load Cartridge
+//		serviceCtxt.setCartridge(loadCartridge(serviceCtxt.getCartridgeType(),
+//				 dataHolder
+//						.getCartridges()));
+//
+//		if (serviceCtxt.getCartridge() == null) {
+//			String msg = "There's no registered Cartridge found. Domain - "
+//					+ clusterId;
+//			log.fatal(msg);
+//			throw new CloudControllerException(msg);
+//		}
+//
+//		if (serviceCtxt.getCartridge().getIaases().isEmpty()) {
+//			String msg = "There's no registered IaaSes found for Cartridge type: "
+//					+ serviceCtxt.getCartridge().getType();
+//			log.fatal(msg);
+//			throw new CloudControllerException(msg);
+//		}
+
+
+//		for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) {
+
+		IaasProvider iaas = cartridge.getIaasProviderOfPartition(partitionId);
+            if(iaas == null) {
+                String msg = "Instance start-up failed for cluster: "+clusterId+". " +
+                        "There's no IaaS provided for the partition: "+partitionId+
+                        " and for the Cartridge type: "+cartridgeType;
                 log.fatal(msg);
                 throw new CloudControllerException(msg);
             }
-            if(iaas.getType().equals(provider)) {
-                IaasContext ctxt;
-                if ((ctxt = serviceCtxt.getIaasContext(iaas.getType())) == null) {
-                    ctxt = serviceCtxt.addIaasContext(iaas.getType());
-                }
+//                IaasContext ctxt;
+//                if ((ctxt = serviceCtxt.getIaasContext(iaas.getType())) == null) {
+//                    ctxt = serviceCtxt.addIaasContext(iaas.getType());
+//                }
                 try {
                     //generating the Unique member ID...
                     String memberID = generateMemberId(clusterId);
                     //have to add memberID to the payload
-                    serviceCtxt.getPayload().append(",");
-                    serviceCtxt.getPayload().append("MEMBER_ID=" + memberID);
+                    StringBuilder payload = new StringBuilder(ctxt.getPayload());
+                    payload.append(",");
+                    payload.append("MEMBER_ID=" + memberID);
                     //reloading the payload with memberID
-                    reloadPayload(serviceCtxt.getCartridge(), serviceCtxt.generatePayload());
+                    iaas.setPayload(payload.toString().getBytes());
 
                     iaas.getIaas().setDynamicPayload(iaas);
                     // get the pre built ComputeService from provider or region or zone or host
-                    if(scope == null || scope.name().equals(Scope.PROVIDER.name())) {
-                        computeService = iaas.getComputeService();
-                        template = iaas.getTemplate();
-                    } else if(scope.name().equals(Scope.REGION.name())) {
-                        for(Region region : iaas.getListOfRegions()) {
-                            if(region.getId().equals(partitionId)) {
-                                computeService = region.getComputeService();
-                                template = region.getTemplate();
-                            }
-                        }
-                    } else if(scope.name().equals(Scope.ZONE.name())) {
-                        for(Region region : iaas.getListOfRegions()) {
-                            for(Zone zone : region.getListOfZones()) {
-                               if(zone.getId().equals(partitionId)) {
-                                computeService = zone.getComputeService();
-                                template = zone.getTemplate();
-                                }
-                            }
-                        }
-                    } else if(scope.name().equals(Scope.HOST.name())) {
-                        for(Region region : iaas.getListOfRegions()) {
-                            for(Zone zone : region.getListOfZones()) {
-                                for(Host host: zone.getListOfHosts()) {
-                                    if(host.getId().equals(partitionId)) {
-                                        computeService = host.getComputeService();
-                                        template = host.getTemplate();
-                                    }
-                                }
-                            }
-                        }
-                    }
+                    computeService = iaas.getComputeService();
+                    template = iaas.getTemplate();
+                    
+//                    if(scope == null || scope.name().equals(Scope.PROVIDER.name())) {
+//                        computeService = iaas.getComputeService();
+//                        template = iaas.getTemplate();
+//                    } else if(scope.name().equals(Scope.REGION.name())) {
+//                        for(Region region : iaas.getListOfRegions()) {
+//                            if(region.getId().equals(partitionId)) {
+//                                computeService = region.getComputeService();
+//                                template = region.getTemplate();
+//                            }
+//                        }
+//                    } else if(scope.name().equals(Scope.ZONE.name())) {
+//                        for(Region region : iaas.getListOfRegions()) {
+//                            for(Zone zone : region.getListOfZones()) {
+//                               if(zone.getId().equals(partitionId)) {
+//                                computeService = zone.getComputeService();
+//                                template = zone.getTemplate();
+//                                }
+//                            }
+//                        }
+//                    } else if(scope.name().equals(Scope.HOST.name())) {
+//                        for(Region region : iaas.getListOfRegions()) {
+//                            for(Zone zone : region.getListOfZones()) {
+//                                for(Host host: zone.getListOfHosts()) {
+//                                    if(host.getId().equals(partitionId)) {
+//                                        computeService = host.getComputeService();
+//                                        template = host.getTemplate();
+//                                    }
+//                                }
+//                            }
+//                        }
+//                    }
                     if (template == null) {
                         String msg = "Failed to start an instance in "
                                 + iaas.getType()
@@ -376,7 +410,7 @@ public class CloudControllerServiceImpl implements CloudControllerService {
                                 + "element in the configuration file of Autoscaler.\n Hence, will try to "
                                 + "start in another IaaS if available.";
                         log.error(msg);
-                        continue;
+                        throw new CloudControllerException(msg);
                     }
 
                     // set instance name as the host name
@@ -438,38 +472,44 @@ public class CloudControllerServiceImpl implements CloudControllerService {
                             ip = node.getPrivateAddresses().iterator().next();
                         }
 
-                        if (node.getId() == null) {
+                        String nodeId = node.getId();
+                        if (nodeId == null) {
                             String msg = "Node id of the starting instance is null.\n"
                                     + node.toString();
                             log.fatal(msg);
                             throw new CloudControllerException(msg);
                         }
+                        
+                        MemberContext memberCtxt = new MemberContext(memberID, nodeId, clusterId, partitionId, cartridgeType, ip);
+                        dataHolder.addMemberContext(memberCtxt);
 
                         // add node ID
-                        ctxt.addNodeId(node.getId());
-                        ctxt.addNodeToPublicIp(node.getId(), ip);
+//                        ctxt.addNodeId(node.getId());
+//                        ctxt.addNodeToPublicIp(node.getId(), ip);
 
                         // to faster look up
-                        dataHolder.addNodeId(
-                                node.getId(), serviceCtxt);
-
-                        serviceCtxt.getCartridge().setLastlyUsedIaas(iaas);
-
-                        // add this ip to the topology
-                        appendToPublicIpProperty(ip, serviceCtxt);
-
-                        dataHolder.updateActiveInstanceCount(iaas.getType(), 1);
+//                        dataHolder.addNodeId(
+//                                node.getId(), serviceCtxt);
+//                        
+//                        dataHolder.addNodeId(memberID, node.getId());
+//
+//                        serviceCtxt.getCartridge().setLastlyUsedIaas(iaas);
+//
+//                        // add this ip to the topology
+//                        appendToPublicIpProperty(ip, serviceCtxt);
+//
+//                        dataHolder.updateActiveInstanceCount(iaas.getType(), 1);
 
                         // persist in registry
                         persist();
 
                         // trigger topology
-                        TopologyBuilder.handleMemberSpawned(memberID, serviceCtxt.getCartridgeType(), clusterId,
-                                 node.getId(), partition, privateIp);
+                        TopologyBuilder.handleMemberSpawned(memberID, cartridgeType, clusterId,
+                                 nodeId, partition, privateIp);
 
                         //update the topology with the newly spawned member
                         // publish data
-                        CartridgeInstanceDataPublisherTask.publish();
+//                        CartridgeInstanceDataPublisherTask.publish();
                         if (log.isDebugEnabled()) {
                             log.debug("Node details: \n" + node.toString()
                                     + "\n***************\n");
@@ -479,7 +519,7 @@ public class CloudControllerServiceImpl implements CloudControllerService {
                                 + iaas.getType()
                                 + ".\tIP Address(public/private): "
                                 + ip
-                                + "\tNode Id: " + node.getId());
+                                + "\tNode Id: " + nodeId);
 
                         return ip;
 
@@ -495,18 +535,17 @@ public class CloudControllerServiceImpl implements CloudControllerService {
                                         + ". Hence, will try to start in another IaaS if available.",
                                 e);
                     }
-            }
 
-        }
+//        }
         return null;
 
 	}
 
-    @Override
-    public String startInstances(String clusterId, Partition partition, int noOfInstancesToBeSpawned) {
-        //TODO
-        return null;
-    }
+//    @Override
+//    public String startInstances(String clusterId, Partition partition, int noOfInstancesToBeSpawned) {
+//        //TODO
+//        return null;
+//    }
 
     /**
 	 * Appends this ip to the Service Context's
@@ -531,15 +570,15 @@ public class CloudControllerServiceImpl implements CloudControllerService {
 	 * Persist data in registry.
 	 */
 	private void persist() {
-		try {
-			RegistryManager.getInstance().persist(
-					dataHolder);
-		} catch (RegistryException e) {
-
-			String msg = "Failed to persist the Cloud Controller data in registry. Further, transaction roll back also failed.";
-			log.fatal(msg);
-			throw new CloudControllerException(msg, e);
-		}
+//		try {
+//			RegistryManager.getInstance().persist(
+//					dataHolder);
+//		} catch (RegistryException e) {
+//
+//			String msg = "Failed to persist the Cloud Controller data in registry. Further, transaction roll back also failed.";
+//			log.fatal(msg);
+//			throw new CloudControllerException(msg, e);
+//		}
 	}
 
     private String generateMemberId(String clusterId) {
@@ -565,173 +604,339 @@ public class CloudControllerServiceImpl implements CloudControllerService {
         }
 
     }
+    
+    @Override
+    public void terminateInstance(String memberId) throws InvalidMemberException, InvalidCartridgeTypeException, 
+    IllegalArgumentException{
 
-	@Override
-	public boolean terminateInstance(String clusterId, Partition partition) {
+        if(memberId == null) {
+            String msg = "Termination failed. Null member id.";
+            log.error(msg);
+            throw new IllegalArgumentException(msg);
+        }
+//        String nodeId = dataHolder.getNodeId(memberId);
+        MemberContext ctxt = dataHolder.getMemberContextOfMemberId(memberId);
+        
+        if(ctxt == null) {
+            String msg = "Termination failed. Invalid Member Id: "+memberId;
+            log.error(msg);
+            throw new InvalidMemberException(msg);
+        }
+        
+        ThreadExecutor exec = new ThreadExecutor();
+        exec.execute(new InstanceTerminator(ctxt));
+        exec.shutdown();
 
-        String partitionId = partition.getId();
-        Scope scope = partition.getScope();
-        String provider = partition.getProperty("provider");
-		log.info("Starting to terminate an instance of domain : " + clusterId);
 
-		ServiceContext serviceCtxt = dataHolder
-				.getServiceContextFromDomain(clusterId);
+//			return true;
 
-		if (serviceCtxt == null) {
-			String msg = "Not a registered service: domain - " + clusterId;
-			log.fatal(msg);
-			throw new CloudControllerException(msg);
-		}
+//		}
 
-		// load Cartridge, if null
-		//if (serviceCtxt.getCartridge() == null) {
-			serviceCtxt.setCartridge(loadCartridge(
-					serviceCtxt.getCartridgeType(),
-					dataHolder.getCartridges()));
-		//}
-
-		// if still, Cartridge is null
-		if (serviceCtxt.getCartridge() == null) {
-			String msg = "There's no registered Cartridge found. Domain - "
-					+ clusterId;
-			log.fatal(msg);
-			throw new CloudControllerException(msg);
-		}
+//		log.info("Termination of an instance which is belong to domain '"
+//				+ clusterId
+//				+ "' , failed! Reason: No matching "
+//				+ "running instance found in any available IaaS.");
+//
+//		return false;
 
-        for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) {
+	}
+    
+    private class InstanceTerminator implements Runnable {
 
-			String msg = "Failed to terminate an instance in "
-					+ iaas.getType()
-					+ ". Hence, will try to terminate an instance in another IaaS if possible.";
-            //TODO adding more locations and retrieve it from the request received
-            if(iaas.getType().equals(provider)) {
-                String nodeId = null;
+        private MemberContext ctxt;
 
-                IaasContext ctxt = serviceCtxt.getIaasContext(iaas.getType());
+        public InstanceTerminator(MemberContext ctxt) {
+            this.ctxt = ctxt;
+        }
 
-                // terminate the last instance first
-                for (String id : Lists.reverse(ctxt.getNodeIds())) {
-                    if (id != null) {
-                        nodeId = id;
-                        break;
-                    }
+        @Override
+        public void run() {
+
+            String memberId = ctxt.getMemberId();
+            String clusterId = ctxt.getClusterId();
+            String partitionId = ctxt.getPartitionId();
+            String cartridgeType = ctxt.getCartridgeType();
+            String nodeId = ctxt.getNodeId();
+
+            try {
+                // these will never be null, since we do not add null values for these.
+                Cartridge cartridge = dataHolder.getCartridge(cartridgeType);
+
+                log.info("Starting to terminate an instance with member id : " + memberId +
+                         " in partition id: " + partitionId + " of cluster id: " + clusterId +
+                         " and of cartridge type: " + cartridgeType);
+
+                if (cartridge == null) {
+                    String msg =
+                                 "Termination of Member Id: " + memberId + " failed. " +
+                                         "Cannot find a matching Cartridge for type: " +
+                                         cartridgeType;
+                    log.error(msg);
+                    throw new InvalidCartridgeTypeException(msg);
                 }
 
+                // Scope scope = partition.getScope();
+                // String provider = partition.getProperty("provider");
+
                 // if no matching node id can be found.
                 if (nodeId == null) {
 
-                    log.warn(msg
-                            + " : Reason- No matching instance found for domain: "
-                            + clusterId
-                            + ".");
-                    continue;
+                    String msg =
+                                 "Termination failed. Cannot find a node id for Member Id: " +
+                                         memberId;
+                    log.error(msg);
+                    throw new InvalidMemberException(msg);
                 }
+                // ServiceContext serviceCtxt = dataHolder
+                // .getServiceContextFromDomain(clusterId);
+                //
+                // if (serviceCtxt == null) {
+                // String msg = "Not a registered service: domain - " + clusterId;
+                // log.fatal(msg);
+                // throw new CloudControllerException(msg);
+                // }
+                //
+                // // load Cartridge, if null
+                // //if (serviceCtxt.getCartridge() == null) {
+                // serviceCtxt.setCartridge(loadCartridge(
+                // serviceCtxt.getCartridgeType(),
+                // dataHolder.getCartridges()));
+                // //}
+                //
+                // // if still, Cartridge is null
+                // if (serviceCtxt.getCartridge() == null) {
+                // String msg = "There's no registered Cartridge found. Domain - "
+                // + clusterId;
+                // log.fatal(msg);
+                // throw new CloudControllerException(msg);
+                // }
+
+                // for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) {
+
+                IaasProvider iaas = cartridge.getIaasProviderOfPartition(partitionId);
+
+                // String msg = "Failed to terminate an instance in "
+                // + iaas.getType()
+                // + ". Hence, will try to terminate an instance in another IaaS if possible.";
+                // //TODO adding more locations and retrieve it from the request received
+                // String nodeId = null;
+
+                // IaasContext ctxt = serviceCtxt.getIaasContext(iaas.getType());
+
+                // // terminate the last instance first
+                // for (String id : Lists.reverse(ctxt.getNodeIds())) {
+                // if (id != null) {
+                // nodeId = id;
+                // break;
+                // }
+                // }
 
                 // terminate it!
-                terminate(iaas, ctxt, nodeId, partition);
+                terminate(iaas, nodeId, ctxt);
 
                 // log information
-                logTermination(nodeId, ctxt, serviceCtxt);
+                logTermination(nodeId, ctxt);
+
+            } catch (Exception e) {
+                String msg =
+                             "Starting to terminate an instance with member id : " + memberId +
+                                     " in partition id: " + partitionId + " of cluster id: " +
+                                     clusterId + " and of cartridge type: " + cartridgeType;
+                log.error(msg);
+                throw new CloudControllerException(msg);
             }
 
-
-
-			return true;
-
-		}
-
-		log.info("Termination of an instance which is belong to domain '"
-				+ clusterId
-				+ "' , failed! Reason: No matching "
-				+ "running instance found in any available IaaS.");
-
-		return false;
-
-	}
-
-    @Override
-    public boolean terminateInstances(int noOfInstances, String clusterId, Partition partition) {
-        log.info("vvvvvvvvvvvvvvvvv");
-        return false;  //TODO
+        }
     }
 
-    @Override
-    public boolean terminateUnhealthyInstances(List<String> instancesToBeTerminated) {
-        log.info("vvvvvvvvvvdddvvvvvvv");
-        return false;  //TODO
-    }
+//    private
+//        void
+//        terminateInstance(MemberContext ctxt) throws InvalidCartridgeTypeException,
+//            InvalidMemberException {
+//        // these will never be null, since we do not add null values for these.
+//        String memberId = ctxt.getMemberId();
+//        String clusterId = ctxt.getClusterId();
+//        String partitionId = ctxt.getPartitionId();
+//        String cartridgeType = ctxt.getCartridgeType();
+//        String nodeId = ctxt.getNodeId();
+//        
+//        Cartridge cartridge = dataHolder.getCartridge(cartridgeType);
+//        
+//        log.info("Starting to terminate an instance with member id : " + memberId+
+//                 " in partition id: "+partitionId+" of cluster id: "+clusterId+ " and of cartridge type: "+cartridgeType);
+//        
+//        if(cartridge == null) {
+//            String msg = "Termination of Member Id: "+memberId+" failed. " +
+//                    "Cannot find a matching Cartridge for type: "+cartridgeType;
+//            log.error(msg);
+//            throw new InvalidCartridgeTypeException(msg);
+//        }
+//        
+////        Scope scope = partition.getScope();
+////        String provider = partition.getProperty("provider");
+//
+//		// if no matching node id can be found.
+//        if (nodeId == null) {
+//
+//            String msg = "Termination failed. Cannot find a node id for Member Id: "+memberId;
+//            log.error(msg);
+//            throw new InvalidMemberException(msg);
+//        }
+////		ServiceContext serviceCtxt = dataHolder
+////				.getServiceContextFromDomain(clusterId);
+////
+////		if (serviceCtxt == null) {
+////			String msg = "Not a registered service: domain - " + clusterId;
+////			log.fatal(msg);
+////			throw new CloudControllerException(msg);
+////		}
+////
+////		// load Cartridge, if null
+////		//if (serviceCtxt.getCartridge() == null) {
+////			serviceCtxt.setCartridge(loadCartridge(
+////					serviceCtxt.getCartridgeType(),
+////					dataHolder.getCartridges()));
+////		//}
+////
+////		// if still, Cartridge is null
+////		if (serviceCtxt.getCartridge() == null) {
+////			String msg = "There's no registered Cartridge found. Domain - "
+////					+ clusterId;
+////			log.fatal(msg);
+////			throw new CloudControllerException(msg);
+////		}
+//
+////        for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) {
+//
+//		IaasProvider iaas = cartridge.getIaasProviderOfPartition(partitionId);
+//		
+////			String msg = "Failed to terminate an instance in "
+////					+ iaas.getType()
+////					+ ". Hence, will try to terminate an instance in another IaaS if possible.";
+////            //TODO adding more locations and retrieve it from the request received
+////                String nodeId = null;
+//
+////                IaasContext ctxt = serviceCtxt.getIaasContext(iaas.getType());
+//
+////                // terminate the last instance first
+////                for (String id : Lists.reverse(ctxt.getNodeIds())) {
+////                    if (id != null) {
+////                        nodeId = id;
+////                        break;
+////                    }
+////                }
+//
+//                
+//
+//                // terminate it!
+//                terminate(iaas, nodeId, ctxt);
+//
+//                // log information
+//                logTermination(nodeId, ctxt);
+//    }
+
+//    @Override
+//    public boolean terminateInstances(String[] memberIds) throws IllegalArgumentException, InvalidMemberException, InvalidCartridgeTypeException {
+//        for (String memberId : memberIds) {
+//            terminateInstance(memberId);
+//        }
+//    }
+
+//    @Override
+//    public boolean terminateUnhealthyInstances(List<String> instancesToBeTerminated) {
+//        log.info("vvvvvvvvvvdddvvvvvvv");
+//        return false;  //TODO
+//    }
 
 	@Override
-	public boolean terminateAllInstances(String clusterId) {
+	public void terminateAllInstances(String clusterId) throws IllegalArgumentException, InvalidClusterException {
 
-		boolean isAtLeastOneTerminated = false;
-
-
-		log.info("Starting to terminate all instances of domain : "
+		log.info("Starting to terminate all instances of cluster : "
 				+ clusterId);
-
-		ServiceContext serviceCtxt = dataHolder
-				.getServiceContextFromDomain(clusterId);
-
-		if (serviceCtxt == null) {
-			String msg = "Not a registered service: domain - " + clusterId;
-			log.fatal(msg);
-			throw new CloudControllerException(msg);
-		}
-
-		// load Cartridge, if null
-		serviceCtxt.setCartridge(loadCartridge(
-					serviceCtxt.getCartridgeType(),
-					dataHolder.getCartridges()));
-		//}
-
-		if (serviceCtxt.getCartridge() == null) {
-			String msg = "There's no registered Cartridge found. Domain - "
-					+ clusterId;
-			log.fatal(msg);
-			throw new CloudControllerException(msg);
-		}
-
-        for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) {
-
-			IaasContext ctxt = serviceCtxt.getIaasContext(iaas.getType());
-
-			if (ctxt == null) {
-				log.error("Iaas Context for " + iaas.getType()
-						+ " not found. Cannot terminate instances");
-				continue;
-			}
-
-			ArrayList<String> temp = new ArrayList<String>(ctxt.getNodeIds());
-			for (String id : temp) {
-				if (id != null) {
-					// terminate it!
-                    //TODO need to enable once partition added to the topology
-                    /*Collection<Member> members = TopologyManager.getInstance().getTopology().
-                            getService(serviceCtxt.getCartridgeType()).
-                            getCluster(serviceCtxt.getClusterId()).getMembers();
-                    for (Iterator iterator = members.iterator(); iterator.hasNext();) {
-                         Member member = (Member) iterator.next();
-                         terminate(iaas, ctxt, member.getIaasNodeId(), member.getPartition());
-                    }*/
-
-					// log information
-					logTermination(id, ctxt, serviceCtxt);
-
-					isAtLeastOneTerminated = true;
-				}
-			}
+		
+		if(clusterId == null) {
+		    String msg = "Instance termination failed. Cluster id is null.";
+		    log.error(msg);
+		    throw new IllegalArgumentException(msg);
 		}
-
-		if (isAtLeastOneTerminated) {
-			return true;
+		
+		List<MemberContext> ctxts = dataHolder.getMemberContextsOfClusterId(clusterId);
+		
+		if(ctxts == null) {
+		    String msg = "Instance termination failed. No members found for cluster id: "+clusterId;
+		    log.error(msg);
+		    throw new InvalidClusterException(msg);
 		}
-
-		log.info("Termination of an instance which is belong to domain '"
-				+ clusterId + "', failed! Reason: No matching "
-				+ "running instance found in lastly used IaaS.");
-
-		return false;
+		
+		ThreadExecutor exec = new ThreadExecutor();
+		for (MemberContext memberContext : ctxts) {
+            exec.execute(new InstanceTerminator(memberContext));
+        }
+		
+		exec.shutdown();
+
+//		ServiceContext serviceCtxt = dataHolder
+//				.getServiceContextFromDomain(clusterId);
+//
+//		if (serviceCtxt == null) {
+//			String msg = "Not a registered service: domain - " + clusterId;
+//			log.fatal(msg);
+//			throw new CloudControllerException(msg);
+//		}
+//
+//		// load Cartridge, if null
+//		serviceCtxt.setCartridge(loadCartridge(
+//					serviceCtxt.getCartridgeType(),
+//					dataHolder.getCartridges()));
+//		//}
+//
+//		if (serviceCtxt.getCartridge() == null) {
+//			String msg = "There's no registered Cartridge found. Domain - "
+//					+ clusterId;
+//			log.fatal(msg);
+//			throw new CloudControllerException(msg);
+//		}
+
+//        for (IaasProvider iaas : serviceCtxt.getCartridge().getIaases()) {
+//
+//			IaasContext ctxt = serviceCtxt.getIaasContext(iaas.getType());
+//
+//			if (ctxt == null) {
+//				log.error("Iaas Context for " + iaas.getType()
+//						+ " not found. Cannot terminate instances");
+//				continue;
+//			}
+//
+//			ArrayList<String> temp = new ArrayList<String>(ctxt.getNodeIds());
+//			for (String id : temp) {
+//				if (id != null) {
+//					// terminate it!
+//                    //TODO need to enable once partition added to the topology
+//                    /*Collection<Member> members = TopologyManager.getInstance().getTopology().
+//                            getService(serviceCtxt.getCartridgeType()).
+//                            getCluster(serviceCtxt.getClusterId()).getMembers();
+//                    for (Iterator iterator = members.iterator(); iterator.hasNext();) {
+//                         Member member = (Member) iterator.next();
+//                         terminate(iaas, ctxt, member.getIaasNodeId(), member.getPartition());
+//                    }*/
+//
+//					// log information
+//					logTermination(id, ctxt, serviceCtxt);
+//
+//					isAtLeastOneTerminated = true;
+//				}
+//			}
+//		}
+//
+//		if (isAtLeastOneTerminated) {
+//			return true;
+//		}
+//
+//		log.info("Termination of an instance which is belong to domain '"
+//				+ clusterId + "', failed! Reason: No matching "
+//				+ "running instance found in lastly used IaaS.");
+//
+//		return false;
 
 	}
 
@@ -813,44 +1018,44 @@ public class CloudControllerServiceImpl implements CloudControllerService {
      * @param nodeId
      * @return will return the IaaSProvider
      */
-	private IaasProvider terminate(IaasProvider iaasTemp, IaasContext ctxt,
-			String nodeId, Partition partition) {
-        Scope scope = partition.getScope();
-        String partitionId = partition.getId();
-		// this is just to be safe
-		if (iaasTemp.getComputeService() == null) {
-			String msg = "Unexpeced error occured! IaasContext's ComputeService is null!";
-			log.error(msg);
-			throw new CloudControllerException(msg);
-		}
-
-        if(scope == null || scope.name().equals(Scope.PROVIDER.name())) {
-            iaasTemp.getComputeService().destroyNode(nodeId);
-        } else if(scope.name().equals(Scope.REGION.name())) {
-            for(Region region : iaasTemp.getListOfRegions()) {
-                if(region.getId().equals(partitionId)) {
-                    region.getComputeService();
-                }
-            }
-        } else if(scope.name().equals(Scope.ZONE.name())) {
-            for(Region region : iaasTemp.getListOfRegions()) {
-                for(Zone zone : region.getListOfZones()) {
-                   if(zone.getId().equals(partitionId)) {
-                        zone.getComputeService().destroyNode(nodeId);
-                   }
-                }
-            }
-        } else if(scope.name().equals(Scope.HOST.name())) {
-            for(Region region : iaasTemp.getListOfRegions()) {
-                for(Zone zone : region.getListOfZones()) {
-                    for(Host host: zone.getListOfHosts()) {
-                        if(host.getId().equals(partitionId)) {
-                            host.getComputeService().destroyNode(nodeId);
-                        }
-                    }
-                }
-            }
-        }
+	private IaasProvider terminate(IaasProvider iaasTemp, 
+			String nodeId, MemberContext ctxt) {
+//        Scope scope = partition.getScope();
+//        String partitionId = partition.getId();
+//		// this is just to be safe
+//		if (iaasTemp.getComputeService() == null) {
+//			String msg = "Unexpeced error occured! IaasContext's ComputeService is null!";
+//			log.error(msg);
+//			throw new CloudControllerException(msg);
+//		}
+//
+//        if(scope == null || scope.name().equals(Scope.PROVIDER.name())) {
+//            iaasTemp.getComputeService().destroyNode(nodeId);
+//        } else if(scope.name().equals(Scope.REGION.name())) {
+//            for(Region region : iaasTemp.getListOfRegions()) {
+//                if(region.getId().equals(partitionId)) {
+//                    region.getComputeService();
+//                }
+//            }
+//        } else if(scope.name().equals(Scope.ZONE.name())) {
+//            for(Region region : iaasTemp.getListOfRegions()) {
+//                for(Zone zone : region.getListOfZones()) {
+//                   if(zone.getId().equals(partitionId)) {
+//                        zone.getComputeService().destroyNode(nodeId);
+//                   }
+//                }
+//            }
+//        } else if(scope.name().equals(Scope.HOST.name())) {
+//            for(Region region : iaasTemp.getListOfRegions()) {
+//                for(Zone zone : region.getListOfZones()) {
+//                    for(Host host: zone.getListOfHosts()) {
+//                        if(host.getId().equals(partitionId)) {
+//                            host.getComputeService().destroyNode(nodeId);
+//                        }
+//                    }
+//                }
+//            }
+//        }
 		// destroy the node
 		iaasTemp.getComputeService().destroyNode(nodeId);
 
@@ -863,44 +1068,43 @@ public class CloudControllerServiceImpl implements CloudControllerService {
 						.equals("false"))) {
 			// allocate an IP address - manual IP assigning mode
 			iaasTemp.getIaas().releaseAddress(iaasTemp,
-					ctxt.getPublicIp(nodeId));
+					ctxt.getAllocatedIpAddress());
 		}
+//
+//		// remove the node id
+//		ctxt.removeNodeId(nodeId);
 
-		// remove the node id
-		ctxt.removeNodeId(nodeId);
-
-		dataHolder.updateActiveInstanceCount(iaasTemp.getType(), -1);
+//		dataHolder.updateActiveInstanceCount(iaasTemp.getType(), -1);
 
 		// publish data to BAM
-		CartridgeInstanceDataPublisherTask.publish();
+//		CartridgeInstanceDataPublisherTask.publish();
 
 		log.info("Node with Id: '" + nodeId + "' is terminated!");
 		return iaasTemp;
 	}
 
-	private void logTermination(String nodeId, IaasContext ctxt,
-			ServiceContext serviceCtxt) {
+	private void logTermination(String nodeId, MemberContext ctxt) {
 
 		// get the ip of the terminated node
-		String ip = ctxt.getPublicIp(nodeId);
-		String ipProp = CloudControllerConstants.PUBLIC_IP_PROPERTY;
-		String ipStr = serviceCtxt.getProperty(ipProp);
-		StringBuilder newIpStr = new StringBuilder("");
-
-		for (String str : ipStr.split(CloudControllerConstants.ENTRY_SEPARATOR)) {
-			if (!str.equals(ip)) {
-				newIpStr.append(str + CloudControllerConstants.ENTRY_SEPARATOR);
-			}
-		}
-
-		// add this ip to the topology
-		serviceCtxt.setProperty(ipProp, newIpStr.length() == 0 ? "" : newIpStr
-				.substring(0, newIpStr.length() - 1).toString());
+//		String ip = ctxt.getPublicIp(nodeId);
+//		String ipProp = CloudControllerConstants.PUBLIC_IP_PROPERTY;
+//		String ipStr = serviceCtxt.getProperty(ipProp);
+//		StringBuilder newIpStr = new StringBuilder("");
+//
+//		for (String str : ipStr.split(CloudControllerConstants.ENTRY_SEPARATOR)) {
+//			if (!str.equals(ip)) {
+//				newIpStr.append(str + CloudControllerConstants.ENTRY_SEPARATOR);
+//			}
+//		}
+//
+//		// add this ip to the topology
+//		serviceCtxt.setProperty(ipProp, newIpStr.length() == 0 ? "" : newIpStr
+//				.substring(0, newIpStr.length() - 1).toString());
         //updating the topology
-        TopologyBuilder.handleMemberTerminated(serviceCtxt.getCartridgeType(), serviceCtxt.getClusterId(), nodeId);
+        TopologyBuilder.handleMemberTerminated(ctxt.getCartridgeType(), ctxt.getClusterId(), nodeId);
 
 		// remove the reference
-		ctxt.removeNodeIdToPublicIp(nodeId);
+//		ctxt.removeNodeIdToPublicIp(nodeId);
 
 		// persist
 		persist();
@@ -954,64 +1158,83 @@ public class CloudControllerServiceImpl implements CloudControllerService {
 
 	@Override
 	public boolean registerService(Registrant registrant)
-			throws UnregisteredCartridgeException {
+			throws UnregisteredCartridgeException, IllegalArgumentException {
 
+	    String cartridgeType = registrant.getCartridgeType();
 	    String clusterId = registrant.getClusterId();
+        String payload = registrant.getPayload();
+        
+        if(cartridgeType == null || clusterId == null || payload == null) {
+	        String msg = "Null Argument/s detected: Cartridge type: "+cartridgeType+", Cluster Id: "+clusterId+", Payload: "+payload;
+	        log.error(msg);
+	        throw new IllegalArgumentException(msg);
+	    }
 	    
-		// create a ServiceContext dynamically
-		ServiceContext newServiceCtxt = new ServiceContext();
-        newServiceCtxt.setClusterId(clusterId);
-		//newServiceCtxt.setSubDomainName(subDomain);
-		newServiceCtxt.setTenantRange(registrant.getTenantRange());
-		newServiceCtxt.setHostName(registrant.getHostName());
-        newServiceCtxt.setAutoScalerPolicyName(registrant.getAutoScalerPolicyName());
-        newServiceCtxt.setPayload(new StringBuilder(registrant.getPayload()));
-        Properties properties = registrant.getProperties();
-        String cartridgeType = registrant.getCartridgeType();
-
-		if (properties != null && properties.getProperties() != null) {
-			// add properties
-			for (Property property : properties.getProperties()) {
-				if (property != null && property.getName() != null) {
-					newServiceCtxt.setProperty(property.getName(),
-							property.getValue());
-				}
-			}
-		}
+        if (dataHolder.getCartridge(cartridgeType) == null) {
 
-		newServiceCtxt.setCartridgeType(cartridgeType);
-
-		for (Cartridge cartridge : dataHolder
-				.getCartridges()) {
-			if (cartridge.getType().equals(cartridgeType)) {
-				newServiceCtxt.setCartridge(cartridge);
-				break;
-			}
-		}
-
-		if (newServiceCtxt.getCartridge() == null) {
-			String msg = "Registration failed - Unregistered Cartridge type: "
-					+ cartridgeType;
-			log.error(msg);
-			throw new UnregisteredCartridgeException(msg);
-		}
-		// persist
-        String uniqueName = clusterId + "-"
-                + UUID.randomUUID() + ".xml";
-        newServiceCtxt.setPayloadFile("/tmp/" + CloudControllerConstants.PAYLOAD_NAME + ".zip");
-        newServiceCtxt.generatePayload();
-        dataHolder.addServiceContext(newServiceCtxt);
-        // notify consumer by adding services
-        TopologyBuilder.handleClusterCreated(newServiceCtxt);
-        try {
-            FileUtils.writeStringToFile(new File(CloudControllerConstants.SERVICES_DIR + uniqueName),
-                                            newServiceCtxt.toXml());
-        } catch (IOException e) {
-            log.error("couldn't write the service definition", e);
-            throw new CloudControllerException("couldn't write the service definition", e);
+            String msg = "Registration of cluster: "+clusterId+
+                    " failed. - Unregistered Cartridge type: " + cartridgeType;
+            log.error(msg);
+            throw new UnregisteredCartridgeException(msg);
         }
-        log.info("Service successfully registered! Domain - " + clusterId
-                + ", Cartridge type - " + cartridgeType);
+        
+	    dataHolder.addClusterContext(new ClusterContext(clusterId, cartridgeType, payload));
+	    TopologyBuilder.handleClusterCreated(registrant);
+	    
+//		// create a ServiceContext dynamically
+//		ServiceContext newServiceCtxt = new ServiceContext();
+//        newServiceCtxt.setClusterId(clusterId);
+//		//newServiceCtxt.setSubDomainName(subDomain);
+//		newServiceCtxt.setTenantRange(registrant.getTenantRange());
+//		newServiceCtxt.setHostName(registrant.getHostName());
+//        newServiceCtxt.setAutoScalerPolicyName(registrant.getAutoScalerPolicyName());
+//        newServiceCtxt.setPayload(new StringBuilder(registrant.getPayload()));
+//        Properties properties = registrant.getProperties();
+//        String cartridgeType = registrant.getCartridgeType();
+//
+//		if (properties != null && properties.getProperties() != null) {
+//			// add properties
+//			for (Property property : properties.getProperties()) {
+//				if (property != null && property.getName() != null) {
+//					newServiceCtxt.setProperty(property.getName(),
+//							property.getValue());
+//				}
+//			}
+//		}
+//
+//		newServiceCtxt.setCartridgeType(cartridgeType);
+//
+//		for (Cartridge cartridge : dataHolder
+//				.getCartridges()) {
+//			if (cartridge.getType().equals(cartridgeType)) {
+//				newServiceCtxt.setCartridge(cartridge);
+//				break;
+//			}
+//		}
+//
+//		if (newServiceCtxt.getCartridge() == null) {
+//			String msg = "Registration failed - Unregistered Cartridge type: "
+//					+ cartridgeType;
+//			log.error(msg);
+//			throw new UnregisteredCartridgeException(msg);
+//		}
+//		// persist
+//        String uniqueName = clusterId + "-"
+//                + UUID.randomUUID() + ".xml";
+//        newServiceCtxt.setPayloadFile("/tmp/" + CloudControllerConstants.PAYLOAD_NAME + ".zip");
+//        newServiceCtxt.generatePayload();
+//        dataHolder.addServiceContext(newServiceCtxt);
+//        // notify consumer by adding services
+//        TopologyBuilder.handleClusterCreated(newServiceCtxt);
+//        try {
+//            FileUtils.writeStringToFile(new File(CloudControllerConstants.SERVICES_DIR + uniqueName),
+//                                            newServiceCtxt.toXml());
+//        } catch (IOException e) {
+//            log.error("couldn't write the service definition", e);
+//            throw new CloudControllerException("couldn't write the service definition", e);
+//        }
+//        log.info("Service successfully registered! Domain - " + clusterId
+//                + ", Cartridge type - " + cartridgeType);
 
 		return true;
 	}
@@ -1067,26 +1290,112 @@ public class CloudControllerServiceImpl implements CloudControllerService {
 	}
 
     @Override
-	public boolean unregisterService(String clusterId)
-			throws UnregisteredServiceException {
+	public void unregisterService(String clusterId) throws UnregisteredClusterException {
+        ClusterContext ctxt = dataHolder.getClusterContext(clusterId);
+        
+        if(ctxt == null) {
+            String msg = "Unregistration of service cluster failed. Cluster not found: "+clusterId;
+            log.error(msg);
+            throw new UnregisteredClusterException(msg);
+        }
+        
+        TopologyBuilder.handleClusterRemoved(ctxt);
 
+        dataHolder.removeClusterContext(clusterId);
+        dataHolder.removeMemberContext(clusterId);
+        
 		//subDomain = checkSubDomain(subDomain);
 
 		// find the service context
-		ServiceContext subjectedSerCtxt = dataHolder
-				.getServiceContextFromDomain(clusterId);
-        TopologyBuilder.handleClusterRemoved(subjectedSerCtxt);
+//		ServiceContext subjectedSerCtxt = dataHolder
+//				.getServiceContextFromDomain(clusterId);
+        
+        
+        
+//        TopologyBuilder.handleClusterRemoved(subjectedSerCtxt);
+
+//		if (subjectedSerCtxt == null) {
+//			throw new UnregisteredClusterException(
+//					"No registered service found for domain: " + clusterId);
+//		}
+//
+//		// get the service definition file.
+//		File serviceDefFile = subjectedSerCtxt.getFile();
+//
+//		// delete that file, so that it gets automatically undeployed.
+//		return serviceDefFile.delete();
+	}
 
-		if (subjectedSerCtxt == null) {
-			throw new UnregisteredServiceException(
-					"No registered service found for domain: " + clusterId);
-		}
 
-		// get the service definition file.
-		File serviceDefFile = subjectedSerCtxt.getFile();
+    @Override
+    public boolean validateDeploymentPolicy(String cartridgeType, DeploymentPolicy deploymentPolicy) 
+            throws InvalidPartitionException, InvalidCartridgeTypeException {
+
+        Map<String, IaasProvider> partitionToIaasProviders = new ConcurrentHashMap<String, IaasProvider>();
+        
+        Cartridge cartridge = dataHolder.getCartridge(cartridgeType);
+        
+        if(cartridge == null) {
+            String msg = "Invalid Cartridge Type: "+cartridgeType;
+            log.error(msg);
+            throw new InvalidCartridgeTypeException(msg);
+        }
+        
+        if(deploymentPolicy == null) {
+            String msg = "Deployment Policy is null.";
+            log.error(msg);
+            throw new InvalidPartitionException(msg);
+        }
+        
+        for (PartitionGroup partitionGroup : deploymentPolicy.getPartitionGroups()) {
+            for (Partition partition : partitionGroup.getPartitions()) {
+                String provider = partition.getProvider();
+                IaasProvider iaasProvider = cartridge.getIaasProvider(provider);
+                
+                if(iaasProvider == null) {
+                    String msg = "Invalid Partition - "+partition.toString() +", in "+deploymentPolicy.toString()+
+                            ". Cause: Iaas Provider is null for: "+provider;
+                    log.error(msg);
+                    throw new InvalidPartitionException(msg);
+                }
+                
+                Iaas iaas = iaasProvider.getIaas();
+                PartitionValidator validator = iaas.getPartitionValidator();
+                validator.setIaasProvider(iaasProvider);
+                IaasProvider updatedIaasProvider = validator.validate(partition.getId(), 
+                                 CloudControllerUtil.toJavaUtilProperties(partition.getProperties()));
+                // add to a temporary Map
+                partitionToIaasProviders.put(partition.getId(), updatedIaasProvider);
+                
+            }
+        }
+        
+        // if and only if the deployment policy valid
+        cartridge.addIaasProviders(partitionToIaasProviders);
+        
+        return true;
+    }
+
+    @Override
+    public boolean validatePartition(Partition partition) throws InvalidPartitionException {
+        String provider = partition.getProvider();
+        IaasProvider iaasProvider = dataHolder.getIaasProvider(provider);
+
+        if (iaasProvider == null) {
+            String msg =
+                         "Invalid Partition - " + partition.toString()+". Cause: Iaas Provider is null for: "+provider;
+            log.error(msg);
+            throw new InvalidPartitionException(msg);
+        }
+
+        Iaas iaas = iaasProvider.getIaas();
+        PartitionValidator validator = iaas.getPartitionValidator();
+        validator.setIaasProvider(iaasProvider);
+        validator.validate(partition.getId(),
+                           CloudControllerUtil.toJavaUtilProperties(partition.getProperties()));
+        TopologyBuilder.handlePartitionCreated(partition);
 
-		// delete that file, so that it gets automatically undeployed.
-		return serviceDefFile.delete();
-	}
+        return true;
+    }
 
 }

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/interfaces/CloudControllerService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java
index eac4281..9494007 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java
@@ -18,21 +18,42 @@
  */
 package org.apache.stratos.cloud.controller.interfaces;
 
+import org.apache.stratos.cloud.controller.exception.InvalidCartridgeTypeException;
+import org.apache.stratos.cloud.controller.exception.InvalidClusterException;
+import org.apache.stratos.cloud.controller.exception.InvalidMemberException;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
 import org.apache.stratos.cloud.controller.exception.UnregisteredCartridgeException;
-import org.apache.stratos.cloud.controller.exception.UnregisteredServiceException;
+import org.apache.stratos.cloud.controller.exception.UnregisteredClusterException;
 import org.apache.stratos.cloud.controller.pojo.Registrant;
 import org.apache.stratos.cloud.controller.util.CartridgeInfo;
-import org.apache.stratos.messaging.domain.topology.Partition;
-
-import java.util.List;
+import org.apache.stratos.messaging.domain.policy.DeploymentPolicy;
+import org.apache.stratos.messaging.domain.policy.Partition;
 
 /**
- * This Interface provides a way to communicate with underline
- * Infrastructure which are supported by <i>JClouds</i>.
+ * This API provides a way to communicate with underline
+ * Infrastructure which are supported by <i>jClouds</i>.
  * 
  */
 public interface CloudControllerService {
 
+    /**
+     * Validate a given {@link Partition} for basic property existence.
+     * @param partition partition to be validated.
+     * @return whether the partition is a valid one.
+     * @throws InvalidPartitionException if the partition is invalid.
+     */
+    public boolean validatePartition(Partition partition) throws InvalidPartitionException;
+    
+    /**
+     * Validate a given {@link DeploymentPolicy} against a Cartridge.
+     * @param cartridgeType type of the cartridge that this policy is going to be attached to.
+     * @param deploymentPolicy policy to be validated.
+     * @return whether the policy is a valid one against the given Cartridge.
+     * @throws InvalidPartitionException if the policy contains at least one invalid partition.
+     * @throws InvalidCartridgeTypeException if the given Cartridge type is not a valid one.
+     */
+    public boolean validateDeploymentPolicy(String cartridgeType, DeploymentPolicy deploymentPolicy) 
+            throws InvalidPartitionException, InvalidCartridgeTypeException;
 
     /**
      * <p>
@@ -40,14 +61,15 @@ public interface CloudControllerService {
      * present service cluster, if there is any. A service cluster is uniquely identified by its
      * domain and sub domain combination.
      * </p>
-     * @param registrant information about the new subscription.
+     * @param clusterContext information about the new subscription.
      * @return whether the registration is successful or not.
      * 
      * @throws UnregisteredCartridgeException
      *             when the cartridge type requested by this service is
      *             not a registered one.
      */
-    public boolean registerService(Registrant registrant) throws UnregisteredCartridgeException;
+    public boolean registerService(Registrant registrant) throws UnregisteredCartridgeException, 
+    IllegalArgumentException;
 
     /**
      * Calling this method will result in an instance startup, which is belong
@@ -62,7 +84,7 @@ public interface CloudControllerService {
      *            an instance need to be started.
      * @return public IP which is associated with the newly started instance.
      */
-    public String startInstance(String clusterId, Partition partition);
+    public String startInstance(String clusterId, Partition partition) throws IllegalArgumentException, UnregisteredCartridgeException;
 
     /**
      * Calling this method will spawn more than one ininstances in the
@@ -77,7 +99,20 @@ public interface CloudControllerService {
      *            an instance need to be started.
      * @return public IP which is associated with the newly started instance.
      */
-    public String startInstances(String clusterId, Partition partition, int noOfInstancesToBeSpawned);
+//    public String startInstances(String clusterId, Partition partition, int noOfInstancesToBeSpawned);
+    
+    /**
+     * Calling this method will result in termination of the instance with given member id in the given Partition.
+     * 
+     * @param memberId
+     *            member ID of the instance to be terminated.
+     * @param partition
+     *            It contains the region, zone, network and host of a IaaS where
+     *            an instance need to be terminated..
+     * @return whether an instance terminated successfully or not.
+     */
+    public void terminateInstance(String memberId) throws InvalidMemberException, InvalidCartridgeTypeException, 
+    IllegalArgumentException;
     
     /**
      * Calling this method will result in termination of an instance which is belong
@@ -90,7 +125,7 @@ public interface CloudControllerService {
      *            an instance need to be terminated..
      * @return whether an instance terminated successfully or not.
      */
-    public boolean terminateInstance(String clusterId, Partition partition);
+//    public boolean terminateInstance(String clusterId, Partition partition);
 
     /**
      * Calling this method will result in termination of an instance which is belong
@@ -105,17 +140,17 @@ public interface CloudControllerService {
      *            an instance need to be terminated..
      * @return whether an instance terminated successfully or not.
      */
-    public boolean terminateInstances(int noOfInstances, String clusterId, Partition partition);
+//    public boolean terminateInstances(String[] memberIds);
 
-     /**
-     * Calling this method will result in termination of an instance which is belong
-     * to the provided instance Id.
-     *
-     * @param instancesToBeTerminated
-     *            list of instance Ids to be terminated.
-     * @return whether an instance terminated successfully or not.
-     */
-    public boolean terminateUnhealthyInstances(List<String> instancesToBeTerminated);
+//     /**
+//     * Calling this method will result in termination of an instance which is belong
+//     * to the provided instance Id.
+//     *
+//     * @param instancesToBeTerminated
+//     *            list of instance Ids to be terminated.
+//     * @return whether an instance terminated successfully or not.
+//     */
+//    public boolean terminateUnhealthyInstances(List<String> instancesToBeTerminated);
 
     /**
      * Calling this method will result in termination of all instances belong
@@ -125,16 +160,16 @@ public interface CloudControllerService {
      *            cluster ID of the instance to be terminated.
      * @return whether an instance terminated successfully or not.
      */
-    public boolean terminateAllInstances(String clusterId);
+    public void terminateAllInstances(String clusterId) throws IllegalArgumentException, InvalidClusterException;
 
     /**
     /**
      * Unregister the service cluster which represents by this domain and sub domain.
      * @param clusterId service cluster domain
      * @return whether the unregistration was successful or not.
-     * @throws org.apache.stratos.cloud.controller.exception.UnregisteredServiceException if the service cluster requested is not a registered one.
+     * @throws org.apache.stratos.cloud.controller.exception.UnregisteredClusterException if the service cluster requested is not a registered one.
      */
-    public boolean unregisterService(String clusterId) throws UnregisteredServiceException;
+    public void unregisterService(String clusterId) throws UnregisteredClusterException;
     
     /**
      * This method will return the information regarding the given cartridge, if present.
@@ -147,16 +182,16 @@ public interface CloudControllerService {
      */
     public CartridgeInfo getCartridgeInfo(String cartridgeType) throws UnregisteredCartridgeException;
 
-    /**
-     * Calling this method will result in returning the pending instances
-     * count of a particular domain.
-     * 
-     * @param clusterId
-     *            service cluster domain
-     * @return number of pending instances for this domain. If no instances of this
-     *         domain is present, this will return zero.
-     */
-    public int getPendingInstanceCount(String clusterId);
+//    /**
+//     * Calling this method will result in returning the pending instances
+//     * count of a particular domain.
+//     * 
+//     * @param clusterId
+//     *            service cluster domain
+//     * @return number of pending instances for this domain. If no instances of this
+//     *         domain is present, this will return zero.
+//     */
+//    public int getPendingInstanceCount(String clusterId);
 
     /**
      * Calling this method will result in returning the types of {@link org.apache.stratos.cloud.controller.util.Cartridge}s

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/interfaces/Iaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/Iaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/Iaas.java
index 4b36226..e652cf2 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/Iaas.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/Iaas.java
@@ -21,6 +21,9 @@ package org.apache.stratos.cloud.controller.interfaces;
 import org.jclouds.compute.ComputeService;
 import org.jclouds.compute.domain.NodeMetadata;
 import org.jclouds.compute.domain.Template;
+import org.apache.stratos.cloud.controller.exception.InvalidHostException;
+import org.apache.stratos.cloud.controller.exception.InvalidRegionException;
+import org.apache.stratos.cloud.controller.exception.InvalidZoneException;
 import org.apache.stratos.cloud.controller.util.IaasProvider;
 import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator;
 
@@ -74,32 +77,35 @@ public abstract class Iaas {
     
     /**
      * Validate a given region name against a particular IaaS.
-     * If a particular IaaS doesn't have a concept called region, it can simply return false.
+     * If a particular IaaS doesn't have a concept called region, it can simply throw {@link InvalidRegionException}.
      * @param iaasInfo {@link IaasProvider} 
      * @param region name of the region.
-     * @return whether the region is valid or not.
+     * @return whether the region is valid.
+     * @throws InvalidRegionException if the region is invalid.
      */
-    public abstract boolean isValidRegion(IaasProvider iaasInfo, String region);
+    public abstract boolean isValidRegion(IaasProvider iaasInfo, String region) throws InvalidRegionException;
     
     /**
      * Validate a given zone name against a particular region in an IaaS.
-     * If a particular IaaS doesn't have a concept called zone, it can simply return false.
+     * If a particular IaaS doesn't have a concept called zone, it can simply throw {@link InvalidZoneException}.
      * @param iaasInfo {@link IaasProvider} 
      * @param region region of the IaaS that the zone belongs to.
      * @param zone 
      * @return whether the zone is valid in the given region or not.
+     * @throws InvalidZoneException if the zone is invalid in a given region.
      */
-    public abstract boolean isValidZone(IaasProvider iaasInfo, String region, String zone);
+    public abstract boolean isValidZone(IaasProvider iaasInfo, String region, String zone) throws InvalidZoneException;
     
     /**
      * Validate a given host id against a particular zone in an IaaS.
-     * If a particular IaaS doesn't have a concept called hosts, it can simply return false.
+     * If a particular IaaS doesn't have a concept called hosts, it can simply throw {@link InvalidHostException}.
      * @param iaasInfo {@link IaasProvider} 
      * @param zone zone of the IaaS that the host belongs to.
      * @param host
      * @return whether the host is valid in the given zone or not.
+     * @throws InvalidHostException if the host is invalid in a given zone.
      */
-    public abstract boolean isValidHost(IaasProvider iaasInfo, String zone, String host);
+    public abstract boolean isValidHost(IaasProvider iaasInfo, String zone, String host) throws InvalidHostException;
     
     /**
      * provides the {@link PartitionValidator} corresponds to this particular IaaS.

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/pojo/ClusterContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java
new file mode 100644
index 0000000..c462728
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java
@@ -0,0 +1,60 @@
+/*
+ * 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.pojo;
+
+/**
+ * Holds runtime data of a Cluster.
+ * @author nirmal
+ *
+ */
+public class ClusterContext {
+
+    // cluster id
+    private String clusterId;
+    // cartridge type
+    private String cartridgeType;
+    // payload as a String
+    private String payload;
+    
+    public ClusterContext(String clusterId, String cartridgeType, String payload) {
+        this.clusterId = clusterId;
+        this.cartridgeType = cartridgeType;
+        this.payload = payload;
+    }
+    
+    public String getClusterId() {
+        return clusterId;
+    }
+    public void setClusterId(String clusterId) {
+        this.clusterId = clusterId;
+    }
+    public String getCartridgeType() {
+        return cartridgeType;
+    }
+    public void setCartridgeType(String cartridgeType) {
+        this.cartridgeType = cartridgeType;
+    }
+    public String getPayload() {
+        return payload;
+    }
+    public void setPayload(String payload) {
+        this.payload = payload;
+    }
+    
+}

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/pojo/MemberContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/MemberContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/MemberContext.java
new file mode 100644
index 0000000..64fd3c2
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/MemberContext.java
@@ -0,0 +1,89 @@
+/*
+ * 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.pojo;
+
+/**
+ * Holds runtime data of a Member.
+ * @author nirmal
+ *
+ */
+public class MemberContext {
+
+    // id of the member
+    private String memberId;
+    // corresponding jclouds node id
+    private String nodeId;
+    // cluster id of this member
+    private String clusterId;
+    // partition id this member is in.
+    private String partitionId;
+    // cartridge type this member belongs to.
+    private String cartridgeType;
+    // allocated ip
+    private String allocatedIpAddress;
+    
+    public MemberContext(String id, String nodeId, String clusterId, String partitionId, String cartridgeType, String ip) {
+        this.memberId = id;
+        this.nodeId = nodeId;
+        this.clusterId = clusterId;
+        this.partitionId = partitionId;
+        this.cartridgeType = cartridgeType;
+        this.allocatedIpAddress = ip;
+        
+    }
+    
+    public String getMemberId() {
+        return memberId;
+    }
+    public void setMemberId(String memberId) {
+        this.memberId = memberId;
+    }
+    public String getNodeId() {
+        return nodeId;
+    }
+    public void setNodeId(String nodeId) {
+        this.nodeId = nodeId;
+    }
+    public String getClusterId() {
+        return clusterId;
+    }
+    public void setClusterId(String clusterId) {
+        this.clusterId = clusterId;
+    }
+    public String getPartitionId() {
+        return partitionId;
+    }
+    public void setPartitionId(String partitionId) {
+        this.partitionId = partitionId;
+    }
+    public String getCartridgeType() {
+        return cartridgeType;
+    }
+    public void setCartridgeType(String cartridgeType) {
+        this.cartridgeType = cartridgeType;
+    }
+    public String getAllocatedIpAddress() {
+        return allocatedIpAddress;
+    }
+    public void setAllocatedIpAddress(String allocatedIpAddress) {
+        this.allocatedIpAddress = allocatedIpAddress;
+    }
+    
+    
+}

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/pojo/Registrant.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Registrant.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Registrant.java
index e9bc8c2..812abaf 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Registrant.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Registrant.java
@@ -18,7 +18,7 @@
  */
 package org.apache.stratos.cloud.controller.pojo;
 
-import org.apache.stratos.cloud.controller.util.Properties;
+import org.apache.stratos.messaging.util.Properties;
 
 /**
  * Upon a new subscription, Stratos Manager would send this POJO.
@@ -29,30 +29,18 @@ public class Registrant {
 
     private String clusterId;
     private String tenantRange;
-    private String cartridgeType;
     private String hostName;
-    private Properties properties;
+    private String cartridgeType;
     private String payload;
+    private Properties properties;
     private String autoScalerPolicyName;
     
-    public String getClusterId() {
-        return clusterId;
-    }
-    public void setClusterId(String clusterId) {
-        this.clusterId = clusterId;
-    }
     public String getTenantRange() {
         return tenantRange;
     }
     public void setTenantRange(String tenantRange) {
         this.tenantRange = tenantRange;
     }
-    public String getCartridgeType() {
-        return cartridgeType;
-    }
-    public void setCartridgeType(String cartridgeType) {
-        this.cartridgeType = cartridgeType;
-    }
     public String getHostName() {
         return hostName;
     }
@@ -65,17 +53,29 @@ public class Registrant {
     public void setProperties(Properties properties) {
         this.properties = properties;
     }
-    public String getPayload() {
-        return payload;
-    }
-    public void setPayload(String payload) {
-        this.payload = payload;
-    }
     public String getAutoScalerPolicyName() {
         return autoScalerPolicyName;
     }
     public void setAutoScalerPolicyName(String autoScalerPolicyName) {
         this.autoScalerPolicyName = autoScalerPolicyName;
     }
+    public String getClusterId() {
+        return clusterId;
+    }
+    public void setClusterId(String clusterId) {
+        this.clusterId = clusterId;
+    }
+    public String getCartridgeType() {
+        return cartridgeType;
+    }
+    public void setCartridgeType(String cartridgeType) {
+        this.cartridgeType = cartridgeType;
+    }
+    public String getPayload() {
+        return payload;
+    }
+    public void setPayload(String payload) {
+        this.payload = payload;
+    }
     
 }

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/publisher/CartridgeInstanceDataPublisherTask.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/CartridgeInstanceDataPublisherTask.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/CartridgeInstanceDataPublisherTask.java
index 11347ec..dcc1042 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/CartridgeInstanceDataPublisherTask.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/CartridgeInstanceDataPublisherTask.java
@@ -265,8 +265,8 @@ public class CartridgeInstanceDataPublisherTask implements Task{
         String trustStorePath = serverConfig.getFirstProperty("Security.TrustStore.Location");
         String trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password");
         String bamServerUrl = serverConfig.getFirstProperty("BamServerURL");
-        String adminUsername = FasterLookUpDataHolder.getInstance().getBamUsername();
-        String adminPassword = FasterLookUpDataHolder.getInstance().getBamPassword();
+        String adminUsername = FasterLookUpDataHolder.getInstance().getDataPubConfig().getBamUsername();
+        String adminPassword = FasterLookUpDataHolder.getInstance().getDataPubConfig().getBamPassword();
 
         System.setProperty("javax.net.ssl.trustStore", trustStorePath);
         System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);