Search in sources :

Example 1 with NoSuchSubscriptionException

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)));
}
Also used : NoSuchSubscriptionException(org.zalando.nakadi.exceptions.NoSuchSubscriptionException) ThrowableProblem(org.zalando.problem.ThrowableProblem) Subscription(org.zalando.nakadi.domain.Subscription) Test(org.junit.Test)

Example 2 with NoSuchSubscriptionException

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"));
}
Also used : NoSuchSubscriptionException(org.zalando.nakadi.exceptions.NoSuchSubscriptionException) Test(org.junit.Test)

Example 3 with NoSuchSubscriptionException

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);
    }
}
Also used : StartingState(org.zalando.nakadi.service.subscription.state.StartingState) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) NakadiSettings(org.zalando.nakadi.config.NakadiSettings) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Subscription(org.zalando.nakadi.domain.Subscription) NakadiException(org.zalando.nakadi.exceptions.NakadiException) SubscriptionNotInitializedException(org.zalando.nakadi.service.subscription.zk.SubscriptionNotInitializedException) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) Partition(org.zalando.nakadi.service.subscription.model.Partition) UUIDGenerator(org.zalando.nakadi.util.UUIDGenerator) ImmutableList(com.google.common.collect.ImmutableList) SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) Map(java.util.Map) TimelineService(org.zalando.nakadi.service.timeline.TimelineService) TopicRepository(org.zalando.nakadi.repository.TopicRepository) SubscriptionClientFactory(org.zalando.nakadi.service.subscription.zk.SubscriptionClientFactory) EventTypeCache(org.zalando.nakadi.repository.db.EventTypeCache) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) OperationTimeoutException(org.zalando.nakadi.exceptions.runtime.OperationTimeoutException) ZookeeperException(org.zalando.nakadi.exceptions.runtime.ZookeeperException) Collectors(java.util.stream.Collectors) TimeLogger(org.zalando.nakadi.util.TimeLogger) TimeUnit(java.util.concurrent.TimeUnit) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) Component(org.springframework.stereotype.Component) List(java.util.List) Stream(java.util.stream.Stream) ServiceTemporarilyUnavailableException(org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException) SubscriptionDbRepository(org.zalando.nakadi.repository.db.SubscriptionDbRepository) InvalidStreamIdException(org.zalando.nakadi.exceptions.InvalidStreamIdException) NoSuchSubscriptionException(org.zalando.nakadi.exceptions.NoSuchSubscriptionException) CursorError(org.zalando.nakadi.domain.CursorError) Comparator(java.util.Comparator) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) TopicRepository(org.zalando.nakadi.repository.TopicRepository) Subscription(org.zalando.nakadi.domain.Subscription) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with NoSuchSubscriptionException

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);
}
Also used : NoSuchSubscriptionException(org.zalando.nakadi.exceptions.NoSuchSubscriptionException) Problem(org.zalando.problem.Problem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 5 with NoSuchSubscriptionException

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());
    }
}
Also used : InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) JSONObject(org.json.JSONObject) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) NoSuchSubscriptionException(org.zalando.nakadi.exceptions.NoSuchSubscriptionException) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) Subscription(org.zalando.nakadi.domain.Subscription) DbWriteOperationsBlockedException(org.zalando.nakadi.exceptions.runtime.DbWriteOperationsBlockedException) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException)

Aggregations

NoSuchSubscriptionException (org.zalando.nakadi.exceptions.NoSuchSubscriptionException)5 Test (org.junit.Test)3 Subscription (org.zalando.nakadi.domain.Subscription)3 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)2 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)2 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)2 ZkSubscriptionClient (org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient)2 ImmutableList (com.google.common.collect.ImmutableList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 JSONObject (org.json.JSONObject)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1 NakadiSettings (org.zalando.nakadi.config.NakadiSettings)1 CursorError (org.zalando.nakadi.domain.CursorError)1