Search in sources :

Example 1 with ConfigurationRuntimeException

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);
    }
}
Also used : MongoClient(com.mongodb.MongoClient) ConfigurationRuntimeException(org.apache.commons.configuration.ConfigurationRuntimeException) MongoCredential(com.mongodb.MongoCredential) ServerAddress(com.mongodb.ServerAddress)

Example 2 with ConfigurationRuntimeException

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);
    }
}
Also used : MongoClient(com.mongodb.MongoClient) ConfigurationRuntimeException(org.apache.commons.configuration.ConfigurationRuntimeException) MongoCredential(com.mongodb.MongoCredential) ServerAddress(com.mongodb.ServerAddress)

Example 3 with ConfigurationRuntimeException

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);
}
Also used : ConfigurationRuntimeException(org.apache.commons.configuration.ConfigurationRuntimeException) JSONObject(org.json.JSONObject) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 4 with ConfigurationRuntimeException

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;
}
Also used : DefaultConfigurationBuilder(org.apache.commons.configuration.DefaultConfigurationBuilder) ConfigurationRuntimeException(org.apache.commons.configuration.ConfigurationRuntimeException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) File(java.io.File)

Example 5 with ConfigurationRuntimeException

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);
    }
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) ConfigurationRuntimeException(org.apache.commons.configuration.ConfigurationRuntimeException) Configuration(org.apache.commons.configuration.Configuration) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration)

Aggregations

ConfigurationRuntimeException (org.apache.commons.configuration.ConfigurationRuntimeException)5 MongoClient (com.mongodb.MongoClient)2 MongoCredential (com.mongodb.MongoCredential)2 ServerAddress (com.mongodb.ServerAddress)2 File (java.io.File)1 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)1 CombinedConfiguration (org.apache.commons.configuration.CombinedConfiguration)1 Configuration (org.apache.commons.configuration.Configuration)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 DefaultConfigurationBuilder (org.apache.commons.configuration.DefaultConfigurationBuilder)1 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 JSONObject (org.json.JSONObject)1