use of build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED in project bazel-buildfarm by bazelbuild.
the class AbstractServerInstance method errorOperation.
protected void errorOperation(Operation operation, RequestMetadata requestMetadata, com.google.rpc.Status status) throws InterruptedException {
if (operation.getDone()) {
throw new IllegalStateException("Trying to error already completed operation [" + name + "]");
}
ExecuteOperationMetadata metadata = expectExecuteOperationMetadata(operation);
if (metadata == null) {
metadata = ExecuteOperationMetadata.getDefaultInstance();
}
CompletedOperationMetadata completedMetadata = CompletedOperationMetadata.newBuilder().setExecuteOperationMetadata(metadata.toBuilder().setStage(ExecutionStage.Value.COMPLETED).build()).setRequestMetadata(requestMetadata).build();
putOperation(operation.toBuilder().setDone(true).setMetadata(Any.pack(completedMetadata)).setResponse(Any.pack(ExecuteResponse.newBuilder().setStatus(status).build())).build());
}
use of build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED in project bazel-buildfarm by bazelbuild.
the class MemoryInstance method putOperation.
@Override
public boolean putOperation(Operation operation) throws InterruptedException {
String operationName = operation.getName();
if (isQueued(operation)) {
// destroy any monitors for this queued operation
// any race should be resolved in a failure to requeue
Watchdog requeuer = requeuers.remove(operationName);
if (requeuer != null) {
requeuer.stop();
}
Watchdog operationTimeoutDelay = operationTimeoutDelays.remove(operationName);
if (operationTimeoutDelay != null) {
operationTimeoutDelay.stop();
}
}
if (!super.putOperation(operation)) {
return false;
}
if (operation.getDone()) {
// destroy requeue timer
Watchdog requeuer = requeuers.remove(operationName);
if (requeuer != null) {
requeuer.stop();
}
// destroy action timed out failure
Watchdog operationTimeoutDelay = operationTimeoutDelays.remove(operationName);
if (operationTimeoutDelay != null) {
operationTimeoutDelay.stop();
}
String operationStatus = "terminated";
if (isCancelled(operation)) {
operationStatus = "cancelled";
} else if (isComplete(operation)) {
operationStatus = "completed";
}
logger.log(Level.INFO, format("Operation %s was %s", operationName, operationStatus));
} else if (isExecuting(operation)) {
Watchdog requeuer = requeuers.get(operationName);
if (requeuer == null) {
// restore a requeuer if a worker indicates they are executing
onDispatched(operation);
} else {
requeuer.pet();
}
// Create a delayed fuse timed out failure
// This is in effect if the worker does not respond
// within a configured delay with operation action timeout results
com.google.rpc.Status.Builder status = com.google.rpc.Status.newBuilder();
Action action = getActionForTimeoutMonitor(operation, status);
if (action == null) {
// prevent further activity of this operation, since it can not
// transition to execution without independent provision of action blob
// or reconfiguration of operation metadata
// force an immediate error completion of the operation
errorOperation(operation, RequestMetadata.getDefaultInstance(), status.build());
return false;
}
Duration actionTimeout = null;
if (action.hasTimeout()) {
actionTimeout = action.getTimeout();
} else if (config.hasDefaultActionTimeout()) {
actionTimeout = config.getDefaultActionTimeout();
}
if (actionTimeout != null) {
Duration delay = config.getOperationCompletedDelay();
Duration timeout = Duration.newBuilder().setSeconds(actionTimeout.getSeconds() + delay.getSeconds()).setNanos(actionTimeout.getNanos() + delay.getNanos()).build();
// this is an overuse of Watchdog, we will never pet it
Watchdog operationTimeoutDelay = new Watchdog(timeout, () -> {
operationTimeoutDelays.remove(operationName);
try {
expireOperation(operation);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
});
operationTimeoutDelays.put(operationName, operationTimeoutDelay);
new Thread(operationTimeoutDelay).start();
}
}
return true;
}
use of build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method queueOperationCompletesOperationWithCachedActionResult.
@Test
public void queueOperationCompletesOperationWithCachedActionResult() throws Exception {
ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("test").build());
ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("operation-with-cached-action-result").setActionDigest(actionKey.getDigest()).build();
ActionResult actionResult = ActionResult.getDefaultInstance();
when(mockBackplane.getActionResult(eq(actionKey))).thenReturn(actionResult);
Poller poller = mock(Poller.class);
instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get();
verify(mockBackplane, times(1)).putOperation(any(Operation.class), eq(CACHE_CHECK));
verify(mockBackplane, never()).putOperation(any(Operation.class), eq(QUEUED));
verify(mockBackplane, times(1)).putOperation(any(Operation.class), eq(COMPLETED));
verify(poller, atLeastOnce()).pause();
}
use of build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED in project bazel-buildfarm by bazelbuild.
the class Cat method printActionResult.
@SuppressWarnings("ConstantConditions")
private static void printActionResult(ActionResult result, int indentLevel) {
for (OutputFile outputFile : result.getOutputFilesList()) {
String attrs = "";
if (outputFile.getIsExecutable()) {
attrs += (attrs.length() == 0 ? "" : ",") + "executable";
}
if (attrs.length() != 0) {
attrs = " (" + attrs + ")";
}
indentOut(indentLevel, "Output File: " + outputFile.getPath() + attrs + " File " + DigestUtil.toString(outputFile.getDigest()));
}
for (OutputDirectory outputDirectory : result.getOutputDirectoriesList()) {
indentOut(indentLevel, "Output Directory: " + outputDirectory.getPath() + " Directory " + DigestUtil.toString(outputDirectory.getTreeDigest()));
}
indentOut(indentLevel, "Exit Code: " + result.getExitCode());
if (!result.getStdoutRaw().isEmpty()) {
indentOut(indentLevel, "Stdout: " + result.getStdoutRaw().toStringUtf8());
}
if (result.hasStdoutDigest()) {
indentOut(indentLevel, "Stdout Digest: " + DigestUtil.toString(result.getStdoutDigest()));
}
if (!result.getStderrRaw().isEmpty()) {
indentOut(indentLevel, "Stderr: " + result.getStderrRaw().toStringUtf8());
}
if (result.hasStderrDigest()) {
indentOut(indentLevel, "Stderr Digest: " + DigestUtil.toString(result.getStderrDigest()));
}
if (result.hasExecutionMetadata()) {
indentOut(indentLevel, "ExecutionMetadata:");
ExecutedActionMetadata executedActionMetadata = result.getExecutionMetadata();
indentOut(indentLevel + 1, "Worker: " + executedActionMetadata.getWorker());
indentOut(indentLevel + 1, "Queued At: " + Timestamps.toString(executedActionMetadata.getQueuedTimestamp()));
indentOut(indentLevel + 1, "Worker Start: " + Timestamps.toString(executedActionMetadata.getWorkerStartTimestamp()));
indentOut(indentLevel + 1, "Input Fetch Start: " + Timestamps.toString(executedActionMetadata.getInputFetchStartTimestamp()));
indentOut(indentLevel + 1, "Input Fetch Completed: " + Timestamps.toString(executedActionMetadata.getInputFetchCompletedTimestamp()));
indentOut(indentLevel + 1, "Execution Start: " + Timestamps.toString(executedActionMetadata.getExecutionStartTimestamp()));
indentOut(indentLevel + 1, "Execution Completed: " + Timestamps.toString(executedActionMetadata.getExecutionCompletedTimestamp()));
indentOut(indentLevel + 1, "Output Upload Start: " + Timestamps.toString(executedActionMetadata.getOutputUploadStartTimestamp()));
indentOut(indentLevel + 1, "Output Upload Completed: " + Timestamps.toString(executedActionMetadata.getOutputUploadCompletedTimestamp()));
indentOut(indentLevel + 1, "Worker Completed: " + Timestamps.toString(executedActionMetadata.getWorkerCompletedTimestamp()));
}
}
use of build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED in project bazel-buildfarm by bazelbuild.
the class Executor method executePolled.
private long executePolled(Operation operation, ResourceLimits limits, Iterable<ExecutionPolicy> policies, Duration timeout, Stopwatch stopwatch) throws InterruptedException {
/* execute command */
logger.log(Level.FINE, "Executor: Operation " + operation.getName() + " Executing command");
ActionResult.Builder resultBuilder = operationContext.executeResponse.getResultBuilder();
resultBuilder.getExecutionMetadataBuilder().setExecutionStartTimestamp(Timestamps.fromMillis(System.currentTimeMillis()));
Command command = operationContext.command;
Path workingDirectory = operationContext.execDir;
if (!command.getWorkingDirectory().isEmpty()) {
workingDirectory = workingDirectory.resolve(command.getWorkingDirectory());
}
String operationName = operation.getName();
ImmutableList.Builder<String> arguments = ImmutableList.builder();
Code statusCode;
try (IOResource resource = workerContext.limitExecution(operationName, arguments, operationContext.command, workingDirectory)) {
for (ExecutionPolicy policy : policies) {
if (policy.getPolicyCase() == WRAPPER) {
arguments.addAll(transformWrapper(policy.getWrapper()));
}
}
if (System.getProperty("os.name").contains("Win")) {
// Make sure that the executable path is absolute, otherwise processbuilder fails on windows
Iterator<String> argumentItr = command.getArgumentsList().iterator();
if (argumentItr.hasNext()) {
// Get first element, this is the executable
String exe = argumentItr.next();
arguments.add(workingDirectory.resolve(exe).toAbsolutePath().normalize().toString());
argumentItr.forEachRemaining(arguments::add);
}
} else {
arguments.addAll(command.getArgumentsList());
}
statusCode = executeCommand(operationName, workingDirectory, arguments.build(), command.getEnvironmentVariablesList(), limits, timeout, // executingMetadata.getStderrStreamName(),
resultBuilder);
// Based on configuration, we will decide whether remaining resources should be an error.
if (workerContext.shouldErrorOperationOnRemainingResources() && resource.isReferenced() && statusCode == Code.OK) {
// there should no longer be any references to the resource. Any references will be
// killed upon close, but we must error the operation due to improper execution
// per the gRPC spec: 'The operation was attempted past the valid range.' Seems
// appropriate
statusCode = Code.OUT_OF_RANGE;
operationContext.executeResponse.getStatusBuilder().setMessage("command resources were referenced after execution completed");
}
} catch (IOException e) {
logger.log(Level.SEVERE, format("error executing operation %s", operationName), e);
operationContext.poller.pause();
putError();
return 0;
}
// switch poller to disable deadline
operationContext.poller.pause();
workerContext.resumePoller(operationContext.poller, "Executor(claim)", operationContext.queueEntry, ExecutionStage.Value.EXECUTING, () -> {
}, Deadline.after(10, DAYS));
resultBuilder.getExecutionMetadataBuilder().setExecutionCompletedTimestamp(Timestamps.fromMillis(System.currentTimeMillis()));
long executeUSecs = stopwatch.elapsed(MICROSECONDS);
logger.log(Level.FINE, String.format("Executor::executeCommand(%s): Completed command: exit code %d", operationName, resultBuilder.getExitCode()));
operationContext.executeResponse.getStatusBuilder().setCode(statusCode.getNumber());
OperationContext reportOperationContext = operationContext.toBuilder().setOperation(operation).build();
boolean claimed = owner.output().claim(reportOperationContext);
operationContext.poller.pause();
if (claimed) {
try {
owner.output().put(reportOperationContext);
} catch (InterruptedException e) {
owner.output().release();
throw e;
}
} else {
logger.log(Level.FINE, "Executor: Operation " + operationName + " Failed to claim output");
boolean wasInterrupted = Thread.interrupted();
try {
putError();
} finally {
if (wasInterrupted) {
Thread.currentThread().interrupt();
}
}
}
return stopwatch.elapsed(MICROSECONDS) - executeUSecs;
}
Aggregations