Search in sources :

Example 31 with PropertyKey

use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.

the class AbstractIndexManagementIT method testRepairGraphIndex.

@Test
public void testRepairGraphIndex() throws InterruptedException, BackendException, ExecutionException {
    tx.commit();
    mgmt.commit();
    // Load the "Graph of the Gods" sample data (WITHOUT mixed index coverage)
    GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);
    // Create and enable a graph index on age
    JanusGraphManagement m = graph.openManagement();
    PropertyKey age = m.getPropertyKey("age");
    m.buildIndex("verticesByAge", Vertex.class).addKey(age).buildCompositeIndex();
    m.commit();
    graph.tx().commit();
    // Block until the SchemaStatus transitions to REGISTERED
    assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "verticesByAge").status(SchemaStatus.REGISTERED).call().getSucceeded());
    m = graph.openManagement();
    JanusGraphIndex index = m.getGraphIndex("verticesByAge");
    m.updateIndex(index, SchemaAction.ENABLE_INDEX);
    m.commit();
    graph.tx().commit();
    // Block until the SchemaStatus transitions to ENABLED
    assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "verticesByAge").status(SchemaStatus.ENABLED).call().getSucceeded());
    // Run a query that hits the index but erroneously returns nothing because we haven't repaired yet
    assertFalse(graph.query().has("age", 10000).vertices().iterator().hasNext());
    // Repair
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    index = m.getGraphIndex("verticesByAge");
    ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REINDEX).get();
    assertEquals(6, metrics.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
    // Test the index
    Iterable<JanusGraphVertex> hits = graph.query().has("age", 4500).vertices();
    assertNotNull(hits);
    assertEquals(1, Iterables.size(hits));
    JanusGraphVertex v = Iterables.getOnlyElement(hits);
    assertNotNull(v);
    assertEquals("neptune", v.value("name"));
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test) JanusGraphBaseTest(org.janusgraph.graphdb.JanusGraphBaseTest)

Example 32 with PropertyKey

use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.

the class SaslAndHMACAuthenticatorTest method testSetupEmptyCredGraphNoUserIndex.

