stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject [49/50] [abbrv] Merge branch '4.0.0-grouping' into docker-grouping-merge
Date Thu, 30 Oct 2014 04:14:13 GMT
http://git-wip-us.apache.org/repos/asf/stratos/blob/17cc86eb/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
index 227790a,6e003b1..3d7be2a
--- 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
@@@ -20,13 -20,12 +20,10 @@@ package org.apache.stratos.cloud.contro
  
  import com.google.common.collect.ImmutableSet;
  import com.google.common.net.InetAddresses;
  import org.apache.commons.lang.StringUtils;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
 -import org.apache.stratos.cloud.controller.application.parser.DefaultApplicationParser;
  import org.apache.stratos.cloud.controller.concurrent.PartitionValidatorCallable;
- import org.apache.stratos.cloud.controller.concurrent.ScheduledThreadExecutor;
  import org.apache.stratos.cloud.controller.concurrent.ThreadExecutor;
  import org.apache.stratos.cloud.controller.deployment.partition.Partition;
  import org.apache.stratos.cloud.controller.exception.*;
@@@ -44,15 -42,8 +40,16 @@@ import org.apache.stratos.cloud.control
  import org.apache.stratos.cloud.controller.topology.TopologyManager;
  import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
  import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
 +import org.apache.stratos.cloud.controller.util.PodActivationWatcher;
  import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator;
 +import org.apache.stratos.common.constants.StratosConstants;
 +import org.apache.stratos.kubernetes.client.KubernetesApiClient;
 +import org.apache.stratos.kubernetes.client.exceptions.KubernetesClientException;
 +import org.apache.stratos.kubernetes.client.model.Label;
 +import org.apache.stratos.kubernetes.client.model.Pod;
 +import org.apache.stratos.kubernetes.client.model.ReplicationController;
 +import org.apache.stratos.kubernetes.client.model.Service;
+ import org.apache.stratos.messaging.domain.topology.Application;
  import org.apache.stratos.messaging.domain.topology.Member;
  import org.apache.stratos.messaging.domain.topology.MemberStatus;
  import org.apache.stratos.messaging.util.Constants;
