Skip to content

Commit

Permalink
Updates for Arango v3.1 and Java driver 4.7.x, Apache Camel v2.22.x
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonnin committed Nov 20, 2018
1 parent c77e6c4 commit 70b9328
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 135 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ buildNumber.properties
.classpath
.project
.settings/
.idea/
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Camel ArangoDB Component
For more details about ArangoDB, consult the [ArangoDB web site](https://www.arangodb.com/).

> ArangoDB is a multi-model database. But, at this moment, this component is only dedicated to the document model.
> ArangoDB is available as a Docker container: see https://www.arangodb.com/download-major/docker/

## Latest news

* Version 2.0: support for ArangoDB 3.1 or above (tested with 3.3.19)


## Build
Expand All @@ -12,6 +18,8 @@ For more details about ArangoDB, consult the [ArangoDB web site](https://www.ara
mvn clean install
```

> For the tests, start an ArangoDB server, e.g. `docker run -p 8529:8529 -e ARANGO_ROOT_PASSWORD=openSesame arangodb/arangodb:3.3.19`
## How to use

### Dependency
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>io.millesabords.camel</groupId>
<artifactId>camel-arangodb</artifactId>
<packaging>bundle</packaging>
<version>1.0</version>
<version>2.0</version>

<name>Camel :: ArangoDB</name>
<description>Camel ArangoDB component</description>
Expand All @@ -15,8 +15,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<camel.version>2.17.2</camel.version>
<arangodb.version>3.0.1</arangodb.version>
<camel.version>2.22.2</camel.version>
<arangodb.version>4.7.3</arangodb.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,41 @@

import java.util.Map;

import com.arangodb.ArangoDB;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.UriEndpointComponent;
import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.util.CamelContextHelper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.arangodb.ArangoConfigure;

/**
* Represents the component that manages {@link ArangoDbEndpoint}.
*/
public class ArangoDbComponent extends UriEndpointComponent {
public class ArangoDbComponent extends DefaultComponent {

private static final Logger LOG = LoggerFactory.getLogger(ArangoDbComponent.class);

public ArangoDbComponent() {
super(ArangoDbEndpoint.class);
}

public ArangoDbComponent(CamelContext context) {
super(context, ArangoDbEndpoint.class);
super(context);
}

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
ArangoConfigure config = null;

ArangoDB arango = null;

if (!StringUtils.isEmpty(remaining)) {
config = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, ArangoConfigure.class);
LOG.debug("Resolved the ArangoConfigure with the name {} as {}", remaining, config);
arango = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, ArangoDB.class);
LOG.debug("Resolved the ArangoDB with the name {} as {}", remaining, arango);
}

final ArangoDbEndpoint endpoint = new ArangoDbEndpoint(uri, this);
endpoint.setConfigure(config);
endpoint.setArango(arango);
setProperties(endpoint, parameters);
return endpoint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@

public interface ArangoDbConstants {

static final String ARANGO_OPERATION_HEADER = "_arango.operation";
String ARANGO_OPERATION_HEADER = "_arango.operation";

static final String ARANGO_COLLECTION_HEADER = "_arango.collection";
String ARANGO_COLLECTION_HEADER = "_arango.collection";

String ARANGO_DATABASE_HEADER = "_arango.database";

static final String ARANGO_AQL_QUERY_HEADER = "_arango.aql_query";
String ARANGO_AQL_QUERY_HEADER = "_arango.aql_query";

static final String ARANGO_AQL_QUERY_VARS_HEADER = "_arango.aql_query_vars";
String ARANGO_AQL_QUERY_VARS_HEADER = "_arango.aql_query_vars";

static final String ARANGO_INSERT_DOC = "insert";
String ARANGO_INSERT_DOC = "insert";

static final String ARANGO_UPDATE_DOC = "update";
String ARANGO_UPDATE_DOC = "update";

static final String ARANGO_DELETE_DOC = "delete";
String ARANGO_DELETE_DOC = "delete";

static final String ARANGO_GET_DOC = "get";
String ARANGO_GET_DOC = "get";

static final String ARANGO_AQL_QUERY = "aql_query";
String ARANGO_AQL_QUERY = "aql_query";

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.millesabords.camel.component.arangodb;

import com.arangodb.ArangoDB;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
Expand All @@ -11,14 +12,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.arangodb.ArangoConfigure;
import com.arangodb.ArangoDriver;
import com.arangodb.ArangoHost;

/**
* Represents an ArangoDB endpoint.
*/
@UriEndpoint(scheme = "arangodb", title = "ArangoDB", syntax = "arangodb:configBean", producerOnly = true, label = "database,nosql")
@UriEndpoint(scheme = "arangodb", title = "ArangoDB", syntax = "arangodb:arangoBean", producerOnly = true, label = "database,nosql")
public class ArangoDbEndpoint extends DefaultEndpoint {

private static final Logger LOG = LoggerFactory.getLogger(ArangoDbEndpoint.class);
Expand All @@ -27,9 +24,9 @@ public class ArangoDbEndpoint extends DefaultEndpoint {

private static final int DEFAULT_PORT = 8529;

/** Name of configuration bean. */
/** Name of ArangoDB bean. */
@UriPath
private String configBean;
private String arangoBean;

/** Name of the database. */
@UriParam @Metadata(required = "true")
Expand All @@ -46,6 +43,14 @@ public class ArangoDbEndpoint extends DefaultEndpoint {
/** Port of ArangoDB. */
@UriParam
private final int port = DEFAULT_PORT;

/** User name to access ArangoDB. */
@UriParam
private String user;

/** Password to access ArangoDB. */
@UriParam
private String password;

/** Operation to execute. */
@UriParam
Expand All @@ -55,9 +60,7 @@ public class ArangoDbEndpoint extends DefaultEndpoint {
@UriParam
private String aql;

private ArangoDriver driver;

private ArangoConfigure configure;
private ArangoDB arango;

private boolean mustShutdown;

Expand Down Expand Up @@ -88,24 +91,25 @@ public boolean isSingleton() {
protected void doStart() throws Exception {
super.doStart();

if (configure == null) {
if (arango == null) {
mustShutdown = true;
configure = new ArangoConfigure();
configure.setArangoHost(new ArangoHost(host, port));
configure.init();

final ArangoDB.Builder builder = new ArangoDB.Builder().host(host, port);

if (user != null) {
builder.user(user).password(password);
}

arango = builder.build();
}

configure.setDefaultDatabase(database);

driver = new ArangoDriver(configure);


LOG.info("Connected to {}:{}, default db is {}", host, port, database);
}

@Override
protected void doStop() throws Exception {
if (mustShutdown && configure != null) {
configure.shutdown();
if (mustShutdown && arango != null) {
arango.shutdown();
}
}

Expand All @@ -125,20 +129,12 @@ public void setCollection(String collection) {
this.collection = collection;
}

public ArangoDriver getDriver() {
return driver;
}

public void setDriver(ArangoDriver driver) {
this.driver = driver;
}

public ArangoConfigure getConfigure() {
return configure;
public ArangoDB getArango() {
return arango;
}

public void setConfigure(ArangoConfigure configure) {
this.configure = configure;
public void setArango(ArangoDB arango) {
this.arango = arango;
}

public boolean isMustShutdown() {
Expand All @@ -157,6 +153,14 @@ public int getPort() {
return port;
}

public String getUser() {
return user;
}

public String getPassword() {
return password;
}

public String getOperation() {
return operation;
}
Expand All @@ -173,12 +177,12 @@ public void setAql(String aql) {
this.aql = aql;
}

public String getConfigBean() {
return configBean;
public String getArangoBean() {
return arangoBean;
}

public void setConfigBean(String configBean) {
this.configBean = configBean;
public void setArangoBean(String arangoBean) {
this.arangoBean = arangoBean;
}

}
Loading

0 comments on commit 70b9328

Please sign in to comment.