use of org.janusgraph.core.schema.JanusGraphManagement in project atlas by apache.
the class AtlasJanusGraphDatabase method validateIndexBackend.
static void validateIndexBackend(Configuration config) {
String configuredIndexBackend = config.getString(INDEX_BACKEND_CONF);
JanusGraphManagement managementSystem = getGraphInstance().openManagement();
String currentIndexBackend = managementSystem.get(INDEX_BACKEND_CONF);
managementSystem.commit();
if (!configuredIndexBackend.equals(currentIndexBackend)) {
throw new RuntimeException("Configured Index Backend " + configuredIndexBackend + " differs from earlier configured Index Backend " + currentIndexBackend + ". Aborting!");
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project windup by windup.
the class GraphContextImpl method initializeJanusIndexes.
private void initializeJanusIndexes(JanusGraph janusGraph) {
Map<String, IndexData> defaultIndexKeys = new HashMap<>();
Map<String, IndexData> searchIndexKeys = new HashMap<>();
Map<String, IndexData> listIndexKeys = new HashMap<>();
Set<Class<? extends WindupFrame<?>>> modelTypes = graphTypeManager.getRegisteredTypes();
for (Class<? extends WindupFrame<?>> type : modelTypes) {
for (Method method : type.getDeclaredMethods()) {
List<Indexed> annotations = getIndexAnnotations(method);
for (Indexed index : annotations) {
Property property = Annotations.getAnnotation(method, Property.class);
if (property != null) {
Class<?> dataType = index.dataType();
switch(index.value()) {
case DEFAULT:
defaultIndexKeys.put(property.value(), new IndexData(property.value(), index.name(), dataType));
break;
case SEARCH:
searchIndexKeys.put(property.value(), new IndexData(property.value(), index.name(), dataType));
break;
case LIST:
listIndexKeys.put(property.value(), new IndexData(property.value(), index.name(), dataType));
break;
default:
break;
}
}
}
}
}
/*
* This is the root Model index that enables us to query on frame-type (by subclass type, etc.) Without this, every typed query would be slow.
* Do not remove this unless something really paradigm-shifting has happened.
*/
listIndexKeys.put(WindupVertexFrame.TYPE_PROP, new IndexData(WindupVertexFrame.TYPE_PROP, "", String.class));
LOG.info("Detected and initialized [" + defaultIndexKeys.size() + "] default indexes: " + defaultIndexKeys);
LOG.info("Detected and initialized [" + searchIndexKeys.size() + "] search indexes: " + searchIndexKeys);
LOG.info("Detected and initialized [" + listIndexKeys.size() + "] list indexes: " + listIndexKeys);
JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
for (Map.Entry<String, IndexData> entry : defaultIndexKeys.entrySet()) {
String key = entry.getKey();
IndexData indexData = entry.getValue();
Class<?> dataType = indexData.type;
PropertyKey propKey = getOrCreatePropertyKey(janusGraphManagement, key, dataType, Cardinality.SINGLE);
janusGraphManagement.buildIndex(indexData.getIndexName(), Vertex.class).addKey(propKey).buildCompositeIndex();
}
for (Map.Entry<String, IndexData> entry : searchIndexKeys.entrySet()) {
String key = entry.getKey();
IndexData indexData = entry.getValue();
Class<?> dataType = indexData.type;
if (dataType == String.class) {
PropertyKey propKey = getOrCreatePropertyKey(janusGraphManagement, key, String.class, Cardinality.SINGLE);
janusGraphManagement.buildIndex(indexData.getIndexName(), Vertex.class).addKey(propKey, Mapping.STRING.asParameter()).buildMixedIndex("search");
} else {
PropertyKey propKey = getOrCreatePropertyKey(janusGraphManagement, key, dataType, Cardinality.SINGLE);
janusGraphManagement.buildIndex(indexData.getIndexName(), Vertex.class).addKey(propKey).buildMixedIndex("search");
}
}
for (Map.Entry<String, IndexData> entry : listIndexKeys.entrySet()) {
String key = entry.getKey();
IndexData indexData = entry.getValue();
Class<?> dataType = indexData.type;
PropertyKey propKey = getOrCreatePropertyKey(janusGraphManagement, key, dataType, Cardinality.LIST);
janusGraphManagement.buildIndex(indexData.getIndexName(), Vertex.class).addKey(propKey).buildCompositeIndex();
}
// Titan enforces items to be String, but there can be multiple items under one property name.
String indexName = "edge-typevalue";
PropertyKey propKey = getOrCreatePropertyKey(janusGraphManagement, WindupEdgeFrame.TYPE_PROP, String.class, Cardinality.LIST);
janusGraphManagement.buildIndex(indexName, Edge.class).addKey(propKey).buildCompositeIndex();
janusGraphManagement.commit();
}
use of org.janusgraph.core.schema.JanusGraphManagement in project sdc by onap.
the class JanusGraphInitializer method createEdgeIndixes.
private static void createEdgeIndixes() {
logger.info("** createEdgeIndixes started");
JanusGraphManagement graphMgt = graph.openManagement();
for (GraphEdgePropertiesDictionary prop : GraphEdgePropertiesDictionary.values()) {
if (!graphMgt.containsGraphIndex(prop.getProperty())) {
PropertyKey propKey = graphMgt.makePropertyKey(prop.getProperty()).dataType(prop.getClazz()).make();
graphMgt.buildIndex(prop.getProperty(), Edge.class).addKey(propKey).buildCompositeIndex();
}
}
graphMgt.commit();
logger.info("** createEdgeIndixes ended");
}
use of org.janusgraph.core.schema.JanusGraphManagement in project sdc by onap.
the class JanusGraphClient method createJanusGraphSchema.
private void createJanusGraphSchema() {
JanusGraphManagement graphMgt = graph.openManagement();
JanusGraphIndex index = null;
for (GraphPropertiesDictionary prop : GraphPropertiesDictionary.values()) {
PropertyKey propKey = null;
if (!graphMgt.containsPropertyKey(prop.getProperty())) {
Class<?> clazz = prop.getClazz();
if (!clazz.isAssignableFrom(ArrayList.class) && !clazz.isAssignableFrom(HashMap.class)) {
propKey = graphMgt.makePropertyKey(prop.getProperty()).dataType(prop.getClazz()).make();
}
} else {
propKey = graphMgt.getPropertyKey(prop.getProperty());
}
if (prop.isIndexed() && !graphMgt.containsGraphIndex(prop.getProperty())) {
if (prop.isUnique()) {
index = graphMgt.buildIndex(prop.getProperty(), Vertex.class).addKey(propKey).unique().buildCompositeIndex();
// Ensures only one name per vertex
graphMgt.setConsistency(propKey, ConsistencyModifier.LOCK);
// Ensures name uniqueness in the graph
graphMgt.setConsistency(index, ConsistencyModifier.LOCK);
} else {
graphMgt.buildIndex(prop.getProperty(), Vertex.class).addKey(propKey).buildCompositeIndex();
}
}
}
graphMgt.commit();
}
use of org.janusgraph.core.schema.JanusGraphManagement in project sdc by onap.
the class JanusGraphTestSetup method createVertexIndixes.
private static void createVertexIndixes() {
logger.info("** createVertexIndixes started");
JanusGraphManagement graphMgt = graph.openManagement();
JanusGraphIndex index = null;
for (GraphPropertiesDictionary prop : GraphPropertiesDictionary.values()) {
PropertyKey propKey = null;
if (!graphMgt.containsPropertyKey(prop.getProperty())) {
Class<?> clazz = prop.getClazz();
if (!ArrayList.class.getName().equals(clazz.getName()) && !HashMap.class.getName().equals(clazz.getName())) {
propKey = graphMgt.makePropertyKey(prop.getProperty()).dataType(prop.getClazz()).make();
}
} else {
propKey = graphMgt.getPropertyKey(prop.getProperty());
}
if (prop.isIndexed()) {
if (!graphMgt.containsGraphIndex(prop.getProperty())) {
if (prop.isUnique()) {
index = graphMgt.buildIndex(prop.getProperty(), Vertex.class).addKey(propKey).unique().buildCompositeIndex();
// Ensures
graphMgt.setConsistency(propKey, ConsistencyModifier.LOCK);
// only
// one
// name
// per
// vertex
// Ensures
graphMgt.setConsistency(index, ConsistencyModifier.LOCK);
// name
// uniqueness
// in
// the
// graph
} else {
graphMgt.buildIndex(prop.getProperty(), Vertex.class).addKey(propKey).buildCompositeIndex();
}
}
}
}
graphMgt.commit();
logger.info("** createVertexIndixes ended");
}
Aggregations