camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [camel] 01/02: CAMEL-12849 - Camel-AWS MQ: Add a describeBroker operation to the producer side
Date Tue, 02 Oct 2018 12:35:24 GMT
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 360fae71a287b9e6461977cee819b69cab9b08ba
Author: Andrea Cosentino <ancosen@gmail.com>
AuthorDate: Tue Oct 2 14:28:29 2018 +0200

    CAMEL-12849 - Camel-AWS MQ: Add a describeBroker operation to the producer side
---
 .../camel/component/aws/mq/MQOperations.java       |  3 ++-
 .../apache/camel/component/aws/mq/MQProducer.java  | 25 ++++++++++++++++++++++
 .../camel/component/aws/mq/AmazonMQClientMock.java |  7 +++++-
 .../component/aws/mq/MQProducerSpringTest.java     | 22 +++++++++++++++++++
 .../camel/component/aws/mq/MQProducerTest.java     | 25 ++++++++++++++++++++++
 .../aws/mq/MQComponentSpringTest-context.xml       |  5 +++++
 6 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQOperations.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQOperations.java
index 241d237..2a2bef0 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQOperations.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQOperations.java
@@ -22,5 +22,6 @@ public enum MQOperations {
     createBroker,
     deleteBroker,
     rebootBroker,
-    updateBroker
+    updateBroker,
+    describeBroker
 }
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQProducer.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQProducer.java
index c217c14..87f7d3c 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQProducer.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/mq/MQProducer.java
@@ -23,6 +23,8 @@ import com.amazonaws.services.mq.model.CreateBrokerRequest;
 import com.amazonaws.services.mq.model.CreateBrokerResult;
 import com.amazonaws.services.mq.model.DeleteBrokerRequest;
 import com.amazonaws.services.mq.model.DeleteBrokerResult;
+import com.amazonaws.services.mq.model.DescribeBrokerRequest;
+import com.amazonaws.services.mq.model.DescribeBrokerResult;
 import com.amazonaws.services.mq.model.ListBrokersRequest;
 import com.amazonaws.services.mq.model.ListBrokersResult;
 import com.amazonaws.services.mq.model.RebootBrokerRequest;
@@ -72,6 +74,9 @@ public class MQProducer extends DefaultProducer {
         case updateBroker:
             updateBroker(getEndpoint().getAmazonMqClient(), exchange);
             break;
+        case describeBroker:
+            describeBroker(getEndpoint().getAmazonMqClient(), exchange);
+            break;
         default:
             throw new IllegalArgumentException("Unsupported operation");
         }
@@ -210,4 +215,24 @@ public class MQProducer extends DefaultProducer {
         Message message = getMessageForResponse(exchange);
         message.setBody(result);
     }
+    
+    private void describeBroker(AmazonMQ mqClient, Exchange exchange) {
+        String brokerId;
+        DescribeBrokerRequest request = new DescribeBrokerRequest();
+        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(MQConstants.BROKER_ID))) {
+            brokerId = exchange.getIn().getHeader(MQConstants.BROKER_ID, String.class);
+            request.withBrokerId(brokerId);
+        } else {
+            throw new IllegalArgumentException("Broker Name must be specified");
+        }
+        DescribeBrokerResult result;
+        try {
+            result = mqClient.describeBroker(request);
+        } catch (AmazonServiceException ase) {
+            LOG.trace("Reboot Broker command returned the error code {}", ase.getErrorCode());
+            throw ase;
+        }
+        Message message = getMessageForResponse(exchange);
+        message.setBody(result);
+    }
 }
\ No newline at end of file
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/AmazonMQClientMock.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/AmazonMQClientMock.java
index ff309af..082874a 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/AmazonMQClientMock.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/AmazonMQClientMock.java
@@ -59,6 +59,7 @@ import com.amazonaws.services.mq.model.UpdateConfigurationRequest;
 import com.amazonaws.services.mq.model.UpdateConfigurationResult;
 import com.amazonaws.services.mq.model.UpdateUserRequest;
 import com.amazonaws.services.mq.model.UpdateUserResult;
