Search in sources :

Example 6 with CompositeConfiguration

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();
}
Also used : ComponentStarter(org.apache.bookkeeper.common.component.ComponentStarter) Configuration(org.apache.commons.configuration.Configuration) DLNamespaceProviderService(org.apache.bookkeeper.stream.server.service.DLNamespaceProviderService) Parameter(com.beust.jcommander.Parameter) CompletableFuture(java.util.concurrent.CompletableFuture) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) InetAddress(java.net.InetAddress) GrpcServerSpec(org.apache.bookkeeper.stream.server.grpc.GrpcServerSpec) LifecycleComponentStack(org.apache.bookkeeper.common.component.LifecycleComponentStack) StorageServerConfiguration(org.apache.bookkeeper.stream.server.conf.StorageServerConfiguration) RangeStoreBuilder(org.apache.bookkeeper.stream.storage.RangeStoreBuilder) HelixStorageContainerManager(org.apache.bookkeeper.stream.storage.impl.sc.helix.HelixStorageContainerManager) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) StatsProviderService(org.apache.bookkeeper.stream.server.service.StatsProviderService) LifecycleComponent(org.apache.bookkeeper.common.component.LifecycleComponent) MalformedURLException(java.net.MalformedURLException) JCommander(com.beust.jcommander.JCommander) StorageResources(org.apache.bookkeeper.stream.storage.StorageResources) StorageService(org.apache.bookkeeper.stream.server.service.StorageService) BookieService(org.apache.bookkeeper.stream.server.service.BookieService) UnknownHostException(java.net.UnknownHostException) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) BookieConfiguration(org.apache.bookkeeper.stream.server.conf.BookieConfiguration) Slf4j(lombok.extern.slf4j.Slf4j) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) DLConfiguration(org.apache.bookkeeper.stream.server.conf.DLConfiguration) GrpcService(org.apache.bookkeeper.stream.server.service.GrpcService) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) MVCCStoreFactoryImpl(org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactoryImpl) Optional(java.util.Optional) ConfigurationException(org.apache.commons.configuration.ConfigurationException) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) StorageResources(org.apache.bookkeeper.stream.storage.StorageResources) HelixStorageContainerManager(org.apache.bookkeeper.stream.storage.impl.sc.helix.HelixStorageContainerManager) BookieConfiguration(org.apache.bookkeeper.stream.server.conf.BookieConfiguration) StorageService(org.apache.bookkeeper.stream.server.service.StorageService) MVCCStoreFactoryImpl(org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactoryImpl) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) GrpcService(org.apache.bookkeeper.stream.server.service.GrpcService) DLNamespaceProviderService(org.apache.bookkeeper.stream.server.service.DLNamespaceProviderService) RangeStoreBuilder(org.apache.bookkeeper.stream.storage.RangeStoreBuilder) StorageServerConfiguration(org.apache.bookkeeper.stream.server.conf.StorageServerConfiguration) DLConfiguration(org.apache.bookkeeper.stream.server.conf.DLConfiguration) StatsProviderService(org.apache.bookkeeper.stream.server.service.StatsProviderService) GrpcServerSpec(org.apache.bookkeeper.stream.server.grpc.GrpcServerSpec) BookieService(org.apache.bookkeeper.stream.server.service.BookieService)

Example 7 with CompositeConfiguration

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;
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 8 with CompositeConfiguration

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);
}
Also used : Keyword(ffx.utilities.Keyword) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Hashtable(java.util.Hashtable) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 9 with CompositeConfiguration

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;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) IOException(java.io.IOException) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 10 with CompositeConfiguration

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);
}
Also used : Path(java.nio.file.Path) PDBFileFilter(ffx.potential.parsers.PDBFileFilter) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ARCFileFilter(ffx.potential.parsers.ARCFileFilter) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) IOException(java.io.IOException) XYZFileFilter(ffx.potential.parsers.XYZFileFilter) MolecularAssembly(ffx.potential.MolecularAssembly) INTFileFilter(ffx.potential.parsers.INTFileFilter) ForceField(ffx.potential.parameters.ForceField) XYZFilter(ffx.potential.parsers.XYZFilter) File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter) INTFilter(ffx.potential.parsers.INTFilter)

Aggregations

CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)89 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)46 Test (org.junit.Test)24 ClusterController (org.apache.whirr.ClusterController)22 Configuration (org.apache.commons.configuration.Configuration)21 File (java.io.File)17 Before (org.junit.Before)11 ForceField (ffx.potential.parameters.ForceField)10 ConfigurationException (org.apache.commons.configuration.ConfigurationException)9 HadoopProxy (org.apache.whirr.service.hadoop.HadoopProxy)9 BeforeClass (org.junit.BeforeClass)9 IOException (java.io.IOException)8 ClusterSpec (org.apache.whirr.ClusterSpec)8 MolecularAssembly (ffx.potential.MolecularAssembly)7 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)7 PDBFilter (ffx.potential.parsers.PDBFilter)7 MapConfiguration (org.apache.commons.configuration.MapConfiguration)6 Crystal (ffx.crystal.Crystal)5 ReflectionList (ffx.crystal.ReflectionList)5 ForceFieldEnergy (ffx.potential.ForceFieldEnergy)5