Ejemplo n.º 1
0
 static ReaderWriterResult getOrCreateReaderWriterItem(final StepContext stepContext) {
   ReaderWriterResult result = (ReaderWriterResult) stepContext.getPersistentUserData();
   if (result == null) {
     result = new ReaderWriterResult();
     stepContext.setPersistentUserData(result);
   }
   return result;
 }
Ejemplo n.º 2
0
  @Override
  public NumbersRecord readItem() throws Exception {
    int i = readerIndex;

    // Throw an exception when forcedFailCount is reached
    if (forcedFailCount != 0 && readerIndex >= forcedFailCount) {
      forcedFailCount = 0;
      failindex = readerIndex;
      testState = STATE_RETRY;
      Reporter.log("Fail on purpose NumbersRecord.readItem<p>");
      throw new MyParentException("Fail on purpose in NumbersRecord.readItem()");
    }

    if (testState == STATE_RETRY) {
      if (stepCtx.getProperties().getProperty("retry.read.exception.invoked") != "true") {
        Reporter.log("onRetryReadException not invoked<p>");
        throw new Exception("onRetryReadException not invoked");
      }

      if (stepCtx.getProperties().getProperty("retry.read.exception.match") != "true") {
        Reporter.log("retryable exception does not match");
        throw new Exception("retryable exception does not match");
      }

      testState = STATE_NORMAL;
    }

    if (readerIndex > 5) {
      return null;
    }

    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet rs = null;

    try {
      connection = RetryConnectionHelper.getConnection(dataSource);

      statement = connection.prepareStatement(RetryConnectionHelper.SELECT_NUMBERS);
      statement.setInt(1, readerIndex);
      rs = statement.executeQuery();

      int quantity = -1;
      while (rs.next()) {
        quantity = rs.getInt("quantity");
      }

      readerIndex++;

      return new NumbersRecord(i, quantity);
    } catch (SQLException e) {
      throw e;
    } finally {
      RetryConnectionHelper.cleanupConnection(connection, rs, statement);
    }
  }
  @Override
  public String process() throws Exception {
    logger.fine(sourceClass + ".process()");

    // Do something a bit "compute-intensive".
    Random r = new Random();
    int x = r.nextInt();
    int y = r.nextInt();
    for (int i = 0; i < 10; i++) {
      x = (y * x) % 3469;
      y = (x * y) % 3491;
    }

    // This is the ongoing appending to the JOB exit status
    String exitStatus = null;
    try {
      exitStatus = contributeToExitStatus();
      appendToJobContext(exitStatus);
    } catch (FailViaException e) {
      logger.fine(sourceClass + ".process(); Exiting with exitStatus = " + exitStatus);
      String errorAppend = (String) jobCtx.getTransientUserData();
      appendToJobContext(errorAppend);
      throw new RuntimeException("Throwing exception on purpose");
    }

    logger.fine(sourceClass + ".process(); exitStatus = " + exitStatus);

    // Now we're going to switch gears and consider the step exit Status
    if (exitStatus.startsWith("s")) {
      logger.fine(
          "For step exitStatus for step: "
              + stepCtx.getStepName()
              + " , return: "
              + JSL_STOP_TRANSITION);
      return JSL_STOP_TRANSITION;
    } else if (exitStatus.startsWith("f")) {
      logger.fine(
          "For step exitStatus for step: "
              + stepCtx.getStepName()
              + " , return: "
              + JSL_FAIL_TRANSITION);
      return JSL_FAIL_TRANSITION;
    } else {
      logger.fine(
          "For step exitStatus for step: " + stepCtx.getStepName() + " , don't return value");
      return null;
    }
  }
Ejemplo n.º 4
0
 @Override
 public Serializable checkpointInfo() throws Exception {
   NumbersCheckpointData _chkptData = new NumbersCheckpointData();
   _chkptData.setCount(readerIndex);
   stepCtx.getProperties().setProperty("checkpoint.index", Integer.toString(readerIndex));
   return _chkptData;
 }
Ejemplo n.º 5
0
  public void open(Serializable cpd) throws NamingException {

    InventoryCheckpointData checkpointData = (InventoryCheckpointData) cpd;

    InitialContext ctx = new InitialContext();
    dataSource = (DataSource) ctx.lookup(ConnectionHelper.jndiName);

    if (cpd != null) {
      this.readerIndex = checkpointData.getInventoryCount();

      stepCtx.getProperties().setProperty("init.checkpoint", this.readerIndex + "");
    }
  }
