stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From saj...@apache.org
Subject [3/4] git commit: Fixing CLI issues listed in STRATOS-403. Introducing a new command to display cartrige info. Fixing STRATOS-398
Date Wed, 05 Feb 2014 05:55:01 GMT
Fixing CLI issues listed in STRATOS-403. Introducing a new command to display cartrige info.
Fixing STRATOS-398


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

Branch: refs/heads/master
Commit: e1c44b6d7146c255051d694ef7f4d8c5df64d5ab
Parents: 247a0e9
Author: Sajith Kariyawasam <sajith@wso2.com>
Authored: Wed Feb 5 11:20:43 2014 +0530
Committer: Sajith Kariyawasam <sajith@wso2.com>
Committed: Wed Feb 5 11:20:43 2014 +0530

----------------------------------------------------------------------
 .../stratos/cli/RestCommandLineService.java     |  96 ++++++++------
 .../apache/stratos/cli/StratosApplication.java  |   3 +
 .../stratos/cli/beans/cartridge/Cartridge.java  |  21 ++-
 .../cli/beans/cartridge/PortMapping.java        |  68 ++++++++++
 .../cli/commands/ListCartridgeInfoCommand.java  | 127 +++++++++++++++++++
 .../stratos/cli/commands/ListCommand.java       |   2 +-
 .../apache/stratos/cli/utils/CliConstants.java  |   5 +
 .../apache/stratos/manager/dto/Cartridge.java   |  18 ++-
 .../rest/endpoint/services/ServiceUtils.java    |  42 +++++-
 .../rest/endpoint/services/StratosAdmin.java    |   9 +-
 .../main/webapp/stratos/WEB-INF/cxf-servlet.xml |   2 +
 11 files changed, 341 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e1c44b6d/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 4077283..4b87d8b 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
@@ -35,6 +35,7 @@ import org.apache.stratos.cli.beans.autoscaler.policy.deployment.DeploymentPolic
 import org.apache.stratos.cli.beans.autoscaler.policy.autoscale.AutoscalePolicy;
 import org.apache.stratos.cli.beans.cartridge.Cartridge;
 import org.apache.stratos.cli.beans.cartridge.CartridgeInfoBean;
+import org.apache.stratos.cli.beans.cartridge.PortMapping;
 import org.apache.stratos.cli.beans.topology.Cluster;
 import org.apache.stratos.cli.beans.topology.Member;
 import org.apache.stratos.cli.exception.CommandException;
@@ -54,6 +55,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import jline.internal.Log;
@@ -347,9 +349,19 @@ public class RestCommandLineService {
                 System.out.println("Subscribe cartridge list is null");
                 return;
             }
+            
+            CartridgeList applicationCartridgeList = new CartridgeList();
+            
+            // Filter out LB cartridges
+            List<Cartridge> allCartridges = cartridgeList.getCartridge();
+            for (Cartridge cartridge : allCartridges) {
+				if(!cartridge.getProvider().equals("lb")){
+					applicationCartridgeList.getCartridge().add(cartridge);
+				}
+			}
 
-            Cartridge[] cartridges = new Cartridge[cartridgeList.getCartridge().size()];
-            cartridges = cartridgeList.getCartridge().toArray(cartridges);
+            Cartridge[] cartridges = new Cartridge[applicationCartridgeList.getCartridge().size()];
+            cartridges = applicationCartridgeList.getCartridge().toArray(cartridges);
 
             if (cartridges.length == 0) {
                 if (logger.isDebugEnabled()) {
@@ -375,6 +387,7 @@ public class RestCommandLineService {
                         data[8] = cartridge.getRepoURL() != null ? cartridge.getRepoURL()
: "";
                     }
                     return data;
+                	
                 }
             };
 
