Search in sources :

Example 66 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method createAction.

private Action createAction(boolean provideAction, boolean provideCommand, Command command) throws Exception {
    Directory inputRoot = Directory.getDefaultInstance();
    ByteString inputRootBlob = inputRoot.toByteString();
    Digest inputRootDigest = DIGEST_UTIL.compute(inputRootBlob);
    provideBlob(inputRootDigest, inputRootBlob);
    return createAction(provideAction, provideCommand, inputRootDigest, command);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) Directory(build.bazel.remote.execution.v2.Directory)

Example 67 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method createAction.

@SuppressWarnings("unchecked")
private Action createAction(boolean provideAction, boolean provideCommand, Digest inputRootDigest, Command command) throws Exception {
    String workerName = "worker";
    when(mockInstanceLoader.load(eq(workerName))).thenReturn(mockWorkerInstance);
    ImmutableSet<String> workers = ImmutableSet.of(workerName);
    when(mockBackplane.getWorkers()).thenReturn(workers);
    ByteString commandBlob = command.toByteString();
    Digest commandDigest = DIGEST_UTIL.compute(commandBlob);
    if (provideCommand) {
        provideBlob(commandDigest, commandBlob);
        when(mockBackplane.getBlobLocationSet(eq(commandDigest))).thenReturn(workers);
    }
    doAnswer((Answer<ListenableFuture<Iterable<Digest>>>) invocation -> {
        Iterable<Digest> digests = (Iterable<Digest>) invocation.getArguments()[0];
        return immediateFuture(StreamSupport.stream(digests.spliterator(), false).filter((digest) -> !blobDigests.contains(digest)).collect(Collectors.toList()));
    }).when(mockWorkerInstance).findMissingBlobs(any(Iterable.class), any(RequestMetadata.class));
    Action action = Action.newBuilder().setCommandDigest(commandDigest).setInputRootDigest(inputRootDigest).build();
    ByteString actionBlob = action.toByteString();
    Digest actionDigest = DIGEST_UTIL.compute(actionBlob);
    if (provideAction) {
        provideBlob(actionDigest, actionBlob);
    }
    doAnswer((Answer<Void>) invocation -> {
        StreamObserver<ByteString> blobObserver = (StreamObserver) invocation.getArguments()[3];
        if (provideAction) {
            blobObserver.onNext(action.toByteString());
            blobObserver.onCompleted();
        } else {
            blobObserver.onError(Status.NOT_FOUND.asException());
        }
        return null;
    }).when(mockWorkerInstance).getBlob(eq(actionDigest), eq(0L), eq(actionDigest.getSizeBytes()), any(ServerCallStreamObserver.class), any(RequestMetadata.class));
    when(mockBackplane.getBlobLocationSet(eq(actionDigest))).thenReturn(provideAction ? workers : ImmutableSet.of());
    when(mockWorkerInstance.findMissingBlobs(eq(ImmutableList.of(actionDigest)), any(RequestMetadata.class))).thenReturn(immediateFuture(ImmutableList.of()));
    return action;
}
Also used : ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) AsyncCache(com.github.benmanes.caffeine.cache.AsyncCache) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Actions.invalidActionVerboseMessage(build.buildfarm.common.Actions.invalidActionVerboseMessage) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) Durations(com.google.protobuf.util.Durations) MISSING_ACTION(build.buildfarm.instance.server.AbstractServerInstance.MISSING_ACTION) ArgumentMatcher(org.mockito.ArgumentMatcher) MockitoAnnotations(org.mockito.MockitoAnnotations) StreamObserver(io.grpc.stub.StreamObserver) StatusProto(io.grpc.protobuf.StatusProto) Digest(build.bazel.remote.execution.v2.Digest) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) COMPLETED(build.bazel.remote.execution.v2.ExecutionStage.Value.COMPLETED) Status(io.grpc.Status) INVALID_PLATFORM(build.buildfarm.instance.server.AbstractServerInstance.INVALID_PLATFORM) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) ImmutableSet(com.google.common.collect.ImmutableSet) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Set(java.util.Set) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) OutputFile(build.bazel.remote.execution.v2.OutputFile) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Instance(build.buildfarm.instance.Instance) Sets(com.google.common.collect.Sets) CacheLoader(com.google.common.cache.CacheLoader) ByteString(com.google.protobuf.ByteString) List(java.util.List) VIOLATION_TYPE_MISSING(build.buildfarm.common.Errors.VIOLATION_TYPE_MISSING) HashFunction(build.buildfarm.common.DigestUtil.HashFunction) QueueEntry(build.buildfarm.v1test.QueueEntry) Any(com.google.protobuf.Any) CacheBuilder(com.google.common.cache.CacheBuilder) CACHE_CHECK(build.bazel.remote.execution.v2.ExecutionStage.Value.CACHE_CHECK) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) Directory(build.bazel.remote.execution.v2.Directory) MoreExecutors.listeningDecorator(com.google.common.util.concurrent.MoreExecutors.listeningDecorator) Iterables(com.google.common.collect.Iterables) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Command(build.bazel.remote.execution.v2.Command) ToolDetails(build.bazel.remote.execution.v2.ToolDetails) Matchers(org.mockito.Matchers) Mock(org.mockito.Mock) MoreExecutors.newDirectExecutorService(com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService) RunWith(org.junit.runner.RunWith) MISSING_COMMAND(build.buildfarm.instance.server.AbstractServerInstance.MISSING_COMMAND) CompletableFuture(java.util.concurrent.CompletableFuture) QueuedOperation(build.buildfarm.v1test.QueuedOperation) ResultsCachePolicy(build.bazel.remote.execution.v2.ResultsCachePolicy) Operation(com.google.longrunning.Operation) Function(java.util.function.Function) DigestUtil(build.buildfarm.common.DigestUtil) QUEUED(build.bazel.remote.execution.v2.ExecutionStage.Value.QUEUED) Answer(org.mockito.stubbing.Answer) Action(build.bazel.remote.execution.v2.Action) NullWrite(build.buildfarm.common.Write.NullWrite) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) Watcher(build.buildfarm.common.Watcher) VIOLATION_TYPE_INVALID(build.buildfarm.common.Errors.VIOLATION_TYPE_INVALID) ActionResult(build.bazel.remote.execution.v2.ActionResult) AdditionalAnswers.answer(org.mockito.AdditionalAnswers.answer) StreamSupport(java.util.stream.StreamSupport) Code(com.google.rpc.Code) Before(org.junit.Before) Backplane(build.buildfarm.backplane.Backplane) Violation(com.google.rpc.PreconditionFailure.Violation) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) ExecutionPolicy(build.bazel.remote.execution.v2.ExecutionPolicy) Poller(build.buildfarm.common.Poller) PreconditionFailure(com.google.rpc.PreconditionFailure) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Mockito.verify(org.mockito.Mockito.verify) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) Mockito.never(org.mockito.Mockito.never) Duration(com.google.protobuf.Duration) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) SECONDS(java.util.concurrent.TimeUnit.SECONDS) CompletedOperationMetadata(build.buildfarm.v1test.CompletedOperationMetadata) StreamObserver(io.grpc.stub.StreamObserver) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) Action(build.bazel.remote.execution.v2.Action) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ByteString(com.google.protobuf.ByteString) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata)

