Search in sources :

Example 11 with NoSuchEventTypeException

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

the class PartitionsController method getPartition.

@RequestMapping(value = "/event-types/{name}/partitions/{partition}", method = RequestMethod.GET)
public ResponseEntity<?> getPartition(@PathVariable("name") final String eventTypeName, @PathVariable("partition") final String partition, @Nullable @RequestParam(value = "consumed_offset", required = false) final String consumedOffset, final NativeWebRequest request) {
    LOG.trace("Get partition endpoint for event-type '{}', partition '{}' is called", eventTypeName, partition);
    try {
        final EventType eventType = eventTypeRepository.findByName(eventTypeName);
        authorizationValidator.authorizeStreamRead(eventType);
        if (consumedOffset != null) {
            final CursorLag cursorLag = getCursorLag(eventTypeName, partition, consumedOffset);
            return ok().body(cursorLag);
        } else {
            final EventTypePartitionView result = getTopicPartition(eventTypeName, partition);
            return ok().body(result);
        }
    } catch (final NoSuchEventTypeException e) {
        return create(Problem.valueOf(NOT_FOUND, "topic not found"), request);
    } catch (final NakadiException e) {
        LOG.error("Could not get partition. Respond with SERVICE_UNAVAILABLE.", e);
        return create(e.asProblem(), request);
    } catch (final InvalidCursorException e) {
        return create(Problem.valueOf(MoreStatus.UNPROCESSABLE_ENTITY, INVALID_CURSOR_MESSAGE), request);
    }
}
Also used : EventType(org.zalando.nakadi.domain.EventType) EventTypePartitionView(org.zalando.nakadi.view.EventTypePartitionView) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) NakadiCursorLag(org.zalando.nakadi.domain.NakadiCursorLag) CursorLag(org.zalando.nakadi.view.CursorLag) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) NakadiException(org.zalando.nakadi.exceptions.NakadiException) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with NoSuchEventTypeException

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

the class CursorsControllerTest method whenNoEventTypeThenUnprocessableEntity.

@Test
public void whenNoEventTypeThenUnprocessableEntity() throws Exception {
    when(cursorsService.commitCursors(any(), any(), any())).thenThrow(new NoSuchEventTypeException("dummy-message"));
    final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "dummy-message");
    checkForProblem(postCursors(DUMMY_CURSORS), expectedProblem);
}
Also used : Problem(org.zalando.problem.Problem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) Test(org.junit.Test)

Example 13 with NoSuchEventTypeException

use of org.zalando.nakadi.exceptions.NoSuchEventTypeException 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 14 with NoSuchEventTypeException

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

the class TimelineServiceTest method testGetTimelinesNotFound.

@Test(expected = NotFoundException.class)
public void testGetTimelinesNotFound() throws Exception {
    Mockito.when(adminService.isAdmin(any())).thenReturn(true);
    Mockito.when(eventTypeCache.getEventType(any())).thenThrow(new NoSuchEventTypeException(""));
    timelineService.getTimelines("event_type");
}
Also used : NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) Test(org.junit.Test)

Example 15 with NoSuchEventTypeException

use of org.zalando.nakadi.exceptions.NoSuchEventTypeException 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

NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)18 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)14 EventType (org.zalando.nakadi.domain.EventType)10 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)9 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)7 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)6 NakadiException (org.zalando.nakadi.exceptions.NakadiException)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 PartitionStatistics (org.zalando.nakadi.domain.PartitionStatistics)5 Timeline (org.zalando.nakadi.domain.Timeline)5 TopicRepository (org.zalando.nakadi.repository.TopicRepository)5 TimelineService (org.zalando.nakadi.service.timeline.TimelineService)5 Map (java.util.Map)4 Optional (java.util.Optional)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 CursorError (org.zalando.nakadi.domain.CursorError)4 ServiceTemporarilyUnavailableException (org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException)4 CursorConverter (org.zalando.nakadi.service.CursorConverter)4