Skip to content

Commit

Permalink
remote: quit early if no remote options specified
Browse files Browse the repository at this point in the history
If neither remote caching nor remote execution is enabled then
quit the remote initialization logic early. The current null
check on the RemoteOptions is not sufficient as it only works
if a none build command is used.

Also, don't create a remote logs directory and don't print
an invocation id if remoting is disabled.
  • Loading branch information
buchgr committed Jan 21, 2019
1 parent 29235b0 commit 7658da5
Showing 1 changed file with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,34 +112,14 @@ public void serverInit(OptionsParsingResult startupOptions, ServerBuilder builde

@Override
public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
env.getEventBus().register(this);

String invocationId = env.getCommandId().toString();
String buildRequestId = env.getBuildRequestId();
env.getReporter().handle(Event.info(String.format("Invocation ID: %s", invocationId)));

Path logDir =
env.getOutputBase().getRelative(env.getRuntime().getProductName() + "-remote-logs");
try {
// Clean out old logs files.
if (logDir.exists()) {
FileSystemUtils.deleteTree(logDir);
}
logDir.createDirectory();
} catch (IOException e) {
env.getReporter()
.handle(Event.error("Could not create base directory for remote logs: " + logDir));
throw new AbruptExitException(ExitCode.LOCAL_ENVIRONMENTAL_ERROR, e);
}
RemoteOptions remoteOptions = env.getOptions().getOptions(RemoteOptions.class);
AuthAndTLSOptions authAndTlsOptions = env.getOptions().getOptions(AuthAndTLSOptions.class);
DigestHashFunction hashFn = env.getRuntime().getFileSystem().getDigestFunction();
DigestUtil digestUtil = new DigestUtil(hashFn);

// Quit if no remote options specified.
if (remoteOptions == null) {
// Quit if no supported command is being used. See getCommandOptions for details.
return;
}
AuthAndTLSOptions authAndTlsOptions = env.getOptions().getOptions(AuthAndTLSOptions.class);
DigestHashFunction hashFn = env.getRuntime().getFileSystem().getDigestFunction();
DigestUtil digestUtil = new DigestUtil(hashFn);

boolean enableRestCache = SimpleBlobStoreFactory.isRestUrlOptions(remoteOptions);
boolean enableDiskCache = SimpleBlobStoreFactory.isDiskCache(remoteOptions);
Expand All @@ -150,12 +130,27 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
}
boolean enableBlobStoreCache = enableRestCache || enableDiskCache;
boolean enableGrpcCache = GrpcRemoteCache.isRemoteCacheOptions(remoteOptions);
if (enableBlobStoreCache && !Strings.isNullOrEmpty(remoteOptions.remoteExecutor)) {
boolean enableRemoteExecution = !Strings.isNullOrEmpty(remoteOptions.remoteExecutor);
if (enableBlobStoreCache && enableRemoteExecution) {
throw new AbruptExitException(
"Cannot combine gRPC based remote execution with local disk or HTTP-based caching",
ExitCode.COMMAND_LINE_ERROR);
}

if (!enableBlobStoreCache && !enableGrpcCache && !enableRemoteExecution) {
// Quit if no remote caching or execution was enabled.
return;
}

env.getEventBus().register(this);
String invocationId = env.getCommandId().toString();
String buildRequestId = env.getBuildRequestId();
env.getReporter().handle(Event.info(String.format("Invocation ID: %s", invocationId)));

Path logDir =
env.getOutputBase().getRelative(env.getRuntime().getProductName() + "-remote-logs");
cleanAndCreateRemoteLogsDir(logDir);

try {
List<ClientInterceptor> interceptors = new ArrayList<>();
if (!remoteOptions.experimentalRemoteGrpcLog.isEmpty()) {
Expand Down Expand Up @@ -267,7 +262,7 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
}

GrpcRemoteExecutor executor = null;
if (!Strings.isNullOrEmpty(remoteOptions.remoteExecutor)) {
if (enableRemoteExecution) {
RemoteRetrier retrier =
new RemoteRetrier(
remoteOptions,
Expand All @@ -292,6 +287,20 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
}
}

private static void cleanAndCreateRemoteLogsDir(Path logDir) throws AbruptExitException{
try {
// Clean out old logs files.
if (logDir.exists()) {
FileSystemUtils.deleteTree(logDir);
}
logDir.createDirectory();
} catch (IOException e) {
String message = String.format("Could not create base directory for remote logs: %s", logDir);
throw new AbruptExitException(message, ExitCode.LOCAL_ENVIRONMENTAL_ERROR, e);
}
}


private void checkClientServerCompatibility(
ServerCapabilities capabilities,
RemoteOptions remoteOptions,
Expand Down

0 comments on commit 7658da5

Please sign in to comment.