Java Code Examples for com.thinkaurelius.titan.core.schema.TitanManagement

The following are top voted examples for showing how to use com.thinkaurelius.titan.core.schema.TitanManagement. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: keti   File: GraphConfig.java   View source code 6 votes vote down vote up
public static void createUniqueCompositeIndex(final Graph newGraph, final String indexName,
        final String[] propertyKeyNames, final Class<?> propertyKeyType) throws InterruptedException {

    Assert.notEmpty(propertyKeyNames);
    newGraph.tx().rollback(); // Never create new indexes while a transaction is active
    TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
    IndexBuilder indexBuilder = mgmt.buildIndex(indexName, Vertex.class);
    if (!mgmt.containsGraphIndex(indexName)) {
        for (String propertyKeyName : propertyKeyNames) {
            PropertyKey indexPropertyKey = getOrCreatePropertyKey(propertyKeyName, propertyKeyType, mgmt);
            indexBuilder.addKey(indexPropertyKey);
        }
        indexBuilder.unique().buildCompositeIndex();
    }
    mgmt.commit();
    // Wait for the index to become available
    ManagementSystem.awaitGraphIndexStatus((TitanGraph) newGraph, indexName).status(SchemaStatus.ENABLED).call();
}
 
Example 2
Project: titan1withtp3.1   File: AbstractTitanGraphProvider.java   View source code 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 3
Project: titan1withtp3.1   File: TitanGraphBaseTest.java   View source code 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 4
Project: titan1withtp3.1   File: EdgeSerializerTest.java   View source code 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 5
Project: titan1withtp3.1   File: SchemaContainer.java   View source code 6 votes vote down vote up
public SchemaContainer(TitanGraph graph) {
    vertexLabels = Maps.newHashMap();
    relationTypes = Maps.newHashMap();
    TitanManagement mgmt = graph.openManagement();

    try {
        for (VertexLabel vl : mgmt.getVertexLabels()) {
            VertexLabelDefinition vld = new VertexLabelDefinition(vl);
            vertexLabels.put(vld.getName(),vld);
        }

        for (EdgeLabel el : mgmt.getRelationTypes(EdgeLabel.class)) {
            EdgeLabelDefinition eld = new EdgeLabelDefinition(el);
            relationTypes.put(eld.getName(),eld);
        }
        for (PropertyKey pk : mgmt.getRelationTypes(PropertyKey.class)) {
            PropertyKeyDefinition pkd = new PropertyKeyDefinition(pk);
            relationTypes.put(pkd.getName(), pkd);
        }
    } finally {
        mgmt.rollback();
    }

}
 
Example 6
Project: incubator-atlas   File: Titan1Graph.java   View source code 6 votes vote down vote up
public Titan1Graph() {
    //determine multi-properties once at startup
    TitanManagement mgmt = null;
    try {
        mgmt = Titan1GraphDatabase.getGraphInstance().openManagement();
        Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class);
        multiProperties = new HashSet<>();
        for (PropertyKey key : keys) {
            if (key.cardinality() != Cardinality.SINGLE) {
                multiProperties.add(key.name());
            }
        }
    } finally {
        if (mgmt != null) {
            mgmt.rollback();
        }
    }
}
 
Example 7
Project: incubator-atlas   File: Titan0Graph.java   View source code 6 votes vote down vote up
public Titan0Graph() {
    //determine multi-properties once at startup
    TitanManagement mgmt = null;
    try {
        mgmt = Titan0GraphDatabase.getGraphInstance().getManagementSystem();
        Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class);
        multiProperties = Collections.synchronizedSet(new HashSet<String>());
        for(PropertyKey key : keys) {
            if (key.getCardinality() != Cardinality.SINGLE) {
                multiProperties.add(key.getName());
            }
        }
    } finally {
        if (mgmt != null) {
            mgmt.rollback();
        }
    }
}
 
