Search in sources :

Example 1 with DigestUtil

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

the class IndexWorker method main.

public static void main(String[] args) throws Exception {
    String host = args[0];
    String instanceName = args[1];
    DigestUtil digestUtil = DigestUtil.forHash(args[2]);
    String reindexworker = args[3];
    ManagedChannel channel = createChannel(host);
    Instance instance = new StubInstance(instanceName, digestUtil, channel);
    CasIndexResults results = instance.reindexCas(reindexworker);
    System.out.println(results.toMessage());
    instance.stop();
}
Also used : StubInstance(build.buildfarm.instance.stub.StubInstance) Instance(build.buildfarm.instance.Instance) CasIndexResults(build.buildfarm.common.CasIndexResults) ManagedChannel(io.grpc.ManagedChannel) DigestUtil(build.buildfarm.common.DigestUtil) StubInstance(build.buildfarm.instance.stub.StubInstance)

Example 2 with DigestUtil

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

the class Mount method main.

@SuppressWarnings("BusyWait")
public static void main(String[] args) throws Exception {
    String host = args[0];
    String instanceName = args[1];
    DigestUtil digestUtil = DigestUtil.forHash(args[2]);
    ManagedChannel channel = createChannel(host);
    Instance instance = new StubInstance(instanceName, digestUtil, channel);
    Path cwd = Paths.get(".");
    FuseCAS fuse = new FuseCAS(cwd.resolve(args[3]), new InputStreamFactory() {

        final Map<Digest, ByteString> cache = new HashMap<>();

        public synchronized InputStream newInput(Digest blobDigest, long offset) {
            if (cache.containsKey(blobDigest)) {
                return cache.get(blobDigest).substring((int) offset).newInput();
            }
            try {
                ByteString value = getBlob(instance, blobDigest, RequestMetadata.getDefaultInstance());
                if (offset == 0) {
                    cache.put(blobDigest, value);
                }
                return value.newInput();
            } catch (IOException e) {
                return null;
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                return null;
            }
        }
    });
    // FIXME make bettar
    fuse.createInputRoot(args[5], DigestUtil.parseDigest(args[4]));
    try {
        // noinspection InfiniteLoopStatement
        for (; ; ) {
            Thread.sleep(1000);
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } finally {
        fuse.stop();
    }
}
Also used : Path(java.nio.file.Path) StubInstance(build.buildfarm.instance.stub.StubInstance) Instance(build.buildfarm.instance.Instance) Digest(build.bazel.remote.execution.v2.Digest) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) InputStream(java.io.InputStream) FuseCAS(build.buildfarm.worker.FuseCAS) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) DigestUtil(build.buildfarm.common.DigestUtil) InputStreamFactory(build.buildfarm.common.InputStreamFactory) StubInstance(build.buildfarm.instance.stub.StubInstance) ManagedChannel(io.grpc.ManagedChannel)

Example 3 with DigestUtil

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

the class MemoryCASTest method duplicateEntryRegistersMultipleOnExpiration.

@Test
public void duplicateEntryRegistersMultipleOnExpiration() throws IOException, InterruptedException {
    ContentAddressableStorage storage = new MemoryCAS(10);
    DigestUtil digestUtil = new DigestUtil(DigestUtil.HashFunction.SHA256);
    Runnable mockOnExpiration = mock(Runnable.class);
    storage.put(new Blob(ByteString.copyFromUtf8("stdout"), digestUtil), mockOnExpiration);
    storage.put(new Blob(ByteString.copyFromUtf8("stdout"), digestUtil), mockOnExpiration);
    verify(mockOnExpiration, never()).run();
    storage.put(new Blob(ByteString.copyFromUtf8("stderr"), digestUtil));
    verify(mockOnExpiration, times(2)).run();
}
Also used : Blob(build.buildfarm.cas.ContentAddressableStorage.Blob) DigestUtil(build.buildfarm.common.DigestUtil) Test(org.junit.Test)

Example 4 with DigestUtil

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

the class MemoryCASTest method expireShouldOccurAtLimitExactly.

