Search in sources :

Example 26 with Controller

use of io.pravega.client.stream.impl.Controller in project pravega by pravega.

the class EndToEndWithScaleTest method testScale.

@Test(timeout = 30000)
public void testScale() throws Exception {
    StreamConfiguration config = StreamConfiguration.builder().scope("test").streamName("test").scalingPolicy(ScalingPolicy.byEventRate(10, 2, 1)).build();
    Controller controller = controllerWrapper.getController();
    controllerWrapper.getControllerService().createScope("test").get();
    controller.createStream(config).get();
    @Cleanup ConnectionFactory connectionFactory = new ConnectionFactoryImpl(ClientConfig.builder().controllerURI(URI.create("tcp://localhost")).build());
    @Cleanup ClientFactory clientFactory = new ClientFactoryImpl("test", controller, connectionFactory);
    @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter("test", new JavaSerializer<>(), EventWriterConfig.builder().build());
    writer.writeEvent("0", "txntest1").get();
    // scale
    Stream stream = new StreamImpl("test", "test");
    Map<Double, Double> map = new HashMap<>();
    map.put(0.0, 0.33);
    map.put(0.33, 0.66);
    map.put(0.66, 1.0);
    Boolean result = controller.scaleStream(stream, Collections.singletonList(0), map, executor).getFuture().get();
    assertTrue(result);
    writer.writeEvent("0", "txntest2").get();
    @Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl("test", controller, clientFactory, connectionFactory);
    groupManager.createReaderGroup("reader", ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/test").build());
    @Cleanup EventStreamReader<String> reader = clientFactory.createReader("readerId", "reader", new JavaSerializer<>(), ReaderConfig.builder().build());
    EventRead<String> event = reader.readNextEvent(10000);
    assertNotNull(event);
    assertEquals("txntest1", event.getEvent());
    event = reader.readNextEvent(10000);
    assertNotNull(event);
    assertEquals("txntest2", event.getEvent());
}
Also used : ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) HashMap(java.util.HashMap) ClientFactory(io.pravega.client.ClientFactory) Controller(io.pravega.client.stream.impl.Controller) Cleanup(lombok.Cleanup) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) StreamImpl(io.pravega.client.stream.impl.StreamImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Stream(io.pravega.client.stream.Stream) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) Test(org.junit.Test)

Example 27 with Controller

use of io.pravega.client.stream.impl.Controller in project pravega by pravega.

the class AutoScaleTest method scaleDownTest.

/**
 * Invoke the simple scale down Test, produce no into a stream.
 * The test will periodically check if a scale event has occured by talking to controller via
 * controller client.
 *
 * @throws InterruptedException if interrupted
 * @throws URISyntaxException   If URI is invalid
 */
