Java Code Examples for com.google.longrunning.Operation#getName()

The following examples show how to use com.google.longrunning.Operation#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisShardBackplane.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
@Override
public void queue(QueueEntry queueEntry, Operation operation) throws IOException {
  String operationName = operation.getName();
  String operationJson = operationPrinter.print(operation);
  String queueEntryJson = JsonFormat.printer().print(queueEntry);
  Operation publishOperation = onPublish.apply(operation);
  client.run(
      jedis -> {
        jedis.setex(operationKey(operationName), config.getOperationExpire(), operationJson);
        queue(
            jedis,
            operation.getName(),
            queueEntry.getPlatform().getPropertiesList(),
            queueEntryJson);
        publishReset(jedis, publishOperation);
      });
}
 
Example 2
Source File: AbstractServerInstance.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
protected static RequestMetadata expectRequestMetadata(Operation operation) {
  String name = operation.getName();
  Any metadata = operation.getMetadata();
  QueuedOperationMetadata queuedOperationMetadata = maybeQueuedOperationMetadata(name, metadata);
  if (queuedOperationMetadata != null) {
    return queuedOperationMetadata.getRequestMetadata();
  }
  ExecutingOperationMetadata executingOperationMetadata =
      maybeExecutingOperationMetadata(name, metadata);
  if (executingOperationMetadata != null) {
    return executingOperationMetadata.getRequestMetadata();
  }
  CompletedOperationMetadata completedOperationMetadata =
      maybeCompletedOperationMetadata(name, metadata);
  if (completedOperationMetadata != null) {
    return completedOperationMetadata.getRequestMetadata();
  }
  return RequestMetadata.getDefaultInstance();
}
 
Example 3
Source File: AbstractServerInstance.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
protected static ExecuteOperationMetadata expectExecuteOperationMetadata(Operation operation) {
  String name = operation.getName();
  Any metadata = operation.getMetadata();
  QueuedOperationMetadata queuedOperationMetadata = maybeQueuedOperationMetadata(name, metadata);
  if (queuedOperationMetadata != null) {
    return queuedOperationMetadata.getExecuteOperationMetadata();
  }
  ExecutingOperationMetadata executingOperationMetadata =
      maybeExecutingOperationMetadata(name, metadata);
  if (executingOperationMetadata != null) {
    return executingOperationMetadata.getExecuteOperationMetadata();
  }
  CompletedOperationMetadata completedOperationMetadata =
      maybeCompletedOperationMetadata(name, metadata);
  if (completedOperationMetadata != null) {
    return completedOperationMetadata.getExecuteOperationMetadata();
  }
  try {
    return operation.getMetadata().unpack(ExecuteOperationMetadata.class);
  } catch (InvalidProtocolBufferException e) {
    logger.log(
        Level.SEVERE, format("invalid execute operation metadata %s", operation.getName()), e);
  }
  return null;
}
 
Example 4
Source File: AbstractServerInstance.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
@Override
public boolean putOperation(Operation operation) throws InterruptedException {
  String name = operation.getName();
  if (isCancelled(operation)) {
    if (outstandingOperations.remove(name) == null) {
      throw new IllegalStateException(
          format("Operation %s was not in outstandingOperations", name));
    }
    updateOperationWatchers(operation);
    return true;
  }
  if (isExecuting(operation) && !outstandingOperations.contains(name)) {
    return false;
  }
  if (isQueued(operation)) {
    if (!matchOperation(operation)) {
      enqueueOperation(operation);
    }
  } else {
    updateOperationWatchers(operation);
  }
  return true;
}
 
Example 5
Source File: GetOperationStatusTest.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
  // Use list operations to get a single operation id for the get call.
  try (AutoMlClient client = AutoMlClient.create()) {
    LocationName projectLocation = LocationName.of(PROJECT_ID, "us-central1");
    ListOperationsRequest request =
        ListOperationsRequest.newBuilder().setName(projectLocation.toString()).build();
    Operation operation =
        client.getOperationsClient().listOperations(request).iterateAll().iterator().next();
    operationId = operation.getName();
  }

  bout = new ByteArrayOutputStream();
  out = new PrintStream(bout);
  System.setOut(out);
}
 
Example 6
Source File: MemoryInstance.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
private void onDispatched(Operation operation) {
  final String operationName = operation.getName();
  Duration timeout = config.getOperationPollTimeout();
  Watchdog requeuer =
      new Watchdog(
          timeout,
          () -> {
            logger.log(Level.INFO, format("REQUEUEING %s", operation.getName()));
            requeuers.remove(operationName);
            requeueOperation(operation);
          });
  requeuers.put(operation.getName(), requeuer);
  new Thread(requeuer).start();
}
 
Example 7
Source File: RedisShardBackplane.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
@Override
public void prequeue(ExecuteEntry executeEntry, Operation operation) throws IOException {
  String operationName = operation.getName();
  String operationJson = operationPrinter.print(operation);
  String executeEntryJson = JsonFormat.printer().print(executeEntry);
  Operation publishOperation = onPublish.apply(operation);
  client.run(
      jedis -> {
        jedis.setex(operationKey(operationName), config.getOperationExpire(), operationJson);
        prequeue.push(jedis, executeEntryJson);
        publishReset(jedis, publishOperation);
      });
}
 
