Search in sources :

Example 1 with DirectoryEntry

use of build.buildfarm.common.TreeIterator.DirectoryEntry 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 2 with DirectoryEntry

use of build.buildfarm.common.TreeIterator.DirectoryEntry 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)

Example 3 with DirectoryEntry

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

the class AbstractServerInstance method getTreeFuture.

protected ListenableFuture<Tree> getTreeFuture(String reason, Digest inputRoot, ExecutorService service, RequestMetadata requestMetadata) {
    return listeningDecorator(service).submit(() -> {
        Tree.Builder tree = Tree.newBuilder().setRootDigest(inputRoot);
        TokenizableIterator<DirectoryEntry> iterator = createTreeIterator(reason, inputRoot, /* pageToken=*/
        "");
        while (iterator.hasNext()) {
            DirectoryEntry entry = iterator.next();
            Directory directory = entry.getDirectory();
            if (directory != null) {
                tree.putDirectories(entry.getDigest().getHash(), directory);
            }
        }
        return tree.build();
    });
}
Also used : Tree(build.buildfarm.v1test.Tree) 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)3 DirectoryEntry (build.buildfarm.common.TreeIterator.DirectoryEntry)3 OutputDirectory (build.bazel.remote.execution.v2.OutputDirectory)2 Tree (build.buildfarm.v1test.Tree)2 Digest (build.bazel.remote.execution.v2.Digest)1 DirectoryNode (build.bazel.remote.execution.v2.DirectoryNode)1 Context (io.grpc.Context)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1