Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Bug 1337995 REST fetch of groups doesn't scale
Browse files Browse the repository at this point in the history
- Don't pull in all resources for every fetched group
- Avoid umbrella transaction
  • Loading branch information
jshaughn authored and Simeon Pinder committed Jun 24, 2016
1 parent 7121c20 commit 6c62a2d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Expand Up @@ -45,17 +45,10 @@
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;

import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.infinispan.Cache;
import org.infinispan.manager.CacheContainer;

import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.measurement.DataType;
import org.rhq.core.domain.measurement.MeasurementDefinition;
Expand All @@ -74,6 +67,12 @@
import org.rhq.enterprise.server.rest.domain.PagingCollection;
import org.rhq.enterprise.server.rest.domain.ResourceWithType;

import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.template.Template;
import freemarker.template.TemplateException;

/**
* Abstract base class for EJB classes that implement REST methods.
* For the cache and its eviction policies see standalone-full.xml (in
Expand Down Expand Up @@ -573,8 +572,14 @@ protected GroupRest fillGroup(ResourceGroup group, UriInfo uriInfo) {
if (group.getGroupDefinition()!=null) {
gr.setDynaGroupDefinitionId(group.getGroupDefinition().getId());
}
gr.setExplicitCount(group.getExplicitResources().size());
gr.setImplicitCount(group.getImplicitResources().size());
int expCount = resourceGroupManager.getExplicitGroupMemberCount(group.getId());
int impCount = expCount;
if (group.isRecursive() && expCount > 0) {
impCount = resourceGroupManager.getImplicitGroupMemberCount(group.getId());
}
gr.setExplicitCount(expCount);
gr.setImplicitCount(impCount);

UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
uriBuilder.path("/group/{id}");
URI uri = uriBuilder.build(group.getId());
Expand Down
Expand Up @@ -26,6 +26,8 @@

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.interceptor.Interceptors;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
Expand All @@ -44,18 +46,10 @@
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiError;
import com.wordnik.swagger.annotations.ApiErrors;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.jboss.resteasy.annotations.GZIP;
import org.jboss.resteasy.annotations.cache.Cache;

import org.rhq.core.domain.criteria.ResourceGroupCriteria;
import org.rhq.core.domain.criteria.ResourceGroupDefinitionCriteria;
import org.rhq.core.domain.measurement.DataType;
Expand Down Expand Up @@ -83,6 +77,12 @@
import org.rhq.enterprise.server.rest.domain.MetricSchedule;
import org.rhq.enterprise.server.rest.domain.ResourceWithType;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiError;
import com.wordnik.swagger.annotations.ApiErrors;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

/**
* Deal with group related things.
* @author Heiko W. Rupp
Expand All @@ -109,12 +109,14 @@ public class GroupHandlerBean extends AbstractRestBean {
@GET
@Path("/")
@ApiOperation(value = "List all groups", multiValueResponse = true, responseClass = "GroupRest")
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public Response getGroups(@ApiParam("String to search in the group name") @QueryParam("q") String q,
@ApiParam("Page size for paging") @QueryParam("ps") @DefaultValue("20") int pageSize,
@ApiParam("Page number for paging, 0-based") @QueryParam("page") Integer page,
@Context HttpHeaders headers, @Context UriInfo uriInfo) {

ResourceGroupCriteria criteria = new ResourceGroupCriteria();
criteria.fetchGroupDefinition(true);
criteria.addSortId(PageOrdering.ASC);

if (q!=null) {
Expand Down

0 comments on commit 6c62a2d

Please sign in to comment.