Search in sources :

Example 1 with BatchUpdateBlobsResponse

use of build.bazel.remote.execution.v2.BatchUpdateBlobsResponse in project bazel-buildfarm by bazelbuild.

the class Executor method loadFilesIntoCAS.

private static void loadFilesIntoCAS(String instanceName, Channel channel, Path blobsDir) throws Exception {
    ContentAddressableStorageBlockingStub casStub = ContentAddressableStorageGrpc.newBlockingStub(channel);
    List<Digest> missingDigests = findMissingBlobs(instanceName, blobsDir, casStub);
    UUID uploadId = UUID.randomUUID();
    int[] bucketSizes = new int[128];
    BatchUpdateBlobsRequest.Builder[] buckets = new BatchUpdateBlobsRequest.Builder[128];
    for (int i = 0; i < 128; i++) {
        bucketSizes[i] = 0;
        buckets[i] = BatchUpdateBlobsRequest.newBuilder().setInstanceName(instanceName);
    }
    ByteStreamStub bsStub = ByteStreamGrpc.newStub(channel);
    for (Digest missingDigest : missingDigests) {
        Path path = blobsDir.resolve(missingDigest.getHash() + "_" + missingDigest.getSizeBytes());
        if (missingDigest.getSizeBytes() < Size.mbToBytes(1)) {
            Request request = Request.newBuilder().setDigest(missingDigest).setData(ByteString.copyFrom(Files.readAllBytes(path))).build();
            int maxBucketSize = 0;
            long minBucketSize = Size.mbToBytes(2) + 1;
            int maxBucketIndex = 0;
            int minBucketIndex = -1;
            int size = (int) missingDigest.getSizeBytes() + 48;
            for (int i = 0; i < 128; i++) {
                int newBucketSize = bucketSizes[i] + size;
                if (newBucketSize < Size.mbToBytes(2) && bucketSizes[i] < minBucketSize) {
                    minBucketSize = bucketSizes[i];
                    minBucketIndex = i;
                }
                if (bucketSizes[i] > maxBucketSize) {
                    maxBucketSize = bucketSizes[i];
                    maxBucketIndex = i;
                }
            }
            if (minBucketIndex < 0) {
                bucketSizes[maxBucketIndex] = size;
                BatchUpdateBlobsRequest batchRequest = buckets[maxBucketIndex].build();
                Stopwatch stopwatch = Stopwatch.createStarted();
                BatchUpdateBlobsResponse batchResponse = casStub.batchUpdateBlobs(batchRequest);
                long usecs = stopwatch.elapsed(MICROSECONDS);
                checkState(batchResponse.getResponsesList().stream().allMatch(response -> Code.forNumber(response.getStatus().getCode()) == Code.OK));
                System.out.println("Updated " + batchRequest.getRequestsCount() + " blobs in " + (usecs / 1000.0) + "ms");
                buckets[maxBucketIndex] = BatchUpdateBlobsRequest.newBuilder().setInstanceName(instanceName).addRequests(request);
            } else {
                bucketSizes[minBucketIndex] += size;
                buckets[minBucketIndex].addRequests(request);
            }
        } else {
            Stopwatch stopwatch = Stopwatch.createStarted();
            SettableFuture<WriteResponse> writtenFuture = SettableFuture.create();
            StreamObserver<WriteRequest> requestObserver = bsStub.write(new StreamObserver<WriteResponse>() {

                @Override
                public void onNext(WriteResponse response) {
                    writtenFuture.set(response);
                }

                @Override
                public void onCompleted() {
                }

                @Override
                public void onError(Throwable t) {
                    writtenFuture.setException(t);
                }
            });
            HashCode hash = HashCode.fromString(missingDigest.getHash());
            String resourceName = uploadResourceName(instanceName, uploadId, hash, missingDigest.getSizeBytes());
            try (InputStream in = Files.newInputStream(path)) {
                boolean first = true;
                long writtenBytes = 0;
                byte[] buf = new byte[64 * 1024];
                while (writtenBytes != missingDigest.getSizeBytes()) {
                    int len = in.read(buf);
                    WriteRequest.Builder request = WriteRequest.newBuilder();
                    if (first) {
                        request.setResourceName(resourceName);
                    }
                    request.setData(ByteString.copyFrom(buf, 0, len)).setWriteOffset(writtenBytes);
                    if (writtenBytes + len == missingDigest.getSizeBytes()) {
                        request.setFinishWrite(true);
                    }
                    requestObserver.onNext(request.build());
                    writtenBytes += len;
                    first = false;
                }
                writtenFuture.get();
                System.out.println("Wrote long " + DigestUtil.toString(missingDigest) + " in " + (stopwatch.elapsed(MICROSECONDS) / 1000.0) + "ms");
            }
        }
    }
    for (int i = 0; i < 128; i++) {
        if (bucketSizes[i] > 0) {
            BatchUpdateBlobsRequest batchRequest = buckets[i].build();
            Stopwatch stopwatch = Stopwatch.createStarted();
            BatchUpdateBlobsResponse batchResponse = casStub.batchUpdateBlobs(batchRequest);
            long usecs = stopwatch.elapsed(MICROSECONDS);
            checkState(batchResponse.getResponsesList().stream().allMatch(response -> Code.forNumber(response.getStatus().getCode()) == Code.OK));
            System.out.println("Updated " + batchRequest.getRequestsCount() + " blobs in " + (usecs / 1000.0) + "ms");
        }
    }
}
Also used : ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) ScheduledFuture(java.util.concurrent.ScheduledFuture) ManagedChannel(io.grpc.ManagedChannel) NegotiationType(io.grpc.netty.NegotiationType) Scanner(java.util.Scanner) SettableFuture(com.google.common.util.concurrent.SettableFuture) Channel(io.grpc.Channel) ByteStreamGrpc(com.google.bytestream.ByteStreamGrpc) DirectoryStream(java.nio.file.DirectoryStream) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) StreamObserver(io.grpc.stub.StreamObserver) Digest(build.bazel.remote.execution.v2.Digest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteStreamUploader.uploadResourceName(build.buildfarm.instance.stub.ByteStreamUploader.uploadResourceName) EXECUTING(build.bazel.remote.execution.v2.ExecutionStage.Value.EXECUTING) Path(java.nio.file.Path) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ExecutionGrpc(build.bazel.remote.execution.v2.ExecutionGrpc) ExecutionStub(build.bazel.remote.execution.v2.ExecutionGrpc.ExecutionStub) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest) ExecuteRequest(build.bazel.remote.execution.v2.ExecuteRequest) FileStatus(build.buildfarm.common.io.FileStatus) UUID(java.util.UUID) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ByteString(com.google.protobuf.ByteString) List(java.util.List) Size(build.buildfarm.common.Size) MICROSECONDS(java.util.concurrent.TimeUnit.MICROSECONDS) FindMissingBlobsRequest(build.bazel.remote.execution.v2.FindMissingBlobsRequest) Stopwatch(com.google.common.base.Stopwatch) Operation(com.google.longrunning.Operation) DigestUtil(build.buildfarm.common.DigestUtil) ContentAddressableStorageGrpc(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc) ImmutableList(com.google.common.collect.ImmutableList) ByteStreamStub(com.google.bytestream.ByteStreamGrpc.ByteStreamStub) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) Code(com.google.rpc.Code) MoreExecutors.shutdownAndAwaitTermination(com.google.common.util.concurrent.MoreExecutors.shutdownAndAwaitTermination) Utils.stat(build.buildfarm.common.io.Utils.stat) FileStore(java.nio.file.FileStore) Files(java.nio.file.Files) HashCode(com.google.common.hash.HashCode) ContentAddressableStorageBlockingStub(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageBlockingStub) IOException(java.io.IOException) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) WriteResponse(com.google.bytestream.ByteStreamProto.WriteResponse) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) AtomicLong(java.util.concurrent.atomic.AtomicLong) WriteRequest(com.google.bytestream.ByteStreamProto.WriteRequest) Paths(java.nio.file.Paths) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) Request(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest.Request) SECONDS(java.util.concurrent.TimeUnit.SECONDS) InputStream(java.io.InputStream) ContentAddressableStorageBlockingStub(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageBlockingStub) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) Stopwatch(com.google.common.base.Stopwatch) ByteString(com.google.protobuf.ByteString) HashCode(com.google.common.hash.HashCode) UUID(java.util.UUID) Path(java.nio.file.Path) Digest(build.bazel.remote.execution.v2.Digest) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) ByteStreamStub(com.google.bytestream.ByteStreamGrpc.ByteStreamStub) WriteRequest(com.google.bytestream.ByteStreamProto.WriteRequest) InputStream(java.io.InputStream) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest) ExecuteRequest(build.bazel.remote.execution.v2.ExecuteRequest) FindMissingBlobsRequest(build.bazel.remote.execution.v2.FindMissingBlobsRequest) WriteRequest(com.google.bytestream.ByteStreamProto.WriteRequest) Request(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest.Request) WriteResponse(com.google.bytestream.ByteStreamProto.WriteResponse) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest)

