private void addMeasurementConfig(
      List<MeasurementConfigEntity> ents, AppdefEntityID id, String typeName) {
    MeasurementConfigEntity ent = new MeasurementConfigEntity();
    ConfigResponse response;
    byte[] config;

    try {
      response =
          configManager.getMergedConfigResponse(
              authzSubjectManager.getOverlordPojo(), ProductPlugin.TYPE_MEASUREMENT, id, true);

      // Only send the configuration to the agent if log or
      // config file tracking has been enabled.
      if (ConfigTrackPlugin.isEnabled(response, id.getType())
          || LogTrackPlugin.isEnabled(response, id.getType())) {

        config = response.encode();

        ent.setPluginName(id.getAppdefKey());
        ent.setPluginType(typeName);
        ent.setConfig(config);

        ents.add(ent);
      }

    } catch (Exception exc) {
      return; // Not a fatal condition
    }
  }
  public boolean isResourceConfigured(
      HttpServletRequest request, ServletContext ctx, boolean setError)
      throws ServletException, AppdefEntityNotFoundException, SessionNotFoundException,
          SessionTimeoutException, PermissionException, EncodingException, RemoteException {
    final String CONFIG_ATTR = "IsResourceUnconfigured";

    Boolean configured = (Boolean) request.getAttribute(CONFIG_ATTR);
    if (configured != null) return !configured.booleanValue();

    if (entityId.isGroup()) return true;

    int sessionId = RequestUtils.getSessionId(request).intValue();

    if (this instanceof ApplicationInventoryHelper) return true;

    ProductBoss productBoss = Bootstrap.getBean(ProductBoss.class);

    String context = request.getContextPath();
    try {
      productBoss.getMergedConfigResponse(
          sessionId, ProductPlugin.TYPE_MEASUREMENT, entityId, true);
    } catch (ConfigFetchException e) {
      if (setError) {
        ActionMessage error =
            new ActionMessage(
                CFG_ERR_RES,
                new String[] {
                  context, String.valueOf(entityId.getType()), String.valueOf(entityId.getID())
                });
        RequestUtils.setError(request, error, ActionMessages.GLOBAL_MESSAGE);
      }
      request.setAttribute(CONFIG_ATTR, Boolean.TRUE);
      return false;
    }

    // only check where the config is invalid
    String validationError =
        productBoss.getConfigResponse(sessionId, entityId).getValidationError();

    if (validationError == null) {
      request.setAttribute(CONFIG_ATTR, Boolean.FALSE);
      return true;
    }
    if (setError) {
      ActionMessage error =
          new ActionMessage(
              CFG_INVALID_RES,
              new String[] {
                StringUtil.replace(validationError, "\n", "<br>&nbsp;&nbsp;" + "&nbsp;&nbsp;"),
                context,
                String.valueOf(entityId.getType()),
                String.valueOf(entityId.getID())
              });
      RequestUtils.setError(request, error, ActionMessages.GLOBAL_MESSAGE);
    }
    request.setAttribute(CONFIG_ATTR, Boolean.TRUE);
    return false;
  }
  /**
   * Return the array of Integer ids for the given <code>notificationType</code> contained in the
   * alert definition notification actions.
   *
   * <p>This method also sets the alert definition object on the form and places it in the request.
   * It also puts the resource id and resource type in the request.
   *
   * @param addForm the form being prepared
   * @param notificationType the type of notification
   * @return the array of ids for already existing notifications based on the notificationType, or a
   *     zero-length array if there are not yet any notifications of this type
   * @throws ServletException
   * @throws RemoteException
   * @throws PermissionException
   * @throws SessionTimeoutException
   * @throws SessionNotFoundException
   * @throws EncodingException
   * @throws InvalidActionDataException
   */
  public Integer[] getNotificationIds(
      HttpServletRequest request,
      AddNotificationsFormNG addForm,
      AppdefEntityID aeid,
      int notificationType)
      throws ServletException, SessionNotFoundException, SessionTimeoutException,
          PermissionException, RemoteException, EncodingException, InvalidActionDataException {
    Integer[] ids = new Integer[0];

    Integer sessionId = RequestUtils.getSessionId(request);

    Integer alertDefId = addForm.getAd();
    log.debug("(1) alertDefId=" + alertDefId);
    if (alertDefId == null) throw new ParameterNotFoundException("alert definition id not found");

    log.debug("(2) alertDefId=" + alertDefId);
    AlertDefinitionValue alertDef =
        (AlertDefinitionValue) request.getAttribute(Constants.ALERT_DEFS_ATTR);
    if (alertDef == null) {
      alertDef = eventsBoss.getAlertDefinition(sessionId.intValue(), alertDefId);
    }
    request.setAttribute(Constants.ALERT_DEFINITION_ATTR, alertDef);

    ActionValue[] actions = alertDef.getActions();
    for (int i = 0; i < actions.length; ++i) {
      if (actions[i].classnameHasBeenSet()
          && !(actions[i].getClassname().equals(null) || actions[i].getClassname().equals(""))) {
        EmailActionConfig emailCfg = new EmailActionConfig();
        ConfigResponse configResponse = ConfigResponse.decode(actions[i].getConfig());

        try {
          emailCfg.init(configResponse);
        } catch (InvalidActionDataException e) {
          // Not an EmailAction
          log.debug("Action is " + actions[i].getClassname());
          continue;
        }

        if (emailCfg.getType() == notificationType) {
          ids = new Integer[emailCfg.getUsers().size()];
          ids = (Integer[]) emailCfg.getUsers().toArray(ids);
          break;
        }
      }
    }

    if (aeid instanceof AppdefEntityTypeID) {
      addForm.setAetid(aeid.getAppdefKey());
      request.setAttribute(Constants.APPDEF_RES_TYPE_ID, aeid.getAppdefKey());
    } else {
      addForm.setRid(aeid.getId());
      addForm.setType(new Integer(aeid.getType()));
      request.setAttribute(Constants.ENTITY_ID_PARAM, aeid.getAppdefKey());
    }

    return ids;
  }
示例#4
0
 @SkipValidation
 public String cancel() throws Exception {
   setHeaderResources();
   clearErrorsAndMessages();
   AppdefEntityID appdefId = RequestUtils.getEntityId(request);
   if (appdefId != null) {
     internalEid = appdefId.getId() + ":" + appdefId.getType();
   }
   internalRid = appdefId.getId().toString();
   internalType = String.valueOf(appdefId.getType());
   return "cancel";
 }
 /**
  * Return a subclass of <code>InventoryHelper</code> specific to the entity type of a particular
  * resource.
  */
 public static InventoryHelper getHelper(AppdefEntityID entityId) {
   switch (entityId.getType()) {
     case AppdefEntityConstants.APPDEF_TYPE_PLATFORM:
       return new PlatformInventoryHelper(entityId, Bootstrap.getBean(AppdefBoss.class));
     case AppdefEntityConstants.APPDEF_TYPE_SERVER:
       return new ServerInventoryHelper(entityId, Bootstrap.getBean(AppdefBoss.class));
     case AppdefEntityConstants.APPDEF_TYPE_SERVICE:
       return new ServiceInventoryHelper(entityId);
     case AppdefEntityConstants.APPDEF_TYPE_APPLICATION:
       return new ApplicationInventoryHelper(entityId, Bootstrap.getBean(AppdefBoss.class));
     case AppdefEntityConstants.APPDEF_TYPE_GROUP:
       return new GroupInventoryHelper(entityId);
     default:
       throw new IllegalArgumentException(entityId.getTypeName());
   }
 }
示例#6
0
  public String save() throws Exception {
    request = getServletRequest();
    log.trace("performing resouce quick control action: " + qcForm.getResourceAction());

    try {

      int sessionId = RequestUtils.getSessionIdInt(request);

      // create the new action to schedule
      Integer localId = qcForm.getResourceId();
      Integer localType = qcForm.getResourceType();
      AppdefEntityID appdefId = new AppdefEntityID(localType.intValue(), localId);
      type = localType.toString();
      rid = localId.toString();
      internalEid = appdefId.toString();

      request.setAttribute(Constants.RESOURCE_PARAM, localId);
      request.setAttribute(Constants.RESOURCE_TYPE_ID_PARAM, type);

      String action = qcForm.getResourceAction();
      String args = qcForm.getArguments();

      if (AppdefEntityConstants.APPDEF_TYPE_GROUP == localType) {
        controlBoss.doGroupAction(sessionId, appdefId, action, args, null);
      } else {
        controlBoss.doAction(sessionId, appdefId, action, args);
      }

      // set confirmation message
      String ctrlStr = qcForm.getResourceAction();
      addActionMessage(
          getText("resource.server.QuickControl.Confirmation", new String[] {ctrlStr}));

      qcForm.reset();
      return SUCCESS;
    } catch (PluginException cpe) {
      log.trace("control not enabled", cpe);
      this.addActionError(getText("resource.common.error.ControlNotEnabled"));
      return "Failure";
    } catch (PermissionException pe) {
      this.addActionError(getText("resource.common.control.error.NewPermission"));
      return "Failure";
    }
  }
