Search in sources :

Example 36 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project janusgraph by JanusGraph.

the class JanusGraphFactory method getLocalConfiguration.

/**
 * Load a properties file containing a JanusGraph graph configuration.
 * <p/>
 * <ol>
 * <li>Load the file contents into a {@link org.apache.commons.configuration.PropertiesConfiguration}</li>
 * <li>For each key that points to a configuration object that is either a directory
 * or local file, check
 * whether the associated value is a non-null, non-absolute path. If so,
 * then prepend the absolute path of the parent directory of the provided configuration {@code file}.
 * This has the effect of making non-absolute backend
 * paths relative to the config file's directory rather than the JVM's
 * working directory.
 * <li>Return the {@link ReadConfiguration} for the prepared configuration file</li>
 * </ol>
 * <p/>
 *
 * @param file A properties file to load
 * @return A configuration derived from {@code file}
 */
private static ReadConfiguration getLocalConfiguration(File file) {
    Preconditions.checkArgument(file != null && file.exists() && file.isFile() && file.canRead(), "Need to specify a readable configuration file, but was given: %s", file.toString());
    try {
        PropertiesConfiguration configuration = new PropertiesConfiguration(file);
        final File tmpParent = file.getParentFile();
        final File configParent;
        if (null == tmpParent) {
            /*
                 * null usually means we were given a JanusGraph config file path
                 * string like "foo.properties" that refers to the current
                 * working directory of the process.
                 */
            configParent = new File(System.getProperty("user.dir"));
        } else {
            configParent = tmpParent;
        }
        Preconditions.checkNotNull(configParent);
        Preconditions.checkArgument(configParent.isDirectory());
        // TODO this mangling logic is a relic from the hardcoded string days; it should be deleted and rewritten as a setting on ConfigOption
        final Pattern p = Pattern.compile("(" + Pattern.quote(STORAGE_NS.getName()) + "\\..*" + "(" + Pattern.quote(STORAGE_DIRECTORY.getName()) + "|" + Pattern.quote(STORAGE_CONF_FILE.getName()) + ")" + "|" + Pattern.quote(INDEX_NS.getName()) + "\\..*" + "(" + Pattern.quote(INDEX_DIRECTORY.getName()) + "|" + Pattern.quote(INDEX_CONF_FILE.getName()) + ")" + ")");
        final Iterator<String> keysToMangle = Iterators.filter(configuration.getKeys(), key -> null != key && p.matcher(key).matches());
        while (keysToMangle.hasNext()) {
            String k = keysToMangle.next();
            Preconditions.checkNotNull(k);
            final String s = configuration.getString(k);
            Preconditions.checkArgument(StringUtils.isNotBlank(s), "Invalid Configuration: key %s has null empty value", k);
            configuration.setProperty(k, getAbsolutePath(configParent, s));
        }
        return new CommonsConfiguration(configuration);
    } catch (ConfigurationException e) {
        throw new IllegalArgumentException("Could not load configuration at: " + file, e);
    }
}
Also used : Pattern(java.util.regex.Pattern) ConfigurationException(org.apache.commons.configuration.ConfigurationException) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) File(java.io.File)

Example 37 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project opennms by OpenNMS.

the class DefaultRemedyConfigDao method getProperties.

/**
 * Retrieves the properties defined in the remedy.properties file.
 *
 * @param remedyTicketerPlugin
 * @return a
 *         <code>java.util.Properties object containing remedy plugin defined properties
 */
