Search in sources :

Example 1 with DirectoryNode

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

the class RemoteClient method listDirectory.

// Recursively list directory files/subdirectories with digests. Returns the number of files
// listed.
private int listDirectory(Path path, Directory dir, Map<Digest, Directory> childrenMap, int limit) throws IOException {
    // Try to list the files in this directory before listing the directories.
    int numFilesListed = listFileNodes(path, dir, limit);
    if (numFilesListed >= limit) {
        return numFilesListed;
    }
    for (DirectoryNode child : dir.getDirectoriesList()) {
        Path childPath = path.resolve(child.getName());
        printDirectoryNodeDetails(child, childPath);
        Digest childDigest = child.getDigest();
        Directory childDir = childrenMap.get(childDigest);
        numFilesListed += listDirectory(childPath, childDir, childrenMap, limit - numFilesListed);
        if (numFilesListed >= limit) {
            return numFilesListed;
        }
    }
    return numFilesListed;
}
Also used : Path(java.nio.file.Path) Digest(build.bazel.remote.execution.v2.Digest) DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) Directory(build.bazel.remote.execution.v2.Directory) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory)

Example 2 with DirectoryNode

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

the class AbstractRemoteActionCache method addChildDirectories.

/**
 * Recursively add all child directories of the given directory to the given list of directories.
 */
private void addChildDirectories(Directory dir, List<Directory> directories) throws IOException {
    for (DirectoryNode childNode : dir.getDirectoriesList()) {
        Directory childDir = Directory.parseFrom(downloadBlob(childNode.getDigest()));
        directories.add(childDir);
        addChildDirectories(childDir, directories);
    }
}
Also used : DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) Directory(build.bazel.remote.execution.v2.Directory) OutputDirectory(build.bazel.remote.execution.v2.OutputDirectory)

Example 3 with DirectoryNode

use of build.bazel.remote.execution.v2.DirectoryNode 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 4 with DirectoryNode

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

the class Extract method directoryGetter.

static Runnable directoryGetter(Path root, String instanceName, Digest digest, Set<Digest> visitedDirectories, Set<Digest> visitedDigests, ByteStreamStub bsStub, Executor executor, AtomicLong outstandingOperations, ListeningScheduledExecutorService retryService) {
    return new Runnable() {

        @Override
        public void run() {
            try {
                runInterruptibly();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                outstandingOperations.getAndDecrement();
            }
        }

        void runInterruptibly() throws InterruptedException {
            try {
                ByteString content = getBlobIntoFile("directory", instanceName, digest, bsStub, root);
                handleDirectory(Directory.parseFrom(content));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void handleDirectory(Directory directory) {
            for (FileNode fileNode : directory.getFilesList()) {
                Digest fileDigest = fileNode.getDigest();
                if (!visitedDigests.contains(fileDigest)) {
                    visitedDigests.add(fileDigest);
                    outstandingOperations.getAndIncrement();
                    executor.execute(blobGetter(root, instanceName, fileDigest, bsStub, outstandingOperations, retryService));
                }
            }
            for (DirectoryNode directoryNode : directory.getDirectoriesList()) {
                Digest directoryDigest = directoryNode.getDigest();
                // we may have seen this digest, but now we will have seen it as a directory
                if (!visitedDirectories.contains(directoryDigest)) {
                    // probably won't collide with other writers, with single thread
                    visitedDigests.add(directoryDigest);
                    visitedDirectories.add(directoryDigest);
                    outstandingOperations.getAndIncrement();
                    executor.execute(directoryGetter(root, instanceName, directoryDigest, visitedDirectories, visitedDigests, bsStub, executor, outstandingOperations, retryService));
                }
            }
        }
    };
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) IOException(java.io.IOException) FileNode(build.bazel.remote.execution.v2.FileNode) Directory(build.bazel.remote.execution.v2.Directory)

Example 5 with DirectoryNode

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

the class OperationQueueWorkerContext method fetchInputs.

private void fetchInputs(Path execDir, Digest inputRoot, Map<Digest, Directory> directoriesIndex, OutputDirectory outputDirectory, ImmutableList.Builder<String> inputFiles, ImmutableList.Builder<Digest> inputDirectories) throws IOException, InterruptedException {
    Directory directory;
    if (inputRoot.getSizeBytes() == 0) {
        directory = Directory.getDefaultInstance();
    } else {
        directory = directoriesIndex.get(inputRoot);
        if (directory == null) {
            throw new IOException("Directory " + DigestUtil.toString(inputRoot) + " is not in input index");
        }
    }
    getInterruptiblyOrIOException(allAsList(fileCache.putFiles(directory.getFilesList(), directory.getSymlinksList(), execDir, inputFiles, newDirectExecutorService())));
    for (DirectoryNode directoryNode : directory.getDirectoriesList()) {
        Digest digest = directoryNode.getDigest();
        String name = directoryNode.getName();
        OutputDirectory childOutputDirectory = outputDirectory != null ? outputDirectory.getChild(name) : null;
        Path dirPath = execDir.resolve(name);
        if (childOutputDirectory != null || !config.getLinkInputDirectories()) {
            Files.createDirectories(dirPath);
            fetchInputs(dirPath, digest, directoriesIndex, childOutputDirectory, inputFiles, inputDirectories);
        } else {
            inputDirectories.add(digest);
            linkDirectory(dirPath, digest, directoriesIndex);
        }
    }
}
Also used : Path(java.nio.file.Path) Digest(build.bazel.remote.execution.v2.Digest) OutputDirectory(build.buildfarm.worker.OutputDirectory) DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) Utils.getInterruptiblyOrIOException(build.buildfarm.common.io.Utils.getInterruptiblyOrIOException) IOException(java.io.IOException) ByteString(com.google.protobuf.ByteString) OutputDirectory(build.buildfarm.worker.OutputDirectory) Directory(build.bazel.remote.execution.v2.Directory)

Aggregations

DirectoryNode (build.bazel.remote.execution.v2.DirectoryNode)17 Directory (build.bazel.remote.execution.v2.Directory)15 Digest (build.bazel.remote.execution.v2.Digest)9 FileNode (build.bazel.remote.execution.v2.FileNode)9 ByteString (com.google.protobuf.ByteString)8 OutputDirectory (build.bazel.remote.execution.v2.OutputDirectory)6 IOException (java.io.IOException)5 Path (java.nio.file.Path)4 OutputDirectory (build.buildfarm.worker.OutputDirectory)3 SymlinkNode (build.bazel.remote.execution.v2.SymlinkNode)2 Utils.getInterruptiblyOrIOException (build.buildfarm.common.io.Utils.getInterruptiblyOrIOException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Action (build.bazel.remote.execution.v2.Action)1 Command (build.bazel.remote.execution.v2.Command)1 ContentAddressableStorage (build.buildfarm.cas.ContentAddressableStorage)1 CASFileCache (build.buildfarm.cas.cfc.CASFileCache)1 DigestUtil (build.buildfarm.common.DigestUtil)1 DirectoryEntry (build.buildfarm.common.TreeIterator.DirectoryEntry)1 Directories (build.buildfarm.common.io.Directories)1 Dirent (build.buildfarm.common.io.Dirent)1