0

尝试动态创建存储桶时,我不断收到以下错误。

错误:

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 错误前的日志:

: --> 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)

代码:

 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
                        )
                    }

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

注意:我尝试implementation("com.influxdb:influxdb-spring:1.8.0")使用稍微不同的配置并收到相同的错误。我能够InfluxDBClient毫无问题地初始化连接到现有的bucking。

4

1 回答 1

0

正如@sranka所指出的,我有两个问题需要纠正:

  1. 在我的配置中,我将添加/api/v2/到错误值的末尾,url因为该值稍后会在代码中添加到请求中。这导致存储桶请求http://localhost:9999/api/v2/api/v2/buckets而不是http://localhost:9999/api/v2/buckets. 设置url修复http://localhost:9999/

  2. 我认为orgId我的配置中的 应该是您通过 InfluxDB UI 创建的组织的名称。它不是。当您登录到 InfluxDB UI 时orgId,您的组织应该看起来像fe941a3875dd5b68并且它在浏览器 URL 中。

于 2020-05-24T16:15:39.410 回答