Search in sources :

Example 51 with PropertiesConfiguration

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

the class GraphApp method openGraph.

/**
 * Opens the graph instance. If the graph instance does not exist, a new
 * graph instance is initialized.
 */
public GraphTraversalSource openGraph() throws ConfigurationException {
    LOGGER.info("opening graph");
    conf = new PropertiesConfiguration(propFileName);
    graph = GraphFactory.open(conf);
    g = graph.traversal();
    return g;
}
Also used : PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 52 with PropertiesConfiguration

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

the class HBaseSnapshotInputFormatIT method getGraph.

protected Graph getGraph() throws IOException, ConfigurationException {
    final PropertiesConfiguration config = new PropertiesConfiguration("target/test-classes/hbase-read-snapshot.properties");
    Path baseOutDir = Paths.get((String) config.getProperty("gremlin.hadoop.outputLocation"));
    baseOutDir.toFile().mkdirs();
    String outDir = Files.createTempDirectory(baseOutDir, null).toAbsolutePath().toString();
    config.setProperty("gremlin.hadoop.outputLocation", outDir);
    // Set the hbase.rootdir property. This is needed by HBaseSnapshotInputFormat.
    config.setProperty("janusgraphmr.ioformat.conf.storage.hbase.ext.hbase.rootdir", HBaseStorageSetup.getHBaseRootdir());
    return GraphFactory.open(config);
}
Also used : Path(java.nio.file.Path) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 53 with PropertiesConfiguration

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

the class HBaseInputFormatIT method getGraph.

protected Graph getGraph() throws IOException, ConfigurationException {
    final PropertiesConfiguration config = new PropertiesConfiguration("target/test-classes/hbase-read.properties");
    Path baseOutDir = Paths.get((String) config.getProperty("gremlin.hadoop.outputLocation"));
    baseOutDir.toFile().mkdirs();
    String outDir = Files.createTempDirectory(baseOutDir, null).toAbsolutePath().toString();
    config.setProperty("gremlin.hadoop.outputLocation", outDir);
    return GraphFactory.open(config);
}
Also used : Path(java.nio.file.Path) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 54 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration 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 55 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration 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)

Aggregations

PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)118 File (java.io.File)38 Configuration (org.apache.commons.configuration.Configuration)33 ConfigurationException (org.apache.commons.configuration.ConfigurationException)33 IOException (java.io.IOException)12 Test (org.testng.annotations.Test)11 BeforeClass (org.testng.annotations.BeforeClass)10 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)9 IndexLoadingConfigMetadata (com.linkedin.pinot.common.metadata.segment.IndexLoadingConfigMetadata)8 FileBasedInstanceDataManager (com.linkedin.pinot.core.data.manager.offline.FileBasedInstanceDataManager)8 FileInputStream (java.io.FileInputStream)7 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)7 URL (java.net.URL)6 ServerQueryExecutorV1Impl (com.linkedin.pinot.core.query.executor.ServerQueryExecutorV1Impl)5 ServerConf (com.linkedin.pinot.server.conf.ServerConf)5 FileNotFoundException (java.io.FileNotFoundException)5 Path (java.nio.file.Path)5 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4