private List<AutoGroupComposite> getResourceChildren(Resource resource, Subject subject) {
    ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
    List<AutoGroupComposite> children =
        resourceManager.findChildrenAutoGroups(subject, resource.getId());

    AutoGroupComposite resourceGroupComposite =
        resourceManager.getResourceAutoGroup(subject, resource.getId());
    if (resourceGroupComposite != null) resourceGroupComposite.setMainResource(true);
    else return new ArrayList<AutoGroupComposite>();

    // now increase everyone's depth by one to account for the resource
    for (AutoGroupComposite child : children) {
      child.setDepth(child.getDepth() + 1);
    }

    children.add(0, resourceGroupComposite);

    Resource parentResource = resourceManager.getParentResource(resource.getId());
    AutoGroupComposite parentGroupComposite = null;
    if (parentResource != null) {
      parentGroupComposite = resourceManager.getResourceAutoGroup(subject, parentResource.getId());
    }

    if (parentGroupComposite != null) {
      // now increase everyone's depth by one to account for the parent
      for (AutoGroupComposite child : children) {
        child.increaseDepth(1);
      }

      children.add(0, parentGroupComposite);
    }

    return children;
  }
示例#2
0
  /**
   * Returns true if any of the condition sets match an inventoried Resource.
   *
   * @param context
   * @return
   */
  public boolean isActive(GlobalActivationContext context) {
    ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
    Subject subject = context.getSubject();

    for (ResourceConditionSet rcs : this.resourceConditionSets) {
      ResourceCriteria criteria = new ResourceCriteria();

      criteria.addFilterPluginName(rcs.getPluginName());
      criteria.addFilterResourceTypeName(rcs.getResourceTypeName());
      Set<Permission> requiredPermissions = rcs.getPermissions();
      if (!((null == requiredPermissions) || requiredPermissions.isEmpty())) {
        Permission[] arr = requiredPermissions.toArray(new Permission[requiredPermissions.size()]);
        criteria.addRequiredPermissions(arr);
      }

      PageList<Resource> resources =
          resourceManager.findResourcesByCriteria(context.getSubject(), criteria);
      if (!((null == resources) || resources.isEmpty())) {
        return ActivatorHelper.areTraitsSatisfied(
            subject, rcs.getTraitMatchers(), resources, false);
      }
    }

    return false;
  }
 @Override
 public Set<Resource> getResources(Set<Integer> resourceIds, boolean includeDescendants) {
   long start = System.currentTimeMillis();
   ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
   Set<Resource> resources = new HashSet<Resource>();
   for (Integer resourceId : resourceIds) {
     Resource resource = resourceManager.getResourceTree(resourceId, includeDescendants);
     if (isVisibleInInventory(resource)) {
       resource = convertToPojoResource(resource, includeDescendants);
       cleanoutResource(resource);
       resources.add(resource);
     }
   }
   if (log.isDebugEnabled()) {
     log.debug(
         "Performance: get Resources ["
             + resourceIds
             + "], recursive="
             + includeDescendants
             + ", timing ("
             + (System.currentTimeMillis() - start)
             + ")ms");
   }
   return resources;
 }
  /**
   * Encode the beginning of the given {@link ResourceLineageComponent}.
   *
   * @param facesContext the JSF context for the current request
   * @param component the {@link ResourceLineageComponent} to be encoded
   */
  @Override
  public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
    ResourceLineageComponent resourceLineage = (ResourceLineageComponent) component;
    ResponseWriter writer = facesContext.getResponseWriter();
    long monitorId = HibernatePerformanceMonitor.get().start();
    ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
    List<Resource> ancestorResources =
        resourceManager.getResourceLineage(resourceLineage.getResourceId());
    HibernatePerformanceMonitor.get().stop(monitorId, "ResourceLineage renderer");
    if (ancestorResources.isEmpty()) {
      throw new IllegalStateException(
          "The list of ancestor resources should always contain at least one resource - the resource whose lineage was requested.");
    }

    Resource parentResource = ancestorResources.get(ancestorResources.size() - 1);
    for (Resource ancestorResource : ancestorResources) {
      writer.startElement("a", resourceLineage);
      writer.writeAttribute("href", buildURL(ancestorResource), null);
      writer.writeText(ancestorResource.getName(), null);
      writer.endElement("a");
      if (ancestorResource.getId()
          != parentResource.getId()) // separator after every item except the last one
      {
        writer.writeText(SEPARATOR, null);
      }
    }
  }
    public PageList<Resource> fetchDataForPage(PageControl pc) {
      Subject subject = EnterpriseFacesContextUtility.getSubject();
      ResourceManagerLocal manager = LookupUtil.getResourceManager();
      int repoId = Integer.parseInt(FacesContextUtility.getRequiredRequestParameter("id"));
      String search =
          FacesContextUtility.getOptionalRequestParameter(
              "repoUnsubscriptionsListForm:searchStringFilter");
      String category =
          FacesContextUtility.getOptionalRequestParameter(
              "repoUnsubscriptionsListForm:searchCategoryFilter");
      ResourceCategory categoryEnum = ResourceCategory.PLATFORM;

      if (search != null && search.trim().equals("")) {
        search = null;
      }

      if (category != null) {
        categoryEnum = ResourceCategory.valueOf(category);
      }

      PageList<Resource> results =
          manager.findAvailableResourcesForRepo(subject, repoId, search, categoryEnum, pc);

      // PageList<ResourceComposite> results = manager.findResourceComposites(subject, categoryEnum,
      // null, null, search, pc);

      return results;
    }
  protected void setResource(HttpServletRequest request, boolean config) throws Exception {
    try {
      Subject subject = WebUtility.getSubject(request);
      Integer resourceTypeId =
          WebUtility.getOptionalIntRequestParameter(
              request, ParamConstants.RESOURCE_TYPE_ID_PARAM, -1);
      int groupId = WebUtility.getOptionalIntRequestParameter(request, AttrConstants.GROUP_ID, -1);
      int parent = WebUtility.getOptionalIntRequestParameter(request, "parent", -1);
      String[] r = request.getParameterValues("r");
      String[] resourceIds = request.getParameterValues("resourceIds");

      // TODO rewrite the selection using WebUtility.getMetricsDisplayMode()
      if ((resourceTypeId > 0) && (parent > 0)) // autogroup
      {
        ResourceTypeManagerLocal resourceTypeManager = LookupUtil.getResourceTypeManager();
        ResourceType resourceType =
            resourceTypeManager.getResourceTypeById(subject, resourceTypeId);
        request.setAttribute(AttrConstants.RESOURCE_TYPE_ATTR, resourceType);
        request.setAttribute(AttrConstants.TITLE_PARAM_ATTR, resourceType.getName());
        request.setAttribute("parent", parent);
        request.setAttribute(ParamConstants.RESOURCE_TYPE_ID_PARAM, resourceTypeId);
        if (log.isDebugEnabled()) {
          log.debug("Autogroup p=" + parent + ", ct=" + resourceTypeId);
        }
      } else if (groupId > 0) // compat (or mixed) group
      {
        ResourceGroupManagerLocal resourceGroupManager = LookupUtil.getResourceGroupManager();
        ResourceGroup group = resourceGroupManager.getResourceGroupById(subject, groupId, null);
        request.setAttribute(AttrConstants.GROUP_ID, groupId);
        request.setAttribute(AttrConstants.TITLE_PARAM_ATTR, group.getName());
        // TODO more ?
      } else if ((resourceTypeId > 0) && (parent == -1)) // MeasurementDefinition
      {
        ResourceTypeManagerLocal resourceTypeManager = LookupUtil.getResourceTypeManager();
        ResourceType resourceType =
            resourceTypeManager.getResourceTypeById(subject, resourceTypeId);
        request.setAttribute(AttrConstants.RESOURCE_TYPE_ATTR, resourceType);
        request.setAttribute(ParamConstants.RESOURCE_TYPE_ID_PARAM, resourceTypeId);
      } else if ((r != null) && (r.length > 0)) // multiple scathered resources
      {
        log.trace("Multiple resources not handled yet"); // TODO what do we do here?
      } else if ((resourceIds != null) && (resourceIds.length > 0)) {
        log.trace("Multiple resources not yet handled"); // TODO what to we do here?
      } else // single resource
      {
        Integer resourceId =
            WebUtility.getRequiredIntRequestParameter(request, ParamConstants.RESOURCE_ID_PARAM);
        ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
        Resource resource = resourceManager.getResourceById(subject, resourceId);
        ResourceUIBean resourceUIBean = new ResourceUIBean(resource, subject);
        request.setAttribute(AttrConstants.RESOURCE_ATTR, resource);
        request.setAttribute(AttrConstants.RESOURCE_ID_ATTR, resourceId);
        request.setAttribute(AttrConstants.TITLE_PARAM_ATTR, resource.getName());
        request.setAttribute(
            AttrConstants.PERFORMANCE_SUPPORTED_ATTR, resourceUIBean.getFacets().isCallTime());
      }
    } catch (ResourceNotFoundException e) {
      RequestUtils.setError(request, MessageConstants.ERR_RESOURCE_NOT_FOUND);
    }
  }
  /** Get a list of the individual 'child resources' of that autogroup. */
  private List<AutoGroupComposite> getAutoGroupChildren(
      Subject subject, int parentId, int resourceTypeId) {
    List<AutoGroupComposite> children = new ArrayList<AutoGroupComposite>();
    ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
    ResourceTypeManagerLocal resourceTypeMananger = LookupUtil.getResourceTypeManager();
    Resource parentResource = resourceManager.getResourceById(subject, parentId);
    ResourceType resourceType = null;
    try {
      resourceType = resourceTypeMananger.getResourceTypeById(subject, resourceTypeId);
    } catch (ResourceTypeNotFoundException e) {
      return children; // empty list if we don't know the child type
    }

    if ((resourceType != null) && (parentResource != null)) {

      // first get the resources in the autogroup
      List<ResourceWithAvailability> resourcesForAutoGroup =
          resourceManager.findResourcesByParentAndType(subject, parentResource, resourceType);

      int i = 0;
      int[] resourceIds = new int[resourcesForAutoGroup.size()];
      for (ResourceWithAvailability resourceInAutoGroup : resourcesForAutoGroup) {
        int id = resourceInAutoGroup.getResource().getId();
        resourceIds[i++] = id;
      }

      // And then the composite to return
      List<AutoGroupComposite> composites =
          resourceManager.findResourcesAutoGroups(subject, resourceIds);

      return composites;
    }

    return children; // empty
  }
 @Override
 public void setResourceEnablement(int resourceId, boolean setEnabled) {
   ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
   Subject overlord = LookupUtil.getSubjectManager().getOverlord();
   if (setEnabled) {
     resourceManager.enableResources(overlord, new int[] {resourceId});
   } else {
     resourceManager.disableResources(overlord, new int[] {resourceId});
   }
 }
 @Override
 public void setResourceError(ResourceError resourceError) {
   try {
     ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
     resourceManager.addResourceError(resourceError);
   } catch (RuntimeException re) {
     log.error("Failed to persist Resource error [" + resourceError + "].", re);
     throw re;
   }
 }
 @Override
 public Map<Integer, InventoryStatus> getInventoryStatus(int rootResourceId, boolean descendents) {
   long start = System.currentTimeMillis();
   ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
   Map<Integer, InventoryStatus> statuses =
       resourceManager.getResourceStatuses(rootResourceId, descendents);
   if (log.isDebugEnabled()) {
     log.debug(
         "Performance: get inventory statuses for ["
             + statuses.size()
             + "] timing ("
             + (System.currentTimeMillis() - start)
             + ")ms");
   }
   return statuses;
 }
  private MeasurementBaseline calculateBaselineForGroup(
      int groupId,
      int definitionId,
      boolean userEntered,
      long startDate,
      long endDate,
      boolean save)
      throws DataNotAvailableException, BaselineCreationException {

    MeasurementAggregate agg =
        dataManager.getAggregate(
            subjectManager.getOverlord(), groupId, definitionId, startDate, endDate);

    Subject overlord = subjectManager.getOverlord();
    List<Integer> resourceIds = resourceManager.findImplicitResourceIdsByResourceGroup(groupId);
    List<MeasurementSchedule> schedules =
        measurementScheduleManager.findSchedulesByResourceIdsAndDefinitionId(
            overlord, ArrayUtils.unwrapCollection(resourceIds), definitionId);

    MeasurementBaseline baseline = null;
    for (MeasurementSchedule schedule : schedules) {
      // attach the entity, so we can find the baseline
      schedule = entityManager.merge(schedule);

      if (save && (schedule.getBaseline() != null)) {
        /*
         * If saving, make sure we're updating the existing one, if it exists
         */
        baseline = schedule.getBaseline();
      } else {
        /*
         * Otherwise, if we're not saving or if the the schedule doesn't have a current baseline, we create a new
         * baseline object
         */
        baseline = new MeasurementBaseline();

        if (save) {
          /*
           * But, if we *are* in save mode, then set the relationship so when we merge the schedule below it
           * persists this new baseline too
           */
          baseline.setSchedule(schedule);
        }
      }

      baseline.setUserEntered(userEntered);
      baseline.setMean(agg.getAvg());
      baseline.setMin(agg.getMin());
      baseline.setMax(agg.getMax());

      if (save) {
        entityManager.persist(baseline);
        entityManager.merge(schedule);
      }
    }

    // all baselines should be the same
    return baseline;
  }