private CompletableFuture<Void> scaleDownTest() {
    final ControllerImpl controller = getController();
    final AtomicBoolean exit = new AtomicBoolean(false);
    // overall wait for test to complete in 260 seconds (4.2 minutes) or scale down, whichever happens first.
    return Retry.withExpBackoff(10, 10, 30, Duration.ofSeconds(10).toMillis()).retryingOn(ScaleOperationNotDoneException.class).throwingOn(RuntimeException.class).runAsync(() -> controller.getCurrentSegments(SCOPE, SCALE_DOWN_STREAM_NAME).thenAccept(x -> {
        if (x.getSegments().size() == 2) {
            throw new ScaleOperationNotDoneException();
        } else {
            log.info("scale down done successfully");
            exit.set(true);
        }
    }), EXECUTOR_SERVICE);
}
Also used : EventStreamWriter(io.pravega.client.stream.EventStreamWriter) StreamImpl(io.pravega.client.stream.impl.StreamImpl) Retry(io.pravega.common.util.Retry) URISyntaxException(java.net.URISyntaxException) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Cleanup(lombok.Cleanup) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) ControllerImpl(io.pravega.client.stream.impl.ControllerImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Service(io.pravega.test.system.framework.services.Service) Duration(java.time.Duration) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Status(io.grpc.Status) URI(java.net.URI) Utils(io.pravega.test.system.framework.Utils) Transaction(io.pravega.client.stream.Transaction) Before(org.junit.Before) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Environment(io.pravega.test.system.framework.Environment) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Executors(java.util.concurrent.Executors) StatusRuntimeException(io.grpc.StatusRuntimeException) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ClientFactory(io.pravega.client.ClientFactory) Controller(io.pravega.client.stream.impl.Controller) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Futures(io.pravega.common.concurrent.Futures) SystemTestRunner(io.pravega.test.system.framework.SystemTestRunner) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StatusRuntimeException(io.grpc.StatusRuntimeException) ControllerImpl(io.pravega.client.stream.impl.ControllerImpl)

Example 28 with Controller

use of io.pravega.client.stream.impl.Controller in project pravega by pravega.

the class AutoScaleTest method createStream.

/**
 * Invoke the createStream method, ensure we are able to create stream.
 *
 * @throws InterruptedException if interrupted
 * @throws URISyntaxException   If URI is invalid
 * @throws ExecutionException   if error in create stream
 */
@Before
public void createStream() throws InterruptedException, ExecutionException {
    // create a scope
    Controller controller = getController();
    Boolean createScopeStatus = controller.createScope(SCOPE).get();
    log.debug("create scope status {}", createScopeStatus);
    // create a stream
    Boolean createStreamStatus = controller.createStream(CONFIG_UP).get();
    log.debug("create stream status for scale up stream {}", createStreamStatus);
    createStreamStatus = controller.createStream(CONFIG_DOWN).get();
    log.debug("create stream status for scaledown stream {}", createStreamStatus);
    log.debug("scale down stream starting segments:" + controller.getCurrentSegments(SCOPE, SCALE_DOWN_STREAM_NAME).get().getSegments().size());
    Map<Double, Double> keyRanges = new HashMap<>();
    keyRanges.put(0.0, 0.5);
    keyRanges.put(0.5, 1.0);
    Boolean status = controller.scaleStream(new StreamImpl(SCOPE, SCALE_DOWN_STREAM_NAME), Collections.singletonList(0), keyRanges, EXECUTOR_SERVICE).getFuture().get();
    assertTrue(status);
    createStreamStatus = controller.createStream(CONFIG_TXN).get();
    log.debug("create stream status for txn stream {}", createStreamStatus);
}
Also used : HashMap(java.util.HashMap) StreamImpl(io.pravega.client.stream.impl.StreamImpl) Controller(io.pravega.client.stream.impl.Controller) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Before(org.junit.Before)

Example 29 with Controller

use of io.pravega.client.stream.impl.Controller in project pravega by pravega.

the class AutoScaleTest method scaleUpTxnTest.

/**
 * Invoke the scale up Test with transactional writes. Produce traffic from multiple writers in parallel.
 * Each writer writes using transactions.
 * Transactions are committed quickly to give
 * The test will periodically check if a scale event has occured by talking to controller via
 * controller client.
 *
 * @throws InterruptedException if interrupted
 * @throws URISyntaxException   If URI is invalid
 */
private CompletableFuture<Void> scaleUpTxnTest() {
    ControllerImpl controller = getController();
    final AtomicBoolean exit = new AtomicBoolean(false);
    ClientFactory clientFactory = getClientFactory();
    startNewTxnWriter(clientFactory, exit);
    // overall wait for test to complete in 260 seconds (4.2 minutes) or scale up, whichever happens first.
    return Retry.withExpBackoff(10, 10, 30, Duration.ofSeconds(10).toMillis()).retryingOn(ScaleOperationNotDoneException.class).throwingOn(RuntimeException.class).runAsync(() -> controller.getCurrentSegments(SCOPE, SCALE_UP_TXN_STREAM_NAME).thenAccept(x -> {
        if (x.getSegments().size() == 1) {
            throw new ScaleOperationNotDoneException();
        } else {
            log.info("txn test scale up done successfully");
            exit.set(true);
        }
    }), EXECUTOR_SERVICE);
}
Also used : EventStreamWriter(io.pravega.client.stream.EventStreamWriter) StreamImpl(io.pravega.client.stream.impl.StreamImpl) Retry(io.pravega.common.util.Retry) URISyntaxException(java.net.URISyntaxException) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Cleanup(lombok.Cleanup) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) ControllerImpl(io.pravega.client.stream.impl.ControllerImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Service(io.pravega.test.system.framework.services.Service) Duration(java.time.Duration) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Status(io.grpc.Status) URI(java.net.URI) Utils(io.pravega.test.system.framework.Utils) Transaction(io.pravega.client.stream.Transaction) Before(org.junit.Before) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Environment(io.pravega.test.system.framework.Environment) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Executors(java.util.concurrent.Executors) StatusRuntimeException(io.grpc.StatusRuntimeException) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ClientFactory(io.pravega.client.ClientFactory) Controller(io.pravega.client.stream.impl.Controller) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Futures(io.pravega.common.concurrent.Futures) SystemTestRunner(io.pravega.test.system.framework.SystemTestRunner) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StatusRuntimeException(io.grpc.StatusRuntimeException) ControllerImpl(io.pravega.client.stream.impl.ControllerImpl) ClientFactory(io.pravega.client.ClientFactory)

Example 30 with Controller

use of io.pravega.client.stream.impl.Controller in project pravega by pravega.

the class ControllerFailoverTest method failoverTest.

@Test(timeout = 180000)
public void failoverTest() throws InterruptedException, ExecutionException {
    String scope = "testFailoverScope" + RandomStringUtils.randomAlphabetic(5);
    String stream = "testFailoverStream" + RandomStringUtils.randomAlphabetic(5);
    int initialSegments = 2;
    List<Integer> segmentsToSeal = Collections.singletonList(0);
    Map<Double, Double> newRangesToCreate = new HashMap<>();
    newRangesToCreate.put(0.0, 0.25);
    newRangesToCreate.put(0.25, 0.5);
    long lease = 29000;
    long maxExecutionTime = 60000;
    long scaleGracePeriod = 30000;
    // Connect with first controller instance.
    final Controller controller1 = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(controllerURIDirect).build()).build(), EXECUTOR_SERVICE);
    // Create scope, stream, and a transaction with high timeout value.
    controller1.createScope(scope).join();
    log.info("Scope {} created successfully", scope);
    createStream(controller1, scope, stream, ScalingPolicy.fixed(initialSegments));
    log.info("Stream {}/{} created successfully", scope, stream);
    long txnCreationTimestamp = System.nanoTime();
    StreamImpl stream1 = new StreamImpl(scope, stream);
    TxnSegments txnSegments = controller1.createTransaction(stream1, lease, scaleGracePeriod).join();
    log.info("Transaction {} created successfully, beginTime={}", txnSegments.getTxnId(), txnCreationTimestamp);
    // Initiate scale operation. It will block until ongoing transaction is complete.
    controller1.startScale(stream1, segmentsToSeal, newRangesToCreate).join();
    // Ensure that scale is not yet done.
    boolean scaleStatus = controller1.checkScaleStatus(stream1, 0).join();
    log.info("Status of scale operation isDone={}", scaleStatus);
    Assert.assertTrue(!scaleStatus);
    // Now stop the controller instance executing scale operation.
    Futures.getAndHandleExceptions(controllerService1.scaleService(1), ExecutionException::new);
    log.info("Successfully stopped one instance of controller service");
    List<URI> conUris = controllerService1.getServiceDetails();
    // Fetch all the RPC endpoints and construct the client URIs.
    final List<String> uris = conUris.stream().filter(uri -> Utils.DOCKER_BASED ? uri.getPort() == Utils.DOCKER_CONTROLLER_PORT : uri.getPort() == Utils.MARATHON_CONTROLLER_PORT).map(URI::getAuthority).collect(Collectors.toList());
    controllerURIDirect = URI.create("tcp://" + String.join(",", uris));
    log.info("Controller Service direct URI: {}", controllerURIDirect);
    // Connect to another controller instance.
    final Controller controller2 = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(controllerURIDirect).build()).build(), EXECUTOR_SERVICE);
    // Fetch status of transaction.
    log.info("Fetching status of transaction {}, time elapsed since its creation={}", txnSegments.getTxnId(), System.nanoTime() - txnCreationTimestamp);
    Transaction.Status status = controller2.checkTransactionStatus(stream1, txnSegments.getTxnId()).join();
    log.info("Transaction {} status={}", txnSegments.getTxnId(), status);
    if (status == Transaction.Status.OPEN) {
        // Abort the ongoing transaction.
        log.info("Trying to abort transaction {}, by sending request to controller at {}", txnSegments.getTxnId(), controllerURIDirect);
        controller2.abortTransaction(stream1, txnSegments.getTxnId()).join();
    }
    // Note: if scale does not complete within desired time, test will timeout.
    while (!scaleStatus) {
        scaleStatus = controller2.checkScaleStatus(stream1, 0).join();
        Thread.sleep(30000);
    }
    // Ensure that the stream has 3 segments now.
    log.info("Checking whether scale operation succeeded by fetching current segments");
    StreamSegments streamSegments = controller2.getCurrentSegments(scope, stream).join();
    log.info("Current segment count=", streamSegments.getSegments().size());
    Assert.assertEquals(initialSegments - segmentsToSeal.size() + newRangesToCreate.size(), streamSegments.getSegments().size());
}
Also used : TxnSegments(io.pravega.client.stream.impl.TxnSegments) HashMap(java.util.HashMap) ControllerImpl(io.pravega.client.stream.impl.ControllerImpl) Controller(io.pravega.client.stream.impl.Controller) URI(java.net.URI) Transaction(io.pravega.client.stream.Transaction) StreamImpl(io.pravega.client.stream.impl.StreamImpl) ExecutionException(java.util.concurrent.ExecutionException) StreamSegments(io.pravega.client.stream.impl.StreamSegments) Test(org.junit.Test)

Aggregations

Controller (io.pravega.client.stream.impl.Controller)33 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)26 Test (org.junit.Test)25 Cleanup (lombok.Cleanup)24 ClientFactory (io.pravega.client.ClientFactory)18 StreamImpl (io.pravega.client.stream.impl.StreamImpl)18 HashMap (java.util.HashMap)16 Stream (io.pravega.client.stream.Stream)15 ConnectionFactoryImpl (io.pravega.client.netty.impl.ConnectionFactoryImpl)13 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)13 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)12 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)12 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)12 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)12 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)10 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)9 TestingServerStarter (io.pravega.test.common.TestingServerStarter)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 Executors (java.util.concurrent.Executors)9 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)9