Search in sources :

Example 1 with Tree

use of build.bazel.remote.execution.v2.Tree in project tools_remote by bazelbuild.

the class GrpcRemoteCacheTest method testDownloadOutputDirectoryNested.

@Test
public void testDownloadOutputDirectoryNested() throws Exception {
    GrpcRemoteCache client = newClient();
    Digest fooDigest = DIGEST_UTIL.computeAsUtf8("foo-contents");
    Digest quxDigest = DIGEST_UTIL.computeAsUtf8("qux-contents");
    Directory wobbleDirMessage = Directory.newBuilder().addFiles(FileNode.newBuilder().setName("qux").setDigest(quxDigest)).build();
    Digest wobbleDigest = DIGEST_UTIL.compute(wobbleDirMessage);
    Tree barTreeMessage = Tree.newBuilder().setRoot(Directory.newBuilder().addFiles(FileNode.newBuilder().setName("qux").setDigest(quxDigest)).addDirectories(DirectoryNode.newBuilder().setName("wobble").setDigest(wobbleDigest))).addChildren(wobbleDirMessage).build();
    Digest barTreeDigest = DIGEST_UTIL.compute(barTreeMessage);
    OutputDirectory barDirMessage = OutputDirectory.newBuilder().setPath("test/bar").setTreeDigest(barTreeDigest).build();
    Digest barDirDigest = DIGEST_UTIL.compute(barDirMessage);
    serviceRegistry.addService(new FakeImmutableCacheByteStreamImpl(ImmutableMap.of(fooDigest, "foo-contents", barTreeDigest, barTreeMessage.toByteString(), quxDigest, "qux-contents", barDirDigest, barDirMessage.toByteString())));
    client.downloadOutputDirectory(barDirMessage, execRoot.resolve("test/bar"));
    assertThat(Files.exists(execRoot.resolve("test/bar"))).isTrue();
    assertThat(Files.isDirectory(execRoot.resolve("test/bar"))).isTrue();
    assertThat(Files.exists(execRoot.resolve("test/bar/wobble"))).isTrue();
    assertThat(Files.isDirectory(execRoot.resolve("test/bar/wobble"))).isTrue();
    assertThat(Files.exists(execRoot.resolve("test/bar/wobble/qux"))).isTrue();
    assertThat(Files.isRegularFile(execRoot.resolve("test/bar/wobble/qux"))).isTrue();
    assertThat(Files.exists(execRoot.resolve("test/bar/qux"))).isTrue();
    assertThat(Files.isRegularFile(execRoot.resolve("test/bar/qux"))).isTrue();
    if (!System.getProperty("os.name").startsWith("Windows")) {
        assertThat(isExecutable(execRoot.resolve("test/bar/wobble/qux"))).isFalse();
        assertThat(isExecutable(execRoot.resolve("test/bar/qux"))).isFalse();
    }
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) Tree(build.bazel.remote.execution.v2.Tree) Directory(build.bazel.remote.execution.v2.Directory) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) Test(org.junit.Test)

Example 2 with Tree

use of build.bazel.remote.execution.v2.Tree in project tools_remote by bazelbuild.

the class RemoteClient method printActionV1.

// Output for print action command.
private void printActionV1(com.google.devtools.remoteexecution.v1test.Action action, int limit) throws IOException {
    // Note: Command V2 is backward compatible to V1. It adds fields but does not remove them, so we
    // can use it here.
    Command command = getCommand(toV2(action.getCommandDigest()));
    System.out.printf("Command [digest: %s]:\n", digestUtil.toString(toV2(action.getCommandDigest())));
    printCommand(command);
    Tree tree = cache.getTree(toV2(action.getInputRootDigest()));
    System.out.printf("\nInput files [total: %d, root Directory digest: %s]:\n", getNumFiles(tree), digestUtil.toString(toV2(action.getInputRootDigest())));
    listTree(Paths.get(""), tree, limit);
    System.out.println("\nOutput files:");
    printList(action.getOutputFilesList(), limit);
    System.out.println("\nOutput directories:");
    printList(action.getOutputDirectoriesList(), limit);
    System.out.println("\nPlatform:");
    if (action.hasPlatform() && !action.getPlatform().getPropertiesList().isEmpty()) {
        System.out.println(action.getPlatform().toString());
    } else {
        System.out.println("(none)");
    }
}
Also used : GetOutDirCommand(com.google.devtools.build.remote.client.RemoteClientOptions.GetOutDirCommand) Command(build.bazel.remote.execution.v2.Command) LsOutDirCommand(com.google.devtools.build.remote.client.RemoteClientOptions.LsOutDirCommand) GetDirCommand(com.google.devtools.build.remote.client.RemoteClientOptions.GetDirCommand) FailedActionsCommand(com.google.devtools.build.remote.client.RemoteClientOptions.FailedActionsCommand) ShowActionCommand(com.google.devtools.build.remote.client.RemoteClientOptions.ShowActionCommand) CatCommand(com.google.devtools.build.remote.client.RemoteClientOptions.CatCommand) PrintLogCommand(com.google.devtools.build.remote.client.RemoteClientOptions.PrintLogCommand) RunCommand(com.google.devtools.build.remote.client.RemoteClientOptions.RunCommand) LsCommand(com.google.devtools.build.remote.client.RemoteClientOptions.LsCommand) ShowActionResultCommand(com.google.devtools.build.remote.client.RemoteClientOptions.ShowActionResultCommand) Tree(build.bazel.remote.execution.v2.Tree)

