Search in sources :

Example 56 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.

the class ConfigurationManagementGraphTest method shouldCloseAllTxsIfIndexExists.

@Test
public void shouldCloseAllTxsIfIndexExists() {
    final StandardJanusGraph graph = (StandardJanusGraph) JanusGraphFactory.open("inmemory");
    // Emulate ConfigurationManagementGraph indices already exists
    JanusGraphManagement management = graph.openManagement();
    PropertyKey key = management.makePropertyKey("some_property").dataType(String.class).make();
    management.buildIndex("Created_Using_Template_Index", Vertex.class).addKey(key).buildCompositeIndex();
    management.buildIndex("Template_Index", Vertex.class).addKey(key).buildCompositeIndex();
    management.buildIndex("Graph_Name_Index", Vertex.class).addKey(key).buildCompositeIndex();
    management.commit();
    new ConfigurationManagementGraph(graph);
    assertEquals(0, graph.getOpenTransactions().size());
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) PropertyKey(org.janusgraph.core.PropertyKey) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Example 57 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project grakn by graknlabs.

the class TxFactoryJanus method makeIndicesVertexCentric.

private static void makeIndicesVertexCentric(JanusGraphManagement management) {
    ResourceBundle keys = ResourceBundle.getBundle("indices-edges");
    Set<String> edgeLabels = keys.keySet();
    for (String edgeLabel : edgeLabels) {
        String[] propertyKeyStrings = keys.getString(edgeLabel).split(",");
        // Get all the property keys we need
        Set<PropertyKey> propertyKeys = stream(propertyKeyStrings).map(keyId -> {
            PropertyKey key = management.getPropertyKey(keyId);
            if (key == null) {
                throw new RuntimeException("Trying to create edge index on label [" + edgeLabel + "] but the property [" + keyId + "] does not exist");
            }
            return key;
        }).collect(Collectors.toSet());
        // Get the edge and indexing information
        RelationType relationType = management.getRelationType(edgeLabel);
        EdgeLabel label = management.getEdgeLabel(edgeLabel);
        // Create index on each property key
        for (PropertyKey key : propertyKeys) {
            if (management.getRelationIndex(relationType, edgeLabel + "by" + key.name()) == null) {
                management.buildEdgeIndex(label, edgeLabel + "by" + key.name(), Direction.BOTH, Order.decr, key);
            }
        }
        // Create index on all property keys
        String propertyKeyId = propertyKeys.stream().map(Namifiable::name).collect(Collectors.joining("_"));
        if (management.getRelationIndex(relationType, edgeLabel + "by" + propertyKeyId) == null) {
            PropertyKey[] allKeys = propertyKeys.toArray(new PropertyKey[propertyKeys.size()]);
            management.buildEdgeIndex(label, edgeLabel + "by" + propertyKeyId, Direction.BOTH, Order.decr, allKeys);
        }
    }
}
Also used : TraversalStrategies(org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResourceBundle(java.util.ResourceBundle) JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) GraknTx(ai.grakn.GraknTx) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) Map(java.util.Map) ErrorMessage(ai.grakn.util.ErrorMessage) PathRetractionStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.PathRetractionStrategy) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) RelationType(org.janusgraph.core.RelationType) Namifiable(org.janusgraph.core.Namifiable) Logger(org.slf4j.Logger) Properties(java.util.Properties) ImmutableMap(com.google.common.collect.ImmutableMap) JanusGraphFactory(org.janusgraph.core.JanusGraphFactory) PropertyKey(org.janusgraph.core.PropertyKey) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Set(java.util.Set) IOException(java.io.IOException) LazyBarrierStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.LazyBarrierStrategy) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraph(org.janusgraph.core.JanusGraph) Collectors(java.util.stream.Collectors) GraknConfigKey(ai.grakn.GraknConfigKey) Direction(org.apache.tinkerpop.gremlin.structure.Direction) VertexLabel(org.janusgraph.core.VertexLabel) Schema(ai.grakn.util.Schema) Arrays.stream(java.util.Arrays.stream) GraknTxJanus(ai.grakn.kb.internal.GraknTxJanus) InputStream(java.io.InputStream) RelationType(org.janusgraph.core.RelationType) EdgeLabel(org.janusgraph.core.EdgeLabel) ResourceBundle(java.util.ResourceBundle) PropertyKey(org.janusgraph.core.PropertyKey)

