stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject [2/3] git commit: Refactoring CLI commands and adding -p option to subscribe command which was overwritten in previous commit
Date Sat, 11 Oct 2014 19:02:02 GMT
Refactoring CLI commands and adding -p option to subscribe command which was overwritten in previous commit


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

Branch: refs/heads/master
Commit: 10bee14e94b33f0714cd8313f48f78f6379e9bcb
Parents: 5d24241
Author: Imesh Gunaratne <imesh@apache.org>
Authored: Sun Oct 12 00:31:36 2014 +0530
Committer: Imesh Gunaratne <imesh@apache.org>
Committed: Sun Oct 12 00:31:36 2014 +0530

----------------------------------------------------------------------
 .../java/org/apache/stratos/cli/RestClient.java |  20 +-
 .../stratos/cli/RestCommandLineService.java     | 665 +++++++------------
 .../apache/stratos/cli/StratosApplication.java  |   4 +-
 .../DescribeCartridgeSubscriptionCommand.java   |  95 +++
 .../commands/ListAutoscalePolicyCommand.java    |   1 -
 .../ListCartridgeSubscriptionsCommand.java      |  84 ++-
 .../cli/commands/ListCartridgesCommand.java     |   3 +-
 .../commands/ListDeploymentPolicyCommand.java   |   1 -
 .../ListSubscribedCartridgesCommand.java        | 120 ----
 .../cli/commands/SubscribeCartridgeCommand.java |  42 +-
 10 files changed, 429 insertions(+), 606 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/10bee14e/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 93c0e74..3228f0f 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
@@ -210,9 +210,20 @@ public class RestClient implements GenericRestClient {
         }
     }
 
