Java Code Examples for com.thinkaurelius.titan.core.schema.TitanManagement#commit()

The following examples show how to use com.thinkaurelius.titan.core.schema.TitanManagement#commit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTitanGraphProvider.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Override
public void loadGraphData(final Graph g, final LoadGraphWith loadGraphWith, final Class testClass, final String testName) {
    if (loadGraphWith != null) {
        this.createIndices((TitanGraph) g, loadGraphWith.value());
    } else {
        if (TransactionTest.class.equals(testClass) && testName.equalsIgnoreCase("shouldExecuteWithCompetingThreads")) {
            TitanManagement mgmt = ((TitanGraph) g).openManagement();
            mgmt.makePropertyKey("blah").dataType(Double.class).make();
            mgmt.makePropertyKey("bloop").dataType(Integer.class).make();
            mgmt.makePropertyKey("test").dataType(Object.class).make();
            mgmt.makeEdgeLabel("friend").make();
            mgmt.commit();
        }
    }
    super.loadGraphData(g, loadGraphWith, testClass, testName);
}
 
Example 2
Source File: TitanGraphBaseTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source File: EdgeSerializerTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testValueOrdering() {
    StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph();
    TitanManagement mgmt = graph.openManagement();
    EdgeLabel father = mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
    for (int i=1;i<=5;i++) mgmt.makePropertyKey("key" + i).dataType(Integer.class).make();
    mgmt.commit();

    TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex();
    TitanEdge e1 = v1.addEdge("father",v2);
    for (int i=1;i<=5;i++) e1.property("key"+i,i);

    graph.tx().commit();

    e1.remove();
    graph.tx().commit();

}
 
Example 4
Source File: Titan0GraphDatabase.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
static void validateIndexBackend(Configuration config) {
    String configuredIndexBackend = config.getString(INDEX_BACKEND_CONF);
    TitanManagement managementSystem = null;

    try {
        managementSystem = getGraphInstance().getManagementSystem();
        String currentIndexBackend = managementSystem.get(INDEX_BACKEND_CONF);

        if (!equals(configuredIndexBackend, currentIndexBackend)) {
            throw new RuntimeException("Configured Index Backend " + configuredIndexBackend
                    + " differs from earlier configured Index Backend " + currentIndexBackend + ". Aborting!");
        }

    } finally {
        if (managementSystem != null) {
            managementSystem.commit();
        }
    }


}
 
Example 5
Source File: ManagementTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@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();
        }
    }
}
 
Example 6
Source File: ManagementTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Test
public void testReservedNamesRejectedForEdgeLabels() {
    for (String s : ILLEGAL_USER_DEFINED_NAMES) {
        TitanManagement tm = graph.openManagement();
        try {
            tm.makeEdgeLabel(s);
            Assert.fail("Edge label \"" + s + "\" must be rejected");
        } catch (IllegalArgumentException e) {
            log.debug("Caught expected exception", e);
        } finally {
            tm.commit();
        }
    }
}
 
Example 7
Source File: ManagementTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Test
public void testReservedNamesRejectedForVertexLabels() {
    for (String s : ILLEGAL_USER_DEFINED_NAMES) {
        TitanManagement tm = graph.openManagement();
        VertexLabelMaker vlm = null;
        try {
            vlm = tm.makeVertexLabel(s);
            Assert.fail("Vertex label \"" + s + "\" must be rejected");
        } catch (IllegalArgumentException e) {
            log.debug("Caught expected exception", e);
        } finally {
            tm.commit();
        }
    }
}
 
Example 8
Source File: SerializerGraphConfiguration.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnlyRegisteredSerialization() {
    TitanManagement mgmt = graph.openManagement();
    PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
    PropertyKey any  = mgmt.makePropertyKey("any").cardinality(Cardinality.LIST).dataType(Object.class).make();
    mgmt.buildIndex("byTime",Vertex.class).addKey(time).buildCompositeIndex();
    EdgeLabel knows = mgmt.makeEdgeLabel("knows").make();
    VertexLabel person = mgmt.makeVertexLabel("person").make();
    mgmt.commit();

    TitanTransaction tx = graph.newTransaction();
    TitanVertex v = tx.addVertex("person");
    v.property("time", 5);
    v.property("any", new Double(5.0));
    v.property("any", new TClass1(5,1.5f));
    v.property("any", TEnum.THREE);
    tx.commit();

    tx = graph.newTransaction();
    v = tx.query().has("time",5).vertices().iterator().next();
    assertEquals(5,(int)v.value("time"));
    assertEquals(3, Iterators.size(v.properties("any")));
    tx.rollback();

    //Verify that non-registered objects aren't allowed
    for (Object o : new Object[]{new TClass2("abc",5)}) {
        tx = graph.newTransaction();
        v = tx.addVertex("person");
        try {
            v.property("any", o); //Should not be allowed
            tx.commit();
            fail();
        } catch (IllegalArgumentException e) {
        } finally {
            if (tx.isOpen()) tx.rollback();
        }

    }
}
 
Example 9
Source File: AbstractIndexManagementIT.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveGraphIndex() throws InterruptedException, BackendException, ExecutionException {
    tx.commit();
    mgmt.commit();

    // Load the "Graph of the Gods" sample data
    GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);

    // Disable the "name" composite index
    TitanManagement m = graph.openManagement();
    TitanGraphIndex nameIndex = m.getGraphIndex("name");
    m.updateIndex(nameIndex, SchemaAction.DISABLE_INDEX);
    m.commit();
    graph.tx().commit();

    // Block until the SchemaStatus transitions to DISABLED
    assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "name")
            .status(SchemaStatus.DISABLED).call().getSucceeded());

    // Remove index
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    TitanGraphIndex index = m.getGraphIndex("name");
    ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REMOVE_INDEX).get();

    assertEquals(12, metrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT));
}
 