Example 8
Project: incubator-atlas   File: Titan0GraphDatabase.java   View source code 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 9
Project: titan1.0.1.kafka   File: AbstractTitanGraphProvider.java   View source code 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 10
Project: titan1.0.1.kafka   File: TitanGraphBaseTest.java   View source code 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 11
Project: titan1.0.1.kafka   File: EdgeSerializerTest.java   View source code 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 12
Project: titan1.0.1.kafka   File: SchemaContainer.java   View source code 6 votes vote down vote up
public SchemaContainer(TitanGraph graph) {
    vertexLabels = Maps.newHashMap();
    relationTypes = Maps.newHashMap();
    TitanManagement mgmt = graph.openManagement();

    try {
        for (VertexLabel vl : mgmt.getVertexLabels()) {
            VertexLabelDefinition vld = new VertexLabelDefinition(vl);
            vertexLabels.put(vld.getName(),vld);
        }

        for (EdgeLabel el : mgmt.getRelationTypes(EdgeLabel.class)) {
            EdgeLabelDefinition eld = new EdgeLabelDefinition(el);
            relationTypes.put(eld.getName(),eld);
        }
        for (PropertyKey pk : mgmt.getRelationTypes(PropertyKey.class)) {
            PropertyKeyDefinition pkd = new PropertyKeyDefinition(pk);
            relationTypes.put(pkd.getName(), pkd);
        }
    } finally {
        mgmt.rollback();
    }

}
 
Example 13
Project: titan0.5.4-hbase1.1.1-custom   File: TransactionalTitanGraphTestSuite.java   View source code 6 votes vote down vote up
@Override
public void testCompetingThreads() {
    TitanBlueprintsGraph graph = (TitanBlueprintsGraph) graphTest.generateGraph();
    //Need to define types before hand to avoid deadlock in transactions

    TitanManagement mgmt = graph.getManagementSystem();
    mgmt.makeEdgeLabel("friend").make();
    mgmt.makePropertyKey("test").dataType(Long.class).make();
    mgmt.makePropertyKey("blah").dataType(Float.class).make();
    mgmt.makePropertyKey("bloop").dataType(Integer.class).make();


    mgmt.commit();
    graph.shutdown();
    super.testCompetingThreads();
}
 
Example 14
Project: titan0.5.4-hbase1.1.1-custom   File: EdgeSerializerTest.java   View source code 6 votes vote down vote up
@Test
public void testValueOrdering() {
    StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph();
    TitanManagement mgmt = graph.getManagementSystem();
    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(null), v2 = graph.addVertex(null);
    TitanEdge e1 = v1.addEdge("father",v2);
    for (int i=1;i<=5;i++) e1.setProperty("key"+i,i);

    graph.commit();

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

}
 
Example 15
Project: titan0.5.4-hbase1.1.1-custom   File: TitanOutputFormatTest.java   View source code 6 votes vote down vote up
@Test
    public void testUnidirectionEdges() throws Exception {
        // Declare schema in Titan
        TitanManagement mgmt = g.getManagementSystem();
        mgmt.makeEdgeLabel("father").unidirected().make();
        mgmt.commit();

//        // Reload schema from Titan into Faunus's Type Manager
//        FaunusTypeManager.getTypeManager(null).clear();
//        SchemaProvider titanSchemaProvider = new SchemaContainer(g);
//        FaunusTypeManager typeManager = FaunusTypeManager.getTypeManager(null); //argument is ignored
//        typeManager.setSchemaProvider(titanSchemaProvider);

        bulkLoadGraphOfTheGods(f1);
        clopen();
        assertEquals(12, new GremlinPipeline(g).V().count());
        assertEquals(17, new GremlinPipeline(g).E().count());
        assertEquals(new GremlinPipeline(g).V("name", "hercules").out("father").count(), 1);
        assertEquals(new GremlinPipeline(g).V("name", "jupiter").in("father").count(), 0);

//        // Reset/clear types to avoid interference with subsequent tests
//        typeManager.clear();
//        typeManager.setSchemaProvider(DefaultSchemaProvider.INSTANCE);
    }
 
Example 16
Project: titan0.5.4-hbase1.1.1-custom   File: TitanCassandraInputFormatTest.java   View source code 6 votes vote down vote up
@Test
public void testCanReadListValuedProperty() throws Exception {
    TitanGraph tg = TitanFactory.open(getTitanConfiguration());

    TitanManagement mgmt = tg.getManagementSystem();
    mgmt.makePropertyKey("email").dataType(String.class).cardinality(com.thinkaurelius.titan.core.Cardinality.LIST).make();
    mgmt.commit();
    tg.commit();

    TitanVertex v = tg.addVertex();
    v.addProperty("email", "one");
    v.addProperty("email", "two");
    tg.commit();

    Configuration c = new Configuration();
    c.set("titan.hadoop.input.format", "com.thinkaurelius.titan.hadoop.formats.cassandra.TitanCassandraInputFormat");
    c.set("titan.hadoop.input.conf.storage.backend", "cassandrathrift");
    c.set("titan.hadoop.input.conf.storage.cassandra.keyspace", KEYSPACE_NAME);
    c.set("titan.hadoop.sideeffect.format", "org.apache.hadoop.mapreduce.lib.output.TextOutputFormat");
    c.set("titan.hadoop.output.format", "com.thinkaurelius.titan.hadoop.formats.graphson.GraphSONOutputFormat");
    c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner");

    HadoopGraph hg = new HadoopGraph(c);

    assertEquals(0, new HadoopPipeline(hg).V().map().submit());
}
 
