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 b9a68df6c9e3a6ccc70cc72a935b89632306b26b Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Fri Dec 21 15:07:45 2018 +0100 CAMEL-13027 - Camel-AWS: Create a Camel-AWS EKS component --- .../camel/component/aws/eks/EKSComponent.java | 118 +++++++++++++ .../aws/eks/EKSComponentVerifierExtension.java | 88 ++++++++++ .../camel/component/aws/eks/EKSConfiguration.java | 137 +++++++++++++++ .../camel/component/aws/eks/EKSConstants.java | 29 ++++ .../camel/component/aws/eks/EKSEndpoint.java | 121 +++++++++++++ .../camel/component/aws/eks/EKSOperations.java | 25 +++ .../camel/component/aws/eks/EKSProducer.java | 175 +++++++++++++++++++ .../services/org/apache/camel/component/aws-eks | 18 ++ .../component/aws/eks/AmazonEKSClientMock.java | 78 +++++++++ .../aws/eks/EKSComponentConfigurationTest.java | 51 ++++++ .../aws/eks/EKSComponentVerifierExtensionTest.java | 73 ++++++++ .../component/aws/eks/EKSProducerSpringTest.java | 121 +++++++++++++ .../camel/component/aws/eks/EKSProducerTest.java | 145 ++++++++++++++++ .../aws/eks/EKSComponentSpringTest-context.xml | 50 ++++++ .../springboot/EKSComponentAutoConfiguration.java | 128 ++++++++++++++ .../eks/springboot/EKSComponentConfiguration.java | 193 +++++++++++++++++++++ .../src/main/resources/META-INF/spring.factories | 4 +- 17 files changed, 1553 insertions(+), 1 deletion(-) diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSComponent.java new file mode 100644 index 0000000..bc5e461 --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSComponent.java @@ -0,0 +1,118 @@ +/** + * 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.aws.eks; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.spi.Metadata; +import org.apache.camel.support.DefaultComponent; +import org.apache.camel.util.ObjectHelper; + +/** + * For working with Amazon EKS. + */ +public class EKSComponent extends DefaultComponent { + + @Metadata + private String accessKey; + @Metadata + private String secretKey; + @Metadata + private String region; + @Metadata(label = "advanced") + private EKSConfiguration configuration; + + public EKSComponent() { + this(null); + } + + public EKSComponent(CamelContext context) { + super(context); + + this.configuration = new EKSConfiguration(); + registerExtension(new EKSComponentVerifierExtension()); + } + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + EKSConfiguration configuration = this.configuration.copy(); + setProperties(configuration, parameters); + + if (ObjectHelper.isEmpty(configuration.getAccessKey())) { + setAccessKey(accessKey); + } + if (ObjectHelper.isEmpty(configuration.getSecretKey())) { + setSecretKey(secretKey); + } + if (ObjectHelper.isEmpty(configuration.getRegion())) { + setRegion(region); + } + if (configuration.getEksClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { + throw new IllegalArgumentException("Amazon eks client or accessKey and secretKey must be specified"); + } + + EKSEndpoint endpoint = new EKSEndpoint(uri, this, configuration); + return endpoint; + } + + public EKSConfiguration getConfiguration() { + return configuration; + } + + /** + * The AWS KMS default configuration + */ + public void setConfiguration(EKSConfiguration configuration) { + this.configuration = configuration; + } + + public String getAccessKey() { + return configuration.getAccessKey(); + } + + /** + * Amazon AWS Access Key + */ + public void setAccessKey(String accessKey) { + configuration.setAccessKey(accessKey); + } + + public String getSecretKey() { + return configuration.getSecretKey(); + } + + /** + * Amazon AWS Secret Key + */ + public void setSecretKey(String secretKey) { + configuration.setSecretKey(secretKey); + } + + public String getRegion() { + return configuration.getRegion(); + } + + /** + * The region in which KMS client needs to work + */ + public void setRegion(String region) { + configuration.setRegion(region); + } + +} diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSComponentVerifierExtension.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSComponentVerifierExtension.java new file mode 100644 index 0000000..c69e6e8 --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSComponentVerifierExtension.java @@ -0,0 +1,88 @@ +/** + * 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.aws.eks; + +import java.util.Map; + +import com.amazonaws.SdkClientException; +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSCredentialsProvider; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.regions.Regions; +import com.amazonaws.services.eks.AmazonEKS; +import com.amazonaws.services.eks.AmazonEKSClientBuilder; +import com.amazonaws.services.eks.model.ListClustersRequest; + +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; + +public class EKSComponentVerifierExtension extends DefaultComponentVerifierExtension { + + public EKSComponentVerifierExtension() { + this("aws-eks"); + } + + public EKSComponentVerifierExtension(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 { + EKSConfiguration configuration = setProperties(new EKSConfiguration(), parameters); + AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); + AmazonEKS client = AmazonEKSClientBuilder.standard().withCredentials(credentialsProvider).withRegion(Regions.valueOf(configuration.getRegion())).build(); + client.listClusters(new ListClustersRequest()); + } catch (SdkClientException e) { + ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage()) + .detail("aws_eks_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/src/main/java/org/apache/camel/component/aws/eks/EKSConfiguration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSConfiguration.java new file mode 100644 index 0000000..88d6562 --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSConfiguration.java @@ -0,0 +1,137 @@ +/** + * 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.aws.eks; + +import com.amazonaws.services.eks.AmazonEKS; + +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; +import org.apache.camel.spi.UriPath; + +@UriParams +public class EKSConfiguration implements Cloneable { + + @UriPath(description = "Logical name") + @Metadata(required = "true") + private String label; + @UriParam(label = "producer") + private AmazonEKS eksClient; + @UriParam(label = "producer", secret = true) + private String accessKey; + @UriParam(label = "producer", secret = true) + private String secretKey; + @UriParam(label = "producer") + @Metadata(required = "true") + private EKSOperations operation; + @UriParam(label = "producer") + private String proxyHost; + @UriParam(label = "producer") + private Integer proxyPort; + @UriParam + private String region; + + public AmazonEKS getEksClient() { + return eksClient; + } + + /** + * To use a existing configured AWS EKS as client + */ + public void setEksClient(AmazonEKS eksClient) { + this.eksClient = eksClient; + } + + public String getAccessKey() { + return accessKey; + } + + /** + * Amazon AWS Access Key + */ + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + /** + * Amazon AWS Secret Key + */ + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public EKSOperations getOperation() { + return operation; + } + + /** + * The operation to perform + */ + public void setOperation(EKSOperations operation) { + this.operation = operation; + } + + public String getProxyHost() { + return proxyHost; + } + + /** + * To define a proxy host when instantiating the EKS client + */ + public void setProxyHost(String proxyHost) { + this.proxyHost = proxyHost; + } + + public Integer getProxyPort() { + return proxyPort; + } + + /** + * To define a proxy port when instantiating the EKS client + */ + public void setProxyPort(Integer proxyPort) { + this.proxyPort = proxyPort; + } + + public String getRegion() { + return region; + } + + /** + * The region in which EKS client needs to work + */ + public void setRegion(String region) { + this.region = region; + } + + // ************************************************* + // + // ************************************************* + + public EKSConfiguration copy() { + try { + return (EKSConfiguration)super.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeCamelException(e); + } + } +} diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSConstants.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSConstants.java new file mode 100644 index 0000000..47b5f6d --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSConstants.java @@ -0,0 +1,29 @@ +/** + * 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.aws.eks; + +/** + * Constants used in Camel AWS EKS module + */ +public interface EKSConstants { + String OPERATION = "CamelAwsEKSOperation"; + String MAX_RESULTS = "CamelAwsEKSMaxResults"; + String DESCRIPTION = "CamelAwsEKSDescription"; + String CLUSTER_NAME = "CamelAwsEKSClusterName"; + String ROLE_ARN = "CamelAwsEKSRoleARN"; + String VPC_CONFIG = "CamelAwsEKSVPCConfig"; +} diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSEndpoint.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSEndpoint.java new file mode 100644 index 0000000..6c45acc --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSEndpoint.java @@ -0,0 +1,121 @@ +/** + * 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.aws.eks; + +import com.amazonaws.ClientConfiguration; +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSCredentialsProvider; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.eks.AmazonEKS; +import com.amazonaws.services.eks.AmazonEKSClientBuilder; + +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.support.ScheduledPollEndpoint; +import org.apache.camel.util.ObjectHelper; + +/** + * The aws-kms is used for managing Amazon EKS + */ +@UriEndpoint(firstVersion = "3.0.0", scheme = "aws-eks", title = "AWS EKS", syntax = "aws-eks:label", producerOnly = true, label = "cloud,management") +public class EKSEndpoint extends ScheduledPollEndpoint { + + private AmazonEKS eksClient; + + @UriParam + private EKSConfiguration configuration; + + public EKSEndpoint(String uri, Component component, EKSConfiguration configuration) { + super(uri, component); + this.configuration = configuration; + } + + public Consumer createConsumer(Processor processor) throws Exception { + throw new UnsupportedOperationException("You cannot receive messages from this endpoint"); + } + + public Producer createProducer() throws Exception { + return new EKSProducer(this); + } + + public boolean isSingleton() { + return true; + } + + @Override + public void doStart() throws Exception { + super.doStart(); + + eksClient = configuration.getEksClient() != null ? configuration.getEksClient() : createEKSClient(); + } + + @Override + public void doStop() throws Exception { + if (ObjectHelper.isEmpty(configuration.getEksClient())) { + if (eksClient != null) { + eksClient.shutdown(); + } + } + super.doStop(); + } + + public EKSConfiguration getConfiguration() { + return configuration; + } + + public AmazonEKS getEksClient() { + return eksClient; + } + + AmazonEKS createEKSClient() { + AmazonEKS client = null; + ClientConfiguration clientConfiguration = null; + AmazonEKSClientBuilder clientBuilder = null; + boolean isClientConfigFound = false; + if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { + clientConfiguration = new ClientConfiguration(); + clientConfiguration.setProxyHost(configuration.getProxyHost()); + clientConfiguration.setProxyPort(configuration.getProxyPort()); + isClientConfigFound = true; + } + if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) { + AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); + if (isClientConfigFound) { + clientBuilder = AmazonEKSClientBuilder.standard().withClientConfiguration(clientConfiguration).withCredentials(credentialsProvider); + } else { + clientBuilder = AmazonEKSClientBuilder.standard().withCredentials(credentialsProvider); + } + } else { + if (isClientConfigFound) { + clientBuilder = AmazonEKSClientBuilder.standard(); + } else { + clientBuilder = AmazonEKSClientBuilder.standard().withClientConfiguration(clientConfiguration); + } + } + if (ObjectHelper.isNotEmpty(configuration.getRegion())) { + clientBuilder = clientBuilder.withRegion(configuration.getRegion()); + } + client = clientBuilder.build(); + return client; + } +} diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSOperations.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSOperations.java new file mode 100644 index 0000000..ffedd44 --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSOperations.java @@ -0,0 +1,25 @@ +/** + * 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.aws.eks; + +public enum EKSOperations { + + listClusters, + describeCluster, + createCluster, + deleteCluster +} diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSProducer.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSProducer.java new file mode 100644 index 0000000..90119be --- /dev/null +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/eks/EKSProducer.java @@ -0,0 +1,175 @@ +/** + * 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.aws.eks; + +import com.amazonaws.AmazonServiceException; +import com.amazonaws.services.eks.AmazonEKS; +import com.amazonaws.services.eks.model.CreateClusterRequest; +import com.amazonaws.services.eks.model.CreateClusterResult; +import com.amazonaws.services.eks.model.DeleteClusterRequest; +import com.amazonaws.services.eks.model.DeleteClusterResult; +import com.amazonaws.services.eks.model.DescribeClusterRequest; +import com.amazonaws.services.eks.model.DescribeClusterResult; +import com.amazonaws.services.eks.model.ListClustersRequest; +import com.amazonaws.services.eks.model.ListClustersResult; +import com.amazonaws.services.eks.model.VpcConfigRequest; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.support.DefaultProducer; +import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.URISupport; + +import static org.apache.camel.component.aws.common.AwsExchangeUtil.getMessageForResponse; + +/** + * A Producer which sends messages to the Amazon EKS Service + * <a href="http://aws.amazon.com/eks/">AWS EKS</a> + */ +public class EKSProducer extends DefaultProducer { + + private transient String eksProducerToString; + + public EKSProducer(Endpoint endpoint) { + super(endpoint); + } + + public void process(Exchange exchange) throws Exception { + switch (determineOperation(exchange)) { + case listClusters: + listClusters(getEndpoint().getEksClient(), exchange); + break; + case describeCluster: + describeCluster(getEndpoint().getEksClient(), exchange); + break; + case createCluster: + createCluster(getEndpoint().getEksClient(), exchange); + break; + case deleteCluster: + deleteCluster(getEndpoint().getEksClient(), exchange); + break; + default: + throw new IllegalArgumentException("Unsupported operation"); + } + } + + private EKSOperations determineOperation(Exchange exchange) { + EKSOperations operation = exchange.getIn().getHeader(EKSConstants.OPERATION, EKSOperations.class); + if (operation == null) { + operation = getConfiguration().getOperation(); + } + return operation; + } + + protected EKSConfiguration getConfiguration() { + return getEndpoint().getConfiguration(); + } + + @Override + public String toString() { + if (eksProducerToString == null) { + eksProducerToString = "KMSProducer[" + URISupport.sanitizeUri(getEndpoint().getEndpointUri()) + "]"; + } + return eksProducerToString; + } + + @Override + public EKSEndpoint getEndpoint() { + return (EKSEndpoint)super.getEndpoint(); + } + + private void listClusters(AmazonEKS eksClient, Exchange exchange) { + ListClustersRequest request = new ListClustersRequest(); + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EKSConstants.MAX_RESULTS))) { + int maxRes = exchange.getIn().getHeader(EKSConstants.MAX_RESULTS, Integer.class); + request.withMaxResults(maxRes); + } + ListClustersResult result; + try { + result = eksClient.listClusters(request); + } catch (AmazonServiceException ase) { + log.trace("List Clusters command returned the error code {}", ase.getErrorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + + private void createCluster(AmazonEKS eksClient, Exchange exchange) { + CreateClusterRequest request = new CreateClusterRequest(); + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EKSConstants.CLUSTER_NAME))) { + String name = exchange.getIn().getHeader(EKSConstants.CLUSTER_NAME, String.class); + request.withName(name); + } + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EKSConstants.ROLE_ARN))) { + String roleArn = exchange.getIn().getHeader(EKSConstants.ROLE_ARN, String.class); + request.withRoleArn(roleArn); + } + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EKSConstants.ROLE_ARN))) { + VpcConfigRequest vpcConfig = exchange.getIn().getHeader(EKSConstants.ROLE_ARN, VpcConfigRequest.class); + request.withResourcesVpcConfig(vpcConfig); + } + CreateClusterResult result; + try { + result = eksClient.createCluster(request); + } catch (AmazonServiceException ase) { + log.trace("Create Cluster command returned the error code {}", ase.getErrorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + + private void describeCluster(AmazonEKS eksClient, Exchange exchange) { + DescribeClusterRequest request = new DescribeClusterRequest(); + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EKSConstants.CLUSTER_NAME))) { + String name = exchange.getIn().getHeader(EKSConstants.CLUSTER_NAME, String.class); + request.withName(name); + } else { + throw new IllegalArgumentException("Cluster name must be specified"); + } + DescribeClusterResult result; + try { + result = eksClient.describeCluster(request); + } catch (AmazonServiceException ase) { + log.trace("Describe Cluster command returned the error code {}", ase.getErrorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + + private void deleteCluster(AmazonEKS eksClient, Exchange exchange) { + DeleteClusterRequest request = new DeleteClusterRequest(); + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EKSConstants.CLUSTER_NAME))) { + String name = exchange.getIn().getHeader(EKSConstants.CLUSTER_NAME, String.class); + request.withName(name); + } else { + throw new IllegalArgumentException("Cluster name must be specified"); + } + DeleteClusterResult result; + try { + result = eksClient.deleteCluster(request); + } catch (AmazonServiceException ase) { + log.trace("Delete Cluster 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/main/resources/META-INF/services/org/apache/camel/component/aws-eks b/components/camel-aws/src/main/resources/META-INF/services/org/apache/camel/component/aws-eks new file mode 100644 index 0000000..8622df4 --- /dev/null +++ b/components/camel-aws/src/main/resources/META-INF/services/org/apache/camel/component/aws-eks @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +class=org.apache.camel.component.aws.eks.EKSComponent diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/AmazonEKSClientMock.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/AmazonEKSClientMock.java new file mode 100644 index 0000000..0280112 --- /dev/null +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/AmazonEKSClientMock.java @@ -0,0 +1,78 @@ +/** + * 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.aws.eks; + +import java.util.ArrayList; +import java.util.List; + +import com.amazonaws.services.eks.AbstractAmazonEKS; +import com.amazonaws.services.eks.model.Cluster; +import com.amazonaws.services.eks.model.ClusterStatus; +import com.amazonaws.services.eks.model.CreateClusterRequest; +import com.amazonaws.services.eks.model.CreateClusterResult; +import com.amazonaws.services.eks.model.DeleteClusterRequest; +import com.amazonaws.services.eks.model.DeleteClusterResult; +import com.amazonaws.services.eks.model.DescribeClusterRequest; +import com.amazonaws.services.eks.model.DescribeClusterResult; +import com.amazonaws.services.eks.model.ListClustersRequest; +import com.amazonaws.services.eks.model.ListClustersResult; + +public class AmazonEKSClientMock extends AbstractAmazonEKS { + + public AmazonEKSClientMock() { + super(); + } + + @Override + public CreateClusterResult createCluster(CreateClusterRequest request) { + CreateClusterResult res = new CreateClusterResult(); + Cluster cluster = new Cluster(); + cluster.setName("Test"); + cluster.setStatus(ClusterStatus.ACTIVE.name()); + res.setCluster(cluster); + return res; + } + + @Override + public DeleteClusterResult deleteCluster(DeleteClusterRequest request) { + DeleteClusterResult res = new DeleteClusterResult(); + Cluster cluster = new Cluster(); + cluster.setName("Test"); + cluster.setStatus(ClusterStatus.DELETING.name()); + res.setCluster(cluster); + return res; + } + + @Override + public DescribeClusterResult describeCluster(DescribeClusterRequest request) { + DescribeClusterResult res = new DescribeClusterResult(); + Cluster cluster = new Cluster(); + cluster.setName("Test"); + cluster.setStatus(ClusterStatus.ACTIVE.name()); + res.setCluster(cluster); + return res; + } + + @Override + public ListClustersResult listClusters(ListClustersRequest request) { + ListClustersResult res = new ListClustersResult(); + List<String> list = new ArrayList<String>(); + list.add("Test"); + res.setClusters(list); + return res; + } +} diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/EKSComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/EKSComponentConfigurationTest.java new file mode 100644 index 0000000..399520a --- /dev/null +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/EKSComponentConfigurationTest.java @@ -0,0 +1,51 @@ +/** + * 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.aws.eks; + +import com.amazonaws.regions.Regions; + +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class EKSComponentConfigurationTest extends CamelTestSupport { + + + @Test + public void createEndpointWithComponentElements() throws Exception { + EKSComponent component = new EKSComponent(context); + component.setAccessKey("XXX"); + component.setSecretKey("YYY"); + EKSEndpoint endpoint = (EKSEndpoint)component.createEndpoint("aws-eks://label"); + + assertEquals("XXX", endpoint.getConfiguration().getAccessKey()); + assertEquals("YYY", endpoint.getConfiguration().getSecretKey()); + } + + @Test + public void createEndpointWithComponentAndEndpointElements() throws Exception { + EKSComponent component = new EKSComponent(context); + component.setAccessKey("XXX"); + component.setSecretKey("YYY"); + component.setRegion(Regions.US_WEST_1.toString()); + EKSEndpoint endpoint = (EKSEndpoint)component.createEndpoint("aws-mq://label?accessKey=xxxxxx&secretKey=yyyyy®ion=US_EAST_1"); + + assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey()); + assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey()); + assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion()); + } + +} diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/EKSComponentVerifierExtensionTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/EKSComponentVerifierExtensionTest.java new file mode 100644 index 0000000..13d9b39 --- /dev/null +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/EKSComponentVerifierExtensionTest.java @@ -0,0 +1,73 @@ +/** + * 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.aws.eks; + +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.junit4.CamelTestSupport; +import org.junit.Assert; +import org.junit.Test; + +public class EKSComponentVerifierExtensionTest extends CamelTestSupport { + + // ************************************************* + // Tests (parameters) + // ************************************************* + @Override + public boolean isUseRouteBuilder() { + return false; + } + + @Test + public void testParameters() throws Exception { + Component component = context().getComponent("aws-eks"); + + 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("label", "test"); + parameters.put("operation", EKSOperations.listClusters); + + ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.PARAMETERS, parameters); + + Assert.assertEquals(ComponentVerifierExtension.Result.Status.OK, result.getStatus()); + } + + @Test + public void testConnectivity() throws Exception { + Component component = context().getComponent("aws-eks"); + 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("label", "test"); + parameters.put("operation", EKSOperations.listClusters); + + ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters); + + Assert.assertEquals(ComponentVerifierExtension.Result.Status.ERROR, result.getStatus()); + } + +} diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/EKSProducerSpringTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/EKSProducerSpringTest.java new file mode 100644 index 0000000..0ff1bb2 --- /dev/null +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/EKSProducerSpringTest.java @@ -0,0 +1,121 @@ +/** + * 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.aws.eks; + +import com.amazonaws.services.eks.model.CreateClusterResult; +import com.amazonaws.services.eks.model.DeleteClusterResult; +import com.amazonaws.services.eks.model.DescribeClusterResult; +import com.amazonaws.services.eks.model.ListClustersResult; +import com.amazonaws.services.eks.model.VpcConfigRequest; +import com.amazonaws.services.kms.model.CreateKeyResult; +import com.amazonaws.services.kms.model.DescribeKeyResult; +import com.amazonaws.services.kms.model.ListKeysResult; +import com.amazonaws.services.kms.model.ScheduleKeyDeletionResult; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.spring.CamelSpringTestSupport; +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class EKSProducerSpringTest extends CamelSpringTestSupport { + + @EndpointInject(uri = "mock:result") + private MockEndpoint mock; + + @Test + public void kmsListClustersTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:listClusters", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(EKSConstants.OPERATION, EKSOperations.listClusters); + } + }); + + assertMockEndpointsSatisfied(); + + ListClustersResult resultGet = (ListClustersResult) exchange.getIn().getBody(); + assertEquals(1, resultGet.getClusters().size()); + assertEquals("Test", resultGet.getClusters().get(0)); + } + + @Test + public void eksCreateClusterTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:createCluster", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(EKSConstants.OPERATION, EKSOperations.createCluster); + exchange.getIn().setHeader(EKSConstants.CLUSTER_NAME, "Test"); + VpcConfigRequest req = new VpcConfigRequest(); + exchange.getIn().setHeader(EKSConstants.VPC_CONFIG, req); + exchange.getIn().setHeader(EKSConstants.ROLE_ARN, "arn:aws:eks::123456789012:user/Camel"); + } + }); + + assertMockEndpointsSatisfied(); + + CreateClusterResult resultGet = (CreateClusterResult) exchange.getIn().getBody(); + assertEquals("Test", resultGet.getCluster().getName()); + } + + @Test + public void eksDescribeClusterTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:describeCluster", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(EKSConstants.OPERATION, EKSOperations.describeCluster); + exchange.getIn().setHeader(EKSConstants.CLUSTER_NAME, "Test"); + } + }); + + assertMockEndpointsSatisfied(); + + DescribeClusterResult resultGet = exchange.getIn().getBody(DescribeClusterResult.class); + assertEquals("Test", resultGet.getCluster().getName()); + } + + @Test + public void eksDeleteClusterTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:deleteCluster", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(EKSConstants.OPERATION, EKSOperations.deleteCluster); + exchange.getIn().setHeader(EKSConstants.CLUSTER_NAME, "Test"); + } + }); + + assertMockEndpointsSatisfied(); + + DeleteClusterResult resultGet = exchange.getIn().getBody(DeleteClusterResult.class); + assertEquals("Test", resultGet.getCluster().getName()); + } + + @Override + protected ClassPathXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/aws/eks/EKSComponentSpringTest-context.xml"); + } +} \ No newline at end of file diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/EKSProducerTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/EKSProducerTest.java new file mode 100644 index 0000000..59271df --- /dev/null +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/eks/EKSProducerTest.java @@ -0,0 +1,145 @@ +/** + * 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.aws.eks; + +import com.amazonaws.services.eks.model.CreateClusterResult; +import com.amazonaws.services.eks.model.DeleteClusterResult; +import com.amazonaws.services.eks.model.DescribeClusterResult; +import com.amazonaws.services.eks.model.ListClustersResult; +import com.amazonaws.services.eks.model.VpcConfigRequest; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class EKSProducerTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:result") + private MockEndpoint mock; + + @Test + public void kmsListClustersTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:listClusters", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(EKSConstants.OPERATION, EKSOperations.listClusters); + } + }); + + assertMockEndpointsSatisfied(); + + ListClustersResult resultGet = (ListClustersResult) exchange.getIn().getBody(); + assertEquals(1, resultGet.getClusters().size()); + assertEquals("Test", resultGet.getClusters().get(0)); + } + + @Test + public void eksCreateClusterTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:createCluster", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(EKSConstants.OPERATION, EKSOperations.createCluster); + exchange.getIn().setHeader(EKSConstants.CLUSTER_NAME, "Test"); + VpcConfigRequest req = new VpcConfigRequest(); + exchange.getIn().setHeader(EKSConstants.VPC_CONFIG, req); + exchange.getIn().setHeader(EKSConstants.ROLE_ARN, "arn:aws:eks::123456789012:user/Camel"); + } + }); + + assertMockEndpointsSatisfied(); + + CreateClusterResult resultGet = (CreateClusterResult) exchange.getIn().getBody(); + assertEquals("Test", resultGet.getCluster().getName()); + } + + @Test + public void eksDescribeClusterTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:describeCluster", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(EKSConstants.OPERATION, EKSOperations.describeCluster); + exchange.getIn().setHeader(EKSConstants.CLUSTER_NAME, "Test"); + } + }); + + assertMockEndpointsSatisfied(); + + DescribeClusterResult resultGet = exchange.getIn().getBody(DescribeClusterResult.class); + assertEquals("Test", resultGet.getCluster().getName()); + } + + @Test + public void eksDeleteClusterTest() throws Exception { + + mock.expectedMessageCount(1); + Exchange exchange = template.request("direct:deleteCluster", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(EKSConstants.OPERATION, EKSOperations.deleteCluster); + exchange.getIn().setHeader(EKSConstants.CLUSTER_NAME, "Test"); + } + }); + + assertMockEndpointsSatisfied(); + + DeleteClusterResult resultGet = exchange.getIn().getBody(DeleteClusterResult.class); + assertEquals("Test", resultGet.getCluster().getName()); + } + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry registry = super.createRegistry(); + + AmazonEKSClientMock clientMock = new AmazonEKSClientMock(); + + registry.bind("amazonEksClient", clientMock); + + return registry; + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:listClusters") + .to("aws-eks://test?eksClient=#amazonEksClient&operation=listClusters") + .to("mock:result"); + from("direct:createCluster") + .to("aws-eks://test?eksClient=#amazonEksClient&operation=createCluster") + .to("mock:result"); + from("direct:deleteCluster") + .to("aws-eks://test?eksClient=#amazonEksClient&operation=deleteCluster") + .to("mock:result"); + from("direct:describeCluster") + .to("aws-eks://test?eksClient=#amazonEksClient&operation=describeCluster") + .to("mock:result"); + } + }; + } +} \ No newline at end of file diff --git a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/eks/EKSComponentSpringTest-context.xml b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/eks/EKSComponentSpringTest-context.xml new file mode 100644 index 0000000..2b17b83 --- /dev/null +++ b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/eks/EKSComponentSpringTest-context.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:listClusters"/> + <to uri="aws-eks://test?eksClient=#amazonEksClient&operation=listClusters"/> + <to uri="mock:result"/> + </route> + <route> + <from uri="direct:createCluster"/> + <to uri="aws-eks://test?eksClient=#amazonEksClient&operation=createCluster"/> + <to uri="mock:result"/> + </route> + <route> + <from uri="direct:deleteCluster"/> + <to uri="aws-eks://test?eksClient=#amazonEksClient&operation=deleteCluster"/> + <to uri="mock:result"/> + </route> + <route> + <from uri="direct:describeCluster"/> + <to uri="aws-eks://test?eksClient=#amazonEksClient&operation=describeCluster"/> + <to uri="mock:result"/> + </route> + </camelContext> + + <bean id="amazonEksClient" class="org.apache.camel.component.aws.eks.AmazonEKSClientMock"/> +</beans> \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/eks/springboot/EKSComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/eks/springboot/EKSComponentAutoConfiguration.java new file mode 100644 index 0000000..0a31cff --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/eks/springboot/EKSComponentAutoConfiguration.java @@ -0,0 +1,128 @@ +/** + * 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.aws.eks.springboot; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Generated; +import org.apache.camel.CamelContext; +import org.apache.camel.component.aws.eks.EKSComponent; +import org.apache.camel.spi.ComponentCustomizer; +import org.apache.camel.spi.HasId; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.ComponentConfigurationProperties; +import org.apache.camel.spring.boot.util.CamelPropertiesHelper; +import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator; +import org.apache.camel.support.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@Configuration +@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class, + EKSComponentAutoConfiguration.GroupConditions.class}) +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({ComponentConfigurationProperties.class, + EKSComponentConfiguration.class}) +public class EKSComponentAutoConfiguration { + + private static final Logger LOGGER = LoggerFactory + .getLogger(EKSComponentAutoConfiguration.class); + @Autowired + private ApplicationContext applicationContext; + @Autowired + private CamelContext camelContext; + @Autowired + private EKSComponentConfiguration configuration; + @Autowired(required = false) + private List<ComponentCustomizer<EKSComponent>> customizers; + + static class GroupConditions extends GroupCondition { + public GroupConditions() { + super("camel.component", "camel.component.aws-eks"); + } + } + + @Lazy + @Bean(name = "aws-eks-component") + @ConditionalOnMissingBean(EKSComponent.class) + public EKSComponent configureEKSComponent() throws Exception { + EKSComponent component = new EKSComponent(); + component.setCamelContext(camelContext); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null, + false); + for (Map.Entry<String, Object> entry : parameters.entrySet()) { + Object value = entry.getValue(); + Class<?> paramClass = value.getClass(); + if (paramClass.getName().endsWith("NestedConfiguration")) { + Class nestedClass = null; + try { + nestedClass = (Class) paramClass.getDeclaredField( + "CAMEL_NESTED_CLASS").get(null); + HashMap<String, Object> nestedParameters = new HashMap<>(); + IntrospectionSupport.getProperties(value, nestedParameters, + null, false); + Object nestedProperty = nestedClass.newInstance(); + CamelPropertiesHelper.setCamelProperties(camelContext, + nestedProperty, nestedParameters, false); + entry.setValue(nestedProperty); + } catch (NoSuchFieldException e) { + } + } + } + CamelPropertiesHelper.setCamelProperties(camelContext, component, + parameters, false); + if (ObjectHelper.isNotEmpty(customizers)) { + for (ComponentCustomizer<EKSComponent> customizer : customizers) { + boolean useCustomizer = (customizer instanceof HasId) + ? HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.aws-eks.customizer", + ((HasId) customizer).getId()) + : HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.aws-eks.customizer"); + if (useCustomizer) { + LOGGER.debug("Configure component {}, with customizer {}", + component, customizer); + customizer.customize(component); + } + } + } + return component; + } +} \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/eks/springboot/EKSComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/eks/springboot/EKSComponentConfiguration.java new file mode 100644 index 0000000..2206d05 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/eks/springboot/EKSComponentConfiguration.java @@ -0,0 +1,193 @@ +/** + * 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.aws.eks.springboot; + +import javax.annotation.Generated; +import com.amazonaws.services.eks.AmazonEKS; +import org.apache.camel.component.aws.eks.EKSOperations; +import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * The aws-kms is used for managing Amazon EKS + * + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@ConfigurationProperties(prefix = "camel.component.aws-eks") +public class EKSComponentConfiguration + extends + ComponentConfigurationPropertiesCommon { + + /** + * Whether to enable auto configuration of the aws-eks component. This is + * enabled by default. + */ + private Boolean enabled; + /** + * The AWS KMS default configuration + */ + private EKSConfigurationNestedConfiguration configuration; + /** + * Amazon AWS Access Key + */ + private String accessKey; + /** + * Amazon AWS Secret Key + */ + private String secretKey; + /** + * The region in which KMS client needs to work + */ + private String region; + /** + * Whether the component should resolve property placeholders on itself when + * starting. Only properties which are of String type can use property + * placeholders. + */ + private Boolean resolvePropertyPlaceholders = true; + + public EKSConfigurationNestedConfiguration getConfiguration() { + return configuration; + } + + public void setConfiguration( + EKSConfigurationNestedConfiguration configuration) { + this.configuration = configuration; + } + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + + public Boolean getResolvePropertyPlaceholders() { + return resolvePropertyPlaceholders; + } + + public void setResolvePropertyPlaceholders( + Boolean resolvePropertyPlaceholders) { + this.resolvePropertyPlaceholders = resolvePropertyPlaceholders; + } + + public static class EKSConfigurationNestedConfiguration { + public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.aws.eks.EKSConfiguration.class; + /** + * To use a existing configured AWS EKS as client + */ + private AmazonEKS eksClient; + /** + * Amazon AWS Access Key + */ + private String accessKey; + /** + * Amazon AWS Secret Key + */ + private String secretKey; + /** + * The operation to perform + */ + private EKSOperations operation; + /** + * To define a proxy host when instantiating the EKS client + */ + private String proxyHost; + /** + * To define a proxy port when instantiating the EKS client + */ + private Integer proxyPort; + /** + * The region in which EKS client needs to work + */ + private String region; + + public AmazonEKS getEksClient() { + return eksClient; + } + + public void setEksClient(AmazonEKS eksClient) { + this.eksClient = eksClient; + } + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public EKSOperations getOperation() { + return operation; + } + + public void setOperation(EKSOperations operation) { + this.operation = operation; + } + + public String getProxyHost() { + return proxyHost; + } + + public void setProxyHost(String proxyHost) { + this.proxyHost = proxyHost; + } + + public Integer getProxyPort() { + return proxyPort; + } + + public void setProxyPort(Integer proxyPort) { + this.proxyPort = proxyPort; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + } +} \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/resources/META-INF/spring.factories index e2d56a1..c950886 100644 --- a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/resources/META-INF/spring.factories +++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/resources/META-INF/spring.factories @@ -30,7 +30,9 @@ org.apache.camel.component.aws.firehose.springboot.KinesisFirehoseComponentAutoC org.apache.camel.component.aws.lambda.springboot.LambdaComponentAutoConfiguration,\ org.apache.camel.component.aws.mq.springboot.MQComponentAutoConfiguration,\ org.apache.camel.component.aws.kms.springboot.KMSComponentAutoConfiguration,\ -org.apache.camel.component.aws.iam.springboot.IAMComponentAutoConfiguration +org.apache.camel.component.aws.iam.springboot.IAMComponentAutoConfiguration,\ +org.apache.camel.component.aws.eks.springboot.EKSComponentAutoConfiguration +