A Dropwizard library that enables connectivity to DSEGraph enabled gremlin servers.
- Configuration
- Health Check
- Managed Cluster
The configuration class includes all of the parameters required to configure a remote connection to a DSEGraph cluster. The default values correspond to all of the defaults specified in the DSEGraph cluster builder.
A health check is setup using the dropwizard health check registry. It executes the
validationQuery
specified in the configuration. It will succeed if the query responds within the
validationQueryTimeout
specified.
The Cluster
built from the DseGraphFactory
is included in dropwizard's managed lifecycle. This
will allow dropwizard to try and gracefully shut down the DSEGraph client connections on shutdown.
This utility includes references to DSE Graph and DropWizard. To maintain correct versions of these 3rd party libraries, there is a Dependency Management section in the POM. To use it, include the following in your pom (NOTE: dropwizard-swagger is only included as an example how to use the proper version to get swagger support):
<properties>
<dropwizard-desgraph.version>1.4.0</dropwizard-desgraph.version>
<dropwizard.version>1.2.5</dropwizard.version>
<desgraph.version>1.2.6</desgraph.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-bom</artifactId>
<version>${dropwizard.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.experoinc</groupId>
<artifactId>dropwizard-dsegraph</artifactId>
<version>${dropwizard-desgraph.version}</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-auth</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-forms</artifactId>
</dependency>
<dependency>
<groupId>com.datastax.dse</groupId>
<artifactId>dse-java-driver-graph</artifactId>
<version>${desgraph.version}</version>
</dependency>
</dependencies>
Include a DseGraphConfiguration
instance in your application config
public class ApplicationConfig extends Configuration {
@Getter
@Valid
@NonNull
private DseGraphBundleConfiguration dseGraph;
}
Define the graph properties:
dseGraph:
graphName: ${DB_NAME:-dse_graph}
#port: 9042 # WARNING: port is non-functional currently, but coming soon
contactPoints:
- ${DB_HOST:-1.2.3.4}
- ${DB_HOST:-5.6.7.8}
# These are optional and defaulted to the values below
shutdownTimeout: 60000
validationQuery: "g.inject(1).hasNext()"
validationQueryTimeout: 10000
Optionally, DSE authentication can be enabled by including userName
& password
values:
dseGraph:
<...>
userName: ${DB_USER:-username}
password: ${DB_PASS:-password}
Optionally, SSL encrypted conections to the cluster can be configured. This approach uses truststore and keystore files which were genereated with OpenSSL and Java keytool
as described in Setting up SSL certificates in the DataStax documentation
Basic SSL only requires a truststore with the DSE cluster public certificates or the public key which has signed the certificates. This is configured with sslTruststoreFile
and sslTruststorePassword
.
If authentication of the client certificates is also required, this is configured with sslKeystoreFile
and sslKeystorePassword
.
dseGraph:
<...>
sslTruststoreFile: ${SSL_TRUSTSTORE_FILE:-\path\to\client.truststore}
sslTruststorePassword: "${SSL_TRUSTSTORE_PASSWORD:-sslTruststorePassword}"
sslKeystoreFile: ${SSL_KEYSTORE_FILE:-\path\to\client.keystore}
sslKeystorePassword: "${SSL_KEYSTORE_PASSWORD:-sslKeystorePassword}"
Instantiate and add the DseGraph bundle in your Application
class and refer to it in the run(ApplicationConfig configuration, Environment environment)
method:
public class App extends Application<ApplicationConfig> {
private final DseGraphBundle<ApplicationConfig> dseGraphBundle =
new DseGraphBundle<ApplicationConfig>() {
@Override
protected DseGraphBundleConfiguration getDseGraphBundleConfiguration(ApplicationConfig configuration) {
return configuration.getDseGraph();
}
};
@Override
public void initialize(Bootstrap<ApplicationConfig> bootstrap) {
bootstrap.addBundle(dseGraphBundle);
}
@Override
public void run(final ApplicationConfig configuration, final Environment environment) {
environment.jersey().register(new MyClusterResource(dseGraphBundle.getCluster()));
environment.jersey().register(new MySessionResource(dseGraphBundle.getSession()));
environment.jersey().register(new MyTraversalResource(dseGraphBundle.getG()));
}
}