Coder Social home page Coder Social logo

janusgraph-utils's Introduction

Develop a scalable graph database app using JanusGraph Build Status

This journey contains sample data and code for running a Twitter-like application in JanusGraph. The utility code illustrates how to use OLTP APIs to define schema, ingest data, and query graph. Developers can use or modify the code to build and operate their custom graph applications, or create similar java and groovy files to interact with JanusGraph.

When the reader has completed this journey, they will understand how to:

  • Generate a synthetic graph dataset
  • Load a graph schema from json
  • Import graph data in csv files into JanusGraph database
  • Query and update graph data using Console and REST API
  • Setup and configure a scalable JanusGraph system

Flow

Prerequisites: Install and configure JanusGraph, Cassandra, ElasticSearch, janusgraph-utils

  1. The user generates Twitter sample schema and data using JanusGraph utilities
  2. The user loads schema and imports data in backend servers using JanusGraph utilities
  3. The user makes search and update requests in a REST/custom client
  4. The client app sends the REST requests to JanusGraph server
  5. The JanusGraph server interacts with backend to process and return graph data

Included components

  • Apache Cassandra: An open source, scalable, high availability database.
  • JanusGraph: A highly scalable graph database optimized for storing and querying large graphs.

Featured technologies

  • Databases: Repository for storing and managing collections of data.
  • Java: A secure, object-oriented programming language for creating applications.

Steps

Run locally

  1. Install prerequisites
  2. Clone the repo
  3. Generate the graph sample
  4. Load schema and import data
  5. Run interactive remote queries

1. Install prerequisites

NOTE: These prerequisites can be installed on one server. The instructions are written for Cassandra 3.10 and ElasticSearch 5.3.0. Newer versions should work however not tested.

Install Cassandra 3.10 on the storage server. Make the following changes in /etc/cassandra/cassandra.yaml and restart Cassandra.

start_rpc: true
rpc_address: 0.0.0.0
rpc_port: 9160
broadcast_rpc_address: x.x.x.x (your storage server ip)

Install ElasticSearch 5.3.0 on the index server. Make the following changes in /etc/elasticsearch/elasticsearch.yml and restart ElasticSearch.

network.host: x.x.x.x (your index server ip)

Install JanusGraph on the graph server

  • Install java, maven, git
  • Run git clone https://github.com/JanusGraph/janusgraph.git
  • Run the following in janusgraph folder
git checkout 4609b6731a01116e96e554140b37ad589f0ae0ca
mvn clean install -DskipTests=true
cp conf/janusgraph-cassandra-es.properties conf/janusgraph-cql-es.properties
vi conf/janusgraph-cql-es.properties
storage.backend=cql
storage.hostname=x.x.x.x (your storage server ip)
index.search.hostname=x.x.x.x (your index server ip)

Install a REST client, such as RESTClient add-on for Firefox, on the client machine

2. Clone the repo

Clone the janusgraph-utils on the graph server.

git clone https://github.com/IBM/janusgraph-utils.git
cd janusgraph-utils/
mvn package

3. Generate the graph sample

Run the command in janusgraph-utils folder to generate data into /tmp folder.

./run.sh gencsv csv-conf/twitter-like-w-date.json /tmp

Modify the generated user file under /tmp so the sample queries will return with data.

sed -i -e '2s/.*/1,Indiana Jones/' /tmp/User.csv

4. Load schema and import data

A graph schema can be loaded from either the Gremlin console or a java utility. You can check the doc doc/users_guide.md for details. Alternatively, just run one command in janusgraph-utils folder to load schema and import data.

export JANUSGRAPH_HOME=~/janusgraph
./run.sh import ~/janusgraph/conf/janusgraph-cql-es.properties /tmp /tmp/schema.json /tmp/datamapper.json

5. Run interactive remote queries

Configure and start JanusGraph server by running the following in ~/janusgraph/conf/gremlin-server folder.

cp ~/janusgraph-utils/samples/date-helper.groovy ../../scripts 
cp ../janusgraph-cql-es.properties janusgraph-cql-es-server.properties
Add a line to janusgraph-cql-es-server.properties, gremlin.graph=org.janusgraph.core.JanusGraphFactory
cp gremlin-server.yaml rest-gremlin-server.yaml
Change the following four lines in rest-gremlin-server.yaml
host: x.x.x.x (your server ip)
channelizer: org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer
graph: conf/gremlin-server/janusgraph-cql-es-server.properties}
scripts: [scripts/empty-sample.groovy,scripts/date-helper.groovy]}}
cd ~/janusgraph; ./bin/gremlin-server.sh ./conf/gremlin-server/rest-gremlin-server.yaml

Now you can query and update graph data using REST. For example, send REST requests using RESTClient in browser with following:

Method: POST
URL: http://x.x.x.x:8182
Body: {"gremlin":“query_to_run"}

You can find sample search and insert queries in samples/twitter-like-queries.txt

Sample output

Sample output for "Find Indiana Jones' tweets that his followers retweeted"

janusgraph-utils's People

Contributors

chinhuang007 avatar markstur avatar stevemart avatar tedhtchang avatar yhwang avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.