Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use swagger to generate static things #16

Merged
merged 46 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
78eef1e
#15: Buckets, Labels, Owners, Members API use generated sources
bednar Mar 11, 2019
84832b0
#15: ScraperTarget API use generated sources
bednar Mar 12, 2019
94c682c
#15: ScraperTarget API use generated sources
bednar Mar 12, 2019
dca215c
#15: Organization API use generated sources
bednar Mar 12, 2019
75c44ba
#15: Organization API use generated sources
bednar Mar 12, 2019
d2f02c4
#15: Lables API use generated sources
bednar Mar 12, 2019
7c993ae
#15: Lables API use generated sources
bednar Mar 12, 2019
87143f6
#15: Source, Onboarding, Check API use generated sources
bednar Mar 12, 2019
98bcf38
#15: Source, Onboarding, Check API use generated sources
bednar Mar 12, 2019
e41ab85
#15: Authorization API use generated sources
bednar Mar 12, 2019
06c0e7d
#15: Authorization API use generated sources
bednar Mar 12, 2019
5505619
#15: Secret API use generated sources
bednar Mar 13, 2019
7579156
#15: Secret API use generated sources
bednar Mar 13, 2019
d35ff1d
#15: Task API use generated sources
bednar Mar 13, 2019
3c3330c
#15: Task API use generated sources
bednar Mar 13, 2019
1099d0a
#15: Telegraf API use generated sources
bednar Mar 18, 2019
a746736
#15: Telegraf API use generated sources
bednar Mar 18, 2019
96b425f
#15: Telegraf API use generated sources
bednar Mar 18, 2019
35b0d99
#15: Telegraf API use generated sources
bednar Mar 18, 2019
1d89ebb
#15: Telegraf API use generated sources
bednar Mar 18, 2019
ed1d0b1
#15: Added open-api generator
bednar Mar 18, 2019
70c07da
#15: Use generated PATH
bednar Mar 19, 2019
90c3b61
#15: Telegraf API use generated sources
bednar Mar 19, 2019
0f07a3c
#15: Use generated PATH
bednar Mar 19, 2019
2da08ae
#15: Use generated PATH
bednar Mar 19, 2019
87a11a3
#15: Upgraded swagger
bednar Mar 20, 2019
75ded31
#15: Added Users service
bednar Mar 20, 2019
a5a7d60
#15: Added Users service
bednar Mar 20, 2019
33ddac1
#15: Added Setup service
bednar Mar 20, 2019
0370f57
#15: Added Setup service
bednar Mar 20, 2019
ce7c31d
#15: Added Query and Write service
bednar Mar 20, 2019
a027ad3
#15: Added Query and Write service
bednar Mar 20, 2019
2ba7933
#15: Added Query and Write service
bednar Mar 20, 2019
0867dd0
#15: Added Ready service
bednar Mar 20, 2019
49c9d27
#15: Fixed Ready property name
bednar Mar 21, 2019
13c80db
#15: Fixed Ready property name
bednar Mar 21, 2019
c0bf9d7
#15: Added Ready and Health Service
bednar Mar 21, 2019
aeba90a
#15: Added Ready and Health Service
bednar Mar 21, 2019
a96766c
#15: Label OrgId is required
bednar Mar 21, 2019
b0a9b98
#15: Use Write Service
bednar Mar 21, 2019
e4b6e09
#15: Use Write Service
bednar Mar 21, 2019
cc88a6e
#15: Fixed code style
bednar Mar 21, 2019
8c429c6
#15: Fixed tests
bednar Mar 21, 2019
13f8d26
Merge branch 'master' into swagger
bednar Mar 21, 2019
b8cf5a0
#15: Hide generated timestamp
bednar Mar 21, 2019
d5a869b
#15: Hide generated timestamp
bednar Mar 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ tree.txt
.java-version

**nightly**
**/influxd.bolt
**/influxd.bolt

**/.openapi-generator*
**/swagger2.yml
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ import org.influxdata.client.domain.Authorization;
import org.influxdata.client.domain.Bucket;
import org.influxdata.client.domain.Permission;
import org.influxdata.client.domain.PermissionResource;
import org.influxdata.client.domain.ResourceType;
import org.influxdata.client.domain.RetentionRule;
import org.influxdata.client.domain.BucketRetentionRules;

