Search in sources :

Example 1 with ConfigurationManagementGraph

use of org.janusgraph.graphdb.management.ConfigurationManagementGraph in project janusgraph by JanusGraph.

the class ConfiguredGraphFactoryTest method shouldGetConfigurationManagementGraphInstance.

@Test
public void shouldGetConfigurationManagementGraphInstance() throws ConfigurationManagementGraphNotEnabledException {
    final ConfigurationManagementGraph thisInstance = ConfigurationManagementGraph.getInstance();
    assertNotNull(thisInstance);
}
Also used : ConfigurationManagementGraph(org.janusgraph.graphdb.management.ConfigurationManagementGraph) Test(org.junit.Test)

Example 2 with ConfigurationManagementGraph

use of org.janusgraph.graphdb.management.ConfigurationManagementGraph in project janusgraph by JanusGraph.

the class ConfiguredGraphFactory method createTemplateConfiguration.

/**
 * Create a template configuration according to the supplied {@link Configuration}; if
 * you already created a template configuration or the supplied {@link Configuration}
 * contains the property "graph.graphname", we throw a {@link RuntimeException}; you can then use
 * this template configuration to create a graph using the
 * ConfiguredGraphFactory create signature and supplying a new graphName.
 */
public static void createTemplateConfiguration(final Configuration config) {
    final ConfigurationManagementGraph configManagementGraph = getConfigGraphManagementInstance();
    configManagementGraph.createTemplateConfiguration(config);
}
Also used : ConfigurationManagementGraph(org.janusgraph.graphdb.management.ConfigurationManagementGraph)

Example 3 with ConfigurationManagementGraph

use of org.janusgraph.graphdb.management.ConfigurationManagementGraph 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 4 with ConfigurationManagementGraph

use of org.janusgraph.graphdb.management.ConfigurationManagementGraph in project janusgraph by JanusGraph.

the class ConfiguredGraphFactory method updateConfiguration.

/**
 * Update configuration corresponding to supplied graphName; we update supplied existing
 * properties and add new ones to the {@link Configuration}; The supplied {@link Configuration} must include a
 * property "graph.graphname" and it must match supplied graphName;
 * NOTE: The updated configuration is only guaranteed to take effect if the {@link Graph} corresponding to
 * graphName has been closed and reopened on every JanusGraph Node.
 */
public static void updateConfiguration(final String graphName, final Configuration config) {
    final ConfigurationManagementGraph configManagementGraph = getConfigGraphManagementInstance();
    removeGraphFromCache(graphName);
    configManagementGraph.updateConfiguration(graphName, config);
}
Also used : ConfigurationManagementGraph(org.janusgraph.graphdb.management.ConfigurationManagementGraph)

Example 5 with ConfigurationManagementGraph

use of org.janusgraph.graphdb.management.ConfigurationManagementGraph in project janusgraph by JanusGraph.

the class ConfiguredGraphFactory method getGraphNames.

/**
 * Get a Set of the graphNames that exist in your configuration management graph
 */
public static Set<String> getGraphNames() {
    final ConfigurationManagementGraph configManagementGraph = getConfigGraphManagementInstance();
    final List<Map<String, Object>> configurations = configManagementGraph.getConfigurations();
    return configurations.stream().map(elem -> (String) elem.getOrDefault(ConfigurationManagementGraph.PROPERTY_GRAPH_NAME, null)).filter(Objects::nonNull).collect(Collectors.toSet());
}
Also used : Map(java.util.Map) ConfigurationManagementGraph(org.janusgraph.graphdb.management.ConfigurationManagementGraph)

Aggregations

ConfigurationManagementGraph (org.janusgraph.graphdb.management.ConfigurationManagementGraph)12 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)3 GraphDatabaseConfigurationBuilder (org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder)3 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)3 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)3 MapConfiguration (org.apache.commons.configuration2.MapConfiguration)2 Map (java.util.Map)1 Settings (org.apache.tinkerpop.gremlin.server.Settings)1 Test (org.junit.Test)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1