Package com.google.appengine.tools.pipeline.impl.model

Examples of com.google.appengine.tools.pipeline.impl.model.JobRecord


      Throwable caughtException, boolean ignoreException) {
    updateSpec.getNonTransactionalGroup().includeJob(jobRecord);
    String errorHandlingGraphGuid = GUIDGenerator.nextGUID();
    Job<?> jobInstance = jobRecord.getJobInstanceInflated().getJobInstanceDeserialized();

    JobRecord errorHandlingJobRecord =
        new JobRecord(jobRecord, errorHandlingGraphGuid, jobInstance, true, new JobSetting[0]);
    errorHandlingJobRecord.setOutputSlotInflated(jobRecord.getOutputSlotInflated());
    errorHandlingJobRecord.setIgnoreException(ignoreException);
    registerNewJobRecord(updateSpec, errorHandlingJobRecord,
        new Object[] {new ImmediateValue<>(caughtException)});
  }
View Full Code Here


  }

  private static void handleChildException(HandleChildExceptionTask handleChildExceptionTask) {
    Key jobKey = handleChildExceptionTask.getKey();
    Key failedChildKey = handleChildExceptionTask.getFailedChildKey();
    JobRecord jobRecord = queryJobOrAbandonTask(jobKey, JobRecord.InflationType.FOR_RUN);
    jobRecord.getQueueSettings().merge(handleChildExceptionTask.getQueueSettings());
    Key rootJobKey = jobRecord.getRootJobKey();
    logger.info("Running pipeline job " + jobKey.getName() + " exception handler; UI at "
        + PipelineServlet.makeViewerUrl(rootJobKey, jobKey));
    JobRecord rootJobRecord;
    if (rootJobKey.equals(jobKey)) {
      rootJobRecord = jobRecord;
    } else {
      rootJobRecord = queryJobOrAbandonTask(rootJobKey, JobRecord.InflationType.NONE);
    }
    if (rootJobRecord.getState() == State.STOPPED) {
      logger.warning("The pipeline has been stopped: " + rootJobRecord);
      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

   */
  private static void finalizeJob(FinalizeJobTask finalizeJobTask) {
    Key jobKey = finalizeJobTask.getJobKey();
    // Get the JobRecord, its finalize Barrier, all the slots in the
    // finalize Barrier, and the job's output Slot.
    JobRecord jobRecord = queryJobOrAbandonTask(jobKey, JobRecord.InflationType.FOR_FINALIZE);
    jobRecord.getQueueSettings().merge(finalizeJobTask.getQueueSettings());
    switch (jobRecord.getState()) {
      case WAITING_TO_FINALIZE:
        // OK, proceed
        break;
      case WAITING_TO_RUN:
      case RETRY:
        throw new RuntimeException("" + jobRecord + " is in RETRY state");
      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;
    }
    Barrier finalizeBarrier = jobRecord.getFinalizeBarrierInflated();
    if (null == finalizeBarrier) {
      throw new RuntimeException("" + jobRecord + " has not been inflated");
    }
    Slot outputSlot = jobRecord.getOutputSlotInflated();
    if (null == outputSlot) {
      throw new RuntimeException("" + jobRecord + " has not been inflated.");
    }

    // 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());
    backEnd.enqueue(task);
  }
View Full Code Here

            break;
          }
        }
        if (shouldBeReleased) {
          Key jobKey = barrier.getJobKey();
          JobRecord jobRecord = queryJobOrAbandonTask(jobKey, JobRecord.InflationType.NONE);
          jobRecord.getQueueSettings().merge(hsfTask.getQueueSettings());
          Task task;
          switch (barrier.getType()) {
            case RUN:
              task = new RunJobTask(jobKey, jobRecord.getQueueSettings());
              break;
            case FINALIZE:
              task = new FinalizeJobTask(jobKey, jobRecord.getQueueSettings());
              break;
            default:
              throw new RuntimeException("Unknown barrier type " + barrier.getType());
          }
          try {
View Full Code Here

          entity = dataStore.get(jobKey);
        } catch (EntityNotFoundException e) {
          throw new RuntimeException(
              "Fatal Pipeline corruption error. No JobRecord found with key = " + jobKey);
        }
        JobRecord jobRecord = new JobRecord(entity);
        JobRecord.State state = jobRecord.getState();
        boolean stateIsExpected = false;
        for (JobRecord.State expectedState : expectedStates) {
          if (state == expectedState) {
            stateIsExpected = true;
            break;
View Full Code Here

  @Override
  public JobRecord queryJob(final Key jobKey, final JobRecord.InflationType inflationType)
      throws NoSuchObjectException {
    Entity entity = getEntity("queryJob", jobKey);
    JobRecord jobRecord = new JobRecord(entity);
    Barrier runBarrier = null;
    Barrier finalizeBarrier = null;
    Slot outputSlot = null;
    JobInstanceRecord jobInstanceRecord = null;
    ExceptionRecord failureRecord = null;
    switch (inflationType) {
      case FOR_RUN:
        runBarrier = queryBarrier(jobRecord.getRunBarrierKey(), true);
        finalizeBarrier = queryBarrier(jobRecord.getFinalizeBarrierKey(), false);
        jobInstanceRecord =
            new JobInstanceRecord(getEntity("queryJob", jobRecord.getJobInstanceKey()));
        outputSlot = querySlot(jobRecord.getOutputSlotKey(), false);
        break;
      case FOR_FINALIZE:
        finalizeBarrier = queryBarrier(jobRecord.getFinalizeBarrierKey(), true);
        outputSlot = querySlot(jobRecord.getOutputSlotKey(), false);
        break;
      case FOR_OUTPUT:
        outputSlot = querySlot(jobRecord.getOutputSlotKey(), false);
        Key failureKey = jobRecord.getExceptionKey();
        failureRecord = queryFailure(failureKey);
        break;
      default:
    }
    jobRecord.inflate(runBarrier, finalizeBarrier, outputSlot, jobInstanceRecord, failureRecord);
    logger.finest("Query returned: " + jobRecord);
    return jobRecord;
  }
View Full Code Here

            while (entities.hasNext()) {
              if (limit > 0 && roots.size() >= limit) {
                dsCursor = entities.getCursor();
                break;
              }
              JobRecord jobRecord = new JobRecord(entities.next());
              roots.add(jobRecord);
            }
            return Pair.of(roots, dsCursor == null ? null : dsCursor.toWebSafeString());
          }
        });
