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 2022/11/02 17:33:32 UTC

[camel] branch main updated (b11d0ccbedc -> a563443d614)

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

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


    from b11d0ccbedc Regen for commit 5b46749491280f8b3ced50fea6a11a8f235bf81c
     new 3529a789a4a CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - Fix check for region before looking for enabled services - CloudWatch
     new 31ef4038076 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - Fix check for region before looking for enabled services - CloudWatch
     new a563443d614 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - Fix check for region before looking for enabled services - CloudWatch

The 3 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:
 components/camel-aws/camel-aws2-cw/pom.xml         |  8 ++
 .../component/aws2/cw/Cw2ClientHealthCheck.java}   | 28 +++----
 .../camel/component/aws2/cw/Cw2Component.java      |  1 -
 .../aws2/cw/Cw2ComponentVerifierExtension.java     | 93 ----------------------
 .../camel/component/aws2/cw/Cw2Endpoint.java       | 17 ++++
 .../cw/Cw2ClientHealthCheckProfileCredsTest.java}  | 12 +--
 .../cw/Cw2ClientHealthCheckStaticCredsTest.java}   | 12 +--
 .../aws2/cw/CwComponentVerifierExtensionTest.java  | 91 ---------------------
 8 files changed, 51 insertions(+), 211 deletions(-)
 copy components/camel-aws/{camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2ClientHealthCheck.java => camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheck.java} (69%)
 delete mode 100644 components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ComponentVerifierExtension.java
 copy components/camel-aws/{camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2CliientHealthCheckStaticCredsTest.java => camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckProfileCredsTest.java} (90%)
 copy components/camel-aws/{camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2CliientHealthCheckStaticCredsTest.java => camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckStaticCredsTest.java} (90%)
 delete mode 100644 components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentVerifierExtensionTest.java


[camel] 03/03: CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - Fix check for region before looking for enabled services - CloudWatch

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a563443d6142c0ca375ddf4fa5c57fedaaa68322
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Nov 2 18:30:21 2022 +0100

    CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - Fix check for region before looking for enabled services - CloudWatch
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../org/apache/camel/component/aws2/cw/Cw2ClientHealthCheck.java    | 4 ++--
 .../component/aws2/cw/Cw2ClientHealthCheckProfileCredsTest.java     | 6 +++---
 .../component/aws2/cw/Cw2ClientHealthCheckStaticCredsTest.java      | 6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheck.java b/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheck.java
index fc0904f2c16..cdad1bdd1f6 100644
--- a/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheck.java
+++ b/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheck.java
@@ -17,6 +17,8 @@
 
 package org.apache.camel.component.aws2.cw;
 
+import java.util.Map;
+
 import org.apache.camel.component.aws2.cw.client.Cw2ClientFactory;
 import org.apache.camel.component.aws2.cw.client.Cw2InternalClient;
 import org.apache.camel.health.HealthCheckResultBuilder;
@@ -27,8 +29,6 @@ import software.amazon.awssdk.regions.Region;
 import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
 import software.amazon.awssdk.services.cloudwatch.model.ListDashboardsRequest;
 
