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 d4a3e44e21c7c00bbe834b3eb68bc9301246f738 Author: Andrea Cosentino <[email protected]> AuthorDate: Tue Feb 27 10:24:02 2024 +0100 CAMEL-20463 - Camel AWS bedrock component Signed-off-by: Andrea Cosentino <[email protected]> --- bom/camel-bom/pom.xml | 5 + catalog/camel-allcomponents/pom.xml | 5 + components/camel-aws/camel-aws-bedrock/pom.xml | 86 +++++++ .../aws2/bedrock/BedrockComponentConfigurer.java | 184 +++++++++++++ .../aws2/bedrock/BedrockEndpointConfigurer.java | 156 +++++++++++ .../aws2/bedrock/BedrockEndpointUriFactory.java | 92 +++++++ .../camel/component/aws2/bedrock/aws-bedrock.json | 77 ++++++ .../services/org/apache/camel/component.properties | 7 + .../org/apache/camel/component/aws-bedrock | 2 + .../apache/camel/configurer/aws-bedrock-component | 2 + .../apache/camel/configurer/aws-bedrock-endpoint | 2 + .../apache/camel/urifactory/aws-bedrock-endpoint | 2 + .../src/main/docs/aws2-eks-component.adoc | 135 ++++++++++ .../component/aws2/bedrock/BedrockComponent.java | 72 ++++++ .../aws2/bedrock/BedrockConfiguration.java | 285 +++++++++++++++++++++ .../component/aws2/bedrock/BedrockConstants.java | 31 +++ .../component/aws2/bedrock/BedrockEndpoint.java | 90 +++++++ .../component/aws2/bedrock/BedrockModels.java | 28 ++ .../component/aws2/bedrock/BedrockOperations.java | 22 ++ .../component/aws2/bedrock/BedrockProducer.java | 131 ++++++++++ .../aws2/bedrock/client/BedrockClientFactory.java | 50 ++++ .../client/BedrockRuntimeInternalClient.java | 32 +++ .../impl/BedrockRuntimeClientIAMOptimizedImpl.java | 94 +++++++ ...edrockRuntimeClientIAMProfileOptimizedImpl.java | 99 +++++++ .../impl/BedrockRuntimeClientSessionTokenImpl.java | 111 ++++++++ .../impl/BedrockRuntimeClientStandardImpl.java | 109 ++++++++ .../component/aws2/bedrock/BedrockProducerIT.java | 85 ++++++ .../src/test/resources/log4j2.properties | 28 ++ components/camel-aws/pom.xml | 1 + .../modules/ROOT/examples/json/aws-bedrock.json | 1 + parent/pom.xml | 10 + 31 files changed, 2034 insertions(+) diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml index a7ef2af46db..b51168e0471 100644 --- a/bom/camel-bom/pom.xml +++ b/bom/camel-bom/pom.xml @@ -121,6 +121,11 @@ <artifactId>camel-avro-rpc-spi</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-aws-bedrock</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws-cloudtrail</artifactId> diff --git a/catalog/camel-allcomponents/pom.xml b/catalog/camel-allcomponents/pom.xml index b4902a65b02..b3f609fdb4e 100644 --- a/catalog/camel-allcomponents/pom.xml +++ b/catalog/camel-allcomponents/pom.xml @@ -142,6 +142,11 @@ <artifactId>camel-aws2-athena</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-aws2-bedrock</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws2-cw</artifactId> diff --git a/components/camel-aws/camel-aws-bedrock/pom.xml b/components/camel-aws/camel-aws-bedrock/pom.xml new file mode 100644 index 00000000000..ecb635f4fed --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/pom.xml @@ -0,0 +1,86 @@ +<?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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>camel-aws-parent</artifactId> + <version>4.5.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-aws2-bedrock</artifactId> + <packaging>jar</packaging> + + <name>Camel :: AWS2 Bedrock</name> + <description>Execute different operations on Amazon Bedrock service</description> + + <properties> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-support</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jackson</artifactId> + </dependency> + <dependency> + <groupId>software.amazon.awssdk</groupId> + <artifactId>bedrock</artifactId> + <version>${aws-java-sdk2-version}</version> + </dependency> + <dependency> + <groupId>software.amazon.awssdk</groupId> + <artifactId>bedrockruntime</artifactId> + <version>${aws-java-sdk2-version}</version> + </dependency> + <dependency> + <groupId>software.amazon.awssdk</groupId> + <artifactId>apache-client</artifactId> + <version>${aws-java-sdk2-version}</version> + </dependency> + + <!-- for testing --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-spring-junit5</artifactId> + <scope>test</scope> + </dependency> + + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-aws-v2</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <version>${awaitility-version}</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/components/camel-aws/camel-aws-bedrock/src/generated/java/org/apache/camel/component/aws2/bedrock/BedrockComponentConfigurer.java b/components/camel-aws/camel-aws-bedrock/src/generated/java/org/apache/camel/component/aws2/bedrock/BedrockComponentConfigurer.java new file mode 100644 index 00000000000..6c971669a3c --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/generated/java/org/apache/camel/component/aws2/bedrock/BedrockComponentConfigurer.java @@ -0,0 +1,184 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.component.aws2.bedrock; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.ExtendedPropertyConfigurerGetter; +import org.apache.camel.spi.PropertyConfigurerGetter; +import org.apache.camel.spi.ConfigurerStrategy; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.util.CaseInsensitiveMap; +import org.apache.camel.support.component.PropertyConfigurerSupport; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class BedrockComponentConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { + + private org.apache.camel.component.aws2.bedrock.BedrockConfiguration getOrCreateConfiguration(BedrockComponent target) { + if (target.getConfiguration() == null) { + target.setConfiguration(new org.apache.camel.component.aws2.bedrock.BedrockConfiguration()); + } + return target.getConfiguration(); + } + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + BedrockComponent target = (BedrockComponent) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.class, value)); return true; + case "autowiredenabled": + case "autowiredEnabled": target.setAutowiredEnabled(property(camelContext, boolean.class, value)); return true; + case "bedrockruntimeclient": + case "bedrockRuntimeClient": getOrCreateConfiguration(target).setBedrockRuntimeClient(property(camelContext, software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient.class, value)); return true; + case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.aws2.bedrock.BedrockConfiguration.class, value)); return true; + case "healthcheckconsumerenabled": + case "healthCheckConsumerEnabled": target.setHealthCheckConsumerEnabled(property(camelContext, boolean.class, value)); return true; + case "healthcheckproducerenabled": + case "healthCheckProducerEnabled": target.setHealthCheckProducerEnabled(property(camelContext, boolean.class, value)); return true; + case "lazystartproducer": + case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; + case "modelid": + case "modelId": getOrCreateConfiguration(target).setModelId(property(camelContext, java.lang.String.class, value)); return true; + case "operation": getOrCreateConfiguration(target).setOperation(property(camelContext, org.apache.camel.component.aws2.bedrock.BedrockOperations.class, value)); return true; + case "overrideendpoint": + case "overrideEndpoint": getOrCreateConfiguration(target).setOverrideEndpoint(property(camelContext, boolean.class, value)); return true; + case "pojorequest": + case "pojoRequest": getOrCreateConfiguration(target).setPojoRequest(property(camelContext, boolean.class, value)); return true; + case "profilecredentialsname": + case "profileCredentialsName": getOrCreateConfiguration(target).setProfileCredentialsName(property(camelContext, java.lang.String.class, value)); return true; + case "proxyhost": + case "proxyHost": getOrCreateConfiguration(target).setProxyHost(property(camelContext, java.lang.String.class, value)); return true; + case "proxyport": + case "proxyPort": getOrCreateConfiguration(target).setProxyPort(property(camelContext, java.lang.Integer.class, value)); return true; + case "proxyprotocol": + case "proxyProtocol": getOrCreateConfiguration(target).setProxyProtocol(property(camelContext, software.amazon.awssdk.core.Protocol.class, value)); return true; + case "region": getOrCreateConfiguration(target).setRegion(property(camelContext, java.lang.String.class, value)); return true; + case "secretkey": + case "secretKey": getOrCreateConfiguration(target).setSecretKey(property(camelContext, java.lang.String.class, value)); return true; + case "sessiontoken": + case "sessionToken": getOrCreateConfiguration(target).setSessionToken(property(camelContext, java.lang.String.class, value)); return true; + case "trustallcertificates": + case "trustAllCertificates": getOrCreateConfiguration(target).setTrustAllCertificates(property(camelContext, boolean.class, value)); return true; + case "uriendpointoverride": + case "uriEndpointOverride": getOrCreateConfiguration(target).setUriEndpointOverride(property(camelContext, java.lang.String.class, value)); return true; + case "usedefaultcredentialsprovider": + case "useDefaultCredentialsProvider": getOrCreateConfiguration(target).setUseDefaultCredentialsProvider(property(camelContext, boolean.class, value)); return true; + case "useprofilecredentialsprovider": + case "useProfileCredentialsProvider": getOrCreateConfiguration(target).setUseProfileCredentialsProvider(property(camelContext, boolean.class, value)); return true; + case "usesessioncredentials": + case "useSessionCredentials": getOrCreateConfiguration(target).setUseSessionCredentials(property(camelContext, boolean.class, value)); return true; + default: return false; + } + } + + @Override + public String[] getAutowiredNames() { + return new String[]{"bedrockRuntimeClient"}; + } + + @Override + public Class<?> getOptionType(String name, boolean ignoreCase) { + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "accessKey": return java.lang.String.class; + case "autowiredenabled": + case "autowiredEnabled": return boolean.class; + case "bedrockruntimeclient": + case "bedrockRuntimeClient": return software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient.class; + case "configuration": return org.apache.camel.component.aws2.bedrock.BedrockConfiguration.class; + case "healthcheckconsumerenabled": + case "healthCheckConsumerEnabled": return boolean.class; + case "healthcheckproducerenabled": + case "healthCheckProducerEnabled": return boolean.class; + case "lazystartproducer": + case "lazyStartProducer": return boolean.class; + case "modelid": + case "modelId": return java.lang.String.class; + case "operation": return org.apache.camel.component.aws2.bedrock.BedrockOperations.class; + case "overrideendpoint": + case "overrideEndpoint": return boolean.class; + case "pojorequest": + case "pojoRequest": return boolean.class; + case "profilecredentialsname": + case "profileCredentialsName": return java.lang.String.class; + case "proxyhost": + case "proxyHost": return java.lang.String.class; + case "proxyport": + case "proxyPort": return java.lang.Integer.class; + case "proxyprotocol": + case "proxyProtocol": return software.amazon.awssdk.core.Protocol.class; + case "region": return java.lang.String.class; + case "secretkey": + case "secretKey": return java.lang.String.class; + case "sessiontoken": + case "sessionToken": return java.lang.String.class; + case "trustallcertificates": + case "trustAllCertificates": return boolean.class; + case "uriendpointoverride": + case "uriEndpointOverride": return java.lang.String.class; + case "usedefaultcredentialsprovider": + case "useDefaultCredentialsProvider": return boolean.class; + case "useprofilecredentialsprovider": + case "useProfileCredentialsProvider": return boolean.class; + case "usesessioncredentials": + case "useSessionCredentials": return boolean.class; + default: return null; + } + } + + @Override + public Object getOptionValue(Object obj, String name, boolean ignoreCase) { + BedrockComponent target = (BedrockComponent) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "accessKey": return getOrCreateConfiguration(target).getAccessKey(); + case "autowiredenabled": + case "autowiredEnabled": return target.isAutowiredEnabled(); + case "bedrockruntimeclient": + case "bedrockRuntimeClient": return getOrCreateConfiguration(target).getBedrockRuntimeClient(); + case "configuration": return target.getConfiguration(); + case "healthcheckconsumerenabled": + case "healthCheckConsumerEnabled": return target.isHealthCheckConsumerEnabled(); + case "healthcheckproducerenabled": + case "healthCheckProducerEnabled": return target.isHealthCheckProducerEnabled(); + case "lazystartproducer": + case "lazyStartProducer": return target.isLazyStartProducer(); + case "modelid": + case "modelId": return getOrCreateConfiguration(target).getModelId(); + case "operation": return getOrCreateConfiguration(target).getOperation(); + case "overrideendpoint": + case "overrideEndpoint": return getOrCreateConfiguration(target).isOverrideEndpoint(); + case "pojorequest": + case "pojoRequest": return getOrCreateConfiguration(target).isPojoRequest(); + case "profilecredentialsname": + case "profileCredentialsName": return getOrCreateConfiguration(target).getProfileCredentialsName(); + case "proxyhost": + case "proxyHost": return getOrCreateConfiguration(target).getProxyHost(); + case "proxyport": + case "proxyPort": return getOrCreateConfiguration(target).getProxyPort(); + case "proxyprotocol": + case "proxyProtocol": return getOrCreateConfiguration(target).getProxyProtocol(); + case "region": return getOrCreateConfiguration(target).getRegion(); + case "secretkey": + case "secretKey": return getOrCreateConfiguration(target).getSecretKey(); + case "sessiontoken": + case "sessionToken": return getOrCreateConfiguration(target).getSessionToken(); + case "trustallcertificates": + case "trustAllCertificates": return getOrCreateConfiguration(target).isTrustAllCertificates(); + case "uriendpointoverride": + case "uriEndpointOverride": return getOrCreateConfiguration(target).getUriEndpointOverride(); + case "usedefaultcredentialsprovider": + case "useDefaultCredentialsProvider": return getOrCreateConfiguration(target).isUseDefaultCredentialsProvider(); + case "useprofilecredentialsprovider": + case "useProfileCredentialsProvider": return getOrCreateConfiguration(target).isUseProfileCredentialsProvider(); + case "usesessioncredentials": + case "useSessionCredentials": return getOrCreateConfiguration(target).isUseSessionCredentials(); + default: return null; + } + } +} + diff --git a/components/camel-aws/camel-aws-bedrock/src/generated/java/org/apache/camel/component/aws2/bedrock/BedrockEndpointConfigurer.java b/components/camel-aws/camel-aws-bedrock/src/generated/java/org/apache/camel/component/aws2/bedrock/BedrockEndpointConfigurer.java new file mode 100644 index 00000000000..1f516f703a8 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/generated/java/org/apache/camel/component/aws2/bedrock/BedrockEndpointConfigurer.java @@ -0,0 +1,156 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.component.aws2.bedrock; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.ExtendedPropertyConfigurerGetter; +import org.apache.camel.spi.PropertyConfigurerGetter; +import org.apache.camel.spi.ConfigurerStrategy; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.util.CaseInsensitiveMap; +import org.apache.camel.support.component.PropertyConfigurerSupport; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class BedrockEndpointConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + BedrockEndpoint target = (BedrockEndpoint) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "accessKey": target.getConfiguration().setAccessKey(property(camelContext, java.lang.String.class, value)); return true; + case "bedrockruntimeclient": + case "bedrockRuntimeClient": target.getConfiguration().setBedrockRuntimeClient(property(camelContext, software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient.class, value)); return true; + case "lazystartproducer": + case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; + case "modelid": + case "modelId": target.getConfiguration().setModelId(property(camelContext, java.lang.String.class, value)); return true; + case "operation": target.getConfiguration().setOperation(property(camelContext, org.apache.camel.component.aws2.bedrock.BedrockOperations.class, value)); return true; + case "overrideendpoint": + case "overrideEndpoint": target.getConfiguration().setOverrideEndpoint(property(camelContext, boolean.class, value)); return true; + case "pojorequest": + case "pojoRequest": target.getConfiguration().setPojoRequest(property(camelContext, boolean.class, value)); return true; + case "profilecredentialsname": + case "profileCredentialsName": target.getConfiguration().setProfileCredentialsName(property(camelContext, java.lang.String.class, value)); return true; + case "proxyhost": + case "proxyHost": target.getConfiguration().setProxyHost(property(camelContext, java.lang.String.class, value)); return true; + case "proxyport": + case "proxyPort": target.getConfiguration().setProxyPort(property(camelContext, java.lang.Integer.class, value)); return true; + case "proxyprotocol": + case "proxyProtocol": target.getConfiguration().setProxyProtocol(property(camelContext, software.amazon.awssdk.core.Protocol.class, value)); return true; + case "region": target.getConfiguration().setRegion(property(camelContext, java.lang.String.class, value)); return true; + case "secretkey": + case "secretKey": target.getConfiguration().setSecretKey(property(camelContext, java.lang.String.class, value)); return true; + case "sessiontoken": + case "sessionToken": target.getConfiguration().setSessionToken(property(camelContext, java.lang.String.class, value)); return true; + case "trustallcertificates": + case "trustAllCertificates": target.getConfiguration().setTrustAllCertificates(property(camelContext, boolean.class, value)); return true; + case "uriendpointoverride": + case "uriEndpointOverride": target.getConfiguration().setUriEndpointOverride(property(camelContext, java.lang.String.class, value)); return true; + case "usedefaultcredentialsprovider": + case "useDefaultCredentialsProvider": target.getConfiguration().setUseDefaultCredentialsProvider(property(camelContext, boolean.class, value)); return true; + case "useprofilecredentialsprovider": + case "useProfileCredentialsProvider": target.getConfiguration().setUseProfileCredentialsProvider(property(camelContext, boolean.class, value)); return true; + case "usesessioncredentials": + case "useSessionCredentials": target.getConfiguration().setUseSessionCredentials(property(camelContext, boolean.class, value)); return true; + default: return false; + } + } + + @Override + public String[] getAutowiredNames() { + return new String[]{"bedrockRuntimeClient"}; + } + + @Override + public Class<?> getOptionType(String name, boolean ignoreCase) { + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "accessKey": return java.lang.String.class; + case "bedrockruntimeclient": + case "bedrockRuntimeClient": return software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient.class; + case "lazystartproducer": + case "lazyStartProducer": return boolean.class; + case "modelid": + case "modelId": return java.lang.String.class; + case "operation": return org.apache.camel.component.aws2.bedrock.BedrockOperations.class; + case "overrideendpoint": + case "overrideEndpoint": return boolean.class; + case "pojorequest": + case "pojoRequest": return boolean.class; + case "profilecredentialsname": + case "profileCredentialsName": return java.lang.String.class; + case "proxyhost": + case "proxyHost": return java.lang.String.class; + case "proxyport": + case "proxyPort": return java.lang.Integer.class; + case "proxyprotocol": + case "proxyProtocol": return software.amazon.awssdk.core.Protocol.class; + case "region": return java.lang.String.class; + case "secretkey": + case "secretKey": return java.lang.String.class; + case "sessiontoken": + case "sessionToken": return java.lang.String.class; + case "trustallcertificates": + case "trustAllCertificates": return boolean.class; + case "uriendpointoverride": + case "uriEndpointOverride": return java.lang.String.class; + case "usedefaultcredentialsprovider": + case "useDefaultCredentialsProvider": return boolean.class; + case "useprofilecredentialsprovider": + case "useProfileCredentialsProvider": return boolean.class; + case "usesessioncredentials": + case "useSessionCredentials": return boolean.class; + default: return null; + } + } + + @Override + public Object getOptionValue(Object obj, String name, boolean ignoreCase) { + BedrockEndpoint target = (BedrockEndpoint) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "accessKey": return target.getConfiguration().getAccessKey(); + case "bedrockruntimeclient": + case "bedrockRuntimeClient": return target.getConfiguration().getBedrockRuntimeClient(); + case "lazystartproducer": + case "lazyStartProducer": return target.isLazyStartProducer(); + case "modelid": + case "modelId": return target.getConfiguration().getModelId(); + case "operation": return target.getConfiguration().getOperation(); + case "overrideendpoint": + case "overrideEndpoint": return target.getConfiguration().isOverrideEndpoint(); + case "pojorequest": + case "pojoRequest": return target.getConfiguration().isPojoRequest(); + case "profilecredentialsname": + case "profileCredentialsName": return target.getConfiguration().getProfileCredentialsName(); + case "proxyhost": + case "proxyHost": return target.getConfiguration().getProxyHost(); + case "proxyport": + case "proxyPort": return target.getConfiguration().getProxyPort(); + case "proxyprotocol": + case "proxyProtocol": return target.getConfiguration().getProxyProtocol(); + case "region": return target.getConfiguration().getRegion(); + case "secretkey": + case "secretKey": return target.getConfiguration().getSecretKey(); + case "sessiontoken": + case "sessionToken": return target.getConfiguration().getSessionToken(); + case "trustallcertificates": + case "trustAllCertificates": return target.getConfiguration().isTrustAllCertificates(); + case "uriendpointoverride": + case "uriEndpointOverride": return target.getConfiguration().getUriEndpointOverride(); + case "usedefaultcredentialsprovider": + case "useDefaultCredentialsProvider": return target.getConfiguration().isUseDefaultCredentialsProvider(); + case "useprofilecredentialsprovider": + case "useProfileCredentialsProvider": return target.getConfiguration().isUseProfileCredentialsProvider(); + case "usesessioncredentials": + case "useSessionCredentials": return target.getConfiguration().isUseSessionCredentials(); + default: return null; + } + } +} + diff --git a/components/camel-aws/camel-aws-bedrock/src/generated/java/org/apache/camel/component/aws2/bedrock/BedrockEndpointUriFactory.java b/components/camel-aws/camel-aws-bedrock/src/generated/java/org/apache/camel/component/aws2/bedrock/BedrockEndpointUriFactory.java new file mode 100644 index 00000000000..e9f56142145 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/generated/java/org/apache/camel/component/aws2/bedrock/BedrockEndpointUriFactory.java @@ -0,0 +1,92 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.component.aws2.bedrock; + +import java.net.URISyntaxException; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.camel.spi.EndpointUriFactory; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +public class BedrockEndpointUriFactory extends org.apache.camel.support.component.EndpointUriFactorySupport implements EndpointUriFactory { + + private static final String BASE = ":label"; + + private static final Set<String> PROPERTY_NAMES; + private static final Set<String> SECRET_PROPERTY_NAMES; + private static final Set<String> MULTI_VALUE_PREFIXES; + static { + Set<String> props = new HashSet<>(20); + props.add("accessKey"); + props.add("bedrockRuntimeClient"); + props.add("label"); + props.add("lazyStartProducer"); + props.add("modelId"); + props.add("operation"); + props.add("overrideEndpoint"); + props.add("pojoRequest"); + props.add("profileCredentialsName"); + props.add("proxyHost"); + props.add("proxyPort"); + props.add("proxyProtocol"); + props.add("region"); + props.add("secretKey"); + props.add("sessionToken"); + props.add("trustAllCertificates"); + props.add("uriEndpointOverride"); + props.add("useDefaultCredentialsProvider"); + props.add("useProfileCredentialsProvider"); + props.add("useSessionCredentials"); + PROPERTY_NAMES = Collections.unmodifiableSet(props); + Set<String> secretProps = new HashSet<>(4); + secretProps.add("accessKey"); + secretProps.add("modelId"); + secretProps.add("secretKey"); + secretProps.add("sessionToken"); + SECRET_PROPERTY_NAMES = Collections.unmodifiableSet(secretProps); + MULTI_VALUE_PREFIXES = Collections.emptySet(); + } + + @Override + public boolean isEnabled(String scheme) { + return "aws-bedrock".equals(scheme); + } + + @Override + public String buildUri(String scheme, Map<String, Object> properties, boolean encode) throws URISyntaxException { + String syntax = scheme + BASE; + String uri = syntax; + + Map<String, Object> copy = new HashMap<>(properties); + + uri = buildPathParameter(syntax, uri, "label", null, true, copy); + uri = buildQueryParameters(uri, copy, encode); + return uri; + } + + @Override + public Set<String> propertyNames() { + return PROPERTY_NAMES; + } + + @Override + public Set<String> secretPropertyNames() { + return SECRET_PROPERTY_NAMES; + } + + @Override + public Set<String> multiValuePrefixes() { + return MULTI_VALUE_PREFIXES; + } + + @Override + public boolean isLenientProperties() { + return false; + } +} + 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 new file mode 100644 index 00000000000..a73750eb5d5 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/org/apache/camel/component/aws2/bedrock/aws-bedrock.json @@ -0,0 +1,77 @@ +{ + "component": { + "kind": "component", + "name": "aws-bedrock", + "title": "AWS Bedrock", + "description": "Manage AWS EKS cluster instances.", + "deprecated": false, + "firstVersion": "4.5.0", + "label": "cloud,management", + "javaType": "org.apache.camel.component.aws2.bedrock.BedrockComponent", + "supportLevel": "Preview", + "groupId": "org.apache.camel", + "artifactId": "camel-aws2-bedrock", + "version": "4.5.0-SNAPSHOT", + "scheme": "aws-bedrock", + "extendsScheme": "", + "syntax": "aws-bedrock:label", + "async": false, + "api": false, + "consumerOnly": false, + "producerOnly": true, + "lenientProperties": false, + "remote": true + }, + "componentProperties": { + "configuration": { "index": 0, "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "Component configuration" }, + "lazyStartProducer": { "index": 1, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...] + "modelId": { "index": 2, "kind": "property", "displayName": "Model Id", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Define the model Id we are going to use" }, + "operation": { "index": 3, "kind": "property", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws2.bedrock.BedrockOperations", "enum": [ "invokeModel" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "The operation to perform" }, + "overrideEndpoint": { "index": 4, "kind": "property", "displayName": "Override Endpoint", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Set the need for overriding the endpoint. This option needs to be used in combina [...] + "pojoRequest": { "index": 5, "kind": "property", "displayName": "Pojo Request", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "If we want to use a POJO request as body or not" }, + "profileCredentialsName": { "index": 6, "kind": "property", "displayName": "Profile Credentials Name", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "false", "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "If using a profile credentials provider, this parameter wi [...] + "region": { "index": 7, "kind": "property", "displayName": "Region", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "ap-south-2", "ap-south-1", "eu-south-1", "eu-south-2", "us-gov-east-1", "me-central-1", "il-central-1", "ca-central-1", "eu-central-1", "us-iso-west-1", "eu-central-2", "us-west-1", "us-west-2", "af-south-1", "eu-north-1", "eu-west-3", "eu-west-2", "eu-west-1", "ap-northeast-3", "ap-northeast-2", "ap-nor [...] + "uriEndpointOverride": { "index": 8, "kind": "property", "displayName": "Uri Endpoint Override", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Set the overriding uri endpoint. This option needs to be used in combination with overrid [...] + "useDefaultCredentialsProvider": { "index": 9, "kind": "property", "displayName": "Use Default Credentials Provider", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Set whether the Bedrock client should expect to load [...] + "useProfileCredentialsProvider": { "index": 10, "kind": "property", "displayName": "Use Profile Credentials Provider", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Set whether the Bedrock client should expect to load [...] + "autowiredEnabled": { "index": 11, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching [...] + "bedrockRuntimeClient": { "index": 12, "kind": "property", "displayName": "Bedrock Runtime Client", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "To us [...] + "healthCheckConsumerEnabled": { "index": 13, "kind": "property", "displayName": "Health Check Consumer Enabled", "group": "health", "label": "health", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Used for enabling or disabling all consumer based health checks from this component" }, + "healthCheckProducerEnabled": { "index": 14, "kind": "property", "displayName": "Health Check Producer Enabled", "group": "health", "label": "health", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on produce [...] + "proxyHost": { "index": 15, "kind": "property", "displayName": "Proxy Host", "group": "proxy", "label": "proxy", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the Bedrock client" }, + "proxyPort": { "index": 16, "kind": "property", "displayName": "Proxy Port", "group": "proxy", "label": "proxy", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "To define a proxy port when instantiating the Bedrock client" }, + "proxyProtocol": { "index": 17, "kind": "property", "displayName": "Proxy Protocol", "group": "proxy", "label": "proxy", "required": false, "type": "object", "javaType": "software.amazon.awssdk.core.Protocol", "enum": [ "HTTP", "HTTPS" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "HTTPS", "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "To define a proxy protoco [...] + "accessKey": { "index": 18, "kind": "property", "displayName": "Access Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, + "secretKey": { "index": 19, "kind": "property", "displayName": "Secret Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" }, + "sessionToken": { "index": 20, "kind": "property", "displayName": "Session Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Amazon AWS Session Token used when the user needs to assume an IAM role" }, + "trustAllCertificates": { "index": 21, "kind": "property", "displayName": "Trust All Certificates", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the [...] + "useSessionCredentials": { "index": 22, "kind": "property", "displayName": "Use Session Credentials", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Set whether the Bedrock client should expect to use Session C [...] + }, + "headers": { + "CamelAwsBedrockOperation": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The operation we want to perform", "constantName": "org.apache.camel.component.aws2.bedrock.BedrockConstants#OPERATION" }, + "CamelAwsBedrockContentType": { "index": 1, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The model content type", "constantName": "org.apache.camel.component.aws2.bedrock.BedrockConstants#MODEL_CONTENT_TYPE" }, + "CamelAwsBedrockAcceptContentType": { "index": 2, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The model accept content type", "constantName": "org.apache.camel.component.aws2.bedrock.BedrockConstants#MODEL_ACCEPT_CONTENT_TYPE" } + }, + "properties": { + "label": { "index": 0, "kind": "path", "displayName": "Label", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Logical name" }, + "modelId": { "index": 1, "kind": "parameter", "displayName": "Model Id", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Define the model Id we are going to use" }, + "operation": { "index": 2, "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws2.bedrock.BedrockOperations", "enum": [ "invokeModel" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "The operation to per [...] + "overrideEndpoint": { "index": 3, "kind": "parameter", "displayName": "Override Endpoint", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Set the need for overriding the endpoint. This option needs to be used in combin [...] + "pojoRequest": { "index": 4, "kind": "parameter", "displayName": "Pojo Request", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "If we want to use a POJO request as body or not" }, + "profileCredentialsName": { "index": 5, "kind": "parameter", "displayName": "Profile Credentials Name", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "false", "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "If using a profile credentials provider, this parameter w [...] + "region": { "index": 6, "kind": "parameter", "displayName": "Region", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "ap-south-2", "ap-south-1", "eu-south-1", "eu-south-2", "us-gov-east-1", "me-central-1", "il-central-1", "ca-central-1", "eu-central-1", "us-iso-west-1", "eu-central-2", "us-west-1", "us-west-2", "af-south-1", "eu-north-1", "eu-west-3", "eu-west-2", "eu-west-1", "ap-northeast-3", "ap-northeast-2", "ap-no [...] + "uriEndpointOverride": { "index": 7, "kind": "parameter", "displayName": "Uri Endpoint Override", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Set the overriding uri endpoint. This option needs to be used in combination with overri [...] + "useDefaultCredentialsProvider": { "index": 8, "kind": "parameter", "displayName": "Use Default Credentials Provider", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Set whether the Bedrock client should expect to load [...] + "useProfileCredentialsProvider": { "index": 9, "kind": "parameter", "displayName": "Use Profile Credentials Provider", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Set whether the Bedrock client should expect to load [...] + "lazyStartProducer": { "index": 10, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a produ [...] + "bedrockRuntimeClient": { "index": 11, "kind": "parameter", "displayName": "Bedrock Runtime Client", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "To u [...] + "proxyHost": { "index": 12, "kind": "parameter", "displayName": "Proxy Host", "group": "proxy", "label": "proxy", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the Bedrock client" }, + "proxyPort": { "index": 13, "kind": "parameter", "displayName": "Proxy Port", "group": "proxy", "label": "proxy", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "To define a proxy port when instantiating the Bedrock client" }, + "proxyProtocol": { "index": 14, "kind": "parameter", "displayName": "Proxy Protocol", "group": "proxy", "label": "proxy", "required": false, "type": "object", "javaType": "software.amazon.awssdk.core.Protocol", "enum": [ "HTTP", "HTTPS" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "HTTPS", "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "To define a proxy protoc [...] + "accessKey": { "index": 15, "kind": "parameter", "displayName": "Access Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, + "secretKey": { "index": 16, "kind": "parameter", "displayName": "Secret Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" }, + "sessionToken": { "index": 17, "kind": "parameter", "displayName": "Session Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Amazon AWS Session Token used when the user needs to assume an IAM role" }, + "trustAllCertificates": { "index": 18, "kind": "parameter", "displayName": "Trust All Certificates", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the [...] + "useSessionCredentials": { "index": 19, "kind": "parameter", "displayName": "Use Session Credentials", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.bedrock.BedrockConfiguration", "configurationField": "configuration", "description": "Set whether the Bedrock client should expect to use Session [...] + } +} diff --git a/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/component.properties b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/component.properties new file mode 100644 index 00000000000..404c214d9da --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/component.properties @@ -0,0 +1,7 @@ +# Generated by camel build tools - do NOT edit this file! +components=aws-bedrock +groupId=org.apache.camel +artifactId=camel-aws2-bedrock +version=4.5.0-SNAPSHOT +projectName=Camel :: AWS2 Bedrock +projectDescription=Execute different operations on Amazon Bedrock service diff --git a/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/component/aws-bedrock b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/component/aws-bedrock new file mode 100644 index 00000000000..a8c817d85d6 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/component/aws-bedrock @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.aws2.bedrock.BedrockComponent diff --git a/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/configurer/aws-bedrock-component b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/configurer/aws-bedrock-component new file mode 100644 index 00000000000..ba30d2eeb23 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/configurer/aws-bedrock-component @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.aws2.bedrock.BedrockComponentConfigurer diff --git a/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/configurer/aws-bedrock-endpoint b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/configurer/aws-bedrock-endpoint new file mode 100644 index 00000000000..6ed18382f3d --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/configurer/aws-bedrock-endpoint @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.aws2.bedrock.BedrockEndpointConfigurer diff --git a/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/urifactory/aws-bedrock-endpoint b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/urifactory/aws-bedrock-endpoint new file mode 100644 index 00000000000..2519dee437c --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/services/org/apache/camel/urifactory/aws-bedrock-endpoint @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.aws2.bedrock.BedrockEndpointUriFactory diff --git a/components/camel-aws/camel-aws-bedrock/src/main/docs/aws2-eks-component.adoc b/components/camel-aws/camel-aws-bedrock/src/main/docs/aws2-eks-component.adoc new file mode 100644 index 00000000000..c9825057f00 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/docs/aws2-eks-component.adoc @@ -0,0 +1,135 @@ += AWS Elastic Kubernetes Service (EKS) Component +:doctitle: AWS Elastic Kubernetes Service (EKS) +:shortname: aws2-eks +:artifactid: camel-aws2-eks +:description: Manage AWS EKS cluster instances. +:since: 3.1 +:supportlevel: Stable +:tabs-sync-option: +:component-header: Only producer is supported +//Manually maintained attributes +:group: AWS +:camel-spring-boot-name: aws2-eks + +*Since Camel {since}* + +*{component-header}* + +The AWS2 EKS component supports create, delete, describe and list clusters +https://aws.amazon.com/eks/[AWS EKS] clusters instances. + +Prerequisites + +You must have a valid Amazon Web Services developer account, and be +signed up to use Amazon EKS. More information is available at +https://aws.amazon.com/eks/[Amazon EKS]. + + +== URI Format + +------------------------- +aws2-eks://label[?options] +------------------------- + +You can append query options to the URI in the following format: + +`?options=value&option2=value&...` + + +// component-configure options: START + +// component-configure options: END + +// component options: START +include::partial$component-configure-options.adoc[] +include::partial$component-endpoint-options.adoc[] +// component options: END + +// endpoint options: START + +// endpoint options: END + + +Required EKS component options + +You have to provide the amazonEKSClient in the +Registry or your accessKey and secretKey to access +the https://aws.amazon.com/eks/[Amazon EKS] service. + +== Usage + +=== Static credentials, Default Credential Provider and Profile Credentials Provider + +You have the possibility of avoiding the usage of explicit static credentials by specifying the useDefaultCredentialsProvider option and set it to true. + +The order of evaluation for Default Credentials Provider is the following: + + - Java system properties - `aws.accessKeyId` and `aws.secretKey`. + - Environment variables - `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. + - Web Identity Token from AWS STS. + - The shared credentials and config files. + - Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI` is set. + - Amazon EC2 Instance profile credentials. + +You have also the possibility of using Profile Credentials Provider, by specifying the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name. + +Only one of static, default and profile credentials could be used at the same time. + +For more information about this you can look at https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials.html[AWS credentials documentation] + +// component headers: START +include::partial$component-endpoint-headers.adoc[] +// component headers: END + +=== EKS Producer operations + +Camel-AWS EKS component provides the following operation on the producer side: + +- listClusters +- createCluster +- describeCluster +- deleteCluster + +== Producer Examples + +- listClusters: this operation will list the available clusters in EKS + +[source,java] +-------------------------------------------------------------------------------- +from("direct:listClusters") + .to("aws2-eks://test?eksClient=#amazonEksClient&operation=listClusters") +-------------------------------------------------------------------------------- + +== Using a POJO as body + +Sometimes building an AWS Request can be complex because of multiple options. We introduce the possibility to use a POJO as a body. +In AWS EKS there are multiple operations you can submit, as an example for List cluster request, you can do something like: + +[source,java] +------------------------------------------------------------------------------------------------------ +from("direct:start") + .setBody(ListClustersRequest.builder().maxResults(12).build()) + .to("aws2-eks://test?eksClient=#amazonEksClient&operation=listClusters&pojoRequest=true") +------------------------------------------------------------------------------------------------------ + +In this way, you'll pass the request directly without the need of passing headers and options specifically related to this operation. + +== Dependencies + +Maven users will need to add the following dependency to their pom.xml. + +*pom.xml* + +[source,xml] +--------------------------------------- +<dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-aws2-eks</artifactId> + <version>${camel-version}</version> +</dependency> +--------------------------------------- + +where `$\{camel-version}` must be replaced by the actual version of Camel. + + +include::spring-boot:partial$starter.adoc[] diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockComponent.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockComponent.java new file mode 100644 index 00000000000..b3ddab6e515 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockComponent.java @@ -0,0 +1,72 @@ +/* + * 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 java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.annotations.Component; +import org.apache.camel.support.HealthCheckComponent; + +/** + * For working with Amazon Bedrock SDK v2. + */ +@Component("aws-bedrock") +public class BedrockComponent extends HealthCheckComponent { + + @Metadata + private BedrockConfiguration configuration = new BedrockConfiguration(); + + public BedrockComponent() { + this(null); + } + + public BedrockComponent(CamelContext context) { + super(context); + } + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + BedrockConfiguration configuration + = this.configuration != null ? this.configuration.copy() : new BedrockConfiguration(); + BedrockEndpoint endpoint = new BedrockEndpoint(uri, this, configuration); + setProperties(endpoint, parameters); + if (Boolean.FALSE.equals(configuration.isUseDefaultCredentialsProvider()) + && Boolean.FALSE.equals(configuration.isUseProfileCredentialsProvider()) + && Boolean.FALSE.equals(configuration.isUseSessionCredentials()) + && configuration.getBedrockRuntimeClient() == null + && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { + throw new IllegalArgumentException( + "useDefaultCredentialsProvider is set to false, useProfileCredentialsProvider is set to false, useSessionCredentials is set to false, Amazon eks client or accessKey and secretKey must be specified"); + } + + return endpoint; + } + + public BedrockConfiguration getConfiguration() { + return configuration; + } + + /** + * Component configuration + */ + public void setConfiguration(BedrockConfiguration configuration) { + this.configuration = configuration; + } +} diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockConfiguration.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockConfiguration.java new file mode 100644 index 00000000000..a2ba9ab6999 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockConfiguration.java @@ -0,0 +1,285 @@ +/* + * 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.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; +import software.amazon.awssdk.core.Protocol; +import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; + +@UriParams +public class BedrockConfiguration implements Cloneable { + + @UriPath(description = "Logical name") + @Metadata(required = true) + private String label; + @UriParam + @Metadata(label = "advanced", autowired = true) + private BedrockRuntimeClient bedrockRuntimeClient; + @UriParam(label = "security", secret = true) + private String accessKey; + @UriParam(label = "security", secret = true) + private String secretKey; + @UriParam(label = "security", secret = true) + private String sessionToken; + @UriParam(secret = true) + private String modelId; + @UriParam + @Metadata(required = true) + private BedrockOperations operation; + @UriParam(label = "proxy", enums = "HTTP,HTTPS", defaultValue = "HTTPS") + private Protocol proxyProtocol = Protocol.HTTPS; + @UriParam(label = "proxy") + private String proxyHost; + @UriParam(label = "proxy") + private Integer proxyPort; + @UriParam(enums = "ap-south-2,ap-south-1,eu-south-1,eu-south-2,us-gov-east-1,me-central-1,il-central-1,ca-central-1,eu-central-1,us-iso-west-1,eu-central-2,us-west-1,us-west-2,af-south-1,eu-north-1,eu-west-3,eu-west-2,eu-west-1,ap-northeast-3,ap-northeast-2,ap-northeast-1,me-south-1,sa-east-1,ap-east-1,cn-north-1,us-gov-west-1,ap-southeast-1,ap-southeast-2,us-iso-east-1,ap-southeast-3,ap-southeast-4,us-east-1,us-east-2,cn-northwest-1,us-isob-east-1,aws-global,aws-cn-global,aws-us-gov [...] + private String region; + @UriParam + private boolean pojoRequest; + @UriParam(label = "security") + private boolean trustAllCertificates; + @UriParam + private boolean overrideEndpoint; + @UriParam + private String uriEndpointOverride; + @UriParam(defaultValue = "false") + private boolean useDefaultCredentialsProvider; + @UriParam(defaultValue = "false") + private boolean useProfileCredentialsProvider; + @UriParam(label = "security") + private boolean useSessionCredentials; + @UriParam(defaultValue = "false") + private String profileCredentialsName; + + public BedrockRuntimeClient getBedrockRuntimeClient() { + return bedrockRuntimeClient; + } + + /** + * To use an existing configured AWS Bedrock Runtime client + */ + public void setBedrockRuntimeClient(BedrockRuntimeClient bedrockRuntimeClient) { + this.bedrockRuntimeClient = bedrockRuntimeClient; + } + + 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 String getSessionToken() { + return sessionToken; + } + + /** + * Amazon AWS Session Token used when the user needs to assume an IAM role + */ + public void setSessionToken(String sessionToken) { + this.sessionToken = sessionToken; + } + + public BedrockOperations getOperation() { + return operation; + } + + /** + * The operation to perform + */ + public void setOperation(BedrockOperations operation) { + this.operation = operation; + } + + public Protocol getProxyProtocol() { + return proxyProtocol; + } + + /** + * To define a proxy protocol when instantiating the Bedrock client + */ + public void setProxyProtocol(Protocol proxyProtocol) { + this.proxyProtocol = proxyProtocol; + } + + public String getProxyHost() { + return proxyHost; + } + + /** + * To define a proxy host when instantiating the Bedrock client + */ + public void setProxyHost(String proxyHost) { + this.proxyHost = proxyHost; + } + + public Integer getProxyPort() { + return proxyPort; + } + + /** + * To define a proxy port when instantiating the Bedrock client + */ + public void setProxyPort(Integer proxyPort) { + this.proxyPort = proxyPort; + } + + public String getRegion() { + return region; + } + + /** + * The region in which Bedrock client needs to work. When using this parameter, the configuration will expect the + * lowercase name of the region (for example, ap-east-1) You'll need to use the name Region.EU_WEST_1.id() + */ + public void setRegion(String region) { + this.region = region; + } + + public boolean isPojoRequest() { + return pojoRequest; + } + + /** + * If we want to use a POJO request as body or not + */ + public void setPojoRequest(boolean pojoRequest) { + this.pojoRequest = pojoRequest; + } + + public boolean isTrustAllCertificates() { + return trustAllCertificates; + } + + /** + * If we want to trust all certificates in case of overriding the endpoint + */ + public void setTrustAllCertificates(boolean trustAllCertificates) { + this.trustAllCertificates = trustAllCertificates; + } + + public boolean isOverrideEndpoint() { + return overrideEndpoint; + } + + /** + * Set the need for overriding the endpoint. This option needs to be used in combination with the + * uriEndpointOverride option + */ + public void setOverrideEndpoint(boolean overrideEndpoint) { + this.overrideEndpoint = overrideEndpoint; + } + + public String getUriEndpointOverride() { + return uriEndpointOverride; + } + + /** + * Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option + */ + public void setUriEndpointOverride(String uriEndpointOverride) { + this.uriEndpointOverride = uriEndpointOverride; + } + + /** + * Set whether the Bedrock client should expect to load credentials through a default credentials provider or to + * expect static credentials to be passed in. + */ + public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvider) { + this.useDefaultCredentialsProvider = useDefaultCredentialsProvider; + } + + public Boolean isUseDefaultCredentialsProvider() { + return useDefaultCredentialsProvider; + } + + public boolean isUseProfileCredentialsProvider() { + return useProfileCredentialsProvider; + } + + /** + * Set whether the Bedrock client should expect to load credentials through a profile credentials provider. + */ + public void setUseProfileCredentialsProvider(boolean useProfileCredentialsProvider) { + this.useProfileCredentialsProvider = useProfileCredentialsProvider; + } + + public boolean isUseSessionCredentials() { + return useSessionCredentials; + } + + /** + * Set whether the Bedrock client should expect to use Session Credentials. This is useful in a situation in which + * the user needs to assume an IAM role for doing operations in Bedrock. + */ + public void setUseSessionCredentials(boolean useSessionCredentials) { + this.useSessionCredentials = useSessionCredentials; + } + + public String getProfileCredentialsName() { + return profileCredentialsName; + } + + /** + * If using a profile credentials provider, this parameter will set the profile name + */ + public void setProfileCredentialsName(String profileCredentialsName) { + this.profileCredentialsName = profileCredentialsName; + } + + public String getModelId() { + return modelId; + } + + /** + * Define the model Id we are going to use + */ + public void setModelId(String modelId) { + this.modelId = modelId; + } + + // ************************************************* + // + // ************************************************* + + public BedrockConfiguration copy() { + try { + return (BedrockConfiguration) super.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeCamelException(e); + } + } +} diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockConstants.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockConstants.java new file mode 100644 index 00000000000..33951e902f2 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockConstants.java @@ -0,0 +1,31 @@ +/* + * 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.spi.Metadata; + +/** + * Constants used in Camel AWS Bedrock module SDK v2 + */ +public interface BedrockConstants { + @Metadata(description = "The operation we want to perform", javaType = "String") + String OPERATION = "CamelAwsBedrockOperation"; + @Metadata(description = "The model content type", javaType = "String") + String MODEL_CONTENT_TYPE = "CamelAwsBedrockContentType"; + @Metadata(description = "The model accept content type", javaType = "String") + String MODEL_ACCEPT_CONTENT_TYPE = "CamelAwsBedrockAcceptContentType"; +} 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 new file mode 100644 index 00000000000..0f54453e4c0 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockEndpoint.java @@ -0,0 +1,90 @@ +/* + * 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.Category; +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.component.aws2.bedrock.client.BedrockClientFactory; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.support.ScheduledPollEndpoint; +import org.apache.camel.util.ObjectHelper; +import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; + +/** + * Manage AWS EKS cluster instances. + */ +@UriEndpoint(firstVersion = "4.5.0", scheme = "aws-bedrock", title = "AWS Bedrock", + syntax = "aws-bedrock:label", producerOnly = true, category = { Category.CLOUD, Category.MANAGEMENT }, + headersClass = BedrockConstants.class) +public class BedrockEndpoint extends ScheduledPollEndpoint { + + private BedrockRuntimeClient bedrockRuntimeClient; + + @UriParam + private BedrockConfiguration configuration; + + public BedrockEndpoint(String uri, Component component, BedrockConfiguration configuration) { + super(uri, component); + this.configuration = configuration; + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + throw new UnsupportedOperationException("You cannot receive messages from this endpoint"); + } + + @Override + public Producer createProducer() throws Exception { + return new BedrockProducer(this); + } + + @Override + public BedrockComponent getComponent() { + return (BedrockComponent) super.getComponent(); + } + + @Override + public void doStart() throws Exception { + super.doStart(); + + bedrockRuntimeClient = configuration.getBedrockRuntimeClient() != null + ? configuration.getBedrockRuntimeClient() + : BedrockClientFactory.getEksClient(configuration).getBedrockRuntimeClient(); + } + + @Override + public void doStop() throws Exception { + if (ObjectHelper.isEmpty(configuration.getBedrockRuntimeClient())) { + if (bedrockRuntimeClient != null) { + bedrockRuntimeClient.close(); + } + } + super.doStop(); + } + + public BedrockConfiguration getConfiguration() { + return configuration; + } + + public BedrockRuntimeClient getBedrockRuntimeClient() { + return bedrockRuntimeClient; + } +} diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockModels.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockModels.java new file mode 100644 index 00000000000..246be29789c --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockModels.java @@ -0,0 +1,28 @@ +/* + * 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; + +public enum BedrockModels { + + TITAN_TEXT_EXPRESS_V1("amazon.titan-text-express-v1"); + + public final String model; + + private BedrockModels(String model) { + this.model = model; + } +} diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockOperations.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockOperations.java new file mode 100644 index 00000000000..957b31ff99e --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockOperations.java @@ -0,0 +1,22 @@ +/* + * 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; + +public enum BedrockOperations { + + invokeModel +} diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockProducer.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockProducer.java new file mode 100644 index 00000000000..d38aa64e4ff --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockProducer.java @@ -0,0 +1,131 @@ +/* + * 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.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.InvalidPayloadException; +import org.apache.camel.Message; +import org.apache.camel.support.DefaultProducer; +import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.URISupport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.awscore.exception.AwsServiceException; +import software.amazon.awssdk.core.SdkBytes; +import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; +import software.amazon.awssdk.services.bedrockruntime.model.InvokeModelRequest; +import software.amazon.awssdk.services.bedrockruntime.model.InvokeModelResponse; + +/** + * A Producer which sends messages to the Amazon Bedrock Service <a href="http://aws.amazon.com/bedrock/">AWS + * Bedrock</a> + */ +public class BedrockProducer extends DefaultProducer { + + private static final Logger LOG = LoggerFactory.getLogger(BedrockProducer.class); + private transient String bedrockProducerToString; + + public BedrockProducer(Endpoint endpoint) { + super(endpoint); + } + + @Override + public void process(Exchange exchange) throws Exception { + switch (determineOperation(exchange)) { + case invokeModel: + invokeModel(getEndpoint().getBedrockRuntimeClient(), exchange); + break; + default: + throw new IllegalArgumentException("Unsupported operation"); + } + } + + private BedrockOperations determineOperation(Exchange exchange) { + BedrockOperations operation = exchange.getIn().getHeader(BedrockConstants.OPERATION, BedrockOperations.class); + if (operation == null) { + operation = getConfiguration().getOperation(); + } + return operation; + } + + protected BedrockConfiguration getConfiguration() { + return getEndpoint().getConfiguration(); + } + + @Override + public String toString() { + if (bedrockProducerToString == null) { + bedrockProducerToString = "BedrockProducer[" + URISupport.sanitizeUri(getEndpoint().getEndpointUri()) + "]"; + } + return bedrockProducerToString; + } + + @Override + public BedrockEndpoint getEndpoint() { + return (BedrockEndpoint) super.getEndpoint(); + } + + private void invokeModel(BedrockRuntimeClient bedrockRuntimeClient, Exchange exchange) throws InvalidPayloadException { + if (getConfiguration().isPojoRequest()) { + Object payload = exchange.getMessage().getMandatoryBody(); + if (payload instanceof InvokeModelRequest) { + InvokeModelResponse result; + try { + result = bedrockRuntimeClient.invokeModel((InvokeModelRequest) payload); + } catch (AwsServiceException ase) { + LOG.trace("Invoke Model command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } else { + InvokeModelRequest.Builder builder = InvokeModelRequest.builder(); + if (ObjectHelper.isNotEmpty(exchange.getMessage().getHeader(BedrockConstants.MODEL_CONTENT_TYPE))) { + String contentType = exchange.getIn().getHeader(BedrockConstants.MODEL_CONTENT_TYPE, String.class); + builder.contentType(contentType); + } else { + throw new IllegalArgumentException("Model Content Type must be specified"); + } + if (ObjectHelper.isNotEmpty(exchange.getMessage().getHeader(BedrockConstants.MODEL_ACCEPT_CONTENT_TYPE))) { + String acceptContentType = exchange.getIn().getHeader(BedrockConstants.MODEL_ACCEPT_CONTENT_TYPE, String.class); + builder.accept(acceptContentType); + } else { + throw new IllegalArgumentException("Model Accept Content Type must be specified"); + } + InvokeModelRequest request = builder + .body(SdkBytes.fromUtf8String(String.valueOf(exchange.getMessage().getBody()))) + .modelId(getConfiguration().getModelId()) + .build(); + InvokeModelResponse result; + try { + result = bedrockRuntimeClient.invokeModel(request); + } catch (AwsServiceException ase) { + LOG.trace("Invoke Model command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } + + public static Message getMessageForResponse(final Exchange exchange) { + return exchange.getMessage(); + } + +} 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 new file mode 100644 index 00000000000..3c23316507a --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/BedrockClientFactory.java @@ -0,0 +1,50 @@ +/* + * 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.client; + +import org.apache.camel.component.aws2.bedrock.BedrockConfiguration; +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; + +/** + * Factory class to return the correct type of AWS Bedrock client. + */ +public final class BedrockClientFactory { + + private BedrockClientFactory() { + } + + /** + * Return the correct AWS Bedrock client (based on remote vs local). + * + * @param configuration configuration + * @return EKSClient + */ + public static BedrockRuntimeInternalClient getEksClient(BedrockConfiguration configuration) { + if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) { + return new BedrockRuntimeClientIAMOptimizedImpl(configuration); + } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) { + return new BedrockRuntimeClientIAMProfileOptimizedImpl(configuration); + } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) { + return new BedrockRuntimeClientSessionTokenImpl(configuration); + } else { + return new BedrockRuntimeClientStandardImpl(configuration); + } + } +} diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/BedrockRuntimeInternalClient.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/BedrockRuntimeInternalClient.java new file mode 100644 index 00000000000..01b50a05919 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/BedrockRuntimeInternalClient.java @@ -0,0 +1,32 @@ +/* + * 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.client; + +import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; + +/** + * Manage the required actions of an Bedrock Runtime client for either local or remote. + */ +public interface BedrockRuntimeInternalClient { + + /** + * Returns an Bedrock Runtime client after a factory method determines which one to return. + * + * @return BedrockRuntimeClient BedrockRuntimeClient + */ + BedrockRuntimeClient getBedrockRuntimeClient(); +} diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/impl/BedrockRuntimeClientIAMOptimizedImpl.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/impl/BedrockRuntimeClientIAMOptimizedImpl.java new file mode 100644 index 00000000000..425925526f1 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/impl/BedrockRuntimeClientIAMOptimizedImpl.java @@ -0,0 +1,94 @@ +/* + * 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.client.impl; + +import java.net.URI; + +import org.apache.camel.component.aws2.bedrock.BedrockConfiguration; +import org.apache.camel.component.aws2.bedrock.client.BedrockRuntimeInternalClient; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.http.SdkHttpConfigurationOption; +import software.amazon.awssdk.http.apache.ApacheHttpClient; +import software.amazon.awssdk.http.apache.ProxyConfiguration; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; +import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClientBuilder; +import software.amazon.awssdk.utils.AttributeMap; + +/** + * Manage an AWS Bedrock Runtime client for all users to use (enabling temporary creds). This implementation is for + * remote instances to manage the credentials on their own (eliminating credential rotations) + */ +public class BedrockRuntimeClientIAMOptimizedImpl implements BedrockRuntimeInternalClient { + private static final Logger LOG = LoggerFactory.getLogger(BedrockRuntimeClientIAMOptimizedImpl.class); + private BedrockConfiguration configuration; + + /** + * Constructor that uses the config file. + */ + public BedrockRuntimeClientIAMOptimizedImpl(BedrockConfiguration configuration) { + LOG.trace( + "Creating an AWS Bedrock Runtime client for an ec2 instance with IAM temporary credentials (normal for ec2s)."); + this.configuration = configuration; + } + + /** + * Getting the Bedrock aws client that is used. + * + * @return BedrockRuntimeClient Client. + */ + @Override + public BedrockRuntimeClient getBedrockRuntimeClient() { + BedrockRuntimeClient client = null; + BedrockRuntimeClientBuilder clientBuilder = BedrockRuntimeClient.builder(); + ProxyConfiguration.Builder proxyConfig = null; + ApacheHttpClient.Builder httpClientBuilder = null; + if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { + proxyConfig = ProxyConfiguration.builder(); + URI proxyEndpoint = URI.create(configuration.getProxyProtocol() + "://" + configuration.getProxyHost() + ":" + + configuration.getProxyPort()); + proxyConfig.endpoint(proxyEndpoint); + httpClientBuilder = ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build()); + clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder); + } + if (ObjectHelper.isNotEmpty(configuration.getRegion())) { + clientBuilder = clientBuilder.region(Region.of(configuration.getRegion())); + } + if (configuration.isOverrideEndpoint()) { + clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride())); + } + if (configuration.isTrustAllCertificates()) { + if (httpClientBuilder == null) { + httpClientBuilder = ApacheHttpClient.builder(); + } + SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap + .builder() + .put( + SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, + Boolean.TRUE) + .build()); + // set created http client to use instead of builder + clientBuilder.httpClient(ahc); + clientBuilder.httpClientBuilder(null); + } + client = clientBuilder.build(); + return client; + } +} diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/impl/BedrockRuntimeClientIAMProfileOptimizedImpl.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/impl/BedrockRuntimeClientIAMProfileOptimizedImpl.java new file mode 100644 index 00000000000..39d4f457f83 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/impl/BedrockRuntimeClientIAMProfileOptimizedImpl.java @@ -0,0 +1,99 @@ +/* + * 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.client.impl; + +import java.net.URI; + +import org.apache.camel.component.aws2.bedrock.BedrockConfiguration; +import org.apache.camel.component.aws2.bedrock.client.BedrockRuntimeInternalClient; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.http.SdkHttpConfigurationOption; +import software.amazon.awssdk.http.apache.ApacheHttpClient; +import software.amazon.awssdk.http.apache.ProxyConfiguration; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; +import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClientBuilder; +import software.amazon.awssdk.utils.AttributeMap; + +/** + * Manage an AWS Bedrock Runtime client for all users to use (enabling temporary creds). This implementation is for + * remote instances to manage the credentials on their own (eliminating credential rotations) + */ +public class BedrockRuntimeClientIAMProfileOptimizedImpl implements BedrockRuntimeInternalClient { + private static final Logger LOG = LoggerFactory.getLogger(BedrockRuntimeClientIAMProfileOptimizedImpl.class); + private BedrockConfiguration configuration; + + /** + * Constructor that uses the config file. + */ + public BedrockRuntimeClientIAMProfileOptimizedImpl(BedrockConfiguration configuration) { + LOG.trace( + "Creating an AWS Bedrock Runtime client for an ec2 instance with IAM temporary credentials (normal for ec2s)."); + this.configuration = configuration; + } + + /** + * Getting the Bedrock Runtime aws client that is used. + * + * @return Bedrock Runtime Client. + */ + @Override + public BedrockRuntimeClient getBedrockRuntimeClient() { + BedrockRuntimeClient client = null; + BedrockRuntimeClientBuilder clientBuilder = BedrockRuntimeClient.builder(); + ProxyConfiguration.Builder proxyConfig = null; + ApacheHttpClient.Builder httpClientBuilder = null; + if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { + proxyConfig = ProxyConfiguration.builder(); + URI proxyEndpoint = URI.create(configuration.getProxyProtocol() + "://" + configuration.getProxyHost() + ":" + + configuration.getProxyPort()); + proxyConfig.endpoint(proxyEndpoint); + httpClientBuilder = ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build()); + clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder); + } + if (configuration.getProfileCredentialsName() != null) { + clientBuilder = clientBuilder + .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName())); + } + if (ObjectHelper.isNotEmpty(configuration.getRegion())) { + clientBuilder = clientBuilder.region(Region.of(configuration.getRegion())); + } + if (configuration.isOverrideEndpoint()) { + clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride())); + } + if (configuration.isTrustAllCertificates()) { + if (httpClientBuilder == null) { + httpClientBuilder = ApacheHttpClient.builder(); + } + SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap + .builder() + .put( + SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, + Boolean.TRUE) + .build()); + // set created http client to use instead of builder + clientBuilder.httpClient(ahc); + clientBuilder.httpClientBuilder(null); + } + client = clientBuilder.build(); + return client; + } +} diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/impl/BedrockRuntimeClientSessionTokenImpl.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/impl/BedrockRuntimeClientSessionTokenImpl.java new file mode 100644 index 00000000000..9056bbf26bd --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/impl/BedrockRuntimeClientSessionTokenImpl.java @@ -0,0 +1,111 @@ +/* + * 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.client.impl; + +import java.net.URI; + +import org.apache.camel.component.aws2.bedrock.BedrockConfiguration; +import org.apache.camel.component.aws2.bedrock.client.BedrockRuntimeInternalClient; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.auth.credentials.AwsSessionCredentials; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.http.SdkHttpConfigurationOption; +import software.amazon.awssdk.http.apache.ApacheHttpClient; +import software.amazon.awssdk.http.apache.ProxyConfiguration; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; +import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClientBuilder; +import software.amazon.awssdk.utils.AttributeMap; + +/** + * Manage an AWS Bedrock Runtime client for all users to use. This implementation is for local instances to use a static + * and solid credential set. + */ +public class BedrockRuntimeClientSessionTokenImpl implements BedrockRuntimeInternalClient { + private static final Logger LOG = LoggerFactory.getLogger(BedrockRuntimeClientSessionTokenImpl.class); + private BedrockConfiguration configuration; + + /** + * Constructor that uses the config file. + */ + public BedrockRuntimeClientSessionTokenImpl(BedrockConfiguration configuration) { + LOG.trace("Creating an AWS Bedrock Runtime manager using static credentials."); + this.configuration = configuration; + } + + /** + * Getting the Bedrock Runtime AWS client that is used. + * + * @return BedrockRuntimeClient Client. + */ + @Override + public BedrockRuntimeClient getBedrockRuntimeClient() { + BedrockRuntimeClient client = null; + BedrockRuntimeClientBuilder clientBuilder = BedrockRuntimeClient.builder(); + ProxyConfiguration.Builder proxyConfig = null; + ApacheHttpClient.Builder httpClientBuilder = null; + boolean isClientConfigFound = false; + if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { + proxyConfig = ProxyConfiguration.builder(); + URI proxyEndpoint = URI.create(configuration.getProxyProtocol() + "://" + configuration.getProxyHost() + ":" + + configuration.getProxyPort()); + proxyConfig.endpoint(proxyEndpoint); + httpClientBuilder = ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build()); + isClientConfigFound = true; + } + if (configuration.getAccessKey() != null && configuration.getSecretKey() != null + && configuration.getSessionToken() != null) { + AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(), + configuration.getSecretKey(), configuration.getSessionToken()); + if (isClientConfigFound) { + clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder) + .credentialsProvider(StaticCredentialsProvider.create(cred)); + } else { + clientBuilder = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred)); + } + } else { + if (!isClientConfigFound) { + clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder); + } + } + if (ObjectHelper.isNotEmpty(configuration.getRegion())) { + clientBuilder = clientBuilder.region(Region.of(configuration.getRegion())); + } + if (configuration.isOverrideEndpoint()) { + clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride())); + } + if (configuration.isTrustAllCertificates()) { + if (httpClientBuilder == null) { + httpClientBuilder = ApacheHttpClient.builder(); + } + SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap + .builder() + .put( + SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, + Boolean.TRUE) + .build()); + // set created http client to use instead of builder + clientBuilder.httpClient(ahc); + clientBuilder.httpClientBuilder(null); + } + client = clientBuilder.build(); + return client; + } +} diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/impl/BedrockRuntimeClientStandardImpl.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/impl/BedrockRuntimeClientStandardImpl.java new file mode 100644 index 00000000000..0ad58c27805 --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/client/impl/BedrockRuntimeClientStandardImpl.java @@ -0,0 +1,109 @@ +/* + * 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.client.impl; + +import java.net.URI; + +import org.apache.camel.component.aws2.bedrock.BedrockConfiguration; +import org.apache.camel.component.aws2.bedrock.client.BedrockRuntimeInternalClient; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.http.SdkHttpConfigurationOption; +import software.amazon.awssdk.http.apache.ApacheHttpClient; +import software.amazon.awssdk.http.apache.ProxyConfiguration; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; +import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClientBuilder; +import software.amazon.awssdk.utils.AttributeMap; + +/** + * Manage an AWS Bedrock Runtime client for all users to use. This implementation is for local instances to use a static + * and solid credential set. + */ +public class BedrockRuntimeClientStandardImpl implements BedrockRuntimeInternalClient { + private static final Logger LOG = LoggerFactory.getLogger(BedrockRuntimeClientStandardImpl.class); + private BedrockConfiguration configuration; + + /** + * Constructor that uses the config file. + */ + public BedrockRuntimeClientStandardImpl(BedrockConfiguration configuration) { + LOG.trace("Creating an AWS Bedrock Runtime manager using static credentials."); + this.configuration = configuration; + } + + /** + * Getting the Bedrock Runtime AWS client that is used. + * + * @return BedrockRuntime Client. + */ + @Override + public BedrockRuntimeClient getBedrockRuntimeClient() { + BedrockRuntimeClient client = null; + BedrockRuntimeClientBuilder clientBuilder = BedrockRuntimeClient.builder(); + ProxyConfiguration.Builder proxyConfig = null; + ApacheHttpClient.Builder httpClientBuilder = null; + boolean isClientConfigFound = false; + if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { + proxyConfig = ProxyConfiguration.builder(); + URI proxyEndpoint = URI.create(configuration.getProxyProtocol() + "://" + configuration.getProxyHost() + ":" + + configuration.getProxyPort()); + proxyConfig.endpoint(proxyEndpoint); + httpClientBuilder = ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build()); + isClientConfigFound = true; + } + if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) { + AwsBasicCredentials cred = AwsBasicCredentials.create(configuration.getAccessKey(), configuration.getSecretKey()); + if (isClientConfigFound) { + clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder) + .credentialsProvider(StaticCredentialsProvider.create(cred)); + } else { + clientBuilder = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred)); + } + } else { + if (!isClientConfigFound) { + clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder); + } + } + if (ObjectHelper.isNotEmpty(configuration.getRegion())) { + clientBuilder = clientBuilder.region(Region.of(configuration.getRegion())); + } + if (configuration.isOverrideEndpoint()) { + clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride())); + } + if (configuration.isTrustAllCertificates()) { + if (httpClientBuilder == null) { + httpClientBuilder = ApacheHttpClient.builder(); + } + SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap + .builder() + .put( + SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, + Boolean.TRUE) + .build()); + // set created http client to use instead of builder + clientBuilder.httpClient(ahc); + clientBuilder.httpClientBuilder(null); + } + client = clientBuilder.build(); + return client; + } +} 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/BedrockProducerIT.java new file mode 100644 index 00000000000..ba0796343aa --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/BedrockProducerIT.java @@ -0,0 +1,85 @@ +/* + * 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 com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +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.mock.MockEndpoint; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.condition.EnabledIfSystemProperties; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; + +// Must be manually tested. Provide your own accessKey and secretKey using -Daws.manual.access.key and -Daws.manual.secret.key +@EnabledIfSystemProperties({ + @EnabledIfSystemProperty(named = "aws.manual.access.key", matches = ".*", disabledReason = "Access key not provided"), + @EnabledIfSystemProperty(named = "aws.manual.secret.key", matches = ".*", disabledReason = "Secret key not provided") +}) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class BedrockProducerIT extends CamelTestSupport { + + @EndpointInject + private ProducerTemplate template; + + @EndpointInject("mock:result") + private MockEndpoint result; + + @Test + public void testInvokeModel() throws InterruptedException { + + result.expectedMessageCount(1); + final Exchange result = template.send("direct:send", exchange -> { + ObjectMapper mapper = new ObjectMapper(); + ObjectNode rootNode = mapper.createObjectNode(); + rootNode.put("inputText", + "User: Generate synthetic data for daily product sales in various categories - include row number, product name, category, date of sale and price. Produce output in JSON format. Count records and ensure there are no more than 5."); + + ArrayNode stopSequences = mapper.createArrayNode(); + stopSequences.add("User:"); + ObjectNode childNode = mapper.createObjectNode(); + childNode.put("maxTokenCount", 1024); + childNode.put("stopSequences", stopSequences); + childNode.put("temperature", 0).put("topP", 1); + + rootNode.put("textGenerationConfig", childNode); + exchange.getMessage().setBody(mapper.writer().writeValueAsString(rootNode)); + exchange.getMessage().setHeader(BedrockConstants.MODEL_CONTENT_TYPE, "application/json"); + exchange.getMessage().setHeader(BedrockConstants.MODEL_ACCEPT_CONTENT_TYPE, "application/json"); + }); + + MockEndpoint.assertIsSatisfied(context); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:send") + .to("aws-bedrock:label?accessKey=RAW({{aws.manual.access.key}})&secretKey=RAW({{aws.manual.secret.key}}®ion=eu-central-1&operation=invokeModel&modelId=" + + BedrockModels.TITAN_TEXT_EXPRESS_V1.model) + .to(result); + } + }; + } +} diff --git a/components/camel-aws/camel-aws-bedrock/src/test/resources/log4j2.properties b/components/camel-aws/camel-aws-bedrock/src/test/resources/log4j2.properties new file mode 100644 index 00000000000..09b374f3f9e --- /dev/null +++ b/components/camel-aws/camel-aws-bedrock/src/test/resources/log4j2.properties @@ -0,0 +1,28 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +appender.file.type = File +appender.file.name = file +appender.file.fileName = target/camel-aws2-eks-test.log +appender.file.layout.type = PatternLayout +appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +appender.out.type = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +rootLogger.level = INFO +rootLogger.appenderRef.file.ref = file diff --git a/components/camel-aws/pom.xml b/components/camel-aws/pom.xml index ab5d6b88e95..633b24a90e7 100644 --- a/components/camel-aws/pom.xml +++ b/components/camel-aws/pom.xml @@ -40,6 +40,7 @@ <modules> <module>camel-aws2-athena</module> + <module>camel-aws-bedrock</module> <module>camel-aws-cloudtrail</module> <module>camel-aws-config</module> <module>camel-aws2-cw</module> diff --git a/docs/components/modules/ROOT/examples/json/aws-bedrock.json b/docs/components/modules/ROOT/examples/json/aws-bedrock.json new file mode 120000 index 00000000000..073b35b8fdc --- /dev/null +++ b/docs/components/modules/ROOT/examples/json/aws-bedrock.json @@ -0,0 +1 @@ +../../../../../../components/camel-aws/camel-aws-bedrock/src/generated/resources/META-INF/org/apache/camel/component/aws2/bedrock/aws-bedrock.json \ No newline at end of file diff --git a/parent/pom.xml b/parent/pom.xml index 8a51beda0bc..16651ae67af 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -720,6 +720,11 @@ <artifactId>camel-avro-rpc-spi</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-aws-bedrock</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws-cloudtrail</artifactId> @@ -745,6 +750,11 @@ <artifactId>camel-aws2-athena</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-aws2-bedrock</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws2-cw</artifactId>
