use of io.pravega.client.stream.impl.ClientFactoryImpl 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");
long requestId = requestIdGenerator.nextLong();
try {
restAuthHelper.authenticateAuthorize(getAuthorizationHeader(), authorizationResource.ofReaderGroupInScope(scopeName, readerGroupName), READ);
} catch (AuthException e) {
log.warn(requestId, "Get reader group for {} failed due to authentication failure.", scopeName + "/" + readerGroupName);
asyncResponse.resume(Response.status(Status.fromStatusCode(e.getResponseCode())).build());
LoggerHelpers.traceLeave(log, "getReaderGroup", traceId);
return;
}
ClientFactoryImpl clientFactory = new ClientFactoryImpl(scopeName, this.localController, this.clientConfig);
ReaderGroupManager readerGroupManager = new ReaderGroupManagerImpl(scopeName, this.localController, clientFactory);
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(requestId, "getReaderGroup for {} failed with exception: ", readerGroupName, exception);
if (exception.getCause() instanceof ReaderGroupNotFoundException) {
return Response.status(Status.NOT_FOUND).build();
} else {
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}).thenAccept(response -> {
asyncResponse.resume(response);
readerGroupManager.close();
clientFactory.close();
LoggerHelpers.traceLeave(log, "getReaderGroup", traceId);
});
}
use of io.pravega.client.stream.impl.ClientFactoryImpl in project pravega by pravega.
the class EndToEndCBRTest method testReaderGroupAutoRetention.
@Test(timeout = 60000)
public void testReaderGroupAutoRetention() throws Exception {
String scope = "test";
String streamName = "testReaderGroupAutoRetention";
String groupName = "testReaderGroupAutoRetention-group";
StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).retentionPolicy(RetentionPolicy.bySizeBytes(10, Long.MAX_VALUE)).build();
LocalController controller = (LocalController) PRAVEGA.getLocalController();
controller.createScope(scope).get();
controller.createStream(scope, streamName, config).get();
Stream stream = Stream.of(scope, streamName);
@Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
@Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory);
// write events
@Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, serializer, EventWriterConfig.builder().build());
writer.writeEvent("1", "e1").join();
writer.writeEvent("2", "e2").join();
// Create a ReaderGroup
@Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl(scope, controller, clientFactory);
groupManager.createReaderGroup(groupName, ReaderGroupConfig.builder().disableAutomaticCheckpoints().retentionType(ReaderGroupConfig.StreamDataRetention.AUTOMATIC_RELEASE_AT_LAST_CHECKPOINT).stream(stream).build());
// Create a Reader
AtomicLong clock = new AtomicLong();
@Cleanup EventStreamReader<String> reader = clientFactory.createReader("reader1", groupName, serializer, ReaderConfig.builder().build(), clock::get, clock::get);
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
EventRead<String> read = reader.readNextEvent(60000);
assertEquals("e1", read.getEvent());
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
@Cleanup("shutdown") final InlineExecutor backgroundExecutor = new InlineExecutor();
ReaderGroup readerGroup = groupManager.getReaderGroup(groupName);
CompletableFuture<Checkpoint> checkpoint = readerGroup.initiateCheckpoint("Checkpoint", backgroundExecutor);
assertFalse(checkpoint.isDone());
read = reader.readNextEvent(60000);
assertTrue(read.isCheckpoint());
assertEquals("Checkpoint", read.getCheckpointName());
assertNull(read.getEvent());
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
read = reader.readNextEvent(60000);
assertEquals("e2", read.getEvent());
Checkpoint cpResult = checkpoint.get(5, TimeUnit.SECONDS);
assertTrue(checkpoint.isDone());
assertEquals("Checkpoint", cpResult.getName());
read = reader.readNextEvent(100);
assertNull(read.getEvent());
assertFalse(read.isCheckpoint());
AssertExtensions.assertEventuallyEquals(true, () -> controller.getSegmentsAtTime(new StreamImpl(scope, streamName), 0L).join().values().stream().anyMatch(off -> off > 0), 30 * 1000L);
String group2 = groupName + "2";
groupManager.createReaderGroup(group2, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(NameUtils.getScopedStreamName(scope, streamName)).build());
EventStreamReader<String> reader2 = clientFactory.createReader("reader2", group2, serializer, ReaderConfig.builder().build());
EventRead<String> eventRead2 = reader2.readNextEvent(10000);
assertEquals("e2", eventRead2.getEvent());
}
use of io.pravega.client.stream.impl.ClientFactoryImpl in project pravega by pravega.
the class EndToEndCBRTest method testReaderGroupManualRetention.
@Test(timeout = 60000)
public void testReaderGroupManualRetention() throws Exception {
String scope = "test";
String streamName = "testReaderGroupManualRetention";
String groupName = "testReaderGroupManualRetention-group";
StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).retentionPolicy(RetentionPolicy.bySizeBytes(10, Long.MAX_VALUE)).build();
LocalController controller = (LocalController) PRAVEGA.getLocalController();
controller.createScope(scope).get();
controller.createStream(scope, streamName, config).get();
Stream stream = Stream.of(scope, streamName);
@Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
@Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory);
// write events
@Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, serializer, EventWriterConfig.builder().build());
writer.writeEvent("1", "e1").join();
writer.writeEvent("2", "e2").join();
// Create a ReaderGroup
@Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl(scope, controller, clientFactory);
groupManager.createReaderGroup(groupName, ReaderGroupConfig.builder().disableAutomaticCheckpoints().retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).stream(stream).build());
// Create a Reader
AtomicLong clock = new AtomicLong();
@Cleanup EventStreamReader<String> reader = clientFactory.createReader("reader1", groupName, serializer, ReaderConfig.builder().build(), clock::get, clock::get);
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
EventRead<String> read = reader.readNextEvent(60000);
assertEquals("e1", read.getEvent());
clock.addAndGet(CLOCK_ADVANCE_INTERVAL);
read = reader.readNextEvent(60000);
assertEquals("e2", read.getEvent());
ReaderGroup readerGroup = groupManager.getReaderGroup(groupName);
Map<Segment, Long> segmentMap = new HashMap<>();
segmentMap.put(new Segment(scope, streamName, 0), 17L);
Map<Stream, StreamCut> scResult2 = new HashMap<>();
scResult2.put(stream, new StreamCutImpl(stream, segmentMap));
readerGroup.updateRetentionStreamCut(scResult2);
AssertExtensions.assertEventuallyEquals(true, () -> controller.getSegmentsAtTime(stream, 0L).join().values().stream().anyMatch(off -> off > 0), 30 * 1000L);
String group2 = groupName + "2";
groupManager.createReaderGroup(group2, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(NameUtils.getScopedStreamName(scope, streamName)).build());
EventStreamReader<String> reader2 = clientFactory.createReader("reader2", group2, serializer, ReaderConfig.builder().build());
EventRead<String> eventRead2 = reader2.readNextEvent(10000);
assertEquals("e2", eventRead2.getEvent());
}
use of io.pravega.client.stream.impl.ClientFactoryImpl in project pravega by pravega.
the class EndToEndReaderGroupTest method testResetSubscriberToNonSubscriberReaderGroup.
@Test(timeout = 30000)
public void testResetSubscriberToNonSubscriberReaderGroup() throws InterruptedException, ExecutionException {
StreamConfiguration config = getStreamConfig();
LocalController controller = (LocalController) PRAVEGA.getLocalController();
String streamName = "testResetSubscriberToNonSubscriberReaderGroup";
controller.createScope("test").get();
controller.createStream("test", streamName, config).get();
@Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
@Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl("test", controller, connectionFactory);
@Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl("test", controller, clientFactory);
// Create a ReaderGroup
String group = "testResetSubscriberToNonSubscriberReaderGroup-group";
groupManager.createReaderGroup(group, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/" + streamName).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build());
List<String> subs = controller.listSubscribers("test", streamName).get();
assertTrue("Subscriber list does not contain required reader group", subs.contains("test/" + group));
ReaderGroup subGroup = groupManager.getReaderGroup(group);
subGroup.resetReaderGroup(ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/" + streamName).build());
subs = controller.listSubscribers("test", streamName).get();
assertFalse("Subscriber list contains required reader group", subs.contains("test/" + group));
}
use of io.pravega.client.stream.impl.ClientFactoryImpl in project pravega by pravega.
the class EndToEndReaderGroupTest method testCreateSubscriberReaderGroup.
@Test(timeout = 30000)
public void testCreateSubscriberReaderGroup() throws InterruptedException, ExecutionException {
StreamConfiguration config = getStreamConfig();
LocalController controller = (LocalController) PRAVEGA.getLocalController();
String streamName = "testCreateSubscriberReaderGroup";
controller.createScope("test").get();
controller.createStream("test", streamName, config).get();
@Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(PRAVEGA.getControllerURI()).build());
@Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl("test", controller, connectionFactory);
@Cleanup ReaderGroupManager groupManager = new ReaderGroupManagerImpl("test", controller, clientFactory);
// Create a ReaderGroup
String groupName = "testCreateSubscriberReaderGroup-group";
groupManager.createReaderGroup(groupName, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream("test/" + streamName).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build());
List<String> subs = controller.listSubscribers("test", streamName).get();
assertTrue("Subscriber list does not contain required reader group", subs.contains("test/" + groupName));
}
Aggregations