stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ud...@apache.org
Subject [3/4] git commit: add more details to getapplicationinfo
Date Wed, 22 Oct 2014 08:26:49 GMT
add more details to getapplicationinfo


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

Branch: refs/heads/4.0.0-grouping
Commit: dda0db8b3e4c430a4b06b5165ca1a1462bfa83dd
Parents: 1763fea
Author: Udara Liyanage <udara@wso2.com>
Authored: Wed Oct 22 13:52:13 2014 +0530
Committer: Udara Liyanage <udara@wso2.com>
Committed: Wed Oct 22 13:52:13 2014 +0530

----------------------------------------------------------------------
 .../rest/endpoint/bean/ApplicationBean.java     | 30 +++++++-
 .../stratos/rest/endpoint/bean/GroupBean.java   | 28 +++++++-
 .../bean/util/converter/PojoConverter.java      | 34 ++++++++-
 .../rest/endpoint/services/ServiceUtils.java    | 75 +++++++++-----------
 .../rest/endpoint/services/StratosAdmin.java    |  3 +-
 5 files changed, 124 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/dda0db8b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/ApplicationBean.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/ApplicationBean.java
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/ApplicationBean.java
index dbcbe9c..eb90f3b 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/ApplicationBean.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/ApplicationBean.java
@@ -11,9 +11,13 @@ import java.util.List;
  */
 @XmlRootElement(name="applications")
 public class ApplicationBean {
+    private String id;
+    private String tenantDomain;
+    private String tenantAdminUsername;
     public List<GroupBean> groups = null;
     public List<Cluster> clusters = null;
-    public String id;
+
+
     public ApplicationBean(){
         this.groups = new ArrayList<GroupBean>();
         this.clusters = new ArrayList<Cluster>();
@@ -21,4 +25,28 @@ public class ApplicationBean {
     public void addGroup(GroupBean groupBean) {
         this.groups.add(groupBean);
     }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public void setTenantDomain(String tenantDomain) {
+        this.tenantDomain = tenantDomain;
+    }
+
+    public void setTenantAdminUsername(String tenantAdminUsername) {
+        this.tenantAdminUsername = tenantAdminUsername;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public String getTenantDomain() {
+        return tenantDomain;
+    }
+
+    public String getTenantAdminUsername() {
+        return tenantAdminUsername;
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/dda0db8b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/GroupBean.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/GroupBean.java
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/GroupBean.java
index b79265c..b86da10 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/GroupBean.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/GroupBean.java
@@ -28,7 +28,9 @@ import java.util.List;
 public class GroupBean {
     private List<GroupBean> subGroups = null;
     private List<Cluster> clusters = null;
-    public String alias;
+    private String alias;
+    private String deploymentPolicy;
+    private String autoScalingPolicy;
 
     public GroupBean(){
         this.setClusters(new ArrayList<Cluster>());
@@ -57,4 +59,28 @@ public class GroupBean {
     public void setClusters(List<Cluster> clusters) {
         this.clusters = clusters;
     }
+
+    public void setAlias(String alias) {
+        this.alias = alias;
+    }
+
+    public void setDeploymentPolicy(String deploymentPolicy) {
+        this.deploymentPolicy = deploymentPolicy;
+    }
+
+    public void setAutoScalingPolicy(String autoScalingPolicy) {
+        this.autoScalingPolicy = autoScalingPolicy;
+    }
+
+    public String getAlias() {
+        return alias;
+    }
+
+    public String getDeploymentPolicy() {
+        return deploymentPolicy;
+    }
+
+    public String getAutoScalingPolicy() {
+        return autoScalingPolicy;
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/dda0db8b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/converter/PojoConverter.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/converter/PojoConverter.java
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/converter/PojoConverter.java
index 3524bf4..5970415 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/converter/PojoConverter.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/converter/PojoConverter.java
@@ -19,8 +19,9 @@
 
 package org.apache.stratos.rest.endpoint.bean.util.converter;
 
-import org.apache.commons.logging.LogFactory;
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.cloud.controller.stub.pojo.*;
 import org.apache.stratos.cloud.controller.stub.pojo.application.*;
 import org.apache.stratos.manager.composite.application.beans.CompositeAppDefinition;
@@ -30,9 +31,12 @@ import org.apache.stratos.manager.composite.application.beans.SubscribableInfo;
 import org.apache.stratos.manager.deploy.service.Service;
 import org.apache.stratos.manager.grouping.definitions.DependencyDefinitions;
 import org.apache.stratos.manager.grouping.definitions.ServiceGroupDefinition;
-import org.apache.stratos.manager.grouping.definitions.StartupOrderDefinition;
 import org.apache.stratos.manager.subscription.SubscriptionDomain;
+import org.apache.stratos.messaging.domain.topology.Application;
 import org.apache.stratos.messaging.domain.topology.Cluster;
+import org.apache.stratos.messaging.domain.topology.Group;
+import org.apache.stratos.rest.endpoint.bean.ApplicationBean;
+import org.apache.stratos.rest.endpoint.bean.GroupBean;
 import org.apache.stratos.rest.endpoint.bean.autoscaler.partition.Partition;
 import org.apache.stratos.rest.endpoint.bean.autoscaler.partition.PartitionGroup;
 import org.apache.stratos.rest.endpoint.bean.autoscaler.policy.autoscale.*;
@@ -40,7 +44,6 @@ import org.apache.stratos.rest.endpoint.bean.autoscaler.policy.deployment.Deploy
 import org.apache.stratos.rest.endpoint.bean.cartridge.definition.*;
 import org.apache.stratos.rest.endpoint.bean.subscription.domain.SubscriptionDomainBean;
 import org.apache.stratos.rest.endpoint.bean.topology.Member;
-import org.apache.commons.logging.Log;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -788,6 +791,31 @@ public class PojoConverter {
         subscribableContext.setType(subscribableDefinition.getType());
         return subscribableContext;
     }
+
+    public static ApplicationBean applicationToBean(Application application) {
+
+        if(application == null){
+            return null;
+        }
+
+        ApplicationBean applicationBean = new ApplicationBean();
+        applicationBean.setId(application.getUniqueIdentifier());
+        applicationBean.setTenantDomain(application.getTenantDomain());
+        applicationBean.setTenantAdminUsername(application.getTenantAdminUserName());
+        return applicationBean;
+    }
+
+    public static GroupBean toGroupBean(Group group) {
+        if(group == null){
+            return null;
+        }
+
+        GroupBean groupBean = new GroupBean();
+        groupBean.setAlias(group.getUniqueIdentifier());
+        groupBean.setDeploymentPolicy(group.getDeploymentPolicy());
+        groupBean.setAutoScalingPolicy(group.getAutoscalingPolicy());
+        return groupBean;
+    }
 	
 	/*
 	public static ConfigCompositeApplication convertToCompositeApplication(CompositeApplicationDefinitionBean
appBean) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/dda0db8b/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 ff357b6..8c0ea6d 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
@@ -52,8 +52,6 @@ import org.apache.stratos.manager.topology.model.TopologyClusterInformationModel
 import org.apache.stratos.manager.utils.ApplicationManagementUtil;
 import org.apache.stratos.manager.utils.CartridgeConstants;
 import org.apache.stratos.messaging.domain.topology.*;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-import org.apache.stratos.messaging.domain.topology.Member;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 import org.apache.stratos.messaging.util.Constants;
 import org.apache.stratos.rest.endpoint.bean.ApplicationBean;
@@ -68,7 +66,6 @@ import org.apache.stratos.rest.endpoint.bean.cartridge.definition.PersistenceBea
 import org.apache.stratos.rest.endpoint.bean.cartridge.definition.ServiceDefinitionBean;
 import org.apache.stratos.rest.endpoint.bean.repositoryNotificationInfoBean.Payload;
 import org.apache.stratos.rest.endpoint.bean.subscription.domain.SubscriptionDomainBean;
-import org.apache.stratos.rest.endpoint.bean.topology.*;
 import org.apache.stratos.rest.endpoint.bean.util.converter.PojoConverter;
 import org.apache.stratos.rest.endpoint.exception.RestAPIException;
 
@@ -1582,28 +1579,43 @@ public class ServiceUtils {
         log.info("Successfully undeployed the Service Group Definition with name " + serviceGroupDefinitionName);
     }
 
-    public static Object getApplicationInfo(String applicationId, ConfigurationContext configContext)
{
+    public static ApplicationBean getApplicationInfo(String applicationId, ConfigurationContext
configContext) {
+        ApplicationBean applicationBean = null;
+        try{
+            TopologyManager.acquireReadLockForApplication(applicationId);
+            Application application = TopologyManager.getTopology().getApplication(applicationId);
+            if(application == null){
+                return null;
+            }
+            applicationBean = PojoConverter.applicationToBean(application);
 
-        TopologyManager.acquireReadLock();
-        Application application = TopologyManager.getTopology().getApplication(applicationId);
-        ApplicationBean applicationBean = applicationToBean(application);
+            Map<String, ClusterDataHolder> topLevelClusterDataMap  = application.getClusterDataMap();
+            for(Map.Entry<String, ClusterDataHolder> entry : topLevelClusterDataMap.entrySet()){
+                ClusterDataHolder clusterDataHolder = entry.getValue();
+                String clusterId = clusterDataHolder.getClusterId();
+                String serviceType = clusterDataHolder.getServiceType();
+                TopologyManager.acquireReadLockForCluster(serviceType, clusterId);
+                Cluster topLevelCluster;
 
-        Map<String, ClusterDataHolder> topLevelClusterDataMap  = application.getClusterDataMap();
-        for(Map.Entry<String, ClusterDataHolder> entry : topLevelClusterDataMap.entrySet()){
-            String alias = entry.getKey();
-            ClusterDataHolder clusterDataHolder = entry.getValue();
-            String clusterId = clusterDataHolder.getClusterId();
-            Cluster topLevelCluster = TopologyManager.getTopology().getService(clusterDataHolder.getServiceType()).getCluster(clusterId);
-            applicationBean.clusters.add(toClusterBean(topLevelCluster));
-        }
+                try {
+                    topLevelCluster = TopologyManager.getTopology().getService(serviceType).getCluster(clusterId);
+                }finally {
+                    TopologyManager.releaseReadLockForCluster(serviceType, clusterId);
+                }
+                applicationBean.clusters.add(PojoConverter.populateClusterPojos(topLevelCluster));
+            }
 
-        Collection<Group> groups = application.getGroups();
-        for(Group group :  groups){
-            GroupBean groupBean = toGroupBean(group);
-            setSubGroups(group, groupBean);
-            applicationBean.addGroup(groupBean);
+            Collection<Group> groups = application.getGroups();
+            for(Group group :  groups){
+                GroupBean groupBean = PojoConverter.toGroupBean(group);
+                setSubGroups(group, groupBean);
+                applicationBean.addGroup(groupBean);
+            }
+        }finally {
+            TopologyManager.releaseReadLockForApplication(applicationId);
         }
-        TopologyManager.releaseReadLock();
+
+
         return applicationBean;
     }
 
@@ -1611,7 +1623,7 @@ public class ServiceUtils {
         Collection<Group> subgroups = group.getGroups();
         addClustersToGroupBean(group, groupBean);
         for(Group subGroup : subgroups){
-            GroupBean subGroupBean = toGroupBean(subGroup);
+            GroupBean subGroupBean = PojoConverter.toGroupBean(subGroup);
 
             setSubGroups(subGroup, subGroupBean);
             groupBean.addGroup(subGroupBean);
@@ -1624,25 +1636,8 @@ public class ServiceUtils {
             String alias = x.getKey();
             ClusterDataHolder clusterHolder = x.getValue();
             Cluster topLevelCluster = TopologyManager.getTopology().getService(clusterHolder.getServiceType()).getCluster(clusterHolder.getClusterId());
-            groupBean.addCluster(toClusterBean(topLevelCluster));
+            groupBean.addCluster(PojoConverter.populateClusterPojos(topLevelCluster));
         }
     }
 
-    private static GroupBean toGroupBean(Group group) {
-        GroupBean groupBean = new GroupBean();
-        groupBean.alias = group.getUniqueIdentifier();
-        return groupBean;
-    }
-
-    private static ApplicationBean applicationToBean(Application application) {
-        ApplicationBean applicationBean = new ApplicationBean();
-        applicationBean.id = application.getUniqueIdentifier();
-        return applicationBean;
-    }
-
-    private static org.apache.stratos.rest.endpoint.bean.topology.Cluster toClusterBean(Cluster
cluster){
-        org.apache.stratos.rest.endpoint.bean.topology.Cluster clusterBean = new org.apache.stratos.rest.endpoint.bean.topology.Cluster();
-        clusterBean.serviceName=cluster.getServiceName();
-        return clusterBean;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/dda0db8b/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 fe4a696..45cae8b 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
@@ -37,6 +37,7 @@ import org.apache.stratos.rest.endpoint.ServiceHolder;
 import org.apache.stratos.rest.endpoint.Utils;
 import org.apache.stratos.rest.endpoint.annotation.AuthorizationAction;
 import org.apache.stratos.rest.endpoint.annotation.SuperTenantService;
+import org.apache.stratos.rest.endpoint.bean.ApplicationBean;
 import org.apache.stratos.rest.endpoint.bean.CartridgeInfoBean;
 import org.apache.stratos.rest.endpoint.bean.StratosAdminResponse;
 import org.apache.stratos.rest.endpoint.bean.SubscriptionDomainRequest;
@@ -455,7 +456,7 @@ public class StratosAdmin extends AbstractAdmin {
     @Consumes("application/json")
     @AuthorizationAction("/permission/protected/manage/monitor/tenants")
     public Response getApplicationInfo(@PathParam("appId") String applicationId) throws RestAPIException
{
-        Object application = ServiceUtils.getApplicationInfo(applicationId, getConfigContext());
+        ApplicationBean application = ServiceUtils.getApplicationInfo(applicationId, getConfigContext());
         if(application == null) {
             return Response.status(Response.Status.NOT_FOUND).build();
         }else{


Mime
View raw message