You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/04/09 11:01:49 UTC

[camel] branch master updated (db60213 -> 504fef7)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from db60213  CAMEL-14864: Only generate configurer in core for core-engine and main.
     new 824d913  CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2
     new bed361a  CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 start instances
     new a87e08d  CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 stop instances
     new 3ce2d64   CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 terminate instances
     new a8a8806  CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 describe instances
     new 519b32e  CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 describe instance status
     new 45c6731  CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 reboot instances
     new bde80f9  CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 remaining operations
     new 5d80d88  Camel-AWS2-EC2: Fixed CS
     new 504fef7  CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 added a little test

The 10 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../aws2/ec2/AWS2EC2ComponentConfigurer.java       |   5 +
 .../aws2/ec2/AWS2EC2EndpointConfigurer.java        |   5 +
 .../apache/camel/component/aws2/ec2/aws2-ec2.json  |   2 +
 .../src/main/docs/aws2-ec2-component.adoc          |   6 +-
 .../component/aws2/ec2/AWS2EC2Configuration.java   |  13 +
 .../camel/component/aws2/ec2/AWS2EC2Producer.java  | 643 ++++++++++++++-------
 .../camel/component/aws2/ec2/EC2ProducerTest.java  |  18 +
 .../dsl/Aws2Ec2ComponentBuilderFactory.java        |  13 +
 .../src/generated/resources/metadata.json          |   3 +-
 .../dsl/AWS2EC2EndpointBuilderFactory.java         |  24 +
 .../modules/ROOT/pages/aws2-ec2-component.adoc     |   6 +-
 docs/components/modules/ROOT/pages/index.adoc      |   4 +-
 12 files changed, 509 insertions(+), 233 deletions(-)


[camel] 09/10: Camel-AWS2-EC2: Fixed CS

Posted by ac...@apache.org.
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

commit 5d80d88ff65a9dba471d4d0c025dc147bd8670ef
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 9 12:22:46 2020 +0200

    Camel-AWS2-EC2: Fixed CS
---
 .../camel/component/aws2/ec2/AWS2EC2Producer.java  | 70 +++++++++++-----------
 .../src/generated/resources/metadata.json          |  2 +-
 2 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
index 15238d4..c648910 100644
--- a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
+++ b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
@@ -72,41 +72,41 @@ public class AWS2EC2Producer extends DefaultProducer {
     @Override
     public void process(Exchange exchange) throws Exception {
         switch (determineOperation(exchange)) {
-        case createAndRunInstances:
-            createAndRunInstance(getEndpoint().getEc2Client(), exchange);
-            break;
-        case startInstances:
-            startInstances(getEndpoint().getEc2Client(), exchange);
-            break;
-        case stopInstances:
-            stopInstances(getEndpoint().getEc2Client(), exchange);
-            break;
-        case terminateInstances:
-            terminateInstances(getEndpoint().getEc2Client(), exchange);
-            break;
-        case describeInstances:
-            describeInstances(getEndpoint().getEc2Client(), exchange);
-            break;
-        case describeInstancesStatus:
-            describeInstancesStatus(getEndpoint().getEc2Client(), exchange);
-            break;
-        case rebootInstances:
-            rebootInstances(getEndpoint().getEc2Client(), exchange);
-            break;
-        case monitorInstances:
-            monitorInstances(getEndpoint().getEc2Client(), exchange);
-            break;
-        case unmonitorInstances:
-            unmonitorInstances(getEndpoint().getEc2Client(), exchange);
-            break;
-        case createTags:
-            createTags(getEndpoint().getEc2Client(), exchange);
-            break;
-        case deleteTags:
-            deleteTags(getEndpoint().getEc2Client(), exchange);
-            break;
-        default:
-            throw new IllegalArgumentException("Unsupported operation");
+            case createAndRunInstances:
+                createAndRunInstance(getEndpoint().getEc2Client(), exchange);
+                break;
+            case startInstances:
+                startInstances(getEndpoint().getEc2Client(), exchange);
+                break;
+            case stopInstances:
+                stopInstances(getEndpoint().getEc2Client(), exchange);
+                break;
+            case terminateInstances:
+                terminateInstances(getEndpoint().getEc2Client(), exchange);
+                break;
+            case describeInstances:
+                describeInstances(getEndpoint().getEc2Client(), exchange);
+                break;
+            case describeInstancesStatus:
+                describeInstancesStatus(getEndpoint().getEc2Client(), exchange);
+                break;
+            case rebootInstances:
+                rebootInstances(getEndpoint().getEc2Client(), exchange);
+                break;
+            case monitorInstances:
+                monitorInstances(getEndpoint().getEc2Client(), exchange);
+                break;
+            case unmonitorInstances:
+                unmonitorInstances(getEndpoint().getEc2Client(), exchange);
+                break;
+            case createTags:
+                createTags(getEndpoint().getEc2Client(), exchange);
+                break;
+            case deleteTags:
+                deleteTags(getEndpoint().getEc2Client(), exchange);
+                break;
+            default:
+                throw new IllegalArgumentException("Unsupported operation");
         }
     }
 
diff --git a/core/camel-componentdsl/src/generated/resources/metadata.json b/core/camel-componentdsl/src/generated/resources/metadata.json
index 8b42e4c..f43f7d6 100644
--- a/core/camel-componentdsl/src/generated/resources/metadata.json
+++ b/core/camel-componentdsl/src/generated/resources/metadata.json
@@ -480,7 +480,6 @@
     "lenientProperties": false,
     "javaType": "org.apache.camel.component.aws2.ec2.AWS2EC2Component",
     "firstVersion": "3.1.0",
-    "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-aws2-ec2",
     "version": "3.3.0-SNAPSHOT"
@@ -7599,6 +7598,7 @@
     "lenientProperties": false,
     "javaType": "org.apache.camel.component.zookeeper.ZooKeeperComponent",
     "firstVersion": "2.9.0",
+    "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-zookeeper",
     "version": "3.3.0-SNAPSHOT"


[camel] 04/10: CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 terminate instances

Posted by ac...@apache.org.
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

commit 3ce2d6450b193302592592c23d32a448df85893a
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 9 11:56:05 2020 +0200

     CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 terminate instances
---
 .../camel/component/aws2/ec2/AWS2EC2Producer.java  | 136 ++++++++++++---------
 .../src/generated/resources/metadata.json          |   2 +-
 .../modules/ROOT/pages/aws2-ec2-component.adoc     |   6 +-
 docs/components/modules/ROOT/pages/index.adoc      |   4 +-
 4 files changed, 83 insertions(+), 65 deletions(-)

diff --git a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
index 77733cd..43f10bb 100644
--- a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
+++ b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
@@ -72,41 +72,41 @@ public class AWS2EC2Producer extends DefaultProducer {
     @Override
     public void process(Exchange exchange) throws Exception {
         switch (determineOperation(exchange)) {
-            case createAndRunInstances:
-                createAndRunInstance(getEndpoint().getEc2Client(), exchange);
-                break;
-            case startInstances:
-                startInstances(getEndpoint().getEc2Client(), exchange);
-                break;
-            case stopInstances:
-                stopInstances(getEndpoint().getEc2Client(), exchange);
-                break;
-            case terminateInstances:
-                terminateInstances(getEndpoint().getEc2Client(), exchange);
-                break;
-            case describeInstances:
-                describeInstances(getEndpoint().getEc2Client(), exchange);
-                break;
-            case describeInstancesStatus:
-                describeInstancesStatus(getEndpoint().getEc2Client(), exchange);
-                break;
-            case rebootInstances:
-                rebootInstances(getEndpoint().getEc2Client(), exchange);
-                break;
-            case monitorInstances:
-                monitorInstances(getEndpoint().getEc2Client(), exchange);
-                break;
-            case unmonitorInstances:
-                unmonitorInstances(getEndpoint().getEc2Client(), exchange);
-                break;
-            case createTags:
-                createTags(getEndpoint().getEc2Client(), exchange);
-                break;
-            case deleteTags:
-                deleteTags(getEndpoint().getEc2Client(), exchange);
-                break;
-            default:
-                throw new IllegalArgumentException("Unsupported operation");
+        case createAndRunInstances:
+            createAndRunInstance(getEndpoint().getEc2Client(), exchange);
+            break;
+        case startInstances:
+            startInstances(getEndpoint().getEc2Client(), exchange);
+            break;
+        case stopInstances:
+            stopInstances(getEndpoint().getEc2Client(), exchange);
+            break;
+        case terminateInstances:
+            terminateInstances(getEndpoint().getEc2Client(), exchange);
+            break;
+        case describeInstances:
+            describeInstances(getEndpoint().getEc2Client(), exchange);
+            break;
+        case describeInstancesStatus:
+            describeInstancesStatus(getEndpoint().getEc2Client(), exchange);
+            break;
+        case rebootInstances:
+            rebootInstances(getEndpoint().getEc2Client(), exchange);
+            break;
+        case monitorInstances:
+            monitorInstances(getEndpoint().getEc2Client(), exchange);
+            break;
+        case unmonitorInstances:
+            unmonitorInstances(getEndpoint().getEc2Client(), exchange);
+            break;
+        case createTags:
+            createTags(getEndpoint().getEc2Client(), exchange);
+            break;
+        case deleteTags:
+            deleteTags(getEndpoint().getEc2Client(), exchange);
+            break;
+        default:
+            throw new IllegalArgumentException("Unsupported operation");
         }
     }
 
@@ -135,7 +135,7 @@ public class AWS2EC2Producer extends DefaultProducer {
         return (AWS2EC2Endpoint)super.getEndpoint();
     }
 
-    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @SuppressWarnings({"rawtypes", "unchecked"})
     private void createAndRunInstance(Ec2Client ec2Client, Exchange exchange) {
         String ami;
         InstanceType instanceType;
@@ -145,7 +145,7 @@ public class AWS2EC2Producer extends DefaultProducer {
                     Object payload = exchange.getIn().getBody();
                     RunInstancesResponse result;
                     try {
-                        result = ec2Client.runInstances((RunInstancesRequest) payload);
+                        result = ec2Client.runInstances((RunInstancesRequest)payload);
                     } catch (AwsServiceException ase) {
                         LOG.trace("Run Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
                         throw ase;
@@ -154,7 +154,7 @@ public class AWS2EC2Producer extends DefaultProducer {
                     Message message = getMessageForResponse(exchange);
                     message.setBody(result);
                 }
-            }    
+            }
         } else {
             RunInstancesRequest.Builder builder = RunInstancesRequest.builder();
             if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.IMAGE_ID))) {
@@ -237,16 +237,16 @@ public class AWS2EC2Producer extends DefaultProducer {
                     Object payload = exchange.getIn().getBody();
                     StartInstancesResponse result;
                     try {
-                        result = ec2Client.startInstances((StartInstancesRequest) payload);
+                        result = ec2Client.startInstances((StartInstancesRequest)payload);
                     } catch (AwsServiceException ase) {
                         LOG.trace("Start Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
                         throw ase;
                     }
-                    LOG.trace("Starting instances with Ids [{}] ", ((StartInstancesRequest) payload).instanceIds());
+                    LOG.trace("Starting instances with Ids [{}] ", ((StartInstancesRequest)payload).instanceIds());
                     Message message = getMessageForResponse(exchange);
                     message.setBody(result);
                 }
-            }    
+            }
         } else {
             StartInstancesRequest.Builder builder = StartInstancesRequest.builder();
             if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
@@ -277,16 +277,16 @@ public class AWS2EC2Producer extends DefaultProducer {
                     Object payload = exchange.getIn().getBody();
                     StopInstancesResponse result;
                     try {
-                        result = ec2Client.stopInstances((StopInstancesRequest) payload);
+                        result = ec2Client.stopInstances((StopInstancesRequest)payload);
                     } catch (AwsServiceException ase) {
                         LOG.trace("Stop Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
                         throw ase;
                     }
-                    LOG.trace("Stopping instances with Ids [{}] ", ((StopInstancesRequest) payload).instanceIds());
+                    LOG.trace("Stopping instances with Ids [{}] ", ((StopInstancesRequest)payload).instanceIds());
                     Message message = getMessageForResponse(exchange);
                     message.setBody(result);
                 }
-            }    
+            }
         } else {
             StopInstancesRequest.Builder builder = StopInstancesRequest.builder();
             if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
@@ -311,23 +311,41 @@ public class AWS2EC2Producer extends DefaultProducer {
     @SuppressWarnings("unchecked")
     private void terminateInstances(Ec2Client ec2Client, Exchange exchange) {
         Collection<String> instanceIds;
-        TerminateInstancesRequest.Builder builder = TerminateInstancesRequest.builder();
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
-            instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
-            builder.instanceIds(instanceIds);
+        if (getConfiguration().isPojoRequest()) {
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                if (exchange.getIn().getBody() instanceof StartInstancesRequest) {
+                    Object payload = exchange.getIn().getBody();
+                    TerminateInstancesResponse result;
+                    try {
+                        result = ec2Client.terminateInstances((TerminateInstancesRequest)payload);
+                    } catch (AwsServiceException ase) {
+                        LOG.trace("Terminate Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                        throw ase;
+                    }
+                    LOG.trace("Terminating instances with Ids [{}] ", ((TerminateInstancesRequest)payload).instanceIds());
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(result);
+                }
+            }
         } else {
-            throw new IllegalArgumentException("Instances Ids must be specified");
-        }
-        TerminateInstancesResponse result;
-        try {
-            result = ec2Client.terminateInstances(builder.build());
-        } catch (AwsServiceException ase) {
-            LOG.trace("Terminate Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
-            throw ase;
+            TerminateInstancesRequest.Builder builder = TerminateInstancesRequest.builder();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
+                instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
+                builder.instanceIds(instanceIds);
+            } else {
+                throw new IllegalArgumentException("Instances Ids must be specified");
+            }
+            TerminateInstancesResponse result;
+            try {
+                result = ec2Client.terminateInstances(builder.build());
+            } catch (AwsServiceException ase) {
+                LOG.trace("Terminate Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                throw ase;
+            }
+            LOG.trace("Terminating instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
+            Message message = getMessageForResponse(exchange);
+            message.setBody(result);
         }
-        LOG.trace("Terminating instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
-        Message message = getMessageForResponse(exchange);
-        message.setBody(result);
     }
 
     @SuppressWarnings("unchecked")
diff --git a/core/camel-componentdsl/src/generated/resources/metadata.json b/core/camel-componentdsl/src/generated/resources/metadata.json
index 4d76857..8b42e4c 100644
--- a/core/camel-componentdsl/src/generated/resources/metadata.json
+++ b/core/camel-componentdsl/src/generated/resources/metadata.json
@@ -5228,6 +5228,7 @@
     "lenientProperties": true,
     "javaType": "org.apache.camel.component.netty.http.NettyHttpComponent",
     "firstVersion": "2.14.0",
+    "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-netty-http",
     "version": "3.3.0-SNAPSHOT"
@@ -7598,7 +7599,6 @@
     "lenientProperties": false,
     "javaType": "org.apache.camel.component.zookeeper.ZooKeeperComponent",
     "firstVersion": "2.9.0",
-    "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-zookeeper",
     "version": "3.3.0-SNAPSHOT"
diff --git a/docs/components/modules/ROOT/pages/aws2-ec2-component.adoc b/docs/components/modules/ROOT/pages/aws2-ec2-component.adoc
index f54c04d..0383b47 100644
--- a/docs/components/modules/ROOT/pages/aws2-ec2-component.adoc
+++ b/docs/components/modules/ROOT/pages/aws2-ec2-component.adoc
@@ -36,7 +36,7 @@ You can append query options to the URI in the following format,
 
 
 // component options: START
-The AWS 2 EC2 component supports 11 options, which are listed below.
+The AWS 2 EC2 component supports 12 options, which are listed below.
 
 
 
@@ -48,6 +48,7 @@ The AWS 2 EC2 component supports 11 options, which are listed below.
 | *configuration* (producer) | The component configuration |  | AWS2EC2Configuration
 | *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. It can be createAndRunInstances, startInstances, stopInstances, terminateInstances, describeInstances, describeInstancesStatus, rebootInstances, monitorInstances, unmonitorInstances, createTags or deleteTags. The value can be one of: createAndRunInstances, startInstances, stopInstances, terminateInstances, describeInstances, describeInstancesStatus, rebootInstances, monitorInstances, unmonitorInstances, createTags, deleteTag [...]
+| *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 EC2 client |  | String
 | *proxyPort* (producer) | To define a proxy port when instantiating the EC2 client |  | Integer
 | *proxyProtocol* (producer) | To define a proxy protocol when instantiating the EC2 client. The value can be one of: HTTP, HTTPS | HTTPS | Protocol
@@ -79,7 +80,7 @@ with the following path and query parameters:
 |===
 
 
-=== Query Parameters (11 parameters):
+=== Query Parameters (12 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -89,6 +90,7 @@ with the following path and query parameters:
 | *amazonEc2Client* (producer) | To use a existing configured AmazonEC2Client as client |  | Ec2Client
 | *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. It can be createAndRunInstances, startInstances, stopInstances, terminateInstances, describeInstances, describeInstancesStatus, rebootInstances, monitorInstances, unmonitorInstances, createTags or deleteTags. The value can be one of: createAndRunInstances, startInstances, stopInstances, terminateInstances, describeInstances, describeInstancesStatus, rebootInstances, monitorInstances, unmonitorInstances, createTags, deleteTag [...]
+| *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 EC2 client |  | String
 | *proxyPort* (producer) | To define a proxy port when instantiating the EC2 client |  | Integer
 | *proxyProtocol* (producer) | To define a proxy protocol when instantiating the EC2 client. The value can be one of: HTTP, HTTPS | HTTPS | Protocol
diff --git a/docs/components/modules/ROOT/pages/index.adoc b/docs/components/modules/ROOT/pages/index.adoc
index deedae7..f1a6f0a 100644
--- a/docs/components/modules/ROOT/pages/index.adoc
+++ b/docs/components/modules/ROOT/pages/index.adoc
@@ -11,7 +11,7 @@ Below is the list of components that are provided by Apache Camel.
 == List of Components
 
 // components: START
-Number of Components: 329 in 262 JAR artifacts (1 deprecated)
+Number of Components: 328 in 261 JAR artifacts (1 deprecated)
 
 [width="100%",cols="4,1,5",options="header"]
 |===
@@ -57,8 +57,6 @@ Number of Components: 329 in 262 JAR artifacts (1 deprecated)
 
 | xref:aws2-ddbstream-component.adoc[AWS 2 DynamoDB Streams] (camel-aws2-ddb) | 3.1 | The aws2-ddbstream component is used for working with Amazon DynamoDB Streams.
 
-| xref:aws2-ec2-component.adoc[AWS 2 EC2] (camel-aws2-ec2) | 3.1 | The aws2-ec2 is used for managing Amazon EC2 instances.
-
 | xref:aws2-ecs-component.adoc[AWS 2 ECS] (camel-aws2-ecs) | 3.1 | The aws2-ecs is used for managing Amazon ECS
 
 | xref:aws2-eks-component.adoc[AWS 2 EKS] (camel-aws2-eks) | 3.1 | The aws2-eks is used for managing Amazon EKS


[camel] 07/10: CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 reboot instances

Posted by ac...@apache.org.
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

commit 45c673162cd5d8bcd0f90e216363f124d966ff91
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 9 12:11:38 2020 +0200

    CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 reboot instances
---
 .../camel/component/aws2/ec2/AWS2EC2Producer.java  | 41 +++++++++++++++-------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
index b5e2e90..a6b509f 100644
--- a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
+++ b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
@@ -393,7 +393,7 @@ public class AWS2EC2Producer extends DefaultProducer {
                     Object payload = exchange.getIn().getBody();
                     DescribeInstanceStatusResponse result;
                     try {
-                        result = ec2Client.describeInstanceStatus((DescribeInstanceStatusRequest) payload);
+                        result = ec2Client.describeInstanceStatus((DescribeInstanceStatusRequest)payload);
                     } catch (AwsServiceException ase) {
                         LOG.trace("Describe Instances Status command returned the error code {}", ase.awsErrorDetails().errorCode());
                         throw ase;
@@ -423,19 +423,34 @@ public class AWS2EC2Producer extends DefaultProducer {
     @SuppressWarnings("unchecked")
     private void rebootInstances(Ec2Client ec2Client, Exchange exchange) {
         Collection<String> instanceIds;
-        RebootInstancesRequest.Builder builder = RebootInstancesRequest.builder();
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
-            instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
-            builder.instanceIds(instanceIds);
+        if (getConfiguration().isPojoRequest()) {
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                if (exchange.getIn().getBody() instanceof DescribeInstanceStatusRequest) {
+                    Object payload = exchange.getIn().getBody();
+                    try {
+                        LOG.trace("Rebooting instances with Ids [{}] ", ((RebootInstancesRequest)payload).instanceIds());
+                        ec2Client.rebootInstances((RebootInstancesRequest)payload);
+                    } catch (AwsServiceException ase) {
+                        LOG.trace("Reboot Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                        throw ase;
+                    }
+                }
+            }
         } else {
-            throw new IllegalArgumentException("Instances Ids must be specified");
-        }
-        try {
-            LOG.trace("Rebooting instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
-            ec2Client.rebootInstances(builder.build());
-        } catch (AwsServiceException ase) {
-            LOG.trace("Reboot Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
-            throw ase;
+            RebootInstancesRequest.Builder builder = RebootInstancesRequest.builder();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
+                instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
+                builder.instanceIds(instanceIds);
+            } else {
+                throw new IllegalArgumentException("Instances Ids must be specified");
+            }
+            try {
+                LOG.trace("Rebooting instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
+                ec2Client.rebootInstances(builder.build());
+            } catch (AwsServiceException ase) {
+                LOG.trace("Reboot Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                throw ase;
+            }
         }
     }
 


[camel] 06/10: CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 describe instance status

Posted by ac...@apache.org.
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

commit 519b32ecc045e1596367db6ad81da78c8bd27ce3
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 9 12:09:06 2020 +0200

    CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 describe instance status
---
 .../camel/component/aws2/ec2/AWS2EC2Producer.java  | 71 ++++++++++++++--------
 1 file changed, 44 insertions(+), 27 deletions(-)

diff --git a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
index c969ee9..b5e2e90 100644
--- a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
+++ b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
@@ -367,40 +367,57 @@ public class AWS2EC2Producer extends DefaultProducer {
                 }
             }
         } else {
-        DescribeInstancesRequest.Builder builder = DescribeInstancesRequest.builder();
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
-            instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
-            builder.instanceIds(instanceIds);
-        }
-        DescribeInstancesResponse result;
-        try {
-            result = ec2Client.describeInstances(builder.build());
-        } catch (AwsServiceException ase) {
-            LOG.trace("Describe Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
-            throw ase;
-        }
-        Message message = getMessageForResponse(exchange);
-        message.setBody(result);
+            DescribeInstancesRequest.Builder builder = DescribeInstancesRequest.builder();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
+                instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
+                builder.instanceIds(instanceIds);
+            }
+            DescribeInstancesResponse result;
+            try {
+                result = ec2Client.describeInstances(builder.build());
+            } catch (AwsServiceException ase) {
+                LOG.trace("Describe Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                throw ase;
+            }
+            Message message = getMessageForResponse(exchange);
+            message.setBody(result);
         }
     }
 
     @SuppressWarnings("unchecked")
     private void describeInstancesStatus(Ec2Client ec2Client, Exchange exchange) {
         Collection<String> instanceIds;
-        DescribeInstanceStatusRequest.Builder builder = DescribeInstanceStatusRequest.builder();
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
-            instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
-            builder.instanceIds(instanceIds);
-        }
-        DescribeInstanceStatusResponse result;
-        try {
-            result = ec2Client.describeInstanceStatus(builder.build());
-        } catch (AwsServiceException ase) {
-            LOG.trace("Describe Instances Status command returned the error code {}", ase.awsErrorDetails().errorCode());
-            throw ase;
+        if (getConfiguration().isPojoRequest()) {
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                if (exchange.getIn().getBody() instanceof DescribeInstanceStatusRequest) {
+                    Object payload = exchange.getIn().getBody();
+                    DescribeInstanceStatusResponse result;
+                    try {
+                        result = ec2Client.describeInstanceStatus((DescribeInstanceStatusRequest) payload);
+                    } catch (AwsServiceException ase) {
+                        LOG.trace("Describe Instances Status command returned the error code {}", ase.awsErrorDetails().errorCode());
+                        throw ase;
+                    }
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(result);
+                }
+            }
+        } else {
+            DescribeInstanceStatusRequest.Builder builder = DescribeInstanceStatusRequest.builder();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
+                instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
+                builder.instanceIds(instanceIds);
+            }
+            DescribeInstanceStatusResponse result;
+            try {
+                result = ec2Client.describeInstanceStatus(builder.build());
+            } catch (AwsServiceException ase) {
+                LOG.trace("Describe Instances Status command returned the error code {}", ase.awsErrorDetails().errorCode());
+                throw ase;
+            }
+            Message message = getMessageForResponse(exchange);
+            message.setBody(result);
         }
-        Message message = getMessageForResponse(exchange);
-        message.setBody(result);
     }
 
     @SuppressWarnings("unchecked")


[camel] 05/10: CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 describe instances

Posted by ac...@apache.org.
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

commit a8a8806fdb2651fd2e0bb78866154236bb04daae
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 9 12:07:19 2020 +0200

    CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 describe instances
---
 .../camel/component/aws2/ec2/AWS2EC2Producer.java     | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
index 43f10bb..c969ee9 100644
--- a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
+++ b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
@@ -313,7 +313,7 @@ public class AWS2EC2Producer extends DefaultProducer {
         Collection<String> instanceIds;
         if (getConfiguration().isPojoRequest()) {
             if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
-                if (exchange.getIn().getBody() instanceof StartInstancesRequest) {
+                if (exchange.getIn().getBody() instanceof TerminateInstancesRequest) {
                     Object payload = exchange.getIn().getBody();
                     TerminateInstancesResponse result;
                     try {
@@ -351,6 +351,22 @@ public class AWS2EC2Producer extends DefaultProducer {
     @SuppressWarnings("unchecked")
     private void describeInstances(Ec2Client ec2Client, Exchange exchange) {
         Collection<String> instanceIds;
+        if (getConfiguration().isPojoRequest()) {
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                if (exchange.getIn().getBody() instanceof DescribeInstancesRequest) {
+                    Object payload = exchange.getIn().getBody();
+                    DescribeInstancesResponse result;
+                    try {
+                        result = ec2Client.describeInstances((DescribeInstancesRequest)payload);
+                    } catch (AwsServiceException ase) {
+                        LOG.trace("Describe Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                        throw ase;
+                    }
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(result);
+                }
+            }
+        } else {
         DescribeInstancesRequest.Builder builder = DescribeInstancesRequest.builder();
         if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
             instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
@@ -365,6 +381,7 @@ public class AWS2EC2Producer extends DefaultProducer {
         }
         Message message = getMessageForResponse(exchange);
         message.setBody(result);
+        }
     }
 
     @SuppressWarnings("unchecked")


[camel] 08/10: CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 remaining operations

Posted by ac...@apache.org.
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

commit bde80f96bb28b3aaf98eb6ab7f7039434faaaf18
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 9 12:20:09 2020 +0200

    CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 remaining operations
---
 .../camel/component/aws2/ec2/AWS2EC2Producer.java  | 222 ++++++++++++++-------
 1 file changed, 147 insertions(+), 75 deletions(-)

diff --git a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
index a6b509f..15238d4 100644
--- a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
+++ b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
@@ -425,7 +425,7 @@ public class AWS2EC2Producer extends DefaultProducer {
         Collection<String> instanceIds;
         if (getConfiguration().isPojoRequest()) {
             if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
-                if (exchange.getIn().getBody() instanceof DescribeInstanceStatusRequest) {
+                if (exchange.getIn().getBody() instanceof RebootInstancesRequest) {
                     Object payload = exchange.getIn().getBody();
                     try {
                         LOG.trace("Rebooting instances with Ids [{}] ", ((RebootInstancesRequest)payload).instanceIds());
@@ -457,103 +457,175 @@ public class AWS2EC2Producer extends DefaultProducer {
     @SuppressWarnings("unchecked")
     private void monitorInstances(Ec2Client ec2Client, Exchange exchange) {
         Collection<String> instanceIds;
-        MonitorInstancesRequest.Builder builder = MonitorInstancesRequest.builder();
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
-            instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
-            builder.instanceIds(instanceIds);
+        if (getConfiguration().isPojoRequest()) {
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                if (exchange.getIn().getBody() instanceof MonitorInstancesRequest) {
+                    Object payload = exchange.getIn().getBody();
+                    MonitorInstancesResponse result;
+                    try {
+                        result = ec2Client.monitorInstances((MonitorInstancesRequest)payload);
+                    } catch (AwsServiceException ase) {
+                        LOG.trace("Monitor Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                        throw ase;
+                    }
+                    LOG.trace("Start Monitoring instances with Ids [{}] ", ((MonitorInstancesRequest)payload).instanceIds());
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(result);
+                }
+            }
         } else {
-            throw new IllegalArgumentException("Instances Ids must be specified");
-        }
-        MonitorInstancesResponse result;
-        try {
-            result = ec2Client.monitorInstances(builder.build());
-        } catch (AwsServiceException ase) {
-            LOG.trace("Monitor Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
-            throw ase;
+            MonitorInstancesRequest.Builder builder = MonitorInstancesRequest.builder();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
+                instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
+                builder.instanceIds(instanceIds);
+            } else {
+                throw new IllegalArgumentException("Instances Ids must be specified");
+            }
+            MonitorInstancesResponse result;
+            try {
+                result = ec2Client.monitorInstances(builder.build());
+            } catch (AwsServiceException ase) {
+                LOG.trace("Monitor Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                throw ase;
+            }
+            LOG.trace("Start Monitoring instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
+            Message message = getMessageForResponse(exchange);
+            message.setBody(result);
         }
-        LOG.trace("Start Monitoring instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
-        Message message = getMessageForResponse(exchange);
-        message.setBody(result);
     }
 
     @SuppressWarnings("unchecked")
     private void unmonitorInstances(Ec2Client ec2Client, Exchange exchange) {
         Collection<String> instanceIds;
-        UnmonitorInstancesRequest.Builder builder = UnmonitorInstancesRequest.builder();
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
-            instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
-            builder.instanceIds(instanceIds);
+        if (getConfiguration().isPojoRequest()) {
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                if (exchange.getIn().getBody() instanceof UnmonitorInstancesRequest) {
+                    Object payload = exchange.getIn().getBody();
+                    UnmonitorInstancesResponse result;
+                    try {
+                        result = ec2Client.unmonitorInstances((UnmonitorInstancesRequest)payload);
+                    } catch (AwsServiceException ase) {
+                        LOG.trace("Unmonitor Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                        throw ase;
+                    }
+                    LOG.trace("Stop Monitoring instances with Ids [{}] ", ((UnmonitorInstancesRequest)payload).instanceIds());
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(result);
+                }
+            }
         } else {
-            throw new IllegalArgumentException("Instances Ids must be specified");
-        }
-        UnmonitorInstancesResponse result;
-        try {
-            result = ec2Client.unmonitorInstances(builder.build());
-        } catch (AwsServiceException ase) {
-            LOG.trace("Unmonitor Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
-            throw ase;
+            UnmonitorInstancesRequest.Builder builder = UnmonitorInstancesRequest.builder();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
+                instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
+                builder.instanceIds(instanceIds);
+            } else {
+                throw new IllegalArgumentException("Instances Ids must be specified");
+            }
+            UnmonitorInstancesResponse result;
+            try {
+                result = ec2Client.unmonitorInstances(builder.build());
+            } catch (AwsServiceException ase) {
+                LOG.trace("Unmonitor Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                throw ase;
+            }
+            LOG.trace("Stop Monitoring instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
+            Message message = getMessageForResponse(exchange);
+            message.setBody(result);
         }
-        LOG.trace("Stop Monitoring instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
-        Message message = getMessageForResponse(exchange);
-        message.setBody(result);
     }
 
     @SuppressWarnings("unchecked")
     private void createTags(Ec2Client ec2Client, Exchange exchange) {
         Collection<String> instanceIds;
-        Collection<Tag> tags;
-        CreateTagsRequest.Builder builder = CreateTagsRequest.builder();
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
-            instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
-            builder.resources(instanceIds);
-        } else {
-            throw new IllegalArgumentException("Instances Ids must be specified");
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_TAGS))) {
-            tags = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_TAGS, Collection.class);
-            builder.tags(tags);
+        if (getConfiguration().isPojoRequest()) {
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                if (exchange.getIn().getBody() instanceof CreateTagsRequest) {
+                    Object payload = exchange.getIn().getBody();
+                    CreateTagsResponse result;
+                    try {
+                        result = ec2Client.createTags((CreateTagsRequest)payload);
+                    } catch (AwsServiceException ase) {
+                        LOG.trace("Create tags command returned the error code {}", ase.awsErrorDetails().errorCode());
+                        throw ase;
+                    }
+                    LOG.trace("Created tags [{}] ", ((CreateTagsRequest)payload).tags());
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(result);
+                }
+            }
         } else {
-            throw new IllegalArgumentException("Tags must be specified");
-        }
-        CreateTagsResponse result;
-        try {
-            result = ec2Client.createTags(builder.build());
-        } catch (AwsServiceException ase) {
-            LOG.trace("Create tags command returned the error code {}", ase.awsErrorDetails().errorCode());
-            throw ase;
+            Collection<Tag> tags;
+            CreateTagsRequest.Builder builder = CreateTagsRequest.builder();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
+                instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
+                builder.resources(instanceIds);
+            } else {
+                throw new IllegalArgumentException("Instances Ids must be specified");
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_TAGS))) {
+                tags = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_TAGS, Collection.class);
+                builder.tags(tags);
+            } else {
+                throw new IllegalArgumentException("Tags must be specified");
+            }
+            CreateTagsResponse result;
+            try {
+                result = ec2Client.createTags(builder.build());
+            } catch (AwsServiceException ase) {
+                LOG.trace("Create tags command returned the error code {}", ase.awsErrorDetails().errorCode());
+                throw ase;
+            }
+            LOG.trace("Created tags [{}] on resources with Ids [{}] ", Arrays.toString(tags.toArray()), Arrays.toString(instanceIds.toArray()));
+            Message message = getMessageForResponse(exchange);
+            message.setBody(result);
         }
-        LOG.trace("Created tags [{}] on resources with Ids [{}] ", Arrays.toString(tags.toArray()), Arrays.toString(instanceIds.toArray()));
-        Message message = getMessageForResponse(exchange);
-        message.setBody(result);
     }
 
     @SuppressWarnings("unchecked")
     private void deleteTags(Ec2Client ec2Client, Exchange exchange) {
         Collection<String> instanceIds;
-        Collection<Tag> tags;
-        DeleteTagsRequest.Builder builder = DeleteTagsRequest.builder();
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
-            instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
-            builder.resources(instanceIds);
-        } else {
-            throw new IllegalArgumentException("Instances Ids must be specified");
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_TAGS))) {
-            tags = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_TAGS, Collection.class);
-            builder.tags(tags);
+        if (getConfiguration().isPojoRequest()) {
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                if (exchange.getIn().getBody() instanceof DeleteTagsRequest) {
+                    Object payload = exchange.getIn().getBody();
+                    DeleteTagsResponse result;
+                    try {
+                        result = ec2Client.deleteTags((DeleteTagsRequest)payload);
+                    } catch (AwsServiceException ase) {
+                        LOG.trace("Delete tags command returned the error code {}", ase.awsErrorDetails().errorCode());
+                        throw ase;
+                    }
+                    LOG.trace("Delete tags [{}]  ", ((DeleteTagsRequest)payload).tags());
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(result);
+                }
+            }
         } else {
-            throw new IllegalArgumentException("Tags must be specified");
-        }
-        DeleteTagsResponse result;
-        try {
-            result = ec2Client.deleteTags(builder.build());
-        } catch (AwsServiceException ase) {
-            LOG.trace("Delete tags command returned the error code {}", ase.awsErrorDetails().errorCode());
-            throw ase;
+            Collection<Tag> tags;
+            DeleteTagsRequest.Builder builder = DeleteTagsRequest.builder();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
+                instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
+                builder.resources(instanceIds);
+            } else {
+                throw new IllegalArgumentException("Instances Ids must be specified");
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_TAGS))) {
+                tags = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_TAGS, Collection.class);
+                builder.tags(tags);
+            } else {
+                throw new IllegalArgumentException("Tags must be specified");
+            }
+            DeleteTagsResponse result;
+            try {
+                result = ec2Client.deleteTags(builder.build());
+            } catch (AwsServiceException ase) {
+                LOG.trace("Delete tags command returned the error code {}", ase.awsErrorDetails().errorCode());
+                throw ase;
+            }
+            LOG.trace("Delete tags [{}] on resources with Ids [{}] ", Arrays.toString(tags.toArray()), Arrays.toString(instanceIds.toArray()));
+            Message message = getMessageForResponse(exchange);
+            message.setBody(result);
         }
-        LOG.trace("Delete tags [{}] on resources with Ids [{}] ", Arrays.toString(tags.toArray()), Arrays.toString(instanceIds.toArray()));
-        Message message = getMessageForResponse(exchange);
-        message.setBody(result);
     }
 
     public static Message getMessageForResponse(final Exchange exchange) {


[camel] 01/10: CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2

Posted by ac...@apache.org.
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

commit 824d913535a8f609c434842ea53020d736abccca
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 9 11:11:55 2020 +0200

    CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2
---
 .../aws2/ec2/AWS2EC2ComponentConfigurer.java       |  5 +++++
 .../aws2/ec2/AWS2EC2EndpointConfigurer.java        |  5 +++++
 .../apache/camel/component/aws2/ec2/aws2-ec2.json  |  2 ++
 .../src/main/docs/aws2-ec2-component.adoc          |  6 ++++--
 .../component/aws2/ec2/AWS2EC2Configuration.java   | 13 ++++++++++++
 .../camel/component/aws2/ec2/AWS2EC2Producer.java  | 18 ++++++++++++++++
 .../dsl/Aws2Ec2ComponentBuilderFactory.java        | 13 ++++++++++++
 .../src/generated/resources/metadata.json          |  3 ++-
 .../dsl/AWS2EC2EndpointBuilderFactory.java         | 24 ++++++++++++++++++++++
 9 files changed, 86 insertions(+), 3 deletions(-)

diff --git a/components/camel-aws2-ec2/src/generated/java/org/apache/camel/component/aws2/ec2/AWS2EC2ComponentConfigurer.java b/components/camel-aws2-ec2/src/generated/java/org/apache/camel/component/aws2/ec2/AWS2EC2ComponentConfigurer.java
index d58b645..40da381 100644
--- a/components/camel-aws2-ec2/src/generated/java/org/apache/camel/component/aws2/ec2/AWS2EC2ComponentConfigurer.java
+++ b/components/camel-aws2-ec2/src/generated/java/org/apache/camel/component/aws2/ec2/AWS2EC2ComponentConfigurer.java
@@ -36,6 +36,8 @@ public class AWS2EC2ComponentConfigurer extends PropertyConfigurerSupport implem
         case "lazystartproducer":
         case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
         case "operation": getOrCreateConfiguration(target).setOperation(property(camelContext, org.apache.camel.component.aws2.ec2.AWS2EC2Operations.class, value)); return true;
+        case "pojorequest":
+        case "pojoRequest": getOrCreateConfiguration(target).setPojoRequest(property(camelContext, boolean.class, value)); return true;
         case "proxyhost":
         case "proxyHost": getOrCreateConfiguration(target).setProxyHost(property(camelContext, java.lang.String.class, value)); return true;
         case "proxyport":
@@ -58,6 +60,7 @@ public class AWS2EC2ComponentConfigurer extends PropertyConfigurerSupport implem
         answer.put("configuration", org.apache.camel.component.aws2.ec2.AWS2EC2Configuration.class);
         answer.put("lazyStartProducer", boolean.class);
         answer.put("operation", org.apache.camel.component.aws2.ec2.AWS2EC2Operations.class);
+        answer.put("pojoRequest", boolean.class);
         answer.put("proxyHost", java.lang.String.class);
         answer.put("proxyPort", java.lang.Integer.class);
         answer.put("proxyProtocol", software.amazon.awssdk.core.Protocol.class);
@@ -80,6 +83,8 @@ public class AWS2EC2ComponentConfigurer extends PropertyConfigurerSupport implem
         case "lazystartproducer":
         case "lazyStartProducer": return target.isLazyStartProducer();
         case "operation": return getOrCreateConfiguration(target).getOperation();
+        case "pojorequest":
+        case "pojoRequest": return getOrCreateConfiguration(target).isPojoRequest();
         case "proxyhost":
         case "proxyHost": return getOrCreateConfiguration(target).getProxyHost();
         case "proxyport":
diff --git a/components/camel-aws2-ec2/src/generated/java/org/apache/camel/component/aws2/ec2/AWS2EC2EndpointConfigurer.java b/components/camel-aws2-ec2/src/generated/java/org/apache/camel/component/aws2/ec2/AWS2EC2EndpointConfigurer.java
index 7339f91..938d932 100644
--- a/components/camel-aws2-ec2/src/generated/java/org/apache/camel/component/aws2/ec2/AWS2EC2EndpointConfigurer.java
+++ b/components/camel-aws2-ec2/src/generated/java/org/apache/camel/component/aws2/ec2/AWS2EC2EndpointConfigurer.java
@@ -28,6 +28,8 @@ public class AWS2EC2EndpointConfigurer extends PropertyConfigurerSupport impleme
         case "lazystartproducer":
         case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
         case "operation": target.getConfiguration().setOperation(property(camelContext, org.apache.camel.component.aws2.ec2.AWS2EC2Operations.class, value)); return true;
+        case "pojorequest":
+        case "pojoRequest": target.getConfiguration().setPojoRequest(property(camelContext, boolean.class, value)); return true;
         case "proxyhost":
         case "proxyHost": target.getConfiguration().setProxyHost(property(camelContext, java.lang.String.class, value)); return true;
         case "proxyport":
@@ -50,6 +52,7 @@ public class AWS2EC2EndpointConfigurer extends PropertyConfigurerSupport impleme
         answer.put("basicPropertyBinding", boolean.class);
         answer.put("lazyStartProducer", boolean.class);
         answer.put("operation", org.apache.camel.component.aws2.ec2.AWS2EC2Operations.class);
+        answer.put("pojoRequest", boolean.class);
         answer.put("proxyHost", java.lang.String.class);
         answer.put("proxyPort", java.lang.Integer.class);
         answer.put("proxyProtocol", software.amazon.awssdk.core.Protocol.class);
@@ -72,6 +75,8 @@ public class AWS2EC2EndpointConfigurer extends PropertyConfigurerSupport impleme
         case "lazystartproducer":
         case "lazyStartProducer": return target.isLazyStartProducer();
         case "operation": return target.getConfiguration().getOperation();
+        case "pojorequest":
+        case "pojoRequest": return target.getConfiguration().isPojoRequest();
         case "proxyhost":
         case "proxyHost": return target.getConfiguration().getProxyHost();
         case "proxyport":
diff --git a/components/camel-aws2-ec2/src/generated/resources/org/apache/camel/component/aws2/ec2/aws2-ec2.json b/components/camel-aws2-ec2/src/generated/resources/org/apache/camel/component/aws2/ec2/aws2-ec2.json
index eb1ef0a..3287c8f 100644
--- a/components/camel-aws2-ec2/src/generated/resources/org/apache/camel/component/aws2/ec2/aws2-ec2.json
+++ b/components/camel-aws2-ec2/src/generated/resources/org/apache/camel/component/aws2/ec2/aws2-ec2.json
@@ -26,6 +26,7 @@
     "configuration": { "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.ec2.AWS2EC2Configuration", "deprecated": false, "secret": false, "description": "The component configuration" },
     "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": "producer", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws2.ec2.AWS2EC2Operations", "enum": [ "createAndRunInstances", "startInstances", "stopInstances", "terminateInstances", "describeInstances", "describeInstancesStatus", "rebootInstances", "monitorInstances", "unmonitorInstances", "createTags", "deleteTags" ], "deprecated": false, "deprecationNote": "", "se [...]
+    "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.ec2.AWS2EC2Configuration", "configurationField": "configuration", "description": "If we want to use a POJO request as body or not" },
     "proxyHost": { "kind": "property", "displayName": "Proxy Host", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ec2.AWS2EC2Configuration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the EC2 client" },
     "proxyPort": { "kind": "property", "displayName": "Proxy Port", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ec2.AWS2EC2Configuration", "configurationField": "configuration", "description": "To define a proxy port when instantiating the EC2 client" },
     "proxyProtocol": { "kind": "property", "displayName": "Proxy Protocol", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "software.amazon.awssdk.core.Protocol", "enum": [ "HTTP", "HTTPS" ], "deprecated": false, "secret": false, "defaultValue": "HTTPS", "configurationClass": "org.apache.camel.component.aws2.ec2.AWS2EC2Configuration", "configurationField": "configuration", "description": "To define a proxy protocol when instantiating the EC2 client" },
@@ -39,6 +40,7 @@
     "amazonEc2Client": { "kind": "parameter", "displayName": "Amazon Ec2 Client", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.ec2.Ec2Client", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ec2.AWS2EC2Configuration", "configurationField": "configuration", "description": "To use a existing configured AmazonEC2Client as client" },
     "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": "producer", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws2.ec2.AWS2EC2Operations", "enum": [ "createAndRunInstances", "startInstances", "stopInstances", "terminateInstances", "describeInstances", "describeInstancesStatus", "rebootInstances", "monitorInstances", "unmonitorInstances", "createTags", "deleteTags" ], "deprecated": false, "deprecationNote": "", "s [...]
+    "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.ec2.AWS2EC2Configuration", "configurationField": "configuration", "description": "If we want to use a POJO request as body or not" },
     "proxyHost": { "kind": "parameter", "displayName": "Proxy Host", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ec2.AWS2EC2Configuration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the EC2 client" },
     "proxyPort": { "kind": "parameter", "displayName": "Proxy Port", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ec2.AWS2EC2Configuration", "configurationField": "configuration", "description": "To define a proxy port when instantiating the EC2 client" },
     "proxyProtocol": { "kind": "parameter", "displayName": "Proxy Protocol", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "software.amazon.awssdk.core.Protocol", "enum": [ "HTTP", "HTTPS" ], "deprecated": false, "secret": false, "defaultValue": "HTTPS", "configurationClass": "org.apache.camel.component.aws2.ec2.AWS2EC2Configuration", "configurationField": "configuration", "description": "To define a proxy protocol when instantiating the EC2 client" },
diff --git a/components/camel-aws2-ec2/src/main/docs/aws2-ec2-component.adoc b/components/camel-aws2-ec2/src/main/docs/aws2-ec2-component.adoc
index 2ff03f2..ca05da4 100644
--- a/components/camel-aws2-ec2/src/main/docs/aws2-ec2-component.adoc
+++ b/components/camel-aws2-ec2/src/main/docs/aws2-ec2-component.adoc
@@ -35,7 +35,7 @@ You can append query options to the URI in the following format,
 
 
 // component options: START
-The AWS 2 EC2 component supports 11 options, which are listed below.
+The AWS 2 EC2 component supports 12 options, which are listed below.
 
 
 
@@ -47,6 +47,7 @@ The AWS 2 EC2 component supports 11 options, which are listed below.
 | *configuration* (producer) | The component configuration |  | AWS2EC2Configuration
 | *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. It can be createAndRunInstances, startInstances, stopInstances, terminateInstances, describeInstances, describeInstancesStatus, rebootInstances, monitorInstances, unmonitorInstances, createTags or deleteTags. The value can be one of: createAndRunInstances, startInstances, stopInstances, terminateInstances, describeInstances, describeInstancesStatus, rebootInstances, monitorInstances, unmonitorInstances, createTags, deleteTag [...]
+| *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 EC2 client |  | String
 | *proxyPort* (producer) | To define a proxy port when instantiating the EC2 client |  | Integer
 | *proxyProtocol* (producer) | To define a proxy protocol when instantiating the EC2 client. The value can be one of: HTTP, HTTPS | HTTPS | Protocol
@@ -78,7 +79,7 @@ with the following path and query parameters:
 |===
 
 
-=== Query Parameters (11 parameters):
+=== Query Parameters (12 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -88,6 +89,7 @@ with the following path and query parameters:
 | *amazonEc2Client* (producer) | To use a existing configured AmazonEC2Client as client |  | Ec2Client
 | *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. It can be createAndRunInstances, startInstances, stopInstances, terminateInstances, describeInstances, describeInstancesStatus, rebootInstances, monitorInstances, unmonitorInstances, createTags or deleteTags. The value can be one of: createAndRunInstances, startInstances, stopInstances, terminateInstances, describeInstances, describeInstancesStatus, rebootInstances, monitorInstances, unmonitorInstances, createTags, deleteTag [...]
+| *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 EC2 client |  | String
 | *proxyPort* (producer) | To define a proxy port when instantiating the EC2 client |  | Integer
 | *proxyProtocol* (producer) | To define a proxy protocol when instantiating the EC2 client. The value can be one of: HTTP, HTTPS | HTTPS | Protocol
diff --git a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Configuration.java b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Configuration.java
index c76d978..1e88b37 100644
--- a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Configuration.java
+++ b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Configuration.java
@@ -47,6 +47,8 @@ public class AWS2EC2Configuration implements Cloneable {
     private Integer proxyPort;
     @UriParam
     private String region;
+    @UriParam(defaultValue = "false")
+    private boolean pojoRequest;
 
     public Ec2Client getAmazonEc2Client() {
         return amazonEc2Client;
@@ -140,6 +142,17 @@ public class AWS2EC2Configuration implements Cloneable {
     public void setRegion(String region) {
         this.region = region;
     }
+    
+    public boolean isPojoRequest() {
+        return pojoRequest;
+    }
+
+    /**
+     * If we want to use a POJO request as body or not
+     */
+    public void setPojoRequest(boolean pojoRequest) {
+        this.pojoRequest = pojoRequest;
+    }
 
     // *************************************************
     //
diff --git a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
index 5dd7584..3a64581 100644
--- a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
+++ b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
@@ -139,6 +139,23 @@ public class AWS2EC2Producer extends DefaultProducer {
     private void createAndRunInstance(Ec2Client ec2Client, Exchange exchange) {
         String ami;
         InstanceType instanceType;
+        if (getConfiguration().isPojoRequest()) {
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                if (exchange.getIn().getBody() instanceof RunInstancesRequest) {
+                    Object payload = exchange.getIn().getBody();
+                    RunInstancesResponse result;
+                    try {
+                        result = ec2Client.runInstances((RunInstancesRequest) payload);
+                    } catch (AwsServiceException ase) {
+                        LOG.trace("Run Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                        throw ase;
+                    }
+                    LOG.trace("Creating and running instances requests performing");
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(result);
+                }
+            }    
+        } else {
         RunInstancesRequest.Builder builder = RunInstancesRequest.builder();
         if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.IMAGE_ID))) {
             ami = exchange.getIn().getHeader(AWS2EC2Constants.IMAGE_ID, String.class);
@@ -208,6 +225,7 @@ public class AWS2EC2Producer extends DefaultProducer {
         LOG.trace("Creating and running instances with ami [{}] and instance type {}", ami, instanceType);
         Message message = getMessageForResponse(exchange);
         message.setBody(result);
+        }
     }
 
     @SuppressWarnings("unchecked")
diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2Ec2ComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2Ec2ComponentBuilderFactory.java
index 80392c9..c31544d 100644
--- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2Ec2ComponentBuilderFactory.java
+++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2Ec2ComponentBuilderFactory.java
@@ -125,6 +125,18 @@ public interface Aws2Ec2ComponentBuilderFactory {
             return this;
         }
         /**
+         * If we want to use a POJO request as body or not.
+         * 
+         * The option is a: <code>boolean</code> type.
+         * 
+         * Default: false
+         * Group: producer
+         */
+        default Aws2Ec2ComponentBuilder pojoRequest(boolean pojoRequest) {
+            doSetProperty("pojoRequest", pojoRequest);
+            return this;
+        }
+        /**
          * To define a proxy host when instantiating the EC2 client.
          * 
          * The option is a: <code>java.lang.String</code> type.
@@ -228,6 +240,7 @@ public interface Aws2Ec2ComponentBuilderFactory {
             case "configuration": ((AWS2EC2Component) component).setConfiguration((org.apache.camel.component.aws2.ec2.AWS2EC2Configuration) value); return true;
             case "lazyStartProducer": ((AWS2EC2Component) component).setLazyStartProducer((boolean) value); return true;
             case "operation": getOrCreateConfiguration((AWS2EC2Component) component).setOperation((org.apache.camel.component.aws2.ec2.AWS2EC2Operations) value); return true;
+            case "pojoRequest": getOrCreateConfiguration((AWS2EC2Component) component).setPojoRequest((boolean) value); return true;
             case "proxyHost": getOrCreateConfiguration((AWS2EC2Component) component).setProxyHost((java.lang.String) value); return true;
             case "proxyPort": getOrCreateConfiguration((AWS2EC2Component) component).setProxyPort((java.lang.Integer) value); return true;
             case "proxyProtocol": getOrCreateConfiguration((AWS2EC2Component) component).setProxyProtocol((software.amazon.awssdk.core.Protocol) value); return true;
diff --git a/core/camel-componentdsl/src/generated/resources/metadata.json b/core/camel-componentdsl/src/generated/resources/metadata.json
index 4f34764b6..f43f7d6 100644
--- a/core/camel-componentdsl/src/generated/resources/metadata.json
+++ b/core/camel-componentdsl/src/generated/resources/metadata.json
@@ -480,7 +480,6 @@
     "lenientProperties": false,
     "javaType": "org.apache.camel.component.aws2.ec2.AWS2EC2Component",
     "firstVersion": "3.1.0",
-    "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-aws2-ec2",
     "version": "3.3.0-SNAPSHOT"
@@ -1784,6 +1783,7 @@
     "lenientProperties": false,
     "javaType": "org.apache.camel.component.corda.CordaComponent",
     "firstVersion": "2.23.0",
+    "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-corda",
     "version": "3.3.0-SNAPSHOT"
@@ -7598,6 +7598,7 @@
     "lenientProperties": false,
     "javaType": "org.apache.camel.component.zookeeper.ZooKeeperComponent",
     "firstVersion": "2.9.0",
+    "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-zookeeper",
     "version": "3.3.0-SNAPSHOT"
diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AWS2EC2EndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AWS2EC2EndpointBuilderFactory.java
index c598f2e..6bf8a63 100644
--- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AWS2EC2EndpointBuilderFactory.java
+++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AWS2EC2EndpointBuilderFactory.java
@@ -149,6 +149,30 @@ public interface AWS2EC2EndpointBuilderFactory {
             return this;
         }
         /**
+         * If we want to use a POJO request as body or not.
+         * 
+         * The option is a: <code>boolean</code> type.
+         * 
+         * Default: false
+         * Group: producer
+         */
+        default AWS2EC2EndpointBuilder pojoRequest(boolean pojoRequest) {
+            doSetProperty("pojoRequest", pojoRequest);
+            return this;
+        }
+        /**
+         * If we want to use a POJO request as body or not.
+         * 
+         * The option will be converted to a <code>boolean</code> type.
+         * 
+         * Default: false
+         * Group: producer
+         */
+        default AWS2EC2EndpointBuilder pojoRequest(String pojoRequest) {
+            doSetProperty("pojoRequest", pojoRequest);
+            return this;
+        }
+        /**
          * To define a proxy host when instantiating the EC2 client.
          * 
          * The option is a: <code>java.lang.String</code> type.


[camel] 02/10: CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 start instances

Posted by ac...@apache.org.
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

commit bed361a39bac74a00fb75827754652379a00f4b7
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 9 11:41:49 2020 +0200

    CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 start instances
---
 .../camel/component/aws2/ec2/AWS2EC2Producer.java  | 186 +++++++++++----------
 .../src/generated/resources/metadata.json          |   2 +-
 2 files changed, 103 insertions(+), 85 deletions(-)

diff --git a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
index 3a64581..af1d286 100644
--- a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
+++ b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
@@ -156,98 +156,116 @@ public class AWS2EC2Producer extends DefaultProducer {
                 }
             }    
         } else {
-        RunInstancesRequest.Builder builder = RunInstancesRequest.builder();
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.IMAGE_ID))) {
-            ami = exchange.getIn().getHeader(AWS2EC2Constants.IMAGE_ID, String.class);
-            builder.imageId(ami);
-        } else {
-            throw new IllegalArgumentException("AMI must be specified");
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_TYPE))) {
-            instanceType = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_TYPE, InstanceType.class);
-            builder.instanceType(instanceType.toString());
-        } else {
-            throw new IllegalArgumentException("Instance Type must be specified");
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_MIN_COUNT))) {
-            int minCount = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_MIN_COUNT, Integer.class);
-            builder.minCount(minCount);
-        } else {
-            throw new IllegalArgumentException("Min instances count must be specified");
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_MAX_COUNT))) {
-            int maxCount = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_MAX_COUNT, Integer.class);
-            builder.maxCount(maxCount);
-        } else {
-            throw new IllegalArgumentException("Max instances count must be specified");
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_MONITORING))) {
-            boolean monitoring = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_MONITORING, Boolean.class);
-            RunInstancesMonitoringEnabled.Builder monitoringEnabled = RunInstancesMonitoringEnabled.builder();
-            monitoringEnabled.enabled(monitoring);
-            builder.monitoring(monitoringEnabled.build());
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_KERNEL_ID))) {
-            String kernelId = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_KERNEL_ID, String.class);
-            builder.kernelId(kernelId);
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_EBS_OPTIMIZED))) {
-            boolean ebsOptimized = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_EBS_OPTIMIZED, Boolean.class);
-            builder.ebsOptimized(ebsOptimized);
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_SECURITY_GROUPS))) {
-            Collection securityGroups = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_SECURITY_GROUPS, Collection.class);
-            builder.securityGroups(securityGroups);
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_KEY_PAIR))) {
-            String keyName = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_KEY_PAIR, String.class);
-            builder.keyName(keyName);
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_CLIENT_TOKEN))) {
-            String clientToken = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_CLIENT_TOKEN, String.class);
-            builder.clientToken(clientToken);
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_PLACEMENT))) {
-            Placement placement = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_PLACEMENT, Placement.class);
-            builder.placement(placement);
-        }
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.SUBNET_ID))) {
-            String subnetId = exchange.getIn().getHeader(AWS2EC2Constants.SUBNET_ID, String.class);
-            builder.subnetId(subnetId);
-        }
-        RunInstancesResponse result;
-        try {
-            result = ec2Client.runInstances(builder.build());
-        } catch (AwsServiceException ase) {
-            LOG.trace("Run Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
-            throw ase;
-        }
-        LOG.trace("Creating and running instances with ami [{}] and instance type {}", ami, instanceType);
-        Message message = getMessageForResponse(exchange);
-        message.setBody(result);
+            RunInstancesRequest.Builder builder = RunInstancesRequest.builder();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.IMAGE_ID))) {
+                ami = exchange.getIn().getHeader(AWS2EC2Constants.IMAGE_ID, String.class);
+                builder.imageId(ami);
+            } else {
+                throw new IllegalArgumentException("AMI must be specified");
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_TYPE))) {
+                instanceType = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_TYPE, InstanceType.class);
+                builder.instanceType(instanceType.toString());
+            } else {
+                throw new IllegalArgumentException("Instance Type must be specified");
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_MIN_COUNT))) {
+                int minCount = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_MIN_COUNT, Integer.class);
+                builder.minCount(minCount);
+            } else {
+                throw new IllegalArgumentException("Min instances count must be specified");
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_MAX_COUNT))) {
+                int maxCount = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_MAX_COUNT, Integer.class);
+                builder.maxCount(maxCount);
+            } else {
+                throw new IllegalArgumentException("Max instances count must be specified");
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_MONITORING))) {
+                boolean monitoring = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_MONITORING, Boolean.class);
+                RunInstancesMonitoringEnabled.Builder monitoringEnabled = RunInstancesMonitoringEnabled.builder();
+                monitoringEnabled.enabled(monitoring);
+                builder.monitoring(monitoringEnabled.build());
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_KERNEL_ID))) {
+                String kernelId = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_KERNEL_ID, String.class);
+                builder.kernelId(kernelId);
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_EBS_OPTIMIZED))) {
+                boolean ebsOptimized = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_EBS_OPTIMIZED, Boolean.class);
+                builder.ebsOptimized(ebsOptimized);
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_SECURITY_GROUPS))) {
+                Collection securityGroups = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_SECURITY_GROUPS, Collection.class);
+                builder.securityGroups(securityGroups);
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_KEY_PAIR))) {
+                String keyName = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_KEY_PAIR, String.class);
+                builder.keyName(keyName);
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_CLIENT_TOKEN))) {
+                String clientToken = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_CLIENT_TOKEN, String.class);
+                builder.clientToken(clientToken);
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_PLACEMENT))) {
+                Placement placement = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_PLACEMENT, Placement.class);
+                builder.placement(placement);
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.SUBNET_ID))) {
+                String subnetId = exchange.getIn().getHeader(AWS2EC2Constants.SUBNET_ID, String.class);
+                builder.subnetId(subnetId);
+            }
+            RunInstancesResponse result;
+            try {
+                result = ec2Client.runInstances(builder.build());
+            } catch (AwsServiceException ase) {
+                LOG.trace("Run Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                throw ase;
+            }
+            LOG.trace("Creating and running instances with ami [{}] and instance type {}", ami, instanceType);
+            Message message = getMessageForResponse(exchange);
+            message.setBody(result);
         }
     }
 
     @SuppressWarnings("unchecked")
     private void startInstances(Ec2Client ec2Client, Exchange exchange) {
         Collection<String> instanceIds;
-        StartInstancesRequest.Builder builder = StartInstancesRequest.builder();
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
-            instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
-            builder.instanceIds(instanceIds);
+        if (getConfiguration().isPojoRequest()) {
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                if (exchange.getIn().getBody() instanceof RunInstancesRequest) {
+                    Object payload = exchange.getIn().getBody();
+                    StartInstancesResponse result;
+                    try {
+                        result = ec2Client.startInstances((StartInstancesRequest) payload);
+                    } catch (AwsServiceException ase) {
+                        LOG.trace("Start Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                        throw ase;
+                    }
+                    LOG.trace("Starting instances with Ids [{}] ", ((StartInstancesRequest) payload).instanceIds());
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(result);
+                }
+            }    
         } else {
-            throw new IllegalArgumentException("Instances Ids must be specified");
+            StartInstancesRequest.Builder builder = StartInstancesRequest.builder();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
+                instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
+                builder.instanceIds(instanceIds);
+            } else {
+                throw new IllegalArgumentException("Instances Ids must be specified");
+            }
+            StartInstancesResponse result;
+            try {
+                result = ec2Client.startInstances(builder.build());
+            } catch (AwsServiceException ase) {
+                LOG.trace("Start Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                throw ase;
+            }
+            LOG.trace("Starting instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
+            Message message = getMessageForResponse(exchange);
+            message.setBody(result);
         }
-        StartInstancesResponse result;
-        try {
-            result = ec2Client.startInstances(builder.build());
-        } catch (AwsServiceException ase) {
-            LOG.trace("Start Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
-            throw ase;
-        }
-        LOG.trace("Starting instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
-        Message message = getMessageForResponse(exchange);
-        message.setBody(result);
     }
 
     @SuppressWarnings("unchecked")
diff --git a/core/camel-componentdsl/src/generated/resources/metadata.json b/core/camel-componentdsl/src/generated/resources/metadata.json
index f43f7d6..00b851a 100644
--- a/core/camel-componentdsl/src/generated/resources/metadata.json
+++ b/core/camel-componentdsl/src/generated/resources/metadata.json
@@ -480,6 +480,7 @@
     "lenientProperties": false,
     "javaType": "org.apache.camel.component.aws2.ec2.AWS2EC2Component",
     "firstVersion": "3.1.0",
+    "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-aws2-ec2",
     "version": "3.3.0-SNAPSHOT"
@@ -3884,7 +3885,6 @@
     "lenientProperties": false,
     "javaType": "org.apache.camel.component.ironmq.IronMQComponent",
     "firstVersion": "2.17.0",
-    "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-ironmq",
     "version": "3.3.0-SNAPSHOT"


[camel] 03/10: CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 stop instances

Posted by ac...@apache.org.
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

commit a87e08d4e02d34951c58dff8c3b508f29731bb0f
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 9 11:45:15 2020 +0200

    CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 stop instances
---
 .../camel/component/aws2/ec2/AWS2EC2Producer.java  | 50 +++++++++++++++-------
 .../src/generated/resources/metadata.json          |  2 +-
 2 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
index af1d286..77733cd 100644
--- a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
+++ b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java
@@ -233,7 +233,7 @@ public class AWS2EC2Producer extends DefaultProducer {
         Collection<String> instanceIds;
         if (getConfiguration().isPojoRequest()) {
             if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
-                if (exchange.getIn().getBody() instanceof RunInstancesRequest) {
+                if (exchange.getIn().getBody() instanceof StartInstancesRequest) {
                     Object payload = exchange.getIn().getBody();
                     StartInstancesResponse result;
                     try {
@@ -271,23 +271,41 @@ public class AWS2EC2Producer extends DefaultProducer {
     @SuppressWarnings("unchecked")
     private void stopInstances(Ec2Client ec2Client, Exchange exchange) {
         Collection<String> instanceIds;
-        StopInstancesRequest.Builder builder = StopInstancesRequest.builder();
-        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
-            instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
-            builder.instanceIds(instanceIds);
+        if (getConfiguration().isPojoRequest()) {
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                if (exchange.getIn().getBody() instanceof StopInstancesRequest) {
+                    Object payload = exchange.getIn().getBody();
+                    StopInstancesResponse result;
+                    try {
+                        result = ec2Client.stopInstances((StopInstancesRequest) payload);
+                    } catch (AwsServiceException ase) {
+                        LOG.trace("Stop Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                        throw ase;
+                    }
+                    LOG.trace("Stopping instances with Ids [{}] ", ((StopInstancesRequest) payload).instanceIds());
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(result);
+                }
+            }    
         } else {
-            throw new IllegalArgumentException("Instances Ids must be specified");
-        }
-        StopInstancesResponse result;
-        try {
-            result = ec2Client.stopInstances(builder.build());
-        } catch (AwsServiceException ase) {
-            LOG.trace("Stop Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
-            throw ase;
+            StopInstancesRequest.Builder builder = StopInstancesRequest.builder();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS))) {
+                instanceIds = exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS, Collection.class);
+                builder.instanceIds(instanceIds);
+            } else {
+                throw new IllegalArgumentException("Instances Ids must be specified");
+            }
+            StopInstancesResponse result;
+            try {
+                result = ec2Client.stopInstances(builder.build());
+            } catch (AwsServiceException ase) {
+                LOG.trace("Stop Instances command returned the error code {}", ase.awsErrorDetails().errorCode());
+                throw ase;
+            }
+            LOG.trace("Stopping instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
+            Message message = getMessageForResponse(exchange);
+            message.setBody(result);
         }
-        LOG.trace("Stopping instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
-        Message message = getMessageForResponse(exchange);
-        message.setBody(result);
     }
 
     @SuppressWarnings("unchecked")
diff --git a/core/camel-componentdsl/src/generated/resources/metadata.json b/core/camel-componentdsl/src/generated/resources/metadata.json
index 00b851a..4d76857 100644
--- a/core/camel-componentdsl/src/generated/resources/metadata.json
+++ b/core/camel-componentdsl/src/generated/resources/metadata.json
@@ -3885,6 +3885,7 @@
     "lenientProperties": false,
     "javaType": "org.apache.camel.component.ironmq.IronMQComponent",
     "firstVersion": "2.17.0",
+    "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-ironmq",
     "version": "3.3.0-SNAPSHOT"
@@ -5227,7 +5228,6 @@
     "lenientProperties": true,
     "javaType": "org.apache.camel.component.netty.http.NettyHttpComponent",
     "firstVersion": "2.14.0",
-    "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-netty-http",
     "version": "3.3.0-SNAPSHOT"


[camel] 10/10: CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 added a little test

Posted by ac...@apache.org.
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

commit 504fef7ddf04c944190b7aaedc50dc677229b5a6
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 9 12:28:52 2020 +0200

    CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-ec2 added a little test
---
 .../camel/component/aws2/ec2/EC2ProducerTest.java      | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/components/camel-aws2-ec2/src/test/java/org/apache/camel/component/aws2/ec2/EC2ProducerTest.java b/components/camel-aws2-ec2/src/test/java/org/apache/camel/component/aws2/ec2/EC2ProducerTest.java
index 795a0f9..0dc321e 100644
--- a/components/camel-aws2-ec2/src/test/java/org/apache/camel/component/aws2/ec2/EC2ProducerTest.java
+++ b/components/camel-aws2-ec2/src/test/java/org/apache/camel/component/aws2/ec2/EC2ProducerTest.java
@@ -33,6 +33,7 @@ import software.amazon.awssdk.services.ec2.model.InstanceStateName;
 import software.amazon.awssdk.services.ec2.model.InstanceType;
 import software.amazon.awssdk.services.ec2.model.MonitorInstancesResponse;
 import software.amazon.awssdk.services.ec2.model.MonitoringState;
+import software.amazon.awssdk.services.ec2.model.RunInstancesRequest;
 import software.amazon.awssdk.services.ec2.model.RunInstancesResponse;
 import software.amazon.awssdk.services.ec2.model.StartInstancesResponse;
 import software.amazon.awssdk.services.ec2.model.StopInstancesResponse;
@@ -67,6 +68,22 @@ public class EC2ProducerTest extends CamelTestSupport {
         assertEquals(resultGet.instances().get(0).instanceType(), InstanceType.T2_MICRO);
         assertEquals(resultGet.instances().get(0).instanceId(), "instance-1");
     }
+    
+    @Test
+    public void createAndRunInstancesPojo() {
+
+        Exchange exchange = template.request("direct:createAndRunPojo", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(AWS2EC2Constants.OPERATION, AWS2EC2Operations.createAndRunInstances);
+                exchange.getIn().setBody(RunInstancesRequest.builder().imageId("test-1").instanceType(InstanceType.T2_MICRO).build());
+            }
+        });
+
+        RunInstancesResponse resultGet = (RunInstancesResponse)exchange.getMessage().getBody();
+        assertEquals(resultGet.instances().get(0).imageId(), "test-1");
+        assertEquals(resultGet.instances().get(0).instanceType(), InstanceType.T2_MICRO);
+        assertEquals(resultGet.instances().get(0).instanceId(), "instance-1");
+    }
 
     @Test
     public void ec2CreateAndRunTestWithKeyPair() throws Exception {
@@ -244,6 +261,7 @@ public class EC2ProducerTest extends CamelTestSupport {
             @Override
             public void configure() throws Exception {
                 from("direct:createAndRun").to("aws2-ec2://test?amazonEc2Client=#amazonEc2Client&operation=createAndRunInstances").to("mock:result");
+                from("direct:createAndRunPojo").to("aws2-ec2://test?amazonEc2Client=#amazonEc2Client&operation=createAndRunInstances&pojoRequest=true").to("mock:result");
                 from("direct:start").to("aws2-ec2://test?amazonEc2Client=#amazonEc2Client&operation=startInstances").to("mock:result");
                 from("direct:stop").to("aws2-ec2://test?amazonEc2Client=#amazonEc2Client&operation=stopInstances").to("mock:result");
                 from("direct:terminate").to("aws2-ec2://test?amazonEc2Client=#amazonEc2Client&operation=terminateInstances").to("mock:result");