private Configuration getProperties() {
    if (m_config != null)
        return m_config;
    String propsFile = new String(System.getProperty("opennms.home") + "/etc/remedy.properties");
    LOG.debug("loading properties from: {}", propsFile);
    Configuration config = null;
    try {
        config = new PropertiesConfiguration(propsFile);
    } catch (final ConfigurationException e) {
        LOG.debug("Unable to load properties from {}", propsFile, e);
    }
    m_config = config;
    return config;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 38 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project opennms by OpenNMS.

the class DroolsTicketerConfigDao method getProperties.

/**
 * Retrieves the properties defined in the drools-ticketer.properties file.
 */
private Configuration getProperties() {
    String propsFile = new String(System.getProperty("opennms.home") + "/etc/drools-ticketer.properties");
    LOG.debug("loading properties from: {}", propsFile);
    Configuration config = null;
    try {
        config = new PropertiesConfiguration(propsFile);
    } catch (final ConfigurationException e) {
        LOG.debug("Unable to load properties from {}", propsFile, e);
    }
    return config;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 39 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project whirr by apache.

the class ClusterSpec method fromConfiguration.

/**
   * 
   * @throws ConfigurationException if the public or private key cannot be read.
   */
public static ClusterSpec fromConfiguration(Configuration config) throws ConfigurationException {
    ClusterSpec spec = new ClusterSpec();
    spec.setServiceName(config.getString(Property.SERVICE_NAME.getConfigName()));
    spec.setInstanceTemplates(InstanceTemplate.parse(config.getStringArray(Property.INSTANCE_TEMPLATES.getConfigName())));
    spec.setProvider(config.getString(Property.PROVIDER.getConfigName()));
    spec.setIdentity(checkNotNull(config.getString(Property.IDENTITY.getConfigName()), Property.IDENTITY));
    spec.setCredential(config.getString(Property.CREDENTIAL.getConfigName()));
    spec.setClusterName(config.getString(Property.CLUSTER_NAME.getConfigName()));
    try {
        String privateKeyPath = config.getString(Property.PRIVATE_KEY_FILE.getConfigName());
        if (privateKeyPath != null)
            spec.setPrivateKey(new File(privateKeyPath));
        String publicKeyPath = config.getString(Property.PUBLIC_KEY_FILE.getConfigName());
        publicKeyPath = publicKeyPath == null && privateKeyPath != null ? privateKeyPath + ".pub" : publicKeyPath;
        if (publicKeyPath != null)
            spec.setPublicKey(new File(publicKeyPath));
    } catch (IOException e) {
        throw new ConfigurationException("error reading key from file", e);
    }
    spec.setClientCidrs(config.getList(Property.CLIENT_CIDRS.getConfigName()));
    spec.config = config;
    return spec;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) File(java.io.File)

Example 40 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project pinot by linkedin.

the class SegmentLocalFSDirectory method loadData.

private synchronized void loadData() throws IOException {
    if (columnIndexDirectory != null) {
        return;
    }
    String version = segmentMetadata.getVersion();
    SegmentVersion segmentVersion = SegmentVersion.valueOf(version);
    switch(segmentVersion) {
        case v1:
        case v2:
            columnIndexDirectory = new FilePerIndexDirectory(segmentDirectory, segmentMetadata, readMode);
            break;
        case v3:
            try {
                columnIndexDirectory = new SingleFileIndexDirectory(segmentDirectory, segmentMetadata, readMode);
            } catch (ConfigurationException e) {
                LOGGER.error("Failed to create columnar index directory", e);
                throw new RuntimeException(e);
            }
            break;
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) SegmentVersion(com.linkedin.pinot.core.indexsegment.generator.SegmentVersion)

Aggregations

ConfigurationException (org.apache.commons.configuration.ConfigurationException)66 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)31 File (java.io.File)20 IOException (java.io.IOException)19 ActionEvent (java.awt.event.ActionEvent)6 Configuration (org.apache.commons.configuration.Configuration)6 ActionListener (java.awt.event.ActionListener)5 FileInputStream (java.io.FileInputStream)5 MalformedURLException (java.net.MalformedURLException)5 ArrayList (java.util.ArrayList)5 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)5 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)4 FileNotFoundException (java.io.FileNotFoundException)3 FileWriter (java.io.FileWriter)3 HashMap (java.util.HashMap)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 CommonsConfiguration (com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration)2 BufferedWriter (java.io.BufferedWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2