Search in sources :

Example 11 with GraphDatabaseConfiguration

use of org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration in project janusgraph by JanusGraph.

the class StandardJanusGraphTxTest method createTxWithMockedInternals.

private StandardJanusGraphTx createTxWithMockedInternals() {
    StandardJanusGraph mockGraph = createMock(StandardJanusGraph.class);
    TransactionConfiguration txConfig = createMock(TransactionConfiguration.class);
    GraphDatabaseConfiguration gdbConfig = createMock(GraphDatabaseConfiguration.class);
    TimestampProvider tsProvider = createMock(TimestampProvider.class);
    Serializer mockSerializer = createMock(Serializer.class);
    EdgeSerializer mockEdgeSerializer = createMock(EdgeSerializer.class);
    IndexSerializer mockIndexSerializer = createMock(IndexSerializer.class);
    RelationType relationType = createMock(RelationType.class);
    IDManager idManager = createMock(IDManager.class);
    PropertyKey propertyKey = createMock(PropertyKey.class);
    DefaultSchemaMaker defaultSchemaMaker = createMock(DefaultSchemaMaker.class);
    expect(mockGraph.getConfiguration()).andReturn(gdbConfig);
    expect(mockGraph.isOpen()).andReturn(true).anyTimes();
    expect(mockGraph.getDataSerializer()).andReturn(mockSerializer);
    expect(mockGraph.getEdgeSerializer()).andReturn(mockEdgeSerializer);
    expect(mockGraph.getIndexSerializer()).andReturn(mockIndexSerializer);
    expect(mockGraph.getIDManager()).andReturn(idManager);
    expect(gdbConfig.getTimestampProvider()).andReturn(tsProvider);
    expect(txConfig.isSingleThreaded()).andReturn(true);
    expect(txConfig.hasPreloadedData()).andReturn(false);
    expect(txConfig.hasVerifyExternalVertexExistence()).andReturn(false);
    expect(txConfig.hasVerifyInternalVertexExistence()).andReturn(false);
    expect(txConfig.getVertexCacheSize()).andReturn(6);
    expect(txConfig.isReadOnly()).andReturn(true);
    expect(txConfig.getDirtyVertexSize()).andReturn(2);
    expect(txConfig.getIndexCacheWeight()).andReturn(2L);
    expect(txConfig.getGroupName()).andReturn(null);
    expect(txConfig.getAutoSchemaMaker()).andReturn(defaultSchemaMaker);
    expect(defaultSchemaMaker.makePropertyKey(isA(PropertyKeyMaker.class), notNull())).andReturn(propertyKey);
    expect(relationType.isPropertyKey()).andReturn(false);
    expect(propertyKey.isPropertyKey()).andReturn(true);
    replayAll();
    StandardJanusGraphTx partialMock = createMockBuilder(StandardJanusGraphTx.class).withConstructor(mockGraph, txConfig).addMockedMethod("getRelationType").createMock();
    expect(partialMock.getRelationType("Foo")).andReturn(null);
    expect(partialMock.getRelationType("Qux")).andReturn(propertyKey);
    expect(partialMock.getRelationType("Baz")).andReturn(relationType);
    replay(partialMock);
    return partialMock;
}
Also used : IndexSerializer(org.janusgraph.graphdb.database.IndexSerializer) IDManager(org.janusgraph.graphdb.idmanagement.IDManager) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) PropertyKeyMaker(org.janusgraph.core.schema.PropertyKeyMaker) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) DefaultSchemaMaker(org.janusgraph.core.schema.DefaultSchemaMaker) RelationType(org.janusgraph.core.RelationType) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) PropertyKey(org.janusgraph.core.PropertyKey) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) IndexSerializer(org.janusgraph.graphdb.database.IndexSerializer) Serializer(org.janusgraph.graphdb.database.serialize.Serializer)

Example 12 with GraphDatabaseConfiguration

use of org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration 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());
    }
    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)

Example 13 with GraphDatabaseConfiguration

use of org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration 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.checkState(null != graphConfigMap, "Please create configuration for this graph using the ConfigurationManagementGraph#createConfiguration API.");
    final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
    Preconditions.checkState(jgm != null, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG);
    final CommonsConfiguration config = new CommonsConfiguration(new MapConfiguration(graphConfigMap));
    return (JanusGraph) jgm.openGraph(graphName, (String gName) -> new StandardJanusGraph(new GraphDatabaseConfiguration(config)));
}
Also used : MapConfiguration(org.apache.commons.configuration.MapConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) JanusGraphManager(org.janusgraph.graphdb.management.JanusGraphManager) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) ConfigurationManagementGraph(org.janusgraph.graphdb.management.ConfigurationManagementGraph) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph)

Aggregations

GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)13 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)11 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)9 MapConfiguration (org.apache.commons.configuration.MapConfiguration)8 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)4 Backend (org.janusgraph.diskstorage.Backend)2 ManagementSystem (org.janusgraph.graphdb.database.management.ManagementSystem)2 ConfigurationManagementGraph (org.janusgraph.graphdb.management.ConfigurationManagementGraph)2 Preconditions (com.google.common.base.Preconditions)1 Iterators (com.google.common.collect.Iterators)1 File (java.io.File)1 Instant (java.time.Instant)1 java.util (java.util)1 Pattern (java.util.regex.Pattern)1 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)1 Configuration (org.apache.commons.configuration.Configuration)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)1