Search in sources :

Example 1 with CompletedOperationMetadata

use of build.buildfarm.v1test.CompletedOperationMetadata in project bazel-buildfarm by bazelbuild.

the class AbstractServerInstance method expectRequestMetadata.

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();
}
Also used : ExecutingOperationMetadata(build.buildfarm.v1test.ExecutingOperationMetadata) ByteString(com.google.protobuf.ByteString) QueuedOperationMetadata(build.buildfarm.v1test.QueuedOperationMetadata) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata) Any(com.google.protobuf.Any)

Example 2 with CompletedOperationMetadata

use of build.buildfarm.v1test.CompletedOperationMetadata in project bazel-buildfarm by bazelbuild.

the class MemoryInstanceTest method requeueFailureNotifiesWatchers.

@Test
public void requeueFailureNotifiesWatchers() throws Exception {
    ExecuteOperationMetadata metadata = ExecuteOperationMetadata.newBuilder().setActionDigest(simpleActionDigest).setStage(QUEUED).build();
    Operation queuedOperation = createOperation("missing-action-operation", metadata);
    outstandingOperations.put(queuedOperation.getName(), queuedOperation);
    Watcher watcher = mock(Watcher.class);
    ListenableFuture<Void> watchFuture = instance.watchOperation(queuedOperation.getName(), watcher);
    assertThat(instance.requeueOperation(queuedOperation)).isFalse();
    watchFuture.get();
    ArgumentCaptor<Operation> operationCaptor = ArgumentCaptor.forClass(Operation.class);
    verify(watcher, atLeastOnce()).observe(operationCaptor.capture());
    List<Operation> operations = operationCaptor.getAllValues();
    Operation erroredOperation = operations.get(operations.size() - 1);
    assertThat(erroredOperation.getDone()).isTrue();
    CompletedOperationMetadata completedMetadata = erroredOperation.getMetadata().unpack(CompletedOperationMetadata.class);
    assertThat(completedMetadata.getExecuteOperationMetadata().getStage()).isEqualTo(COMPLETED);
    PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(simpleActionDigest)).setDescription(MISSING_ACTION)).build();
    ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setStatus(Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(simpleActionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure))).build();
    assertThat(erroredOperation.getResponse().unpack(ExecuteResponse.class)).isEqualTo(executeResponse);
}
Also used : PreconditionFailure(com.google.rpc.PreconditionFailure) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) Watcher(build.buildfarm.common.Watcher) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) Operation(com.google.longrunning.Operation) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata) Test(org.junit.Test)

Example 3 with CompletedOperationMetadata

use of build.buildfarm.v1test.CompletedOperationMetadata in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method assertResponse.

void assertResponse(ExecuteResponse executeResponse) throws Exception {
    ArgumentCaptor<Operation> operationCaptor = ArgumentCaptor.forClass(Operation.class);
    verify(mockBackplane, times(1)).putOperation(operationCaptor.capture(), eq(COMPLETED));
    Operation erroredOperation = operationCaptor.getValue();
    assertThat(erroredOperation.getDone()).isTrue();
    CompletedOperationMetadata completedMetadata = erroredOperation.getMetadata().unpack(CompletedOperationMetadata.class);
    assertThat(completedMetadata.getExecuteOperationMetadata().getStage()).isEqualTo(COMPLETED);
    assertThat(erroredOperation.getResponse().unpack(ExecuteResponse.class)).isEqualTo(executeResponse);
}
Also used : QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata)

Example 4 with CompletedOperationMetadata

use of build.buildfarm.v1test.CompletedOperationMetadata in project bazel-buildfarm by bazelbuild.

the class Cat method printOperation.

