Search in sources :

Example 11 with ActionKey

use of build.buildfarm.common.DigestUtil.ActionKey in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method actionResultWatcherPropagatesNull.

@Test
public void actionResultWatcherPropagatesNull() {
    ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("test").build());
    Watcher mockWatcher = mock(Watcher.class);
    Watcher actionResultWatcher = instance.newActionResultWatcher(actionKey, mockWatcher);
    actionResultWatcher.observe(null);
    verify(mockWatcher, times(1)).observe(null);
}
Also used : Watcher(build.buildfarm.common.Watcher) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) Test(org.junit.Test)

Example 12 with ActionKey

use of build.buildfarm.common.DigestUtil.ActionKey in project bazel-buildfarm by bazelbuild.

the class StubInstanceTest method getActionResultReturnsNullForNotFound.

@Test
public void getActionResultReturnsNullForNotFound() throws Exception {
    AtomicReference<GetActionResultRequest> reference = new AtomicReference<>();
    serviceRegistry.addService(new ActionCacheImplBase() {

        @Override
        public void getActionResult(GetActionResultRequest request, StreamObserver<ActionResult> responseObserver) {
            reference.set(request);
            responseObserver.onError(Status.NOT_FOUND.asException());
        }
    });
    Instance instance = newStubInstance("test");
    ActionKey actionKey = DIGEST_UTIL.computeActionKey(Action.getDefaultInstance());
    assertThat(instance.getActionResult(actionKey, RequestMetadata.getDefaultInstance()).get()).isNull();
    GetActionResultRequest request = reference.get();
    assertThat(request.getInstanceName()).isEqualTo(instance.getName());
    assertThat(request.getActionDigest()).isEqualTo(actionKey.getDigest());
    instance.stop();
}
Also used : ActionResult(build.bazel.remote.execution.v2.ActionResult) Instance(build.buildfarm.instance.Instance) AtomicReference(java.util.concurrent.atomic.AtomicReference) ActionCacheImplBase(build.bazel.remote.execution.v2.ActionCacheGrpc.ActionCacheImplBase) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) GetActionResultRequest(build.bazel.remote.execution.v2.GetActionResultRequest) Test(org.junit.Test)

Example 13 with ActionKey

use of build.buildfarm.common.DigestUtil.ActionKey in project bazel-buildfarm by bazelbuild.

the class AbstractServerInstance method execute.

