Examples of UpdateSpec


Examples of com.google.appengine.tools.pipeline.impl.backend.UpdateSpec

      throw new AbandonTaskException();
    }
    // TODO(user): add jobState check
    JobRecord failedJobRecord =
        queryJobOrAbandonTask(failedChildKey, JobRecord.InflationType.FOR_OUTPUT);
    UpdateSpec updateSpec = new UpdateSpec(rootJobKey);
    cancelChildren(jobRecord, failedChildKey);
    executeExceptionHandler(updateSpec, jobRecord, failedJobRecord.getException(), false);
    backEnd.save(updateSpec, jobRecord.getQueueSettings());
  }
View Full Code Here

Examples of com.google.appengine.tools.pipeline.impl.backend.UpdateSpec

    }

    // release the finalize barrier now so that any concurrent
    // HandleSlotFilled tasks will stop trying
    finalizeBarrier.setReleased();
    UpdateSpec updateSpec = new UpdateSpec(jobRecord.getRootJobKey());
    updateSpec.getOrCreateTransaction("releaseFinalizeBarrier").includeBarrier(finalizeBarrier);
    backEnd.save(updateSpec, jobRecord.getQueueSettings());

    updateSpec = new UpdateSpec(jobRecord.getRootJobKey());
    // Copy the finalize value to the output slot
    List<Object> finalizeArguments = finalizeBarrier.buildArgumentList();
    int numFinalizeArguments = finalizeArguments.size();
    if (1 != numFinalizeArguments) {
      throw new RuntimeException(
          "Internal logic error: numFinalizeArguments=" + numFinalizeArguments);
    }
    Object finalizeValue = finalizeArguments.get(0);
    logger.finest("Finalizing " + jobRecord + " with value=" + finalizeValue);
    outputSlot.fill(finalizeValue);

    // Change state of the job to FINALIZED and set the end time
    jobRecord.setState(State.FINALIZED);
    jobRecord.setEndTime(new Date());

    // Propagate the filler of the finalize slot to also be the filler of the
    // output slot. If there is no unique filler of the finalize slot then we
    // resort to assigning the current job as the filler job.
    Key fillerJobKey = getFinalizeSlotFiller(finalizeBarrier);
    if (null == fillerJobKey) {
      fillerJobKey = jobKey;
    }
    outputSlot.setSourceJobKey(fillerJobKey);

    // Save the job and the output slot
    updateSpec.getNonTransactionalGroup().includeJob(jobRecord);
    updateSpec.getNonTransactionalGroup().includeSlot(outputSlot);
    backEnd.save(updateSpec, jobRecord.getQueueSettings());

    // enqueue a HandleSlotFilled task
    HandleSlotFilledTask task =
        new HandleSlotFilledTask(outputSlot.getKey(), jobRecord.getQueueSettings());
View Full Code Here

Examples of com.google.appengine.tools.pipeline.impl.backend.UpdateSpec

   */
  private static void handleDelayedSlotFill(DelayedSlotFillTask task) {
    Key slotKey = task.getSlotKey();
    Slot slot = querySlotOrAbandonTask(slotKey, true);
    Key rootJobKey = task.getRootJobKey();
    UpdateSpec updateSpec = new UpdateSpec(rootJobKey);
    slot.fill(null);
    updateSpec.getNonTransactionalGroup().includeSlot(slot);
    backEnd.save(updateSpec, task.getQueueSettings());
    // re-reading Slot (in handleSlotFilled) is needed (to capture slot fill after this one)
    handleSlotFilled(new HandleSlotFilledTask(slotKey, task.getQueueSettings()));
  }
View Full Code Here

