Search in sources :

Example 1 with Output

use of com.google.devtools.build.lib.remote.RemoteProtocol.Output in project bazel by bazelbuild.

the class ConcurrentMapActionCache method downloadAllResults.

@Override
public void downloadAllResults(ActionResult result, Path execRoot) throws IOException, CacheNotFoundException {
    for (Output output : result.getOutputList()) {
        if (output.getContentCase() == ContentCase.FILE_METADATA) {
            FileMetadata m = output.getFileMetadata();
            downloadFileContents(m.getDigest(), execRoot.getRelative(output.getPath()), m.getExecutable());
        } else {
            downloadTree(output.getDigest(), execRoot.getRelative(output.getPath()));
        }
    }
}
Also used : Output(com.google.devtools.build.lib.remote.RemoteProtocol.Output) FileMetadata(com.google.devtools.build.lib.remote.RemoteProtocol.FileMetadata)

Example 2 with Output

use of com.google.devtools.build.lib.remote.RemoteProtocol.Output in project bazel by bazelbuild.

the class GrpcActionCache method downloadAllResults.

/**
   * Download all results of a remotely executed action locally. TODO(olaola): will need to amend to
   * include the {@link com.google.devtools.build.lib.remote.TreeNodeRepository} for updating.
   */
@Override
public void downloadAllResults(ActionResult result, Path execRoot) throws IOException, CacheNotFoundException {
    // Send all the file requests in a single synchronous batch.
    // TODO(olaola): profile to maybe replace with separate concurrent requests.
    CasDownloadBlobRequest.Builder request = CasDownloadBlobRequest.newBuilder();
    Map<ContentDigest, Pair<Path, FileMetadata>> metadataMap = new HashMap<>();
    for (Output output : result.getOutputList()) {
        Path path = execRoot.getRelative(output.getPath());
        if (output.getContentCase() == ContentCase.FILE_METADATA) {
            FileMetadata fileMetadata = output.getFileMetadata();
            ContentDigest digest = fileMetadata.getDigest();
            if (digest.getSizeBytes() > 0) {
                request.addDigest(digest);
                metadataMap.put(digest, Pair.of(path, fileMetadata));
            } else {
                // Handle empty file locally.
                FileSystemUtils.createDirectoryAndParents(path.getParentDirectory());
                FileSystemUtils.writeContent(path, new byte[0]);
            }
        } else {
            downloadTree(output.getDigest(), path);
        }
    }
    Iterator<CasDownloadReply> replies = getBlockingStub().downloadBlob(request.build());
    Set<ContentDigest> results = new HashSet<>();
    while (replies.hasNext()) {
        results.add(createFileFromStream(metadataMap, replies));
    }
    for (ContentDigest digest : metadataMap.keySet()) {
        if (!results.contains(digest)) {
            throw new CacheNotFoundException(digest);
        }
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) HashMap(java.util.HashMap) FileMetadata(com.google.devtools.build.lib.remote.RemoteProtocol.FileMetadata) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest) CasDownloadReply(com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadReply) Output(com.google.devtools.build.lib.remote.RemoteProtocol.Output) CasDownloadBlobRequest(com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadBlobRequest) Pair(com.google.devtools.build.lib.util.Pair) HashSet(java.util.HashSet)

Aggregations

FileMetadata (com.google.devtools.build.lib.remote.RemoteProtocol.FileMetadata)2 Output (com.google.devtools.build.lib.remote.RemoteProtocol.Output)2 CasDownloadBlobRequest (com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadBlobRequest)1 CasDownloadReply (com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadReply)1 ContentDigest (com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest)1 Pair (com.google.devtools.build.lib.util.Pair)1 Path (com.google.devtools.build.lib.vfs.Path)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1