Search in sources :

Example 21 with Storage

use of org.zalando.nakadi.domain.Storage in project nakadi by zalando.

the class BaseAT method createDefaultStorage.

@BeforeClass
public static void createDefaultStorage() {
    final Storage storage = new Storage();
    storage.setId("default");
    storage.setType(Storage.Type.KAFKA);
    storage.setConfiguration(new Storage.KafkaConfiguration(null, null, ZOOKEEPER_URL, ""));
    try {
        STORAGE_DB_REPOSITORY.createStorage(storage);
    } catch (final DuplicatedStorageException ignore) {
    }
}
Also used : Storage(org.zalando.nakadi.domain.Storage) DuplicatedStorageException(org.zalando.nakadi.exceptions.runtime.DuplicatedStorageException) BeforeClass(org.junit.BeforeClass)

Example 22 with Storage

use of org.zalando.nakadi.domain.Storage in project nakadi by zalando.

the class KafkaRepositoryCreator method createTopicRepository.

@Override
public TopicRepository createTopicRepository(final Storage storage) throws TopicRepositoryException {
    try {
        final Storage.KafkaConfiguration kafkaConfiguration = storage.getKafkaConfiguration();
        final ZooKeeperHolder zooKeeperHolder = new ZooKeeperHolder(kafkaConfiguration.getZkAddress(), kafkaConfiguration.getZkPath(), kafkaConfiguration.getExhibitorAddress(), kafkaConfiguration.getExhibitorPort());
        final KafkaFactory kafkaFactory = new KafkaFactory(new KafkaLocationManager(zooKeeperHolder, kafkaSettings), metricRegistry);
        final KafkaTopicRepository kafkaTopicRepository = new KafkaTopicRepository(zooKeeperHolder, kafkaFactory, nakadiSettings, kafkaSettings, zookeeperSettings, uuidGenerator);
        // check that it does work
        kafkaTopicRepository.listTopics();
        return kafkaTopicRepository;
    } catch (final Exception e) {
        throw new TopicRepositoryException("Could not create topic repository", e);
    }
}
Also used : KafkaFactory(org.zalando.nakadi.repository.kafka.KafkaFactory) Storage(org.zalando.nakadi.domain.Storage) KafkaTopicRepository(org.zalando.nakadi.repository.kafka.KafkaTopicRepository) KafkaLocationManager(org.zalando.nakadi.repository.kafka.KafkaLocationManager) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) TopicRepositoryException(org.zalando.nakadi.exceptions.runtime.TopicRepositoryException) TopicRepositoryException(org.zalando.nakadi.exceptions.runtime.TopicRepositoryException)

Example 23 with Storage

use of org.zalando.nakadi.domain.Storage in project nakadi by zalando.

the class PartitionsControllerTest method mockCursorLag.

private List<NakadiCursorLag> mockCursorLag() {
    final Timeline timeline = mock(Timeline.class);
    when(timeline.getStorage()).thenReturn(new Storage("ccc", Storage.Type.KAFKA));
    final NakadiCursorLag lag = mock(NakadiCursorLag.class);
    final NakadiCursor firstCursor = NakadiCursor.of(timeline, "0", "0");
    final NakadiCursor lastCursor = NakadiCursor.of(timeline, "0", "1");
    when(lag.getLag()).thenReturn(42L);
    when(lag.getPartition()).thenReturn("0");
    when(lag.getFirstCursor()).thenReturn(firstCursor);
    when(lag.getLastCursor()).thenReturn(lastCursor);
    return Lists.newArrayList(lag);
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) TestUtils.buildTimeline(org.zalando.nakadi.utils.TestUtils.buildTimeline) Storage(org.zalando.nakadi.domain.Storage) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) NakadiCursorLag(org.zalando.nakadi.domain.NakadiCursorLag)

Example 24 with Storage

use of org.zalando.nakadi.domain.Storage in project nakadi by zalando.

the class TimelinesControllerTest method whenGetTimelinesThenOk.

@Test
public void whenGetTimelinesThenOk() throws Exception {
    final Storage kafkaStorage = StoragesControllerTest.createKafkaStorage("deafult");
    final ImmutableList<Timeline> timelines = ImmutableList.of(Timeline.createTimeline("event_type", 0, kafkaStorage, "topic", new Date()), Timeline.createTimeline("event_type_1", 1, kafkaStorage, "topic_1", new Date()));
    Mockito.when(timelineService.getTimelines(Mockito.any())).thenReturn(timelines);
    final List<TimelineView> timelineViews = timelines.stream().map(TimelineView::new).collect(Collectors.toList());
    mockMvc.perform(MockMvcRequestBuilders.get("/event-types/event_type/timelines").contentType(MediaType.APPLICATION_JSON).principal(PrincipalMockFactory.mockPrincipal("nakadi"))).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().json(TestUtils.OBJECT_MAPPER.writeValueAsString(timelineViews)));
}
Also used : TimelineView(org.zalando.nakadi.view.TimelineView) Timeline(org.zalando.nakadi.domain.Timeline) Storage(org.zalando.nakadi.domain.Storage) Date(java.util.Date) Test(org.junit.Test)

Example 25 with Storage

use of org.zalando.nakadi.domain.Storage in project nakadi by zalando.

the class NakadiConfigTest method shouldTakeStorageById.

@Test
public void shouldTakeStorageById() throws Exception {
    Mockito.when(dataBuilder.forPath(StorageService.ZK_TIMELINES_DEFAULT_STORAGE)).thenReturn("new-storage".getBytes());
    final Storage storage = new Storage();
    storage.setId("new-storage");
    Mockito.when(storageDbRepository.getStorage("new-storage")).thenReturn(Optional.of(storage));
    final DefaultStorage defaultStorage = new NakadiConfig().defaultStorage(storageDbRepository, environment, zooKeeperHolder);
    Assert.assertEquals("new-storage", defaultStorage.getStorage().getId());
}
Also used : DefaultStorage(org.zalando.nakadi.domain.DefaultStorage) Storage(org.zalando.nakadi.domain.Storage) DefaultStorage(org.zalando.nakadi.domain.DefaultStorage) Test(org.junit.Test)

Aggregations

Storage (org.zalando.nakadi.domain.Storage)31 Test (org.junit.Test)16 Timeline (org.zalando.nakadi.domain.Timeline)14 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)10 PartitionStatistics (org.zalando.nakadi.domain.PartitionStatistics)7 TopicRepository (org.zalando.nakadi.repository.TopicRepository)7 Date (java.util.Date)6 DefaultStorage (org.zalando.nakadi.domain.DefaultStorage)6 List (java.util.List)4 EventType (org.zalando.nakadi.domain.EventType)4 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 DuplicatedStorageException (org.zalando.nakadi.exceptions.runtime.DuplicatedStorageException)3 TimelineService (org.zalando.nakadi.service.timeline.TimelineService)3 Cursor (org.zalando.nakadi.view.Cursor)3 SubscriptionCursorWithoutToken (org.zalando.nakadi.view.SubscriptionCursorWithoutToken)3 Collections (java.util.Collections)2 Optional (java.util.Optional)2 Logger (org.slf4j.Logger)2