Search in sources :

Example 11 with RequestMetadata

use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.

the class GrpcCASTest method writeIsResumable.

@Test
public void writeIsResumable() throws Exception {
    UUID uuid = UUID.randomUUID();
    ByteString writeContent = ByteString.copyFromUtf8("written");
    Digest digest = DIGEST_UTIL.compute(writeContent);
    String instanceName = "test";
    HashCode hash = HashCode.fromString(digest.getHash());
    String resourceName = ByteStreamUploader.uploadResourceName(instanceName, uuid, hash, digest.getSizeBytes());
    // better test might just put a full gRPC CAS behind an in-process and validate state
    SettableFuture<ByteString> content = SettableFuture.create();
    serviceRegistry.addService(new ByteStreamServiceWriter(resourceName, content, (int) digest.getSizeBytes()));
    Channel channel = InProcessChannelBuilder.forName(fakeServerName).directExecutor().build();
    GrpcCAS cas = new GrpcCAS(instanceName, channel, /* uploader=*/
    null, onExpirations);
    RequestMetadata requestMetadata = RequestMetadata.getDefaultInstance();
    Write initialWrite = cas.getWrite(digest, uuid, requestMetadata);
    try (OutputStream writeOut = initialWrite.getOutput(1, SECONDS, () -> {
    })) {
        writeContent.substring(0, 4).writeTo(writeOut);
    }
    Write finalWrite = cas.getWrite(digest, uuid, requestMetadata);
    try (OutputStream writeOut = finalWrite.getOutput(1, SECONDS, () -> {
    })) {
        writeContent.substring(4).writeTo(writeOut);
    }
    assertThat(content.get(1, TimeUnit.SECONDS)).isEqualTo(writeContent);
}
Also used : Write(build.buildfarm.common.Write) HashCode(com.google.common.hash.HashCode) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) Channel(io.grpc.Channel) OutputStream(java.io.OutputStream) ByteString(com.google.protobuf.ByteString) UUID(java.util.UUID) ByteStreamServiceWriter(build.buildfarm.common.grpc.ByteStreamServiceWriter) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Example 12 with RequestMetadata

use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.

the class ShardInstanceTest method duplicateExecutionsServedFromCacheAreForcedToSkipLookup.

@Test
public void duplicateExecutionsServedFromCacheAreForcedToSkipLookup() throws Exception {
    ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("test").build());
    ActionResult actionResult = ActionResult.newBuilder().addOutputFiles(OutputFile.newBuilder().setPath("does-not-exist").setDigest(Digest.newBuilder().setHash("dne").setSizeBytes(1))).setStdoutDigest(Digest.newBuilder().setHash("stdout").setSizeBytes(1)).setStderrDigest(Digest.newBuilder().setHash("stderr").setSizeBytes(1)).build();
    when(mockBackplane.canQueue()).thenReturn(true);
    when(mockBackplane.canPrequeue()).thenReturn(true);
    when(mockBackplane.getActionResult(actionKey)).thenReturn(actionResult);
    Digest actionDigest = actionKey.getDigest();
    RequestMetadata requestMetadata = RequestMetadata.newBuilder().setToolDetails(ToolDetails.newBuilder().setToolName("buildfarm-test").setToolVersion("0.1")).setCorrelatedInvocationsId(UUID.randomUUID().toString()).setToolInvocationId(UUID.randomUUID().toString()).setActionId(actionDigest.getHash()).build();
    String operationName = "cache-served-operation";
    ExecuteEntry cacheServedExecuteEntry = ExecuteEntry.newBuilder().setOperationName(operationName).setActionDigest(actionDigest).setRequestMetadata(requestMetadata).build();
    Poller poller = mock(Poller.class);
    instance.queue(cacheServedExecuteEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
    verify(poller, times(1)).pause();
    verify(mockBackplane, never()).queue(any(QueueEntry.class), any(Operation.class));
    ArgumentCaptor<Operation> cacheCheckOperationCaptor = ArgumentCaptor.forClass(Operation.class);
    verify(mockBackplane, times(1)).putOperation(cacheCheckOperationCaptor.capture(), eq(CACHE_CHECK));
    Operation cacheCheckOperation = cacheCheckOperationCaptor.getValue();
    assertThat(cacheCheckOperation.getName()).isEqualTo(operationName);
    ArgumentCaptor<Operation> completedOperationCaptor = ArgumentCaptor.forClass(Operation.class);
    verify(mockBackplane, times(1)).putOperation(completedOperationCaptor.capture(), eq(COMPLETED));
    Operation completedOperation = completedOperationCaptor.getValue();
    assertThat(completedOperation.getName()).isEqualTo(operationName);
    ExecuteResponse executeResponse = completedOperation.getResponse().unpack(ExecuteResponse.class);
    assertThat(executeResponse.getResult()).isEqualTo(actionResult);
    assertThat(executeResponse.getCachedResult()).isTrue();
    Watcher mockWatcher = mock(Watcher.class);
    instance.execute(actionDigest, /* skipCacheLookup=*/
    false, ExecutionPolicy.getDefaultInstance(), ResultsCachePolicy.getDefaultInstance(), requestMetadata, /* watcher=*/
    mockWatcher);
    verify(mockWatcher, times(1)).observe(any(Operation.class));
    ArgumentCaptor<ExecuteEntry> executeEntryCaptor = ArgumentCaptor.forClass(ExecuteEntry.class);
    verify(mockBackplane, times(1)).prequeue(executeEntryCaptor.capture(), any(Operation.class));
    ExecuteEntry executeEntry = executeEntryCaptor.getValue();
    assertThat(executeEntry.getSkipCacheLookup()).isTrue();
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) Watcher(build.buildfarm.common.Watcher) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ByteString(com.google.protobuf.ByteString) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) QueueEntry(build.buildfarm.v1test.QueueEntry) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) ActionResult(build.bazel.remote.execution.v2.ActionResult) Poller(build.buildfarm.common.Poller) Test(org.junit.Test)

Example 13 with RequestMetadata

use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.

the class ExecutionServiceTest method keepaliveIsCancelledWithContext.

@SuppressWarnings("unchecked")
@Test
public void keepaliveIsCancelledWithContext() throws Exception {
    ScheduledExecutorService keepaliveScheduler = newSingleThreadScheduledExecutor();
    ExecutionService service = new ExecutionService(instance, /* keepaliveAfter=*/
    1, // far enough in the future that we'll get scheduled and
    SECONDS, /* keepaliveUnit=*/
    keepaliveScheduler, new LogMetricsPublisher(// cancelled without executing
    MetricsConfig.getDefaultInstance()));
    ServerCallStreamObserver<Operation> response = mock(ServerCallStreamObserver.class);
    RequestMetadata requestMetadata = RequestMetadata.newBuilder().build();
    Operation operation = Operation.newBuilder().setName("immediately-cancelled-watch-operation").build();
    KeepaliveWatcher watcher = service.createWatcher(response, requestMetadata);
    watcher.observe(operation);
    ListenableFuture<?> future = watcher.getFuture();
    assertThat(future).isNotNull();
    ArgumentCaptor<Runnable> onCancelHandlerCaptor = ArgumentCaptor.forClass(Runnable.class);
    verify(response, times(1)).setOnCancelHandler(onCancelHandlerCaptor.capture());
    Runnable onCancelHandler = onCancelHandlerCaptor.getValue();
    onCancelHandler.run();
    assertThat(future.isCancelled()).isTrue();
    assertThat(shutdownAndAwaitTermination(keepaliveScheduler, 1, SECONDS)).isTrue();
    // should only get one call for the real operation
    verify(response, times(1)).onNext(operation);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) KeepaliveWatcher(build.buildfarm.server.ExecutionService.KeepaliveWatcher) LogMetricsPublisher(build.buildfarm.metrics.log.LogMetricsPublisher) Operation(com.google.longrunning.Operation) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Example 14 with RequestMetadata

use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.

the class AbstractServerInstanceTest method outputDirectoriesFilesAreEnsuredPresent.

