Search in sources :

Example 1 with ReadConfiguration

use of org.janusgraph.diskstorage.configuration.ReadConfiguration 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 2 with ReadConfiguration

use of org.janusgraph.diskstorage.configuration.ReadConfiguration in project janusgraph by JanusGraph.

the class JanusGraphFactory method open.

/**
 * Opens a {@link JanusGraph} database configured according to the provided configuration.
 * This method shouldn't be called by end users; it is used by internal server processes to
 * open graphs defined at server start that do not include the graphname property.
 *
 * @param configuration Configuration for the graph database
 * @param backupName Backup name for graph
 * @return JanusGraph graph database
 */
public static JanusGraph open(ReadConfiguration configuration, String backupName) {
    final ModifiableConfiguration config = new ModifiableConfiguration(ROOT_NS, (WriteConfiguration) configuration, BasicConfiguration.Restriction.NONE);
    final String graphName = config.has(GRAPH_NAME) ? config.get(GRAPH_NAME) : backupName;
    final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
    if (null != graphName) {
        Preconditions.checkNotNull(jgm, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG);
        return (JanusGraph) jgm.openGraph(graphName, gName -> new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(configuration)));
    } else {
        if (jgm != null) {
            log.warn("You should supply \"graph.graphname\" in your .properties file configuration if you are opening " + "a graph that has not already been opened at server start, i.e. it was " + "defined in your YAML file. This will ensure the graph is tracked by the JanusGraphManager, " + "which will enable autocommit and rollback functionality upon all gremlin script executions. " + "Note that JanusGraphFactory#open(String === shortcut notation) does not support consuming the property " + "\"graph.graphname\" so these graphs should be accessed dynamically by supplying a .properties file here " + "or by using the ConfiguredGraphFactory.");
        }
        return new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(configuration));
    }
}
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) GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) JanusGraphManager(org.janusgraph.graphdb.management.JanusGraphManager) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph)

Example 3 with ReadConfiguration

use of org.janusgraph.diskstorage.configuration.ReadConfiguration in project janusgraph by JanusGraph.

the class ReadConfigurationBuilderTest method shouldBuildReadConfiguration.

@Test
public void shouldBuildReadConfiguration() {
    when(storeManager.getFeatures()).thenReturn(features);
    when(keyColumnValueStoreConfiguration.asReadConfiguration()).thenReturn(readConfiguration);
    ReadConfiguration result = buildConfiguration();
    assertEquals(readConfiguration, result);
}
Also used : ReadConfiguration(org.janusgraph.diskstorage.configuration.ReadConfiguration) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ReadConfiguration

use of org.janusgraph.diskstorage.configuration.ReadConfiguration in project janusgraph by JanusGraph.

the class GraphDatabaseConfigurationBuilder method build.

public GraphDatabaseConfiguration build(ReadConfiguration localConfig) {
    Preconditions.checkNotNull(localConfig);
    BasicConfiguration localBasicConfiguration = new BasicConfiguration(ROOT_NS, localConfig, BasicConfiguration.Restriction.NONE);
    ModifiableConfiguration overwrite = new ModifiableConfiguration(ROOT_NS, new CommonsConfiguration(), BasicConfiguration.Restriction.NONE);
    final KeyColumnValueStoreManager storeManager = Backend.getStorageManager(localBasicConfiguration);
    final StoreFeatures storeFeatures = storeManager.getFeatures();
    final ReadConfiguration globalConfig = new ReadConfigurationBuilder().buildGlobalConfiguration(localConfig, localBasicConfiguration, overwrite, storeManager, new ModifiableConfigurationBuilder(), new KCVSConfigurationBuilder());
    // Copy over local config options
    ModifiableConfiguration localConfiguration = new ModifiableConfiguration(ROOT_NS, new CommonsConfiguration(), BasicConfiguration.Restriction.LOCAL);
    localConfiguration.setAll(getLocalSubset(localBasicConfiguration.getAll()));
    Configuration combinedConfig = new MixedConfiguration(ROOT_NS, globalConfig, localConfig);
    // Compute unique instance id
    String uniqueGraphId = UniqueInstanceIdRetriever.getInstance().getOrGenerateUniqueInstanceId(combinedConfig);
    overwrite.set(UNIQUE_INSTANCE_ID, uniqueGraphId);
    checkAndOverwriteTransactionLogConfiguration(combinedConfig, overwrite, storeFeatures);
    checkAndOverwriteSystemManagementLogConfiguration(combinedConfig, overwrite);
    MergedConfiguration configuration = new MergedConfiguration(overwrite, combinedConfig);
    return new GraphDatabaseConfiguration(localConfig, localConfiguration, uniqueGraphId, configuration);
}
Also used : StoreFeatures(org.janusgraph.diskstorage.keycolumnvalue.StoreFeatures) KCVSConfigurationBuilder(org.janusgraph.diskstorage.configuration.backend.builder.KCVSConfigurationBuilder) MergedConfiguration(org.janusgraph.diskstorage.configuration.MergedConfiguration) MergedConfiguration(org.janusgraph.diskstorage.configuration.MergedConfiguration) MixedConfiguration(org.janusgraph.diskstorage.configuration.MixedConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) ReadConfiguration(org.janusgraph.diskstorage.configuration.ReadConfiguration) MixedConfiguration(org.janusgraph.diskstorage.configuration.MixedConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) ReadConfiguration(org.janusgraph.diskstorage.configuration.ReadConfiguration) ModifiableConfigurationBuilder(org.janusgraph.diskstorage.configuration.builder.ModifiableConfigurationBuilder) KeyColumnValueStoreManager(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager) ReadConfigurationBuilder(org.janusgraph.diskstorage.configuration.builder.ReadConfigurationBuilder) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration)

Aggregations

ReadConfiguration (org.janusgraph.diskstorage.configuration.ReadConfiguration)4 BasicConfiguration (org.janusgraph.diskstorage.configuration.BasicConfiguration)3 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)3 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)3 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)3 Preconditions (com.google.common.base.Preconditions)2 File (java.io.File)2 Instant (java.time.Instant)2 List (java.util.List)2 Set (java.util.Set)2 Spliterators (java.util.Spliterators)2 Pattern (java.util.regex.Pattern)2 Collectors (java.util.stream.Collectors)2 StreamSupport (java.util.stream.StreamSupport)2 BaseConfiguration (org.apache.commons.configuration2.BaseConfiguration)2 Configuration (org.apache.commons.configuration2.Configuration)2 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)2 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Graph (org.apache.tinkerpop.gremlin.structure.Graph)2