Search in sources :

Example 11 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project winery by eclipse.

the class CsarImporter method importNamespacePrefixes.

/**
 * Import namespace prefixes. This is kind of a quick hack. TODO: during the import, the prefixes should be
 * extracted using JAXB and stored in the NamespacesResource
 *
 * @param rootPath the root path of the extracted CSAR
 */
private void importNamespacePrefixes(Path rootPath) {
    NamespaceManager namespaceManager = targetRepository.getNamespaceManager();
    Path properties = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_PROPERTIES);
    Path json = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_JSON);
    if (Files.exists(properties) || Files.exists(json)) {
        NamespaceManager localNamespaceManager;
        if (Files.exists(properties)) {
            PropertiesConfiguration pconf = new PropertiesConfiguration();
            try (final BufferedReader propertyReader = Files.newBufferedReader(properties)) {
                pconf.read(propertyReader);
                localNamespaceManager = new ConfigurationBasedNamespaceManager(pconf);
            } catch (IOException | ConfigurationException e) {
                CsarImporter.LOGGER.debug(e.getMessage(), e);
                return;
            }
        } else {
            localNamespaceManager = new JsonBasedNamespaceManager(json.toFile());
        }
        for (String s : localNamespaceManager.getAllNamespaces().keySet()) {
            boolean addToStorage = false;
            String namespace = s;
            if (namespaceManager.hasPermanentProperties(namespace)) {
                String storedPrefix = namespaceManager.getPrefix(namespace);
                // QUICK HACK to check whether the prefix is a generated one
                // We assume we know the internal generation routine
                Matcher m = CsarImporter.GENERATED_PREFIX_PATTERN.matcher(storedPrefix);
                if (m.matches()) {
                    // the stored prefix is a generated one
                    // replace it by the one stored in the exported properties
                    addToStorage = true;
                }
            } else {
                addToStorage = true;
            }
            if (addToStorage) {
                String prefix = localNamespaceManager.getPrefix(namespace);
                namespaceManager.setNamespaceProperties(namespace, new NamespaceProperties(namespace, prefix));
            }
        }
    }
}
Also used : Path(java.nio.file.Path) JsonBasedNamespaceManager(org.eclipse.winery.repository.backend.filebased.JsonBasedNamespaceManager) ConfigurationBasedNamespaceManager(org.eclipse.winery.repository.backend.filebased.ConfigurationBasedNamespaceManager) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) ConfigurationBasedNamespaceManager(org.eclipse.winery.repository.backend.filebased.ConfigurationBasedNamespaceManager) Matcher(java.util.regex.Matcher) PathMatcher(java.nio.file.PathMatcher) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) JsonBasedNamespaceManager(org.eclipse.winery.repository.backend.filebased.JsonBasedNamespaceManager) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) NamespaceProperties(org.eclipse.winery.repository.backend.filebased.NamespaceProperties) BufferedReader(java.io.BufferedReader)

Example 12 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project janusgraph by JanusGraph.

the class JanusGraphFactory method getLocalConfiguration.

/**
 * Load a properties file containing a JanusGraph graph configuration.
 * <p>
 * <ol>
 * <li>Load the file contents into a {@link org.apache.commons.configuration2.PropertiesConfiguration}</li>
 * <li>For each key that points to a configuration object that is either a directory
 * or local file, check
 * whether the associated value is a non-null, non-absolute path. If so,
 * then prepend the absolute path of the parent directory of the provided configuration {@code file}.
 * 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 {@link ReadConfiguration} for the prepared configuration file</li>
 * </ol>
 * <p>
 *
 * @param file A properties file to load
 * @return A configuration derived from {@code file}
 */
