Skip to content

feat: Apache Karaf support #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ commands:
- restore_cache:
name: Restoring Maven Cache
keys:
- &cache-key maven-cache_v3-<< parameters.maven-image >>-{{ checksum "pom.xml" }}-{{ checksum "client-core/pom.xml" }}-{{ checksum "client/pom.xml" }}-{{ checksum "client-kotlin/pom.xml" }}-{{ checksum "client-legacy/pom.xml" }}-{{ checksum "client-reactive/pom.xml" }}-{{ checksum "client-scala/cross/2.12/pom.xml" }}-{{ checksum "client-scala/cross/2.13/pom.xml" }}-{{ checksum "client-osgi/pom.xml" }}-{{ checksum "client-test/pom.xml" }}-{{ checksum "spring/pom.xml" }}-{{ checksum "flux-dsl/pom.xml" }}
- &cache-key maven-cache_v3-<< parameters.maven-image >>-{{ checksum "pom.xml" }}-{{ checksum "client-core/pom.xml" }}-{{ checksum "client/pom.xml" }}-{{ checksum "client-kotlin/pom.xml" }}-{{ checksum "client-legacy/pom.xml" }}-{{ checksum "client-reactive/pom.xml" }}-{{ checksum "client-scala/cross/2.12/pom.xml" }}-{{ checksum "client-scala/cross/2.13/pom.xml" }}-{{ checksum "client-osgi/pom.xml" }}-{{ checksum "client-test/pom.xml" }}-{{ checksum "spring/pom.xml" }}-{{ checksum "flux-dsl/pom.xml" }}-{{ checksum "karaf/pom.xml" }}-{{ checksum "karaf/karaf-assembly/pom.xml" }}-{{ checksum "karaf/karaf-features/pom.xml" }}-{{ checksum "karaf/karaf-kar/pom.xml" }}
- maven-cache_v3-<< parameters.maven-image >>-
- run:
name: "Running tests"
Expand Down Expand Up @@ -162,7 +162,7 @@ jobs:
- restore_cache:
name: Restoring Maven Cache
keys:
- &cache-key-deploy maven-cache-deploy_v2-{{ checksum "pom.xml" }}-{{ checksum "client-core/pom.xml" }}-{{ checksum "client/pom.xml" }}-{{ checksum "client-kotlin/pom.xml" }}-{{ checksum "client-legacy/pom.xml" }}-{{ checksum "client-reactive/pom.xml" }}-{{ checksum "client-scala/cross/2.12/pom.xml" }}-{{ checksum "client-scala/cross/2.13/pom.xml" }}-{{ checksum "client-osgi/pom.xml" }}-{{ checksum "client-test/pom.xml" }}-{{ checksum "spring/pom.xml" }}-{{ checksum "flux-dsl/pom.xml" }}
- &cache-key-deploy maven-cache-deploy_v2-{{ checksum "pom.xml" }}-{{ checksum "client-core/pom.xml" }}-{{ checksum "client/pom.xml" }}-{{ checksum "client-kotlin/pom.xml" }}-{{ checksum "client-legacy/pom.xml" }}-{{ checksum "client-reactive/pom.xml" }}-{{ checksum "client-scala/cross/2.12/pom.xml" }}-{{ checksum "client-scala/cross/2.13/pom.xml" }}-{{ checksum "client-osgi/pom.xml" }}-{{ checksum "client-test/pom.xml" }}-{{ checksum "spring/pom.xml" }}-{{ checksum "flux-dsl/pom.xml" }}-{{ checksum "karaf/pom.xml" }}-{{ checksum "karaf/karaf-assembly/pom.xml" }}-{{ checksum "karaf/karaf-features/pom.xml" }}-{{ checksum "karaf/karaf-kar/pom.xml" }}
- maven-cache-deploy_v2-
- run:
name: Deploying Snapshot
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ You have to replace your dependency from: `influxdb-client-scala` to:
1. [#216](https://github.com/influxdata/influxdb-client-java/pull/216): Allow to specify a name of `column` in `last` function [FluxDSL]
1. [#218](https://github.com/influxdata/influxdb-client-java/pull/218): Supports enum types in mapping into POJO
1. [#220](https://github.com/influxdata/influxdb-client-java/pull/220): Create client supporting OSGi environments
1. [#221](https://github.com/influxdata/influxdb-client-java/pull/221): Add feature definition and documentation for Apache Karaf support

## 2.1.0 [2021-04-01]

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The Java, Reactive, OSGi, Kotlin and Scala clients are implemented for the Influ
| **[kotlin](./client-kotlin)** | The reference Kotlin client that allows query and write for the InfluxDB 2.0 by [Kotlin Channel coroutines](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html). | [KDoc](https://influxdata.github.io/influxdb-client-java/influxdb-client-kotlin/dokka/influxdb-client-kotlin/com.influxdb.client.kotlin/index.html), [readme](./client-kotlin#influxdb-client-kotlin/) | 2.0|
| **[scala](./client-scala)** | The reference Scala client that allows query and write for the InfluxDB 2.0 by [Akka Streams](https://doc.akka.io/docs/akka/2.6/stream/). | [Scaladoc](https://influxdata.github.io/influxdb-client-java/client-scala/cross/influxdb-client-scala_2.13/scaladocs/com/influxdb/client/scala/index.html), [readme](./client-scala#influxdb-client-scala/) | 2.0 |
| **[osgi](./client-osgi)** | The reference OSGi (R6) client embedding Java and reactive clients and providing standard features (declarative services, configuration, event processing) for the InfluxDB 2.0. | [javadoc](https://influxdata.github.io/influxdb-client-java/influxdb-client-osgi/apidocs/index.html), [readme](./client-osgi) | 2.0 |
| **[karaf](./karaf)** | The Apache Karaf feature definition for the InfluxDB 2.0. | [readme](./karaf) | 2.0 |

There is also possibility to use the Flux language over the InfluxDB 1.7+ provided by:

Expand Down
148 changes: 148 additions & 0 deletions karaf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Apache Karaf Integration for InfluxDB 2.0

## Features

- [Submodules](#submodules)
- [Installation](#installation)
- [Configuration](#configuration)
- [Examples](#examples)

## Submodules

The Apache Karaf feature definition modules supporting InfluxDB 2.0:

| Module | Description |
| --- | --- |
| **karaf-features** | Apache Karaf feature definition (XML) artifact for InfluxDB 2.0. |
| **karaf-kar** | KAraf aRchive (KAR) artifact containing client for InfluxDB 2.0. |
| **karaf-assembly** | Apache Karaf (sample) distribution having InfluxDB 2.0 client. |

## Installation

Apache Karaf Integration can be enabled by installing Karaf feature or KAR file.

### Preparing

Download [Apache Karaf](http://karaf.apache.org/download.html) 4.2+, extract to directory referenced by `KARAF_HOME` below and start container:

```
$KARAF_HOME/bin/karaf
```

### Karaf feature installation

Add feature repository (`mvn:com.influxdb/influxdb-karaf-features/VERSION/xml/features`) and install feature named `influxdb-client` (replace `VERSION` with current version).

```
karaf@root()> feature:repo-add mvn:com.influxdb/influxdb-karaf-features/VERSION/xml/features
karaf@root()> feature:install influxdb-client
```

Feature repository can be referenced by custom Karaf distributions too.

### KAR deployment

Install KAR Maven artifact `mvn:com.influxdb/influxdb-karaf-kar/VERSION/kar` (replace `VERSION` with current version):

```
karaf@root()> kar:install mvn:com.influxdb/influxdb-karaf-kar/VERSION/kar
```

### Sample Apache Karaf distribution

A sample Apache Karaf distribution is created automatically by compiling karaf-assembly Maven module. ZIP and TGZ packages can be found in `karaf-assembly/target/` directory. OSGi component developers using InfluxDB do not need to download Apache Karaf and complete installation process (above) but unpack archive only and start the server.

An alternate way to start the server is running `karaf-assembly/target/assembly/bin/karaf`. Installed features and bundles can be checked by the following commands:

```
karaf@root()> feature:list | grep influx
influxdb-client │ 2.2.0.SNAPSHOT │ │ Started │ influxdb-features-2.2.0-SNAPSHOT │ InfluxDB client
kotlin │ 1.3.72 │ │ Started │ influxdb-features-2.2.0-SNAPSHOT │ Kotlin
influxdb-karaf-features │ 2.2.0.SNAPSHOT │ │ Uninstalled │ influxdb-features-2.2.0-SNAPSHOT │ Apache Karaf Features for InfluxDB 2.0
karaf@root()> bundle:list | grep -i influx
16 │ Active │ 80 │ 2.2.0.SNAPSHOT │ The OSGi InfluxDB 2.0 Client
```

Declarative services (i.e. that are writing data to InfluxDB by OSGi events) become available if you copy configuration files (see below) to `karaf-assembly/target/assembly/deploy` directory.

```
karaf@root()> scr:list
com.influxdb.client.osgi.LineProtocolWriter in bundle 16 (com.influxdb.client-osgi:2.2.0.SNAPSHOT) enabled, 1 instance.
Id: 3, State:ACTIVE, PID(s): [com.influxdb.client.osgi.LineProtocolWriter.7617b1fb-5b49-402b-b794-1bab69bf6136]
com.influxdb.client.osgi.InfluxDBConnector in bundle 16 (com.influxdb.client-osgi:2.2.0.SNAPSHOT) enabled, 1 instance.
Id: 1, State:ACTIVE, PID(s): [com.influxdb.client.osgi.InfluxDBConnector.1e27ec4c-4dcb-4545-a2ec-40405877a409]
com.influxdb.client.osgi.PointWriter in bundle 16 (com.influxdb.client-osgi:2.2.0.SNAPSHOT) enabled, 1 instance.
```

## Configuration

Configuration options are described by [client-osgi](../client-osgi/README.md). Create configurations by hand (`*.cfg` files, copy them to `KARAF_HOME/deploy` directory) or via web console (need to install `webconsole` Karaf feature).

## Examples

### Preparing

Install Apache Karaf Integration as described above. Create the following configuration files (replace connection properties):

- `KARAF_HOME/deploy/com.influxdb.client.osgi.InfluxDBConnector-test.cfg`
```
alias=test
url=http://localhost:8086
token=TOKEN
organization=example
bucket=test
```

- `KARAF_HOME/deploy/com.influxdb.client.osgi.LineProtocolWriter-tester.cfg`
```
client.target=(alias=test)
timestamp.append=true
```

- `KARAF_HOME/deploy/com.influxdb.client.osgi.PointWriter-tester.cfg`
```
event.topics=influxdb/point/*
client.target=(alias=test)
host.name.add=true
host.address.add=true
timestamp.add=true
timestamp.precision=ns
```

### Write RAW (line protocol) record

Publish OSGi event containing line protocol record (i.e. via Karaf console).

```
karaf@root()> event:send influxdb/lineprotocol "record=weather,location=HU temperature=5.89,humidity=48"
```

### Write structured data

Publish OSGi event containing structured data (i.e. by custom component). Both InfluxDB Point and Java Map types are supported (see [client-osgi](../client-osgi/README.md) and [javadoc](https://influxdata.github.io/influxdb-client-java/influxdb-client-osgi/apidocs/index.html) for details).

```java
@Component
public class Tester {

@Reference
EventAdmin eventAdmin;

public void tester() {
final Map<String, String> tags = new TreeMap<>();
tags.put("location", "HU");

final Map<String, Object> fields = new TreeMap<>();
fields.put("temperature", 5.89);
fields.put("humidity", 48);
fields.put("raining", false);
fields.put("sky", "CLOUDY");

final Map<String, Object> point = new TreeMap<>();
point.put("tags", tags);
point.put("fields", fields);

eventAdmin.postEvent(new Event("influxdb/point/weather", Collections.singletonMap("point", point)));
}
}
```
132 changes: 132 additions & 0 deletions karaf/karaf-assembly/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

-->
<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>
<artifactId>influxdb-karaf</artifactId>
<groupId>com.influxdb</groupId>
<version>2.2.0-SNAPSHOT</version>
</parent>

<artifactId>influxdb-karaf-assembly</artifactId>
<packaging>karaf-assembly</packaging>

<name>Apache Karaf Assembly for InfluxDB 2.0</name>
<description>
Apache Karaf distribution including InfluxDB 2.0 client.
</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<extensions>true</extensions>

<executions>
<execution>
<id>default-assembly</id>
<configuration>
<javase>1.8</javase>
<framework>framework</framework>
<bootFeatures>
<feature>instance</feature>
<feature>package</feature>
<feature>log</feature>
<feature>ssh</feature>
<feature>system</feature>
<feature>eventadmin</feature>
<feature>feature</feature>
<feature>shell</feature>
<feature>management</feature>
<feature>service</feature>
<feature>jaas</feature>
<feature>deployer</feature>
<feature>diagnostic</feature>
<feature>wrap</feature>
<feature>bundle</feature>
<feature>config</feature>
<feature>kar</feature>
</bootFeatures>
<startupFeatures>
<feature>influxdb-client</feature>
</startupFeatures>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>generate-docker</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<extensions>true</extensions>

<executions>
<execution>
<id>dockerfile</id>
<goals>
<goal>dockerfile</goal>
</goals>
</execution>

<execution>
<id>docker</id>
<goals>
<goal>docker</goal>
</goals>
<configuration>
<imageName>${project.artifactId}</imageName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>influxdb-karaf-features</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
<classifier>features</classifier>
<type>xml</type>
</dependency>
</dependencies>
</project>
79 changes: 79 additions & 0 deletions karaf/karaf-features/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

-->
<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>
<artifactId>influxdb-karaf</artifactId>
<groupId>com.influxdb</groupId>
<version>2.2.0-SNAPSHOT</version>
</parent>

<artifactId>influxdb-karaf-features</artifactId>
<packaging>feature</packaging>

<name>Apache Karaf Features for InfluxDB 2.0</name>
<description>
Apache Karaf Features for InfluxDB 2.0: feature definition of client bundles and dependencies.
</description>

<build>
<resources>
<resource>
<directory>src/main/feature</directory>
<filtering>true</filtering>
<targetPath>target/feature</targetPath>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<executions>
<execution>
<id>default-verify</id>
<configuration>
<javase>1.8</javase>
<distribution>org.apache.karaf.features:framework</distribution>
<descriptors>
<descriptor>mvn:org.apache.karaf.features/framework/${karaf.version}/xml/features</descriptor>
<descriptor>mvn:org.apache.karaf.features/standard/${karaf.version}/xml/features</descriptor>
<descriptor>file:${project.build.directory}/feature/feature.xml</descriptor>
</descriptors>
<framework>
<feature>framework</feature>
<feature>scr</feature>
</framework>
<features>
<feature>influxdb-client</feature>
</features>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading