Search in sources :

Example 6 with DbWriteOperationsBlockedException

use of org.zalando.nakadi.exceptions.runtime.DbWriteOperationsBlockedException 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)

Example 7 with DbWriteOperationsBlockedException

use of org.zalando.nakadi.exceptions.runtime.DbWriteOperationsBlockedException in project nakadi by zalando.

the class SubscriptionService method createSubscription.

public Subscription createSubscription(final SubscriptionBase subscriptionBase) throws TooManyPartitionsException, RepositoryProblemException, DuplicatedSubscriptionException, NoEventTypeException, InconsistentStateException, WrongInitialCursorsException, DbWriteOperationsBlockedException {
    if (featureToggleService.isFeatureEnabled(FeatureToggleService.Feature.DISABLE_DB_WRITE_OPERATIONS)) {
        throw new DbWriteOperationsBlockedException("Cannot create subscription: write operations on DB " + "are blocked by feature flag.");
    }
    subscriptionValidationService.validateSubscription(subscriptionBase);
    final Subscription subscription = subscriptionRepository.createSubscription(subscriptionBase);
    nakadiKpiPublisher.publish(subLogEventType, () -> new JSONObject().put("subscription_id", subscription.getId()).put("status", "created"));
    return subscription;
}
Also used : JSONObject(org.json.JSONObject) Subscription(org.zalando.nakadi.domain.Subscription) DbWriteOperationsBlockedException(org.zalando.nakadi.exceptions.runtime.DbWriteOperationsBlockedException)

Aggregations

DbWriteOperationsBlockedException (org.zalando.nakadi.exceptions.runtime.DbWriteOperationsBlockedException)7 JSONObject (org.json.JSONObject)5 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)5 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)4 IOException (java.io.IOException)3 Date (java.util.Date)3 EventType (org.zalando.nakadi.domain.EventType)3 Subscription (org.zalando.nakadi.domain.Subscription)3 Timeline (org.zalando.nakadi.domain.Timeline)3 NakadiException (org.zalando.nakadi.exceptions.NakadiException)3 NotFoundException (org.zalando.nakadi.exceptions.NotFoundException)3 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)3 TimelineException (org.zalando.nakadi.exceptions.TimelineException)3 TopicCreationException (org.zalando.nakadi.exceptions.TopicCreationException)3 UnableProcessException (org.zalando.nakadi.exceptions.UnableProcessException)3 AccessDeniedException (org.zalando.nakadi.exceptions.runtime.AccessDeniedException)3 TopicRepository (org.zalando.nakadi.repository.TopicRepository)3 Closeable (java.io.Closeable)2 TimeoutException (java.util.concurrent.TimeoutException)2 JSONException (org.json.JSONException)2