Search in sources :

Example 6 with COMPLETED

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());
}
Also used : ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata)

Example 7 with COMPLETED

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;
}
Also used : Action(build.bazel.remote.execution.v2.Action) Watchdog(build.buildfarm.common.Watchdog) MultimapBuilder(com.google.common.collect.MultimapBuilder) CacheBuilder(com.google.common.cache.CacheBuilder) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) Duration(com.google.protobuf.Duration) ByteString(com.google.protobuf.ByteString)

Example 8 with COMPLETED

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();
}
Also used : ActionResult(build.bazel.remote.execution.v2.ActionResult) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) Poller(build.buildfarm.common.Poller) Test(org.junit.Test)

Example 9 with COMPLETED

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()));
    }
}
Also used : OutputFile(build.bazel.remote.execution.v2.OutputFile) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) ExecutedActionMetadata(build.bazel.remote.execution.v2.ExecutedActionMetadata) ByteString(com.google.protobuf.ByteString)

Example 10 with COMPLETED

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;
}
Also used : Path(java.nio.file.Path) IOResource(build.buildfarm.worker.WorkerContext.IOResource) ImmutableList(com.google.common.collect.ImmutableList) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) Code(com.google.rpc.Code) ActionResult(build.bazel.remote.execution.v2.ActionResult) Command(build.bazel.remote.execution.v2.Command) ExecutionPolicy(build.buildfarm.v1test.ExecutionPolicy)

Aggregations

Operation (com.google.longrunning.Operation)6 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)5 ByteString (com.google.protobuf.ByteString)5 Test (org.junit.Test)5 ActionResult (build.bazel.remote.execution.v2.ActionResult)4 Digest (build.bazel.remote.execution.v2.Digest)4 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)4 QueuedOperation (build.buildfarm.v1test.QueuedOperation)4 CompletedOperationMetadata (build.buildfarm.v1test.CompletedOperationMetadata)3 PreconditionFailure (com.google.rpc.PreconditionFailure)3 IOException (java.io.IOException)3 Action (build.bazel.remote.execution.v2.Action)2 Command (build.bazel.remote.execution.v2.Command)2 ExecutedActionMetadata (build.bazel.remote.execution.v2.ExecutedActionMetadata)2 ActionKey (build.buildfarm.common.DigestUtil.ActionKey)2 Poller (build.buildfarm.common.Poller)2 Watcher (build.buildfarm.common.Watcher)2 ExecuteEntry (build.buildfarm.v1test.ExecuteEntry)2 QueueEntry (build.buildfarm.v1test.QueueEntry)2 Path (java.nio.file.Path)2