use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class GraphIndexStatusWatcher method call.
@Override
public GraphIndexStatusReport call() throws InterruptedException {
Preconditions.checkNotNull(g, "Graph instance must not be null");
Preconditions.checkNotNull(graphIndexName, "Index name must not be null");
Preconditions.checkNotNull(statuses, "Target statuses must not be null");
Preconditions.checkArgument(statuses.size() > 0, "Target statuses must include at least one status");
Map<String, SchemaStatus> notConverged = new HashMap<>();
Map<String, SchemaStatus> converged = new HashMap<>();
JanusGraphIndex idx;
Timer t = new Timer(TimestampProviders.MILLI).start();
boolean timedOut;
while (true) {
JanusGraphManagement management = null;
try {
management = g.openManagement();
idx = management.getGraphIndex(graphIndexName);
for (PropertyKey pk : idx.getFieldKeys()) {
SchemaStatus s = idx.getIndexStatus(pk);
LOGGER.debug("Key {} has status {}", pk, s);
if (!statuses.contains(s))
notConverged.put(pk.toString(), s);
else
converged.put(pk.toString(), s);
}
} finally {
if (null != management)
// Let an exception here propagate up the stack
management.rollback();
}
if (!notConverged.isEmpty()) {
String waitingOn = StringUtils.join(notConverged, "=", ",");
LOGGER.info("Some key(s) on index {} do not currently have status(es) {}: {}", graphIndexName, statuses, waitingOn);
} else {
LOGGER.info("All {} key(s) on index {} have status(es) {}", converged.size(), graphIndexName, statuses);
return new GraphIndexStatusReport(true, graphIndexName, statuses, notConverged, converged, t.elapsed());
}
timedOut = null != timeout && 0 < t.elapsed().compareTo(timeout);
if (timedOut) {
LOGGER.info("Timed out ({}) while waiting for index {} to converge on status(es) {}", timeout, graphIndexName, statuses);
return new GraphIndexStatusReport(false, graphIndexName, statuses, notConverged, converged, t.elapsed());
}
notConverged.clear();
converged.clear();
Thread.sleep(poll.toMillis());
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class RelationIndexStatusWatcher method call.
/**
* Poll a relation index until it has a certain {@link SchemaStatus},
* or until a configurable timeout is exceeded.
*
* @return a report with information about schema state, execution duration, and the index
*/
@Override
public RelationIndexStatusReport call() throws InterruptedException {
Preconditions.checkNotNull(g, "Graph instance must not be null");
Preconditions.checkNotNull(relationIndexName, "Index name must not be null");
Preconditions.checkNotNull(statuses, "Target statuses must not be null");
Preconditions.checkArgument(statuses.size() > 0, "Target statuses must include at least one status");
RelationTypeIndex idx;
Timer t = new Timer(TimestampProviders.MILLI).start();
boolean timedOut;
while (true) {
final SchemaStatus actualStatus;
JanusGraphManagement management = null;
try {
management = g.openManagement();
idx = management.getRelationIndex(management.getRelationType(relationTypeName), relationIndexName);
actualStatus = idx.getIndexStatus();
LOGGER.info("Index {} (relation type {}) has status {}", relationIndexName, relationTypeName, actualStatus);
if (statuses.contains(actualStatus)) {
return new RelationIndexStatusReport(true, relationIndexName, relationTypeName, actualStatus, statuses, t.elapsed());
}
} finally {
if (null != management)
// Let an exception here propagate up the stack
management.rollback();
}
timedOut = null != timeout && 0 < t.elapsed().compareTo(timeout);
if (timedOut) {
LOGGER.info("Timed out ({}) while waiting for index {} (relation type {}) to reach status(es) {}", timeout, relationIndexName, relationTypeName, statuses);
return new RelationIndexStatusReport(false, relationIndexName, relationTypeName, actualStatus, statuses, t.elapsed());
}
Thread.sleep(poll.toMillis());
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class JanusGraphApp method createSchema.
@Override
public void createSchema() {
final JanusGraphManagement management = getJanusGraph().openManagement();
try {
// naive check if the schema was previously created
if (management.getRelationTypes(RelationType.class).iterator().hasNext()) {
management.rollback();
return;
}
LOGGER.info("creating schema");
createProperties(management);
createVertexLabels(management);
createEdgeLabels(management);
createCompositeIndexes(management);
createMixedIndexes(management);
management.commit();
} catch (Exception e) {
management.rollback();
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class QueryTest method testFuzzyMatchWithoutIndex.
@Test
public void testFuzzyMatchWithoutIndex() {
JanusGraphManagement mgmt = graph.openManagement();
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
mgmt.commit();
tx.addVertex().property("name", "some value");
tx.commit();
// Exact match
assertEquals(1, graph.traversal().V().has("name", Text.textFuzzy("some value")).count().next());
assertEquals(1, graph.traversal().V().has("name", Text.textContainsFuzzy("value")).count().next());
// One character different
assertEquals(1, graph.traversal().V().has("name", Text.textFuzzy("some values")).count().next());
assertEquals(1, graph.traversal().V().has("name", Text.textContainsFuzzy("values")).count().next());
// Two characters different
assertEquals(1, graph.traversal().V().has("name", Text.textFuzzy("some val")).count().next());
assertEquals(1, graph.traversal().V().has("name", Text.textContainsFuzzy("values!")).count().next());
// Three characters different
assertEquals(0, graph.traversal().V().has("name", Text.textFuzzy("some Val")).count().next());
assertEquals(0, graph.traversal().V().has("name", Text.textContainsFuzzy("valuable")).count().next());
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class QueryTest method testTextNegatedWithoutIndex.
@Test
public void testTextNegatedWithoutIndex() {
JanusGraphManagement mgmt = graph.openManagement();
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
mgmt.commit();
tx.addVertex().property("name", "some value");
tx.addVertex().property("name", "other value");
tx.commit();
// Text.textNotFuzzy
assertEquals(1, graph.traversal().V().has("name", Text.textNotFuzzy("other values")).count().next());
assertEquals(2, graph.traversal().V().has("name", Text.textNotFuzzy("final values")).count().next());
// Text.textNotRegex
assertEquals(0, graph.traversal().V().has("name", Text.textNotRegex(".*value")).count().next());
assertEquals(1, graph.traversal().V().has("name", Text.textNotRegex("other.*")).count().next());
assertEquals(2, graph.traversal().V().has("name", Text.textNotRegex("final.*")).count().next());
// Text.textNotPrefix
assertEquals(1, graph.traversal().V().has("name", Text.textNotPrefix("other")).count().next());
assertEquals(2, graph.traversal().V().has("name", Text.textNotPrefix("final")).count().next());
// Text.textNotContains
assertEquals(0, graph.traversal().V().has("name", Text.textNotContains("value")).count().next());
assertEquals(1, graph.traversal().V().has("name", Text.textNotContains("other")).count().next());
assertEquals(2, graph.traversal().V().has("name", Text.textNotContains("final")).count().next());
// Text.textNotContainsFuzzy
assertEquals(0, graph.traversal().V().has("name", Text.textNotContainsFuzzy("values")).count().next());
assertEquals(1, graph.traversal().V().has("name", Text.textNotContainsFuzzy("others")).count().next());
assertEquals(2, graph.traversal().V().has("name", Text.textNotContainsFuzzy("final")).count().next());
// Text.textNotContainsRegex
assertEquals(0, graph.traversal().V().has("name", Text.textNotContainsRegex("val.*")).count().next());
assertEquals(1, graph.traversal().V().has("name", Text.textNotContainsRegex("oth.*")).count().next());
assertEquals(2, graph.traversal().V().has("name", Text.textNotContainsRegex("fin.*")).count().next());
// Text.textNotContainsPrefix
assertEquals(0, graph.traversal().V().has("name", Text.textNotContainsPrefix("val")).count().next());
assertEquals(1, graph.traversal().V().has("name", Text.textNotContainsPrefix("oth")).count().next());
assertEquals(2, graph.traversal().V().has("name", Text.textNotContainsPrefix("final")).count().next());
// Text.textNotContainsPhrase
assertEquals(0, graph.traversal().V().has("name", Text.textNotContainsPhrase("value")).count().next());
assertEquals(1, graph.traversal().V().has("name", Text.textNotContainsPhrase("other value")).count().next());
assertEquals(2, graph.traversal().V().has("name", Text.textNotContainsPhrase("final value")).count().next());
}
Aggregations