This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 5632c9a5529 CAMEL-17975: camel-core - Route watch reload will not
start routes again if previous failed
5632c9a5529 is described below
commit 5632c9a5529a91dae1d22f073fe04a52c9ff5324
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Apr 16 21:20:03 2022 +0200
CAMEL-17975: camel-core - Route watch reload will not start routes again if
previous failed
---
.../camel/support/RouteWatcherReloadStrategy.java | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
b/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
index 201c2872e85..d806ff3c16a 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
@@ -59,6 +59,7 @@ public class RouteWatcherReloadStrategy extends
FileWatcherResourceReloadStrateg
private String pattern;
private boolean removeAllRoutes = true;
+ private final List<Resource> previousSources = new ArrayList<>();
public RouteWatcherReloadStrategy() {
}
@@ -165,6 +166,17 @@ public class RouteWatcherReloadStrategy extends
FileWatcherResourceReloadStrateg
// remember all existing resources
List<Resource> sources = new ArrayList<>();
+ if (!previousSources.isEmpty()) {
+ // last update failed, so we need to update all previous sources
to ensure we go back
+ // to the last working set
+ previousSources.forEach(rs -> {
+ // remember all the sources of the current routes (except the
updated)
+ if (rs != null && !equalResourceLocation(resource, rs)) {
+ sources.add(rs);
+ }
+ });
+ }
+
try {
// should all existing routes be stopped and removed first?
if (removeAllRoutes) {
@@ -196,9 +208,18 @@ public class RouteWatcherReloadStrategy extends
FileWatcherResourceReloadStrateg
}
}
+ // just in case remember this set of sources as what was attempted
previously to update
+ // in case the update fails with an exception
+ previousSources.clear();
+ previousSources.addAll(sources);
+
// reload those other routes that was stopped and removed as we
want to keep running those
Set<String> ids
=
getCamelContext().adapt(ExtendedCamelContext.class).getRoutesLoader().updateRoutes(sources);
+
+ // update okay, so clear as we do not need to remember those
anymore
+ previousSources.clear();
+
if (!ids.isEmpty()) {
List<String> lines = new ArrayList<>();
int total = 0;