View Full Code Here

    }
    for (Entity entity : queryAll(Slot.DATA_STORE_KIND, rootJobKey)) {
      slots.put(entity.getKey(), new Slot(entity, true));
    }
    for (Entity entity : queryAll(JobRecord.DATA_STORE_KIND, rootJobKey)) {
      jobs.put(entity.getKey(), new JobRecord(entity));
    }
    for (Entity entity : queryAll(JobInstanceRecord.DATA_STORE_KIND, rootJobKey)) {
      jobInstanceRecords.put(entity.getKey(), new JobInstanceRecord(entity));
    }
    for (Entity entity : queryAll(ExceptionRecord.DATA_STORE_KIND, rootJobKey)) {
View Full Code Here

  @Override
  public void deletePipeline(Key rootJobKey, boolean force, boolean async)
      throws IllegalStateException {
    if (!force) {
      try {
        JobRecord rootJobRecord = queryJob(rootJobKey, JobRecord.InflationType.NONE);
        switch (rootJobRecord.getState()) {
          case FINALIZED:
          case STOPPED:
            break;
          default:
            throw new IllegalStateException("Pipeline is still running: " + rootJobRecord);
View Full Code Here

    String rootJobHandle = req.getParameter(ROOT_PIPELINE_ID);
    if (null == rootJobHandle) {
      throw new ServletException(ROOT_PIPELINE_ID + " parameter not found.");
    }
    try {
      JobRecord jobInfo;
      try {
        jobInfo = PipelineManager.getJob(rootJobHandle);
      } catch (NoSuchObjectException nsoe) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
      }
      String rootJobKey = jobInfo.getRootJobKey().getName();
      if (!rootJobKey.equals(rootJobHandle)) {
        resp.addHeader(ROOT_PIPELINE_ID, rootJobKey);
        resp.sendError(449, rootJobKey);
        return;
      }
View Full Code Here

TOP

Related Classes of com.google.appengine.tools.pipeline.impl.model.JobRecord

Copyright © 2018 www.massapicom. 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.