Commit 6aefa229 by Johannes Edmeier

Polish

parent 984351fa
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
~ Copyright 2014-2017 the original author or authors. ~ Copyright 2014-2018 the original author or authors.
~ ~
~ Licensed under the Apache License, Version 2.0 (the "License"); ~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License. ~ you may not use this file except in compliance with the License.
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
</execution> </execution>
</executions> </executions>
<configuration> <configuration>
<mainClass>de.codecentric.boot.admin.TestApplication</mainClass> <mainClass>de.codecentric.boot.admin.SpringBootAdminApplication</mainClass>
<addResources>false</addResources> <addResources>false</addResources>
</configuration> </configuration>
</plugin> </plugin>
......
...@@ -35,6 +35,16 @@ ...@@ -35,6 +35,16 @@
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
...@@ -24,10 +24,10 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter; ...@@ -24,10 +24,10 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.reactive.config.WebFluxConfigurer; import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver; import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
...@@ -35,65 +35,68 @@ import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver; ...@@ -35,65 +35,68 @@ import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
@Configuration @Configuration
@ConditionalOnBean(AdminServerMarkerConfiguration.Marker.class) @ConditionalOnBean(AdminServerMarkerConfiguration.Marker.class)
@AutoConfigureAfter(AdminServerWebConfiguration.class) @AutoConfigureAfter(AdminServerWebConfiguration.class)
@EnableConfigurationProperties(AdminServerUiProperties.class)
public class AdminServerUiAutoConfiguration { public class AdminServerUiAutoConfiguration {
private final AdminServerUiProperties uiProperties;
private final ApplicationContext applicationContext;
//FIXME make property of it public AdminServerUiAutoConfiguration(AdminServerUiProperties uiProperties, ApplicationContext applicationContext) {
public static final String SBA_RESOURCE_LOC = "file:/Users/jedmeier/projects/spring-boot-admin/spring-boot-admin-server-ui/target/dist/"; this.uiProperties = uiProperties;
//public static final String SBA_RESOURCE_LOC = "classpath:/META-INF/spring-boot-admin-server-ui/"; this.applicationContext = applicationContext;
}
@Configuration
public static class UiConfiguration {
private final ApplicationContext applicationContext;
public UiConfiguration(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Bean
@ConditionalOnMissingBean
public UiController homeUiController() {
return new UiController();
}
@Bean @Bean
public SpringResourceTemplateResolver adminTemplateResolver() { @ConditionalOnMissingBean
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); public UiController homeUiController() {
resolver.setApplicationContext(this.applicationContext); return new UiController();
resolver.setPrefix(SBA_RESOURCE_LOC); }
resolver.setSuffix(".html");
resolver.setTemplateMode("HTML");
resolver.setCharacterEncoding("UTF-8");
//FIXME make property of it
resolver.setCacheable(false);
resolver.setOrder(10);
resolver.setCheckExistence(true);
return resolver;
}
@Bean
public SpringResourceTemplateResolver adminTemplateResolver() {
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(this.applicationContext);
resolver.setPrefix(uiProperties.getTemplateLocation());
resolver.setSuffix(".html");
resolver.setTemplateMode("HTML");
resolver.setCharacterEncoding("UTF-8");
//FIXME make property of it
resolver.setCacheable(false);
resolver.setOrder(10);
resolver.setCheckExistence(true);
return resolver;
} }
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@Configuration @Configuration
public static class ReactiveUiConfiguration implements WebFluxConfigurer { public static class ReactiveUiConfiguration implements WebFluxConfigurer {
private final AdminServerUiProperties uiProperties;
public ReactiveUiConfiguration(AdminServerUiProperties uiProperties) {
this.uiProperties = uiProperties;
}
@Override @Override
public void addResourceHandlers(org.springframework.web.reactive.config.ResourceHandlerRegistry registry) { public void addResourceHandlers(org.springframework.web.reactive.config.ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(SBA_RESOURCE_LOC) registry.addResourceHandler("/**")
//FIXME make property of it .addResourceLocations(uiProperties.getResourceLocations())
.setCacheControl(CacheControl.noStore()); .setCacheControl(uiProperties.getCache().toCacheControl());
} }
} }
//FIXME move to ui project
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@Configuration @Configuration
public static class ServletUiConfiguration implements WebMvcConfigurer { public static class ServletUiConfiguration implements WebMvcConfigurer {
private final AdminServerUiProperties uiProperties;
public ServletUiConfiguration(AdminServerUiProperties uiProperties) {
this.uiProperties = uiProperties;
}
@Override @Override
public void addResourceHandlers(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry registry) { public void addResourceHandlers(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(SBA_RESOURCE_LOC) registry.addResourceHandler("/**")
//FIXME make property of it .addResourceLocations(uiProperties.getResourceLocations())
.setCacheControl(CacheControl.noStore()); .setCacheControl(uiProperties.getCache().toCacheControl());
} }
} }
} }
/*
* Copyright 2014-2018 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 de.codecentric.boot.admin.server.ui.config;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.TimeUnit;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.http.CacheControl;
@lombok.Data
@ConfigurationProperties("spring.boot.admin.ui")
public class AdminServerUiProperties {
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {"classpath:/META-INF/spring-boot-admin-server-ui/"};
/**
* Locations of SBA ui resources.
*/
private String[] resourceLocations = CLASSPATH_RESOURCE_LOCATIONS;
/**
* Locations of SBA ui template.
*/
private String templateLocation = CLASSPATH_RESOURCE_LOCATIONS[0];
private final Cache cache = new Cache();
@lombok.Data
public static class Cache {
/**
* include "max-age" directive in Cache-Control http header.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration maxAge = Duration.ofSeconds(3600);
/**
* include "no-cache" directive in Cache-Control http header.
*/
private Boolean noCache = false;
/**
* include "no-store" directive in Cache-Control http header.
*/
private Boolean noStore = false;
public CacheControl toCacheControl() {
if (Boolean.TRUE.equals(this.noStore)) {
return CacheControl.noStore();
}
if (Boolean.TRUE.equals(this.noCache)) {
return CacheControl.noCache();
}
if (this.maxAge != null) {
return CacheControl.maxAge(this.maxAge.getSeconds(), TimeUnit.SECONDS);
}
return CacheControl.empty();
}
}
}
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
package de.codecentric.boot.admin.server.config; package de.codecentric.boot.admin.server.config;
import java.time.Duration; import java.time.Duration;
import java.time.temporal.ChronoUnit;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
@lombok.Data @lombok.Data
@ConfigurationProperties("spring.boot.admin") @ConfigurationProperties("spring.boot.admin")
...@@ -80,23 +82,27 @@ public class AdminServerProperties { ...@@ -80,23 +82,27 @@ public class AdminServerProperties {
/** /**
* Time interval to update the status of instances with expired statusInfo * Time interval to update the status of instances with expired statusInfo
*/ */
private Duration period = Duration.ofSeconds(10); @DefaultDurationUnit(ChronoUnit.MILLIS)
private Duration period = Duration.ofMillis(10_000L);
/** /**
* Lifetime of status. The status won't be updated as long the last status isn't * Lifetime of status. The status won't be updated as long the last status isn't
* expired. * expired.
*/ */
private Duration statusLifetime = Duration.ofSeconds(10); @DefaultDurationUnit(ChronoUnit.MILLIS)
private Duration statusLifetime = Duration.ofMillis(10_000L);
/** /**
* Connect timeout when querying the instances' status and info. * Connect timeout when querying the instances' status and info.
*/ */
private Duration connectTimeout = Duration.ofSeconds(2); @DefaultDurationUnit(ChronoUnit.MILLIS)
private Duration connectTimeout = Duration.ofMillis(2_000);
/** /**
* read timeout when querying the instances' status and info. * read timeout when querying the instances' status and info.
*/ */
private Duration readTimeout = Duration.ofSeconds(5); @DefaultDurationUnit(ChronoUnit.MILLIS)
private Duration readTimeout = Duration.ofMillis(5_000);
} }
} }
{"groups": [ {
"groups": [
],"properties": [ ],
{ "properties": [
"name": "spring.boot.admin.hazelcast.enabled", {
"type": "java.lang.Boolean", "name": "spring.boot.admin.hazelcast.enabled",
"description": "Enable Hazelcast support.", "type": "java.lang.Boolean",
"defaultValue": "true" "description": "Enable Hazelcast support.",
}, "defaultValue": "true"
{ },
"name": "spring.boot.admin.hazelcast.application-store", {
"type": "java.lang.String", "name": "spring.boot.admin.hazelcast.event-store",
"description": "Name of backing Hazelcast-Map for storing applications", "type": "java.lang.String",
"defaultValue": "spring-boot-admin-application-store" "description": "Name of backing Hazelcast-Map for storing the instance events",
}, "defaultValue": "spring-boot-admin-application-store"
{ },
"name": "spring.boot.admin.hazelcast.application-store", {
"type": "java.lang.String", "name": "spring.boot.admin.discovery.enabled",
"description": "Name of backing Hazelcast-List for storing the journal", "type": "java.lang.Boolean",
"defaultValue": "spring-boot-admin-event-store" "description": "Enable Spring Cloud Discovery support.",
}, "defaultValue": "true"
{ }
"name": "spring.boot.admin.discovery.enabled", ]
"type": "java.lang.Boolean", }
"description": "Enable Spring Cloud Discovery support.",
"defaultValue": "true"
}
]}
/* /*
* Copyright 2014-2017 the original author or authors. * Copyright 2014-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
package de.codecentric.boot.admin.client.config; package de.codecentric.boot.admin.client.config;
import java.time.Duration; import java.time.Duration;
import java.time.temporal.ChronoUnit;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
@lombok.Data @lombok.Data
@ConfigurationProperties(prefix = "spring.boot.admin.client") @ConfigurationProperties(prefix = "spring.boot.admin.client")
...@@ -35,17 +37,20 @@ public class ClientProperties { ...@@ -35,17 +37,20 @@ public class ClientProperties {
/** /**
* Time interval the registration is repeated * Time interval the registration is repeated
*/ */
private Duration period = Duration.ofSeconds(10); @DefaultDurationUnit(ChronoUnit.MILLIS)
private Duration period = Duration.ofMillis(10_000L);
/** /**
* Connect timeout for the registration. * Connect timeout for the registration.
*/ */
private Duration connectTimeout = Duration.ofSeconds(5); @DefaultDurationUnit(ChronoUnit.MILLIS)
private Duration connectTimeout = Duration.ofMillis(5_000L);
/** /**
* Read timeout (in ms) for the registration. * Read timeout (in ms) for the registration.
*/ */
private Duration readTimeout = Duration.ofSeconds(5); @DefaultDurationUnit(ChronoUnit.MILLIS)
private Duration readTimeout = Duration.ofMillis(5_000L);
/** /**
* Username for basic authentication on admin server * Username for basic authentication on admin server
......
/* /*
* Copyright 2014-2017 the original author or authors. * Copyright 2014-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
*/ */
package de.codecentric.boot.admin.client.config; package de.codecentric.boot.admin.client.config;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
...@@ -65,6 +65,6 @@ public class InstanceProperties { ...@@ -65,6 +65,6 @@ public class InstanceProperties {
/** /**
* Metadata that should be associated with this application * Metadata that should be associated with this application
*/ */
private Map<String, String> metadata = new HashMap<>(); private Map<String, String> metadata = new LinkedHashMap<>();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment