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

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


    Barrier barrier = Barrier.dummyInstanceForTesting();
    for (Object value : slotValues) {
      if (value instanceof ListMarker) {
        List<?> valueList = ((ListMarker) value).valueList;
        List<Slot> slotList = new ArrayList<>(valueList.size());
        Slot dummyListSlot = createDummySlot();
        dummyListSlot.fill(null);
        for (Object v : valueList) {
          Slot slot = createDummySlot();
          slot.fill(v);
          slotList.add(slot);
        }
        barrier.addListArgumentSlots(dummyListSlot, slotList);
      } else if (value instanceof PhantomMarker) {
        Slot slot = createDummySlot();
        slot.fill(((PhantomMarker) value).value);
        barrier.addPhantomArgumentSlot(slot);
      } else {
        Slot slot = createDummySlot();
        slot.fill(value);
        barrier.addRegularArgumentSlot(slot);
      }

    }
    Object[] arguments = barrier.buildArgumentArray();
View Full Code Here


    }
  }

  public static Slot createDummySlot() {
    Key dummyKey = KeyFactory.createKey("dummy", "dummy");
    return new Slot(dummyKey, dummyKey, "abc");
  }
View Full Code Here

    if (0 == jobRecord.getRunBarrierInflated().getWaitingOnKeys().size()) {
      // If the run barrier is not waiting on anything, add a phantom filled
      // slot in order to trigger a HandleSlotFilledTask in order to trigger
      // a RunJobTask.
      Slot slot = new Slot(jobRecord.getRootJobKey(), generatorKey, graphGuid);
      jobRecord.getRunBarrierInflated().addPhantomArgumentSlot(slot);
      registerSlotFilled(updateSpec, jobRecord.getQueueSettings(), slot, null);
    }

    // Register the newly created objects with the UpdateSpec.
View Full Code Here

      Object concreteValue = null;
      if (null != value) {
        ImmediateValue<?> iv = (ImmediateValue<?>) value;
        concreteValue = iv.getValue();
      }
      Slot slot = new Slot(rootJobKey, generatorJobKey, graphGUID);
      registerSlotFilled(updateSpec, queueSettings, slot, concreteValue);
      barrier.addRegularArgumentSlot(slot);
    } else if (value instanceof FutureValueImpl<?>) {
      FutureValueImpl<?> futureValue = (FutureValueImpl<?>) value;
      Slot slot = futureValue.getSlot();
      barrier.addRegularArgumentSlot(slot);
      updateSpec.getNonTransactionalGroup().includeSlot(slot);
    } else if (value instanceof FutureList<?>) {
      FutureList<?> futureList = (FutureList<?>) value;
      List<Slot> slotList = new ArrayList<>(futureList.getListOfValues().size());
      // The dummyListSlot is a marker slot that indicates that the
      // next group of slots forms a single list argument.
      Slot dummyListSlot = new Slot(rootJobKey, generatorJobKey, graphGUID);
      registerSlotFilled(updateSpec, queueSettings, dummyListSlot, null);
      for (Value<?> valFromList : futureList.getListOfValues()) {
        Slot slot = null;
        if (valFromList instanceof ImmediateValue<?>) {
          ImmediateValue<?> ivFromList = (ImmediateValue<?>) valFromList;
          slot = new Slot(rootJobKey, generatorJobKey, graphGUID);
          registerSlotFilled(updateSpec, queueSettings, slot, ivFromList.getValue());
        } else if (valFromList instanceof FutureValueImpl<?>) {
          FutureValueImpl<?> futureValFromList = (FutureValueImpl<?>) valFromList;
          slot = futureValFromList.getSlot();
        } else if (value instanceof FutureList<?>) {
View Full Code Here

  public static void acceptPromisedValue(String promiseHandle, Object value)
      throws NoSuchObjectException, OrphanedObjectException {
    checkNonEmpty(promiseHandle, "promiseHandle");
    Key key = KeyFactory.stringToKey(promiseHandle);
    Slot slot = null;
    // It is possible, though unlikely, that we might be asked to accept a
    // promise before the slot to hold the promise has been saved. We will try 5
    // times, sleeping 1, 2, 4, 8 seconds between attempts.
    int attempts = 0;
    boolean interrupted = false;
    try {
      while (slot == null) {
        attempts++;
        try {
          slot = backEnd.querySlot(key, false);
        } catch (NoSuchObjectException e) {
          if (attempts >= 5) {
            throw new NoSuchObjectException("There is no promise with handle " + promiseHandle);
          }
          try {
            Thread.sleep((long) Math.pow(2.0, attempts - 1) * 1000L);
          } catch (InterruptedException f) {
            interrupted = true;
          }
        }
      }
    } finally {
      // TODO(user): replace with Uninterruptibles#sleepUninterruptibly once we use guava
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
    Key generatorJobKey = slot.getGeneratorJobKey();
    if (null == generatorJobKey) {
      throw new RuntimeException(
          "Pipeline is fatally corrupted. Slot for promised value has no generatorJobKey: " + slot);
    }
    JobRecord generatorJob = backEnd.queryJob(generatorJobKey, JobRecord.InflationType.NONE);
    if (null == generatorJob) {
      throw new RuntimeException("Pipeline is fatally corrupted. "
          + "The generator job for a promised value slot was not found: " + generatorJobKey);
    }
    String childGraphGuid = generatorJob.getChildGraphGuid();
    if (null == childGraphGuid) {
      // The generator job has not been saved with a childGraphGuid yet. This can happen if the
      // promise handle leaked out to an external thread before the job that generated it
      // had finished.
      throw new NoSuchObjectException(
          "The framework is not ready to accept the promised value yet. "
          + "Please try again after the job that generated the promis handle has completed.");
    }
    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

    }
    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

   * Release the barrier by enqueueing an appropriate task (either
   * {@link RunJobTask} or {@link FinalizeJobTask}.
   */
  private static void handleSlotFilled(HandleSlotFilledTask hsfTask) {
    Key slotKey = hsfTask.getSlotKey();
    Slot slot = querySlotOrAbandonTask(slotKey, true);
    List<Barrier> waitingList = slot.getWaitingOnMeInflated();
    if (null == waitingList) {
      throw new RuntimeException("Internal logic error: " + slot + " is not inflated");
    }
    // For each barrier that is waiting on the slot ...
    for (Barrier barrier : waitingList) {
View Full Code Here

  /**
   * Fills the slot with null value and calls handleSlotFilled
   */
  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

      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);
View Full Code Here

    Map<Key, Entity> entityMap = getEntities("inflateBarriers", keySet);

    // Step 3. Convert into map from key to Slot
    Map<Key, Slot> slotMap = new HashMap<>(entityMap.size());
    for (Key key : keySet) {
      Slot s = new Slot(entityMap.get(key));
      slotMap.put(key, s);
    }
    // Step 4. Inflate each of the barriers
    for (Barrier barrier : barriers) {
      barrier.inflate(slotMap);
View Full Code Here

TOP

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

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.