Search in sources :

Example 11 with COMPLETED

use of build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED in project bazel-buildfarm by bazelbuild.

the class ReportResultStage method reportPolled.

private OperationContext reportPolled(OperationContext operationContext) throws InterruptedException {
    String operationName = operationContext.operation.getName();
    ActionResult.Builder resultBuilder = operationContext.executeResponse.getResultBuilder();
    resultBuilder.getExecutionMetadataBuilder().setOutputUploadStartTimestamp(Timestamps.fromMillis(System.currentTimeMillis()));
    boolean blacklist = false;
    try {
        workerContext.uploadOutputs(operationContext.queueEntry.getExecuteEntry().getActionDigest(), resultBuilder, operationContext.execDir, operationContext.command.getOutputFilesList(), operationContext.command.getOutputDirectoriesList());
    } catch (StatusException e) {
        ExecuteResponse executeResponse = operationContext.executeResponse.build();
        if (executeResponse.getStatus().getCode() == Code.OK.getNumber() && executeResponse.getResult().getExitCode() == 0) {
            // something about the outputs was malformed - fail the operation with this status if not
            // already failing
            Status status = StatusProto.fromThrowable(e);
            if (status == null) {
                logger.log(Level.SEVERE, String.format("no rpc status from exception for %s", operationName), e);
                status = asExecutionStatus(e);
            }
            operationContext.executeResponse.setStatus(status);
            if (isRetriable(status)) {
                blacklist = true;
            }
        }
    } catch (InterruptedException | ClosedByInterruptException e) {
        // cancellation here should not be logged
        return null;
    } catch (IOException e) {
        logger.log(Level.SEVERE, String.format("error uploading outputs for %s", operationName), e);
        return null;
    }
    Operation operation = operationContext.operation;
    ExecuteOperationMetadata metadata;
    try {
        metadata = operation.getMetadata().unpack(ExecutingOperationMetadata.class).getExecuteOperationMetadata();
    } catch (InvalidProtocolBufferException e) {
        logger.log(Level.SEVERE, String.format("invalid execute operation metadata for %s", operationName), e);
        return null;
    }
    Timestamp now = Timestamps.fromMillis(System.currentTimeMillis());
    resultBuilder.getExecutionMetadataBuilder().setWorkerCompletedTimestamp(now).setOutputUploadCompletedTimestamp(now);
    ExecuteResponse executeResponse = operationContext.executeResponse.build();
    if (blacklist || (!operationContext.action.getDoNotCache() && executeResponse.getStatus().getCode() == Code.OK.getNumber() && executeResponse.getResult().getExitCode() == 0)) {
        try {
            if (blacklist) {
                workerContext.blacklistAction(metadata.getActionDigest().getHash());
            } else {
                workerContext.putActionResult(DigestUtil.asActionKey(metadata.getActionDigest()), executeResponse.getResult());
            }
        } catch (IOException e) {
            logger.log(Level.SEVERE, String.format("error reporting action result for %s", operationName), e);
            return null;
        }
    }
    CompletedOperationMetadata completedMetadata = CompletedOperationMetadata.newBuilder().setExecuteOperationMetadata(metadata.toBuilder().setStage(COMPLETED).build()).setRequestMetadata(operationContext.queueEntry.getExecuteEntry().getRequestMetadata()).build();
    Operation completedOperation = operation.toBuilder().setDone(true).setMetadata(Any.pack(completedMetadata)).setResponse(Any.pack(executeResponse)).build();
    operationContext.poller.pause();
    try {
        if (!workerContext.putOperation(completedOperation)) {
            return null;
        }
    } catch (IOException e) {
        logger.log(Level.SEVERE, String.format("error reporting operation complete for %s", operationName), e);
        return null;
    }
    return operationContext.toBuilder().setOperation(completedOperation).build();
}
Also used : Actions.asExecutionStatus(build.buildfarm.common.Actions.asExecutionStatus) Status(com.google.rpc.Status) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) IOException(java.io.IOException) Operation(com.google.longrunning.Operation) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata) Timestamp(com.google.protobuf.Timestamp) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) StatusException(io.grpc.StatusException) ActionResult(build.bazel.remote.execution.v2.ActionResult) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata)

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