use of build.bazel.remote.execution.v2.FindMissingBlobsRequest in project bazel-buildfarm by bazelbuild.
the class ContentAddressableStorageService method findMissingBlobs.
@Override
public void findMissingBlobs(FindMissingBlobsRequest request, StreamObserver<FindMissingBlobsResponse> responseObserver) {
FindMissingBlobsResponse.Builder responseBuilder = FindMissingBlobsResponse.newBuilder();
try {
for (Digest blobDigest : request.getBlobDigestsList()) {
if (!simpleBlobStore.containsKey(blobDigest.getHash())) {
responseBuilder.addMissingBlobDigests(blobDigest);
}
}
responseObserver.onNext(responseBuilder.build());
responseObserver.onCompleted();
} catch (IOException e) {
responseObserver.onError(Status.fromThrowable(e).asException());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
use of build.bazel.remote.execution.v2.FindMissingBlobsRequest in project bazel-buildfarm by bazelbuild.
the class BuildFarmServerTest method findMissingBlobs.
@Test
public void findMissingBlobs() {
DigestUtil digestUtil = new DigestUtil(HashFunction.SHA256);
ByteString content = ByteString.copyFromUtf8("Hello, World!");
Iterable<Digest> digests = Collections.singleton(digestUtil.compute(content));
FindMissingBlobsRequest request = FindMissingBlobsRequest.newBuilder().setInstanceName(INSTANCE_NAME).addAllBlobDigests(digests).build();
ContentAddressableStorageGrpc.ContentAddressableStorageBlockingStub stub = ContentAddressableStorageGrpc.newBlockingStub(inProcessChannel);
FindMissingBlobsResponse response = stub.findMissingBlobs(request);
assertThat(response.getMissingBlobDigestsList()).containsExactlyElementsIn(digests);
}
use of build.bazel.remote.execution.v2.FindMissingBlobsRequest in project bazel-buildfarm by bazelbuild.
the class StubInstanceTest method findMissingBlobsCallsFindMissingBlobs.
@Test
public void findMissingBlobsCallsFindMissingBlobs() throws ExecutionException, InterruptedException {
AtomicReference<FindMissingBlobsRequest> reference = new AtomicReference<>();
serviceRegistry.addService(new ContentAddressableStorageImplBase() {
@Override
public void findMissingBlobs(FindMissingBlobsRequest request, StreamObserver<FindMissingBlobsResponse> responseObserver) {
reference.set(request);
responseObserver.onNext(FindMissingBlobsResponse.getDefaultInstance());
responseObserver.onCompleted();
}
});
Instance instance = newStubInstance("findMissingBlobs-test");
Iterable<Digest> digests = ImmutableList.of(Digest.newBuilder().setHash("present").setSizeBytes(1).build());
assertThat(instance.findMissingBlobs(digests, RequestMetadata.getDefaultInstance()).get()).isEmpty();
instance.stop();
}
use of build.bazel.remote.execution.v2.FindMissingBlobsRequest in project bazel-buildfarm by bazelbuild.
the class ContentAddressableStorageService method instanceFindMissingBlobs.
void instanceFindMissingBlobs(Instance instance, FindMissingBlobsRequest request, StreamObserver<FindMissingBlobsResponse> responseObserver) {
Stopwatch stopwatch = Stopwatch.createStarted();
FindMissingBlobsResponse.Builder builder = FindMissingBlobsResponse.newBuilder();
ListenableFuture<FindMissingBlobsResponse.Builder> responseFuture = transform(instance.findMissingBlobs(request.getBlobDigestsList(), TracingMetadataUtils.fromCurrentContext()), builder::addAllMissingBlobDigests, directExecutor());
addCallback(responseFuture, new FutureCallback<FindMissingBlobsResponse.Builder>() {
@Override
public void onSuccess(FindMissingBlobsResponse.Builder builder) {
try {
FindMissingBlobsResponse response = builder.build();
responseObserver.onNext(response);
responseObserver.onCompleted();
long elapsedMicros = stopwatch.elapsed(MICROSECONDS);
missingBlobs.observe(request.getBlobDigestsList().size());
logger.log(Level.FINE, "FindMissingBlobs(" + instance.getName() + ") for " + request.getBlobDigestsList().size() + " blobs in " + elapsedMicros / 1000.0);
} catch (Throwable t) {
onFailure(t);
}
}
@SuppressWarnings("NullableProblems")
@Override
public void onFailure(Throwable t) {
Status status = Status.fromThrowable(t);
if (status.getCode() != Code.CANCELLED) {
logger.log(Level.SEVERE, format("findMissingBlobs(%s): %d", request.getInstanceName(), request.getBlobDigestsCount()), t);
responseObserver.onError(t);
}
}
}, directExecutor());
}
use of build.bazel.remote.execution.v2.FindMissingBlobsRequest in project bazel-buildfarm by bazelbuild.
the class StubInstance method findMissingBlobs.
@Override
public ListenableFuture<Iterable<Digest>> findMissingBlobs(Iterable<Digest> digests, RequestMetadata requestMetadata) {
throwIfStopped();
FindMissingBlobsRequest request = FindMissingBlobsRequest.newBuilder().setInstanceName(getName()).addAllBlobDigests(digests).build();
if (request.getSerializedSize() > Size.mbToBytes(4)) {
throw new IllegalStateException(String.format("FINDMISSINGBLOBS IS TOO LARGE: %d digests are required in one request!", request.getBlobDigestsCount()));
}
return transform(deadlined(casFutureStub).withInterceptors(attachMetadataInterceptor(requestMetadata)).findMissingBlobs(request), FindMissingBlobsResponse::getMissingBlobDigestsList, directExecutor());
}
Aggregations