Examples of com.google.appengine.tools.pipeline.impl.backend.UpdateSpec

   * @return The pipelineID of the newly created pipeline, also known as the
   *         rootJobID.
   */
  public static String startNewPipeline(
      JobSetting[] settings, Job<?> jobInstance, Object... params) {
    UpdateSpec updateSpec = new UpdateSpec(null);
    Job<?> rootJobInstance = jobInstance;
    // If rootJobInstance has exceptionHandler it has to be wrapped to ensure that root job
    // ends up in finalized state in case of exception of run method and
    // exceptionHandler returning a result.
    if (JobRecord.isExceptionHandlerSpecified(jobInstance)) {
      rootJobInstance = new RootJobInstance(jobInstance, settings, params);
      params = new Object[0];
    }
    // Create the root Job and its associated Barriers and Slots
    // Passing null for parent JobRecord and graphGUID
    // Create HandleSlotFilledTasks for the input parameters.
    JobRecord jobRecord = registerNewJobRecord(
        updateSpec, settings, null, null, rootJobInstance, params);
    updateSpec.setRootJobKey(jobRecord.getRootJobKey());
    // Save the Pipeline model objects and enqueue the tasks that start the Pipeline executing.
    backEnd.save(updateSpec, jobRecord.getQueueSettings());
    return jobRecord.getKey().getName();
  }
View Full Code Here

Examples of com.google.appengine.tools.pipeline.impl.backend.UpdateSpec

  public static void stopJob(String jobHandle) throws NoSuchObjectException {
    checkNonEmpty(jobHandle, "jobHandle");
    Key key = KeyFactory.createKey(JobRecord.DATA_STORE_KIND, jobHandle);
    JobRecord jobRecord = backEnd.queryJob(key, JobRecord.InflationType.NONE);
    jobRecord.setState(State.STOPPED);
    UpdateSpec updateSpec = new UpdateSpec(jobRecord.getRootJobKey());
    updateSpec.getOrCreateTransaction("stopJob").includeJob(jobRecord);
    backEnd.save(updateSpec, jobRecord.getQueueSettings());
  }
View Full Code Here

Examples of com.google.appengine.tools.pipeline.impl.backend.UpdateSpec

    }
    if (!childGraphGuid.equals(slot.getGraphGuid())) {
      // The slot has been orphaned
      throw new OrphanedObjectException(promiseHandle);
    }
    UpdateSpec updateSpec = new UpdateSpec(slot.getRootJobKey());
    registerSlotFilled(updateSpec, generatorJob.getQueueSettings(), slot, value);
    backEnd.save(updateSpec, generatorJob.getQueueSettings());
  }
View Full Code Here

