use of org.zalando.nakadi.exceptions.InternalNakadiException in project nakadi by zalando.
the class CachingEventTypeRepositoryTest method whenRemoveCacheEntryFailsThenRollbackDbRemoval.
@Test
public void whenRemoveCacheEntryFailsThenRollbackDbRemoval() throws Exception {
Mockito.doThrow(Exception.class).when(cache).removed("event-name");
final EventType original = mock(EventType.class);
Mockito.doReturn(original).when(dbRepo).findByName("event-name");
try {
cachedRepo.removeEventType("event-name");
} catch (InternalNakadiException e) {
verify(dbRepo, times(1)).saveEventType(original);
}
}
use of org.zalando.nakadi.exceptions.InternalNakadiException in project nakadi by zalando.
the class CachingEventTypeRepositoryTest method whenUpdateCacheFailThenRollbackDbPersistence.
@Test
public void whenUpdateCacheFailThenRollbackDbPersistence() throws Exception {
Mockito.doThrow(Exception.class).when(cache).updated("event-name");
final EventType original = mock(EventType.class);
Mockito.doReturn(original).when(dbRepo).findByName("event-name");
try {
cachedRepo.update(et);
} catch (InternalNakadiException e) {
verify(dbRepo, times(1)).update(original);
}
}
use of org.zalando.nakadi.exceptions.InternalNakadiException in project nakadi by zalando.
the class TimelineService method createTimeline.
public void createTimeline(final String eventTypeName, final String storageId) throws AccessDeniedException, TimelineException, TopicRepositoryException, InconsistentStateException, RepositoryProblemException, DbWriteOperationsBlockedException {
if (featureToggleService.isFeatureEnabled(FeatureToggleService.Feature.DISABLE_DB_WRITE_OPERATIONS)) {
throw new DbWriteOperationsBlockedException("Cannot create timeline: write operations on DB " + "are blocked by feature flag.");
}
try {
final EventType eventType = eventTypeCache.getEventType(eventTypeName);
if (!adminService.isAdmin(AuthorizationService.Operation.WRITE)) {
final Resource resource = new EventTypeResource(eventTypeName, eventType.getAuthorization());
throw new AccessDeniedException(AuthorizationService.Operation.ADMIN, resource);
}
final Storage storage = storageDbRepository.getStorage(storageId).orElseThrow(() -> new UnableProcessException("No storage with id: " + storageId));
final Timeline activeTimeline = getActiveTimeline(eventType);
final TopicRepository currentTopicRepo = topicRepositoryHolder.getTopicRepository(activeTimeline.getStorage());
final TopicRepository nextTopicRepo = topicRepositoryHolder.getTopicRepository(storage);
final List<PartitionStatistics> partitionStatistics = currentTopicRepo.loadTopicStatistics(Collections.singleton(activeTimeline));
final String newTopic = nextTopicRepo.createTopic(partitionStatistics.size(), eventType.getOptions().getRetentionTime());
final Timeline nextTimeline = Timeline.createTimeline(activeTimeline.getEventType(), activeTimeline.getOrder() + 1, storage, newTopic, new Date());
switchTimelines(activeTimeline, nextTimeline);
} catch (final TopicCreationException | ServiceUnavailableException | InternalNakadiException e) {
throw new TimelineException("Internal service error", e);
} catch (final NoSuchEventTypeException e) {
throw new NotFoundException("EventType \"" + eventTypeName + "\" does not exist", e);
}
}
use of org.zalando.nakadi.exceptions.InternalNakadiException in project nakadi by zalando.
the class TimelineServiceTest method testGetTimelinesException.
@Test(expected = TimelineException.class)
public void testGetTimelinesException() throws Exception {
Mockito.when(adminService.isAdmin(any())).thenReturn(true);
Mockito.when(eventTypeCache.getEventType(any())).thenThrow(new InternalNakadiException(""));
timelineService.getTimelines("event_type");
}
use of org.zalando.nakadi.exceptions.InternalNakadiException 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