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());
}
}
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());
}
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());
}
Aggregations