diff options
-rwxr-xr-x | scripts/bootstrap/compile.sh | 17 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java | 200 | ||||
-rw-r--r-- | src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java | 12 | ||||
-rw-r--r-- | third_party/grpc/BUILD | 28 | ||||
-rw-r--r-- | third_party/grpc/README.bazel.md | 4 |
5 files changed, 136 insertions, 125 deletions
diff --git a/scripts/bootstrap/compile.sh b/scripts/bootstrap/compile.sh index 7c28986831..f94aa410b3 100755 --- a/scripts/bootstrap/compile.sh +++ b/scripts/bootstrap/compile.sh @@ -17,7 +17,10 @@ # Script for building bazel from scratch without bazel PROTO_FILES=$(ls src/main/protobuf/*.proto) -LIBRARY_JARS=$(find third_party -name '*.jar' | grep -Fv /javac.jar | grep -Fv /javac7.jar | grep -Fv JavaBuilder | tr "\n" " ") +LIBRARY_JARS=$(find third_party -name '*.jar' | grep -Fv /javac.jar | grep -Fv /javac7.jar | grep -Fv JavaBuilder | grep -ve third_party/grpc/grpc.*jar | tr "\n" " ") +GRPC_JAVA_VERSION=0.15.0 +GRPC_LIBRARY_JARS=$(find third_party/grpc -name '*.jar' | grep -e .*${GRPC_JAVA_VERSION}.*jar | tr "\n" " ") +LIBRARY_JARS="${LIBRARY_JARS} ${GRPC_LIBRARY_JARS}" DIRS=$(echo src/{java_tools/singlejar/java/com/google/devtools/build/zip,main/java,tools/xcode-common/java/com/google/devtools/build/xcode/{common,util}} third_party/java/dd_plist/java ${OUTPUT_DIR}/src) EXCLUDE_FILES=src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java @@ -41,13 +44,13 @@ linux) JAVA_HOME="${JAVA_HOME:-$(readlink -f $(which javac) | sed 's_/bin/javac__')}" if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-x86_64.exe} - GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.14.1-linux-x86_64.exe} + GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.15.0-linux-x86_64.exe} else if [ "${MACHINE_IS_ARM}" = 'yes' ]; then PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-arm32.exe} else PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-x86_32.exe} - GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.14.1-linux-x86_32.exe} + GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.15.0-linux-x86_32.exe} fi fi ;; @@ -59,7 +62,7 @@ freebsd) # We choose the 32-bit version for maximum compatiblity since 64-bit # linux binaries are only supported in FreeBSD-11. PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-x86_32.exe} - GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.14.1-linux-x86_32.exe} + GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.15.0-linux-x86_32.exe} ;; darwin) @@ -69,7 +72,7 @@ darwin) fi if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then PROTOC=${PROTOC:-third_party/protobuf/protoc-osx-x86_64.exe} - GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.14.1-osx-x86_64.exe} + GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.15.0-osx-x86_64.exe} else PROTOC=${PROTOC:-third_party/protobuf/protoc-osx-x86_32.exe} fi @@ -84,10 +87,10 @@ msys*|mingw*) # We do not use the JNI library on Windows. if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then PROTOC=${PROTOC:-third_party/protobuf/protoc-windows-x86_64.exe} - GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.14.1-windows-x86_64.exe} + GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.15.0-windows-x86_64.exe} else PROTOC=${PROTOC:-third_party/protobuf/protoc-windows-x86_32.exe} - GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.14.1-windows-x86_32.exe} + GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.15.0-windows-x86_32.exe} fi esac 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 f6a37fa334..7385bdaaaa 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 @@ -61,7 +61,7 @@ import io.grpc.stub.StreamObserver; * <p>Only this class should depend on gRPC so that we only need to exclude this during * bootstrapping. */ -public class GrpcServerImpl extends RPCServer implements CommandServerGrpc.CommandServer { +public class GrpcServerImpl extends RPCServer { // UTF-8 won't do because we want to be able to pass arbitrary binary strings. // Not that the internals of Bazel handle that correctly, but why not make at least this little // part correct? @@ -271,9 +271,10 @@ public class GrpcServerImpl extends RPCServer implements CommandServerGrpc.Comma @Override public void serve() throws IOException { Preconditions.checkState(!serving); - server = NettyServerBuilder.forAddress(new InetSocketAddress("localhost", port)) - .addService(CommandServerGrpc.bindService(this)) - .build(); + server = + NettyServerBuilder.forAddress(new InetSocketAddress("localhost", port)) + .addService(commandServer) + .build(); server.start(); if (maxIdleSeconds > 0) { @@ -347,105 +348,114 @@ public class GrpcServerImpl extends RPCServer implements CommandServerGrpc.Comma return instance; } - @Override - public void run( - RunRequest request, StreamObserver<RunResponse> observer) { - if (!request.getCookie().equals(requestCookie) - || request.getClientDescription().isEmpty()) { - observer.onNext(RunResponse.newBuilder() - .setExitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR.getNumericExitCode()) - .build()); - observer.onCompleted(); - return; - } + private final CommandServerGrpc.CommandServerImplBase commandServer = + new CommandServerGrpc.CommandServerImplBase() { + @Override + public void run(RunRequest request, StreamObserver<RunResponse> observer) { + if (!request.getCookie().equals(requestCookie) + || request.getClientDescription().isEmpty()) { + observer.onNext( + RunResponse.newBuilder() + .setExitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR.getNumericExitCode()) + .build()); + observer.onCompleted(); + return; + } - ImmutableList.Builder<String> args = ImmutableList.builder(); - for (ByteString requestArg : request.getArgList()) { - args.add(requestArg.toString(CHARSET)); - } + ImmutableList.Builder<String> args = ImmutableList.builder(); + for (ByteString requestArg : request.getArgList()) { + args.add(requestArg.toString(CHARSET)); + } - String commandId; - int exitCode; - try (RunningCommand command = new RunningCommand()) { - commandId = command.id; - OutErr rpcOutErr = OutErr.create( - new RpcOutputStream(observer, command.id, StreamType.STDOUT), - new RpcOutputStream(observer, command.id, StreamType.STDERR)); - - exitCode = commandExecutor.exec( - args.build(), rpcOutErr, - request.getBlockForLock() ? LockingMode.WAIT : LockingMode.ERROR_OUT, - request.getClientDescription(), clock.currentTimeMillis()); - } catch (InterruptedException e) { - exitCode = ExitCode.INTERRUPTED.getNumericExitCode(); - commandId = ""; // The default value, the client will ignore it - } + String commandId; + int exitCode; + try (RunningCommand command = new RunningCommand()) { + commandId = command.id; + OutErr rpcOutErr = + OutErr.create( + new RpcOutputStream(observer, command.id, StreamType.STDOUT), + new RpcOutputStream(observer, command.id, StreamType.STDERR)); + + exitCode = + commandExecutor.exec( + args.build(), + rpcOutErr, + request.getBlockForLock() ? LockingMode.WAIT : LockingMode.ERROR_OUT, + request.getClientDescription(), + clock.currentTimeMillis()); + } catch (InterruptedException e) { + exitCode = ExitCode.INTERRUPTED.getNumericExitCode(); + commandId = ""; // The default value, the client will ignore it + } - // There is a chance that a cancel request comes in after commandExecutor#exec() has finished - // and no one calls Thread.interrupted() to receive the interrupt. So we just reset the - // interruption state here to make these cancel requests not have any effect outside of command - // execution (after the try block above, the cancel request won't find the thread to interrupt) - Thread.interrupted(); - - RunResponse response = RunResponse.newBuilder() - .setCookie(responseCookie) - .setCommandId(commandId) - .setFinished(true) - .setExitCode(exitCode) - .build(); - - observer.onNext(response); - observer.onCompleted(); - - switch (commandExecutor.shutdown()) { - case NONE: - break; - - case CLEAN: - server.shutdownNow(); - break; - - case EXPUNGE: - disableShutdownHooks(); - server.shutdownNow(); - break; - } - } + // There is a chance that a cancel request comes in after commandExecutor#exec() has + // finished and no one calls Thread.interrupted() to receive the interrupt. So we just + // reset the interruption state here to make these cancel requests not have any effect + // outside of command execution (after the try block above, the cancel request won't find + // the thread to interrupt) + Thread.interrupted(); + + RunResponse response = + RunResponse.newBuilder() + .setCookie(responseCookie) + .setCommandId(commandId) + .setFinished(true) + .setExitCode(exitCode) + .build(); + + observer.onNext(response); + observer.onCompleted(); + + switch (commandExecutor.shutdown()) { + case NONE: + break; + + case CLEAN: + server.shutdownNow(); + break; + + case EXPUNGE: + disableShutdownHooks(); + server.shutdownNow(); + break; + } + } - @Override - public void ping(PingRequest pingRequest, StreamObserver<PingResponse> streamObserver) { - Preconditions.checkState(serving); + @Override + public void ping(PingRequest pingRequest, StreamObserver<PingResponse> streamObserver) { + Preconditions.checkState(serving); - try (RunningCommand command = new RunningCommand()) { - PingResponse.Builder response = PingResponse.newBuilder(); - if (pingRequest.getCookie().equals(requestCookie)) { - response.setCookie(responseCookie); - } + try (RunningCommand command = new RunningCommand()) { + PingResponse.Builder response = PingResponse.newBuilder(); + if (pingRequest.getCookie().equals(requestCookie)) { + response.setCookie(responseCookie); + } - streamObserver.onNext(response.build()); - streamObserver.onCompleted(); - } - } + streamObserver.onNext(response.build()); + streamObserver.onCompleted(); + } + } - @Override - public void cancel(CancelRequest request, StreamObserver<CancelResponse> streamObserver) { - if (!request.getCookie().equals(requestCookie)) { - streamObserver.onCompleted(); - return; - } + @Override + public void cancel(CancelRequest request, StreamObserver<CancelResponse> streamObserver) { + if (!request.getCookie().equals(requestCookie)) { + streamObserver.onCompleted(); + return; + } - try (RunningCommand cancelCommand = new RunningCommand()) { - synchronized (runningCommands) { - RunningCommand pendingCommand = runningCommands.get(request.getCommandId()); - if (pendingCommand != null) { - pendingCommand.thread.interrupt(); - } + try (RunningCommand cancelCommand = new RunningCommand()) { + synchronized (runningCommands) { + RunningCommand pendingCommand = runningCommands.get(request.getCommandId()); + if (pendingCommand != null) { + pendingCommand.thread.interrupt(); + } - startSlowInterruptWatcher(ImmutableSet.of(request.getCommandId())); - } + startSlowInterruptWatcher(ImmutableSet.of(request.getCommandId())); + } - streamObserver.onNext(CancelResponse.newBuilder().setCookie(responseCookie).build()); - streamObserver.onCompleted(); - } - } + streamObserver.onNext(CancelResponse.newBuilder().setCookie(responseCookie).build()); + streamObserver.onCompleted(); + } + } + }; } diff --git a/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java b/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java index 2bf5c39f46..e1fc04ca3f 100644 --- a/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java +++ b/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java @@ -20,7 +20,7 @@ import com.google.devtools.build.lib.remote.MemcacheWorkExecutor; import com.google.devtools.build.lib.remote.RemoteOptions; import com.google.devtools.build.lib.remote.RemoteProtocol.RemoteWorkRequest; import com.google.devtools.build.lib.remote.RemoteProtocol.RemoteWorkResponse; -import com.google.devtools.build.lib.remote.RemoteWorkGrpc; +import com.google.devtools.build.lib.remote.RemoteWorkGrpc.RemoteWorkImplBase; import com.google.devtools.build.lib.util.OS; import com.google.devtools.build.lib.util.ProcessUtils; import com.google.devtools.build.lib.vfs.FileSystem; @@ -41,10 +41,10 @@ import java.util.logging.Level; import java.util.logging.Logger; /** - * Implements a remote worker that accepts work items as protobufs. - * The server implementation is based on grpc. + * Implements a remote worker that accepts work items as protobufs. The server implementation is + * based on grpc. */ -public class RemoteWorker implements RemoteWorkGrpc.RemoteWork { +public class RemoteWorker extends RemoteWorkImplBase { private static final Logger LOG = Logger.getLogger(RemoteWorker.class.getName()); private static final boolean LOG_FINER = LOG.isLoggable(Level.FINER); private final Path workPath; @@ -126,9 +126,7 @@ public class RemoteWorker implements RemoteWorkGrpc.RemoteWork { FileSystemUtils.createDirectoryAndParents(workPath); RemoteWorker worker = new RemoteWorker(workPath, remoteOptions, remoteWorkerOptions, cache); final Server server = - ServerBuilder.forPort(remoteWorkerOptions.listenPort) - .addService(RemoteWorkGrpc.bindService(worker)) - .build(); + ServerBuilder.forPort(remoteWorkerOptions.listenPort).addService(worker).build(); server.start(); final Path pidFile; diff --git a/third_party/grpc/BUILD b/third_party/grpc/BUILD index 25d2a5f407..2ba07e3f8b 100644 --- a/third_party/grpc/BUILD +++ b/third_party/grpc/BUILD @@ -10,11 +10,11 @@ filegroup( java_import( name = "grpc-jar", jars = [ - "grpc-netty-0.14.1.jar", - "grpc-protobuf-0.14.1.jar", - "grpc-protobuf-lite-0.14.1.jar", - "grpc-stub-0.14.1.jar", - "grpc-core-0.14.1.jar", + "grpc-netty-0.15.0.jar", + "grpc-protobuf-0.15.0.jar", + "grpc-protobuf-lite-0.15.0.jar", + "grpc-stub-0.15.0.jar", + "grpc-core-0.15.0.jar", ], runtime_deps = ["//third_party:netty"], ) @@ -22,15 +22,15 @@ java_import( filegroup( name = "grpc-java-plugin", srcs = select({ - "//third_party:windows_mingw": ["protoc-gen-grpc-java-0.14.1-windows-x86_32.exe"], - "//third_party:windows_msys64_mingw64": ["protoc-gen-grpc-java-0.14.1-windows-x86_64.exe"], - "//third_party:windows_msys64": ["protoc-gen-grpc-java-0.14.1-windows-x86_64.exe"], - "//third_party:windows_clang": ["protoc-gen-grpc-java-0.14.1-windows-x86_64.exe"], - "//third_party:darwin": ["protoc-gen-grpc-java-0.14.1-osx-x86_64.exe"], - "//third_party:k8": ["protoc-gen-grpc-java-0.14.1-linux-x86_64.exe"], - "//third_party:piii": ["protoc-gen-grpc-java-0.14.1-linux-x86_32.exe"], - "//third_party:arm": ["protoc-gen-grpc-java-0.14.1-linux-x86_32.exe"], - "//third_party:freebsd": ["protoc-gen-grpc-java-0.14.1-linux-x86_32.exe"], + "//third_party:windows_mingw": ["protoc-gen-grpc-java-0.15.0-windows-x86_32.exe"], + "//third_party:windows_msys64_mingw64": ["protoc-gen-grpc-java-0.15.0-windows-x86_64.exe"], + "//third_party:windows_msys64": ["protoc-gen-grpc-java-0.15.0-windows-x86_64.exe"], + "//third_party:windows_clang": ["protoc-gen-grpc-java-0.15.0-windows-x86_64.exe"], + "//third_party:darwin": ["protoc-gen-grpc-java-0.15.0-osx-x86_64.exe"], + "//third_party:k8": ["protoc-gen-grpc-java-0.15.0-linux-x86_64.exe"], + "//third_party:piii": ["protoc-gen-grpc-java-0.15.0-linux-x86_32.exe"], + "//third_party:arm": ["protoc-gen-grpc-java-0.15.0-linux-x86_32.exe"], + "//third_party:freebsd": ["protoc-gen-grpc-java-0.15.0-linux-x86_32.exe"], }), ) diff --git a/third_party/grpc/README.bazel.md b/third_party/grpc/README.bazel.md index 9c7eaa0bf7..9e910bbb80 100644 --- a/third_party/grpc/README.bazel.md +++ b/third_party/grpc/README.bazel.md @@ -12,10 +12,10 @@ How to update the C++ sources of gRPC: How to update the Java plugin: Download it from Maven central. The project is called `protoc-gen-grpc-java` -and the version is `0.14.1` . +and the version is `0.15.0` . How to update the Java code: Download it from Maven central. The jars are called `grpc-core`, `grpc-netty`, `grpc-protobuf`, `grpc-protobuf-lite`, `grpc-stub` and the version is -`0.14.1`. +`0.15.0`. |