You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2013/07/10 18:51:59 UTC

[24/45] fixing component version issues and adding currently refactored components to the parent pom

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/internal/TopologyMgtDSComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/internal/TopologyMgtDSComponent.java b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/internal/TopologyMgtDSComponent.java
new file mode 100644
index 0000000..2500485
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/internal/TopologyMgtDSComponent.java
@@ -0,0 +1,290 @@
+/*
+ *  Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ *  Licensed 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.adc.topology.mgt.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.adc.topology.mgt.builder.TopologySyncher;
+import org.apache.stratos.adc.topology.mgt.service.TopologyManagementService;
+import org.apache.stratos.adc.topology.mgt.service.impl.TopologyManagementServiceImpl;
+import org.apache.stratos.adc.topology.mgt.subscriber.TopologySubscriber;
+import org.apache.stratos.adc.topology.mgt.util.ConfigHolder;
+import org.apache.stratos.adc.topology.mgt.util.TopologyConstants;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.utils.ConfigurationContextService;
+import org.apache.stratos.lb.common.service.LoadBalancerConfigurationService;
+import org.wso2.carbon.ntask.core.service.TaskService;
+
+//* @scr.reference name="synapse.config.service"
+//* interface="org.wso2.carbon.mediation.initializer.services.SynapseConfigurationService"
+//* cardinality="1..1" policy="dynamic" bind="setSynapseConfigurationService"
+//* unbind="unsetSynapseConfigurationService"
+//* @scr.reference name="registry.service"
+//* interface="org.wso2.carbon.registry.core.service.RegistryService"
+//* cardinality="1..1" policy="dynamic"
+//* bind="setRegistryService" unbind="unsetRegistryService"
+//* @scr.reference name="dependency.mgt.service"
+//* interface="org.wso2.carbon.mediation.dependency.mgt.services.DependencyManagementService"
+//* cardinality="0..1" policy="dynamic"
+//* bind="setDependencyManager" unbind="unsetDependencyManager"
+//* @scr.reference name="user.realmservice.default"
+//* interface="org.wso2.carbon.user.core.service.RealmService"
+//* cardinality="1..1" policy="dynamic" bind="setRealmService"
+//* unbind="unsetRealmService"
+
+/**
+ * @scr.component name="topology.mgt.service" immediate="true"
+ * @scr.reference name="configuration.context.service"
+ * interface="org.wso2.carbon.utils.ConfigurationContextService" cardinality="1..1"
+ * policy="dynamic" bind="setConfigurationContextService" unbind="unsetConfigurationContextService"
+ * @scr.reference name="org.apache.stratos.lb.common"
+ * interface="org.apache.stratos.lb.common.service.LoadBalancerConfigurationService"
+ * cardinality="1..1" policy="dynamic" bind="setLoadBalancerConfigurationService"
+ * unbind="unsetLoadBalancerConfigurationService"
+ * @scr.reference name="ntask.component" interface="org.wso2.carbon.ntask.core.service.TaskService"
+ * cardinality="1..1" policy="dynamic" bind="setTaskService" unbind="unsetTaskService"
+ */
+@SuppressWarnings({"UnusedDeclaration", "JavaDoc"})
+public class TopologyMgtDSComponent {
+
+    private static final Log log = LogFactory.getLog(TopologyMgtDSComponent.class);
+
+//    private boolean activated = false;
+
+    protected void activate(ComponentContext ctxt) {
+    	try {
+    		// start consumer
+    		// initialize TopologyBuilder Consumer
+            if (System.getProperty("mb.server.ip") != null) {
+                Thread topologyConsumer = new Thread(new TopologySyncher(ConfigHolder.getInstance().getSharedTopologyDiffQueue()));
+                // start consumer
+                topologyConsumer.start();
+
+                TopologySubscriber.subscribe(TopologyConstants.TOPIC_NAME);
+            }
+
+    		
+            BundleContext bundleContext = ctxt.getBundleContext();
+            bundleContext.registerService(TopologyManagementService.class.getName(),
+                                          new TopologyManagementServiceImpl(), null);
+
+            log.debug("******* Topology Mgt Service bundle is activated ******* ");
+        } catch (Throwable e) {
+            log.error("******* Topology Mgt Service Service bundle is failed to activate ****", e);
+        }
+//    	log.info("**************************************");
+//    	for (String str : ConfigHolder.getInstance().getLbConfig().getServiceDomains()) {
+//	        log.info(str);
+//        }
+//    	log.info("**************************************");
+    	
+//    	if(!activated){
+//    		GroupMgtAgentBuilder.createGroupMgtAgents();
+//    		activated = true;
+//    	}
+    	
+    	
+    	// topology synching task activation
+//    	TaskManager tm = null;
+//		try {
+//			// topology sync
+//			ConfigHolder.getInstance().getTaskService()
+//			          .registerTaskType(TopologyConstants.TOPOLOGY_SYNC_TASK_TYPE);
+//
+//			tm =
+//					ConfigHolder.getInstance().getTaskService()
+//			               .getTaskManager(TopologyConstants.TOPOLOGY_SYNC_TASK_TYPE);
+//
+//			TriggerInfo triggerInfo = new TriggerInfo(TopologyConstants.TOPOLOGY_SYNC_CRON);
+//			TaskInfo taskInfo =
+//			                    new TaskInfo(TopologyConstants.TOPOLOGY_SYNC_TASK_NAME,
+//			                                 TopologySubscriberTask.class.getName(),
+//			                                 new HashMap<String, String>(), triggerInfo);
+//			tm.registerTask(taskInfo);
+//
+//			// start consumer
+//			// initialize TopologyBuilder Consumer
+//	        Thread topologyConsumer = new Thread(new TopologyBuilder(ConfigHolder.getInstance().getSharedTopologyDiffQueue()));
+//	        // start consumer
+//	        topologyConsumer.start();
+//			
+//		} catch (Exception e) {
+//			String msg = "Error scheduling task: " + TopologyConstants.TOPOLOGY_SYNC_TASK_NAME;
+//			log.error(msg, e);
+//			if (tm != null) {
+//				try {
+//					tm.deleteTask(TopologyConstants.TOPOLOGY_SYNC_TASK_NAME);
+//				} catch (TaskException e1) {
+//					log.error(e1);
+//				}
+//			}
+//			throw new TopologyMgtException(msg, e);
+//		}
+    }
+
+    protected void deactivate(ComponentContext context) {}
+
+    protected void setConfigurationContextService(ConfigurationContextService cfgCtxService) {
+        ConfigHolder.getInstance().setAxisConfiguration(
+                cfgCtxService.getServerConfigContext().getAxisConfiguration());
+    }
+
+    protected void unsetConfigurationContextService(ConfigurationContextService cfgCtxService) {
+        ConfigHolder.getInstance().setAxisConfiguration(null);
+    }
+
+//    protected void setSynapseConfigurationService(
+//            SynapseConfigurationService synapseConfigurationService) {
+//
+//        ConfigHolder.getInstance().setSynapseConfiguration(
+//                synapseConfigurationService.getSynapseConfiguration());
+//    }
+//
+//    protected void unsetSynapseConfigurationService(
+//            SynapseConfigurationService synapseConfigurationService) {
+//
+//        ConfigHolder.getInstance().setSynapseConfiguration(null);
+//    }
+
+    /**
+     * Here we receive an event about the creation of a SynapseEnvironment. If this is
+     * SuperTenant we have to wait until all the other constraints are met and actual
+     * initialization is done in the activate method. Otherwise we have to do the activation here.
+     *
+     * @param synapseEnvironmentService SynapseEnvironmentService which contains information
+     *                                  about the new Synapse Instance
+     */
+//    protected void setSynapseEnvironmentService(
+//            SynapseEnvironmentService synapseEnvironmentService) {
+//        boolean alreadyCreated = ConfigHolder.getInstance().getSynapseEnvironmentServices().
+//                containsKey(synapseEnvironmentService.getTenantId());
+//
+//        ConfigHolder.getInstance().addSynapseEnvironmentService(
+//                synapseEnvironmentService.getTenantId(),
+//                synapseEnvironmentService);
+//        if (activated) {
+//            if (!alreadyCreated) {
+//                try {
+//                    registerDeployer(synapseEnvironmentService.getConfigurationContext().getAxisConfiguration(),
+//                            synapseEnvironmentService.getSynapseEnvironment());
+//                    if (log.isDebugEnabled()) {
+//                        log.debug("Endpoint Admin bundle is activated ");
+//                    }
+//                } catch (Throwable e) {
+//                    log.error("Failed to activate Endpoint Admin bundle ", e);
+//                }
+//            }
+//        }
+//    }
+
+//    /**
+//     * Here we receive an event about Destroying a SynapseEnvironment. This can be the super tenant
+//     * destruction or a tenant destruction.
+//     *
+//     * @param synapseEnvironmentService synapseEnvironment
+//     */
+//    protected void unsetSynapseEnvironmentService(
+//            SynapseEnvironmentService synapseEnvironmentService) {
+//        ConfigHolder.getInstance().removeSynapseEnvironmentService(
+//                synapseEnvironmentService.getTenantId());
+//    }
+//
+//    protected void setRegistryService(RegistryService regService) {
+//        if (log.isDebugEnabled()) {
+//            log.debug("RegistryService bound to the endpoint component");
+//        }
+//        try {
+//            ConfigHolder.getInstance().setConfigRegistry(regService.getConfigSystemRegistry());
+//            ConfigHolder.getInstance().setGovernanceRegistry(regService.getGovernanceSystemRegistry());
+//        } catch (RegistryException e) {
+//            log.error("Couldn't retrieve the registry from the registry service");
+//        }
+//    }
+//
+//    protected void unsetRegistryService(RegistryService regService) {
+//        if (log.isDebugEnabled()) {
+//            log.debug("RegistryService unbound from the endpoint component");
+//        }
+//        ConfigHolder.getInstance().setConfigRegistry(null);
+//    }
+//
+//    protected void setDependencyManager(DependencyManagementService dependencyMgr) {
+//        if (log.isDebugEnabled()) {
+//            log.debug("Dependency management service bound to the endpoint component");
+//        }
+//        ConfigHolder.getInstance().setDependencyManager(dependencyMgr);
+//    }
+//
+//    protected void unsetDependencyManager(DependencyManagementService dependencyMgr) {
+//        if (log.isDebugEnabled()) {
+//            log.debug("Dependency management service unbound from the endpoint component");
+//        }
+//        ConfigHolder.getInstance().setDependencyManager(null);
+//    }
+//
+//    protected void setSynapseRegistrationsService(
+//            SynapseRegistrationsService synapseRegistrationsService) {
+//
+//    }
+
+//    protected void unsetSynapseRegistrationsService(
+//            SynapseRegistrationsService synapseRegistrationsService) {
+//        int tenantId = synapseRegistrationsService.getTenantId();
+//        if (ConfigHolder.getInstance().getSynapseEnvironmentServices().containsKey(tenantId)) {
+//            SynapseEnvironment env = ConfigHolder.getInstance().
+//                    getSynapseEnvironmentService(tenantId).getSynapseEnvironment();
+//
+//            ConfigHolder.getInstance().removeSynapseEnvironmentService(
+//                    synapseRegistrationsService.getTenantId());
+//
+//            AxisConfiguration axisConfig = synapseRegistrationsService.getConfigurationContext().
+//                    getAxisConfiguration();
+//            if (axisConfig != null) {
+//                try {
+//                    unregisterDeployer(axisConfig, env);
+//                } catch (Exception e) {
+//                    log.warn("Couldn't remove the EndpointDeployer");
+//                }
+//            }
+//        }
+//    }
+
+//    protected void setRealmService(RealmService realmService) {
+//        ConfigHolder.getInstance().setRealmService(realmService);
+//    }
+//
+//    protected void unsetRealmService(RealmService realmService) {
+//        ConfigHolder.getInstance().setRealmService(null);
+//    }
+//    
+    protected void setLoadBalancerConfigurationService(LoadBalancerConfigurationService lbConfigSer){
+        ConfigHolder.getInstance().setLbConfigService(lbConfigSer);
+    }
+    
+    protected void unsetLoadBalancerConfigurationService(LoadBalancerConfigurationService lbConfigSer){
+        ConfigHolder.getInstance().setLbConfigService(null);
+    }
+    
+    protected void setTaskService(TaskService taskService) {
+        ConfigHolder.getInstance().setTaskService(taskService);
+    }
+
+    protected void unsetTaskService(TaskService taskService) {
+        ConfigHolder.getInstance().setTaskService(null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/service/TopologyManagementService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/service/TopologyManagementService.java b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/service/TopologyManagementService.java
new file mode 100644
index 0000000..9b490e9
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/service/TopologyManagementService.java
@@ -0,0 +1,69 @@
+/*
+ *  Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ *  Licensed 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.adc.topology.mgt.service;
+
+import org.apache.stratos.adc.topology.mgt.serviceobjects.DomainContext;
+
+/**
+ * This exposes details regarding up-to-date topology
+ *
+ */
+public interface TopologyManagementService {
+
+	/**
+	 * Provide service cluster domains corresponds to the given information.
+	 * @param cartridgeType cartridge type
+	 * @param tenantId tenant id
+	 * @return String array of service cluster domains
+	 */
+	String[] getDomains(String cartridgeType, int tenantId);
+
+	/**
+	 * Provide service cluster sub domains corresponds to the given information.
+	 * @param cartridgeType cartridge type
+	 * @param tenantId tenant id
+	 * @return String array of service cluster sub domains
+	 */
+	String[] getSubDomains(String cartridgeType, int tenantId);
+
+//	/**
+//	 * Provide public IPs corresponds to the given information.
+//	 * @param cartridgeType cartridge type
+//	 * @param tenantId tenant id
+//	 * @return String array of public IPs
+//	 */
+//	String[] getActiveIPs(String cartridgeType, int tenantId);
+	
+	/**
+	 * Provide public IPs corresponds to the given information.
+	 * @param cartridgeType cartridge type
+	 * @param domain service cluster domain
+	 * @param subDomain service cluster sub domain
+	 * @return String array of public IPs
+	 */
+	String[] getActiveIPs(String cartridgeType, String domain, String subDomain);
+	
+	/**
+	 * Provide domains and the relevant subdomains corresponding to the given information
+	 * 
+	 * @param cartridgeType cartridge type
+	 * @param tenantId tenant id
+	 * @return DomainContext instances array of domains and sub domains 
+	 */
+	DomainContext[] getDomainsAndSubdomains (String cartridgeType, int tenantId);
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/service/impl/TopologyManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/service/impl/TopologyManagementServiceImpl.java b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/service/impl/TopologyManagementServiceImpl.java
new file mode 100644
index 0000000..9b976cf
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/service/impl/TopologyManagementServiceImpl.java
@@ -0,0 +1,127 @@
+/*
+ *  Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ *  Licensed 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.adc.topology.mgt.service.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.stratos.adc.topology.mgt.service.TopologyManagementService;
+import org.apache.stratos.adc.topology.mgt.serviceobjects.DomainContext;
+import org.apache.stratos.adc.topology.mgt.util.ConfigHolder;
+import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration.ServiceConfiguration;
+import org.apache.stratos.lb.common.conf.util.LoadBalancerConfigUtil;
+
+public class TopologyManagementServiceImpl implements TopologyManagementService {
+	
+	ConfigHolder data = ConfigHolder.getInstance();
+
+	public String[] getDomains(String cartridgeType, int tenantId) {
+		List<String> domains = new ArrayList<String>();
+		if(data.getServiceConfigs() != null){
+			List<ServiceConfiguration> serviceConfigs = data.getServiceConfigs().get(cartridgeType);
+			if(serviceConfigs != null){
+				
+				for (ServiceConfiguration serviceConfiguration : serviceConfigs) {
+	                
+					List<Integer> tenantIds = LoadBalancerConfigUtil.getTenantIds(serviceConfiguration.getTenantRange());
+					if(!tenantIds.isEmpty() && (tenantIds.contains(tenantId) || tenantIds.contains(0))){
+						if (!domains.contains(serviceConfiguration.getDomain())) {
+							domains.add(serviceConfiguration.getDomain());
+						}
+					}
+                }
+			}
+		}
+		return domains.toArray(new String[domains.size()]);
+	}
+
+	public String[] getSubDomains(String cartridgeType, int tenantId) {
+		List<String> subDomains = new ArrayList<String>();
+		if(data.getServiceConfigs() != null){
+			List<ServiceConfiguration> serviceConfigs = data.getServiceConfigs().get(cartridgeType);
+			if(serviceConfigs != null){
+				
+				for (ServiceConfiguration serviceConfiguration : serviceConfigs) {
+	                
+					List<Integer> tenantIds = LoadBalancerConfigUtil.getTenantIds(serviceConfiguration.getTenantRange());
+					if(!tenantIds.isEmpty() && (tenantIds.contains(tenantId) || tenantIds.contains(0))){
+						if (!subDomains.contains(serviceConfiguration.getSubDomain())) {
+							subDomains.add(serviceConfiguration.getSubDomain());
+						}
+					}
+                }
+			}
+		}
+		return subDomains.toArray(new String[subDomains.size()]);
+	}
+
+    public String[] getActiveIPs(String cartridgeType, String domain, String subDomain) {
+		List<String> publicIps = new ArrayList<String>();
+		
+		if(domain == null || subDomain == null){
+			return new String[0];
+		}
+		
+		if(data.getServiceConfigs() != null){
+			List<ServiceConfiguration> serviceConfigs = data.getServiceConfigs().get(cartridgeType);
+			if(serviceConfigs != null){
+				
+				for (ServiceConfiguration serviceConfiguration : serviceConfigs) {
+	                
+					if(domain.equals(serviceConfiguration.getDomain()) && subDomain.equals(serviceConfiguration.getSubDomain())){
+						
+						String ipStr = serviceConfiguration.getPublicIp();
+						if(ipStr != null && !ipStr.isEmpty()){
+							for (String ip : ipStr.split(",")) {
+								if (!publicIps.contains(ip)) {
+									publicIps.add(ip);
+								}
+							}
+						}
+					}
+                }
+			}
+		}
+		return publicIps.toArray(new String[publicIps.size()]);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.wso2.carbon.stratos.topology.mgt.service.TopologyManagementService#getDomainsAndSubdomains(java.lang.String, int)
+	 */
+	public DomainContext[] getDomainsAndSubdomains(String cartridgeType, int tenantId) {
+		List<DomainContext> domainContexts = new ArrayList<DomainContext>();
+		
+		if(data.getServiceConfigs() != null){
+			List<ServiceConfiguration> serviceConfigs = data.getServiceConfigs().get(cartridgeType);
+			if(serviceConfigs != null){
+				
+				for (ServiceConfiguration serviceConfiguration : serviceConfigs) {
+	                
+					List<Integer> tenantIds = LoadBalancerConfigUtil.getTenantIds(serviceConfiguration.getTenantRange());
+					if(!tenantIds.isEmpty() && (tenantIds.contains(tenantId) || tenantIds.contains(0))){
+						DomainContext domainCtx = new DomainContext(serviceConfiguration.getDomain(), serviceConfiguration.getSubDomain());
+						if (!domainContexts.contains(domainCtx)) {
+							domainContexts.add(domainCtx);
+						}
+					}
+                }
+			}
+		}
+		return domainContexts.toArray(new DomainContext[domainContexts.size()]);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/serviceobjects/DomainContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/serviceobjects/DomainContext.java b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/serviceobjects/DomainContext.java
new file mode 100644
index 0000000..54357d2
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/serviceobjects/DomainContext.java
@@ -0,0 +1,90 @@
+/**
+ *  Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ *  Licensed 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.adc.topology.mgt.serviceobjects;
+
+/**
+ * Class to hold domain and subdomain details
+ *
+ */
+public class DomainContext {
+    
+    private String domain;
+    private String subDomain;
+    
+    /**
+     * Constructor
+     * 
+     * @param domain domain name
+     * @param subDomain subdomain name
+     */
+    public DomainContext (String domain, String subDomain) {
+        this.domain = domain;
+        this.subDomain = subDomain;
+    }
+
+    /**
+     * Returns the domain 
+     * 
+     * @return the domain
+     */
+    public String getDomain() {
+        return domain;
+    }
+
+    /**
+     * Returns the sub domain
+     * 
+     * @return the subDomain
+     */
+    public String getSubDomain() {
+        return subDomain;
+    }
+    
+    /**
+     * Overridden equals method
+     */
+    public boolean equals (Object object) {
+        if (object == null) 
+            return false;
+        if (object == this)  
+            return true;
+        if (!(object instanceof DomainContext))
+            return false;
+        
+        DomainContext domainCtx = (DomainContext)object;
+        if(this.getDomain().equals(domainCtx.getDomain()) &&
+                this.getSubDomain().equals(domainCtx.getSubDomain()))
+            return true;
+        else
+            return false;
+    }
+    
+    /**
+     * Overridden hashCode method
+     */
+    public int hashCode () {
+        int domainHash = 0;
+        int subDomainHash = 0;
+        
+        if(domain != null)
+            domainHash = domain.hashCode();
+        if(subDomain != null)
+            subDomainHash = subDomain.hashCode();
+        
+        return domainHash + subDomainHash;
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopicHealthChecker.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopicHealthChecker.java b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopicHealthChecker.java
new file mode 100644
index 0000000..de8f9df
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopicHealthChecker.java
@@ -0,0 +1,67 @@
+/*
+*  Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+*  WSO2 Inc. 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.adc.topology.mgt.subscriber;
+
+import javax.jms.TopicSubscriber;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This health checker runs forever, and is responsible for re-establishing a connection
+ * between SC and CC.
+ */
+public class TopicHealthChecker implements Runnable{
+    
+    private static final Log log = LogFactory.getLog(TopicHealthChecker.class);
+    private String topicName;
+    private TopicSubscriber subscriber;
+
+    public TopicHealthChecker(String topicName, TopicSubscriber subscriber) {
+        this.topicName = topicName;
+        this.subscriber = subscriber;
+    }
+    
+    @Override
+    public void run() {
+        log.info("Topic Health Checker is running... ");
+
+        while (true) {
+            try {
+                subscriber.getTopic();
+                
+                // health checker runs in every 30s
+                Thread.sleep(30000);
+
+            } catch (Exception e) {
+                // implies connection is not established
+                // sleep for 5s and retry
+                try {
+                    log.info("Health checker failed and will retry to establish a connection after a 5s.");
+                    Thread.sleep(5000);
+                    break;
+                } catch (InterruptedException ignore) {
+                }
+            }
+
+        }
+
+        TopologySubscriber.subscribe(topicName);
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologyListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologyListener.java b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologyListener.java
new file mode 100644
index 0000000..57289d7
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologyListener.java
@@ -0,0 +1,44 @@
+/*
+ *  Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ *  Licensed 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.adc.topology.mgt.subscriber;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.adc.topology.mgt.util.ConfigHolder;
+
+public class TopologyListener implements MessageListener {
+
+    private static final Log log = LogFactory.getLog(TopologyListener.class);
+
+    @SuppressWarnings("unchecked")
+    public void onMessage(Message message) {
+        TextMessage receivedMessage = (TextMessage) message;
+        try {
+
+            ConfigHolder.getInstance().getSharedTopologyDiffQueue().add(receivedMessage.getText());
+
+        } catch (JMSException e) {
+            log.error(e.getMessage(), e);
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriber.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriber.java b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriber.java
new file mode 100644
index 0000000..97bf94f
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriber.java
@@ -0,0 +1,92 @@
+/*
+ *  Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ *  Licensed 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.adc.topology.mgt.subscriber;
+
+import java.util.Properties;
+
+import javax.jms.*;
+import javax.naming.InitialContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.adc.topology.mgt.util.TopologyConstants;
+
+public class TopologySubscriber {
+
+	private static final Log log = LogFactory.getLog(TopologySubscriber.class);
+	
+    public static void subscribe(String topicName) {
+        Properties initialContextProperties = new Properties();
+        TopicSubscriber topicSubscriber = null;
+        TopicSession topicSession = null;
+        TopicConnection topicConnection = null;
+        InitialContext initialContext = null;
+
+        initialContextProperties.put("java.naming.factory.initial",
+            "org.wso2.andes.jndi.PropertiesFileInitialContextFactory");
+
+        String mbServerIp =
+            System.getProperty(TopologyConstants.MB_SERVER_IP) == null
+                ? TopologyConstants.DEFAULT_MB_SERVER_IP
+                : System.getProperty(TopologyConstants.MB_SERVER_IP);
+
+        String connectionString =
+            "amqp://admin:admin@clientID/carbon?brokerlist='tcp://" +
+                mbServerIp + "'&reconnect='true'";
+        initialContextProperties.put("connectionfactory.qpidConnectionfactory", connectionString);
+
+        try {
+            initialContext = new InitialContext(initialContextProperties);
+            TopicConnectionFactory topicConnectionFactory =
+                (TopicConnectionFactory) initialContext.lookup("qpidConnectionfactory");
+            topicConnection = topicConnectionFactory.createTopicConnection();
+            topicConnection.start();
+            topicSession =
+                topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+
+            Topic topic = topicSession.createTopic(topicName);
+            topicSubscriber =
+                topicSession.createSubscriber(topic);
+
+            topicSubscriber.setMessageListener(new TopologyListener());
+
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+
+            try {
+                if (topicSubscriber != null) {
+                    topicSubscriber.close();
+                }
+
+                if (topicSession != null) {
+                    topicSession.close();
+                }
+
+                if (topicConnection != null) {
+                    topicConnection.close();
+                }
+            } catch (JMSException e1) {
+                // ignore
+            }
+
+        } finally {
+            // start the health checker
+            Thread healthChecker = new Thread(new TopicHealthChecker(topicName, topicSubscriber));
+            healthChecker.start();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriberTask.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriberTask.java b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriberTask.java
new file mode 100644
index 0000000..525de89
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriberTask.java
@@ -0,0 +1 @@
+package org.apache.stratos.adc.topology.mgt.subscriber;

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/util/ConfigHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/util/ConfigHolder.java b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/util/ConfigHolder.java
new file mode 100644
index 0000000..a45aa8f
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/util/ConfigHolder.java
@@ -0,0 +1,197 @@
+/**
+ *  Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ *  Licensed 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.adc.topology.mgt.util;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.adc.topology.mgt.exception.TopologyMgtException;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
+import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration.ServiceConfiguration;
+import org.apache.stratos.lb.common.service.LoadBalancerConfigurationService;
+import org.wso2.carbon.ntask.core.service.TaskService;
+import org.wso2.carbon.registry.core.session.UserRegistry;
+import org.wso2.carbon.user.core.service.RealmService;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ *
+ */
+public class ConfigHolder {
+
+    private static ConfigHolder instance;
+    private static final Log log = LogFactory.getLog(ConfigHolder.class);
+
+    private SynapseConfiguration synapseConfiguration;
+    private ConfigurationContext configCtxt;
+    private AxisConfiguration axisConfiguration;
+    private UserRegistry configRegistry;
+    private UserRegistry governanceRegistry;
+    private TaskService taskService;
+    private BlockingQueue sharedTopologyDiffQueue = new LinkedBlockingQueue();
+    private String previousMessage;
+    private Map<String, List<ServiceConfiguration>> serviceNameToServiceConfigurations;
+//    private DependencyManagementService dependencyManager;
+    private LoadBalancerConfigurationService lbConfigService;
+    
+
+//    private Map<Integer, SynapseEnvironmentService> synapseEnvironmentServices =
+//            new HashMap<Integer, SynapseEnvironmentService>();
+
+    public RealmService getRealmService() {
+        return realmService;
+    }
+
+    public void setRealmService(RealmService realmService) {
+        this.realmService = realmService;
+    }
+
+    private RealmService realmService;
+
+    private ConfigHolder() {
+    }
+
+    public static ConfigHolder getInstance() {
+        if (instance == null) {
+            instance = new ConfigHolder();
+        }
+        return instance;
+    }
+
+    public SynapseConfiguration getSynapseConfiguration() throws TopologyMgtException{
+        assertNull("SynapseConfiguration", synapseConfiguration);
+        return synapseConfiguration;
+    }
+
+    public void setSynapseConfiguration(SynapseConfiguration synapseConfiguration) {
+        this.synapseConfiguration = synapseConfiguration;
+    }
+
+    public AxisConfiguration getAxisConfiguration() throws TopologyMgtException {
+        assertNull("AxisConfiguration", axisConfiguration);
+        return axisConfiguration;
+    }
+
+    public void setAxisConfiguration(AxisConfiguration axisConfiguration) {
+        this.axisConfiguration = axisConfiguration;
+    }
+
+    public UserRegistry getConfigRegistry() throws TopologyMgtException {
+        assertNull("Registry", configRegistry);
+        return configRegistry;
+    }
+
+    public void setConfigRegistry(UserRegistry configRegistry) {
+        this.configRegistry = configRegistry;
+    }
+
+////    public DependencyManagementService getDependencyManager() {
+////        return dependencyManager;
+////    }
+//
+//    public void setDependencyManager(DependencyManagementService dependencyManager) {
+//        this.dependencyManager = dependencyManager;
+//    }
+
+    private void assertNull(String name, Object object) throws TopologyMgtException {
+        if (object == null) {
+            String message = name + " reference in the proxy admin config holder is null";
+            log.error(message);
+            throw new TopologyMgtException(message);
+        }
+    }
+
+    public UserRegistry getGovernanceRegistry() {
+        return governanceRegistry;
+    }
+
+    public void setGovernanceRegistry(UserRegistry governanceRegistry) {
+        this.governanceRegistry = governanceRegistry;
+    }
+
+//    public SynapseEnvironmentService getSynapseEnvironmentService(int id) {
+//        return synapseEnvironmentServices.get(id);
+//    }
+//
+//    public void addSynapseEnvironmentService(int id,
+//                                             SynapseEnvironmentService synapseEnvironmentService) {
+//        synapseEnvironmentServices.put(id, synapseEnvironmentService);
+//    }
+//
+//    public void removeSynapseEnvironmentService(int id) {
+//        synapseEnvironmentServices.remove(id);
+//    }
+//
+//    public Map<Integer, SynapseEnvironmentService> getSynapseEnvironmentServices() {
+//        return synapseEnvironmentServices;
+//    }
+
+    public ConfigurationContext getConfigCtxt() {
+        return configCtxt;
+    }
+
+    public void setConfigCtxt(ConfigurationContext configCtxt) {
+        this.configCtxt = configCtxt;
+    }
+    
+    public void setLbConfigService(LoadBalancerConfigurationService lbConfigSer) {
+        this.lbConfigService = lbConfigSer;
+    }
+
+    public LoadBalancerConfiguration getLbConfig() {
+        return (LoadBalancerConfiguration) lbConfigService.getLoadBalancerConfig();
+    }
+    
+    public TaskService getTaskService() {
+        return taskService;
+    }
+
+    public void setTaskService(TaskService taskService) {
+        this.taskService = taskService;
+    }
+
+    public BlockingQueue getSharedTopologyDiffQueue() {
+	    return sharedTopologyDiffQueue;
+    }
+
+	public void setSharedTopologyDiffQueue(BlockingQueue sharedTopologyDiffQueue) {
+	    this.sharedTopologyDiffQueue = sharedTopologyDiffQueue;
+    }
+
+	public void setServiceConfigs(Map<String, List<ServiceConfiguration>> serviceNameToServiceConfigurations) {
+
+		this.serviceNameToServiceConfigurations = serviceNameToServiceConfigurations;
+    }
+	
+	public Map<String, List<ServiceConfiguration>> getServiceConfigs(){
+		return serviceNameToServiceConfigurations;
+	}
+
+	public String getPreviousMessage() {
+	    return previousMessage;
+    }
+
+	public void setPreviousMessage(String previousMessage) {
+	    this.previousMessage = previousMessage;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyConstants.java b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyConstants.java
new file mode 100644
index 0000000..984610d
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyConstants.java
@@ -0,0 +1,13 @@
+package org.apache.stratos.adc.topology.mgt.util;
+
+public class TopologyConstants {
+    
+    public static final String TOPIC_NAME = "cloud-controller-topology";
+    public static final String MB_SERVER_IP = "mb.server.ip";
+    public static final String DEFAULT_MB_SERVER_IP = "localhost:5673";
+    
+    public static final String TOPOLOGY_SYNC_CRON = "1 * * * * ? *";
+	public static final String TOPOLOGY_SYNC_TASK_NAME = "TopologySubscriberTaskOfADC";
+	public static final String TOPOLOGY_SYNC_TASK_TYPE = "TOPOLOGY_SUBSCRIBER_TASK";
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyMgtUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyMgtUtil.java b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyMgtUtil.java
new file mode 100644
index 0000000..01ff6db
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyMgtUtil.java
@@ -0,0 +1,5 @@
+package org.apache.stratos.adc.topology.mgt.util;
+
+public class TopologyMgtUtil {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.topology.mgt/src/main/resources/META-INF/services.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/src/main/resources/META-INF/services.xml b/components/org.apache.stratos.adc.topology.mgt/src/main/resources/META-INF/services.xml
new file mode 100644
index 0000000..ef91287
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/src/main/resources/META-INF/services.xml
@@ -0,0 +1,9 @@
+<serviceGroup>
+    <service name="TopologyMgtService" scope="application">
+        <parameter name="ServiceClass">org.apache.stratos.adc.topology.mgt.service.impl.TopologyManagementServiceImpl</parameter>
+        <messageReceivers>
+        <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
+        <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
+    </messageReceivers>
+    </service>
+</serviceGroup> 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.autoscaler.service/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler.service/pom.xml b/components/org.apache.stratos.autoscaler.service/pom.xml
new file mode 100644
index 0000000..cd31522
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler.service/pom.xml
@@ -0,0 +1,208 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     ~  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.
+     ~
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <parent>
+        <groupId>org.apache.stratos</groupId>
+        <artifactId>stratos-components-parent</artifactId>
+        <version>3.0.0-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.stratos</groupId>
+    <artifactId>org.apache.stratos.autoscaler.service</artifactId>
+    <packaging>aar</packaging>
+    <name>Apache Stratos - Autoscaler Service</name>
+    <url>http://apache.org</url>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <version>1.7.1</version>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                        <configuration>
+                            <artifactSet>
+                                <includes>
+                                    <include>org.jclouds:*</include>
+                                    <include>org.jclouds.*:*</include>
+                                </includes>
+                            </artifactSet>
+                            <filtering>true</filtering>
+                            <filters>
+                                <filter>
+                                    <artifact>org.jclouds*:*</artifact>
+                                    <includes>
+                                        <include>META-INF/services/org.jclouds.apis.ApiMetadata</include>
+                                        <include>META-INF/services/org.jclouds.providers.ProviderMetadata</include>
+                                    </includes>
+                                </filter>
+                            </filters>
+                            <transformers>
+                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer">
+                                </transformer>
+                            </transformers>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.axis2</groupId>
+                <artifactId>axis2-aar-maven-plugin</artifactId>
+                <version>1.4</version>
+                <extensions>true</extensions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>1.4.0</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Bundle-Name>${project.artifactId}</Bundle-Name>
+                        <Export-Package>
+                            org.apache.stratos.autoscaler.service
+                        </Export-Package>
+                        <Private-Package>
+                            org.apache.stratos.autoscaler.service.*, !org.apache.stratos.autoscaler.service
+                        </Private-Package>
+                        <Import-Package>
+                        	  !org.apache.commons.logging,
+                            org.apache.commons.logging; version=0.0.0,
+                            org.wso2.carbon.utils.*,
+                            org.jclouds.compute*;version="${jclouds.version}";resolution:=optional,
+                            org.jclouds*;version="${jclouds.version}",
+                            *; resolution:=optional
+                        </Import-Package>
+                        <DynamicImport-Package>*</DynamicImport-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.utils</artifactId>
+	    <version>${wso2carbon.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.stratos</groupId>
+            <artifactId>org.apache.stratos.lb.common</artifactId>
+            <version>${apache.stratos.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.securevault</artifactId>
+            <version>4.1.0</version>
+            <!--version>${wso2carbon.version}</version-->
+        </dependency>
+        <!--dependency>
+            <groupId>org.apache.synapse</groupId>
+            <artifactId>synapse-core</artifactId>
+            <version>${synapse.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.synapse</groupId>
+            <artifactId>synapse-commons</artifactId>
+            <version>${synapse.version}</version>
+        </dependency--> 
+	
+        <!--  Jclouds dependencies -->
+         <dependency>
+           <groupId>org.jclouds</groupId>
+           <artifactId>jclouds-allcompute</artifactId>
+           <version>${jclouds.version}</version>
+         </dependency>
+         <dependency>
+           <groupId>org.jclouds</groupId>
+           <artifactId>jclouds-compute</artifactId>
+           <version>${jclouds.version}</version>
+         </dependency>
+         <dependency>
+           <groupId>org.jclouds.driver</groupId>
+           <artifactId>jclouds-bouncycastle</artifactId>
+           <version>${jclouds.version}</version>
+           <exclusions>
+              <exclusion>
+                 <groupId>org.bouncycastle</groupId>
+                 <artifactId>bcprov-jdk16</artifactId>
+              </exclusion>
+           </exclusions>
+         </dependency>
+         <dependency>
+           <groupId>org.jclouds.driver</groupId>
+           <artifactId>jclouds-sshj</artifactId>
+           <version>${jclouds.version}</version>
+         </dependency>
+         <dependency>
+           <groupId>org.jclouds.driver</groupId>
+           <artifactId>jclouds-log4j</artifactId>
+           <version>${jclouds.version}</version>
+         </dependency>
+         <dependency>
+           <groupId>org.jclouds.driver</groupId>
+           <artifactId>jclouds-enterprise</artifactId>
+           <version>${jclouds.version}</version>
+         </dependency>
+         <!--dependency>
+           <groupId>org.jclouds.api</groupId>
+           <artifactId>ec2</artifactId>
+           <version>${jclouds.version}</version>
+         </dependency>
+         <dependency>
+           <groupId>org.jclouds.provider</groupId>
+           <artifactId>aws-ec2</artifactId>
+           <version>${jclouds.version}</version>
+         </dependency>
+         <dependency>
+           <groupId>org.jclouds.api</groupId>
+           <artifactId>openstack-nova</artifactId>
+           <version>${jclouds.version}</version>
+         </dependency-->
+       
+    </dependencies>
+
+    <properties>
+        <jclouds.version>1.5.0-beta.5</jclouds.version>
+    </properties>
+
+</project>
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/IAutoscalerService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/IAutoscalerService.java b/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/IAutoscalerService.java
new file mode 100644
index 0000000..9bf06fc
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/IAutoscalerService.java
@@ -0,0 +1,112 @@
+/**
+ *  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.autoscaler.service;
+
+import org.apache.stratos.lb.common.conf.util.Constants;
+
+/**
+ * This Interface provides a way for a component, to communicate with an underline
+ * Infrastructure which are supported by <i>JClouds</i>.
+ * 
+ */
+public interface IAutoscalerService {
+    
+    /**
+     * Initialize the service.
+     * @param isSpi if this service is to be used by SPI, this parameter should be set to
+     * true. When this is true, you should specify an image id, each time you
+     * are starting an instance i.e. you should use {@link #startSpiInstance(String, String)}
+     * method, instead of using {@link #startInstance(String)}.
+     * @return
+     */
+    public boolean initAutoscaler(boolean isSpi);
+
+    
+    /**
+     * Calling this method will result in an instance startup, which is belong
+     * to the provided service domain. This method is non-blocking, means we do not
+     * wait till the instance is started up. Also note that the instance that is starting up
+     * belongs to the group whose name is derived from its service domain, replacing <i>.</i>
+     * by a hyphen (<i>-</i>). 
+     * @param domainName service clustering domain of the instance to be started up.
+     * @param sudDomainName service clustering sub domain of the instance to be started up.
+     * If this is null, the default value will be used. Default value is 
+     * {@link Constants}.DEFAULT_SUB_DOMAIN.
+     * @return whether the starting up is successful or not.
+     */
+    public boolean startInstance(String domainName, String sudDomainName);
+    
+    /**
+     * Calling this method will result in an instance startup, which is belong
+     * to the provided service domain. This method will return the public IP address of
+     * the instance that is started. Thus, this method is blocking, since we need to 
+     * return the IP Address and for that we have to wait till the instance started up.
+     * @param domainName should be in following format.
+     * <code>${service-domain}\t\${tenant-id}</code>.
+     * @param imageId starting instance will be an instance of this image. Image id should
+     * be a valid one.
+     * @param sudDomainName service clustering sub domain of the instance to be started up.
+     * If this is null, the default value will be used. Default value is 
+     * {@link Constants}.DEFAULT_SUB_DOMAIN.
+     * @return public IP address of the instance in String format. If instance failed to 
+     * start, this will return an empty String.
+     */
+    public String startSpiInstance(String domainName, String subDomainName, String imageId);
+    
+   
+    /**
+     * Calling this method will result in termination of an instance which is belong
+     * to the provided service domain.
+     * @param domainName service domain of the instance to be terminated.
+     * @param sudDomainName service clustering sub domain of the instance to be started up.
+     * If this is null, the default value will be used. Default value is {@link Constants}.DEFAULT_SUB_DOMAIN.
+     * @return whether an instance terminated successfully or not.
+     */
+	public boolean terminateInstance(String domainName, String subDomainName);
+	
+	/**
+	 * Calling this method will result in termination of the lastly spawned instance which is
+	 * belong to the provided service domain.
+	 * @param domainName service domain of the instance to be terminated.
+	 * @param sudDomainName service clustering sub domain of the instance to be started up.
+     * If this is null, the default value will be used. Default value is {@link Constants}.DEFAULT_SUB_DOMAIN.
+	 * @return whether the termination is successful or not.
+	 */
+	public boolean terminateLastlySpawnedInstance(String domainName, String subDomainName);
+	
+	/**
+     * Calling this method will result in termination of an instance which has the
+     * provided public IP address.
+     * @param publicIp public IP address of the instance to be terminated.
+     * @return whether the instance terminated successfully or not.
+     */
+    public boolean terminateSpiInstance(String publicIp);
+	
+	/**
+	 * Calling this method will result in returning the pending instances
+	 * count of a particular domain.
+	 * @param domainName service domain
+	 * @param sudDomainName service clustering sub domain of the instance to be started up.
+     * If this is null, the default value will be used. Default value is {@link Constants}.DEFAULT_SUB_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 domainName, String subDomainName);
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/AutoscalerServiceException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/AutoscalerServiceException.java b/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/AutoscalerServiceException.java
new file mode 100644
index 0000000..70e82c8
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/AutoscalerServiceException.java
@@ -0,0 +1,33 @@
+/**
+ *  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.autoscaler.service.exception;
+
+public class AutoscalerServiceException extends RuntimeException {
+    
+    private static final long serialVersionUID = -6326227079367867222L;
+
+    public AutoscalerServiceException(String msg) {
+        super(msg);
+    }
+    
+    public AutoscalerServiceException(String msg, Exception ex) {
+        super(msg, ex);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/DeserializationException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/DeserializationException.java b/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/DeserializationException.java
new file mode 100644
index 0000000..01819d1
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/DeserializationException.java
@@ -0,0 +1,33 @@
+/**
+ *  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.autoscaler.service.exception;
+
+public class DeserializationException extends RuntimeException {
+    
+    private static final long serialVersionUID = -2426068347954381831L;
+
+    public DeserializationException(String msg) {
+        super(msg);
+    }
+    
+    public DeserializationException(String msg, Exception ex) {
+        super(msg, ex);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/MalformedConfigurationFileException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/MalformedConfigurationFileException.java b/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/MalformedConfigurationFileException.java
new file mode 100644
index 0000000..090e931
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/MalformedConfigurationFileException.java
@@ -0,0 +1,33 @@
+/**
+ *  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.autoscaler.service.exception;
+
+public class MalformedConfigurationFileException extends RuntimeException {
+
+    private static final long serialVersionUID = -1662095377704279326L;
+    
+    public MalformedConfigurationFileException(String msg) {
+        super(msg);
+    }
+    
+    public MalformedConfigurationFileException(String msg, Exception ex) {
+        super(msg, ex);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/NoInstanceFoundException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/NoInstanceFoundException.java b/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/NoInstanceFoundException.java
new file mode 100644
index 0000000..be9356f
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/NoInstanceFoundException.java
@@ -0,0 +1,39 @@
+/**
+ *  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.autoscaler.service.exception;
+
+/**
+ * This will throw when no instance is found
+ */
+public class NoInstanceFoundException extends Exception {
+
+    /**
+     * For serializing requirement
+     */
+    private static final long serialVersionUID = -435060299292679892L;
+
+
+    public NoInstanceFoundException(String msg) {
+        super(msg);
+    }
+    
+    public NoInstanceFoundException(String msg, Exception ex) {
+        super(msg, ex);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/SerializationException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/SerializationException.java b/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/SerializationException.java
new file mode 100644
index 0000000..0ccbd61
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler.service/src/main/java/org/apache/stratos/autoscaler/service/exception/SerializationException.java
@@ -0,0 +1,33 @@
+/**
+ *  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.autoscaler.service.exception;
+
+public class SerializationException extends RuntimeException {
+    
+    private static final long serialVersionUID = -3701458642228072331L;
+
+    public SerializationException(String msg) {
+        super(msg);
+    }
+    
+    public SerializationException(String msg, Exception ex) {
+        super(msg, ex);
+    }
+
+}