/**
   * Cancel existing kickstart sessions on the host server for the system to be kickstarted (the
   * target server).
   */
  private void cancelExistingSessions() {
    Server hostServer = getHostServer();

    List sessions = KickstartFactory.lookupAllKickstartSessionsByServer(hostServer.getId());
    if (sessions != null) {
      log.debug("    Found sessions: " + sessions);
      Iterator i = sessions.iterator();
      while (i.hasNext()) {
        KickstartSession sess = (KickstartSession) i.next();
        if (sess != null && sess.getState() != null) {
          log.debug(
              "    Working with session: " + sess.getState().getLabel() + " id: " + sess.getId());
        }
        KickstartSessionState state = sess.getState();

        if (!state.equals(KickstartFactory.SESSION_STATE_FAILED)
            || !state.equals(KickstartFactory.SESSION_STATE_COMPLETE)) {
          log.debug(
              "    need to cancel this Session this.s: "
                  + hostServer.getId()
                  + " sess.hostServer: "
                  + (sess.getHostServer() == null ? "null" : "" + sess.getHostServer().getId()));
          if (sess.getHostServer() != null
              && sess.getHostServer().getId().equals(hostServer.getId())) {
            log.debug("    Marking session failed.");
            sess.markFailed(
                LocalizationService.getInstance().getMessage("kickstart.session.newsession"));
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
  public void testKsSessionPathparse() throws Exception {
    user.addPermanentRole(RoleFactory.ORG_ADMIN);
    KickstartSession session = KickstartSessionTest.createKickstartSession(ksdata, user);
    KickstartFactory.saveKickstartSession(session);
    session = (KickstartSession) reload(session);
    assertNotSame(session.getState(), KickstartFactory.SESSION_STATE_CONFIG_ACCESSED);

    String encodedSession = SessionSwap.encodeData(session.getId().toString());
    // URL: /kickstart/ks/session/2xb7d56e8958b0425e762cc74e8705d8e7
    String url = "http://rhn.redhat.com/session/ks/session/" + encodedSession;
    request.setAttribute(RequestContext.REQUESTED_URI, url);
    Map<String, Object> options = helper.parseKickstartUrl(url);
    assertNotNull(options);
    assertNotNull(options.get("org_id"));
    assertNotNull(options.get("ksdata"));
    assertNotNull(options.get("session"));
    assertNotNull(options.get("host"));
    assertEquals(session.getState(), KickstartFactory.SESSION_STATE_CONFIG_ACCESSED);
  }
  /**
   * @param firstAction The first Action in the session's action chain
   *     <p>return Returns the KickstartSession.
   */
  protected KickstartSession setupKickstartSession(Action firstAction) {
    kickstartSession = new KickstartSession();
    Boolean deployConfig = this.getKsdata().getKickstartDefaults().getCfgManagementFlag();

    // TODO: Proxy logic

    // Setup the KickstartSession
    kickstartSession.setPackageFetchCount(new Long(0));
    kickstartSession.setKickstartMode(KickstartSession.MODE_ONETIME);
    kickstartSession.setDeployConfigs(deployConfig);
    kickstartSession.setAction(firstAction);
    kickstartSession.setKsdata(this.getKsdata());
    kickstartSession.setKstree(this.getKsdata().getTree());
    kickstartSession.setVirtualizationType(
        this.getKsdata().getKickstartDefaults().getVirtualizationType());
    kickstartSession.setLastAction(new Date());
    kickstartSession.setNewServer(this.getTargetServer());
    kickstartSession.setOldServer(this.getTargetServer());
    kickstartSession.setHostServer(this.getHostServer());
    kickstartSession.setUser(this.getUser());
    kickstartSession.setState(KickstartFactory.SESSION_STATE_CREATED);
    kickstartSession.setOrg(this.getUser().getOrg());
    kickstartSession.setSystemRhnHost(this.getProxyHost());
    kickstartSession.setVirtualizationType(
        this.getKsdata().getKickstartDefaults().getVirtualizationType());
    log.debug("** Saving new KickstartSession: " + kickstartSession.getId());
    KickstartFactory.saveKickstartSession(kickstartSession);
    log.debug("** Saved new KickstartSession: " + kickstartSession.getId());

    return kickstartSession;
  }