diff options
6 files changed, 12 insertions, 116 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java index 1155611945..4325524c9c 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java @@ -119,7 +119,7 @@ public class BlazeCommandDispatcher { * code, the desire to shut down the server, or that a given binary should be executed by the * client. */ - BlazeCommandResult exec( + public BlazeCommandResult exec( InvocationPolicy invocationPolicy, List<String> args, OutErr outErr, @@ -623,6 +623,7 @@ public class BlazeCommandDispatcher { * Returns the runtime instance shared by the commands that this dispatcher * dispatches to. */ + @VisibleForTesting public BlazeRuntime getRuntime() { return runtime; } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java index 83c339d5b7..a070deb32a 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java @@ -851,7 +851,6 @@ public final class BlazeRuntime { Runnable prepareForAbruptShutdown = () -> rpcServer[0].prepareForAbruptShutdown(); BlazeRuntime runtime = newRuntime(modules, Arrays.asList(args), prepareForAbruptShutdown); BlazeCommandDispatcher dispatcher = new BlazeCommandDispatcher(runtime); - CommandExecutor commandExecutor = new CommandExecutor(dispatcher); BlazeServerStartupOptions startupOptions = runtime.getStartupOptionsProvider().getOptions(BlazeServerStartupOptions.class); try { @@ -860,7 +859,7 @@ public final class BlazeRuntime { Class<?> factoryClass = Class.forName( "com.google.devtools.build.lib.server.GrpcServerImpl$Factory"); RPCServer.Factory factory = (RPCServer.Factory) factoryClass.getConstructor().newInstance(); - rpcServer[0] = factory.create(commandExecutor, runtime.getClock(), + rpcServer[0] = factory.create(dispatcher, runtime.getClock(), startupOptions.commandPort, runtime.getWorkspace().getWorkspace(), runtime.getServerDirectory(), diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommandExecutor.java b/src/main/java/com/google/devtools/build/lib/runtime/CommandExecutor.java deleted file mode 100644 index b36cc65d39..0000000000 --- a/src/main/java/com/google/devtools/build/lib/runtime/CommandExecutor.java +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2016 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.google.devtools.build.lib.runtime; - -import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.LockingMode; -import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy; -import com.google.devtools.build.lib.server.ServerCommand; -import com.google.devtools.build.lib.util.Pair; -import com.google.devtools.build.lib.util.io.OutErr; -import java.util.List; -import java.util.Optional; - -/** - * Executes a Blaze command. - * - * <p>This is the common execution path between the gRPC server and the legacy AF_UNIX server. - */ -public class CommandExecutor implements ServerCommand { - private final BlazeCommandDispatcher dispatcher; - - CommandExecutor(BlazeCommandDispatcher dispatcher) { - this.dispatcher = dispatcher; - } - - @Override - public BlazeCommandResult exec( - InvocationPolicy invocationPolicy, - List<String> args, - OutErr outErr, - LockingMode lockingMode, - String clientDescription, - long firstContactTime, - Optional<List<Pair<String, String>>> startupOptionsTaggedWithBazelRc) - throws InterruptedException { - - return dispatcher.exec( - invocationPolicy, - args, - outErr, - lockingMode, - clientDescription, - firstContactTime, - startupOptionsTaggedWithBazelRc); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java b/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java index 58ad98edae..1213d6e47d 100644 --- a/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java +++ b/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java @@ -25,10 +25,10 @@ import com.google.common.util.concurrent.Uninterruptibles; import com.google.devtools.build.lib.clock.BlazeClock; import com.google.devtools.build.lib.clock.Clock; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher; import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.LockingMode; import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.BlazeRuntime; -import com.google.devtools.build.lib.runtime.CommandExecutor; import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy; import com.google.devtools.build.lib.server.CommandProtos.CancelRequest; import com.google.devtools.build.lib.server.CommandProtos.CancelResponse; @@ -152,10 +152,10 @@ public class GrpcServerImpl implements RPCServer { */ public static class Factory implements RPCServer.Factory { @Override - public RPCServer create(CommandExecutor commandExecutor, Clock clock, int port, + public RPCServer create(BlazeCommandDispatcher dispatcher, Clock clock, int port, Path workspace, Path serverDirectory, int maxIdleSeconds) throws IOException { return new GrpcServerImpl( - commandExecutor, clock, port, workspace, serverDirectory, maxIdleSeconds); + dispatcher, clock, port, workspace, serverDirectory, maxIdleSeconds); } } @@ -497,7 +497,7 @@ public class GrpcServerImpl implements RPCServer { @GuardedBy("runningCommands") private final Map<String, RunningCommand> runningCommands = new HashMap<>(); - private final CommandExecutor commandExecutor; + private final BlazeCommandDispatcher dispatcher; private final ExecutorService streamExecutorPool; private final ExecutorService commandExecutorPool; private final Clock clock; @@ -517,7 +517,7 @@ public class GrpcServerImpl implements RPCServer { private IdleServerTasks idleServerTasks; boolean serving; - public GrpcServerImpl(CommandExecutor commandExecutor, Clock clock, int port, + public GrpcServerImpl(BlazeCommandDispatcher dispatcher, Clock clock, int port, Path workspace, Path serverDirectory, int maxIdleSeconds) throws IOException { Runtime.getRuntime().addShutdownHook(new Thread() { @Override @@ -533,7 +533,7 @@ public class GrpcServerImpl implements RPCServer { pidInFile = new String(FileSystemUtils.readContentAsLatin1(pidFile)); deleteAtExit(pidFile); - this.commandExecutor = commandExecutor; + this.dispatcher = dispatcher; this.clock = clock; this.serverDirectory = serverDirectory; this.workspace = workspace; @@ -852,7 +852,7 @@ public class GrpcServerImpl implements RPCServer { InvocationPolicy policy = InvocationPolicyParser.parsePolicy(request.getInvocationPolicy()); logger.info(BlazeRuntime.getRequestLogString(args)); result = - commandExecutor.exec( + dispatcher.exec( policy, args, rpcOutErr, diff --git a/src/main/java/com/google/devtools/build/lib/server/RPCServer.java b/src/main/java/com/google/devtools/build/lib/server/RPCServer.java index 7ebb77e2b0..014b17b5ae 100644 --- a/src/main/java/com/google/devtools/build/lib/server/RPCServer.java +++ b/src/main/java/com/google/devtools/build/lib/server/RPCServer.java @@ -14,7 +14,7 @@ package com.google.devtools.build.lib.server; import com.google.devtools.build.lib.clock.Clock; -import com.google.devtools.build.lib.runtime.CommandExecutor; +import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher; import com.google.devtools.build.lib.vfs.Path; import java.io.IOException; @@ -28,7 +28,7 @@ public interface RPCServer { * Present so that we don't need to invoke a constructor with multiple arguments by reflection. */ interface Factory { - RPCServer create(CommandExecutor commandExecutor, Clock clock, int port, + RPCServer create(BlazeCommandDispatcher dispatcher, Clock clock, int port, Path workspace, Path serverDirectory, int maxIdleSeconds) throws IOException; } diff --git a/src/main/java/com/google/devtools/build/lib/server/ServerCommand.java b/src/main/java/com/google/devtools/build/lib/server/ServerCommand.java deleted file mode 100644 index c47e12853d..0000000000 --- a/src/main/java/com/google/devtools/build/lib/server/ServerCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.google.devtools.build.lib.server; - -import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher; -import com.google.devtools.build.lib.runtime.BlazeCommandResult; -import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy; -import com.google.devtools.build.lib.util.Pair; -import com.google.devtools.build.lib.util.io.OutErr; -import java.util.List; -import java.util.Optional; - -/** - * The {@link RPCServer} calls an arbitrary command implementing this - * interface. - */ -public interface ServerCommand { - - /** - * Executes the request, writing any output or error messages into err. Returns 0 on success; any - * other value or exception indicates an error. - * - * @param startupOptionsTaggedWithBazelRc List of startup options in Pair(bazelRc, option) form. - * The empty string bazelRc is interpreted as the command line, and option should be in - * --[no]flag or --flag=value form. If we don't have access to this information (--batch), - * leave this parameter as Optional.empty(). - */ - BlazeCommandResult exec( - InvocationPolicy policy, - List<String> args, - OutErr outErr, - BlazeCommandDispatcher.LockingMode lockingMode, - String clientDescription, - long firstContactTime, - Optional<List<Pair<String, String>>> startupOptionsTaggedWithBazelRc) - throws InterruptedException; -} |