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 fda38b3c2c6 CAMEL-21514: camel-jgropus - Upgrade to 5.4 and remove
cluster lock (#16444)
fda38b3c2c6 is described below
commit fda38b3c2c64d7c95c44100250cebb4f366b6137
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Dec 4 14:02:41 2024 +0100
CAMEL-21514: camel-jgropus - Upgrade to 5.4 and remove cluster lock (#16444)
* CAMEL-21514: camel-jgropus - Upgrade to 5.4 and remove cluster lock
---
.../src/main/docs/jgroups-component.adoc | 22 ---
.../jgroups/cluster/JGroupsLockClusterService.java | 59 --------
.../jgroups/cluster/JGroupsLockClusterView.java | 164 ---------------------
.../jgroups/cluster/JGroupsLockMasterTest.java | 104 -------------
.../ROOT/pages/camel-4x-upgrade-guide-4_10.adoc | 16 ++
.../modules/ROOT/pages/camel-4x-upgrade-guide.adoc | 1 +
parent/pom.xml | 2 +-
7 files changed, 18 insertions(+), 350 deletions(-)
diff --git a/components/camel-jgroups/src/main/docs/jgroups-component.adoc
b/components/camel-jgroups/src/main/docs/jgroups-component.adoc
index 98e4a4c0a2b..573917c68bd 100644
--- a/components/camel-jgroups/src/main/docs/jgroups-component.adoc
+++ b/components/camel-jgroups/src/main/docs/jgroups-component.adoc
@@ -185,25 +185,3 @@
from("jgroups:clusterName?enableViewMessages=true").to(mockEndpoint);
...
mockEndpoint.assertIsSatisfied();
---------------------------------------------------------------------
-
-=== Keeping singleton route within the cluster
-
-The snippet below demonstrates how to keep the singleton consumer route
-in the cluster of Camel Contexts. As soon as the master node dies, one
-of the slaves will be elected as a new master and started. In this
-particular example, we want to keep singleton xref:jetty-component.adoc[jetty]
-instance listening for the requests on
-address` http://localhost:8080/orders`.
-
-[source,java]
------------------------------------------------------------------------------------------------------------------------------------------------------------------
-JGroupsLockClusterService service = new JGroupsLockClusterService();
-service.setId("uniqueNodeId");
-...
-context.addService(service);
-
-from("master:mycluster:jetty:http://localhost:8080/orders").to("jms:orders");
------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
-
-include::spring-boot:partial$starter.adoc[]
diff --git
a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/cluster/JGroupsLockClusterService.java
b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/cluster/JGroupsLockClusterService.java
deleted file mode 100644
index d8fe5440f02..00000000000
---
a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/cluster/JGroupsLockClusterService.java
+++ /dev/null
@@ -1,59 +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.component.jgroups.cluster;
-
-import org.apache.camel.support.cluster.AbstractCamelClusterService;
-
-public class JGroupsLockClusterService extends
AbstractCamelClusterService<JGroupsLockClusterView> {
-
- private static final String DEFAULT_JGROUPS_CONFIG = "locking.xml";
- private static final String DEFAULT_JGROUPS_CLUSTERNAME = "jgroups-master";
-
- private String jgroupsConfig;
- private String jgroupsClusterName;
-
- public JGroupsLockClusterService() {
- this.jgroupsConfig = DEFAULT_JGROUPS_CONFIG;
- this.jgroupsClusterName = DEFAULT_JGROUPS_CLUSTERNAME;
- }
-
- public JGroupsLockClusterService(String jgroupsConfig, String
jgroupsClusterName) {
- this.jgroupsConfig = jgroupsConfig;
- this.jgroupsClusterName = jgroupsClusterName;
- }
-
- @Override
- protected JGroupsLockClusterView createView(String namespace) throws
Exception {
- return new JGroupsLockClusterView(this, namespace, jgroupsConfig,
jgroupsClusterName);
- }
-
- public String getJgroupsConfig() {
- return jgroupsConfig;
- }
-
- public void setJgroupsConfig(String jgroupsConfig) {
- this.jgroupsConfig = jgroupsConfig;
- }
-
- public String getJgroupsClusterName() {
- return jgroupsClusterName;
- }
-
- public void setJgroupsClusterName(String jgroupsClusterName) {
- this.jgroupsClusterName = jgroupsClusterName;
- }
-}
diff --git
a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/cluster/JGroupsLockClusterView.java
b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/cluster/JGroupsLockClusterView.java
deleted file mode 100644
index 519429cd585..00000000000
---
a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/cluster/JGroupsLockClusterView.java
+++ /dev/null
@@ -1,164 +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.component.jgroups.cluster;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.locks.Lock;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.cluster.CamelClusterMember;
-import org.apache.camel.cluster.CamelClusterService;
-import org.apache.camel.support.cluster.AbstractCamelClusterView;
-import org.apache.camel.util.ObjectHelper;
-import org.jgroups.JChannel;
-import org.jgroups.blocks.locking.LockService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class JGroupsLockClusterView extends AbstractCamelClusterView {
-
- private static final transient Logger LOG =
LoggerFactory.getLogger(JGroupsLockClusterView.class);
- private final CamelClusterMember localMember = new JGropusLocalMember();
- private String jgroupsConfig;
- private String jgroupsClusterName;
- private String lockName;
- private JChannel channel;
- private LockService lockService;
- private Lock lock;
- private ScheduledExecutorService executor;
- private volatile boolean isMaster;
-
- protected JGroupsLockClusterView(CamelClusterService cluster, String
namespace, String jgroupsConfig,
- String jgroupsClusterName) {
- super(cluster, namespace);
- lockName = namespace;
- this.jgroupsConfig = jgroupsConfig;
- this.jgroupsClusterName = jgroupsClusterName;
- }
-
- @Override
- public Optional<CamelClusterMember> getLeader() {
- if (isMaster) {
- return Optional.of(localMember);
- } else {
- return Optional.empty();
- }
- }
-
- @Override
- public CamelClusterMember getLocalMember() {
- return localMember;
- }
-
- @Override
- public List<CamelClusterMember> getMembers() {
- return new ArrayList<CamelClusterMember>() {
- {
- add(localMember);
- }
- };
- }
-
- @Override
- protected void doStart() throws Exception {
- if (lock != null) {
- lock.unlock();
- lock = null;
- }
- if (channel == null) {
- channel = new JChannel(jgroupsConfig);
- lockService = new LockService(channel);
- }
- channel.connect(jgroupsClusterName);
- lock = lockService.getLock(lockName);
-
- // Camel context should be set at this stage.
- final CamelContext context = ObjectHelper.notNull(getCamelContext(),
"CamelContext");
- executor =
context.getExecutorServiceManager().newSingleThreadScheduledExecutor(this,
- "JGroupsLockClusterView-" + getClusterService().getId() + "-"
+ lockName);
- executor.execute(() -> {
- LOG.info(
- "Attempting to become master acquiring the lock for group:
{} in JGroups cluster {} with configuration: {}",
- lockName, jgroupsClusterName, jgroupsConfig);
- lock.lock();
- isMaster = true;
- fireLeadershipChangedEvent(localMember);
- LOG.info("Became master by acquiring the lock for group: {} in
JGroups cluster {} with configuration: {}",
- lockName, jgroupsClusterName, jgroupsConfig);
- });
- }
-
- @Override
- protected void doStop() throws Exception {
- shutdownExecutor();
- isMaster = false;
- fireLeadershipChangedEvent((CamelClusterMember) null);
- clearLock();
- channel.disconnect();
- }
-
- @Override
- protected void doShutdown() throws Exception {
- shutdownExecutor();
- isMaster = false;
- fireLeadershipChangedEvent((CamelClusterMember) null);
- clearLock();
- if (channel != null) {
- channel.close();
- channel = null;
- }
- }
-
- private void clearLock() {
- if (lock != null) {
- lock.unlock();
- lock = null;
- }
- }
-
- private void shutdownExecutor() {
- CamelContext context = getCamelContext();
- if (executor != null) {
- if (context != null) {
- context.getExecutorServiceManager().shutdown(executor);
- } else {
- executor.shutdown();
- }
- executor = null;
- }
- }
-
- private final class JGropusLocalMember implements CamelClusterMember {
- @Override
- public boolean isLeader() {
- return isMaster;
- }
-
- @Override
- public boolean isLocal() {
- return true;
- }
-
- @Override
- public String getId() {
- return getClusterService().getId();
- }
- }
-}
diff --git
a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/cluster/JGroupsLockMasterTest.java
b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/cluster/JGroupsLockMasterTest.java
deleted file mode 100644
index 005f9f3d95b..00000000000
---
a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/cluster/JGroupsLockMasterTest.java
+++ /dev/null
@@ -1,104 +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.component.jgroups.cluster;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.IntStream;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.DefaultCamelContext;
-import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-public class JGroupsLockMasterTest {
- private static final Logger LOGGER =
LoggerFactory.getLogger(JGroupsLockMasterTest.class);
- private static final List<String> CLIENTS = IntStream.range(0,
3).mapToObj(Integer::toString).toList();
- private static final List<String> RESULTS = new ArrayList<>();
- private static final ScheduledExecutorService SCHEDULER =
Executors.newScheduledThreadPool(CLIENTS.size());
- private static final CountDownLatch LATCH = new
CountDownLatch(CLIENTS.size());
-
- // ************************************
- // Test
- // ************************************
-
- @Test
- public void test() throws Exception {
- for (String id : CLIENTS) {
- SCHEDULER.submit(() -> run(id));
- }
-
- LATCH.await(1, TimeUnit.MINUTES);
- SCHEDULER.shutdownNow();
-
- assertEquals(CLIENTS.size(), RESULTS.size());
- assertTrue(RESULTS.containsAll(CLIENTS));
- }
-
- // ************************************
- // Run a Camel node
- // ************************************
-
- private static void run(String id) {
- try {
- int events = ThreadLocalRandom.current().nextInt(2, 6);
- CountDownLatch contextLatch = new CountDownLatch(events);
-
- JGroupsLockClusterService service = new
JGroupsLockClusterService();
- service.setId("node-" + id);
-
- DefaultCamelContext context = new DefaultCamelContext();
- context.disableJMX();
- context.getCamelContextExtension().setName("context-" + id);
- context.addService(service);
- context.addRoutes(new RouteBuilder() {
- @Override
- public void configure() {
- from("master:jgl:timer:master?delay=1000&period=1000")
- .routeId("route-" + id)
- .log("From ${routeId}")
- .process(e -> contextLatch.countDown());
- }
- });
-
- // Start the context after some random time so the startup order
- // changes for each test.
- Thread.sleep(ThreadLocalRandom.current().nextInt(500));
- context.start();
-
- contextLatch.await();
-
- LOGGER.debug("Shutting down node {}", id);
- RESULTS.add(id);
-
- context.stop();
-
- LATCH.countDown();
- } catch (Exception e) {
- LOGGER.warn("{}", e.getMessage(), e);
- }
- }
-}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_10.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_10.adoc
new file mode 100644
index 00000000000..179935d3b05
--- /dev/null
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_10.adoc
@@ -0,0 +1,16 @@
+= Apache Camel 4.x Upgrade Guide
+
+This document is for helping you upgrade your Apache Camel application
+from Camel 4.x to 4.y. For example, if you are upgrading Camel 4.0 to 4.2,
then you should follow the guides
+from both 4.0 to 4.1 and 4.1 to 4.2.
+
+== Upgrading Camel 4.9 to 4.10
+
+=== camel-jgroups
+
+The cluster lock has been removed as it has been removed in JGroups 5.4
onwards, and it was
+not recommended to be used in older JGroups releases. You can use another
Camel component such as
+`camel-infinispan` that has cluster locking.
+
+The `camel-jgroups-cluster-service-starter` in Camel Spring Boot has been
removed.
+
diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide.adoc
index 59c7af239db..d1e264fb7ee 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide.adoc
@@ -18,4 +18,5 @@ You can find the upgrade guide for each release in the
following pages:
- xref:camel-4x-upgrade-guide-4_7.adoc[Upgrade guide 4.6 -> 4.7]
- xref:camel-4x-upgrade-guide-4_8.adoc[Upgrade guide 4.7 -> 4.8]
- xref:camel-4x-upgrade-guide-4_9.adoc[Upgrade guide 4.8 -> 4.9]
+- xref:camel-4x-upgrade-guide-4_10.adoc[Upgrade guide 4.9 -> 4.10]
diff --git a/parent/pom.xml b/parent/pom.xml
index e7d6d91154e..b14374977bb 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -280,7 +280,7 @@
<jetty-runner-groupId>org.eclipse.jetty</jetty-runner-groupId>
<jettison-version>1.5.4</jettison-version>
<jgit-version>7.0.0.202409031743-r</jgit-version>
- <jgroups-version>5.3.13.Final</jgroups-version>
+ <jgroups-version>5.4.0.Final</jgroups-version>
<jgroups-raft-version>1.0.14.Final</jgroups-raft-version>
<jgroups-raft-leveldbjni-version>1.8</jgroups-raft-leveldbjni-version>
<jgroups-raft-mapdb-version>1.0.8</jgroups-raft-mapdb-version>