Example 3 with Tree

use of build.bazel.remote.execution.v2.Tree in project tools_remote by bazelbuild.

the class AbstractRemoteActionCache method downloadDirectory.

/**
 * Download the full contents of a Directory to a local path given its digest.
 *
 * @param downloadPath The path to download the directory contents to.
 * @param directoryDigest The digest of the Directory to download.
 * @throws IOException
 */
public void downloadDirectory(Path downloadPath, Digest directoryDigest) throws IOException {
    Tree tree = getTree(directoryDigest);
    Map<Digest, Directory> childrenMap = new HashMap<>();
    for (Directory child : tree.getChildrenList()) {
        childrenMap.put(digestUtil.compute(child), child);
    }
    downloadDirectory(downloadPath, tree.getRoot(), childrenMap);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) HashMap(java.util.HashMap) Tree(build.bazel.remote.execution.v2.Tree) Directory(build.bazel.remote.execution.v2.Directory) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory)

Example 4 with Tree

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

the class ShardInstance method getTreeFuture.

@Override
protected ListenableFuture<Tree> getTreeFuture(String reason, Digest inputRoot, ExecutorService service, RequestMetadata requestMetadata) {
    SettableFuture<Void> future = SettableFuture.create();
    Tree.Builder tree = Tree.newBuilder().setRootDigest(inputRoot);
    Set<Digest> digests = Sets.newConcurrentHashSet();
    Queue<Digest> remaining = new ConcurrentLinkedQueue();
    remaining.offer(inputRoot);
    Context ctx = Context.current();
    TreeCallback callback = new TreeCallback(future) {

        @Override
        protected void onDirectory(Digest digest, Directory directory) {
            tree.putDirectories(digest.getHash(), directory);
            for (DirectoryNode childNode : directory.getDirectoriesList()) {
                Digest child = childNode.getDigest();
                if (digests.add(child)) {
                    remaining.offer(child);
                }
            }
        }

        @Override
        boolean next() {
            Digest nextDigest = remaining.poll();
            if (!future.isDone() && nextDigest != null) {
                ctx.run(() -> addCallback(transform(expectDirectory(reason, nextDigest, requestMetadata), directory -> new DirectoryEntry(nextDigest, directory), service), this, service));
                return true;
            }
            return false;
        }
    };
    callback.next();
    return transform(future, (result) -> tree.build(), service);
}
Also used : Context(io.grpc.Context) Digest(build.bazel.remote.execution.v2.Digest) DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) DirectoryEntry(build.buildfarm.common.TreeIterator.DirectoryEntry) Tree(build.buildfarm.v1test.Tree) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Directory(build.bazel.remote.execution.v2.Directory)

Example 5 with Tree

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

the class AbstractServerInstance method getTree.

@Override
public String getTree(Digest rootDigest, int pageSize, String pageToken, Tree.Builder tree) {
    tree.setRootDigest(rootDigest);
    if (pageSize == 0) {
        pageSize = getTreeDefaultPageSize();
    }
    if (pageSize >= 0 && pageSize > getTreeMaxPageSize()) {
        pageSize = getTreeMaxPageSize();
    }
    TokenizableIterator<DirectoryEntry> iter = createTreeIterator("getTree", rootDigest, pageToken);
    while (iter.hasNext() && pageSize != 0) {
        DirectoryEntry entry = iter.next();
        Directory directory = entry.getDirectory();
        // portion present and omit the rest.
        if (directory != null) {
            tree.putDirectories(entry.getDigest().getHash(), directory);
            if (pageSize > 0) {
                pageSize--;
            }
        }
    }
    return iter.toNextPageToken();
}
Also used : DirectoryEntry(build.buildfarm.common.TreeIterator.DirectoryEntry) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory) Directory(build.bazel.remote.execution.v2.Directory)

Aggregations

Directory (build.bazel.remote.execution.v2.Directory)20 Digest (build.bazel.remote.execution.v2.Digest)19 Tree (build.bazel.remote.execution.v2.Tree)17 OutputDirectory (build.bazel.remote.execution.v2.OutputDirectory)14 ByteString (com.google.protobuf.ByteString)9 Test (org.junit.Test)8 Tree (build.buildfarm.v1test.Tree)7 IOException (java.io.IOException)7 Command (build.bazel.remote.execution.v2.Command)4 GetTreeResponse (build.bazel.remote.execution.v2.GetTreeResponse)4 DirectoryEntry (build.buildfarm.common.TreeIterator.DirectoryEntry)4 Chunker (build.buildfarm.instance.stub.Chunker)4 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Action (build.bazel.remote.execution.v2.Action)3 HashCode (com.google.common.hash.HashCode)3 ActionResult (build.bazel.remote.execution.v2.ActionResult)2 DirectoryNode (build.bazel.remote.execution.v2.DirectoryNode)2 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)2