Alpha Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 1 | // 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 | |
| 15 | package com.google.devtools.build.lib.remote; |
| 16 | |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 17 | import com.google.common.collect.ImmutableList; |
Alpha Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 18 | import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible; |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 19 | import com.google.devtools.build.lib.remote.ContentDigests.ActionKey; |
| 20 | import com.google.devtools.build.lib.remote.RemoteProtocol.ActionResult; |
| 21 | import com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest; |
| 22 | import com.google.devtools.build.lib.remote.TreeNodeRepository.TreeNode; |
Alpha Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 23 | import com.google.devtools.build.lib.vfs.Path; |
Alpha Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 24 | import java.io.IOException; |
| 25 | import java.util.Collection; |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 26 | import javax.annotation.Nullable; |
Alpha Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 27 | |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 28 | /** A cache for storing artifacts (input and output) as well as the output of running an action. */ |
Alpha Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 29 | @ThreadCompatible |
| 30 | interface RemoteActionCache { |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 31 | // 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 Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 36 | /** |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 37 | * 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 Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 39 | */ |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 40 | void uploadTree(TreeNodeRepository repository, Path execRoot, TreeNode root) |
Janak Ramakrishnan | 452def0 | 2016-08-18 08:47:26 +0000 | [diff] [blame] | 41 | throws IOException, InterruptedException; |
Alpha Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 42 | |
| 43 | /** |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 44 | * Download the entire tree data rooted by the given digest and write it into the given location. |
Alpha Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 45 | */ |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 46 | void downloadTree(ContentDigest rootDigest, Path rootLocation) |
Alpha Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 47 | throws IOException, CacheNotFoundException; |
| 48 | |
| 49 | /** |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 50 | * 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 Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 52 | */ |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 53 | void downloadAllResults(ActionResult result, Path execRoot) |
Alpha Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 54 | throws IOException, CacheNotFoundException; |
| 55 | |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 56 | /** |
| 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 Ramakrishnan | 452def0 | 2016-08-18 08:47:26 +0000 | [diff] [blame] | 61 | throws IOException, InterruptedException; |
Alpha Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 62 | |
Ola Rozenfeld | 72d117d | 2016-09-19 15:02:32 +0000 | [diff] [blame] | 63 | /** |
| 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 Lam | 79adf59 | 2016-02-10 15:38:59 +0000 | [diff] [blame] | 100 | } |