use of org.apache.commons.configuration.ConfigurationException in project sakuli by ConSol.
the class SakuliPropertyPlaceholderConfigurer method addPropertiesFromFile.
/**
* Reads in the properties for a specific file
*
* @param props Properties to update
* @param filePath path to readable properties file
* @param active activate or deactivate the function
*/
protected void addPropertiesFromFile(Properties props, String filePath, boolean active) {
if (active) {
logger.info("read in properties from '{}'", filePath);
try {
PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(filePath);
Iterator<String> keyIt = propertiesConfiguration.getKeys();
while (keyIt.hasNext()) {
String key = keyIt.next();
Object value = propertiesConfiguration.getProperty(key);
props.put(key, value);
}
} catch (ConfigurationException | NullPointerException e) {
throw new RuntimeException("Error by reading the property file '" + filePath + "'", e);
}
}
}
use of org.apache.commons.configuration.ConfigurationException in project titan by thinkaurelius.
the class GraphDatabaseConfiguration method getConfiguration.
/**
* Load a properties file containing a Titan graph configuration or create a
* stub configuration for a directory.
* <p/>
* If the argument is a file:
* <p/>
* <ol>
* <li>Load its contents into a {@link PropertiesConfiguration}</li>
* <li>For each key starting with {@link #STORAGE_NAMESPACE} and ending in
* {@link #STORAGE_DIRECTORY_KEY} or {@link #STORAGE_CONF_FILE_KEY}, check
* whether the associated value is a non-null, non-absolute path. If so,
* then prepend the absolute path of the parent directory of
* {@code dirorFile}. 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 {@code PropertiesConfiguration}</li>
* </ol>
* <p/>
* <p/>
* Otherwise (if the argument is not a file):
* <ol>
* <li>Create a new {@link BaseConfiguration}</li>
* <li>Set the key STORAGE_DIRECTORY_KEY in namespace STORAGE_NAMESPACE to
* the absolute path of the argument</li>
* <li>Return the {@code BaseConfiguration}</li>
*
* @param dirOrFile
* A properties file to load or directory in which to read and
* write data
* @return A configuration derived from {@code dirOrFile}
*/
@SuppressWarnings("unchecked")
public static final Configuration getConfiguration(File dirOrFile) {
Preconditions.checkNotNull(dirOrFile, "Need to specify a configuration file or storage directory");
Configuration configuration;
try {
if (dirOrFile.isFile()) {
configuration = new PropertiesConfiguration(dirOrFile);
final File tmpParent = dirOrFile.getParentFile();
final File configParent;
if (null == tmpParent) {
/*
* null usually means we were given a Titan 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());
final Pattern p = Pattern.compile(Pattern.quote(STORAGE_NAMESPACE) + "\\..*" + "(" + Pattern.quote(STORAGE_DIRECTORY_KEY) + "|" + Pattern.quote(STORAGE_CONF_FILE_KEY) + ")");
final Iterator<String> keysToMangle = Iterators.filter(configuration.getKeys(), new Predicate<String>() {
@Override
public boolean apply(String key) {
if (null == key)
return false;
return p.matcher(key).matches();
}
});
while (keysToMangle.hasNext()) {
String k = keysToMangle.next();
Preconditions.checkNotNull(k);
String s = configuration.getString(k);
if (null == s) {
log.warn("Configuration key {} has null value", k);
continue;
}
File storedir = new File(s);
if (!storedir.isAbsolute()) {
configuration.setProperty(k, configParent.getAbsolutePath() + File.separator + s);
log.debug("Overwrote relative path for key {}: was {}, now {}", k, s, configuration.getProperty(k));
} else {
log.debug("Loaded absolute path for key {}: {}", k, s);
}
}
} else {
configuration = new BaseConfiguration();
configuration.setProperty(keyInNamespace(STORAGE_NAMESPACE, STORAGE_DIRECTORY_KEY), dirOrFile.getAbsolutePath());
}
} catch (ConfigurationException e) {
throw new IllegalArgumentException("Could not load configuration at: " + dirOrFile, e);
}
return configuration;
}
use of org.apache.commons.configuration.ConfigurationException in project oxCore by GluuFederation.
the class FileConfiguration method loadProperties.
protected void loadProperties() {
try {
this.propertiesConfiguration = new PropertiesConfiguration(this.fileName);
this.loaded = true;
} catch (ConfigurationException ex) {
LOG.error(String.format("Failed to load '%s' configuration file from config folder", this.fileName));
} catch (Exception e) {
LOG.error(String.format("Failed to load '%s' configuration file from config folder", this.fileName));
LOG.error(e.getMessage(), e);
}
}
use of org.apache.commons.configuration.ConfigurationException in project incubator-gobblin by apache.
the class CliOptions method parseArgs.
/**
* Parse command line arguments and return a {@link java.util.Properties} object for the Gobblin job found.
* @param caller Class of the calling main method. Used for error logs.
* @param args Command line arguments.
* @param conf Hadoop configuration object
* @return Instance of {@link Properties} for the Gobblin job to run.
* @throws IOException
*/
public static Properties parseArgs(Class<?> caller, String[] args, Configuration conf) throws IOException {
try {
// Parse command-line options
if (conf != null) {
args = new GenericOptionsParser(conf, args).getCommandLine().getArgs();
}
CommandLine cmd = new DefaultParser().parse(options(), args);
if (cmd.hasOption(HELP_OPTION.getOpt())) {
printUsage(caller);
System.exit(0);
}
String jobConfigLocation = JOB_CONFIG_OPTION.getLongOpt();
if (!cmd.hasOption(jobConfigLocation)) {
printUsage(caller);
System.exit(1);
}
// Load job configuration properties
Properties jobConfig;
if (conf == null) {
jobConfig = JobConfigurationUtils.fileToProperties(cmd.getOptionValue(jobConfigLocation));
} else {
jobConfig = JobConfigurationUtils.fileToProperties(cmd.getOptionValue(jobConfigLocation), conf);
for (String configKey : jobConfig.stringPropertyNames()) {
if (conf.get(configKey) != null) {
conf.unset(configKey);
}
}
JobConfigurationUtils.putConfigurationIntoProperties(conf, jobConfig);
}
return jobConfig;
} catch (ParseException | ConfigurationException e) {
throw new IOException(e);
}
}
use of org.apache.commons.configuration.ConfigurationException in project incubator-gobblin by apache.
the class PathAlterationListenerAdaptorForMonitor method loadNewJobConfigAndHandleNewJob.
public void loadNewJobConfigAndHandleNewJob(Path path, JobScheduler.Action action) {
// Load the new job configuration and schedule the new job
String customizedInfo = "";
try {
Properties jobProps = SchedulerUtils.loadGenericJobConfig(this.jobScheduler.properties, path, jobConfigFileDirPath, this.jobSpecResolver);
LOG.debug("Loaded job properties: {}", jobProps);
switch(action) {
case SCHEDULE:
boolean runOnce = Boolean.valueOf(jobProps.getProperty(ConfigurationKeys.JOB_RUN_ONCE_KEY, "false"));
customizedInfo = "schedule";
addToJobNameMap(jobProps);
jobScheduler.scheduleJob(jobProps, runOnce ? new RunOnceJobListener() : new EmailNotificationJobListener());
break;
case RESCHEDULE:
customizedInfo = "reschedule";
rescheduleJob(jobProps);
break;
case UNSCHEDULE:
throw new RuntimeException("Should not call loadNewJobConfigAndHandleNewJob for unscheduling jobs.");
default:
break;
}
} catch (ConfigurationException | IOException e) {
LOG.error("Failed to load from job configuration file " + path.toString(), e);
} catch (JobException je) {
LOG.error("Failed to " + customizedInfo + " new job loaded from job configuration file " + path.toString(), je);
}
}
Aggregations