Search in sources :

Example 1 with NotFoundException

use of org.zalando.nakadi.exceptions.NotFoundException in project nakadi by zalando.

the class CursorOperationsController method getDistance.

@RequestMapping(path = "/event-types/{eventTypeName}/cursor-distances", method = RequestMethod.POST)
public ResponseEntity<?> getDistance(@PathVariable("eventTypeName") final String eventTypeName, @Valid @RequestBody final ValidListWrapper<CursorDistance> queries) throws InternalNakadiException, NoSuchEventTypeException {
    final EventType eventType = eventTypeRepository.findByName(eventTypeName);
    authorizationValidator.authorizeStreamRead(eventType);
    queries.getList().forEach(query -> {
        try {
            final NakadiCursor initialCursor = cursorConverter.convert(eventTypeName, query.getInitialCursor());
            final NakadiCursor finalCursor = cursorConverter.convert(eventTypeName, query.getFinalCursor());
            final Long distance = cursorOperationsService.calculateDistance(initialCursor, finalCursor);
            query.setDistance(distance);
        } catch (InternalNakadiException | ServiceUnavailableException e) {
            throw new MyNakadiRuntimeException1("problem calculating cursors distance", e);
        } catch (final NoSuchEventTypeException e) {
            throw new NotFoundException("event type not found", e);
        } catch (final InvalidCursorException e) {
            throw new CursorConversionException("problem converting cursors", e);
        }
    });
    return status(OK).body(queries.getList());
}
Also used : CursorConversionException(org.zalando.nakadi.exceptions.runtime.CursorConversionException) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) MyNakadiRuntimeException1(org.zalando.nakadi.exceptions.runtime.MyNakadiRuntimeException1) EventType(org.zalando.nakadi.domain.EventType) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) NotFoundException(org.zalando.nakadi.exceptions.NotFoundException) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with NotFoundException

use of org.zalando.nakadi.exceptions.NotFoundException in project nakadi by zalando.

the class PartitionsController method getTopicPartition.

private EventTypePartitionView getTopicPartition(final String eventTypeName, final String partition) throws InternalNakadiException, NoSuchEventTypeException, ServiceUnavailableException {
    final List<Timeline> timelines = timelineService.getActiveTimelinesOrdered(eventTypeName);
    final Optional<PartitionStatistics> firstStats = timelineService.getTopicRepository(timelines.get(0)).loadPartitionStatistics(timelines.get(0), partition);
    if (!firstStats.isPresent()) {
        throw new NotFoundException("partition not found");
    }
    final PartitionStatistics lastStats;
    if (timelines.size() == 1) {
        lastStats = firstStats.get();
    } else {
        lastStats = timelineService.getTopicRepository(timelines.get(timelines.size() - 1)).loadPartitionStatistics(timelines.get(timelines.size() - 1), partition).get();
    }
    return new EventTypePartitionView(eventTypeName, lastStats.getPartition(), cursorConverter.convert(firstStats.get().getFirst()).getOffset(), cursorConverter.convert(lastStats.getLast()).getOffset());
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) PartitionStatistics(org.zalando.nakadi.domain.PartitionStatistics) EventTypePartitionView(org.zalando.nakadi.view.EventTypePartitionView) NotFoundException(org.zalando.nakadi.exceptions.NotFoundException)

Example 3 with NotFoundException

use of org.zalando.nakadi.exceptions.NotFoundException 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);
    }
}
Also used : AccessDeniedException(org.zalando.nakadi.exceptions.runtime.AccessDeniedException) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) EventType(org.zalando.nakadi.domain.EventType) Resource(org.zalando.nakadi.plugin.api.authz.Resource) EventTypeResource(org.zalando.nakadi.domain.EventTypeResource) EventTypeResource(org.zalando.nakadi.domain.EventTypeResource) TopicCreationException(org.zalando.nakadi.exceptions.TopicCreationException) NotFoundException(org.zalando.nakadi.exceptions.NotFoundException) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) Date(java.util.Date) TimelineException(org.zalando.nakadi.exceptions.TimelineException) DuplicatedTimelineException(org.zalando.nakadi.exceptions.runtime.DuplicatedTimelineException) Timeline(org.zalando.nakadi.domain.Timeline) DefaultStorage(org.zalando.nakadi.domain.DefaultStorage) Storage(org.zalando.nakadi.domain.Storage) PartitionStatistics(org.zalando.nakadi.domain.PartitionStatistics) TopicRepository(org.zalando.nakadi.repository.TopicRepository) DbWriteOperationsBlockedException(org.zalando.nakadi.exceptions.runtime.DbWriteOperationsBlockedException) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException)

Example 4 with NotFoundException

use of org.zalando.nakadi.exceptions.NotFoundException in project nakadi by zalando.

the class EventTypeService method deleteEventType.

private Multimap<TopicRepository, String> deleteEventType(final String eventTypeName) throws EventTypeUnavailableException, EventTypeDeletionException {
    try {
        final Multimap<TopicRepository, String> topicsToDelete = timelineService.deleteAllTimelinesForEventType(eventTypeName);
        eventTypeRepository.removeEventType(eventTypeName);
        return topicsToDelete;
    } catch (TimelineException | NotFoundException e) {
        LOG.error("Problem deleting timeline for event type " + eventTypeName, e);
        throw new EventTypeDeletionException("Failed to delete timelines for event type " + eventTypeName);
    } catch (NakadiException e) {
        LOG.error("Error deleting event type " + eventTypeName, e);
        throw new EventTypeDeletionException("Failed to delete event type " + eventTypeName);
    }
}
Also used : NotFoundException(org.zalando.nakadi.exceptions.NotFoundException) EventTypeDeletionException(org.zalando.nakadi.exceptions.runtime.EventTypeDeletionException) TopicRepository(org.zalando.nakadi.repository.TopicRepository) TimelineException(org.zalando.nakadi.exceptions.TimelineException) NakadiException(org.zalando.nakadi.exceptions.NakadiException) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException)

Aggregations

NotFoundException (org.zalando.nakadi.exceptions.NotFoundException)4 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)3 EventType (org.zalando.nakadi.domain.EventType)2 PartitionStatistics (org.zalando.nakadi.domain.PartitionStatistics)2 Timeline (org.zalando.nakadi.domain.Timeline)2 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)2 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)2 TimelineException (org.zalando.nakadi.exceptions.TimelineException)2 TopicRepository (org.zalando.nakadi.repository.TopicRepository)2 Date (java.util.Date)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 DefaultStorage (org.zalando.nakadi.domain.DefaultStorage)1 EventTypeResource (org.zalando.nakadi.domain.EventTypeResource)1 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)1 ShiftedNakadiCursor (org.zalando.nakadi.domain.ShiftedNakadiCursor)1 Storage (org.zalando.nakadi.domain.Storage)1 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)1 NakadiException (org.zalando.nakadi.exceptions.NakadiException)1 TopicCreationException (org.zalando.nakadi.exceptions.TopicCreationException)1 UnableProcessException (org.zalando.nakadi.exceptions.UnableProcessException)1