]> git.basschouten.com Git - openhab-addons.git/commitdiff
[influxdb] Add compatibility with InfluxDB Cloud Serverless (#16151)
authorPLeusmann <philipp.leusmann@rwth-aachen.de>
Wed, 17 Jan 2024 20:05:10 +0000 (21:05 +0100)
committerGitHub <noreply@github.com>
Wed, 17 Jan 2024 20:05:10 +0000 (21:05 +0100)
* Use influx client 4.3.0

Signed-off-by: Philipp Leusmann <pl@byteshift.eu>
* cleanup

Signed-off-by: Philipp Leusmann <pl@byteshift.eu>
* changed log level to debug

Signed-off-by: Philipp Leusmann <pl@byteshift.eu>
* spotless reformat

Signed-off-by: Philipp Leusmann <pl@byteshift.eu>
---------

Signed-off-by: Philipp Leusmann <pl@byteshift.eu>
Co-authored-by: Philipp Leusmann <pl@byteshift.eu>
bundles/org.openhab.persistence.influxdb/pom.xml
bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/influx2/InfluxDB2RepositoryImpl.java

index 9c5fa79944a3311c19621dce902f9a939159ca81..114840e8f864f70558aa30606fc83cb52ec103ec 100644 (file)
@@ -20,7 +20,7 @@
     </bnd.importpackage>
     <okhttp3.version>3.14.9</okhttp3.version>
     <retrofit.version>2.7.2</retrofit.version>
-    <influx2.version>1.15.0</influx2.version>
+    <influx2.version>4.3.0</influx2.version>
     <influx1.version>2.21</influx1.version>
   </properties>
 
       <artifactId>influxdb-client-java</artifactId>
       <version>${influx2.version}</version>
     </dependency>
+    <dependency>
+      <groupId>com.influxdb</groupId>
+      <artifactId>influxdb-client-utils</artifactId>
+      <version>${influx2.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>com.squareup.retrofit2</groupId>
+      <artifactId>adapter-rxjava2</artifactId>
+      <version>${retrofit.version}</version>
+    </dependency>
     <dependency>
       <groupId>com.influxdb</groupId>
       <artifactId>influxdb-client-core</artifactId>
index beb18ee43f1cea161968e17a8186cd6929cfa471..898f0303462303c3fb9d1427e358fdbb7cccec93 100644 (file)
@@ -44,7 +44,6 @@ import com.influxdb.client.InfluxDBClientFactory;
 import com.influxdb.client.InfluxDBClientOptions;
 import com.influxdb.client.QueryApi;
 import com.influxdb.client.WriteApi;
-import com.influxdb.client.domain.HealthCheck;
 import com.influxdb.client.domain.Ready;
 import com.influxdb.client.domain.WritePrecision;
 import com.influxdb.client.write.Point;
@@ -78,7 +77,7 @@ public class InfluxDB2RepositoryImpl implements InfluxDBRepository {
     @Override
     public boolean isConnected() {
         InfluxDBClient client = this.client;
-        return client != null && client.health().getStatus() == HealthCheck.StatusEnum.PASS;
+        return client != null && client.ping();
     }
 
     @Override
@@ -97,9 +96,10 @@ public class InfluxDB2RepositoryImpl implements InfluxDBRepository {
         this.client = createdClient;
 
         queryAPI = createdClient.getQueryApi();
-        writeAPI = createdClient.getWriteApi();
+        writeAPI = createdClient.makeWriteApi();
         deleteAPI = createdClient.getDeleteApi();
-        logger.debug("Successfully connected to InfluxDB. Instance ready={}", createdClient.ready());
+
+        logger.debug("Successfully connected to InfluxDB. Instance pingable={}", createdClient.ping());
 
         return checkConnectionStatus();
     }
@@ -117,8 +117,16 @@ public class InfluxDB2RepositoryImpl implements InfluxDBRepository {
     public boolean checkConnectionStatus() {
         final InfluxDBClient currentClient = client;
         if (currentClient != null) {
+            boolean isUp = false;
             Ready ready = currentClient.ready();
-            boolean isUp = ready != null && ready.getStatus() == Ready.StatusEnum.READY;
+            if (ready != null) {
+                isUp = ready.getStatus() == Ready.StatusEnum.READY;
+            } else {
+                logger.debug(
+                        "Failure resolving database readiness. Falling back to ping check. This is normal when using InfluxDB Cloud Serverless.");
+                isUp = currentClient.ping();
+            }
+
             if (isUp) {
                 logger.debug("database status is OK");
             } else {