This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 9e773e0 CAMEL-11669: Routes : add 'group' 9e773e0 is described below commit 9e773e0e024fdf49005f47b50a26ae3fb9d7428e Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Tue Apr 17 12:52:17 2018 +0200 CAMEL-11669: Routes : add 'group' --- .../src/main/java/org/apache/camel/Route.java | 7 ++++ .../java/org/apache/camel/impl/DefaultRoute.java | 4 ++ .../apache/camel/model/ProcessorDefinition.java | 18 +++++++++ .../org/apache/camel/model/RouteDefinition.java | 11 ++++++ .../org/apache/camel/model/RouteGroupTest.java | 45 ++++++++++++++++++++++ .../org/apache/camel/model/XmlRouteGroupTest.java | 30 +++++++++++++++ .../org/apache/camel/model/routeGroup.xml | 29 ++++++++++++++ 7 files changed, 144 insertions(+) diff --git a/camel-core/src/main/java/org/apache/camel/Route.java b/camel-core/src/main/java/org/apache/camel/Route.java index 48c6445..7dd5af3 100644 --- a/camel-core/src/main/java/org/apache/camel/Route.java +++ b/camel-core/src/main/java/org/apache/camel/Route.java @@ -46,6 +46,13 @@ public interface Route extends EndpointAware { String getId(); /** + * Gets the route group + * + * @return the route group + */ + String getGroup(); + + /** * Gets the uptime in a human readable format * * @return the uptime in days/hours/minutes diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java index d67c8cc..b63093c 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java +++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java @@ -67,6 +67,10 @@ public abstract class DefaultRoute extends ServiceSupport implements Route { return (String) properties.get(Route.ID_PROPERTY); } + public String getGroup() { + return (String) properties.get(Route.GROUP_PROPERTY); + } + public String getUptime() { long delta = getUptimeMillis(); if (delta == 0) { diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java index 86e705b..c5885e4 100644 --- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java @@ -1095,6 +1095,24 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type> } /** + * Set the route group for this route. + * + * @param group the route group + * @return the builder + */ + @SuppressWarnings("unchecked") + public Type routeGroup(String group) { + ProcessorDefinition<?> def = this; + + RouteDefinition route = ProcessorDefinitionHelper.getRoute(def); + if (route != null) { + route.setGroup(group); + } + + return (Type) this; + } + + /** * Set the route description for this route * * @param description the route description diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java index 9e17ac4..3f7a32c 100644 --- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java @@ -376,6 +376,17 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> { } /** + * Set the route group for this route + * + * @param group the route group + * @return the builder + */ + public RouteDefinition routeGroup(String group) { + setGroup(group); + return this; + } + + /** * Set the route id for this route * * @param id the route id diff --git a/camel-core/src/test/java/org/apache/camel/model/RouteGroupTest.java b/camel-core/src/test/java/org/apache/camel/model/RouteGroupTest.java new file mode 100644 index 0000000..67bbf2f --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/model/RouteGroupTest.java @@ -0,0 +1,45 @@ +/* + * 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.model; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Route; +import org.apache.camel.builder.RouteBuilder; + +public class RouteGroupTest extends ContextTestSupport { + + public void testRouteGroup() { + RouteDefinition definition = context.getRouteDefinition("route-id"); + Route route = context.getRoute("route-id"); + + assertEquals("route-group", definition.getGroup()); + assertEquals("route-group", route.getGroup()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .routeId("route-id") + .routeGroup("route-group") + .to("mock:output"); + } + }; + } +} diff --git a/camel-core/src/test/java/org/apache/camel/model/XmlRouteGroupTest.java b/camel-core/src/test/java/org/apache/camel/model/XmlRouteGroupTest.java new file mode 100644 index 0000000..0393f80 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/model/XmlRouteGroupTest.java @@ -0,0 +1,30 @@ +/* + * 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.model; + +import javax.xml.bind.JAXBException; + +public class XmlRouteGroupTest extends XmlTestSupport { + + public void testXmlRouteGroup() throws JAXBException { + RouteContainer context = assertParseAsJaxb("routeGroup.xml"); + RouteDefinition route = assertOneElement(context.getRoutes()); + + assertEquals("route-id", route.getId()); + assertEquals("route-group", route.getGroup()); + } +} diff --git a/camel-core/src/test/resources/org/apache/camel/model/routeGroup.xml b/camel-core/src/test/resources/org/apache/camel/model/routeGroup.xml new file mode 100644 index 0000000..e05e5fa --- /dev/null +++ b/camel-core/src/test/resources/org/apache/camel/model/routeGroup.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> +<routes xmlns="http://camel.apache.org/schema/spring" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <!-- + xsi:schemaLocation="http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd" + --> + + <route id="route-id" group="route-group"> + <from uri="seda:a"/> + <to uri="seda:b"/> + </route> +</routes> -- To stop receiving notification emails like this one, please contact lburgazz...@apache.org.