Examples of com.google.appengine.tools.pipeline.impl.backend.UpdateSpec

    }

    // Release the run barrier now so any concurrent HandleSlotFilled tasks
    // will stop trying to release it.
    runBarrier.setReleased();
    UpdateSpec tempSpec = new UpdateSpec(rootJobKey);
    tempSpec.getOrCreateTransaction("releaseRunBarrier").includeBarrier(runBarrier);
    backEnd.save(tempSpec, jobRecord.getQueueSettings());

    State jobState = jobRecord.getState();
    switch (jobState) {
      case WAITING_TO_RUN:
      case RETRY:
        // OK, proceed
        break;
      case WAITING_TO_FINALIZE:
        logger.info("This job has already been run " + jobRecord);
        return;
      case STOPPED:
        logger.info("This job has been stoped " + jobRecord);
        return;
      case CANCELED:
        logger.info("This job has already been canceled " + jobRecord);
        return;
      case FINALIZED:
        logger.info("This job has already been run " + jobRecord);
        return;
    }

    // Deserialize the instance of Job and set some values on the instance
    JobInstanceRecord record = jobRecord.getJobInstanceInflated();
    if (null == record) {
      throw new RuntimeException(
          "Internal logic error:" + jobRecord + " does not have jobInstanceInflated.");
    }
    Job<?> job = record.getJobInstanceDeserialized();
    UpdateSpec updateSpec = new UpdateSpec(rootJobKey);
    setJobRecord(job, jobRecord);
    String currentRunGUID = GUIDGenerator.nextGUID();
    setCurrentRunGuid(job, currentRunGUID);
    setUpdateSpec(job, updateSpec);

    // Get the run() method we will invoke and its arguments
    Object[] params = runBarrier.buildArgumentArray();
    boolean callExceptionHandler = jobRecord.isCallExceptionHandler();
    Method methodToExecute =
        findJobMethodToInvoke(job.getClass(), callExceptionHandler, params);
    if (callExceptionHandler && methodToExecute == null) {
      // No matching exceptionHandler found. Propagate to the parent.
      Throwable exceptionToHandle = (Throwable) params[0];
      handleExceptionDuringRun(jobRecord, rootJobRecord, currentRunGUID, exceptionToHandle);
      return;
    }
    if (logger.isLoggable(Level.FINEST)) {
      StringBuilder builder = new StringBuilder(1024);
      builder.append("Running " + jobRecord + " with params: ");
      builder.append(StringUtils.toString(params));
      logger.finest(builder.toString());
    }

    // Set the Job's start time and save the jobRecord now before we invoke
    // run(). The start time will be displayed in the UI.
    jobRecord.incrementAttemptNumber();
    jobRecord.setStartTime(new Date());
    tempSpec = new UpdateSpec(jobRecord.getRootJobKey());
    tempSpec.getNonTransactionalGroup().includeJob(jobRecord);
    if (!backEnd.saveWithJobStateCheck(
        tempSpec, jobRecord.getQueueSettings(), jobKey, State.WAITING_TO_RUN, State.RETRY)) {
      logger.info("Ignoring runJob request for job " + jobRecord + " which is not in a"
          + " WAITING_TO_RUN or a RETRY state");
      return;
    }
    //TODO(user): Use the commented code to avoid resetting stack trace of rethrown exceptions
    //    List<Throwable> throwableParams = new ArrayList<Throwable>(params.length);
    //    for (Object param : params) {
    //      if (param instanceof Throwable) {
    //        throwableParams.add((Throwable) param);
    //      }
    //    }
    // Invoke the run or handleException method. This has the side-effect of populating
    // the UpdateSpec with any child job graph generated by the invoked method.
    Value<?> returnValue = null;
    Throwable caughtException = null;
    try {
      methodToExecute.setAccessible(true);
      returnValue = (Value<?>) methodToExecute.invoke(job, params);
    } catch (InvocationTargetException e) {
      caughtException = e.getCause();
    } catch (Throwable e) {
      caughtException = e;
    }
    if (null != caughtException) {
      //TODO(user): use the following condition to keep original exception trace
      //      if (!throwableParams.contains(caughtException)) {
      //      }
      handleExceptionDuringRun(jobRecord, rootJobRecord, currentRunGUID, caughtException);
      return;
    }

    // The run() method returned without error.
    // We do all of the following in a transaction:
    // (1) Check that the job is currently in the state WAITING_TO_RUN or RETRY
    // (2) Change the state of the job to WAITING_TO_FINALIZE
    // (3) Set the finalize slot to be the one generated by the run() method
    // (4) Set the job's child graph GUID to be the currentRunGUID
    // (5) Enqueue a FanoutTask that will fan-out to a set of
    // HandleSlotFilledTasks for each of the slots that were immediately filled
    // by the running of the job.
    // See "http://goto/java-pipeline-model".
    logger.finest("Job returned: " + returnValue);
    registerSlotsWithBarrier(updateSpec, returnValue, rootJobKey, jobRecord.getKey(),
        jobRecord.getQueueSettings(), currentRunGUID, finalizeBarrier);
    jobRecord.setState(State.WAITING_TO_FINALIZE);
    jobRecord.setChildGraphGuid(currentRunGUID);
    updateSpec.getFinalTransaction().includeJob(jobRecord);
    updateSpec.getFinalTransaction().includeBarrier(finalizeBarrier);
    backEnd.saveWithJobStateCheck(
        updateSpec, jobRecord.getQueueSettings(), jobKey, State.WAITING_TO_RUN, State.RETRY);
  }
View Full Code Here

