openning graph through java

235 views
Skip to first unread message

mohit kaushik

unread,
Mar 25, 2014, 8:26:24 AM3/25/14
to aureliu...@googlegroups.com
i want to create a graph in memory so i run from my java program

TitanGraph graph = TitanFactory.open("/home/mohit.kaushik/Documents/titan-all-0.4.2/conf/configuration.properties");
congiguration file contains
storage.backend=hazelcastcache
storage.directory=/home/mohit.kaushik/Documents/titan-all-0.4.2/bin/local/tmp/titan/mohit
and this gives the following error

Exception in thread "main" java.lang.IllegalArgumentException: Could not find implementation class: com.thinkaurelius.titan.diskstorage.hazelcast.HazelcastCacheStoreManager
    at com.thinkaurelius.titan.diskstorage.Backend.instantiate(Backend.java:347)
    at com.thinkaurelius.titan.diskstorage.Backend.getImplementationClass(Backend.java:367)
    at com.thinkaurelius.titan.diskstorage.Backend.getStorageManager(Backend.java:311)
    at com.thinkaurelius.titan.diskstorage.Backend.<init>(Backend.java:121)
    at com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.getBackend(GraphDatabaseConfiguration.java:1163)
    at com.thinkaurelius.titan.graphdb.database.StandardTitanGraph.<init>(StandardTitanGraph.java:75)
    at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:40)
    at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:29)
    at TitanDemo.main(TitanDemo.java:41)
and i am not even able to run the GraphOf Gods Factory from java ..........


package com.thinkaurelius.titan.example;

import com.thinkaurelius.titan.core.TitanFactory;
import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.core.TitanKey;
import com.thinkaurelius.titan.core.attribute.Geoshape;
import com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.ElementHelper;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;

import java.io.File;

import static com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.INDEX_BACKEND_KEY;
import static com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_DIRECTORY_KEY;


/**
 * Example Graph factory that creates a {@link TitanGraph} based on roman mythology.
 * Used in the documentation examples and tutorials.
 *
 * @author Marko A. Rodriguez (http://markorodriguez.com)
 */
public class GraphOfTheGodsFactory {
    public static void main(String[] args) {
       
        GraphOfTheGodsFactory.create("/tmp/titan_graph");
    }

   
    public static final String INDEX_NAME = "search";

    public static TitanGraph create(final String directory) {
        BaseConfiguration config = new BaseConfiguration();
        Configuration storage = config.subset(GraphDatabaseConfiguration.STORAGE_NAMESPACE);
        // configuring local backend
        storage.setProperty(GraphDatabaseConfiguration.STORAGE_BACKEND_KEY, "inmemory");
        storage.setProperty(GraphDatabaseConfiguration.STORAGE_DIRECTORY_KEY, directory);
        // configuring elastic search index
        Configuration index = storage.subset(GraphDatabaseConfiguration.INDEX_NAMESPACE).subset(INDEX_NAME);
        index.setProperty(INDEX_BACKEND_KEY, "elasticsearch");
        index.setProperty("local-mode", true);
        index.setProperty("client-only", false);
        index.setProperty(STORAGE_DIRECTORY_KEY, directory + File.separator + "es");

        TitanGraph graph = TitanFactory.open(config);
        GraphOfTheGodsFactory.load(graph);
        return graph;
    }

    public static void load(final TitanGraph graph) {

        graph.makeKey("name").dataType(String.class).indexed(Vertex.class).unique().make();
        graph.makeKey("age").dataType(Integer.class).indexed(INDEX_NAME, Vertex.class).make();
        graph.makeKey("type").dataType(String.class).make();

        final TitanKey time = graph.makeKey("time").dataType(Integer.class).make();
        final TitanKey reason = graph.makeKey("reason").dataType(String.class).indexed(INDEX_NAME, Edge.class).make();
        graph.makeKey("place").dataType(Geoshape.class).indexed(INDEX_NAME, Edge.class).make();

        graph.makeLabel("father").manyToOne().make();
        graph.makeLabel("mother").manyToOne().make();
        graph.makeLabel("battled").sortKey(time).make();
        graph.makeLabel("lives").signature(reason).make();
        graph.makeLabel("pet").make();
        graph.makeLabel("brother").make();

        graph.commit();

        // vertices

        Vertex saturn = graph.addVertex(null);
        saturn.setProperty("name", "saturn");
        saturn.setProperty("age", 10000);
        saturn.setProperty("type", "titan");

        Vertex sky = graph.addVertex(null);
        ElementHelper.setProperties(sky, "name", "sky", "type", "location");

        Vertex sea = graph.addVertex(null);
        ElementHelper.setProperties(sea, "name", "sea", "type", "location");

        Vertex jupiter = graph.addVertex(null);
        ElementHelper.setProperties(jupiter, "name", "jupiter", "age", 5000, "type", "god");

        Vertex neptune = graph.addVertex(null);
        ElementHelper.setProperties(neptune, "name", "neptune", "age", 4500, "type", "god");

        Vertex hercules = graph.addVertex(null);
        ElementHelper.setProperties(hercules, "name", "hercules", "age", 30, "type", "demigod");

        Vertex alcmene = graph.addVertex(null);
        ElementHelper.setProperties(alcmene, "name", "alcmene", "age", 45, "type", "human");

        Vertex pluto = graph.addVertex(null);
        ElementHelper.setProperties(pluto, "name", "pluto", "age", 4000, "type", "god");

        Vertex nemean = graph.addVertex(null);
        ElementHelper.setProperties(nemean, "name", "nemean", "type", "monster");

        Vertex hydra = graph.addVertex(null);
        ElementHelper.setProperties(hydra, "name", "hydra", "type", "monster");

        Vertex cerberus = graph.addVertex(null);
        ElementHelper.setProperties(cerberus, "name", "cerberus", "type", "monster");

        Vertex tartarus = graph.addVertex(null);
        ElementHelper.setProperties(tartarus, "name", "tartarus", "type", "location");

        // edges

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

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

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

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

        cerberus.addEdge("lives", tartarus);

        // commit the transaction to disk
        graph.commit();
    }
}
it gives the following exception
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Objects.firstNonNull(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    at com.google.common.cache.CacheBuilder.getKeyStrength(CacheBuilder.java:529)
    at com.google.common.cache.LocalCache.<init>(LocalCache.java:239)
    at com.google.common.cache.LocalCache$LocalManualCache.<init>(LocalCache.java:4771)
    at com.google.common.cache.CacheBuilder.build(CacheBuilder.java:803)
    at com.thinkaurelius.titan.diskstorage.keycolumnvalue.CachedKeyColumnValueStore.<init>(CachedKeyColumnValueStore.java:52)
    at com.thinkaurelius.titan.diskstorage.keycolumnvalue.CachedKeyColumnValueStore.<init>(CachedKeyColumnValueStore.java:46)
    at com.thinkaurelius.titan.diskstorage.Backend.getBufferStore(Backend.java:226)
    at com.thinkaurelius.titan.diskstorage.Backend.initialize(Backend.java:256)
    at com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.getBackend(GraphDatabaseConfiguration.java:1164)
    at com.thinkaurelius.titan.graphdb.database.StandardTitanGraph.<init>(StandardTitanGraph.java:75)
    at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:40)
    at com.thinkaurelius.titan.example.GraphOfTheGodsFactory.create(GraphOfTheGodsFactory.java:48)
    at com.thinkaurelius.titan.example.GraphOfTheGodsFactory.main(GraphOfTheGodsFactory.java:29)


whle the graphofgodsfactory runs properly from groovy.......
and i must tell you, i am not using cassandra.......please help

Regards
MOhit

Stephen Mallette

unread,
Mar 25, 2014, 8:58:50 AM3/25/14
to aureliu...@googlegroups.com
Mohit, it seems you are trying to use the hazelcast backend from the titan-all distribution.  The Hazelcast backend is "experimental" and as such is in a separate repo:


I don't think we have an explicit distribution for the titan-experimental repository so I guess you would have to build it yourself.

Separately, I think it's great that you are trying the many aspects of Titan, but when you submit one question after another in such rapid succession it makes it hard to keep track of the problems you are dealing with.  Please take some extra time to solve some of these easier problems on your own before bringing them to the mailing list.  We're happy to help people understand the technology (especially those who are just getting started), but please be mindful of our time when asking for help.  

Stephen


--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mohit kaushik

unread,
Mar 26, 2014, 12:50:53 AM3/26/14
to aureliu...@googlegroups.com
Thanks Stephen,
Its really feels good that you are always happy to help beginners. Its really a support for us.
yesterday i created the graph of gods with my name and i also opened it yesterday but when i am opening and it and try to iterate verteces by g.V it says

WARN  com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx  - Query requires iterating over all vertices [()]. For better performance, use indexes
//same for the edges.....
and i understand time is precious for everyone so i also searched it on web but did not find any satisfactory answer. somewhere it was written that you should commit but graphofgodsfactory does it automatically so i think don't need it.

I want to know what are the other ways now by which i can iterate over vertices and edges and also can run other gremlin commands.

Thanks and Regards
Mohit



Daniel Kuppitz

unread,
Mar 26, 2014, 10:46:06 AM3/26/14
to aureliu...@googlegroups.com
Mohit,

what's the problem here? g.V() says Query requires iterating over all vertices because the query obviously requires iterating over all vertices. Which problem are you trying to solve? How to not iterate over all vertices?
Create indices and do index lookups (g.V("name","saturn")) or access vertices by their ID (g.v(4)).

Cheers,
Daniel



Reply all
Reply to author
Forward
0 new messages