Search in sources :

Example 1 with Chunker

use of build.buildfarm.instance.stub.Chunker in project bazel-buildfarm by bazelbuild.

the class OperationQueueWorkerContext method uploadManifest.

private static void uploadManifest(UploadManifest manifest, ByteStreamUploader uploader) throws IOException, InterruptedException {
    Map<HashCode, Chunker> filesToUpload = Maps.newHashMap();
    Map<Digest, Path> digestToFile = manifest.getDigestToFile();
    Map<Digest, Chunker> digestToChunkers = manifest.getDigestToChunkers();
    Collection<Digest> digests = new ArrayList<>();
    digests.addAll(digestToFile.keySet());
    digests.addAll(digestToChunkers.keySet());
    for (Digest digest : digests) {
        Chunker chunker;
        Path file = digestToFile.get(digest);
        if (file != null) {
            chunker = Chunker.builder().setInput(digest.getSizeBytes(), file).build();
        } else {
            chunker = digestToChunkers.get(digest);
            if (chunker == null) {
                String message = "FindMissingBlobs call returned an unknown digest: " + digest;
                throw new IOException(message);
            }
        }
        filesToUpload.put(HashCode.fromString(digest.getHash()), chunker);
    }
    if (!filesToUpload.isEmpty()) {
        uploader.uploadBlobs(filesToUpload);
    }
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) Digest(build.bazel.remote.execution.v2.Digest) Chunker(build.buildfarm.instance.stub.Chunker) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Utils.getInterruptiblyOrIOException(build.buildfarm.common.io.Utils.getInterruptiblyOrIOException) IOException(java.io.IOException)

Example 2 with Chunker

use of build.buildfarm.instance.stub.Chunker in project bazel-buildfarm by bazelbuild.

the class UploadOutputsTest method uploadOutputsUploadsFiles.

@SuppressWarnings("unchecked")
@Test
public void uploadOutputsUploadsFiles() throws IOException, StatusException, InterruptedException {
    Path topdir = root.resolve("foo");
    Files.createDirectory(topdir);
    Path file = topdir.resolve("bar");
    Files.createFile(file);
    // maybe make some files...
    uploadOutputs(ImmutableList.of(), ImmutableList.of("foo"));
    Tree tree = Tree.newBuilder().setRoot(Directory.newBuilder().addFiles(FileNode.newBuilder().setName("bar").setDigest(DIGEST_UTIL.empty()).setIsExecutable(Files.isExecutable(file)).build()).build()).build();
    ByteString treeBlob = tree.toByteString();
    ArgumentCaptor<Map<HashCode, Chunker>> uploadCaptor = ArgumentCaptor.forClass(Map.class);
    verify(mockUploader).uploadBlobs(uploadCaptor.capture());
    Map<HashCode, Chunker> upload = uploadCaptor.getValue();
    Chunker emptyChunker = upload.get(DIGEST_UTIL.computeHash(ByteString.EMPTY));
    assertThat(emptyChunker.next().getData()).isEqualTo(ByteString.EMPTY);
    Chunker treeChunker = upload.get(DIGEST_UTIL.computeHash(treeBlob));
    assertThat(treeChunker.next().getData()).isEqualTo(treeBlob);
    assertThat(resultBuilder.getOutputDirectoriesList()).containsExactly(OutputDirectory.newBuilder().setPath("foo").setTreeDigest(DIGEST_UTIL.compute(tree)).build());
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) ByteString(com.google.protobuf.ByteString) Chunker(build.buildfarm.instance.stub.Chunker) Tree(build.bazel.remote.execution.v2.Tree) Map(java.util.Map) Test(org.junit.Test)

Example 3 with Chunker

use of build.buildfarm.instance.stub.Chunker in project bazel-buildfarm by bazelbuild.

the class UploadOutputsTest method uploadOutputsUploadsNestedDirectories.

