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/05 12:32:53 UTC

[16/34] committing refactoered adc components and top level pom in components

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/replication/RequestTokenReplicationCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/replication/RequestTokenReplicationCommand.java b/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/replication/RequestTokenReplicationCommand.java
new file mode 100644
index 0000000..5d26a2c
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/replication/RequestTokenReplicationCommand.java
@@ -0,0 +1,73 @@
+/**
+ *  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.lb.common.replication;
+
+import org.apache.axis2.clustering.ClusteringCommand;
+import org.apache.axis2.clustering.ClusteringFault;
+import org.apache.axis2.clustering.ClusteringMessage;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+
+/**
+ * This is the notification message a primary load balancer will send to all other load balancers
+ * in the cluster, to replicate its state. When the other load balancers received this message, 
+ * they will set their states to the state of primary load balancer.
+ */
+public class RequestTokenReplicationCommand extends ClusteringMessage {
+
+    private static final long serialVersionUID = -7897961078018830555L;
+    private static final Log log = LogFactory.getLog(RequestTokenReplicationCommand.class);
+    private Map<String, Map<String, ?>> appDomainContexts;
+
+    public Map<String, Map<String, ?>> getAppDomainContexts() {
+        return appDomainContexts;
+    }
+
+    public void setAppDomainContexts(Map<String, Map<String, ?>> appDomainContexts) {
+        this.appDomainContexts = appDomainContexts;
+    }
+
+    public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
+        // set the appDomainContexts map
+        configurationContext.setNonReplicableProperty("autoscale.app.domain.contexts",
+                                          getAppDomainContexts());
+        
+        log.info("Request Tokens Replicated! ");
+    }
+
+    public String toString() {
+        return "Replication message sent!";
+    }
+
+    @Override
+    public ClusteringCommand getResponse() {
+        return new ClusteringCommand() {
+            
+            private static final long serialVersionUID = -8271265673996681347L;
+
+            @Override
+            public void execute(ConfigurationContext arg0) throws ClusteringFault {
+                // do nothing
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/service/LoadBalancerConfigurationService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/service/LoadBalancerConfigurationService.java b/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/service/LoadBalancerConfigurationService.java
new file mode 100644
index 0000000..5958ad9
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/service/LoadBalancerConfigurationService.java
@@ -0,0 +1,79 @@
+/**
+ *  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.lb.common.service;
+
+import org.apache.stratos.lb.common.conf.util.HostContext;
+
+import java.util.Map;
+
+/**
+ * This service provides a way to consume details in loadbalancer.conf file.
+ * Also to update the runtime object model of loadbalancer conf.
+ */
+public interface LoadBalancerConfigurationService {
+
+    /**
+     * Provides a reference to the runtime object model of loadbalancer.conf
+     * @return {@link Object} which is an instance of {@link org.apache.stratos.lb.common.conf.LoadBalancerConfiguration}
+     */
+    public Object getLoadBalancerConfig();
+    
+//    /**
+//     * Return a {@link Map} of {@link HostContext} objects, built using the given config.
+//     * @param config service configuration.
+//     * @return {@link Map} {@link Object}
+//     */
+//    public Object getHostContext(String config);
+    
+    /**
+     * Return a {@link Map} of {@link HostContext} objects, built using the given configuration.
+     * @param config service configuration diff. This can be in following format.
+     * 
+     * <p/>
+     * appserver {
+     * hosts                   appserver.cloud-test.wso2.com;
+     * domains   {
+     * 		wso2.as1.domain {
+     * 			tenant_range    1-100;
+     * 		}
+     *		wso2.as2.domain {
+     * 			tenant_range    101-200;
+     * 		}
+     * 		wso2.as3.domain {
+     *	 		tenant_range    *;
+     * 		}
+     * 	}
+     * } 
+     * <p/>
+     * esb {
+     * hosts                   esb.cloud-test.wso2.com;
+     * domains   {
+     * 		wso2.esb.domain {
+     *	 		tenant_range    *;
+     * 		}
+     * 	}
+     * }
+     * <p/>
+     * @return a {@link Map} of {@link HostContext} objects.
+     * key - host name
+     * Value - {@link HostContext}
+     */
+    public Object getHostContexts(String config) ;
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/service/impl/LoadBalancerConfigurationServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/service/impl/LoadBalancerConfigurationServiceImpl.java b/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/service/impl/LoadBalancerConfigurationServiceImpl.java
new file mode 100644
index 0000000..99c2ced
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/service/impl/LoadBalancerConfigurationServiceImpl.java
@@ -0,0 +1,60 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+
+ *  http://www.apache.org/licenses/LICENSE-2.0
+
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.stratos.lb.common.service.impl;
+
+import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
+import org.apache.stratos.lb.common.conf.structure.Node;
+import org.apache.stratos.lb.common.conf.structure.NodeBuilder;
+import org.apache.stratos.lb.common.conf.util.Constants;
+import org.apache.stratos.lb.common.conf.util.HostContext;
+import org.apache.stratos.lb.common.service.LoadBalancerConfigurationService;
+
+import java.util.Map;
+
+public class LoadBalancerConfigurationServiceImpl implements LoadBalancerConfigurationService {
+
+    @Override
+    public Object getLoadBalancerConfig() {
+        return LoadBalancerConfiguration.getInstance();
+    }
+
+	@Override
+    public Object getHostContexts(String config) {
+
+		// build a Node object for whole loadbalancer.conf
+        Node rootNode = new Node();
+        rootNode.setName(Constants.SERVICES_ELEMENT);
+        rootNode = NodeBuilder.buildNode(rootNode, config);
+		
+        Map<String, HostContext> oldMap = LoadBalancerConfiguration.getInstance().getHostContextMap();
+        LoadBalancerConfiguration.getInstance().createServicesConfig(rootNode);
+        
+//        MapDifference<String, HostContext> diff = Maps.difference(LoadBalancerConfiguration.getInstance().getHostContextMap(),
+//                                                             oldMap );
+//		
+//		return diff.entriesOnlyOnLeft();
+        return LoadBalancerConfiguration.getInstance().getHostContextMap();
+    }
+
+//	@Override
+//    public Object getHostContext(String config) {
+//	    return null;
+//    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/util/DomainMapping.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/util/DomainMapping.java b/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/util/DomainMapping.java
new file mode 100644
index 0000000..7355833
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/main/java/org/apache/stratos/lb/common/util/DomainMapping.java
@@ -0,0 +1,40 @@
+/**
+ *  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.lb.common.util;
+
+/**
+ *
+ */
+public class DomainMapping {
+    private String mapping;
+    private String actualHost;
+
+    public DomainMapping(String mapping) {
+        this.mapping = mapping;
+    }
+
+    public String getActualHost() {
+        return actualHost;
+    }
+
+    public void setActualHost(String actualHost) {
+        this.actualHost = actualHost;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/main/resources/META-INF/services.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/main/resources/META-INF/services.xml b/components/org.apache.stratos.lb.common/4.1.3/src/main/resources/META-INF/services.xml
new file mode 100644
index 0000000..6d1f398
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/main/resources/META-INF/services.xml
@@ -0,0 +1,9 @@
+<serviceGroup>
+    <service name="LoadBalancerConfigurationService" scope="application">
+        <parameter name="ServiceClass">org.wso2.stratos.lb.common.service.impl.LoadBalancerConfigurationServiceImpll</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/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/test/java/org/apache/stratos/lb/common/test/LoadBalancerConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/test/java/org/apache/stratos/lb/common/test/LoadBalancerConfigurationTest.java b/components/org.apache.stratos.lb.common/4.1.3/src/test/java/org/apache/stratos/lb/common/test/LoadBalancerConfigurationTest.java
new file mode 100644
index 0000000..4efbbd2
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/test/java/org/apache/stratos/lb/common/test/LoadBalancerConfigurationTest.java
@@ -0,0 +1,169 @@
+/**
+ *  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.lb.common.test;
+
+import java.io.File;
+
+import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
+import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration.ServiceConfiguration;
+import org.apache.stratos.lb.common.conf.util.HostContext;
+
+import junit.framework.TestCase;
+
+public class LoadBalancerConfigurationTest extends TestCase {
+    
+    private LoadBalancerConfiguration lbConfig ;
+    private LoadBalancerConfiguration lbConfig1;
+    
+    
+    @Override
+    protected void setUp() throws Exception {
+
+        LoadBalancerConfiguration.setInstance(null);
+        File f = new File("src/test/resources/loadbalancer.conf");
+        System.setProperty("loadbalancer.conf", f.getAbsolutePath());
+        lbConfig = LoadBalancerConfiguration.getInstance();
+    }
+    
+    public final void testCreateLoadBalancerConfig() {
+
+        LoadBalancerConfiguration.LBConfiguration loadBalancerConfig =
+            lbConfig.getLoadBalancerConfig();
+        
+        assertEquals(1, loadBalancerConfig.getInstances());
+        assertEquals(5000, loadBalancerConfig.getAutoscalerTaskInterval());
+        assertEquals(15000, loadBalancerConfig.getServerStartupDelay());
+    }
+
+    public final void testCreateServicesConfig() {
+
+        /* Tests relavant to loadbalancer.conf file */
+        
+        ServiceConfiguration asServiceConfig =
+                                               lbConfig.getServiceConfig("wso2.as1.domain",
+                                                                         "worker");
+
+        assertEquals(1, asServiceConfig.getInstancesPerScaleUp());
+        assertEquals(5, asServiceConfig.getMaxAppInstances());
+        assertEquals(0, asServiceConfig.getMinAppInstances());
+        assertEquals(60000, asServiceConfig.getMessageExpiryTime());
+        assertEquals(400, asServiceConfig.getMaxRequestsPerSecond());
+        assertEquals(0.65, asServiceConfig.getAlarmingUpperRate());
+        assertEquals(10, asServiceConfig.getRoundsToAverage());
+        assertEquals("worker", asServiceConfig.getSubDomain());
+
+        asServiceConfig = lbConfig.getServiceConfig("wso2.as2.domain", "worker1");
+        assertEquals("worker1", asServiceConfig.getSubDomain());
+
+        asServiceConfig = lbConfig.getServiceConfig("wso2.esb.domain", "mgt");
+        assertEquals("mgt", asServiceConfig.getSubDomain());
+
+        assertEquals(2, lbConfig.getHostNamesTracker().keySet().size());
+        assertEquals(3, lbConfig.getHostNamesTracker().get("appserver").size());
+        assertEquals(2, lbConfig.getHostNamesTracker().get("esb").size());
+
+        for (HostContext ctx : lbConfig.getHostContextMap().values()) {
+
+            if (ctx.getHostName().equals("appserver.cloud-test.wso2.com")) {
+
+                assertEquals("nirmal", ctx.getSubDomainFromTenantId(30));
+                assertEquals(18, ctx.getTenantDomainContexts().size());
+            } else if (ctx.getHostName().equals("as2.cloud-test.wso2.com")) {
+                assertEquals("worker", ctx.getSubDomainFromTenantId(2));
+            } else if (ctx.getHostName().equals("esb.cloud-test.wso2.com")) {
+                assertEquals("mgt", ctx.getSubDomainFromTenantId(5));
+            }
+        }
+        
+        /* tests relevant to loadbalancer1.conf file */
+        
+        File f = new File("src/test/resources/loadbalancer2.conf");
+        System.setProperty("loadbalancer.conf", f.getAbsolutePath());
+        
+        LoadBalancerConfiguration.setInstance(null);
+        lbConfig1 = LoadBalancerConfiguration.getInstance();
+        
+        for (HostContext ctx : lbConfig1.getHostContextMap().values()) {
+
+            if (ctx.getHostName().equals("appserver.cloud-test.wso2.com")) {
+
+                assertEquals("nirmal", ctx.getSubDomainFromTenantId(30));
+                assertEquals("wso2.as1.domain", ctx.getDomainFromTenantId(5));
+                assertEquals("wso2.as.domain", ctx.getDomainFromTenantId(8));
+                assertEquals("wso2.as.domain", ctx.getDomainFromTenantId(2));
+                assertEquals(4, ctx.getTenantDomainContexts().size());
+                
+            } else if (ctx.getHostName().equals("esb.cloud-test.wso2.com")) {
+                
+                assertEquals("mgt", ctx.getSubDomainFromTenantId(5));
+            }
+        }
+
+    }
+
+    public final void testGetServiceDomains() throws Exception {
+
+        setUp();
+        String[] serviceDomains = lbConfig.getServiceDomains();
+        assertEquals(4, serviceDomains.length);
+        
+        assertTrue("wso2.as1.domain".equals(serviceDomains[0]) ||
+            "wso2.as1.domain".equals(serviceDomains[1]) ||
+            "wso2.as1.domain".equals(serviceDomains[2]) ||
+            "wso2.as1.domain".equals(serviceDomains[3]));
+        
+        assertTrue("wso2.as2.domain".equals(serviceDomains[0]) ||
+            "wso2.as2.domain".equals(serviceDomains[1]) ||
+            "wso2.as2.domain".equals(serviceDomains[2]) ||
+            "wso2.as2.domain".equals(serviceDomains[3]));
+        
+        assertTrue("wso2.as3.domain".equals(serviceDomains[0]) ||
+            "wso2.as3.domain".equals(serviceDomains[1]) ||
+            "wso2.as3.domain".equals(serviceDomains[2]) ||
+            "wso2.as3.domain".equals(serviceDomains[3]));
+        
+        assertTrue("wso2.esb.domain".equals(serviceDomains[0]) ||
+                   "wso2.esb.domain".equals(serviceDomains[1]) ||
+                   "wso2.esb.domain".equals(serviceDomains[2]) ||
+                   "wso2.esb.domain".equals(serviceDomains[3]));
+        
+    }
+    
+    public final void testGetServiceSubDomains() throws Exception {
+
+        setUp();
+        String[] serviceSubDomains = lbConfig.getServiceSubDomains("wso2.as3.domain");
+        assertEquals(2, serviceSubDomains.length);
+        
+        assertTrue("nirmal".equals(serviceSubDomains[0]) ||
+            "nirmal".equals(serviceSubDomains[1]));
+        
+        assertTrue("nirmal2".equals(serviceSubDomains[0]) ||
+            "nirmal2".equals(serviceSubDomains[1]));
+        
+        serviceSubDomains = lbConfig.getServiceSubDomains("wso2.esb.domain");
+        assertEquals(2, serviceSubDomains.length);
+        
+        serviceSubDomains = lbConfig.getServiceSubDomains("wso2.as1.domain");
+        assertEquals(1, serviceSubDomains.length);
+        
+        
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/test/java/org/apache/stratos/lb/common/test/NodeBuilderTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/test/java/org/apache/stratos/lb/common/test/NodeBuilderTest.java b/components/org.apache.stratos.lb.common/4.1.3/src/test/java/org/apache/stratos/lb/common/test/NodeBuilderTest.java
new file mode 100644
index 0000000..e3b2f5e
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/test/java/org/apache/stratos/lb/common/test/NodeBuilderTest.java
@@ -0,0 +1,124 @@
+/**
+ *  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.lb.common.test;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.stratos.lb.common.conf.structure.Node;
+import org.apache.stratos.lb.common.conf.structure.NodeBuilder;
+
+public class NodeBuilderTest extends TestCase {
+
+    String content;
+
+    public void setUp() throws Exception {
+    }
+
+    public final void testBuildNode() {
+
+        // Testing a node only has properties
+        Node a = new Node();
+        a.setName("loadbalancer");
+
+        content =
+            "securityGroups      stratos-appserver-lb;\ninstanceType        m1.large;\n"
+                + "instances           1;\nelasticIP           ${ELASTIC_IP};\n"
+                + "availabilityZone    us-east-1c;\npayload             /mnt/payload.zip;";
+
+        a = NodeBuilder.buildNode(a, content);
+
+        Assert.assertEquals("loadbalancer", a.getName());
+        Assert.assertEquals("stratos-appserver-lb", a.getProperty("securityGroups"));
+        Assert.assertEquals("${ELASTIC_IP}", a.getProperty("elasticIP"));
+        Assert.assertEquals("/mnt/payload.zip", a.getProperty("payload"));
+        Assert.assertNull(a.getProperty("payloader"));
+
+        // Testing a node has sub nodes and properties
+        a = new Node();
+        a.setName("appserver");
+
+        content =
+            "hosts                   appserver.cloud-test.wso2.com,as.cloud-test.wso2.com;\n"
+                + "domains   {\n" + "wso2.as1.domain {\n" + "tenant_range    1-100;\n" + "}\n"
+                + "wso2.as2.domain {\n" + "tenant_range    101-200;\n" + "}\n"
+                + "wso2.as3.domain { # domain\n" + "tenant_range    *;\n" + "}\n" + "}\n"
+                + "# line comment \n"
+                + "payload                 resources/cluster_node.zip;# payload\n"
+                + "availability_zone       us-east-1c;\n";
+
+        a = NodeBuilder.buildNode(a, content);
+
+        Assert.assertEquals("appserver", a.getName());
+        Assert.assertEquals(1, a.getChildNodes().size());
+        Assert.assertEquals("domains", a.getChildNodes().get(0).getName());
+        Assert.assertEquals("appserver.cloud-test.wso2.com,as.cloud-test.wso2.com",
+                            a.getProperty("hosts"));
+        Assert.assertEquals("resources/cluster_node.zip", a.getProperty("payload"));
+        Assert.assertEquals(null, a.getProperty("payloader"));
+
+        Node b = a.getChildNodes().get(0);
+
+        Assert.assertEquals(3, b.getChildNodes().size());
+        Assert.assertEquals(null, b.getProperty("payload"));
+
+        Node c = b.getChildNodes().get(0);
+
+        Assert.assertEquals(0, c.getChildNodes().size());
+        Assert.assertEquals("1-100", c.getProperty("tenant_range"));
+
+        c = b.getChildNodes().get(2);
+
+        Assert.assertEquals(0, c.getChildNodes().size());
+        Assert.assertEquals("*", c.getProperty("tenant_range"));
+        
+        String nodeStr = "appserver {\n" +
+                "\thosts\tappserver.cloud-test.wso2.com,as.cloud-test.wso2.com;\n" +
+                "\tpayload\tresources/cluster_node.zip;\n" +
+        		"\tavailability_zone\tus-east-1c;\n" +
+        		"\tdomains {\n" +
+        		"\t\twso2.as1.domain {\n" +
+        		"\t\t\ttenant_range\t1-100;\n" +
+        		"\t\t}\n" +
+        		"\t\twso2.as2.domain {\n" +
+        		"\t\t\ttenant_range\t101-200;\n" +
+        		"\t\t}\n" +
+        		"\t\twso2.as3.domain {\n" +
+        		"\t\t\ttenant_range\t*;\n" +
+        		"\t\t}\n" +
+        		"\t}\n" +
+        		"}";
+        
+        assertEquals(nodeStr, a.toString());
+        
+        // test equals method
+        assertEquals(true, a.equals(a));
+        assertEquals(false, a.equals(b));
+        assertEquals(false, c.equals(b));
+        
+        // test buildNode(String)
+        c = NodeBuilder.buildNode(nodeStr);
+        
+        assertEquals(c.getName(), "appserver");
+        assertEquals(c.getChildNodes().size(), 1);
+        assertEquals(c.getProperty("availability_zone"), "us-east-1c");
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/loadbalancer.conf
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/loadbalancer.conf b/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/loadbalancer.conf
new file mode 100644
index 0000000..b2fd44f
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/loadbalancer.conf
@@ -0,0 +1,64 @@
+loadbalancer {
+    instances	1;
+    enable_autoscaler	true;
+    # interval between two task executions in milliseconds
+    autoscaler_task_interval	5000;
+    # after an instance booted up, task will wait till this much of time and let the server started up
+    server_startup_delay		15000; #default will be 60000ms
+}
+
+services {
+    defaults {
+        min_app_instances 1;
+        max_app_instances       5;
+        max_requests_per_second   400;
+        alarming_upper_rate 0.65;
+        alarming_lower_rate 0.2;
+        scale_down_factor 0.25;
+        rounds_to_average       10;
+        instances_per_scale_up  1;
+        message_expiry_time     60000;
+    }
+
+    appserver {
+        hosts                   appserver.cloud-test.wso2.com, as.cloud-test.wso2.com;
+        sub_domain      worker1;
+        domains   {
+            wso2.as1.domain {
+            	hosts as2.cloud-test.wso2.com;
+            	  min_app_instances   0;
+            	  sub_domain      worker;
+                tenant_range    1-5;
+            }
+            wso2.as2.domain {
+                tenant_range    7;
+            }
+            wso2.as3.domain {
+                sub_domain nirmal;
+                tenant_range    10-20;
+            }
+            
+            wso2.as3.domain {
+                sub_domain nirmal2;
+                tenant_range    21-25;
+            }
+            
+            wso2.esb.domain {
+            	sub_domain nirmal;
+                tenant_range    *;
+            }
+        }
+    }
+    
+    esb {
+        hosts                   esb.cloud-test.wso2.com,mgt.as.cloud-test.wso2.com;
+        domains   {
+            wso2.esb.domain {
+                sub_domain      mgt;
+                tenant_range    *;
+            }
+        }
+    }
+
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/loadbalancer1.conf
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/loadbalancer1.conf b/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/loadbalancer1.conf
new file mode 100644
index 0000000..8b87a32
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/loadbalancer1.conf
@@ -0,0 +1,39 @@
+loadbalancer {
+    instances	1;
+    enable_autoscaler	true;
+    # interval between two task executions in milliseconds
+    autoscaler_task_interval	5000;
+    # after an instance booted up, task will wait till this much of time and let the server started up
+    server_startup_delay		15000; #default will be 60000ms
+}
+
+services {
+
+    appserver {
+        hosts                   appserver.cloud-test.wso2.com, as.cloud-test.wso2.com;
+        sub_domain      worker1;
+        domains   {
+            
+            wso2.as.domain {
+            	sub_domain nirmal;
+                tenant_range    *;
+            }
+            wso2.as1.domain {
+            	sub_domain nirmal;
+                tenant_range    5-7;
+            }
+        }
+    }
+    
+    esb {
+        hosts                   esb.cloud-test.wso2.com, mgt.as.cloud-test.wso2.com;
+        domains   {
+            wso2.esb.domain {
+                sub_domain      mgt;
+                tenant_range    *;
+            }
+        }
+    }
+
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/loadbalancer2.conf
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/loadbalancer2.conf b/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/loadbalancer2.conf
new file mode 100644
index 0000000..718d881
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/loadbalancer2.conf
@@ -0,0 +1,30 @@
+services {
+
+    appserver {
+        hosts                   appserver.cloud-test.wso2.com, as.cloud-test.wso2.com;
+        sub_domain      worker1;
+        domains   {
+            
+            wso2.as.domain {
+            	sub_domain nirmal;
+                tenant_range    *;
+            }
+            wso2.as1.domain {
+            	sub_domain nirmal;
+                tenant_range    5-7;
+            }
+        }
+    }
+    
+    esb {
+        hosts                   esb.cloud-test.wso2.com, mgt.as.cloud-test.wso2.com;
+        domains   {
+            wso2.esb.domain {
+                sub_domain      mgt;
+                tenant_range    *;
+            }
+        }
+    }
+
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/testng.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/testng.xml b/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/testng.xml
new file mode 100644
index 0000000..44b9822
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/4.1.3/src/test/resources/testng.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+<suite name="Default suite">
+  <test verbose="2" name="Default test">
+    <classes>
+      <!--class name="org.wso2.carbon.lb.common.test.AgentPersistenceManagerTest">
+          <methods>
+            <include name="addZone" />
+              <include name="addHostMachine" />
+              <include name="deleteHostMachine" />
+          </methods>
+      </class-->
+    </classes>
+  </test>
+</suite>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.wso2.carbon.adc.mgt.cli/2.1.3/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/pom.xml b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/pom.xml
deleted file mode 100644
index 44c27ce..0000000
--- a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/pom.xml
+++ /dev/null
@@ -1,125 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- ~ Copyright (c) 2009-2010, 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. -->
-<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>2.0.0</version>
-                <relativePath>../../pom.xml</relativePath>
-	</parent>
-
-	<modelVersion>4.0.0</modelVersion>
-	<artifactId>org.apache.stratos.adc.mgt.cli</artifactId>
-        <version>2.1.3</version>
-	<packaging>jar</packaging>
-	<name>Apache Stratos - ADC Management CLI</name>
-	<description>ADC management CLI bundle</description>
-	<url>http://apache.org</url>
-	
-	<properties>
-		<slf4j.version>1.7.5</slf4j.version>
-	</properties>
-
-	<dependencies>
-		<!-- <dependency>
-			<groupId>org.wso2.carbon</groupId>
-			<artifactId>org.wso2.carbon.ui</artifactId>
-		</dependency> -->
-		<!-- Adding HttpClient dependencies. Those were resolved with above one -->
-		<dependency>
-			<groupId>commons-httpclient</groupId>
-			<artifactId>commons-httpclient</artifactId>
-			<version>${commons-httpclient.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.wso2.securevault</groupId>
-			<artifactId>org.wso2.securevault</artifactId>
-			<version>1.0.0-wso2v2</version>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.httpcomponents.wso2</groupId>
-			<artifactId>httpcore</artifactId>
-			<version>4.1.0-wso2v1</version>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.stratos</groupId>
-			<artifactId>org.apache.stratos.adc.mgt.stub</artifactId>
-			<version>4.1.3</version>
-		</dependency>
-		<dependency>
-			<groupId>commons-cli</groupId>
-			<artifactId>commons-cli</artifactId>
-			<version>1.2</version>
-		</dependency>
-		<dependency>
-			<groupId>jline</groupId>
-			<artifactId>jline</artifactId>
-			<version>2.11</version>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.commons</groupId>
-			<artifactId>commons-lang3</artifactId>
-			<version>3.1</version>
-		</dependency>
-		<dependency>
-			<groupId>commons-validator</groupId>
-			<artifactId>commons-validator</artifactId>
-			<version>1.4.0</version>
-		</dependency>
-		<!-- Logging -->
-		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-api</artifactId>
-			<version>${slf4j.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-log4j12</artifactId>
-			<version>${slf4j.version}</version>
-			<scope>runtime</scope>
-		</dependency>
-		<dependency>
-			<groupId>com.google.code.gson</groupId>
-			<artifactId>gson</artifactId>
-			<version>2.1</version>
-		</dependency>
-	</dependencies>
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-assembly-plugin</artifactId>
-				<configuration>
-					<archive>
-						<manifest>
-							<mainClass>org.apache.stratos.adc.mgt.cli.CliTool</mainClass>
-						</manifest>
-					</archive>
-					<descriptors>
-						<descriptor>src/main/assembly/src.xml</descriptor>
-					</descriptors>
-				</configuration>
-				<executions>
-					<execution>
-						<id>make-assembly</id> <!-- this is used for inheritance merges -->
-						<phase>package</phase> <!-- bind to the packaging phase -->
-						<goals>
-							<goal>single</goal>
-						</goals>
-					</execution>
-				</executions>
-			</plugin>
-		</plugins>
-	</build>
-
-</project>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/assembly/src.xml
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/assembly/src.xml b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/assembly/src.xml
deleted file mode 100644
index 80e2e06..0000000
--- a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/assembly/src.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<!--
-  ~ Copyright 2005-2011 WSO2, Inc. (http://wso2.com)
-  ~
-  ~ 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.
-  -->
-<assembly
-	xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
-	<id>Tool</id>
-	<formats>
-		<format>jar</format>
-	</formats>
-	<includeBaseDirectory>false</includeBaseDirectory>
-	<dependencySets>
-		<dependencySet>
-			<outputDirectory>/</outputDirectory>
-			<useProjectArtifact>true</useProjectArtifact>
-			<unpack>true</unpack>
-			<scope>runtime</scope>
-		</dependencySet>
-	</dependencySets>
-</assembly>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CliTool.java
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CliTool.java b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CliTool.java
deleted file mode 100644
index 1ff4f91..0000000
--- a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CliTool.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2013, WSO2, Inc. http://wso2.org
- * 
- * 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.wso2.carbon.adc.mgt.cli;
-
-import static org.wso2.carbon.adc.mgt.cli.utils.CliConstants.STRATOS_DIR;
-
-import java.io.File;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class is used for input the commands through CLITool, command prompt.
- */
-public class CliTool {
-
-	private static final Logger logger = LoggerFactory.getLogger(CliTool.class);
-
-	/**
-	 * Main executable method used to call from CLI.
-	 * 
-	 */
-	public static void main(final String[] args) {
-		CliTool cliTool = new CliTool();
-		cliTool.createConfigDirectory();
-		cliTool.handleConsoleInputs(args);
-	}
-
-	/**
-	 * Here is the place all the command line inputs get processed
-	 * 
-	 * @param arguments
-	 *            passed to CLI tool.
-	 */
-	private void handleConsoleInputs(String[] arguments) {
-		if (logger.isInfoEnabled()) {
-			logger.info("Stratos CLI Started...");
-		}
-		StratosApplication application = new StratosApplication();
-		application.start(arguments);
-	}
-
-	private void createConfigDirectory() {
-		File stratosFile = new File(System.getProperty("user.home"), STRATOS_DIR);
-		if (stratosFile.exists()) {
-			if (logger.isInfoEnabled()) {
-				logger.info("Using directory: {}", stratosFile.getPath());
-			}
-		} else {
-			if (stratosFile.mkdir()) {
-				if (logger.isInfoEnabled()) {
-					logger.info("Created directory: {}", stratosFile.getPath());
-				}
-			} else if (logger.isWarnEnabled()) {
-				logger.warn("Failed to created directory: {}", stratosFile.getPath());
-			}
-		}
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/Command.java
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/Command.java b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/Command.java
deleted file mode 100644
index 5e3a250..0000000
--- a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/Command.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2013, WSO2, Inc. http://wso2.org
- * 
- * 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.wso2.carbon.adc.mgt.cli;
-
-import org.apache.commons.cli.Options;
-import org.wso2.carbon.adc.mgt.cli.exception.CommandException;
-
-public interface Command<T extends CommandContext> {
-
-	/**
-	 * @return The name of the command
-	 */
-	String getName();
-
-	/**
-	 * Information about the command
-	 * 
-	 * @return The description of the command
-	 */
-	String getDescription();
-
-	/**
-	 * This should return the syntax required for the command.
-	 * 
-	 * Used to display help.
-	 * 
-	 * @return The syntax for this command
-	 */
-	String getArgumentSyntax();
-
-	/**
-	 * The options accepted by the command
-	 * 
-	 * @return The Options for the commands
-	 */
-	Options getOptions();
-
-	/**
-	 * Executing the commands. Returns a code
-	 * 
-	 * @param context
-	 *            The context assoicated with the Command Line Application
-	 * @param args
-	 *            The arguments for the command
-	 * @return The status code
-	 * @throws CommandException
-	 *             if any errors occur when executing the command
-	 */
-	int execute(T context, String[] args) throws CommandException;
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandContext.java
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandContext.java b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandContext.java
deleted file mode 100644
index 59364ff..0000000
--- a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandContext.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2013, WSO2, Inc. http://wso2.org
- * 
- * 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.wso2.carbon.adc.mgt.cli;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Observable;
-
-public class CommandContext extends Observable {
-
-	/**
-	 * Properties for the context.
-	 */
-	private Map<String, Object> properties;
-
-	/**
-	 * The application
-	 */
-	private final CommandLineApplication<? extends CommandContext> application;
-
-	public CommandContext(CommandLineApplication<? extends CommandContext> application) {
-		properties = new HashMap<String, Object>();
-		this.application = application;
-	}
-
-	public final CommandLineApplication<? extends CommandContext> getApplication() {
-		return application;
-	}
-
-	/**
-	 * Set property in the context
-	 * 
-	 * @param key
-	 *            The key
-	 * @param o
-	 *            The value for the key
-	 * @return The previous value or null
-	 */
-	public Object put(String key, Object o) {
-		Object previous = properties.put(key, o);
-		setChanged();
-		notifyObservers();
-		return previous;
-	}
-
-	/**
-	 * Get property value from the context
-	 * 
-	 * @param key
-	 *            The key
-	 * @return The value
-	 */
-	public Object getObject(String key) {
-		return properties.get(key);
-	}
-
-	/**
-	 * Get the string value, or null
-	 * 
-	 * @param key
-	 *            The key
-	 * @return The string value, or null.
-	 */
-	public String getString(String key) {
-		Object o = getObject(key);
-		if (o instanceof String) {
-			return (String) o;
-		}
-		return null;
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandLineApplication.java
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandLineApplication.java b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandLineApplication.java
deleted file mode 100644
index bafc14d..0000000
--- a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandLineApplication.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright 2013, WSO2, Inc. http://wso2.org
- * 
- * 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.wso2.carbon.adc.mgt.cli;
-
-import java.io.File;
-import java.io.IOException;
-
-import jline.console.ConsoleReader;
-import jline.console.history.FileHistory;
-
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.wso2.carbon.adc.mgt.cli.utils.CliConstants;
-
-public abstract class CommandLineApplication<T extends CommandContext> {
-
-	private static final Logger logger = LoggerFactory.getLogger(CommandLineApplication.class);
-
-	protected final ConsoleReader reader;
-	protected FileHistory history;
-
-	public CommandLineApplication() {
-		reader = createConsoleReader();
-	}
-
-	/**
-	 * Creates new jline ConsoleReader.
-	 * 
-	 * @return a jline ConsoleReader instance
-	 */
-	protected ConsoleReader createConsoleReader() {
-		ConsoleReader consoleReader = null;
-		try {
-			consoleReader = new ConsoleReader();
-			consoleReader.setPrompt(getPrompt());
-			history = new FileHistory(getHistoryFile());
-			consoleReader.setHistory(history);
-		} catch (IOException e) {
-			throw new IllegalStateException("Cannot create jline console reader", e);
-		}
-		return consoleReader;
-	}
-
-	public ConsoleReader getConsoleReader() {
-		return reader;
-	}
-
-	protected abstract String getPrompt();
-
-	/**
-	 * Get the history file for the Console Reader.
-	 * 
-	 * @return File for storing history
-	 */
-	protected abstract File getHistoryFile();
-
-	public final void start(String[] args) {
-		Thread shutdownHookThread = new Thread("CLI Shutdown Hook") {
-			@Override
-			public void run() {
-				performDestroy();
-			}
-		};
-		Runtime.getRuntime().addShutdownHook(shutdownHookThread);
-		int returnCode = run(args);
-		if (logger.isDebugEnabled()) {
-			logger.debug("Exiting with error code {}", returnCode);
-		}
-		System.exit(returnCode);
-	}
-
-	protected abstract int run(String[] args);
-
-	protected void promptLoop() {
-		String line = null;
-		boolean exit = false;
-
-		try {
-			while (!exit && (reader != null && ((line = reader.readLine()) != null))) {
-				if ("".equals(line)) {
-					continue;
-				}
-				if (StringUtils.isNotBlank(line)) {
-					execute(line);
-					exit = CliConstants.EXIT_ACTION.equals(line.trim());
-				}
-			}
-		} catch (IOException e) {
-			throw new IllegalStateException("Error in reading line", e);
-		}
-	}
-
-	private int execute(String line) {
-		try {
-			if (logger.isDebugEnabled()) {
-				logger.debug("Executing command line: \"{}\"", line);
-			}
-			int returnCode = executeCommand(line);
-			if (logger.isDebugEnabled()) {
-				logger.debug("Command line executed \"{}\". Return code: {}", line, returnCode);
-			}
-			return returnCode;
-		} catch (RuntimeException e) {
-			if (logger.isErrorEnabled()) {
-				logger.error("Error executing command line: " + line, e);
-			}
-			return 1;
-		}
-	}
-
-	protected abstract int executeCommand(String line);
-
-	private void performDestroy() {
-		if (logger.isDebugEnabled()) {
-			logger.debug("Shutting down application... Invoking destroy methods");
-		}
-		if (history != null) {
-			try {
-				history.flush();
-			} catch (IOException e) {
-				if (logger.isErrorEnabled()) {
-					logger.error("Error flushing history.", e);
-				}
-			}
-		}
-		destroy();
-	}
-
-	/**
-	 * May override to perform action before destroying
-	 */
-	protected void destroy() {
-	};
-
-	public String getInput(String prompt) {
-		return getInput(prompt, null);
-	}
-
-	public String getInput(String prompt, Character mask) {
-		String line = null;
-		try {
-			reader.setPrompt(prompt + ": ");
-			while ((line = reader.readLine(mask)) != null) {
-				if ("".equals(line)) {
-					continue;
-				}
-				return line;
-			}
-		} catch (IOException e) {
-			throw new IllegalStateException("Error in reading line", e);
-		} finally {
-			reader.setPrompt(CliConstants.STRATOS_SHELL_PROMPT);
-		}
-		return line;
-	}
-	
-	/**
-	 * @return {@code true if user confirmed}
-	 */
-	public boolean getConfirmation(String prompt) {
-		prompt = prompt + " [yes/no]";
-
-		String input = "";
-		int tries = 0;
-		do {
-			tries++;
-			input = getInput(prompt);
-		} while (!"y".equals(input) && !"yes".equals(input) && !"n".equals(input) && !"no".equals(input) && tries < 3);
-
-		return "y".equals(input) || "yes".equals(input);
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ca25b1f7/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandLineService.java
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandLineService.java b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandLineService.java
deleted file mode 100644
index a640600..0000000
--- a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandLineService.java
+++ /dev/null
@@ -1,553 +0,0 @@
-/*
- * Copyright 2013, WSO2, Inc. http://wso2.org
- * 
- * 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.wso2.carbon.adc.mgt.cli;
-
-import java.rmi.RemoteException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.client.Options;
-import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.description.TransportOutDescription;
-import org.apache.axis2.transport.http.HttpTransportProperties;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.wso2.carbon.adc.mgt.cli.exception.CommandException;
-import org.wso2.carbon.adc.mgt.cli.utils.CommandLineUtils;
-import org.wso2.carbon.adc.mgt.cli.utils.RowMapper;
-import org.wso2.carbon.adc.mgt.dto.xsd.Cartridge;
-import org.wso2.carbon.adc.mgt.dto.xsd.PolicyDefinition;
-import org.wso2.carbon.adc.mgt.dto.xsd.SubscriptionInfo;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServiceADCExceptionException;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServiceAlreadySubscribedExceptionException;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServiceDomainMappingExistsExceptionException;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServiceDuplicateCartridgeAliasExceptionException;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServiceInvalidCartridgeAliasExceptionException;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServiceInvalidRepositoryExceptionException;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServiceNotSubscribedExceptionException;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServicePolicyExceptionException;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServiceRepositoryCredentialsRequiredExceptionException;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServiceRepositoryRequiredExceptionException;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServiceRepositoryTransportExceptionException;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServiceStub;
-import org.wso2.carbon.adc.mgt.stub.ApplicationManagementServiceUnregisteredCartridgeExceptionException;
-
-import com.google.gson.Gson;
-
-public class CommandLineService {
-
-	private static final Logger logger = LoggerFactory.getLogger(CommandLineService.class);
-
-	private ApplicationManagementServiceStub stub;
-
-	private CommandLineService() {
-	}
-
-	private static class SingletonHolder {
-		private final static CommandLineService INSTANCE = new CommandLineService();
-	}
-
-	public static CommandLineService getInstance() {
-		return SingletonHolder.INSTANCE;
-	}
-	
-	private void initializeApplicationManagementStub(String serverURL, String username, String password) throws AxisFault {
-		HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
-        authenticator.setUsername(username);
-        authenticator.setPassword(password);
-        authenticator.setPreemptiveAuthentication(true);
-		
-        ApplicationManagementServiceStub stub;
-        ConfigurationContext configurationContext = null;
-        try {
-            configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
-        } catch (Exception e) {
-            String msg = "Backend error occurred. Please contact the service admins!";
-            throw new AxisFault(msg, e);
-        }
-        HashMap<String, TransportOutDescription> transportsOut = configurationContext
-                .getAxisConfiguration().getTransportsOut();
-        for (TransportOutDescription transportOutDescription : transportsOut.values()) {
-            transportOutDescription.getSender().init(configurationContext, transportOutDescription);
-        }
-        stub = new ApplicationManagementServiceStub(configurationContext, serverURL + "/services/ApplicationManagementService");
-        ServiceClient client = stub._getServiceClient();
-        Options option = client.getOptions();
-        option.setManageSession(true);
-        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator);
-        option.setTimeOutInMilliSeconds(300000);
-        this.stub = stub;
-    }
-
-	public boolean login(String serverURL, String username, String password, boolean validateLogin) throws CommandException {
-		try {
-			// Following code will avoid validating certificate
-			SSLContext sc;
-			// Get SSL context
-			sc = SSLContext.getInstance("SSL");
-			// Create empty HostnameVerifier
-			HostnameVerifier hv = new HostnameVerifier() {
-				public boolean verify(String urlHostName, SSLSession session) {
-					return true;
-				}
-			};
-			// Create a trust manager that does not validate certificate
-			// chains
-			TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
-				public java.security.cert.X509Certificate[] getAcceptedIssuers() {
-					return null;
-				}
-
-				public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
-				}
-
-				public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
-				}
-			} };
-			sc.init(null, trustAllCerts, new java.security.SecureRandom());
-			SSLContext.setDefault(sc);
-			HttpsURLConnection.setDefaultHostnameVerifier(hv);
-		} catch (Exception e) {
-			throw new RuntimeException("Error while authentication process!", e);
-		}
-
-		// Initialize Service Stub
-		try {
-			initializeApplicationManagementStub(serverURL, username, password);
-		} catch (AxisFault e) {
-			System.out.println("Error connecting to the back-end");
-			throw new CommandException(e);
-		}
-		
-		try {
-			if (validateLogin) {
-				String tenantDomain = stub.getTenantDomain();
-				if (logger.isDebugEnabled()) {
-					logger.debug("Tenant Domain {}", tenantDomain);
-				}
-				return (tenantDomain != null);
-			} else {
-				// Just return true as we don't need to validate
-				return true;
-			}
-		} catch (RemoteException e) {
-			System.out.println("Authentication failed!");
-			throw new CommandException(e);
-		}
-	}
-
-	public void listSubscribedCartridges(final boolean full) throws CommandException {
-		try {
-			Cartridge[] cartridges = stub.getSubscribedCartridges();
-
-			if (cartridges == null) {
-				if (logger.isDebugEnabled()) {
-					logger.debug("No subscribed cartridges found");
-				}
-				System.out.println("There are no subscribed cartridges");
-				return;
-			}
-
-			RowMapper<Cartridge> cartridgeMapper = new RowMapper<Cartridge>() {
-
-				@Override
-				public String[] getData(Cartridge cartridge) {
-					String[] data = full ? new String[9] : new String[7];
-					data[0] = cartridge.getCartridgeType();
-					data[1] = cartridge.getDisplayName();
-					data[2] = cartridge.getVersion();
-					data[3] = cartridge.getMultiTenant() ? "Multi-Tenant" : "Single-Tenant";
-					data[4] = cartridge.getCartridgeAlias();
-					data[5] = cartridge.getStatus();
-					data[6] = cartridge.getMultiTenant() ? "N/A" : String.valueOf(cartridge.getActiveInstances());
-					if (full) {
-						data[7] = getAccessURLs(cartridge);
-						data[8] = cartridge.getRepoURL() != null ? cartridge.getRepoURL() : "";
-					}
-					return data;
-				}
-			};
-			
-			List<String> headers = new ArrayList<String>();
-			headers.add("Type");
-			headers.add("Name");
-			headers.add("Version");
-			headers.add("Tenancy Model");
-			headers.add("Alias");
-			headers.add("Status");
-			headers.add("Running Instances");
-			if (full) {
-				headers.add("Access URL(s)");
-				headers.add("Repo URL");
-			}
-
-			System.out.println("Subscribed Cartridges:");
-			CommandLineUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
-
-			System.out.println();
-
-		} catch (ApplicationManagementServiceADCExceptionException e) {
-			handleException("cannot.list.subscribed.cartridges", e);
-		} catch (RemoteException e) {
-			handleException(e);
-		}
-	}
-
-	public void listAvailableCartridges() throws CommandException {
-		try {
-			Cartridge[] multiTenantCatridges = stub.getAvailableCartridges(true);
-
-			if (multiTenantCatridges == null) {
-				if (logger.isDebugEnabled()) {
-					logger.debug("No multi-tenant cartridges available");
-				}
-				System.out.println("There are no multi-tenant cartridges available");
-			}
-
-			RowMapper<Cartridge> cartridgeMapper = new RowMapper<Cartridge>() {
-
-				@Override
-				public String[] getData(Cartridge cartridge) {
-					String[] data = new String[3];
-					data[0] = cartridge.getCartridgeType();
-					data[1] = cartridge.getDisplayName();
-					data[2] = cartridge.getVersion();
-					return data;
-				}
-			};
-
-			System.out.println("Available Multi-Tenant Cartridges:");
-			CommandLineUtils.printTable(multiTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
-			System.out.println();
-			
-			Cartridge[] singleTenantCatridges = stub.getAvailableCartridges(false);
-
-			if (multiTenantCatridges == null) {
-				if (logger.isDebugEnabled()) {
-					logger.debug("No single-tenant cartridges available");
-				}
-				System.out.println("There are no single-tenant cartridges available");
-			}
-			
-			System.out.println("Available Single-Tenant Cartridges:");
-			CommandLineUtils.printTable(singleTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
-			System.out.println();
-		} catch (ApplicationManagementServiceADCExceptionException e) {
-			handleException("cannot.list.available.cartridges", e);
-		} catch (RemoteException e) {
-			handleException(e);
-		}
-	}
-	
-	public void listAvailablePolicies() throws CommandException {
-		try {
-			PolicyDefinition[] policies = stub.getPolicyDefinitions();
-
-			if (policies == null) {
-				if (logger.isDebugEnabled()) {
-					logger.debug("No policies available");
-				}
-				System.out.println("There are no policies available");
-			}
-
-			RowMapper<PolicyDefinition> policyMapper = new RowMapper<PolicyDefinition>() {
-
-				@Override
-				public String[] getData(PolicyDefinition policyDefinition) {
-					String[] data = new String[3];
-					data[0] = policyDefinition.getName();
-					data[1] = policyDefinition.getDescription();
-					data[2] = policyDefinition.getDefaultPolicy() ? "Yes" : "No";
-					return data;
-				}
-			};
-
-			CommandLineUtils.printTable(policies, policyMapper, "Policy Name", "Description", "Default");
-			System.out.println();
-		} catch (RemoteException e) {
-			handleException(e);
-		}
-	}
-
-	public void info(String alias) throws CommandException {
-		try {
-            Cartridge cartridge = null;
-            try {
-                cartridge = stub.getCartridgeInfo(alias);
-            } catch (ApplicationManagementServiceADCExceptionException e) {
-            	handleException(e);
-                return;
-            } catch (ApplicationManagementServiceNotSubscribedExceptionException e) {
-            	handleException("notsubscribed.error", e, alias);
-			}
-			if (logger.isDebugEnabled()) {
-				logger.debug("Cartridge Info: {}", new Gson().toJson(cartridge));
-			}
-			final String FORMAT = "%-20s: %s%n";
-			System.out.println();
-			System.out.println("Cartridge Information");
-			System.out.println("---------------------");
-			System.out.format(FORMAT, "Cartridge", cartridge.getCartridgeType());
-			System.out.format(FORMAT, "Name", cartridge.getDisplayName());
-			System.out.format(FORMAT, "Description", cartridge.getDescription());
-			System.out.format(FORMAT, "Version", cartridge.getVersion());
-			System.out.format(FORMAT, "Tenancy Model", cartridge.getMultiTenant() ? "Multi-Tenant" : "Single-Tenant");
-			System.out.format(FORMAT, "Alias", cartridge.getCartridgeAlias());
-			if (StringUtils.isNotBlank(cartridge.getPolicyDescription())) {
-				System.out.format(FORMAT, "Policy", cartridge.getPolicyDescription());
-			}
-			System.out.format(FORMAT, "Access URL(s)", getAccessURLs(cartridge));
-			if (StringUtils.isNotBlank(cartridge.getIp())) {
-				System.out.format(FORMAT, "Host", cartridge.getIp());
-			}
-			if (StringUtils.isNotBlank(cartridge.getDbUserName())) {
-				System.out.format(FORMAT, "Database Username", cartridge.getDbUserName());
-			}
-			if (StringUtils.isNotBlank(cartridge.getPassword())) {
-				System.out.format(FORMAT, "Password", cartridge.getPassword());
-			}
-			if (StringUtils.isNotBlank(cartridge.getRepoURL())) {
-				System.out.format(FORMAT, "Repository URL", cartridge.getRepoURL());
-			}
-			System.out.format(FORMAT, "Status", cartridge.getStatus());
-			System.out.format(FORMAT, "Running Instances",
-					cartridge.getMultiTenant() ? "N/A" : String.valueOf(cartridge.getActiveInstances()));
-			System.out.println();
-
-        } catch (RemoteException e) {
-        	handleException(e);
-        }
-	}
-
-	public void unsubscribe(String alias) throws CommandException {
-		try {
-			stub.unsubscribe(alias);
-			System.out.println("You have successfully unsubscribed " + alias);
-        } catch (ApplicationManagementServiceADCExceptionException e) {
-        	handleException("cannot.unsubscribe", e);
-        } catch (ApplicationManagementServiceNotSubscribedExceptionException e) {
-			handleException("notsubscribed.error", e, alias);
-        } catch (RemoteException e) {
-        	handleException(e);
-        }
-	}
-
-	public void sync(String alias) throws CommandException {
-		try {
-			System.out.format("Synchronizing repository for alias: %s%n", alias);
-			stub.synchronizeRepository(alias);
-		} catch (ApplicationManagementServiceADCExceptionException e) {
-			handleException("cannot.syncrepo", e);
-		} catch (RemoteException e) {
-			handleException(e);
-		} catch (ApplicationManagementServiceNotSubscribedExceptionException e) {
-			handleException("notsubscribed.error", e, alias);
-		}
-	}
-
-	public String addDomainMapping(String domain, String alias) throws CommandException {
-		try {
-			return stub.addDomainMapping(domain, alias);
-		} catch (ApplicationManagementServiceADCExceptionException e) {
-			handleException("cannot.mapdomain", e);
-		} catch (RemoteException e) {
-			handleException(e);
-		} catch (ApplicationManagementServiceNotSubscribedExceptionException e) {
-			handleException("notsubscribed.error", e, alias);
-		} catch (ApplicationManagementServiceDomainMappingExistsExceptionException e) {
-			handleException("domainmapping.exists.error", e, domain, alias);
-		}
-		return null;
-	}
-
-	public void removeDomainMapping(String alias) throws CommandException {
-		try {
-			stub.removeDomainMapping(alias);
-			System.out.format("Domain mapping removed for alias: %s.%n", alias);
-		} catch (ApplicationManagementServiceADCExceptionException e) {
-			handleException("cannot.removedomain", e);
-		} catch (RemoteException e) {
-			handleException(e);
-		} catch (ApplicationManagementServiceNotSubscribedExceptionException e) {
-			handleException("notsubscribed.error", e, alias);
-		}
-	}
-
-	public void subscribe(String cartridgeType, String alias, String policy, String externalRepoURL,
-			boolean privateRepo, String username, String password, String dataCartridgeType, String dataCartridgeAlias)
-			throws CommandException {
-		
-		SubscriptionInfo subcriptionConnectInfo = null;
-		if (StringUtils.isNotBlank(dataCartridgeType) && StringUtils.isNotBlank(dataCartridgeAlias)) {
-			System.out.format("Subscribing to data cartridge %s with alias %s.%n", dataCartridgeType,
-					dataCartridgeAlias);
-			try {
-				subcriptionConnectInfo = stub.subscribe(dataCartridgeType, dataCartridgeAlias, null, null, false, null,
-						null, null, null);
-				System.out.format("You have successfully subscribed to %s cartridge with alias %s.%n",
-						dataCartridgeType, dataCartridgeAlias);
-				System.out.format("%nSubscribing to %s cartridge and connecting with %s data cartridge.%n", alias,
-						dataCartridgeAlias);
-			} catch (RemoteException e) {
-				handleException(e);
-			} catch (ApplicationManagementServiceADCExceptionException e) {
-				handleException("cannot.subscribe", e);
-			} catch (ApplicationManagementServiceRepositoryRequiredExceptionException e) {
-				handleException("repository.required", e);
-			} catch (ApplicationManagementServiceUnregisteredCartridgeExceptionException e) {
-				handleException("cartridge.notregistered", e, dataCartridgeType);
-			} catch (ApplicationManagementServiceInvalidCartridgeAliasExceptionException e) {
-				handleException("cartridge.invalid.alias", e);
-			} catch (ApplicationManagementServiceAlreadySubscribedExceptionException e) {
-				handleException("cartridge.already.subscribed", e, e.getFaultMessage().getAlreadySubscribedException()
-						.getCartridgeType());
-			} catch (ApplicationManagementServiceDuplicateCartridgeAliasExceptionException e) {
-				handleException("cartridge.alias.duplicate", e, dataCartridgeAlias);
-			} catch (ApplicationManagementServicePolicyExceptionException e) {
-				handleException("policy.error", e);
-			} catch (ApplicationManagementServiceRepositoryTransportExceptionException e) {
-				handleException("repository.transport.error", e, externalRepoURL);
-			} catch (ApplicationManagementServiceRepositoryCredentialsRequiredExceptionException e) {
-				handleException("repository.credentials.required", e, externalRepoURL);
-			} catch (ApplicationManagementServiceInvalidRepositoryExceptionException e) {
-				handleException("repository.invalid.error", e, externalRepoURL);
-			}
-		}
-		
-		
-		try {
-			SubscriptionInfo subcriptionInfo = stub.subscribe(cartridgeType, alias, policy, externalRepoURL,
-					privateRepo, username, password, dataCartridgeType, dataCartridgeAlias);
-
-			System.out
-					.format("You have successfully subscribed to %s cartridge with alias %s.%n", cartridgeType, alias);
-
-			String repoURL = null;
-			String hostnames = null;
-			String hostnamesLabel = null;
-			if (subcriptionInfo != null) {
-				repoURL = subcriptionInfo.getRepositoryURL();
-				hostnames = subcriptionInfo.getHostname();
-				hostnamesLabel = "host name";
-
-				if (repoURL != null) {
-					System.out.println("GIT Repository URL: " + repoURL);
-				}
-
-				Cartridge cart = stub.getCartridgeInfo(alias);
-				System.out.format("Your application is being published here. %s%n", getAccessURLs(cart));
-			}
-			if (subcriptionConnectInfo != null) {
-				hostnames += ", " + subcriptionConnectInfo.getHostname();
-				hostnamesLabel = "host names";
-
-				Cartridge cart = stub.getCartridgeInfo(alias);
-				System.out.format("Your data application is being published here. %s%n", getAccessURLs(cart));
-			}
-			if (externalRepoURL != null) {
-				String takeTimeMsg = "(this might take few minutes... depending on repo size)\n";
-				System.out.println(takeTimeMsg);
-			}
-
-			System.out.format("Please map the %s \"%s\" to ELB IP%n", hostnamesLabel, hostnames);
-		} catch (RemoteException e) {
-			handleException(e);
-		} catch (ApplicationManagementServiceADCExceptionException e) {
-			handleException("cannot.subscribe", e);
-		} catch (ApplicationManagementServiceRepositoryRequiredExceptionException e) {
-			handleException("repository.required", e);
-		} catch (ApplicationManagementServiceUnregisteredCartridgeExceptionException e) {
-			handleException("cartridge.notregistered", e, cartridgeType);
-		} catch (ApplicationManagementServiceInvalidCartridgeAliasExceptionException e) {
-			handleException("cartridge.invalid.alias", e);
-		} catch (ApplicationManagementServiceAlreadySubscribedExceptionException e) {
-			handleException("cartridge.already.subscribed", e, e.getFaultMessage().getAlreadySubscribedException()
-					.getCartridgeType());
-		} catch (ApplicationManagementServiceDuplicateCartridgeAliasExceptionException e) {
-			handleException("cartridge.alias.duplicate", e, alias);
-		} catch (ApplicationManagementServicePolicyExceptionException e) {
-			handleException("policy.error", e);
-		} catch (ApplicationManagementServiceRepositoryTransportExceptionException e) {
-			handleException("repository.transport.error", e, externalRepoURL);
-		} catch (ApplicationManagementServiceRepositoryCredentialsRequiredExceptionException e) {
-			handleException("repository.credentials.required", e, externalRepoURL);
-		} catch (ApplicationManagementServiceInvalidRepositoryExceptionException e) {
-			handleException("repository.invalid.error", e, externalRepoURL);
-		} catch (ApplicationManagementServiceNotSubscribedExceptionException e) {
-			handleException("notsubscribed.error", e, alias);
-		}
-	}
-
-	private String getAccessURLs(Cartridge cartridge) {
-		String[] accessURLs = cartridge.getAccessURLs();
-		StringBuilder urlBuilder = new StringBuilder();
-		if (accessURLs != null) {
-			for (int i = 0; i < accessURLs.length; i++) {
-				String url = accessURLs[i];
-				if (url != null) {
-					if (i > 0) {
-						urlBuilder.append(", ");
-					}
-					urlBuilder.append(url);
-				}
-			}
-		}
-		return urlBuilder.toString();
-	}
-
-	private void handleException(Exception e) throws CommandException {
-		if (logger.isDebugEnabled()) {
-			logger.debug("Displaying message from Exception {}\n{}", e.getClass(), e.getMessage());
-		}
-		// TODO: Fix handling error message.
-		// Sometimes the Axis2 stub throws only the RemoteException (an
-		// AxisFault)
-		// So, other exceptions won't come here.
-		String message = e.getMessage();
-		if (message == null || (message != null && message.contains("Exception"))) {
-			message = "Error executing command!";
-		}
-		if (logger.isErrorEnabled()) {
-			logger.error(message);
-		}
-		System.out.println(message);
-		throw new CommandException(message, e);
-	}
-    
-    private void handleException(String key, Exception e, Object... args) throws CommandException {
-    	if (logger.isDebugEnabled()) {
-    		logger.debug("Displaying message for {}. Exception thrown is {}", key, e.getClass());
-    	}
-    	String message = CommandLineUtils.getMessage(key, args);
-        if (logger.isErrorEnabled()) {
-        	logger.error(message);
-        }
-        System.out.println(message);
-        throw new CommandException(message, e);
-    }
-}