use of org.apache.commons.configuration.tree.ConfigurationNode in project OA4MP by ncsa.
the class TestUtils method findConfigNode.
/**
* Loads a given configuration from a specified (on the command line) file.
* Generally you should stick all of your configurations for a test run in a single
* file then use this to pull off the ones you need, by name. If you do not specify a name
* this will try to get a configuration with the name specified at the command line.
*
* @param configName
* @return
*/
public static ConfigurationNode findConfigNode(String configName) {
try {
String fileName = System.getProperty(getBootstrapper().getOa4mpConfigFileKey());
if (fileName == null) {
throw new MyConfigurationException("Error: No configuration file specified");
}
XMLConfiguration cfg = null;
if (fileName.length() != 0) {
// A properties file is supplied. Use that.
try {
cfg = Configurations.getConfiguration(new File(fileName));
} catch (MyConfigurationException cx) {
cx.printStackTrace();
// plan B, maybe it's in the deployment itself? try to get as a resource
URL url = TestUtils.class.getResource(fileName);
if (url == null) {
throw new MyConfigurationException("Error:No configuration found. for \"" + fileName + "\"");
}
cfg = Configurations.getConfiguration(url);
}
} else {
throw new MyConfigurationException("Error:No configuration file found.");
}
ConfigurationNode cn = null;
if (configName == null) {
// try to find a specified configuration.
String cfgName = System.getProperty(getBootstrapper().getOa4mpConfigNameKey());
if (cfgName == null) {
System.out.println("no name for a configuration given");
cn = cfg.configurationAt(COMPONENT).getRootNode();
} else {
System.out.println("getting named configuration \"" + cfgName + "\"");
cn = Configurations.getConfig(cfg, COMPONENT, cfgName);
}
} else {
cn = Configurations.getConfig(cfg, COMPONENT, configName);
}
return cn;
} catch (Exception x) {
throw new MyConfigurationException("Error loading configuration", x);
}
}
use of org.apache.commons.configuration.tree.ConfigurationNode in project OA4MP by ncsa.
the class Monitor method initialize.
@Override
public void initialize() throws Exception {
super.initialize();
// Allow for over-riding the log file from the command line.
if (getLogfileName().equals(DEFAULT_LOG_FILE)) {
setMyLogger(getEnvironment().getMyLogger());
} else {
File f = new File(getLogfileName());
info("Setting up environment, log file = " + f.getAbsolutePath());
}
String cfgName = null;
if (hasOption(CONFIG_NAME_OPTION, CONFIG_NAME_LONG_OPTION)) {
cfgName = getCommandLine().getOptionValue(CONFIG_NAME_OPTION);
}
if (cfgName == null) {
info("no named for a configuration given");
} else {
info("getting named configuration \"" + cfgName + "\"");
}
try {
List list = getConfigurationNode().getChildren("mail");
if (list.size() != 0) {
mup = new MailUtilProvider((ConfigurationNode) list.get(0));
}
} catch (Throwable t) {
info("Did not initialize a mail notification environment:" + t.getMessage());
}
serviceClient = ((AbstractClientLoader) getLoader()).createServiceClient(getClientEnvironment().getAccessTokenUri());
info("Done with bootstrap.");
}
use of org.apache.commons.configuration.tree.ConfigurationNode in project OA4MP by ncsa.
the class XsedeConfigurationLoader method getClaimSource.
@Override
public ClaimSource getClaimSource() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
if (0 < cn.getChildrenCount("xsedeApi".toString())) {
ConfigurationNode node = Configurations.getFirstNode(cn, "xsedeApi".toString());
ConfigurationNode username = Configurations.getFirstNode(node, "username".toString());
ConfigurationNode password = Configurations.getFirstNode(node, "password".toString());
ConfigurationNode apikey = Configurations.getFirstNode(node, "api-key".toString());
ConfigurationNode apihash = Configurations.getFirstNode(node, "api-hash".toString());
ConfigurationNode apiurl = Configurations.getFirstNode(node, "api-url".toString());
ConfigurationNode apiresource = Configurations.getFirstNode(node, "api-resource".toString());
if (apikey != null && apihash != null && apiurl != null && apiresource != null) {
claimSource = new XsedeClaimsSource(loggerProvider.get(), apikey.getValue().toString(), apihash.getValue().toString(), apiurl.getValue().toString(), apiresource.getValue().toString());
} else if (username != null && password != null) {
claimSource = new XsedeClaimsSource(username.getValue().toString(), password.getValue().toString(), loggerProvider.get());
} else
throw new InstantiationException("Couldn't find XUP API authentication credentials");
// scopeHandler.setScopes(Arrays.asList("xsede"));
// this is a complete list of scopes from the configuration file.
claimSource.setScopes(getScopes());
return claimSource;
} else
throw new InstantiationException("Couldn't find an XUP API authentication credential");
}
Aggregations