Example 17
Project: titan0.5.4-hbase1.1.1-custom   File: SchemaContainer.java   View source code 6 votes vote down vote up
public SchemaContainer(TitanGraph graph) {
    vertexLabels = Maps.newHashMap();
    relationTypes = Maps.newHashMap();
    TitanManagement mgmt = graph.getManagementSystem();

    try {
        for (VertexLabel vl : mgmt.getVertexLabels()) {
            VertexLabelDefinition vld = new VertexLabelDefinition(vl);
            vertexLabels.put(vld.getName(),vld);
        }

        for (EdgeLabel el : mgmt.getRelationTypes(EdgeLabel.class)) {
            EdgeLabelDefinition eld = new EdgeLabelDefinition(el);
            relationTypes.put(eld.getName(),eld);
        }
        for (PropertyKey pk : mgmt.getRelationTypes(PropertyKey.class)) {
            PropertyKeyDefinition pkd = new PropertyKeyDefinition(pk);
            relationTypes.put(pkd.getName(), pkd);
        }
    } finally {
        mgmt.rollback();
    }

}
 
Example 18
Project: molgraph   File: TitanHandler.java   View source code 6 votes vote down vote up
protected void prepareIndices(String... keys)
  {
    // https://groups.google.com/forum/#!topic/aureliusgraphs/lGA3Ye4RI5E
    // transactional scope difference between management and graph
    if (Tools.isSet(keys))
    {
      TitanManagement m = G.getManagementSystem();

      for (String key : keys)
        prepareCompositeIndex(m, key);
//      makeStrKeys(m, ACC,NAME,ORGANISM,SUBCELOC,LABEL,DB,TYPE,PROTEIN,GENE,TERM,PATHWAY,MOLTYPE,EVIDENCE,ENTRY,PROTID);
//      m.buildIndex("byAcc",  Vertex.class).addKey(getStrKey(ACC) ).buildCompositeIndex();
//      m.buildIndex("byName", Vertex.class).addKey(getStrKey(NAME)).buildCompositeIndex();
      m.commit();
    }
  }
 
Example 19
Project: keti   File: GraphConfig.java   View source code 5 votes vote down vote up
public static void createIndex(final Graph newGraph, final String indexName, final String indexKey)
        throws InterruptedException {
    newGraph.tx().rollback(); // Never create new indexes while a transaction is active
    TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
    if (!mgmt.containsGraphIndex(indexName)) {
        PropertyKey indexPropertyKey = mgmt.makePropertyKey(indexKey).dataType(String.class).make();
        mgmt.buildIndex(indexName, Vertex.class).addKey(indexPropertyKey).buildCompositeIndex();
    }
    mgmt.commit();
    // Wait for the index to become available
    ManagementSystem.awaitGraphIndexStatus((TitanGraph) newGraph, indexName).status(SchemaStatus.ENABLED).call();
}
 
Example 20
Project: keti   File: GraphConfig.java   View source code 5 votes vote down vote up
public static void createUniqueIndexForLabel(final Graph newGraph, final String indexName, final String indexKey,
        final String label) throws InterruptedException {
    newGraph.tx().rollback(); // Never create new indexes while a transaction is active
    TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
    if (!mgmt.containsGraphIndex(indexName)) {
        PropertyKey indexPropertyKey = mgmt.makePropertyKey(indexKey).dataType(Integer.class).make();
        VertexLabel versionLabel = mgmt.makeVertexLabel(label).make();
        // Create a unique composite index for the property key that indexes only vertices with a given label
        mgmt.buildIndex(indexName, Vertex.class).addKey(indexPropertyKey).indexOnly(versionLabel).unique()
                .buildCompositeIndex();
    }
    mgmt.commit();
    // Wait for the index to become available
    ManagementSystem.awaitGraphIndexStatus((TitanGraph) newGraph, indexName).status(SchemaStatus.ENABLED).call();
}
 
