Final polish before 1.0.0.RC1

This commit is contained in:
Phillip Webb
2014-01-21 13:30:23 -08:00
parent 853b0a8027
commit ac54d7fe3c
67 changed files with 390 additions and 218 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -53,6 +53,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
* Configuration triggered from {@link EndpointWebMvcAutoConfiguration} when a new
* {@link EmbeddedServletContainer} running on a different port is required.
*
* @author Dave Syer
* @see EndpointWebMvcAutoConfiguration
*/
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -48,11 +48,9 @@ import org.springframework.messaging.support.ExecutorSubscribableChannel;
import com.codahale.metrics.MetricRegistry;
/**
* <p>
* {@link EnableAutoConfiguration Auto-configuration} for metrics services. Creates
* user-facing {@link GaugeService} and {@link CounterService} instances, and also back
* end repositories to catch the data pumped into them.
* </p>
* end repositories to catch the data pumped into them. </p>
* <p>
* An {@link InMemoryMetricRepository} is always created unless another
* {@link MetricRepository} is already provided by the user. In general, even if metric

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -21,7 +21,6 @@ import javax.validation.constraints.Pattern;
/**
* Abstract base for {@link Endpoint} implementations.
* <p>
*
* @author Phillip Webb
* @author Christian Dupuis

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -35,7 +35,6 @@ public class TraceEndpoint extends AbstractEndpoint<List<Trace>> {
/**
* Create a new {@link TraceEndpoint} instance.
*
* @param repository the trace repository
*/
public TraceEndpoint(TraceRepository repository) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2014 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.
@@ -184,8 +184,6 @@ public class EndpointMBeanExporter extends MBeanExporter implements SmartLifecyc
return builder.toString();
}
// SmartLifeCycle implementation
@Override
public final int getPhase() {
return this.phase;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -46,7 +46,6 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
* @author Phillip Webb
* @author Christian Dupuis
* @author Dave Syer
*
*/
public class EndpointHandlerMapping extends RequestMappingHandlerMapping implements
ApplicationContextAware {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -17,18 +17,26 @@
package org.springframework.boot.actuate.endpoint.mvc;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Adapter class to expose {@link Endpoint}s as {@link MvcEndpoint}s.
*
* @author Dave Syer
*/
public class GenericMvcEndpoint implements MvcEndpoint {
public class EndpointMvcAdapter implements MvcEndpoint {
private Endpoint<?> delegate;
private final Endpoint<?> delegate;
public GenericMvcEndpoint(Endpoint<?> delegate) {
/**
* Create a new {@link EndpointMvcAdapter}.
* @param delegate the underlying {@link Endpoint} to adapt.
*/
public EndpointMvcAdapter(Endpoint<?> delegate) {
Assert.notNull(delegate, "Delegate must not be null");
this.delegate = delegate;
}
@@ -49,11 +57,9 @@ public class GenericMvcEndpoint implements MvcEndpoint {
}
@Override
public Class<?> getEndpointType() {
@SuppressWarnings("unchecked")
Class<? extends Endpoint<?>> type = (Class<? extends Endpoint<?>>) this.delegate
.getClass();
return type;
@SuppressWarnings("rawtypes")
public Class<? extends Endpoint> getEndpointType() {
return this.delegate.getClass();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -27,9 +27,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
* Adapter to expose {@link EnvironmentEndpoint} as an {@link MvcEndpoint}.
*
* @author Dave Syer
*/
public class EnvironmentMvcEndpoint extends GenericMvcEndpoint implements
public class EnvironmentMvcEndpoint extends EndpointMvcAdapter implements
EnvironmentAware {
private Environment environment;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2014 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.
@@ -38,8 +38,7 @@ import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ServletWrappingController;
/**
* {@link Endpoint} implementation to register the Jolokia infrastructure with the Boot
* management subsystem.
* {@link MvcEndpoint} to expose Jolokia.
*
* @author Christian Dupuis
*/
@@ -110,7 +109,8 @@ public class JolokiaMvcEndpoint implements MvcEndpoint, InitializingBean,
}
@Override
public Class<?> getEndpointType() {
@SuppressWarnings("rawtypes")
public Class<? extends Endpoint> getEndpointType() {
return null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -18,17 +18,19 @@ package org.springframework.boot.actuate.endpoint.mvc;
import java.util.Map;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.web.ErrorController;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
/**
* Special endpoint for handling "/error" path when the management servlet is in a child
* context. The regular {@link ErrorController} should be available there but because of
* the way the handler mappings are set up it will not be detected.
* Special {@link MvcEndpoint} for handling "/error" path when the management servlet is
* in a child context. The regular {@link ErrorController} should be available there but
* because of the way the handler mappings are set up it will not be detected.
*
* @author Dave Syer
*/
@@ -36,9 +38,11 @@ import org.springframework.web.context.request.RequestContextHolder;
public class ManagementErrorEndpoint implements MvcEndpoint {
private final ErrorController controller;
private String path;
private final String path;
public ManagementErrorEndpoint(String path, ErrorController controller) {
Assert.notNull(controller, "Controller must not be null");
this.path = path;
this.controller = controller;
}
@@ -61,7 +65,8 @@ public class ManagementErrorEndpoint implements MvcEndpoint {
}
@Override
public Class<?> getEndpointType() {
@SuppressWarnings("rawtypes")
public Class<? extends Endpoint> getEndpointType() {
return null;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -25,11 +25,13 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
* Adapter to expose {@link MetricsEndpoint} as an {@link MvcEndpoint}.
*
* @author Dave Syer
*/
public class MetricsMvcEndpoint extends GenericMvcEndpoint {
public class MetricsMvcEndpoint extends EndpointMvcAdapter {
private MetricsEndpoint delegate;
private final MetricsEndpoint delegate;
public MetricsMvcEndpoint(MetricsEndpoint delegate) {
super(delegate);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -29,10 +29,22 @@ import org.springframework.boot.actuate.endpoint.Endpoint;
*/
public interface MvcEndpoint {
/**
* Return the MVC path of the endpoint.
*/
String getPath();
/**
* Return if the endpoint exposes sensitive information.
*/
boolean isSensitive();
Class<?> getEndpointType();
/**
* Return the type of {@link Endpoint} exposed, or {@code null} if this
* {@link MvcEndpoint} exposes information that cannot be represented as a traditional
* {@link Endpoint}.
*/
@SuppressWarnings("rawtypes")
Class<? extends Endpoint> getEndpointType();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -60,7 +60,7 @@ public class MvcEndpoints implements ApplicationContextAware, InitializingBean {
Endpoint.class).values();
for (Endpoint<?> endpoint : delegates) {
if (isGenericEndpoint(endpoint.getClass())) {
this.endpoints.add(new GenericMvcEndpoint(endpoint));
this.endpoints.add(new EndpointMvcAdapter(endpoint));
}
}
}
@@ -85,4 +85,4 @@ public class MvcEndpoints implements ApplicationContextAware, InitializingBean {
&& !MvcEndpoint.class.isAssignableFrom(type);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -22,9 +22,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Adapter to expose {@link ShutdownEndpoint} as an {@link MvcEndpoint}.
*
* @author Dave Syer
*/
public class ShutdownMvcEndpoint extends GenericMvcEndpoint {
public class ShutdownMvcEndpoint extends EndpointMvcAdapter {
public ShutdownMvcEndpoint(ShutdownEndpoint delegate) {
super(delegate);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -17,7 +17,7 @@
package org.springframework.boot.actuate.health;
/**
* Default implementation of {@link HealthIndicator} that simply returns "ok".
* Default implementation of {@link HealthIndicator} that simply returns {@literal "ok"}.
*
* @author Dave Syer
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -49,7 +49,6 @@ public abstract class AbstractMetricExporter implements Exporter {
/**
* The earliest time for which data will be exported.
*
* @param earliestTimestamp the timestamp to set
*/
public void setEarliestTimestamp(Date earliestTimestamp) {
@@ -58,7 +57,6 @@ public abstract class AbstractMetricExporter implements Exporter {
/**
* Ignore timestamps (export all metrics).
*
* @param ignoreTimestamps the flag to set
*/
public void setIgnoreTimestamps(boolean ignoreTimestamps) {
@@ -96,7 +94,6 @@ public abstract class AbstractMetricExporter implements Exporter {
* prefixes). If the metrics to be exported partition into groups identified by a
* String, subclasses should override this method. Otherwise the default should be
* fine (iteration over all metrics).
*
* @return groups of metrics to iterate over (default singleton empty string)
*/
protected Iterable<String> groups() {
@@ -105,7 +102,6 @@ public abstract class AbstractMetricExporter implements Exporter {
/**
* Write the values associated with a group.
*
* @param group the group to write
* @param values the values to write
*/
@@ -113,10 +109,9 @@ public abstract class AbstractMetricExporter implements Exporter {
/**
* Get the next group of metrics to write.
*
* @param group the group name to write
* @return some metrics to write
*/
protected abstract Iterable<Metric<?>> next(String group);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -37,6 +37,7 @@ public class InMemoryMetricRepository implements MetricRepository, MultiMetricRe
PrefixMetricReader {
private SimpleInMemoryRepository<Metric<?>> metrics = new SimpleInMemoryRepository<Metric<?>>();
private Collection<String> groups = new HashSet<String>();
@Override

View File

@@ -43,6 +43,7 @@ public class RedisMultiMetricRepository implements MultiMetricRepository {
private static final String DEFAULT_METRICS_PREFIX = "spring.groups.";
private String prefix = DEFAULT_METRICS_PREFIX;
private String keys = this.prefix + "keys";
private BoundZSetOperations<String, String> zSetOperations;
@@ -57,7 +58,6 @@ public class RedisMultiMetricRepository implements MultiMetricRepository {
/**
* The prefix for all metrics keys.
*
* @param prefix the prefix to set for all metrics keys
*/
public void setPrefix(String prefix) {

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2012-2014 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.actuate.metrics.repository.redis;
import org.springframework.data.redis.connection.RedisConnectionFactory;
@@ -8,6 +24,8 @@ import org.springframework.data.redis.serializer.GenericToStringSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* General Utils for working with Redis.
*
* @author Luke Taylor
*/
class RedisUtils {

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2012-2014 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.actuate.metrics.rich;
import org.springframework.util.Assert;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -30,6 +30,7 @@ import com.codahale.metrics.Timer;
/**
* A {@link MetricWriter} that send data to a Codahale {@link MetricRegistry} based on a
* naming convention:
*
* <ul>
* <li>Updates to {@link #increment(Delta)} with names in "meter.*" are treated as
* {@link Meter} events</li>
@@ -49,7 +50,8 @@ public class CodahaleMetricWriter implements MetricWriter {
private final MetricRegistry registry;
/**
* @param registry
* Create a new {@link CodahaleMetricWriter} instance.
* @param registry the underlying metric registry
*/
public CodahaleMetricWriter(MetricRegistry registry) {
this.registry = registry;
@@ -94,17 +96,20 @@ public class CodahaleMetricWriter implements MetricWriter {
this.registry.remove(metricName);
}
/**
* Simple {@link Gauge} implementation to {@literal double} value.
*/
private static class SimpleGauge implements Gauge<Double> {
private final double gauge;
private final double value;
private SimpleGauge(double gauge) {
this.gauge = gauge;
private SimpleGauge(double value) {
this.value = value;
}
@Override
public Double getValue() {
return this.gauge;
return this.value;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -54,9 +54,7 @@ public class DefaultCounterService implements CounterService {
if (metricName.startsWith("counter") || metricName.startsWith("meter")) {
return metricName;
}
else {
return "counter." + metricName;
}
return "counter." + metricName;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -46,9 +46,7 @@ public class DefaultGaugeService implements GaugeService {
|| metricName.startsWith("timer")) {
return metricName;
}
else {
return "gauge." + metricName;
}
return "gauge." + metricName;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -81,6 +81,9 @@ public class ManagementServerProperties implements SecurityPrequisite {
return this.security;
}
/**
* Security configuration.
*/
public static class Security {
private boolean enabled = true;
@@ -116,11 +119,8 @@ public class ManagementServerProperties implements SecurityPrequisite {
}
private static Security maybeCreateSecurity() {
if (ClassUtils
.isPresent("org.springframework.security.core.Authentication", null)) {
return new Security();
}
return null;
return (ClassUtils.isPresent("org.springframework.security.core.Authentication",
null) ? new Security() : null);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -36,7 +36,6 @@ public interface ErrorController {
/**
* Extract a useful model of the error from the request attributes.
*
* @param attributes the request attributes
* @param trace flag to indicate that stack trace information should be included
* @return a model containing error messages and codes etc.

View File

@@ -260,7 +260,8 @@ public class EndpointWebMvcAutoConfigurationTests {
}
@Override
public Class<?> getEndpointType() {
@SuppressWarnings("rawtypes")
public Class<? extends Endpoint> getEndpointType() {
return Endpoint.class;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -146,7 +146,7 @@ public class EndpointHandlerMappingTests {
}
private static class TestMvcEndpoint extends GenericMvcEndpoint {
private static class TestMvcEndpoint extends EndpointMvcAdapter {
public TestMvcEndpoint(TestEndpoint delegate) {
super(delegate);
@@ -154,7 +154,7 @@ public class EndpointHandlerMappingTests {
}
private static class TestActionEndpoint extends GenericMvcEndpoint {
private static class TestActionEndpoint extends EndpointMvcAdapter {
public TestActionEndpoint(TestEndpoint delegate) {
super(delegate);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@@ -54,10 +54,9 @@ public class RedisServer implements TestRule {
try {
this.resource = obtainResource();
}
catch (Exception e) {
catch (Exception ex) {
maybeCleanup();
return failOrSkip(e);
return failOrSkip(ex);
}
return new Statement() {
@@ -82,17 +81,18 @@ public class RedisServer implements TestRule {
};
}
private Statement failOrSkip(Exception e) {
private Statement failOrSkip(Exception exception) {
String serversRequired = System.getenv(EXTERNAL_SERVERS_REQUIRED);
if ("true".equalsIgnoreCase(serversRequired)) {
logger.error(this.resourceDescription + " IS REQUIRED BUT NOT AVAILABLE", e);
logger.error(this.resourceDescription + " IS REQUIRED BUT NOT AVAILABLE",
exception);
fail(this.resourceDescription + " IS NOT AVAILABLE");
// Never reached, here to satisfy method signature
return null;
}
else {
logger.error(this.resourceDescription + " IS NOT AVAILABLE, SKIPPING TESTS",
e);
exception);
return new Statement() {
@Override