Move shutdown enable flag to the endpoint
This commit is contained in:
parent
cd54e1ed49
commit
171c1366f9
|
@ -20,8 +20,6 @@ import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.actuate.properties.ManagementServerProperties;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
@ -40,8 +38,7 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>> impl
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
private ConfigurableApplicationContext context;
|
||||||
|
|
||||||
@Autowired(required = false)
|
private boolean enabled = false;
|
||||||
private ManagementServerProperties configuration = new ManagementServerProperties();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link ShutdownEndpoint} instance.
|
* Create a new {@link ShutdownEndpoint} instance.
|
||||||
|
@ -52,12 +49,17 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> invoke() {
|
public Map<String, Object> invoke() {
|
||||||
if (this.configuration == null || !this.configuration.isAllowShutdown()
|
|
||||||
|| this.context == null) {
|
if (!this.enabled) {
|
||||||
return Collections.<String, Object> singletonMap("message",
|
return Collections.<String, Object> singletonMap("message",
|
||||||
"Shutdown not enabled, sorry.");
|
"Shutdown not enabled, sorry.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.context == null) {
|
||||||
|
return Collections.<String, Object> singletonMap("message",
|
||||||
|
"No context to shutdown.");
|
||||||
|
}
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -87,4 +89,11 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>> impl
|
||||||
return POST_HTTP_METHOD;
|
return POST_HTTP_METHOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return this.enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,18 +42,8 @@ public class ManagementServerProperties implements SecurityPrequisite {
|
||||||
@NotNull
|
@NotNull
|
||||||
private String contextPath = "";
|
private String contextPath = "";
|
||||||
|
|
||||||
private boolean allowShutdown = false;
|
|
||||||
|
|
||||||
private Security security = maybeCreateSecurity();
|
private Security security = maybeCreateSecurity();
|
||||||
|
|
||||||
public boolean isAllowShutdown() {
|
|
||||||
return this.allowShutdown;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAllowShutdown(boolean allowShutdown) {
|
|
||||||
this.allowShutdown = allowShutdown;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the management port or {@code null} if the
|
* Returns the management port or {@code null} if the
|
||||||
* {@link ServerProperties#getPort() server port} should be used.
|
* {@link ServerProperties#getPort() server port} should be used.
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
package org.springframework.boot.actuate.endpoint;
|
package org.springframework.boot.actuate.endpoint;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.boot.actuate.endpoint.ShutdownEndpoint;
|
|
||||||
import org.springframework.boot.actuate.properties.ManagementServerProperties;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -32,6 +30,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
* Tests for {@link ShutdownEndpoint}.
|
* Tests for {@link ShutdownEndpoint}.
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoint> {
|
public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoint> {
|
||||||
|
|
||||||
|
@ -53,16 +52,11 @@ public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoin
|
||||||
@EnableConfigurationProperties
|
@EnableConfigurationProperties
|
||||||
public static class Config {
|
public static class Config {
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ManagementServerProperties managementServerProperties() {
|
|
||||||
ManagementServerProperties properties = new ManagementServerProperties();
|
|
||||||
properties.setAllowShutdown(true);
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ShutdownEndpoint endpoint() {
|
public ShutdownEndpoint endpoint() {
|
||||||
return new ShutdownEndpoint();
|
ShutdownEndpoint endpoint = new ShutdownEndpoint();
|
||||||
|
endpoint.setEnabled(true);
|
||||||
|
return endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue