Skip to content

Commit 13ab60b

Browse files
authored
feat: add Apache Karaf support (#221)
1 parent 445d53d commit 13ab60b

File tree

10 files changed

+577
-3
lines changed

10 files changed

+577
-3
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ commands:
4242
- restore_cache:
4343
name: Restoring Maven Cache
4444
keys:
45-
- &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" }}
45+
- &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" }}
4646
- maven-cache_v3-<< parameters.maven-image >>-
4747
- run:
4848
name: "Running tests"
@@ -162,7 +162,7 @@ jobs:
162162
- restore_cache:
163163
name: Restoring Maven Cache
164164
keys:
165-
- &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" }}
165+
- &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" }}
166166
- maven-cache-deploy_v2-
167167
- run:
168168
name: Deploying Snapshot

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ You have to replace your dependency from: `influxdb-client-scala` to:
1313
1. [#216](https://github.com/influxdata/influxdb-client-java/pull/216): Allow to specify a name of `column` in `last` function [FluxDSL]
1414
1. [#218](https://github.com/influxdata/influxdb-client-java/pull/218): Supports enum types in mapping into POJO
1515
1. [#220](https://github.com/influxdata/influxdb-client-java/pull/220): Create client supporting OSGi environments
16+
1. [#221](https://github.com/influxdata/influxdb-client-java/pull/221): Add feature definition and documentation for Apache Karaf support
1617

1718
## 2.1.0 [2021-04-01]
1819

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ The Java, Reactive, OSGi, Kotlin and Scala clients are implemented for the Influ
5151
| **[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|
5252
| **[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 |
5353
| **[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 |
54+
| **[karaf](./karaf)** | The Apache Karaf feature definition for the InfluxDB 2.0. | [readme](./karaf) | 2.0 |
5455

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

karaf/README.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Apache Karaf Integration for InfluxDB 2.0
2+
3+
## Features
4+
5+
- [Submodules](#submodules)
6+
- [Installation](#installation)
7+
- [Configuration](#configuration)
8+
- [Examples](#examples)
9+
10+
## Submodules
11+
12+
The Apache Karaf feature definition modules supporting InfluxDB 2.0:
13+
14+
| Module | Description |
15+
| --- | --- |
16+
| **karaf-features** | Apache Karaf feature definition (XML) artifact for InfluxDB 2.0. |
17+
| **karaf-kar** | KAraf aRchive (KAR) artifact containing client for InfluxDB 2.0. |
18+
| **karaf-assembly** | Apache Karaf (sample) distribution having InfluxDB 2.0 client. |
19+
20+
## Installation
21+
22+
Apache Karaf Integration can be enabled by installing Karaf feature or KAR file.
23+
24+
### Preparing
25+
26+
Download [Apache Karaf](http://karaf.apache.org/download.html) 4.2+, extract to directory referenced by `KARAF_HOME` below and start container:
27+
28+
```
29+
$KARAF_HOME/bin/karaf
30+
```
31+
32+
### Karaf feature installation
33+
34+
Add feature repository (`mvn:com.influxdb/influxdb-karaf-features/VERSION/xml/features`) and install feature named `influxdb-client` (replace `VERSION` with current version).
35+
36+
```
37+
karaf@root()> feature:repo-add mvn:com.influxdb/influxdb-karaf-features/VERSION/xml/features
38+
karaf@root()> feature:install influxdb-client
39+
```
40+
41+
Feature repository can be referenced by custom Karaf distributions too.
42+
43+
### KAR deployment
44+
45+
Install KAR Maven artifact `mvn:com.influxdb/influxdb-karaf-kar/VERSION/kar` (replace `VERSION` with current version):
46+
47+
```
48+
karaf@root()> kar:install mvn:com.influxdb/influxdb-karaf-kar/VERSION/kar
49+
```
50+
51+
### Sample Apache Karaf distribution
52+
53+
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.
54+
55+
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:
56+
57+
```
58+
karaf@root()> feature:list | grep influx
59+
influxdb-client │ 2.2.0.SNAPSHOT │ │ Started │ influxdb-features-2.2.0-SNAPSHOT │ InfluxDB client
60+
kotlin │ 1.3.72 │ │ Started │ influxdb-features-2.2.0-SNAPSHOT │ Kotlin
61+
influxdb-karaf-features │ 2.2.0.SNAPSHOT │ │ Uninstalled │ influxdb-features-2.2.0-SNAPSHOT │ Apache Karaf Features for InfluxDB 2.0
62+
karaf@root()> bundle:list | grep -i influx
63+
16 │ Active │ 80 │ 2.2.0.SNAPSHOT │ The OSGi InfluxDB 2.0 Client
64+
```
65+
66+
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.
67+
68+
```
69+
karaf@root()> scr:list
70+
com.influxdb.client.osgi.LineProtocolWriter in bundle 16 (com.influxdb.client-osgi:2.2.0.SNAPSHOT) enabled, 1 instance.
71+
Id: 3, State:ACTIVE, PID(s): [com.influxdb.client.osgi.LineProtocolWriter.7617b1fb-5b49-402b-b794-1bab69bf6136]
72+
com.influxdb.client.osgi.InfluxDBConnector in bundle 16 (com.influxdb.client-osgi:2.2.0.SNAPSHOT) enabled, 1 instance.
73+
Id: 1, State:ACTIVE, PID(s): [com.influxdb.client.osgi.InfluxDBConnector.1e27ec4c-4dcb-4545-a2ec-40405877a409]
74+
com.influxdb.client.osgi.PointWriter in bundle 16 (com.influxdb.client-osgi:2.2.0.SNAPSHOT) enabled, 1 instance.
75+
```
76+
77+
## Configuration
78+
79+
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).
80+
81+
## Examples
82+
83+
### Preparing
84+
85+
Install Apache Karaf Integration as described above. Create the following configuration files (replace connection properties):
86+
87+
- `KARAF_HOME/deploy/com.influxdb.client.osgi.InfluxDBConnector-test.cfg`
88+
```
89+
alias=test
90+
url=http://localhost:8086
91+
token=TOKEN
92+
organization=example
93+
bucket=test
94+
```
95+
96+
- `KARAF_HOME/deploy/com.influxdb.client.osgi.LineProtocolWriter-tester.cfg`
97+
```
98+
client.target=(alias=test)
99+
timestamp.append=true
100+
```
101+
102+
- `KARAF_HOME/deploy/com.influxdb.client.osgi.PointWriter-tester.cfg`
103+
```
104+
event.topics=influxdb/point/*
105+
client.target=(alias=test)
106+
host.name.add=true
107+
host.address.add=true
108+
timestamp.add=true
109+
timestamp.precision=ns
110+
```
111+
112+
### Write RAW (line protocol) record
113+
114+
Publish OSGi event containing line protocol record (i.e. via Karaf console).
115+
116+
```
117+
karaf@root()> event:send influxdb/lineprotocol "record=weather,location=HU temperature=5.89,humidity=48"
118+
```
119+
120+
### Write structured data
121+
122+
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).
123+
124+
```java
125+
@Component
126+
public class Tester {
127+
128+
@Reference
129+
EventAdmin eventAdmin;
130+
131+
public void tester() {
132+
final Map<String, String> tags = new TreeMap<>();
133+
tags.put("location", "HU");
134+
135+
final Map<String, Object> fields = new TreeMap<>();
136+
fields.put("temperature", 5.89);
137+
fields.put("humidity", 48);
138+
fields.put("raining", false);
139+
fields.put("sky", "CLOUDY");
140+
141+
final Map<String, Object> point = new TreeMap<>();
142+
point.put("tags", tags);
143+
point.put("fields", fields);
144+
145+
eventAdmin.postEvent(new Event("influxdb/point/weather", Collections.singletonMap("point", point)));
146+
}
147+
}
148+
```

karaf/karaf-assembly/pom.xml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
The MIT License
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
24+
-->
25+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
27+
<modelVersion>4.0.0</modelVersion>
28+
29+
<parent>
30+
<artifactId>influxdb-karaf</artifactId>
31+
<groupId>com.influxdb</groupId>
32+
<version>2.2.0-SNAPSHOT</version>
33+
</parent>
34+
35+
<artifactId>influxdb-karaf-assembly</artifactId>
36+
<packaging>karaf-assembly</packaging>
37+
38+
<name>Apache Karaf Assembly for InfluxDB 2.0</name>
39+
<description>
40+
Apache Karaf distribution including InfluxDB 2.0 client.
41+
</description>
42+
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.apache.karaf.tooling</groupId>
47+
<artifactId>karaf-maven-plugin</artifactId>
48+
<extensions>true</extensions>
49+
50+
<executions>
51+
<execution>
52+
<id>default-assembly</id>
53+
<configuration>
54+
<javase>1.8</javase>
55+
<framework>framework</framework>
56+
<bootFeatures>
57+
<feature>instance</feature>
58+
<feature>package</feature>
59+
<feature>log</feature>
60+
<feature>ssh</feature>
61+
<feature>system</feature>
62+
<feature>eventadmin</feature>
63+
<feature>feature</feature>
64+
<feature>shell</feature>
65+
<feature>management</feature>
66+
<feature>service</feature>
67+
<feature>jaas</feature>
68+
<feature>deployer</feature>
69+
<feature>diagnostic</feature>
70+
<feature>wrap</feature>
71+
<feature>bundle</feature>
72+
<feature>config</feature>
73+
<feature>kar</feature>
74+
</bootFeatures>
75+
<startupFeatures>
76+
<feature>influxdb-client</feature>
77+
</startupFeatures>
78+
</configuration>
79+
</execution>
80+
</executions>
81+
</plugin>
82+
</plugins>
83+
</build>
84+
85+
<profiles>
86+
<profile>
87+
<id>generate-docker</id>
88+
<activation>
89+
<activeByDefault>false</activeByDefault>
90+
</activation>
91+
<build>
92+
<plugins>
93+
<plugin>
94+
<groupId>org.apache.karaf.tooling</groupId>
95+
<artifactId>karaf-maven-plugin</artifactId>
96+
<extensions>true</extensions>
97+
98+
<executions>
99+
<execution>
100+
<id>dockerfile</id>
101+
<goals>
102+
<goal>dockerfile</goal>
103+
</goals>
104+
</execution>
105+
106+
<execution>
107+
<id>docker</id>
108+
<goals>
109+
<goal>docker</goal>
110+
</goals>
111+
<configuration>
112+
<imageName>${project.artifactId}</imageName>
113+
</configuration>
114+
</execution>
115+
</executions>
116+
</plugin>
117+
</plugins>
118+
</build>
119+
</profile>
120+
</profiles>
121+
122+
<dependencies>
123+
<dependency>
124+
<groupId>${project.groupId}</groupId>
125+
<artifactId>influxdb-karaf-features</artifactId>
126+
<version>${project.version}</version>
127+
<scope>runtime</scope>
128+
<classifier>features</classifier>
129+
<type>xml</type>
130+
</dependency>
131+
</dependencies>
132+
</project>

karaf/karaf-features/pom.xml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
The MIT License
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
24+
-->
25+
<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">
26+
<modelVersion>4.0.0</modelVersion>
27+
28+
<parent>
29+
<artifactId>influxdb-karaf</artifactId>
30+
<groupId>com.influxdb</groupId>
31+
<version>2.2.0-SNAPSHOT</version>
32+
</parent>
33+
34+
<artifactId>influxdb-karaf-features</artifactId>
35+
<packaging>feature</packaging>
36+
37+
<name>Apache Karaf Features for InfluxDB 2.0</name>
38+
<description>
39+
Apache Karaf Features for InfluxDB 2.0: feature definition of client bundles and dependencies.
40+
</description>
41+
42+
<build>
43+
<resources>
44+
<resource>
45+
<directory>src/main/feature</directory>
46+
<filtering>true</filtering>
47+
<targetPath>target/feature</targetPath>
48+
</resource>
49+
</resources>
50+
51+
<plugins>
52+
<plugin>
53+
<groupId>org.apache.karaf.tooling</groupId>
54+
<artifactId>karaf-maven-plugin</artifactId>
55+
<executions>
56+
<execution>
57+
<id>default-verify</id>
58+
<configuration>
59+
<javase>1.8</javase>
60+
<distribution>org.apache.karaf.features:framework</distribution>
61+
<descriptors>
62+
<descriptor>mvn:org.apache.karaf.features/framework/${karaf.version}/xml/features</descriptor>
63+
<descriptor>mvn:org.apache.karaf.features/standard/${karaf.version}/xml/features</descriptor>
64+
<descriptor>file:${project.build.directory}/feature/feature.xml</descriptor>
65+
</descriptors>
66+
<framework>
67+
<feature>framework</feature>
68+
<feature>scr</feature>
69+
</framework>
70+
<features>
71+
<feature>influxdb-client</feature>
72+
</features>
73+
</configuration>
74+
</execution>
75+
</executions>
76+
</plugin>
77+
</plugins>
78+
</build>
79+
</project>

0 commit comments

Comments
 (0)