private PackageAction syncToVictim(
      RequestContext requestContext, Long sid, Set pkgIdCombos, String option) {

    PackageAction pa = null;
    Date time = new Date(requestContext.getParamAsLong("time"));

    if (isProfileSync(requestContext)) {
      Long prid = requestContext.getRequiredParam("prid");

      pa =
          ProfileManager.syncToProfile(
              requestContext.getCurrentUser(), sid, prid, pkgIdCombos, option, time);

      if (pa == null) {
        createMessage(requestContext.getRequest(), "message.nopackagestosync");
        return null;
      }

      List args = new ArrayList();
      args.add(sid.toString());
      args.add(pa.getId().toString());
      args.add(requestContext.lookupAndBindServer().getName());
      args.add(
          ProfileManager.lookupByIdAndOrg(prid, requestContext.getCurrentUser().getOrg())
              .getName());

      createMessage(requestContext.getRequest(), "message.syncpackages", args);
    } else if (isSystemSync(requestContext)) {
      Long sid1 = requestContext.getRequiredParam("sid_1");
      pa =
          ProfileManager.syncToSystem(
              requestContext.getCurrentUser(), sid, sid1, pkgIdCombos, option, time);

      if (pa == null) {
        createMessage(requestContext.getRequest(), "message.nopackagestosync");
        return null;
      }

      List args = new ArrayList();
      args.add(sid.toString());
      args.add(pa.getId().toString());
      args.add(requestContext.lookupAndBindServer().getName());
      args.add(SystemManager.lookupByIdAndUser(sid1, requestContext.getCurrentUser()).getName());

      createMessage(requestContext.getRequest(), "message.syncpackages", args);
    }

    addHardwareMessage(pa, requestContext);

    return pa;
  }
示例#2
0
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getCurrentUser();
    Long sid = requestContext.getRequiredParam("sid");
    RhnSet set = getSetDecl(sid).get(user);

    ListRhnSetHelper help = new ListRhnSetHelper(this, request, getSetDecl(sid));
    help.setListName(LIST_NAME);
    String parentURL = request.getRequestURI() + "?sid=" + sid;
    help.setParentUrl(parentURL);

    help.execute();

    if (help.isDispatched()) {
      if (requestContext.wasDispatched("errata.jsp.apply")) {
        return applyErrata(mapping, formIn, request, response);
      }
    }

    String showButton = "true";
    // Show the "Apply Errata" button only when unapplied errata exist:
    if (!SystemManager.hasUnscheduledErrata(user, sid)) {
      showButton = "false";
    }

    Map params = new HashMap();
    Set keys = request.getParameterMap().keySet();
    for (Iterator i = keys.iterator(); i.hasNext(); ) {
      String key = (String) i.next();
      params.put(key, request.getParameter(key));
    }

    Server server = SystemManager.lookupByIdAndUser(sid, user);
    SdcHelper.ssmCheck(request, server.getId(), user);
    request.setAttribute("showApplyErrata", showButton);
    request.setAttribute("set", set);
    request.setAttribute("system", server);
    request.setAttribute("combo", getComboList(request));
    request.setAttribute(SELECTOR, request.getParameter(SELECTOR));

    return getStrutsDelegate()
        .forwardParams(mapping.findForward(RhnHelper.DEFAULT_FORWARD), params);
  }
  /**
   * Setup the system for provisioning with cobbler.
   *
   * @param mapping ActionMapping for struts
   * @param form DynaActionForm representing the form
   * @param ctx RequestContext request context
   * @param response HttpServletResponse response object
   * @param step WizardStep what step are we on?
   * @return ActionForward struts action forward
   * @throws Exception if something goes amiss
   */
  public ActionForward runFourth(
      ActionMapping mapping,
      DynaActionForm form,
      RequestContext ctx,
      HttpServletResponse response,
      WizardStep step)
      throws Exception {

    log.debug("runFourth");
    if (!validateFirstSelections(form, ctx)) {
      return runFirst(mapping, form, ctx, response, step);
    }
    Long sid = (Long) form.get(RequestContext.SID);
    String cobblerId = form.getString(RequestContext.COBBLER_ID);

    log.debug("runFourth.cobblerId: " + cobblerId);

    User user = ctx.getCurrentUser();
    Server server = SystemManager.lookupByIdAndUser(sid, user);

    Map params = new HashMap();
    params.put(RequestContext.SID, sid);

    log.debug("Creating cobbler system record");
    org.cobbler.Profile profile =
        org.cobbler.Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), cobblerId);

    KickstartData data =
        KickstartFactory.lookupKickstartDataByCobblerIdAndOrg(user.getOrg(), profile.getUid());

    if (showDiskWarning(data, form)) {
      form.set(NEXT_ACTION, "fourth");
      return mapping.findForward("fifth");
    }

    CobblerSystemCreateCommand cmd =
        new CobblerSystemCreateCommand(server, profile.getName(), data);
    cmd.store();
    log.debug("cobbler system record created.");
    String[] args = new String[2];
    args[0] = server.getName();
    args[1] = profile.getName();
    createMessage(ctx.getRequest(), "kickstart.schedule.cobblercreate", args);
    return getStrutsDelegate().forwardParams(mapping.findForward("cobbler-success"), params);
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {

    StrutsDelegate strutsDelegate = getStrutsDelegate();

    ActionForward forward = null;
    DynaActionForm f = (DynaActionForm) form;
    RequestContext requestContext = new RequestContext(request);
    Long sid = requestContext.getRequiredParam("sid");
    User user = requestContext.getLoggedInUser();
    Server server = SystemManager.lookupByIdAndUser(sid, user);
    request.setAttribute("system", server);

    DynaActionForm dynaForm = (DynaActionForm) form;
    DatePicker picker =
        getStrutsDelegate()
            .prepopulateDatePicker(request, dynaForm, "date", DatePicker.YEAR_RANGE_POSITIVE);

    request.setAttribute("date", picker);

    if (!isSubmitted(f)) {
      setup(request, f);
      forward =
          strutsDelegate.forwardParams(mapping.findForward("default"), request.getParameterMap());
    } else {
      ActionMessages msgs = processForm(user, server, f, request);
      strutsDelegate.saveMessages(request, msgs);

      String mode = (String) f.get("mode");
      forward =
          strutsDelegate.forwardParams(
              mapping.findForward(getForward(mode)), request.getParameterMap());
    }

    return forward;
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {
    RequestContext context = new RequestContext(request);
    User user = context.getCurrentUser();
    Long sid = context.getRequiredParam("sid");
    Server server = SystemManager.lookupByIdAndUser(sid, user);
    Long xid = context.getRequiredParam("xid");
    XccdfTestResult testResult = ScapFactory.lookupTestResultByIdAndSid(xid, server.getId());
    request.setAttribute("testResult", testResult);
    request.setAttribute("system", server);

    ListHelper helper = new ListHelper(this, request);
    helper.execute();

    request.setAttribute(
        ListTagHelper.PARENT_URL, request.getRequestURI() + "?sid=" + sid + "&xid=" + xid);
    SdcHelper.ssmCheck(request, sid, user);

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
  /**
   * Executes the appropriate PackageAction
   *
   * @param mapping ActionMapping
   * @param formIn ActionForm
   * @param request ServletRequest
   * @param response ServletResponse
   * @return The ActionForward to go to next.
   */
  public ActionForward executePackageAction(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    StrutsDelegate strutsDelegate = getStrutsDelegate();

    Long sid = requestContext.getRequiredParam("sid");
    User user = requestContext.getCurrentUser();
    // updateList(newactions, user.getId());

    List<Map<String, Long>> data = PackageListItem.toKeyMaps(getDataResult(request));
    int numPackages = data.size();

    // Archive the actions
    Server server = SystemManager.lookupByIdAndUser(sid, user);

    // The earliest time to perform the action.
    DynaActionForm dynaActionForm = (DynaActionForm) formIn;
    Date earliest =
        getStrutsDelegate().readDatePicker(dynaActionForm, "date", DatePicker.YEAR_RANGE_POSITIVE);

    // The action chain to append this action to, if any
    ActionChain actionChain = ActionChainHelper.readActionChain(dynaActionForm, user);

    PackageAction pa = schedulePackageAction(formIn, requestContext, data, earliest, actionChain);

    // Remove the actions from the users set
    SessionSetHelper.obliterate(request, getDecl(sid));

    ActionMessages msgs = new ActionMessages();

    if (actionChain == null) {
      /**
       * If there was only one action archived, display the "action" archived message, else display
       * the "actions" archived message.
       */
      if (numPackages == 1) {
        msgs.add(
            ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage(
                getMessageKeyForOne(),
                LocalizationService.getInstance().formatNumber(numPackages),
                pa.getId().toString(),
                sid.toString(),
                StringUtil.htmlifyText(server.getName())));
      } else {
        msgs.add(
            ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage(
                getMessageKeyForMany(),
                LocalizationService.getInstance().formatNumber(numPackages),
                pa.getId().toString(),
                sid.toString(),
                StringUtil.htmlifyText(server.getName())));
      }
    } else {
      msgs.add(
          ActionMessages.GLOBAL_MESSAGE,
          new ActionMessage(
              "message.addedtoactionchain",
              actionChain.getId(),
              StringUtil.htmlifyText(actionChain.getLabel())));
    }

    strutsDelegate.saveMessages(request, msgs);
    Map params = new HashMap();
    processParamMap(formIn, request, params);
    return strutsDelegate.forwardParams(mapping.findForward(RhnHelper.CONFIRM_FORWARD), params);
  }
  /**
   * The first step in the wizard
   *
   * @param mapping ActionMapping for struts
   * @param form DynaActionForm representing the form
   * @param ctx RequestContext request context
   * @param response HttpServletResponse response object
   * @param step WizardStep what step are we on?
   * @return ActionForward struts action forward
   * @throws Exception if something goes amiss
   */
  public ActionForward runFirst(
      ActionMapping mapping,
      DynaActionForm form,
      RequestContext ctx,
      HttpServletResponse response,
      WizardStep step)
      throws Exception {
    log.debug("runFirst");
    Long sid = (Long) form.get(RequestContext.SID);
    User user = ctx.getCurrentUser();

    KickstartScheduleCommand cmd = getKickstartScheduleCommand(sid, user);

    Server system = SystemManager.lookupByIdAndUser(sid, user);
    if (system.isVirtualGuest()
        && VirtualInstanceFactory.getInstance()
            .getParaVirtType()
            .equals(system.getVirtualInstance().getType())) {
      ctx.getRequest().setAttribute(IS_VIRTUAL_GUEST, Boolean.TRUE.toString());

      ctx.getRequest().setAttribute(VIRT_HOST_IS_REGISTERED, Boolean.FALSE.toString());
      if (system.getVirtualInstance().getHostSystem() != null) {
        Long hostSid = system.getVirtualInstance().getHostSystem().getId();
        ctx.getRequest().setAttribute(VIRT_HOST_IS_REGISTERED, Boolean.TRUE.toString());
        ctx.getRequest().setAttribute(HOST_SID, hostSid);
      }
    } else {
      ctx.getRequest().setAttribute(IS_VIRTUAL_GUEST, Boolean.FALSE.toString());
    }

    addRequestAttributes(ctx, cmd, form);
    checkForKickstart(form, cmd, ctx);
    setupProxyInfo(ctx);
    if (StringUtils.isBlank(form.getString(PROXY_HOST))) {
      form.set(PROXY_HOST, "");
    }
    // create and prepopulate the date picker.
    getStrutsDelegate()
        .prepopulateDatePicker(ctx.getRequest(), form, "date", DatePicker.YEAR_RANGE_POSITIVE);

    SdcHelper.ssmCheck(ctx.getRequest(), system.getId(), user);
    Map params = new HashMap<String, String>();
    params.put(RequestContext.SID, sid);
    ListHelper helper = new ListHelper(new Profiles(), ctx.getRequest(), params);
    helper.execute();
    if (!StringUtils.isBlank(form.getString(RequestContext.COBBLER_ID))) {
      ListTagHelper.selectRadioValue(
          ListHelper.LIST, form.getString(RequestContext.COBBLER_ID), ctx.getRequest());
    } else if (system.getCobblerId() != null) {
      // if nothing is selected by the user yet, use the cobbler
      //  system record to pre-select something.
      SystemRecord rec =
          SystemRecord.lookupById(
              CobblerXMLRPCHelper.getConnection(ConfigDefaults.get().getCobblerAutomatedUser()),
              system.getCobblerId());
      if (rec != null) {
        ListTagHelper.selectRadioValue(ListHelper.LIST, rec.getProfile().getId(), ctx.getRequest());
      }
    }

    ActionForward retval = mapping.findForward("first");
    return retval;
  }