Search in sources :

Example 6 with UnableProcessException

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

the class EventTypeAuthorizationTest method whenPUTNullAuthorizationForExistingAuthorization.

@Test
public void whenPUTNullAuthorizationForExistingAuthorization() throws Exception {
    final EventType newEventType = EventTypeTestBuilder.builder().build();
    doReturn(newEventType).when(eventTypeRepository).findByName(any());
    doThrow(new UnableProcessException("Changing authorization object to `null` is not possible due to existing one")).when(authorizationValidator).validateAuthorization(any(), any());
    putEventType(newEventType, newEventType.getName()).andExpect(status().isUnprocessableEntity()).andExpect(content().string(matchesProblem(Problem.valueOf(MoreStatus.UNPROCESSABLE_ENTITY, "Changing authorization object to `null` is not possible due to existing one"))));
}
Also used : EventType(org.zalando.nakadi.domain.EventType) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) Test(org.junit.Test)

Example 7 with UnableProcessException

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

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

the class EventTypeControllerTest method whenPostAndAuthorizationInvalidThen422.

@Test
public void whenPostAndAuthorizationInvalidThen422() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.setAuthorization(new ResourceAuthorization(ImmutableList.of(new ResourceAuthorizationAttribute("type1", "value1")), ImmutableList.of(new ResourceAuthorizationAttribute("type2", "value2")), ImmutableList.of(new ResourceAuthorizationAttribute("type3", "value3"))));
    doThrow(new UnableProcessException("dummy")).when(authorizationValidator).validateAuthorization(any());
    postETAndExpect422WithProblem(eventType, Problem.valueOf(MoreStatus.UNPROCESSABLE_ENTITY, "dummy"));
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) ResourceAuthorizationAttribute(org.zalando.nakadi.domain.ResourceAuthorizationAttribute) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) Test(org.junit.Test)

Example 9 with UnableProcessException

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

the class AuthorizationValidatorTest method whenInvalidAuthAttributesThenInvalidEventTypeException.

@Test
public void whenInvalidAuthAttributesThenInvalidEventTypeException() throws Exception {
    final ResourceAuthorization auth = new ResourceAuthorization(ImmutableList.of(attr1), ImmutableList.of(attr2), ImmutableList.of(attr3, attr4));
    when(authorizationService.isAuthorizationAttributeValid(attr1)).thenReturn(false);
    when(authorizationService.isAuthorizationAttributeValid(attr2)).thenReturn(true);
    when(authorizationService.isAuthorizationAttributeValid(attr3)).thenReturn(true);
    when(authorizationService.isAuthorizationAttributeValid(attr4)).thenReturn(false);
    try {
        validator.validateAuthorization(auth);
        fail("Exception expected to be thrown");
    } catch (final UnableProcessException e) {
        assertThat(e.getMessage(), equalTo("authorization attribute type1:value1 is invalid, " + "authorization attribute type4:value4 is invalid"));
    }
}
Also used : ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) Test(org.junit.Test)

Aggregations

UnableProcessException (org.zalando.nakadi.exceptions.UnableProcessException)9 Test (org.junit.Test)4 ResourceAuthorization (org.zalando.nakadi.domain.ResourceAuthorization)4 EventType (org.zalando.nakadi.domain.EventType)3 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)3 List (java.util.List)2 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)2 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)2 NakadiRuntimeException (org.zalando.nakadi.exceptions.NakadiRuntimeException)2 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)2 OperationTimeoutException (org.zalando.nakadi.exceptions.runtime.OperationTimeoutException)2 ServiceTemporarilyUnavailableException (org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException)2 ZookeeperException (org.zalando.nakadi.exceptions.runtime.ZookeeperException)2 TopicRepository (org.zalando.nakadi.repository.TopicRepository)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1