示例#12
0
  private void deleteNewResource(Resource resource) throws Exception {
    if (null != resource) {
      EntityManager em = null;

      try {
        ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();

        // invoke bulk delete on the resource to remove any dependencies not defined in the
        // hibernate entity model
        // perform in-band and out-of-band work in quick succession
        List<Integer> deletedIds = resourceManager.uninventoryResource(overlord, resource.getId());
        for (Integer deletedResourceId : deletedIds) {
          resourceManager.uninventoryResourceAsyncWork(overlord, deletedResourceId);
        }

        // now dispose of other hibernate entities
        getTransactionManager().begin();
        em = getEntityManager();

        ResourceType type = em.find(ResourceType.class, resource.getResourceType().getId());
        Agent agent = em.find(Agent.class, resource.getAgent().getId());
        if (null != agent) {
          em.remove(agent);
        }
        if (null != type) {
          em.remove(type);
        }

        getTransactionManager().commit();
      } catch (Exception e) {
        try {
          System.out.println(
              "CANNOT CLEAN UP TEST (" + this.getClass().getSimpleName() + ") Cause: " + e);
          getTransactionManager().rollback();
        } catch (Exception ignore) {
        }
      } finally {
        if (null != em) {
          em.close();
        }
      }
    }
  }
  private void loadTree() {
    int searchId;
    Resource currentResource = EnterpriseFacesContextUtility.getResourceIfExists();
    if (currentResource == null) {
      searchId = Integer.parseInt(FacesContextUtility.getOptionalRequestParameter("parent"));
    } else {
      searchId = currentResource.getId();
    }

    Subject user = EnterpriseFacesContextUtility.getSubject();

    long start = System.currentTimeMillis();
    long monitorId = HibernatePerformanceMonitor.get().start();
    Resource rootResource = resourceManager.getRootResourceForResource(searchId);
    long end = System.currentTimeMillis();
    HibernatePerformanceMonitor.get().stop(monitorId, "ResourceTree root resource");
    log.debug("Found root resource in " + (end - start));

    Agent agent =
        agentManager.getAgentByResourceId(
            LookupUtil.getSubjectManager().getOverlord(), rootResource.getId());

    start = System.currentTimeMillis();
    monitorId = HibernatePerformanceMonitor.get().start();
    List<ResourceFlyweight> resources =
        resourceManager.findResourcesByAgent(
            user, agent.getId(), PageControl.getUnlimitedInstance());
    end = System.currentTimeMillis();
    HibernatePerformanceMonitor.get().stop(monitorId, "ResourceTree agent resource");
    log.debug("Loaded " + resources.size() + " raw resources in " + (end - start));

    start = System.currentTimeMillis();
    monitorId = HibernatePerformanceMonitor.get().start();
    rootNode = load(rootResource.getId(), resources);
    end = System.currentTimeMillis();
    HibernatePerformanceMonitor.get().stop(monitorId, "ResourceTree tree construction");
    log.debug("Constructed tree in " + (end - start));
  }
  private Resource getPlatform(String hostname) {
    ResourceCriteria criteria = new ResourceCriteria();
    criteria.setFiltersOptional(true);
    criteria.addFilterResourceKey(hostname);
    criteria.addFilterName(hostname);
    criteria.addFilterResourceCategories(ResourceCategory.PLATFORM);
    criteria.fetchResourceType(true);
    criteria.fetchExplicitGroups(true);

    ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
    PageList<Resource> resources = resourceManager.findResourcesByCriteria(overlord, criteria);

    if (resources.isEmpty()) {
      String msg =
          "Could not find platform with hostname "
              + hostname
              + ". The value that you specify for the "
              + "host argument should match either a platform's resource name and/or its resource key.";
      throw new ResourceNotFoundException(msg);
    }

    return resources.get(0);
  }
  @Override
  public List<Resource> getResourcesAsList(Integer... resourceIds) {
    long start = System.currentTimeMillis();

    ResourceCriteria criteria = new ResourceCriteria();
    // get all of the resources for the supplied ids
    criteria.addFilterIds(resourceIds);
    // filter out any that are not actually in inventory
    criteria.addFilterInventoryStatuses(
        new ArrayList<InventoryStatus>(InventoryStatus.getInInventorySet()));
    // get all of them, don't limit to default paging
    criteria.clearPaging();
    criteria.fetchResourceType(true);
    criteria.fetchPluginConfiguration(true);

    ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
    Subject overlord = LookupUtil.getSubjectManager().getOverlord();
    List<Resource> result = resourceManager.findResourcesByCriteria(overlord, criteria);

    if (log.isDebugEnabled()) {
      log.debug(
          "Performance: get ResourcesAsList ["
              + resourceIds
              + "], timing ("
              + (System.currentTimeMillis() - start)
              + ")ms");
    }

    // Now do some clean out of stuff the agent does not need
    // Perhaps we should limit the query above to only return relevant stuff

    for (Resource resource : result) {
      cleanoutResource(resource);
    }

    return result;
  }