Example 68 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method queueActionMissingErrorsOperation.

@Test
public void queueActionMissingErrorsOperation() throws Exception {
    Action action = createAction(false);
    Digest actionDigest = DIGEST_UTIL.compute(action);
    ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("missing-action-operation").setActionDigest(actionDigest).setSkipCacheLookup(true).build();
    when(mockBackplane.canQueue()).thenReturn(true);
    Poller poller = mock(Poller.class);
    boolean failedPreconditionExceptionCaught = false;
    try {
        instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
    } catch (ExecutionException e) {
        com.google.rpc.Status status = StatusProto.fromThrowable(e);
        if (status.getCode() == Code.FAILED_PRECONDITION.getNumber()) {
            failedPreconditionExceptionCaught = true;
        } else {
            e.getCause().printStackTrace();
        }
    }
    assertThat(failedPreconditionExceptionCaught).isTrue();
    PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(actionDigest)).setDescription(MISSING_ACTION)).build();
    ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setStatus(com.google.rpc.Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure))).build();
    assertResponse(executeResponse);
    verify(poller, atLeastOnce()).pause();
}
Also used : Status(io.grpc.Status) Action(build.bazel.remote.execution.v2.Action) PreconditionFailure(com.google.rpc.PreconditionFailure) Digest(build.bazel.remote.execution.v2.Digest) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ExecutionException(java.util.concurrent.ExecutionException) Poller(build.buildfarm.common.Poller) Test(org.junit.Test)

Example 69 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method queueDirectoryMissingErrorsOperation.

