Search in sources :

Example 16 with JanusGraphManager

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

the class ConfiguredGraphFactory method open.

/**
 * Open a {@link JanusGraph} using a previously created Configuration using the
 * {@link ConfigurationManagementGraph} API. A corresponding configuration must exist.
 *
 * <p>NOTE: If your configuration corresponding to this graph does not contain information about
 * the backend's keyspace/table/storage directory, then we set the keyspace/table to the
 * graphName or set the storage directory to the storage_root + /graphName.</p>
 *
 * @param graphName
 *
 * @return JanusGraph
 */
public static JanusGraph open(String graphName) {
    final ConfigurationManagementGraph configManagementGraph = getConfigGraphManagementInstance();
    final Map<String, Object> graphConfigMap = configManagementGraph.getConfiguration(graphName);
    Preconditions.checkNotNull(graphConfigMap, "Please create configuration for this graph using the ConfigurationManagementGraph#createConfiguration API.");
    final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
    Preconditions.checkNotNull(jgm, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG);
    final CommonsConfiguration config = new CommonsConfiguration(ConfigurationUtil.loadMapConfiguration(graphConfigMap));
    return (JanusGraph) jgm.openGraph(graphName, (String gName) -> new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(config)));
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) 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 17 with JanusGraphManager

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

the class JanusGraphFactory method drop.

/**
 * Drop graph database, deleting all data in storage and indexing backends. Graph can be open or closed (will be
 * closed as part of the drop operation). The graph is also removed from the {@link JanusGraphManager}
 * graph reference tracker, if there.
 *
 * <p><b>WARNING: This is an irreversible operation that will delete all graph and index data.</b></p>
 * @param graph JanusGraph graph database. Can be open or closed.
 * @throws BackendException If an error occurs during deletion
 */
public static void drop(JanusGraph graph) throws BackendException {
    Preconditions.checkNotNull(graph);
    Preconditions.checkArgument(graph instanceof StandardJanusGraph, "Invalid graph instance detected: %s", graph.getClass());
    final StandardJanusGraph g = (StandardJanusGraph) graph;
    final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
    if (jgm != null) {
        jgm.removeGraph(g.getGraphName());
        jgm.removeTraversalSource(ConfiguredGraphFactory.toTraversalSourceName(g.getGraphName()));
    }
    if (graph.isOpen()) {
        graph.close();
    }
    final GraphDatabaseConfiguration config = g.getConfiguration();
    final Backend backend = config.getBackend();
    try {
        backend.clearStorage();
    } finally {
        IOUtils.closeQuietly(backend);
    }
}
Also used : Backend(org.janusgraph.diskstorage.Backend) JanusGraphManager(org.janusgraph.graphdb.management.JanusGraphManager) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph)

Aggregations

JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)17 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)9 GraphManager (org.apache.tinkerpop.gremlin.server.GraphManager)5 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)4 GraphDatabaseConfigurationBuilder (org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder)4 ConfigurationManagementGraph (org.janusgraph.graphdb.management.ConfigurationManagementGraph)4 MapConfiguration (org.apache.commons.configuration2.MapConfiguration)3 Graph (org.apache.tinkerpop.gremlin.structure.Graph)2 Backend (org.janusgraph.diskstorage.Backend)2 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)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 Bindings (javax.script.Bindings)1