This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch bedrock in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4513ee77aba5196426d2141dd355afb5d5ca89a4 Author: Andrea Cosentino <[email protected]> AuthorDate: Tue Feb 27 11:08:22 2024 +0100 CAMEL-20463 - Camel AWS bedrock component Signed-off-by: Andrea Cosentino <[email protected]> --- .../camel/component/aws2/bedrock/aws-bedrock.json | 2 +- .../src/main/docs/aws-bedrock-component.adoc | 2 +- .../component/aws2/bedrock/BedrockEndpoint.java | 4 +- .../aws2/bedrock/client/BedrockClientFactory.java | 8 +-- .../bedrock/BedrockRuntimeClientFactoryTest.java | 69 ++++++++++++++++++++++ .../{ => integration}/BedrockProducerIT.java | 4 +- 6 files changed, 80 insertions(+), 9 deletions(-) diff --git a/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/org/apache/camel/component/aws2/bedrock/aws-bedrock.json b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/org/apache/camel/component/aws2/bedrock/aws-bedrock.json index a73750eb5d5..941c6a92006 100644 --- a/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/org/apache/camel/component/aws2/bedrock/aws-bedrock.json +++ b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/org/apache/camel/component/aws2/bedrock/aws-bedrock.json @@ -3,7 +3,7 @@ "kind": "component", "name": "aws-bedrock", "title": "AWS Bedrock", - "description": "Manage AWS EKS cluster instances.", + "description": "Invoke Model of AWS Bedrock service.", "deprecated": false, "firstVersion": "4.5.0", "label": "cloud,management", diff --git a/components/camel-aws/camel-aws-bedrock/src/main/docs/aws-bedrock-component.adoc b/components/camel-aws/camel-aws-bedrock/src/main/docs/aws-bedrock-component.adoc index 9e2879a45a4..2033537c15e 100644 --- a/components/camel-aws/camel-aws-bedrock/src/main/docs/aws-bedrock-component.adoc +++ b/components/camel-aws/camel-aws-bedrock/src/main/docs/aws-bedrock-component.adoc @@ -2,7 +2,7 @@ :doctitle: AWS Bedrock :shortname: aws-bedrock :artifactid: camel-aws2-bedrock -:description: Manage AWS EKS cluster instances. +:description: Invoke Model of AWS Bedrock service. :since: 4.5 :supportlevel: Preview :tabs-sync-option: diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockEndpoint.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockEndpoint.java index 0f54453e4c0..f7bad7e4f54 100644 --- a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockEndpoint.java +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockEndpoint.java @@ -29,7 +29,7 @@ import org.apache.camel.util.ObjectHelper; import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; /** - * Manage AWS EKS cluster instances. + * Invoke Model of AWS Bedrock service. */ @UriEndpoint(firstVersion = "4.5.0", scheme = "aws-bedrock", title = "AWS Bedrock", syntax = "aws-bedrock:label", producerOnly = true, category = { Category.CLOUD, Category.MANAGEMENT }, @@ -67,7 +67,7 @@ public class BedrockEndpoint extends ScheduledPollEndpoint { bedrockRuntimeClient = configuration.getBedrockRuntimeClient() != null ? configuration.getBedrockRuntimeClient() - : BedrockClientFactory.getEksClient(configuration).getBedrockRuntimeClient(); + : BedrockClientFactory.getBedrockRuntimeClient(configuration).getBedrockRuntimeClient(); } @Override diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/BedrockClientFactory.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/BedrockClientFactory.java index 3c23316507a..485ca1b0666 100644 --- a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/BedrockClientFactory.java +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/BedrockClientFactory.java @@ -23,7 +23,7 @@ import org.apache.camel.component.aws2.bedrock.client.impl.BedrockRuntimeClientS import org.apache.camel.component.aws2.bedrock.client.impl.BedrockRuntimeClientStandardImpl; /** - * Factory class to return the correct type of AWS Bedrock client. + * Factory class to return the correct type of AWS Bedrock runtime client. */ public final class BedrockClientFactory { @@ -31,12 +31,12 @@ public final class BedrockClientFactory { } /** - * Return the correct AWS Bedrock client (based on remote vs local). + * Return the correct AWS Bedrock runtime client (based on remote vs local). * * @param configuration configuration - * @return EKSClient + * @return BedrockRuntimeInternalClient */ - public static BedrockRuntimeInternalClient getEksClient(BedrockConfiguration configuration) { + public static BedrockRuntimeInternalClient getBedrockRuntimeClient(BedrockConfiguration configuration) { if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) { return new BedrockRuntimeClientIAMOptimizedImpl(configuration); } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) { diff --git a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/BedrockRuntimeClientFactoryTest.java b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/BedrockRuntimeClientFactoryTest.java new file mode 100644 index 00000000000..5dddff89d86 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/BedrockRuntimeClientFactoryTest.java @@ -0,0 +1,69 @@ +/* + * 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.bedrock; + +import org.apache.camel.component.aws2.bedrock.client.BedrockClientFactory; +import org.apache.camel.component.aws2.bedrock.client.BedrockRuntimeInternalClient; +import org.apache.camel.component.aws2.bedrock.client.impl.BedrockRuntimeClientIAMOptimizedImpl; +import org.apache.camel.component.aws2.bedrock.client.impl.BedrockRuntimeClientIAMProfileOptimizedImpl; +import org.apache.camel.component.aws2.bedrock.client.impl.BedrockRuntimeClientSessionTokenImpl; +import org.apache.camel.component.aws2.bedrock.client.impl.BedrockRuntimeClientStandardImpl; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class BedrockRuntimeClientFactoryTest { + + @Test + public void getStandardBedrockClientDefault() { + BedrockConfiguration bedrockConfiguration = new BedrockConfiguration(); + BedrockRuntimeInternalClient bedrockClient = BedrockClientFactory.getBedrockRuntimeClient(bedrockConfiguration); + assertTrue(bedrockClient instanceof BedrockRuntimeClientStandardImpl); + } + + @Test + public void getStandardDefaultBedrockClient() { + BedrockConfiguration bedrockConfiguration = new BedrockConfiguration(); + bedrockConfiguration.setUseDefaultCredentialsProvider(false); + BedrockRuntimeInternalClient bedrockClient = BedrockClientFactory.getBedrockRuntimeClient(bedrockConfiguration); + assertTrue(bedrockClient instanceof BedrockRuntimeClientStandardImpl); + } + + @Test + public void getIAMOptimizedBedrockClient() { + BedrockConfiguration bedrockConfiguration = new BedrockConfiguration(); + bedrockConfiguration.setUseDefaultCredentialsProvider(true); + BedrockRuntimeInternalClient bedrockClient = BedrockClientFactory.getBedrockRuntimeClient(bedrockConfiguration); + assertTrue(bedrockClient instanceof BedrockRuntimeClientIAMOptimizedImpl); + } + + @Test + public void getSessionTokenBedrockClient() { + BedrockConfiguration bedrockConfiguration = new BedrockConfiguration(); + bedrockConfiguration.setUseSessionCredentials(true); + BedrockRuntimeInternalClient bedrockClient = BedrockClientFactory.getBedrockRuntimeClient(bedrockConfiguration); + assertTrue(bedrockClient instanceof BedrockRuntimeClientSessionTokenImpl); + } + + @Test + public void getProfileBedrockClient() { + BedrockConfiguration bedrockConfiguration = new BedrockConfiguration(); + bedrockConfiguration.setUseProfileCredentialsProvider(true); + BedrockRuntimeInternalClient bedrockClient = BedrockClientFactory.getBedrockRuntimeClient(bedrockConfiguration); + assertTrue(bedrockClient instanceof BedrockRuntimeClientIAMProfileOptimizedImpl); + } +} diff --git a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/BedrockProducerIT.java b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/integration/BedrockProducerIT.java similarity index 95% rename from components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/BedrockProducerIT.java rename to components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/integration/BedrockProducerIT.java index ba0796343aa..44e57b055e1 100644 --- a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/BedrockProducerIT.java +++ b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/integration/BedrockProducerIT.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.aws2.bedrock; +package org.apache.camel.component.aws2.bedrock.integration; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; @@ -23,6 +23,8 @@ import org.apache.camel.EndpointInject; import org.apache.camel.Exchange; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.aws2.bedrock.BedrockConstants; +import org.apache.camel.component.aws2.bedrock.BedrockModels; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test;
