14
14
package com .google .devtools .build .lib .remote ;
15
15
16
16
import static com .google .common .base .Preconditions .checkArgument ;
17
+ import static com .google .common .base .Preconditions .checkNotNull ;
18
+ import static com .google .common .base .Preconditions .checkState ;
17
19
import static com .google .devtools .build .lib .remote .util .Utils .getFromFuture ;
18
20
import static com .google .devtools .build .lib .remote .util .Utils .getInMemoryOutputPath ;
19
21
import static com .google .devtools .build .lib .remote .util .Utils .hasFilesToDownload ;
29
31
import build .bazel .remote .execution .v2 .LogFile ;
30
32
import build .bazel .remote .execution .v2 .Platform ;
31
33
import build .bazel .remote .execution .v2 .RequestMetadata ;
32
- import com .google .common .base .Preconditions ;
33
34
import com .google .common .base .Strings ;
34
35
import com .google .common .collect .ImmutableList ;
35
36
import com .google .common .collect .ImmutableMap ;
@@ -81,7 +82,7 @@ public class RemoteExecutionService {
81
82
private final String commandId ;
82
83
private final DigestUtil digestUtil ;
83
84
private final RemoteOptions remoteOptions ;
84
- private final RemoteCache remoteCache ;
85
+ @ Nullable private final RemoteCache remoteCache ;
85
86
@ Nullable private final RemoteExecutionClient remoteExecutor ;
86
87
private final ImmutableSet <ActionInput > filesToDownload ;
87
88
@@ -92,7 +93,7 @@ public RemoteExecutionService(
92
93
String commandId ,
93
94
DigestUtil digestUtil ,
94
95
RemoteOptions remoteOptions ,
95
- RemoteCache remoteCache ,
96
+ @ Nullable RemoteCache remoteCache ,
96
97
@ Nullable RemoteExecutionClient remoteExecutor ,
97
98
ImmutableSet <ActionInput > filesToDownload ) {
98
99
this .execRoot = execRoot ;
@@ -213,6 +214,21 @@ public NetworkTime getNetworkTime() {
213
214
}
214
215
}
215
216
217
+ /** Returns {@code true} if the result of spawn may be cached remotely. */
218
+ public boolean mayBeCachedRemotely (Spawn spawn ) {
219
+ return remoteCache != null && Spawns .mayBeCached (spawn ) && Spawns .mayBeCachedRemotely (spawn );
220
+ }
221
+
222
+ /** Returns {@code true} if the result of spawn may be cached. */
223
+ public boolean mayBeCached (Spawn spawn ) {
224
+ return remoteCache != null && Spawns .mayBeCached (spawn );
225
+ }
226
+
227
+ /** Returns {@code true} if the spawn may be executed remotely. */
228
+ public boolean mayBeExecutedRemotely (Spawn spawn ) {
229
+ return remoteCache != null && remoteExecutor != null && Spawns .mayBeExecutedRemotely (spawn );
230
+ }
231
+
216
232
/** Creates a new {@link RemoteAction} instance from spawn. */
217
233
public RemoteAction buildRemoteAction (Spawn spawn , SpawnExecutionContext context )
218
234
throws IOException , UserExecException {
@@ -334,6 +350,7 @@ public ExecuteResponse getResponse() {
334
350
@ Nullable
335
351
public RemoteActionResult lookupCache (RemoteAction action )
336
352
throws IOException , InterruptedException {
353
+ checkNotNull (remoteCache , "remoteCache can't be null" );
337
354
ActionResult actionResult =
338
355
remoteCache .downloadActionResult (
339
356
action .remoteActionExecutionContext , action .actionKey , /* inlineOutErr= */ false );
@@ -349,6 +366,7 @@ public RemoteActionResult lookupCache(RemoteAction action)
349
366
@ Nullable
350
367
public InMemoryOutput downloadOutputs (RemoteAction action , RemoteActionResult result )
351
368
throws InterruptedException , IOException , ExecException {
369
+ checkNotNull (remoteCache , "remoteCache can't be null" );
352
370
RemoteOutputsMode remoteOutputsMode = remoteOptions .remoteOutputsMode ;
353
371
boolean downloadOutputs =
354
372
shouldDownloadAllSpawnOutputs (
@@ -383,6 +401,7 @@ public InMemoryOutput downloadOutputs(RemoteAction action, RemoteActionResult re
383
401
/** Upload outputs of a remote action which was executed locally to remote cache. */
384
402
public void uploadOutputs (RemoteAction action )
385
403
throws InterruptedException , IOException , ExecException {
404
+ checkNotNull (remoteCache , "remoteCache can't be null" );
386
405
Collection <Path > outputFiles =
387
406
action .spawn .getOutputFiles ().stream ()
388
407
.map ((inp ) -> execRoot .getRelative (inp .getExecPath ()))
@@ -404,7 +423,8 @@ public void uploadOutputs(RemoteAction action)
404
423
*/
405
424
public void uploadInputsIfNotPresent (RemoteAction action )
406
425
throws IOException , InterruptedException {
407
- Preconditions .checkState (remoteCache instanceof RemoteExecutionCache );
426
+ checkNotNull (remoteCache , "remoteCache can't be null" );
427
+ checkState (remoteCache instanceof RemoteExecutionCache );
408
428
RemoteExecutionCache remoteExecutionCache = (RemoteExecutionCache ) remoteCache ;
409
429
// Upload the command and all the inputs into the remote cache.
410
430
Map <Digest , Message > additionalInputs = Maps .newHashMapWithExpectedSize (2 );
@@ -423,7 +443,7 @@ public void uploadInputsIfNotPresent(RemoteAction action)
423
443
public RemoteActionResult execute (
424
444
RemoteAction action , boolean acceptCachedResult , OperationObserver observer )
425
445
throws IOException , InterruptedException {
426
- Preconditions . checkNotNull (remoteExecutor , "remoteExecutor" );
446
+ checkNotNull (remoteExecutor , "remoteExecutor can't be null " );
427
447
428
448
ExecuteRequest .Builder requestBuilder =
429
449
ExecuteRequest .newBuilder ()
@@ -457,6 +477,7 @@ public static class ServerLogs {
457
477
/** Downloads server logs from a remotely executed action if any. */
458
478
public ServerLogs maybeDownloadServerLogs (RemoteAction action , ExecuteResponse resp , Path logDir )
459
479
throws InterruptedException , IOException {
480
+ checkNotNull (remoteCache , "remoteCache can't be null" );
460
481
ServerLogs serverLogs = new ServerLogs ();
461
482
serverLogs .directory = logDir .getRelative (action .getActionId ());
462
483
0 commit comments