Beispiel #1
0
  private void setTitle(HttpServletRequest request, Portal portal, String titleName)
      throws Exception {
    Resource resource = RequestUtils.getResource(request);
    ResourceGroup group = RequestUtils.getResourceGroupIfExists(request);
    ResourceType type;
    if (resource != null) {
      // resource alert definition
      type = resource.getResourceType();
    } else if (group != null) {
      // group alert definition
      type = group.getResourceType();
    } else {
      // template alert definition
      type = RequestUtils.getResourceType(request);
    }

    ResourceCategory category = type.getCategory();

    titleName = StringUtil.replace(titleName, "platform", category.toString().toLowerCase());

    portal.setName(titleName);

    // if there's an alert definition available, set our second
    // title parameter to its name
    try {
      AlertDefinition alertDef = AlertDefUtil.getAlertDefinition(request);
      request.setAttribute(Constants.TITLE_PARAM2_ATTR, alertDef.getName());
    } catch (ParameterNotFoundException e) {
      // it's okay
      log.trace("couldn't find alert definition: " + e.getMessage());
    }
  }
  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);
    }
  }
Beispiel #3
0
  /**
   * This sets the return path for a ResourceAction by appending the type and resource id to the
   * forward url.
   *
   * @param request The current controller's request.
   * @param mapping The current controller's mapping that contains the input.
   * @exception ParameterNotFoundException if the type or id are not found
   * @exception ServletException If there is not input defined for this form
   */
  @Override
  protected void setReturnPath(HttpServletRequest request, ActionMapping mapping) throws Exception {
    HashMap parms = new HashMap();

    int resourceId = RequestUtils.getResourceId(request);
    parms.put(Constants.RESOURCE_ID_PARAM, resourceId);

    try {
      parms.put(
          Constants.ALERT_DEFINITION_PARAM,
          RequestUtils.getIntParameter(request, Constants.ALERT_DEFINITION_PARAM));
      parms.put(Constants.CHILD_RESOURCE_TYPE_ID_PARAM, WebUtility.getChildResourceTypeId(request));
    } catch (ParameterNotFoundException pnfe) {
      // that's ok!
      log.trace("couldn't find parameter: " + pnfe.getMessage());
    }

    // sets the returnPath to match the mode we're in.
    String mode = request.getParameter(Constants.MODE_PARAM);
    parms.put(Constants.MODE_PARAM, mode);

    String returnPath = ActionUtils.findReturnPath(mapping, parms);
    SessionUtils.setReturnPath(request.getSession(), returnPath);
  }
Beispiel #4
0
  public ActionForward listDefinitions(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    setResource(request);

    super.setNavMapLocation(request, mapping, Constants.ALERT_CONFIG_LOC);

    // clean out the return path
    SessionUtils.resetReturnPath(request.getSession());

    // set the return path
    try {
      setReturnPath(request, mapping);
    } catch (ParameterNotFoundException pne) {
      if (log.isDebugEnabled()) {
        log.debug("", pne);
      }
    }

    Portal portal = Portal.createPortal();
    setTitle(request, portal, "alerts.config.platform.DefinitionList.Title");
    portal.setDialog(false);

    try {
      RequestUtils.getStringParameter(request, Constants.APPDEF_RES_TYPE_ID);
      portal.addPortlet(new Portlet(".admin.alerts.List"), 1);
    } catch (ParameterNotFoundException e) {
      portal.addPortlet(new Portlet(".events.config.list"), 1);
    }

    request.setAttribute(Constants.PORTAL_KEY, portal);

    return null;
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    EditMetricBaselineForm metricBaselineForm = (EditMetricBaselineForm) form;

    Integer metricId = metricBaselineForm.getM();
    Integer alertDefId = metricBaselineForm.getAd();
    String oldMode = metricBaselineForm.getOldMode();
    String mname = metricBaselineForm.getMetricName();
    Integer rid = metricBaselineForm.getRid();
    //        Integer type = metricBaselineForm.getType();

    log.debug("in edit metric baseline actions ...");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(Constants.RESOURCE_PARAM, rid);
    //        params.put(Constants.RESOURCE_TYPE_ID_PARAM,type);
    params.put(Constants.ALERT_DEFINITION_PARAM, alertDefId);
    params.put(Constants.METRIC_ID_PARAM, metricId);
    params.put("oldMode", oldMode);
    params.put(Constants.METRIC_NAME_PARAM, mname);

    ActionForward forward = checkSubmit(request, mapping, form, params);
    if (forward != null) {
      BaseValidatorForm spiderForm = metricBaselineForm;
      if (spiderForm.isCancelClicked()) {
        params.put("mode", oldMode);
        params.remove("oldMode");
        forward = checkSubmit(request, mapping, form, params);
      }

      return forward;
    }

    if (RequestUtils.getStringParameter(request, "recalc").equals("y")) {
      // ok clicked
      ServletContext ctx = getServlet().getServletContext();
      //            BaselineBoss boss= ContextUtils.getBaselineBoss(ctx);
      Integer sessionId = RequestUtils.getSessionId(request);

      // XXX call the recalculate baseline from the BaselineBoss
      // based on the radio button value
      log.debug(
          "START = "
              + metricBaselineForm.getStartDate().getTime()
              + "END = "
              + metricBaselineForm.getEndDate().getTime()
              + "Metric id is "
              + metricId);

      //            MeasurementBaseline value = boss.recalculateBaseline(sessionId,metricId,
      //                  metricBaselineForm.getStartDate().getTime(),
      //                  metricBaselineForm.getEndDate().getTime() );
      //            request.setAttribute("BaselineValue",value);
      return returnReset(request, mapping, params);
    }

    log.debug("returning success");
    return returnSuccess(request, mapping, params);
  }
  @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;
  }