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