private static void printOperation(Operation operation) {
    System.out.println("Operation: " + operation.getName());
    System.out.println("Done: " + (operation.getDone() ? "true" : "false"));
    System.out.println("Metadata:");
    try {
        ExecuteOperationMetadata metadata;
        RequestMetadata requestMetadata;
        if (operation.getMetadata().is(QueuedOperationMetadata.class)) {
            QueuedOperationMetadata queuedOperationMetadata = operation.getMetadata().unpack(QueuedOperationMetadata.class);
            metadata = queuedOperationMetadata.getExecuteOperationMetadata();
            requestMetadata = queuedOperationMetadata.getRequestMetadata();
        } else if (operation.getMetadata().is(ExecutingOperationMetadata.class)) {
            ExecutingOperationMetadata executingMetadata = operation.getMetadata().unpack(ExecutingOperationMetadata.class);
            System.out.println("  Started At: " + new Date(executingMetadata.getStartedAt()));
            System.out.println("  Executing On: " + executingMetadata.getExecutingOn());
            metadata = executingMetadata.getExecuteOperationMetadata();
            requestMetadata = executingMetadata.getRequestMetadata();
        } else if (operation.getMetadata().is(CompletedOperationMetadata.class)) {
            CompletedOperationMetadata completedMetadata = operation.getMetadata().unpack(CompletedOperationMetadata.class);
            metadata = completedMetadata.getExecuteOperationMetadata();
            requestMetadata = completedMetadata.getRequestMetadata();
        } else {
            metadata = operation.getMetadata().unpack(ExecuteOperationMetadata.class);
            requestMetadata = null;
        }
        System.out.println("  Stage: " + metadata.getStage());
        System.out.println("  Action: " + DigestUtil.toString(metadata.getActionDigest()));
        System.out.println("  Stdout Stream: " + metadata.getStdoutStreamName());
        System.out.println("  Stderr Stream: " + metadata.getStderrStreamName());
        if (requestMetadata != null) {
            printRequestMetadata(requestMetadata);
        }
    } catch (InvalidProtocolBufferException e) {
        System.out.println("  UNKNOWN TYPE: " + e.getMessage());
    }
    if (operation.getDone()) {
        switch(operation.getResultCase()) {
            case RESPONSE:
                System.out.println("Response:");
                try {
                    printExecuteResponse(operation.getResponse().unpack(ExecuteResponse.class));
                } catch (InvalidProtocolBufferException e) {
                    System.out.println("  UNKNOWN RESPONSE TYPE: " + operation.getResponse());
                }
                break;
            case ERROR:
                System.out.println("Error: " + Code.forNumber(operation.getError().getCode()));
                break;
            default:
                System.out.println("  UNKNOWN RESULT!");
                break;
        }
    }
}
Also used : ExecutingOperationMetadata(build.buildfarm.v1test.ExecutingOperationMetadata) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) QueuedOperationMetadata(build.buildfarm.v1test.QueuedOperationMetadata) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata) Date(java.util.Date) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata)

Example 5 with CompletedOperationMetadata

use of build.buildfarm.v1test.CompletedOperationMetadata 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)

Aggregations

CompletedOperationMetadata (build.buildfarm.v1test.CompletedOperationMetadata)8 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)5 ExecutingOperationMetadata (build.buildfarm.v1test.ExecutingOperationMetadata)4 QueuedOperationMetadata (build.buildfarm.v1test.QueuedOperationMetadata)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)4 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)3 Operation (com.google.longrunning.Operation)3 Any (com.google.protobuf.Any)2 ByteString (com.google.protobuf.ByteString)2 ActionResult (build.bazel.remote.execution.v2.ActionResult)1 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)1 Actions.asExecutionStatus (build.buildfarm.common.Actions.asExecutionStatus)1 Watcher (build.buildfarm.common.Watcher)1 QueuedOperation (build.buildfarm.v1test.QueuedOperation)1 Timestamp (com.google.protobuf.Timestamp)1 PreconditionFailure (com.google.rpc.PreconditionFailure)1 Status (com.google.rpc.Status)1 StatusException (io.grpc.StatusException)1 IOException (java.io.IOException)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1