Search in sources :

Example 76 with JanusGraphManagement

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!");
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement)

Example 77 with JanusGraphManagement

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();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) HashMap(java.util.HashMap) Method(java.lang.reflect.Method) WindupFrame(org.jboss.windup.graph.model.WindupFrame) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) Map(java.util.Map) HashMap(java.util.HashMap) PropertyKey(org.janusgraph.core.PropertyKey)

Example 78 with JanusGraphManagement

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");
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) GraphEdgePropertiesDictionary(org.openecomp.sdc.be.dao.neo4j.GraphEdgePropertiesDictionary) PropertyKey(org.janusgraph.core.PropertyKey)

Example 79 with JanusGraphManagement

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();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) GraphPropertiesDictionary(org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey)

Example 80 with JanusGraphManagement

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");
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) GraphPropertiesDictionary(org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey)

Aggregations

JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)92 PropertyKey (org.janusgraph.core.PropertyKey)44 Test (org.junit.jupiter.api.Test)26 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)24 JanusGraph (org.janusgraph.core.JanusGraph)23 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)20 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)17 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)12 HashMap (java.util.HashMap)9 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)9 ArrayList (java.util.ArrayList)8 Before (org.junit.Before)8 Test (org.junit.Test)8 JanusGraphDBEngine (org.onap.aai.serialization.engines.JanusGraphDBEngine)8 TransactionalGraphEngine (org.onap.aai.serialization.engines.TransactionalGraphEngine)8 JanusGraphBaseTest (org.janusgraph.graphdb.JanusGraphBaseTest)7 RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)6 EdgeLabel (org.janusgraph.core.EdgeLabel)6 Map (java.util.Map)5 JanusGraphException (org.janusgraph.core.JanusGraphException)5