@@@ -77,61 -67,67 +74,62 @@@ import java.util.concurrent.Future
   */
  public class CloudControllerServiceImpl implements CloudControllerService {
  
- 	private static final Log LOG = LogFactory
 -    private static final Log log = LogFactory
 -            .getLog(CloudControllerServiceImpl.class);
 -    private FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder
 -            .getInstance();
 -
 -    public CloudControllerServiceImpl() {
 -        // acquire serialized data from registry
 -        acquireData();
 -    }
 -
 -    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.setClusterIdToContext(serializedObj.getClusterIdToContext());
 -                    currentData.setMemberIdToContext(serializedObj.getMemberIdToContext());
 -                    currentData.setClusterIdToMemberContext(serializedObj.getClusterIdToMemberContext());
 -                    currentData.setCartridges(serializedObj.getCartridges());
++	private static final Log log = LogFactory
 +			.getLog(CloudControllerServiceImpl.class);
 +	private FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder
 +			.getInstance();
 +
 +	public CloudControllerServiceImpl() {
 +		// acquire serialized data from registry
 +		acquireData();
 +	}
 +
 +	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.setClusterIdToContext(serializedObj.getClusterIdToContext());
 +					currentData.setMemberIdToContext(serializedObj.getMemberIdToContext());
 +					currentData.setClusterIdToMemberContext(serializedObj.getClusterIdToMemberContext());
 +					currentData.setCartridges(serializedObj.getCartridges());
 +					currentData.setKubClusterIdToKubClusterContext(serializedObj.getKubClusterIdToKubClusterContext());
+                     currentData.setServiceGroups(serializedObj.getServiceGroups());
  
- 					if(LOG.isDebugEnabled()) {
+                     if(log.isDebugEnabled()) {
 +					    
- 					    LOG.debug("Cloud Controller Data is retrieved from registry.");
++					    log.debug("Cloud Controller Data is retrieved from registry.");
 +					}
 +				} else {
- 				    if(LOG.isDebugEnabled()) {
++				    if(log.isDebugEnabled()) {
 +				        
- 				        LOG.debug("Cloud Controller Data cannot be found in registry.");
++				        log.debug("Cloud Controller Data cannot be found in registry.");
 +				    }
 +				}
 +			} catch (Exception e) {
  
 -                        log.debug("Cloud Controller Data is retrieved from registry.");
 -                    }
 -                } else {
 -                    if(log.isDebugEnabled()) {
 -
 -                        log.debug("Cloud Controller Data cannot be found 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);
++				log.warn(msg, e);
 +			}
  
 -                String msg = "Unable to acquire data from Registry. Hence, any historical data will not get reflected.";
 -                log.warn(msg, e);
 -            }
 +		}
 +	}
  
 -        }
 +    public void deployCartridgeDefinition(CartridgeConfig cartridgeConfig) throws InvalidCartridgeDefinitionException, 
 +    InvalidIaasProviderException {
          
 -    }
 -
 -
 -    public void deployCartridgeDefinition(CartridgeConfig cartridgeConfig) throws InvalidCartridgeDefinitionException,
 -            InvalidIaasProviderException {
 -        if (cartridgeConfig == null) {
 -            String msg = "Invalid Cartridge Definition: Definition is null.";
 -            log.error(msg);
 -            throw new IllegalArgumentException(msg);
 -
 -        }
 +        handleNullObject(cartridgeConfig, "Invalid Cartridge Definition: Definition is null.");
  
-         if(LOG.isDebugEnabled()){
-             LOG.debug("Cartridge definition: " + cartridgeConfig.toString());
+         if(log.isDebugEnabled()){
+             log.debug("Cartridge definition: " + cartridgeConfig.toString());
          }
  
          Cartridge cartridge = null;
@@@ -140,10 -135,10 +138,10 @@@
              cartridge = CloudControllerUtil.toCartridge(cartridgeConfig);
          } catch (Exception e) {
              String msg =
 -                    "Invalid Cartridge Definition: Cartridge Type: " +
 -                            cartridgeConfig.getType()+
 -                            ". Cause: Cannot instantiate a Cartridge Instance with the given Config. "+e.getMessage();
 +                         "Invalid Cartridge Definition: Cartridge Type: " +
 +                                 cartridgeConfig.getType()+
 +                                 ". Cause: Cannot instantiate a Cartridge Instance with the given Config. "+e.getMessage();
-             LOG.error(msg, e);
+             log.error(msg, e);
              throw new InvalidCartridgeDefinitionException(msg, e);
          }
  
@@@ -191,79 -185,212 +189,207 @@@
      }
  
      private void populateNewCartridge(Cartridge cartridge,
 -                                      Cartridge cartridgeToBeRemoved) {
 -
 -        List<IaasProvider> newIaasProviders = cartridge.getIaases();
 -        Map<String, IaasProvider> oldPartitionToIaasMap = cartridgeToBeRemoved.getPartitionToIaasProvider();
 -
 -        for (String partitionId : oldPartitionToIaasMap.keySet()) {
 -            IaasProvider oldIaasProvider = oldPartitionToIaasMap.get(partitionId);
 -            if (newIaasProviders.contains(oldIaasProvider)) {
 -                if (log.isDebugEnabled()) {
 +			Cartridge cartridgeToBeRemoved) {
 +    	
 +    	List<IaasProvider> newIaasProviders = cartridge.getIaases();
 +    	Map<String, IaasProvider> oldPartitionToIaasMap = cartridgeToBeRemoved.getPartitionToIaasProvider();
 +    	
 +    	for (Entry<String, IaasProvider> entry : oldPartitionToIaasMap.entrySet()) {
 +    	    if (entry == null) {
 +    	        continue;
 +    	    }
 +    	    String partitionId = entry.getKey();
 +			IaasProvider oldIaasProvider = entry.getValue();
 +			if (newIaasProviders.contains(oldIaasProvider)) {
- 				if (LOG.isDebugEnabled()) {
- 					LOG.debug("Copying a partition from the Cartridge that is undeployed, to the new Cartridge. "
++				if (log.isDebugEnabled()) {
+                     log.debug("Copying a partition from the Cartridge that is undeployed, to the new Cartridge. "
 -                            + "[partition id] : "+partitionId+" [cartridge type] "+cartridge.getType() );
 -                }
 -                cartridge.addIaasProvider(partitionId, newIaasProviders.get(newIaasProviders.indexOf(oldIaasProvider)));
 -            }
 -        }
 -
 -    }
 +							+ "[partition id] : "+partitionId+" [cartridge type] "+cartridge.getType() );
 +				}
 +				cartridge.addIaasProvider(partitionId, newIaasProviders.get(newIaasProviders.indexOf(oldIaasProvider)));
 +			}
 +		}
 +		
 +	}
  
 -    public void undeployCartridgeDefinition(String cartridgeType) throws InvalidCartridgeTypeException {
 +	public void undeployCartridgeDefinition(String cartridgeType) throws InvalidCartridgeTypeException {
  
          Cartridge cartridge = null;
          if((cartridge = dataHolder.getCartridge(cartridgeType)) != null) {
              if (dataHolder.getCartridges().remove(cartridge)) {
 -                // invalidate partition validation cache
 -                dataHolder.removeFromCartridgeTypeToPartitionIds(cartridgeType);
 -
 -                if (log.isDebugEnabled()) {
 -                    log.debug("Partition cache invalidated for cartridge "+cartridgeType);
 -                }
 -
 +            	// invalidate partition validation cache
 +            	dataHolder.removeFromCartridgeTypeToPartitionIds(cartridgeType);
 +            	
-             	if (LOG.isDebugEnabled()) {
-             		LOG.debug("Partition cache invalidated for cartridge "+cartridgeType);
++            	if (log.isDebugEnabled()) {
++            		log.debug("Partition cache invalidated for cartridge "+cartridgeType);
 +            	}
 +            	
                  persist();
 -
 +                
                  // sends the service removed event
                  List<Cartridge> cartridgeList = new ArrayList<Cartridge>();
                  cartridgeList.add(cartridge);
                  TopologyBuilder.handleServiceRemoved(cartridgeList);
 -
 +                
-                 if(LOG.isInfoEnabled()) {
-                     LOG.info("Successfully undeployed the Cartridge definition: " + cartridgeType);
+                 if(log.isInfoEnabled()) {
+                     log.info("Successfully undeployed the Cartridge definition: " + cartridgeType);
                  }
                  return;
              }
          }
          String msg = "Cartridge [type] "+cartridgeType+" is not a deployed Cartridge type.";
-         LOG.error(msg);
+         log.error(msg);
          throw new InvalidCartridgeTypeException(msg);
      }
 -    
++
+     public void deployServiceGroup(ServiceGroup servicegroup) throws InvalidServiceGroupException {
 -    	
 -    	if (servicegroup == null) {
++
++        if (servicegroup == null) {
+             String msg = "Invalid ServiceGroup Definition: Definition is null.";
+             log.error(msg);
+             throw new IllegalArgumentException(msg);
+ 
+         }
 -    	
 -    	if(log.isDebugEnabled()) {
++
++        if(log.isDebugEnabled()) {
+             log.debug("CloudControllerServiceImpl:deployServiceGroup:" + servicegroup.getName());
+         }
 -    	
 -    	String [] subGroups = servicegroup.getCartridges();
 -    	
+ 
 -    	if(log.isDebugEnabled()) {
++        String [] subGroups = servicegroup.getCartridges();
++
++
++        if(log.isDebugEnabled()) {
+             log.debug("CloudControllerServiceImpl:deployServiceGroup:subGroups" + subGroups);
+             if (subGroups != null) {
 -            	log.debug("CloudControllerServiceImpl:deployServiceGroup:subGroups:size" + subGroups.length);
++                log.debug("CloudControllerServiceImpl:deployServiceGroup:subGroups:size" + subGroups.length);
+             } else {
 -            	log.debug("CloudControllerServiceImpl:deployServiceGroup:subGroups: is null");
++                log.debug("CloudControllerServiceImpl:deployServiceGroup:subGroups: is null");
+             }
+         }
 -    	
 -    	
 -    	Dependencies dependencies = servicegroup.getDependencies();
 -    	
 -    	if(log.isDebugEnabled()) {
++
++
++        Dependencies dependencies = servicegroup.getDependencies();
++
++        if(log.isDebugEnabled()) {
+             log.debug("CloudControllerServiceImpl:deployServiceGroup:dependencies" + dependencies);
+         }
 -    	
 -    	if (dependencies != null) {
 -	    	String [] startupOrders = dependencies.getStartupOrders();
 -	    	
 -	    	if(log.isDebugEnabled()) {
 -	            log.debug("CloudControllerServiceImpl:deployServiceGroup:startupOrders" + startupOrders);
 -	            
 -	            if (startupOrders != null) {
 -	            	log.debug("CloudControllerServiceImpl:deployServiceGroup:startupOrder:size" + startupOrders.length);
 -	            } else {
 -	            	log.debug("CloudControllerServiceImpl:deployServiceGroup:startupOrder: is null");
 -	            }
 -	        }
 -    	}
 -    	
 -    	dataHolder.addServiceGroup(servicegroup);
 -    	
 -    	this.persist();
 -    	
++
++        if (dependencies != null) {
++            String [] startupOrders = dependencies.getStartupOrders();
++
++            if(log.isDebugEnabled()) {
++                log.debug("CloudControllerServiceImpl:deployServiceGroup:startupOrders" + startupOrders);
++
++                if (startupOrders != null) {
++                    log.debug("CloudControllerServiceImpl:deployServiceGroup:startupOrder:size" + startupOrders.length);
++                } else {
++                    log.debug("CloudControllerServiceImpl:deployServiceGroup:startupOrder: is null");
++                }
++            }
++        }
++
++        dataHolder.addServiceGroup(servicegroup);
++
++        this.persist();
++
+     }
 -    
++
+     public void undeployServiceGroup(String name) throws InvalidServiceGroupException {
 -    	if(log.isDebugEnabled()) {
++        if(log.isDebugEnabled()) {
+             log.debug("CloudControllerServiceImpl:undeployServiceGroup: " + name);
+         }
 -    	
++
+         ServiceGroup serviceGroup = null;
 -        
++
+         serviceGroup = dataHolder.getServiceGroup(name);
 -        
++
+         if (serviceGroup  != null) {
+             if (dataHolder.getServiceGroups().remove(serviceGroup)) {
+                 persist();
+                 if(log.isInfoEnabled()) {
+                     log.info("Successfully undeployed the Service Group definition: " + serviceGroup);
+                 }
+                 return;
+             }
 -        } 
 -        
++        }
++
+         String msg = "ServiceGroup " + name + " is not a deployed Service Group definition";
+         log.error(msg);
+         throw new InvalidServiceGroupException(msg);
 -    	
++
+     }
 -    
++
+     @Override
+     public ServiceGroup getServiceGroup (String name) throws InvalidServiceGroupException {
 -    	
 -    	if(log.isDebugEnabled()) {
++
++        if(log.isDebugEnabled()) {
+             log.debug("getServiceGroupDefinition:" + name);
+         }
 -    	
 -    	ServiceGroup serviceGroup = this.dataHolder.getServiceGroup(name);
 -    	
 -    	if (serviceGroup == null) {
 -    		if(log.isDebugEnabled()) {
++
++        ServiceGroup serviceGroup = this.dataHolder.getServiceGroup(name);
++
++        if (serviceGroup == null) {
++            if(log.isDebugEnabled()) {
+                 log.debug("getServiceGroupDefinition: no entry found for service group " + name);
+             }
 -    		String msg = "ServiceGroup " + name + " is not a deployed Service Group definition";
 -    		throw new InvalidServiceGroupException(msg);
 -    	}
 -    	
 -    	return serviceGroup;
++            String msg = "ServiceGroup " + name + " is not a deployed Service Group definition";
++            throw new InvalidServiceGroupException(msg);
++        }
++
++        return serviceGroup;
+     }
 -    
++
+     public String [] getServiceGroupSubGroups (String name) throws InvalidServiceGroupException {
 -    	ServiceGroup serviceGroup = this.getServiceGroup(name);
 -    	if (serviceGroup == null) {
 -    		throw new InvalidServiceGroupException("Invalid ServiceGroup " + serviceGroup);
 -    	}
 -    	
 -    	return serviceGroup.getSubGroups();
++        ServiceGroup serviceGroup = this.getServiceGroup(name);
++        if (serviceGroup == null) {
++            throw new InvalidServiceGroupException("Invalid ServiceGroup " + serviceGroup);
++        }
++
++        return serviceGroup.getSubGroups();
+     }
 -    
++
+     /**
 -     * 
++     *
+      */
+     public String [] getServiceGroupCartridges (String name) throws InvalidServiceGroupException {
 -    	ServiceGroup serviceGroup = this.getServiceGroup(name);
 -    	if (serviceGroup == null) {
 -    		throw new InvalidServiceGroupException("Invalid ServiceGroup " + serviceGroup);
 -    	}
 -    	String [] cs = serviceGroup.getCartridges();
 -    	return cs;
 -    	
++        ServiceGroup serviceGroup = this.getServiceGroup(name);
++        if (serviceGroup == null) {
++            throw new InvalidServiceGroupException("Invalid ServiceGroup " + serviceGroup);
++        }
++        String [] cs = serviceGroup.getCartridges();
++        return cs;
++
+     }
 -    
++
+     public Dependencies getServiceGroupDependencies (String name) throws InvalidServiceGroupException {
 -    	ServiceGroup serviceGroup = this.getServiceGroup(name);
 -    	if (serviceGroup == null) {
 -    		throw new InvalidServiceGroupException("Invalid ServiceGroup " + serviceGroup);
 -    	}
 -    	return serviceGroup.getDependencies();
++        ServiceGroup serviceGroup = this.getServiceGroup(name);
++        if (serviceGroup == null) {
++            throw new InvalidServiceGroupException("Invalid ServiceGroup " + serviceGroup);
++        }
++        return serviceGroup.getDependencies();
+     }
 -
 +    
      @Override
      public MemberContext startInstance(MemberContext memberContext) throws
 -            UnregisteredCartridgeException, InvalidIaasProviderException {
 +        UnregisteredCartridgeException, InvalidIaasProviderException {
  
-     	if(LOG.isDebugEnabled()) {
-     		LOG.debug("CloudControllerServiceImpl:startInstance");
 -        if(log.isDebugEnabled()) {
++    	if(log.isDebugEnabled()) {
+             log.debug("CloudControllerServiceImpl:startInstance");
 -        }
 +    	}
  
 -        if (memberContext == null) {
 -            String msg = "Instance start-up failed. Member is null.";
 -            log.error(msg);
 -            throw new IllegalArgumentException(msg);
 -        }
 +    	handleNullObject(memberContext, "Instance start-up failed. Member is null.");
  
          String clusterId = memberContext.getClusterId();
          Partition partition = memberContext.getPartition();
  
 -        if(log.isDebugEnabled()) {
 -            log.debug("Received an instance spawn request : " + memberContext.toString());
 +        if(LOG.isDebugEnabled()) {
 +        	LOG.debug("Received an instance spawn request : " + memberContext);
          }
  
+         ComputeService computeService = null;
          Template template = null;
  
 -        if (partition == null) {
 -            String msg =
 -                    "Instance start-up failed. Specified Partition is null. " +
 -                            memberContext.toString();
 -            log.error(msg);
 -            throw new IllegalArgumentException(msg);
 -        }
 +        handleNullObject(partition, "Instance start-up failed. Specified Partition is null. " +
 +                                 memberContext);
  
          String partitionId = partition.getId();
          ClusterContext ctxt = dataHolder.getClusterContext(clusterId);
@@@ -287,21 -418,21 +413,21 @@@
  
          IaasProvider iaasProvider = cartridge.getIaasProviderOfPartition(partitionId);
          if (iaasProvider == null) {
-         	if (LOG.isDebugEnabled()) {
-         		LOG.debug("IaasToPartitionMap "+cartridge.hashCode()
 -            if (log.isDebugEnabled()) {
++        	if (log.isDebugEnabled()) {
+                 log.debug("IaasToPartitionMap "+cartridge.hashCode()
 -                        + " for cartridge "+cartridgeType+ " and for partition: "+partitionId);
 -            }
 -            String msg = "Instance start-up failed. "
 -                    + "There's no IaaS provided for the partition: "
 -                    + partitionId
 -                    + " and for the Cartridge type: "
 -                    + cartridgeType
 -                    + ". Only following "
 -                    + "partitions can be found in this Cartridge: "
 -                    + cartridge.getPartitionToIaasProvider().keySet()
 -                    .toString() + ". " + memberContext.toString()
 -                    + ". ";
 +        				+ " for cartridge "+cartridgeType+ " and for partition: "+partitionId);
 +        	}
 +			String msg = "Instance start-up failed. "
 +					+ "There's no IaaS provided for the partition: "
 +					+ partitionId
 +					+ " and for the Cartridge type: "
 +					+ cartridgeType
 +					+ ". Only following "
 +					+ "partitions can be found in this Cartridge: "
 +					+ cartridge.getPartitionToIaasProvider().keySet()
 +							.toString() + ". " + memberContext.toString()
 +					+ ". ";
-             LOG.fatal(msg);
+             log.fatal(msg);
              throw new InvalidIaasProviderException(msg);
          }
          String type = iaasProvider.getType();
@@@ -393,16 -589,16 +519,16 @@@
  
      }
  
 -    private void createVolumeAndSetInClusterContext(Volume volume,
 -                                                    IaasProvider iaasProvider) {
 -        // iaas cannot be null at this state #startInstance method
 -        Iaas iaas = iaasProvider.getIaas();
 -        int sizeGB = volume.getSize();
 -        String snapshotId =  volume.getSnapshotId();
 +	private void createVolumeAndSetInClusterContext(Volume volume,
 +			IaasProvider iaasProvider) {
 +		// iaas cannot be null at this state #startInstance method
 +		Iaas iaas = iaasProvider.getIaas();
 +		int sizeGB = volume.getSize();
 +		String snapshotId =  volume.getSnapshotId();
          if(StringUtils.isNotEmpty(volume.getVolumeId())){
              // volumeID is specified, so not creating additional volumes
-             if(LOG.isDebugEnabled()){
-                 LOG.debug("Volume creation is skipping since a volume ID is specified. [Volume ID]" + volume.getVolumeId());
+             if(log.isDebugEnabled()){
+                 log.debug("Volume creation is skipping since a volume ID is specified. [Volume ID]" + volume.getVolumeId());
              }
              volume.setId(volume.getVolumeId());
          }else{
@@@ -415,52 -611,53 +541,52 @@@
  
  
      private StringBuilder getPersistencePayload(ClusterContext ctx, Iaas iaas) {
 -        StringBuilder persistencePayload = new StringBuilder();
 -        if(isPersistenceMappingAvailable(ctx)){
 -            for(Volume volume : ctx.getVolumes()){
 -                if(log.isDebugEnabled()){
 +		StringBuilder persistencePayload = new StringBuilder();
 +		if(isPersistenceMappingAvailable(ctx)){
 +			for(Volume volume : ctx.getVolumes()){
- 				if(LOG.isDebugEnabled()){
- 					LOG.debug("Adding persistence mapping " + volume.toString());
++				if(log.isDebugEnabled()){
+                     log.debug("Adding persistence mapping " + volume.toString());
 -                }
 +				}
                  if(persistencePayload.length() != 0) {
 -                    persistencePayload.append("|");
 +                   persistencePayload.append("|");
                  }
 -
 -                persistencePayload.append(iaas.getIaasDevice(volume.getDevice()));
 -                persistencePayload.append("|");
 +                
 +				persistencePayload.append(iaas.getIaasDevice(volume.getDevice()));
 +				persistencePayload.append("|");
                  persistencePayload.append(volume.getId());
                  persistencePayload.append("|");
                  persistencePayload.append(volume.getMappingPath());
 -            }
 -        }
 +			}
 +		}
-         if(LOG.isDebugEnabled()){
-             LOG.debug("Persistence payload is" + persistencePayload.toString());
+         if(log.isDebugEnabled()){
+             log.debug("Persistence payload is" + persistencePayload.toString());
          }
 -        System.out.println("****** " + persistencePayload);
 -        return persistencePayload;
 -    }
 +		return persistencePayload;
 +	}
  
 -    private boolean isPersistenceMappingAvailable(ClusterContext ctx) {
 -        return ctx.getVolumes() != null && ctx.isVolumeRequired();
 -    }
 +	private boolean isPersistenceMappingAvailable(ClusterContext ctx) {
 +		return ctx.getVolumes() != null && ctx.isVolumeRequired();
 +	}
  
 -    private void addToPayload(StringBuilder payload, String name, String value) {
 -        payload.append(",");
 +	private void addToPayload(StringBuilder payload, String name, String value) {
 +	    payload.append(",");
          payload.append(name+"=" + value);
      }
  
      /**
 -     * 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);
 -        }
 -    }
 +	 * 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);
++			log.fatal(msg);
 +			throw new CloudControllerException(msg, e);
 +		}
 +	}
  
      private String generateMemberId(String clusterId) {
          UUID memberId = UUID.randomUUID();
@@@ -468,19 -665,23 +594,19 @@@
      }
  
      @Override
 -    public void terminateInstance(String memberId) throws InvalidMemberException, InvalidCartridgeTypeException
 +    public void terminateInstance(String memberId) throws InvalidMemberException, InvalidCartridgeTypeException 
      {
  
 -        if(memberId == null) {
 -            String msg = "Termination failed. Null member id.";
 -            log.error(msg);
 -            throw new IllegalArgumentException(msg);
 -        }
 -
 +        handleNullObject(memberId, "Termination failed. Null member id.");
 +        
          MemberContext ctxt = dataHolder.getMemberContextOfMemberId(memberId);
 -
 +        
          if(ctxt == null) {
              String msg = "Termination failed. Invalid Member Id: "+memberId;
-             LOG.error(msg);
+             log.error(msg);
              throw new InvalidMemberException(msg);
          }
 -
 +        
          ThreadExecutor exec = ThreadExecutor.getInstance();
          exec.execute(new InstanceTerminator(ctxt));
  
@@@ -507,16 -708,16 +633,16 @@@
                  // 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 +
+                 log.info("Starting to terminate an instance with member id : " + memberId +
 -                        " in partition id: " + partitionId + " of cluster id: " + clusterId +
 -                        " and of cartridge type: " + cartridgeType);
 +                         " 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;
 +                                 "Termination of Member Id: " + memberId + " failed. " +
 +                                         "Cannot find a matching Cartridge for type: " +
 +                                         cartridgeType;
-                     LOG.error(msg);
+                     log.error(msg);
                      throw new InvalidCartridgeTypeException(msg);
                  }
  
@@@ -524,12 -725,9 +650,12 @@@
                  if (nodeId == null) {
  
                      String msg =
 -                            "Termination failed. Cannot find a node id for Member Id: " +
 -                                    memberId;
 +                                 "Termination failed. Cannot find a node id for Member Id: " +
 +                                         memberId;
 +
 +                    // log information
 +                    logTermination(ctxt);
-                     LOG.error(msg);
+                     log.error(msg);
                      throw new InvalidMemberException(msg);
                  }
  
@@@ -543,8 -741,8 +669,8 @@@
  
              } catch (Exception e) {
                  String msg =
 -                        "Instance termination failed. "+ctxt.toString();
 +                             "Instance termination failed. "+ctxt.toString();
-                 LOG.error(msg, e);
+                 log.error(msg, e);
                  throw new CloudControllerException(msg, e);
              }
  
@@@ -556,9 -754,10 +682,10 @@@
          private MemberContext memberContext;
          private IaasProvider iaasProvider;
          private String cartridgeType;
+         NodeMetadata node;
  
-         public JcloudsInstanceCreator(MemberContext memberContext, IaasProvider iaasProvider, 
-         		String cartridgeType) {
 -        public IpAllocator(MemberContext memberContext, IaasProvider iaasProvider,
 -                           String cartridgeType, NodeMetadata node) {
++        public IpAllocator(MemberContext memberContext, IaasProvider iaasProvider, 
++        		String cartridgeType, NodeMetadata node) {
              this.memberContext = memberContext;
              this.iaasProvider = iaasProvider;
              this.cartridgeType = cartridgeType;
@@@ -769,9 -889,9 +897,9 @@@
  
              } catch (Exception e) {
                  String msg = "Error occurred while allocating an ip address. " + memberContext.toString();
-                 LOG.error(msg, e);
+                 log.error(msg, e);
                  throw new CloudControllerException(msg, e);
 -            }
 +            } 
  
  
          }
@@@ -813,71 -937,65 +941,71 @@@
       * @param nodeId
       * @return will return the IaaSProvider
       */
 -    private IaasProvider terminate(IaasProvider iaasProvider,
 -                                   String nodeId, MemberContext ctxt) {
 -        Iaas iaas = iaasProvider.getIaas();
 -        if (iaas == null) {
 -
 -            try {
 -                iaas = CloudControllerUtil.getIaas(iaasProvider);
 -            } catch (InvalidIaasProviderException e) {
 -                String msg =
 -                        "Instance termination failed. " +ctxt.toString()  +
 -                                ". Cause: Unable to build Iaas of this " + iaasProvider.toString();
 -                log.error(msg, e);
 -                throw new CloudControllerException(msg, e);
 -            }
 -
 -        }
 -
 -        //detach volumes if any
 -        detachVolume(iaasProvider, ctxt);
 -
 -        // destroy the node
 -        iaasProvider.getComputeService().destroyNode(nodeId);
 -
 -        // release allocated IP address
 -        if (ctxt.getAllocatedIpAddress() != null) {
 +	private IaasProvider terminate(IaasProvider iaasProvider, 
 +			String nodeId, MemberContext ctxt) {
 +	    Iaas iaas = iaasProvider.getIaas();
 +	    if (iaas == null) {
 +	        
 +	        try {
 +	            iaas = CloudControllerUtil.getIaas(iaasProvider);
 +	        } catch (InvalidIaasProviderException e) {
 +	            String msg =
 +	                    "Instance termination failed. " +ctxt.toString()  +
 +	                    ". Cause: Unable to build Iaas of this " + iaasProvider.toString();
- 	            LOG.error(msg, e);
++	            log.error(msg, e);
 +	            throw new CloudControllerException(msg, e);
 +	        }
 +	        
 +	    }
 +	    
 +	    //detach volumes if any
 +	    detachVolume(iaasProvider, ctxt);
 +	    
 +		// destroy the node
 +		iaasProvider.getComputeService().destroyNode(nodeId);
 +
 +		// release allocated IP address
 +		if (ctxt.getAllocatedIpAddress() != null) {
              iaas.releaseAddress(ctxt.getAllocatedIpAddress());
 -        }
 -
 -        log.info("Member is terminated: "+ctxt.toString());
 -        return iaasProvider;
 -    }
 -
 -    private void detachVolume(IaasProvider iaasProvider, MemberContext ctxt) {
 -        String clusterId = ctxt.getClusterId();
 -        ClusterContext clusterCtxt = dataHolder.getClusterContext(clusterId);
 -        if (clusterCtxt.getVolumes() != null) {
 -            for (Volume volume : clusterCtxt.getVolumes()) {
 -                try {
 -                    String volumeId = volume.getId();
 -                    if (volumeId == null) {
 -                        return;
 -                    }
 -                    Iaas iaas = iaasProvider.getIaas();
 -                    iaas.detachVolume(ctxt.getInstanceId(), volumeId);
 -                } catch (ResourceNotFoundException ignore) {
 -                    if(log.isDebugEnabled()) {
 -                        log.debug(ignore);
 -                    }
 -                }
 -            }
 -        }
 -    }
 -
 -    private void logTermination(MemberContext memberContext) {
 -
 +		}
 +		
- 		LOG.info("Member is terminated: "+ctxt.toString());
++		log.info("Member is terminated: "+ctxt.toString());
 +		return iaasProvider;
 +	}
 +
 +	private void detachVolume(IaasProvider iaasProvider, MemberContext ctxt) {
 +		String clusterId = ctxt.getClusterId();
 +		ClusterContext clusterCtxt = dataHolder.getClusterContext(clusterId);
 +		if (clusterCtxt.getVolumes() != null) {
 +			for (Volume volume : clusterCtxt.getVolumes()) {
 +				try {
 +					String volumeId = volume.getId();
 +					if (volumeId == null) {
 +						return;
 +					}
 +					Iaas iaas = iaasProvider.getIaas();
 +					iaas.detachVolume(ctxt.getInstanceId(), volumeId);
 +				} catch (ResourceNotFoundException ignore) {
- 					if(LOG.isDebugEnabled()) {
- 						LOG.debug(ignore);
++					if(log.isDebugEnabled()) {
++						log.debug(ignore);
 +					}
 +				}
 +			}
 +		}
 +	}
 +
 +	private void logTermination(MemberContext memberContext) {
 +
 +	    if (memberContext == null) {
 +	        return;
 +	    }
 +	    
 +	    String partitionId = memberContext.getPartition() == null ? null : memberContext.getPartition().getId();
 +	    
          //updating the topology
 -        TopologyBuilder.handleMemberTerminated(memberContext.getCartridgeType(),
 -                memberContext.getClusterId(), memberContext.getNetworkPartitionId(),
 -                memberContext.getPartition().getId(), memberContext.getMemberId());
 +        TopologyBuilder.handleMemberTerminated(memberContext.getCartridgeType(), 
 +        		memberContext.getClusterId(), memberContext.getNetworkPartitionId(), 
 +        		partitionId, memberContext.getMemberId());
  
          //publishing data
          CartridgeInstanceDataPublisher.publish(memberContext.getMemberId(),
@@@ -1290,474 -1393,29 +1418,498 @@@
          return dataHolder.getClusterContext(clusterId);
      }
  
 +	@Override
 +	public MemberContext[] startContainers(ContainerClusterContext containerClusterContext)
 +			throws UnregisteredCartridgeException {
 +		
 +		if(LOG.isDebugEnabled()) {
 +    		LOG.debug("CloudControllerServiceImpl:startContainers");
 +    	}
 +		
 +		handleNullObject(containerClusterContext, "Container start-up failed. ContainerClusterContext is null.");
 +
 +        String clusterId = containerClusterContext.getClusterId();
 +        handleNullObject(clusterId, "Container start-up failed. Cluster id is null.");
 +        
 +        if(LOG.isDebugEnabled()) {
 +        	LOG.debug("Received a container spawn request : " + containerClusterContext.toString());
 +        }
 +
 +        ClusterContext ctxt = dataHolder.getClusterContext(clusterId);
 +        handleNullObject(ctxt, "Container start-up failed. Invalid cluster id. " + containerClusterContext.toString());
 +        
 +        String cartridgeType = ctxt.getCartridgeType();
 +
 +        Cartridge cartridge = dataHolder.getCartridge(cartridgeType);
 +
 +        if (cartridge == null) {
 +            String msg =
 +                         "Instance start-up failed. No matching Cartridge found [type] "+cartridgeType +". "+
 +                                 containerClusterContext.toString();
 +            LOG.error(msg);
 +            throw new UnregisteredCartridgeException(msg);
 +        }
 +
 +        try {
 +            String minReplicas = validateProperty(StratosConstants.KUBERNETES_MIN_REPLICAS, ctxt);
 +            String kubernetesClusterId = validateProperty(StratosConstants.KUBERNETES_CLUSTER_ID, ctxt);
 +            String kubernetesMasterIp = validateProperty(StratosConstants.KUBERNETES_MASTER_IP, containerClusterContext);
 +            String kubernetesPortRange = validateProperty(StratosConstants.KUBERNETES_PORT_RANGE, containerClusterContext);
 +			
 +			KubernetesClusterContext kubClusterContext = getKubernetesClusterContext(kubernetesClusterId, kubernetesMasterIp, kubernetesPortRange);
 +			
 +			KubernetesApiClient kubApi = kubClusterContext.getKubApi();
 +			
 +			// first let's create a replication controller.
 +			ContainerClusterContextToReplicationController controllerFunction = new ContainerClusterContextToReplicationController();
 +			ReplicationController controller = controllerFunction.apply(containerClusterContext);
 +			
 +			if (LOG.isDebugEnabled()) {
 +				LOG.debug("Cloud Controller is delegating request to start a replication controller "+controller+
 +						" for "+ containerClusterContext + " to Kubernetes layer.");
 +			}
 +			
 +			kubApi.createReplicationController(controller);
 +			
 +			if (LOG.isDebugEnabled()) {
 +				LOG.debug("Cloud Controller successfully started the controller "
 +						+ controller + " via Kubernetes layer.");
 +			}
 +			
 +			// secondly let's create a kubernetes service proxy to load balance these containers
 +			ContainerClusterContextToKubernetesService serviceFunction = new ContainerClusterContextToKubernetesService();
 +			Service service = serviceFunction.apply(containerClusterContext);
 +			
 +			if (LOG.isDebugEnabled()) {
 +				LOG.debug("Cloud Controller is delegating request to start a service "+service+
 +						" for "+ containerClusterContext + " to Kubernetes layer.");
 +			}
 +			
 +			kubApi.createService(service);
 +			
 +			// set host port and update
 +			ctxt.addProperty(StratosConstants.ALLOCATED_SERVICE_HOST_PORT, service.getPort());
 +			dataHolder.addClusterContext(ctxt);
 +			
 +			if (LOG.isDebugEnabled()) {
 +				LOG.debug("Cloud Controller successfully started the service "
 +						+ controller + " via Kubernetes layer.");
 +			}
 +			
 +			// create a label query
 +			Label l = new Label();
 +			l.setName(clusterId);
 +			// execute the label query
 +			Pod[] newlyCreatedPods = new Pod[0];
 +			int expectedCount = Integer.parseInt(minReplicas);
 +			
 +			for (int i = 0; i < expectedCount ; i++) {
 +			    newlyCreatedPods = kubApi.getSelectedPods(new Label[]{l});
 +			    
 +			    if (LOG.isDebugEnabled()) {
 +			        
 +			        LOG.debug("Pods Count: "+newlyCreatedPods.length+" for cluster: "+clusterId);
 +			    }
 +			    if(newlyCreatedPods.length == expectedCount) {
 +			        break;
 +			    }
 +			    Thread.sleep(10000);
 +            }
 +
 +			if (newlyCreatedPods.length == 0) {
 +				if (LOG.isDebugEnabled()) {
 +					LOG.debug(String.format("Pods are not created for cluster : %s, hence deleting the service", clusterId));
 +				}
 +				terminateAllContainers(clusterId);
 +				return new MemberContext[0];
 +			}
 +			
 +			if (LOG.isDebugEnabled()) {
 +			    
 +			    LOG.debug(String.format("Pods created : %s for cluster : %s",newlyCreatedPods.length, clusterId));
 +			}
 +			
 +			List<MemberContext> memberContexts = new ArrayList<MemberContext>();
 +			
 +			PodToMemberContext podToMemberContextFunc = new PodToMemberContext();
 +			// generate Member Contexts
 +			for (Pod pod : newlyCreatedPods) {
 +                MemberContext context = podToMemberContextFunc.apply(pod);
 +                context.setCartridgeType(cartridgeType);
 +                context.setClusterId(clusterId);
 +                
 +                context.setProperties(CloudControllerUtil.addProperty(context
 +                        .getProperties(), StratosConstants.ALLOCATED_SERVICE_HOST_PORT,
 +                        String.valueOf(service.getPort())));
 +                
 +                dataHolder.addMemberContext(context);
 +                
 +                // wait till Pod status turns to running and send member spawned.
 +                ScheduledThreadExecutor exec = ScheduledThreadExecutor.getInstance();
 +                if (LOG.isDebugEnabled()) {
 +                    LOG.debug("Cloud Controller is starting the instance start up thread.");
 +                }
 +                dataHolder.addScheduledFutureJob(context.getMemberId(), exec.schedule(new PodActivationWatcher(pod.getId(), context, kubApi), 5000));
 +                
 +                memberContexts.add(context);
 +            }
 +			
 +			// persist in registry
 +			persist();
 +
 +            LOG.info("Kubernetes entities are successfully starting up: " + memberContexts);
 +
 +            return memberContexts.toArray(new MemberContext[0]);
 +
 +        } catch (Exception e) {
 +            String msg = "Failed to start an instance. " + containerClusterContext.toString()+" Cause: "+e.getMessage();
 +            LOG.error(msg, e);
 +            throw new IllegalStateException(msg, e);
 +        }
 +	}
 +
 +	private String validateProperty(String property, ClusterContext ctxt) {
 +
 +	    String propVal = CloudControllerUtil.getProperty(ctxt.getProperties(), property);
 +        handleNullObject(propVal, "Property validation failed. Cannot find '"+property+"' in " + ctxt);
 +        return propVal;
 +    }
 +	
 +	private String validateProperty(String property, ContainerClusterContext ctxt) {
 +
 +        String propVal = CloudControllerUtil.getProperty(ctxt.getProperties(), property);
 +        handleNullObject(propVal, "Property validation failed. '"+property+"' in " + ctxt);
 +        return propVal;
 +        
 +    }
 +
 +    private KubernetesClusterContext getKubernetesClusterContext(
 +			String kubernetesClusterId, String kubernetesMasterIp,
 +			String kubernetesPortRange) {
 +		
 +		KubernetesClusterContext origCtxt = dataHolder.getKubernetesClusterContext(kubernetesClusterId);
 +		KubernetesClusterContext newCtxt = new KubernetesClusterContext(kubernetesClusterId, kubernetesPortRange, kubernetesMasterIp);
 +		
 +		if (origCtxt == null) {
 +			dataHolder.addKubernetesClusterContext(newCtxt);
 +			return newCtxt;
 +		}
 +		
 +		if (!origCtxt.equals(newCtxt)) {
 +			// if for some reason master IP etc. have changed
 +			newCtxt.setAvailableHostPorts(origCtxt.getAvailableHostPorts());
 +			dataHolder.addKubernetesClusterContext(newCtxt);
 +			return newCtxt;
 +		}  else {
 +			return origCtxt;
 +		}
 +	}
 +
 +	@Override
 +	public MemberContext[] terminateAllContainers(String clusterId)
 +			throws InvalidClusterException {
 +		
 +		ClusterContext ctxt = dataHolder.getClusterContext(clusterId);
 +		handleNullObject(ctxt, "Kubernetes units temrination failed. Invalid cluster id. "+clusterId);
 +        
 +        String kubernetesClusterId = CloudControllerUtil.getProperty(ctxt.getProperties(), 
 +				StratosConstants.KUBERNETES_CLUSTER_ID);
 +		handleNullObject(kubernetesClusterId, "Kubernetes units termination failed. Cannot find '"+
 +                    StratosConstants.KUBERNETES_CLUSTER_ID+"'. " + ctxt);
 +        
 +        KubernetesClusterContext kubClusterContext = dataHolder.getKubernetesClusterContext(kubernetesClusterId);
 +		handleNullObject(kubClusterContext, "Kubernetes units termination failed. Cannot find a matching Kubernetes Cluster for cluster id: " 
 +                            +kubernetesClusterId);
 +
 +		KubernetesApiClient kubApi = kubClusterContext.getKubApi();
 +		// delete the service
 +		try {
 +			kubApi.deleteService(CloudControllerUtil.getCompatibleId(clusterId));
 +		} catch (KubernetesClientException e) {
 +			// we're not going to throw this error, but proceed with other deletions
 +			LOG.error("Failed to delete Kubernetes service with id: "+clusterId, e);
 +		}
 +		
 +		// set replicas=0 for the replication controller
 +		try {
 +			kubApi.updateReplicationController(clusterId, 0);
 +		} catch (KubernetesClientException e) {
 +			// we're not going to throw this error, but proceed with other deletions
 +			LOG.error("Failed to update Kubernetes Controller with id: "+clusterId, e);
 +		}
 +		
 +		// delete pods forcefully
 +        try {
 +            // create a label query
 +            Label l = new Label();
 +            l.setName(clusterId);
 +            // execute the label query
 +            Pod[] pods = kubApi.getSelectedPods(new Label[]{l});
 +            
 +            for (Pod pod : pods) {
 +                try {
 +                    // delete pods forcefully
 +                    kubApi.deletePod(pod.getId());
 +                } catch (KubernetesClientException ignore) {
 +                    // we can't do nothing here
 +                    LOG.warn(String.format("Failed to delete Pod [%s] forcefully!", pod.getId()));
 +                }
 +            }
 +        } catch (KubernetesClientException e) {
 +            // we're not going to throw this error, but proceed with other deletions
 +            LOG.error("Failed to delete pods forcefully for cluster: "+clusterId, e);
 +        }
 +		
 +		// delete the replication controller.
 +		try {
 +			kubApi.deleteReplicationController(clusterId);
 +		} catch (KubernetesClientException e) {
 +			String msg = "Failed to delete Kubernetes Controller with id: "+clusterId;
 +			LOG.error(msg, e);
 +			throw new InvalidClusterException(msg, e);
 +		}
 +		
 +		String allocatedPort = CloudControllerUtil.getProperty(ctxt.getProperties(), 
 +				StratosConstants.ALLOCATED_SERVICE_HOST_PORT);
 +		
 +		if (allocatedPort != null) {
 +			kubClusterContext.deallocateHostPort(Integer
 +					.parseInt(allocatedPort));
 +		} else {
 +			LOG.warn("Host port dealloacation failed due to a missing property: "
 +					+ StratosConstants.ALLOCATED_SERVICE_HOST_PORT);
 +		}
 +		
 +		List<MemberContext> membersToBeRemoved = dataHolder.getMemberContextsOfClusterId(clusterId);
 +		
 +		for (MemberContext memberContext : membersToBeRemoved) {
 +            logTermination(memberContext);
 +        }
 +		
 +		// persist
 +		persist();
 +		
 +		return membersToBeRemoved.toArray(new MemberContext[0]);
 +	}
 +
 +	@Override
 +	public MemberContext[] updateContainers(String clusterId, int replicas)
 +			throws UnregisteredCartridgeException {
 +		
 +	    if(LOG.isDebugEnabled()) {
 +            LOG.debug("CloudControllerServiceImpl:updateContainers for cluster : "+clusterId);
 +        }
 +
 +        ClusterContext ctxt = dataHolder.getClusterContext(clusterId);
 +        handleNullObject(ctxt, "Container update failed. Invalid cluster id. " + clusterId);
 +        
 +        String cartridgeType = ctxt.getCartridgeType();
 +
 +        Cartridge cartridge = dataHolder.getCartridge(cartridgeType);
 +
 +        if (cartridge == null) {
 +            String msg =
 +                         "Container update failed. No matching Cartridge found [type] "+cartridgeType 
 +                             +". [cluster id] "+ clusterId;
 +            LOG.error(msg);
 +            throw new UnregisteredCartridgeException(msg);
 +        }
 +
 +        try {
 +            String kubernetesClusterId = validateProperty(StratosConstants.KUBERNETES_CLUSTER_ID, ctxt);
 +            
 +            KubernetesClusterContext kubClusterContext = dataHolder.getKubernetesClusterContext(kubernetesClusterId);
 +            
 +            if (kubClusterContext == null) {
 +                String msg =
 +                             "Instance start-up failed. No matching Kubernetes Context Found for [id] "+kubernetesClusterId 
 +                             +". [cluster id] "+ clusterId;
 +                LOG.error(msg);
 +                throw new UnregisteredCartridgeException(msg);
 +            }
 +            
 +            KubernetesApiClient kubApi = kubClusterContext.getKubApi();
 +            // create a label query
 +            Label l = new Label();
 +            l.setName(clusterId);
 +            
 +            // get the current pods - useful when scale down
 +            Pod[] previousStatePods = kubApi.getSelectedPods(new Label[]{l});
 +            
 +            // update the replication controller - cluster id = replication controller id
 +            if (LOG.isDebugEnabled()) {
 +                LOG.debug("Cloud Controller is delegating request to update a replication controller "+clusterId+
 +                        " to Kubernetes layer.");
 +            }
 +            
 +            kubApi.updateReplicationController(clusterId, replicas);
 +            
 +            if (LOG.isDebugEnabled()) {
 +                LOG.debug("Cloud Controller successfully updated the controller "
 +                        + clusterId + " via Kubernetes layer.");
 +            }
 +            
 +            // execute the label query
 +            Pod[] allPods = new Pod[0];
 +            
 +            // wait replicas*5s time in the worst case ; best case = 0s
 +            for (int i = 0; i < (replicas*previousStatePods.length+1) ; i++) {
 +                allPods = kubApi.getSelectedPods(new Label[]{l});
 +                
 +                if (LOG.isDebugEnabled()) {
 +                    
 +                    LOG.debug("Pods Count: "+allPods.length+" for cluster: "+clusterId);
 +                }
 +                if(allPods.length == replicas) {
 +                    break;
 +                }
 +                Thread.sleep(10000);
 +            }
 +            
 +            if (LOG.isDebugEnabled()) {
 +                
 +                LOG.debug(String.format("Pods created : %s for cluster : %s",allPods.length, clusterId));
 +            }
 +            
 +            List<MemberContext> memberContexts = new ArrayList<MemberContext>();
 +            
 +            PodToMemberContext podToMemberContextFunc = new PodToMemberContext();
 +            // generate Member Contexts
 +            for (Pod pod : allPods) {
 +                MemberContext context;
 +                // if member context does not exist -> a new member (scale up)
 +                if ((context = dataHolder.getMemberContextOfMemberId(pod.getId())) == null) {
 +                    
 +                    context = podToMemberContextFunc.apply(pod);
 +                    context.setCartridgeType(cartridgeType);
 +                    context.setClusterId(clusterId);
 +                    
 +                    context.setProperties(CloudControllerUtil.addProperty(context
 +                            .getProperties(), StratosConstants.ALLOCATED_SERVICE_HOST_PORT,
 +                            CloudControllerUtil.getProperty(ctxt.getProperties(), 
 +                                    StratosConstants.ALLOCATED_SERVICE_HOST_PORT)));
 +                    
 +                    // wait till Pod status turns to running and send member spawned.
 +                    ScheduledThreadExecutor exec = ScheduledThreadExecutor.getInstance();
 +                    if (LOG.isDebugEnabled()) {
 +                        LOG.debug("Cloud Controller is starting the instance start up thread.");
 +                    }
 +                    dataHolder.addScheduledFutureJob(context.getMemberId(), exec.schedule(new PodActivationWatcher(pod.getId(), context, kubApi), 5000));
 +                    
 +                    memberContexts.add(context);
 +                    
 +                }
 +                // publish data
 +                // TODO
 +//                CartridgeInstanceDataPublisher.publish(context.getMemberId(), null, null, context.getClusterId(), cartridgeType, MemberStatus.Created.toString(), node);
 +                
 +            }
 +            
 +            if (memberContexts.isEmpty()) {
 +                // terminated members
 +                @SuppressWarnings("unchecked")
 +                List<Pod> difference = ListUtils.subtract(Arrays.asList(previousStatePods), Arrays.asList(allPods));
 +                for (Pod pod : difference) {
 +                    if (pod != null) {
 +                        MemberContext context = dataHolder.getMemberContextOfMemberId(pod.getId());
 +                        logTermination(context);
 +                        memberContexts.add(context);
 +                    }
 +                }
 +            }
 +            
 +            
 +            // persist in registry
 +            persist();
 +
 +            LOG.info("Kubernetes entities are successfully starting up. "+memberContexts);
 +
 +            return memberContexts.toArray(new MemberContext[0]);
 +
 +        } catch (Exception e) {
 +            String msg = "Failed to update containers belong to cluster " + clusterId+". Cause: "+e.getMessage();
 +            LOG.error(msg, e);
 +            throw new IllegalStateException(msg, e);
 +        }
 +	}
 +
 +    @Override
 +    public MemberContext terminateContainer(String memberId) throws MemberTerminationFailedException {
 +
 +        handleNullObject(memberId, "Failed to terminate member. Invalid Member id. [Member id] " + memberId);
 +
 +        MemberContext memberContext = dataHolder.getMemberContextOfMemberId(memberId);
 +
 +        handleNullObject(memberContext, "Failed to terminate member. Member id not found. [Member id] " + memberId);
 +
 +        String clusterId = memberContext.getClusterId();
 +
 +        handleNullObject(clusterId, "Failed to terminate member. Cluster id is null. [Member id] " + memberId);
 +
 +        ClusterContext ctxt = dataHolder.getClusterContext(clusterId);
 +
 +        handleNullObject(ctxt,
 +                String.format("Failed to terminate member [Member id] %s. Invalid cluster id %s ", memberId, clusterId));
 +        
 +        String kubernetesClusterId = CloudControllerUtil.getProperty(ctxt.getProperties(), 
 +                StratosConstants.KUBERNETES_CLUSTER_ID);
 +        
 +        handleNullObject(kubernetesClusterId, String.format("Failed to terminate member [Member id] %s. Cannot find '"+
 +                    StratosConstants.KUBERNETES_CLUSTER_ID+"' in [cluster context] %s ", memberId, ctxt));
 +        
 +        KubernetesClusterContext kubClusterContext = dataHolder.getKubernetesClusterContext(kubernetesClusterId);
 +        
 +        handleNullObject(kubClusterContext, String.format("Failed to terminate member [Member id] %s. Cannot find a matching Kubernetes Cluster in [cluster context] %s ", memberId, ctxt));
 +        
 +        KubernetesApiClient kubApi = kubClusterContext.getKubApi();
 +        // delete the Pod
 +        try {
 +            // member id = pod id
 +            kubApi.deletePod(memberId);
 +            
 +            MemberContext memberToBeRemoved = dataHolder.getMemberContextOfMemberId(memberId);
 +            
 +            logTermination(memberToBeRemoved);
 +            
 +            return memberToBeRemoved;
 +            
 +        } catch (KubernetesClientException e) {
 +            String msg = String.format("Failed to terminate member [Member id] %s", memberId);
 +            LOG.error(msg, e);
 +            throw new MemberTerminationFailedException(msg, e);
 +        }
 +    }
 +    
 +    private void handleNullObject(Object obj, String errorMsg) {
 +        if (obj == null) {
 +            LOG.error(errorMsg);
 +            throw new IllegalArgumentException(errorMsg);
 +        }
 +    }
 +
+     public void deployApplicationDefinition (ApplicationContext applicationContext) throws ApplicationDefinitionException {
+ 
+         ApplicationParser applicationParser = new DefaultApplicationParser();
+         Application application = applicationParser.parse(applicationContext);
+ 
+         // Create a Cluster Context obj. for each of the Clusters in the Application
+         for (ApplicationClusterContext applicationClusterContext : applicationParser.getApplicationClusterContexts()) {
+             dataHolder.addClusterContext(new ClusterContext(applicationClusterContext.getClusterId(),
+                     applicationClusterContext.getCartridgeType(), applicationClusterContext.getTextPayload(),
+                     applicationClusterContext.getHostName(), applicationClusterContext.isLbCluster()));
+         }
+ 
+         TopologyBuilder.handleApplicationDeployed(application, applicationParser.getApplicationClusterContexts(),
+                 applicationParser.getPayloadData());
+ 
+         persist();
+     }
+ 
+     @Override
+     public void unDeployApplicationDefinition(String applicationId, int tenantId, String tenantDomain) throws ApplicationDefinitionException {
+ 
+         TopologyBuilder.handleApplicationUndeployed(applicationId);
+     }
+ 
  }
  

http://git-wip-us.apache.org/repos/asf/stratos/blob/17cc86eb/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java
index d81eab7,5301b14..835cc09
--- 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
@@@ -19,16 -19,9 +19,18 @@@
  package org.apache.stratos.cloud.controller.interfaces;
  
  import org.apache.stratos.cloud.controller.deployment.partition.Partition;
 +import org.apache.stratos.cloud.controller.exception.InvalidCartridgeDefinitionException;
 +import org.apache.stratos.cloud.controller.exception.InvalidCartridgeTypeException;
 +import org.apache.stratos.cloud.controller.exception.InvalidClusterException;
 +import org.apache.stratos.cloud.controller.exception.InvalidIaasProviderException;
 +import org.apache.stratos.cloud.controller.exception.InvalidMemberException;
 +import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
 +import org.apache.stratos.cloud.controller.exception.MemberTerminationFailedException;
 +import org.apache.stratos.cloud.controller.exception.UnregisteredCartridgeException;
 +import org.apache.stratos.cloud.controller.exception.UnregisteredClusterException;
+ import org.apache.stratos.cloud.controller.exception.*;
  import org.apache.stratos.cloud.controller.pojo.*;
+ import org.apache.stratos.cloud.controller.pojo.application.ApplicationContext;
  
  /**
   * This API provides a way to communicate with underline

http://git-wip-us.apache.org/repos/asf/stratos/blob/17cc86eb/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerDSComponent.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerDSComponent.java
index 934788f,5831948..88ff2b6
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerDSComponent.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerDSComponent.java
@@@ -30,7 -32,10 +32,9 @@@ import org.apache.stratos.cloud.control
  import org.apache.stratos.cloud.controller.topic.instance.status.InstanceStatusEventMessageListener;
  import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
  import org.apache.stratos.cloud.controller.util.ServiceReferenceHolder;
 -import org.apache.stratos.messaging.broker.publish.EventPublisherPool;
  import org.apache.stratos.messaging.broker.subscribe.TopicSubscriber;
+ import org.apache.stratos.messaging.message.receiver.application.status.ApplicationStatusEventReceiver;
+ import org.apache.stratos.messaging.util.Constants;
  import org.osgi.framework.BundleContext;
  import org.osgi.service.component.ComponentContext;
  import org.wso2.carbon.ntask.core.service.TaskService;
@@@ -59,71 -64,77 +63,67 @@@ import org.wso2.carbon.utils.Configurat
   */
  public class CloudControllerDSComponent {
  
- 	private static final Log LOG = LogFactory
- 			.getLog(CloudControllerDSComponent.class);
- 
- 	protected void activate(ComponentContext context) {
- 		try {
- 
- 			// Start instance status event message listener
- 			TopicSubscriber subscriber = new TopicSubscriber(
- 					CloudControllerConstants.INSTANCE_TOPIC);
- 			subscriber.setMessageListener(
- 					new InstanceStatusEventMessageListener());
- 			Thread tsubscriber = new Thread(subscriber);
- 			tsubscriber.start();
- 
- 			// Start instance status message delegator
- 			InstanceStatusEventMessageDelegator delegator =
- 					new InstanceStatusEventMessageDelegator();
- 			Thread tdelegator = new Thread(delegator);
- 			tdelegator.start();
- 
- 			// Register cloud controller service
- 			BundleContext bundleContext = context.getBundleContext();
- 			bundleContext.registerService(CloudControllerService.class.getName(),
- 			                              new CloudControllerServiceImpl(), null);
- 
- 			if (LOG.isInfoEnabled()) {
- 				LOG.info("Scheduling tasks");
- 			}
- 
- 			TopologySynchronizerTaskScheduler.schedule(ServiceReferenceHolder
- 					                                           .getInstance().getTaskService());
- 
- 		} catch (Throwable e) {
- 			LOG.error("Cloud Controller Service bundle is failed to activate.", e);
- 		}
- 	}
- 
- 	protected void setTaskService(TaskService taskService) {
- 		if (LOG.isDebugEnabled()) {
- 			LOG.debug("Setting the Task Service");
- 		}
- 		ServiceReferenceHolder.getInstance().setTaskService(taskService);
- 	}
- 
- 	protected void unsetTaskService(TaskService taskService) {
- 		if (LOG.isDebugEnabled()) {
- 			LOG.debug("Unsetting the Task Service");
- 		}
- 		ServiceReferenceHolder.getInstance().setTaskService(null);
- 	}
- 
+     private static final Log log = LogFactory.getLog(CloudControllerDSComponent.class);
 -    private ApplicationStatusTopicReceiver applicationStatusTopicReceiver;
++
+     protected void activate(ComponentContext context) {
+         try {
+                	
+             // Start instance status event message listener
+             TopicSubscriber subscriber = new TopicSubscriber(CloudControllerConstants.INSTANCE_TOPIC);
+             subscriber.setMessageListener(new InstanceStatusEventMessageListener());
+             Thread tsubscriber = new Thread(subscriber);
+             tsubscriber.start();
+ 
+             // Start instance status message delegator
+             InstanceStatusEventMessageDelegator delegator = new InstanceStatusEventMessageDelegator();
+             Thread tdelegator = new Thread(delegator);
+             tdelegator.start();
 -
 -            applicationStatusTopicReceiver = new ApplicationStatusTopicReceiver();
 -            Thread appThread = new Thread(applicationStatusTopicReceiver);
 -            appThread.start();
 -            if (log.isDebugEnabled()) {
 -                log.debug("Application status Receiver thread started");
 -            }
 -
+         	
+         	// Register cloud controller service
+             BundleContext bundleContext = context.getBundleContext();
+             bundleContext.registerService(CloudControllerService.class.getName(), new CloudControllerServiceImpl(), null);
+ 
+             if(log.isInfoEnabled()) {
+                 log.info("Scheduling tasks");
+             }
+             
+ 			TopologySynchronizerTaskScheduler
+ 						.schedule(ServiceReferenceHolder.getInstance()
+ 								.getTaskService());
 -
 -
+ 			
+         } catch (Throwable e) {
+             log.error("******* Cloud Controller Service bundle is failed to activate ****", e);
+         }
+     }
+     
+     protected void setTaskService(TaskService taskService) {
+         if (log.isDebugEnabled()) {
+             log.debug("Setting the Task Service");
+         }
+         ServiceReferenceHolder.getInstance().setTaskService(taskService);
+     }
+ 
+     protected void unsetTaskService(TaskService taskService) {
+         if (log.isDebugEnabled()) {
+             log.debug("Unsetting the Task Service");
+         }
+         ServiceReferenceHolder.getInstance().setTaskService(null);
+     }
+     
  	protected void setRegistryService(RegistryService registryService) {
- 		if (LOG.isDebugEnabled()) {
- 			LOG.debug("Setting the Registry Service");
- 		}
- 
- 		try {
- 			UserRegistry registry = registryService
- 					.getGovernanceSystemRegistry();
- 			ServiceReferenceHolder.getInstance().setRegistry(registry);
- 		} catch (RegistryException e) {
- 			String msg = "Failed when retrieving Governance System Registry.";
- 			LOG.error(msg, e);
- 			throw new CloudControllerException(msg, e);
+ 		if (log.isDebugEnabled()) {
+ 			log.debug("Setting the Registry Service");
  		}
+ 		
+ 		try {			
+ 			UserRegistry registry = registryService.getGovernanceSystemRegistry();
+ 	        ServiceReferenceHolder.getInstance()
+ 	                                             .setRegistry(registry);
+         } catch (RegistryException e) {
+         	String msg = "Failed when retrieving Governance System Registry.";
+         	log.error(msg, e);
+         	throw new CloudControllerException(msg, e);
+         } 
  	}
  
  	protected void unsetRegistryService(RegistryService registryService) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/17cc86eb/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Cartridge.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Cartridge.java
index 3103a22,805aaa5..002157e
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Cartridge.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Cartridge.java
@@@ -374,21 -372,13 +376,29 @@@ public class Cartridge implements Seria
  		this.serviceGroup = serviceGroup;
  	}
  
 +	public Container getContainer() {
 +		return container;
 +	}
 +
 +	public void setContainer(Container container) {
 +		this.container = container;
 +	}
 +
 +	public String getDeployerType() {
 +		return deployerType;
 +	}
 +
 +	public void setDeployerType(String deployerType) {
 +		this.deployerType = deployerType;
 +	}
-     
-     
++
+ 
+     public String[] getExportingProperties() {
+         return exportingProperties;
+     }
+ 
+     public void setExportingProperties(String[] exportingProperties) {
+         this.exportingProperties = exportingProperties;
+     }
+ 
  }

http://git-wip-us.apache.org/repos/asf/stratos/blob/17cc86eb/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/CartridgeConfig.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/CartridgeConfig.java
index 670ef19,00fe884..51e571e
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/CartridgeConfig.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/CartridgeConfig.java
@@@ -66,10 -62,8 +66,11 @@@ public class CartridgeConfig implement
      private LoadbalancerConfig lbConfig;
      
      private String serviceGroup;
 +    
 +    private Container container;
+     private String[] exportingProperties;
  
 +    private String deployerType;
  
      public String getType() {
          return type;
@@@ -285,21 -271,12 +286,30 @@@
  		this.serviceGroup = serviceGroup;
  	}
  
+ 
+     public String[] getExportingProperties() {
+         return exportingProperties;
+     }
+ 
+     public void setExportingProperties(String[] exportingProperties) {
+         this.exportingProperties = exportingProperties;
+     }
++
 +	public Container getContainer() {
 +		return container;
 +	}
 +
 +	public void setContainer(Container container) {
 +		this.container = container;
 +	}
 +
 +	public String getDeployerType() {
 +		return deployerType;
 +	}
 +
 +	public void setDeployerType(String deployerType) {
 +		this.deployerType = deployerType;
 +	}	
 +	
 +    
  }

http://git-wip-us.apache.org/repos/asf/stratos/blob/17cc86eb/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/stratos/blob/17cc86eb/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
index aa98e5d,b6e3470..bf74095
--- 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
@@@ -24,11 -23,14 +24,15 @@@ import org.apache.commons.logging.LogFa
  import org.apache.stratos.cloud.controller.exception.InvalidCartridgeTypeException;
  import org.apache.stratos.cloud.controller.exception.InvalidMemberException;
  import org.apache.stratos.cloud.controller.pojo.*;
+ import org.apache.stratos.cloud.controller.pojo.Cartridge;
+ import org.apache.stratos.cloud.controller.pojo.payload.MetaDataHolder;
  import org.apache.stratos.cloud.controller.publisher.CartridgeInstanceDataPublisher;
+ import org.apache.stratos.cloud.controller.registry.RegistryManager;
  import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
  import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
 +import org.apache.stratos.common.constants.StratosConstants;
  import org.apache.stratos.messaging.domain.topology.*;
+ import org.apache.stratos.messaging.event.application.status.*;
  import org.apache.stratos.messaging.event.instance.status.InstanceActivatedEvent;
  import org.apache.stratos.messaging.event.instance.status.InstanceMaintenanceModeEvent;
  import org.apache.stratos.messaging.event.instance.status.InstanceReadyToShutdownEvent;
@@@ -119,13 -121,8 +123,13 @@@ public class TopologyBuilder 
              TopologyManager.acquireWriteLock();
              String cartridgeType = registrant.getCartridgeType();
              service = topology.getService(cartridgeType);
 +            
 +            if(log.isDebugEnabled()) {
 +            	log.debug(" Service is retrieved from Topology [" + service + "] ");
 +            }
 +            
              Properties props = CloudControllerUtil.toJavaUtilProperties(registrant.getProperties());
-             
+ 
              Cluster cluster;
              String clusterId = registrant.getClusterId();
              if (service.clusterExists(clusterId)) {
@@@ -140,21 -137,19 +144,22 @@@
                  }
                  cluster.setProperties(props);
                  cluster.setLbCluster(isLb);
 +                setKubernetesCluster(cluster);
              } else {
                  cluster = new Cluster(cartridgeType, clusterId,
-                                       registrant.getDeploymentPolicyName(), registrant.getAutoScalerPolicyName());
+                         registrant.getDeploymentPolicyName(), registrant.getAutoScalerPolicyName(), null);
                  cluster.addHostName(registrant.getHostName());
-                 if(service.getServiceType() == ServiceType.MultiTenant) {
+                 if (service.getServiceType() == ServiceType.MultiTenant) {
                      cluster.setTenantRange(registrant.getTenantRange());
                  }
-                 if(service.getProperties().getProperty(Constants.IS_PRIMARY) != null) {
+                 if (service.getProperties().getProperty(Constants.IS_PRIMARY) != null) {
                      props.setProperty(Constants.IS_PRIMARY, service.getProperties().getProperty(Constants.IS_PRIMARY));
                  }
                  cluster.setProperties(props);
                  cluster.setLbCluster(isLb);
+                 //cluster.setStatus(Status.Created);
 +                setKubernetesCluster(cluster);
 +                cluster.setStatus(ClusterStatus.Created);
                  service.addCluster(cluster);
              }
              TopologyManager.updateTopology(topology);
@@@ -162,18 -157,10 +167,18 @@@
  
          } finally {
              TopologyManager.releaseWriteLock();
-         }
+         }*/
      }
  
 -    public static void handleClusterRemoved(ClusterContext ctxt) {
 +    private static void setKubernetesCluster(Cluster cluster) {  
 +    	boolean isKubernetesCluster = (cluster.getProperties().getProperty(StratosConstants.KUBERNETES_CLUSTER_ID) != null);
 +		if (log.isDebugEnabled()) {
 +			log.debug(" Kubernetes Cluster ["+ isKubernetesCluster + "] ");
 +		}
 +		cluster.setKubernetesCluster(isKubernetesCluster);		
 +	}
 +
 +	public static void handleClusterRemoved(ClusterContext ctxt) {
          Topology topology = TopologyManager.getTopology();
          Service service = topology.getService(ctxt.getCartridgeType());
          String deploymentPolicy;
@@@ -364,17 -331,34 +349,24 @@@
          }
  
          MemberActivatedEvent memberActivatedEvent = new MemberActivatedEvent(instanceActivatedEvent.getServiceName(),
-                         instanceActivatedEvent.getClusterId(), instanceActivatedEvent.getNetworkPartitionId(), instanceActivatedEvent.getPartitionId(), instanceActivatedEvent.getMemberId());
+                 instanceActivatedEvent.getClusterId(), instanceActivatedEvent.getNetworkPartitionId(), instanceActivatedEvent.getPartitionId(), instanceActivatedEvent.getMemberId());
  
+         // grouping - set grouid
+         memberActivatedEvent.setGroupId(instanceActivatedEvent.getGroupId());
          try {
              TopologyManager.acquireWriteLock();
+             // try update lifecycle state
+             if (!member.isStateTransitionValid(MemberStatus.Activated)) {
+                 log.error("Invalid State Transition from " + member.getStatus() + " to " + MemberStatus.Activated);
+             }
              member.setStatus(MemberStatus.Activated);
              log.info("member started event adding status activated");
 -            Cartridge cartridge = FasterLookUpDataHolder.getInstance().
 -                    getCartridge(instanceActivatedEvent.getServiceName());
 -
 -            List<PortMapping> portMappings = cartridge.getPortMappings();
 -            Port port;
 -            //adding ports to the event
 -            for (PortMapping portMapping : portMappings) {
 -                port = new Port(portMapping.getProtocol(),
 -                        Integer.parseInt(portMapping.getPort()),
 -                        Integer.parseInt(portMapping.getProxyPort()));
 -                member.addPort(port);
 -                memberActivatedEvent.addPort(port);
 -            }
 +            // Adding ports to the event
 +            // TODO: Need to remove this since ports are now set in member spawned event
 +            memberActivatedEvent.addPorts(member.getPorts());
  
              memberActivatedEvent.setMemberIp(member.getMemberIp());
+             memberActivatedEvent.setMemberPublicIp(member.getMemberPublicIp());
              TopologyManager.updateTopology(topology);
  
          } finally {


Mime
View raw message