-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Create class based on bound out BDD endpoint engine in crt #3870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sbiscigl
wants to merge
1
commit into
main
Choose a base branch
from
bdd-bind
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/aws-cpp-sdk-core/include/aws/core/endpoint/BDDEndpointProvider.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
|
|
||
| #pragma once | ||
|
|
||
| #include <aws/core/endpoint/internal/CrtEndpointProvider.h> | ||
|
|
||
| #include <aws/crt/endpoints/BddEngine.h> | ||
|
|
||
| namespace Aws | ||
| { | ||
| namespace Endpoint | ||
| { | ||
| /** | ||
| * Resolves an endpoint using the compiled-bytecode CRT BDD engine. | ||
| */ | ||
| AWS_CORE_API ResolveEndpointOutcome | ||
| ResolveEndpointBddImpl(const Aws::Crt::Endpoints::BddEngine& bddEngine, | ||
| const EndpointParameters& builtInParameters, | ||
| const EndpointParameters& clientContextParameters, | ||
| const EndpointParameters& endpointParameters); | ||
|
|
||
| /** | ||
| * Resolves endpoints from compiled BDD bytecode via the CRT BddEngine. Drop-in | ||
| * replacement for DefaultEndpointProvider. | ||
| * | ||
| * WARNING: non-owning. The engine points directly into the bytecode blob passed to | ||
| * the constructor; the caller is responsible for keeping it alive for the lifetime of | ||
| * this provider. Generated clients pass GetRulesBlob() (static storage), which satisfies this. | ||
| */ | ||
| template<typename ClientConfigurationT = Aws::Client::GenericClientConfiguration, | ||
| typename BuiltInParametersT = Aws::Endpoint::BuiltInParameters, | ||
| typename ClientContextParametersT = Aws::Endpoint::ClientContextParameters> | ||
| class AWS_CORE_API BDDEndpointProvider : public CrtEndpointProvider<Aws::Crt::Endpoints::BddEngine, | ||
| ResolveEndpointBddImpl, ClientConfigurationT, BuiltInParametersT, ClientContextParametersT> | ||
| { | ||
| public: | ||
| using CrtEndpointProvider<Aws::Crt::Endpoints::BddEngine, ResolveEndpointBddImpl, | ||
| ClientConfigurationT, BuiltInParametersT, ClientContextParametersT>::CrtEndpointProvider; | ||
|
|
||
| virtual ~BDDEndpointProvider() = default; | ||
| }; | ||
|
|
||
| /** | ||
| * Export endpoint provider symbols for Windows DLL, otherwise declare as extern | ||
| */ | ||
| AWS_CORE_EXTERN template class AWS_CORE_API BDDEndpointProvider<Aws::Client::GenericClientConfiguration, | ||
| Aws::Endpoint::BuiltInParameters, | ||
| Aws::Endpoint::ClientContextParameters>; | ||
| } // namespace Endpoint | ||
| } // namespace Aws |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/aws-cpp-sdk-core/include/aws/core/endpoint/internal/CrtEndpointProvider.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
|
|
||
| #pragma once | ||
|
|
||
| #include <aws/core/endpoint/AWSPartitions.h> | ||
| #include <aws/core/endpoint/EndpointProviderBase.h> | ||
| #include <aws/core/endpoint/EndpointParameter.h> | ||
| #include <aws/core/endpoint/ClientContextParameters.h> | ||
| #include <aws/core/endpoint/BuiltInParameters.h> | ||
|
|
||
| #include <aws/crt/Types.h> | ||
|
|
||
| #include <aws/core/utils/Outcome.h> | ||
| #include <aws/core/client/AWSError.h> | ||
| #include <aws/core/utils/logging/LogMacros.h> | ||
|
|
||
| namespace Aws { | ||
| namespace Endpoint { | ||
| /** | ||
| * Endpoint provider backed by a CRT endpoint engine. The two things that differ between | ||
| * the JSON-ruleset and BDD-bytecode providers are captured as template parameters: | ||
| * - RulesEngineT: the CRT engine type (Aws::Crt::Endpoints::RuleEngine or BddEngine), | ||
| * both constructed from a ruleset blob plus the partitions blob. | ||
| * - ResolveFn: the resolution entry point for that engine. It is an out-of-line exported | ||
| * symbol (ResolveEndpointDefaultImpl / ResolveEndpointBddImpl) so the resolution body | ||
| * lives once in aws-cpp-sdk-core rather than inlined into every service binary. | ||
| * Everything else (parameter storage, init, override, accessors) is shared here. | ||
| */ | ||
| template<typename RulesEngineT, | ||
| ResolveEndpointOutcome(*ResolveFn)(const RulesEngineT &, | ||
| const EndpointParameters &, | ||
| const EndpointParameters &, | ||
| const EndpointParameters &), | ||
| typename ClientConfigurationT = Aws::Client::GenericClientConfiguration, | ||
| typename BuiltInParametersT = Aws::Endpoint::BuiltInParameters, | ||
| typename ClientContextParametersT = Aws::Endpoint::ClientContextParameters> | ||
| class CrtEndpointProvider : public EndpointProviderBase<ClientConfigurationT, BuiltInParametersT, | ||
| ClientContextParametersT> { | ||
| public: | ||
| CrtEndpointProvider(const char *endpointRulesBlob, const size_t endpointRulesBlobSz) | ||
| : m_crtEngine(Aws::Crt::ByteCursorFromArray((const uint8_t *) endpointRulesBlob, endpointRulesBlobSz), | ||
| Aws::Crt::ByteCursorFromArray((const uint8_t *) AWSPartitions::GetPartitionsBlob(), | ||
| AWSPartitions::PartitionsBlobSize)) { | ||
| if (!m_crtEngine) { | ||
| AWS_LOGSTREAM_FATAL("CrtEndpointProvider", "Invalid CRT endpoint engine state"); | ||
| } | ||
| } | ||
|
|
||
| virtual ~CrtEndpointProvider() = default; | ||
|
|
||
| void InitBuiltInParameters(const ClientConfigurationT &config) override { | ||
| m_builtInParameters.SetFromClientConfiguration(config); | ||
| } | ||
|
|
||
| void InitBuiltInParameters(const ClientConfigurationT &config, const Aws::String &serviceName) override { | ||
| m_builtInParameters.SetFromClientConfiguration(config, serviceName); | ||
| } | ||
|
|
||
| ResolveEndpointOutcome ResolveEndpoint(const EndpointParameters &endpointParameters) const override { | ||
| return ResolveFn(m_crtEngine, m_builtInParameters.GetAllParameters(), | ||
| m_clientContextParameters.GetAllParameters(), endpointParameters); | ||
| }; | ||
|
|
||
| const ClientContextParametersT &GetClientContextParameters() const override { | ||
| return m_clientContextParameters; | ||
| } | ||
|
|
||
| ClientContextParametersT &AccessClientContextParameters() override { | ||
| return m_clientContextParameters; | ||
| } | ||
|
|
||
| const BuiltInParametersT &GetBuiltInParameters() const { | ||
| return m_builtInParameters; | ||
| } | ||
|
|
||
| BuiltInParametersT &AccessBuiltInParameters() { | ||
| return m_builtInParameters; | ||
| } | ||
|
|
||
| void OverrideEndpoint(const Aws::String &endpoint) override { | ||
| m_builtInParameters.OverrideEndpoint(endpoint); | ||
| } | ||
|
|
||
| protected: | ||
| /* Crt endpoint engine (RuleEngine or BddEngine) built from the service's ruleset blob */ | ||
| RulesEngineT m_crtEngine; | ||
|
|
||
| /* Also known as a configurable parameters defined by the AWS Service in their c2j/smithy model definition */ | ||
| ClientContextParametersT m_clientContextParameters; | ||
|
|
||
| /* Also known as parameters on the ClientConfiguration in this SDK */ | ||
| BuiltInParametersT m_builtInParameters; | ||
| }; | ||
| } // namespace Endpoint | ||
| } // namespace Aws | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing i wanna point out here since we are wrapping the raw pointer
endpointRulesBlobin aByteCursor(non-owning). The two engines slightly differ in construction:aws_endpoints_ruleset_new_from_stringwhich parses the JSON into it's internal DOM (copy)aws_endpoints_bdd_engine_new_from_bytecodeon the partitions blob (copy), but explicitly states that the caller is responsible for keeping the bytecode buffer aliveFor the BDD path, should we ensure the lifetime of that cursor by copying it into a
Aws::Vector<uint8_t>orAws::String membermember variable before constructing?ex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good callout, and we solve this through our
constexprruleset blob, that puts the data firmly in.rodataso we never have to worry about lifetimes. Lets address this the same as CRT and add a loud warning comment. Anyone who will newly subclass this for their own endpoint provider will have to do so explicitly the only path they would get it is if they didnt hav a custom endpoint provider, so it would be a new code path. Lets add a warning to match CRT.