Creating a database in InfluxDB v1.8 using the new Java client

Hi,

I am using InfluxDB v1.8.5 and I have recently migrated my Java Client from GitHub - influxdata/influxdb-java: Java client for InfluxDB to GitHub - influxdata/influxdb-client-java: InfluxDB 2 JVM Based Clients.

My use case requires to create the Database from the Java application. I initially thought I had something working by using the createV1 method from the new client then using the bucket API to create databases. But I realised a 404 is returned and my database was actually created by telegraf itself (I believe…).

In the past, I used to create a Query from java that was doing CREATE DATABASE database_name
But doing something similar returns a 403 error.

I have not thoroughly investigated yet, but I just wanted to make sure such thing was possible using the new client.

Thanks in advance.

Hello @0liver,
In 2.x databases are called buckets. Buckets = database + retention policy.
InfluxDBClient influxDBClient = InfluxDBClientFactory.create(“http://localhost:8086”, token);

    //
    // Create bucket "iot_bucket" with data retention set to 3,600 seconds
    //
    BucketRetentionRules retention = new BucketRetentionRules();
    retention.setEverySeconds(3600);

    Bucket bucket = influxDBClient.getBucketsApi().createBucket("iot-bucket", retention, "12bdc4164c2e8141");

Are you using the InfluxDB 2.x client library with InfluxDB 1.x? Or are you using 2.x client library with InfluxDB 2?

Hi @Anaisdg ,

Thank you for your reply. You are correct, I am using the InfluxDB 2.x client library with InfluxDB 1.8 as I thought they would work together (as suggested by: GitHub - influxdata/influxdb-client-java: InfluxDB 2 JVM Based Clients)

But if I understood correctly, the support for version 1.8 is only partial, correct ?

Thanks in advance.

Here are the compatibility docs:
https://docs.influxdata.com/influxdb/v2.0/api/v1-compatibility/#tag/Write
So yes I don’t think you can use the client to create a bucket. :confused:

Hi @Anaisdg,

That’s fair enough.

However, I am a bit confused by the documentation you have sent as I believe this is the V1 endpoints for InfluxDB v2, am I correct ?

In my case, I would like to use the new Java Client used for V2 with V1 (as it seems v1 has some compatibility with V2 API). But I believe your statement is still correct.

I have implemented a workaround for my use case. It is not ideal because I would prefer using the Client itself.

I will try to get in touch with the maintainers of the Java Client to understand a bit more what is allowed / not allowed in my case.

Thanks !

Hello @0liver,
That’s correct. You’re using the v2 client which uses the v2 API which has compatibility with the /query and /write endpoints for 1.x. I believe you’re right and I shared the forward with you whoops. This always confuses me. You’re looking for backward compatibility.
Here are the docs for backward:
https://docs.influxdata.com/influxdb/v1.8/tools/api/
Here are the docs for forward.
https://docs.influxdata.com/influxdb/v2.0/reference/api/influxdb-1x/

@0liver InfluxDB 1.8.5 includes v2 compatible endpoints, but only for writes and queries. You can’t actually create a database in 1.x using a v2 client.

Thank you for replies @Anaisdg and @scott .

If I may ask 1 last question: Is this support never to be included ? Or is it something that is considered and may come in future versions of the v2 client ?

For now, migrating to v2 would be too much of a hassle for us. So, the idea was to plan for a smoother migration by migrating the client first. Then, wait to see if v2 can become an option or wait for IOx to be released.

But from my understanding, there is no certainty that this client GitHub - influxdata/influxdb-client-java: InfluxDB 2 JVM Based Clients will be the one for IOx, am I correct ?

Thanks in advance.

This discussion is also very useful for me, :blush: thanks for sharing!