diff options
author | 2017-07-12 15:59:31 +0200 | |
---|---|---|
committer | 2017-07-12 16:03:16 +0200 | |
commit | 67bd6fc6354f2abbbc149fcd0120228b538842d3 (patch) | |
tree | 2479d1ee004c22860900ea83cb7b7efb1e512343 /src/main/java/com/google/devtools/build/lib | |
parent | 4e9fa1947c838882befd94f95233275e68be82f1 (diff) |
remote: Refactor GrpcRemoteExecutor to only take what it needs.
- Only pass to the GrpcRemoteExecutor constructor the objects it really
needs.
- Share a Retrier between GrpcRemoteCache and GrpcRemoteExecutor.
RELNOTES: None
PiperOrigin-RevId: 161660054
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
3 files changed, 25 insertions, 22 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteCache.java b/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteCache.java index 5b21e249b5..6a6e0bee9a 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteCache.java +++ b/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteCache.java @@ -77,11 +77,12 @@ public class GrpcRemoteCache implements RemoteActionCache { MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1)); @VisibleForTesting - public GrpcRemoteCache(Channel channel, ChannelOptions channelOptions, RemoteOptions options) { + public GrpcRemoteCache(Channel channel, ChannelOptions channelOptions, RemoteOptions options, + Retrier retrier) { this.options = options; this.channelOptions = channelOptions; this.channel = channel; - this.retrier = new Retrier(options); + this.retrier = retrier; uploader = new ByteStreamUploader(options.remoteInstanceName, channel, channelOptions.getCallCredentials(), options.remoteTimeout, retrier, retryScheduler); diff --git a/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutor.java b/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutor.java index 173f10ddb0..ad4a4ddbe7 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutor.java @@ -28,6 +28,7 @@ import com.google.watcher.v1.ChangeBatch; import com.google.watcher.v1.Request; import com.google.watcher.v1.WatcherGrpc; import com.google.watcher.v1.WatcherGrpc.WatcherBlockingStub; +import io.grpc.CallCredentials; import io.grpc.Channel; import io.grpc.Status.Code; import io.grpc.StatusRuntimeException; @@ -39,32 +40,31 @@ import javax.annotation.Nullable; /** A remote work executor that uses gRPC for communicating the work, inputs and outputs. */ @ThreadSafe -public class GrpcRemoteExecutor { - private final RemoteOptions options; - private final ChannelOptions channelOptions; +final class GrpcRemoteExecutor { + private final Channel channel; + private final CallCredentials callCredentials; + private final int callTimeoutSecs; private final Retrier retrier; - public static boolean isRemoteExecutionOptions(RemoteOptions options) { - return options.remoteExecutor != null; - } - - public GrpcRemoteExecutor(Channel channel, ChannelOptions channelOptions, RemoteOptions options) { - this.options = options; - this.channelOptions = channelOptions; + public GrpcRemoteExecutor(Channel channel, @Nullable CallCredentials callCredentials, + int callTimeoutSecs, Retrier retrier) { + Preconditions.checkArgument(callTimeoutSecs > 0, "callTimeoutSecs must be gt 0."); this.channel = channel; - this.retrier = new Retrier(options); + this.callCredentials = callCredentials; + this.callTimeoutSecs = callTimeoutSecs; + this.retrier = retrier; } private ExecutionBlockingStub execBlockingStub() { return ExecutionGrpc.newBlockingStub(channel) - .withCallCredentials(channelOptions.getCallCredentials()) - .withDeadlineAfter(options.remoteTimeout, TimeUnit.SECONDS); + .withCallCredentials(callCredentials) + .withDeadlineAfter(callTimeoutSecs, TimeUnit.SECONDS); } private WatcherBlockingStub watcherBlockingStub() { return WatcherGrpc.newBlockingStub(channel) - .withCallCredentials(channelOptions.getCallCredentials()); + .withCallCredentials(callCredentials); } private @Nullable ExecuteResponse getOperationResponse(Operation op) diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java index 01d99aefd2..9b6e42c35d 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java @@ -50,8 +50,8 @@ final class RemoteActionContextProvider extends ActionContextProvider { AuthAndTLSOptions authAndTlsOptions = env.getOptions().getOptions(AuthAndTLSOptions.class); ChannelOptions channelOptions = ChannelOptions.create(authAndTlsOptions); - // Initialize remote cache and execution handlers. We use separate handlers for every - // action to enable server-side parallelism (need a different gRPC channel per action). + Retrier retrier = new Retrier(remoteOptions); + RemoteActionCache remoteCache; if (SimpleBlobStoreFactory.isRemoteCacheOptions(remoteOptions)) { remoteCache = new SimpleBlobStoreActionCache(SimpleBlobStoreFactory.create(remoteOptions)); @@ -60,19 +60,21 @@ final class RemoteActionContextProvider extends ActionContextProvider { new GrpcRemoteCache( GrpcUtils.createChannel(remoteOptions.remoteCache, channelOptions), channelOptions, - remoteOptions); + remoteOptions, + retrier); } else { remoteCache = null; } // Otherwise remoteCache remains null and remote caching/execution are disabled. GrpcRemoteExecutor remoteExecutor; - if (remoteCache != null && GrpcRemoteExecutor.isRemoteExecutionOptions(remoteOptions)) { + if (remoteCache != null && remoteOptions.remoteExecutor != null) { remoteExecutor = new GrpcRemoteExecutor( GrpcUtils.createChannel(remoteOptions.remoteExecutor, channelOptions), - channelOptions, - remoteOptions); + channelOptions.getCallCredentials(), + remoteOptions.remoteTimeout, + retrier); } else { remoteExecutor = null; } |