use of io.pravega.client.control.impl.ControllerImpl in project pravega by pravega.
the class JwtTokenProviderImplTest method testTokenRefreshFutureIsClearedUponFailure.
@Test
public void testTokenRefreshFutureIsClearedUponFailure() {
ClientConfig config = ClientConfig.builder().controllerURI(URI.create("tcp://non-existent-cluster:9090")).build();
@Cleanup("shutdownNow") val executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "test");
@Cleanup Controller controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(config).retryAttempts(1).build(), executor);
JwtTokenProviderImpl tokenProvider = (JwtTokenProviderImpl) DelegationTokenProviderFactory.create(controllerClient, "bob-0", "bob-0", AccessOperation.ANY);
try {
String token = tokenProvider.retrieveToken().join();
fail("Didn't expect the control to come here");
} catch (CompletionException e) {
log.info("Encountered CompletionException as expected");
assertNull("Expected a null tokenRefreshFuture", tokenProvider.getTokenRefreshFuture().get());
}
try {
tokenProvider.retrieveToken().join();
} catch (CompletionException e) {
log.info("Encountered CompletionException as expected");
assertNull("Expected a null tokenRefreshFuture", tokenProvider.getTokenRefreshFuture().get());
}
}
use of io.pravega.client.control.impl.ControllerImpl in project pravega by pravega.
the class ByteStreamClientFactory method withScope.
/**
* Creates a new instance of ByteStreamClientFactory.
*
* @param scope The scope string.
* @param config Configuration for the client.
* @return Instance of ByteStreamClientFactory implementation.
*/
static ByteStreamClientFactory withScope(String scope, ClientConfig config) {
val connectionFactory = new SocketConnectionFactoryImpl(config);
ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(config).build(), connectionFactory.getInternalExecutor());
val connectionPool = new ConnectionPoolImpl(config, Preconditions.checkNotNull(connectionFactory));
val inputStreamFactory = new SegmentInputStreamFactoryImpl(controller, connectionPool);
val outputStreamFactory = new SegmentOutputStreamFactoryImpl(controller, connectionPool);
val metaStreamFactory = new SegmentMetadataClientFactoryImpl(controller, connectionPool);
return new ByteStreamClientImpl(scope, controller, connectionPool, inputStreamFactory, outputStreamFactory, metaStreamFactory);
}
use of io.pravega.client.control.impl.ControllerImpl in project pravega by pravega.
the class SynchronizerClientFactory method withScope.
/**
* Creates a new instance of Client Factory.
*
* @param scope The scope string.
* @param config Configuration for the client.
* @return Instance of ClientFactory implementation.
*/
static SynchronizerClientFactory withScope(String scope, ClientConfig config) {
// Change the max number of number of allowed connections to the segment store to 1.
val updatedConfig = config.toBuilder().maxConnectionsPerSegmentStore(1).enableTlsToSegmentStore(config.isEnableTlsToSegmentStore()).enableTlsToController(config.isEnableTlsToController()).build();
val connectionFactory = new SocketConnectionFactoryImpl(updatedConfig, 1);
return new ClientFactoryImpl(scope, new ControllerImpl(ControllerImplConfig.builder().clientConfig(updatedConfig).build(), connectionFactory.getInternalExecutor()), updatedConfig, connectionFactory);
}
use of io.pravega.client.control.impl.ControllerImpl in project pravega by pravega.
the class SetupUtils method startAllServices.
/**
* Start all pravega related services required for the test deployment.
*
* @param numThreads the number of threads for the internal client threadpool.
* @param enableAuth set to enale authentication
* @param enableTls set to enable tls
* @throws Exception on any errors.
*/
public void startAllServices(Integer numThreads, boolean enableAuth, boolean enableTls) throws Exception {
if (!this.started.compareAndSet(false, true)) {
log.warn("Services already started, not attempting to start again");
return;
}
if (enableAuth) {
clientConfigBuilder = clientConfigBuilder.credentials(new DefaultCredentials(SecurityConfigDefaults.AUTH_ADMIN_PASSWORD, SecurityConfigDefaults.AUTH_ADMIN_USERNAME));
}
if (enableTls) {
clientConfigBuilder = clientConfigBuilder.trustStore(pathToConfig() + SecurityConfigDefaults.TLS_CA_CERT_FILE_NAME).controllerURI(URI.create("tls://localhost:" + controllerRPCPort)).validateHostName(false);
} else {
clientConfigBuilder = clientConfigBuilder.controllerURI(URI.create("tcp://localhost:" + controllerRPCPort));
}
this.executor = ExecutorServiceHelpers.newScheduledThreadPool(2, "Controller pool");
this.controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(getClientConfig()).build(), executor);
this.clientFactory = new ClientFactoryImpl(scope, controller, getClientConfig());
// Start zookeeper.
this.zkTestServer = new TestingServerStarter().start();
this.zkTestServer.start();
// Start Pravega Service.
this.serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
this.serviceBuilder.initialize();
StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
TableStore tableStore = serviceBuilder.createTableStoreService();
this.server = new PravegaConnectionListener(enableTls, false, "localhost", servicePort, store, tableStore, SegmentStatsRecorder.noOp(), TableSegmentStatsRecorder.noOp(), new PassingTokenVerifier(), pathToConfig() + SecurityConfigDefaults.TLS_SERVER_CERT_FILE_NAME, pathToConfig() + SecurityConfigDefaults.TLS_SERVER_PRIVATE_KEY_FILE_NAME, true, serviceBuilder.getLowPriorityExecutor(), SecurityConfigDefaults.TLS_PROTOCOL_VERSION);
this.server.startListening();
log.info("Started Pravega Service");
this.adminListener = new AdminConnectionListener(enableTls, false, "localhost", adminPort, store, tableStore, new PassingTokenVerifier(), pathToConfig() + SecurityConfigDefaults.TLS_SERVER_CERT_FILE_NAME, pathToConfig() + SecurityConfigDefaults.TLS_SERVER_PRIVATE_KEY_FILE_NAME, SecurityConfigDefaults.TLS_PROTOCOL_VERSION);
this.adminListener.startListening();
log.info("AdminConnectionListener started successfully.");
// Start Controller.
this.controllerWrapper = new ControllerWrapper(this.zkTestServer.getConnectString(), false, true, controllerRPCPort, "localhost", servicePort, Config.HOST_STORE_CONTAINER_COUNT, controllerRESTPort, enableAuth, pathToConfig() + SecurityConfigDefaults.AUTH_HANDLER_INPUT_FILE_NAME, "secret", true, 600, enableTls, SecurityConfigDefaults.TLS_PROTOCOL_VERSION, pathToConfig() + SecurityConfigDefaults.TLS_SERVER_CERT_FILE_NAME, pathToConfig() + SecurityConfigDefaults.TLS_SERVER_PRIVATE_KEY_FILE_NAME, pathToConfig() + SecurityConfigDefaults.TLS_SERVER_KEYSTORE_NAME, pathToConfig() + SecurityConfigDefaults.TLS_PASSWORD_FILE_NAME);
this.controllerWrapper.awaitRunning();
this.controllerWrapper.getController().createScope(scope).get();
log.info("Initialized Pravega Controller");
}
Aggregations