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;
}
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);
}
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);
}
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);
}
}
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;
}
Aggregations