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();
}
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);
}
}
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"));
}
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);
}
}
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)));
}
Aggregations