-import java.util.Map;
-
 public class Cw2ClientHealthCheck extends AbstractHealthCheck {
 
     private final Cw2Endpoint cw2Endpoint;
diff --git a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckProfileCredsTest.java b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckProfileCredsTest.java
index 4b415ecee93..638f0e9d787 100644
--- a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckProfileCredsTest.java
+++ b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckProfileCredsTest.java
@@ -17,6 +17,9 @@
 
 package org.apache.camel.component.aws2.cw;
 
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.health.HealthCheck;
@@ -29,9 +32,6 @@ import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Collection;
-import java.util.concurrent.TimeUnit;
-
 import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
 
 public class Cw2ClientHealthCheckProfileCredsTest extends CamelTestSupport {
diff --git a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckStaticCredsTest.java b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckStaticCredsTest.java
index 637951eb6c1..eb2553d91a0 100644
--- a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckStaticCredsTest.java
+++ b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckStaticCredsTest.java
@@ -17,6 +17,9 @@
 
 package org.apache.camel.component.aws2.cw;
 
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.health.HealthCheck;
@@ -29,9 +32,6 @@ import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Collection;
-import java.util.concurrent.TimeUnit;
-
 import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
 
 public class Cw2ClientHealthCheckStaticCredsTest extends CamelTestSupport {


[camel] 01/03: CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - Fix check for region before looking for enabled services - CloudWatch

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3529a789a4a24a2f1828c2d4667184720d23c0a0
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Nov 2 18:27:08 2022 +0100

    CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - Fix check for region before looking for enabled services - CloudWatch
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 components/camel-aws/camel-aws2-cw/pom.xml         |  8 ++
 .../component/aws2/cw/Cw2ClientHealthCheck.java    | 80 +++++++++++++++++++
 .../camel/component/aws2/cw/Cw2Component.java      |  1 -
 .../aws2/cw/Cw2ComponentVerifierExtension.java     | 93 ----------------------
 .../camel/component/aws2/cw/Cw2Endpoint.java       | 17 ++++
 .../aws2/cw/CwComponentVerifierExtensionTest.java  | 91 ---------------------
 6 files changed, 105 insertions(+), 185 deletions(-)

diff --git a/components/camel-aws/camel-aws2-cw/pom.xml b/components/camel-aws/camel-aws2-cw/pom.xml
index 8926c8e5c4b..8c26a4ccec7 100644
--- a/components/camel-aws/camel-aws2-cw/pom.xml
+++ b/components/camel-aws/camel-aws2-cw/pom.xml
@@ -40,6 +40,10 @@
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-support</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-health</artifactId>
+        </dependency>
         <dependency>
             <groupId>software.amazon.awssdk</groupId>
             <artifactId>cloudwatch</artifactId>
@@ -76,5 +80,9 @@
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-health</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheck.java b/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheck.java
new file mode 100644
index 00000000000..fc0904f2c16
--- /dev/null
+++ b/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheck.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.aws2.cw;
+
+import org.apache.camel.component.aws2.cw.client.Cw2ClientFactory;
+import org.apache.camel.component.aws2.cw.client.Cw2InternalClient;
+import org.apache.camel.health.HealthCheckResultBuilder;
+import org.apache.camel.impl.health.AbstractHealthCheck;
+import org.apache.camel.util.ObjectHelper;
+import software.amazon.awssdk.awscore.exception.AwsServiceException;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
+import software.amazon.awssdk.services.cloudwatch.model.ListDashboardsRequest;
+
+import java.util.Map;
+
+public class Cw2ClientHealthCheck extends AbstractHealthCheck {
+
+    private final Cw2Endpoint cw2Endpoint;
+    private final String clientId;
+
+    public Cw2ClientHealthCheck(Cw2Endpoint cw2Endpoint, String clientId) {
+        super("camel", "aws2-cw-client-" + clientId);
+        this.cw2Endpoint = cw2Endpoint;
+        this.clientId = clientId;
+    }
+
+    @Override
+    public boolean isLiveness() {
+        // this health check is only readiness
+        return false;
+    }
+
+    @Override
+    protected void doCall(HealthCheckResultBuilder builder, Map<String, Object> options) {
+        Cw2Configuration configuration = cw2Endpoint.getConfiguration();
+        if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
+            if (!CloudWatchClient.serviceMetadata().regions().contains(Region.of(configuration.getRegion()))) {
+                builder.message("The service is not supported in this region");
+                builder.down();
+                return;
+            }
+        }
+        try {
+            Cw2InternalClient cw2Client = Cw2ClientFactory.getCloudWatchClient(configuration);
+            cw2Client.getCloudWatchClient().listDashboards(ListDashboardsRequest.builder().build());
+        } catch (AwsServiceException e) {
+            builder.message(e.getMessage());
+            builder.error(e);
+            if (ObjectHelper.isNotEmpty(e.statusCode())) {
+                builder.detail(SERVICE_STATUS_CODE, e.statusCode());
+            }
+            if (ObjectHelper.isNotEmpty(e.awsErrorDetails().errorCode())) {
+                builder.detail(SERVICE_ERROR_CODE, e.awsErrorDetails().errorCode());
+            }
+            builder.down();
+            return;
+        } catch (Exception e) {
+            builder.error(e);
+            builder.down();
+            return;
+        }
+        builder.up();
+    }
+}
diff --git a/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Component.java b/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Component.java
index a4048d8d734..1b3333b2b55 100644
--- a/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Component.java
+++ b/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Component.java
@@ -39,7 +39,6 @@ public class Cw2Component extends DefaultComponent {
 
     public Cw2Component(CamelContext context) {
         super(context);
-        registerExtension(new Cw2ComponentVerifierExtension());
     }
 
     @Override
diff --git a/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ComponentVerifierExtension.java b/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ComponentVerifierExtension.java
deleted file mode 100644
index 249bcaf0fe9..00000000000
--- a/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ComponentVerifierExtension.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.aws2.cw;
-
-import java.util.Map;
-
-import org.apache.camel.component.extension.verifier.DefaultComponentVerifierExtension;
-import org.apache.camel.component.extension.verifier.ResultBuilder;
-import org.apache.camel.component.extension.verifier.ResultErrorBuilder;
-import org.apache.camel.component.extension.verifier.ResultErrorHelper;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.awscore.exception.AwsServiceException;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
-import software.amazon.awssdk.services.cloudwatch.CloudWatchClientBuilder;
-
-public class Cw2ComponentVerifierExtension extends DefaultComponentVerifierExtension {
-
-    public Cw2ComponentVerifierExtension() {
-        this("aws2-cw");
-    }
-
-    public Cw2ComponentVerifierExtension(String scheme) {
-        super(scheme);
-    }
-
-    // *********************************
-    // Parameters validation
-    // *********************************
-
-    @Override
-    protected Result verifyParameters(Map<String, Object> parameters) {
-
-        ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS)
-                .error(ResultErrorHelper.requiresOption("accessKey", parameters))
-                .error(ResultErrorHelper.requiresOption("secretKey", parameters))
-                .error(ResultErrorHelper.requiresOption("region", parameters));
-
-        // Validate using the catalog
-
-        super.verifyParametersAgainstCatalog(builder, parameters);
-
-        return builder.build();
-    }
-
-    // *********************************
-    // Connectivity validation
-    // *********************************
-
-    @Override
-    protected Result verifyConnectivity(Map<String, Object> parameters) {
-        ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY);
-        try {
-            Cw2Configuration configuration = setProperties(new Cw2Configuration(), parameters);
-            if (!CloudWatchClient.serviceMetadata().regions().contains(Region.of(configuration.getRegion()))) {
-                ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(
-                        VerificationError.StandardCode.ILLEGAL_PARAMETER, "The service is not supported in this region");
-                return builder.error(errorBuilder.build()).build();
-            }
-            AwsBasicCredentials cred = AwsBasicCredentials.create(configuration.getAccessKey(), configuration.getSecretKey());
-            CloudWatchClientBuilder clientBuilder = CloudWatchClient.builder();
-            CloudWatchClient client = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred))
-                    .region(Region.of(configuration.getRegion())).build();
-            client.listMetrics();
-        } catch (AwsServiceException e) {
-            ResultErrorBuilder errorBuilder
-                    = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage())
-                            .detail("aws_cw_exception_message", e.getMessage())
-                            .detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName())
-                            .detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e);
-
-            builder.error(errorBuilder.build());
-        } catch (Exception e) {
-            builder.error(ResultErrorBuilder.withException(e).build());
-        }
-        return builder.build();
-    }
-}
diff --git a/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Endpoint.java b/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Endpoint.java
index 4bd17681875..5c1dfec0808 100644
--- a/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Endpoint.java
+++ b/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Endpoint.java
@@ -22,6 +22,8 @@ import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.component.aws2.cw.client.Cw2ClientFactory;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.impl.health.ComponentsHealthCheckRepository;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.support.DefaultEndpoint;
@@ -38,6 +40,8 @@ public class Cw2Endpoint extends DefaultEndpoint {
     @UriParam
     private Cw2Configuration configuration;
     private CloudWatchClient cloudWatchClient;
+    private ComponentsHealthCheckRepository healthCheckRepository;
+    private Cw2ClientHealthCheck clientHealthCheck;
 
     public Cw2Endpoint(String uri, Component component, Cw2Configuration configuration) {
         super(uri, component);
@@ -72,6 +76,19 @@ public class Cw2Endpoint extends DefaultEndpoint {
         super.doStop();
     }
 
+    @Override
+    public void doStart() throws Exception {
+        super.doStart();
+
+        healthCheckRepository = HealthCheckHelper.getHealthCheckRepository(getCamelContext(),
+                ComponentsHealthCheckRepository.REPOSITORY_ID, ComponentsHealthCheckRepository.class);
+
+        if (healthCheckRepository != null) {
+            clientHealthCheck = new Cw2ClientHealthCheck(this, getId());
+            healthCheckRepository.addHealthCheck(clientHealthCheck);
+        }
+    }
+
     public Cw2Configuration getConfiguration() {
         return configuration;
     }
diff --git a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentVerifierExtensionTest.java b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentVerifierExtensionTest.java
deleted file mode 100644
index 7981cf63a22..00000000000
--- a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentVerifierExtensionTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.aws2.cw;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.camel.Component;
-import org.apache.camel.component.extension.ComponentVerifierExtension;
-import org.apache.camel.test.junit5.CamelTestSupport;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-public class CwComponentVerifierExtensionTest extends CamelTestSupport {
-
-    // *************************************************
-    // Tests (parameters)
-    // *************************************************
-    @Override
-    public boolean isUseRouteBuilder() {
-        return false;
-    }
-
-    @Test
-    public void testParameters() {
-        Component component = context().getComponent("aws2-cw");
-
-        ComponentVerifierExtension verifier
-                = component.getExtension(ComponentVerifierExtension.class).orElseThrow(IllegalStateException::new);
-
-        Map<String, Object> parameters = new HashMap<>();
-        parameters.put("secretKey", "l");
-        parameters.put("accessKey", "k");
-        parameters.put("region", "l");
-        parameters.put("namespace", "test");
-
-        ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.PARAMETERS, parameters);
-
-        assertEquals(ComponentVerifierExtension.Result.Status.OK, result.getStatus());
-    }
-
-    @Test
-    public void testConnectivity() {
-        Component component = context().getComponent("aws2-cw");
-        ComponentVerifierExtension verifier
-                = component.getExtension(ComponentVerifierExtension.class).orElseThrow(IllegalStateException::new);
-
-        Map<String, Object> parameters = new HashMap<>();
-        parameters.put("secretKey", "l");
-        parameters.put("accessKey", "k");
-        parameters.put("region", "US_EAST_1");
-        parameters.put("namespace", "test");
-
-        ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters);
-
-        assertEquals(ComponentVerifierExtension.Result.Status.ERROR, result.getStatus());
-    }
-
-    @Test
-    public void testConnectivityAndRegion() {
-        Component component = context().getComponent("aws2-cw");
-        ComponentVerifierExtension verifier
-                = component.getExtension(ComponentVerifierExtension.class).orElseThrow(IllegalStateException::new);
-
-        Map<String, Object> parameters = new HashMap<>();
-        parameters.put("secretKey", "l");
-        parameters.put("accessKey", "k");
-        parameters.put("region", "test");
-        parameters.put("namespace", "test");
-
-        ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters);
-
-        assertEquals(ComponentVerifierExtension.Result.Status.ERROR, result.getStatus());
-    }
-
-}


