use of org.zalando.nakadi.exceptions.ServiceUnavailableException in project nakadi by zalando.
the class SubscriptionValidationServiceTest method whenServiceUnavailableThenException.
@Test(expected = RepositoryProblemException.class)
public void whenServiceUnavailableThenException() throws Exception {
subscriptionBase.setInitialCursors(ImmutableList.of(new SubscriptionCursorWithoutToken(ET1, P0, ""), new SubscriptionCursorWithoutToken(ET2, P0, ""), new SubscriptionCursorWithoutToken(ET3, P0, "")));
final NakadiCursor cursor = mockCursorWithTimeline();
when(cursorConverter.convert((SubscriptionCursorWithoutToken) any())).thenReturn(cursor);
doThrow(new ServiceUnavailableException("")).when(topicRepository).validateReadCursors(any());
subscriptionValidationService.validateSubscription(subscriptionBase);
}
use of org.zalando.nakadi.exceptions.ServiceUnavailableException in project nakadi by zalando.
the class AbstractZkSubscriptionClient method runLocked.
@Override
public final <T> T runLocked(final Callable<T> function) {
try {
Exception releaseException = null;
if (null == lock) {
lock = new InterProcessSemaphoreMutex(curatorFramework, "/nakadi/locks/subscription_" + subscriptionId);
}
final boolean acquired = lock.acquire(SECONDS_TO_WAIT_FOR_LOCK, TimeUnit.SECONDS);
if (!acquired) {
throw new ServiceUnavailableException("Failed to acquire subscription lock within " + SECONDS_TO_WAIT_FOR_LOCK + " seconds");
}
final T result;
try {
result = function.call();
} finally {
try {
lock.release();
} catch (final Exception e) {
log.error("Failed to release lock", e);
releaseException = e;
}
}
if (releaseException != null) {
throw releaseException;
}
return result;
} catch (final NakadiRuntimeException | MyNakadiRuntimeException1 e) {
throw e;
} catch (final Exception e) {
throw new NakadiRuntimeException(e);
}
}
use of org.zalando.nakadi.exceptions.ServiceUnavailableException 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.ServiceUnavailableException in project nakadi by zalando.
the class SubscriptionService method listSubscriptions.
public Result listSubscriptions(@Nullable final String owningApplication, @Nullable final Set<String> eventTypes, final int limit, final int offset) {
if (limit < 1 || limit > 1000) {
final Problem problem = Problem.valueOf(Response.Status.BAD_REQUEST, "'limit' parameter should have value from 1 to 1000");
return Result.problem(problem);
}
if (offset < 0) {
final Problem problem = Problem.valueOf(Response.Status.BAD_REQUEST, "'offset' parameter can't be lower than 0");
return Result.problem(problem);
}
try {
final Set<String> eventTypesFilter = eventTypes == null ? ImmutableSet.of() : eventTypes;
final Optional<String> owningAppOption = Optional.ofNullable(owningApplication);
final List<Subscription> subscriptions = subscriptionRepository.listSubscriptions(eventTypesFilter, owningAppOption, offset, limit);
final PaginationLinks paginationLinks = SubscriptionsUriHelper.createSubscriptionPaginationLinks(owningAppOption, eventTypesFilter, offset, limit, subscriptions.size());
return Result.ok(new PaginationWrapper<>(subscriptions, paginationLinks));
} catch (final ServiceUnavailableException e) {
LOG.error("Error occurred during listing of subscriptions", e);
return Result.problem(e.asProblem());
}
}
use of org.zalando.nakadi.exceptions.ServiceUnavailableException in project nakadi by zalando.
the class SubscriptionService method getSubscriptionStat.
public ItemsWrapper<SubscriptionEventTypeStats> getSubscriptionStat(final String subscriptionId) throws InconsistentStateException, NoSuchSubscriptionException, ServiceTemporarilyUnavailableException {
final Subscription subscription;
try {
subscription = subscriptionRepository.getSubscription(subscriptionId);
} catch (final ServiceUnavailableException ex) {
throw new InconsistentStateException(ex.getMessage());
}
final List<SubscriptionEventTypeStats> subscriptionStat = createSubscriptionStat(subscription);
return new ItemsWrapper<>(subscriptionStat);
}
Aggregations