示例#16
0
  @Test(enabled = ENABLE_TESTS)
  public void testDriftDef() throws Exception {
    Configuration config = new Configuration();
    DriftDefinition driftDefPojo = new DriftDefinition(config);
    driftDefPojo.setName("testDriftDef");
    driftDefPojo.setInterval(60L);
    driftDefPojo.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem, "foo/bar"));

    driftManager.updateDriftDefinition(
        overlord, EntityContext.forResource(newResource.getId()), driftDefPojo);

    ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
    ResourceCriteria c = new ResourceCriteria();
    c.addFilterId(newResource.getId());
    c.fetchDriftDefinitions(true);
    List<Resource> resources = resourceManager.findResourcesByCriteria(overlord, c);
    assertEquals(1, resources.size());
    Set<DriftDefinition> driftDefs = resources.get(0).getDriftDefinitions();
    assertNotNull(driftDefs);
    assertEquals(3, driftDefs.size());
    DriftDefinition driftDef = null;
    for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext(); ) {
      driftDef = i.next();
      if (driftDefPojo.getName().equals(driftDef.getName())) break;
    }
    assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
    assertEquals(driftDefPojo.getName(), driftDef.getName());
    assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
    assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());

    driftDefPojo.setInterval(120L);
    driftManager.updateDriftDefinition(
        overlord, EntityContext.forResource(newResource.getId()), driftDefPojo);

    resources = resourceManager.findResourcesByCriteria(overlord, c);
    assertEquals(1, resources.size());
    driftDefs = resources.get(0).getDriftDefinitions();
    assertNotNull(driftDefs);
    assertEquals(3, driftDefs.size());
    driftDef = null;
    for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext(); ) {
      driftDef = i.next();
      if (driftDefPojo.getName().equals(driftDef.getName())) break;
    }
    assertEquals(driftDefPojo.getName(), driftDef.getName());
    assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
    assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
    assertEquals(120L, driftDef.getInterval());

    driftDefPojo.setName("testDriftDef-2");
    driftDefPojo.setInterval(30L);
    driftDefPojo.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem, "foo/baz"));

    driftManager.updateDriftDefinition(
        overlord, EntityContext.forResource(newResource.getId()), driftDefPojo);

    resources = resourceManager.findResourcesByCriteria(overlord, c);
    assertEquals(1, resources.size());
    driftDefs = resources.get(0).getDriftDefinitions();
    assertNotNull(driftDefs);
    assertEquals(4, driftDefs.size());
    for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext(); ) {
      driftDef = i.next();
      if ("testDriftDef".equals(driftDef.getName())) {
        assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
        assertEquals("foo/bar", driftDef.getBasedir().getValueName());
        assertEquals(BaseDirValueContext.fileSystem, driftDef.getBasedir().getValueContext());
        assertEquals(120L, driftDef.getInterval());
      } else if ("testDriftDef-2".equals(driftDef.getName())) {
        assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
        assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
        assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());
      } else if (!"test-1".equals(driftDef.getName()) && !"test-2".equals(driftDef.getName())) {
        fail("Unexpected drift def name: " + driftDef.getName());
      }
    }

    driftManager.deleteDriftDefinition(
        overlord, EntityContext.forResource(newResource.getId()), "testDriftDef");
    resources = resourceManager.findResourcesByCriteria(overlord, c);
    assertEquals(1, resources.size());
    driftDefs = resources.get(0).getDriftDefinitions();
    assertNotNull(driftDefs);
    assertEquals(3, driftDefs.size());
    for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext(); ) {
      driftDef = i.next();
      if (driftDefPojo.getName().equals(driftDef.getName())) break;
    }
    assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
    assertEquals(driftDefPojo.getName(), driftDef.getName());
    assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
    assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());
  }
