use of io.pravega.client.stream.ReaderGroup 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);
});
}
use of io.pravega.client.stream.ReaderGroup in project pravega by pravega.
the class StreamMetadataResourceImpl method listReaderGroups.
@Override
public void listReaderGroups(final String scopeName, final SecurityContext securityContext, final AsyncResponse asyncResponse) {
long traceId = LoggerHelpers.traceEnter(log, "listReaderGroups");
try {
authenticate(scopeName, READ);
} catch (AuthenticationException e) {
log.warn("Get reader groups for {} failed due to authentication failure.", scopeName);
asyncResponse.resume(Response.status(Status.UNAUTHORIZED).build());
LoggerHelpers.traceLeave(log, "listReaderGroups", traceId);
return;
}
// Each reader group is represented by a stream within the mentioned scope.
controllerService.listStreamsInScope(scopeName).thenApply(streamsList -> {
ReaderGroupsList readerGroups = new ReaderGroupsList();
streamsList.forEach(stream -> {
if (stream.getStreamName().startsWith(READER_GROUP_STREAM_PREFIX)) {
ReaderGroupsListReaderGroups readerGroup = new ReaderGroupsListReaderGroups();
readerGroup.setReaderGroupName(stream.getStreamName().substring(READER_GROUP_STREAM_PREFIX.length()));
readerGroups.addReaderGroupsItem(readerGroup);
}
});
log.info("Successfully fetched readerGroups for scope: {}", scopeName);
return Response.status(Status.OK).entity(readerGroups).build();
}).exceptionally(exception -> {
if (exception.getCause() instanceof StoreException.DataNotFoundException || exception instanceof StoreException.DataNotFoundException) {
log.warn("Scope name: {} not found", scopeName);
return Response.status(Status.NOT_FOUND).build();
} else {
log.warn("listReaderGroups for {} failed with exception: ", scopeName, exception);
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}).thenApply(asyncResponse::resume).thenAccept(x -> LoggerHelpers.traceLeave(log, "listReaderGroups", traceId));
}
use of io.pravega.client.stream.ReaderGroup in project pravega by pravega.
the class ReaderCheckpointTest method readerCheckpointTest.
@Test
public void readerCheckpointTest() {
@Cleanup ReaderGroupManager readerGroupManager = ReaderGroupManager.withScope(SCOPE, controllerURI);
ReaderGroup readerGroup = readerGroupManager.createReaderGroup(READER_GROUP_NAME, ReaderGroupConfig.builder().stream(io.pravega.client.stream.Stream.of(SCOPE, STREAM)).build());
int startInclusive = 1;
int endExclusive = 100;
log.info("Write events with range [{},{})", startInclusive, endExclusive);
writeEvents(IntStream.range(startInclusive, endExclusive).boxed().collect(Collectors.toList()));
readEventsAndVerify(startInclusive, endExclusive);
// initiate checkpoint100
Checkpoint checkPoint100 = createCheckPointAndVerify(readerGroup, "batch100");
// write and read events 100 to 200
startInclusive = 100;
endExclusive = 200;
log.info("Write events with range [{},{})", startInclusive, endExclusive);
writeEvents(IntStream.range(startInclusive, endExclusive).boxed().collect(Collectors.toList()));
readEventsAndVerify(startInclusive, endExclusive);
// reset to check point 100
readerGroup.resetReaderGroup(ReaderGroupConfig.builder().startFromCheckpoint(checkPoint100).build());
readEventsAndVerify(100, endExclusive);
// initiate checkpoint200
Checkpoint checkPoint200 = createCheckPointAndVerify(readerGroup, "batch200");
// write and read events 200 to 300
startInclusive = 200;
endExclusive = 300;
log.info("Write events with range [{},{})", startInclusive, endExclusive);
writeEvents(IntStream.range(startInclusive, endExclusive).boxed().collect(Collectors.toList()));
readEventsAndVerify(startInclusive, endExclusive);
// reset back to checkpoint 200
readerGroup.resetReaderGroup(ReaderGroupConfig.builder().startFromCheckpoint(checkPoint200).build());
readEventsAndVerify(200, endExclusive);
// reset back to checkpoint 100
readerGroup.resetReaderGroup(ReaderGroupConfig.builder().startFromCheckpoint(checkPoint100).build());
readEventsAndVerify(100, endExclusive);
// clean up
readerGroupManager.deleteReaderGroup(READER_GROUP_NAME);
}
Aggregations