示例#7
0
  // @SkipValidation
  // public String start() throws Exception {
  //
  // // log.trace("preparing new server control action");
  // // request=getServletRequest();
  // // int sessionId = RequestUtils.getSessionId(request).intValue();
  // //
  // // AppdefEntityID appdefId = RequestUtils.getEntityId(request);
  // //
  // // List<String> actions = controlBoss.getActions(sessionId, appdefId);
  // //
  // // Map options= new LinkedHashMap<String, String>();
  // // for (String action : actions) {
  // // String value = action;
  // // String label = StringUtil.capitalize(value);
  // // options.put(value,label);
  // // }
  // // cForm.setControlActions(options);
  // // cForm.setNumControlActions(new Integer(options.size()));
  // // if (cForm.getStartHour() == null) {
  // // Date date = new Date();
  // // Calendar calendar = GregorianCalendar.getInstance();
  // // calendar.setTime(date);
  // // int hours=calendar.get(Calendar.HOUR);
  // // cForm.setStartHour(hours+"");
  // // }
  // // if (cForm.getStartMin()==null) {
  // // DateTime dt = new DateTime();
  // // int minutes = dt.getMinuteOfHour();
  // // cForm.setStartMin(minutes+"");
  // // }
  // // if (cForm.getStartAmPm()==null) {
  // // Date date = new Date();
  // // Calendar calendar = GregorianCalendar.getInstance();
  // // calendar.setTime(date);
  // // int ampm=calendar.get(Calendar.AM_PM);
  // // if (ampm==0) {
  // // cForm.setStartAmPm("AM");
  // // } else {
  // // cForm.setStartAmPm("PM");
  // // }
  // // }
  // return "formNewActionLoad";
  // }
  public String save() throws Exception {

    log.trace("creating new action");
    try {
      request = getServletRequest();
      int sessionId = RequestUtils.getSessionId(request).intValue();
      AppdefEntityID appdefId = RequestUtils.getEntityId(request);
      request.setAttribute(Constants.RESOURCE_PARAM, appdefId.getId());
      request.setAttribute(Constants.RESOURCE_TYPE_ID_PARAM, new Integer(appdefId.getType()));
      boolean validationFailed = false;
      String des = this.cForm.getDescription();
      if (des != null && des.length() > 100) {
        this.addFieldError("description", getText("ng.errors.maxlength", new String[] {"100"}));

        validationFailed = true;
      }
      if (!(cForm.getStartTime().equals("1"))) {
        try {
          int tmph = Integer.parseInt(cForm.getStartHour());
          if (tmph < 0 || tmph > 12) {
            this.addFieldError(
                "startHour", getText("errors.range", new String[] {tmph + "", "1", "12"}));
            validationFailed = true;
          }
        } catch (NumberFormatException nfe) {
          this.addFieldError(
              "startHour",
              getText("errors.invalid.StartHour", new String[] {cForm.getStartHour() + ""}));
          validationFailed = true;
        }

        try {
          int tmpmin = Integer.parseInt(cForm.getStartMin());
          if (tmpmin > 59 || tmpmin < 0) {
            this.addFieldError(
                "startMin", getText("errors.range", new String[] {tmpmin + "", "0", "59"}));
            validationFailed = true;
          }
        } catch (NumberFormatException nfe) {
          this.addFieldError(
              "startMin",
              getText("errors.invalid.StartMin", new String[] {cForm.getStartMin() + ""}));
          validationFailed = true;
        }
      }

      String cAction = this.cForm.getControlAction();
      if (cAction != null && cAction.equals("")) {
        this.addFieldError(
            "controlAction",
            getText(
                "errors.required", new String[] {getText("dash.home.TableHeader.ControlAction")}));
        validationFailed = true;
      }
      // make sure that the ControlAction is valid.
      String action = cForm.getControlAction();
      List<String> validActions = controlBoss.getActions(sessionId, appdefId);
      if (!validActions.contains(action)) {
        this.addActionError(getText("resource.common.control.error.ControlActionNotValid"));
        validationFailed = true;
      }
      if (!(cForm.getStartTime().equals("1"))) {
        cForm.setStartTime(ScheduleFormNG.START_ON_DATE);

        if (cForm.getStartTime().equals(ScheduleFormNG.START_ON_DATE)
            && cForm.getRecurInterval().equals(ScheduleFormNG.RECUR_WEEKLY)) {
          Integer tmpNumWeeks = null;
          try {
            tmpNumWeeks = new Integer(Integer.parseInt(cForm.getNumWeeks()));
          } catch (NumberFormatException nfe) {
            this.addFieldError(
                "numWeeks",
                getText(
                    "resource.autodiscovery.ScheduleTab.error.numWeeks",
                    new String[] {cForm.getNumWeeks()}));
            validationFailed = true;
          }
          if (null == cForm.getRecurrenceDay() || cForm.getRecurrenceDay().length == 0) {
            this.addFieldError(
                "recurrenceDay", getText("resource.autodiscovery.ScheduleTab.error.recurrenceDay"));
            validationFailed = true;
          }
        }
        if (cForm.getStartTime().equals(ScheduleFormNG.START_ON_DATE)
            && cForm.getRecurInterval().equals(ScheduleFormNG.RECUR_DAILY)) {
          Integer tmpNumDays = null;
          try {
            tmpNumDays = new Integer(Integer.parseInt(cForm.getNumDays()));
          } catch (NumberFormatException nfe) {
            this.addFieldError(
                "numDays",
                getText(
                    "resource.autodiscovery.ScheduleTab.error.numDays",
                    new String[] {cForm.getNumDays()}));
            validationFailed = true;
          }
        }
        if (cForm.getStartTime().equals(ScheduleFormNG.START_ON_DATE)
            && cForm.getRecurInterval().equals(ScheduleFormNG.RECUR_MONTHLY)) {
          Integer tmpNumMonths = null;
          try {
            tmpNumMonths = new Integer(Integer.parseInt(cForm.getNumMonths()));
          } catch (NumberFormatException nfe) {
            this.addFieldError(
                "numMonths",
                getText(
                    "resource.autodiscovery.ScheduleTab.error.numDays",
                    new String[] {cForm.getNumMonths()}));
            validationFailed = true;
          }
        }

        LocalDate localDate =
            new LocalDate(cForm.getEndYear(), cForm.getEndMonth() + 1, cForm.getEndDay());
        Date endDate = new Date();
        if (cForm.getRecurInterval().equals("recurNever")
            && (cForm.getEndTime().equals("1") || cForm.getEndTime().equals(null))) {
          endDate = null;
        } else {
          endDate = java.sql.Date.valueOf(localDate + "");
        }
        if ((!(cForm.getRecurInterval().equals(ScheduleFormNG.RECUR_NEVER))
            && (cForm.getStartDate() != null && !(cForm.getEndTime().equals("1"))))) {
          Date tmpStartDate = cForm.getStartDate();
          Date tmpEndDate = endDate;
          if (tmpStartDate.after(tmpEndDate)) {
            this.addFieldError(
                "startMonth", getText("resource.common.monitor.error.FromEarlierThanTo"));
            validationFailed = true;
          }
        }
        Date d = new Date();
        GregorianCalendar cal = new GregorianCalendar();
        cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
        cal.set(Calendar.MONTH, Calendar.getInstance().get(Calendar.MONTH));
        cal.set(Calendar.DAY_OF_MONTH, Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
        cal.set(Calendar.HOUR_OF_DAY, Calendar.getInstance().get(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, Calendar.getInstance().get(Calendar.MINUTE));
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        d = cal.getTime();
        Date startDate = cForm.getStartDate();
        if ((startDate != null) && (d.after(startDate))) {
          this.addFieldError("startYear", getText("resource.common.control.error.ScheduleInvalid"));
          validationFailed = true;
        }
      } else {
        cForm.setStartTime(ScheduleFormNG.START_NOW);
      }
      request.setAttribute("recurrenceDay", cForm.getRecurrenceDay());
      if (validationFailed) {
        return INPUT;
      }
      if (cForm.getStartTime().equals(ScheduleFormNG.START_NOW)) {
        if (runBackendSave) {
          controlBoss.doAction(sessionId, appdefId, action, (String) null);
        }
      } else {

        // create the new action to schedule

        if (runBackendSave) {
          controlBoss.doAction(sessionId, appdefId, action, covertToScheduleValue());
        }
      }

      // set confirmation message
      if (runBackendSave) {
        addActionMessage(getText("resource.common.scheduled.Confirmation"));
      }
      internalRid = appdefId.getId().toString();
      internalType = String.valueOf(appdefId.getType());
      internalEid = internalType + ":" + internalRid;
      return SUCCESS;
    } catch (PluginNotFoundException pnfe) {
      log.trace("no plugin available", pnfe);
      this.addActionError(getText("resource.common.control.PluginNotFound"));
      return INPUT;
    } catch (PluginException cpe) {
      log.trace("control not enabled", cpe);
      this.addActionError(getText("resource.common.error.ControlNotEnabled"));
      return INPUT;
    } catch (PermissionException pe) {
      this.addActionError(getText("resource.common.control.error.NewPermission"));
      return INPUT;
    } catch (SchedulerException se) {
      this.addActionError(getText("resource.common.control.error.ScheduleInvalid"));
      return INPUT;
    }
  }
示例#8
0
 public AppdefEntityID getEntityId() {
   return AppdefEntityID.newServerID(getId());
 }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    HttpSession session = request.getSession();

    AddApplicationServicesForm addForm = (AddApplicationServicesForm) form;
    AppdefEntityID aeid = new AppdefEntityID(addForm.getType().intValue(), addForm.getRid());

    HashMap<String, Object> forwardParams = new HashMap<String, Object>(2);
    forwardParams.put(Constants.ENTITY_ID_PARAM, aeid.getAppdefKey());
    forwardParams.put(Constants.ACCORDION_PARAM, "3");

    ActionForward forward = checkSubmit(request, mapping, form, forwardParams);
    if (forward != null) {
      BaseValidatorForm spiderForm = (BaseValidatorForm) form;

      if (spiderForm.isCancelClicked()
          || spiderForm.isResetClicked()
          || forward.getName().equalsIgnoreCase(Constants.RESET_URL)) {
        log.trace("removing pending service list");
        SessionUtils.removeList(session, Constants.PENDING_APPSVCS_SES_ATTR);
      } else if (spiderForm.isAddClicked()) {
        log.trace(
            "adding to pending service list " + Arrays.asList(addForm.getAvailableServices()));
        SessionUtils.addToList(
            session, Constants.PENDING_APPSVCS_SES_ATTR, addForm.getAvailableServices());
      } else if (spiderForm.isRemoveClicked()) {
        log.trace("removing from pending service list");
        SessionUtils.removeFromList(
            session, Constants.PENDING_APPSVCS_SES_ATTR, addForm.getPendingServices());
      }
      return forward;
    }

    Integer sessionId = RequestUtils.getSessionId(request);

    log.trace("getting pending service list");
    List<String> uiPendings =
        SessionUtils.getListAsListStr(session, Constants.PENDING_APPSVCS_SES_ATTR);
    List<AppdefEntityID> svcList = new ArrayList<AppdefEntityID>();

    for (int pRcs = 0; pRcs < uiPendings.size(); pRcs++) {
      log.debug("uiPendings = " + uiPendings.get(pRcs));
      StringTokenizer tok = new StringTokenizer(uiPendings.get(pRcs), " ");
      svcList.add(new AppdefEntityID(tok.nextToken()));
    }
    // when we call boss.setApplicationServices(...) our map must
    // be populated with all of the existing services (and whether
    // or not they're entry points) as well as our new ones

    // first, get the existing ones
    PageControl nullPc = new PageControl(-1, -1);
    List<AppdefResourceValue> existingServices =
        appdefBoss.findServiceInventoryByApplication(sessionId.intValue(), aeid.getId(), nullPc);
    DependencyTree tree = appdefBoss.getAppDependencyTree(sessionId.intValue(), aeid.getId());
    for (AppdefResourceValue service : existingServices) {

      log.debug("service =" + service.getClass().getName());

      tree.findAppService(service);
      svcList.add(service.getEntityId());
    }

    // second, get the new ones

    // set all added services to be entry points, if they're not to be
    // entry points and are instead part of a dependency chain,
    // setting up the dependencies is a separate activity

    log.trace("adding servicess " + svcList + " for application [" + aeid.getID() + "]");
    appdefBoss.setApplicationServices(sessionId.intValue(), aeid.getId(), svcList);
    log.trace("removing pending service list");
    SessionUtils.removeList(session, Constants.PENDING_APPSVCS_SES_ATTR);

    RequestUtils.setConfirmation(request, "resource.application.inventory.confirm.AddedServices");
    return returnSuccess(request, mapping, forwardParams);
  }