Ejemplo n.º 6
0
  public void open(Serializable cpd) throws NamingException {

    NumbersCheckpointData numbersCheckpointData = (NumbersCheckpointData) cpd;

    forcedFailCount = Integer.parseInt(forcedFailCountProp);

    InitialContext ctx = new InitialContext();
    dataSource = (DataSource) ctx.lookup(RetryConnectionHelper.jndiName);

    if (cpd != null) {
      forcedFailCount = 0;
      this.readerIndex = numbersCheckpointData.getCount();
      stepCtx.getProperties().setProperty("init.checkpoint", this.readerIndex + "");
    }
  }
Ejemplo n.º 7
0
 @Override
 public void analyzeStatus(final BatchStatus batchStatus, final String exitStatus)
     throws Exception {
   // the check for number of threads used is not very accurate.  The underlying thread pool
   // may choose a cold thread even when a warm thread has already been returned to pool and
   // available.
   // especially when thread.count is 1, there may be 2 or more threads being used, but at one
   // point,
   // there should be only 1 active thread running partition.
   numOfCompletedPartitions++;
   if (numOfCompletedPartitions == 3 && !skipThreadCheck) { // partitions in job xml
     if (childThreadIds.size() <= threadCount) { // threads in job xml
       stepContext.setExitStatus(
           String.format(
               "PASS: Max allowable thread count %s, actual threads %s",
               threadCount, childThreadIds.size()));
     } else {
       stepContext.setExitStatus(
           String.format(
               "FAIL: Expecting max thread count %s, but got %s",
               threadCount, childThreadIds.size()));
     }
   }
 }
Ejemplo n.º 8
0
 static ReaderWriterResult getReaderWriterItem(final StepContext stepContext) {
   return (ReaderWriterResult) stepContext.getPersistentUserData();
 }
  private String contributeToExitStatus() throws FailViaException {
    logger.fine(sourceClass + ".calculateExitStatus(), runNumberString = " + runNumberString);

    // runNumberString = runNumber.N
    int execNum = Integer.parseInt(runNumberString.substring(new String("runNumber.").length()));

    String stepId = stepCtx.getStepName();

    logger.fine(
        sourceClass + ".calculateExitStatus(), execution # = " + execNum + ", stepId = " + stepId);

    if (stepId.equals("step1")) {
      switch (execNum) {
        case 1:
          return "c1";
        case 2:
          return "c1";
        case 3:
          return "c1";
        case 4:
          return "c1";
        case 5:
          return "ILLEGAL.STATE";
        case 6:
          return "c1";
        case 7:
          return "c1";
        default:
          return "ILLEGAL.STATE";
      }
    } else if (stepId.equals("step2")) {
      switch (execNum) {
        case 1:
          return "c2";
        case 2:
          return "c2";
        case 3:
          return "c2";
        case 4:
          return "c2";
        case 5:
          return "ILLEGAL.STATE";
        case 6:
          return "c2";
        case 7:
          return "c2";
        default:
          return "ILLEGAL.STATE";
      }
    } else if (stepId.equals("step3")) {
      switch (execNum) {
        case 1:
          throw new FailViaException();
        case 2:
          throw new FailViaException();
        case 3:
          return "s3";
        case 4:
          return "ILLEGAL.STATE";
        case 5:
          return "ILLEGAL.STATE";
        case 6:
          return "ILLEGAL.STATE";
        case 7:
          return "ILLEGAL.STATE";
        default:
          return "ILLEGAL.STATE";
      }
    } else if (stepId.equals("step4")) {
      switch (execNum) {
        case 1:
          return "ILLEGAL.STATE";
        case 2:
          return "ILLEGAL.STATE";
        case 3:
          return "ILLEGAL.STATE";
        case 4:
          return "s4";
        case 5:
          return "f4";
        case 6:
          return "c4";
          // Should not be able to rexecute a fourth time on run 7
        default:
          return "ILLEGAL.STATE";
      }
    } else if (stepId.equals("step5")) {
      switch (execNum) {
          // Only gets to run on run #6
        case 6:
          return "f5";
        default:
          return "ILLEGAL.STATE";
      }
    } else {
      return "ILLEGAL.STATE";
    }
  }