use of com.thinkaurelius.titan.core.PropertyKey in project incubator-atlas by apache.
the class Titan1GraphManagement method addVertexIndexKey.
@Override
public void addVertexIndexKey(String indexName, AtlasPropertyKey propertyKey) {
PropertyKey titanKey = TitanObjectFactory.createPropertyKey(propertyKey);
TitanGraphIndex vertexIndex = management.getGraphIndex(indexName);
management.addIndexKey(vertexIndex, titanKey);
}
use of com.thinkaurelius.titan.core.PropertyKey in project incubator-atlas by apache.
the class Titan1GraphManagement method createVertexIndex.
@Override
public void createVertexIndex(String propertyName, String backingIndex, List<AtlasPropertyKey> propertyKeys) {
TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);
for (AtlasPropertyKey key : propertyKeys) {
PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key);
indexBuilder.addKey(titanKey);
}
indexBuilder.buildMixedIndex(backingIndex);
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class GraphOfTheGodsFactory method load.
public static void load(final TitanGraph graph, String mixedIndexName, boolean uniqueNameCompositeIndex) {
//Create Schema
TitanManagement mgmt = graph.openManagement();
final PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
TitanManagement.IndexBuilder nameIndexBuilder = mgmt.buildIndex("name", Vertex.class).addKey(name);
if (uniqueNameCompositeIndex)
nameIndexBuilder.unique();
TitanGraphIndex namei = nameIndexBuilder.buildCompositeIndex();
mgmt.setConsistency(namei, ConsistencyModifier.LOCK);
final PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
if (null != mixedIndexName)
mgmt.buildIndex("vertices", Vertex.class).addKey(age).buildMixedIndex(mixedIndexName);
final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
final PropertyKey reason = mgmt.makePropertyKey("reason").dataType(String.class).make();
final PropertyKey place = mgmt.makePropertyKey("place").dataType(Geoshape.class).make();
if (null != mixedIndexName)
mgmt.buildIndex("edges", Edge.class).addKey(reason).addKey(place).buildMixedIndex(mixedIndexName);
mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
mgmt.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make();
EdgeLabel battled = mgmt.makeEdgeLabel("battled").signature(time).make();
mgmt.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.decr, time);
mgmt.makeEdgeLabel("lives").signature(reason).make();
mgmt.makeEdgeLabel("pet").make();
mgmt.makeEdgeLabel("brother").make();
mgmt.makeVertexLabel("titan").make();
mgmt.makeVertexLabel("location").make();
mgmt.makeVertexLabel("god").make();
mgmt.makeVertexLabel("demigod").make();
mgmt.makeVertexLabel("human").make();
mgmt.makeVertexLabel("monster").make();
mgmt.commit();
TitanTransaction tx = graph.newTransaction();
// vertices
Vertex saturn = tx.addVertex(T.label, "titan", "name", "saturn", "age", 10000);
Vertex sky = tx.addVertex(T.label, "location", "name", "sky");
Vertex sea = tx.addVertex(T.label, "location", "name", "sea");
Vertex jupiter = tx.addVertex(T.label, "god", "name", "jupiter", "age", 5000);
Vertex neptune = tx.addVertex(T.label, "god", "name", "neptune", "age", 4500);
Vertex hercules = tx.addVertex(T.label, "demigod", "name", "hercules", "age", 30);
Vertex alcmene = tx.addVertex(T.label, "human", "name", "alcmene", "age", 45);
Vertex pluto = tx.addVertex(T.label, "god", "name", "pluto", "age", 4000);
Vertex nemean = tx.addVertex(T.label, "monster", "name", "nemean");
Vertex hydra = tx.addVertex(T.label, "monster", "name", "hydra");
Vertex cerberus = tx.addVertex(T.label, "monster", "name", "cerberus");
Vertex tartarus = tx.addVertex(T.label, "location", "name", "tartarus");
// edges
jupiter.addEdge("father", saturn);
jupiter.addEdge("lives", sky, "reason", "loves fresh breezes");
jupiter.addEdge("brother", neptune);
jupiter.addEdge("brother", pluto);
neptune.addEdge("lives", sea).property("reason", "loves waves");
neptune.addEdge("brother", jupiter);
neptune.addEdge("brother", pluto);
hercules.addEdge("father", jupiter);
hercules.addEdge("mother", alcmene);
hercules.addEdge("battled", nemean, "time", 1, "place", Geoshape.point(38.1f, 23.7f));
hercules.addEdge("battled", hydra, "time", 2, "place", Geoshape.point(37.7f, 23.9f));
hercules.addEdge("battled", cerberus, "time", 12, "place", Geoshape.point(39f, 22f));
pluto.addEdge("brother", jupiter);
pluto.addEdge("brother", neptune);
pluto.addEdge("lives", tartarus, "reason", "no fear of death");
pluto.addEdge("pet", cerberus);
cerberus.addEdge("lives", tartarus);
// commit the transaction to disk
tx.commit();
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
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(status, "Target status must not be null");
Map<String, SchemaStatus> notConverged = new HashMap<>();
Map<String, SchemaStatus> converged = new HashMap<>();
TitanGraphIndex idx;
Timer t = new Timer(TimestampProviders.MILLI).start();
boolean timedOut;
while (true) {
TitanManagement mgmt = null;
try {
mgmt = g.openManagement();
idx = mgmt.getGraphIndex(graphIndexName);
for (PropertyKey pk : idx.getFieldKeys()) {
SchemaStatus s = idx.getIndexStatus(pk);
LOGGER.debug("Key {} has status {}", pk, s);
if (!status.equals(s))
notConverged.put(pk.toString(), s);
else
converged.put(pk.toString(), s);
}
} finally {
if (null != mgmt)
// Let an exception here propagate up the stack
mgmt.rollback();
}
String waitingOn = Joiner.on(",").withKeyValueSeparator("=").join(notConverged);
if (!notConverged.isEmpty()) {
LOGGER.info("Some key(s) on index {} do not currently have status {}: {}", graphIndexName, status, waitingOn);
} else {
LOGGER.info("All {} key(s) on index {} have status {}", converged.size(), graphIndexName, status);
return new GraphIndexStatusReport(true, graphIndexName, status, 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 {}", timeout, graphIndexName, status);
return new GraphIndexStatusReport(false, graphIndexName, status, notConverged, converged, t.elapsed());
}
notConverged.clear();
converged.clear();
Thread.sleep(poll.toMillis());
}
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class ManagementSystem method buildRelationTypeIndex.
private RelationTypeIndex buildRelationTypeIndex(RelationType type, String name, Direction direction, Order sortOrder, PropertyKey... sortKeys) {
Preconditions.checkArgument(type != null && direction != null && sortOrder != null && sortKeys != null);
Preconditions.checkArgument(StringUtils.isNotBlank(name), "Name cannot be blank: %s", name);
Token.verifyName(name);
Preconditions.checkArgument(sortKeys.length > 0, "Need to specify sort keys");
for (RelationType key : sortKeys) Preconditions.checkArgument(key != null, "Keys cannot be null");
Preconditions.checkArgument(!(type instanceof EdgeLabel) || !((EdgeLabel) type).isUnidirected() || direction == Direction.OUT, "Can only index uni-directed labels in the out-direction: %s", type);
Preconditions.checkArgument(!((InternalRelationType) type).multiplicity().isConstrained(direction), "The relation type [%s] has a multiplicity or cardinality constraint in direction [%s] and can therefore not be indexed", type, direction);
String composedName = composeRelationTypeIndexName(type, name);
StandardRelationTypeMaker maker;
if (type.isEdgeLabel()) {
StandardEdgeLabelMaker lm = (StandardEdgeLabelMaker) transaction.makeEdgeLabel(composedName);
lm.unidirected(direction);
maker = lm;
} else {
assert type.isPropertyKey();
assert direction == Direction.OUT;
StandardPropertyKeyMaker lm = (StandardPropertyKeyMaker) transaction.makePropertyKey(composedName);
lm.dataType(((PropertyKey) type).dataType());
maker = lm;
}
maker.status(type.isNew() ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);
maker.invisible();
maker.multiplicity(Multiplicity.MULTI);
maker.sortKey(sortKeys);
maker.sortOrder(sortOrder);
//Compose signature
long[] typeSig = ((InternalRelationType) type).getSignature();
Set<PropertyKey> signature = Sets.newHashSet();
for (long typeId : typeSig) signature.add(transaction.getExistingPropertyKey(typeId));
for (RelationType sortType : sortKeys) signature.remove(sortType);
if (!signature.isEmpty()) {
PropertyKey[] sig = signature.toArray(new PropertyKey[signature.size()]);
maker.signature(sig);
}
RelationType typeIndex = maker.make();
addSchemaEdge(type, typeIndex, TypeDefinitionCategory.RELATIONTYPE_INDEX, null);
RelationTypeIndexWrapper index = new RelationTypeIndexWrapper((InternalRelationType) typeIndex);
if (!type.isNew())
updateIndex(index, SchemaAction.REGISTER_INDEX);
return index;
}
Aggregations