@Test
public void testSetupEmptyCredGraphNoUserIndex() {
    final SaslAndHMACAuthenticator authenticator = createMockBuilder(SaslAndHMACAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").addMockedMethod("createHMACAuthenticator").createMock();
    final Map<String, Object> configMap = new HashMap<String, Object>();
    configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
    configMap.put(SaslAndHMACAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    configMap.put(SaslAndHMACAuthenticator.CONFIG_DEFAULT_USER, "user");
    final JanusGraph graph = createMock(JanusGraph.class);
    final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
    final ManagementSystem mgmt = createMock(ManagementSystem.class);
    final JanusGraphSimpleAuthenticator janusSimpleAuthenticator = createMock(JanusGraphSimpleAuthenticator.class);
    final HMACAuthenticator hmacAuthenticator = createMock(HMACAuthenticator.class);
    final SimpleAuthenticator simpleAuthenticator = createMock(SimpleAuthenticator.class);
    final Transaction tx = createMock(Transaction.class);
    final PropertyKey pk = createMock(PropertyKey.class);
    final PropertyKeyMaker pkm = createMock(PropertyKeyMaker.class);
    final JanusGraphManagement.IndexBuilder indexBuilder = createMock(JanusGraphManagement.IndexBuilder.class);
    final JanusGraphIndex index = createMock(JanusGraphIndex.class);
    final PropertyKey[] pks = { pk };
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(authenticator.createSimpleAuthenticator()).andReturn(janusSimpleAuthenticator);
    expect(authenticator.createHMACAuthenticator()).andReturn(hmacAuthenticator);
    hmacAuthenticator.setup(configMap);
    expectLastCall();
    expect(janusSimpleAuthenticator.createSimpleAuthenticator()).andReturn(simpleAuthenticator);
    simpleAuthenticator.setup(configMap);
    expectLastCall();
    expect(credentialGraph.findUser("user")).andReturn(null);
    expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
    expect(graph.openManagement()).andReturn(mgmt).times(2);
    expect(graph.tx()).andReturn(tx);
    expect(index.getFieldKeys()).andReturn(pks);
    expect(index.getIndexStatus(eq(pk))).andReturn(SchemaStatus.ENABLED);
    tx.rollback();
    expectLastCall();
    expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(false);
    expect(mgmt.makePropertyKey(PROPERTY_USERNAME)).andReturn(pkm);
    expect(pkm.dataType(eq(String.class))).andReturn(pkm);
    expect(pkm.cardinality(Cardinality.SINGLE)).andReturn(pkm);
    expect(pkm.make()).andReturn(pk);
    expect(mgmt.buildIndex(eq("byUsername"), eq(Vertex.class))).andReturn(indexBuilder);
    expect(mgmt.getGraphIndex(eq("byUsername"))).andReturn(index);
    expect(indexBuilder.addKey(eq(pk))).andReturn(indexBuilder);
    expect(indexBuilder.unique()).andReturn(indexBuilder);
    expect(indexBuilder.buildCompositeIndex()).andReturn(index);
    mgmt.commit();
    expectLastCall();
    mgmt.rollback();
    expectLastCall();
    replayAll();
    authenticator.setup(configMap);
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) HashMap(java.util.HashMap) JanusGraph(org.janusgraph.core.JanusGraph) ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) PropertyKeyMaker(org.janusgraph.core.schema.PropertyKeyMaker) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) SimpleAuthenticator(org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 33 with PropertyKey

use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.

the class AbstractJanusGraphProvider method createIndices.

private void createIndices(final JanusGraph g, final LoadGraphWith.GraphData graphData) {
    JanusGraphManagement management = g.openManagement();
    if (graphData.equals(LoadGraphWith.GraphData.GRATEFUL)) {
        VertexLabel artist = management.makeVertexLabel("artist").make();
        VertexLabel song = management.makeVertexLabel("song").make();
        PropertyKey name = management.makePropertyKey("name").cardinality(Cardinality.LIST).dataType(String.class).make();
        PropertyKey songType = management.makePropertyKey("songType").cardinality(Cardinality.LIST).dataType(String.class).make();
        PropertyKey performances = management.makePropertyKey("performances").cardinality(Cardinality.LIST).dataType(Integer.class).make();
        management.buildIndex("artistByName", Vertex.class).addKey(name).indexOnly(artist).buildCompositeIndex();
        management.buildIndex("songByName", Vertex.class).addKey(name).indexOnly(song).buildCompositeIndex();
        management.buildIndex("songByType", Vertex.class).addKey(songType).indexOnly(song).buildCompositeIndex();
        management.buildIndex("songByPerformances", Vertex.class).addKey(performances).indexOnly(song).buildCompositeIndex();
    } else if (graphData.equals(LoadGraphWith.GraphData.MODERN)) {
        VertexLabel person = management.makeVertexLabel("person").make();
        VertexLabel software = management.makeVertexLabel("software").make();
        PropertyKey name = management.makePropertyKey("name").cardinality(Cardinality.LIST).dataType(String.class).make();
        PropertyKey lang = management.makePropertyKey("lang").cardinality(Cardinality.LIST).dataType(String.class).make();
        PropertyKey age = management.makePropertyKey("age").cardinality(Cardinality.LIST).dataType(Integer.class).make();
        management.buildIndex("personByName", Vertex.class).addKey(name).indexOnly(person).buildCompositeIndex();
        management.buildIndex("softwareByName", Vertex.class).addKey(name).indexOnly(software).buildCompositeIndex();
        management.buildIndex("personByAge", Vertex.class).addKey(age).indexOnly(person).buildCompositeIndex();
        management.buildIndex("softwareByLang", Vertex.class).addKey(lang).indexOnly(software).buildCompositeIndex();
    } else if (graphData.equals(LoadGraphWith.GraphData.CLASSIC)) {
        PropertyKey name = management.makePropertyKey("name").cardinality(Cardinality.LIST).dataType(String.class).make();
        PropertyKey lang = management.makePropertyKey("lang").cardinality(Cardinality.LIST).dataType(String.class).make();
        PropertyKey age = management.makePropertyKey("age").cardinality(Cardinality.LIST).dataType(Integer.class).make();
        management.buildIndex("byName", Vertex.class).addKey(name).buildCompositeIndex();
        management.buildIndex("byAge", Vertex.class).addKey(age).buildCompositeIndex();
        management.buildIndex("byLang", Vertex.class).addKey(lang).buildCompositeIndex();
    } else {
    // TODO: add CREW work here.
    // TODO: add meta_property indices when meta_property graph is provided
    // throw new RuntimeException("Could not load graph with " + graphData);
    }
    management.commit();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) CacheVertex(org.janusgraph.graphdb.vertices.CacheVertex) EdgeLabelVertex(org.janusgraph.graphdb.types.vertices.EdgeLabelVertex) VertexLabelVertex(org.janusgraph.graphdb.types.VertexLabelVertex) PreloadedVertex(org.janusgraph.graphdb.vertices.PreloadedVertex) StandardVertex(org.janusgraph.graphdb.vertices.StandardVertex) PropertyKeyVertex(org.janusgraph.graphdb.types.vertices.PropertyKeyVertex) JanusGraphSchemaVertex(org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) EmptyVertex(org.janusgraph.graphdb.types.system.EmptyVertex) VertexLabel(org.janusgraph.core.VertexLabel) PropertyKey(org.janusgraph.core.PropertyKey)

Example 34 with PropertyKey

use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.

the class JanusGraphSimpleAuthenticatorTest method testSetupEmptyCredGraphNoUserIndex.

@Test
public void testSetupEmptyCredGraphNoUserIndex() {
    final JanusGraphSimpleAuthenticator authenticator = createMockBuilder(JanusGraphSimpleAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").createMock();
    final Map<String, Object> configMap = new HashMap<String, Object>();
    configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
    configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_USER, "user");
    final JanusGraph graph = createMock(JanusGraph.class);
    final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
    final ManagementSystem mgmt = createMock(ManagementSystem.class);
    final Transaction tx = createMock(Transaction.class);
    final PropertyKey pk = createMock(PropertyKey.class);
    final PropertyKeyMaker pkm = createMock(PropertyKeyMaker.class);
    final JanusGraphManagement.IndexBuilder indexBuilder = createMock(JanusGraphManagement.IndexBuilder.class);
    final JanusGraphIndex index = createMock(JanusGraphIndex.class);
    final PropertyKey[] pks = { pk };
    final SimpleAuthenticator sa = createMock(SimpleAuthenticator.class);
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(authenticator.createSimpleAuthenticator()).andReturn(sa);
    expect(credentialGraph.findUser("user")).andReturn(null);
    expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
    expect(graph.openManagement()).andReturn(mgmt);
    expect(graph.tx()).andReturn(tx);
    sa.setup(configMap);
    EasyMock.expectLastCall();
    graph.close();
    EasyMock.expectLastCall();
    tx.rollback();
    EasyMock.expectLastCall();
    expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(false);
    expect(mgmt.makePropertyKey(PROPERTY_USERNAME)).andReturn(pkm);
    expect(pkm.dataType(eq(String.class))).andReturn(pkm);
    expect(pkm.cardinality(Cardinality.SINGLE)).andReturn(pkm);
    expect(pkm.make()).andReturn(pk);
    expect(mgmt.buildIndex(eq("byUsername"), eq(Vertex.class))).andReturn(indexBuilder);
    expect(mgmt.getGraphIndex(eq("byUsername"))).andReturn(index);
    expect(indexBuilder.addKey(eq(pk))).andReturn(indexBuilder);
    expect(indexBuilder.unique()).andReturn(indexBuilder);
    expect(indexBuilder.buildCompositeIndex()).andReturn(index);
    expect(index.getFieldKeys()).andReturn(pks);
    expect(index.getIndexStatus(eq(pk))).andReturn(SchemaStatus.ENABLED);
    expect(graph.tx()).andReturn(tx);
    expect(graph.openManagement()).andReturn(mgmt);
    tx.rollback();
    EasyMock.expectLastCall().atLeastOnce();
    mgmt.commit();
    EasyMock.expectLastCall();
    mgmt.rollback();
    EasyMock.expectLastCall();
    replayAll();
    authenticator.setup(configMap);
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) HashMap(java.util.HashMap) JanusGraph(org.janusgraph.core.JanusGraph) ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) PropertyKeyMaker(org.janusgraph.core.schema.PropertyKeyMaker) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) SimpleAuthenticator(org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 35 with PropertyKey

use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.

the class ConfigurationManagementGraph method createIndexIfDoesNotExist.

private void createIndexIfDoesNotExist(String indexName, String propertyKeyName, Class dataType, boolean unique) {
    graph.tx().rollback();
    JanusGraphManagement management = graph.openManagement();
    if (null == management.getGraphIndex(indexName)) {
        final PropertyKey key = management.makePropertyKey(propertyKeyName).dataType(dataType).make();
        final JanusGraphIndex index;
        if (unique)
            index = management.buildIndex(indexName, Vertex.class).addKey(key).unique().buildCompositeIndex();
        else
            index = management.buildIndex(indexName, Vertex.class).addKey(key).buildCompositeIndex();
        try {
            if (index.getIndexStatus(key) == INSTALLED) {
                management.commit();
                ManagementSystem.awaitGraphIndexStatus(graph, indexName).call();
                management = graph.openManagement();
                management.updateIndex(index, ENABLE_INDEX).get();
            } else if (index.getIndexStatus(key) == REGISTERED) {
                management.updateIndex(index, ENABLE_INDEX).get();
            }
        } catch (InterruptedException | ExecutionException e) {
            log.warn("Failed to create index {} for ConfigurationManagementGraph with exception: {}", indexName, e.toString());
            management.rollback();
            graph.tx().rollback();
        }
        management.commit();
        graph.tx().commit();
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) ExecutionException(java.util.concurrent.ExecutionException) PropertyKey(org.janusgraph.core.PropertyKey)

Aggregations

PropertyKey (org.janusgraph.core.PropertyKey)84 Test (org.junit.Test)59 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)57 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)28 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)28 EdgeLabel (org.janusgraph.core.EdgeLabel)21 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 Edge (org.apache.tinkerpop.gremlin.structure.Edge)14 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)13 VertexLabel (org.janusgraph.core.VertexLabel)13 JanusGraphVertexProperty (org.janusgraph.core.JanusGraphVertexProperty)11 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)9 BaseVertexLabel (org.janusgraph.graphdb.types.system.BaseVertexLabel)9 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)8 JanusGraph (org.janusgraph.core.JanusGraph)8 JanusGraphException (org.janusgraph.core.JanusGraphException)8 RelationTypeIndex (org.janusgraph.core.schema.RelationTypeIndex)8 Instant (java.time.Instant)6 ExecutionException (java.util.concurrent.ExecutionException)6