Search in sources :

Example 16 with ReaderGroupManager

use of io.pravega.client.admin.ReaderGroupManager in project pravega by pravega.

the class StreamSeekTest method testStreamSeek.

@Test(timeout = 50000)
public void testStreamSeek() throws Exception {
    createScope(SCOPE);
    createStream(STREAM1);
    createStream(STREAM2);
    @Cleanup ClientFactory clientFactory = ClientFactory.withScope(SCOPE, controllerUri);
    @Cleanup EventStreamWriter<String> writer1 = clientFactory.createEventWriter(STREAM1, serializer, EventWriterConfig.builder().build());
    @Cleanup ReaderGroupManager groupManager = ReaderGroupManager.withScope(SCOPE, controllerUri);
    ReaderGroup readerGroup = groupManager.createReaderGroup("group", ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(Stream.of(SCOPE, STREAM1)).stream(Stream.of(SCOPE, STREAM2)).build());
    // Prep the stream with data.
    // 1.Write two events with event size of 30
    writer1.writeEvent(keyGenerator.get(), getEventData.apply(1)).get();
    writer1.writeEvent(keyGenerator.get(), getEventData.apply(2)).get();
    // 2.Scale stream
    Map<Double, Double> newKeyRanges = new HashMap<>();
    newKeyRanges.put(0.0, 0.33);
    newKeyRanges.put(0.33, 0.66);
    newKeyRanges.put(0.66, 1.0);
    scaleStream(STREAM1, newKeyRanges);
    // 3.Write three events with event size of 30
    writer1.writeEvent(keyGenerator.get(), getEventData.apply(3)).get();
    writer1.writeEvent(keyGenerator.get(), getEventData.apply(4)).get();
    writer1.writeEvent(keyGenerator.get(), getEventData.apply(5)).get();
    // Create a reader
    @Cleanup EventStreamReader<String> reader = clientFactory.createReader("readerId", "group", serializer, ReaderConfig.builder().build());
    // Offset of a streamCut is always set to zero.
    // Stream cut 1
    Map<Stream, StreamCut> streamCut1 = readerGroup.getStreamCuts();
    readAndVerify(reader, 1, 2);
    readAndVerify(reader, 3, 4, 5);
    // Stream cut 2
    Map<Stream, StreamCut> streamCut2 = readerGroup.getStreamCuts();
    // reset the readers to offset 0.
    readerGroup.resetReaderGroup(ReaderGroupConfig.builder().startFromStreamCuts(streamCut1).build());
    verifyReinitializationRequiredException(reader);
    @Cleanup EventStreamReader<String> reader1 = clientFactory.createReader("readerId", "group", serializer, ReaderConfig.builder().build());
    // verify that we are at streamCut1
    readAndVerify(reader1, 1, 2);
    // reset readers to post scale offset 0
    readerGroup.resetReaderGroup(ReaderGroupConfig.builder().startFromStreamCuts(streamCut2).build());
    verifyReinitializationRequiredException(reader1);
    @Cleanup EventStreamReader<String> reader2 = clientFactory.createReader("readerId", "group", serializer, ReaderConfig.builder().build());
    // verify that we are at streamCut2
    readAndVerify(reader2, 3, 4, 5);
}
Also used : ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) StreamCut(io.pravega.client.stream.StreamCut) HashMap(java.util.HashMap) ReaderGroup(io.pravega.client.stream.ReaderGroup) ClientFactory(io.pravega.client.ClientFactory) Cleanup(lombok.Cleanup) Stream(io.pravega.client.stream.Stream) Test(org.junit.Test)

Example 17 with ReaderGroupManager

use of io.pravega.client.admin.ReaderGroupManager in project pravega by pravega.

the class EndToEndTruncationTest method testTruncation.

