use of org.zalando.nakadi.exceptions.runtime.DuplicatedStorageException in project nakadi by zalando.
the class StorageService method createStorage.
public Result<Void> createStorage(final JSONObject json) throws DbWriteOperationsBlockedException {
if (featureToggleService.isFeatureEnabled(FeatureToggleService.Feature.DISABLE_DB_WRITE_OPERATIONS)) {
throw new DbWriteOperationsBlockedException("Cannot create storage: write operations on DB " + "are blocked by feature flag.");
}
final String type;
final String id;
final JSONObject configuration;
try {
id = json.getString("id");
type = json.getString("storage_type");
switch(type) {
case "kafka":
configuration = json.getJSONObject("kafka_configuration");
break;
default:
return Result.problem(Problem.valueOf(UNPROCESSABLE_ENTITY, "Type '" + type + "' is not a valid storage type"));
}
} catch (JSONException e) {
return Result.problem(Problem.valueOf(UNPROCESSABLE_ENTITY, e.getMessage()));
}
final Storage storage = new Storage();
storage.setId(id);
storage.setType(Storage.Type.valueOf(type.toUpperCase()));
try {
storage.parseConfiguration(objectMapper, configuration.toString());
} catch (final IOException e) {
return Result.problem(Problem.valueOf(UNPROCESSABLE_ENTITY, e.getMessage()));
}
try {
storageDbRepository.createStorage(storage);
} catch (final RepositoryProblemException e) {
LOG.error("DB error occurred when creating storage", e);
return Result.problem(Problem.valueOf(INTERNAL_SERVER_ERROR, e.getMessage()));
} catch (final DuplicatedStorageException e) {
return Result.problem(Problem.valueOf(CONFLICT, e.getMessage()));
}
return Result.ok();
}
use of org.zalando.nakadi.exceptions.runtime.DuplicatedStorageException 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.exceptions.runtime.DuplicatedStorageException 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) {
}
}
Aggregations