Repository: incubator-stratos
Updated Branches:
  refs/heads/master 4179bbe01 -> b0cf6bc8a


adding method to get active services


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

Branch: refs/heads/master
Commit: b0cf6bc8ad83e9b4e79811a482e55a79342a323e
Parents: 4179bbe
Author: rekathiru <[email protected]>
Authored: Wed Feb 19 17:00:48 2014 +0530
Committer: rekathiru <[email protected]>
Committed: Wed Feb 19 17:00:48 2014 +0530

----------------------------------------------------------------------
 .../rest/endpoint/services/ServiceUtils.java    | 52 +++++++++++++++++++-
 .../rest/endpoint/services/StratosAdmin.java    | 13 ++++-
 2 files changed, 62 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b0cf6bc8/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 3c3f580..bdfaa50 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
@@ -43,6 +43,7 @@ import org.apache.stratos.manager.utils.CartridgeConstants;
 import org.apache.stratos.messaging.domain.topology.Cluster;
 import org.apache.stratos.messaging.domain.topology.Member;
 import org.apache.stratos.messaging.domain.topology.MemberStatus;
+import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 import org.apache.stratos.messaging.util.Constants;
 import org.apache.stratos.rest.endpoint.bean.CartridgeInfoBean;
 import org.apache.stratos.rest.endpoint.bean.StratosAdminResponse;
@@ -432,8 +433,14 @@ public class ServiceUtils {
         return PojoConverter.populatePartitionGroupPojos(partitionGroups);
     }
 
-    static Cartridge getAvailableSingleTenantCartridgeInfo(String 
cartridgeType, Boolean multiTenant, ConfigurationContext configurationContext) 
throws RestAPIException {
-       List<Cartridge> cartridges = getAvailableCartridges(null, null, 
configurationContext);
+    static Cartridge getAvailableCartridgeInfo(String cartridgeType, Boolean 
multiTenant, ConfigurationContext configurationContext) throws RestAPIException 
{
+        List<Cartridge> cartridges;
+
+        if(multiTenant != null) {
+            cartridges = getAvailableCartridges(null, multiTenant, 
configurationContext);
+        } else {
+            cartridges = getAvailableCartridges(null, null, 
configurationContext);
+        }
         for(Cartridge cartridge : cartridges) {
             if(cartridge.getCartridgeType().equals(cartridgeType)) {
                 return cartridge;
@@ -608,6 +615,47 @@ public class ServiceUtils {
         return new ServiceDefinitionBean();
     }
 
+    public static List<Cartridge> getActiveDeployedServiceInformation 
(ConfigurationContext configurationContext) throws RestAPIException {
+
+        Collection<Service> services = null;
+
+        try {
+            services = serviceDeploymentManager.getServices();
+
+        } catch (ADCException e) {
+            String msg = "Error in getting deployed service cluster definition 
";
+            log.error(msg, e);
+            throw new RestAPIException(msg);
+        }
+
+        List<Cartridge> availableMultitenantCartridges = new 
ArrayList<Cartridge>();
+        int tenantId = 
ApplicationManagementUtil.getTenantId(configurationContext);
+        //getting the services for the tenantId
+        for(Service service : services) {
+            String tenantRange = service.getTenantRange();
+            if(tenantRange.equals(Constants.TENANT_RANGE_ALL)) {
+                //check whether any active instances found for this service in 
the Topology
+
+                Cluster cluster = 
TopologyManager.getTopology().getService(service.getType()).
+                                        getCluster(service.getClusterId());
+                boolean activeMemberFound = false;
+                for(Member member : cluster.getMembers()) {
+                    if(member.isActive()) {
+                        activeMemberFound = true;
+                        break;
+                    }
+                }
+                if(activeMemberFound) {
+                    
availableMultitenantCartridges.add(getAvailableCartridgeInfo(null, true, 
configurationContext));
+                }
+            } else {
+                //TODO have to check for the serivces which has correct tenant 
range
+            }
+        }
+
+        return availableMultitenantCartridges;
+    }
+
        static List<Cartridge> getSubscriptions (String cartridgeSearchString, 
ConfigurationContext configurationContext) throws RestAPIException {
 
         List<Cartridge> cartridges = new ArrayList<Cartridge>();

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b0cf6bc8/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 a9cfb53..072e258 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
@@ -327,7 +327,7 @@ public class StratosAdmin extends AbstractAdmin {
     @AuthorizationAction("/permission/protected/manage/monitor/tenants")
     public Cartridge 
getAvailableSingleTenantCartridgeInfo(@PathParam("cartridgeType") String 
cartridgeType)
                                             throws RestAPIException {
-        return 
ServiceUtils.getAvailableSingleTenantCartridgeInfo(cartridgeType, false, 
getConfigContext());
+        return ServiceUtils.getAvailableCartridgeInfo(cartridgeType, false, 
getConfigContext());
     }
 
     @GET
@@ -934,6 +934,17 @@ public class StratosAdmin extends AbstractAdmin {
         return ServiceUtils.getDeployedServiceInformation(serviceType);
     }
 
+    @GET
+    @Path("/service/active")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    public List<Cartridge> getActiveService()throws RestAPIException {
+
+        return 
ServiceUtils.getActiveDeployedServiceInformation(getConfigContext());
+    }
+
+
     @DELETE
     @Path("/service/definition/{serviceType}")
     @Produces("application/json")

Reply via email to