Search in sources :

Example 1 with GraphDatabaseConfigurationBuilder

use of org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder 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 2 with GraphDatabaseConfigurationBuilder

use of org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder in project janusgraph by JanusGraph.

the class ConfiguredGraphFactory method create.

/**
 * Creates a {@link JanusGraph} configuration stored in the {@link ConfigurationManagementGraph}
 * graph and a {@link JanusGraph} graph reference according to the single
 * Template Configuration  previously created by the {@link ConfigurationManagementGraph} API;
 * A configuration for this graph must not already exist, and a Template Configuration must
 * exist. If the Template Configuration does not include its
 * backend's respective keyspace/table/storage_directory parameter, we set the keyspace/table
 * to the supplied graphName or we append the graphName to the supplied
 * storage_root parameter.
 *
 * @param graphName
 *
 * @return JanusGraph
 */
public static synchronized JanusGraph create(final String graphName) {
    final ConfigurationManagementGraph configManagementGraph = getConfigGraphManagementInstance();
    final Map<String, Object> graphConfigMap = configManagementGraph.getConfiguration(graphName);
    Preconditions.checkState(null == graphConfigMap, String.format("Configuration for graph %s already exists.", graphName));
    final Map<String, Object> templateConfigMap = configManagementGraph.getTemplateConfiguration();
    Preconditions.checkNotNull(templateConfigMap, "Please create a template Configuration using the ConfigurationManagementGraph#createTemplateConfiguration API.");
    templateConfigMap.put(ConfigurationManagementGraph.PROPERTY_GRAPH_NAME, graphName);
    templateConfigMap.put(ConfigurationManagementGraph.PROPERTY_CREATED_USING_TEMPLATE, true);
    final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
    Preconditions.checkNotNull(jgm, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG);
    final CommonsConfiguration config = new CommonsConfiguration(ConfigurationUtil.loadMapConfiguration(templateConfigMap));
    final JanusGraph g = (JanusGraph) jgm.openGraph(graphName, (String gName) -> new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(config)));
    configManagementGraph.createConfiguration(new MapConfiguration(templateConfigMap));
    return g;
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) JanusGraphManager(org.janusgraph.graphdb.management.JanusGraphManager) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) ConfigurationManagementGraph(org.janusgraph.graphdb.management.ConfigurationManagementGraph) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph)

Example 3 with GraphDatabaseConfigurationBuilder

use of org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder in project janusgraph by JanusGraph.

the class HBaseStoreManagerConfigTest method testHBaseTimestampProvider.

@Test
public // Test HBase preferred timestamp provider MILLI is set by default
void testHBaseTimestampProvider() {
    // Get an empty configuration
    // GraphDatabaseConfiguration.buildGraphConfiguration() only build an empty one.
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    // Set backend to hbase
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND, "hbase");
    // Instantiate a GraphDatabaseConfiguration based on the above
    GraphDatabaseConfiguration graphConfig = new GraphDatabaseConfigurationBuilder().build(config.getConfiguration());
    // Check the TIMESTAMP_PROVIDER has been set to the hbase preferred MILLI
    TimestampProviders provider = graphConfig.getConfiguration().get(GraphDatabaseConfiguration.TIMESTAMP_PROVIDER);
    assertEquals(HBaseStoreManager.PREFERRED_TIMESTAMPS, provider);
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) TimestampProviders(org.janusgraph.diskstorage.util.time.TimestampProviders) Test(org.junit.jupiter.api.Test)

Example 4 with GraphDatabaseConfigurationBuilder

use of org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder in project janusgraph by JanusGraph.

the class GraphDatabaseConfigurationInstanceExecutorServiceTest method shouldCreateCustomBackendFixedThreadPoolSize.

@Test
public void shouldCreateCustomBackendFixedThreadPoolSize() {
    final Map<String, Object> map = getStorageConfiguration();
    map.put(UNIQUE_INSTANCE_ID_HOSTNAME.toStringWithoutRoot(), true);
    map.put(PARALLEL_BACKEND_OPS.toStringWithoutRoot(), true);
    map.put(PARALLEL_BACKEND_EXECUTOR_SERVICE_CORE_POOL_SIZE.toStringWithoutRoot(), 15);
    final MapConfiguration config = ConfigurationUtil.loadMapConfiguration(map);
    assertDoesNotThrow(() -> {
        final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
        graph.traversal().V().hasNext();
        graph.close();
    });
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Example 5 with GraphDatabaseConfigurationBuilder

use of org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder in project janusgraph by JanusGraph.

the class GraphDatabaseConfigurationInstanceExecutorServiceTest method shouldCreateCustomBackendExecutorServiceWithoutExecutorServiceConfigurationConstructor.

@Test
public void shouldCreateCustomBackendExecutorServiceWithoutExecutorServiceConfigurationConstructor() {
    final Map<String, Object> map = getStorageConfiguration();
    map.put(UNIQUE_INSTANCE_ID_HOSTNAME.toStringWithoutRoot(), true);
    map.put(PARALLEL_BACKEND_OPS.toStringWithoutRoot(), true);
    map.put(PARALLEL_BACKEND_EXECUTOR_SERVICE_CLASS.toStringWithoutRoot(), CustomParameterlessExecutorServiceImplementation.class.getName());
    final MapConfiguration config = ConfigurationUtil.loadMapConfiguration(map);
    assertDoesNotThrow(() -> {
        final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
        graph.traversal().V().hasNext();
        graph.close();
    });
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Aggregations

GraphDatabaseConfigurationBuilder (org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder)19 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)18 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)18 MapConfiguration (org.apache.commons.configuration2.MapConfiguration)16 Test (org.junit.jupiter.api.Test)14 HashMap (java.util.HashMap)4 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)4 Settings (org.apache.tinkerpop.gremlin.server.Settings)2 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)2 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)2 ConfigurationManagementGraph (org.janusgraph.graphdb.management.ConfigurationManagementGraph)2 Preconditions (com.google.common.base.Preconditions)1 File (java.io.File)1 Instant (java.time.Instant)1 List (java.util.List)1 Set (java.util.Set)1 Spliterators (java.util.Spliterators)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1