Polish "Add influxDB java client auto-configuration"
Closes gh-9066
This commit is contained in:
@@ -641,6 +641,11 @@
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.influxdb</groupId>
|
||||
<artifactId>influxdb-java</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq</artifactId>
|
||||
@@ -661,11 +666,6 @@
|
||||
<artifactId>quartz</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.influxdb</groupId>
|
||||
<artifactId>influxdb-java</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- Annotation processing -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.influxdb.InfluxDBFactory;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
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;
|
||||
@@ -31,32 +32,32 @@ import org.springframework.context.annotation.Configuration;
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for InfluxDB.
|
||||
*
|
||||
* @author Sergey Kuptsov
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(InfluxDB.class)
|
||||
@EnableConfigurationProperties(InfluxDBProperties.class)
|
||||
public class InfluxDBAutoConfiguration {
|
||||
@EnableConfigurationProperties(InfluxDbProperties.class)
|
||||
public class InfluxDbAutoConfiguration {
|
||||
|
||||
private final InfluxDBProperties properties;
|
||||
private final InfluxDbProperties properties;
|
||||
|
||||
public InfluxDBAutoConfiguration(InfluxDBProperties properties) {
|
||||
public InfluxDbAutoConfiguration(InfluxDbProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public InfluxDB influxDB() {
|
||||
if (Strings.isNullOrEmpty(this.properties.getUser())) {
|
||||
return InfluxDBFactory.connect(
|
||||
this.properties.getUrl()
|
||||
);
|
||||
@ConditionalOnProperty("spring.influx.client.url")
|
||||
public InfluxDB influxDb() {
|
||||
InfluxDbProperties.Client client = this.properties.getClient();
|
||||
if (Strings.isNullOrEmpty(client.getUser())) {
|
||||
return InfluxDBFactory.connect(client.getUrl());
|
||||
}
|
||||
else {
|
||||
return InfluxDBFactory.connect(
|
||||
this.properties.getUrl(),
|
||||
this.properties.getUser(),
|
||||
this.properties.getPassword()
|
||||
);
|
||||
return InfluxDBFactory.connect(client.getUrl(), client.getUser(),
|
||||
client.getPassword());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,46 +22,59 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
* Configuration properties for InfluxDB.
|
||||
*
|
||||
* @author Sergey Kuptsov
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "spring.data.influx")
|
||||
public class InfluxDBProperties {
|
||||
@ConfigurationProperties(prefix = "spring.influx")
|
||||
public class InfluxDbProperties {
|
||||
|
||||
/**
|
||||
* The url to connect to.
|
||||
*/
|
||||
private String url;
|
||||
private final Client client = new Client();
|
||||
|
||||
/**
|
||||
* The username which is used to authorize against the influxDB instance.
|
||||
*/
|
||||
private String user;
|
||||
|
||||
/**
|
||||
* The password for the username which is used to authorize against the influxDB.
|
||||
*/
|
||||
private String password;
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
public Client getClient() {
|
||||
return this.client;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
public static class Client {
|
||||
|
||||
/**
|
||||
* Url of the InfluxDB instance to connect to.
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* Login user.
|
||||
*/
|
||||
private String user;
|
||||
|
||||
/**
|
||||
* Login password.
|
||||
*/
|
||||
private String password;
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,7 @@ org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.influx.InfluxDbAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,\
|
||||
@@ -122,8 +123,7 @@ org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.websocket.reactive.WebSocketReactiveAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.websocket.servlet.WebSocketMessagingAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.influx.InfluxDBAutoConfiguration
|
||||
org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration
|
||||
|
||||
# Failure analyzers
|
||||
org.springframework.boot.diagnostics.FailureAnalyzer=\
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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 org.assertj.core.api.Java6Assertions;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
/**
|
||||
* Tests for {@link InfluxDBAutoConfiguration}.
|
||||
*
|
||||
* @author Sergey Kuptsov
|
||||
*/
|
||||
public class InfluxDBAutoConfigurationTest {
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canEnableConfiguration() {
|
||||
this.context.register(InfluxDBAutoConfiguration.class);
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.influx.url=http://localhost");
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.influx.password:password");
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.influx.user:user");
|
||||
this.context.refresh();
|
||||
Java6Assertions.assertThat(this.context.getBeansOfType(InfluxDB.class)).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canEnableWithEmptyUserConfiguration() {
|
||||
this.context.register(InfluxDBAutoConfiguration.class);
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.influx.url=http://localhost");
|
||||
this.context.refresh();
|
||||
Java6Assertions.assertThat(this.context.getBeansOfType(InfluxDB.class)).isNotEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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
|
||||
*
|
||||
* http://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 org.influxdb.InfluxDB;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link InfluxDbAutoConfiguration}.
|
||||
*
|
||||
* @author Sergey Kuptsov
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class InfluxDbAutoConfigurationTest {
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clientRequiresUrl() {
|
||||
load();
|
||||
assertThat(this.context.getBeansOfType(InfluxDB.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clientCanBeCustomized() {
|
||||
load("spring.influx.client.url=http://localhost",
|
||||
"spring.influx.client.password:password",
|
||||
"spring.influx.client.user:user");
|
||||
assertThat(this.context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clientCanBeCreatedWithoutCredentials() {
|
||||
load("spring.influx.client.url=http://localhost");
|
||||
assertThat(this.context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
||||
}
|
||||
|
||||
private void load(String... environment) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues.of(environment).applyTo(ctx);
|
||||
ctx.register(InfluxDbAutoConfiguration.class);
|
||||
ctx.refresh();
|
||||
this.context = ctx;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -93,6 +93,7 @@
|
||||
<httpclient.version>4.5.3</httpclient.version>
|
||||
<httpcore.version>4.4.6</httpcore.version>
|
||||
<infinispan.version>8.2.6.Final</infinispan.version>
|
||||
<influxdb-java.version>2.5</influxdb-java.version>
|
||||
<jackson.version>2.9.0.pr3</jackson.version>
|
||||
<janino.version>3.0.7</janino.version>
|
||||
<javassist.version>3.21.0-GA</javassist.version> <!-- Same as Hibernate -->
|
||||
@@ -190,7 +191,6 @@
|
||||
<webjars-locator.version>0.32-1</webjars-locator.version>
|
||||
<wsdl4j.version>1.6.3</wsdl4j.version>
|
||||
<xml-apis.version>1.4.01</xml-apis.version>
|
||||
<influxdb-java.version>2.5</influxdb-java.version>
|
||||
<!-- Plugin versions -->
|
||||
<build-helper-maven-plugin.version>1.10</build-helper-maven-plugin.version>
|
||||
<exec-maven-plugin.version>1.5.0</exec-maven-plugin.version>
|
||||
@@ -1857,6 +1857,11 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.influxdb</groupId>
|
||||
<artifactId>influxdb-java</artifactId>
|
||||
<version>${influxdb-java.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
@@ -2473,11 +2478,6 @@
|
||||
<artifactId>xml-apis</artifactId>
|
||||
<version>${xml-apis.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.influxdb</groupId>
|
||||
<artifactId>influxdb-java</artifactId>
|
||||
<version>${influxdb-java.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<build>
|
||||
|
||||
@@ -714,6 +714,11 @@ content into your application; rather pick only the properties that you need.
|
||||
spring.h2.console.settings.trace=false # Enable trace output.
|
||||
spring.h2.console.settings.web-allow-others=false # Enable remote access.
|
||||
|
||||
# InfluxDB ({sc-spring-boot-autoconfigure}/influx/InfluxProperties.{sc-ext}[InfluxProperties])
|
||||
spring.influx.client.password= # Login password.
|
||||
spring.influx.client.url= # Url of the InfluxDB instance to connect to.
|
||||
spring.influx.client.user= # Login user.
|
||||
|
||||
# JOOQ ({sc-spring-boot-autoconfigure}/jooq/JooqAutoConfiguration.{sc-ext}[JooqAutoConfiguration])
|
||||
spring.jooq.sql-dialect= # Sql dialect to use, auto-detected by default.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user