// this deserves a real async execute, but not now
@SuppressWarnings("ConstantConditions")
@Override
public ListenableFuture<Void> execute(Digest actionDigest, boolean skipCacheLookup, ExecutionPolicy executionPolicy, ResultsCachePolicy resultsCachePolicy, RequestMetadata requestMetadata, Watcher watcher) throws InterruptedException {
    try {
        validateActionDigest("execute", actionDigest, requestMetadata);
    } catch (StatusException e) {
        com.google.rpc.Status status = StatusProto.fromThrowable(e);
        if (status == null) {
            getLogger().log(Level.SEVERE, "no rpc status from exception", e);
            status = com.google.rpc.Status.newBuilder().setCode(Status.fromThrowable(e).getCode().value()).build();
        }
        logFailedStatus(actionDigest, status);
        Operation operation = Operation.newBuilder().setDone(true).setMetadata(Any.pack(ExecuteOperationMetadata.newBuilder().setStage(ExecutionStage.Value.COMPLETED).build())).setResponse(Any.pack(ExecuteResponse.newBuilder().setStatus(status).build())).build();
        try {
            watcher.observe(operation);
        } catch (Throwable t) {
            return immediateFailedFuture(t);
        }
        return immediateFuture(null);
    }
    ActionKey actionKey = DigestUtil.asActionKey(actionDigest);
    Operation operation = createOperation(actionKey);
    getLogger().info("Operation " + operation.getName() + " was created");
    getLogger().info(format("%s::execute(%s): %s", getName(), DigestUtil.toString(actionDigest), operation.getName()));
    putOperation(operation);
    ListenableFuture<Void> watchFuture = watchOperation(operation.getName(), watcher);
    ExecuteOperationMetadata metadata = expectExecuteOperationMetadata(operation);
    Operation.Builder operationBuilder = operation.toBuilder();
    final ListenableFuture<ActionResult> actionResultFuture;
    final ExecuteOperationMetadata cacheCheckMetadata;
    if (skipCacheLookup) {
        actionResultFuture = immediateFuture(null);
        cacheCheckMetadata = metadata;
    } else {
        cacheCheckMetadata = metadata.toBuilder().setStage(ExecutionStage.Value.CACHE_CHECK).build();
        putOperation(operationBuilder.setMetadata(Any.pack(metadata)).build());
        actionResultFuture = getActionResult(actionKey, requestMetadata);
    }
    Futures.addCallback(actionResultFuture, new FutureCallback<ActionResult>() {

        @SuppressWarnings("ConstantConditions")
        void onCompleted(@Nullable ActionResult actionResult) {
            final ExecuteOperationMetadata nextMetadata;
            if (actionResult == null) {
                nextMetadata = cacheCheckMetadata.toBuilder().setStage(ExecutionStage.Value.QUEUED).build();
            } else {
                nextMetadata = cacheCheckMetadata.toBuilder().setStage(ExecutionStage.Value.COMPLETED).build();
                operationBuilder.setDone(true).setResponse(Any.pack(ExecuteResponse.newBuilder().setResult(actionResult).setStatus(com.google.rpc.Status.newBuilder().setCode(Code.OK.getNumber()).build()).setCachedResult(true).build()));
            }
            Operation nextOperation = operationBuilder.setMetadata(Any.pack(nextMetadata)).build();
            try {
                if (!nextOperation.getDone()) {
                    updateOperationWatchers(// updates watchers initially for queued stage
                    nextOperation);
                }
                putOperation(nextOperation);
            } catch (InterruptedException e) {
            // ignore
            }
        }

        @Override
        public void onSuccess(ActionResult actionResult) {
            onCompleted(actionResult);
        }

        @SuppressWarnings("NullableProblems")
        @Override
        public void onFailure(Throwable t) {
            logger.log(Level.WARNING, format("action cache check of %s failed", DigestUtil.toString(actionDigest)), t);
            onCompleted(null);
        }
    }, directExecutor());
    return watchFuture;
}
Also used : Status(io.grpc.Status) Actions.asExecutionStatus(build.buildfarm.common.Actions.asExecutionStatus) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) QueuedOperation(build.buildfarm.v1test.QueuedOperation) EnrichedOperation(build.buildfarm.operations.EnrichedOperation) Operation(com.google.longrunning.Operation) StatusException(io.grpc.StatusException) ActionResult(build.bazel.remote.execution.v2.ActionResult) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata)

Aggregations

ActionKey (build.buildfarm.common.DigestUtil.ActionKey)13 ActionResult (build.bazel.remote.execution.v2.ActionResult)10 Test (org.junit.Test)10 QueuedOperation (build.buildfarm.v1test.QueuedOperation)8 Operation (com.google.longrunning.Operation)8 Watcher (build.buildfarm.common.Watcher)6 Digest (build.bazel.remote.execution.v2.Digest)5 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)5 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)4 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)4 Poller (build.buildfarm.common.Poller)4 Instance (build.buildfarm.instance.Instance)4 ExecuteEntry (build.buildfarm.v1test.ExecuteEntry)4 ByteString (com.google.protobuf.ByteString)4 Action (build.bazel.remote.execution.v2.Action)3 QueueEntry (build.buildfarm.v1test.QueueEntry)3 ServerCallStreamObserver (io.grpc.stub.ServerCallStreamObserver)3 Command (build.bazel.remote.execution.v2.Command)2 Directory (build.bazel.remote.execution.v2.Directory)2 DirectoryNode (build.bazel.remote.execution.v2.DirectoryNode)2