Example 2 with BatchUpdateBlobsResponse

use of build.bazel.remote.execution.v2.BatchUpdateBlobsResponse in project bazel-buildfarm by bazelbuild.

the class StubInstanceTest method putAllBlobsUploadsBlobs.

@Test
public void putAllBlobsUploadsBlobs() throws Exception {
    String instanceName = "putAllBlobs-test";
    serviceRegistry.addService(new ContentAddressableStorageImplBase() {

        @Override
        public void batchUpdateBlobs(BatchUpdateBlobsRequest batchRequest, StreamObserver<BatchUpdateBlobsResponse> responseObserver) {
            checkState(batchRequest.getInstanceName().equals(instanceName));
            responseObserver.onNext(BatchUpdateBlobsResponse.newBuilder().addAllResponses(batchRequest.getRequestsList().stream().map(request -> Response.newBuilder().setDigest(request.getDigest()).build()).collect(Collectors.toList())).build());
            responseObserver.onCompleted();
        }
    });
    Instance instance = newStubInstance("putAllBlobs-test");
    ByteString first = ByteString.copyFromUtf8("first");
    ByteString last = ByteString.copyFromUtf8("last");
    ImmutableList<ByteString> blobs = ImmutableList.of(first, last);
    ImmutableList<Digest> digests = ImmutableList.of(DIGEST_UTIL.compute(first), DIGEST_UTIL.compute(last));
    assertThat(instance.putAllBlobs(blobs, RequestMetadata.getDefaultInstance())).containsAllIn(digests);
}
Also used : RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) ReadBlobInterchange(build.buildfarm.instance.stub.StubInstance.ReadBlobInterchange) StreamObserver(io.grpc.stub.StreamObserver) Digest(build.bazel.remote.execution.v2.Digest) ReadRequest(com.google.bytestream.ByteStreamProto.ReadRequest) After(org.junit.After) Status(io.grpc.Status) InProcessChannelBuilder(io.grpc.inprocess.InProcessChannelBuilder) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest) ByteStreamImplBase(com.google.bytestream.ByteStreamGrpc.ByteStreamImplBase) ClientCallStreamObserver(io.grpc.stub.ClientCallStreamObserver) Collectors(java.util.stream.Collectors) Instance(build.buildfarm.instance.Instance) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ByteString(com.google.protobuf.ByteString) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) ByteStreams(com.google.common.io.ByteStreams) QueryWriteStatusResponse(com.google.bytestream.ByteStreamProto.QueryWriteStatusResponse) Mockito.mock(org.mockito.Mockito.mock) GetActionResultRequest(build.bazel.remote.execution.v2.GetActionResultRequest) ContentAddressableStorageImplBase(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FindMissingBlobsRequest(build.bazel.remote.execution.v2.FindMissingBlobsRequest) RunWith(org.junit.runner.RunWith) QueryWriteStatusRequest(com.google.bytestream.ByteStreamProto.QueryWriteStatusRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) DigestUtil(build.buildfarm.common.DigestUtil) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) InProcessServerBuilder(io.grpc.inprocess.InProcessServerBuilder) Code(io.grpc.Status.Code) Action(build.bazel.remote.execution.v2.Action) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) ActionResult(build.bazel.remote.execution.v2.ActionResult) ReadResponse(com.google.bytestream.ByteStreamProto.ReadResponse) FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) Server(io.grpc.Server) Before(org.junit.Before) OutputStream(java.io.OutputStream) UpdateActionResultRequest(build.bazel.remote.execution.v2.UpdateActionResultRequest) ActionCacheImplBase(build.bazel.remote.execution.v2.ActionCacheGrpc.ActionCacheImplBase) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) Write(build.buildfarm.common.Write) Mockito.verify(org.mockito.Mockito.verify) WriteResponse(com.google.bytestream.ByteStreamProto.WriteResponse) ExecutionException(java.util.concurrent.ExecutionException) Response(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse.Response) WriteRequest(com.google.bytestream.ByteStreamProto.WriteRequest) SECONDS(java.util.concurrent.TimeUnit.SECONDS) InputStream(java.io.InputStream) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) Instance(build.buildfarm.instance.Instance) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) ContentAddressableStorageImplBase(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase) ByteString(com.google.protobuf.ByteString) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest) Test(org.junit.Test)