@Test(timeout = 30000)
public void testTruncation() throws Exception {
    StreamConfiguration config = StreamConfiguration.builder().scope("test").streamName("test").scalingPolicy(ScalingPolicy.byEventRate(10, 2, 2)).build();
    LocalController controller = (LocalController) 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", "truncationTest1").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, Lists.newArrayList(0, 1), map, executor).getFuture().get();
    assertTrue(result);
    writer.writeEvent("0", "truncationTest2").get();
    Map<Integer, Long> streamCutPositions = new HashMap<>();
    streamCutPositions.put(2, 0L);
    streamCutPositions.put(3, 0L);
    streamCutPositions.put(4, 0L);
    controller.truncateStream(stream.getStreamName(), stream.getStreamName(), streamCutPositions).join();
    @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("truncationTest2", event.getEvent());
    event = reader.readNextEvent(1000);
    assertNull(event.getEvent());
// TODO: test more scenarios like: issue #2011
// 1. get a valid stream cut with offset > 0
// validate truncation within a segment
// 2. have an existing reader reading from non truncated segment and then truncate the segment.
// verify that reader gets appropriate response and handles it successfully.
}
Also used : ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) HashMap(java.util.HashMap) ClientFactory(io.pravega.client.ClientFactory) Cleanup(lombok.Cleanup) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) LocalController(io.pravega.controller.server.eventProcessor.LocalController) 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 18 with ReaderGroupManager

use of io.pravega.client.admin.ReaderGroupManager 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 19 with ReaderGroupManager

use of io.pravega.client.admin.ReaderGroupManager in project pravega by pravega.

the class StreamTransactionMetadataTasksTest method createEventProcessor.

private <T extends ControllerEvent> void createEventProcessor(final String readerGroupName, final String streamName, final EventStreamReader<T> reader, final EventStreamWriter<T> writer, Supplier<EventProcessor<T>> factory) throws CheckpointStoreException {
    ClientFactory clientFactory = Mockito.mock(ClientFactory.class);
    Mockito.when(clientFactory.<T>createReader(anyString(), anyString(), any(), any())).thenReturn(reader);
    Mockito.when(clientFactory.<T>createEventWriter(anyString(), any(), any())).thenReturn(writer);
    ReaderGroup readerGroup = Mockito.mock(ReaderGroup.class);
    Mockito.when(readerGroup.getGroupName()).thenReturn(readerGroupName);
    ReaderGroupManager readerGroupManager = Mockito.mock(ReaderGroupManager.class);
    Mockito.when(readerGroupManager.createReaderGroup(anyString(), any(ReaderGroupConfig.class))).then(invocation -> readerGroup);
    EventProcessorSystemImpl system = new EventProcessorSystemImpl("system", "host", SCOPE, clientFactory, readerGroupManager);
    EventProcessorGroupConfig eventProcessorConfig = EventProcessorGroupConfigImpl.builder().eventProcessorCount(1).readerGroupName(readerGroupName).streamName(streamName).checkpointConfig(CheckpointConfig.periodic(1, 1)).build();
    EventProcessorConfig<T> config = EventProcessorConfig.<T>builder().config(eventProcessorConfig).decider(ExceptionHandler.DEFAULT_EXCEPTION_HANDLER).serializer(new JavaSerializer<>()).supplier(factory).build();
    system.createEventProcessorGroup(config, CheckpointStoreFactory.createInMemoryStore());
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) ReaderGroup(io.pravega.client.stream.ReaderGroup) ClientFactory(io.pravega.client.ClientFactory) EventProcessorSystemImpl(io.pravega.controller.eventProcessor.impl.EventProcessorSystemImpl)

Example 20 with ReaderGroupManager

use of io.pravega.client.admin.ReaderGroupManager in project pravega by pravega.

the class StreamMetadataResourceImpl method getReaderGroup.

@Override
public void getReaderGroup(final String scopeName, final String readerGroupName, final SecurityContext securityContext, final AsyncResponse asyncResponse) {
    long traceId = LoggerHelpers.traceEnter(log, "getReaderGroup");
    try {
        authenticate(scopeName + "/" + readerGroupName, READ);
    } catch (AuthenticationException e) {
        log.warn("Get reader group for {} failed due to authentication failure.", scopeName + "/" + readerGroupName);
        asyncResponse.resume(Response.status(Status.UNAUTHORIZED).build());
        LoggerHelpers.traceLeave(log, "getReaderGroup", traceId);
        return;
    }
    ReaderGroupManager readerGroupManager = new ReaderGroupManagerImpl(scopeName, this.localController, new ClientFactoryImpl(scopeName, this.localController), this.connectionFactory);
    ReaderGroupProperty readerGroupProperty = new ReaderGroupProperty();
    readerGroupProperty.setScopeName(scopeName);
    readerGroupProperty.setReaderGroupName(readerGroupName);
    CompletableFuture.supplyAsync(() -> {
        ReaderGroup readerGroup = readerGroupManager.getReaderGroup(readerGroupName);
        readerGroupProperty.setOnlineReaderIds(new ArrayList<>(readerGroup.getOnlineReaders()));
        readerGroupProperty.setStreamList(new ArrayList<>(readerGroup.getStreamNames()));
        return Response.status(Status.OK).entity(readerGroupProperty).build();
    }, controllerService.getExecutor()).exceptionally(exception -> {
        log.warn("getReaderGroup for {} failed with exception: ", readerGroupName, exception);
        if (exception.getCause() instanceof InvalidStreamException) {
            return Response.status(Status.NOT_FOUND).build();
        } else {
            return Response.status(Status.INTERNAL_SERVER_ERROR).build();
        }
    }).thenAccept(response -> {
        asyncResponse.resume(response);
        readerGroupManager.close();
        LoggerHelpers.traceLeave(log, "getReaderGroup", traceId);
    });
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) Arrays(java.util.Arrays) ApiV1(io.pravega.controller.server.rest.v1.ApiV1) READ(io.pravega.auth.AuthHandler.Permissions.READ) StreamsList(io.pravega.controller.server.rest.generated.model.StreamsList) AuthHandler(io.pravega.auth.AuthHandler) SecurityContext(javax.ws.rs.core.SecurityContext) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) ReaderGroup(io.pravega.client.stream.ReaderGroup) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) LocalController(io.pravega.controller.server.eventProcessor.LocalController) StoreException(io.pravega.controller.store.stream.StoreException) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) Map(java.util.Map) ReaderGroupProperty(io.pravega.controller.server.rest.generated.model.ReaderGroupProperty) INTERNAL_NAME_PREFIX(io.pravega.shared.NameUtils.INTERNAL_NAME_PREFIX) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) CreateScopeRequest(io.pravega.controller.server.rest.generated.model.CreateScopeRequest) Collectors(java.util.stream.Collectors) CreateStreamRequest(io.pravega.controller.server.rest.generated.model.CreateStreamRequest) READER_GROUP_STREAM_PREFIX(io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) HttpHeaders(javax.ws.rs.core.HttpHeaders) StreamState(io.pravega.controller.server.rest.generated.model.StreamState) Response(javax.ws.rs.core.Response) ScopesList(io.pravega.controller.server.rest.generated.model.ScopesList) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) CompletableFuture(java.util.concurrent.CompletableFuture) UpdateStreamRequest(io.pravega.controller.server.rest.generated.model.UpdateStreamRequest) ArrayList(java.util.ArrayList) READ_UPDATE(io.pravega.auth.AuthHandler.Permissions.READ_UPDATE) ScaleMetadata(io.pravega.controller.store.stream.ScaleMetadata) DeleteStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteStreamStatus) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) Status(javax.ws.rs.core.Response.Status) LoggerHelpers(io.pravega.common.LoggerHelpers) ControllerService(io.pravega.controller.server.ControllerService) NameUtils(io.pravega.shared.NameUtils) Iterator(java.util.Iterator) ScopeProperty(io.pravega.controller.server.rest.generated.model.ScopeProperty) ModelHelper(io.pravega.controller.server.rest.ModelHelper) ReaderGroupsList(io.pravega.controller.server.rest.generated.model.ReaderGroupsList) PravegaAuthManager(io.pravega.controller.server.rpc.auth.PravegaAuthManager) ReaderGroupsListReaderGroups(io.pravega.controller.server.rest.generated.model.ReaderGroupsListReaderGroups) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ReaderGroupProperty(io.pravega.controller.server.rest.generated.model.ReaderGroupProperty) AuthenticationException(io.pravega.common.auth.AuthenticationException) ReaderGroup(io.pravega.client.stream.ReaderGroup) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) InvalidStreamException(io.pravega.client.stream.InvalidStreamException)

Aggregations

ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)25 ClientFactory (io.pravega.client.ClientFactory)21 Cleanup (lombok.Cleanup)19 Test (org.junit.Test)18 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)16 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)14 Stream (io.pravega.client.stream.Stream)12 Controller (io.pravega.client.stream.impl.Controller)12 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)11 ConnectionFactoryImpl (io.pravega.client.netty.impl.ConnectionFactoryImpl)11 HashMap (java.util.HashMap)11 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)10 ReaderGroup (io.pravega.client.stream.ReaderGroup)10 StreamImpl (io.pravega.client.stream.impl.StreamImpl)9 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)8 URI (java.net.URI)7 StreamManager (io.pravega.client.admin.StreamManager)5 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 ClientConfig (io.pravega.client.ClientConfig)3