use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class JanusGraphManager method openGraph.
@Override
public Graph openGraph(String gName, Function<String, Graph> thunk) {
Graph graph = graphs.get(gName);
if (graph != null && !((StandardJanusGraph) graph).isClosed()) {
if (null != gremlinExecutor) {
this.gremlinExecutor.getScriptEngineManager().put(gName, graph);
this.gremlinExecutor.getScriptEngineManager().put(gName + "_traversal", graph.traversal());
}
return graph;
} else {
synchronized (instantiateGraphLock) {
graph = graphs.get(gName);
if (graph == null || ((StandardJanusGraph) graph).isClosed()) {
graph = thunk.apply(gName);
graphs.put(gName, graph);
}
}
if (null != gremlinExecutor) {
this.gremlinExecutor.getScriptEngineManager().put(gName, graph);
this.gremlinExecutor.getScriptEngineManager().put(gName + "_traversal", graph.traversal());
}
return graph;
}
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class JanusGraphFactory method open.
/**
* Opens a {@link JanusGraph} database configured according to the provided configuration.
* This method shouldn't be called by end users; it is used by internal server processes to
* open graphs defined at server start that do not include the graphname property.
*
* @param configuration Configuration for the graph database
* @param backupName Backup name for graph
* @return JanusGraph graph database
*/
public static JanusGraph open(ReadConfiguration configuration, String backupName) {
final ModifiableConfiguration config = new ModifiableConfiguration(ROOT_NS, (WriteConfiguration) configuration, BasicConfiguration.Restriction.NONE);
final String graphName = config.has(GRAPH_NAME) ? config.get(GRAPH_NAME) : backupName;
final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
if (null != graphName) {
Preconditions.checkState(jgm != null, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG);
return (JanusGraph) jgm.openGraph(graphName, gName -> new StandardJanusGraph(new GraphDatabaseConfiguration(configuration)));
} else {
if (jgm != null) {
log.warn("You should supply \"graph.graphname\" in your .properties file configuration if you are opening " + "a graph that has not already been opened at server start, i.e. it was " + "defined in your YAML file. This will ensure the graph is tracked by the JanusGraphManager, " + "which will enable autocommit and rollback functionality upon all gremlin script executions. " + "Note that JanusGraphFactory#open(String === shortcut notation) does not support consuming the property " + "\"graph.graphname\" so these graphs should be accessed dynamically by supplying a .properties file here " + "or by using the ConfiguredGraphFactory.");
}
return new StandardJanusGraph(new GraphDatabaseConfiguration(configuration));
}
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class ConfiguredGraphFactory 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 removed from the {@link
* JanusGraphManager} graph reference tracker, if there. Finally, if a configuration for this
* graph exists on the {@link ConfigurationManagementGraph}, then said configuration will be
* removed.
*
* <p><b>WARNING: This is an irreversible operation that will delete all graph and index data.</b></p>
* @param graphName String graphName. Corresponding graph can be open or closed.
* @throws BackendException If an error occurs during deletion
* @throws ConfigurationManagementGraphNotEnabledException If ConfigurationManagementGraph not
*/
public static void drop(String graphName) throws BackendException, ConfigurationManagementGraphNotEnabledException, Exception {
final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.close(graphName);
JanusGraphFactory.drop(graph);
removeConfiguration(graphName);
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class ConfiguredGraphFactory method create.
/**
* Creates a {@link JanusGraph} configuration stored in the {@ConfigurationGraphManagament}
* 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.checkState(null != 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.checkState(jgm != null, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG);
final CommonsConfiguration config = new CommonsConfiguration(new MapConfiguration(templateConfigMap));
final JanusGraph g = (JanusGraph) jgm.openGraph(graphName, (String gName) -> new StandardJanusGraph(new GraphDatabaseConfiguration(config)));
configManagementGraph.createConfiguration(new MapConfiguration(templateConfigMap));
return g;
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class ManagementUtil method awaitIndexUpdate.
private static void awaitIndexUpdate(JanusGraph g, String indexName, String relationTypeName, long time, TemporalUnit unit) {
Preconditions.checkArgument(g != null && g.isOpen(), "Need to provide valid, open graph instance");
Preconditions.checkArgument(time > 0 && unit != null, "Need to provide valid time interval");
Preconditions.checkArgument(StringUtils.isNotBlank(indexName), "Need to provide an index name");
StandardJanusGraph graph = (StandardJanusGraph) g;
TimestampProvider times = graph.getConfiguration().getTimestampProvider();
Instant end = times.getTime().plus(Duration.of(time, unit));
boolean isStable = false;
while (times.getTime().isBefore(end)) {
JanusGraphManagement management = graph.openManagement();
try {
if (StringUtils.isNotBlank(relationTypeName)) {
RelationTypeIndex idx = management.getRelationIndex(management.getRelationType(relationTypeName), indexName);
Preconditions.checkArgument(idx != null, "Index could not be found: %s @ %s", indexName, relationTypeName);
isStable = idx.getIndexStatus().isStable();
} else {
JanusGraphIndex idx = management.getGraphIndex(indexName);
Preconditions.checkArgument(idx != null, "Index could not be found: %s", indexName);
isStable = true;
for (PropertyKey key : idx.getFieldKeys()) {
if (!idx.getIndexStatus(key).isStable())
isStable = false;
}
}
} finally {
management.rollback();
}
if (isStable)
break;
try {
times.sleepFor(Duration.ofMillis(500));
} catch (InterruptedException ignored) {
}
}
if (!isStable)
throw new JanusGraphException("Index did not stabilize within the given amount of time. For sufficiently long " + "wait periods this is most likely caused by a failed/incorrectly shut down JanusGraph instance or a lingering transaction.");
}
Aggregations