use of org.apache.commons.configuration.PropertiesConfiguration in project whirr by apache.
the class ClusterSpecCommand method getClusterSpec.
protected ClusterSpec getClusterSpec(OptionSet optionSet) throws ConfigurationException {
Configuration optionsConfig = new PropertiesConfiguration();
for (Map.Entry<Property, OptionSpec> entry : optionSpecs.entrySet()) {
Property property = entry.getKey();
OptionSpec option = entry.getValue();
if (property.hasMultipleArguments()) {
optionsConfig.setProperty(property.getConfigName(), optionSet.valuesOf(option));
} else {
optionsConfig.setProperty(property.getConfigName(), optionSet.valueOf(option));
}
}
CompositeConfiguration config = new CompositeConfiguration();
config.addConfiguration(optionsConfig);
if (optionSet.has(configOption)) {
Configuration defaults = new PropertiesConfiguration(optionSet.valueOf(configOption));
config.addConfiguration(defaults);
}
for (Property required : EnumSet.of(SERVICE_NAME, CLUSTER_NAME, IDENTITY)) {
if (config.getString(required.getConfigName()) == null) {
throw new IllegalArgumentException(String.format("Option '%s' not set.", required.getSimpleName()));
}
}
return ClusterSpec.fromConfiguration(config);
}
use of org.apache.commons.configuration.PropertiesConfiguration in project archaius by Netflix.
the class OverridingPropertiesConfiguration method getConfigFromPropertiesFile.
public static AbstractConfiguration getConfigFromPropertiesFile(URL startingUrl, Set<String> loaded, String... nextLoadKeys) throws FileNotFoundException {
if (loaded.contains(startingUrl.toExternalForm())) {
logger.warn(startingUrl + " is already loaded");
return null;
}
PropertiesConfiguration propConfig = null;
try {
propConfig = new OverridingPropertiesConfiguration(startingUrl);
logger.info("Loaded properties file " + startingUrl);
} catch (ConfigurationException e) {
Throwable cause = e.getCause();
if (cause instanceof FileNotFoundException) {
throw (FileNotFoundException) cause;
} else {
throw new RuntimeException(e);
}
}
if (nextLoadKeys == null) {
return propConfig;
}
String urlString = startingUrl.toExternalForm();
String base = urlString.substring(0, urlString.lastIndexOf("/"));
loaded.add(startingUrl.toString());
loadFromPropertiesFile(propConfig, base, loaded, nextLoadKeys);
return propConfig;
}
use of org.apache.commons.configuration.PropertiesConfiguration in project OpenAttestation by OpenAttestation.
the class TAConfig method gatherConfiguration.
private Configuration gatherConfiguration(String propertiesFilename, Properties defaults) {
CompositeConfiguration composite = new CompositeConfiguration();
// first priority are properties defined on the current JVM (-D switch or through web container)
SystemConfiguration system = new SystemConfiguration();
dumpConfiguration(system, "system");
composite.addConfiguration(system);
// second priority are properties defined on the classpath (like user's home directory)
try {
// user's home directory (assuming it's on the classpath!)
readPropertiesFile("/" + propertiesFilename, composite);
} catch (IOException ex) {
log.info("Did not find " + propertiesFilename + " on classpath", ex);
}
// third priority are properties defined in standard install location
System.out.println("TAConfig os.name=" + System.getProperty("os.name"));
ArrayList<File> files = new ArrayList<File>();
// windows-specific location
if (System.getProperty("os.name", "").toLowerCase().equals("win")) {
System.out.println("TAConfig user.home=" + System.getProperty("user.home"));
files.add(new File("C:" + File.separator + "Intel" + File.separator + "CloudSecurity" + File.separator + propertiesFilename));
files.add(new File(System.getProperty("user.home") + File.separator + propertiesFilename));
}
// linux-specific location
if (System.getProperty("os.name", "").toLowerCase().equals("linux") || System.getProperty("os.name", "").toLowerCase().equals("unix")) {
files.add(new File("./config/" + propertiesFilename));
files.add(new File("/etc/oat-client/" + propertiesFilename));
}
// this line specific to TA for backwards compatibility, not needed in AS/AH
files.add(new File(System.getProperty("app.path") + File.separator + propertiesFilename));
// add all the files we found
for (File f : files) {
try {
if (f.exists() && f.canRead()) {
PropertiesConfiguration standard = new PropertiesConfiguration(f);
dumpConfiguration(standard, "file:" + f.getAbsolutePath());
composite.addConfiguration(standard);
}
} catch (ConfigurationException ex) {
log.error(null, ex);
}
}
// last priority are the defaults that were passed in, we use them if no better source was found
if (defaults != null) {
MapConfiguration defaultconfig = new MapConfiguration(defaults);
dumpConfiguration(defaultconfig, "default");
composite.addConfiguration(defaultconfig);
}
dumpConfiguration(composite, "composite");
return composite;
}
use of org.apache.commons.configuration.PropertiesConfiguration in project pinot by linkedin.
the class ResourceTestHelper method setup.
/**
* Sets up Pinot server instance, index directory for creation of segments, creates a default segment
* and starts pinot admin api service
* This should be called only once in the @BeforeClass method of a unit test.
* Caller must ensure teardown() is called when the test completes (in @AfterClass)
*/
public void setup() throws Exception {
INDEX_DIR = Files.createTempDirectory(TableSizeResourceTest.class.getName() + "_segmentDir").toFile();
File confFile = new File(TestUtils.getFileFromResourceUrl(InstanceServerStarter.class.getClassLoader().getResource("conf/pinot.properties")));
config = new PropertiesConfiguration();
config.setDelimiterParsingDisabled(false);
config.load(confFile);
serverConf = new ServerConf(config);
LOGGER.info("Trying to create a new ServerInstance!");
serverInstance = new ServerInstance();
LOGGER.info("Trying to initial ServerInstance!");
serverInstance.init(serverConf, new MetricsRegistry());
LOGGER.info("Trying to start ServerInstance!");
serverInstance.start();
apiApplication = new AdminApiApplication(serverInstance);
apiApplication.start(Integer.parseInt(CommonConstants.Server.DEFAULT_ADMIN_API_PORT));
client = ClientBuilder.newClient();
target = client.target(apiApplication.getBaseUri().toString());
setupSegment();
}
use of org.apache.commons.configuration.PropertiesConfiguration in project pinot by linkedin.
the class SingleNodeServerStarter method buildServerConfig.
/**
* Construct from config file path
* @param configFilePath Path to the config file
* @throws Exception
*/
public static void buildServerConfig(File configFilePath) throws Exception {
if (!configFilePath.exists()) {
LOGGER.error("configuration file: " + configFilePath.getAbsolutePath() + " does not exist.");
throw new ConfigurationException("configuration file: " + configFilePath.getAbsolutePath() + " does not exist.");
}
// build _serverConf
final PropertiesConfiguration serverConf = new PropertiesConfiguration();
serverConf.setDelimiterParsingDisabled(false);
serverConf.load(configFilePath);
_serverConf = new ServerConf(serverConf);
}
Aggregations