public class InfluxDB2ManagementExample {

Expand All @@ -277,17 +276,17 @@ public class InfluxDB2ManagementExample {
PermissionResource resource = new PermissionResource();
resource.setId(bucket.getId());
resource.setOrgID("org_id");
resource.setType(ResourceType.BUCKETS);
resource.setType(PermissionResource.TypeEnum.BUCKETS);

// Read permission
Permission read = new Permission();
read.setResource(resource);
read.setAction(Permission.READ_ACTION);
read.setAction(Permission.ActionEnum.READ);

// Write permission
Permission write = new Permission();
write.setResource(resource);
write.setAction(Permission.WRITE_ACTION);
write.setAction(Permission.ActionEnum.WRITE);

Authorization authorization = influxDBClient.getAuthorizationsApi()
.createAuthorization("org_id", Arrays.asList(read, write));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ protected <T> T execute(@Nonnull final Call<T> call) throws InfluxException {
return execute(call, (String) null);
}

//
// TODO null catch can be only used for "search" not for getByID
//
protected <T> T execute(@Nonnull final Call<T> call, @Nullable final String nullError) throws InfluxException {
return execute(call, nullError, null, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
package org.influxdata.client.kotlin

import org.influxdata.LogLevel
import org.influxdata.client.domain.Health
import org.influxdata.client.domain.Check

/**
* The reference Kotlin client that allows query and write for the InfluxDB 2.0 by Kotlin Channel coroutines.
Expand All @@ -43,7 +43,7 @@ interface InfluxDBClientKotlin {
*
* @return health of an instance
*/
fun health(): Health
fun health(): Check

/**
* Gets the [LogLevel] that is used for logging requests and responses.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
package org.influxdata.client.kotlin

import kotlinx.coroutines.channels.Channel
import org.influxdata.client.domain.Dialect
import org.influxdata.client.domain.Query
import org.influxdata.query.FluxRecord

/**
Expand All @@ -41,6 +43,15 @@ interface QueryKotlinApi {
*/
fun query(query: String, orgID: String): Channel<FluxRecord>

/**
* Executes the Flux query against the InfluxDB and asynchronously stream [FluxRecord]s to [Channel].
*
* @param query the flux query to execute
* @param orgID specifies the source organization
* @return the stream of [FluxRecord]s
*/
fun query(query: Query, orgID: String): Channel<FluxRecord>

/**
* Executes the Flux query against the InfluxDB and asynchronously stream measurements to [Channel].
*
Expand All @@ -51,6 +62,16 @@ interface QueryKotlinApi {
*/
fun <M> query(query: String, orgID: String, measurementType: Class<M>): Channel<M>

/**
* Executes the Flux query against the InfluxDB and asynchronously stream measurements to [Channel].
*
* @param query the flux query to execute
* @param orgID specifies the source organization
* @param <M> the type of the measurement (POJO)
* @return the stream of measurements
*/
fun <M> query(query: Query, orgID: String, measurementType: Class<M>): Channel<M>

/**
* Executes the Flux query against the InfluxDB and asynchronously stream response to [Channel].
*
Expand All @@ -69,6 +90,15 @@ interface QueryKotlinApi {
* [See dialect SPEC](http://bit.ly/flux-dialect).
* @return the response stream
*/
fun queryRaw(query: String, dialect: String, orgID: String): Channel<String>
fun queryRaw(query: String, dialect: Dialect, orgID: String): Channel<String>


/**
* Executes the Flux query against the InfluxDB and asynchronously stream response to [Channel].
*
* @param query the flux query to execute
* @param orgID specifies the source organization
* @return the response stream
*/
fun queryRaw(query: Query, orgID: String): Channel<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ package org.influxdata.client.kotlin.internal

import org.influxdata.LogLevel
import org.influxdata.client.InfluxDBClientOptions
import org.influxdata.client.domain.Health
import org.influxdata.client.domain.Check
import org.influxdata.client.internal.AbstractInfluxDBClient
import org.influxdata.client.internal.InfluxDBService
import org.influxdata.client.kotlin.InfluxDBClientKotlin
import org.influxdata.client.kotlin.QueryKotlinApi
import org.influxdata.client.service.QueryService

/**
* @author Jakub Bednar (bednar@github) (07/02/2019 13:21)
*/
internal class InfluxDBClientKotlinImpl(options: InfluxDBClientOptions) : AbstractInfluxDBClient<InfluxDBService>(options, InfluxDBService::class.java), InfluxDBClientKotlin {
internal class InfluxDBClientKotlinImpl(options: InfluxDBClientOptions) : AbstractInfluxDBClient(options), InfluxDBClientKotlin {

override fun getQueryKotlinApi(): QueryKotlinApi {
return QueryKotlinApiImpl(influxDBService)
return QueryKotlinApiImpl(retrofit.create<QueryService>(QueryService::class.java))
}

override fun health(): Health {
return health(influxDBService.health())
override fun health(): Check {
return health(healthService.healthGet(null))
}

override fun getLogLevel(): LogLevel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.runBlocking
import org.influxdata.Arguments
import org.influxdata.Cancellable
import org.influxdata.client.internal.InfluxDBService
import org.influxdata.client.domain.Dialect
import org.influxdata.client.domain.Query
import org.influxdata.client.internal.AbstractInfluxDBClient
import org.influxdata.client.kotlin.QueryKotlinApi
import org.influxdata.client.service.QueryService
import org.influxdata.internal.AbstractQueryApi
import org.influxdata.query.FluxRecord
import org.influxdata.query.FluxTable
Expand All @@ -37,20 +40,28 @@ import java.util.function.Consumer
/**
* @author Jakub Bednar (bednar@github) (30/10/2018 08:51)
*/
internal class QueryKotlinApiImpl(private val influxDBService: InfluxDBService) : AbstractQueryApi(), QueryKotlinApi {
internal class QueryKotlinApiImpl(private val service: QueryService) : AbstractQueryApi(), QueryKotlinApi {

override fun query(query: String, orgID: String): Channel<FluxRecord> {

Arguments.checkNonEmpty(query, "query")
Arguments.checkNonEmpty(orgID, "orgID")

return query(Query().dialect(AbstractInfluxDBClient.DEFAULT_DIALECT).query(query), orgID)
}

override fun query(query: Query, orgID: String): Channel<FluxRecord> {

Arguments.checkNotNull(query, "query")
Arguments.checkNonEmpty(orgID, "orgID")

val consumer = BiConsumer { channel: Channel<FluxRecord>, record: FluxRecord ->
runBlocking {
channel.send(record)
}
}

return query(query, AbstractQueryApi.DEFAULT_DIALECT.toString(), orgID, consumer)
return query(query, orgID, consumer)
}

override fun <M> query(query: String, orgID: String, measurementType: Class<M>): Channel<M> {
Expand All @@ -65,25 +76,49 @@ internal class QueryKotlinApiImpl(private val influxDBService: InfluxDBService)
}
}

return query(query, AbstractQueryApi.DEFAULT_DIALECT.toString(), orgID, consumer)
return query(Query().dialect(AbstractInfluxDBClient.DEFAULT_DIALECT).query(query), orgID, consumer)
}

override fun <M> query(query: Query, orgID: String, measurementType: Class<M>): Channel<M> {

Arguments.checkNotNull(query, "query")
Arguments.checkNonEmpty(orgID, "orgID")
Arguments.checkNotNull(measurementType, "measurementType")

val consumer = BiConsumer { channel: Channel<M>, record: FluxRecord ->
runBlocking {
channel.send(resultMapper.toPOJO(record, measurementType))
}
}

return query(query, orgID, consumer)
}

override fun queryRaw(query: String, orgID: String): Channel<String> {

Arguments.checkNonEmpty(query, "query")
Arguments.checkNonEmpty(orgID, "orgID")

return queryRaw(query, AbstractQueryApi.DEFAULT_DIALECT.toString(), orgID)
return queryRaw(query, AbstractInfluxDBClient.DEFAULT_DIALECT, orgID)
}

override fun queryRaw(query: String, dialect: String, orgID: String): Channel<String> {
override fun queryRaw(query: String, dialect: Dialect, orgID: String): Channel<String> {

Arguments.checkNonEmpty(query, "query")
Arguments.checkNonEmpty(orgID, "orgID")

val channel = Channel<String>()
return queryRaw(Query().dialect(dialect).query(query), orgID)
}

override fun queryRaw(query: Query, orgID: String): Channel<String> {

Arguments.checkNotNull(query, "query")
Arguments.checkNonEmpty(orgID, "orgID")

val channel = Channel<String>()

val queryCall = influxDBService.query(orgID, createBody(dialect, query))
val queryCall = service.queryPostResponseBody(null, "text/csv", "application/json",
null, orgID, query)

val consumer = BiConsumer { cancellable: Cancellable, line: String ->

Expand All @@ -99,17 +134,18 @@ internal class QueryKotlinApiImpl(private val influxDBService: InfluxDBService)
queryRaw(queryCall, consumer, Consumer { channel.close(it) }, Runnable { channel.close() }, true)

return channel

}

private fun <T> query(query: String, dialect: String, orgID: String, consumer: BiConsumer<Channel<T>, FluxRecord>): Channel<T> {
private fun <T> query(query: Query, orgID: String, consumer: BiConsumer<Channel<T>, FluxRecord>): Channel<T> {

Arguments.checkNonEmpty(query, "query")
Arguments.checkNotNull(query, "query")
Arguments.checkNonEmpty(orgID, "orgID")
Arguments.checkNonEmpty(dialect, "dialect")

val channel = Channel<T>()

val queryCall = influxDBService.query(orgID, createBody(dialect, query))
val queryCall = service.queryPostResponseBody(null, "text/csv", "application/json",
null, orgID, query)

val responseConsumer = object : FluxResponseConsumer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package org.influxdata.client.kotlin

import org.assertj.core.api.Assertions
import org.influxdata.LogLevel
import org.influxdata.client.domain.Check
import org.junit.jupiter.api.Test
import org.junit.platform.runner.JUnitPlatform
import org.junit.runner.RunWith
Expand All @@ -46,7 +47,7 @@ internal class ITInfluxDBClientKotlin : AbstractITInfluxDBClientKotlin() {
val health = influxDBClient.health()

Assertions.assertThat(health).isNotNull
Assertions.assertThat(health.isHealthy).isTrue()
Assertions.assertThat(health.status).isEqualTo(Check.StatusEnum.PASS)
Assertions.assertThat(health.message).isEqualTo("ready for queries and writes")
}

Expand All @@ -59,7 +60,7 @@ internal class ITInfluxDBClientKotlin : AbstractITInfluxDBClientKotlin() {
val health = clientNotRunning.health()

Assertions.assertThat(health).isNotNull
Assertions.assertThat(health.isHealthy).isFalse()
Assertions.assertThat(health.status).isEqualTo(Check.StatusEnum.FAIL)
Assertions.assertThat(health.message).startsWith("Failed to connect to")

clientNotRunning.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@ import kotlinx.coroutines.runBlocking
import org.influxdata.annotations.Column
import org.influxdata.client.InfluxDBClientFactory
import org.influxdata.client.domain.Bucket
import org.influxdata.client.domain.BucketRetentionRules
import org.influxdata.client.domain.Dialect
import org.influxdata.client.domain.Organization
import org.influxdata.client.domain.Permission
import org.influxdata.client.domain.PermissionResource
import org.influxdata.client.domain.ResourceType
import org.influxdata.client.domain.RetentionRule
import org.json.JSONObject
import org.influxdata.client.domain.WritePrecision
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.platform.runner.JUnitPlatform
import org.junit.runner.RunWith
import java.net.ConnectException
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.*

/**
Expand All @@ -72,9 +71,9 @@ internal class ITQueryKotlinApi : AbstractITInfluxDBClientKotlin() {
.findFirst()
.orElseThrow { IllegalStateException() }

val retentionRule = RetentionRule()
retentionRule.type = "expire"
retentionRule.everySeconds = 3600L
val retentionRule = BucketRetentionRules()
retentionRule.type = BucketRetentionRules.TypeEnum.EXPIRE
retentionRule.everySeconds = 3600

bucket = client.bucketsApi
.createBucket(generateName("h2o"), retentionRule, organization)
Expand All @@ -85,16 +84,16 @@ internal class ITQueryKotlinApi : AbstractITInfluxDBClientKotlin() {

val resource = PermissionResource()
resource.orgID = organization.id
resource.type = ResourceType.BUCKETS
resource.type = PermissionResource.TypeEnum.BUCKETS
resource.id = bucket.id

val readBucket = Permission()
readBucket.resource = resource
readBucket.action = Permission.READ_ACTION
readBucket.action = Permission.ActionEnum.READ

val writeBucket = Permission()
writeBucket.resource = resource
writeBucket.action = Permission.WRITE_ACTION
writeBucket.action = Permission.ActionEnum.WRITE

val authorization = client.authorizationsApi
.createAuthorization(organization, Arrays.asList(readBucket, writeBucket))
Expand All @@ -111,7 +110,7 @@ internal class ITQueryKotlinApi : AbstractITInfluxDBClientKotlin() {
.joinToString("\n")

val writeApi = client.writeApi
writeApi.writeRecord(bucket.name, organization.id, ChronoUnit.NANOS, records)
writeApi.writeRecord(bucket.name, organization.id, WritePrecision.NS, records)
writeApi.close()

client.close()
Expand Down Expand Up @@ -146,7 +145,7 @@ internal class ITQueryKotlinApi : AbstractITInfluxDBClientKotlin() {
val values = records.map { it.value }.toList()

assert(values).hasSize(10)
assert(values).containsExactly(10L, 11L, 20L, 22L, 35L, 38L, 55L, 45L, 49L, 65L)
assert(values).containsExactly(55L, 65L, 35L, 38L, 45L, 49L, 10L, 11L, 20L, 22L)
}

@Test
Expand Down Expand Up @@ -228,9 +227,7 @@ internal class ITQueryKotlinApi : AbstractITInfluxDBClientKotlin() {
"|> filter(fn: (r) => (r[\"_measurement\"] == \"mem\" and r[\"_field\"] == \"free\"))\t" +
"|> sum()"

val dialect = JSONObject()
.put("header", false)
.toString()
val dialect = Dialect().header(false)

val lines = queryKotlinApi.queryRaw(flux, dialect, organization.id).toList()

Expand Down
Loading