Example 3 with BatchUpdateBlobsResponse

use of build.bazel.remote.execution.v2.BatchUpdateBlobsResponse in project bazel-buildfarm by bazelbuild.

the class BuildFarmServerTest method batchUpdateBlobs.

@Test
public void batchUpdateBlobs() {
    DigestUtil digestUtil = new DigestUtil(HashFunction.SHA256);
    ByteString content = ByteString.copyFromUtf8("Hello, World!");
    Digest digest = digestUtil.compute(content);
    BatchUpdateBlobsRequest request = BatchUpdateBlobsRequest.newBuilder().setInstanceName(INSTANCE_NAME).addRequests(Request.newBuilder().setDigest(digest).setData(content).build()).build();
    ContentAddressableStorageGrpc.ContentAddressableStorageBlockingStub stub = ContentAddressableStorageGrpc.newBlockingStub(inProcessChannel);
    BatchUpdateBlobsResponse response = stub.batchUpdateBlobs(request);
    Response expected = Response.newBuilder().setDigest(digest).setStatus(com.google.rpc.Status.newBuilder().setCode(Code.OK.getNumber()).build()).build();
    assertThat(response.getResponsesList()).containsExactlyElementsIn(Collections.singleton(expected));
}
Also used : BatchReadBlobsResponse(build.bazel.remote.execution.v2.BatchReadBlobsResponse) ListOperationsResponse(com.google.longrunning.ListOperationsResponse) FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) WriteResponse(com.google.bytestream.ByteStreamProto.WriteResponse) Response(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse.Response) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) Digest(build.bazel.remote.execution.v2.Digest) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) ByteString(com.google.protobuf.ByteString) ContentAddressableStorageGrpc(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc) DigestUtil(build.buildfarm.common.DigestUtil) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest) Test(org.junit.Test)

