0

Attempting to dynamically create a bucket, I keep receiving the following error.

Error:

Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 233 path $.labels
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226) ~[gson-2.8.6.jar:na]
        at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39) ~[converter-gson-2.5.0.jar:na]
        at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27) ~[converter-gson-2.5.0.jar:na]
        at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:223) ~[retrofit-2.5.0.jar:na]
        at retrofit2.OkHttpCall.execute(OkHttpCall.java:186) ~[retrofit-2.5.0.jar:na]
        at com.influxdb.internal.AbstractRestClient.execute(AbstractRestClient.java:76) ~[influxdb-client-core-1.8.0.jar:1.8.0]
        at com.influxdb.client.internal.BucketsApiImpl.createBucket(BucketsApiImpl.java:196) ~[influxdb-client-java-1.8.0.jar:1.8.0]

OkHttp Logs prior to error:

: --> POST http://localhost:9999/api/v2/api/v2/buckets
: Content-Type: application/json
: Content-Length: 136
: User-Agent: influxdb-client-java/1.8.0
: 
: {"orgID":"Cool Company","name":"candles","description":"Dynamically created bucket","retentionRules":[{"type":"expire","everySeconds":900}]}
: --> END POST (136-byte body)
: <-- 200 OK http://localhost:9999/api/v2/api/v2/buckets (33ms)
: Content-Type: application/json; charset=utf-8
: Date: Sat, 23 May 2020 16:45:55 GMT
: Content-Length: 907
: 
: {"authorizations":"/api/v2/authorizations","buckets":"/api/v2/buckets","checks":"/api/v2/checks","dashboards":"/api/v2/dashboards","delete":"/api/v2/delete","external":{"statusFeed":"https://www.influxdata.com/feed/json"},"labels":"/api/v2/labels","me":"/api/v2/me","notificationEndpoints":"/api/v2/notificationEndpoints","notificationRules":"/api/v2/notificationRules","orgs":"/api/v2/orgs","query":{"analyze":"/api/v2/query/analyze","ast":"/api/v2/query/ast","self":"/api/v2/query","suggestions":"/api/v2/query/suggestions"},"scrapers":"/api/v2/scrapers","setup":"/api/v2/setup","signin":"/api/v2/signin","signout":"/api/v2/signout","sources":"/api/v2/sources","swagger":"/api/v2/swagger.json","system":{"debug":"/debug/pprof","health":"/health","metrics":"/metrics"},"tasks":"/api/v2/tasks","telegrafs":"/api/v2/telegrafs","users":"/api/v2/users","variables":"/api/v2/variables","write":"/api/v2/write"}

: <-- END HTTP (907-byte body)

Code:

 private fun dynamicallyCreateBucket(
            bucketName: String,
            influxDBClient: InfluxDBClient,
            org: String
    ) {
        val bucket: Bucket = createBucket(
                bucketName = bucketName,
                orgId = org,
                influxDBClient = influxDBClient
        )
    }

    private fun createBucket(
            bucketName: String,
            orgId: String,
            influxDBClient: InfluxDBClient
    ): Bucket =
            PostBucketRequest()
                    .description("Dynamically created bucket")
                    .name(bucketName)
                    .orgID(orgId)
                    .addRetentionRulesItem(BucketRetentionRules().everySeconds(900))
                    .let {
                        influxDBClient.bucketsApi.createBucket(
                                bucketName,
                                BucketRetentionRules().everySeconds(900),
                                orgId
                        )
                    }

Version: implementation("com.influxdb:influxdb-client-java:1.8.0")

Note: I tried implementation("com.influxdb:influxdb-spring:1.8.0") with a slightly different configuration and received the same error . I am able to initialize InfluxDBClient connecting to an existing bucking without any problems.

Naruto Sempai
  • 6,233
  • 8
  • 35
  • 51
  • 1
    The same question was reported in https://github.com/influxdata/influxdb-client-java/issues/115 , it gets answered therein. – sranka May 23 '20 at 21:00

1 Answers1

0

As pointed out by @sranka I had two issues that needed to be corrected:

  1. In my configuration I was adding /api/v2/ to the end of the value for url which was wrong since this value gets added to the request later in the code. This was causing the bucket request to be http://localhost:9999/api/v2/api/v2/buckets instead of http://localhost:9999/api/v2/buckets. Setting url to be http://localhost:9999/ fixed it

  2. I thought the orgId in my configuration was suppose to be the name of the Organization that you create via InfluxDB UI. It's not. The orgId of your organization should look something like fe941a3875dd5b68 and it is in the browser URL when you login into InfluxDB UI.

Naruto Sempai
  • 6,233
  • 8
  • 35
  • 51