use of org.zalando.nakadi.exceptions.NoSuchSubscriptionException in project nakadi by zalando.
the class SubscriptionControllerTest method whenGetNoneExistingSubscriptionThenNotFound.
@Test
public void whenGetNoneExistingSubscriptionThenNotFound() throws Exception {
final Subscription subscription = builder().build();
when(subscriptionRepository.getSubscription(subscription.getId())).thenThrow(new NoSuchSubscriptionException("dummy-message"));
final ThrowableProblem expectedProblem = Problem.valueOf(Response.Status.NOT_FOUND, "dummy-message");
getSubscription(subscription.getId()).andExpect(status().isNotFound()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem)));
}
use of org.zalando.nakadi.exceptions.NoSuchSubscriptionException in project nakadi by zalando.
the class SubscriptionControllerTest method whenDeleteSubscriptionThatDoesNotExistThenNotFound.
@Test
public void whenDeleteSubscriptionThatDoesNotExistThenNotFound() throws Exception {
mockGetFromRepoSubscriptionWithOwningApp("sid", "nakadiClientId");
doThrow(new NoSuchSubscriptionException("dummy message")).when(subscriptionRepository).deleteSubscription("sid");
checkForProblem(mockMvcBuilder.build().perform(delete("/subscriptions/sid")), Problem.valueOf(NOT_FOUND, "dummy message"));
}
use of org.zalando.nakadi.exceptions.NoSuchSubscriptionException 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.NoSuchSubscriptionException in project nakadi by zalando.
the class CursorsControllerTest method whenNoSubscriptionThenNotFound.
@Test
public void whenNoSubscriptionThenNotFound() throws Exception {
when(cursorsService.commitCursors(any(), eq(SUBSCRIPTION_ID), any())).thenThrow(new NoSuchSubscriptionException("dummy-message"));
final Problem expectedProblem = Problem.valueOf(NOT_FOUND, "dummy-message");
checkForProblem(postCursors(DUMMY_CURSORS), expectedProblem);
}
use of org.zalando.nakadi.exceptions.NoSuchSubscriptionException in project nakadi by zalando.
the class SubscriptionService method deleteSubscription.
public Result<Void> deleteSubscription(final String subscriptionId) throws DbWriteOperationsBlockedException {
if (featureToggleService.isFeatureEnabled(FeatureToggleService.Feature.DISABLE_DB_WRITE_OPERATIONS)) {
throw new DbWriteOperationsBlockedException("Cannot delete subscription: write operations on DB " + "are blocked by feature flag.");
}
try {
final Subscription subscription = subscriptionRepository.getSubscription(subscriptionId);
subscriptionRepository.deleteSubscription(subscriptionId);
final ZkSubscriptionClient zkSubscriptionClient = subscriptionClientFactory.createClient(subscription, "subscription." + subscriptionId + ".delete_subscription");
zkSubscriptionClient.deleteSubscription();
nakadiKpiPublisher.publish(subLogEventType, () -> new JSONObject().put("subscription_id", subscriptionId).put("status", "deleted"));
return Result.ok();
} catch (final NoSuchSubscriptionException e) {
LOG.debug("Failed to find subscription: {}", subscriptionId, e);
return Result.problem(e.asProblem());
} catch (final ServiceUnavailableException e) {
LOG.error("Error occurred when trying to delete subscription: {}", subscriptionId, e);
return Result.problem(e.asProblem());
} catch (final NoSuchEventTypeException | InternalNakadiException e) {
LOG.error("Exception can not occur", e);
return Result.problem(e.asProblem());
}
}
Aggregations