示例#17
0
  @SuppressWarnings("unchecked")
  @Override
  public ActionForward execute(
      ComponentContext context,
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    dataManager = LookupUtil.getMeasurementDataManager();
    chartsManager = LookupUtil.getMeasurementChartsManager();

    WebUser user = SessionUtils.getWebUser(request.getSession());
    Subject subject = user.getSubject();
    Resource resource = (Resource) request.getAttribute(AttrConstants.RESOURCE_ATTR);

    // Get metric time range
    MeasurementPreferences preferences = user.getMeasurementPreferences();
    MetricRangePreferences rangePreferences = preferences.getMetricRangePreferences();
    long begin = rangePreferences.begin;
    long end = rangePreferences.end;

    List<AutoGroupComposite> children;
    List<AutoGroupCompositeDisplaySummary> displaySummary;
    int parentId = -1;
    int resourceTypeId = -1;
    if (resource == null) {
      parentId =
          WebUtility.getOptionalIntRequestParameter(
              request, AttrConstants.AUTOGROUP_PARENT_ATTR, -1);
      if (parentId > 0) // get data for individual autogroup children
      {
        resourceTypeId =
            WebUtility.getOptionalIntRequestParameter(
                request, AttrConstants.AUTOGROUP_TYPE_ATTR, -1);
        children = getAutoGroupChildren(subject, parentId, resourceTypeId);
        if (children == null) children = new ArrayList<AutoGroupComposite>();
        displaySummary = new ArrayList<AutoGroupCompositeDisplaySummary>(children.size() + 1);

        // get the parent
        ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
        AutoGroupComposite parentComposite =
            resourceManager.getResourceAutoGroup(subject, parentId);
        if (parentComposite != null) {
          parentComposite.setMainResource(true);
          List<MetricDisplaySummary> metricSummaries = null;
          metricSummaries =
              chartsManager.getMetricDisplaySummariesForMetrics(
                  subject, parentId, DataType.MEASUREMENT, begin, end, true, true);
          displaySummary.add(
              0, new AutoGroupCompositeDisplaySummary(parentComposite, metricSummaries));
        }
        /* We have n children with each child representing exactly 1 resource.
         * As we are in an autogroup, all children have the same type, so we can just feed them to the backend
         * in one call with all n resources.
         */

        // Loop over children, get resources, call some ..forMultiMetrics..
        List<Integer> resourceIds = new ArrayList<Integer>();
        for (AutoGroupComposite child : children) {
          List resources = child.getResources();
          ResourceWithAvailability rwa = (ResourceWithAvailability) resources.get(0);
          resourceIds.add(rwa.getResource().getId());
        }

        // Map<ResourceId, List<Summaries for that resource>
        Map<Integer, List<MetricDisplaySummary>> summaries =
            dataManager.findNarrowedMetricDisplaySummariesForResourcesAndParent(
                subject, resourceTypeId, parentId, resourceIds, begin, end);
        for (AutoGroupComposite child : children) {
          if (parentComposite != null) child.increaseDepth(1);

          List resources = child.getResources();
          ResourceWithAvailability rwa = (ResourceWithAvailability) resources.get(0);
          List<MetricDisplaySummary> sumList = summaries.get(rwa.getResource().getId());
          displaySummary.add(new AutoGroupCompositeDisplaySummary(child, sumList));
        }

      } else {
        RequestUtils.setError(request, MessageConstants.ERR_RESOURCE_NOT_FOUND);
        return null;
      }
    } else { // resource != null
      // get children of that single resource, which can be individual resources or autogroups
      children = getResourceChildren(resource, subject);

      displaySummary = new ArrayList<AutoGroupCompositeDisplaySummary>(children.size());
      for (AutoGroupComposite child : children) {
        List<MetricDisplaySummary> metrics = getMetrics(resource, child, subject, begin, end);

        displaySummary.add(new AutoGroupCompositeDisplaySummary(child, metrics));
      }
    }

    context.putAttribute(AttrConstants.CTX_SUMMARIES, displaySummary);

    return null;
  }
 @Override
 public void clearResourceConfigError(int resourceId) {
   ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
   resourceManager.clearResourceConfigError(resourceId);
 }