[camel] 02/03: CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - Fix check for region before looking for enabled services - CloudWatch

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 31ef403807626ee29c7fd8008997636fc54159ec
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Nov 2 18:29:14 2022 +0100

    CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - Fix check for region before looking for enabled services - CloudWatch
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../cw/Cw2ClientHealthCheckProfileCredsTest.java   | 97 ++++++++++++++++++++++
 .../cw/Cw2ClientHealthCheckStaticCredsTest.java    | 97 ++++++++++++++++++++++
 2 files changed, 194 insertions(+)

diff --git a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckProfileCredsTest.java b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckProfileCredsTest.java
new file mode 100644
index 00000000000..4b415ecee93
--- /dev/null
+++ b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckProfileCredsTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.aws2.cw;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.health.HealthCheckRegistry;
+import org.apache.camel.impl.health.DefaultHealthCheckRegistry;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
+import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
+
+public class Cw2ClientHealthCheckProfileCredsTest extends CamelTestSupport {
+
+    private static final Logger LOG = LoggerFactory.getLogger(Cw2ClientHealthCheckProfileCredsTest.class);
+
+    CamelContext context;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        context = super.createCamelContext();
+        context.getPropertiesComponent().setLocation("ref:prop");
+
+        // install health check manually (yes a bit cumbersome)
+        HealthCheckRegistry registry = new DefaultHealthCheckRegistry();
+        registry.setCamelContext(context);
+        Object hc = registry.resolveById("context");
+        registry.register(hc);
+        hc = registry.resolveById("routes");
+        registry.register(hc);
+        hc = registry.resolveById("consumers");
+        registry.register(hc);
+        context.setExtension(HealthCheckRegistry.class, registry);
+
+        return context;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+
+            @Override
+            public void configure() {
+                from("direct:listClusters")
+                        .to("aws2-cw://test?region=l&useDefaultCredentialsProvider=true");
+            }
+        };
+    }
+
+    @Test
+    public void testConnectivity() {
+
+        Collection<HealthCheck.Result> res = HealthCheckHelper.invokeLiveness(context);
+        boolean up = res.stream().allMatch(r -> r.getState().equals(HealthCheck.State.UP));
+        Assertions.assertTrue(up, "liveness check");
+
+        // health-check readiness should be down
+        await().atMost(20, TimeUnit.SECONDS).untilAsserted(() -> {
+            Collection<HealthCheck.Result> res2 = HealthCheckHelper.invokeReadiness(context);
+            boolean down = res2.stream().allMatch(r -> r.getState().equals(HealthCheck.State.DOWN));
+            boolean containsAws2AthenaHealthCheck = res2.stream()
+                    .filter(result -> result.getCheck().getId().startsWith("aws2-cw-client"))
+                    .findAny()
+                    .isPresent();
+            boolean hasRegionMessage = res2.stream()
+                    .anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region")));
+            Assertions.assertTrue(down, "liveness check");
+            Assertions.assertTrue(containsAws2AthenaHealthCheck, "aws2-cw check");
+            Assertions.assertTrue(hasRegionMessage, "aws2-eks check error message");
+        });
+
+    }
+}
diff --git a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckStaticCredsTest.java b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckStaticCredsTest.java
new file mode 100644
index 00000000000..637951eb6c1
--- /dev/null
+++ b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/Cw2ClientHealthCheckStaticCredsTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.aws2.cw;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.health.HealthCheckRegistry;
+import org.apache.camel.impl.health.DefaultHealthCheckRegistry;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
+import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
+
+public class Cw2ClientHealthCheckStaticCredsTest extends CamelTestSupport {
+
+    private static final Logger LOG = LoggerFactory.getLogger(Cw2ClientHealthCheckStaticCredsTest.class);
+
+    CamelContext context;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        context = super.createCamelContext();
+        context.getPropertiesComponent().setLocation("ref:prop");
+
+        // install health check manually (yes a bit cumbersome)
+        HealthCheckRegistry registry = new DefaultHealthCheckRegistry();
+        registry.setCamelContext(context);
+        Object hc = registry.resolveById("context");
+        registry.register(hc);
+        hc = registry.resolveById("routes");
+        registry.register(hc);
+        hc = registry.resolveById("consumers");
+        registry.register(hc);
+        context.setExtension(HealthCheckRegistry.class, registry);
+
+        return context;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+
+            @Override
+            public void configure() {
+                from("direct:listClusters")
+                        .to("aws2-cw://test?region=l&secretKey=l&accessKey=k");
+            }
+        };
+    }
+
+    @Test
+    public void testConnectivity() {
+
+        Collection<HealthCheck.Result> res = HealthCheckHelper.invokeLiveness(context);
+        boolean up = res.stream().allMatch(r -> r.getState().equals(HealthCheck.State.UP));
+        Assertions.assertTrue(up, "liveness check");
+
+        // health-check readiness should be down
+        await().atMost(20, TimeUnit.SECONDS).untilAsserted(() -> {
+            Collection<HealthCheck.Result> res2 = HealthCheckHelper.invokeReadiness(context);
+            boolean down = res2.stream().allMatch(r -> r.getState().equals(HealthCheck.State.DOWN));
+            boolean containsAws2AthenaHealthCheck = res2.stream()
+                    .filter(result -> result.getCheck().getId().startsWith("aws2-cw-client"))
+                    .findAny()
+                    .isPresent();
+            boolean hasRegionMessage = res2.stream()
+                    .anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region")));
+            Assertions.assertTrue(down, "liveness check");
+            Assertions.assertTrue(containsAws2AthenaHealthCheck, "aws2-cw check");
+            Assertions.assertTrue(hasRegionMessage, "aws2-eks check error message");
+        });
+
+    }
+}