From 5177d835fdcecb68c33536678b153d85994ef459 Mon Sep 17 00:00:00 2001 From: Gwenneg Lepage Date: Mon, 13 Nov 2023 08:14:23 +0100 Subject: [PATCH] Finish connectors migration to SEDA (#2333) --- .../connector/ConnectorConfig.java | 9 ------ .../EngineToConnectorRouteBuilder.java | 13 ++------- .../connector/ExceptionProcessor.java | 28 ++++++++----------- .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - 11 files changed, 14 insertions(+), 44 deletions(-) diff --git a/connector-common/src/main/java/com/redhat/cloud/notifications/connector/ConnectorConfig.java b/connector-common/src/main/java/com/redhat/cloud/notifications/connector/ConnectorConfig.java index fcdcde18f6..35ea8054d1 100644 --- a/connector-common/src/main/java/com/redhat/cloud/notifications/connector/ConnectorConfig.java +++ b/connector-common/src/main/java/com/redhat/cloud/notifications/connector/ConnectorConfig.java @@ -27,7 +27,6 @@ public class ConnectorConfig { private static final String REDELIVERY_DELAY = "notifications.connector.redelivery.delay"; private static final String REDELIVERY_MAX_ATTEMPTS = "notifications.connector.redelivery.max-attempts"; private static final String SEDA_CONCURRENT_CONSUMERS = "notifications.connector.seda.concurrent-consumers"; - private static final String SEDA_ENABLED = "notifications.connector.seda.enabled"; private static final String SEDA_QUEUE_SIZE = "notifications.connector.seda.queue-size"; @ConfigProperty(name = ENDPOINT_CACHE_MAX_SIZE, defaultValue = "100") @@ -69,9 +68,6 @@ public class ConnectorConfig { @ConfigProperty(name = SEDA_CONCURRENT_CONSUMERS, defaultValue = "1") int sedaConcurrentConsumers; - @ConfigProperty(name = SEDA_ENABLED, defaultValue = "false") - boolean sedaEnabled; - // https://camel.apache.org/components/4.0.x/seda-component.html#_component_option_queueSize @ConfigProperty(name = SEDA_QUEUE_SIZE, defaultValue = "1000") int sedaQueueSize; @@ -95,7 +91,6 @@ protected void log(Map additionalConfig) { config.put(REDELIVERY_DELAY, redeliveryDelay); config.put(REDELIVERY_MAX_ATTEMPTS, redeliveryMaxAttempts); config.put(SEDA_CONCURRENT_CONSUMERS, sedaConcurrentConsumers); - config.put(SEDA_ENABLED, sedaEnabled); config.put(SEDA_QUEUE_SIZE, sedaQueueSize); config.putAll(additionalConfig); @@ -153,10 +148,6 @@ public int getSedaConcurrentConsumers() { return sedaConcurrentConsumers; } - public boolean isSedaEnabled() { - return sedaEnabled; - } - public int getSedaQueueSize() { return sedaQueueSize; } diff --git a/connector-common/src/main/java/com/redhat/cloud/notifications/connector/EngineToConnectorRouteBuilder.java b/connector-common/src/main/java/com/redhat/cloud/notifications/connector/EngineToConnectorRouteBuilder.java index caecba54f6..08de0023fd 100644 --- a/connector-common/src/main/java/com/redhat/cloud/notifications/connector/EngineToConnectorRouteBuilder.java +++ b/connector-common/src/main/java/com/redhat/cloud/notifications/connector/EngineToConnectorRouteBuilder.java @@ -46,9 +46,7 @@ public void configure() throws Exception { .handled(true) .process(exceptionProcessor); - if (connectorConfig.isSedaEnabled()) { - configureSedaComponent(); - } + configureSedaComponent(); from(buildKafkaEndpoint()) .routeId(ENGINE_TO_CONNECTOR) @@ -58,14 +56,7 @@ public void configure() throws Exception { .removeHeaders("*") .process(incomingCloudEventProcessor) .to(log(getClass().getName()).level("DEBUG").showProperties(true)) - // TODO The following lines should be removed when all connectors are migrated to SEDA. - .choice() - .when(exchange -> connectorConfig.isSedaEnabled()) - .to(seda(ENGINE_TO_CONNECTOR)) - .endChoice() - .otherwise() - .to(direct(ENGINE_TO_CONNECTOR)) - .end(); + .to(seda(ENGINE_TO_CONNECTOR)); configureRoute(); } diff --git a/connector-common/src/main/java/com/redhat/cloud/notifications/connector/ExceptionProcessor.java b/connector-common/src/main/java/com/redhat/cloud/notifications/connector/ExceptionProcessor.java index 1402f58a46..56bf458cc3 100644 --- a/connector-common/src/main/java/com/redhat/cloud/notifications/connector/ExceptionProcessor.java +++ b/connector-common/src/main/java/com/redhat/cloud/notifications/connector/ExceptionProcessor.java @@ -47,22 +47,18 @@ public void process(Exchange exchange) { process(t, exchange); - if (connectorConfig.isSedaEnabled()) { - /* - * There is currently a bug in Camel that will cause a NullPointerException throw when SEDA is used and the - * exchange is passed to producerTemplate#send. To work around that bug, we're cloning the current exchange - * and removing all Camel internal properties related to the exception that is being processed. - */ - Exchange exchangeCopy = exchange.copy(); - exchangeCopy.removeProperty(ERRORHANDLER_BRIDGE); - exchangeCopy.removeProperty(EXCEPTION_CAUGHT); - exchangeCopy.removeProperty(FAILURE_ENDPOINT); - exchangeCopy.removeProperty(FAILURE_ROUTE_ID); - exchangeCopy.removeProperty(FATAL_FALLBACK_ERROR_HANDLER); - producerTemplate.send("direct:" + CONNECTOR_TO_ENGINE, exchangeCopy); - } else { - producerTemplate.send("direct:" + CONNECTOR_TO_ENGINE, exchange); - } + /* + * There is currently a bug in Camel that will cause a NullPointerException throw when SEDA is used and the + * exchange is passed to producerTemplate#send. To work around that bug, we're cloning the current exchange + * and removing all Camel internal properties related to the exception that is being processed. + */ + Exchange exchangeCopy = exchange.copy(); + exchangeCopy.removeProperty(ERRORHANDLER_BRIDGE); + exchangeCopy.removeProperty(EXCEPTION_CAUGHT); + exchangeCopy.removeProperty(FAILURE_ENDPOINT); + exchangeCopy.removeProperty(FAILURE_ROUTE_ID); + exchangeCopy.removeProperty(FATAL_FALLBACK_ERROR_HANDLER); + producerTemplate.send("direct:" + CONNECTOR_TO_ENGINE, exchangeCopy); } protected final void logDefault(Throwable t, Exchange exchange) { diff --git a/connector-drawer/src/main/resources/application.properties b/connector-drawer/src/main/resources/application.properties index 59e5c30796..a2b1ab0a72 100644 --- a/connector-drawer/src/main/resources/application.properties +++ b/connector-drawer/src/main/resources/application.properties @@ -6,7 +6,6 @@ notifications.connector.redelivery.counter-name=camel.drawer.retry.counter # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.concurrent-consumers=20 -notifications.connector.seda.enabled=true # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.queue-size=20 diff --git a/connector-email/src/main/resources/application.properties b/connector-email/src/main/resources/application.properties index 1d249b059a..4271d39d0f 100644 --- a/connector-email/src/main/resources/application.properties +++ b/connector-email/src/main/resources/application.properties @@ -5,7 +5,6 @@ notifications.connector.name=email_subscription notifications.connector.redelivery.counter-name=camel.email.retry.counter # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.concurrent-consumers=20 -notifications.connector.seda.enabled=true # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.queue-size=20 diff --git a/connector-google-chat/src/main/resources/application.properties b/connector-google-chat/src/main/resources/application.properties index ae13f93ccf..af16733516 100644 --- a/connector-google-chat/src/main/resources/application.properties +++ b/connector-google-chat/src/main/resources/application.properties @@ -5,7 +5,6 @@ notifications.connector.name=google_chat notifications.connector.redelivery.counter-name=camel.google.chat.retry.counter # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.concurrent-consumers=20 -notifications.connector.seda.enabled=true # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.queue-size=20 diff --git a/connector-microsoft-teams/src/main/resources/application.properties b/connector-microsoft-teams/src/main/resources/application.properties index 0bf369970f..58d3ed2a00 100644 --- a/connector-microsoft-teams/src/main/resources/application.properties +++ b/connector-microsoft-teams/src/main/resources/application.properties @@ -5,7 +5,6 @@ notifications.connector.name=teams notifications.connector.redelivery.counter-name=camel.teams.retry.counter # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.concurrent-consumers=20 -notifications.connector.seda.enabled=true # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.queue-size=20 diff --git a/connector-servicenow/src/main/resources/application.properties b/connector-servicenow/src/main/resources/application.properties index 577b8de169..7a9b8481f4 100644 --- a/connector-servicenow/src/main/resources/application.properties +++ b/connector-servicenow/src/main/resources/application.properties @@ -5,7 +5,6 @@ notifications.connector.name=servicenow notifications.connector.redelivery.counter-name=camel.servicenow.retry.counter # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.concurrent-consumers=20 -notifications.connector.seda.enabled=true # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.queue-size=20 diff --git a/connector-slack/src/main/resources/application.properties b/connector-slack/src/main/resources/application.properties index 5eb2732988..ab74543053 100644 --- a/connector-slack/src/main/resources/application.properties +++ b/connector-slack/src/main/resources/application.properties @@ -5,7 +5,6 @@ notifications.connector.name=slack notifications.connector.redelivery.counter-name=camel.slack.retry.counter # The following value matches the default size of the OkHttp connection pool. notifications.connector.seda.concurrent-consumers=5 -notifications.connector.seda.enabled=true # The following value matches the default size of the OkHttp connection pool. notifications.connector.seda.queue-size=5 diff --git a/connector-splunk/src/main/resources/application.properties b/connector-splunk/src/main/resources/application.properties index 3e0178c29d..a2151ce405 100644 --- a/connector-splunk/src/main/resources/application.properties +++ b/connector-splunk/src/main/resources/application.properties @@ -5,7 +5,6 @@ notifications.connector.name=splunk notifications.connector.redelivery.counter-name=camel.splunk.retry.counter # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.concurrent-consumers=20 -notifications.connector.seda.enabled=true # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.queue-size=20 diff --git a/connector-webhook/src/main/resources/application.properties b/connector-webhook/src/main/resources/application.properties index d384a6c8cd..ae097db1ab 100644 --- a/connector-webhook/src/main/resources/application.properties +++ b/connector-webhook/src/main/resources/application.properties @@ -6,7 +6,6 @@ notifications.connector.redelivery.counter-name=camel.webhook.retry.counter notifications.connector.alternative.names=ansible # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.concurrent-consumers=20 -notifications.connector.seda.enabled=true # The following value matches the default value of the `connectionsPerRoute` option from the Camel `http` component. notifications.connector.seda.queue-size=20