+    public Object getEntity(String serviceEndpoint, Class responseJsonClass, String identifier, String entityName) {
+        try {
+            return executeGet(serviceEndpoint.replace("{id}", identifier), responseJsonClass);
+        } catch (Exception e) {
+            String message = String.format("Error in getting %s", entityName);
+            System.out.println(message);
+            logger.error(message, e);
+            return null;
+        }
+    }
+
     public Object listEntity(String serviceEndpoint, Class responseJsonClass, String entityName) {
         try {
-            return executeList(serviceEndpoint, responseJsonClass, entityName);
+            return executeGet(serviceEndpoint, responseJsonClass);
         } catch (Exception e) {
             String message = String.format("Error in listing %s", entityName);
             System.out.println(message);
@@ -262,7 +273,7 @@ public class RestClient implements GenericRestClient {
         }
     }
 
-    private Object executeList(String serviceEndpoint, Class responseJsonClass, String entityName) throws Exception {
+    private Object executeGet(String serviceEndpoint, Class responseJsonClass) throws Exception {
         DefaultHttpClient httpClient = new DefaultHttpClient();
         HttpResponse response = null;
 
@@ -270,7 +281,10 @@ public class RestClient implements GenericRestClient {
             response = doGet(httpClient, getBaseURL() + serviceEndpoint);
             int responseCode = response.getStatusLine().getStatusCode();
 
-            if (responseCode < 200 || responseCode >= 300) {
+            if((responseCode >= 400) && (responseCode < 500)) {
+                // Entity not found
+                return null;
+            } else if (responseCode < 200 || responseCode >= 300) {
                 printError(response);
                 return null;
             } else {

http://git-wip-us.apache.org/repos/asf/stratos/blob/10bee14e/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 21856fa..72c7855 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
@@ -104,7 +104,7 @@ public class RestCommandLineService {
     private final String LIST_KUBERNETES_HOSTS_ENDPOINT = "/stratos/admin/kubernetes/hosts/{groupId}";
 
     private final String GET_CARTRIDGE_ENDPOINT = "/stratos/admin/cartridge/available/info";
-    private final String GET_CARTRIDGE_OF_TENANT_ENDPOINT = "/stratos/admin/cartridge/info/";
+    private final String GET_CARTRIDGE_OF_TENANT_ENDPOINT = "/stratos/admin/cartridge/info/{id}";
     private final String GET_CLUSTER_OF_TENANT_ENDPOINT = "/stratos/admin/cluster/";
     private final String GET_KUBERNETES_GROUP_ENDPOINT = "/stratos/admin/kubernetes/group/{id}";
     private final String GET_KUBERNETES_MASTER_ENDPOINT = "/stratos/admin/kubernetes/master/{id}";
@@ -147,7 +147,7 @@ public class RestCommandLineService {
             };
             // Create a trust manager that does not validate certificate
             // chains
-            TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
+            TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
                 public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                     return null;
                 }
@@ -157,7 +157,7 @@ public class RestCommandLineService {
 
                 public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
                 }
-            } };
+            }};
             sc.init(null, trustAllCerts, new java.security.SecureRandom());
             SSLContext.setDefault(sc);
             HttpsURLConnection.setDefaultHostnameVerifier(hv);
@@ -184,10 +184,9 @@ public class RestCommandLineService {
 
                 if (response != null) {
                     String responseCode = "" + response.getStatusLine().getStatusCode();
-                    if ( (responseCode.equals(CliConstants.RESPONSE_OK)) && (response.toString().contains("WWW-Authenticate: Basic"))) {
+                    if ((responseCode.equals(CliConstants.RESPONSE_OK)) && (response.toString().contains("WWW-Authenticate: Basic"))) {
                         return true;
-                    }
-                    else {
+                    } else {
                         System.out.println("Invalid STRATOS_URL");
                     }
                 }
@@ -230,137 +229,59 @@ public class RestCommandLineService {
         this.restClient = new RestClient(serverURL, username, password);
     }
 
-    public Cartridge listCartridge(String cartridgeType) throws CommandException{
-        DefaultHttpClient httpClient = new DefaultHttpClient();
-        HttpResponse response;
-
+    public Cartridge getCartridge(String cartridgeType) throws CommandException {
         try {
-            String endpoint = restClient.getBaseURL() + GET_CARTRIDGE_ENDPOINT + "/" + cartridgeType;
-            response = restClient.doGet(httpClient, endpoint);
-
-            String responseCode = "" + response.getStatusLine().getStatusCode();
-            String resultString = CliUtils.getHttpResponseString(response);
-            if (resultString == null) {
-                return null;
-            }
-
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
+            CartridgeList list = (CartridgeList) restClient.listEntity(LIST_CARTRIDGES_ENDPOINT,
+                    CartridgeList.class, "cartridges");
 
-            if (!responseCode.equals(CliConstants.RESPONSE_OK)) {
-                ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
-                System.out.println(exception);
-                return null;
+            for (int i = 0; i < list.getCartridge().size(); i++) {
+                Cartridge cartridge = list.getCartridge().get(i);
+                if (cartridgeType.equals(cartridge.getCartridgeType())) {
+                    return cartridge;
+                }
             }
-
-            String cartridgeString = resultString.substring(13, resultString.length() -1);
-            Cartridge cartridge = gson.fromJson(cartridgeString, Cartridge.class);
-            return cartridge;
-
         } catch (Exception e) {
-            handleException("Exception in listing cartridge info", e);
-            return null;
-        } finally {
-            httpClient.getConnectionManager().shutdown();
+            String message = "Error in getting cartridge";
+            System.out.println(message);
+            logger.error(message, e);
         }
+        return null;
     }
 
-    public ArrayList<Cartridge> listCartridges(String serviceGroup) throws CommandException{
-        DefaultHttpClient httpClient = new DefaultHttpClient();
-        HttpResponse response = null;
-
+    public ArrayList<Cartridge> listCartridgesByServiceGroup(String serviceGroup) throws CommandException {
         try {
-            response = restClient.doGet(httpClient, restClient.getBaseURL() + LIST_CARTRIDGES_ENDPOINT);
-
-            String responseCode = "" + response.getStatusLine().getStatusCode();
-            String resultString = CliUtils.getHttpResponseString(response);
-
-            if (resultString == null) {
-                return null;
-            }
-
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-
-            if (!responseCode.equals(CliConstants.RESPONSE_OK)) {
-                ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
-                System.out.println(exception);
-                return null;
-            }
-
-            CartridgeList cartridgeList = gson.fromJson(resultString, CartridgeList.class);
-
-            ArrayList<Cartridge> cartridgesInServiceGroup = new ArrayList<Cartridge>();
+            CartridgeList list = (CartridgeList) restClient.listEntity(LIST_CARTRIDGES_ENDPOINT,
+                    CartridgeList.class, "cartridges");
 
-            for (int i = 0; i < cartridgeList.getCartridge().size(); i++) {
-                if (serviceGroup.equals(cartridgeList.getCartridge().get(i).getServiceGroup())) {
-                    cartridgesInServiceGroup.add(cartridgeList.getCartridge().get(i));
+            ArrayList<Cartridge> arrayList = new ArrayList<Cartridge>();
+            for (int i = 0; i < list.getCartridge().size(); i++) {
+                if (serviceGroup.equals(list.getCartridge().get(i).getServiceGroup())) {
+                    arrayList.add(list.getCartridge().get(i));
                 }
             }
 
-            return cartridgesInServiceGroup;
+            return arrayList;
 
         } catch (Exception e) {
-            handleException("Exception in listing cartridge info", e);
+            String message = "Error in listing cartridges";
+            System.out.println(message);
+            logger.error(message, e);
             return null;
-        } finally {
-            httpClient.getConnectionManager().shutdown();
         }
     }
 
     // List currently available multi tenant and single tenant cartridges
-    public void listAvailableCartridges() throws CommandException {
-        DefaultHttpClient httpClient = new DefaultHttpClient();
+    public void listCartridges() throws CommandException {
         try {
-            HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + LIST_CARTRIDGES_ENDPOINT);
-
-            String responseCode = "" + response.getStatusLine().getStatusCode();
-            String resultString = CliUtils.getHttpResponseString(response);
-            if (resultString == null) {
-                return;
-            }
-
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-
-            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
-                ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
-                System.out.println(exception);
-                return;
-            }
-
-            CartridgeList cartridgeList = gson.fromJson(resultString, CartridgeList.class);
+            CartridgeList cartridgeList = (CartridgeList) restClient.listEntity(LIST_CARTRIDGES_ENDPOINT,
+                    CartridgeList.class, "cartridges");
 
-            if (cartridgeList == null) {
-                System.out.println("Available cartridge list is null");
+            if ((cartridgeList == null) || (cartridgeList.getCartridge() == null) ||
+                    (cartridgeList.getCartridge().size() == 0)) {
+                System.out.println("No cartridges found");
                 return;
             }
 
-            CartridgeList multiTelentCartridgeList = new CartridgeList();
-            CartridgeList singleTeneCartridgetList = new CartridgeList();
-
-            ArrayList<Cartridge> multiTenetCartridge = new ArrayList<Cartridge>();
-            ArrayList<Cartridge> singleTentCartridge = new ArrayList<Cartridge>();
-
-            HashSet<String> existingServiceGroups = new HashSet<String>();
-
-            for (Cartridge cartridge : cartridgeList.getCartridge()) {
-                if(existingServiceGroups.contains(cartridge.getServiceGroup())){
-                    continue;
-                }else{
-                    existingServiceGroups.add(cartridge.getServiceGroup());
-                }
-                if (cartridge.isMultiTenant()) {
-                    multiTenetCartridge.add(cartridge);
-                }
-                else {
-                    singleTentCartridge.add(cartridge);
-                }
-            }
-
-            multiTelentCartridgeList.setCartridge(multiTenetCartridge);
-            singleTeneCartridgetList.setCartridge(singleTentCartridge);
-
             RowMapper<Cartridge> cartridgeMapper = new RowMapper<Cartridge>() {
 
                 public String[] getData(Cartridge cartridge) {
@@ -370,116 +291,59 @@ public class RestCommandLineService {
                     data[2] = cartridge.getDescription();
                     data[3] = cartridge.getVersion();
                     data[4] = String.valueOf(cartridge.isMultiTenant());
-                    data[5] = cartridge.getIsPublic() ? "Public" : "Private";;
-
+                    data[5] = cartridge.getIsPublic() ? "Public" : "Private";
                     return data;
                 }
             };
 
-            if (multiTenetCartridge.size() == 0) {
-                String message = "Cannot find any deployed multi-tenant Cartridge. "
-                        + "Please deploy a Cartridge using [" + CliConstants.CARTRIDGE_DEPLOYMENT + "] command.";
-                if (logger.isDebugEnabled()) {
-                    logger.debug(message);
-                }
-                System.out.println(message);
-            }
-            else {
-                Cartridge[] cartridges = new Cartridge[multiTelentCartridgeList.getCartridge().size()];
-                cartridges = multiTelentCartridgeList.getCartridge().toArray(cartridges);
-
-                System.out.println("Available Multi-Tenant Cartridges:");
-                CliUtils.printTable(cartridges, cartridgeMapper, "Type", "Name", "Description", "Version", "Multitenanted");
-                System.out.println();
-            }
-
-            if (singleTentCartridge.size() == 0) {
-                String message = "Cannot find any deployed single-tenant Cartridge. "
-                        + "Please deploy a Cartridge using [" + CliConstants.CARTRIDGE_DEPLOYMENT + "] command.";
-                if (logger.isDebugEnabled()) {
-                    logger.debug(message);
-                }
-                System.out.println(message);
-            }
-            else {
-                Cartridge[] cartridges1 = new Cartridge[singleTeneCartridgetList.getCartridge().size()];
-                cartridges1 = singleTeneCartridgetList.getCartridge().toArray(cartridges1   );
+            Cartridge[] cartridges = new Cartridge[cartridgeList.getCartridge().size()];
+            cartridges = cartridgeList.getCartridge().toArray(cartridges);
 
-                System.out.println("Available Single-Tenant Cartridges:");
-                CliUtils.printTable(cartridges1, cartridgeMapper, "Type", "Name", "Description", "Version", "Multitenanted", "Accessibility");
-                System.out.println();
-            }
+            CliUtils.printTable(cartridges, cartridgeMapper, "Type", "Name", "Description", "Version",
+                    "Is Multi-Tenant", "Accessibility");
         } catch (Exception e) {
-            handleException("Exception in listing available cartridges", e);
-        } finally {
-            httpClient.getConnectionManager().shutdown();
+            String message = "Error in listing cartridges";
+            System.out.println(message);
+            logger.error(message, e);
         }
     }
 
-    // List currently available multi tenant and single tenant cartridges
-    public void describeAvailableCartridges(String type) throws CommandException {
-        DefaultHttpClient httpClient = new DefaultHttpClient();
+    // Describe currently available multi tenant and single tenant cartridges
+    public void describeAvailableCartridges(String cartridgeType) throws CommandException {
         try {
-            HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + LIST_CARTRIDGES_ENDPOINT);
-
-            String responseCode = "" + response.getStatusLine().getStatusCode();
-            String resultString = CliUtils.getHttpResponseString(response);
-            if (resultString == null) {
-                return;
-            }
-
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-
-            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
-                ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
-                System.out.println(exception);
-                return;
-            }
-
-            CartridgeList cartridgeList = gson.fromJson(resultString, CartridgeList.class);
+            CartridgeList cartridgeList = (CartridgeList) restClient.listEntity(LIST_CARTRIDGES_ENDPOINT,
+                    CartridgeList.class, "cartridges");
 
-            if (cartridgeList == null) {
-                System.out.println("Available cartridge list is null");
+            if ((cartridgeList == null) || (cartridgeList.getCartridge() == null) ||
+                    (cartridgeList.getCartridge().size() == 0)) {
+                System.out.println("Cartridge not found");
                 return;
             }
 
             for (Cartridge tmp : cartridgeList.getCartridge()) {
-                if(tmp.getCartridgeType().equalsIgnoreCase(type)) {
-                    System.out.println("The cartridge is:");
-                    System.out.println(gson.toJson(tmp));
+                if (tmp.getCartridgeType().equalsIgnoreCase(cartridgeType)) {
+                    System.out.println("Cartridge:");
+                    System.out.println(getGson().toJson(tmp));
                     return;
                 }
             }
-            System.out.println("Cannot find a matching Cartridge for [type] "+type);
+            System.out.println("Cartridge not found: " + cartridgeType);
         } catch (Exception e) {
-            handleException("Exception in listing available cartridges", e);
-        } finally {
-            httpClient.getConnectionManager().shutdown();
+            String message = "Error in describing cartridge: " + cartridgeType;
+            System.out.println(message);
+            logger.error(message, e);
         }
     }
 
     // List subscribe cartridges
-    public void listSubscribedCartridges(final boolean full) throws CommandException {
-        DefaultHttpClient httpClient = new DefaultHttpClient();
+    public void listCartridgeSubscriptions(final boolean showURLs) throws CommandException {
         try {
-            HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + LIST_CARTRIDGE_SUBSCRIPTIONS_ENDPOINT);
-
-            String responseCode = "" + response.getStatusLine().getStatusCode();
-            String resultString = CliUtils.getHttpResponseString(response);
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
+            CartridgeList cartridgeList = (CartridgeList) restClient.listEntity(LIST_CARTRIDGE_SUBSCRIPTIONS_ENDPOINT,
+                    CartridgeList.class, "cartridge subscriptions");
 
-            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
-                ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
-                System.out.println(exception);
-                return;
-            }
-
-            CartridgeList cartridgeList = gson.fromJson(resultString, CartridgeList.class);
-
-            if (cartridgeList == null) {
-                System.out.println("Subscribe cartridge list is null");
+            if ((cartridgeList == null) || (cartridgeList.getCartridge() == null) ||
+                    (cartridgeList.getCartridge().size() == 0)) {
+                System.out.println("No cartridge subscriptions found");
                 return;
             }
 
@@ -488,7 +352,7 @@ public class RestCommandLineService {
             // Filter out LB cartridges
             List<Cartridge> allCartridges = cartridgeList.getCartridge();
             for (Cartridge cartridge : allCartridges) {
-                if( ! cartridge.isLoadBalancer()) {
+                if (!cartridge.isLoadBalancer()) {
                     applicationCartridgeList.getCartridge().add(cartridge);
                 }
             }
@@ -496,28 +360,20 @@ public class RestCommandLineService {
             Cartridge[] cartridges = new Cartridge[applicationCartridgeList.getCartridge().size()];
             cartridges = applicationCartridgeList.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>() {
 
                 public String[] getData(Cartridge cartridge) {
-                    String[] data = full ? new String[11] : new String[9];
+                    String[] data = showURLs ? new String[11] : new String[9];
                     data[0] = cartridge.getCartridgeType();
                     data[1] = cartridge.getDisplayName();
-                    data[2] = cartridge.getIsPublic() ? "Public" : "Private";;
+                    data[2] = cartridge.getIsPublic() ? "Public" : "Private";
                     data[3] = cartridge.getVersion();
                     data[4] = cartridge.isMultiTenant() ? "Multi-Tenant" : "Single-Tenant";
                     data[5] = cartridge.getCartridgeAlias();
                     data[6] = cartridge.getStatus();
                     data[7] = cartridge.isMultiTenant() ? "N/A" : String.valueOf(cartridge.getActiveInstances());
                     data[8] = cartridge.getHostName();
-                    if (full) {
+                    if (showURLs) {
                         data[9] = getAccessURLs(cartridge);
                         data[10] = cartridge.getRepoURL() != null ? cartridge.getRepoURL() : "";
                     }
@@ -535,51 +391,35 @@ public class RestCommandLineService {
             headers.add("Alias");
             headers.add("Status");
             headers.add("Running Instances");
-            //headers.add("LB Cluster ID");
             headers.add("Host Name");
-            if (full) {
+            if (showURLs) {
                 headers.add("Access URL(s)");
                 headers.add("Repo URL");
             }
 
-            System.out.println("Subscribed Cartridges:");
+            System.out.println("Cartridge subscriptions:");
             CliUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
-            System.out.println();
-
         } catch (Exception e) {
-            handleException("Exception in listing subscribe cartridges", e);
-        } finally {
-            httpClient.getConnectionManager().shutdown();
+            String message = "Error in listing cartridge subscriptions";
+            System.out.println(message);
+            logger.error(message, e);
         }
     }
 
     // Lists subscribed cartridge info (from alias)
-    public void listSubscribedCartridgeInfo(String alias) throws CommandException {
+    public void describeCartridgeSubscription(String alias) throws CommandException {
         DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
-            HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
-                    + GET_CARTRIDGE_OF_TENANT_ENDPOINT + alias);
-
-            String responseCode = "" + response.getStatusLine().getStatusCode();
-            String resultString = CliUtils.getHttpResponseString(response);
-
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
+            CartridgeWrapper cartridgeWrapper = (CartridgeWrapper) restClient.getEntity(GET_CARTRIDGE_OF_TENANT_ENDPOINT,
+                    CartridgeWrapper.class, alias, "cartridge subscription");
 
-            if ( !responseCode.equals(CliConstants.RESPONSE_OK)) {
-                ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
-                System.out.println(exception);
+            if((cartridgeWrapper == null) || (cartridgeWrapper.getCartridge() == null)) {
+                System.out.println("Cartridge subscription not found: " + alias);
                 return;
             }
 
-            CartridgeWrapper cartridgeWrapper = gson.fromJson(resultString, CartridgeWrapper.class);
             Cartridge cartridge = cartridgeWrapper.getCartridge();
 
-            if (cartridge == null) {
-                System.out.println("Cartridge is null");
-                return;
-            }
-
             // Get LB IP s
             Map<String, Set<String>> lbIpMap = getLbIpList(cartridge, httpClient);
             final Set<String> lbPrivateIpSet = lbIpMap.get("private");
@@ -587,44 +427,42 @@ public class RestCommandLineService {
             Cartridge[] cartridges = new Cartridge[1];
             cartridges[0] = cartridge;
 
-
             System.out.println("\nSubscribed Cartridges Info\n");
             System.out.println("\tType : " + cartridge.getCartridgeType());
-            System.out.println("\tName : "	+ cartridge.getDisplayName());
-            System.out.println("\tVersion : "	+ cartridge.getVersion());
-            System.out.println("\tPublic : "	+ cartridge.getIsPublic());
-            String tenancy  = cartridge.isMultiTenant() ? "Multi-Tenant" : "Single-Tenant";
-            System.out.println("\tTenancy Model	: "	+ tenancy);
-            System.out.println("\tAlias : "	+ cartridge.getCartridgeAlias());
-            System.out.println("\tStatus : "	+ cartridge.getStatus());
-            String instanceCount  = String.valueOf(cartridge.getActiveInstances());
+            System.out.println("\tName : " + cartridge.getDisplayName());
+            System.out.println("\tVersion : " + cartridge.getVersion());
+            System.out.println("\tPublic : " + cartridge.getIsPublic());
+            String tenancy = cartridge.isMultiTenant() ? "Multi-Tenant" : "Single-Tenant";
+            System.out.println("\tTenancy Model	: " + tenancy);
+            System.out.println("\tAlias : " + cartridge.getCartridgeAlias());
+            System.out.println("\tStatus : " + cartridge.getStatus());
+            String instanceCount = String.valueOf(cartridge.getActiveInstances());
             System.out.println("\tRunning Instances	: " + instanceCount);
             System.out.println("\tAccess URL(s) : " + getAccessURLs(cartridge));
             if (cartridge.getRepoURL() != null) {
                 System.out.println("\tRepo URL : " + cartridge.getRepoURL());
             }
-            System.out.println("\tLB Private IP	: "	+ lbPrivateIpSet.toString());
+            System.out.println("\tLB Private IP	: " + lbPrivateIpSet.toString());
             if (lbFloatingIpSet != null) {
-                System.out.println("\tLB Floating IP : " +  lbFloatingIpSet.toString());
+                System.out.println("\tLB Floating IP : " + lbFloatingIpSet.toString());
             }
             if (cartridge.getProvider().equals("data")) {
-                System.out.println("\tDB-username : " +cartridge.getDbUserName());
-                System.out.println("\tDB-password : "	+cartridge.getPassword());
-                System.out.println("\tDB-Host IP (private)  : "	+cartridge.getIp());
+                System.out.println("\tDB-username : " + cartridge.getDbUserName());
+                System.out.println("\tDB-password : " + cartridge.getPassword());
+                System.out.println("\tDB-Host IP (private)  : " + cartridge.getIp());
                 if (cartridge.getPublicIp() != null) {
                     System.out.println("\tDB-Host IP (floating) : "
                             + cartridge.getPublicIp());
                 }
             }
-            System.out.println();
         } catch (Exception e) {
-            handleException("Exception in listing subscribe cartridges", e);
-        } finally {
-            httpClient.getConnectionManager().shutdown();
+            String message = "Error in getting cartridge subscription";
+            System.out.println(message);
+            logger.error(message, e);
         }
     }
 
-    private Map<String, Set<String>> getLbIpList(Cartridge cartridge, DefaultHttpClient httpClient) throws Exception{
+    private Map<String, Set<String>> getLbIpList(Cartridge cartridge, DefaultHttpClient httpClient) throws Exception {
         try {
             Map<String, Set<String>> privateFloatingLBIPMap = new HashMap<String, Set<String>>();
             Set<String> lbFloatingIpSet = new HashSet<String>();
@@ -650,7 +488,7 @@ public class RestCommandLineService {
                 GsonBuilder gsonBuilder = new GsonBuilder();
                 Gson gson = gsonBuilder.create();
 
-                if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                if (!responseCode.equals(CliConstants.RESPONSE_OK)) {
                     ExceptionMapper exception = gson.fromJson(resultStringCluster, ExceptionMapper.class);
                     System.out.println(exception);
                     return null;
@@ -677,7 +515,9 @@ public class RestCommandLineService {
 
             return privateFloatingLBIPMap;
         } catch (Exception e) {
-            handleException("Exception in get LB ip list", e);
+            String message = "Error in getting load balancer ip list";
+            System.out.println(message);
+            logger.error(message, e);
             return null;
         }
     }
@@ -695,7 +535,7 @@ public class RestCommandLineService {
 
             if (members.length == 0) {
                 if (logger.isDebugEnabled()) {
-                    logger.debug("No Members found");
+                    logger.debug("No members found");
                 }
                 System.out.println("No members found for the corresponding cluster for type " + cartridgeType
                         + ", alias " + alias);
@@ -704,26 +544,26 @@ public class RestCommandLineService {
 
             System.out.println("\nList of members in the [cluster]: " + alias);
             for (Member member : members) {
-                System.out.println("\n\tServiceName : "+member.getServiceName());
-                System.out.println("\tClusterId : "+member.getClusterId());
-                System.out.println("\tNewtworkPartitionId : "+member.getNetworkPartitionId());
-                System.out.println("\tPartitionId : "+member.getPartitionId());
-                System.out.println("\tStatus : "+member.getStatus());
-                if(member.getLbClusterId() != null) {
-                    System.out.println("\tLBCluster : "+member.getLbClusterId());
+                System.out.println("\n\tServiceName : " + member.getServiceName());
+                System.out.println("\tClusterId : " + member.getClusterId());
+                System.out.println("\tNewtworkPartitionId : " + member.getNetworkPartitionId());
+                System.out.println("\tPartitionId : " + member.getPartitionId());
+                System.out.println("\tStatus : " + member.getStatus());
+                if (member.getLbClusterId() != null) {
+                    System.out.println("\tLBCluster : " + member.getLbClusterId());
                 }
-                System.out.println("\tMemberPrivateIp : "+member.getMemberIp());
-                System.out.println("\tMemberFloatingIp : "+member.getMemberPublicIp());
+                System.out.println("\tMemberPrivateIp : " + member.getMemberIp());
+                System.out.println("\tMemberFloatingIp : " + member.getMemberPublicIp());
                 System.out.println("\t-----------------------");
             }
 
             System.out.println("==================================================");
-            System.out.println("List of LB members for the [cluster]: " + alias );
+            System.out.println("List of LB members for the [cluster]: " + alias);
 
             // Invoke  cluster/{clusterId}
             for (Member m : members) {
                 HttpResponse responseCluster = restClient.doGet(httpClient, restClient.getBaseURL() + GET_CLUSTER_OF_TENANT_ENDPOINT
-                        +"clusterId/"+ m.getLbClusterId());
+                        + "clusterId/" + m.getLbClusterId());
 
                 String responseCode = "" + responseCluster.getStatusLine().getStatusCode();
                 String resultStringCluster = CliUtils.getHttpResponseString(responseCluster);
@@ -731,7 +571,7 @@ public class RestCommandLineService {
                 GsonBuilder gsonBuilder = new GsonBuilder();
                 Gson gson = gsonBuilder.create();
 
-                if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                if (!responseCode.equals(CliConstants.RESPONSE_OK)) {
                     ExceptionMapper exception = gson.fromJson(resultStringCluster, ExceptionMapper.class);
                     System.out.println(exception);
                     break;
@@ -741,13 +581,15 @@ public class RestCommandLineService {
             }
 
         } catch (Exception e) {
-            handleException("Exception in listing subscribe cartridges", e);
+            String message = "Error in listing members";
+            System.out.println(message);
+            logger.error(message, e);
         } finally {
             httpClient.getConnectionManager().shutdown();
         }
     }
 
-    private Member[] getMembers(String cartridgeType, String alias, DefaultHttpClient httpClient) throws Exception{
+    private Member[] getMembers(String cartridgeType, String alias, DefaultHttpClient httpClient) throws Exception {
         try {
             HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
                     + GET_CLUSTER_OF_TENANT_ENDPOINT + cartridgeType + "/" + alias);
@@ -755,7 +597,7 @@ public class RestCommandLineService {
             String responseCode = "" + response.getStatusLine().getStatusCode();
 
             Gson gson = new Gson();
-            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+            if (!responseCode.equals(CliConstants.RESPONSE_OK)) {
                 String resultString = CliUtils.getHttpResponseString(response);
                 ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
                 System.out.println(exception);
@@ -774,15 +616,17 @@ public class RestCommandLineService {
 
             return members;
         } catch (Exception e) {
-            handleException("Exception in get member", e);
+            String message = "Error in listing members";
+            System.out.println(message);
+            logger.error(message, e);
             return null;
         }
     }
 
     private Cluster getClusterObjectFromString(String resultString) {
         String tmp;
-        if(resultString.startsWith("{\"cluster\"")) {
-            tmp = resultString.substring("{\"cluster\"".length() + 1, resultString.length()-1);
+        if (resultString.startsWith("{\"cluster\"")) {
+            tmp = resultString.substring("{\"cluster\"".length() + 1, resultString.length() - 1);
             resultString = tmp;
         }
         GsonBuilder gsonBuilder = new GsonBuilder();
@@ -820,21 +664,21 @@ public class RestCommandLineService {
         }
 
         for (Member member : members) {
-            System.out.println("\n\tServiceName : "+member.getServiceName());
-            System.out.println("\tClusterId : "+member.getClusterId());
-            System.out.println("\tNewtworkPartitionId : "+member.getNetworkPartitionId());
-            System.out.println("\tPartitionId : "+member.getPartitionId());
-            System.out.println("\tStatus : "+member.getStatus());
-            if(member.getLbClusterId() != null) {
-                System.out.println("\tLBCluster : "+member.getLbClusterId());
-            }
-            System.out.println("\tMemberPrivateIp : "+member.getMemberIp());
-            System.out.println("\tMemberFloatingIp : "+member.getMemberPublicIp());
+            System.out.println("\n\tServiceName : " + member.getServiceName());
+            System.out.println("\tClusterId : " + member.getClusterId());
+            System.out.println("\tNewtworkPartitionId : " + member.getNetworkPartitionId());
+            System.out.println("\tPartitionId : " + member.getPartitionId());
+            System.out.println("\tStatus : " + member.getStatus());
+            if (member.getLbClusterId() != null) {
+                System.out.println("\tLBCluster : " + member.getLbClusterId());
+            }
+            System.out.println("\tMemberPrivateIp : " + member.getMemberIp());
+            System.out.println("\tMemberFloatingIp : " + member.getMemberPublicIp());
             System.out.println("\t-----------------------");
         }
     }
 
-    private String getAsPolicyFromServiceDefinition(String cartridgeType) throws CommandException{
+    private String getAsPolicyFromServiceDefinition(String cartridgeType) throws CommandException {
         DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
             HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
@@ -845,7 +689,7 @@ public class RestCommandLineService {
             GsonBuilder gsonBuilder = new GsonBuilder();
             Gson gson = gsonBuilder.create();
 
-            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+            if (!responseCode.equals(CliConstants.RESPONSE_OK)) {
                 String resultString = CliUtils.getHttpResponseString(response);
                 ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
                 System.out.println(exception);
@@ -858,8 +702,8 @@ public class RestCommandLineService {
                 return null;
             }
 
-            String  serviceDefinitionString =  resultString.substring(25, resultString.length() -1);
-            ServiceDefinitionBean serviceDefinition= gson.fromJson(serviceDefinitionString, ServiceDefinitionBean.class);
+            String serviceDefinitionString = resultString.substring(25, resultString.length() - 1);
+            ServiceDefinitionBean serviceDefinition = gson.fromJson(serviceDefinitionString, ServiceDefinitionBean.class);
             if (serviceDefinition == null) {
                 System.out.println("Deploy service list is empty");
                 return null;
@@ -875,7 +719,7 @@ public class RestCommandLineService {
         }
     }
 
-    private String getDeploymentPolicyFromServiceDefinition(String cartridgeType) throws CommandException{
+    private String getDeploymentPolicyFromServiceDefinition(String cartridgeType) throws CommandException {
         DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
             HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
@@ -886,7 +730,7 @@ public class RestCommandLineService {
             GsonBuilder gsonBuilder = new GsonBuilder();
             Gson gson = gsonBuilder.create();
 
-            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+            if (!responseCode.equals(CliConstants.RESPONSE_OK)) {
                 String resultString = CliUtils.getHttpResponseString(response);
                 ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
                 System.out.println(exception);
@@ -899,8 +743,8 @@ public class RestCommandLineService {
                 return null;
             }
 
-            String  serviceDefinitionString =  resultString.substring(25, resultString.length() -1);
-            ServiceDefinitionBean serviceDefinition= gson.fromJson(serviceDefinitionString, ServiceDefinitionBean.class);
+            String serviceDefinitionString = resultString.substring(25, resultString.length() - 1);
+            ServiceDefinitionBean serviceDefinition = gson.fromJson(serviceDefinitionString, ServiceDefinitionBean.class);
             if (serviceDefinition == null) {
                 System.out.println("Deploy service list is empty");
                 return null;
@@ -918,7 +762,7 @@ public class RestCommandLineService {
 
     // This method does the cartridge subscription
     public void subscribe(String cartridgeType, String alias, String externalRepoURL, boolean privateRepo, String username,
-                          String password,String asPolicy,
+                          String password, String asPolicy,
                           String depPolicy, String size, boolean remoOnTermination, boolean persistanceMapping,
                           boolean enableCommits, String volumeId)
             throws CommandException {
@@ -929,7 +773,12 @@ public class RestCommandLineService {
         Gson gson = gsonBuilder.create();
 
         try {
-            Cartridge cartridge = listCartridge(cartridgeType);
+            Cartridge cartridge = getCartridge(cartridgeType);
+            if (cartridge == null) {
+                System.out.println("Cartridge not found: " + cartridgeType);
+                return;
+            }
+
             if (cartridge.isMultiTenant()) {
                 asPolicy = getAsPolicyFromServiceDefinition(cartridgeType);
                 depPolicy = getDeploymentPolicyFromServiceDefinition(cartridgeType);
@@ -956,7 +805,7 @@ public class RestCommandLineService {
 
             String responseCode = "" + response.getStatusLine().getStatusCode();
 
-            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+            if (!responseCode.equals(CliConstants.RESPONSE_OK)) {
                 String resultString = CliUtils.getHttpResponseString(response);
                 ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
                 System.out.println(exception);
@@ -970,7 +819,7 @@ public class RestCommandLineService {
                 return;
             }
 
-            String  subscriptionOutputJSON = subscriptionOutput.substring(20, subscriptionOutput.length() -1);
+            String subscriptionOutputJSON = subscriptionOutput.substring(20, subscriptionOutput.length() - 1);
             SubscriptionInfo subcriptionInfo = gson.fromJson(subscriptionOutputJSON, SubscriptionInfo.class);
 
             System.out.format("You have successfully subscribed to %s cartridge with alias %s.%n", cartridgeType, alias);
@@ -1000,22 +849,22 @@ public class RestCommandLineService {
             httpClient.getConnectionManager().shutdown();
         }
     }
-    
- // This method does the cartridge subscription
+
+    // This method does the cartridge subscription
     public void subscribe(String subscriptionJson)
             throws CommandException {
-        
+
         DefaultHttpClient httpClient = new DefaultHttpClient();
         GsonBuilder gsonBuilder = new GsonBuilder();
         Gson gson = gsonBuilder.create();
-        
+
         try {
             HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + SUBSCRIBE_CARTRIDGE_ENDPOINT,
                     subscriptionJson);
 
             String responseCode = "" + response.getStatusLine().getStatusCode();
 
-            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+            if (!responseCode.equals(CliConstants.RESPONSE_OK)) {
                 String resultString = CliUtils.getHttpResponseString(response);
                 ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
                 System.out.println(exception);
@@ -1029,10 +878,10 @@ public class RestCommandLineService {
                 return;
             }
 
-            String  subscriptionOutputJSON = subscriptionOutput.substring(20, subscriptionOutput.length() -1);
+            String subscriptionOutputJSON = subscriptionOutput.substring(20, subscriptionOutput.length() - 1);
             SubscriptionInfo subcriptionInfo = gson.fromJson(subscriptionOutputJSON, SubscriptionInfo.class);
 
-            System.out.format("You have successfully subscribed.");
+            System.out.format("You have successfully subscribed. ");
 
             String repoURL;
             String hostnames = null;
@@ -1054,12 +903,12 @@ public class RestCommandLineService {
         } finally {
             httpClient.getConnectionManager().shutdown();
         }
-        
+
     }
 
     // This method helps to create the new tenant
     public void addTenant(String admin, String firstName, String lastaName, String password, String domain, String email)
-            throws CommandException{
+            throws CommandException {
         DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
             TenantInfoBean tenantInfo = new TenantInfoBean();
@@ -1080,7 +929,7 @@ public class RestCommandLineService {
 
             String responseCode = "" + response.getStatusLine().getStatusCode();
 
-            if (responseCode.equals(CliConstants.RESPONSE_OK)){
+            if (responseCode.equals(CliConstants.RESPONSE_OK)) {
                 System.out.println("Tenant added successfully");
                 return;
             } else {
@@ -1098,7 +947,7 @@ public class RestCommandLineService {
 
     // This method helps to create the new user
     public void addUser(String userName, String credential, String role, String firstName, String lastName, String email, String profileName)
-            throws CommandException{
+            throws CommandException {
         DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
             UserInfoBean userInfoBean = new UserInfoBean();
@@ -1120,7 +969,7 @@ public class RestCommandLineService {
 
             String responseCode = "" + response.getStatusLine().getStatusCode();
 
-            if (responseCode.equals(CliConstants.RESPONSE_CREATED)){
+            if (responseCode.equals(CliConstants.RESPONSE_CREATED)) {
                 System.out.println("User added successfully");
                 return;
             } else {
@@ -1137,7 +986,7 @@ public class RestCommandLineService {
     }
 
     // This method helps to delete the created tenant
-    public void deleteTenant(String tenantDomain) throws CommandException{
+    public void deleteTenant(String tenantDomain) throws CommandException {
         DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
             HttpResponse response = restClient.doDelete(httpClient, restClient.getBaseURL()
@@ -1165,7 +1014,7 @@ public class RestCommandLineService {
     }
 
     // This method helps to delete the created user
-    public void deleteUser(String userName) throws CommandException{
+    public void deleteUser(String userName) throws CommandException {
         DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
             HttpResponse response = restClient.doDelete(httpClient, restClient.getBaseURL()
@@ -1250,37 +1099,17 @@ public class RestCommandLineService {
 
     // This method helps to list all tenants
     public void listAllTenants() throws CommandException {
-        DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
-            HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
-                    + LIST_TENANT_ENDPOINT);
-
-            String responseCode = "" + response.getStatusLine().getStatusCode();
-            String resultString = CliUtils.getHttpResponseString(response);
+            TenantInfoList tenantInfoList = (TenantInfoList)restClient.listEntity(LIST_TENANT_ENDPOINT,
+                    TenantInfoList.class, "tenants");
 
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-
-            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
-                ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
-                System.out.println(exception);
-                return;
-            }
-
-            if (resultString == null) {
-                System.out.println("Response content is empty");
-                return;
-            }
-
-            TenantInfoList tenantInfoList = gson.fromJson(resultString, TenantInfoList.class);
-
-            if (tenantInfoList == null) {
-                System.out.println("Tenant information list is empty");
+            if ((tenantInfoList == null) || (tenantInfoList.getTenantInfoBean() == null) ||
+                    (tenantInfoList.getTenantInfoBean().size() == 0)) {
+                System.out.println("No tenants found");
                 return;
             }
 
-            RowMapper<TenantInfoBean> tenantInfoMapper = new RowMapper<TenantInfoBean>() {
-
+            RowMapper<TenantInfoBean> rowMapper = new RowMapper<TenantInfoBean>() {
                 public String[] getData(TenantInfoBean tenantInfo) {
                     String[] data = new String[5];
                     data[0] = tenantInfo.getTenantDomain();
@@ -1292,63 +1121,31 @@ public class RestCommandLineService {
                 }
             };
 
-            TenantInfoBean[] tenants = new TenantInfoBean[tenantInfoList.getTenantInfoBean().size()];
-            tenants = tenantInfoList.getTenantInfoBean().toArray(tenants);
-
-            if (tenants.length == 0) {
-                String message = "Cannot find any Tenant. "
-                        + "Please create a new tenant using [" + CliConstants.ADD_TENANT + "] command.";
-                if (logger.isDebugEnabled()) {
-                    logger.debug(message);
-                }
-                System.out.println(message);
-                return;
-            }
-
-            System.out.println("Available Tenants:" );
-            CliUtils.printTable(tenants, tenantInfoMapper, "Domain", "Tenant ID", "Email", "State", "Created Date");
-            System.out.println();
+            TenantInfoBean[] tenantArray = new TenantInfoBean[tenantInfoList.getTenantInfoBean().size()];
+            tenantArray = tenantInfoList.getTenantInfoBean().toArray(tenantArray);
 
+            System.out.println("Tenants:");
+            CliUtils.printTable(tenantArray, rowMapper, "Domain", "Tenant ID", "Email", "State", "Created Date");
         } catch (Exception e) {
-            handleException("Exception in listing partitions", e);
-        } finally {
-            httpClient.getConnectionManager().shutdown();
+            String message = "Error in listing users";
+            System.out.println(message);
+            logger.error(message, e);
         }
     }
 
     // This method helps to list all users
     public void listAllUsers() throws CommandException {
-        DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
-            HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
-                    + LIST_USERS_ENDPOINT);
-
-            String responseCode = "" + response.getStatusLine().getStatusCode();
-            String resultString = CliUtils.getHttpResponseString(response);
+            UserInfoList userInfoList = (UserInfoList) restClient.listEntity(LIST_USERS_ENDPOINT,
+                    UserInfoList.class, "users");
 
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-
-            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
-                ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
-                System.out.println(exception);
-                return;
-            }
-
-            if (resultString == null) {
-                System.out.println("Response content is empty");
+            if ((userInfoList == null) || (userInfoList.getUserInfoBean() == null) ||
+                    (userInfoList.getUserInfoBean().size() == 0)) {
+                System.out.println("No users found");
                 return;
             }
 
-            UserInfoList userInfoList = gson.fromJson(resultString, UserInfoList.class);
-
-            if (userInfoList == null) {
-                System.out.println("User information list is empty");
-                return;
-            }
-
-            RowMapper<UserInfoBean> userInfoMapper = new RowMapper<UserInfoBean>() {
-
+            RowMapper<UserInfoBean> rowMapper = new RowMapper<UserInfoBean>() {
                 public String[] getData(UserInfoBean userInfo) {
                     String[] data = new String[2];
                     data[0] = userInfo.getUserName();
@@ -1357,27 +1154,15 @@ public class RestCommandLineService {
                 }
             };
 
-            UserInfoBean[] users = new UserInfoBean[userInfoList.getUserInfoBean().size()];
-            users = userInfoList.getUserInfoBean().toArray(users);
-
-            if (users.length == 0) {
-                String message = "Cannot find any User. "
-                        + "Please create a new user using [" + CliConstants.ADD_USER + "] command.";
-                if (logger.isDebugEnabled()) {
-                    logger.debug(message);
-                }
-                System.out.println(message);
-                return;
-            }
-
-            System.out.println("Available Tenants:" );
-            CliUtils.printTable(users, userInfoMapper, "Username", "Role");
-            System.out.println();
+            UserInfoBean[] usersArray = new UserInfoBean[userInfoList.getUserInfoBean().size()];
+            usersArray = userInfoList.getUserInfoBean().toArray(usersArray);
 
+            System.out.println("Users:");
+            CliUtils.printTable(usersArray, rowMapper, "Username", "Role");
         } catch (Exception e) {
-            handleException("Exception in listing partitions", e);
-        } finally {
-            httpClient.getConnectionManager().shutdown();
+            String message = "Error in listing users";
+            System.out.println(message);
+            logger.error(message, e);
         }
     }
 
@@ -1401,49 +1186,51 @@ public class RestCommandLineService {
                 System.out.println(exception);
             }
 
-        } catch ( Exception e) {
-            handleException("Exception in un-subscribing cartridge", e);
+        } catch (Exception e) {
+            String message = "Error in un-subscribing cartridge";
+            System.out.println(message);
+            logger.error(message, e);
         } finally {
             httpClient.getConnectionManager().shutdown();
         }
     }
 
     // This method helps to deploy cartridge definitions
-    public void deployCartridgeDefinition (String cartridgeDefinition) throws CommandException{
+    public void deployCartridgeDefinition(String cartridgeDefinition) throws CommandException {
         restClient.deployEntity(DEPLOY_CARTRIDGE_ENDPOINT, cartridgeDefinition, "cartridge");
     }
 
     // This method helps to undeploy cartridge definitions
-    public void undeployCartrigdeDefinition (String id) throws CommandException{
+    public void undeployCartrigdeDefinition(String id) throws CommandException {
         restClient.undeployEntity(DEPLOY_CARTRIDGE_ENDPOINT, "cartridge", id);
     }
 
     // This method helps to deploy partitions
-    public void deployPartition (String partitionDefinition) throws CommandException{
+    public void deployPartition(String partitionDefinition) throws CommandException {
         restClient.deployEntity(DEPLOY_PARTITION_ENDPOINT, partitionDefinition, "partition");
     }
 
     // This method helps to deploy autoscalling polices
-    public void deployAutoscalingPolicy (String autoScalingPolicy) throws CommandException{
+    public void deployAutoscalingPolicy(String autoScalingPolicy) throws CommandException {
         restClient.deployEntity(DEPLOY_AUTOSCALING_POLICY_ENDPOINT, autoScalingPolicy, "autoscaling policy");
     }
 
     // This method helps to deploy multi-tenant service cluster
-    public void deployService (String serviceDefinition) throws CommandException{
+    public void deployService(String serviceDefinition) throws CommandException {
         restClient.deployEntity(DEPLOY_SERVICE_ENDPOINT, serviceDefinition, "service");
     }
 
     // This method helps to undeploy multi-tenant service cluster
-    public void undeployService(String id) throws  CommandException {
+    public void undeployService(String id) throws CommandException {
         restClient.undeployEntity(DEPLOY_SERVICE_ENDPOINT, "service", id);
     }
 
     public void listServices() throws CommandException {
         try {
             ServiceDefinitionList list = (ServiceDefinitionList) restClient.listEntity(LIST_SERVICE_ENDPOINT,
-                ServiceDefinitionList.class, "service");
+                    ServiceDefinitionList.class, "service");
 
-            if((list == null) || (list.getServiceDefinition() == null) || (list.getServiceDefinition().size() == 0)) {
+            if ((list == null) || (list.getServiceDefinition() == null) || (list.getServiceDefinition().size() == 0)) {
                 System.out.println("No services found");
                 return;
             }
@@ -1457,7 +1244,8 @@ public class RestCommandLineService {
                     data[2] = definition.getAutoscalingPolicyName();
                     data[3] = definition.getClusterDomain();
                     data[4] = definition.getTenantRange();
-                    data[5] = definition.getIsPublic() ? "Public" : "Private";;
+                    data[5] = definition.getIsPublic() ? "Public" : "Private";
+                    ;
                     return data;
                 }
             };
@@ -1465,7 +1253,7 @@ public class RestCommandLineService {
             ServiceDefinitionBean[] array = new ServiceDefinitionBean[list.getServiceDefinition().size()];
             array = list.getServiceDefinition().toArray(array);
 
-            System.out.println("Services available:");
+            System.out.println("Services found:");
             CliUtils.printTable(array, rowMapper, "Cartridge Type", "Deployment Policy Name",
                     "Autoscaling Policy Name", "Cluster Domain", "Tenant Range", "Accessibility");
         } catch (Exception e) {
@@ -1476,12 +1264,12 @@ public class RestCommandLineService {
     }
 
     // This method helps to deploy deployment polices
-    public void deployDeploymentPolicy (String deploymentPolicy) throws CommandException{
+    public void deployDeploymentPolicy(String deploymentPolicy) throws CommandException {
         restClient.deployEntity(DEPLOY_DEPLOYMENT_POLICY_ENDPOINT, deploymentPolicy, "deployment policy");
     }
 
     // This method list available partitons
-    public void listPartitions() throws CommandException{
+    public void listPartitions() throws CommandException {
         try {
             PartitionList list = (PartitionList) restClient.listEntity(LIST_PARTITION_ENDPOINT,
                     PartitionList.class, "partitions");
@@ -1505,10 +1293,8 @@ public class RestCommandLineService {
             Partition[] partitions = new Partition[list.getPartition().size()];
             partitions = list.getPartition().toArray(partitions);
 
-            System.out.println("Available partitions:" );
+            System.out.println("Partitions found:");
             CliUtils.printTable(partitions, rowMapper, "ID", "Provider", "Accessibility");
-            System.out.println();
-
         } catch (Exception e) {
             String message = "Error in listing partitions";
             System.out.println(message);
@@ -1539,7 +1325,7 @@ public class RestCommandLineService {
             AutoscalePolicy[] array = new AutoscalePolicy[list.getAutoscalePolicy().size()];
             array = list.getAutoscalePolicy().toArray(array);
 
-            System.out.println("Available autoscaling policies:");
+            System.out.println("Autoscaling policies found:");
             CliUtils.printTable(array, rowMapper, "ID", "Accessibility");
         } catch (Exception e) {
             String message = "Error in listing autoscaling policies";
@@ -1550,7 +1336,7 @@ public class RestCommandLineService {
 
     public void listDeploymentPolicies() throws CommandException {
         try {
-            DeploymentPolicyList list = (DeploymentPolicyList)restClient.listEntity(LIST_DEPLOYMENT_POLICY_ENDPOINT,
+            DeploymentPolicyList list = (DeploymentPolicyList) restClient.listEntity(LIST_DEPLOYMENT_POLICY_ENDPOINT,
                     DeploymentPolicyList.class, "deployment policies");
 
             if ((list == null) || (list.getDeploymentPolicy() == null) || (list.getDeploymentPolicy().size() == 0)) {
@@ -1571,9 +1357,8 @@ public class RestCommandLineService {
             DeploymentPolicy[] array = new DeploymentPolicy[list.getDeploymentPolicy().size()];
             array = list.getDeploymentPolicy().toArray(array);
 
-            System.out.println("Available deployment policies:");
+            System.out.println("Deployment policies found:");
             CliUtils.printTable(array, rowMapper, "ID", "Accessibility");
-            System.out.println();
         } catch (Exception e) {
             String message = "Error in listing deployment policies";
             System.out.println(message);
@@ -1583,7 +1368,7 @@ public class RestCommandLineService {
 
     public void describeDeploymentPolicy(String id) throws CommandException {
         try {
-            DeploymentPolicyList list = (DeploymentPolicyList)restClient.listEntity(LIST_DEPLOYMENT_POLICY_ENDPOINT,
+            DeploymentPolicyList list = (DeploymentPolicyList) restClient.listEntity(LIST_DEPLOYMENT_POLICY_ENDPOINT,
                     DeploymentPolicyList.class, "deployment policies");
 
             if ((list == null) || (list.getDeploymentPolicy() == null) || (list.getDeploymentPolicy().size() == 0)) {
@@ -1592,7 +1377,7 @@ public class RestCommandLineService {
             }
 
             for (DeploymentPolicy policy : list.getDeploymentPolicy()) {
-                if(policy.getId().equals(id)) {
+                if (policy.getId().equals(id)) {
                     System.out.println("Deployment policy: " + id);
                     System.out.println(getGson().toJson(policy));
                     return;
@@ -1617,7 +1402,7 @@ public class RestCommandLineService {
             }
 
             for (Partition partition : list.getPartition()) {
-                if(partition.getId().equals(id)) {
+                if (partition.getId().equals(id)) {
                     System.out.println("Partition: " + id);
                     System.out.println(getGson().toJson(partition));
                     return;
@@ -1641,8 +1426,8 @@ public class RestCommandLineService {
                 return;
             }
 
-            for(AutoscalePolicy policy : list.getAutoscalePolicy()) {
-                if(policy.getId().equalsIgnoreCase(id)) {
+            for (AutoscalePolicy policy : list.getAutoscalePolicy()) {
+                if (policy.getId().equalsIgnoreCase(id)) {
                     System.out.println("Autoscaling policy: " + id);
                     System.out.println(getGson().toJson(policy));
                     return;
@@ -1663,7 +1448,7 @@ public class RestCommandLineService {
     public void listKubernetesGroups() {
         try {
             KubernetesGroupList list = (KubernetesGroupList) restClient.listEntity(LIST_KUBERNETES_GROUP_ENDPOINT, KubernetesGroupList.class, "kubernetes group");
-            if((list != null) && (list.getKubernetesGroup() != null) && (list.getKubernetesGroup().size() > 0)) {
+            if ((list != null) && (list.getKubernetesGroup() != null) && (list.getKubernetesGroup().size() > 0)) {
                 RowMapper<KubernetesGroup> partitionMapper = new RowMapper<KubernetesGroup>() {
                     public String[] getData(KubernetesGroup kubernetesGroup) {
                         String[] data = new String[2];
@@ -1675,7 +1460,7 @@ public class RestCommandLineService {
 
                 KubernetesGroup[] array = new KubernetesGroup[list.getKubernetesGroup().size()];
                 array = list.getKubernetesGroup().toArray(array);
-                System.out.println("Available kubernetes groups:" );
+                System.out.println("Kubernetes groups found:");
                 CliUtils.printTable(array, partitionMapper, "Group ID", "Description");
             } else {
                 System.out.println("No kubernetes groups found");
@@ -1700,7 +1485,7 @@ public class RestCommandLineService {
         try {
             KubernetesHostList list = (KubernetesHostList) restClient.listEntity(LIST_KUBERNETES_HOSTS_ENDPOINT.replace("{groupId}", groupId),
                     KubernetesHostList.class, "kubernetes host");
-            if((list != null) && (list.getKubernetesHost() != null) && (list.getKubernetesHost().size() > 0)) {
+            if ((list != null) && (list.getKubernetesHost() != null) && (list.getKubernetesHost().size() > 0)) {
                 RowMapper<KubernetesHost> partitionMapper = new RowMapper<KubernetesHost>() {
                     public String[] getData(KubernetesHost kubernetesHost) {
                         String[] data = new String[3];
@@ -1713,7 +1498,7 @@ public class RestCommandLineService {
 
                 KubernetesHost[] array = new KubernetesHost[list.getKubernetesHost().size()];
                 array = list.getKubernetesHost().toArray(array);
-                System.out.println("Available kubernetes hosts:" );
+                System.out.println("Kubernetes hosts found:");
                 CliUtils.printTable(array, partitionMapper, "Host ID", "Hostname", "IP Address");
             } else {
                 System.out.println("No kubernetes hosts found");
@@ -1865,8 +1650,9 @@ public class RestCommandLineService {
             userInfoBean = new ArrayList<UserInfoBean>();
         }
     }
+
     // This class is for convert JSON string to CartridgeList object
-    private class CartridgeList  {
+    private class CartridgeList {
         private ArrayList<Cartridge> cartridge;
 
         public ArrayList<Cartridge> getCartridge() {
@@ -1882,7 +1668,7 @@ public class RestCommandLineService {
         }
     }
 
-    private class ClusterList{
+    private class ClusterList {
         private ArrayList<Cluster> cluster;
 
         public ArrayList<Cluster> getCluster() {
@@ -1892,7 +1678,12 @@ public class RestCommandLineService {
         public void setCluster(ArrayList<Cluster> clusters) {
             this.cluster = clusters;
         }
-        ClusterList(){cluster = new ArrayList<Cluster>();};
+
+        ClusterList() {
+            cluster = new ArrayList<Cluster>();
+        }
+
+        ;
     }
 
     // This will return access url from a given cartridge
@@ -1901,7 +1692,7 @@ public class RestCommandLineService {
         StringBuilder urlBuilder = new StringBuilder();
 
         for (PortMapping portMapping : portMappings) {
-            String url = portMapping.getProtocol()+"://"+ cartridge.getHostName() + ":" + portMapping.getProxyPort() + "/";
+            String url = portMapping.getProtocol() + "://" + cartridge.getHostName() + ":" + portMapping.getProxyPort() + "/";
             urlBuilder.append(url).append(", ");
         }
 
@@ -1978,7 +1769,7 @@ public class RestCommandLineService {
             return multiTenetCartridge.size() > 0;
 
         } catch (Exception e) {
-            handleException("Exception in listing available cartridges", e);
+            handleException("Exception in listing cartridges", e);
             return false;
         } finally {
             httpClient.getConnectionManager().shutdown();

http://git-wip-us.apache.org/repos/asf/stratos/blob/10bee14e/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 b52f9ed..5b0c633 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
@@ -150,7 +150,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
         command = new DeployDeploymentPolicyCommand();
         commands.put(command.getName(), command);
 		
-		command = new ListSubscribedCartridgesCommand();
+		command = new ListCartridgeSubscriptionsCommand();
 		commands.put(command.getName(), command);
 
         command = new ListPartitionCommand();
@@ -177,7 +177,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
         command = new DescribeAutoScalingPolicyCommand();
         commands.put(command.getName(), command);
         
-        command = new ListCartridgeSubscriptionsCommand();
+        command = new DescribeCartridgeSubscriptionCommand();
         commands.put(command.getName(), command);
 		
 		command = new SyncCommand();

http://git-wip-us.apache.org/repos/asf/stratos/blob/10bee14e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeSubscriptionCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeSubscriptionCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeSubscriptionCommand.java
new file mode 100644
index 0000000..ecac615
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeSubscriptionCommand.java
@@ -0,0 +1,95 @@
+/**
+ *  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.commands;
+
+import org.apache.commons.cli.Options;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.stratos.cli.Command;
+import org.apache.stratos.cli.RestCommandLineService;
+import org.apache.stratos.cli.StratosCommandContext;
+import org.apache.stratos.cli.exception.CommandException;
+import org.apache.stratos.cli.utils.CliConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DescribeCartridgeSubscriptionCommand implements Command<StratosCommandContext>{
+	
+	private static final Logger logger = LoggerFactory.getLogger(DescribeCartridgeSubscriptionCommand.class);
+	
+	private final Options options;
+	
+	public DescribeCartridgeSubscriptionCommand() {
+		options = constructOptions();
+	}
+	
+	/**
+	 * Construct Options.
+	 * 
+	 * @return Options expected from command-line.
+	 */
+	private Options constructOptions() {
+
+		final Options options = new Options();
+		return options;
+	}
+	
+	@Override
+	public String getName() {
+		return "describe-cartridge-subscription";
+	}
+
+	@Override
+	public String getDescription() {
+		return "Describe cartridge subscription";
+	}
+
+	@Override
+	public String getArgumentSyntax() {
+		return "[cartridge-subscription-alias]";
+	}
+
+	@Override
+	public Options getOptions() {
+		return options;
+	}
+
+	@Override
+	public int execute(StratosCommandContext context, String[] args) throws CommandException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("Executing {} command...", getName());
+		}
+		
+		if (args != null && args.length > 0) {
+			String cartridgeSubscriptionAlias = args[0];
+
+            if(StringUtils.isBlank(cartridgeSubscriptionAlias)){
+                System.out.println("Please specify a non blank alias");
+                return CliConstants.COMMAND_FAILED;
+            }
+            else{
+                RestCommandLineService.getInstance().describeCartridgeSubscription(cartridgeSubscriptionAlias);
+                return CliConstants.COMMAND_SUCCESSFULL;
+            }
+		} else {
+			context.getStratosApplication().printUsage(getName());
+			return CliConstants.COMMAND_FAILED;
+		}
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/10bee14e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java
index a7e439e..90a4e4d 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java
@@ -51,7 +51,6 @@ public class ListAutoscalePolicyCommand implements Command<StratosCommandContext
             logger.debug("Executing {} command...", getName());
         }
         if (args == null || args.length == 0) {
-            //CommandLineService.getInstance().listAvailableCartridges();
             RestCommandLineService.getInstance().listAutoscalingPolicies();
             return CliConstants.COMMAND_SUCCESSFULL;
         } else {

http://git-wip-us.apache.org/repos/asf/stratos/blob/10bee14e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeSubscriptionsCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeSubscriptionsCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeSubscriptionsCommand.java
index 372a23a..4e10118 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeSubscriptionsCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeSubscriptionsCommand.java
@@ -18,22 +18,26 @@
  */
 package org.apache.stratos.cli.commands;
 
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.stratos.cli.Command;
+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;
 import org.apache.stratos.cli.StratosCommandContext;
 import org.apache.stratos.cli.exception.CommandException;
 import org.apache.stratos.cli.utils.CliConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-public class ListCartridgeSubscriptionsCommand implements Command<StratosCommandContext>{
-	
+public class ListCartridgeSubscriptionsCommand implements Command<StratosCommandContext> {
+
 	private static final Logger logger = LoggerFactory.getLogger(ListCartridgeSubscriptionsCommand.class);
 	
 	private final Options options;
-	
+
 	public ListCartridgeSubscriptionsCommand() {
 		options = constructOptions();
 	}
@@ -44,52 +48,72 @@ public class ListCartridgeSubscriptionsCommand implements Command<StratosCommand
 	 * @return Options expected from command-line.
 	 */
 	private Options constructOptions() {
-
 		final Options options = new Options();
+		Option fullOption = new Option(CliConstants.FULL_OPTION, CliConstants.FULL_LONG_OPTION, false,
+				"Display extra details");
+		options.addOption(fullOption);
 		return options;
 	}
-	
-	@Override
+
 	public String getName() {
 		return "list-cartridge-subscriptions";
 	}
 
-	@Override
 	public String getDescription() {
 		return "List cartridge subscriptions";
 	}
 
-	@Override
 	public String getArgumentSyntax() {
 		return null;
 	}
 
-	@Override
-	public Options getOptions() {
-		return options;
-	}
-
-	@Override
 	public int execute(StratosCommandContext context, String[] args) throws CommandException {
 		if (logger.isDebugEnabled()) {
 			logger.debug("Executing {} command...", getName());
 		}
-		
-		if (args != null && args.length > 0) {
-			String alias = args[0];
+		if (args == null || args.length == 0) {
+            RestCommandLineService.getInstance().listCartridgeSubscriptions(false);
+			//CommandLineService.getInstance().listCartridgeSubscriptions(false);
+			return CliConstants.COMMAND_SUCCESSFULL;
+		} else if (args != null && args.length > 0) {
+			String[] remainingArgs = null;
+			boolean full = false;
+			final CommandLineParser parser = new GnuParser();
+			CommandLine commandLine;
+			try {
+				commandLine = parser.parse(options, args);
+				remainingArgs = commandLine.getArgs();
+				if (!(remainingArgs == null || remainingArgs.length == 0)) {
+					context.getStratosApplication().printUsage(getName());
+					return CliConstants.COMMAND_FAILED;
+				}
 
-            if(StringUtils.isBlank(alias)){
-                System.out.println("Please specify a non blank alias");
-                return CliConstants.COMMAND_FAILED;
-            }
-            else{
-                RestCommandLineService.getInstance().listSubscribedCartridgeInfo(alias);
-                return CliConstants.COMMAND_SUCCESSFULL;
-            }
-		}else {
+				if (commandLine.hasOption(CliConstants.FULL_OPTION)) {
+					if (logger.isTraceEnabled()) {
+						logger.trace("Full option is passed");
+					}
+					full = true;
+				}
+				if (logger.isDebugEnabled()) {
+					logger.debug("Listing subscribed cartridges, Full Option: {}", full);
+				}
+                RestCommandLineService.getInstance().listCartridgeSubscriptions(full);
+				return CliConstants.COMMAND_SUCCESSFULL;
+			} catch (ParseException e) {
+				if (logger.isErrorEnabled()) {
+					logger.error("Error parsing arguments", e);
+				}
+				System.out.println(e.getMessage());
+				return CliConstants.COMMAND_FAILED;
+			}
+		} else {
 			context.getStratosApplication().printUsage(getName());
 			return CliConstants.COMMAND_FAILED;
 		}
 	}
 
+	public Options getOptions() {
+		return options;
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/10bee14e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgesCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgesCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgesCommand.java
index d1e9a8f..3492d76 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgesCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgesCommand.java
@@ -51,8 +51,7 @@ public class ListCartridgesCommand implements Command<StratosCommandContext> {
 			logger.debug("Executing {} command...", getName());
 		}
 		if (args == null || args.length == 0) {
-			//CommandLineService.getInstance().listAvailableCartridges();
-            RestCommandLineService.getInstance().listAvailableCartridges();
+            RestCommandLineService.getInstance().listCartridges();
 			return CliConstants.COMMAND_SUCCESSFULL;
 		} else {
 			context.getStratosApplication().printUsage(getName());

http://git-wip-us.apache.org/repos/asf/stratos/blob/10bee14e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPolicyCommand.java
index 16f09ae..752bcb5 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPolicyCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPolicyCommand.java
@@ -51,7 +51,6 @@ public class ListDeploymentPolicyCommand implements Command<StratosCommandContex
             logger.debug("Executing {} command...", getName());
         }
         if (args == null || args.length == 0) {
-            //CommandLineService.getInstance().listAvailableCartridges();
             RestCommandLineService.getInstance().listDeploymentPolicies();
             return CliConstants.COMMAND_SUCCESSFULL;
         } else {

http://git-wip-us.apache.org/repos/asf/stratos/blob/10bee14e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListSubscribedCartridgesCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListSubscribedCartridgesCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListSubscribedCartridgesCommand.java
deleted file mode 100644
index 0911c7d..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListSubscribedCartridgesCommand.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/**
- *  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.commands;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-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;
-import org.apache.stratos.cli.StratosCommandContext;
-import org.apache.stratos.cli.exception.CommandException;
-import org.apache.stratos.cli.utils.CliConstants;
-
-public class ListSubscribedCartridgesCommand implements Command<StratosCommandContext> {
-
-	private static final Logger logger = LoggerFactory.getLogger(ListSubscribedCartridgesCommand.class);
-	
-	private final Options options;
-
-	public ListSubscribedCartridgesCommand() {
-		options = constructOptions();
-	}
-	
-	/**
-	 * Construct Options.
-	 * 
-	 * @return Options expected from command-line.
-	 */
-	private Options constructOptions() {
-		final Options options = new Options();
-		Option fullOption = new Option(CliConstants.FULL_OPTION, CliConstants.FULL_LONG_OPTION, false,
-				"Display extra details");
-		options.addOption(fullOption);
-		return options;
-	}
-
-	public String getName() {
-		return CliConstants.LIST_ACTION;
-	}
-
-	public String getDescription() {
-		return "List subscribed cartridges with summarized details";
-	}
-
-	public String getArgumentSyntax() {
-		return null;
-	}
-
-	public int execute(StratosCommandContext context, String[] args) throws CommandException {
-		if (logger.isDebugEnabled()) {
-			logger.debug("Executing {} command...", getName());
-		}
-		if (args == null || args.length == 0) {
-            RestCommandLineService.getInstance().listSubscribedCartridges(false);
-			//CommandLineService.getInstance().listSubscribedCartridges(false);
-			return CliConstants.COMMAND_SUCCESSFULL;
-		} else if (args != null && args.length > 0) {
-			String[] remainingArgs = null;
-			boolean full = false;
-			final CommandLineParser parser = new GnuParser();
-			CommandLine commandLine;
-			try {
-				commandLine = parser.parse(options, args);
-				remainingArgs = commandLine.getArgs();
-				if (!(remainingArgs == null || remainingArgs.length == 0)) {
-					context.getStratosApplication().printUsage(getName());
-					return CliConstants.COMMAND_FAILED;
-				}
-
-				if (commandLine.hasOption(CliConstants.FULL_OPTION)) {
-					if (logger.isTraceEnabled()) {
-						logger.trace("Full option is passed");
-					}
-					full = true;
-				}
-				if (logger.isDebugEnabled()) {
-					logger.debug("Listing subscribed cartridges, Full Option: {}", full);
-				}
-                RestCommandLineService.getInstance().listSubscribedCartridges(full);
-				//CommandLineService.getInstance().listSubscribedCartridges(full);
-				return CliConstants.COMMAND_SUCCESSFULL;
-			} catch (ParseException e) {
-				if (logger.isErrorEnabled()) {
-					logger.error("Error parsing arguments", e);
-				}
-				System.out.println(e.getMessage());
-				return CliConstants.COMMAND_FAILED;
-			}
-		} else {
-			context.getStratosApplication().printUsage(getName());
-			return CliConstants.COMMAND_FAILED;
-		}
-	}
-
-	public Options getOptions() {
-		return options;
-	}
-
-}


Mime
View raw message