use of io.pravega.shared.rest.RESTServerConfig in project pravega by pravega.
the class Main method main.
public static void main(String[] args) {
StatsProvider statsProvider = null;
try {
// 0. Initialize metrics provider
MetricsProvider.initialize(Config.METRICS_CONFIG);
statsProvider = MetricsProvider.getMetricsProvider();
statsProvider.start();
ZKClientConfig zkClientConfig = ZKClientConfigImpl.builder().connectionString(Config.ZK_URL).secureConnectionToZooKeeper(Config.SECURE_ZK).trustStorePath(Config.ZK_TRUSTSTORE_FILE_PATH).trustStorePasswordPath(Config.ZK_TRUSTSTORE_PASSWORD_FILE_PATH).namespace("pravega/" + Config.CLUSTER_NAME).initialSleepInterval(Config.ZK_RETRY_SLEEP_MS).maxRetries(Config.ZK_MAX_RETRIES).sessionTimeoutMs(Config.ZK_SESSION_TIMEOUT_MS).build();
StoreClientConfig storeClientConfig;
if (Config.USE_PRAVEGA_TABLES) {
storeClientConfig = StoreClientConfigImpl.withPravegaTablesClient(zkClientConfig);
} else {
storeClientConfig = StoreClientConfigImpl.withZKClient(zkClientConfig);
}
HostMonitorConfig hostMonitorConfig = HostMonitorConfigImpl.builder().hostMonitorEnabled(Config.HOST_MONITOR_ENABLED).hostMonitorMinRebalanceInterval(Config.CLUSTER_MIN_REBALANCE_INTERVAL).containerCount(Config.HOST_STORE_CONTAINER_COUNT).hostContainerMap(HostMonitorConfigImpl.getHostContainerMap(Config.SERVICE_HOST, Config.SERVICE_PORT, Config.HOST_STORE_CONTAINER_COUNT)).build();
TimeoutServiceConfig timeoutServiceConfig = TimeoutServiceConfig.builder().maxLeaseValue(Config.MAX_LEASE_VALUE).build();
ControllerEventProcessorConfig eventProcessorConfig = ControllerEventProcessorConfigImpl.withDefault();
GRPCServerConfig grpcServerConfig = Config.GRPC_SERVER_CONFIG;
RESTServerConfig restServerConfig = RESTServerConfigImpl.builder().host(Config.REST_SERVER_IP).port(Config.REST_SERVER_PORT).tlsEnabled(Config.TLS_ENABLED).tlsProtocolVersion(Config.TLS_PROTOCOL_VERSION.toArray(new String[Config.TLS_PROTOCOL_VERSION.size()])).keyFilePath(Config.REST_KEYSTORE_FILE_PATH).keyFilePasswordPath(Config.REST_KEYSTORE_PASSWORD_FILE_PATH).build();
ControllerServiceConfig serviceConfig = ControllerServiceConfigImpl.builder().threadPoolSize(Config.ASYNC_TASK_POOL_SIZE).storeClientConfig(storeClientConfig).hostMonitorConfig(hostMonitorConfig).controllerClusterListenerEnabled(true).timeoutServiceConfig(timeoutServiceConfig).eventProcessorConfig(Optional.of(eventProcessorConfig)).grpcServerConfig(Optional.of(grpcServerConfig)).restServerConfig(Optional.of(restServerConfig)).tlsEnabledForSegmentStore(Config.TLS_ENABLED_FOR_SEGMENT_STORE).build();
setUncaughtExceptionHandler(Main::logUncaughtException);
ControllerServiceMain controllerServiceMain = new ControllerServiceMain(serviceConfig);
controllerServiceMain.startAsync();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
onShutdown(controllerServiceMain);
}));
controllerServiceMain.awaitTerminated();
log.info("Controller service exited");
System.exit(0);
} catch (Throwable e) {
log.error("Controller service failed", e);
System.exit(-1);
} finally {
if (statsProvider != null) {
statsProvider.close();
}
}
}
use of io.pravega.shared.rest.RESTServerConfig in project pravega by pravega.
the class RESTServerConfigImplTests method testToStringIsSuccessfulWithTlsDisabled.
@Test
public void testToStringIsSuccessfulWithTlsDisabled() {
RESTServerConfig config = RESTServerConfigImpl.builder().host("localhost").port(2020).authorizationEnabled(false).userPasswordFile(null).tlsEnabled(false).keyFilePath(null).keyFilePasswordPath(null).build();
assertNotNull(config.toString());
}
use of io.pravega.shared.rest.RESTServerConfig in project pravega by pravega.
the class RESTServerConfigImplTests method testToStringIsSuccessfulWithAllConfigSpecified.
// region Tests that verify the toString() method.
// Note: It might seem odd that we are unit testing the toString() method of the code under test. The reason we are
// doing that is that the method is hand-rolled and there is a bit of logic there that isn't entirely unlikely to fail.
@Test
public void testToStringIsSuccessfulWithAllConfigSpecified() {
RESTServerConfig config = RESTServerConfigImpl.builder().host("localhost").port(2020).authorizationEnabled(true).userPasswordFile("/passwd").tlsEnabled(true).tlsProtocolVersion(SecurityConfigDefaults.TLS_PROTOCOL_VERSION).keyFilePath("/rest.keystore.jks").keyFilePasswordPath("/keystore.jks.passwd").build();
assertNotNull(config.toString());
}
use of io.pravega.shared.rest.RESTServerConfig in project pravega by pravega.
the class RESTAuthHelperTest method init.
@Before
public void init() {
RESTServerConfig config = RESTServerConfigImpl.builder().host("localhost").port(TestUtils.getAvailableListenPort()).authorizationEnabled(true).userPasswordFile("passwd").tlsEnabled(false).build();
AuthHandlerManager authManager = new AuthHandlerManager(config);
authManager.registerHandler(new FakeAuthHandler());
authHelper = new RESTAuthHelper(authManager);
}
use of io.pravega.shared.rest.RESTServerConfig in project pravega by pravega.
the class InProcPravegaCluster method startLocalController.
private ControllerServiceMain startLocalController(int controllerId) {
ZKClientConfig zkClientConfig = ZKClientConfigImpl.builder().connectionString(zkUrl).namespace("pravega/" + clusterName).initialSleepInterval(2000).maxRetries(1).sessionTimeoutMs(10 * 1000).secureConnectionToZooKeeper(this.secureZK).trustStorePath(jksTrustFile).trustStorePasswordPath(keyPasswordFile).build();
StoreClientConfig storeClientConfig = StoreClientConfigImpl.withPravegaTablesClient(zkClientConfig);
HostMonitorConfig hostMonitorConfig = HostMonitorConfigImpl.builder().hostMonitorEnabled(true).containerCount(containerCount).hostMonitorMinRebalanceInterval(1).build();
TimeoutServiceConfig timeoutServiceConfig = TimeoutServiceConfig.builder().maxLeaseValue(Config.MAX_LEASE_VALUE).build();
ControllerEventProcessorConfig eventProcessorConfig = ControllerEventProcessorConfigImpl.withDefaultBuilder().shutdownTimeout(Duration.ofMillis(100)).build();
GRPCServerConfig grpcServerConfig = GRPCServerConfigImpl.builder().port(this.controllerPorts[controllerId]).publishedRPCHost("localhost").publishedRPCPort(this.controllerPorts[controllerId]).authorizationEnabled(this.enableAuth).tlsEnabled(this.enableTls).tlsProtocolVersion(this.tlsProtocolVersion).tlsTrustStore(this.certFile).tlsCertFile(this.certFile).tlsKeyFile(this.keyFile).userPasswordFile(this.passwdFile).tokenSigningKey("secret").accessTokenTTLInSeconds(600).replyWithStackTraceOnError(false).requestTracingEnabled(true).build();
RESTServerConfig restServerConfig = null;
if (this.enableRestServer) {
restServerConfig = RESTServerConfigImpl.builder().host("0.0.0.0").port(this.restServerPort).tlsEnabled(this.enableTls).tlsProtocolVersion(this.tlsProtocolVersion).keyFilePath(this.jksKeyFile).keyFilePasswordPath(this.keyPasswordFile).build();
}
ControllerServiceConfig serviceConfig = ControllerServiceConfigImpl.builder().threadPoolSize(Runtime.getRuntime().availableProcessors()).storeClientConfig(storeClientConfig).hostMonitorConfig(hostMonitorConfig).controllerClusterListenerEnabled(false).timeoutServiceConfig(timeoutServiceConfig).eventProcessorConfig(Optional.of(eventProcessorConfig)).grpcServerConfig(Optional.of(grpcServerConfig)).restServerConfig(Optional.ofNullable(restServerConfig)).shutdownTimeout(Duration.ofMillis(100)).build();
ControllerServiceMain controllerService = new ControllerServiceMain(serviceConfig);
try {
controllerService.startAsync().awaitRunning();
return controllerService;
} catch (Throwable ex) {
Callbacks.invokeSafely(controllerService::close, ex2 -> log.error("Unable to clean up controller startup.", ex2));
throw ex;
}
}
Aggregations