Search in sources :

Example 16 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class GraphDatabaseConfigurationInstanceIdTest method graphShouldOpenWithSameInstanceId.

@Test
public void graphShouldOpenWithSameInstanceId() {
    final Map<String, Object> map = new HashMap<String, Object>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    map.put(UNIQUE_INSTANCE_ID.toStringWithoutRoot(), "not-unique");
    map.put(REPLACE_INSTANCE_IF_EXISTS.toStringWithoutRoot(), true);
    final MapConfiguration config = new MapConfiguration(map);
    final StandardJanusGraph graph1 = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
    assertEquals(graph1.openManagement().getOpenInstances().size(), 1);
    assertEquals(graph1.openManagement().getOpenInstances().toArray()[0], "not-unique");
    final StandardJanusGraph graph2 = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
    assertEquals(graph1.openManagement().getOpenInstances().size(), 1);
    assertEquals(graph1.openManagement().getOpenInstances().toArray()[0], "not-unique");
    assertEquals(graph2.openManagement().getOpenInstances().size(), 1);
    assertEquals(graph2.openManagement().getOpenInstances().toArray()[0], "not-unique");
    graph1.close();
    graph2.close();
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Example 17 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class AbstractJanusGraphProvider method clear.

// @Override
// public <ID> ID reconstituteGraphSONIdentifier(final Class<? extends Element> clazz, final Object id) {
// if (Edge.class.isAssignableFrom(clazz)) {
// // JanusGraphSONModule toStrings the edgeId - expect a String value for the id
// if (!(id instanceof String)) throw new RuntimeException("Expected a String value for the RelationIdentifier");
// return (ID) RelationIdentifier.parse((String) id);
// } else {
// return (ID) id;
// }
// }
@Override
public void clear(Graph g, final Configuration configuration) throws Exception {
    if (null != g) {
        while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph();
        JanusGraph graph = (JanusGraph) g;
        if (graph.isOpen()) {
            if (g.tx().isOpen())
                g.tx().rollback();
            try {
                g.close();
            } catch (IOException | IllegalStateException e) {
                logger.warn("Titan graph may not have closed cleanly", e);
            }
        }
    }
    WriteConfiguration config = new CommonsConfiguration(configuration);
    BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE);
    if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) {
        JanusGraphBaseTest.clearGraph(config);
    }
}
Also used : Graph(org.apache.tinkerpop.gremlin.structure.Graph) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) WrappedGraph(org.apache.tinkerpop.gremlin.structure.util.wrapped.WrappedGraph) JanusGraph(org.janusgraph.core.JanusGraph) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) JanusGraph(org.janusgraph.core.JanusGraph) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) IOException(java.io.IOException) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) WrappedGraph(org.apache.tinkerpop.gremlin.structure.util.wrapped.WrappedGraph)

Example 18 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class ManagementLoggerGraphCacheEvictionTest method graphShouldBeRemovedFromCache.

@Test
public void graphShouldBeRemovedFromCache() throws InterruptedException {
    final JanusGraphManager jgm = new JanusGraphManager(new Settings());
    assertNotNull(jgm);
    assertNotNull(JanusGraphManager.getInstance());
    assertNull(jgm.getGraph("graph1"));
    final Map<String, Object> map = new HashMap<>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    map.put(GRAPH_NAME.toStringWithoutRoot(), "graph1");
    final MapConfiguration config = new MapConfiguration(map);
    final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
    jgm.putGraph("graph1", graph);
    assertEquals("graph1", ((StandardJanusGraph) JanusGraphManager.getInstance().getGraph("graph1")).getGraphName());
    final ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
    mgmt.evictGraphFromCache();
    mgmt.commit();
    // wait for log to be asynchronously pulled
    Thread.sleep(10000);
    assertNull(jgm.getGraph("graph1"));
}
Also used : ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) Settings(org.apache.tinkerpop.gremlin.server.Settings) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Example 19 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class JanusGraphFactory method getLocalConfiguration.

// ###################################
// HELPER METHODS
// ###################################
private static ReadConfiguration getLocalConfiguration(String shortcutOrFile) {
    File file = new File(shortcutOrFile);
    if (file.exists())
        return getLocalConfiguration(file);
    else {
        int pos = shortcutOrFile.indexOf(':');
        if (pos < 0)
            pos = shortcutOrFile.length();
        String backend = shortcutOrFile.substring(0, pos);
        Preconditions.checkArgument(StandardStoreManager.getAllManagerClasses().containsKey(backend.toLowerCase()), "Backend shorthand unknown: %s", backend);
        String secondArg = null;
        if (pos + 1 < shortcutOrFile.length())
            secondArg = shortcutOrFile.substring(pos + 1).trim();
        BaseConfiguration config = new BaseConfiguration();
        ModifiableConfiguration writeConfig = new ModifiableConfiguration(ROOT_NS, new CommonsConfiguration(config), BasicConfiguration.Restriction.NONE);
        writeConfig.set(STORAGE_BACKEND, backend);
        ConfigOption option = Backend.getOptionForShorthand(backend);
        if (option == null) {
            Preconditions.checkArgument(secondArg == null);
        } else if (option == STORAGE_DIRECTORY || option == STORAGE_CONF_FILE) {
            Preconditions.checkArgument(StringUtils.isNotBlank(secondArg), "Need to provide additional argument to initialize storage backend");
            writeConfig.set(option, getAbsolutePath(secondArg));
        } else if (option == STORAGE_HOSTS) {
            Preconditions.checkArgument(StringUtils.isNotBlank(secondArg), "Need to provide additional argument to initialize storage backend");
            writeConfig.set(option, new String[] { secondArg });
        } else
            throw new IllegalArgumentException("Invalid configuration option for backend " + option);
        return new CommonsConfiguration(config);
    }
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) File(java.io.File)

Example 20 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration 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

CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)20 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)10 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)9 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)9 Test (org.junit.Test)9 MapConfiguration (org.apache.commons.configuration.MapConfiguration)8 HashMap (java.util.HashMap)7 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)6 ImmutableMap (com.google.common.collect.ImmutableMap)2 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)2 BasicConfiguration (org.janusgraph.diskstorage.configuration.BasicConfiguration)2 ManagementSystem (org.janusgraph.graphdb.database.management.ManagementSystem)2 ConfigurationManagementGraph (org.janusgraph.graphdb.management.ConfigurationManagementGraph)2 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)2 FileInputStream (java.io.FileInputStream)1 Duration (java.time.Duration)1