This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 0a26d0b CAMEL-15561 - Camel-AWS2-Eventbridge: More producer operations 0a26d0b is described below commit 0a26d0b30e2f53d56ab503accca9678eaae78e53 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Tue Sep 22 12:30:56 2020 +0200 CAMEL-15561 - Camel-AWS2-Eventbridge: More producer operations --- .../catalog/docs/aws2-eventbridge-component.adoc | 4 +- .../aws2/eventbridge/aws2-eventbridge.json | 4 +- .../src/main/docs/aws2-eventbridge-component.adoc | 4 +- .../aws2/eventbridge/EventbridgeConstants.java | 1 + .../aws2/eventbridge/EventbridgeOperations.java | 3 +- .../aws2/eventbridge/EventbridgeProducer.java | 44 ++++++++++++++++++++++ .../dsl/EventbridgeEndpointBuilderFactory.java | 3 +- .../ROOT/pages/aws2-eventbridge-component.adoc | 4 +- 8 files changed, 57 insertions(+), 10 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws2-eventbridge-component.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws2-eventbridge-component.adoc index 3d0b2e5..a681327 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws2-eventbridge-component.adoc +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws2-eventbridge-component.adoc @@ -59,7 +59,7 @@ The AWS 2 Eventbridge component supports 16 options, which are listed below. | *eventbusName* (producer) | The eventbus name, the default value is default and this means it will be the AWS event bus of your account. | default | String | *eventPatternFile* (producer) | EventPattern File | | String | *lazyStartProducer* (producer) | 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 during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] -| *operation* (producer) | *Required* The operation to perform. There are 2 enums and the value can be one of: putRule, putTargets | putRule | EventbridgeOperations +| *operation* (producer) | *Required* The operation to perform. There are 3 enums and the value can be one of: putRule, putTargets, removeTargets | putRule | EventbridgeOperations | *pojoRequest* (producer) | If we want to use a POJO request as body or not | false | boolean | *proxyHost* (producer) | To define a proxy host when instantiating the Eventbridge client | | String | *proxyPort* (producer) | To define a proxy port when instantiating the Eventbridge client | | Integer @@ -105,7 +105,7 @@ with the following path and query parameters: | *eventbusName* (producer) | The eventbus name, the default value is default and this means it will be the AWS event bus of your account. | default | String | *eventPatternFile* (producer) | EventPattern File | | String | *lazyStartProducer* (producer) | 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 during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] -| *operation* (producer) | *Required* The operation to perform. There are 2 enums and the value can be one of: putRule, putTargets | putRule | EventbridgeOperations +| *operation* (producer) | *Required* The operation to perform. There are 3 enums and the value can be one of: putRule, putTargets, removeTargets | putRule | EventbridgeOperations | *pojoRequest* (producer) | If we want to use a POJO request as body or not | false | boolean | *proxyHost* (producer) | To define a proxy host when instantiating the Eventbridge client | | String | *proxyPort* (producer) | To define a proxy port when instantiating the Eventbridge client | | Integer diff --git a/components/camel-aws2-eventbridge/src/generated/resources/org/apache/camel/component/aws2/eventbridge/aws2-eventbridge.json b/components/camel-aws2-eventbridge/src/generated/resources/org/apache/camel/component/aws2/eventbridge/aws2-eventbridge.json index 4664ef3..787ca71 100644 --- a/components/camel-aws2-eventbridge/src/generated/resources/org/apache/camel/component/aws2/eventbridge/aws2-eventbridge.json +++ b/components/camel-aws2-eventbridge/src/generated/resources/org/apache/camel/component/aws2/eventbridge/aws2-eventbridge.json @@ -28,7 +28,7 @@ "eventbusName": { "kind": "property", "displayName": "Eventbus Name", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "defaultValue": "default", "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", "description": "The eventbus name, the default value is default and this means it will be the AWS event bus of your a [...] "eventPatternFile": { "kind": "property", "displayName": "Event Pattern File", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", "description": "EventPattern File" }, "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": 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 during starting and cause the r [...] - "operation": { "kind": "property", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws2.eventbridge.EventbridgeOperations", "enum": [ "putRule", "putTargets" ], "deprecated": false, "deprecationNote": "", "secret": false, "defaultValue": "putRule", "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", "description": " [...] + "operation": { "kind": "property", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws2.eventbridge.EventbridgeOperations", "enum": [ "putRule", "putTargets", "removeTargets" ], "deprecated": false, "deprecationNote": "", "secret": false, "defaultValue": "putRule", "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", [...] "pojoRequest": { "kind": "property", "displayName": "Pojo Request", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "false", "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", "description": "If we want to use a POJO request as body or not" }, "proxyHost": { "kind": "property", "displayName": "Proxy Host", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the Eventbridge client" }, "proxyPort": { "kind": "property", "displayName": "Proxy Port", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", "description": "To define a proxy port when instantiating the Eventbridge client" }, @@ -46,7 +46,7 @@ "eventbusName": { "kind": "parameter", "displayName": "Eventbus Name", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "defaultValue": "default", "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", "description": "The eventbus name, the default value is default and this means it will be the AWS event bus of your [...] "eventPatternFile": { "kind": "parameter", "displayName": "Event Pattern File", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", "description": "EventPattern File" }, "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": 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 during starting and cause the [...] - "operation": { "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws2.eventbridge.EventbridgeOperations", "enum": [ "putRule", "putTargets" ], "deprecated": false, "deprecationNote": "", "secret": false, "defaultValue": "putRule", "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", "description": [...] + "operation": { "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws2.eventbridge.EventbridgeOperations", "enum": [ "putRule", "putTargets", "removeTargets" ], "deprecated": false, "deprecationNote": "", "secret": false, "defaultValue": "putRule", "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration" [...] "pojoRequest": { "kind": "parameter", "displayName": "Pojo Request", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "false", "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", "description": "If we want to use a POJO request as body or not" }, "proxyHost": { "kind": "parameter", "displayName": "Proxy Host", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the Eventbridge client" }, "proxyPort": { "kind": "parameter", "displayName": "Proxy Port", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.eventbridge.EventbridgeConfiguration", "configurationField": "configuration", "description": "To define a proxy port when instantiating the Eventbridge client" }, diff --git a/components/camel-aws2-eventbridge/src/main/docs/aws2-eventbridge-component.adoc b/components/camel-aws2-eventbridge/src/main/docs/aws2-eventbridge-component.adoc index 3d0b2e5..a681327 100644 --- a/components/camel-aws2-eventbridge/src/main/docs/aws2-eventbridge-component.adoc +++ b/components/camel-aws2-eventbridge/src/main/docs/aws2-eventbridge-component.adoc @@ -59,7 +59,7 @@ The AWS 2 Eventbridge component supports 16 options, which are listed below. | *eventbusName* (producer) | The eventbus name, the default value is default and this means it will be the AWS event bus of your account. | default | String | *eventPatternFile* (producer) | EventPattern File | | String | *lazyStartProducer* (producer) | 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 during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] -| *operation* (producer) | *Required* The operation to perform. There are 2 enums and the value can be one of: putRule, putTargets | putRule | EventbridgeOperations +| *operation* (producer) | *Required* The operation to perform. There are 3 enums and the value can be one of: putRule, putTargets, removeTargets | putRule | EventbridgeOperations | *pojoRequest* (producer) | If we want to use a POJO request as body or not | false | boolean | *proxyHost* (producer) | To define a proxy host when instantiating the Eventbridge client | | String | *proxyPort* (producer) | To define a proxy port when instantiating the Eventbridge client | | Integer @@ -105,7 +105,7 @@ with the following path and query parameters: | *eventbusName* (producer) | The eventbus name, the default value is default and this means it will be the AWS event bus of your account. | default | String | *eventPatternFile* (producer) | EventPattern File | | String | *lazyStartProducer* (producer) | 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 during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] -| *operation* (producer) | *Required* The operation to perform. There are 2 enums and the value can be one of: putRule, putTargets | putRule | EventbridgeOperations +| *operation* (producer) | *Required* The operation to perform. There are 3 enums and the value can be one of: putRule, putTargets, removeTargets | putRule | EventbridgeOperations | *pojoRequest* (producer) | If we want to use a POJO request as body or not | false | boolean | *proxyHost* (producer) | To define a proxy host when instantiating the Eventbridge client | | String | *proxyPort* (producer) | To define a proxy port when instantiating the Eventbridge client | | Integer diff --git a/components/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeConstants.java b/components/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeConstants.java index 100e8ba..0d84b7f 100644 --- a/components/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeConstants.java +++ b/components/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeConstants.java @@ -24,4 +24,5 @@ public interface EventbridgeConstants { String RULE_NAME = "CamelAwsEventbridgeRuleName"; String EVENT_PATTERN = "CamelAwsEventbridgeEventPattern"; String TARGETS = "CamelAwsEventbridgeTargets"; + String TARGETS_IDS = "CamelAwsEventbridgeTargetsIds"; } diff --git a/components/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeOperations.java b/components/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeOperations.java index 903c4de..ad29052 100644 --- a/components/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeOperations.java +++ b/components/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeOperations.java @@ -19,5 +19,6 @@ package org.apache.camel.component.aws2.eventbridge; public enum EventbridgeOperations { putRule, - putTargets + putTargets, + removeTargets } diff --git a/components/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeProducer.java b/components/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeProducer.java index 610b862..149ee12 100644 --- a/components/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeProducer.java +++ b/components/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeProducer.java @@ -38,6 +38,8 @@ import software.amazon.awssdk.services.eventbridge.model.PutRuleRequest; import software.amazon.awssdk.services.eventbridge.model.PutRuleResponse; import software.amazon.awssdk.services.eventbridge.model.PutTargetsRequest; import software.amazon.awssdk.services.eventbridge.model.PutTargetsResponse; +import software.amazon.awssdk.services.eventbridge.model.RemoveTargetsRequest; +import software.amazon.awssdk.services.eventbridge.model.RemoveTargetsResponse; import software.amazon.awssdk.services.eventbridge.model.Target; /** @@ -63,6 +65,9 @@ public class EventbridgeProducer extends DefaultProducer { case putTargets: putTargets(getEndpoint().getEventbridgeClient(), exchange); break; + case removeTargets: + removeTargets(getEndpoint().getEventbridgeClient(), exchange); + break; default: throw new IllegalArgumentException("Unsupported operation"); } @@ -170,6 +175,45 @@ public class EventbridgeProducer extends DefaultProducer { } } + private void removeTargets(EventBridgeClient eventbridgeClient, Exchange exchange) throws InvalidPayloadException { + if (getConfiguration().isPojoRequest()) { + Object payload = exchange.getIn().getMandatoryBody(); + if (payload instanceof RemoveTargetsRequest) { + RemoveTargetsResponse result; + try { + result = eventbridgeClient.removeTargets((RemoveTargetsRequest) payload); + } catch (AwsServiceException ase) { + LOG.trace("RemoveTargets command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } else { + RemoveTargetsRequest.Builder builder = RemoveTargetsRequest.builder(); + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EventbridgeConstants.RULE_NAME))) { + String ruleName = exchange.getIn().getHeader(EventbridgeConstants.RULE_NAME, String.class); + builder.rule(ruleName); + } + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EventbridgeConstants.TARGETS_IDS))) { + Collection<String> ids = exchange.getIn().getHeader(EventbridgeConstants.TARGETS_IDS, Collection.class); + builder.ids(ids); + } else { + throw new IllegalArgumentException("At least one targets must be specified"); + } + builder.eventBusName(getConfiguration().getEventbusName()); + RemoveTargetsResponse result; + try { + result = eventbridgeClient.removeTargets(builder.build()); + } catch (AwsServiceException ase) { + LOG.trace("Remove Targets command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } + @Override public EventbridgeEndpoint getEndpoint() { return (EventbridgeEndpoint) super.getEndpoint(); diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/EventbridgeEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/EventbridgeEndpointBuilderFactory.java index a949184..8d79468 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/EventbridgeEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/EventbridgeEndpointBuilderFactory.java @@ -414,7 +414,8 @@ public interface EventbridgeEndpointBuilderFactory { */ enum EventbridgeOperations { putRule, - putTargets; + putTargets, + removeTargets; } /** diff --git a/docs/components/modules/ROOT/pages/aws2-eventbridge-component.adoc b/docs/components/modules/ROOT/pages/aws2-eventbridge-component.adoc index b1c1d78..21e2f44 100644 --- a/docs/components/modules/ROOT/pages/aws2-eventbridge-component.adoc +++ b/docs/components/modules/ROOT/pages/aws2-eventbridge-component.adoc @@ -61,7 +61,7 @@ The AWS 2 Eventbridge component supports 16 options, which are listed below. | *eventbusName* (producer) | The eventbus name, the default value is default and this means it will be the AWS event bus of your account. | default | String | *eventPatternFile* (producer) | EventPattern File | | String | *lazyStartProducer* (producer) | 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 during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] -| *operation* (producer) | *Required* The operation to perform. There are 2 enums and the value can be one of: putRule, putTargets | putRule | EventbridgeOperations +| *operation* (producer) | *Required* The operation to perform. There are 3 enums and the value can be one of: putRule, putTargets, removeTargets | putRule | EventbridgeOperations | *pojoRequest* (producer) | If we want to use a POJO request as body or not | false | boolean | *proxyHost* (producer) | To define a proxy host when instantiating the Eventbridge client | | String | *proxyPort* (producer) | To define a proxy port when instantiating the Eventbridge client | | Integer @@ -107,7 +107,7 @@ with the following path and query parameters: | *eventbusName* (producer) | The eventbus name, the default value is default and this means it will be the AWS event bus of your account. | default | String | *eventPatternFile* (producer) | EventPattern File | | String | *lazyStartProducer* (producer) | 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 during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] -| *operation* (producer) | *Required* The operation to perform. There are 2 enums and the value can be one of: putRule, putTargets | putRule | EventbridgeOperations +| *operation* (producer) | *Required* The operation to perform. There are 3 enums and the value can be one of: putRule, putTargets, removeTargets | putRule | EventbridgeOperations | *pojoRequest* (producer) | If we want to use a POJO request as body or not | false | boolean | *proxyHost* (producer) | To define a proxy host when instantiating the Eventbridge client | | String | *proxyPort* (producer) | To define a proxy port when instantiating the Eventbridge client | | Integer