Search in sources :

Example 11 with TitanManagement

use of com.thinkaurelius.titan.core.schema.TitanManagement in project incubator-atlas by apache.

the class Titan1Graph method getIndexKeys.

private Set<String> getIndexKeys(Class<? extends Element> titanElementClass) {
    TitanManagement mgmt = getGraph().openManagement();
    Iterable<TitanGraphIndex> indices = mgmt.getGraphIndexes(titanElementClass);
    Set<String> result = new HashSet<String>();
    for (TitanGraphIndex index : indices) {
        result.add(index.name());
    }
    mgmt.commit();
    return result;
}
Also used : TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) HashSet(java.util.HashSet)

Example 12 with TitanManagement

use of com.thinkaurelius.titan.core.schema.TitanManagement in project titan by thinkaurelius.

the class TitanGraphBaseTest method clopen.

public void clopen(Object... settings) {
    config = getConfiguration();
    if (mgmt != null && mgmt.isOpen())
        mgmt.rollback();
    if (null != tx && tx.isOpen())
        tx.commit();
    if (settings != null && settings.length > 0) {
        Map<TestConfigOption, Object> options = validateConfigOptions(settings);
        TitanManagement gconf = null;
        ModifiableConfiguration lconf = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.LOCAL);
        for (Map.Entry<TestConfigOption, Object> option : options.entrySet()) {
            if (option.getKey().option.isLocal()) {
                lconf.set(option.getKey().option, option.getValue(), option.getKey().umbrella);
            } else {
                if (gconf == null)
                    gconf = graph.openManagement();
                gconf.set(ConfigElement.getPath(option.getKey().option, option.getKey().umbrella), option.getValue());
            }
        }
        if (gconf != null)
            gconf.commit();
        lconf.close();
    }
    if (null != graph && graph.isOpen())
        graph.close();
    Preconditions.checkNotNull(config);
    open(config);
}
Also used : TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement)

Example 13 with TitanManagement

use of com.thinkaurelius.titan.core.schema.TitanManagement in project titan by thinkaurelius.

the class ManagementTest method testReservedNamesRejectedForPropertyKeys.

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

Example 14 with TitanManagement

use of com.thinkaurelius.titan.core.schema.TitanManagement in project titan by thinkaurelius.

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
    TitanManagement 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();
    TitanGraphIndex 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<TitanVertex> hits = graph.query().has("age", 4500).vertices();
    assertNotNull(hits);
    assertEquals(1, Iterables.size(hits));
    TitanVertex v = Iterables.getOnlyElement(hits);
    assertNotNull(v);
    assertEquals("neptune", v.value("name"));
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) ScanMetrics(com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics) TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test) TitanGraphBaseTest(com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)

Example 15 with TitanManagement

use of com.thinkaurelius.titan.core.schema.TitanManagement in project titan by thinkaurelius.

the class AbstractIndexManagementIT method testRepairRelationIndex.

@Test
public void testRepairRelationIndex() 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 relation index on lives edges by reason
    TitanManagement m = graph.openManagement();
    PropertyKey reason = m.getPropertyKey("reason");
    EdgeLabel lives = m.getEdgeLabel("lives");
    m.buildEdgeIndex(lives, "livesByReason", Direction.BOTH, Order.decr, reason);
    m.commit();
    graph.tx().commit();
    // Block until the SchemaStatus transitions to REGISTERED
    assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "livesByReason", "lives").status(SchemaStatus.REGISTERED).call().getSucceeded());
    m = graph.openManagement();
    RelationTypeIndex index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason");
    m.updateIndex(index, SchemaAction.ENABLE_INDEX);
    m.commit();
    graph.tx().commit();
    // Block until the SchemaStatus transitions to ENABLED
    assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "livesByReason", "lives").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("reason", "no fear of death").edges().iterator().hasNext());
    // Repair
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason");
    ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REINDEX).get();
    assertEquals(8, metrics.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
}
Also used : EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) ScanMetrics(com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics) TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test) TitanGraphBaseTest(com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)

Aggregations

TitanManagement (com.thinkaurelius.titan.core.schema.TitanManagement)21 Test (org.junit.Test)8 TitanGraphBaseTest (com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)7 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)6 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)6 ScanMetrics (com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics)5 StandardTitanGraph (com.thinkaurelius.titan.graphdb.database.StandardTitanGraph)5 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)4 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 RelationType (com.thinkaurelius.titan.core.RelationType)2 TitanException (com.thinkaurelius.titan.core.TitanException)2 TitanGraph (com.thinkaurelius.titan.core.TitanGraph)2 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)2 SchemaStatus (com.thinkaurelius.titan.core.schema.SchemaStatus)2 Timer (com.thinkaurelius.titan.diskstorage.util.time.Timer)2 HashMap (java.util.HashMap)2 Function (com.google.common.base.Function)1 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)1 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)1