Merge pull request #9066 from kuptservol:influxdb-autoconfiguration
* pr/9066: Polish "Add influxDB java client auto-configuration" Add influxDB java client auto-configuration
This commit is contained in:
commit
4651633b0d
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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 com.google.common.base.Strings;
|
||||
import org.influxdb.InfluxDB;
|
||||
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;
|
||||
|
||||
/**
|
||||
* {@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 {
|
||||
|
||||
private final InfluxDbProperties properties;
|
||||
|
||||
public InfluxDbAutoConfiguration(InfluxDbProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@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(client.getUrl(), client.getUser(),
|
||||
client.getPassword());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Configuration properties for InfluxDB.
|
||||
*
|
||||
* @author Sergey Kuptsov
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "spring.influx")
|
||||
public class InfluxDbProperties {
|
||||
|
||||
private final Client client = new Client();
|
||||
|
||||
public Client getClient() {
|
||||
return this.client;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright 2012-2015 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auto-configuration for InfluxDB.
|
||||
*/
|
||||
package org.springframework.boot.autoconfigure.influx;
|
||||
|
|
@ -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,\
|
||||
|
|
|
|||
|
|
@ -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 -->
|
||||
|
|
@ -1856,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>
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue