Search in sources :

Example 16 with Storage

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

the class StorageDbRepositoryTest method testStorageOrdered.

@Test
public void testStorageOrdered() throws Exception {
    final String namePrefix = randomValidStringOfLength(31);
    final Storage storage2 = repository.createStorage(createStorage(namePrefix + "2", "exaddress", 8181, "address1", "path3"));
    final Storage storage1 = repository.createStorage(createStorage(namePrefix + "1", "exaddress", 8181, "address2", "path2"));
    final Storage storage3 = repository.createStorage(createStorage(namePrefix + "3", "exaddress", 8181, "address3", "path1"));
    final List<Storage> storages = repository.listStorages().stream().filter(st -> st.getId() != null).filter(st -> st.getId().startsWith(namePrefix)).collect(Collectors.toList());
    assertEquals(3, storages.size());
    assertEquals(storage1, storages.get(0));
    assertEquals(storage2, storages.get(1));
    assertEquals(storage3, storages.get(2));
}
Also used : Storage(org.zalando.nakadi.domain.Storage) EventType(org.zalando.nakadi.domain.EventType) NoStorageException(org.zalando.nakadi.exceptions.runtime.NoStorageException) Date(java.util.Date) Assert.assertNotSame(org.junit.Assert.assertNotSame) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) TestUtils(org.zalando.nakadi.utils.TestUtils) Collectors(java.util.stream.Collectors) TestUtils.randomUUID(org.zalando.nakadi.utils.TestUtils.randomUUID) List(java.util.List) TestUtils.randomValidStringOfLength(org.zalando.nakadi.utils.TestUtils.randomValidStringOfLength) Timeline(org.zalando.nakadi.domain.Timeline) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) StorageIsUsedException(org.zalando.nakadi.exceptions.runtime.StorageIsUsedException) Storage(org.zalando.nakadi.domain.Storage) Test(org.junit.Test)

Example 17 with Storage

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

the class NakadiConfig method defaultStorage.

@Bean
@Qualifier("default_storage")
public DefaultStorage defaultStorage(final StorageDbRepository storageDbRepository, final Environment environment, final ZooKeeperHolder zooKeeperHolder) throws InternalNakadiException {
    final String storageId = getStorageId(zooKeeperHolder, environment);
    final Optional<Storage> storageOpt = storageDbRepository.getStorage(storageId);
    if (!storageOpt.isPresent()) {
        LOGGER.info("Creating timelines storage `{}` from defaults", storageId);
        final Storage storage = new Storage();
        storage.setId(storageId);
        storage.setType(Storage.Type.KAFKA);
        storage.setConfiguration(new Storage.KafkaConfiguration(environment.getProperty("nakadi.zookeeper.exhibitor.brokers"), Integer.valueOf(environment.getProperty("nakadi.zookeeper.exhibitor.port", "0")), environment.getProperty("nakadi.zookeeper.brokers"), environment.getProperty("nakadi.zookeeper.kafkaNamespace", "")));
        try {
            storageDbRepository.createStorage(storage);
        } catch (final DuplicatedStorageException e) {
            LOGGER.info("Creation of default storage failed: {}", e.getMessage());
        }
        return new DefaultStorage(storage);
    } else {
        return new DefaultStorage(storageOpt.get());
    }
}
Also used : DefaultStorage(org.zalando.nakadi.domain.DefaultStorage) Storage(org.zalando.nakadi.domain.Storage) DefaultStorage(org.zalando.nakadi.domain.DefaultStorage) DuplicatedStorageException(org.zalando.nakadi.exceptions.runtime.DuplicatedStorageException) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Bean(org.springframework.context.annotation.Bean)

Example 18 with Storage

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

the class StorageDbRepositoryTest method testDeleteUsedStorage.

@Test(expected = StorageIsUsedException.class)
public void testDeleteUsedStorage() throws Exception {
    final String name = randomUUID();
    final Storage storage = repository.createStorage(createStorage(name, "exaddress", 8181, "address", "path"));
    final EventType eventType = eventTypeDbRepository.saveEventType(TestUtils.buildDefaultEventType());
    final Timeline timeline = TimelineDbRepositoryTest.createTimeline(storage, UUID.randomUUID(), 0, "topic", eventType.getName(), new Date(), new Date(), null, null);
    timelineDbRepository.createTimeline(timeline);
    repository.deleteStorage(storage.getId());
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) Storage(org.zalando.nakadi.domain.Storage) EventType(org.zalando.nakadi.domain.EventType) Date(java.util.Date) Test(org.junit.Test)

Example 19 with Storage

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

the class StorageDbRepositoryTest method testStorageDeleted.

@Test
public void testStorageDeleted() throws Exception {
    final String name = randomUUID();
    final Storage storage = repository.createStorage(createStorage(name, "exaddress", 8181, "address2", "path2"));
    assertEquals(storage, repository.getStorage(storage.getId()).get());
    repository.deleteStorage(storage.getId());
    assertFalse(repository.getStorage(storage.getId()).isPresent());
}
Also used : Storage(org.zalando.nakadi.domain.Storage) Test(org.junit.Test)

Example 20 with Storage

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

the class StorageDbRepositoryTest method testStorageCreated.

@Test
public void testStorageCreated() throws Exception {
    final String name = randomUUID();
    final Storage storage = createStorage(name, "exaddress", 8181, "address", "path");
    repository.createStorage(storage);
    final Optional<Storage> createdCopy = repository.getStorage(storage.getId());
    assertTrue(createdCopy.isPresent());
    assertNotSame(createdCopy.get(), storage);
    assertEquals(storage, createdCopy.get());
}
Also used : Storage(org.zalando.nakadi.domain.Storage) 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