Example 8
Source File: AbstractServerInstance.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
protected void expireOperation(Operation operation) throws InterruptedException {
  ActionResult actionResult =
      ActionResult.newBuilder()
          .setExitCode(-1)
          .setStderrRaw(
              ByteString.copyFromUtf8(
                  "[BUILDFARM]: Action timed out with no response from worker"))
          .build();
  ExecuteResponse executeResponse =
      ExecuteResponse.newBuilder()
          .setResult(actionResult)
          .setStatus(
              com.google.rpc.Status.newBuilder().setCode(Code.DEADLINE_EXCEEDED.getNumber()))
          .build();
  ExecuteOperationMetadata metadata = expectExecuteOperationMetadata(operation);
  if (metadata == null) {
    throw new IllegalStateException(
        "Operation " + operation.getName() + " did not contain valid metadata");
  }
  metadata = metadata.toBuilder().setStage(ExecutionStage.Value.COMPLETED).build();
  putOperation(
      operation
          .toBuilder()
          .setDone(true)
          .setMetadata(Any.pack(metadata))
          .setResponse(Any.pack(executeResponse))
          .build());
}
 
Example 9
Source File: MemoryInstance.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean matchOperation(Operation operation) throws InterruptedException {
  ExecuteOperationMetadata metadata = expectExecuteOperationMetadata(operation);
  Preconditions.checkState(metadata != null, "metadata not found");

  Action action =
      getUnchecked(
          expect(
              metadata.getActionDigest(),
              Action.parser(),
              newDirectExecutorService(),
              RequestMetadata.getDefaultInstance()));
  Preconditions.checkState(action != null, "action not found");

  Command command =
      getUnchecked(
          expect(
              action.getCommandDigest(),
              Command.parser(),
              newDirectExecutorService(),
              RequestMetadata.getDefaultInstance()));
  Preconditions.checkState(command != null, "command not found");

  Tree tree = getCompleteTree(action.getInputRootDigest());

  QueuedOperation queuedOperation =
      QueuedOperation.newBuilder().setAction(action).setCommand(command).setTree(tree).build();
  ByteString queuedOperationBlob = queuedOperation.toByteString();
  Digest queuedOperationDigest = getDigestUtil().compute(queuedOperationBlob);
  String operationName = operation.getName();
  try {
    putBlob(
        this,
        queuedOperationDigest,
        queuedOperationBlob,
        60,
        SECONDS,
        RequestMetadata.getDefaultInstance());
  } catch (StatusException | IOException | ExcessiveWriteSizeException e) {
    logger.log(Level.SEVERE, format("could not emplace queued operation: %s", operationName), e);
    return false;
  }

  ImmutableList.Builder<Worker> rejectedWorkers = new ImmutableList.Builder<>();
  boolean dispatched = false;
  WorkerQueue queue =
      queuedOperations.MatchEligibleQueue(createProvisions(command.getPlatform()));
  synchronized (queue.workers) {
    while (!dispatched && !queue.workers.isEmpty()) {
      Worker worker = queue.workers.remove(0);
      if (!satisfiesRequirements(worker.getProvisions(), command.getPlatform())) {
        rejectedWorkers.add(worker);
      } else {
        QueueEntry queueEntry =
            QueueEntry.newBuilder()
                // FIXME find a way to get this properly populated...
                .setExecuteEntry(
                    ExecuteEntry.newBuilder()
                        .setOperationName(operationName)
                        .setActionDigest(metadata.getActionDigest())
                        .setStdoutStreamName(metadata.getStdoutStreamName())
                        .setStderrStreamName(metadata.getStderrStreamName()))
                .setQueuedOperationDigest(queuedOperationDigest)
                .setPlatform(command.getPlatform())
                .build();
        dispatched = worker.getListener().onEntry(queueEntry);
        if (dispatched) {
          onDispatched(operation);
        }
      }
    }
    Iterables.addAll(queue.workers, rejectedWorkers.build());
  }
  return dispatched;
}
 
Example 10
Source File: RedisShardBackplane.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
@Override
public boolean putOperation(Operation operation, ExecutionStage.Value stage) throws IOException {
  // FIXME queue and prequeue should no longer be passed to here
  boolean prequeue = stage == ExecutionStage.Value.UNKNOWN && !operation.getDone();
  boolean queue = stage == ExecutionStage.Value.QUEUED;
  boolean complete = !queue && operation.getDone();
  boolean publish = !queue && stage != ExecutionStage.Value.UNKNOWN;

  if (complete) {
    // for filtering anything that shouldn't be stored
    operation = onComplete.apply(operation);
  }

  String json;
  try {
    json = operationPrinter.print(operation);
  } catch (InvalidProtocolBufferException e) {
    logger.log(Level.SEVERE, "error printing operation " + operation.getName(), e);
    return false;
  }

  Operation publishOperation;
  if (publish) {
    publishOperation = onPublish.apply(operation);
  } else {
    publishOperation = null;
  }

  String name = operation.getName();
  client.run(
      jedis -> {
        jedis.setex(operationKey(name), config.getOperationExpire(), json);
        if (publishOperation != null) {
          publishReset(jedis, publishOperation);
        }
        if (complete) {
          completeOperation(jedis, name);
        }
      });
  return true;
}