use of org.apache.commons.configuration.ConfigurationRuntimeException in project incubator-rya by apache.
the class RyaSailFactory method createMongoClient.
/**
* Create a {@link MongoClient} that is connected to the configured database.
*
* @param mongoConf - Configures what will be connected to. (not null)
* @throws ConfigurationRuntimeException An invalid port was provided by {@code mongoConf}.
* @throws MongoException Couldn't connect to the MongoDB database.
*/
private static MongoClient createMongoClient(final MongoDBRdfConfiguration mongoConf) throws ConfigurationRuntimeException, MongoException {
requireNonNull(mongoConf);
requireNonNull(mongoConf.getMongoHostname());
requireNonNull(mongoConf.getMongoPort());
requireNonNull(mongoConf.getMongoDBName());
// Connect to a running MongoDB server.
final int port;
try {
port = Integer.parseInt(mongoConf.getMongoPort());
} catch (final NumberFormatException e) {
throw new ConfigurationRuntimeException("Port '" + mongoConf.getMongoPort() + "' must be an integer.");
}
final ServerAddress server = new ServerAddress(mongoConf.getMongoHostname(), port);
// Connect to a specific MongoDB Database if that information is provided.
final String username = mongoConf.getMongoUser();
final String database = mongoConf.getMongoDBName();
final String password = mongoConf.getMongoPassword();
if (username != null && password != null) {
final MongoCredential cred = MongoCredential.createCredential(username, database, password.toCharArray());
return new MongoClient(server, Arrays.asList(cred));
} else {
return new MongoClient(server);
}
}
use of org.apache.commons.configuration.ConfigurationRuntimeException in project incubator-rya by apache.
the class GeoRyaSailFactory method createMongoClient.
/**
* Create a {@link MongoClient} that is connected to the configured database.
*
* @param mongoConf - Configures what will be connected to. (not null)
* @throws ConfigurationRuntimeException An invalid port was provided by {@code mongoConf}.
* @throws MongoException Couldn't connect to the MongoDB database.
*/
private static MongoClient createMongoClient(final MongoDBRdfConfiguration mongoConf) throws ConfigurationRuntimeException, MongoException {
requireNonNull(mongoConf);
requireNonNull(mongoConf.getMongoHostname());
requireNonNull(mongoConf.getMongoPort());
requireNonNull(mongoConf.getMongoDBName());
// Connect to a running MongoDB server.
final int port;
try {
port = Integer.parseInt(mongoConf.getMongoPort());
} catch (final NumberFormatException e) {
throw new ConfigurationRuntimeException("Port '" + mongoConf.getMongoPort() + "' must be an integer.");
}
final ServerAddress server = new ServerAddress(mongoConf.getMongoHostname(), port);
// Connect to a specific MongoDB Database if that information is provided.
final String username = mongoConf.getMongoUser();
final String database = mongoConf.getMongoDBName();
final String password = mongoConf.getMongoPassword();
if (username != null && password != null) {
final MongoCredential cred = MongoCredential.createCredential(username, database, password.toCharArray());
return new MongoClient(server, Arrays.asList(cred));
} else {
return new MongoClient(server);
}
}
use of org.apache.commons.configuration.ConfigurationRuntimeException in project pinot by linkedin.
the class AbstractTableConfig method init.
public static AbstractTableConfig init(String jsonString) throws JSONException, IOException {
JSONObject tableJson = new JSONObject(jsonString);
String tableType = tableJson.getString("tableType").toLowerCase();
String tableName = new TableNameBuilder(TableType.valueOf(tableType.toUpperCase())).forTable(tableJson.getString("tableName"));
SegmentsValidationAndRetentionConfig validationConfig = loadSegmentsConfig(new ObjectMapper().readTree(tableJson.getJSONObject("segmentsConfig").toString()));
TenantConfig tenantConfig = loadTenantsConfig(new ObjectMapper().readTree(tableJson.getJSONObject("tenants").toString()));
TableCustomConfig customConfig = loadCustomConfig(new ObjectMapper().readTree(tableJson.getJSONObject("metadata").toString()));
IndexingConfig indexingConfig = loadIndexingConfig(new ObjectMapper().readTree(tableJson.getJSONObject("tableIndexConfig").toString()));
QuotaConfig quotaConfig = null;
if (tableJson.has(QuotaConfig.QUOTA_SECTION_NAME)) {
try {
quotaConfig = loadQuotaConfig(new ObjectMapper().readTree(tableJson.getJSONObject(QuotaConfig.QUOTA_SECTION_NAME).toString()));
} catch (ConfigurationRuntimeException e) {
LOGGER.error("Invalid quota configuration value for table: {}", tableName);
throw e;
}
}
if (tableType.equals("offline")) {
return new OfflineTableConfig(tableName, tableType, validationConfig, tenantConfig, customConfig, indexingConfig, quotaConfig);
} else if (tableType.equals(TABLE_TYPE_REALTIME)) {
return new RealtimeTableConfig(tableName, tableType, validationConfig, tenantConfig, customConfig, indexingConfig, quotaConfig);
}
throw new UnsupportedOperationException("unknown tableType : " + tableType);
}
use of org.apache.commons.configuration.ConfigurationRuntimeException in project metron by apache.
the class ConfigurationManager method getConfiguration.
/**
* Common method to load content of all configuration resources defined in
* 'config-definition.xml'.
*
* @param configDefFilePath
* the config def file path
* @return Configuration
*/
public static Configuration getConfiguration(String configDefFilePath) {
if (configurationsCache.containsKey(configDefFilePath)) {
return configurationsCache.get(configDefFilePath);
}
CombinedConfiguration configuration = null;
synchronized (configurationsCache) {
if (configurationsCache.containsKey(configDefFilePath)) {
return configurationsCache.get(configDefFilePath);
}
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
String filePath = getConfigDefFilePath(configDefFilePath);
LOGGER.info("loading from 'configDefFilePath' : {}", filePath);
builder.setFile(new File(filePath));
try {
configuration = builder.getConfiguration(true);
configurationsCache.put(filePath, configuration);
} catch (ConfigurationException | ConfigurationRuntimeException e) {
LOGGER.info("Exception in loading property files.", e);
}
}
return configuration;
}
use of org.apache.commons.configuration.ConfigurationRuntimeException in project archaius by Netflix.
the class ConcurrentCompositeConfiguration method clone.
/**
* Returns a copy of this object. This implementation will create a deep
* clone, i.e. all configurations contained in this composite will also be
* cloned. This only works if all contained configurations support cloning;
* otherwise a runtime exception will be thrown. Registered event handlers
* won't get cloned.
*/
@Override
public Object clone() {
try {
ConcurrentCompositeConfiguration copy = (ConcurrentCompositeConfiguration) super.clone();
copy.clearConfigurationListeners();
copy.configList = new LinkedList<AbstractConfiguration>();
copy.containerConfiguration = (AbstractConfiguration) ConfigurationUtils.cloneConfiguration(getContainerConfiguration());
copy.configList.add(copy.containerConfiguration);
for (Configuration config : configList) {
if (config != getContainerConfiguration()) {
copy.addConfiguration((AbstractConfiguration) ConfigurationUtils.cloneConfiguration(config));
}
}
return copy;
} catch (CloneNotSupportedException cnex) {
// cannot happen
throw new ConfigurationRuntimeException(cnex);
}
}
Aggregations