@Test
public void expireShouldOccurAtLimitExactly() throws IOException, InterruptedException {
    ContentAddressableStorage storage = new MemoryCAS(11);
    DigestUtil digestUtil = new DigestUtil(DigestUtil.HashFunction.SHA256);
    Runnable mockOnExpiration = mock(Runnable.class);
    storage.put(new Blob(ByteString.copyFromUtf8("stdin"), digestUtil), mockOnExpiration);
    storage.put(new Blob(ByteString.copyFromUtf8("stdout"), digestUtil), mockOnExpiration);
    verify(mockOnExpiration, never()).run();
    storage.put(new Blob(ByteString.copyFromUtf8("a"), digestUtil));
    verify(mockOnExpiration, times(1)).run();
}
Also used : Blob(build.buildfarm.cas.ContentAddressableStorage.Blob) DigestUtil(build.buildfarm.common.DigestUtil) Test(org.junit.Test)

Example 5 with DigestUtil

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

the class BuildFarmServerTest method progressiveUploadCompletes.

@Test
public void progressiveUploadCompletes() throws Exception {
    DigestUtil digestUtil = new DigestUtil(HashFunction.SHA256);
    ByteString content = ByteString.copyFromUtf8("Hello, World!");
    Digest digest = digestUtil.compute(content);
    HashCode hash = HashCode.fromString(digest.getHash());
    UUID uuid = UUID.randomUUID();
    String resourceName = ByteStreamUploader.uploadResourceName(INSTANCE_NAME, uuid, hash, content.size());
    assertThat(getBlob(digest)).isNull();
    FutureWriteResponseObserver futureResponder = new FutureWriteResponseObserver();
    StreamObserver<WriteRequest> requestObserver = ByteStreamGrpc.newStub(inProcessChannel).write(futureResponder);
    ByteString shortContent = content.substring(0, 6);
    requestObserver.onNext(WriteRequest.newBuilder().setWriteOffset(0).setResourceName(resourceName).setData(shortContent).build());
    requestObserver.onError(Status.CANCELLED.asException());
    // should be done
    assertThat(futureResponder.isDone()).isTrue();
    futureResponder = new FutureWriteResponseObserver();
    requestObserver = ByteStreamGrpc.newStub(inProcessChannel).write(futureResponder);
    requestObserver.onNext(WriteRequest.newBuilder().setWriteOffset(6).setResourceName(resourceName).setData(content.substring(6)).setFinishWrite(true).build());
    requestObserver.onCompleted();
    assertThat(futureResponder.get()).isEqualTo(WriteResponse.newBuilder().setCommittedSize(content.size()).build());
    assertThat(getBlob(digest)).isEqualTo(content);
}
Also used : HashCode(com.google.common.hash.HashCode) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) WriteRequest(com.google.bytestream.ByteStreamProto.WriteRequest) ByteString(com.google.protobuf.ByteString) DigestUtil(build.buildfarm.common.DigestUtil) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

DigestUtil (build.buildfarm.common.DigestUtil)23 Instance (build.buildfarm.instance.Instance)10 Test (org.junit.Test)10 ByteString (com.google.protobuf.ByteString)8 StubInstance (build.buildfarm.instance.stub.StubInstance)7 ManagedChannel (io.grpc.ManagedChannel)7 Digest (build.bazel.remote.execution.v2.Digest)6 Blob (build.buildfarm.cas.ContentAddressableStorage.Blob)5 Path (java.nio.file.Path)3 ContentAddressableStorageGrpc (build.bazel.remote.execution.v2.ContentAddressableStorageGrpc)2 FindMissingBlobsResponse (build.bazel.remote.execution.v2.FindMissingBlobsResponse)2 CASFileCache (build.buildfarm.cas.cfc.CASFileCache)2 HashFunction (build.buildfarm.common.DigestUtil.HashFunction)2 InputStreamFactory (build.buildfarm.common.InputStreamFactory)2 ImmutableList (com.google.common.collect.ImmutableList)2 Operation (com.google.longrunning.Operation)2 NettyChannelBuilder (io.grpc.netty.NettyChannelBuilder)2 ConfigurationException (javax.naming.ConfigurationException)2 Action (build.bazel.remote.execution.v2.Action)1 ActionCacheGrpc (build.bazel.remote.execution.v2.ActionCacheGrpc)1