@SuppressWarnings("unchecked")
@Test
public void uploadOutputsUploadsNestedDirectories() throws IOException, StatusException, InterruptedException {
    Path topdir = root.resolve("foo");
    Files.createDirectory(topdir);
    Path subdir = topdir.resolve("bar");
    Files.createDirectory(subdir);
    Path file = subdir.resolve("baz");
    Files.createFile(file);
    // maybe make some files...
    uploadOutputs(ImmutableList.of(), ImmutableList.of("foo"));
    Directory subDirectory = Directory.newBuilder().addFiles(FileNode.newBuilder().setName("baz").setDigest(DIGEST_UTIL.empty()).setIsExecutable(Files.isExecutable(file)).build()).build();
    Tree tree = Tree.newBuilder().setRoot(Directory.newBuilder().addDirectories(DirectoryNode.newBuilder().setName("bar").setDigest(DIGEST_UTIL.compute(subDirectory)).build()).build()).addChildren(subDirectory).build();
    ByteString treeBlob = tree.toByteString();
    ArgumentCaptor<Map<HashCode, Chunker>> uploadCaptor = ArgumentCaptor.forClass(Map.class);
    verify(mockUploader).uploadBlobs(uploadCaptor.capture());
    Map<HashCode, Chunker> upload = uploadCaptor.getValue();
    Chunker emptyChunker = upload.get(DIGEST_UTIL.computeHash(ByteString.EMPTY));
    assertThat(emptyChunker.next().getData()).isEqualTo(ByteString.EMPTY);
    Chunker treeChunker = upload.get(DIGEST_UTIL.computeHash(treeBlob));
    assertThat(treeChunker.next().getData()).isEqualTo(treeBlob);
    assertThat(resultBuilder.getOutputDirectoriesList()).containsExactly(OutputDirectory.newBuilder().setPath("foo").setTreeDigest(DIGEST_UTIL.compute(tree)).build());
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) ByteString(com.google.protobuf.ByteString) Chunker(build.buildfarm.instance.stub.Chunker) Tree(build.bazel.remote.execution.v2.Tree) Map(java.util.Map) Directory(build.bazel.remote.execution.v2.Directory) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) Test(org.junit.Test)

Example 4 with Chunker

use of build.buildfarm.instance.stub.Chunker in project bazel-buildfarm by bazelbuild.

the class UploadOutputsTest method uploadOutputsUploadsEmptyOutputDirectories.

@SuppressWarnings("unchecked")
@Test
public void uploadOutputsUploadsEmptyOutputDirectories() throws IOException, StatusException, InterruptedException {
    Files.createDirectory(root.resolve("foo"));
    // maybe make some files...
    uploadOutputs(ImmutableList.of(), ImmutableList.of("foo"));
    Tree emptyTree = Tree.newBuilder().setRoot(Directory.getDefaultInstance()).build();
    ByteString emptyTreeBlob = emptyTree.toByteString();
    ArgumentCaptor<Map<HashCode, Chunker>> uploadCaptor = ArgumentCaptor.forClass(Map.class);
    verify(mockUploader).uploadBlobs(uploadCaptor.capture());
    Map<HashCode, Chunker> upload = uploadCaptor.getValue();
    Chunker chunker = upload.get(DIGEST_UTIL.computeHash(emptyTreeBlob));
    assertThat(chunker.next().getData()).isEqualTo(emptyTreeBlob);
    assertThat(resultBuilder.getOutputDirectoriesList()).containsExactly(OutputDirectory.newBuilder().setPath("foo").setTreeDigest(DIGEST_UTIL.compute(emptyTree)).build());
}
Also used : HashCode(com.google.common.hash.HashCode) ByteString(com.google.protobuf.ByteString) Chunker(build.buildfarm.instance.stub.Chunker) Tree(build.bazel.remote.execution.v2.Tree) Map(java.util.Map) Test(org.junit.Test)

Example 5 with Chunker

use of build.buildfarm.instance.stub.Chunker in project bazel-buildfarm by bazelbuild.

the class UploadManifest method addDirectory.

private void addDirectory(Path dir) throws IllegalStateException, IOException {
    Tree.Builder tree = Tree.newBuilder();
    Directory root = computeDirectory(dir, tree);
    tree.setRoot(root);
    ByteString blob = tree.build().toByteString();
    Digest digest = digestUtil.compute(blob);
    Chunker chunker = Chunker.builder().setInput(blob).build();
    if (result != null) {
        result.addOutputDirectoriesBuilder().setPath(execRoot.relativize(dir).toString()).setTreeDigest(digest);
    }
    digestToChunkers.put(digest, chunker);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) Chunker(build.buildfarm.instance.stub.Chunker) Tree(build.bazel.remote.execution.v2.Tree) Directory(build.bazel.remote.execution.v2.Directory)

Aggregations

Chunker (build.buildfarm.instance.stub.Chunker)6 ByteString (com.google.protobuf.ByteString)5 Tree (build.bazel.remote.execution.v2.Tree)4 HashCode (com.google.common.hash.HashCode)4 Digest (build.bazel.remote.execution.v2.Digest)3 Path (java.nio.file.Path)3 Map (java.util.Map)3 Test (org.junit.Test)3 Directory (build.bazel.remote.execution.v2.Directory)2 OutputDirectory (build.bazel.remote.execution.v2.OutputDirectory)1 Utils.getInterruptiblyOrIOException (build.buildfarm.common.io.Utils.getInterruptiblyOrIOException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1