saravanakumar1987 opened a new pull request, #30290:
URL: https://github.com/apache/camel/pull/30290

   # Description
   
   Fixes [CAMEL-27102](https://issues.apache.org/jira/browse/CAMEL-27102), the 
follow-up of the review of apache/camel#30260. It answers the question of that 
review whether `endpoint` should be the required option. The fix follows 
CAMEL-27046 for camel-alibaba-eventbridge (apache/camel#30254).
   
   ## What was wrong
   
   - With `region` and without `endpoint`, the client of 
`com.aliyun:fc_open20210406` 2.1.0 takes its endpoint from its own map of 21 
regions when the region is in this map. Each value has the form 
`account-id.<region>.fc.aliyuncs.com`, with the text `account-id` in it, and 
`com.aliyun:tea-openapi` 0.3.20 does not replace this text. For a region 
outside the map, `com.aliyun:endpoint-util` 0.0.7 gives 
`fc-open.<region>.aliyuncs.com`.
   - Alibaba documents the public endpoint of Function Compute in the form 
`<account-ID>.<region-ID>.fc.aliyuncs.com`, and the internal endpoint in the 
form `<account-ID>.<region-ID>-internal.fc.aliyuncs.com`: 
https://help.aliyun.com/en/functioncompute/fc-endpoints. So a region alone 
cannot reach a function of the caller's account. When the endpoint is set, the 
constructor of the client keeps it as it is.
   - A test with live credentials, without this change, created two clients 
with `FCUtils.createClient` and called `getFunction` with each. With 
`region=cn-hangzhou` and without `endpoint`, the answer named the resource 
`acs:fc:cn-hangzhou:account-id:services/...`, so Function Compute took the text 
`account-id` as the account ID. With the endpoint of the account and without a 
region, the answer named the resource of the account.
   - `FCUtils.createClient` threw `Region or endpoint is required` only when 
both were empty, so it accepted a region without an endpoint. The description 
of `endpoint` said: "If not set, the region option determines the endpoint, and 
one of the two is required." Both examples of the doc page set `region` and no 
`endpoint`.
   - `endpoint` was not marked as required, so the endpoint validation of the 
catalog accepted a URI with a region and without an endpoint. Since 
apache/camel#30260, neither option was marked as required.
   
   ## The change
   
   - `endpoint` has `@Metadata(required = true)`, as the endpoint of 
`AlibabaEventBridgeEndpoint` has. Its description now says that it contains the 
ID of the Alibaba Cloud account, as in `12345.cn-hangzhou.fc.aliyuncs.com`, and 
that the region option does not determine it, so this option is required.
   - `region` is deprecated in the way `retentionPolicy` of camel-influxdb2 is 
(apache/camel#29709): the field has `@Deprecated` and 
`@Metadata(deprecationNote = "Use the endpoint option, which contains the 
region.")`, and its getter and setter have `@Deprecated`, with this note as 
their `@deprecated` Javadoc. Its description is now "The region ID of Function 
Compute, for example cn-hangzhou. The producer does not use it."
   - The description of `fcClient` no longer lists `region` among the options 
that are not used when a client is set. The rest of it does not change.
   - `FCUtils.createClient` checks the endpoint alone, as 
`AlibabaEventBridgeUtils.createClient` does, and throws an 
`IllegalArgumentException` with "Endpoint is required" when it is empty. It 
always sets the endpoint on the config of the SDK, and no longer sets the 
region.
   - The component JSON and its catalog copy have `endpoint` as required, and 
`region` as deprecated, with the note, which the generator also appends to the 
description of `region`. In the Endpoint DSL, the Javadoc of `endpoint(String)` 
says "Required: true", and `region(String)` has `@Deprecated` and the note in 
its Javadoc.
   - In the doc page, both examples set `endpoint` to 
`12345.cn-hangzhou.fc.aliyuncs.com` instead of `region`, and the new section 
"Endpoint of Function Compute", directly before "Producer example", gives the 
forms of the public and of the internal endpoint: `<account ID>.<region 
ID>.fc.aliyuncs.com` and `<account ID>.<region ID>-internal.fc.aliyuncs.com`. 
The catalog copy of the page is regenerated.
   
   The section "camel-alibaba-fc - endpoint is marked as required instead of 
region" of the 4.24 upgrade guide replaces the section "camel-alibaba-fc - 
region is no longer marked as required" that apache/camel#30260 added, in the 
same place, because both changes are in 4.24. It says that the `endpoint` 
option is now marked as required and the `region` option no longer is, because 
the endpoint contains the ID of the Alibaba Cloud account, so the region does 
not determine it. It says that a URI with `region` and without `endpoint` now 
fails at the first message with `Endpoint is required`, unless the `fcClient` 
option is set or autowired, and what the client of the SDK and Function Compute 
did with such a URI before, when the region was in the map of the SDK. It says 
that the endpoint validation of the catalog now reports a URI without 
`endpoint` as missing a required option, where it reported a URI without 
`region` before, that it also reports such a URI when the `fcClient` option is 
 set or autowired, and that such a route still runs. It also says that the 
`region` option is deprecated, because the producer no longer uses it. No 
option, header name or Java API is removed or renamed: `region`, its getter and 
setter, and `region(String)` of the Endpoint DSL stay, deprecated.
   
   ## Tests
   
   - `CamelCatalogTest#testValidateEndpointAlibabaFc` has the case that 
`testValidateEndpointAlibabaEventBridge` has: the URI 
`alibaba-fc:invokeFunction?region=cn-hangzhou` is not valid, and `endpoint` is 
its missing required option.
   - The new `CreateClientTest` of the module has the two tests of the 
`CreateClientTest` of camel-alibaba-eventbridge. For an `FCEndpoint` with a 
region and access keys, but without the endpoint option, `createClient` throws 
an `IllegalArgumentException` with "Endpoint is required". With the endpoint 
option and without a region, `createClient` returns a client whose endpoint is 
the option and whose region is not set. The first test has 
`@SuppressWarnings("deprecation")`, because it sets the deprecated `region`.
   
   ## How it was verified
   
   - With the new tests and without the change, `testValidateEndpointAlibabaFc` 
failed at its new `assertFalse`: the catalog accepted the URI with a region and 
without an endpoint.
   - With the new tests and without the change, 
`aRegionWithoutAnEndpointIsRejected` failed, because `createClient` returned a 
client instead of throwing an exception. 
`anEndpointWithoutARegionCreatesAClient` passed.
   - With the change, `mvn install -nsu` in the module ran its 12 tests, the 2 
new ones and the 10 others, with no failure, error or rerun, and changed only 
the component JSON among the generated files.
   - With the change, `mvn install -DskipTests -nsu` in `catalog/camel-catalog` 
regenerated the catalog copies of the component JSON and of the doc page, and 
in `dsl/camel-endpointdsl` it regenerated `FCEndpointBuilderFactory`.
   - With the change and the regenerated files, both new tests pass.
   
   ## Not changed
   
   - The other tests of the module keep `region` in their URIs, together with a 
client in the `fcClient` option: a mock in `InvokeFunctionTest` and 
`InvokeFunctionPayloadTest`, and a client of the SDK for a local HTTP server in 
`InvokeFunctionRealClientTest`. So `createClient` does not run in them, and 
they pass without a change.
   - A URI with both `region` and `endpoint` sends the same requests as before, 
although `createClient` no longer sets the region. The constructor of the 
client of the SDK uses the region only to choose an endpoint when none is set. 
Each request goes through `callApi` of `com.aliyun:tea-openapi` 0.3.20, which 
calls `doRequest` unless the config sets the signature version v4 or the 
signature algorithm v2, and the config of `createClient` sets neither. 
`doRequest` does not read the region.
   - `FCProducer`, the headers and the options other than `endpoint`, `region` 
and `fcClient` do not change. The producer still creates the client when it 
processes its first message.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [x] I have run `mvn clean install -Dquickly -DskipTests` from the root 
folder on upstream `main` (ed8ad1eb6ac5, the parent of the commit), and then, 
with the change, `mvn install -nsu` in 
`components/camel-alibaba/camel-alibaba-fc`, which also runs its code 
generators, the formatter and the import sorter, and `mvn install -DskipTests 
-nsu` in `catalog/camel-catalog` and in `dsl/camel-endpointdsl`. I have 
committed all auto-generated changes: the component JSON, its catalog copy, the 
catalog copy of the doc page and `FCEndpointBuilderFactory`.
   
   The commands that were run:
   
   ```
   # without the change, with the new tests, in catalog/camel-catalog
   mvn -o -B test -Dtest=CamelCatalogTest#testValidateEndpointAlibabaFc 
-Dsurefire.failIfNoSpecifiedTests=false -Dsurefire.rerunFailingTestsCount=0
   # and in components/camel-alibaba/camel-alibaba-fc
   mvn -o -B test -Dtest=CreateClientTest 
-Dsurefire.failIfNoSpecifiedTests=false -Dsurefire.rerunFailingTestsCount=0
   # with the change, in components/camel-alibaba/camel-alibaba-fc
   mvn install -nsu
   # then in catalog/camel-catalog and in dsl/camel-endpointdsl
   mvn install -DskipTests -nsu
   # then the two test commands again, each in its folder
   ```
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   The change, the tests and this text were drafted with Claude Code 
(Anthropic), from the ticket, the code of camel-alibaba-fc, 
camel-alibaba-eventbridge, camel-influxdb2, camel-catalog and the Endpoint DSL, 
the bytecode of `com.aliyun:fc_open20210406` 2.1.0 and 
`com.aliyun:endpoint-util` 0.0.7, and the sources of `com.aliyun:tea-openapi` 
0.3.20. The tests were run as described above. The test with live credentials 
ran without this change, and is not part of this pull request. The change and 
the claims of this text were checked by an independent AI review.
   
   _Claude Code on behalf of saravanakumar1987_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to