This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-27696-jgroups-default-config in repository https://gitbox.apache.org/repos/asf/camel.git
commit 70909a16af5d53f5005ca52b0ad2c84485ecc821 Author: Claus Ibsen <[email protected]> AuthorDate: Fri Nov 27 17:16:35 2026 +0100 CAMEL-27696: camel-jgroups-raft - document that the bundled raft.xml is for development only, and warn when it is used Without channelProperties, a jgroups-raft endpoint (and the JGroupsRaftClusterService with its default jgroupsConfig) uses the raft.xml of the camel-jgroups-raft JAR: UDP multicast without AUTH or encryption, and A as the only RAFT member. A jgroups endpoint without channel and channelProperties uses the default udp.xml of JGroups, also without AUTH or encryption. The option texts and the docs now say these are meant for development and tests, and what to set in production. The endpoints and the cluster service log a WARN when they start with the default configuration. The bundled raft.xml is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../catalog/beans/JGroupsRaftClusterService.json | 2 +- .../camel/catalog/components/jgroups-raft.json | 4 +- .../apache/camel/catalog/components/jgroups.json | 4 +- .../camel/catalog/docs/jgroups-component.adoc | 4 + .../camel/catalog/docs/jgroups-raft-component.adoc | 30 +++++++ .../camel/component/jgroups/raft/jgroups-raft.json | 4 +- .../camel/bean/JGroupsRaftClusterService.json | 2 +- .../src/main/docs/jgroups-raft-component.adoc | 30 +++++++ .../jgroups/raft/JGroupsRaftComponent.java | 8 +- .../jgroups/raft/JGroupsRaftEndpoint.java | 13 ++- .../raft/cluster/JGroupsRaftClusterService.java | 16 +++- .../raft/JGroupsRaftDefaultConfigWarningTest.java | 94 ++++++++++++++++++++++ .../camel/component/jgroups/raft/WarnCapture.java | 79 ++++++++++++++++++ ...RaftClusterServiceDefaultConfigWarningTest.java | 81 +++++++++++++++++++ .../apache/camel/component/jgroups/jgroups.json | 4 +- .../src/main/docs/jgroups-component.adoc | 4 + .../camel/component/jgroups/JGroupsComponent.java | 6 +- .../camel/component/jgroups/JGroupsEndpoint.java | 11 ++- .../jgroups/JGroupsDefaultChannelWarningTest.java | 90 +++++++++++++++++++++ .../camel/component/jgroups/WarnCapture.java | 79 ++++++++++++++++++ .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 8 ++ .../dsl/JgroupsComponentBuilderFactory.java | 9 ++- .../dsl/JgroupsRaftComponentBuilderFactory.java | 9 ++- .../dsl/JGroupsEndpointBuilderFactory.java | 30 +++++-- .../dsl/JGroupsRaftEndpointBuilderFactory.java | 27 +++++-- 25 files changed, 615 insertions(+), 33 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/JGroupsRaftClusterService.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/JGroupsRaftClusterService.json index 32ce7531d26b..e61b48998933 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/JGroupsRaftClusterService.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/JGroupsRaftClusterService.json @@ -10,7 +10,7 @@ "groupId": "org.apache.camel", "artifactId": "camel-jgroups-raft", "version": "4.24.0-SNAPSHOT", - "properties": { "id": { "index": 0, "kind": "property", "displayName": "Id", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Unique Raft id" }, "jgroupsConfig": { "index": 1, "kind": "property", "displayName": "Jgroups Config", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "raft.xml", "descriptio [...] + "properties": { "id": { "index": 0, "kind": "property", "displayName": "Id", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Unique Raft id" }, "jgroupsConfig": { "index": 1, "kind": "property", "displayName": "Jgroups Config", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "raft.xml", "descriptio [...] } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/jgroups-raft.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/jgroups-raft.json index b097f0f9e128..22142d0c3b4e 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/jgroups-raft.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/jgroups-raft.json @@ -24,7 +24,7 @@ "remote": true }, "componentProperties": { - "channelProperties": { "index": 0, "kind": "property", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "raft.xml", "description": "The JGroups XML configuration of the JChannel that each endpoint creates, as a file, a URL or a classpath resource. If not set, the raft.xml in the camel-jgroups-raft JAR is used, which lists A [...] + "channelProperties": { "index": 0, "kind": "property", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "raft.xml", "description": "The JGroups XML configuration of the JChannel that each endpoint creates, as a file, a URL or a classpath resource. If not set, the raft.xml in the camel-jgroups-raft JAR is used, and a WARN is [...] "raftHandle": { "index": 1, "kind": "property", "displayName": "Raft Handle", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.jgroups.raft.RaftHandle", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom org.jgroups.raft.RaftHandle for all the endpoints of this component. When set, the raftId, channelProperties and stateMachine options are not used. The component closes its channel and its log when the compon [...] "raftId": { "index": 2, "kind": "property", "displayName": "Raft Id", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The Raft ID of this member, which also names the JChannel. A member whose ID is not in the members attribute of RAFT in the channel configuration is a Learner, which does not vote. If not set, the raft_id of the channel configuration is used. N [...] "stateMachine": { "index": 3, "kind": "property", "displayName": "State Machine", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.jgroups.raft.StateMachine", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "NopStateMachine", "description": "The org.jgroups.raft.StateMachine that applies the committed log entries, for the RaftHandle that each endpoint creates. The default NopStateMachine ignores the entries and returns an [...] @@ -53,7 +53,7 @@ }, "properties": { "clusterName": { "index": 0, "kind": "path", "displayName": "Cluster Name", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The name of the JGroups cluster that the channel of the RaftHandle connects to. All the members of the Raft cluster use the same name." }, - "channelProperties": { "index": 1, "kind": "parameter", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "raft.xml", "description": "The JGroups XML configuration of the JChannel that the endpoint creates, as a file, a URL or a classpath resource. If not set, the channelProperties of the component is used, else the raft.xml [...] + "channelProperties": { "index": 1, "kind": "parameter", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "raft.xml", "description": "The JGroups XML configuration of the JChannel that the endpoint creates, as a file, a URL or a classpath resource. If not set, the channelProperties of the component is used, else the raft.xml [...] "raftHandle": { "index": 2, "kind": "parameter", "displayName": "Raft Handle", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.jgroups.raft.RaftHandle", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom org.jgroups.raft.RaftHandle for this endpoint instead of the raftHandle of the component. When set, the raftId, channelProperties and stateMachine options are not used. The component closes its channel and i [...] "raftId": { "index": 3, "kind": "parameter", "displayName": "Raft Id", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The Raft ID of this member, which also names the JChannel. A member whose ID is not in the members attribute of RAFT in the channel configuration is a Learner, which does not vote. If not set, the raftId of the component is used, else the raf [...] "stateMachine": { "index": 4, "kind": "parameter", "displayName": "State Machine", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.jgroups.raft.StateMachine", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "NopStateMachine", "description": "The org.jgroups.raft.StateMachine that applies the committed log entries, for the RaftHandle that the endpoint creates. If not set, the stateMachine of the component is used. The def [...] diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/jgroups.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/jgroups.json index a9344c62cbbb..ee7b92b2362a 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/jgroups.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/jgroups.json @@ -25,7 +25,7 @@ }, "componentProperties": { "channel": { "index": 0, "kind": "property", "displayName": "Channel", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.jgroups.JChannel", "deprecated": false, "autowired": false, "secret": false, "description": "Channel to use" }, - "channelProperties": { "index": 1, "kind": "property", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Specifies configuration properties of the JChannel used by the endpoint." }, + "channelProperties": { "index": 1, "kind": "property", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The JGroups configuration of the JChannel that each endpoint creates, as an XML file, a URL or a classpath resource. If neither this option nor the channel option is set, the default udp.xml in the JGroups JAR is used, an [...] "bridgeErrorHandler": { "index": 2, "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the like [...] "enableViewMessages": { "index": 3, "kind": "property", "displayName": "Enable View Messages", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If set to true, the consumer endpoint will receive org.jgroups.View messages as well (not only org.jgroups.Message instances). By default only regular messages are consumed by the endpoint." }, "lazyStartProducer": { "index": 4, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...] @@ -46,7 +46,7 @@ }, "properties": { "clusterName": { "index": 0, "kind": "path", "displayName": "Cluster Name", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The name of the JGroups cluster the component should connect to." }, - "channelProperties": { "index": 1, "kind": "parameter", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Specifies configuration properties of the JChannel used by the endpoint." }, + "channelProperties": { "index": 1, "kind": "parameter", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The JGroups configuration of the JChannel that the endpoint creates, as an XML file, a URL or a classpath resource. If not set, the channelProperties of the component is used. If neither is set and the component has no c [...] "enableViewMessages": { "index": 2, "kind": "parameter", "displayName": "Enable View Messages", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If set to true, the consumer endpoint will receive org.jgroups.View messages as well (not only org.jgroups.Message instances). By default only regular messages are consumed by the endpoint." }, "bridgeErrorHandler": { "index": 3, "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming [...] "exceptionHandler": { "index": 4, "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By def [...] diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jgroups-component.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jgroups-component.adoc index e75c9ad64acd..8917092d206c 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jgroups-component.adoc +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jgroups-component.adoc @@ -58,6 +58,10 @@ The default JGroups protocol stack (`udp.xml`) multicasts over UDP and does multicast group or bind port can join and send messages. Treat cluster peers as part of your trust boundary and harden the deployment accordingly. +The endpoint uses this default stack when neither the `channelProperties` option +nor the `channel` option of the component is set, and then logs a WARN when it +starts: the default stack is meant for development and tests. + * *Authenticate and encrypt the channel.* Supply a hardened JGroups configuration through the `channelProperties` option and add the `AUTH` protocol together with `SYM_ENCRYPT` or `ASYM_ENCRYPT`, so that only trusted diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jgroups-raft-component.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jgroups-raft-component.adoc index 2414df00620d..c7ae276b13d8 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jgroups-raft-component.adoc +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jgroups-raft-component.adoc @@ -45,6 +45,36 @@ include::partial$component-endpoint-options.adoc[] include::partial$component-endpoint-headers.adoc[] // component options: END +== Channel configuration + +The `channelProperties` option (of the endpoint or the component) sets the JGroups XML configuration of the channel, +as a file, a URL or a classpath resource. When it is not set, the endpoint uses `raft.xml`, which is the configuration +in the `camel-jgroups-raft` JAR unless the application has its own `raft.xml` first on the classpath. The +`jgroupsConfig` option of the `JGroupsRaftClusterService` has the same default. + +The `raft.xml` in the JAR is a sample for development and tests: + +* it uses UDP multicast (`228.5.5.5`), without authentication or encryption, so any host on the same network that uses +the same cluster name can join the cluster and take part in the Raft log, and the messages are sent in clear text; +* it lists `A` as the only member in the `members` attribute of `RAFT`. + +A WARN is logged when an endpoint (or the cluster service) starts with this default. In production, use your own +JGroups configuration, under another name, with: + +* the `AUTH` protocol, and `SYM_ENCRYPT` or `ASYM_ENCRYPT`, so that only trusted members join the cluster and the +messages are encrypted; +* the Raft IDs of all the members of the cluster in the `members` attribute of `RAFT` (for example +`members="node1,node2,node3"`), and the `raft_id` of each member; +* a transport that fits the network, such as TCP with a list of the members, when multicast is not wanted. + +[source,java] +---- +from("direct:start").to("jgroups-raft:clusterName?raftId=node1&channelProperties=my-raft.xml"); +---- + +See the http://belaban.github.io/jgroups-raft/[JGroups-raft] and http://www.jgroups.org/[JGroups] documentation for +the protocols. + == Usage Using `jgroups-raft` component with `enableRoleChangeEvents=true` on the consumer side of the route will capture diff --git a/components/camel-jgroups-raft/src/generated/resources/META-INF/org/apache/camel/component/jgroups/raft/jgroups-raft.json b/components/camel-jgroups-raft/src/generated/resources/META-INF/org/apache/camel/component/jgroups/raft/jgroups-raft.json index b097f0f9e128..22142d0c3b4e 100644 --- a/components/camel-jgroups-raft/src/generated/resources/META-INF/org/apache/camel/component/jgroups/raft/jgroups-raft.json +++ b/components/camel-jgroups-raft/src/generated/resources/META-INF/org/apache/camel/component/jgroups/raft/jgroups-raft.json @@ -24,7 +24,7 @@ "remote": true }, "componentProperties": { - "channelProperties": { "index": 0, "kind": "property", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "raft.xml", "description": "The JGroups XML configuration of the JChannel that each endpoint creates, as a file, a URL or a classpath resource. If not set, the raft.xml in the camel-jgroups-raft JAR is used, which lists A [...] + "channelProperties": { "index": 0, "kind": "property", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "raft.xml", "description": "The JGroups XML configuration of the JChannel that each endpoint creates, as a file, a URL or a classpath resource. If not set, the raft.xml in the camel-jgroups-raft JAR is used, and a WARN is [...] "raftHandle": { "index": 1, "kind": "property", "displayName": "Raft Handle", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.jgroups.raft.RaftHandle", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom org.jgroups.raft.RaftHandle for all the endpoints of this component. When set, the raftId, channelProperties and stateMachine options are not used. The component closes its channel and its log when the compon [...] "raftId": { "index": 2, "kind": "property", "displayName": "Raft Id", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The Raft ID of this member, which also names the JChannel. A member whose ID is not in the members attribute of RAFT in the channel configuration is a Learner, which does not vote. If not set, the raft_id of the channel configuration is used. N [...] "stateMachine": { "index": 3, "kind": "property", "displayName": "State Machine", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.jgroups.raft.StateMachine", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "NopStateMachine", "description": "The org.jgroups.raft.StateMachine that applies the committed log entries, for the RaftHandle that each endpoint creates. The default NopStateMachine ignores the entries and returns an [...] @@ -53,7 +53,7 @@ }, "properties": { "clusterName": { "index": 0, "kind": "path", "displayName": "Cluster Name", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The name of the JGroups cluster that the channel of the RaftHandle connects to. All the members of the Raft cluster use the same name." }, - "channelProperties": { "index": 1, "kind": "parameter", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "raft.xml", "description": "The JGroups XML configuration of the JChannel that the endpoint creates, as a file, a URL or a classpath resource. If not set, the channelProperties of the component is used, else the raft.xml [...] + "channelProperties": { "index": 1, "kind": "parameter", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "raft.xml", "description": "The JGroups XML configuration of the JChannel that the endpoint creates, as a file, a URL or a classpath resource. If not set, the channelProperties of the component is used, else the raft.xml [...] "raftHandle": { "index": 2, "kind": "parameter", "displayName": "Raft Handle", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.jgroups.raft.RaftHandle", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom org.jgroups.raft.RaftHandle for this endpoint instead of the raftHandle of the component. When set, the raftId, channelProperties and stateMachine options are not used. The component closes its channel and i [...] "raftId": { "index": 3, "kind": "parameter", "displayName": "Raft Id", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The Raft ID of this member, which also names the JChannel. A member whose ID is not in the members attribute of RAFT in the channel configuration is a Learner, which does not vote. If not set, the raftId of the component is used, else the raf [...] "stateMachine": { "index": 4, "kind": "parameter", "displayName": "State Machine", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.jgroups.raft.StateMachine", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "NopStateMachine", "description": "The org.jgroups.raft.StateMachine that applies the committed log entries, for the RaftHandle that the endpoint creates. If not set, the stateMachine of the component is used. The def [...] diff --git a/components/camel-jgroups-raft/src/generated/resources/META-INF/services/org/apache/camel/bean/JGroupsRaftClusterService.json b/components/camel-jgroups-raft/src/generated/resources/META-INF/services/org/apache/camel/bean/JGroupsRaftClusterService.json index 32ce7531d26b..e61b48998933 100644 --- a/components/camel-jgroups-raft/src/generated/resources/META-INF/services/org/apache/camel/bean/JGroupsRaftClusterService.json +++ b/components/camel-jgroups-raft/src/generated/resources/META-INF/services/org/apache/camel/bean/JGroupsRaftClusterService.json @@ -10,7 +10,7 @@ "groupId": "org.apache.camel", "artifactId": "camel-jgroups-raft", "version": "4.24.0-SNAPSHOT", - "properties": { "id": { "index": 0, "kind": "property", "displayName": "Id", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Unique Raft id" }, "jgroupsConfig": { "index": 1, "kind": "property", "displayName": "Jgroups Config", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "raft.xml", "descriptio [...] + "properties": { "id": { "index": 0, "kind": "property", "displayName": "Id", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Unique Raft id" }, "jgroupsConfig": { "index": 1, "kind": "property", "displayName": "Jgroups Config", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "raft.xml", "descriptio [...] } } diff --git a/components/camel-jgroups-raft/src/main/docs/jgroups-raft-component.adoc b/components/camel-jgroups-raft/src/main/docs/jgroups-raft-component.adoc index 2414df00620d..c7ae276b13d8 100644 --- a/components/camel-jgroups-raft/src/main/docs/jgroups-raft-component.adoc +++ b/components/camel-jgroups-raft/src/main/docs/jgroups-raft-component.adoc @@ -45,6 +45,36 @@ include::partial$component-endpoint-options.adoc[] include::partial$component-endpoint-headers.adoc[] // component options: END +== Channel configuration + +The `channelProperties` option (of the endpoint or the component) sets the JGroups XML configuration of the channel, +as a file, a URL or a classpath resource. When it is not set, the endpoint uses `raft.xml`, which is the configuration +in the `camel-jgroups-raft` JAR unless the application has its own `raft.xml` first on the classpath. The +`jgroupsConfig` option of the `JGroupsRaftClusterService` has the same default. + +The `raft.xml` in the JAR is a sample for development and tests: + +* it uses UDP multicast (`228.5.5.5`), without authentication or encryption, so any host on the same network that uses +the same cluster name can join the cluster and take part in the Raft log, and the messages are sent in clear text; +* it lists `A` as the only member in the `members` attribute of `RAFT`. + +A WARN is logged when an endpoint (or the cluster service) starts with this default. In production, use your own +JGroups configuration, under another name, with: + +* the `AUTH` protocol, and `SYM_ENCRYPT` or `ASYM_ENCRYPT`, so that only trusted members join the cluster and the +messages are encrypted; +* the Raft IDs of all the members of the cluster in the `members` attribute of `RAFT` (for example +`members="node1,node2,node3"`), and the `raft_id` of each member; +* a transport that fits the network, such as TCP with a list of the members, when multicast is not wanted. + +[source,java] +---- +from("direct:start").to("jgroups-raft:clusterName?raftId=node1&channelProperties=my-raft.xml"); +---- + +See the http://belaban.github.io/jgroups-raft/[JGroups-raft] and http://www.jgroups.org/[JGroups] documentation for +the protocols. + == Usage Using `jgroups-raft` component with `enableRoleChangeEvents=true` on the consumer side of the route will capture diff --git a/components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/JGroupsRaftComponent.java b/components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/JGroupsRaftComponent.java index 5535aaa23715..608d22c675fc 100644 --- a/components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/JGroupsRaftComponent.java +++ b/components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/JGroupsRaftComponent.java @@ -66,8 +66,12 @@ public class JGroupsRaftComponent extends DefaultComponent { @UriParam @Metadata(defaultValue = "raft.xml", description = "The JGroups XML configuration of the JChannel that each endpoint creates, as a file, a URL or a" - + " classpath resource. If not set, the raft.xml in the camel-jgroups-raft JAR is used, which" - + " lists A as the only RAFT member. Not used when the raftHandle option is set.") + + " classpath resource. If not set, the raft.xml in the camel-jgroups-raft JAR is used, and a WARN" + + " is logged when an endpoint starts. That raft.xml is a sample for development and tests: it" + + " uses UDP multicast without authentication or encryption, and lists A as the only RAFT member." + + " In production, set your own configuration, with AUTH and SYM_ENCRYPT or ASYM_ENCRYPT, and the" + + " members of the cluster in the members attribute of RAFT. Not used when the raftHandle option" + + " is set.") private String channelProperties; // the connected producers and consumers of each RaftHandle that the endpoints did not create (such as the diff --git a/components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/JGroupsRaftEndpoint.java b/components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/JGroupsRaftEndpoint.java index 52dc3fba15b2..8061130fe18c 100644 --- a/components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/JGroupsRaftEndpoint.java +++ b/components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/JGroupsRaftEndpoint.java @@ -79,8 +79,11 @@ public class JGroupsRaftEndpoint extends DefaultEndpoint { private String raftId; @UriParam(description = "The JGroups XML configuration of the JChannel that the endpoint creates, as a file, a URL or a" + " classpath resource. If not set, the channelProperties of the component is used, else the" - + " raft.xml in the camel-jgroups-raft JAR, which lists A as the only RAFT member. Not used when" - + " the raftHandle option is set.") + + " raft.xml in the camel-jgroups-raft JAR, and a WARN is logged when the endpoint starts. That" + + " raft.xml is a sample for development and tests: it uses UDP multicast without authentication" + + " or encryption, and lists A as the only RAFT member. In production, set your own" + + " configuration, with AUTH and SYM_ENCRYPT or ASYM_ENCRYPT, and the members of the cluster in" + + " the members attribute of RAFT. Not used when the raftHandle option is set.") @Metadata(defaultValue = "raft.xml") private String channelProperties; @UriParam(description = "To use a custom org.jgroups.raft.RaftHandle for this endpoint instead of the raftHandle of the" @@ -214,6 +217,12 @@ public class JGroupsRaftEndpoint extends DefaultEndpoint { JChannel channel = new JChannel(channelProperties).name(raftId); // NOSONAR return new RaftHandle(channel, stateMachine).raftId(raftId); } + LOG.warn("The JGroups-raft endpoint {} has no channelProperties, so its channel uses {}, by default the sample" + + " configuration in the camel-jgroups-raft JAR. That configuration is meant for development and tests:" + + " it uses UDP multicast without authentication or encryption, and lists A as the only RAFT member. In" + + " production, set channelProperties to your own JGroups configuration, with AUTH and SYM_ENCRYPT or" + + " ASYM_ENCRYPT, and the members of the cluster in the members attribute of RAFT.", + getEndpointUri(), JGroupsRaftConstants.DEFAULT_JGROUPSRAFT_CONFIG); LOG.trace("Raft Handle created with defaults: {}, {},", JGroupsRaftConstants.DEFAULT_JGROUPSRAFT_CONFIG, stateMachine); @SuppressWarnings("resource") // NOTE: channel will be closed by this endpoint during diff --git a/components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusterService.java b/components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusterService.java index 5edfd51dac25..3434a0a6b23b 100644 --- a/components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusterService.java +++ b/components/camel-jgroups-raft/src/main/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusterService.java @@ -46,7 +46,13 @@ public class JGroupsRaftClusterService extends AbstractCamelClusterService<JGrou @Metadata(description = "Unique Raft id", required = true) private String id; - @Metadata(description = "The path to the JGroups Raft configuration", defaultValue = DEFAULT_JGROUPS_CONFIG) + @Metadata(description = "The JGroups XML configuration of the channel, as a file, a URL or a classpath resource. The" + + " default raft.xml in the camel-jgroups-raft JAR is a sample for development and tests (UDP" + + " multicast without authentication or encryption, and A as the only RAFT member), and a WARN" + + " is logged when it is used. In production, set your own configuration, with AUTH and" + + " SYM_ENCRYPT or ASYM_ENCRYPT, and the members of the cluster in the members attribute of" + + " RAFT.", + defaultValue = DEFAULT_JGROUPS_CONFIG) private String jgroupsConfig; @Metadata(description = "The name of the cluster", defaultValue = DEFAULT_JGROUPS_CLUSTERNAME) private String jgroupsClusterName; @@ -164,6 +170,14 @@ public class JGroupsRaftClusterService extends AbstractCamelClusterService<JGrou private RaftHandle createRaftHandle() throws Exception { String config = jgroupsConfig != null && !jgroupsConfig.isEmpty() ? jgroupsConfig : DEFAULT_JGROUPS_CONFIG; + if (DEFAULT_JGROUPS_CONFIG.equals(config)) { + LOG.warn("The JGroupsRaftClusterService with Id {} uses {}, by default the sample configuration in the" + + " camel-jgroups-raft JAR. That configuration is meant for development and tests: it uses UDP" + + " multicast without authentication or encryption, and lists A as the only RAFT member. In" + + " production, set jgroupsConfig to your own JGroups configuration, with AUTH and SYM_ENCRYPT or" + + " ASYM_ENCRYPT, and the members of the cluster in the members attribute of RAFT.", + getId(), config); + } return new RaftHandle(new JChannel(config), new NopStateMachine()).raftId(getId()); } diff --git a/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/JGroupsRaftDefaultConfigWarningTest.java b/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/JGroupsRaftDefaultConfigWarningTest.java new file mode 100644 index 000000000000..e43279e4ef2a --- /dev/null +++ b/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/JGroupsRaftDefaultConfigWarningTest.java @@ -0,0 +1,94 @@ +/* + * 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.raft; + +import java.util.UUID; + +import org.apache.camel.impl.DefaultCamelContext; +import org.jgroups.protocols.raft.InMemoryLog; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Without channelProperties, the endpoint uses the raft.xml of the camel-jgroups-raft JAR, a sample for development and + * tests, and logs a WARN when it starts. In the tests, the raft.xml of the test resources comes first on the classpath. + */ +class JGroupsRaftDefaultConfigWarningTest { + + private final String id = UUID.randomUUID().toString(); + private WarnCapture capture; + private DefaultCamelContext context; + + @BeforeEach + void start() { + capture = new WarnCapture(JGroupsRaftEndpoint.class); + context = new DefaultCamelContext(); + context.disableJMX(); + context.start(); + } + + @AfterEach + void stop() { + try { + context.stop(); + } finally { + capture.close(); + InMemoryLog.logs.keySet().removeIf(key -> key.contains(id)); + } + } + + @Test + void warnsWithoutChannelProperties() { + String clusterName = "default-" + id; + + // the endpoint starts (and creates its RaftHandle) when it is added to the started context + JGroupsRaftEndpoint endpoint = context.getEndpoint("jgroups-raft:" + clusterName + "?raftId=learner-" + id, + JGroupsRaftEndpoint.class); + // the same endpoint again: it is started once + context.getEndpoint("jgroups-raft:" + clusterName + "?raftId=learner-" + id, JGroupsRaftEndpoint.class); + + assertNotNull(endpoint.getResolvedRaftHandle()); + assertEquals(1, capture.count(clusterName), capture.warnings()::toString); + assertEquals(1, capture.count(clusterName, "has no channelProperties", "raft.xml"), capture.warnings()::toString); + } + + @Test + void noWarningWithChannelPropertiesOfEndpoint() { + String clusterName = "endpoint-" + id; + + context.getEndpoint("jgroups-raft:" + clusterName + "?raftId=learner-" + id + "&channelProperties=raftB.xml", + JGroupsRaftEndpoint.class); + + assertEquals(0, capture.count(clusterName), capture.warnings()::toString); + } + + @Test + void noWarningWithChannelPropertiesOfComponent() { + String clusterName = "component-" + id; + JGroupsRaftComponent component = new JGroupsRaftComponent(); + component.setChannelProperties("raftB.xml"); + context.addComponent("my-jgroups-raft", component); + + context.getEndpoint("my-jgroups-raft:" + clusterName + "?raftId=learner-" + id, JGroupsRaftEndpoint.class); + + assertEquals(0, capture.count(clusterName), capture.warnings()::toString); + } +} diff --git a/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/WarnCapture.java b/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/WarnCapture.java new file mode 100644 index 000000000000..09eb8b6c9450 --- /dev/null +++ b/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/WarnCapture.java @@ -0,0 +1,79 @@ +/* + * 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.raft; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.TimeUnit; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.Logger; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.Property; + +import static org.awaitility.Awaitility.await; + +/** + * Captures the WARN messages of the logger of a class, while it is open. + */ +public final class WarnCapture implements AutoCloseable { + + private final Logger logger; + private final List<String> warnings = new CopyOnWriteArrayList<>(); + private final AbstractAppender appender; + + public WarnCapture(Class<?> type) { + logger = (Logger) LogManager.getLogger(type); + appender = new AbstractAppender("WarnCapture-" + UUID.randomUUID(), null, null, true, Property.EMPTY_ARRAY) { + @Override + public void append(LogEvent event) { + if (event.getLevel() == Level.WARN) { + warnings.add(event.getMessage().getFormattedMessage()); + } + } + }; + // the test classes may run in parallel: while another one is still starting log4j, the logger has the default + // configuration, which log4j replaces once it has read log4j2.properties, and an appender attached to it is + // stopped and lost, so attach it once log4j has started + await().atMost(30, TimeUnit.SECONDS).until(logger.getContext()::isStarted); + appender.start(); + logger.addAppender(appender); + // addAppender creates a non-additive logger config, which would hide this logger from the root appenders + logger.setAdditive(true); + } + + /** + * The number of WARN messages that contain all the texts. + */ + public long count(String... texts) { + return warnings.stream().filter(message -> Arrays.stream(texts).allMatch(message::contains)).count(); + } + + public List<String> warnings() { + return warnings; + } + + @Override + public void close() { + logger.removeAppender(appender); + appender.stop(); + } +} diff --git a/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusterServiceDefaultConfigWarningTest.java b/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusterServiceDefaultConfigWarningTest.java new file mode 100644 index 000000000000..96e8bb17461a --- /dev/null +++ b/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusterServiceDefaultConfigWarningTest.java @@ -0,0 +1,81 @@ +/* + * 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.raft.cluster; + +import java.util.UUID; + +import org.apache.camel.component.jgroups.raft.WarnCapture; +import org.jgroups.protocols.raft.InMemoryLog; +import org.jgroups.protocols.raft.RAFT; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * With the default jgroupsConfig, the cluster service uses the raft.xml of the camel-jgroups-raft JAR, a sample for + * development and tests, and logs a WARN when it creates its RaftHandle. In the tests, the raft.xml of the test + * resources comes first on the classpath. + */ +class JGroupsRaftClusterServiceDefaultConfigWarningTest { + + private final String id = UUID.randomUUID().toString(); + private final RAFT.RoleChange listener = role -> { + }; + private WarnCapture capture; + + @BeforeEach + void startCapture() { + capture = new WarnCapture(JGroupsRaftClusterService.class); + } + + @AfterEach + void stopCapture() { + capture.close(); + InMemoryLog.logs.keySet().removeIf(key -> key.contains(id)); + } + + @Test + void warnsWithDefaultConfig() throws Exception { + // a raft id that is not a member of the configuration: a Learner, which does not take part in elections + JGroupsRaftClusterService service = newService("default-" + id); + + service.connectView(listener); + service.disconnectView(listener); + + assertEquals(1, capture.count("default-" + id, "raft.xml"), capture.warnings()::toString); + } + + @Test + void noWarningWithJgroupsConfig() throws Exception { + JGroupsRaftClusterService service = newService("configured-" + id); + service.setJgroupsConfig("raftABC.xml"); + + service.connectView(listener); + service.disconnectView(listener); + + assertEquals(0, capture.count("configured-" + id), capture.warnings()::toString); + } + + private static JGroupsRaftClusterService newService(String raftId) { + JGroupsRaftClusterService service = new JGroupsRaftClusterService(); + service.setId(raftId); + service.setJgroupsClusterName("cluster-" + raftId); + return service; + } +} diff --git a/components/camel-jgroups/src/generated/resources/META-INF/org/apache/camel/component/jgroups/jgroups.json b/components/camel-jgroups/src/generated/resources/META-INF/org/apache/camel/component/jgroups/jgroups.json index a9344c62cbbb..ee7b92b2362a 100644 --- a/components/camel-jgroups/src/generated/resources/META-INF/org/apache/camel/component/jgroups/jgroups.json +++ b/components/camel-jgroups/src/generated/resources/META-INF/org/apache/camel/component/jgroups/jgroups.json @@ -25,7 +25,7 @@ }, "componentProperties": { "channel": { "index": 0, "kind": "property", "displayName": "Channel", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.jgroups.JChannel", "deprecated": false, "autowired": false, "secret": false, "description": "Channel to use" }, - "channelProperties": { "index": 1, "kind": "property", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Specifies configuration properties of the JChannel used by the endpoint." }, + "channelProperties": { "index": 1, "kind": "property", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The JGroups configuration of the JChannel that each endpoint creates, as an XML file, a URL or a classpath resource. If neither this option nor the channel option is set, the default udp.xml in the JGroups JAR is used, an [...] "bridgeErrorHandler": { "index": 2, "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the like [...] "enableViewMessages": { "index": 3, "kind": "property", "displayName": "Enable View Messages", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If set to true, the consumer endpoint will receive org.jgroups.View messages as well (not only org.jgroups.Message instances). By default only regular messages are consumed by the endpoint." }, "lazyStartProducer": { "index": 4, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...] @@ -46,7 +46,7 @@ }, "properties": { "clusterName": { "index": 0, "kind": "path", "displayName": "Cluster Name", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The name of the JGroups cluster the component should connect to." }, - "channelProperties": { "index": 1, "kind": "parameter", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Specifies configuration properties of the JChannel used by the endpoint." }, + "channelProperties": { "index": 1, "kind": "parameter", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The JGroups configuration of the JChannel that the endpoint creates, as an XML file, a URL or a classpath resource. If not set, the channelProperties of the component is used. If neither is set and the component has no c [...] "enableViewMessages": { "index": 2, "kind": "parameter", "displayName": "Enable View Messages", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If set to true, the consumer endpoint will receive org.jgroups.View messages as well (not only org.jgroups.Message instances). By default only regular messages are consumed by the endpoint." }, "bridgeErrorHandler": { "index": 3, "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming [...] "exceptionHandler": { "index": 4, "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By def [...] diff --git a/components/camel-jgroups/src/main/docs/jgroups-component.adoc b/components/camel-jgroups/src/main/docs/jgroups-component.adoc index e75c9ad64acd..8917092d206c 100644 --- a/components/camel-jgroups/src/main/docs/jgroups-component.adoc +++ b/components/camel-jgroups/src/main/docs/jgroups-component.adoc @@ -58,6 +58,10 @@ The default JGroups protocol stack (`udp.xml`) multicasts over UDP and does multicast group or bind port can join and send messages. Treat cluster peers as part of your trust boundary and harden the deployment accordingly. +The endpoint uses this default stack when neither the `channelProperties` option +nor the `channel` option of the component is set, and then logs a WARN when it +starts: the default stack is meant for development and tests. + * *Authenticate and encrypt the channel.* Supply a hardened JGroups configuration through the `channelProperties` option and add the `AUTH` protocol together with `SYM_ENCRYPT` or `ASYM_ENCRYPT`, so that only trusted diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsComponent.java b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsComponent.java index 8ac4ed72cbe8..222b3204acc6 100644 --- a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsComponent.java +++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsComponent.java @@ -98,7 +98,11 @@ public class JGroupsComponent extends DefaultComponent { } /** - * Specifies configuration properties of the JChannel used by the endpoint. + * The JGroups configuration of the JChannel that each endpoint creates, as an XML file, a URL or a classpath + * resource. If neither this option nor the channel option is set, the default udp.xml in the JGroups JAR is used, + * and a WARN is logged when an endpoint starts. That udp.xml is meant for development and tests: it uses UDP + * multicast without authentication or encryption. In production, set your own configuration, with AUTH and + * SYM_ENCRYPT or ASYM_ENCRYPT. */ public void setChannelProperties(String channelProperties) { this.channelProperties = channelProperties; diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java index f78e0edb68ed..82f3ffab53c3 100644 --- a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java +++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java @@ -275,6 +275,11 @@ public class JGroupsEndpoint extends DefaultEndpoint { if (channelProperties != null && !channelProperties.isEmpty()) { return new JChannel(channelProperties); } + LOG.warn("The JGroups endpoint {} has no channel and no channelProperties, so its channel uses the default udp.xml" + + " in the JGroups JAR. That configuration is meant for development and tests: it uses UDP multicast" + + " without authentication or encryption. In production, set channelProperties to your own JGroups" + + " configuration, with AUTH and SYM_ENCRYPT or ASYM_ENCRYPT.", + getEndpointUri()); return new JChannel(); } @@ -355,7 +360,11 @@ public class JGroupsEndpoint extends DefaultEndpoint { } /** - * Specifies configuration properties of the JChannel used by the endpoint. + * The JGroups configuration of the JChannel that the endpoint creates, as an XML file, a URL or a classpath + * resource. If not set, the channelProperties of the component is used. If neither is set and the component has no + * channel, the default udp.xml in the JGroups JAR is used, and a WARN is logged when the endpoint starts. That + * udp.xml is meant for development and tests: it uses UDP multicast without authentication or encryption. In + * production, set your own configuration, with AUTH and SYM_ENCRYPT or ASYM_ENCRYPT. */ public void setChannelProperties(String channelProperties) { this.channelProperties = channelProperties; diff --git a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsDefaultChannelWarningTest.java b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsDefaultChannelWarningTest.java new file mode 100644 index 000000000000..69e15c8689e6 --- /dev/null +++ b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsDefaultChannelWarningTest.java @@ -0,0 +1,90 @@ +/* + * 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; + +import java.util.UUID; + +import org.apache.camel.impl.DefaultCamelContext; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Without channel and channelProperties, the endpoint uses the default udp.xml of the JGroups JAR, meant for + * development and tests, and logs a WARN when it starts. + */ +class JGroupsDefaultChannelWarningTest { + + private final String id = UUID.randomUUID().toString(); + private WarnCapture capture; + private DefaultCamelContext context; + + @BeforeEach + void start() { + capture = new WarnCapture(JGroupsEndpoint.class); + context = new DefaultCamelContext(); + context.disableJMX(); + context.start(); + } + + @AfterEach + void stop() { + try { + context.stop(); + } finally { + capture.close(); + } + } + + @Test + void warnsWithoutChannelProperties() { + String clusterName = "default-" + id; + + // the endpoint starts (and creates its channel, without connecting it) when it is added to the started context + JGroupsEndpoint endpoint = context.getEndpoint("jgroups:" + clusterName, JGroupsEndpoint.class); + // the same endpoint again: it is started once + context.getEndpoint("jgroups:" + clusterName, JGroupsEndpoint.class); + + assertNotNull(endpoint.getResolvedChannel()); + assertEquals(1, capture.count(clusterName), capture.warnings()::toString); + assertEquals(1, capture.count(clusterName, "udp.xml"), capture.warnings()::toString); + } + + @Test + void noWarningWithChannelPropertiesOfEndpoint() { + String clusterName = "endpoint-" + id; + + context.getEndpoint("jgroups:" + clusterName + "?channelProperties=udp.xml", JGroupsEndpoint.class); + + assertEquals(0, capture.count(clusterName), capture.warnings()::toString); + } + + @Test + void noWarningWithChannelPropertiesOfComponent() { + String clusterName = "component-" + id; + JGroupsComponent component = new JGroupsComponent(); + component.setChannelProperties("udp.xml"); + context.addComponent("my-jgroups", component); + + context.getEndpoint("my-jgroups:" + clusterName, JGroupsEndpoint.class); + + assertEquals(0, capture.count(clusterName), capture.warnings()::toString); + } +} diff --git a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/WarnCapture.java b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/WarnCapture.java new file mode 100644 index 000000000000..1e0a589ae003 --- /dev/null +++ b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/WarnCapture.java @@ -0,0 +1,79 @@ +/* + * 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; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.TimeUnit; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.Logger; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.Property; + +import static org.awaitility.Awaitility.await; + +/** + * Captures the WARN messages of the logger of a class, while it is open. + */ +public final class WarnCapture implements AutoCloseable { + + private final Logger logger; + private final List<String> warnings = new CopyOnWriteArrayList<>(); + private final AbstractAppender appender; + + public WarnCapture(Class<?> type) { + logger = (Logger) LogManager.getLogger(type); + appender = new AbstractAppender("WarnCapture-" + UUID.randomUUID(), null, null, true, Property.EMPTY_ARRAY) { + @Override + public void append(LogEvent event) { + if (event.getLevel() == Level.WARN) { + warnings.add(event.getMessage().getFormattedMessage()); + } + } + }; + // the test classes may run in parallel: while another one is still starting log4j, the logger has the default + // configuration, which log4j replaces once it has read log4j2.properties, and an appender attached to it is + // stopped and lost, so attach it once log4j has started + await().atMost(30, TimeUnit.SECONDS).until(logger.getContext()::isStarted); + appender.start(); + logger.addAppender(appender); + // addAppender creates a non-additive logger config, which would hide this logger from the root appenders + logger.setAdditive(true); + } + + /** + * The number of WARN messages that contain all the texts. + */ + public long count(String... texts) { + return warnings.stream().filter(message -> Arrays.stream(texts).allMatch(message::contains)).count(); + } + + public List<String> warnings() { + return warnings; + } + + @Override + public void close() { + logger.removeAppender(appender); + appender.stop(); + } +} diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc index 25708c2cd51b..429df8289d5a 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc @@ -12297,6 +12297,14 @@ With `allowUrlBody=true`, a body that does not start with `version: 1` and is no with a space or a relative name, now fails with an `InvalidPayloadException`, as a URL with an unknown scheme already did. Before, it failed with an `IllegalArgumentException`. A URL that cannot be fetched keeps its own exception. +=== camel-jgroups-raft, camel-jgroups - a WARN when the default channel configuration is used + +An endpoint without the `channelProperties` option now logs a WARN when it starts: `jgroups-raft` then uses the +`raft.xml` of the `camel-jgroups-raft` JAR (also the default `jgroupsConfig` of the `JGroupsRaftClusterService`), and +`jgroups` (without a `channel` on the component) the default `udp.xml` of JGroups. These configurations use UDP +multicast without authentication or encryption, and are meant for development and tests. Nothing else changes: set +`channelProperties` to your own JGroups configuration to remove the WARN. + === Kamelets - removed Kamelets The Kamelet catalog (camel-kamelets 4.24) removes Kamelets that could not work on Camel 4.23 or 4.24: diff --git a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/JgroupsComponentBuilderFactory.java b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/JgroupsComponentBuilderFactory.java index 267704a0b8fc..88c057667925 100644 --- a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/JgroupsComponentBuilderFactory.java +++ b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/JgroupsComponentBuilderFactory.java @@ -66,8 +66,13 @@ public interface JgroupsComponentBuilderFactory { } /** - * Specifies configuration properties of the JChannel used by the - * endpoint. + * The JGroups configuration of the JChannel that each endpoint creates, + * as an XML file, a URL or a classpath resource. If neither this option + * nor the channel option is set, the default udp.xml in the JGroups JAR + * is used, and a WARN is logged when an endpoint starts. That udp.xml + * is meant for development and tests: it uses UDP multicast without + * authentication or encryption. In production, set your own + * configuration, with AUTH and SYM_ENCRYPT or ASYM_ENCRYPT. * * The option is a: <code>java.lang.String</code> type. * diff --git a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/JgroupsRaftComponentBuilderFactory.java b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/JgroupsRaftComponentBuilderFactory.java index 426ba9f28b2e..a3c91b1aebe6 100644 --- a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/JgroupsRaftComponentBuilderFactory.java +++ b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/JgroupsRaftComponentBuilderFactory.java @@ -56,8 +56,13 @@ public interface JgroupsRaftComponentBuilderFactory { /** * The JGroups XML configuration of the JChannel that each endpoint * creates, as a file, a URL or a classpath resource. If not set, the - * raft.xml in the camel-jgroups-raft JAR is used, which lists A as the - * only RAFT member. Not used when the raftHandle option is set. + * raft.xml in the camel-jgroups-raft JAR is used, and a WARN is logged + * when an endpoint starts. That raft.xml is a sample for development + * and tests: it uses UDP multicast without authentication or + * encryption, and lists A as the only RAFT member. In production, set + * your own configuration, with AUTH and SYM_ENCRYPT or ASYM_ENCRYPT, + * and the members of the cluster in the members attribute of RAFT. Not + * used when the raftHandle option is set. * * The option is a: <code>java.lang.String</code> type. * diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JGroupsEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JGroupsEndpointBuilderFactory.java index 2d6b01aa5ca2..48976b6b01af 100644 --- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JGroupsEndpointBuilderFactory.java +++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JGroupsEndpointBuilderFactory.java @@ -44,8 +44,14 @@ public interface JGroupsEndpointBuilderFactory { return (AdvancedJGroupsEndpointConsumerBuilder) this; } /** - * Specifies configuration properties of the JChannel used by the - * endpoint. + * The JGroups configuration of the JChannel that the endpoint creates, + * as an XML file, a URL or a classpath resource. If not set, the + * channelProperties of the component is used. If neither is set and the + * component has no channel, the default udp.xml in the JGroups JAR is + * used, and a WARN is logged when the endpoint starts. That udp.xml is + * meant for development and tests: it uses UDP multicast without + * authentication or encryption. In production, set your own + * configuration, with AUTH and SYM_ENCRYPT or ASYM_ENCRYPT. * * The option is a: <code>java.lang.String</code> type. * @@ -303,8 +309,14 @@ public interface JGroupsEndpointBuilderFactory { } /** - * Specifies configuration properties of the JChannel used by the - * endpoint. + * The JGroups configuration of the JChannel that the endpoint creates, + * as an XML file, a URL or a classpath resource. If not set, the + * channelProperties of the component is used. If neither is set and the + * component has no channel, the default udp.xml in the JGroups JAR is + * used, and a WARN is logged when the endpoint starts. That udp.xml is + * meant for development and tests: it uses UDP multicast without + * authentication or encryption. In production, set your own + * configuration, with AUTH and SYM_ENCRYPT or ASYM_ENCRYPT. * * The option is a: <code>java.lang.String</code> type. * @@ -387,8 +399,14 @@ public interface JGroupsEndpointBuilderFactory { } /** - * Specifies configuration properties of the JChannel used by the - * endpoint. + * The JGroups configuration of the JChannel that the endpoint creates, + * as an XML file, a URL or a classpath resource. If not set, the + * channelProperties of the component is used. If neither is set and the + * component has no channel, the default udp.xml in the JGroups JAR is + * used, and a WARN is logged when the endpoint starts. That udp.xml is + * meant for development and tests: it uses UDP multicast without + * authentication or encryption. In production, set your own + * configuration, with AUTH and SYM_ENCRYPT or ASYM_ENCRYPT. * * The option is a: <code>java.lang.String</code> type. * diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JGroupsRaftEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JGroupsRaftEndpointBuilderFactory.java index 2fe8e60d2482..9888f81a7f46 100644 --- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JGroupsRaftEndpointBuilderFactory.java +++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JGroupsRaftEndpointBuilderFactory.java @@ -48,8 +48,13 @@ public interface JGroupsRaftEndpointBuilderFactory { * The JGroups XML configuration of the JChannel that the endpoint * creates, as a file, a URL or a classpath resource. If not set, the * channelProperties of the component is used, else the raft.xml in the - * camel-jgroups-raft JAR, which lists A as the only RAFT member. Not - * used when the raftHandle option is set. + * camel-jgroups-raft JAR, and a WARN is logged when the endpoint + * starts. That raft.xml is a sample for development and tests: it uses + * UDP multicast without authentication or encryption, and lists A as + * the only RAFT member. In production, set your own configuration, with + * AUTH and SYM_ENCRYPT or ASYM_ENCRYPT, and the members of the cluster + * in the members attribute of RAFT. Not used when the raftHandle option + * is set. * * The option is a: <code>java.lang.String</code> type. * @@ -337,8 +342,13 @@ public interface JGroupsRaftEndpointBuilderFactory { * The JGroups XML configuration of the JChannel that the endpoint * creates, as a file, a URL or a classpath resource. If not set, the * channelProperties of the component is used, else the raft.xml in the - * camel-jgroups-raft JAR, which lists A as the only RAFT member. Not - * used when the raftHandle option is set. + * camel-jgroups-raft JAR, and a WARN is logged when the endpoint + * starts. That raft.xml is a sample for development and tests: it uses + * UDP multicast without authentication or encryption, and lists A as + * the only RAFT member. In production, set your own configuration, with + * AUTH and SYM_ENCRYPT or ASYM_ENCRYPT, and the members of the cluster + * in the members attribute of RAFT. Not used when the raftHandle option + * is set. * * The option is a: <code>java.lang.String</code> type. * @@ -517,8 +527,13 @@ public interface JGroupsRaftEndpointBuilderFactory { * The JGroups XML configuration of the JChannel that the endpoint * creates, as a file, a URL or a classpath resource. If not set, the * channelProperties of the component is used, else the raft.xml in the - * camel-jgroups-raft JAR, which lists A as the only RAFT member. Not - * used when the raftHandle option is set. + * camel-jgroups-raft JAR, and a WARN is logged when the endpoint + * starts. That raft.xml is a sample for development and tests: it uses + * UDP multicast without authentication or encryption, and lists A as + * the only RAFT member. In production, set your own configuration, with + * AUTH and SYM_ENCRYPT or ASYM_ENCRYPT, and the members of the cluster + * in the members attribute of RAFT. Not used when the raftHandle option + * is set. * * The option is a: <code>java.lang.String</code> type. *
