Search in sources :

Example 31 with ControllerImpl

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());
    }
}
Also used : lombok.val(lombok.val) CompletionException(java.util.concurrent.CompletionException) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) ClientConfig(io.pravega.client.ClientConfig) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 32 with ControllerImpl

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);
}
Also used : lombok.val(lombok.val) SegmentOutputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) SegmentInputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentInputStreamFactoryImpl) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) ByteStreamClientImpl(io.pravega.client.byteStream.impl.ByteStreamClientImpl)

Example 33 with ControllerImpl

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);
}
Also used : lombok.val(lombok.val) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl)

Example 34 with ControllerImpl

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");
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) TestingServerStarter(io.pravega.test.common.TestingServerStarter) AdminConnectionListener(io.pravega.segmentstore.server.host.handler.AdminConnectionListener) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ControllerWrapper(io.pravega.test.integration.demo.ControllerWrapper) TableStore(io.pravega.segmentstore.contracts.tables.TableStore)

Aggregations

ControllerImpl (io.pravega.client.control.impl.ControllerImpl)34 ClientConfig (io.pravega.client.ClientConfig)20 URI (java.net.URI)19 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)17 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)17 Before (org.junit.Before)16 Service (io.pravega.test.system.framework.services.Service)14 Test (org.junit.Test)14 Cleanup (lombok.Cleanup)12 Controller (io.pravega.client.control.impl.Controller)11 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)10 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)8 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)8 Futures (io.pravega.common.concurrent.Futures)8 HashMap (java.util.HashMap)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 Slf4j (lombok.extern.slf4j.Slf4j)8 Assert.assertTrue (org.junit.Assert.assertTrue)8 Stream (io.pravega.client.stream.Stream)7 StreamCut (io.pravega.client.stream.StreamCut)7