Search in sources :

Example 41 with JanusGraphManagement

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

the class ManagementTest method testReservedNamesRejectedForVertexLabels.

@Test
public void testReservedNamesRejectedForVertexLabels() {
    for (String s : ILLEGAL_USER_DEFINED_NAMES) {
        JanusGraphManagement tm = graph.openManagement();
        try {
            tm.makeVertexLabel(s);
            fail("Vertex label \"" + s + "\" must be rejected");
        } catch (IllegalArgumentException e) {
            log.debug("Caught expected exception", e);
        } finally {
            tm.commit();
        }
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Test(org.junit.jupiter.api.Test) JanusGraphBaseTest(org.janusgraph.graphdb.JanusGraphBaseTest)

Example 42 with JanusGraphManagement

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

the class ManagementTest method testReservedNamesRejectedForPropertyKeys.

@Test
public void testReservedNamesRejectedForPropertyKeys() {
    for (String s : ILLEGAL_USER_DEFINED_NAMES) {
        JanusGraphManagement tm = graph.openManagement();
        try {
            tm.makePropertyKey(s);
            fail("Property key  \"" + s + "\" must be rejected");
        } catch (IllegalArgumentException e) {
            log.debug("Caught expected exception", e);
        } finally {
            tm.commit();
        }
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Test(org.junit.jupiter.api.Test) JanusGraphBaseTest(org.janusgraph.graphdb.JanusGraphBaseTest)

Example 43 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project sunbird-rc-core by Sunbird-RC.

the class JanusGraphStorage method createIndex.

@Override
public void createIndex(Graph graph, String label, List<String> propertyNames) {
    if (propertyNames.size() > 0) {
        List<JanusGraphIndex> graphIndexList = new ArrayList<>();
        VertexLabel vlabel = ((JanusGraph) graph).getVertexLabel(label);
        graph.tx().commit();
        JanusGraphManagement janusGraphManagement = ((JanusGraph) graph).openManagement();
        propertyNames.forEach(propertyName -> {
            PropertyKey propertyKey = janusGraphManagement.getPropertyKey(propertyName);
            JanusGraphIndex graphIndex = janusGraphManagement.buildIndex(vlabel.name() + propertyKey.toString(), Vertex.class).addKey(propertyKey).buildCompositeIndex();
            graphIndexList.add(graphIndex);
        });
        janusGraphManagement.commit();
    } else {
        logger.info("Could not create single index for empty properties");
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) VertexLabel(org.janusgraph.core.VertexLabel) JanusGraph(org.janusgraph.core.JanusGraph) ArrayList(java.util.ArrayList) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey)

Example 44 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project sunbird-rc-core by Sunbird-RC.

the class JanusGraphStorage method createUniqueIndex.

@Override
public void createUniqueIndex(Graph graph, String label, List<String> propertyNames) {
    if (propertyNames.size() > 0) {
        List<JanusGraphIndex> graphIndexList = new ArrayList<>();
        VertexLabel vlabel = ((JanusGraph) graph).getVertexLabel(label);
        graph.tx().commit();
        JanusGraphManagement janusGraphManagement = ((JanusGraph) graph).openManagement();
        propertyNames.forEach(propertyName -> {
            PropertyKey propertyKey = janusGraphManagement.getPropertyKey(propertyName);
            JanusGraphIndex graphIndex = janusGraphManagement.buildIndex(vlabel.name() + propertyKey.toString(), Vertex.class).addKey(propertyKey).unique().buildCompositeIndex();
            graphIndexList.add(graphIndex);
        });
        janusGraphManagement.commit();
    } else {
        logger.info("Could not create unique index for empty properties");
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexLabel(org.janusgraph.core.VertexLabel) JanusGraph(org.janusgraph.core.JanusGraph) ArrayList(java.util.ArrayList) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey)

Example 45 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project atlas by apache.

the class AtlasJanusGraphManagement method updateSchemaStatus.

public static void updateSchemaStatus(JanusGraphManagement mgmt, JanusGraph graph, Class<? extends Element> elementType) {
    LOG.info("updating SchemaStatus for {}: Starting...", elementType.getSimpleName());
    int count = 0;
    Iterable<JanusGraphIndex> iterable = mgmt.getGraphIndexes(elementType);
    for (JanusGraphIndex index : iterable) {
        if (index.isCompositeIndex()) {
            PropertyKey[] propertyKeys = index.getFieldKeys();
            SchemaStatus status = index.getIndexStatus(propertyKeys[0]);
            String indexName = index.name();
            try {
                if (status == REGISTERED) {
                    JanusGraphManagement management = graph.openManagement();
                    JanusGraphIndex indexToUpdate = management.getGraphIndex(indexName);
                    management.updateIndex(indexToUpdate, ENABLE_INDEX).get();
                    management.commit();
                    GraphIndexStatusReport report = ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(ENABLED).call();
                    if (!report.getConvergedKeys().isEmpty() && report.getConvergedKeys().containsKey(indexName)) {
                        LOG.info("SchemaStatus updated for index: {}, from {} to {}.", index.name(), REGISTERED, ENABLED);
                        count++;
                    } else if (!report.getNotConvergedKeys().isEmpty() && report.getNotConvergedKeys().containsKey(indexName)) {
                        LOG.error("SchemaStatus failed to update index: {}, from {} to {}.", index.name(), REGISTERED, ENABLED);
                    }
                } else if (status == INSTALLED) {
                    LOG.warn("SchemaStatus {} found for index: {}", INSTALLED, indexName);
                }
            } catch (InterruptedException e) {
                LOG.error("IllegalStateException for indexName : {}, Exception: ", indexName, e);
            } catch (ExecutionException e) {
                LOG.error("ExecutionException for indexName : {}, Exception: ", indexName, e);
            }
        }
    }
    LOG.info("updating SchemaStatus for {}: {}: Done!", elementType.getSimpleName(), count);
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) GraphIndexStatusReport(org.janusgraph.graphdb.database.management.GraphIndexStatusReport) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) ExecutionException(java.util.concurrent.ExecutionException) SchemaStatus(org.janusgraph.core.schema.SchemaStatus) AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) 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