Influxdb component created
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2976e7dd Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2976e7dd Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2976e7dd Branch: refs/heads/master Commit: 2976e7dd9bfbcee7dadb4658ee2666837c71a035 Parents: f496aac Author: Jose Luis Pedrosa <jlpedr...@gmail.com> Authored: Sun Jun 19 00:17:15 2016 +0200 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Fri Jul 15 09:21:19 2016 +0200 ---------------------------------------------------------------------- apache-camel/pom.xml | 4 + .../src/main/descriptors/common-bin.xml | 1 + components/camel-influxdb/pom.xml | 69 +++++++ .../camel-influxdb/src/main/docs/influxdb.adoc | 107 ++++++++++ .../influxdb/CamelInfluxDbException.java | 32 +++ .../component/influxdb/InfluxDbComponent.java | 63 ++++++ .../component/influxdb/InfluxDbConstants.java | 33 +++ .../component/influxdb/InfluxDbEndpoint.java | 157 ++++++++++++++ .../component/influxdb/InfluxDbProducer.java | 97 +++++++++ .../converters/CamelInfluxDbConverters.java | 59 ++++++ .../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++++++++++ .../src/main/resources/META-INF/NOTICE.txt | 11 + .../services/org/apache/camel/TypeConverter | 18 ++ .../org/apache/camel/component/influxdb | 18 ++ .../influxdb/AbstractInfluxDbTest.java | 40 ++++ .../influxdb/InfluxDbProducerTest.java | 116 +++++++++++ .../influxdb/MockedInfluxDbConfiguration.java | 51 +++++ .../converters/CamelInfluxDbConverterTest.java | 108 ++++++++++ .../src/test/resources/influxdb.test.properties | 1 + .../src/test/resources/log4j.properties | 35 ++++ components/pom.xml | 1 + parent/pom.xml | 6 + .../features/src/main/resources/features.xml | 6 + 23 files changed, 1236 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/apache-camel/pom.xml ---------------------------------------------------------------------- diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml index e2e6001..6595f1a 100644 --- a/apache-camel/pom.xml +++ b/apache-camel/pom.xml @@ -381,6 +381,10 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-influxdb</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-irc</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/apache-camel/src/main/descriptors/common-bin.xml ---------------------------------------------------------------------- diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml index 5f3e9bc..1e71816 100644 --- a/apache-camel/src/main/descriptors/common-bin.xml +++ b/apache-camel/src/main/descriptors/common-bin.xml @@ -106,6 +106,7 @@ <include>org.apache.camel:camel-ibatis</include> <include>org.apache.camel:camel-ical</include> <include>org.apache.camel:camel-infinispan</include> + <include>org.apache.camel:camel-influxdb</include> <include>org.apache.camel:camel-ignite</include> <include>org.apache.camel:camel-irc</include> <include>org.apache.camel:camel-ironmq</include> http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/pom.xml b/components/camel-influxdb/pom.xml new file mode 100644 index 0000000..53c476a --- /dev/null +++ b/components/camel-influxdb/pom.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor + license agreements. See the NOTICE file distributed with this work for additional + information regarding copyright ownership. The ASF licenses this file to + You under the Apache License, Version 2.0 (the "License"); you may not use + this file except in compliance with the License. You may obtain a copy of + the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required + by applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS + OF ANY KIND, either express or implied. See the License for the specific + language governing permissions and limitations under the License. --> +<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/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>components</artifactId> + <version>2.18-SNAPSHOT</version> + </parent> + + <artifactId>camel-influxdb</artifactId> + <packaging>jar</packaging> + <name>Camel :: InfluxDB</name> + <description>Camel InfluxDB component</description> + + <properties> + <camel.osgi.export.pkg>org.apache.camel.component.influxdb.*</camel.osgi.export.pkg> + <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=influxdb</camel.osgi.export.service> + </properties> + + <dependencies> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + </dependency> + + <!-- InfluxDB driver dependency --> + <dependency> + <groupId>org.influxdb</groupId> + <artifactId>influxdb-java</artifactId> + <version>${influx-java-driver-version}</version> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-spring</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/main/docs/influxdb.adoc ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/main/docs/influxdb.adoc b/components/camel-influxdb/src/main/docs/influxdb.adoc new file mode 100644 index 0000000..b7ffb1c --- /dev/null +++ b/components/camel-influxdb/src/main/docs/influxdb.adoc @@ -0,0 +1,107 @@ +[[InfluxDb-InfluxDbComponent]] +InfluxDb Component +~~~~~~~~~~~~~~~~~~~~ + +*Available as of Camel 2.18.0* + +This component allows you to interact with InfluxDB +https://influxdata.com/time-series-platform/influxdb/ a time series database. The native body type for this component is +Point (the native influxdb class), but it can also accept Map<String, Object> as message body and it will get converted +to Point.class, please note that the map must contain an element with InfluxDbConstants.MEASUREMENT_NAME as key. + +Aditionally of course you may register your own Converters to your data type to Point, or use the +(un)marshalling tools provided by camel. + + +From *Camel 2.18* onwards Influxdb requires Java 8. + +Maven users will need to add the following dependency to their `pom.xml` +for this component: + +[source,xml] +------------------------------------------------------------ +<dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-influxdb</artifactId> + <version>x.x.x</version> + <!-- use the same version as your Camel core version --> +</dependency> +------------------------------------------------------------ + +[[InfluxDb-URIformat]] +URI format +^^^^^^^^^^ + +[source,java] +------------------------------- +influxdb://beanName?[options] +------------------------------- + +[[InfluxDb-URIOptions]] +URI Options +^^^^^^^^^^^ + +The producer allows sending messages to a influxdb +configured in the registry, using the native java driver. + + +// component options: START +The InfluxDb component has no options. +// component options: END + + +// endpoint options: START +The InfluxDb component supports 15 endpoint options which are listed below: + +{% raw %} +[width="100%",cols="2s,1,1m,1m,5",options="header"] +|======================================================================= +|======================================================================= +{% endraw %} +// endpoint options: END + + + +[[InfluxDb-MessageHeaders]] +Message Headers +^^^^^^^^^^^^^^^ + +[width="100%",cols="10%,10%,10%,10%,60%",options="header",] +|======================================================================= +|Name |Default Value |Type |Context |Description + + +|======================================================================= + +[[InfluxDb-Example]] +Example +^^^^^^^ + + +Below is an example route that stores a point into the db (taking the db name from the URI) +specific key: + +[source,java] +------------------------------------------------------------------------------------ +from("direct:start") + .setHeader(InfluxDbConstants.DBNAME_HEADER, constant("myTimeSeriesDB")) + .to("influxdb://connectionBean); +------------------------------------------------------------------------------------ + +[source,java] +------------------------------------------------------------------------------------ +from("direct:start") + .to("influxdb://connectionBean?databaseName=myTimeSeriesDB"); +------------------------------------------------------------------------------------ + +For more information, see these resources... + +[[InfluxDb-SeeAlso]] +See Also +^^^^^^^^ + +* link:configuring-camel.html[Configuring Camel] +* link:component.html[Component] +* link:endpoint.html[Endpoint] +* link:getting-started.html[Getting Started] + http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/CamelInfluxDbException.java ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/CamelInfluxDbException.java b/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/CamelInfluxDbException.java new file mode 100644 index 0000000..aedbfb5 --- /dev/null +++ b/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/CamelInfluxDbException.java @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.influxdb; + +public class CamelInfluxDbException extends RuntimeException { + + public CamelInfluxDbException(String message, Throwable cause) { + super(message, cause); + } + + public CamelInfluxDbException(String message) { + super(message); + } + + public CamelInfluxDbException(Throwable cause) { + super(cause); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbComponent.java b/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbComponent.java new file mode 100644 index 0000000..9cb5657 --- /dev/null +++ b/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbComponent.java @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.influxdb; + +import java.util.Map; + +import org.apache.camel.Endpoint; +import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.impl.UriEndpointComponent; +import org.apache.camel.util.CamelContextHelper; +import org.influxdb.InfluxDB; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Created by jose on 18/06/16. + */ +public class InfluxDbComponent extends UriEndpointComponent { + + private static final Logger LOG = LoggerFactory.getLogger(InfluxDbComponent.class); + + InfluxDB influxDbConnection; + + + public InfluxDbComponent() { + super(InfluxDbEndpoint.class); + this.influxDbConnection = null; + } + + + + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + if (LOG.isDebugEnabled()) { + LOG.debug("Creating influx db endpoint"); + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Looking for influxDb connection bean, remaining {}", remaining); + } + + if (influxDbConnection == null) { + influxDbConnection = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, InfluxDB.class); + } + + return new InfluxDbEndpoint(uri, this, influxDbConnection); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbConstants.java ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbConstants.java b/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbConstants.java new file mode 100644 index 0000000..e98d947 --- /dev/null +++ b/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbConstants.java @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.influxdb; + +/** + * Created by jose on 18/06/16. + */ +public final class InfluxDbConstants { + + public static final String MEASUREMENT_NAME = "camelInfluxDB.MeasurementName"; + public static final String RETENTION_POLICY_HEADER = "camelInfluxDB.RetentionPolicy"; + public static final String DBNAME_HEADER = "camelInfluxDB.databaseName"; + + private InfluxDbConstants() { + + } + + +} http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbEndpoint.java b/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbEndpoint.java new file mode 100644 index 0000000..f0fc3f9 --- /dev/null +++ b/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbEndpoint.java @@ -0,0 +1,157 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.influxdb; + +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.impl.DefaultEndpoint; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; +import org.apache.camel.util.CamelContextHelper; +import org.influxdb.InfluxDB; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@UriEndpoint(scheme = "influxdb", title = "InfluxDB", syntax = "influxdb:connectionBean", label = "database,ticks", producerOnly = true) +public class InfluxDbEndpoint extends DefaultEndpoint { + + private static final Logger LOG = LoggerFactory.getLogger(InfluxDbEndpoint.class); + + private InfluxDB influxDB; + + @UriPath + @Metadata(required = "true", description = "Connection to the influx database, of class InfluxDB.class") + private String connectionBean; + + @UriParam(description = "the name of the series where the points will be created, name can be modified dynamically by headers") + private String databaseName; + + @UriParam(defaultValue = "default", description = "defines the retention policy for the points created in influxdb") + private String retentionPolicy = "default"; + + /** + * @param uri + * @param influxDbComponent + */ + public InfluxDbEndpoint(String uri, InfluxDbComponent influxDbComponent, InfluxDB dbConn) { + super(uri, influxDbComponent); + + if (dbConn == null) { + throw new IllegalArgumentException("dbConn is null"); + } + + this.influxDB = dbConn; + + if (LOG.isDebugEnabled()) { + LOG.debug("Prepairing influxdb enpoint with uri {}", uri); + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Creating influx db producer connectionBean:{}, databaseName:{}, retentionPolicy:{}", connectionBean, databaseName, retentionPolicy); + } + + } + + @Override + public Producer createProducer() throws Exception { + + if (LOG.isDebugEnabled()) { + LOG.debug("Creating influx db producer"); + } + return new InfluxDbProducer(this); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + if (LOG.isDebugEnabled()) { + LOG.debug("Creating influx db consumer"); + } + throw new UnsupportedOperationException("You cannot receive messages from this endpoint"); + } + + @Override + public boolean isSingleton() { + return false; + } + + + + public InfluxDB getInfluxDB() { + return influxDB; + } + + public void setInfluxDB(InfluxDB influxDB) { + this.influxDB = influxDB; + } + + /** + * Getter for databaseName + * + * @return the name of the database where the time series will be stored + */ + public String getDatabaseName() { + return databaseName; + } + + /** + * Setter for databaseName + * + * @param databaseName + */ + public void setDatabaseName(String databaseName) { + this.databaseName = databaseName; + } + + /** + * Getter for retentionPolicy + * + * @return the string that defines the retention policy to the data created + * by the endpoint + */ + public String getRetentionPolicy() { + return retentionPolicy; + } + + /** + * Setter for retentionPolicy + * + * @param retentionPolicy + */ + public void setRetentionPolicy(String retentionPolicy) { + this.retentionPolicy = retentionPolicy; + } + + /** + * Getter for connectionBean + * + * @return the name of the bean for the {@link org.influxdb.InfluxDB} + * connection + */ + public String getConnectionBean() { + return connectionBean; + } + + /** + * Name of {@link org.influxdb.InfluxDB} to use. + */ + public void setConnectionBean(String connectionBean) { + this.connectionBean = connectionBean; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbProducer.java b/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbProducer.java new file mode 100644 index 0000000..92b4fc3 --- /dev/null +++ b/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/InfluxDbProducer.java @@ -0,0 +1,97 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.influxdb; + +import org.apache.camel.Exchange; +import org.apache.camel.impl.DefaultProducer; +import org.influxdb.InfluxDB; +import org.influxdb.dto.Point; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Producer for the InfluxDB components + * + */ +public class InfluxDbProducer extends DefaultProducer { + + private static final Logger LOG = LoggerFactory.getLogger(InfluxDbProducer.class); + + InfluxDbEndpoint endpoint; + InfluxDB connection; + + public InfluxDbProducer(InfluxDbEndpoint endpoint) { + super(endpoint); + if (endpoint == null) { + throw new IllegalArgumentException("Can't create a producer when the endpoint is null"); + } + + if (endpoint.getInfluxDB() == null) { + throw new IllegalArgumentException("Can't create a producer when the database connection is null"); + } + + this.connection = endpoint.getInfluxDB(); + this.endpoint = endpoint; + } + + /** + * Processes the message exchange + * + * @param exchange the message exchange + * @throws Exception if an internal processing error has occurred. + */ + @Override + public void process(Exchange exchange) throws Exception { + + String dataBaseName = calculateDatabaseName(exchange); + String retentionPolicy = calculateRetentionPolicy(exchange); + Point p = exchange.getIn().getMandatoryBody(Point.class); + + + + try { + if (LOG.isDebugEnabled()) { + LOG.debug("Writing point {}", p.lineProtocol()); + } + + connection.write(dataBaseName, retentionPolicy, p); + } catch (Exception ex) { + exchange.setException(new CamelInfluxDbException(ex)); + } + } + + private String calculateRetentionPolicy(Exchange exchange) { + String retentionPolicy = exchange.getIn().getHeader(InfluxDbConstants.RETENTION_POLICY_HEADER, String.class); + + if (retentionPolicy != null) { + return retentionPolicy; + } + + return endpoint.getRetentionPolicy(); + } + + private String calculateDatabaseName(Exchange exchange) { + String dbName = exchange.getIn().getHeader(InfluxDbConstants.DBNAME_HEADER, String.class); + + if (dbName != null) { + return dbName; + } + + return endpoint.getDatabaseName(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/converters/CamelInfluxDbConverters.java ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/converters/CamelInfluxDbConverters.java b/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/converters/CamelInfluxDbConverters.java new file mode 100644 index 0000000..e3da9cf --- /dev/null +++ b/components/camel-influxdb/src/main/java/org/apache/camel/component/influxdb/converters/CamelInfluxDbConverters.java @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.influxdb.converters; + +import java.util.Map; + +import org.apache.camel.Converter; +import org.apache.camel.component.influxdb.CamelInfluxDbException; +import org.apache.camel.component.influxdb.InfluxDbConstants; +import org.influxdb.dto.Point; + + +@Converter +public final class CamelInfluxDbConverters { + + private CamelInfluxDbConverters() { + + } + + @Converter + public static Point fromMapToPoint(Map<String, Object> map) { + + Object measurenmentName = map.get(InfluxDbConstants.MEASUREMENT_NAME); + + if (measurenmentName == null) { + String format = String.format("Unable to find the header for the measurement " + map.size() + " to:" + map.keySet().toString()); + throw new CamelInfluxDbException(format); + } + + + String measurenmentNameString = measurenmentName.toString(); + Point.Builder pointBuilder = Point.measurement(measurenmentNameString); + + map.remove(InfluxDbConstants.MEASUREMENT_NAME); + + pointBuilder.fields(map); + map.put(InfluxDbConstants.MEASUREMENT_NAME, measurenmentName); + + + return pointBuilder.build(); + + } + + +} http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/main/resources/META-INF/LICENSE.txt ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/main/resources/META-INF/LICENSE.txt b/components/camel-influxdb/src/main/resources/META-INF/LICENSE.txt new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/components/camel-influxdb/src/main/resources/META-INF/LICENSE.txt @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/main/resources/META-INF/NOTICE.txt ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/main/resources/META-INF/NOTICE.txt b/components/camel-influxdb/src/main/resources/META-INF/NOTICE.txt new file mode 100644 index 0000000..2e215bf --- /dev/null +++ b/components/camel-influxdb/src/main/resources/META-INF/NOTICE.txt @@ -0,0 +1,11 @@ + ========================================================================= + == NOTICE file corresponding to the section 4 d of == + == the Apache License, Version 2.0, == + == in this case for the Apache Camel distribution. == + ========================================================================= + + This product includes software developed by + The Apache Software Foundation (http://www.apache.org/). + + Please read the different LICENSE files present in the licenses directory of + this distribution. http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/main/resources/META-INF/services/org/apache/camel/TypeConverter ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/main/resources/META-INF/services/org/apache/camel/TypeConverter b/components/camel-influxdb/src/main/resources/META-INF/services/org/apache/camel/TypeConverter new file mode 100644 index 0000000..31a3bb9 --- /dev/null +++ b/components/camel-influxdb/src/main/resources/META-INF/services/org/apache/camel/TypeConverter @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +org.apache.camel.component.influxdb.converters.CamelInfluxDbConverters http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/main/resources/META-INF/services/org/apache/camel/component/influxdb ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/main/resources/META-INF/services/org/apache/camel/component/influxdb b/components/camel-influxdb/src/main/resources/META-INF/services/org/apache/camel/component/influxdb new file mode 100644 index 0000000..a0d9e3c --- /dev/null +++ b/components/camel-influxdb/src/main/resources/META-INF/services/org/apache/camel/component/influxdb @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +class=org.apache.camel.component.influxdb.InfluxDbComponent + http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/AbstractInfluxDbTest.java ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/AbstractInfluxDbTest.java b/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/AbstractInfluxDbTest.java new file mode 100644 index 0000000..f4719d5 --- /dev/null +++ b/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/AbstractInfluxDbTest.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.component.influxdb; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.properties.PropertiesComponent; +import org.apache.camel.spring.SpringCamelContext; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +public class AbstractInfluxDbTest extends CamelTestSupport { + + protected ApplicationContext applicationContext; + + @Override + protected CamelContext createCamelContext() throws Exception { + applicationContext = new AnnotationConfigApplicationContext(MockedInfluxDbConfiguration.class); + CamelContext ctx = new SpringCamelContext(applicationContext); + PropertiesComponent pc = new PropertiesComponent("classpath:influxdb.test.properties"); + ctx.addComponent("properties", pc); + return ctx; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/InfluxDbProducerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/InfluxDbProducerTest.java b/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/InfluxDbProducerTest.java new file mode 100644 index 0000000..4dd6cae --- /dev/null +++ b/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/InfluxDbProducerTest.java @@ -0,0 +1,116 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.component.influxdb; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.EndpointInject; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Before; +import org.junit.Test; + +public class InfluxDbProducerTest extends AbstractInfluxDbTest { + + @EndpointInject(uri = "mock:test") + MockEndpoint successEndpoint; + + @EndpointInject(uri = "mock:error") + MockEndpoint errorEndpoint; + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + + errorHandler(deadLetterChannel("mock:error").redeliveryDelay(0).maximumRedeliveries(0)); + + //test route + from("direct:test") + .to("influxdb:influxDbBean?databaseName={{influxdb.testDb}}") + .to("mock:test"); + } + }; + } + + @Before + public void resetEndpoints() { + errorEndpoint.reset(); + successEndpoint.reset(); + } + + @Test + public void writePointFromMapAndStaticDbName() throws InterruptedException { + + errorEndpoint.expectedMessageCount(0); + successEndpoint.expectedMessageCount(1); + + Map<String, Object> pointMap = createMapPoint(); + sendBody("direct:test", pointMap); + + errorEndpoint.assertIsSatisfied(); + successEndpoint.assertIsSatisfied(); + + } + + @Test + public void writePointFromMapAndDynamicDbName() throws InterruptedException { + + errorEndpoint.expectedMessageCount(0); + successEndpoint.expectedMessageCount(1); + + Map<String, Object> pointMap = createMapPoint(); + Map<String, Object> header = createHeader(); + sendBody("direct:test", pointMap, header); + + errorEndpoint.assertIsSatisfied(); + successEndpoint.assertIsSatisfied(); + + } + + @Test + public void missingMeassurementNameFails() throws InterruptedException { + + errorEndpoint.expectedMessageCount(1); + successEndpoint.expectedMessageCount(0); + + Map<String, Object> pointMap = new HashMap<>(); + pointMap.remove(InfluxDbConstants.MEASUREMENT_NAME); + sendBody("direct:test", pointMap); + + + errorEndpoint.assertIsSatisfied(); + successEndpoint.assertIsSatisfied(); + + } + + private Map<String, Object> createHeader() { + Map<String, Object> header = new HashMap<>(); + header.put(InfluxDbConstants.DBNAME_HEADER, "myOtherDatabase"); + return header; + } + + private Map<String, Object> createMapPoint() { + Map<String, Object> pointMap = new HashMap<>(); + pointMap.put(InfluxDbConstants.MEASUREMENT_NAME, "MyTestMeasurement"); + pointMap.put("CPU", 1); + return pointMap; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/MockedInfluxDbConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/MockedInfluxDbConfiguration.java b/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/MockedInfluxDbConfiguration.java new file mode 100644 index 0000000..08f9fed --- /dev/null +++ b/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/MockedInfluxDbConfiguration.java @@ -0,0 +1,51 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.component.influxdb; + +import java.net.UnknownHostException; + +import static junit.framework.TestCase.assertNotNull; + +import org.influxdb.InfluxDB; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +import static org.mockito.Mockito.*; + +@Configuration +public class MockedInfluxDbConfiguration { + + private static final Logger LOG = LoggerFactory.getLogger(MockedInfluxDbConfiguration.class); + + @Bean + public InfluxDB influxDbBean() throws UnknownHostException { + + if (LOG.isDebugEnabled()) { + LOG.debug("Creating new instance of a mocked influx db connection"); + } + InfluxDB mockedDbConnection = mock(InfluxDB.class); + //InfluxDB mockedDbConnection = InfluxDBFactory.connect("http://127.0.0.1:8086", "root", "root"); + assertNotNull(mockedDbConnection); + return mockedDbConnection; + } + + +} http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/converters/CamelInfluxDbConverterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/converters/CamelInfluxDbConverterTest.java b/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/converters/CamelInfluxDbConverterTest.java new file mode 100644 index 0000000..82ada82 --- /dev/null +++ b/components/camel-influxdb/src/test/java/org/apache/camel/component/influxdb/converters/CamelInfluxDbConverterTest.java @@ -0,0 +1,108 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.camel.component.influxdb.converters; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.component.influxdb.InfluxDbConstants; +import org.influxdb.dto.Point; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + + +public class CamelInfluxDbConverterTest { + + private static final Logger LOG = LoggerFactory.getLogger(CamelInfluxDbConverterTest.class); + + @Test + public void doesNotAddCamelHeaders() { + Map<String, Object> pointInMapFormat = new HashMap<>(); + pointInMapFormat.put(InfluxDbConstants.MEASUREMENT_NAME, "testCPU"); + double value = 99.999999d; + pointInMapFormat.put("busy", value); + + Point p = CamelInfluxDbConverters.fromMapToPoint(pointInMapFormat); + assertNotNull(p); + + String line = p.lineProtocol(); + + assertNotNull(line); + LOG.debug("doesNotAddCamelHeaders generated: \"{}\"", line); + assertTrue(!line.contains(InfluxDbConstants.MEASUREMENT_NAME)); + + } + + @Test + public void canAddDouble() { + Map<String, Object> pointInMapFormat = new HashMap<>(); + pointInMapFormat.put(InfluxDbConstants.MEASUREMENT_NAME, "testCPU"); + double value = 99.999999d; + pointInMapFormat.put("busy", value); + + Point p = CamelInfluxDbConverters.fromMapToPoint(pointInMapFormat); + assertNotNull(p); + + String line = p.lineProtocol(); + + assertNotNull(line); + LOG.debug("Doublecommand generated: \"{}\"", line); + assertTrue(line.contains("busy=99.999999")); + + } + + @Test + public void canAddInt() { + Map<String, Object> pointInMapFormat = new HashMap<>(); + pointInMapFormat.put(InfluxDbConstants.MEASUREMENT_NAME, "testCPU"); + int value = 99999999; + pointInMapFormat.put("busy", value); + + Point p = CamelInfluxDbConverters.fromMapToPoint(pointInMapFormat); + assertNotNull(p); + + String line = p.lineProtocol(); + + assertNotNull(line); + LOG.debug("Int command generated: \"{}\"", line); + assertTrue(line.contains("busy=99999999")); + + } + + @Test + public void canAddByte() { + Map<String, Object> pointInMapFormat = new HashMap<>(); + pointInMapFormat.put(InfluxDbConstants.MEASUREMENT_NAME, "testCPU"); + byte value = Byte.MAX_VALUE; + pointInMapFormat.put("busy", value); + + Point p = CamelInfluxDbConverters.fromMapToPoint(pointInMapFormat); + assertNotNull(p); + + String line = p.lineProtocol(); + + assertNotNull(line); + LOG.debug("Byte command generated: \"{}\"", line); + assertTrue(line.contains("busy=127")); + + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/test/resources/influxdb.test.properties ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/test/resources/influxdb.test.properties b/components/camel-influxdb/src/test/resources/influxdb.test.properties new file mode 100644 index 0000000..c7c65e1 --- /dev/null +++ b/components/camel-influxdb/src/test/resources/influxdb.test.properties @@ -0,0 +1 @@ +influxdb.testDb=myTestTimeSeries \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/camel-influxdb/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-influxdb/src/test/resources/log4j.properties b/components/camel-influxdb/src/test/resources/log4j.properties new file mode 100644 index 0000000..4bc1764 --- /dev/null +++ b/components/camel-influxdb/src/test/resources/log4j.properties @@ -0,0 +1,35 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +log4j.rootLogger=INFO, file +# change the logging level of this category to increase verbosity of the MongoDB component +#log4j.category.org.apache.camel.component.mongodb=INFO + +# uncomment the following line to turn on Camel debugging +#log4j.logger.org.apache.camel=DEBUG + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + + +# File appender +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +log4j.appender.file.file=target/camel-influxdb-test.log http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index c742ff7..6882f95 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -150,6 +150,7 @@ <module>camel-ical</module> <module>camel-ignite</module> <module>camel-infinispan</module> + <module>camel-influxdb</module> <module>camel-irc</module> <module>camel-ironmq</module> <module>camel-jackson</module> http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 3984633..edc8d48 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -255,6 +255,7 @@ <ignite-version>1.5.0.final</ignite-version> <ignite-version-range>[1.5.0-b1,1.6)</ignite-version-range> <infinispan-version>8.2.3.Final</infinispan-version> + <influx-java-driver-version>2.2</influx-java-driver-version> <irclib-bundle-version>1.10_5</irclib-bundle-version> <irclib-version>1.10</irclib-version> <ironmq-version>3.0.4</ironmq-version> @@ -1114,6 +1115,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-influxdb</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-ignite</artifactId> <version>${project.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/2976e7dd/platforms/karaf/features/src/main/resources/features.xml ---------------------------------------------------------------------- diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml index 32b0c16..c960122 100644 --- a/platforms/karaf/features/src/main/resources/features.xml +++ b/platforms/karaf/features/src/main/resources/features.xml @@ -808,6 +808,12 @@ <bundle dependency='true'>mvn:commons-pool/commons-pool/${commons-pool-version}</bundle> <bundle>mvn:org.apache.camel/camel-infinispan/${project.version}</bundle> </feature> + <feature name='camel-influxdb' version='${project.version}' resolver='(obr)' start-level='50'> + <details>The camel-influxdb feature requires Java 8</details> + <bundle dependency='true'>mvn:org.influxdb/influxdb-java/${influx-java-driver-version}</bundle> + <feature version='${project.influxdb}'>camel-core</feature> + <bundle>mvn:org.apache.camel/camel-influxdb/${project.version}</bundle> + </feature> <feature name='camel-irc' version='${project.version}' resolver='(obr)' start-level='50'> <feature version='${project.version}'>camel-core</feature> <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.irclib/${irclib-bundle-version}</bundle>