+import com.sun.corba.se.pept.broker.Broker;
 
 public class AmazonMQClientMock implements AmazonMQ {
 
@@ -98,7 +99,11 @@ public class AmazonMQClientMock implements AmazonMQ {
 
     @Override
     public DescribeBrokerResult describeBroker(DescribeBrokerRequest describeBrokerRequest)
{
-        throw new UnsupportedOperationException();
+        DescribeBrokerResult result = new DescribeBrokerResult();
+        result.setBrokerId("1");
+        result.setBrokerName("Test");
+        result.setBrokerState(BrokerState.RUNNING.toString());
+        return result;
     }
 
     @Override
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerSpringTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerSpringTest.java
index f14e39d..ace9f00 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerSpringTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerSpringTest.java
@@ -21,6 +21,7 @@ import com.amazonaws.services.mq.model.ConfigurationId;
 import com.amazonaws.services.mq.model.CreateBrokerResult;
 import com.amazonaws.services.mq.model.DeleteBrokerResult;
 import com.amazonaws.services.mq.model.DeploymentMode;
+import com.amazonaws.services.mq.model.DescribeBrokerResult;
 import com.amazonaws.services.mq.model.ListBrokersResult;
 import com.amazonaws.services.mq.model.UpdateBrokerResult;
 
@@ -131,6 +132,27 @@ public class MQProducerSpringTest extends CamelSpringTestSupport {
         assertEquals(resultGet.getBrokerId(), "1");
     }
     
+    @Test
+    public void mqDescribeBrokerTest() throws Exception {
+
+        mock.expectedMessageCount(1);
+        Exchange exchange = template.request("direct:describeBroker", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(MQConstants.OPERATION, MQOperations.describeBroker);
+                exchange.getIn().setHeader(MQConstants.BROKER_ID, "1");
+                ConfigurationId cId = new ConfigurationId();
+                cId.setId("1");
+                cId.setRevision(12);
+                exchange.getIn().setHeader(MQConstants.CONFIGURATION_ID, cId);
+            }
+        });
+        
+        assertMockEndpointsSatisfied();
+        DescribeBrokerResult resultGet = (DescribeBrokerResult) exchange.getIn().getBody();
+        assertEquals(resultGet.getBrokerId(), "1");
+    }
+    
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry registry = super.createRegistry();
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerTest.java
index 1bd449d..b3e4ccb 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/mq/MQProducerTest.java
@@ -21,6 +21,7 @@ import com.amazonaws.services.mq.model.ConfigurationId;
 import com.amazonaws.services.mq.model.CreateBrokerResult;
 import com.amazonaws.services.mq.model.DeleteBrokerResult;
 import com.amazonaws.services.mq.model.DeploymentMode;
+import com.amazonaws.services.mq.model.DescribeBrokerResult;
 import com.amazonaws.services.mq.model.ListBrokersResult;
 import com.amazonaws.services.mq.model.UpdateBrokerResult;
 
@@ -131,6 +132,27 @@ public class MQProducerTest extends CamelTestSupport {
         assertEquals(resultGet.getBrokerId(), "1");
     }
     
+    @Test
+    public void mqDescribeBrokerTest() throws Exception {
+
+        mock.expectedMessageCount(1);
+        Exchange exchange = template.request("direct:describeBroker", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(MQConstants.OPERATION, MQOperations.describeBroker);
+                exchange.getIn().setHeader(MQConstants.BROKER_ID, "1");
+                ConfigurationId cId = new ConfigurationId();
+                cId.setId("1");
+                cId.setRevision(12);
+                exchange.getIn().setHeader(MQConstants.CONFIGURATION_ID, cId);
+            }
+        });
+        
+        assertMockEndpointsSatisfied();
+        DescribeBrokerResult resultGet = (DescribeBrokerResult) exchange.getIn().getBody();
+        assertEquals(resultGet.getBrokerId(), "1");
+    }
+    
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry registry = super.createRegistry();
@@ -162,6 +184,9 @@ public class MQProducerTest extends CamelTestSupport {
                 from("direct:updateBroker")
                     .to("aws-mq://test?amazonMqClient=#amazonMqClient&operation=updateBroker")
                     .to("mock:result");
+                from("direct:describeBroker")
+                    .to("aws-mq://test?amazonMqClient=#amazonMqClient&operation=describeBroker")
+                    .to("mock:result");
             }
         };
     }
diff --git a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/mq/MQComponentSpringTest-context.xml
b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/mq/MQComponentSpringTest-context.xml
index c629c07..08bd1e8 100644
--- a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/mq/MQComponentSpringTest-context.xml
+++ b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/mq/MQComponentSpringTest-context.xml
@@ -49,6 +49,11 @@
             <to uri="aws-mq://Test?amazonMqClient=#amazonMqClient&amp;operation=updateBroker"/>
             <to uri="mock:result"/>
         </route>
+        <route>
+            <from uri="direct:describeBroker"/>
+            <to uri="aws-mq://Test?amazonMqClient=#amazonMqClient&amp;operation=describeBroker"/>
+            <to uri="mock:result"/>
+        </route>
     </camelContext>
 
     <bean id="amazonMqClient" class="org.apache.camel.component.aws.mq.AmazonMQClientMock"/>


Mime
View raw message