@SuppressWarnings("unchecked")
@Test
public void outputDirectoriesFilesAreEnsuredPresent() throws Exception {
    // our test subjects - these should appear in the findMissingBlobs request
    Digest fileDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("Output Directory Root File Content"));
    Digest childFileDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("Output Directory Child File Content"));
    Digest otherFileDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("Another Output Directory File Content"));
    // setup block and ensureOutputsPresent trigger
    RequestMetadata requestMetadata = RequestMetadata.newBuilder().setCorrelatedInvocationsId("https://localhost:12345/test/build?ENSURE_OUTPUTS_PRESENT=true#92af266a-c5bf-48ca-a723-344ae516a786").build();
    ContentAddressableStorage contentAddressableStorage = mock(ContentAddressableStorage.class);
    ActionCache actionCache = mock(ActionCache.class);
    AbstractServerInstance instance = new DummyServerInstance(contentAddressableStorage, actionCache);
    Tree tree = Tree.newBuilder().setRoot(Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(fileDigest)).build()).addChildren(Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(childFileDigest)).build()).build();
    Tree otherTree = Tree.newBuilder().setRoot(Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(otherFileDigest)).build()).build();
    Digest treeDigest = DIGEST_UTIL.compute(tree);
    doBlob(contentAddressableStorage, treeDigest, tree.toByteString(), requestMetadata);
    Digest otherTreeDigest = DIGEST_UTIL.compute(otherTree);
    doBlob(contentAddressableStorage, otherTreeDigest, otherTree.toByteString(), requestMetadata);
    ActionKey actionKey = DigestUtil.asActionKey(DIGEST_UTIL.compute(ByteString.copyFromUtf8("action")));
    ActionResult actionResult = ActionResult.newBuilder().addOutputDirectories(OutputDirectory.newBuilder().setTreeDigest(treeDigest).build()).addOutputDirectories(OutputDirectory.newBuilder().setTreeDigest(otherTreeDigest).build()).build();
    when(actionCache.get(actionKey)).thenReturn(immediateFuture(actionResult));
    // invocation
    assertThat(instance.getActionResult(actionKey, requestMetadata).get()).isEqualTo(actionResult);
    // validation
    ArgumentCaptor<Iterable<Digest>> findMissingBlobsCaptor = ArgumentCaptor.forClass(Iterable.class);
    verify(contentAddressableStorage, times(1)).get(eq(treeDigest), /* offset=*/
    eq(0L), eq(treeDigest.getSizeBytes()), any(ServerCallStreamObserver.class), eq(requestMetadata));
    verify(contentAddressableStorage, times(1)).findMissingBlobs(findMissingBlobsCaptor.capture());
    assertThat(findMissingBlobsCaptor.getValue()).containsAtLeast(fileDigest, childFileDigest, otherFileDigest);
}
Also used : ActionCache(build.buildfarm.ac.ActionCache) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) ActionResult(build.bazel.remote.execution.v2.ActionResult) Digest(build.bazel.remote.execution.v2.Digest) ContentAddressableStorage(build.buildfarm.cas.ContentAddressableStorage) Tree(build.bazel.remote.execution.v2.Tree) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Example 15 with RequestMetadata

use of com.google.cloud.talent.v4.RequestMetadata in project bazel-buildfarm by bazelbuild.

the class ExecutionService method execute.

@Override
public void execute(ExecuteRequest request, StreamObserver<Operation> responseObserver) {
    ServerCallStreamObserver<Operation> serverCallStreamObserver = (ServerCallStreamObserver<Operation>) responseObserver;
    try {
        RequestMetadata requestMetadata = TracingMetadataUtils.fromCurrentContext();
        withCancellation(serverCallStreamObserver, instance.execute(request.getActionDigest(), request.getSkipCacheLookup(), request.getExecutionPolicy(), request.getResultsCachePolicy(), requestMetadata, createWatcher(serverCallStreamObserver, requestMetadata)));
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) Operation(com.google.longrunning.Operation) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata)

Aggregations

RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)17 Digest (build.bazel.remote.execution.v2.Digest)11 ByteString (com.google.protobuf.ByteString)8 ServerCallStreamObserver (io.grpc.stub.ServerCallStreamObserver)7 ActionResult (build.bazel.remote.execution.v2.ActionResult)6 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)6 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)6 ActionKey (build.buildfarm.common.DigestUtil.ActionKey)6 Operation (com.google.longrunning.Operation)6 DigestUtil (build.buildfarm.common.DigestUtil)5 Watcher (build.buildfarm.common.Watcher)5 Write (build.buildfarm.common.Write)5 Instance (build.buildfarm.instance.Instance)5 QueuedOperation (build.buildfarm.v1test.QueuedOperation)4 Job (com.google.cloud.talent.v4beta1.Job)4 JobServiceClient (com.google.cloud.talent.v4beta1.JobServiceClient)4 RequestMetadata (com.google.cloud.talent.v4beta1.RequestMetadata)4 SearchJobsRequest (com.google.cloud.talent.v4beta1.SearchJobsRequest)4 Duration (com.google.protobuf.Duration)4 Test (org.junit.Test)4