[ 
https://issues.apache.org/jira/browse/CAMEL-18923?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17677062#comment-17677062
 ] 

Raymond edited comment on CAMEL-18923 at 1/15/23 4:48 PM:
----------------------------------------------------------

Yes, it's a 1..n relation. I reported this as a bug, as currently the 'route' 
API is the only one available to manage it. A separate API to handle route 
configurations or other ways to handle it would be nice.

Here shortly how I use a route configuration:

1) I have one integration consists of multiple routes.
2) All the routes have the same errorhandler (configured in a 
routeConfiguration)

These routes and routeconfiguration are configured by users. When either a 
route or routeconfiguration is changed I like to update them all. As a 
routeconfiguration is used by routes, I load or update the routeConfiguration, 
before attaching (by loading or updating) other routes.

The current routeLoader has the following methods:
 - routerloader.loader(resource)
 - routelouader.update(resource)

There is (as far as I know) no:
 - Routeloader.remove(Resource resource);
 - Routeloader.loadOrUpdate(Resource resource);
 - Routeloader.loadOrUpdate(String route);
 - Routeloader.loadOrUpdate(List<string> routes);
 - Routeloader.loadOrUpdate(String routeConfiguration, boolean overwrite);

or (when there would be a specific routeconfiguration api):

context.getRouteConfiguration(routeConfigurationId);

context.addRouteConfigurationsSize();

context.getRouteConfiguration(routeConfigurationId);
context.removeRouteConfiguration(routeConfigurationId);

context.getRouteConfiguration(routeConfigurationId);

context.getRoutesForRouteConfiguration(routeConfigurationId)

 

I also attached the Class I now use to load a group of routes (a 
flow/integraiton). The above example methods and this sample class can be used 
as inspiration.

For now, what I could do is don't use the update functionality, but something 
like this:

1. If a route exists then remove it (including routeConfiguration).
2. Create a list of resources for routes and routetemplates.
3. Load the routeConfiguration
4. Load the list of resources

However, as I do it now I load resources separately, also because this way I 
can create a JSON report if one of the routes flows, so that it is clear which 
route doesn't load.

Thanks, so far.

 

 

 


was (Author: skin27):
Yes, it's a 1..n relation. I reported this as a bug, as currently only the 
'route' API are the only one available. A separate API to handle route 
configurations or other ways to handle it would be nice.

Here shortly how I use the route configuration:

1) I have one integration consists of multiple routes.
2) All the routes have the same errorhandler

These routes and routeconfiguration are configured by users. When either a 
route or routeconfiguration is changed I like to update them all. As a 
routeconfiguration is used by routes, I load or update the routeConfiguration, 
before attaching (by loading or updating) other routes.

The current routeLoader has the following methods:

- routerloader.loader(resource)
- routelouader.update(resource)

There is (as far as I know) no:

- Routeloader.remove(Resource resource);
- Routeloader.loadOrUpdate(Resource resource);
- Routeloader.loadOrUpdate(String route);
- Routeloader.loadOrUpdate(List<string> routes);
- Routeloader.loadOrUpdate(String routeConfiguration, boolean overwrite);

or (when having a specific routeconfiguration api):

context.getRouteConfiguration(routeConfigurationId);

context.addRouteConfigurationsSize();

context.getRouteConfiguration(routeConfigurationId);
context.removeRouteConfiguration(routeConfigurationId);

context.getRouteConfiguration(routeConfigurationId);

context.getRoutesForRouteConfiguration(routeConfigurationId)

 

I also attached the Class I now use to load a group of routes (a flow). The 
above example methods and this sample class can be used as inspiration.

For now, what I could do is don't use the update functionality, but something 
like this:

1. If route exists than remove it (including routeConfiguration).
2. Create a list of resources for routes and routetemplates.
3. Load the routeConfiguration
4. Load the list of resources

However as I do it now I load resources seperately, also because this way I can 
create a JSON report if one of the routes flows, so that's it's clear which 
route doesn't load.

Thanks, so far.







 

 

 