Example 4 with BatchUpdateBlobsResponse

use of build.bazel.remote.execution.v2.BatchUpdateBlobsResponse in project bazel-buildfarm by bazelbuild.

the class StubInstance method putAllBlobs.

@Override
public Iterable<Digest> putAllBlobs(Iterable<ByteString> blobs, RequestMetadata requestMetadata) {
    long totalSize = 0;
    ImmutableList.Builder<Request> requests = ImmutableList.builder();
    for (ByteString blob : blobs) {
        checkState(totalSize + blob.size() <= maxBatchUpdateBlobsSize);
        requests.add(Request.newBuilder().setDigest(digestUtil.compute(blob)).setData(blob).build());
        totalSize += blob.size();
    }
    BatchUpdateBlobsRequest batchRequest = BatchUpdateBlobsRequest.newBuilder().setInstanceName(getName()).addAllRequests(requests.build()).build();
    BatchUpdateBlobsResponse batchResponse = deadlined(casBlockingStub).withInterceptors(attachMetadataInterceptor(requestMetadata)).batchUpdateBlobs(batchRequest);
    PutAllBlobsException exception = null;
    for (BatchUpdateBlobsResponse.Response response : batchResponse.getResponsesList()) {
        com.google.rpc.Status status = response.getStatus();
        if (Code.forNumber(status.getCode()) != Code.OK) {
            if (exception == null) {
                exception = new PutAllBlobsException();
            }
            exception.addFailedResponse(response);
        }
    }
    if (exception != null) {
        throw exception;
    }
    return Iterables.transform(batchResponse.getResponsesList(), BatchUpdateBlobsResponse.Response::getDigest);
}
Also used : OperationsGrpc(com.google.longrunning.OperationsGrpc) ByteStreamGrpc(com.google.bytestream.ByteStreamGrpc) OperationQueueGrpc(build.buildfarm.v1test.OperationQueueGrpc) ExecutionGrpc(build.bazel.remote.execution.v2.ExecutionGrpc) ActionCacheGrpc(build.bazel.remote.execution.v2.ActionCacheGrpc) WorkerProfileGrpc(build.buildfarm.v1test.WorkerProfileGrpc) AdminGrpc(build.buildfarm.v1test.AdminGrpc) CapabilitiesGrpc(build.bazel.remote.execution.v2.CapabilitiesGrpc) ContentAddressableStorageGrpc(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc) ShutDownWorkerGrpc(build.buildfarm.v1test.ShutDownWorkerGrpc) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) ImmutableList(com.google.common.collect.ImmutableList) ByteString(com.google.protobuf.ByteString) BackplaneStatusRequest(build.buildfarm.v1test.BackplaneStatusRequest) ReadRequest(com.google.bytestream.ByteStreamProto.ReadRequest) WaitExecutionRequest(build.bazel.remote.execution.v2.WaitExecutionRequest) ListOperationsRequest(com.google.longrunning.ListOperationsRequest) TakeOperationRequest(build.buildfarm.v1test.TakeOperationRequest) FindMissingBlobsRequest(build.bazel.remote.execution.v2.FindMissingBlobsRequest) WorkerProfileRequest(build.buildfarm.v1test.WorkerProfileRequest) ReindexAllCasRequest(build.buildfarm.v1test.ReindexAllCasRequest) WorkerListRequest(build.buildfarm.v1test.WorkerListRequest) Request(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest.Request) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest) PrepareWorkerForGracefulShutDownRequest(build.buildfarm.v1test.PrepareWorkerForGracefulShutDownRequest) ReindexCasRequest(build.buildfarm.v1test.ReindexCasRequest) GetActionResultRequest(build.bazel.remote.execution.v2.GetActionResultRequest) GetClientStartTimeRequest(build.buildfarm.v1test.GetClientStartTimeRequest) GetTreeRequest(build.bazel.remote.execution.v2.GetTreeRequest) PollOperationRequest(build.buildfarm.v1test.PollOperationRequest) CancelOperationRequest(com.google.longrunning.CancelOperationRequest) GetCapabilitiesRequest(build.bazel.remote.execution.v2.GetCapabilitiesRequest) UpdateActionResultRequest(build.bazel.remote.execution.v2.UpdateActionResultRequest) GetOperationRequest(com.google.longrunning.GetOperationRequest) DeleteOperationRequest(com.google.longrunning.DeleteOperationRequest) BatchReadBlobsRequest(build.bazel.remote.execution.v2.BatchReadBlobsRequest) ShutDownWorkerGracefullyRequest(build.buildfarm.v1test.ShutDownWorkerGracefullyRequest) BatchReadBlobsResponse(build.bazel.remote.execution.v2.BatchReadBlobsResponse) ListOperationsResponse(com.google.longrunning.ListOperationsResponse) ReadResponse(com.google.bytestream.ByteStreamProto.ReadResponse) FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) GetTreeResponse(build.bazel.remote.execution.v2.GetTreeResponse) Response(build.bazel.remote.execution.v2.BatchReadBlobsResponse.Response) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest)

Example 5 with BatchUpdateBlobsResponse

use of build.bazel.remote.execution.v2.BatchUpdateBlobsResponse in project bazel-buildfarm by bazelbuild.

the class ContentAddressableStorageService method batchUpdateBlobs.

@Override
public void batchUpdateBlobs(BatchUpdateBlobsRequest batchRequest, StreamObserver<BatchUpdateBlobsResponse> responseObserver) {
    ImmutableList.Builder<BatchUpdateBlobsResponse.Response> responses = new ImmutableList.Builder<>();
    Function<com.google.rpc.Code, com.google.rpc.Status> statusForCode = (code) -> com.google.rpc.Status.newBuilder().setCode(code.getNumber()).build();
    for (Request request : batchRequest.getRequestsList()) {
        Digest digest = request.getDigest();
        try {
            simpleBlobStore.put(digest.getHash(), digest.getSizeBytes(), request.getData().newInput());
            responses.add(BatchUpdateBlobsResponse.Response.newBuilder().setDigest(digest).setStatus(statusForCode.apply(com.google.rpc.Code.OK)).build());
        } catch (IOException e) {
            StatusException statusException = Status.fromThrowable(e).asException();
            responses.add(BatchUpdateBlobsResponse.Response.newBuilder().setDigest(digest).setStatus(StatusProto.fromThrowable(statusException)).build());
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            return;
        }
    }
    responseObserver.onNext(BatchUpdateBlobsResponse.newBuilder().addAllResponses(responses.build()).build());
    responseObserver.onCompleted();
}
Also used : Status(io.grpc.Status) Directory(build.bazel.remote.execution.v2.Directory) GetTreeRequest(build.bazel.remote.execution.v2.GetTreeRequest) TreeIterator(build.buildfarm.common.TreeIterator) FindMissingBlobsRequest(build.bazel.remote.execution.v2.FindMissingBlobsRequest) StatusException(io.grpc.StatusException) Function(java.util.function.Function) TokenizableIterator(build.buildfarm.common.TokenizableIterator) StreamObserver(io.grpc.stub.StreamObserver) ContentAddressableStorageGrpc(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc) ImmutableList(com.google.common.collect.ImmutableList) StatusProto(io.grpc.protobuf.StatusProto) Digest(build.bazel.remote.execution.v2.Digest) FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) Status(io.grpc.Status) GetTreeResponse(build.bazel.remote.execution.v2.GetTreeResponse) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest) Futures.catching(com.google.common.util.concurrent.Futures.catching) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) DirectoryEntry(build.buildfarm.common.TreeIterator.DirectoryEntry) Request(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest.Request) Futures.transform(com.google.common.util.concurrent.Futures.transform) Digest(build.bazel.remote.execution.v2.Digest) ImmutableList(com.google.common.collect.ImmutableList) GetTreeRequest(build.bazel.remote.execution.v2.GetTreeRequest) FindMissingBlobsRequest(build.bazel.remote.execution.v2.FindMissingBlobsRequest) BatchUpdateBlobsRequest(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest) Request(build.bazel.remote.execution.v2.BatchUpdateBlobsRequest.Request) IOException(java.io.IOException) FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) GetTreeResponse(build.bazel.remote.execution.v2.GetTreeResponse) BatchUpdateBlobsResponse(build.bazel.remote.execution.v2.BatchUpdateBlobsResponse) StatusException(io.grpc.StatusException)