Examples of com.google.appengine.tools.pipeline.impl.backend.UpdateSpec

    // No error handler present. So just mark this job as CANCELED.
    if (logger.isLoggable(Level.FINEST)) {
      logger.finest("Marking " + jobRecord + " as CANCELED");
    }
    jobRecord.setState(State.CANCELED);
    UpdateSpec updateSpec = new UpdateSpec(jobRecord.getRootJobKey());
    updateSpec.getNonTransactionalGroup().includeJob(jobRecord);
    if (jobRecord.isExceptionHandlerSpecified()) {
      executeExceptionHandler(updateSpec, jobRecord, new CancellationException(), true);
    }
    backEnd.save(updateSpec, jobRecord.getQueueSettings());
  }
View Full Code Here

Examples of com.google.appengine.tools.pipeline.impl.backend.UpdateSpec

          caughtException);
    }
    if (jobRecord.isIgnoreException()) {
      return;
    }
    UpdateSpec updateSpec = new UpdateSpec(jobRecord.getRootJobKey());
    ExceptionRecord exceptionRecord = new ExceptionRecord(
        jobRecord.getRootJobKey(), jobRecord.getKey(), currentRunGUID, caughtException);
    updateSpec.getNonTransactionalGroup().includeException(exceptionRecord);
    Key exceptionKey = exceptionRecord.getKey();
    jobRecord.setExceptionKey(exceptionKey);
    if (jobRecord.isCallExceptionHandler() || attemptNumber >= maxAttempts) {
      jobRecord.setState(State.STOPPED);
      updateSpec.getNonTransactionalGroup().includeJob(jobRecord);
      if (jobRecord.isExceptionHandlerSpecified()) {
        cancelChildren(jobRecord, null);
        executeExceptionHandler(updateSpec, jobRecord, caughtException, false);
      } else {
        if (null != jobRecord.getExceptionHandlingAncestorKey()) {
          cancelChildren(jobRecord, null);
          // current job doesn't have an error handler. So just delegate it to the
          // nearest ancestor that has one.
          Task handleChildExceptionTask = new HandleChildExceptionTask(
              jobRecord.getExceptionHandlingAncestorKey(), jobRecord.getKey(),
              jobRecord.getQueueSettings());
          updateSpec.getFinalTransaction().registerTask(handleChildExceptionTask);
        } else {
          rootJobRecord.setState(State.STOPPED);
          rootJobRecord.setExceptionKey(exceptionKey);
          updateSpec.getNonTransactionalGroup().includeJob(rootJobRecord);
        }
      }
      backEnd.save(updateSpec, jobRecord.getQueueSettings());
    } else {
      jobRecord.setState(State.RETRY);
      int backoffFactor = jobRecord.getBackoffFactor();
      int backoffSeconds = jobRecord.getBackoffSeconds();
      RunJobTask task =
          new RunJobTask(jobRecord.getKey(), attemptNumber, jobRecord.getQueueSettings());
      task.getQueueSettings().setDelayInSeconds(
          backoffSeconds * (long) Math.pow(backoffFactor, attemptNumber));
      updateSpec.getFinalTransaction().includeJob(jobRecord);
      updateSpec.getFinalTransaction().registerTask(task);
      backEnd.saveWithJobStateCheck(updateSpec, jobRecord.getQueueSettings(), jobRecord.getKey(),
          State.WAITING_TO_RUN, State.RETRY);
    }
  }
View Full Code Here

Examples of com.google.appengine.tools.pipeline.impl.backend.UpdateSpec

   * @return The pipelineID of the newly created pipeline, also known as the
   *         rootJobID.
   */
  public static String startNewPipeline(
      JobSetting[] settings, Job<?> jobInstance, Object... params) {
    UpdateSpec updateSpec = new UpdateSpec(null);
    String graphGUID = null; // The root job graph doesn't have a GUID
    JobRecord parentJobKey = null; // The root job graph doesn't have a parent
    // Create the root Job and its associated Barriers and Slots
    // Create HandleSlotFilledTasks for the input parameters.
    JobRecord jobRecord =
        registerNewJobRecord(updateSpec, settings, parentJobKey, graphGUID, jobInstance, params);
    updateSpec.setRootJobKey(jobRecord.getRootJobKey());
    // Save the Pipeline model objects and enqueue the tasks that start the
    // Pipeline executing.
    backEnd.save(updateSpec);
    return jobRecord.getKey().getName();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.