> Cannot update a routeconfiguration with a routeloader
> -----------------------------------------------------
>
>                 Key: CAMEL-18923
>                 URL: https://issues.apache.org/jira/browse/CAMEL-18923
>             Project: Camel
>          Issue Type: Improvement
>          Components: came-core
>    Affects Versions: 3.20.1
>         Environment: openjdk version "11.0.17" 2022-10-18
> OpenJDK Runtime Environment Temurin-11.0.17+8 (build 11.0.17+8)
> OpenJDK 64-Bit Server VM Temurin-11.0.17+8 (build 11.0.17+8, mixed mode)
>            Reporter: Raymond
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 3.21.0, 4.0
>
>         Attachments: FlowLoader.java, routeloader-with-routeconfiguration.7z, 
> routeloader-with-routeconfiguration.zip
>
>
> I load a routeConfiguration with the routeloader. This works from 3.20.0, but 
> I can't get any info about it and cannot update the route after it is loaded.
> I use the following code:
>  
> {code:java}
> // 1. Start Camel
> context = new DefaultCamelContext();
> context.start();
> //2. Load route template
> context.addRoutes((RouteBuilder) new MyTemplate());
> //3. Create route template resource from string
> String content = "<templatedRoutes id=\"camel\" 
> xmlns=\"http://camel.apache.org/schema/spring\";>\n" +
>         "    <!-- create two routes from the template -->\n" +
>         "    <templatedRoute routeTemplateRef=\"myTemplate\">\n" +
>         "        <parameter name=\"name\" value=\"Manually Loaded 
> Tempate\"/>\n" +
>         "        <parameter name=\"greeting\" value=\"Hello\"/>\n" +
>         "    </templatedRoute>\n" +
>         "</templatedRoutes>";
> Resource resource = ResourceHelper.fromString("in-memory.xml", content);
> //4. Load resource
> ExtendedCamelContext extendedCamelContext = 
> context.adapt(ExtendedCamelContext.class);
> RoutesLoader loader = extendedCamelContext.getRoutesLoader();
> loader.loadRoutes(resource);
> //5. check the size of all routes
> LOG.info("RoutesSize = " + context.getRoutesSize());
> //6. Create route configuration resource from string
> content = "<routeConfiguration id=\"myRouteConfig\">\n" +
>         "\t<onException>\n" +
>         "\t   <exception>java.lang.Exception</exception>\n" +
>         "\t   <redeliveryPolicy maximumRedeliveries=\"0\" 
> redeliveryDelay=\"5000\"/>\n" +
>         "\t   <setExchangePattern pattern=\"InOut\"/>\n" +
>         "\t</onException>\n" +
>         "</routeConfiguration>";
> resource = ResourceHelper.fromString("in-memory.xml", content);
> //7. Load resource
> loader.loadRoutes(resource);
> //8. Print something of hte status of the routeconfiguraton
> LOG.info("RoutesSize = " + context.getRoutesSize());
> LOG.info("RouteConfiguration Status = " + 
> context.getRouteController().getRouteStatus("myRouteConfig"));
> Route route = context.getRoute("myRouteConfig");
> if(route != null){
>     LOG.info("RouteConfiguration Uptime = " + route.getUptimeMillis());
> }else{
>     LOG.info("RouteConfiguration is null");
> }
> //9. Update resource
> loader.updateRoutes(resource);
> route = context.getRoute("myRouteConfig");
> if(route != null){
>     LOG.info("2. RouteConfiguration Uptime = " + route.getUptimeMillis());
> }else{
>     LOG.info("2. RouteConfiguration is null");
> } {code}
> Log using Apache Camel 3.19.0
> {code:java}
> [INFO] Starting Camel ...
> 16:27:05.793 [org.apache.camel.example.MyApplication.main()] INFO  
> o.a.c.i.engine.AbstractCamelContext - Apache Camel 3.19.0 (camel-1) is 
> starting
> 16:27:05.829 [org.apache.camel.example.MyApplication.main()] INFO  
> o.a.c.i.engine.AbstractCamelContext - Routes startup (started:0)
> 16:27:05.829 [org.apache.camel.example.MyApplication.main()] INFO  
> o.a.c.i.engine.AbstractCamelContext - Apache Camel 3.19.0 (camel-1) started 
> in 429ms (build:216ms init:190ms start:23ms)
> 16:27:06.413 [org.apache.camel.example.MyApplication.main()] INFO  
> o.apache.camel.example.MyApplication - RoutesSize = 1
> 16:27:06.439 [org.apache.camel.example.MyApplication.main()] INFO  
> o.apache.camel.example.MyApplication - RoutesSize = 1
> 16:27:06.440 [org.apache.camel.example.MyApplication.main()] INFO  
> o.apache.camel.example.MyApplication - RouteConfiguration Status = null
> 16:27:06.440 [org.apache.camel.example.MyApplication.main()] INFO  
> o.apache.camel.example.MyApplication - RouteConfiguration is null
> 16:27:06.442 [org.apache.camel.example.MyApplication.main()] INFO  
> o.apache.camel.example.MyApplication - RouteConfiguration is null
> 16:27:07.423 [Camel (camel-1) thread #1 - timer://Manually Loaded Tempate] 
> INFO  route2 - Hello Manually Loaded Tempate
> 16:27:10.413 [Camel (camel-1) thread #1 - timer://Manually Loaded Tempate] 
> INFO  route2 - Hello Manually Loaded Tempate {code}
> Log using Apache Camel 3.20.0 (Same code)
>  
> {code:java}
> [INFO] Starting Camel ...
> 16:29:52.895 [org.apache.camel.example.MyApplication.main()] INFO  
> o.a.c.i.engine.AbstractCamelContext - Apache Camel 3.20.0 (camel-1) is 
> starting
> 16:29:52.913 [org.apache.camel.example.MyApplication.main()] INFO  
> o.a.c.i.engine.AbstractCamelContext - Routes startup (started:0)
> 16:29:52.913 [org.apache.camel.example.MyApplication.main()] INFO  
> o.a.c.i.engine.AbstractCamelContext - Apache Camel 3.20.0 (camel-1) started 
> in 416ms (build:250ms init:156ms start:10ms)
> 16:29:53.121 [org.apache.camel.example.MyApplication.main()] INFO  
> o.apache.camel.example.MyApplication - RoutesSize = 0
> 16:29:53.154 [org.apache.camel.example.MyApplication.main()] INFO  
> o.apache.camel.example.MyApplication - RoutesSize = 0
> 16:29:53.155 [org.apache.camel.example.MyApplication.main()] INFO  
> o.apache.camel.example.MyApplication - RouteConfiguration Status = null
> 16:29:53.157 [org.apache.camel.example.MyApplication.main()] INFO  
> o.apache.camel.example.MyApplication - RouteConfiguration is null
> [ERROR] *************************************
> [ERROR] Error occurred while running main from: 
> org.apache.camel.example.MyApplication
> [ERROR]
> java.lang.reflect.InvocationTargetException
>     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
>     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke 
> (NativeMethodAccessorImpl.java:62)
>     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke 
> (DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke (Method.java:566)
>     at org.apache.camel.maven.RunMojo$1.run (RunMojo.java:412)
>     at java.lang.Thread.run (Thread.java:829)
> Caused by: java.lang.IllegalArgumentException: Route configuration already 
> exists with id: myRouteConfig
>     at org.apache.camel.impl.DefaultModel.addRouteConfiguration 
> (DefaultModel.java:139)
>     at org.apache.camel.impl.DefaultCamelContext.addRouteConfiguration 
> (DefaultCamelContext.java:311)
>     at org.apache.camel.dsl.xml.io.XmlRoutesBuilderLoader$1.addConfigurations 
> (XmlRoutesBuilderLoader.java:92)
>     at java.util.Optional.ifPresent (Optional.java:183)
>     at org.apache.camel.dsl.xml.io.XmlRoutesBuilderLoader$1.configuration 
> (XmlRoutesBuilderLoader.java:76)
>     at 
> org.apache.camel.builder.RouteConfigurationBuilder.updateRouteConfigurationsToCamelContext
>  (RouteConfigurationBuilder.java:88)
>     at org.apache.camel.impl.engine.DefaultRoutesLoader.updateRoutes 
> (DefaultRoutesLoader.java:186)
>     at org.apache.camel.spi.RoutesLoader.updateRoutes (RoutesLoader.java:98)
>     at org.apache.camel.example.MyApplication.main (MyApplication.java:79)
>     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
>     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke 
> (NativeMethodAccessorImpl.java:62)
>     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke 
> (DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke (Method.java:566)
>     at org.apache.camel.maven.RunMojo$1.run (RunMojo.java:412)
>     at java.lang.Thread.run (Thread.java:829) {code}
> I added an example in the attachement.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to