@Test
public void queueDirectoryMissingErrorsOperation() throws Exception {
    ByteString foo = ByteString.copyFromUtf8("foo");
    Digest subdirDigest = DIGEST_UTIL.compute(foo);
    Directory inputRoot = Directory.newBuilder().addDirectories(DirectoryNode.newBuilder().setName("missing-subdir").setDigest(subdirDigest)).build();
    ByteString inputRootContent = inputRoot.toByteString();
    Digest inputRootDigest = DIGEST_UTIL.compute(inputRootContent);
    provideBlob(inputRootDigest, inputRootContent);
    Action action = createAction(true, true, inputRootDigest, SIMPLE_COMMAND);
    Digest actionDigest = DIGEST_UTIL.compute(action);
    ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("missing-directory-operation").setActionDigest(actionDigest).setSkipCacheLookup(true).build();
    when(mockBackplane.propertiesEligibleForQueue(Matchers.anyList())).thenReturn(true);
    when(mockBackplane.canQueue()).thenReturn(true);
    Poller poller = mock(Poller.class);
    boolean failedPreconditionExceptionCaught = false;
    try {
        instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
    } catch (ExecutionException e) {
        com.google.rpc.Status status = StatusProto.fromThrowable(e);
        if (status.getCode() == Code.FAILED_PRECONDITION.getNumber()) {
            failedPreconditionExceptionCaught = true;
        } else {
            e.getCause().printStackTrace();
        }
    }
    assertThat(failedPreconditionExceptionCaught).isTrue();
    PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(subdirDigest)).setDescription("The directory `/missing-subdir` was not found in the CAS.")).build();
    ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setStatus(com.google.rpc.Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure))).build();
    assertResponse(executeResponse);
    verify(poller, atLeastOnce()).pause();
}
Also used : Status(io.grpc.Status) Action(build.bazel.remote.execution.v2.Action) PreconditionFailure(com.google.rpc.PreconditionFailure) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ExecutionException(java.util.concurrent.ExecutionException) Poller(build.buildfarm.common.Poller) Directory(build.bazel.remote.execution.v2.Directory) Test(org.junit.Test)

Example 70 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method requeueSucceedsForValidOperation.

@Test
public void requeueSucceedsForValidOperation() throws Exception {
    String operationName = "valid-operation";
    when(mockBackplane.getOperation(eq(operationName))).thenReturn(Operation.newBuilder().setName(operationName).build());
    Action action = createAction();
    QueuedOperation queuedOperation = QueuedOperation.newBuilder().setAction(action).setCommand(SIMPLE_COMMAND).build();
    ByteString queuedOperationBlob = queuedOperation.toByteString();
    Digest queuedOperationDigest = DIGEST_UTIL.compute(queuedOperationBlob);
    provideBlob(queuedOperationDigest, queuedOperationBlob);
    Digest actionDigest = DIGEST_UTIL.compute(action);
    QueueEntry queueEntry = QueueEntry.newBuilder().setExecuteEntry(ExecuteEntry.newBuilder().setOperationName(operationName).setSkipCacheLookup(true).setActionDigest(actionDigest)).setQueuedOperationDigest(queuedOperationDigest).build();
    instance.requeueOperation(queueEntry, Durations.fromSeconds(60)).get();
}
Also used : Action(build.bazel.remote.execution.v2.Action) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) QueuedOperation(build.buildfarm.v1test.QueuedOperation) ByteString(com.google.protobuf.ByteString) QueueEntry(build.buildfarm.v1test.QueueEntry) Test(org.junit.Test)

Aggregations

Digest (build.bazel.remote.execution.v2.Digest)191 ByteString (com.google.protobuf.ByteString)110 Test (org.junit.Test)99 IOException (java.io.IOException)55 Directory (build.bazel.remote.execution.v2.Directory)42 ImmutableList (com.google.common.collect.ImmutableList)35 Path (java.nio.file.Path)33 Status (io.grpc.Status)30 ExecutionException (java.util.concurrent.ExecutionException)29 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)27 InputStream (java.io.InputStream)25 Instance (build.buildfarm.instance.Instance)24 Action (build.bazel.remote.execution.v2.Action)22 DigestUtil (build.buildfarm.common.DigestUtil)22 OutputStream (java.io.OutputStream)22 Write (build.buildfarm.common.Write)21 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)21 Operation (com.google.longrunning.Operation)21 UUID (java.util.UUID)20 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)19