getapplicationinfo rest api
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/6804f41a Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/6804f41a Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/6804f41a Branch: refs/heads/4.0.0-grouping Commit: 6804f41ae45cf3d59a8216543cbecb8e14fb7aeb Parents: ca43f8d Author: Udara Liyanage <[email protected]> Authored: Mon Oct 20 17:43:39 2014 +0530 Committer: Udara Liyanage <[email protected]> Committed: Mon Oct 20 17:43:39 2014 +0530 ---------------------------------------------------------------------- .../autoscaler/monitor/group/GroupMonitor.java | 1 - .../rest/endpoint/bean/ApplicationBean.java | 6 ++++ .../stratos/rest/endpoint/bean/GroupBean.java | 31 ++++++++++++++++++-- .../rest/endpoint/bean/topology/Cluster.java | 2 +- .../rest/endpoint/services/ServiceUtils.java | 24 ++++++++++++++- .../rest/endpoint/services/StratosAdmin.java | 6 +++- 6 files changed, 63 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/6804f41a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java index 20dd003..5129e34 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java @@ -91,7 +91,6 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler log.error(e); } } else if (status1 == ClusterStatus.Inactive || status1 == GroupStatus.Inactive) { - //TODO if C1 depends on C2, then if C2 is in_active, then by getting killdepend as C1 and //TODO need to send in_active for c1. When C1 in_active receives, get dependent and //TODO check whether dependent in_active. Then kill c1. http://git-wip-us.apache.org/repos/asf/stratos/blob/6804f41a/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 024664b..dbcbe9c 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 @@ -1,16 +1,22 @@ package org.apache.stratos.rest.endpoint.bean; +import org.apache.stratos.rest.endpoint.bean.topology.Cluster; + +import javax.xml.bind.annotation.XmlRootElement; import java.util.ArrayList; import java.util.List; /** * Created by udara on 10/17/14. */ +@XmlRootElement(name="applications") public class ApplicationBean { 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>(); } public void addGroup(GroupBean groupBean) { this.groups.add(groupBean); http://git-wip-us.apache.org/repos/asf/stratos/blob/6804f41a/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 77736bd..b79265c 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 @@ -18,18 +18,43 @@ */ package org.apache.stratos.rest.endpoint.bean; +import org.apache.stratos.rest.endpoint.bean.topology.Cluster; + +import javax.xml.bind.annotation.XmlRootElement; import java.util.ArrayList; import java.util.List; +@XmlRootElement(name="groups") public class GroupBean { - List<GroupBean> subGroups = null; + private List<GroupBean> subGroups = null; + private List<Cluster> clusters = null; public String alias; public GroupBean(){ - this.subGroups = new ArrayList<GroupBean>(); + this.setClusters(new ArrayList<Cluster>()); + this.setSubGroups(new ArrayList<GroupBean>()); } public void addGroup(GroupBean groupBean){ - subGroups.add(groupBean); + getSubGroups().add(groupBean); + } + public void addCluster(Cluster cluster){ + getClusters().add(cluster); + } + + public List<GroupBean> getSubGroups() { + return subGroups; + } + + public void setSubGroups(List<GroupBean> subGroups) { + this.subGroups = subGroups; + } + + public List<Cluster> getClusters() { + return clusters; + } + + public void setClusters(List<Cluster> clusters) { + this.clusters = clusters; } } http://git-wip-us.apache.org/repos/asf/stratos/blob/6804f41a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/topology/Cluster.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/topology/Cluster.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/topology/Cluster.java index 6b8af54..f2e5d73 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/topology/Cluster.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/topology/Cluster.java @@ -21,7 +21,7 @@ package org.apache.stratos.rest.endpoint.bean.topology; import javax.xml.bind.annotation.XmlRootElement; import java.util.List; -@XmlRootElement +@XmlRootElement(name="clusters") public class Cluster { @Override http://git-wip-us.apache.org/repos/asf/stratos/blob/6804f41a/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 e29fb4c..ff357b6 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,6 +52,8 @@ 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; @@ -66,6 +68,7 @@ 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; @@ -1591,6 +1594,7 @@ public class ServiceUtils { ClusterDataHolder clusterDataHolder = entry.getValue(); String clusterId = clusterDataHolder.getClusterId(); Cluster topLevelCluster = TopologyManager.getTopology().getService(clusterDataHolder.getServiceType()).getCluster(clusterId); + applicationBean.clusters.add(toClusterBean(topLevelCluster)); } Collection<Group> groups = application.getGroups(); @@ -1600,18 +1604,30 @@ public class ServiceUtils { applicationBean.addGroup(groupBean); } TopologyManager.releaseReadLock(); - return null; + return applicationBean; } private static void setSubGroups(Group group, GroupBean groupBean) { Collection<Group> subgroups = group.getGroups(); + addClustersToGroupBean(group, groupBean); for(Group subGroup : subgroups){ GroupBean subGroupBean = toGroupBean(subGroup); + setSubGroups(subGroup, subGroupBean); groupBean.addGroup(subGroupBean); } } + private static void addClustersToGroupBean(Group group, GroupBean groupBean) { + Map<String, ClusterDataHolder> clustersDatamap = group.getClusterDataMap(); + for(Map.Entry<String, ClusterDataHolder> x : clustersDatamap.entrySet()){ + String alias = x.getKey(); + ClusterDataHolder clusterHolder = x.getValue(); + Cluster topLevelCluster = TopologyManager.getTopology().getService(clusterHolder.getServiceType()).getCluster(clusterHolder.getClusterId()); + groupBean.addCluster(toClusterBean(topLevelCluster)); + } + } + private static GroupBean toGroupBean(Group group) { GroupBean groupBean = new GroupBean(); groupBean.alias = group.getUniqueIdentifier(); @@ -1623,4 +1639,10 @@ public class ServiceUtils { 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/6804f41a/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 668f9d6..fe4a696 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 @@ -456,7 +456,11 @@ public class StratosAdmin extends AbstractAdmin { @AuthorizationAction("/permission/protected/manage/monitor/tenants") public Response getApplicationInfo(@PathParam("appId") String applicationId) throws RestAPIException { Object application = ServiceUtils.getApplicationInfo(applicationId, getConfigContext()); - return Response.status(Response.Status.NOT_FOUND).build(); + if(application == null) { + return Response.status(Response.Status.NOT_FOUND).build(); + }else{ + return Response.ok().entity(application).build(); + } } @GET
