Move shutdown enable flag to the endpoint

This commit is contained in:
Dave Syer 2013-11-26 18:01:08 +00:00
parent cd54e1ed49
commit 171c1366f9
3 changed files with 19 additions and 26 deletions

View File

@ -20,8 +20,6 @@ import java.util.Collections;
import java.util.Map;
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.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@ -40,8 +38,7 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>> impl
private ConfigurableApplicationContext context;
@Autowired(required = false)
private ManagementServerProperties configuration = new ManagementServerProperties();
private boolean enabled = false;
/**
* Create a new {@link ShutdownEndpoint} instance.
@ -52,12 +49,17 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>> impl
@Override
public Map<String, Object> invoke() {
if (this.configuration == null || !this.configuration.isAllowShutdown()
|| this.context == null) {
if (!this.enabled) {
return Collections.<String, Object> singletonMap("message",
"Shutdown not enabled, sorry.");
}
if (this.context == null) {
return Collections.<String, Object> singletonMap("message",
"No context to shutdown.");
}
new Thread(new Runnable() {
@Override
public void run() {
@ -87,4 +89,11 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>> impl
return POST_HTTP_METHOD;
}
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@ -42,18 +42,8 @@ public class ManagementServerProperties implements SecurityPrequisite {
@NotNull
private String contextPath = "";
private boolean allowShutdown = false;
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
* {@link ServerProperties#getPort() server port} should be used.

View File

@ -17,8 +17,6 @@
package org.springframework.boot.actuate.endpoint;
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.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -32,6 +30,7 @@ import static org.junit.Assert.assertTrue;
* Tests for {@link ShutdownEndpoint}.
*
* @author Phillip Webb
* @author Dave Syer
*/
public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoint> {
@ -53,16 +52,11 @@ public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoin
@EnableConfigurationProperties
public static class Config {
@Bean
public ManagementServerProperties managementServerProperties() {
ManagementServerProperties properties = new ManagementServerProperties();
properties.setAllowShutdown(true);
return properties;
}
@Bean
public ShutdownEndpoint endpoint() {
return new ShutdownEndpoint();
ShutdownEndpoint endpoint = new ShutdownEndpoint();
endpoint.setEnabled(true);
return endpoint;
}
}