use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.
the class StorageServer method startStorageServer.
public static LifecycleComponent startStorageServer(CompositeConfiguration conf, int grpcPort, int numStorageContainers, Optional<String> instanceName) throws ConfigurationException, UnknownHostException {
BookieConfiguration bkConf = BookieConfiguration.of(conf);
bkConf.validate();
DLConfiguration dlConf = DLConfiguration.of(conf);
dlConf.validate();
StorageServerConfiguration serverConf = StorageServerConfiguration.of(conf);
serverConf.validate();
StorageConfiguration storageConf = new StorageConfiguration(conf);
storageConf.validate();
// Get my local endpoint
Endpoint myEndpoint = createLocalEndpoint(grpcPort, false);
// Create shared resources
StorageResources storageResources = StorageResources.create();
// Create the stats provider
StatsProviderService statsProviderService = new StatsProviderService(bkConf);
StatsLogger rootStatsLogger = statsProviderService.getStatsProvider().getStatsLogger("");
// Create the bookie service
BookieService bookieService = new BookieService(bkConf, rootStatsLogger);
// Create the distributedlog namespace service
DLNamespaceProviderService dlNamespaceProvider = new DLNamespaceProviderService(bookieService.serverConf(), dlConf, rootStatsLogger.scope("dl"));
// Create range (stream) store
RangeStoreBuilder rangeStoreBuilder = RangeStoreBuilder.newBuilder().withStatsLogger(rootStatsLogger.scope("storage")).withStorageConfiguration(storageConf).withStorageResources(storageResources).withNumStorageContainers(numStorageContainers).withDefaultBackendUri(dlNamespaceProvider.getDlogUri()).withStorageContainerManagerFactory((ignored, storeConf, registry) -> new HelixStorageContainerManager(bookieService.serverConf().getZkServers(), "stream/helix", storeConf, registry, myEndpoint, instanceName, rootStatsLogger.scope("helix"))).withRangeStoreFactory(new MVCCStoreFactoryImpl(dlNamespaceProvider, storageConf.getRangeStoreDirs(), storageResources, storageConf.getServeReadOnlyTables()));
StorageService storageService = new StorageService(storageConf, rangeStoreBuilder, rootStatsLogger.scope("storage"));
// Create gRPC server
StatsLogger rpcStatsLogger = rootStatsLogger.scope("grpc");
GrpcServerSpec serverSpec = GrpcServerSpec.builder().storeSupplier(storageService).storeServerConf(serverConf).endpoint(myEndpoint).statsLogger(rpcStatsLogger).build();
GrpcService grpcService = new GrpcService(serverConf, serverSpec, rpcStatsLogger);
// Create all the service stack
return LifecycleComponentStack.newBuilder().withName("storage-server").addComponent(// stats provider
statsProviderService).addComponent(// bookie server
bookieService).addComponent(// service that provides dl namespace
dlNamespaceProvider).addComponent(// range (stream) store
storageService).addComponent(// range (stream) server (gRPC)
grpcService).build();
}
use of org.apache.commons.configuration.CompositeConfiguration in project gridss by PapenfussLab.
the class GridssConfiguration method LoadConfiguration.
public static Configuration LoadConfiguration(File configuration) throws ConfigurationException {
CompositeConfiguration config = new CompositeConfiguration();
if (configuration != null) {
PropertiesConfiguration configurationOverride = new PropertiesConfiguration(configuration);
config.addConfiguration(configurationOverride);
}
config.addConfiguration(getDefaultPropertiesConfiguration());
for (String key : Lists.newArrayList(config.getKeys())) {
for (String value : config.getStringArray(key)) {
log.info(String.format("%s=%s", key, value));
}
}
return config;
}
use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.
the class KeywordPanel method configToKeywords.
private void configToKeywords(FFXSystem newSystem) {
CompositeConfiguration properties = newSystem.getProperties();
Hashtable<String, Keyword> keywordHash = new Hashtable<>();
// Create the "Comments" property.
Keyword keyword = new Keyword("COMMENTS");
keywordHash.put("COMMENTS", keyword);
// Loop over properties from the keyword file.
Configuration config = properties.getConfiguration(0);
if (config instanceof PropertiesConfiguration) {
PropertiesConfiguration prop = (PropertiesConfiguration) config;
Iterator<String> keys = prop.getKeys();
while (keys.hasNext()) {
String key = keys.next();
if (keywordHash.contains(key)) {
keyword = keywordHash.get(key);
keyword.append(prop.getStringArray(key));
} else {
String[] values = prop.getStringArray(key);
keyword = new Keyword(key, values);
keywordHash.put(key, keyword);
}
}
}
newSystem.setKeywords(keywordHash);
}
use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.
the class Keyword method loadProperties.
/**
* This method sets up configuration properties in the following precedence
* * order:
*
* 1.) Structure specific properties (for example pdbname.properties)
*
* 2.) Java system properties a.) -Dkey=value from the Java command line b.)
* System.setProperty("key","value") within Java code.
*
* 3.) User specific properties (~/.ffx/ffx.properties)
*
* 4.) System wide properties (file defined by environment variable
* FFX_PROPERTIES)
*
* 5.) Internal force field definition.
*
* @since 1.0
* @param file a {@link java.io.File} object.
* @return a {@link org.apache.commons.configuration.CompositeConfiguration}
* object.
*/
public static CompositeConfiguration loadProperties(File file) {
/**
* Command line options take precedence.
*/
CompositeConfiguration properties = new CompositeConfiguration();
/**
* Structure specific options are first.
*/
if (file != null) {
String structureBasename = FilenameUtils.removeExtension(file.getAbsolutePath());
String propertyFilename = (new File(structureBasename + ".properties").exists()) ? structureBasename + ".properties" : (new File(structureBasename + ".prop").exists()) ? structureBasename + ".prop" : (new File(structureBasename + ".key").exists()) ? structureBasename + ".key" : null;
if (propertyFilename != null) {
File structurePropFile = new File(propertyFilename);
if (structurePropFile.canRead()) {
try {
properties.addConfiguration(new PropertiesConfiguration(structurePropFile));
properties.addProperty("propertyFile", structurePropFile.getCanonicalPath());
} catch (ConfigurationException | IOException e) {
logger.log(Level.INFO, " Error loading {0}.", structureBasename);
}
}
}
}
/**
* Java system properties
*
* a.) -Dkey=value from the Java command line
*
* b.) System.setProperty("key","value") within Java code.
*/
properties.addConfiguration(new SystemConfiguration());
/**
* User specific options are 3rd.
*/
String filename = System.getProperty("user.home") + File.separator + ".ffx/ffx.properties";
File userPropFile = new File(filename);
if (userPropFile.exists() && userPropFile.canRead()) {
try {
properties.addConfiguration(new PropertiesConfiguration(userPropFile));
} catch (ConfigurationException e) {
logger.log(Level.INFO, " Error loading {0}.", filename);
}
}
/**
* System wide options are 2nd to last.
*/
filename = System.getenv("FFX_PROPERTIES");
if (filename != null) {
File systemPropFile = new File(filename);
if (systemPropFile.exists() && systemPropFile.canRead()) {
try {
properties.addConfiguration(new PropertiesConfiguration(systemPropFile));
} catch (ConfigurationException e) {
logger.log(Level.INFO, " Error loading {0}.", filename);
}
}
}
/**
* Echo the interpolated configuration.
*/
if (logger.isLoggable(Level.FINE)) {
// Configuration config = properties.interpolatedConfiguration();
Iterator<String> i = properties.getKeys();
StringBuilder sb = new StringBuilder();
sb.append(String.format("\n %-30s %s\n", "Property", "Value"));
while (i.hasNext()) {
String s = i.next();
// sb.append(String.format(" %-30s %s\n", s, Arrays.toString(config.getList(s).toArray())));
sb.append(String.format(" %-30s %s\n", s, Arrays.toString(properties.getList(s).toArray())));
}
logger.fine(sb.toString());
}
return properties;
}
use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.
the class PotentialsFileOpener method run.
/**
* At present, parses the PDB, XYZ, INT, or ARC file from the constructor
* and creates MolecularAssembly and properties objects.
*/
@Override
public void run() {
int numFiles = allFiles.length;
for (int i = 0; i < numFiles; i++) {
File fileI = allFiles[i];
Path pathI = allPaths[i];
MolecularAssembly assembly = new MolecularAssembly(pathI.toString());
assembly.setFile(fileI);
CompositeConfiguration properties = Keyword.loadProperties(fileI);
ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
ForceField forceField = forceFieldFilter.parse();
String[] patches = properties.getStringArray("patch");
for (String patch : patches) {
logger.info(" Attempting to read force field patch from " + patch + ".");
CompositeConfiguration patchConfiguration = new CompositeConfiguration();
try {
patchConfiguration.addProperty("propertyFile", fileI.getCanonicalPath());
} catch (IOException e) {
logger.log(Level.INFO, " Error loading {0}.", patch);
}
patchConfiguration.addProperty("parameters", patch);
forceFieldFilter = new ForceFieldFilter(patchConfiguration);
ForceField patchForceField = forceFieldFilter.parse();
forceField.append(patchForceField);
if (RotamerLibrary.addRotPatch(patch)) {
logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
}
}
assembly.setForceField(forceField);
if (new PDBFileFilter().acceptDeep(fileI)) {
filter = new PDBFilter(fileI, assembly, forceField, properties);
} else if (new XYZFileFilter().acceptDeep(fileI)) {
filter = new XYZFilter(fileI, assembly, forceField, properties);
} else if (new INTFileFilter().acceptDeep(fileI) || new ARCFileFilter().accept(fileI)) {
filter = new INTFilter(fileI, assembly, forceField, properties);
} else {
throw new IllegalArgumentException(String.format(" File %s could not be recognized as a valid PDB, XYZ, INT, or ARC file.", pathI.toString()));
}
/* If on-open mutations requested, add them to filter. */
if (mutationsToApply != null && !mutationsToApply.isEmpty()) {
if (!(filter instanceof PDBFilter)) {
throw new UnsupportedOperationException("Applying mutations during open only supported by PDB filter atm.");
}
((PDBFilter) filter).mutate(mutationsToApply);
}
if (filter.readFile()) {
if (!(filter instanceof PDBFilter)) {
Utilities.biochemistry(assembly, filter.getAtomList());
}
filter.applyAtomProperties();
assembly.finalize(true, forceField);
// ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
ForceFieldEnergy energy;
if (nThreads > 0) {
energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints(), nThreads);
} else {
energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
}
assembly.setPotential(energy);
assemblies.add(assembly);
propertyList.add(properties);
if (filter instanceof PDBFilter) {
PDBFilter pdbFilter = (PDBFilter) filter;
List<Character> altLocs = pdbFilter.getAltLocs();
if (altLocs.size() > 1 || altLocs.get(0) != ' ') {
StringBuilder altLocString = new StringBuilder("\n Alternate locations found [ ");
for (Character c : altLocs) {
// Do not report the root conformer.
if (c == ' ') {
continue;
}
altLocString.append(format("(%s) ", c));
}
altLocString.append("]\n");
logger.info(altLocString.toString());
}
/**
* Alternate conformers may have different chemistry, so
* they each need to be their own MolecularAssembly.
*/
for (Character c : altLocs) {
if (c.equals(' ') || c.equals('A')) {
continue;
}
MolecularAssembly newAssembly = new MolecularAssembly(pathI.toString());
newAssembly.setForceField(assembly.getForceField());
pdbFilter.setAltID(newAssembly, c);
pdbFilter.clearSegIDs();
if (pdbFilter.readFile()) {
String fileName = assembly.getFile().getAbsolutePath();
newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c);
filter.applyAtomProperties();
newAssembly.finalize(true, assembly.getForceField());
// energy = ForceFieldEnergy.energyFactory(newAssembly, filter.getCoordRestraints());
if (nThreads > 0) {
energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints(), nThreads);
} else {
energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
}
newAssembly.setPotential(energy);
assemblies.add(newAssembly);
}
}
}
} else {
logger.warning(String.format(" Failed to read file %s", fileI.toString()));
}
}
activeAssembly = assemblies.get(0);
activeProperties = propertyList.get(0);
}
Aggregations