Example 21
Project: keti   File: GraphConfig.java   View source code 5 votes vote down vote up
private static PropertyKey getOrCreatePropertyKey(final String keyName, final Class<?> keyType,
        final TitanManagement mgmt) {
    PropertyKey propertyKey = mgmt.getPropertyKey(keyName);
    if (null == propertyKey) {
        propertyKey = mgmt.makePropertyKey(keyName).dataType(keyType).make();
    }
    return propertyKey;
}
 
Example 22
Project: keti   File: GraphConfig.java   View source code 5 votes vote down vote up
public static void createEdgeIndex(final Graph newGraph, final String indexName, final String label,
        final String indexKey) throws InterruptedException {
    newGraph.tx().rollback(); // Never create new indexes while a transaction is active
    TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
    EdgeLabel edgeLabel = mgmt.getOrCreateEdgeLabel(label);
    if (!mgmt.containsRelationIndex(edgeLabel, indexName)) {
        PropertyKey indexPropertyKey = getOrCreatePropertyKey(indexKey, String.class, mgmt);
        mgmt.buildEdgeIndex(edgeLabel, indexName, Direction.OUT, indexPropertyKey);
    }
    mgmt.commit();
    // Wait for the index to become available
    ManagementSystem.awaitRelationIndexStatus((TitanGraph) newGraph, indexName, label).status(SchemaStatus.ENABLED)
            .call();
}
 
Example 23
Project: titan1withtp3.1   File: ManagementTest.java   View source code 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 24
Project: titan1withtp3.1   File: ManagementTest.java   View source code 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 25
Project: titan1withtp3.1   File: ManagementTest.java   View source code 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 26
Project: titan1withtp3.1   File: SerializerGraphConfiguration.java   View source code 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 27
Project: titan1withtp3.1   File: AbstractIndexManagementIT.java   View source code 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 28
Project: titan1withtp3.1   File: AbstractIndexManagementIT.java   View source code 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 29
Project: titan1withtp3.1   File: AbstractIndexManagementIT.java   View source code 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 30
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 5 votes vote down vote up
@Override
public TitanManagement.IndexBuilder indexOnly(TitanSchemaType schemaType) {
    Preconditions.checkNotNull(schemaType);
    Preconditions.checkArgument(elementCategory.isValidConstraint(schemaType), "Need to specify a valid schema type for this index definition: %s", schemaType);
    constraint = schemaType;
    return this;
}
 
Example 31
Project: titan1withtp3.1   File: RelationIndexStatusWatcher.java   View source code 5 votes vote down vote up
/**
 * Poll a relation index until it has a certain {@link SchemaStatus},
 * or until a configurable timeout is exceeded.
 *
 * @return a report with information about schema state, execution duration, and the index
 */
@Override
public RelationIndexStatusReport call() throws InterruptedException {
    Preconditions.checkNotNull(g, "Graph instance must not be null");
    Preconditions.checkNotNull(relationIndexName, "Index name must not be null");
    Preconditions.checkNotNull(status, "Target status must not be null");

    RelationTypeIndex idx;

    Timer t = new Timer(TimestampProviders.MILLI).start();
    boolean timedOut;
    while (true) {
        SchemaStatus actualStatus = null;
        TitanManagement mgmt = null;
        try {
            mgmt = g.openManagement();
            idx = mgmt.getRelationIndex(mgmt.getRelationType(relationTypeName), relationIndexName);
            actualStatus = idx.getIndexStatus();
            LOGGER.info("Index {} (relation type {}) has status {}", relationIndexName, relationTypeName, actualStatus);
            if (status.equals(actualStatus)) {
                return new RelationIndexStatusReport(true, relationIndexName, relationTypeName, actualStatus, status, t.elapsed());
            }
        } finally {
            if (null != mgmt)
                mgmt.rollback(); // Let an exception here propagate up the stack
        }

        timedOut = null != timeout && 0 < t.elapsed().compareTo(timeout);

        if (timedOut) {
            LOGGER.info("Timed out ({}) while waiting for index {} (relation type {}) to reach status {}",
                    timeout, relationIndexName, relationTypeName, status);
            return new RelationIndexStatusReport(false, relationIndexName, relationTypeName, actualStatus, status, t.elapsed());
        }

        Thread.sleep(poll.toMillis());
    }
}
 
Example 32
Project: antioch   File: TitanService.java   View source code 5 votes vote down vote up
@Override
public Map<String, Object> getMetadata() {
  TitanManagement mgmt = titanGraph.openManagement();
  Map<String, Object> metadata = super.getMetadata();
  @SuppressWarnings("unchecked")
  Map<String, Object> storageMap = (Map<String, Object>) metadata.get("storage");
  storageMap.put("vertexIndexes", indexInfo(mgmt, Vertex.class));
  storageMap.put("edgeIndexes", indexInfo(mgmt, Edge.class));
  return metadata;
}
 
Example 33
Project: antioch   File: TitanService.java   View source code 5 votes vote down vote up
private static boolean createIndexWhenAbsent(TitanManagement mgmt, VertexCompositeIndex compositeIndex) {
  String name = compositeIndex.name;
  if (!mgmt.containsGraphIndex(name)) {
    String property = compositeIndex.property;
    String label = compositeIndex.label;
    boolean unique = compositeIndex.unique;
    LOG.info("building {} index '{}' for label '{}' + property '{}'", unique ? "unique" : "non-unique", name, label, property);

    PropertyKey uuidKey = mgmt.containsPropertyKey(property)//
        ? mgmt.getPropertyKey(property)//
        : mgmt.makePropertyKey(property).dataType(String.class).make();

    IndexBuilder indexBuilder = mgmt.buildIndex(name, Vertex.class)//
        .addKey(uuidKey);

    if (label != null) {
      VertexLabel vertexLabel = mgmt.containsVertexLabel(label)//
          ? mgmt.getVertexLabel(label)//
          : mgmt.makeVertexLabel(label).make();
      indexBuilder = indexBuilder.indexOnly(vertexLabel);
    }

    if (unique) {
      indexBuilder = indexBuilder.unique();
    }

    TitanGraphIndex index = indexBuilder.buildCompositeIndex();
    mgmt.setConsistency(index, ConsistencyModifier.LOCK);

    return true;
  }
  return false;
}
 
Example 34
Project: antioch   File: TitanService.java   View source code 5 votes vote down vote up
private static void waitForCompletion(TitanManagement mgmt, VertexCompositeIndex compositeIndex) {
  String name = compositeIndex.name;
  TitanGraphIndex graphIndex = mgmt.getGraphIndex(name);
  PropertyKey propertyKey = graphIndex.getFieldKeys()[0];
  // For composite indexes, the propertyKey is ignored and the status of the index as a whole is returned
  if (!SchemaStatus.ENABLED.equals(graphIndex.getIndexStatus(propertyKey))) {
    try {
      GraphIndexStatusReport report = ManagementSystem.awaitGraphIndexStatus(titanGraph, name).call();
      LOG.info("report={}", report);
    } catch (InterruptedException e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
}
 
Example 35
Project: incubator-atlas   File: Titan1Graph.java   View source code 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 36
Project: incubator-atlas   File: Titan1GraphManagement.java   View source code 5 votes vote down vote up
@Override
public void createVertexIndex(String propertyName, String backingIndex, List<AtlasPropertyKey> propertyKeys) {

    TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);
    for (AtlasPropertyKey key : propertyKeys) {
        PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(titanKey);
    }
    indexBuilder.buildMixedIndex(backingIndex);
}
 
Example 37
Project: incubator-atlas   File: Titan1GraphManagement.java   View source code 5 votes vote down vote up
public void createExactMatchVertexIndex(String propertyName, boolean enforceUniqueness,
                                  List<AtlasPropertyKey> propertyKeys) {

    TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);
    for (AtlasPropertyKey key : propertyKeys) {
        PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(titanKey);
    }
    if (enforceUniqueness) {
        indexBuilder.unique();
    }
    indexBuilder.buildCompositeIndex();
}
 
Example 38
Project: incubator-atlas   File: Titan1GraphDatabase.java   View source code 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 39
Project: incubator-atlas   File: Titan0GraphManagement.java   View source code 5 votes vote down vote up
@Override
public void createExactMatchIndex(String propertyName, boolean enforceUniqueness,
        List<AtlasPropertyKey> propertyKeys) {

    TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);
    for(AtlasPropertyKey key : propertyKeys) {
        PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(titanKey);
    }
    if (enforceUniqueness) {
        indexBuilder.unique();
    }
    indexBuilder.buildCompositeIndex();
}
 
Example 40
Project: incubator-atlas   File: Titan0GraphManagement.java   View source code 5 votes vote down vote up
@Override
public void createVertexIndex(String propertyName, String backingIndex, List<AtlasPropertyKey> propertyKeys) {

    TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);
    for(AtlasPropertyKey key : propertyKeys) {
        PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(titanKey);
    }
    indexBuilder.buildMixedIndex(backingIndex);
}