Aggregations

BatchUpdateBlobsRequest (build.bazel.remote.execution.v2.BatchUpdateBlobsRequest)5 BatchUpdateBlobsResponse (build.bazel.remote.execution.v2.BatchUpdateBlobsResponse)5 FindMissingBlobsResponse (build.bazel.remote.execution.v2.FindMissingBlobsResponse)5 ByteString (com.google.protobuf.ByteString)5 ContentAddressableStorageGrpc (build.bazel.remote.execution.v2.ContentAddressableStorageGrpc)4 Digest (build.bazel.remote.execution.v2.Digest)4 FindMissingBlobsRequest (build.bazel.remote.execution.v2.FindMissingBlobsRequest)4 ImmutableList (com.google.common.collect.ImmutableList)4 Request (build.bazel.remote.execution.v2.BatchUpdateBlobsRequest.Request)3 DigestUtil (build.buildfarm.common.DigestUtil)3 BatchReadBlobsResponse (build.bazel.remote.execution.v2.BatchReadBlobsResponse)2 Response (build.bazel.remote.execution.v2.BatchUpdateBlobsResponse.Response)2 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)2 ExecutionGrpc (build.bazel.remote.execution.v2.ExecutionGrpc)2 GetActionResultRequest (build.bazel.remote.execution.v2.GetActionResultRequest)2 GetTreeRequest (build.bazel.remote.execution.v2.GetTreeRequest)2 GetTreeResponse (build.bazel.remote.execution.v2.GetTreeResponse)2 UpdateActionResultRequest (build.bazel.remote.execution.v2.UpdateActionResultRequest)2 WriteRequest (com.google.bytestream.ByteStreamProto.WriteRequest)2 WriteResponse (com.google.bytestream.ByteStreamProto.WriteResponse)2