@@ -403,11 +416,11 @@ public class RestCommandLineService {
 
     
     // Lists subscribed cartridge info (from alias)
-    public void listSubscribedCartridgeInfo(final boolean full, String alias) throws CommandException
{
+    public void listSubscribedCartridgeInfo(String alias) throws CommandException {
         DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
             HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl()
+ listSubscribedCartridgeInfoRestEndpoint
-            		+"info/"+alias, restClientService.getUsername(), restClientService.getPassword());
+            		+alias, restClientService.getUsername(), restClientService.getPassword());
 
             String responseCode = "" + response.getStatusLine().getStatusCode();
             if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
@@ -419,21 +432,24 @@ public class RestCommandLineService {
 
             GsonBuilder gsonBuilder = new GsonBuilder();
             Gson gson = gsonBuilder.create();
-            Cartridge cartridge = gson.fromJson(resultString, Cartridge.class);
-
+            CartridgeList cartridgeList = gson.fromJson(resultString, CartridgeList.class);
+            Cartridge cartridge = cartridgeList.getCartridge().get(0);
             if (cartridge == null) {
                 System.out.println("Cartridge is null");
                 return;
             }
             // Get LB IP s
-            final Set<String> lbIpList = getLbIpList(cartridge, httpClient);
+            Map<String, Set<String>> lbIpMap = getLbIpList(cartridge, httpClient);
+            final Set<String> lbPrivateIpSet = lbIpMap.get("private");
+            final Set<String> lbFloatingIpSet = lbIpMap.get("floating");
             Cartridge[] cartridges = new Cartridge[1];
             cartridges[0] = cartridge;
 
             RowMapper<Cartridge> cartridgeMapper = new RowMapper<Cartridge>()
{
 
                 public String[] getData(Cartridge cartridge) {
-                    String[] data = full ? new String[10] : new String[7];
+                	
+                	String[] data = lbFloatingIpSet != null ? new String[13] : new String[12];
                     data[0] = cartridge.getCartridgeType();
                     data[1] = cartridge.getDisplayName();
                     data[2] = cartridge.getVersion();
@@ -441,11 +457,14 @@ public class RestCommandLineService {
                     data[4] = cartridge.getCartridgeAlias();
                     data[5] = cartridge.getStatus();
                     data[6] = cartridge.isMultiTenant() ? "N/A" : String.valueOf(cartridge.getActiveInstances());
-                    if (full) {
-                        data[7] = getAccessURLs(cartridge);
-                        data[8] = cartridge.getRepoURL() != null ? cartridge.getRepoURL()
: "";
-                    }
-                    data[9] = lbIpList.toString();
+                    data[7] = getAccessURLs(cartridge);
+                    data[8] = cartridge.getRepoURL() != null ? cartridge.getRepoURL() : "";
+                    data[9] = lbPrivateIpSet.toString();
+					if (lbFloatingIpSet != null) {
+						data[10] = lbFloatingIpSet.toString();
+					}
+					data[11] = cartridge.getDbUserName();
+					data[12] = cartridge.getPassword();
                     return data;
                 }
             };
@@ -458,15 +477,15 @@ public class RestCommandLineService {
             headers.add("Alias");
             headers.add("Status");
             headers.add("Running Instances");
-            if (full) {
-                headers.add("Access URL(s)");
-                headers.add("Repo URL");
-            }
-            headers.add("LoadBalancer Ip");
-            
-            
-            // Display Database info as well..
-            
+            headers.add("Access URL(s)");
+            headers.add("Repo URL");
+            headers.add("LB Private Ip");
+			if (lbFloatingIpSet != null) {
+				headers.add("LB Floating Ip");
+			}
+			headers.add("DB username");
+			headers.add("DB password");
+                        
             System.out.println("Subscribed Cartridges Info ************ : [TODO database
info]");
             CommandLineUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new
String[headers.size()]));
             System.out.println();
@@ -478,9 +497,11 @@ public class RestCommandLineService {
     }
     
     
-    private Set<String> getLbIpList(Cartridge cartridge, DefaultHttpClient httpClient)
{
+    private Map<String, Set<String>> getLbIpList(Cartridge cartridge, DefaultHttpClient
httpClient) {
     	
-    	Set<String> lbIpSet = new HashSet<String>();
+    	Map<String, Set<String>> privateFloatingLBIPMap = new HashMap<String,
Set<String>>();
+    	Set<String> lbFloatingIpSet = new HashSet<String>();
+    	Set<String> lbPrivateIpSet = new HashSet<String>();
     	Member[] members = getMembers(cartridge.getCartridgeType(), cartridge.getCartridgeAlias(),
httpClient);
     	
     	Set<String> lbClusterIdSet = new HashSet<String>();
@@ -507,11 +528,15 @@ public class RestCommandLineService {
             lbMembers = cluster.getMember().toArray(lbMembers);
            
             for (Member lbMember : lbMembers) {
-            	lbIpSet.add(lbMember.getMemberPublicIp());
+            	lbPrivateIpSet.add(lbMember.getMemberIp());
+            	lbFloatingIpSet.add(lbMember.getMemberPublicIp());
 			}
+            
 		}
+        privateFloatingLBIPMap.put("private", lbPrivateIpSet);
+        privateFloatingLBIPMap.put("floating", lbFloatingIpSet);
 
-		return lbIpSet;
+		return privateFloatingLBIPMap;
 	}
 
 	public void listMembersOfCluster(String cartridgeType, String alias) throws CommandException
{
@@ -1412,19 +1437,12 @@ public class RestCommandLineService {
 
     // This will return access url from a given cartridge
     private String getAccessURLs(Cartridge cartridge) {
-        String[] accessURLs = cartridge.getAccessURLs();
-        StringBuilder urlBuilder = new StringBuilder();
-        if (accessURLs != null) {
-            for (int i = 0; i < accessURLs.length; i++) {
-                String url = accessURLs[i];
-                if (url != null) {
-                    if (i > 0) {
-                        urlBuilder.append(", ");
-                    }
-                    urlBuilder.append(url);
-                }
-            }
-        }
+    	PortMapping[] portMappings = cartridge.getPortMappings();
+    	StringBuilder urlBuilder = new StringBuilder();
+    	for (PortMapping portMapping : portMappings) {
+			String url = portMapping.getProtocol()+"://"+ cartridge.getHostName() + ":" + portMapping.getProxyPort()
+ "/";
+			urlBuilder.append(url).append(",");
+		} 
         return urlBuilder.toString();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e1c44b6d/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 6e19c56..f0e2cf4 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
@@ -140,6 +140,9 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
 
         command = new DescribeAutoScalingPolicyCommand();
         commands.put(command.getName(), command);
+        
+        command = new ListCartridgeInfoCommand();
+        commands.put(command.getName(), command);
 		
 		//command = new AddDomainMappingCommand();
 		//commands.put(command.getName(), command);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e1c44b6d/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/Cartridge.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/Cartridge.java
b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/Cartridge.java
index 8bcc45e..976ee72 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/Cartridge.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/Cartridge.java
@@ -21,6 +21,7 @@ package org.apache.stratos.cli.beans.cartridge;
 
 import javax.xml.bind.annotation.XmlRootElement;
 
+
 @XmlRootElement
 public class Cartridge implements Comparable<Cartridge> {
 
@@ -41,8 +42,10 @@ public class Cartridge implements Comparable<Cartridge> {
     private String repoURL;
     private String dbUserName;
     private String mappedDomain;
+    private String dbHost;
 
     private String[] accessURLs;
+    private PortMapping[] portMappings;
 
     public String getDisplayName() {
         return displayName;
@@ -187,8 +190,24 @@ public class Cartridge implements Comparable<Cartridge> {
     public void setMappedDomain(String mappedDomain) {
         this.mappedDomain = mappedDomain;
     }
+    
+    public PortMapping[] getPortMappings() {
+		return portMappings;
+	}
+
+	public void setPortMappings(PortMapping[] portMappings) {
+		this.portMappings = portMappings;
+	}
+	
+	public String getDbHost() {
+		return dbHost;
+	}
+
+	public void setDbHost(String dbHost) {
+		this.dbHost = dbHost;
+	}
 
-    public int compareTo(Cartridge o) {
+	public int compareTo(Cartridge o) {
         int compare = 0;
         if (cartridgeAlias != null && o.cartridgeAlias != null) {
             compare = cartridgeAlias.compareTo(o.cartridgeAlias);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e1c44b6d/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/PortMapping.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/PortMapping.java
b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/PortMapping.java
new file mode 100644
index 0000000..136f22f
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/PortMapping.java
@@ -0,0 +1,68 @@
+/*
+ * 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.beans.cartridge;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class PortMapping {
+
+	private String protocol;
+	private String port;
+	private String proxyPort;
+	
+	public PortMapping(){
+		
+	}
+	
+	public PortMapping(String protocol, String port, String proxyPort){
+		this.protocol = protocol;
+		this.port = port;
+		this.proxyPort = proxyPort;
+	}
+
+	public String getProtocol() {
+    	return protocol;
+    }
+
+	public void setProtocol(String protocol) {
+    	this.protocol = protocol;
+    }
+
+	public String getPort() {
+    	return port;
+    }
+
+	public void setPort(String port) {
+    	this.port = port;
+    }
+
+	public String getProxyPort() {
+    	return proxyPort;
+    }
+
+	public void setProxyPort(String proxyPort) {
+    	this.proxyPort = proxyPort;
+    }
+
+    public String toString () {
+
+        return "Protocol: " + protocol + ", Port: " + port + ", Proxy Port: " + proxyPort;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e1c44b6d/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeInfoCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeInfoCommand.java
b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeInfoCommand.java
new file mode 100644
index 0000000..7a70a2a
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeInfoCommand.java
@@ -0,0 +1,127 @@
+/**
+ *  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.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 ListCartridgeInfoCommand implements Command<StratosCommandContext>{
+	
+	private static final Logger logger = LoggerFactory.getLogger(ListCartridgeInfoCommand.class);
+	
+	private final Options options;
+	
+	public ListCartridgeInfoCommand() {
+		options = constructOptions();
+	}
+	
+	/**
+	 * Construct Options.
+	 * 
+	 * @return Options expected from command-line.
+	 */
+	private Options constructOptions() {
+		final Options options = new Options();
+		
+        Option alias = new Option(CliConstants.ALIAS_OPTION, CliConstants.ALIAS_LONG_OPTION,
+                true, "subscription alias");
+        alias.setArgName("alias");
+        options.addOption(alias);
+		
+		return options;
+	}
+	
+	@Override
+	public String getName() {
+		return CliConstants.LIST_INFO_ACTION;
+	}
+
+	@Override
+	public String getDescription() {
+		return "List subscribed cartridges with details";
+	}
+
+	@Override
+	public String getArgumentSyntax() {
+		// TODO Auto-generated method stub
+		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 = null;
+
+			final CommandLineParser parser = new GnuParser();
+			CommandLine commandLine;
+			try {
+				commandLine = parser.parse(options, args);
+				if (logger.isDebugEnabled()) {
+					logger.debug("Executing {} command...", getName());
+				}
+                if (commandLine.hasOption(CliConstants.ALIAS_OPTION)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Cartridge alias option is passed");
+                    }
+                    alias = commandLine.getOptionValue(CliConstants.ALIAS_OPTION);
+                }
+
+                if (alias == null) {
+                    System.out.println("alias is required...");
+                    context.getStratosApplication().printUsage(getName());
+                    return CliConstants.BAD_ARGS_CODE;
+                }
+                RestCommandLineService.getInstance().listSubscribedCartridgeInfo(alias);
+
+				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;
+		}
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e1c44b6d/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCommand.java
b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCommand.java
index df265da..8f1b259 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCommand.java
@@ -60,7 +60,7 @@ public class ListCommand implements Command<StratosCommandContext>
{
 	}
 
 	public String getDescription() {
-		return "List subscribed cartridges with details";
+		return "List subscribed cartridges with summarized details";
 	}
 
 	public String getArgumentSyntax() {

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e1c44b6d/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 5ba8d88..40c7064 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
@@ -58,6 +58,11 @@ public class CliConstants {
 	 * List the subscribed cartridges
 	 */
 	public static final String LIST_ACTION = "list-subscribe-cartridges";
+	
+	/**
+	 * List the subscribed cartridges
+	 */
+	public static final String LIST_INFO_ACTION = "subscribe-cartridges-info";
 
 	/**
 	 * List the available cartridges

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e1c44b6d/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/dto/Cartridge.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/dto/Cartridge.java
b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/dto/Cartridge.java
index 7e6b44e..e435669 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/dto/Cartridge.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/dto/Cartridge.java
@@ -21,6 +21,8 @@ package org.apache.stratos.manager.dto;
 
 import javax.xml.bind.annotation.XmlRootElement;
 
+import org.apache.stratos.cloud.controller.pojo.PortMapping;
+
 @XmlRootElement
 public class Cartridge implements Comparable<Cartridge> {
 
@@ -28,7 +30,7 @@ public class Cartridge implements Comparable<Cartridge> {
     private String description;
 	private String cartridgeAlias;
 	private String cartridgeType;
-	//private int activeInstances;
+	private int activeInstances;
 	private String status;
 	//private String ip;
 	private String provider;
@@ -46,6 +48,7 @@ public class Cartridge implements Comparable<Cartridge> {
     private String password;
 
 	private String[] accessURLs;
+	private PortMapping[] portMappings;
 
 	public String getDisplayName() {
 		return displayName;
@@ -79,13 +82,13 @@ public class Cartridge implements Comparable<Cartridge> {
 		this.cartridgeType = cartridgeType;
 	}
 
-	/*public int getActiveInstances() {
+	public int getActiveInstances() {
 		return activeInstances;
 	}
 
 	public void setActiveInstances(int activeInstances) {
 		this.activeInstances = activeInstances;
-	}*/
+	}
 
 	public String getStatus() {
 		return status;
@@ -210,4 +213,13 @@ public class Cartridge implements Comparable<Cartridge> {
     public void setDbHost(String dbHost) {
         this.dbHost = dbHost;
     }
+
+	public PortMapping[] getPortMappings() {
+		return portMappings;
+	}
+
+	public void setPortMappings(PortMapping[] portMappings) {
+		this.portMappings = portMappings;
+	}
+    
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e1c44b6d/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
index 9436a0d..c16d49b 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
@@ -39,6 +39,7 @@ import org.apache.stratos.manager.utils.PersistenceManager;
 import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
 import org.apache.stratos.cloud.controller.pojo.Properties;
 import org.apache.stratos.messaging.domain.topology.Cluster;
+import org.apache.stratos.messaging.domain.topology.Member;
 import org.apache.stratos.messaging.util.Constants;
 import org.apache.stratos.rest.endpoint.bean.autoscaler.partition.Partition;
 import org.apache.stratos.rest.endpoint.bean.autoscaler.partition.PartitionGroup;
@@ -504,12 +505,27 @@ public class ServiceUtils {
             if (subscriptions != null && !subscriptions.isEmpty()) {
 
                 for (CartridgeSubscription subscription : subscriptions) {
-
+                	
                     if (!cartridgeMatches(subscription.getCartridgeInfo(), subscription,
searchPattern)) {
                         continue;
                     }
-
-                    cartridges.add(getCartridgeFromSubscription(subscription));
+                    Cartridge cartridge = getCartridgeFromSubscription(subscription);
+                    Cluster cluster = TopologyClusterInformationModel.getInstance().getCluster(ApplicationManagementUtil.getTenantId(configurationContext)
+                            ,cartridge.getCartridgeType(), cartridge.getCartridgeAlias());
+                    String cartridgeStatus = "Inactive";
+                    int activeMemberCount = 0;
+					if (cluster != null) {
+						Collection<Member> members = cluster.getMembers();
+						for (Member member : members) {
+							if (member.isActive()) {
+								cartridgeStatus = "Active";
+								activeMemberCount++;
+							}
+						}
+					}
+                    cartridge.setActiveInstances(activeMemberCount);
+					cartridge.setStatus(cartridgeStatus);
+                    cartridges.add(cartridge);
                 }
             } else {
                 if (log.isDebugEnabled()) {
@@ -533,9 +549,25 @@ public class ServiceUtils {
 
     
     static Cartridge getSubscription(String cartridgeAlias, ConfigurationContext configurationContext)
throws ADCException {
-    	return getCartridgeFromSubscription(cartridgeSubsciptionManager.getCartridgeSubscription(ApplicationManagementUtil.
+    	
+    	Cartridge cartridge =  getCartridgeFromSubscription(cartridgeSubsciptionManager.getCartridgeSubscription(ApplicationManagementUtil.
                     getTenantId(configurationContext), cartridgeAlias));
     	
+        Cluster cluster = TopologyClusterInformationModel.getInstance().getCluster(ApplicationManagementUtil.getTenantId(configurationContext)
+                ,cartridge.getCartridgeType(), cartridge.getCartridgeAlias());
+        String cartridgeStatus = "Inactive";
+        int activeMemberCount = 0;
+        Collection<Member> members = cluster.getMembers();
+        for (Member member : members) {
+			if(member.isActive()) {
+				cartridgeStatus = "Active";
+				activeMemberCount++;
+			}
+		}        
+        cartridge.setActiveInstances(activeMemberCount);
+		cartridge.setStatus(cartridgeStatus);
+		return cartridge;
+    	
     }
     
     private static Cartridge getCartridgeFromSubscription (CartridgeSubscription subscription)
throws ADCException {
@@ -562,7 +594,7 @@ public class ServiceUtils {
         }
 
         cartridge.setStatus(subscription.getSubscriptionStatus());
-
+        cartridge.setPortMappings(subscription.getCartridgeInfo().getPortMappings());
         return cartridge;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e1c44b6d/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
index 6223aae..c5cc172 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
@@ -68,7 +68,12 @@ public class StratosAdmin extends AbstractAdmin {
     @Context
     HttpServletRequest httpServletRequest;
 
-
+    @POST
+    @Path("/init")
+    public void initialize ()
+            throws RestAPIException {
+    	
+    }
     /*
     This method gets called by the client who are interested in using session mechanism to
authenticate themselves in
     subsequent calls. This method call get authenticated by the basic authenticator.
@@ -361,13 +366,11 @@ public class StratosAdmin extends AbstractAdmin {
     @Consumes("application/json")
     @AuthorizationAction("/permission/protected/manage/monitor/tenants")
     public Cluster getCluster(@PathParam("clusterId") String clusterId) throws ADCException
{
-    	log.info("--- clusterID -- " + clusterId);
     	Cluster cluster = null;
         Cluster[] clusters = ServiceUtils.getClustersForTenant(getConfigContext());
         for (Cluster clusterObj : clusters) {
 			if (clusterObj.clusterId.equals(clusterId)){
 				cluster = clusterObj;
-				log.info(" -- CLuster is returned -- ");
 				break;
 			}
 		}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e1c44b6d/components/org.apache.stratos.rest.endpoint/src/main/webapp/stratos/WEB-INF/cxf-servlet.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/webapp/stratos/WEB-INF/cxf-servlet.xml
b/components/org.apache.stratos.rest.endpoint/src/main/webapp/stratos/WEB-INF/cxf-servlet.xml
index 22a9ca3..65be7b5 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/webapp/stratos/WEB-INF/cxf-servlet.xml
+++ b/components/org.apache.stratos.rest.endpoint/src/main/webapp/stratos/WEB-INF/cxf-servlet.xml
@@ -66,6 +66,8 @@
                 <value>partition</value>
                 <value>member</value>
                 <value>hostNames</value>
+                <value>portMappings</value>
+                <value>cartridge</value>
             </list>
         </property>
     </bean>


Mime
View raw message