Skip to content

Commit

Permalink
JanusGraph examples
Browse files Browse the repository at this point in the history
Fixes JanusGraph#530

Signed-off-by: Jason Plurad <pluradj@us.ibm.com>
  • Loading branch information
pluradj committed Sep 23, 2017
1 parent 7c951bb commit acaa79c
Show file tree
Hide file tree
Showing 40 changed files with 1,976 additions and 0 deletions.
11 changes: 11 additions & 0 deletions janusgraph-dist/src/assembly/descriptor/archive.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@
<componentDescriptor>${assembly.descriptor.dir}/htmldocs.component.xml</componentDescriptor>
<componentDescriptor>${assembly.descriptor.dir}/readmes.component.xml</componentDescriptor>
</componentDescriptors>

<fileSets>
<fileSet>
<directory>${top.level.basedir}/janusgraph-examples</directory>
<outputDirectory>/examples</outputDirectory>
<excludes>
<exclude>**/target/**</exclude>
</excludes>
</fileSet>
</fileSets>

</assembly>
39 changes: 39 additions & 0 deletions janusgraph-examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# JanusGraph Examples

The JanusGraph examples show the basics of how to configure and construct
a graph application. It uses [Apache Maven](https://maven.apache.org) to
manage the numerous dependencies required to build the application. The common
application will:

* Open and initialize the graph
* Define the schema
* Build the graph
* Run traversal queries to get data from the graph
* Make updates to the graph
* Close the graph

By using different graph configurations, the same example code can run against
the various supported storage and indexing backends.

## Prerequisites

* Java 8 Developer Kit, update 40 or higher
* Apache Maven, version 3.3 or higher

## Building the Examples

```
mvn clean install
```

## Running the Examples

Refer to the directions in each sub-directory.

* [Common](example-common/README.md)
* [BerkeleyJE](example-berkeleyje/README.md)
* [Cassandra](example-cassandra/README.md)
* [CQL](example-cql/README.md)
* [HBase](example-hbase/README.md)
* [RemoteGraph](example-remotegraph/README.md)
* [TinkerGraph](example-tinkergraph/README.md)
1 change: 1 addition & 0 deletions janusgraph-examples/example-berkeleyje/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jgex/
48 changes: 48 additions & 0 deletions janusgraph-examples/example-berkeleyje/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# BerkeleyJE Storage, Lucene Index

## About BerkeleyJE and Lucene

[Oracle Berkeley DB Java Edition](http://www.oracle.com/technetwork/database/berkeleydb/overview/index-093405.html)
is an embedded database, so it runs within your application rather than as
a standalone server. By including the `janusgraph-berkeleyje` dependency,
the required jar files are pulled in. The data is stored in a directory on
the file system.

[Apache Lucene](http://lucene.apache.org/) is an embedded index, so it runs
within your application rather than as a standalone server. By including the
`janusgraph-lucene` dependency, the required jar files are pulled in. The
data is stored in a directory on the file system.

## JanusGraph configuration

[`jgex-berkeleyje.properties`](conf/jgex-berkeleyje.properties) contains
the directory locations for BerkeleyJE and Lucene.

Refer to the JanusGraph [configuration reference](http://docs.janusgraph.org/latest/config-ref.html)
for additional properties.

## Running the example

Use [Apache Maven](http://maven.apache.org/) and the
[exec-maven-plugin](http://www.mojohaus.org/exec-maven-plugin/java-mojo.html)
to pull in the required jar files onto the runtime classpath.

```
$ cd $JANUSGRAPH_HOME/janusgraph-examples/example-berkeleyje
$ mvn exec:java -Dexec.mainClass="org.janusgraph.example.JanusGraphApp" -Dexec.args="conf/jgex-berkeleyje.properties"
```

## Drop the graph

Make sure to stop the application before dropping the graph. The configuration
uses the application name `jgex` as the root directory for the BerkeleyJE
and Lucene directories.

```
$ cd $JANUSGRAPH_HOME/janusgraph-examples/example-berkeleyje
$ mvn exec:java -Dexec.mainClass="org.janusgraph.example.JanusGraphApp" -Dexec.args="conf/jgex-berkeleyje.properties drop"
$ rm -rf jgex/
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
gremlin.graph=org.janusgraph.core.JanusGraphFactory

storage.backend=berkeleyje
storage.directory=jgex/berkeleyje

index.jgex.backend=lucene
index.jgex.directory=jgex/lucene
37 changes: 37 additions & 0 deletions janusgraph-examples/example-berkeleyje/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-examples</artifactId>
<version>0.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>example-berkeleyje</artifactId>
<packaging>pom</packaging>
<name>Example-BerkeleyJE: BerkeleyJE Storage, Lucene Index</name>
<url>http://janusgraph.org</url>

<dependencies>
<!-- These are all runtime dependencies -->
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>example-common</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-berkeleyje</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-lucene</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>

</project>
53 changes: 53 additions & 0 deletions janusgraph-examples/example-cassandra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Cassandra Thrift Storage, Elasticsearch Index

## About Cassandra and Elasticsearch

[Apache Cassandra](http://cassandra.apache.org/) is a distributed database
designed for scalability and high availability. Cassandra supports two
protocols for communications, Thrift (legacy RPC protocol) and CQL (native
protocol). Depending on the Cassandra version, Thrift may not be started by
default. Make sure that [Thrift is started](http://docs.datastax.com/en/cassandra/2.1/cassandra/tools/toolsStatusThrift.html)
when using this example.

[Elasticsearch](https://www.elastic.co/products/elasticsearch) is a scalable,
distributed search engine.

> Check the JanusGraph [version compatibility](http://docs.janusgraph.org/latest/version-compat.html)
to ensure you select versions of Cassandra and Elasticsearch compatible with
this JanusGraph release.

## JanusGraph configuration

* [`jgex-cassandra.properties`](conf/jgex-cassandra.properties) contains the
Cassandra and Elasticsearch server locations. By providing different values
for `storage.cassandra.keyspace` and `index.jgex.index-name`, you can store
multiple graphs on the same Cassandra and Elasticsearch servers. Refer to
the JanusGraph [configuration reference](http://docs.janusgraph.org/latest/config-ref.html)
for additional properties.

* [`logback.xml`](conf/logback.xml) configures logging with [Logback](https://logback.qos.ch/),
which is the logger used by Cassandra. The example configuration logs to the
console and adjusts the logging level for some noisier packages. Refer to
the Logback [manual](https://logback.qos.ch/manual/index.html) for additional
details.

## Run the example

Use [Apache Maven](http://maven.apache.org/) and the [exec-maven-plugin](http://www.mojohaus.org/exec-maven-plugin/java-mojo.html)
to pull in the required jar files onto the runtime classpath.

```
$ cd $JANUSGRAPH_HOME/janusgraph-examples/example-cassandra
$ mvn exec:java -Dexec.mainClass="org.janusgraph.example.JanusGraphApp" -Dlogback.configurationFile="conf/logback.xml" -Dexec.args="conf/jgex-cassandra.properties"
```

## Drop the graph

Make sure to stop the application before dropping the graph.

```
$ cd $JANUSGRAPH_HOME/janusgraph-examples/example-cassandra
$ mvn exec:java -Dexec.mainClass="org.janusgraph.example.JanusGraphApp" -Dlogback.configurationFile="conf/logback.xml" -Dexec.args="conf/jgex-cassandra.properties drop"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
gremlin.graph=org.janusgraph.core.JanusGraphFactory

storage.backend=cassandra
storage.cassandra.keyspace=jgex
storage.hostname=127.0.0.1

index.jgex.backend=elasticsearch
index.jgex.index-name=jgex
index.jgex.hostname=127.0.0.1
13 changes: 13 additions & 0 deletions janusgraph-examples/example-cassandra/conf/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss} %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<logger name="com.netflix.astyanax.connectionpool.impl" level="WARN"/>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
37 changes: 37 additions & 0 deletions janusgraph-examples/example-cassandra/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-examples</artifactId>
<version>0.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>example-cassandra</artifactId>
<packaging>pom</packaging>
<name>Example-Cassandra: C* Thrift Storage, ES Index</name>
<url>http://janusgraph.org</url>

<dependencies>
<!-- These are all runtime dependencies -->
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>example-common</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-cassandra</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-es</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>

</project>
24 changes: 24 additions & 0 deletions janusgraph-examples/example-common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Common Example

## About the common example

`GraphApp` is an abstract class that defines a basic structure for a graph
application. It contains methods for configuring a graph instance, defining
a graph schema, creating a graph structure, and querying a graph.

`JanusGraphApp` is a subclass of `GraphApp` using JanusGraph-specific methods
to create the schema.

## In-Memory configuration

[`jgex-inmemory.properties`](conf/jgex-inmemory.properties) contains the
settings for the JanusGraph [in-memory storage backend](http://docs.janusgraph.org/latest/inmemorystorage.html).
This backend is primarily for testing purposes.

## Running the example

```
$ cd $JANUSGRAPH_HOME/janusgraph-examples/example-common
$ mvn exec:java -Dexec.mainClass="org.janusgraph.example.JanusGraphApp" -Dexec.args="conf/jgex-inmemory.properties"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gremlin.graph=org.janusgraph.core.JanusGraphFactory

storage.backend=inmemory
22 changes: 22 additions & 0 deletions janusgraph-examples/example-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-examples</artifactId>
<version>0.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>example-common</artifactId>
<name>Example-Common: Common Graph Code for Examples</name>
<url>http://janusgraph.org</url>

<dependencies>
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit acaa79c

Please sign in to comment.