blob: 62790e8a76fffa1944185501129219419302bb27 [file] [log] [blame]
Alpha Lam79adf592016-02-10 15:38:59 +00001// Copyright 2016 The Bazel Authors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.devtools.build.lib.remote;
16
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000017import com.google.common.collect.ImmutableList;
Alpha Lam79adf592016-02-10 15:38:59 +000018import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible;
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000019import com.google.devtools.build.lib.remote.ContentDigests.ActionKey;
20import com.google.devtools.build.lib.remote.RemoteProtocol.ActionResult;
21import com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest;
22import com.google.devtools.build.lib.remote.TreeNodeRepository.TreeNode;
Alpha Lam79adf592016-02-10 15:38:59 +000023import com.google.devtools.build.lib.vfs.Path;
Alpha Lam79adf592016-02-10 15:38:59 +000024import java.io.IOException;
25import java.util.Collection;
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000026import javax.annotation.Nullable;
Alpha Lam79adf592016-02-10 15:38:59 +000027
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000028/** A cache for storing artifacts (input and output) as well as the output of running an action. */
Alpha Lam79adf592016-02-10 15:38:59 +000029@ThreadCompatible
30interface RemoteActionCache {
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000031 // CAS API
32
33 // TODO(olaola): create a unified set of exceptions raised by the cache to encapsulate the
34 // underlying CasStatus messages and gRPC errors errors.
35
Alpha Lam79adf592016-02-10 15:38:59 +000036 /**
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000037 * Upload enough of the tree metadata and data into remote cache so that the entire tree can be
38 * reassembled remotely using the root digest.
Alpha Lam79adf592016-02-10 15:38:59 +000039 */
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000040 void uploadTree(TreeNodeRepository repository, Path execRoot, TreeNode root)
Janak Ramakrishnan452def02016-08-18 08:47:26 +000041 throws IOException, InterruptedException;
Alpha Lam79adf592016-02-10 15:38:59 +000042
43 /**
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000044 * Download the entire tree data rooted by the given digest and write it into the given location.
Alpha Lam79adf592016-02-10 15:38:59 +000045 */
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000046 void downloadTree(ContentDigest rootDigest, Path rootLocation)
Alpha Lam79adf592016-02-10 15:38:59 +000047 throws IOException, CacheNotFoundException;
48
49 /**
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000050 * Download all results of a remotely executed action locally. TODO(olaola): will need to amend to
51 * include the {@link com.google.devtools.build.lib.remote.TreeNodeRepository} for updating.
Alpha Lam79adf592016-02-10 15:38:59 +000052 */
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000053 void downloadAllResults(ActionResult result, Path execRoot)
Alpha Lam79adf592016-02-10 15:38:59 +000054 throws IOException, CacheNotFoundException;
55
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000056 /**
57 * Upload all results of a locally executed action to the cache. Add the files to the ActionResult
58 * builder.
59 */
60 void uploadAllResults(Path execRoot, Collection<Path> files, ActionResult.Builder result)
Janak Ramakrishnan452def02016-08-18 08:47:26 +000061 throws IOException, InterruptedException;
Alpha Lam79adf592016-02-10 15:38:59 +000062
Ola Rozenfeld72d117d2016-09-19 15:02:32 +000063 /**
64 * Put the file contents cache if it is not already in it. No-op if the file is already stored in
65 * cache. The given path must be a full absolute path. Note: this is horribly inefficient, need to
66 * patch through an overload that uses an ActionInputFile cache to compute the digests!
67 *
68 * @return The key for fetching the file contents blob from cache.
69 */
70 ContentDigest uploadFileContents(Path file) throws IOException, InterruptedException;
71
72 /**
73 * Download a blob keyed by the given digest and write it to the specified path. Set the
74 * executable parameter to the specified value.
75 */
76 void downloadFileContents(ContentDigest digest, Path dest, boolean executable)
77 throws IOException, CacheNotFoundException;
78
79 /** Upload the given blobs to the cache, and return their digests. */
80 ImmutableList<ContentDigest> uploadBlobs(Iterable<byte[]> blobs) throws InterruptedException;
81
82 /** Upload the given blob to the cache, and return its digests. */
83 ContentDigest uploadBlob(byte[] blob) throws InterruptedException;
84
85 /** Download and return a blob with a given digest from the cache. */
86 byte[] downloadBlob(ContentDigest digest) throws CacheNotFoundException;
87
88 /** Download and return blobs with given digests from the cache. */
89 ImmutableList<byte[]> downloadBlobs(Iterable<ContentDigest> digests)
90 throws CacheNotFoundException;
91
92 // Execution Cache API
93
94 /** Returns a cached result for a given Action digest, or null if not found in cache. */
95 @Nullable
96 ActionResult getCachedActionResult(ActionKey actionKey);
97
98 /** Sets the given result as result of the given Action. */
99 void setCachedActionResult(ActionKey actionKey, ActionResult result) throws InterruptedException;
Alpha Lam79adf592016-02-10 15:38:59 +0000100}