Commit 6aefa229 by Johannes Edmeier

Polish

parent 984351fa
<?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");
~ you may not use this file except in compliance with the License.
......@@ -73,7 +73,7 @@
</execution>
</executions>
<configuration>
<mainClass>de.codecentric.boot.admin.TestApplication</mainClass>
<mainClass>de.codecentric.boot.admin.SpringBootAdminApplication</mainClass>
<addResources>false</addResources>
</configuration>
</plugin>
......
......@@ -35,6 +35,16 @@
<artifactId>spring-boot-starter-web</artifactId>
<optional>true</optional>
</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>
<build>
<plugins>
......
......@@ -24,10 +24,10 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
......@@ -35,17 +35,13 @@ import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
@Configuration
@ConditionalOnBean(AdminServerMarkerConfiguration.Marker.class)
@AutoConfigureAfter(AdminServerWebConfiguration.class)
@EnableConfigurationProperties(AdminServerUiProperties.class)
public class AdminServerUiAutoConfiguration {
//FIXME make property of it
public static final String SBA_RESOURCE_LOC = "file:/Users/jedmeier/projects/spring-boot-admin/spring-boot-admin-server-ui/target/dist/";
//public static final String SBA_RESOURCE_LOC = "classpath:/META-INF/spring-boot-admin-server-ui/";
@Configuration
public static class UiConfiguration {
private final AdminServerUiProperties uiProperties;
private final ApplicationContext applicationContext;
public UiConfiguration(ApplicationContext applicationContext) {
public AdminServerUiAutoConfiguration(AdminServerUiProperties uiProperties, ApplicationContext applicationContext) {
this.uiProperties = uiProperties;
this.applicationContext = applicationContext;
}
......@@ -59,7 +55,7 @@ public class AdminServerUiAutoConfiguration {
public SpringResourceTemplateResolver adminTemplateResolver() {
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(this.applicationContext);
resolver.setPrefix(SBA_RESOURCE_LOC);
resolver.setPrefix(uiProperties.getTemplateLocation());
resolver.setSuffix(".html");
resolver.setTemplateMode("HTML");
resolver.setCharacterEncoding("UTF-8");
......@@ -70,30 +66,37 @@ public class AdminServerUiAutoConfiguration {
return resolver;
}
}
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@Configuration
public static class ReactiveUiConfiguration implements WebFluxConfigurer {
private final AdminServerUiProperties uiProperties;
public ReactiveUiConfiguration(AdminServerUiProperties uiProperties) {
this.uiProperties = uiProperties;
}
@Override
public void addResourceHandlers(org.springframework.web.reactive.config.ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(SBA_RESOURCE_LOC)
//FIXME make property of it
.setCacheControl(CacheControl.noStore());
registry.addResourceHandler("/**")
.addResourceLocations(uiProperties.getResourceLocations())
.setCacheControl(uiProperties.getCache().toCacheControl());
}
}
//FIXME move to ui project
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@Configuration
public static class ServletUiConfiguration implements WebMvcConfigurer {
private final AdminServerUiProperties uiProperties;
public ServletUiConfiguration(AdminServerUiProperties uiProperties) {
this.uiProperties = uiProperties;
}
@Override
public void addResourceHandlers(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(SBA_RESOURCE_LOC)
//FIXME make property of it
.setCacheControl(CacheControl.noStore());
registry.addResourceHandler("/**")
.addResourceLocations(uiProperties.getResourceLocations())
.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 @@
package de.codecentric.boot.admin.server.config;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
@lombok.Data
@ConfigurationProperties("spring.boot.admin")
......@@ -80,23 +82,27 @@ public class AdminServerProperties {
/**
* 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
* 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.
*/
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.
*/
private Duration readTimeout = Duration.ofSeconds(5);
@DefaultDurationUnit(ChronoUnit.MILLIS)
private Duration readTimeout = Duration.ofMillis(5_000);
}
}
{"groups": [
],"properties": [
{
"groups": [
],
"properties": [
{
"name": "spring.boot.admin.hazelcast.enabled",
"type": "java.lang.Boolean",
......@@ -8,21 +9,16 @@
"defaultValue": "true"
},
{
"name": "spring.boot.admin.hazelcast.application-store",
"name": "spring.boot.admin.hazelcast.event-store",
"type": "java.lang.String",
"description": "Name of backing Hazelcast-Map for storing applications",
"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",
"description": "Name of backing Hazelcast-List for storing the journal",
"defaultValue": "spring-boot-admin-event-store"
},
{
"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");
* you may not use this file except in compliance with the License.
......@@ -16,7 +16,9 @@
package de.codecentric.boot.admin.client.config;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
@lombok.Data
@ConfigurationProperties(prefix = "spring.boot.admin.client")
......@@ -35,17 +37,20 @@ public class ClientProperties {
/**
* 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.
*/
private Duration connectTimeout = Duration.ofSeconds(5);
@DefaultDurationUnit(ChronoUnit.MILLIS)
private Duration connectTimeout = Duration.ofMillis(5_000L);
/**
* 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
......
/*
* 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");
* you may not use this file except in compliance with the License.
......@@ -15,7 +15,7 @@
*/
package de.codecentric.boot.admin.client.config;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
......@@ -65,6 +65,6 @@ public class InstanceProperties {
/**
* 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