Search in sources :

Example 1 with DefaultStorage

use of org.zalando.nakadi.domain.DefaultStorage 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 2 with DefaultStorage

use of org.zalando.nakadi.domain.DefaultStorage 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)

Example 3 with DefaultStorage

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

the class NakadiConfigTest method shouldCreateDefaultStorageWhenNoDefaultStorageInZk.

@Test
public void shouldCreateDefaultStorageWhenNoDefaultStorageInZk() throws Exception {
    Mockito.when(dataBuilder.forPath(StorageService.ZK_TIMELINES_DEFAULT_STORAGE)).thenReturn(null);
    Mockito.when(environment.getProperty("nakadi.timelines.storage.default")).thenReturn("default");
    Mockito.when(storageDbRepository.getStorage("default")).thenReturn(Optional.ofNullable(null));
    final DefaultStorage defaultStorage = new NakadiConfig().defaultStorage(storageDbRepository, environment, zooKeeperHolder);
    Assert.assertEquals("default", defaultStorage.getStorage().getId());
}
Also used : DefaultStorage(org.zalando.nakadi.domain.DefaultStorage) Test(org.junit.Test)

Aggregations

DefaultStorage (org.zalando.nakadi.domain.DefaultStorage)3 Test (org.junit.Test)2 Storage (org.zalando.nakadi.domain.Storage)2 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 Bean (org.springframework.context.annotation.Bean)1 DuplicatedStorageException (org.zalando.nakadi.exceptions.runtime.DuplicatedStorageException)1