/** * Log the exception message at warn level and stack trace as trace level. * Return response status HttpStatus.NOT_FOUND */ @ExceptionHandler({NoSuchAppRegistrationException.class, NoSuchTaskDefinitionException.class, NoSuchTaskExecutionException.class, NoSuchJobExecutionException.class, NoSuchJobInstanceException.class, NoSuchJobException.class, NoSuchStepExecutionException.class, MetricsMvcEndpoint.NoSuchMetricException.class}) @ResponseStatus(HttpStatus.NOT_FOUND) @ResponseBody public VndErrors onNotFoundException(Exception e) { String logref = logWarnLevelExceptionMessage(e); if (logger.isTraceEnabled()) { logTraceLevelStrackTrace(e); } String msg = getExceptionMessage(e); return new VndErrors(logref, msg); }
@Parameters(name = "{0}") public static Object[] parameters() { return new Object[] { new Object[] { "actuator", HalJsonMvcEndpoint.class }, new Object[] { "autoconfig", AutoConfigurationReportEndpoint.class }, new Object[] { "beans", BeansEndpoint.class }, new Object[] { "configprops", ConfigurationPropertiesReportEndpoint.class }, new Object[] { "docs", DocsMvcEndpoint.class }, new Object[] { "dump", DumpEndpoint.class }, new Object[] { "env", EnvironmentMvcEndpoint.class }, new Object[] { "flyway", FlywayEndpoint.class }, new Object[] { "health", HealthMvcEndpoint.class }, new Object[] { "info", InfoEndpoint.class }, new Object[] { "jolokia", JolokiaMvcEndpoint.class }, new Object[] { "liquibase", LiquibaseEndpoint.class }, new Object[] { "logfile", LogFileMvcEndpoint.class }, new Object[] { "mappings", RequestMappingEndpoint.class }, new Object[] { "metrics", MetricsMvcEndpoint.class }, new Object[] { "shutdown", ShutdownEndpoint.class }, new Object[] { "trace", TraceEndpoint.class } }; }
/** * Log the exception message at warn level and stack trace as trace level. Return * response status HttpStatus.NOT_FOUND * * @param e one of the exceptions, {@link NoSuchStreamDefinitionException}, * {@link NoSuchAppRegistrationException}, {@link NoSuchTaskDefinitionException}, * {@link NoSuchTaskExecutionException}, {@link NoSuchJobExecutionException}, * {@link NoSuchJobInstanceException}, {@link NoSuchJobException}, * {@link NoSuchStepExecutionException}, * {@link MetricsMvcEndpoint.NoSuchMetricException}, {@link NoSuchAppException}, or * {@link NoSuchAppInstanceException} * @return the error response in JSON format with media type * application/vnd.error+json */ @ExceptionHandler({ NoSuchStreamDefinitionException.class, NoSuchAppRegistrationException.class, NoSuchTaskDefinitionException.class, NoSuchTaskExecutionException.class, NoSuchJobExecutionException.class, NoSuchJobInstanceException.class, NoSuchJobException.class, NoSuchStepExecutionException.class, MetricsMvcEndpoint.NoSuchMetricException.class, NoSuchAppException.class, NoSuchAppInstanceException.class, ApplicationDoesNotExistException.class }) @ResponseStatus(HttpStatus.NOT_FOUND) @ResponseBody public VndErrors onNotFoundException(Exception e) { String logref = logWarnLevelExceptionMessage(e); if (logger.isTraceEnabled()) { logTraceLevelStrackTrace(e); } String msg = getExceptionMessage(e); return new VndErrors(logref, msg); }
/** * Retrieve information about a specific counter. */ @RequestMapping(value = "/{name}", method = RequestMethod.GET) public FieldValueCounterResource display(@PathVariable("name") String name) { FieldValueCounter counter = repository.findOne(name); if (counter == null) { throw new MetricsMvcEndpoint.NoSuchMetricException(name); } return deepAssembler.toResource(counter); }
/** * Delete (reset) a specific counter. */ @RequestMapping(value = "/{name}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) protected void delete(@PathVariable("name") String name) { FieldValueCounter counter = repository.findOne(name); if (counter == null) { throw new MetricsMvcEndpoint.NoSuchMetricException(name); } repository.reset(name); }
/** * Find a given counter, taking care of name conversion between the Spring Boot domain and our domain. * @throws MetricsMvcEndpoint.NoSuchMetricException if the counter does not exist */ private Metric<Double> findCounter(@PathVariable("name") String name) { @SuppressWarnings("unchecked") Metric<Double> c = (Metric<Double>) metricRepository.findOne(COUNTER_PREFIX + name); if (c == null) { throw new MetricsMvcEndpoint.NoSuchMetricException(name); } return c; }
/** * Retrieve information about a specific aggregate counter. */ @RequestMapping(value = "/{name}", method = RequestMethod.GET) public AggregateCounterResource display(@PathVariable("name") String name) { AggregateCounter counter = repository.findOne(name); if (counter == null) { throw new MetricsMvcEndpoint.NoSuchMetricException(name); } return deepAssembler.toResource(counter); }
/** * Delete (reset) a specific counter. */ @RequestMapping(value = "/{name}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) protected void delete(@PathVariable("name") String name) { AggregateCounter counter = repository.findOne(name); if (counter == null) { throw new MetricsMvcEndpoint.NoSuchMetricException(name); } repository.reset(name); }
@Bean @ConditionalOnBean(MetricsEndpoint.class) @ConditionalOnEnabledEndpoint("metrics") public MetricsMvcEndpoint metricsMvcEndpoint(MetricsEndpoint delegate) { return new MetricsMvcEndpoint(delegate); }
@Test public void metricsEndpointDisabled() throws Exception { endpointDisabled("metrics", MetricsMvcEndpoint.class); }
@Test public void metricsEndpointEnabledOverride() throws Exception { endpointEnabledOverride("metrics", MetricsMvcEndpoint.class); }