Skip to content
Jesse White edited this page Apr 3, 2017 · 5 revisions

Using the Java API

Configuring Maven

Add the following dependency to your pom.xml:

<dependency>
  <groupId>org.opennms.newts</groupId>
  <artifactId>newts-cassandra</artifactId>
  <version>1.4.3</version>
</dependency>

Additionally, if you wish to enable search lookups and indexing, add the following as well:

<dependency>
  <groupId>org.opennms.newts</groupId>
  <artifactId>newts-cassandra-search</artifactId>
  <version>1.4.3</version>
</dependency>

Creating Schema

Newts modules register any Cassandra schema they require using the Java ServiceLoader mechanism. You can use a ServiceLoader to discover these schemas, and the org.opennms.newts.cassandra.SchemaManager class to apply them to a running Cassandra cluster. For example:

// Find all registered instances of Schema.class
ServiceLoader<Schema> schemas = ServiceLoader.load(Schema.class);

// Create each discovered schema
try (SchemaManager m = new SchemaManager(keyspace, host, port, "cassandra", "cassandra", false)) {
    for (Schema s : schemas)
        m.create(s, true);
}

Important Note on Keyspaces!

If necessary (if an existing keyspace does not exist), these schemas will create a keyspace using Cassandra's SimpleStategy and a replication factor of 1 (read: no replication). For all but the most trivial of test installs, this is probably not what you want. Therefore, you can either a) create your keyspace beforehand, or b) alter the automatically generated one after the fact.

See Also

The Java API Reference.

Clone this wiki locally