Search in sources :

Example 1 with RemoteOptions

use of com.google.devtools.build.lib.remote.RemoteOptions in project bazel by bazelbuild.

the class RemoteWorker method main.

public static void main(String[] args) throws Exception {
    OptionsParser parser = OptionsParser.newOptionsParser(RemoteOptions.class, RemoteWorkerOptions.class);
    parser.parseAndExitUponError(args);
    RemoteOptions remoteOptions = parser.getOptions(RemoteOptions.class);
    RemoteWorkerOptions remoteWorkerOptions = parser.getOptions(RemoteWorkerOptions.class);
    if (remoteWorkerOptions.workPath == null) {
        printUsage(parser);
        return;
    }
    System.out.println("*** Initializing in-memory cache server.");
    ConcurrentMap<String, byte[]> cache = ConcurrentMapFactory.isRemoteCacheOptions(remoteOptions) ? ConcurrentMapFactory.create(remoteOptions) : new ConcurrentHashMap<String, byte[]>();
    System.out.println("*** Starting grpc server on all locally bound IPs on port " + remoteWorkerOptions.listenPort + ".");
    Path workPath = getFileSystem().getPath(remoteWorkerOptions.workPath);
    FileSystemUtils.createDirectoryAndParents(workPath);
    RemoteWorker worker = new RemoteWorker(workPath, remoteWorkerOptions, new ConcurrentMapActionCache(cache));
    final Server server = ServerBuilder.forPort(remoteWorkerOptions.listenPort).addService(worker.getCasServer()).addService(worker.getExecutionServer()).addService(worker.getExecCacheServer()).build();
    server.start();
    final Path pidFile;
    if (remoteWorkerOptions.pidFile != null) {
        pidFile = getFileSystem().getPath(remoteWorkerOptions.pidFile);
        PrintWriter writer = new PrintWriter(pidFile.getOutputStream());
        writer.append(Integer.toString(ProcessUtils.getpid()));
        writer.append("\n");
        writer.close();
    } else {
        pidFile = null;
    }
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            System.err.println("*** Shutting down grpc server.");
            server.shutdown();
            if (pidFile != null) {
                try {
                    pidFile.delete();
                } catch (IOException e) {
                    System.err.println("Cannot remove pid file: " + pidFile.toString());
                }
            }
            System.err.println("*** Server shut down.");
        }
    });
    server.awaitTermination();
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Server(io.grpc.Server) ConcurrentMapActionCache(com.google.devtools.build.lib.remote.ConcurrentMapActionCache) RemoteOptions(com.google.devtools.build.lib.remote.RemoteOptions) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) OptionsParser(com.google.devtools.common.options.OptionsParser) PrintWriter(java.io.PrintWriter)

Aggregations

ConcurrentMapActionCache (com.google.devtools.build.lib.remote.ConcurrentMapActionCache)1 RemoteOptions (com.google.devtools.build.lib.remote.RemoteOptions)1 Path (com.google.devtools.build.lib.vfs.Path)1 OptionsParser (com.google.devtools.common.options.OptionsParser)1 ByteString (com.google.protobuf.ByteString)1 Server (io.grpc.Server)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1