Example 10
Source File: AbstractIndexManagementIT.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveRelationIndex() throws InterruptedException, BackendException, ExecutionException {
    tx.commit();
    mgmt.commit();

    // Load the "Graph of the Gods" sample data
    GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);

    // Disable the "battlesByTime" index
    TitanManagement m = graph.openManagement();
    RelationType battled = m.getRelationType("battled");
    RelationTypeIndex battlesByTime = m.getRelationIndex(battled, "battlesByTime");
    m.updateIndex(battlesByTime, SchemaAction.DISABLE_INDEX);
    m.commit();
    graph.tx().commit();

    // Block until the SchemaStatus transitions to DISABLED
    assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "battlesByTime", "battled")
            .status(SchemaStatus.DISABLED).call().getSucceeded());

    // Remove index
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    battled = m.getRelationType("battled");
    battlesByTime = m.getRelationIndex(battled, "battlesByTime");
    ScanMetrics metrics = mri.updateIndex(battlesByTime, SchemaAction.REMOVE_INDEX).get();

    assertEquals(6, metrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT));
}
 
Example 11
Source File: AbstractIndexManagementIT.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 12
Source File: Titan1Graph.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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;

    }
 
Example 13
Source File: Titan1GraphDatabase.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
static void validateIndexBackend(Configuration config) {
    String configuredIndexBackend = config.getString(INDEX_BACKEND_CONF);

    TitanManagement 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!");
    }

}
 
Example 14
Source File: AbstractIndexManagementIT.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@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"));
}
 
Example 15
Source File: GraphOfTheGodsFactory.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static void load(final TitanGraph graph, String mixedIndexName, boolean uniqueNameCompositeIndex) {

        //Create Schema
        TitanManagement mgmt = graph.openManagement();
        final PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
        TitanManagement.IndexBuilder nameIndexBuilder = mgmt.buildIndex("name", Vertex.class).addKey(name);
        if (uniqueNameCompositeIndex)
            nameIndexBuilder.unique();
        TitanGraphIndex namei = nameIndexBuilder.buildCompositeIndex();
        mgmt.setConsistency(namei, ConsistencyModifier.LOCK);
        final PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
        if (null != mixedIndexName)
            mgmt.buildIndex("vertices", Vertex.class).addKey(age).buildMixedIndex(mixedIndexName);

        final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
        final PropertyKey reason = mgmt.makePropertyKey("reason").dataType(String.class).make();
        final PropertyKey place = mgmt.makePropertyKey("place").dataType(Geoshape.class).make();
        if (null != mixedIndexName)
            mgmt.buildIndex("edges", Edge.class).addKey(reason).addKey(place).buildMixedIndex(mixedIndexName);

        mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
        mgmt.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make();
        EdgeLabel battled = mgmt.makeEdgeLabel("battled").signature(time).make();
        mgmt.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.decr, time);
        mgmt.makeEdgeLabel("lives").signature(reason).make();
        mgmt.makeEdgeLabel("pet").make();
        mgmt.makeEdgeLabel("brother").make();

        mgmt.makeVertexLabel("titan").make();
        mgmt.makeVertexLabel("location").make();
        mgmt.makeVertexLabel("god").make();
        mgmt.makeVertexLabel("demigod").make();
        mgmt.makeVertexLabel("human").make();
        mgmt.makeVertexLabel("monster").make();

        mgmt.commit();

        TitanTransaction tx = graph.newTransaction();
        // vertices

        Vertex saturn = tx.addVertex(T.label, "titan", "name", "saturn", "age", 10000);

        Vertex sky = tx.addVertex(T.label, "location", "name", "sky");

        Vertex sea = tx.addVertex(T.label, "location", "name", "sea");

        Vertex jupiter = tx.addVertex(T.label, "god", "name", "jupiter", "age", 5000);

        Vertex neptune = tx.addVertex(T.label, "god", "name", "neptune", "age", 4500);

        Vertex hercules = tx.addVertex(T.label, "demigod", "name", "hercules", "age", 30);

        Vertex alcmene = tx.addVertex(T.label, "human", "name", "alcmene", "age", 45);

        Vertex pluto = tx.addVertex(T.label, "god", "name", "pluto", "age", 4000);

        Vertex nemean = tx.addVertex(T.label, "monster", "name", "nemean");

        Vertex hydra = tx.addVertex(T.label, "monster", "name", "hydra");

        Vertex cerberus = tx.addVertex(T.label, "monster", "name", "cerberus");

        Vertex tartarus = tx.addVertex(T.label, "location", "name", "tartarus");

        // edges

        jupiter.addEdge("father", saturn);
        jupiter.addEdge("lives", sky, "reason", "loves fresh breezes");
        jupiter.addEdge("brother", neptune);
        jupiter.addEdge("brother", pluto);

        neptune.addEdge("lives", sea).property("reason", "loves waves");
        neptune.addEdge("brother", jupiter);
        neptune.addEdge("brother", pluto);

        hercules.addEdge("father", jupiter);
        hercules.addEdge("mother", alcmene);
        hercules.addEdge("battled", nemean, "time", 1, "place", Geoshape.point(38.1f, 23.7f));
        hercules.addEdge("battled", hydra, "time", 2, "place", Geoshape.point(37.7f, 23.9f));
        hercules.addEdge("battled", cerberus, "time", 12, "place", Geoshape.point(39f, 22f));

        pluto.addEdge("brother", jupiter);
        pluto.addEdge("brother", neptune);
        pluto.addEdge("lives", tartarus, "reason", "no fear of death");
        pluto.addEdge("pet", cerberus);

        cerberus.addEdge("lives", tartarus);

        // commit the transaction to disk
        tx.commit();
    }