Esempio n. 1
0
 public Agent getAgent() {
   if (agent == null) {
     hasPermission();
     int agentId = FacesContextUtility.getRequiredRequestParameter("agentId", Integer.class);
     agent = agentManager.getAgentByID(agentId);
   }
   return agent;
 }
Esempio n. 2
0
 @Override
 public PageList<Agent> findAgentsByCriteria(AgentCriteria criteria) throws RuntimeException {
   try {
     return SerialUtility.prepare(
         agentManager.findAgentsByCriteria(getSessionSubject(), criteria),
         "TopologyGWTServiceImpl.findAgentsByCriteria");
   } catch (Throwable t) {
     throw getExceptionToThrowToClient(t);
   }
 }
  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));
  }
  @Override
  public Set<ResourceMeasurementScheduleRequest> postProcessNewlyCommittedResources(
      Set<Integer> resourceIds) {
    if (log.isDebugEnabled()) {
      log.debug("Post-processing " + resourceIds.size() + "newly committed resources");
      log.debug("Ids were: " + resourceIds);
    }

    Subject overlord = LookupUtil.getSubjectManager().getOverlord();
    AlertTemplateManagerLocal alertTemplateManager = LookupUtil.getAlertTemplateManager();
    MeasurementScheduleManagerLocal scheduleManager = LookupUtil.getMeasurementScheduleManager();
    AgentManagerLocal agentManager = LookupUtil.getAgentManager();
    StatusManagerLocal statusManager = LookupUtil.getStatusManager();

    long start = System.currentTimeMillis();

    // do this in one fell swoop, instead of one resource at a time
    Set<ResourceMeasurementScheduleRequest> results =
        scheduleManager.findSchedulesForResourceAndItsDescendants(
            ArrayUtils.unwrapCollection(resourceIds), false);

    long time = (System.currentTimeMillis() - start);

    if (time >= 10000L) {
      log.info(
          "Performance: commit resource, create schedules timing: resourceCount/millis="
              + resourceIds.size()
              + '/'
              + time);
    } else if (log.isDebugEnabled()) {
      log.debug(
          "Performance: commit resource, create schedules timing: resourceCount/millis="
              + resourceIds.size()
              + '/'
              + time);
    }

    start = System.currentTimeMillis();

    for (Integer resourceId : resourceIds) {
      // apply alert templates
      try {
        alertTemplateManager.updateAlertDefinitionsForResource(overlord, resourceId);
      } catch (AlertDefinitionCreationException adce) {
        /* should never happen because AlertDefinitionCreationException is only ever
         * thrown if updateAlertDefinitionsForResource isn't called as the overlord
         *
         * but we'll log it anyway, just in case, so it isn't just swallowed
         */
        log.error(adce);
      } catch (Throwable t) {
        log.debug("Could not apply alert templates for resourceId = " + resourceId, t);
      }
    }

    try {
      if (resourceIds.size() > 0) {
        // they all come from the same agent, so pick any old one
        int anyResourceIdFromNewlyCommittedSet = resourceIds.iterator().next();
        int agentId = agentManager.getAgentIdByResourceId(anyResourceIdFromNewlyCommittedSet);
        statusManager.updateByAgent(agentId);
      }
    } catch (Throwable t) {
      log.debug("Could not reload caches for newly committed resources", t);
    }

    time = (System.currentTimeMillis() - start);

    if (time >= 10000L) {
      log.info(
          "Performance: commit resource, apply alert templates timing: resourceCount/millis="
              + resourceIds.size()
              + '/'
              + time);
    } else if (log.isDebugEnabled()) {
      log.debug(
          "Performance: commit resource, apply alert templates timing: resourceCount/millis="
              + resourceIds.size()
              + '/'
              + time);
    }

    return results;
  }