Example 58 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project grakn by graknlabs.

the class TxFactoryJanus method makeIndicesComposite.

private static void makeIndicesComposite(JanusGraphManagement management) {
    ResourceBundle keys = ResourceBundle.getBundle("indices-composite");
    Set<String> keyString = keys.keySet();
    for (String propertyKeyLabel : keyString) {
        String indexLabel = "by" + propertyKeyLabel;
        JanusGraphIndex index = management.getGraphIndex(indexLabel);
        if (index == null) {
            boolean isUnique = Boolean.parseBoolean(keys.getString(propertyKeyLabel));
            PropertyKey key = management.getPropertyKey(propertyKeyLabel);
            JanusGraphManagement.IndexBuilder indexBuilder = management.buildIndex(indexLabel, Vertex.class).addKey(key);
            if (isUnique) {
                indexBuilder.unique();
            }
            indexBuilder.buildCompositeIndex();
        }
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ResourceBundle(java.util.ResourceBundle) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey)

Example 59 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project grakn by graknlabs.

the class TxFactoryJanus method buildJanusIndexes.

private static void buildJanusIndexes(JanusGraph graph) {
    JanusGraphManagement management = graph.openManagement();
    makeVertexLabels(management);
    makeEdgeLabels(management);
    makePropertyKeys(management);
    makeIndicesVertexCentric(management);
    makeIndicesComposite(management);
    management.commit();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement)

Example 60 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project grakn by graknlabs.

the class TxFactoryJanusTest method testGraphConfig.

@Test
public void testGraphConfig() throws InterruptedException {
    JanusGraphManagement management = sharedGraph.openManagement();
    // Test Composite Indices
    String byId = "by" + Schema.VertexProperty.ID.name();
    String byIndex = "by" + Schema.VertexProperty.INDEX.name();
    String byValueString = "by" + Schema.VertexProperty.VALUE_STRING.name();
    String byValueLong = "by" + Schema.VertexProperty.VALUE_LONG.name();
    String byValueDouble = "by" + Schema.VertexProperty.VALUE_DOUBLE.name();
    String byValueBoolean = "by" + Schema.VertexProperty.VALUE_BOOLEAN.name();
    assertEquals(byId, management.getGraphIndex(byId).toString());
    assertEquals(byIndex, management.getGraphIndex(byIndex).toString());
    assertEquals(byValueString, management.getGraphIndex(byValueString).toString());
    assertEquals(byValueLong, management.getGraphIndex(byValueLong).toString());
    assertEquals(byValueDouble, management.getGraphIndex(byValueDouble).toString());
    assertEquals(byValueBoolean, management.getGraphIndex(byValueBoolean).toString());
    // Text Edge Indices
    ResourceBundle keys = ResourceBundle.getBundle("indices-edges");
    Set<String> keyString = keys.keySet();
    for (String label : keyString) {
        assertNotNull(management.getEdgeLabel(label));
    }
    // Test Properties
    Arrays.stream(Schema.VertexProperty.values()).forEach(property -> assertNotNull(management.getPropertyKey(property.name())));
    Arrays.stream(Schema.EdgeProperty.values()).forEach(property -> assertNotNull(management.getPropertyKey(property.name())));
    // Test Labels
    Arrays.stream(Schema.BaseType.values()).forEach(label -> assertNotNull(management.getVertexLabel(label.name())));
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) ResourceBundle(java.util.ResourceBundle) Test(org.junit.Test)

Aggregations

JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)66 PropertyKey (org.janusgraph.core.PropertyKey)37 Test (org.junit.jupiter.api.Test)26 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)19 JanusGraph (org.janusgraph.core.JanusGraph)17 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)13 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)12 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)9 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)9 HashMap (java.util.HashMap)8 JanusGraphBaseTest (org.janusgraph.graphdb.JanusGraphBaseTest)7 RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 JanusGraphException (org.janusgraph.core.JanusGraphException)5 EdgeLabel (org.janusgraph.core.EdgeLabel)4 ScanMetrics (org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics)4 GraphPropertiesDictionary (org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary)4 ResourceBundle (java.util.ResourceBundle)3 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)3