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

[03/21] git commit: RESTful subscribe cartridge implementation in CLI

RESTful subscribe cartridge implementation in CLI


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/309fa06e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/309fa06e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/309fa06e

Branch: refs/heads/master
Commit: 309fa06e7dedc347e202f6fbcc64ea3dc41db4c6
Parents: 32c67e3
Author: Manula Thantriwatte <ma...@apache.org>
Authored: Thu Dec 5 18:06:00 2013 +0530
Committer: Manula Thantriwatte <ma...@apache.org>
Committed: Thu Dec 5 18:06:00 2013 +0530

----------------------------------------------------------------------
 .../apache/stratos/cli/CartridgeInfoBean.java   | 106 +++++++
 .../apache/stratos/cli/CommandLineService.java  |  11 +-
 .../java/org/apache/stratos/cli/RestClient.java |  40 ++-
 .../stratos/cli/RestCommandLineService.java     | 279 ++++++++++++++++++-
 .../apache/stratos/cli/StratosApplication.java  |   3 +-
 .../apache/stratos/cli/SubscriptionInfo.java    |  48 ++++
 .../stratos/cli/commands/CartridgesCommand.java |   4 +-
 .../stratos/cli/commands/ListCommand.java       |   7 +-
 .../stratos/cli/commands/SubscribeCommand.java  |   7 +-
 .../rest/endpoint/services/StratosAdmin.java    |   5 -
 10 files changed, 485 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/309fa06e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CartridgeInfoBean.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CartridgeInfoBean.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CartridgeInfoBean.java
new file mode 100644
index 0000000..827912f
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CartridgeInfoBean.java
@@ -0,0 +1,106 @@
+/*
+*  Copyright (c) 2005-2012, 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.cli;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class CartridgeInfoBean {
+    String cartridgeType;
+    String alias;
+    String policy;
+    String repoURL;
+    boolean privateRepo;
+    String repoUsername;
+    String repoPassword;
+    String dataCartridgeType;
+    String dataCartridgeAlias;
+
+
+    public String getCartridgeType() {
+        return cartridgeType;
+    }
+
+    public void setCartridgeType(String cartridgeType) {
+        this.cartridgeType = cartridgeType;
+    }
+
+    public String getAlias() {
+        return alias;
+    }
+
+    public void setAlias(String alias) {
+        this.alias = alias;
+    }
+
+    public String getPolicy() {
+        return policy;
+    }
+
+    public void setPolicy(String policy) {
+        this.policy = policy;
+    }
+
+    public String getRepoURL() {
+        return repoURL;
+    }
+
+    public void setRepoURL(String repoURL) {
+        this.repoURL = repoURL;
+    }
+
+    public boolean isPrivateRepo() {
+        return privateRepo;
+    }
+
+    public void setPrivateRepo(boolean privateRepo) {
+        this.privateRepo = privateRepo;
+    }
+
+    public String getRepoUsername() {
+        return repoUsername;
+    }
+
+    public void setRepoUsername(String repoUsername) {
+        this.repoUsername = repoUsername;
+    }
+
+    public String getRepoPassword() {
+        return repoPassword;
+    }
+
+    public void setRepoPassword(String repoPassword) {
+        this.repoPassword = repoPassword;
+    }
+
+    public String getDataCartridgeType() {
+        return dataCartridgeType;
+    }
+
+    public void setDataCartridgeType(String dataCartridgeType) {
+        this.dataCartridgeType = dataCartridgeType;
+    }
+
+    public String getDataCartridgeAlias() {
+        return dataCartridgeAlias;
+    }
+
+    public void setDataCartridgeAlias(String dataCartridgeAlias) {
+        this.dataCartridgeAlias = dataCartridgeAlias;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/309fa06e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java
index d7dcc5a..21eeb2c 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java
@@ -166,13 +166,16 @@ public class CommandLineService {
 
 	public void listSubscribedCartridges(final boolean full) throws CommandException {
 		try {
+            RestCommandLineService restService = new RestCommandLineService();
+            restService.listSubscribedCartridges(false);
+
 			Cartridge[] cartridges = stub.getSubscribedCartridges();
 
 			if (cartridges == null) {
 				if (logger.isDebugEnabled()) {
 					logger.debug("No subscribed cartridges found");
 				}
-				System.out.println("There are no subscribed cartridges");
+				//System.out.println("There are no subscribed cartridges");
 				return;
 			}
 
@@ -209,10 +212,10 @@ public class CommandLineService {
 				headers.add("Repo URL");
 			}
 
-			System.out.println("Subscribed Cartridges:");
-			CommandLineUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
+			//System.out.println("Subscribed Cartridges:");
+			//CommandLineUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
 
-			System.out.println();
+			//System.out.println();
 
 		} catch (ApplicationManagementServiceADCExceptionException e) {
 			handleException("cannot.list.subscribed.cartridges", e);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/309fa06e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
index 18e4820..1fa273b 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
@@ -31,6 +31,16 @@ import org.apache.http.entity.StringEntity;
 
 public class RestClient implements GenericRestClient{
 
+    private String url;
+    private String username;
+    private String password;
+
+    RestClient(String url, String username, String password) {
+        this.setUrl(url);
+        this.setUsername(username);
+        this.setPassword(password);
+    }
+
     public String doPost(String resourcePath, String jsonParamString, String userName, String passWord) {
         try {
 
@@ -56,13 +66,15 @@ public class RestClient implements GenericRestClient{
             BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
 
             String output;
+            String result = "";
             System.out.println("Output from Server .... \n");
             while ((output = br.readLine()) != null) {
-                System.out.println(output);
+                //System.out.println(output);
+                result += output;
             }
 
             httpClient.getConnectionManager().shutdown();
-            return output;
+            return result;
 
         } catch (MalformedURLException e) {
             e.printStackTrace();
@@ -118,4 +130,28 @@ public class RestClient implements GenericRestClient{
     public void doPut() {
         //To change body of implemented methods use File | Settings | File Templates.
     }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/309fa06e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
index c55be5a..a1b6c39 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
@@ -20,19 +20,31 @@ package org.apache.stratos.cli;
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
+import org.apache.axis2.AxisFault;
+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.apache.stratos.cli.exception.CommandException;
-import org.apache.stratos.cli.utils.CliConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
+import java.rmi.RemoteException;
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
 import org.apache.stratos.cli.utils.RowMapper;
 import org.apache.stratos.cli.utils.CommandLineUtils;
 
+import javax.net.ssl.*;
+
 public class RestCommandLineService {
 
 	private static final Logger logger = LoggerFactory.getLogger(RestCommandLineService.class);
 
-    RestClient restClientService = new RestClient();
+    private RestClient restClientService;
 
 	RestCommandLineService() {
 	}
@@ -45,15 +57,101 @@ public class RestCommandLineService {
 		return SingletonHolder.INSTANCE;
 	}
 
-    public void listAvailableCartridges() throws CommandException {
+    public boolean login(String serverURL, String username, String password, boolean validateLogin) throws CommandException {
+        try {
+            System.out.println("Login called");
+            // 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 {
+            initializeRestClient(serverURL, username, password);
+        } catch (AxisFault e) {
+            System.out.println("Error connecting to the back-end");
+            throw new CommandException(e);
+        }
+
+        System.out.println("End initialization, Login successfull");
+        return true;
+        /*
         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);
+        }
+        */
+    }
 
