use of org.zalando.nakadi.exceptions.UnableProcessException in project nakadi by zalando.
the class AuthorizationValidatorTest method whenDuplicatesThenInvalidEventTypeException.
@Test
public void whenDuplicatesThenInvalidEventTypeException() throws Exception {
final ResourceAuthorization auth = new ResourceAuthorization(ImmutableList.of(attr1, attr3, attr2, attr1, attr1, attr3), ImmutableList.of(attr3, attr2, attr2), ImmutableList.of(attr3, attr4));
when(authorizationService.isAuthorizationAttributeValid(any())).thenReturn(true);
try {
validator.validateAuthorization(auth);
fail("Exception expected to be thrown");
} catch (final UnableProcessException e) {
assertThat(e.getMessage(), equalTo("authorization property 'admins' contains duplicated attribute(s): type1:value1, type3:value3; " + "authorization property 'readers' contains duplicated attribute(s): type2:value2"));
}
}
use of org.zalando.nakadi.exceptions.UnableProcessException in project nakadi by zalando.
the class AbstractZkSubscriptionClient method resetCursors.
@Override
public final void resetCursors(final List<SubscriptionCursorWithoutToken> cursors, final long timeout) throws OperationTimeoutException, ZookeeperException, OperationInterruptedException, RequestInProgressException {
ZkSubscription<List<String>> sessionsListener = null;
boolean resetWasAlreadyInitiated = false;
try {
// close subscription connections
getCurator().create().withMode(CreateMode.EPHEMERAL).forPath(resetCursorPath);
final AtomicBoolean sessionsChanged = new AtomicBoolean(true);
sessionsListener = subscribeForSessionListChanges(() -> {
sessionsChanged.set(true);
synchronized (sessionsChanged) {
sessionsChanged.notifyAll();
}
});
final long finishAt = System.currentTimeMillis() + timeout;
while (finishAt > System.currentTimeMillis()) {
if (sessionsChanged.compareAndSet(true, false)) {
if (sessionsListener.getData().isEmpty()) {
forceCommitOffsets(cursors);
return;
}
}
synchronized (sessionsChanged) {
sessionsChanged.wait(100);
}
}
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new OperationInterruptedException("Resetting cursors is interrupted", e);
} catch (final KeeperException.NodeExistsException e) {
resetWasAlreadyInitiated = true;
throw new RequestInProgressException("Cursors reset is already in progress for provided subscription", e);
} catch (final KeeperException.NoNodeException e) {
throw new UnableProcessException("Impossible to reset cursors for subscription", e);
} catch (final Exception e) {
getLog().error(e.getMessage(), e);
throw new ZookeeperException("Unexpected problem occurred when resetting cursors", e);
} finally {
if (sessionsListener != null) {
sessionsListener.close();
}
try {
if (!resetWasAlreadyInitiated) {
getCurator().delete().guaranteed().forPath(resetCursorPath);
}
} catch (final Exception e) {
getLog().error(e.getMessage(), e);
}
}
throw new OperationTimeoutException("Timeout resetting cursors");
}
use of org.zalando.nakadi.exceptions.UnableProcessException in project nakadi by zalando.
the class CursorsService method validateSubscriptionCommitCursors.
private void validateSubscriptionCommitCursors(final Subscription subscription, final List<NakadiCursor> cursors) throws UnableProcessException {
validateCursorsBelongToSubscription(subscription, cursors);
cursors.forEach(cursor -> {
try {
cursor.checkStorageAvailability();
} catch (final InvalidCursorException e) {
throw new UnableProcessException(e.getMessage(), e);
}
});
}
use of org.zalando.nakadi.exceptions.UnableProcessException in project nakadi by zalando.
the class CursorsService method resetCursors.
public void resetCursors(final String subscriptionId, final List<NakadiCursor> cursors) throws ServiceUnavailableException, NoSuchSubscriptionException, UnableProcessException, OperationTimeoutException, ZookeeperException, InternalNakadiException, NoSuchEventTypeException, InvalidCursorException {
final Subscription subscription = subscriptionRepository.getSubscription(subscriptionId);
validateCursorsBelongToSubscription(subscription, cursors);
for (final NakadiCursor cursor : cursors) {
cursor.checkStorageAvailability();
}
final Map<TopicRepository, List<NakadiCursor>> topicRepositories = cursors.stream().collect(Collectors.groupingBy(c -> timelineService.getTopicRepository(c.getTimeline())));
for (final Map.Entry<TopicRepository, List<NakadiCursor>> entry : topicRepositories.entrySet()) {
entry.getKey().validateReadCursors(entry.getValue());
}
final ZkSubscriptionClient zkClient = zkSubscriptionFactory.createClient(subscription, "subscription." + subscriptionId + ".reset_cursors");
// In case if subscription was never initialized - initialize it
zkClient.runLocked(() -> StartingState.initializeSubscriptionLocked(zkClient, subscription, timelineService, cursorConverter));
// add 1 second to commit timeout in order to give time to finish reset if there is uncommitted events
if (!cursors.isEmpty()) {
final long timeout = TimeUnit.SECONDS.toMillis(nakadiSettings.getDefaultCommitTimeoutSeconds()) + TimeUnit.SECONDS.toMillis(1);
zkClient.resetCursors(cursors.stream().map(cursorConverter::convertToNoToken).collect(Collectors.toList()), timeout);
}
}
use of org.zalando.nakadi.exceptions.UnableProcessException in project nakadi by zalando.
the class AuthorizationValidator method validateAuthorization.
public void validateAuthorization(final EventType original, final EventTypeBase newEventType) throws UnableProcessException, ServiceTemporarilyUnavailableException {
final ResourceAuthorization originalAuth = original.getAuthorization();
final ResourceAuthorization newAuth = newEventType.getAuthorization();
if (originalAuth != null && newAuth == null) {
throw new UnableProcessException("Changing authorization object to `null` is not possible due to existing one");
}
if (originalAuth != null && originalAuth.equals(newAuth)) {
return;
}
validateAuthorization(newAuth);
}
Aggregations