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 4ba5f73f0f97ced3e3572448d15f702ac672f36c Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Mon Dec 19 11:19:25 2022 +0100 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - ECS Signed-off-by: Andrea Cosentino <anco...@gmail.com> --- .../camel/component/aws2/ecs/ECS2Component.java | 2 - .../aws2/ecs/ECS2ComponentVerifierExtension.java | 95 ---------------------- .../camel/component/aws2/ecs/ECS2Endpoint.java | 2 +- 3 files changed, 1 insertion(+), 98 deletions(-) diff --git a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Component.java b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Component.java index f351016dc32..afd809c9677 100644 --- a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Component.java +++ b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Component.java @@ -43,8 +43,6 @@ public class ECS2Component extends DefaultComponent { public ECS2Component(CamelContext context) { super(context); - - registerExtension(new ECS2ComponentVerifierExtension()); } @Override diff --git a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2ComponentVerifierExtension.java b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2ComponentVerifierExtension.java deleted file mode 100644 index a92ffe7d1d1..00000000000 --- a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2ComponentVerifierExtension.java +++ /dev/null @@ -1,95 +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.ecs; - -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.core.exception.SdkClientException; -import software.amazon.awssdk.regions.Region; -import software.amazon.awssdk.services.ecs.EcsClient; -import software.amazon.awssdk.services.ecs.EcsClientBuilder; -import software.amazon.awssdk.services.ecs.model.ListClustersRequest; - -public class ECS2ComponentVerifierExtension extends DefaultComponentVerifierExtension { - - public ECS2ComponentVerifierExtension() { - this("aws2-ecs"); - } - - public ECS2ComponentVerifierExtension(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 { - ECS2Configuration configuration = setProperties(new ECS2Configuration(), parameters); - if (!EcsClient.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()); - EcsClientBuilder clientBuilder = EcsClient.builder(); - EcsClient client = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred)) - .region(Region.of(configuration.getRegion())).build(); - client.listClusters(ListClustersRequest.builder().build()); - } catch (SdkClientException e) { - ResultErrorBuilder errorBuilder - = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage()) - .detail("aws_ecs_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-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Endpoint.java b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Endpoint.java index 45a40c3196c..0915d298303 100644 --- a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Endpoint.java +++ b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Endpoint.java @@ -82,7 +82,7 @@ public class ECS2Endpoint extends ScheduledPollEndpoint { healthCheckRepository.removeHealthCheck(clientHealthCheck); clientHealthCheck = null; } - + if (ObjectHelper.isEmpty(configuration.getEcsClient())) { if (ecsClient != null) { ecsClient.close();