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();
}
}
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)");
}
}
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);
}
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);
}
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();
}
Aggregations