use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server 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();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grakn by graknlabs.
the class EngineContext method startGraknEngineServer.
private GraknEngineServer startGraknEngineServer(RedisWrapper redisWrapper) throws IOException {
EngineID id = EngineID.me();
GraknEngineStatus status = new GraknEngineStatus();
MetricRegistry metricRegistry = new MetricRegistry();
// distributed locks
LockProvider lockProvider = new JedisLockProvider(redisWrapper.getJedisPool());
graknKeyspaceStore = GraknKeyspaceStoreImpl.create(new GraknSystemKeyspaceSession(config));
// tx-factory
engineGraknTxFactory = EngineGraknTxFactory.create(lockProvider, config, graknKeyspaceStore);
// post-processing
IndexStorage indexStorage = RedisIndexStorage.create(redisWrapper.getJedisPool(), metricRegistry);
CountStorage countStorage = RedisCountStorage.create(redisWrapper.getJedisPool(), metricRegistry);
IndexPostProcessor indexPostProcessor = IndexPostProcessor.create(lockProvider, indexStorage);
CountPostProcessor countPostProcessor = CountPostProcessor.create(config, engineGraknTxFactory, lockProvider, metricRegistry, countStorage);
PostProcessor postProcessor = PostProcessor.create(indexPostProcessor, countPostProcessor);
GrpcOpenRequestExecutor requestExecutor = new GrpcOpenRequestExecutorImpl(engineGraknTxFactory);
Server server = ServerBuilder.forPort(0).addService(new GrpcGraknService(requestExecutor, postProcessor)).build();
GrpcServer grpcServer = GrpcServer.create(server);
GraknTestUtil.allocateSparkPort(config);
QueueSanityCheck queueSanityCheck = new RedisSanityCheck(redisWrapper);
GraknEngineServer graknEngineServer = GraknEngineServerFactory.createGraknEngineServer(id, config, status, spark, Collections.emptyList(), grpcServer, engineGraknTxFactory, metricRegistry, queueSanityCheck, lockProvider, postProcessor, graknKeyspaceStore);
graknEngineServer.start();
// Read the automatically allocated ports and write them back into the config
config.setConfigProperty(GraknConfigKey.GRPC_PORT, server.getPort());
return graknEngineServer;
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project grakn by graknlabs.
the class GrpcServerTest method setUp.
@Before
public void setUp() throws IOException {
doNothing().when(mockedPostProcessor).submit(any(CommitLog.class));
GrpcOpenRequestExecutor requestExecutor = new GrpcOpenRequestExecutorImpl(txFactory);
Server server = ServerBuilder.forPort(PORT).addService(new GrpcGraknService(requestExecutor, mockedPostProcessor)).build();
grpcServer = GrpcServer.create(server);
grpcServer.start();
QueryBuilder qb = mock(QueryBuilder.class);
when(tx.admin()).thenReturn(tx);
when(txFactory.tx(eq(MYKS), any())).thenReturn(tx);
when(tx.graql()).thenReturn(qb);
when(qb.parse(QUERY)).thenReturn(query);
when(query.results(any())).thenAnswer(params -> Stream.of(QueryResult.getDefaultInstance()));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project pravega by pravega.
the class ControllerImplTest method testKeepAlive.
@Test
public void testKeepAlive() throws IOException, ExecutionException, InterruptedException {
// Verify that keep-alive timeout less than permissible by the server results in a failure.
NettyChannelBuilder builder = NettyChannelBuilder.forAddress("localhost", serverPort).keepAliveTime(10, TimeUnit.SECONDS);
if (testSecure) {
builder = builder.sslContext(GrpcSslContexts.forClient().trustManager(new File("../config/cert.pem")).build());
} else {
builder = builder.usePlaintext(true);
}
final ControllerImpl controller = new ControllerImpl(builder, ControllerImplConfig.builder().clientConfig(ClientConfig.builder().trustStore("../config/cert.pem").controllerURI(URI.create((testSecure ? "tls://" : "tcp://") + "localhost:" + serverPort)).build()).retryAttempts(1).build(), this.executor);
CompletableFuture<Boolean> createStreamStatus = controller.createStream(StreamConfiguration.builder().streamName("streamdelayed").scope("scope1").scalingPolicy(ScalingPolicy.fixed(1)).build());
AssertExtensions.assertThrows("Should throw RetriesExhaustedException", createStreamStatus, throwable -> throwable instanceof RetriesExhaustedException);
// Verify that the same RPC with permissible keepalive time succeeds.
int serverPort2 = TestUtils.getAvailableListenPort();
NettyServerBuilder testServerBuilder = NettyServerBuilder.forPort(serverPort2).addService(testServerImpl).permitKeepAliveTime(5, TimeUnit.SECONDS);
if (testSecure) {
testServerBuilder = testServerBuilder.useTransportSecurity(new File("../config/cert.pem"), new File("../config/key.pem"));
}
Server testServer = testServerBuilder.build().start();
builder = NettyChannelBuilder.forAddress("localhost", serverPort2).keepAliveTime(10, TimeUnit.SECONDS);
if (testSecure) {
builder = builder.sslContext(GrpcSslContexts.forClient().trustManager(new File("../config/cert.pem")).build());
} else {
builder = builder.usePlaintext(true);
}
final ControllerImpl controller1 = new ControllerImpl(builder, ControllerImplConfig.builder().clientConfig(ClientConfig.builder().trustStore("../config/cert.pem").controllerURI(URI.create((testSecure ? "tls://" : "tcp://") + "localhost:" + serverPort)).build()).retryAttempts(1).build(), this.executor);
createStreamStatus = controller1.createStream(StreamConfiguration.builder().streamName("streamdelayed").scope("scope1").scalingPolicy(ScalingPolicy.fixed(1)).build());
assertTrue(createStreamStatus.get());
testServer.shutdownNow();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project janusgraph by JanusGraph.
the class JanusGraphGrpcServerBaseTest method createServer.
private static Pair<Server, String> createServer(JanusGraphContextHandler contextHandler) throws IOException {
String serverName = InProcessServerBuilder.generateName();
Server server = InProcessServerBuilder.forName(serverName).directExecutor().addService(new JanusGraphManagerServiceImpl(contextHandler)).addService(new SchemaManagerImpl(contextHandler)).build().start();
return new Pair<>(server, serverName);
}
Aggregations