Skip to content

Commit dd6a33a

Browse files
committed
reduce size of generated client libraries
1 parent d3185f9 commit dd6a33a

24 files changed

Lines changed: 273 additions & 91 deletions

src/aws-cpp-sdk-core/include/aws/core/client/AWSProtocolClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ namespace Aws
2424
public:
2525
typedef AWSClient BASECLASS;
2626

27+
typedef OutcomeType OUTCOME;
28+
typedef ResponseType RESPONSE;
29+
2730
AWSProtocolClient(const Aws::Client::ClientConfiguration& configuration,
2831
const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer,
2932
const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller)

src/aws-cpp-sdk-core/include/aws/core/client/AWSXmlClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ namespace Aws
3636
public:
3737
typedef AWSClient BASECLASS;
3838

39+
typedef XmlOutcome OUTCOME;
40+
typedef Utils::Xml::XmlDocument RESPONSE;
41+
3942
AWSXMLClient(const Aws::Client::ClientConfiguration& configuration,
4043
const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer,
4144
const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller);

src/aws-cpp-sdk-core/include/aws/core/utils/Outcome.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ namespace Aws
2727
class Outcome
2828
{
2929
public:
30+
typedef R RESULT;
31+
typedef E ERROR;
3032

3133
Outcome() : result(), error(), success(false)
3234
{

src/aws-cpp-sdk-core/include/aws/core/utils/logging/ErrorMacros.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ do { \
2222
} \
2323
} while (0)
2424

25+
#define AWS_OPERATION_CHECK_PTR_DYNAMIC(PTR, OPERATION, ERROR_TYPE, ERROR) \
26+
do { \
27+
if (PTR == nullptr) \
28+
{ \
29+
AWS_LOGSTREAM_FATAL(OPERATION, "Unexpected nullptr: " #PTR); \
30+
return Aws::Client::AWSError<ERROR_TYPE>(ERROR, #ERROR, "Unexpected nullptr: " #PTR, false); \
31+
} \
32+
} while (0)
33+
34+
2535
#define AWS_CHECK(LOG_TAG, CONDITION, ERROR_MESSAGE, RETURN) \
2636
do { \
2737
if (!(CONDITION)) \
@@ -49,6 +59,15 @@ do { \
4959
} \
5060
} while (0)
5161

62+
#define AWS_OPERATION_CHECK_SUCCESS_DYNAMIC(OUTCOME, OPERATION, ERROR_TYPE, ERROR, ERROR_MESSAGE) \
63+
do { \
64+
if (!OUTCOME.IsSuccess()) \
65+
{ \
66+
AWS_LOGSTREAM_ERROR(OPERATION, ERROR_MESSAGE); \
67+
return Aws::Client::AWSError<ERROR_TYPE>(ERROR, #ERROR, ERROR_MESSAGE, false); \
68+
} \
69+
} while (0)
70+
5271
#define AWS_OPERATION_CHECK_PARAMETER_PRESENT(REQUEST, FIELD, OPERATION, CLIENT_NAMESPACE) \
5372
do { \
5473
if (!REQUEST##.##FIELD##HasBeenSet()) \
@@ -66,6 +85,14 @@ if(!m_isInitialized) \
6685
} \
6786
Aws::Utils::RAIICounter raiiGuard(this->m_operationsProcessed, &this->m_shutdownSignal)
6887

88+
#define AWS_OPERATION_GUARD_DYNAMIC(OPERATION) \
89+
if(!m_isInitialized) \
90+
{ \
91+
AWS_LOGSTREAM_ERROR(OPERATION, "Unable to call " << OPERATION << ": client is not initialized (or already terminated)"); \
92+
return Aws::Client::AWSError<CoreErrors>(CoreErrors::NOT_INITIALIZED, "NOT_INITIALIZED", "Client is not initialized or already terminated", false); \
93+
} \
94+
Aws::Utils::RAIICounter raiiGuard(this->m_operationsProcessed, &this->m_shutdownSignal)
95+
6996
#define AWS_ASYNC_OPERATION_GUARD(OPERATION) \
7097
if(!m_isInitialized) \
7198
{ \

tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborServiceClientHeader.vm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ ${cbor_virtual}std::shared_ptr<${metadata.classNamePrefix}EndpointProviderBase>&
5858
void Load${metadata.classNamePrefix}SpecificConfig(const Aws::Client::ClientConfiguration& clientConfiguration);
5959
#end
6060

61+
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/common/ServiceInvokeOperationHeader.vm")
62+
6163
#if(!$serviceModel.endpointRules)
6264
#if($metadata.hasEndpointTrait)
6365
Aws::String m_baseUri;

tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborServiceClientSource.vm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ const char* ${className}::GetAllocationTag() {return ALLOCATION_TAG;}
5555
#parseOverrideOrDefault( "ServiceClientSourceInit_template" "com/amazonaws/util/awsclientgenerator/velocity/cpp/ServiceClientSourceInit.vm")
5656
#end
5757

58+
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/common/ServiceInvokeOperationSource.vm")
59+
5860
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/json/serviceoperations/JsonServiceOperationsSource.vm")

tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/common/ServiceClientOperationRequestRequiredMemberValidate.vm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
return handler(this, ${operation.name}Outcome(Aws::Client::AWSError<${metadata.classNamePrefix}Errors>(${metadata.classNamePrefix}Errors::INTERNAL_FAILURE, "INTERNAL_FAILURE", "Endpoint provider is not initialized", false)), handlerContext);
1111
}
1212
#end
13-
#else
13+
#elseif(!$emitGenericOperation)
1414
AWS_OPERATION_CHECK_PTR(m_endpointProvider, ${operation.name}, CoreErrors, CoreErrors::ENDPOINT_RESOLUTION_FAILURE);
1515
#end
1616
#else##-#if(!$operation.request.shape.hasEventStreamMembers())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
typedef Aws::Utils::Outcome<Aws::AmazonWebServiceResult<RESPONSE>, ${metadata.classNamePrefix}Error> InvokeOutcome;
3+
4+
InvokeOutcome InvokeServiceOperation(
5+
const AmazonWebServiceRequest& request,
6+
#if($metadata.protocol == "rest-json" || $metadata.protocol == "rest-xml")
7+
const std::function<void(Aws::Endpoint::ResolveEndpointOutcome&)>& resolveUri,
8+
#end
9+
#if($serviceModel.metadata.namespace == "S3" || $serviceModel.metadata.namespace == "S3Crt")
10+
Aws::String bucketName,
11+
#end
12+
Aws::Http::HttpMethod httpMethod
13+
) const;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#if($metadata.protocol == "ec2" || $metadata.protocol == "json" || $metadata.protocol == "query" || $metadata.protocol == "smithy-rpc-v2-cbor")
2+
#set($emitGenericOperation = true)
3+
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/common/ServiceClientOperationRequestRequiredMemberValidate.vm")
4+
5+
return ${operation.name}Outcome{InvokeServiceOperation(request, Aws::Http::HttpMethod::HTTP_${operation.http.method})};
6+
#elseif($metadata.protocol == "rest-json" || $metadata.protocol == "rest-xml")
7+
#set($emitGenericOperation = true)
8+
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/common/ServiceClientOperationRequestRequiredMemberValidate.vm")
9+
10+
auto uriResolver = [&](Aws::Endpoint::ResolveEndpointOutcome& endpointResolutionOutcome) {
11+
(void)endpointResolutionOutcome;
12+
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/common/UriRequestPathSegments.vm")
13+
};
14+
15+
#if($serviceModel.metadata.namespace == "S3" || $serviceModel.metadata.namespace == "S3Crt")
16+
#if(($serviceModel.metadata.namespace == "S3" || ($serviceModel.metadata.namespace == "S3Crt" && !$operation.s3CrtEnabled)) && $operation.shouldUsePropertyBag)
17+
return ${operation.name}Outcome{InvokeServiceOperation(request, uriResolver, request.GetBucket(), Aws::Http::HttpMethod::HTTP_${operation.http.method})};
18+
#else
19+
return ${operation.name}Outcome{InvokeServiceOperation(request, uriResolver, "", Aws::Http::HttpMethod::HTTP_${operation.http.method})};
20+
#end
21+
#else
22+
return ${operation.name}Outcome{InvokeServiceOperation(request, uriResolver, Aws::Http::HttpMethod::HTTP_${operation.http.method})};
23+
#end
24+
#end
25+
26+
#set($emitGenericOperation = false)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
${className}::InvokeOutcome ${className}::InvokeServiceOperation(
2+
const AmazonWebServiceRequest& request,
3+
#if($metadata.protocol == "rest-json" || $metadata.protocol == "rest-xml")
4+
const std::function<void(Aws::Endpoint::ResolveEndpointOutcome&)>& resolveUri,
5+
#end
6+
#if($serviceModel.metadata.namespace == "S3" || $serviceModel.metadata.namespace == "S3Crt")
7+
Aws::String bucketName,
8+
#end
9+
Aws::Http::HttpMethod httpMethod
10+
) const
11+
{
12+
auto operationName = request.GetServiceRequestName();
13+
auto serviceName = GetServiceClientName();
14+
15+
AWS_OPERATION_GUARD_DYNAMIC(operationName);
16+
17+
AWS_OPERATION_CHECK_PTR_DYNAMIC(m_endpointProvider, operationName, CoreErrors, CoreErrors::ENDPOINT_RESOLUTION_FAILURE);
18+
AWS_OPERATION_CHECK_PTR_DYNAMIC(m_telemetryProvider, operationName, CoreErrors, CoreErrors::NOT_INITIALIZED);
19+
20+
auto tracer = m_telemetryProvider->getTracer(serviceName, {});
21+
auto meter = m_telemetryProvider->getMeter(serviceName, {});
22+
AWS_OPERATION_CHECK_PTR_DYNAMIC(meter, operationName, CoreErrors, CoreErrors::NOT_INITIALIZED);
23+
24+
auto span = tracer->CreateSpan(Aws::String(serviceName) + "." + operationName,
25+
{{TracingUtils::SMITHY_METHOD_DIMENSION, operationName},
26+
{TracingUtils::SMITHY_SERVICE_DIMENSION, serviceName},
27+
{TracingUtils::SMITHY_SYSTEM_DIMENSION, TracingUtils::SMITHY_METHOD_AWS_VALUE}},
28+
smithy::components::tracing::SpanKind::CLIENT);
29+
30+
#if($serviceModel.metadata.namespace == "S3" || $serviceModel.metadata.namespace == "S3Crt")
31+
if (!bucketName.empty()) {
32+
request.SetServiceSpecificParameters([bucketName]() -> std::shared_ptr<Http::ServiceSpecificParameters> {
33+
Aws::Map<Aws::String, Aws::String> params;
34+
params.emplace("bucketName", bucketName);
35+
ServiceSpecificParameters serviceSpecificParameters{params};
36+
return Aws::MakeShared<ServiceSpecificParameters>(ALLOCATION_TAG, serviceSpecificParameters);
37+
}());
38+
}
39+
#end
40+
41+
return TracingUtils::MakeCallWithTiming<InvokeOutcome>(
42+
[&]() -> InvokeOutcome {
43+
auto endpointResolutionOutcome = TracingUtils::MakeCallWithTiming<ResolveEndpointOutcome>(
44+
[&]() -> ResolveEndpointOutcome { return m_endpointProvider->ResolveEndpoint(request.GetEndpointContextParams()); },
45+
TracingUtils::SMITHY_CLIENT_ENDPOINT_RESOLUTION_METRIC, *meter,
46+
{{TracingUtils::SMITHY_METHOD_DIMENSION, operationName},
47+
{TracingUtils::SMITHY_SERVICE_DIMENSION, serviceName}});
48+
49+
AWS_OPERATION_CHECK_SUCCESS_DYNAMIC(endpointResolutionOutcome, operationName, CoreErrors,
50+
CoreErrors::ENDPOINT_RESOLUTION_FAILURE, endpointResolutionOutcome.GetError().GetMessage());
51+
52+
#if($metadata.findFirstSupportedProtocol() == "smithy-rpc-v2-cbor")
53+
endpointResolutionOutcome.GetResult().AddPathSegments("/service/${serviceModel.metadata.targetPrefix}/operation/");
54+
endpointResolutionOutcome.GetResult().AddPathSegment(operationName);
55+
#end
56+
57+
#if($metadata.protocol == "rest-json" || $metadata.protocol == "rest-xml")
58+
resolveUri(endpointResolutionOutcome);
59+
#end
60+
61+
return MakeRequest(request, endpointResolutionOutcome.GetResult(), httpMethod, Aws::Auth::SIGV4_SIGNER);
62+
},
63+
TracingUtils::SMITHY_CLIENT_DURATION_METRIC, *meter,
64+
{{TracingUtils::SMITHY_METHOD_DIMENSION, operationName},
65+
{TracingUtils::SMITHY_SERVICE_DIMENSION, serviceName}});
66+
}

0 commit comments

Comments
 (0)