-            String stratosURL = System.getenv(CliConstants.STRATOS_URL_ENV_PROPERTY);
-            String username = System.getenv(CliConstants.STRATOS_USERNAME_ENV_PROPERTY);
-            String password = System.getenv(CliConstants.STRATOS_PASSWORD_ENV_PROPERTY);
+    private void initializeRestClient(String serverURL, String username, String password) throws AxisFault {
+        HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
+        authenticator.setUsername(username);
+        authenticator.setPassword(password);
+        authenticator.setPreemptiveAuthentication(true);
 
-            System.out.println(stratosURL + " : " + username + " : " + password);
-            String resultString = restClientService.doGet("http://ec2-54-254-71-178.ap-southeast-1.compute.amazonaws.com:9765/stratos/admin/cartridge/list", "admin@manula.org", "admin123");
+        RestClient restClient;
+        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);
+        }
+
+        restClient = new RestClient(serverURL, username, password);
+        //restClient = 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.restClientService = restClient;
+    }
+
+    public void listAvailableCartridges() throws CommandException {
+        try {
+            String resultString = restClientService.doGet("http://ec2-54-254-71-178.ap-southeast-1.compute.amazonaws.com:9765/stratos/admin/cartridge/list", restClientService.getUsername(), restClientService.getPassword());
             GsonBuilder gsonBuilder = new GsonBuilder();
             Gson gson = gsonBuilder.create();
             CartridgeList cartridgeList = gson.fromJson(resultString, CartridgeList.class);
@@ -127,6 +225,154 @@ public class RestCommandLineService {
         }
     }
 
+    public void listSubscribedCartridges(final boolean full) throws CommandException {
+        try {
+
+            String resultString = restClientService.doGet("http://ec2-54-254-71-178.ap-southeast-1.compute.amazonaws.com:9765/stratos/admin/cartridge/list/subscribed", restClientService.getUsername(), restClientService.getPassword());
+
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            Gson gson = gsonBuilder.create();
+            CartridgeList cartridgeList = gson.fromJson(resultString, CartridgeList.class);
+
+            if (cartridgeList == null) {
+                System.out.println("Object is null");
+            }
+
+            Cartridge[] cartridges = new Cartridge[cartridgeList.getCartridge().size()];
+            cartridges = cartridgeList.getCartridge().toArray(cartridges);
+
+            if (cartridges.length == 0) {
+                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.isMultiTenant() ? "Multi-Tenant" : "Single-Tenant";
+                    data[4] = cartridge.getCartridgeAlias();
+                    data[5] = cartridge.getStatus();
+                    data[6] = cartridge.isMultiTenant() ? "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: 1");
+            CommandLineUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
+
+            System.out.println();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void subscribe(String cartridgeType, String alias, String policy, String externalRepoURL,
+                          boolean privateRepo, String username, String password, String dataCartridgeType, String dataCartridgeAlias)
+            throws CommandException {
+
+        CartridgeInfoBean cartridgeInfoBean = new CartridgeInfoBean();
+        cartridgeInfoBean.setCartridgeType(cartridgeType);
+        cartridgeInfoBean.setAlias(alias);
+        cartridgeInfoBean.setPolicy(policy);
+        cartridgeInfoBean.setRepoURL(externalRepoURL);
+        cartridgeInfoBean.setPrivateRepo(privateRepo);
+        cartridgeInfoBean.setRepoUsername(username);
+        cartridgeInfoBean.setRepoPassword(password);
+        cartridgeInfoBean.setDataCartridgeType(dataCartridgeType);
+        cartridgeInfoBean.setDataCartridgeAlias(dataCartridgeAlias);
+
+        GsonBuilder gsonBuilder = new GsonBuilder();
+        Gson gson = gsonBuilder.create();
+        String jsonSubscribeString = gson.toJson(cartridgeInfoBean, CartridgeInfoBean.class);
+        System.out.println("\n" + jsonSubscribeString + "\n");
+        String completeJsonSubscribeString = "{\"cartridgeInfoBean\":" + jsonSubscribeString + "}";
+        System.out.println("\n" + jsonSubscribeString + "\n");
+
+        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 {
+                System.out.println("First try");
+                String subscription = restClientService.doPost("http://ec2-54-254-71-178.ap-southeast-1.compute.amazonaws.com:9765/stratos/admin/cartridge/subscribe", completeJsonSubscribeString, restClientService.getUsername(), restClientService.getPassword());
+                System.out.println(subscription);
+                subcriptionConnectInfo = gson.fromJson(subscription, SubscriptionInfo.class);
+                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 (Exception e) {
+                e.printStackTrace();
+            }
+        }
+
+        try {
+            System.out.println("Second try");
+            String subscriptionOutput = restClientService.doPost("http://ec2-54-254-71-178.ap-southeast-1.compute.amazonaws.com:9765/stratos/admin/cartridge/subscribe", completeJsonSubscribeString, restClientService.getUsername(), restClientService.getPassword());
+            SubscriptionInfo subcriptionInfo = gson.fromJson(subscriptionOutput, SubscriptionInfo.class);
+            System.out.println(subscriptionOutput);
+
+            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 (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     private class CartridgeList  {
         private ArrayList<Cartridge> cartridge;
 
@@ -142,4 +388,21 @@ public class RestCommandLineService {
             cartridge = new ArrayList<Cartridge>();
         }
     }
+
+    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();
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/309fa06e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java
index 97e1844..abf7bb2 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java
@@ -321,7 +321,8 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
 		stratosURL = context.getString(CliConstants.STRATOS_URL_ENV_PROPERTY);
 
 		try {
-			success = CommandLineService.getInstance().login(stratosURL, usernameInput, passwordInput, validateLogin);
+            success = RestCommandLineService.getInstance().login(stratosURL, usernameInput, passwordInput, validateLogin);
+			//success = CommandLineService.getInstance().login(stratosURL, usernameInput, passwordInput, validateLogin);
 		} catch (Exception e) {
 			if (logger.isErrorEnabled()) {
 				logger.error("Error when trying to login", e);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/309fa06e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/SubscriptionInfo.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/SubscriptionInfo.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/SubscriptionInfo.java
new file mode 100644
index 0000000..4e9dd02
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/SubscriptionInfo.java
@@ -0,0 +1,48 @@
+/*
+ * 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.cli;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+
+@XmlRootElement
+public class SubscriptionInfo implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	private String hostname;
+	private String repositoryURL;
+
+	public String getHostname() {
+		return hostname;
+	}
+
+	public void setHostname(String hostname) {
+		this.hostname = hostname;
+	}
+
+	public String getRepositoryURL() {
+		return repositoryURL;
+	}
+
+	public void setRepositoryURL(String repositoryURL) {
+		this.repositoryURL = repositoryURL;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/309fa06e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgesCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgesCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgesCommand.java
index ec4c2d6..e94b43b 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgesCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgesCommand.java
@@ -19,6 +19,7 @@
 package org.apache.stratos.cli.commands;
 
 import org.apache.commons.cli.Options;
+import org.apache.stratos.cli.RestCommandLineService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.stratos.cli.Command;
@@ -55,7 +56,8 @@ public class CartridgesCommand implements Command<StratosCommandContext> {
 			logger.debug("Executing {} command...", getName());
 		}
 		if (args == null || args.length == 0) {
-			CommandLineService.getInstance().listAvailableCartridges();
+			//CommandLineService.getInstance().listAvailableCartridges();
+            RestCommandLineService.getInstance().listAvailableCartridges();
 			return CliConstants.SUCCESSFUL_CODE;
 		} else {
 			context.getStratosApplication().printUsage(getName());

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/309fa06e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCommand.java
index d5eb79e..4a52df0 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCommand.java
@@ -24,6 +24,7 @@ import org.apache.commons.cli.GnuParser;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
+import org.apache.stratos.cli.RestCommandLineService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.stratos.cli.Command;
@@ -76,7 +77,8 @@ public class ListCommand implements Command<StratosCommandContext> {
 			logger.debug("Executing {} command...", getName());
 		}
 		if (args == null || args.length == 0) {
-			CommandLineService.getInstance().listSubscribedCartridges(false);
+            RestCommandLineService.getInstance().listSubscribedCartridges(false);
+			//CommandLineService.getInstance().listSubscribedCartridges(false);
 			return CliConstants.SUCCESSFUL_CODE;
 		} else if (args != null && args.length > 0) {
 			String[] remainingArgs = null;
@@ -100,7 +102,8 @@ public class ListCommand implements Command<StratosCommandContext> {
 				if (logger.isDebugEnabled()) {
 					logger.debug("Listing subscribed cartridges, Full Option: {}", full);
 				}
-				CommandLineService.getInstance().listSubscribedCartridges(full);
+                RestCommandLineService.getInstance().listSubscribedCartridges(full);
+				//CommandLineService.getInstance().listSubscribedCartridges(full);
 				return CliConstants.SUCCESSFUL_CODE;
 			} catch (ParseException e) {
 				if (logger.isErrorEnabled()) {

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/309fa06e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java
index 40a75ea..e867501 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java
@@ -25,6 +25,7 @@ import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.stratos.cli.RestCommandLineService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.stratos.cli.Command;
@@ -184,8 +185,10 @@ public class SubscribeCommand implements Command<StratosCommandContext> {
 					context.getStratosApplication().printUsage(getName());
 					return CliConstants.BAD_ARGS_CODE;
 				}
-				CommandLineService.getInstance().subscribe(type, alias, policy, repoURL, privateRepo, username,
-						password, dataCartridgeType, dataCartridgeAlias);
+                RestCommandLineService.getInstance().subscribe(type, alias, policy, repoURL, privateRepo, username,
+                		password, dataCartridgeType, dataCartridgeAlias);
+				//CommandLineService.getInstance().subscribe(type, alias, policy, repoURL, privateRepo, username,
+				//		password, dataCartridgeType, dataCartridgeAlias);
 				return CliConstants.SUCCESSFUL_CODE;
 			} catch (ParseException e) {
 				if (logger.isErrorEnabled()) {

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/309fa06e/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
index a40cbc6..143fadf 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
@@ -457,9 +457,6 @@ public class StratosAdmin extends AbstractAdmin {
         }
     }
 
-
-
-
     private List<TenantInfoBean> getAllTenants() throws Exception {
         TenantManager tenantManager = ServiceHolder.getTenantManager();
         Tenant[] tenants;
@@ -497,6 +494,4 @@ public class StratosAdmin extends AbstractAdmin {
         }
         return tenantList;
     }
-
-
 }