private static ReadConfiguration getLocalConfiguration(File file) {
    Preconditions.checkNotNull(file);
    Preconditions.checkArgument(file.exists() && file.isFile() && file.canRead(), "Need to specify a readable configuration file, but was given: %s", file.toString());
    try {
        PropertiesConfiguration configuration = ConfigurationUtil.loadPropertiesConfig(file);
        final File tmpParent = file.getParentFile();
        final File configParent;
        if (null == tmpParent) {
            /*
                 * null usually means we were given a JanusGraph 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());
        // TODO this mangling logic is a relic from the hardcoded string days; it should be deleted and rewritten as a setting on ConfigOption
        final Pattern p = Pattern.compile("(" + Pattern.quote(STORAGE_NS.getName()) + "\\..*" + "(" + Pattern.quote(STORAGE_DIRECTORY.getName()) + "|" + Pattern.quote(STORAGE_CONF_FILE.getName()) + ")" + "|" + Pattern.quote(INDEX_NS.getName()) + "\\..*" + "(" + Pattern.quote(INDEX_DIRECTORY.getName()) + "|" + Pattern.quote(INDEX_CONF_FILE.getName()) + ")" + ")");
        final List<String> keysToMangle = StreamSupport.stream(Spliterators.spliteratorUnknownSize(configuration.getKeys(), 0), false).filter(key -> null != key && p.matcher(key).matches()).collect(Collectors.toList());
        for (String k : keysToMangle) {
            Preconditions.checkNotNull(k);
            final String s = configuration.getString(k);
            Preconditions.checkArgument(StringUtils.isNotBlank(s), "Invalid Configuration: key %s has null empty value", k);
            configuration.setProperty(k, getAbsolutePath(configParent, s));
        }
        return new CommonsConfiguration(configuration);
    } catch (ConfigurationException e) {
        throw new IllegalArgumentException("Could not load configuration at: " + file, e);
    }
}
Also used : GRAPH_NAME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.GRAPH_NAME) StandardStoreManager(org.janusgraph.diskstorage.StandardStoreManager) Spliterators(java.util.Spliterators) Graph(org.apache.tinkerpop.gremlin.structure.Graph) STORAGE_BACKEND(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_BACKEND) LoggerFactory(org.slf4j.LoggerFactory) ConfigOption(org.janusgraph.diskstorage.configuration.ConfigOption) StringUtils(org.apache.commons.lang3.StringUtils) Backend(org.janusgraph.diskstorage.Backend) ROOT_NS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ROOT_NS) StandardTransactionLogProcessor(org.janusgraph.graphdb.log.StandardTransactionLogProcessor) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) STORAGE_HOSTS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_HOSTS) StreamSupport(java.util.stream.StreamSupport) JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG(org.janusgraph.graphdb.management.JanusGraphManager.JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG) TransactionRecovery(org.janusgraph.core.log.TransactionRecovery) BackendException(org.janusgraph.diskstorage.BackendException) ConfigurationUtil(org.janusgraph.util.system.ConfigurationUtil) Logger(org.slf4j.Logger) LoggerUtil.sanitizeAndLaunder(org.janusgraph.util.system.LoggerUtil.sanitizeAndLaunder) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) STORAGE_DIRECTORY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_DIRECTORY) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) IOUtils(org.janusgraph.util.system.IOUtils) Set(java.util.Set) Instant(java.time.Instant) STORAGE_NS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_NS) Collectors(java.util.stream.Collectors) Configuration(org.apache.commons.configuration2.Configuration) File(java.io.File) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) List(java.util.List) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) LogProcessorFramework(org.janusgraph.core.log.LogProcessorFramework) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) JanusGraphManager(org.janusgraph.graphdb.management.JanusGraphManager) INDEX_DIRECTORY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_DIRECTORY) BaseConfiguration(org.apache.commons.configuration2.BaseConfiguration) INDEX_CONF_FILE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_CONF_FILE) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) STORAGE_CONF_FILE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_CONF_FILE) Preconditions(com.google.common.base.Preconditions) Pattern(java.util.regex.Pattern) StandardLogProcessorFramework(org.janusgraph.graphdb.log.StandardLogProcessorFramework) INDEX_NS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_NS) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) ReadConfiguration(org.janusgraph.diskstorage.configuration.ReadConfiguration) Pattern(java.util.regex.Pattern) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) File(java.io.File)

Example 13 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project janusgraph by JanusGraph.

the class ConfigurationUtil method loadPropertiesConfig.

private static PropertiesConfiguration loadPropertiesConfig(PropertiesBuilderParameters params, boolean setCommaDelimiterHandler) throws ConfigurationException {
    FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class);
    PropertiesBuilderParameters newParams = params;
    if (setCommaDelimiterHandler) {
        newParams = newParams.setListDelimiterHandler(COMMA_DELIMITER_HANDLER);
    }
    return builder.configure(newParams).getConfiguration();
}
Also used : FileBasedConfigurationBuilder(org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder) PropertiesBuilderParameters(org.apache.commons.configuration2.builder.fluent.PropertiesBuilderParameters) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 14 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project janusgraph by JanusGraph.

the class HBaseSnapshotInputFormatIT method getGraph.

protected Graph getGraph() throws IOException, ConfigurationException {
    final PropertiesConfiguration config = ConfigurationUtil.loadPropertiesConfig("target/test-classes/hbase-read-snapshot.properties", false);
    Path baseOutDir = Paths.get((String) config.getProperty("gremlin.hadoop.outputLocation"));
    baseOutDir.toFile().mkdirs();
    String outDir = Files.createTempDirectory(baseOutDir, null).toAbsolutePath().toString();
    config.setProperty("gremlin.hadoop.outputLocation", outDir);
    // Set the hbase.rootdir property. This is needed by HBaseSnapshotInputFormat.
    config.setProperty("janusgraphmr.ioformat.conf.storage.hbase.ext.hbase.rootdir", hBaseContainer.getHBaseRootDir().toString());
    return GraphFactory.open(config);
}
Also used : Path(java.nio.file.Path) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 15 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project janusgraph by JanusGraph.

the class HBaseInputFormatIT method getGraph.

protected Graph getGraph() throws IOException, ConfigurationException {
    final PropertiesConfiguration config = ConfigurationUtil.loadPropertiesConfig("target/test-classes/hbase-read.properties", false);
    Path baseOutDir = Paths.get((String) config.getProperty("gremlin.hadoop.outputLocation"));
    baseOutDir.toFile().mkdirs();
    String outDir = Files.createTempDirectory(baseOutDir, null).toAbsolutePath().toString();
    config.setProperty("gremlin.hadoop.outputLocation", outDir);
    return GraphFactory.open(config);
}
Also used : Path(java.nio.file.Path) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Aggregations

PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)28 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)10 File (java.io.File)7 IOException (java.io.IOException)6 Path (java.nio.file.Path)6 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)5 Configuration (org.apache.commons.configuration2.Configuration)4 Configurations (org.apache.commons.configuration2.builder.fluent.Configurations)4 FileReader (java.io.FileReader)3 FileBasedConfigurationBuilder (org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 StringWriter (java.io.StringWriter)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 BaseConfiguration (org.apache.commons.configuration2.BaseConfiguration)2 PropertiesBuilderParameters (org.apache.commons.configuration2.builder.fluent.PropertiesBuilderParameters)2 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)2 Preconditions (com.google.common.base.Preconditions)1 BufferedReader (java.io.BufferedReader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1