mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Revert "Add support for InfluxDB 2.x"
This reverts commit 52fedb2bb4
.
See gh-25891
This commit is contained in:
parent
4d30eb453f
commit
6d50e65572
@ -23,7 +23,6 @@ dependencies {
|
||||
optional("com.hazelcast:hazelcast")
|
||||
optional("com.hazelcast:hazelcast-spring")
|
||||
optional("com.h2database:h2")
|
||||
optional("com.influxdb:influxdb-client-java")
|
||||
optional("com.nimbusds:oauth2-oidc-sdk")
|
||||
optional("com.oracle.database.jdbc:ojdbc8")
|
||||
optional("com.oracle.database.jdbc:ucp")
|
||||
|
@ -16,10 +16,6 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.influx;
|
||||
|
||||
import com.influxdb.client.InfluxDBClient;
|
||||
import com.influxdb.client.InfluxDBClientFactory;
|
||||
import com.influxdb.client.InfluxDBClientOptions;
|
||||
import com.influxdb.client.InfluxDBClientOptions.Builder;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.impl.InfluxDBImpl;
|
||||
@ -32,7 +28,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for InfluxDB.
|
||||
@ -43,10 +38,21 @@ import org.springframework.util.StringUtils;
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty("spring.influx.url")
|
||||
@ConditionalOnClass(InfluxDB.class)
|
||||
@EnableConfigurationProperties(InfluxDbProperties.class)
|
||||
public class InfluxDbAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty("spring.influx.url")
|
||||
public InfluxDB influxDb(InfluxDbProperties properties, ObjectProvider<InfluxDbOkHttpClientBuilderProvider> builder,
|
||||
ObjectProvider<InfluxDbCustomizer> customizers) {
|
||||
InfluxDB influxDb = new InfluxDBImpl(properties.getUrl(), properties.getUser(), properties.getPassword(),
|
||||
determineBuilder(builder.getIfAvailable()));
|
||||
customizers.orderedStream().forEach((customizer) -> customizer.customize(influxDb));
|
||||
return influxDb;
|
||||
}
|
||||
|
||||
private static OkHttpClient.Builder determineBuilder(InfluxDbOkHttpClientBuilderProvider builder) {
|
||||
if (builder != null) {
|
||||
return builder.get();
|
||||
@ -54,40 +60,4 @@ public class InfluxDbAutoConfiguration {
|
||||
return new OkHttpClient.Builder();
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(InfluxDB.class)
|
||||
static class Influx1xConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
InfluxDB influxDb(InfluxDbProperties properties, ObjectProvider<InfluxDbOkHttpClientBuilderProvider> builder,
|
||||
ObjectProvider<InfluxDbCustomizer> customizers) {
|
||||
InfluxDB influxDb = new InfluxDBImpl(properties.getUrl(), properties.getUser(), properties.getPassword(),
|
||||
determineBuilder(builder.getIfAvailable()));
|
||||
customizers.orderedStream().forEach((customizer) -> customizer.customize(influxDb));
|
||||
return influxDb;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(InfluxDBClient.class)
|
||||
static class Influx2xConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
InfluxDBClient influxDbClient(InfluxDbProperties properties,
|
||||
ObjectProvider<InfluxDbOkHttpClientBuilderProvider> httpClientBuilder,
|
||||
ObjectProvider<InfluxDbClientOptionsBuilderCustomizer> customizers) {
|
||||
Builder builder = InfluxDBClientOptions.builder().url(properties.getUrl());
|
||||
if (StringUtils.hasText(properties.getUser()) && StringUtils.hasText(properties.getPassword())) {
|
||||
builder.authenticate(properties.getUser(), properties.getPassword().toCharArray());
|
||||
}
|
||||
builder.okHttpClient(determineBuilder(httpClientBuilder.getIfAvailable()));
|
||||
customizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
|
||||
return InfluxDBClientFactory.create(builder.build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.influx;
|
||||
|
||||
import com.influxdb.client.InfluxDBClient;
|
||||
import com.influxdb.client.InfluxDBClientOptions;
|
||||
|
||||
/**
|
||||
* Callback interface that can be implemented by beans wishing to further customize
|
||||
* {@link InfluxDBClientOptions} used to configure an {@link InfluxDBClient} whilst
|
||||
* retaining default auto-configuration.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.6.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface InfluxDbClientOptionsBuilderCustomizer {
|
||||
|
||||
/**
|
||||
* Customize the {@link InfluxDBClientOptions}.
|
||||
* @param builder the influxDB client options builder to customize
|
||||
*/
|
||||
void customize(InfluxDBClientOptions.Builder builder);
|
||||
|
||||
}
|
@ -17,12 +17,8 @@
|
||||
package org.springframework.boot.autoconfigure.influx;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.influxdb.client.InfluxDBClient;
|
||||
import com.influxdb.client.InfluxDBClientOptions;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import retrofit2.Retrofit;
|
||||
@ -30,7 +26,6 @@ import retrofit2.Retrofit;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.context.runner.ContextConsumer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
@ -91,42 +86,6 @@ class InfluxDbAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void influxDbClientRequiresUrl() {
|
||||
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(InfluxDBClient.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void influxDbClientCanBeCustomized() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.influx.url=http://localhost", "spring.influx.user=user",
|
||||
"spring.influx.password=password")
|
||||
.run((context) -> assertThat(context).hasSingleBean(InfluxDBClient.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void influxDbClientCanBeCreatedWithoutCredentials() {
|
||||
this.contextRunner.withPropertyValues("spring.influx.url=http://localhost").run(assertInfluxDbClientOptions(
|
||||
(options) -> assertThat(options.getOkHttpClient().build().readTimeoutMillis()).isEqualTo(10000)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void influxDbClientWithOkHttpClientBuilderProvider() {
|
||||
this.contextRunner.withUserConfiguration(CustomOkHttpClientBuilderProviderConfig.class)
|
||||
.withPropertyValues("spring.influx.url=http://localhost")
|
||||
.run(assertInfluxDbClientOptions(
|
||||
(options) -> assertThat(options.getOkHttpClient().build().readTimeoutMillis())
|
||||
.isEqualTo(40000)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void influxDbClientWithCustomizer() {
|
||||
this.contextRunner
|
||||
.withBean(InfluxDbClientOptionsBuilderCustomizer.class, () -> (options) -> options.org("my_org"))
|
||||
.withPropertyValues("spring.influx.url=http://localhost")
|
||||
.run(assertInfluxDbClientOptions((options) -> assertThat(options.getOrg()).isEqualTo("my_org")));
|
||||
}
|
||||
|
||||
private int getReadTimeoutProperty(AssertableApplicationContext context) {
|
||||
InfluxDB influxDb = context.getBean(InfluxDB.class);
|
||||
Retrofit retrofit = (Retrofit) ReflectionTestUtils.getField(influxDb, "retrofit");
|
||||
@ -134,16 +93,6 @@ class InfluxDbAutoConfigurationTests {
|
||||
return callFactory.readTimeoutMillis();
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertInfluxDbClientOptions(
|
||||
Consumer<InfluxDBClientOptions> options) {
|
||||
return (context) -> {
|
||||
assertThat(context).hasSingleBean(InfluxDBClient.class);
|
||||
assertThat(context).getBean(InfluxDBClient.class)
|
||||
.extracting("options", InstanceOfAssertFactories.type(InfluxDBClientOptions.class))
|
||||
.satisfies(options);
|
||||
};
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class CustomOkHttpClientBuilderProviderConfig {
|
||||
|
||||
|
@ -526,13 +526,6 @@ bom {
|
||||
]
|
||||
}
|
||||
}
|
||||
library("InfluxDB Client Java", "2.3.0") {
|
||||
group("com.influxdb") {
|
||||
modules = [
|
||||
"influxdb-client-java"
|
||||
]
|
||||
}
|
||||
}
|
||||
library("InfluxDB Java", "2.21") {
|
||||
group("org.influxdb") {
|
||||
modules = [
|
||||
|
@ -634,7 +634,7 @@ https://www.influxdata.com/[InfluxDB] is an open-source time series database opt
|
||||
|
||||
[[data.nosql.influxdb.connecting]]
|
||||
==== Connecting to InfluxDB
|
||||
Spring Boot auto-configures a client instance, provided that either `influxdb-java` (Influx 1.x) or `influxdb-client-java` (Influx 2.x) is on the classpath and the URL of the database is set, as shown in the following example:
|
||||
Spring Boot auto-configures an `InfluxDB` instance, provided the `influxdb-java` client is on the classpath and the URL of the database is set, as shown in the following example:
|
||||
|
||||
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
|
||||
----
|
||||
@ -648,4 +648,4 @@ If the connection to InfluxDB requires a user and password, you can set the `spr
|
||||
InfluxDB relies on OkHttp.
|
||||
If you need to tune the http client `InfluxDB` uses behind the scenes, you can register an `InfluxDbOkHttpClientBuilderProvider` bean.
|
||||
|
||||
If you need more control over the configuration, consider registering an `InfluxDbCustomizer` (Influx 1.x), or an `InfluxDbClientOptionsBuilderCustomizer` (Influx 2.x) bean.
|
||||
If you need more control over the configuration, consider registering an `InfluxDbCustomizer` bean.
|
||||
|
Loading…
Reference in New Issue
Block a user