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:56 UTC

[04/21] git commit: RESTful add-tenant service implementations

RESTful add-tenant service implementations


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

Branch: refs/heads/master
Commit: 7bf4824ef16a0ad66976676e55039adfb919fd46
Parents: 309fa06
Author: Manula Thantriwatte <ma...@apache.org>
Authored: Fri Dec 6 18:35:31 2013 +0530
Committer: Manula Thantriwatte <ma...@apache.org>
Committed: Fri Dec 6 18:35:31 2013 +0530

----------------------------------------------------------------------
 .../apache/stratos/cli/CommandLineService.java  |  32 ++-
 .../java/org/apache/stratos/cli/RestClient.java |   7 +-
 .../stratos/cli/RestCommandLineService.java     |  60 +++---
 .../apache/stratos/cli/StratosApplication.java  |  15 +-
 .../org/apache/stratos/cli/TenantInfoBean.java  |  85 ++++++++
 .../apache/stratos/cli/WebClientWrapper.java    |  63 ++++++
 .../stratos/cli/commands/AddTenantCommand.java  | 193 +++++++++++++++++++
 .../stratos/cli/commands/SubscribeCommand.java  |   2 +-
 .../apache/stratos/cli/utils/CliConstants.java  |  20 ++
 9 files changed, 418 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7bf4824e/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 21eeb2c..286190a 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,16 +166,13 @@ 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;
 			}
 
@@ -212,10 +209,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);
@@ -226,18 +223,13 @@ public class CommandLineService {
 
 	public void listAvailableCartridges() throws CommandException {
 		try {
-            System.out.println("Custom called");
-            RestCommandLineService restService = new RestCommandLineService();
-            restService.listAvailableCartridges();
-            System.out.println("Custom end");
-
             Cartridge[] multiTenantCatridges = stub.getAvailableCartridges(true);
 
 			if (multiTenantCatridges == null) {
 				if (logger.isDebugEnabled()) {
 					logger.debug("No multi-tenant cartridges available");
 				}
-				//System.out.println("There are no multi-tenant cartridges available");
+				System.out.println("There are no multi-tenant cartridges available");
 			}
 
 			RowMapper<Cartridge> cartridgeMapper = new RowMapper<Cartridge>() {
@@ -252,9 +244,9 @@ public class CommandLineService {
 				}
 			};
 
-			//System.out.println("Available Multi-Tenant Cartridges:");
-			//CommandLineUtils.printTable(multiTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
-			//System.out.println();
+			System.out.println("Available Multi-Tenant Cartridges:");
+			CommandLineUtils.printTable(multiTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
+			System.out.println();
 			
 			Cartridge[] singleTenantCatridges = stub.getAvailableCartridges(false);
 
@@ -262,12 +254,12 @@ public class CommandLineService {
 				if (logger.isDebugEnabled()) {
 					logger.debug("No single-tenant cartridges available");
 				}
-				//System.out.println("There are no single-tenant cartridges available");
+				System.out.println("There are no single-tenant cartridges available");
 			}
 			
-			//System.out.println("Available Single-Tenant Cartridges:");
-			//CommandLineUtils.printTable(singleTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
-			//System.out.println();
+			System.out.println("Available Single-Tenant Cartridges:");
+			CommandLineUtils.printTable(singleTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
+			System.out.println();
 		} catch (ApplicationManagementServiceADCExceptionException e) {
 			handleException("cannot.list.available.cartridges", e);
 		} catch (RemoteException e) {

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7bf4824e/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 1fa273b..eadd031 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
@@ -56,10 +56,10 @@ public class RestClient implements GenericRestClient{
             String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
             postRequest.addHeader("Authorization", basicAuth);
 
+            httpClient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpClient);
             HttpResponse response = httpClient.execute(postRequest);
 
             if (response.getStatusLine().getStatusCode() != 200) {
-                System.out.println("Error");
                 throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
             }
 
@@ -67,9 +67,7 @@ public class RestClient implements GenericRestClient{
 
             String output;
             String result = "";
-            System.out.println("Output from Server .... \n");
             while ((output = br.readLine()) != null) {
-                //System.out.println(output);
                 result += output;
             }
 
@@ -95,6 +93,7 @@ public class RestClient implements GenericRestClient{
             String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
             getRequest.addHeader("Authorization", basicAuth);
 
+            httpClient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpClient);
             HttpResponse response = httpClient.execute(getRequest);
 
             if (response.getStatusLine().getStatusCode() != 200) {
@@ -105,9 +104,7 @@ public class RestClient implements GenericRestClient{
 
             String output;
             String result = "";
-            System.out.println("Output from Server .... \n");
             while ((output = br.readLine()) != null) {
-                //System.out.println(output);
                 result += output;
             }
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7bf4824e/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 a1b6c39..62d78d0 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
@@ -29,12 +29,9 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.stratos.cli.exception.CommandException;
 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;
 
@@ -46,10 +43,12 @@ public class RestCommandLineService {
 
     private RestClient restClientService;
 
-	RestCommandLineService() {
-	}
+    private final String listAvailableCartridgesRestEndpoint = "/stratos/admin/cartridge/list";
+    private final String listSubscribedCartridgesRestEndpoint = "/stratos/admin/cartridge/list/subscribed";
+    private final String subscribCartridgeRestEndpoint = "/stratos/admin/cartridge/subscribe";
+    private final String addTenantEndPoint = "/stratos/admin/tenant";
 
-	private static class SingletonHolder {
+    private static class SingletonHolder {
 		private final static RestCommandLineService INSTANCE = new RestCommandLineService();
 	}
 
@@ -59,7 +58,6 @@ public class RestCommandLineService {
 
     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
@@ -98,7 +96,6 @@ public class RestCommandLineService {
             throw new CommandException(e);
         }
 
-        System.out.println("End initialization, Login successfull");
         return true;
         /*
         try {
@@ -151,13 +148,15 @@ public class RestCommandLineService {
 
     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());
+            String resultString = restClientService.doGet(restClientService.getUrl() + listAvailableCartridgesRestEndpoint,
+                    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");
+                System.out.println("Available cartridge list is null");
             }
 
             CartridgeList multiTelentCartridgeList = new CartridgeList();
@@ -219,7 +218,6 @@ public class RestCommandLineService {
                 CommandLineUtils.printTable(cartridges1, cartridgeMapper, "Type", "Name", "Version");
                 System.out.println();
             }
-
         } catch (Exception e) {
                 e.printStackTrace();
         }
@@ -228,14 +226,15 @@ 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());
+            String resultString = restClientService.doGet(restClientService.getUrl() + listSubscribedCartridgesRestEndpoint,
+                    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");
+                System.out.println("Subscribe cartridge list is null");
             }
 
             Cartridge[] cartridges = new Cartridge[cartridgeList.getCartridge().size()];
@@ -282,11 +281,9 @@ public class RestCommandLineService {
                 headers.add("Repo URL");
             }
 
-            System.out.println("Subscribed Cartridges: 1");
+            System.out.println("Subscribed Cartridges:");
             CommandLineUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
-
             System.out.println();
-
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -309,10 +306,9 @@ public class RestCommandLineService {
 
         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)) {
@@ -320,8 +316,8 @@ public class RestCommandLineService {
                     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);
+                String subscription = restClientService.doPost(restClientService.getUrl() + subscribCartridgeRestEndpoint,
+                        completeJsonSubscribeString, restClientService.getUsername(), restClientService.getPassword());
                 subcriptionConnectInfo = gson.fromJson(subscription, SubscriptionInfo.class);
                 System.out.format("You have successfully subscribed to %s cartridge with alias %s.%n",
                         dataCartridgeType, dataCartridgeAlias);
@@ -334,9 +330,8 @@ public class RestCommandLineService {
 
         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());
+            String subscriptionOutput = restClientService.doPost(restClientService.getUrl() + subscribCartridgeRestEndpoint, 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);
 
@@ -373,6 +368,27 @@ public class RestCommandLineService {
         }
     }
 
+    public void addTenant(String admin, String firstName, String lastaName, String password, String domain, String email, String active) {
+        TenantInfoBean tenantInfo = new TenantInfoBean();
+        tenantInfo.setAdmin(admin);
+        tenantInfo.setFirstname(firstName);
+        tenantInfo.setLastname(lastaName);
+        tenantInfo.setAdminPassword(password);
+        tenantInfo.setTenantDomain(domain);
+        tenantInfo.setEmail(email);
+        tenantInfo.setActive(active);
+
+        GsonBuilder gsonBuilder = new GsonBuilder();
+        Gson gson = gsonBuilder.create();
+
+        String jsonString = gson.toJson(tenantInfo, TenantInfoBean.class);
+        String completeJsonString = "{\"tenantInfoBean\":" + jsonString + "}";
+
+        String result = restClientService.doPost(restClientService.getUrl() + addTenantEndPoint, completeJsonString, restClientService.getUsername(), restClientService.getPassword());
+
+        System.out.println(result);
+    }
+
     private class CartridgeList  {
         private ArrayList<Cartridge> cartridge;
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7bf4824e/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 abf7bb2..2d7cf30 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
@@ -40,19 +40,9 @@ import org.apache.commons.lang3.text.StrTokenizer;
 import org.apache.commons.validator.routines.UrlValidator;
 import org.apache.log4j.Level;
 import org.apache.log4j.LogManager;
+import org.apache.stratos.cli.commands.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.stratos.cli.commands.AddDomainMappingCommand;
-import org.apache.stratos.cli.commands.CartridgesCommand;
-import org.apache.stratos.cli.commands.ExitCommand;
-import org.apache.stratos.cli.commands.HelpCommand;
-import org.apache.stratos.cli.commands.InfoCommand;
-import org.apache.stratos.cli.commands.ListCommand;
-import org.apache.stratos.cli.commands.PoliciesCommand;
-import org.apache.stratos.cli.commands.RemoveDomainMappingCommand;
-import org.apache.stratos.cli.commands.SubscribeCommand;
-import org.apache.stratos.cli.commands.SyncCommand;
-import org.apache.stratos.cli.commands.UnsubscribeCommand;
 import org.apache.stratos.cli.completer.CommandCompleter;
 import org.apache.stratos.cli.exception.CommandException;
 import org.apache.stratos.cli.utils.CliConstants;
@@ -114,6 +104,9 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
 		
 		command = new CartridgesCommand();
 		commands.put(command.getName(), command);
+
+        command = new AddTenantCommand();
+        commands.put(command.getName(), command);
 		
 		command = new ListCommand();
 		commands.put(command.getName(), command);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7bf4824e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/TenantInfoBean.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/TenantInfoBean.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/TenantInfoBean.java
new file mode 100644
index 0000000..fe73749
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/TenantInfoBean.java
@@ -0,0 +1,85 @@
+/**
+ *  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;
+
+public class TenantInfoBean {
+    private String admin;
+    private String firstname;
+    private String lastname;
+    private String adminPassword;
+    private String tenantDomain;
+    private String email;
+    private String active;
+
+    public String getAdmin() {
+        return admin;
+    }
+
+    public void setAdmin(String admin) {
+        this.admin = admin;
+    }
+
+    public String getFirstname() {
+        return firstname;
+    }
+
+    public void setFirstname(String firstname) {
+        this.firstname = firstname;
+    }
+
+    public String getLastname() {
+        return lastname;
+    }
+
+    public void setLastname(String lastname) {
+        this.lastname = lastname;
+    }
+
+    public String getAdminPassword() {
+        return adminPassword;
+    }
+
+    public void setAdminPassword(String adminPassword) {
+        this.adminPassword = adminPassword;
+    }
+
+    public String getTenantDomain() {
+        return tenantDomain;
+    }
+
+    public void setTenantDomain(String tenantDomain) {
+        this.tenantDomain = tenantDomain;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    public String getActive() {
+        return active;
+    }
+
+    public void setActive(String active) {
+        this.active = active;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7bf4824e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/WebClientWrapper.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/WebClientWrapper.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/WebClientWrapper.java
new file mode 100644
index 0000000..20270ae
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/WebClientWrapper.java
@@ -0,0 +1,63 @@
+/**
+ *  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 java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.DefaultHttpClient;
+
+public class WebClientWrapper {
+
+    public static HttpClient wrapClient(HttpClient base) {
+        try {
+            SSLContext ctx = SSLContext.getInstance("TLS");
+            X509TrustManager tm = new X509TrustManager() {
+                public void checkClientTrusted(X509Certificate[] xcs,
+                                               String string) throws CertificateException {
+                }
+
+                public void checkServerTrusted(X509Certificate[] xcs,
+                                               String string) throws CertificateException {
+                }
+
+                public X509Certificate[] getAcceptedIssuers() {
+                    return null;
+                }
+            };
+            ctx.init(null, new TrustManager[] { tm }, null);
+            SSLSocketFactory ssf = new SSLSocketFactory(ctx);
+            ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+            ClientConnectionManager ccm = base.getConnectionManager();
+            SchemeRegistry sr = ccm.getSchemeRegistry();
+            sr.register(new Scheme("https", ssf, 443));
+            return new DefaultHttpClient(ccm, base.getParams());
+        } catch (Exception ex) {
+            return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7bf4824e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java
new file mode 100644
index 0000000..b92d901
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java
@@ -0,0 +1,193 @@
+/**
+ *  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.*;
+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;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.Option;
+
+public class AddTenantCommand implements Command<StratosCommandContext> {
+
+    private static final Logger logger = LoggerFactory.getLogger(AddTenantCommand.class);
+
+    private final Options options;
+
+    public AddTenantCommand(){
+        options = constructOptions();
+    }
+
+    private Options constructOptions() {
+        final Options options = new Options();
+
+        Option usernameOption = new Option(CliConstants.USERNAME_OPTION, CliConstants.USERNAME_LONG_OPTION, true,
+                "Tenant user name");
+        usernameOption.setArgName("username");
+        options.addOption(usernameOption);
+
+        Option fistnameOption = new Option(CliConstants.FIRST_NAME_OPTION, CliConstants.FIRST_NAME_LONG_OPTION, true,
+                "Tenant first name");
+        fistnameOption.setArgName("firstname");
+        options.addOption(fistnameOption);
+
+        Option lastnameOption = new Option(CliConstants.LAST_NAME_OPTION, CliConstants.LAST_NAME_LONG_OPTION, true,
+                "Tenant last name");
+        fistnameOption.setArgName("lastname");
+        options.addOption(lastnameOption);
+
+        Option passwordOption = new Option(CliConstants.PASSWORD_OPTION, CliConstants.PASSWORD_LONG_OPTION, true,
+                "Tenant password");
+        passwordOption.setArgName("password");
+        options.addOption(passwordOption);
+
+        Option domainOption = new Option(CliConstants.DOMAIN_NAME_OPTION, CliConstants.DOMAIN_NAME_LONG_OPTION, true,
+                "Tenant domain");
+        passwordOption.setArgName("domain");
+        options.addOption(domainOption);
+
+        Option emailOption = new Option(CliConstants.EMAIL_OPTION, CliConstants.EMAIL_LONG_OPTION, true,
+                "Tenant email");
+        passwordOption.setArgName("email");
+        options.addOption(emailOption);
+
+        Option acvive = new Option(CliConstants.ACTIVE_OPTION, CliConstants.ACTIVE_LONG_OPTION, true,
+                "Is tenant active");
+        passwordOption.setArgName("active");
+        options.addOption(acvive);
+
+        return options;
+    }
+
+    @Override
+    public String getName() {
+        return CliConstants.ADD_TENANT;
+    }
+
+    @Override
+    public String getDescription() {
+        return "Add new tenant";
+    }
+
+    @Override
+    public String getArgumentSyntax() {
+        return null;
+    }
+
+    @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 admin = null;
+            String firstName = null;
+            String lastaName = null;
+            String password = null;
+            String domain = null;
+            String email = null;
+            String active = null;
+
+            final CommandLineParser parser = new GnuParser();
+            CommandLine commandLine;
+
+            try {
+                commandLine = parser.parse(options, args);
+
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Add tenant");
+                }
+
+                if (commandLine.hasOption(CliConstants.USERNAME_OPTION)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Username option is passed");
+                    }
+                    admin = commandLine.getOptionValue(CliConstants.USERNAME_OPTION);
+                }
+                if (commandLine.hasOption(CliConstants.FIRST_NAME_OPTION)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("First name option is passed");
+                    }
+                    firstName = commandLine.getOptionValue(CliConstants.FIRST_NAME_OPTION);
+                }
+                if (commandLine.hasOption(CliConstants.LAST_NAME_OPTION)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Last name option is passed");
+                    }
+                    lastaName = commandLine.getOptionValue(CliConstants.LAST_NAME_OPTION);
+                }
+                if (commandLine.hasOption(CliConstants.PASSWORD_OPTION)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Password option is passed");
+                    }
+                    password = commandLine.getOptionValue(CliConstants.PASSWORD_OPTION);
+                }
+                if (commandLine.hasOption(CliConstants.DOMAIN_NAME_OPTION)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Domain name option is passed");
+                    }
+                    domain = commandLine.getOptionValue(CliConstants.DOMAIN_NAME_OPTION);
+                }
+                if (commandLine.hasOption(CliConstants.EMAIL_OPTION)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Email option is passed");
+                    }
+                    email = commandLine.getOptionValue(CliConstants.EMAIL_OPTION);
+
+                }
+                if (commandLine.hasOption(CliConstants.ACTIVE_OPTION)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Tenat active option is passed");
+                    }
+                    active = commandLine.getOptionValue(CliConstants.ACTIVE_OPTION);
+                }
+
+                if (admin == null || firstName == null || lastaName == null || password == null || domain == null || email == null || active == null) {
+                    System.out.println("usage: " + getName() + " [-u <user name>] [-f <first name>] [-l <last name>] [-p <password>] [-d <domain name>] [-e <email>] [-a <active/deactivate>]");
+                    return CliConstants.BAD_ARGS_CODE;
+                }
+
+                RestCommandLineService.getInstance().addTenant(admin, firstName, lastaName, password, domain, email, active);
+                return CliConstants.SUCCESSFUL_CODE;
+
+            } catch (ParseException e) {
+                if (logger.isErrorEnabled()) {
+                    logger.error("Error parsing arguments", e);
+                }
+                System.out.println(e.getMessage());
+                return CliConstants.BAD_ARGS_CODE;
+            }
+
+        } else {
+            context.getStratosApplication().printUsage(getName());
+            return CliConstants.BAD_ARGS_CODE;
+        }
+    }
+
+    @Override
+    public Options getOptions() {
+        return options;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7bf4824e/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 e867501..f9e8d66 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
@@ -38,7 +38,7 @@ public class SubscribeCommand implements Command<StratosCommandContext> {
 
 	private static final Logger logger = LoggerFactory.getLogger(ListCommand.class);
 
-	private final Options options;;
+	private final Options options;
 
 	public SubscribeCommand() {
 		options = constructOptions();

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7bf4824e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
index a7e91ac..3176c63 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
@@ -64,6 +64,11 @@ public class CliConstants {
 	 */
 	public static final String CARTRIDGES_ACTION = "cartridges";
 
+    /**
+     * Add tenant
+     */
+    public static final String ADD_TENANT = "add-tenant";
+
 	/**
 	 * Give information of a cartridge.
 	 */
@@ -127,4 +132,19 @@ public class CliConstants {
 	
 	public static final String DEBUG_OPTION = "debug";
 
+    // Add tenant options
+    public static final String FIRST_NAME_OPTION = "f";
+    public static final String FIRST_NAME_LONG_OPTION = "first-name";
+
+    public static final String LAST_NAME_OPTION = "l";
+    public static final String LAST_NAME_LONG_OPTION = "last-name";
+
+    public static final String DOMAIN_NAME_OPTION = "d";
+    public static final String DOMAIN_NAME_LONG_OPTION = "domain-name";
+
+    public static final String EMAIL_OPTION = "e";
+    public static final String EMAIL_LONG_OPTION = "email";
+
+    public static final String ACTIVE_OPTION = "a";
+    public static final String ACTIVE_LONG_OPTION = "active";
 }