You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2017/09/19 15:45:30 UTC
camel git commit: refactoring actuator endpoints for M4
Repository: camel
Updated Branches:
refs/heads/boot2 8033b30c9 -> 04a895274
refactoring actuator endpoints for M4
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/04a89527
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/04a89527
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/04a89527
Branch: refs/heads/boot2
Commit: 04a89527412b2916272337e1bf0a755ffa01bdfb
Parents: 8033b30
Author: Nicola Ferraro <ni...@gmail.com>
Authored: Tue Sep 19 17:45:25 2017 +0200
Committer: Nicola Ferraro <ni...@gmail.com>
Committed: Tue Sep 19 17:45:25 2017 +0200
----------------------------------------------------------------------
.../endpoint/CamelRouteControllerEndpoint.java | 27 +-
...outeControllerEndpointAutoConfiguration.java | 7 -
.../CamelRouteControllerMvcEndpoint.java | 79 ------
.../actuate/endpoint/CamelRoutesEndpoint.java | 187 ++++++++++----
.../CamelRoutesEndpointAutoConfiguration.java | 6 -
.../endpoint/CamelRoutesMvcEndpoint.java | 247 -------------------
.../endpoint/CamelRoutesEndpointTest.java | 2 +-
.../endpoint/CamelRoutesMvcEndpointTest.java | 68 -----
8 files changed, 156 insertions(+), 467 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/04a89527/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpoint.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpoint.java
index 357a8d0..16e21d0 100644
--- a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpoint.java
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpoint.java
@@ -16,36 +16,31 @@
*/
package org.apache.camel.spring.boot.actuate.endpoint;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Collectors;
-
import org.apache.camel.CamelContext;
import org.apache.camel.Route;
import org.apache.camel.spi.RouteController;
-import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
-import org.springframework.boot.actuate.endpoint.Endpoint;
-import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.actuate.endpoint.DefaultEnablement;
+import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
/**
* {@link Endpoint} to expose {@link RouteController} information.
*/
-@ConfigurationProperties(prefix = "endpoints." + CamelRouteControllerEndpoint.ENDPOINT_ID)
-public class CamelRouteControllerEndpoint extends AbstractEndpoint<List<String>> {
-
- public static final String ENDPOINT_ID = "camelroutecontroller";
+@Endpoint(id = "camelroutecontroller", defaultEnablement = DefaultEnablement.ENABLED)
+public class CamelRouteControllerEndpoint {
private CamelContext camelContext;
public CamelRouteControllerEndpoint(CamelContext camelContext) {
- super(ENDPOINT_ID);
this.camelContext = camelContext;
- // is enabled by default
- this.setEnabled(true);
}
- @Override
- public List<String> invoke() {
+ @ReadOperation
+ public List<String> getControlledRoutes() {
RouteController controller = camelContext.getRouteController();
if (controller != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/04a89527/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpointAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpointAutoConfiguration.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpointAutoConfiguration.java
index 2c09427..bf7918f 100644
--- a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpointAutoConfiguration.java
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpointAutoConfiguration.java
@@ -39,11 +39,4 @@ public class CamelRouteControllerEndpointAutoConfiguration {
public CamelRouteControllerEndpoint routeControllerEndpoint(CamelContext camelContext) {
return new CamelRouteControllerEndpoint(camelContext);
}
-
- @Bean
- @ConditionalOnClass(CamelContext.class)
- @ConditionalOnMissingBean
- public CamelRouteControllerMvcEndpoint routeControllerMvcEndpoint(CamelRouteControllerEndpoint delegate) {
- return new CamelRouteControllerMvcEndpoint(delegate);
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/04a89527/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerMvcEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerMvcEndpoint.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerMvcEndpoint.java
deleted file mode 100644
index cbde49e..0000000
--- a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerMvcEndpoint.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.camel.spring.boot.actuate.endpoint;
-
-import java.util.function.Supplier;
-
-import org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter;
-import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-/**
- * Adapter to expose {@link CamelRouteControllerEndpoint} as an {@link MvcEndpoint}.
- */
-@ConfigurationProperties(prefix = "endpoints." + CamelRouteControllerEndpoint.ENDPOINT_ID)
-public class CamelRouteControllerMvcEndpoint extends EndpointMvcAdapter {
-
- /**
- * Default path
- */
- public static final String PATH = "/camel/route-controller";
-
- private final CamelRouteControllerEndpoint delegate;
-
- public CamelRouteControllerMvcEndpoint(CamelRouteControllerEndpoint delegate) {
- super(delegate);
-
- this.setPath(PATH);
- this.delegate = delegate;
- }
-
- // ********************************************
- // Endpoints
- // ********************************************
-
- // ********************************************
- // Helpers
- // ********************************************
-
- private Object doIfEnabled(Supplier<Object> supplier) {
- if (!delegate.isEnabled()) {
- return getDisabledResponse();
- }
-
- return supplier.get();
- }
-
- @SuppressWarnings("serial")
- @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
- public static class GenericException extends RuntimeException {
- public GenericException(String message, Throwable cause) {
- super(message, cause);
-
- }
- }
-
- @SuppressWarnings("serial")
- @ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "No such route")
- public static class NoSuchRouteException extends RuntimeException {
- public NoSuchRouteException(String message) {
- super(message);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/04a89527/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
index af867ae..cf95354 100644
--- a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -16,48 +16,86 @@
*/
package org.apache.camel.spring.boot.actuate.endpoint;
-import java.util.Date;
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.apache.camel.CamelContext;
import org.apache.camel.Route;
+import org.apache.camel.RuntimeCamelException;
import org.apache.camel.StatefulService;
import org.apache.camel.api.management.mbean.ManagedRouteMBean;
import org.apache.camel.spi.RouteError;
-import org.apache.camel.spring.boot.actuate.endpoint.CamelRoutesEndpoint.RouteEndpointInfo;
-import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
-import org.springframework.boot.actuate.endpoint.Endpoint;
-import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.actuate.endpoint.DefaultEnablement;
+import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
+import org.springframework.boot.actuate.endpoint.annotation.Selector;
+import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
/**
* {@link Endpoint} to expose {@link org.apache.camel.Route} information.
*/
-@ConfigurationProperties(prefix = "endpoints." + CamelRoutesEndpoint.ENDPOINT_ID)
-public class CamelRoutesEndpoint extends AbstractEndpoint<List<RouteEndpointInfo>> {
-
- public static final String ENDPOINT_ID = "camelroutes";
+@Endpoint(id = "camelroutes", defaultEnablement = DefaultEnablement.ENABLED)
+public class CamelRoutesEndpoint {
private CamelContext camelContext;
public CamelRoutesEndpoint(CamelContext camelContext) {
- super(ENDPOINT_ID);
this.camelContext = camelContext;
- // is enabled by default
- this.setEnabled(true);
}
- @Override
- public List<RouteEndpointInfo> invoke() {
+ @ReadOperation
+ public List<RouteEndpointInfo> readRoutes() {
return getRoutesInfo();
}
- public RouteEndpointInfo getRouteInfo(String id) {
+ @ReadOperation
+ public Object doReadAction(@Selector String id, @Selector ReadAction action) {
+ switch (action) {
+ case DETAIL:
+ return getRouteDetailsInfo(id);
+ case INFO:
+ return getRouteInfo(id);
+ default:
+ throw new IllegalArgumentException("Unsupported read action " + action);
+ }
+ }
+
+ @WriteOperation
+ public void doWriteAction(@Selector String id, @Selector WriteAction action, TimeInfo timeInfo) {
+ switch (action) {
+ case STOP:
+ stopRoute(
+ id,
+ Optional.ofNullable(timeInfo).flatMap(ti -> Optional.ofNullable(ti.getTimeout())),
+ Optional.of(TimeUnit.SECONDS),
+ Optional.ofNullable(timeInfo).flatMap(ti -> Optional.ofNullable(ti.getAbortAfterTimeout())));
+ break;
+ case START:
+ startRoute(id);
+ break;
+ case RESET:
+ resetRoute(id);
+ break;
+ case SUSPEND:
+ suspendRoute(id,
+ Optional.ofNullable(timeInfo).flatMap(ti -> Optional.ofNullable(ti.getTimeout())),
+ Optional.of(TimeUnit.SECONDS));
+ break;
+ case RESUME:
+ resumeRoute(id);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported write action " + action);
+ }
+ }
+
+ private RouteEndpointInfo getRouteInfo(String id) {
Route route = camelContext.getRoute(id);
if (route != null) {
return new RouteEndpointInfo(route);
@@ -72,7 +110,7 @@ public class CamelRoutesEndpoint extends AbstractEndpoint<List<RouteEndpointInfo
.collect(Collectors.toList());
}
- public RouteDetailsEndpointInfo getRouteDetailsInfo(String id) {
+ private RouteDetailsEndpointInfo getRouteDetailsInfo(String id) {
Route route = camelContext.getRoute(id);
if (route != null) {
return new RouteDetailsEndpointInfo(camelContext, route);
@@ -81,35 +119,55 @@ public class CamelRoutesEndpoint extends AbstractEndpoint<List<RouteEndpointInfo
return null;
}
- public void startRoute(String id) throws Exception {
- camelContext.getRouteController().startRoute(id);
+ private void startRoute(String id) {
+ try {
+ camelContext.getRouteController().startRoute(id);
+ } catch (Exception e) {
+ throw new RuntimeCamelException(e);
+ }
}
- public void resetRoute(String id) throws Exception {
- ManagedRouteMBean managedRouteMBean = camelContext.getManagedRoute(id, ManagedRouteMBean.class);
- if (managedRouteMBean != null) {
- managedRouteMBean.reset(true);
- }
+ private void resetRoute(String id) {
+ try {
+ ManagedRouteMBean managedRouteMBean = camelContext.getManagedRoute(id, ManagedRouteMBean.class);
+ if (managedRouteMBean != null) {
+ managedRouteMBean.reset(true);
+ }
+ } catch (Exception e) {
+ throw new RuntimeCamelException(e);
+ }
}
- public void stopRoute(String id, Optional<Long> timeout, Optional<TimeUnit> timeUnit, Optional<Boolean> abortAfterTimeout) throws Exception {
- if (timeout.isPresent()) {
- camelContext.getRouteController().stopRoute(id, timeout.get(), timeUnit.orElse(TimeUnit.SECONDS), abortAfterTimeout.orElse(Boolean.TRUE));
- } else {
- camelContext.getRouteController().stopRoute(id);
+ private void stopRoute(String id, Optional<Long> timeout, Optional<TimeUnit> timeUnit, Optional<Boolean> abortAfterTimeout) {
+ try {
+ if (timeout.isPresent()) {
+ camelContext.getRouteController().stopRoute(id, timeout.get(), timeUnit.orElse(TimeUnit.SECONDS), abortAfterTimeout.orElse(Boolean.TRUE));
+ } else {
+ camelContext.getRouteController().stopRoute(id);
+ }
+ } catch (Exception e) {
+ throw new RuntimeCamelException(e);
}
}
- public void suspendRoute(String id, Optional<Long> timeout, Optional<TimeUnit> timeUnit) throws Exception {
- if (timeout.isPresent()) {
- camelContext.getRouteController().suspendRoute(id, timeout.get(), timeUnit.orElse(TimeUnit.SECONDS));
- } else {
- camelContext.getRouteController().suspendRoute(id);
+ private void suspendRoute(String id, Optional<Long> timeout, Optional<TimeUnit> timeUnit) {
+ try {
+ if (timeout.isPresent()) {
+ camelContext.getRouteController().suspendRoute(id, timeout.get(), timeUnit.orElse(TimeUnit.SECONDS));
+ } else {
+ camelContext.getRouteController().suspendRoute(id);
+ }
+ } catch (Exception e) {
+ throw new RuntimeCamelException(e);
}
}
- public void resumeRoute(String id) throws Exception {
- camelContext.getRouteController().resumeRoute(id);
+ private void resumeRoute(String id) {
+ try {
+ camelContext.getRouteController().resumeRoute(id);
+ } catch (Exception e) {
+ throw new RuntimeCamelException(e);
+ }
}
/**
@@ -374,4 +432,47 @@ public class CamelRoutesEndpoint extends AbstractEndpoint<List<RouteEndpointInfo
}
}
+ /**
+ * List of write actions available for the endpoint
+ */
+ public enum WriteAction {
+ STOP,
+ START,
+ RESET,
+ SUSPEND,
+ RESUME
+ }
+
+ /*
+ * List of read actions available for the endpoint
+ */
+ public enum ReadAction {
+ DETAIL,
+ INFO
+ }
+
+ /**
+ * Optional time information for the actions
+ */
+ public static class TimeInfo {
+ private Long timeout;
+ private Boolean abortAfterTimeout;
+
+ public Long getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(Long timeout) {
+ this.timeout = timeout;
+ }
+
+ public Boolean getAbortAfterTimeout() {
+ return abortAfterTimeout;
+ }
+
+ public void setAbortAfterTimeout(Boolean abortAfterTimeout) {
+ this.abortAfterTimeout = abortAfterTimeout;
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/04a89527/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java
index 2425359..26199cf 100644
--- a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java
+++ b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointAutoConfiguration.java
@@ -40,10 +40,4 @@ public class CamelRoutesEndpointAutoConfiguration {
return new CamelRoutesEndpoint(camelContext);
}
- @Bean
- @ConditionalOnClass(CamelContext.class)
- @ConditionalOnMissingBean
- public CamelRoutesMvcEndpoint camelMvcEndpoint(CamelRoutesEndpoint delegate) {
- return new CamelRoutesMvcEndpoint(delegate);
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/04a89527/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpoint.java b/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpoint.java
deleted file mode 100644
index cf4836e..0000000
--- a/components/camel-spring-boot2/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpoint.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.camel.spring.boot.actuate.endpoint;
-
-import java.util.Optional;
-import java.util.concurrent.TimeUnit;
-import java.util.function.Supplier;
-
-import org.springframework.boot.actuate.endpoint.mvc.ActuatorMediaTypes;
-import org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter;
-import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestAttribute;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-/**
- * Adapter to expose {@link CamelRoutesEndpoint} as an {@link MvcEndpoint}.
- */
-@ConfigurationProperties(prefix = "endpoints." + CamelRoutesEndpoint.ENDPOINT_ID)
-public class CamelRoutesMvcEndpoint extends EndpointMvcAdapter {
-
- /**
- * Default path
- */
- public static final String PATH = "/camel/routes";
-
- private final CamelRoutesEndpoint delegate;
-
- public CamelRoutesMvcEndpoint(CamelRoutesEndpoint delegate) {
- super(delegate);
-
- this.setPath(PATH);
- this.delegate = delegate;
- }
-
- // ********************************************
- // Endpoints
- // ********************************************
-
- @ResponseBody
- @GetMapping(
- value = "/{id}/detail",
- produces = {
- ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
- MediaType.APPLICATION_JSON_VALUE
- }
- )
- public Object detail(
- @PathVariable String id) {
-
- return doIfEnabled(() -> {
- Object result = delegate.getRouteDetailsInfo(id);
- if (result == null) {
- throw new NoSuchRouteException("No such route " + id);
- }
-
- return result;
- });
- }
-
- @ResponseBody
- @GetMapping(
- value = "/{id}/info",
- produces = {
- ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
- MediaType.APPLICATION_JSON_VALUE
- }
- )
- public Object info(
- @PathVariable String id) {
-
- return doIfEnabled(() -> {
- Object result = delegate.getRouteInfo(id);
- if (result == null) {
- throw new NoSuchRouteException("No such route " + id);
- }
-
- return result;
- });
- }
-
- @ResponseBody
- @PostMapping(
- value = "/{id}/stop",
- produces = {
- ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
- MediaType.APPLICATION_JSON_VALUE
- }
- )
- public Object stop(
- @PathVariable String id,
- @RequestAttribute(required = false) Long timeout,
- @RequestAttribute(required = false) Boolean abortAfterTimeout) {
-
- return doIfEnabled(() -> {
- try {
- delegate.stopRoute(
- id,
- Optional.ofNullable(timeout),
- Optional.of(TimeUnit.SECONDS),
- Optional.ofNullable(abortAfterTimeout)
- );
- } catch (Exception e) {
- throw new GenericException("Error stopping route " + id, e);
- }
-
- return ResponseEntity.ok().build();
- });
- }
-
- @ResponseBody
- @PostMapping(
- value = "/{id}/start",
- produces = {
- ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
- MediaType.APPLICATION_JSON_VALUE
- }
- )
- public Object start(
- @PathVariable String id) {
-
- return doIfEnabled(() -> {
- try {
- delegate.startRoute(id);
- } catch (Exception e) {
- throw new GenericException("Error starting route " + id, e);
- }
-
- return ResponseEntity.ok().build();
- });
- }
-
- @ResponseBody
- @PostMapping(value = "/{id}/reset", produces = {ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE})
- public Object reset(@PathVariable String id) {
-
- return doIfEnabled(() -> {
- try {
- delegate.resetRoute(id);
- } catch (Exception e) {
- throw new GenericException("Error resetting route stats " + id, e);
- }
-
- return ResponseEntity.ok().build();
- });
- }
-
-
- @ResponseBody
- @PostMapping(
- value = "/{id}/suspend",
- produces = {
- ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
- MediaType.APPLICATION_JSON_VALUE
- }
- )
- public Object suspend(
- @PathVariable String id,
- @RequestAttribute(required = false) Long timeout) {
-
- return doIfEnabled(() -> {
- try {
- delegate.suspendRoute(
- id,
- Optional.ofNullable(timeout),
- Optional.of(TimeUnit.SECONDS)
- );
- } catch (Exception e) {
- throw new GenericException("Error suspending route " + id, e);
- }
-
- return ResponseEntity.ok().build();
- });
- }
-
- @ResponseBody
- @PostMapping(
- value = "/{id}/resume",
- produces = {
- ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
- MediaType.APPLICATION_JSON_VALUE
- }
- )
- public Object resume(
- @PathVariable String id) {
-
- return doIfEnabled(() -> {
- try {
- delegate.resumeRoute(id);
- } catch (Exception e) {
- throw new GenericException("Error resuming route " + id, e);
- }
-
- return ResponseEntity.ok().build();
- });
- }
-
- // ********************************************
- // Helpers
- // ********************************************
-
- private Object doIfEnabled(Supplier<Object> supplier) {
- if (!delegate.isEnabled()) {
- return getDisabledResponse();
- }
-
- return supplier.get();
- }
-
- @SuppressWarnings("serial")
- @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
- public static class GenericException extends RuntimeException {
- public GenericException(String message, Throwable cause) {
- super(message, cause);
-
- }
- }
-
- @SuppressWarnings("serial")
- @ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "No such route")
- public static class NoSuchRouteException extends RuntimeException {
- public NoSuchRouteException(String message) {
- super(message);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/04a89527/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointTest.java
index ea6e8cb..20118be 100644
--- a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointTest.java
+++ b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpointTest.java
@@ -49,7 +49,7 @@ public class CamelRoutesEndpointTest extends Assert {
@Test
public void testRoutesEndpoint() throws Exception {
- List<RouteEndpointInfo> routes = endpoint.invoke();
+ List<RouteEndpointInfo> routes = endpoint.readRoutes();
assertFalse(routes.isEmpty());
assertEquals(routes.size(), camelContext.getRoutes().size());
http://git-wip-us.apache.org/repos/asf/camel/blob/04a89527/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpointTest.java b/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpointTest.java
deleted file mode 100644
index c0b1e45..0000000
--- a/components/camel-spring-boot2/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpointTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.camel.spring.boot.actuate.endpoint;
-
-import java.util.List;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.spring.boot.CamelAutoConfiguration;
-import org.apache.camel.spring.boot.actuate.endpoint.CamelRoutesEndpoint.RouteDetailsEndpointInfo;
-import org.apache.camel.spring.boot.actuate.endpoint.CamelRoutesEndpoint.RouteEndpointInfo;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-/**
- * Test for the {@link CamelRoutesEndpoint} actuator endpoint.
- */
-@DirtiesContext
-@RunWith(SpringRunner.class)
-@EnableAutoConfiguration
-@SpringBootApplication
-@SpringBootTest(classes = {CamelAutoConfiguration.class, CamelRoutesEndpointAutoConfiguration.class, ActuatorTestRoute.class})
-public class CamelRoutesMvcEndpointTest extends Assert {
-
- @Autowired
- CamelRoutesMvcEndpoint endpoint;
-
- @Autowired
- CamelContext camelContext;
-
- @Test
- public void testRoutesEndpoint() throws Exception {
- List<RouteEndpointInfo> routes = (List<RouteEndpointInfo>)endpoint.invoke();
-
- assertFalse(routes.isEmpty());
- assertEquals(routes.size(), camelContext.getRoutes().size());
- assertTrue(routes.stream().anyMatch(r -> "foo-route".equals(r.getId())));
- }
-
- @Test
- public void testMvcRoutesEndpoint() throws Exception {
- Object result = endpoint.detail("foo-route");
-
- assertTrue(result instanceof RouteDetailsEndpointInfo);
- assertEquals("foo-route", ((RouteDetailsEndpointInfo)result).getId());
- }
-
-}