use of org.zalando.nakadi.exceptions.runtime.WrongInitialCursorsException in project nakadi by zalando.
the class SubscriptionValidationService method validateInitialCursors.
private void validateInitialCursors(final SubscriptionBase subscription, final List<EventTypePartition> allPartitions) throws WrongInitialCursorsException, RepositoryProblemException {
final boolean cursorsMissing = allPartitions.stream().anyMatch(p -> !subscription.getInitialCursors().stream().anyMatch(p::ownsCursor));
if (cursorsMissing) {
throw new WrongInitialCursorsException("initial_cursors should contain cursors for all partitions of subscription");
}
final boolean hasCursorForWrongPartition = subscription.getInitialCursors().stream().anyMatch(c -> !allPartitions.contains(new EventTypePartition(c.getEventType(), c.getPartition())));
if (hasCursorForWrongPartition) {
throw new WrongInitialCursorsException("initial_cursors should contain cursors only for partitions of this subscription");
}
if (subscription.getInitialCursors().size() > allPartitions.size()) {
throw new WrongInitialCursorsException("there should be no more than 1 cursor for each partition in initial_cursors");
}
try {
for (final SubscriptionCursorWithoutToken cursor : subscription.getInitialCursors()) {
final NakadiCursor nakadiCursor = cursorConverter.convert(cursor);
if (nakadiCursor.getTimeline().isDeleted()) {
throw new InvalidCursorException(UNAVAILABLE, nakadiCursor);
}
timelineService.getTopicRepository(nakadiCursor.getTimeline()).validateReadCursors(Collections.singletonList(nakadiCursor));
}
} catch (final InvalidCursorException ex) {
throw new WrongInitialCursorsException(ex.getMessage(), ex);
} catch (final NakadiException ex) {
throw new RepositoryProblemException("Topic repository problem occurred when validating cursors", ex);
}
}
Aggregations