Skip to content

Commit

Permalink
Remove hybrid runtime modes (#2870)
Browse files Browse the repository at this point in the history
This PR removes the `both_default_middleware` and
`both_default_orchestrator` runtime modes since they no longer compile,
and there's no easy way to fix them with the divergences between the two
in service config.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
jdisanti authored and Velfi committed Jul 31, 2023
1 parent 219800e commit 0e02650
Show file tree
Hide file tree
Showing 36 changed files with 155 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class AwsFluentClientDecorator : ClientCodegenDecorator {
baseGenerator.operationShape,
renderClientCreation = { params ->
rust("let mut ${params.configBuilderName} = ${params.configBuilderName};")
if (codegenContext.smithyRuntimeMode.defaultToOrchestrator) {
if (codegenContext.smithyRuntimeMode.generateOrchestrator) {
// TODO(enableNewSmithyRuntimeLaunch): A builder field could not be accessed directly in the orchestrator
// mode when this code change was made. smithy-rs#2792 will enable us to use getters in builders.
// Make this `set_region` conditional by checking if `config_builder.region().is_none()` once the PR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@ class AwsPresignedFluentBuilderMethod(
""",
*codegenScope,
"OpError" to section.operationErrorType,
"RawResponseType" to if (codegenContext.smithyRuntimeMode.defaultToMiddleware) {
"RawResponseType" to if (codegenContext.smithyRuntimeMode.generateMiddleware) {
RuntimeType.smithyHttp(runtimeConfig).resolve("operation::Response")
} else {
RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("client::orchestrator::HttpResponse")
},
) {
if (codegenContext.smithyRuntimeMode.defaultToMiddleware) {
if (codegenContext.smithyRuntimeMode.generateMiddleware) {
renderPresignedMethodBodyMiddleware()
} else {
renderPresignedMethodBody(section)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CredentialCacheConfig(codegenContext: ClientCodegenContext) : ConfigCustom
override fun section(section: ServiceConfig) = writable {
when (section) {
ServiceConfig.ConfigStruct -> {
if (runtimeMode.defaultToMiddleware) {
if (runtimeMode.generateMiddleware) {
rustTemplate(
"""pub(crate) credentials_cache: #{SharedCredentialsCache},""",
*codegenScope,
Expand All @@ -75,7 +75,7 @@ class CredentialCacheConfig(codegenContext: ClientCodegenContext) : ConfigCustom
}

ServiceConfig.ConfigImpl -> {
if (runtimeMode.defaultToOrchestrator) {
if (runtimeMode.generateOrchestrator) {
rustTemplate(
"""
/// Returns the credentials cache.
Expand All @@ -99,7 +99,7 @@ class CredentialCacheConfig(codegenContext: ClientCodegenContext) : ConfigCustom
}

ServiceConfig.BuilderStruct ->
if (runtimeMode.defaultToMiddleware) {
if (runtimeMode.generateMiddleware) {
rustTemplate("credentials_cache: #{Option}<#{CredentialsCache}>,", *codegenScope)
}

Expand All @@ -116,7 +116,7 @@ class CredentialCacheConfig(codegenContext: ClientCodegenContext) : ConfigCustom
*codegenScope,
)

if (runtimeMode.defaultToOrchestrator) {
if (runtimeMode.generateOrchestrator) {
rustTemplate(
"""
/// Sets the credentials cache for this service
Expand All @@ -142,7 +142,7 @@ class CredentialCacheConfig(codegenContext: ClientCodegenContext) : ConfigCustom
}

ServiceConfig.BuilderBuild -> {
if (runtimeMode.defaultToOrchestrator) {
if (runtimeMode.generateOrchestrator) {
rustTemplate(
"""
if let Some(credentials_provider) = layer.load::<#{SharedCredentialsProvider}>().cloned() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CredentialProviderConfig(codegenContext: ClientCodegenContext) : ConfigCus
override fun section(section: ServiceConfig) = writable {
when (section) {
ServiceConfig.BuilderStruct -> {
if (smithyRuntimeMode.defaultToMiddleware) {
if (smithyRuntimeMode.generateMiddleware) {
rustTemplate("credentials_provider: #{Option}<#{SharedCredentialsProvider}>,", *codegenScope)
}
}
Expand All @@ -99,7 +99,7 @@ class CredentialProviderConfig(codegenContext: ClientCodegenContext) : ConfigCus
*codegenScope,
)

if (smithyRuntimeMode.defaultToOrchestrator) {
if (smithyRuntimeMode.generateOrchestrator) {
rustTemplate(
"""
/// Sets the credentials provider for this service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fun decoratorForBuiltIn(
override fun loadBuiltInFromServiceConfig(parameter: Parameter, configRef: String): Writable? =
when (parameter.builtIn) {
builtIn.builtIn -> writable {
if (codegenContext.smithyRuntimeMode.defaultToOrchestrator) {
if (codegenContext.smithyRuntimeMode.generateOrchestrator) {
val newtype = configParamNewtype(parameter, name, codegenContext.runtimeConfig)
val symbol = parameter.symbol().mapRustType { t -> t.stripOuter<RustType.Option>() }
rustTemplate(
Expand All @@ -151,7 +151,7 @@ fun decoratorForBuiltIn(
} else {
rust("$configRef.$name")
}
if (codegenContext.smithyRuntimeMode.defaultToMiddleware && parameter.type == ParameterType.STRING) {
if (codegenContext.smithyRuntimeMode.generateMiddleware && parameter.type == ParameterType.STRING) {
rust(".clone()")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class HttpConnectorDecorator : ClientCodegenDecorator {
codegenContext: ClientCodegenContext,
baseCustomizations: List<ConfigCustomization>,
): List<ConfigCustomization> =
baseCustomizations.letIf(codegenContext.smithyRuntimeMode.exclusivelyGenerateMiddleware) {
baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateMiddleware) {
it + HttpConnectorConfigCustomization(codegenContext)
}
}
Expand All @@ -45,12 +45,12 @@ class HttpConnectorConfigCustomization(
override fun section(section: ServiceConfig): Writable {
return when (section) {
is ServiceConfig.ConfigStruct -> writable {
if (runtimeMode.defaultToMiddleware) {
if (runtimeMode.generateMiddleware) {
rustTemplate("http_connector: Option<#{HttpConnector}>,", *codegenScope)
}
}
is ServiceConfig.ConfigImpl -> writable {
if (runtimeMode.defaultToOrchestrator) {
if (runtimeMode.generateOrchestrator) {
rustTemplate(
"""
/// Return an [`HttpConnector`](#{HttpConnector}) to use when making requests, if any.
Expand All @@ -73,7 +73,7 @@ class HttpConnectorConfigCustomization(
}
}
is ServiceConfig.BuilderStruct -> writable {
if (runtimeMode.defaultToMiddleware) {
if (runtimeMode.generateMiddleware) {
rustTemplate("http_connector: Option<#{HttpConnector}>,", *codegenScope)
}
}
Expand Down Expand Up @@ -157,7 +157,7 @@ class HttpConnectorConfigCustomization(
""",
*codegenScope,
)
if (runtimeMode.defaultToOrchestrator) {
if (runtimeMode.generateOrchestrator) {
rustTemplate(
"""
pub fn set_http_connector(&mut self, http_connector: #{Option}<impl #{Into}<#{HttpConnector}>>) -> &mut Self {
Expand All @@ -180,7 +180,7 @@ class HttpConnectorConfigCustomization(
}
}
is ServiceConfig.BuilderBuild -> writable {
if (runtimeMode.defaultToMiddleware) {
if (runtimeMode.generateMiddleware) {
rust("http_connector: self.http_connector,")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class RegionDecorator : ClientCodegenDecorator {
override fun loadBuiltInFromServiceConfig(parameter: Parameter, configRef: String): Writable? {
return when (parameter.builtIn) {
Builtins.REGION.builtIn -> writable {
if (codegenContext.smithyRuntimeMode.defaultToOrchestrator) {
if (codegenContext.smithyRuntimeMode.generateOrchestrator) {
rustTemplate(
"$configRef.load::<#{Region}>().map(|r|r.as_ref().to_owned())",
"Region" to region(codegenContext.runtimeConfig).resolve("Region"),
Expand Down Expand Up @@ -171,12 +171,12 @@ class RegionProviderConfig(codegenContext: ClientCodegenContext) : ConfigCustomi
override fun section(section: ServiceConfig) = writable {
when (section) {
ServiceConfig.ConfigStruct -> {
if (runtimeMode.defaultToMiddleware) {
if (runtimeMode.generateMiddleware) {
rustTemplate("pub(crate) region: #{Option}<#{Region}>,", *codegenScope)
}
}
ServiceConfig.ConfigImpl -> {
if (runtimeMode.defaultToOrchestrator) {
if (runtimeMode.generateOrchestrator) {
rustTemplate(
"""
/// Returns the AWS region, if it was provided.
Expand All @@ -200,7 +200,7 @@ class RegionProviderConfig(codegenContext: ClientCodegenContext) : ConfigCustomi
}

ServiceConfig.BuilderStruct -> {
if (runtimeMode.defaultToMiddleware) {
if (runtimeMode.generateMiddleware) {
rustTemplate("pub(crate) region: #{Option}<#{Region}>,", *codegenScope)
}
}
Expand All @@ -227,7 +227,7 @@ class RegionProviderConfig(codegenContext: ClientCodegenContext) : ConfigCustomi
*codegenScope,
)

if (runtimeMode.defaultToOrchestrator) {
if (runtimeMode.generateOrchestrator) {
rustTemplate(
"""
/// Sets the AWS region to use when making requests.
Expand All @@ -253,7 +253,7 @@ class RegionProviderConfig(codegenContext: ClientCodegenContext) : ConfigCustomi
}

ServiceConfig.BuilderBuild -> {
if (runtimeMode.defaultToMiddleware) {
if (runtimeMode.generateMiddleware) {
rust("region: self.region,")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class SigV4SigningConfig(
)
}
ServiceConfig.BuilderBuild -> {
if (runtimeMode.defaultToOrchestrator) {
if (runtimeMode.generateOrchestrator) {
rustTemplate(
"""
layer.store_put(#{SigningService}::from_static(${sigV4Trait.name.dq()}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class UserAgentDecorator : ClientCodegenDecorator {
override fun section(section: ServiceConfig): Writable =
when (section) {
is ServiceConfig.BuilderStruct -> writable {
if (runtimeMode.defaultToMiddleware) {
if (runtimeMode.generateMiddleware) {
rustTemplate("app_name: #{Option}<#{AppName}>,", *codegenScope)
}
}
Expand All @@ -174,7 +174,7 @@ class UserAgentDecorator : ClientCodegenDecorator {
*codegenScope,
)

if (runtimeMode.defaultToOrchestrator) {
if (runtimeMode.generateOrchestrator) {
rustTemplate(
"""
/// Sets the name of the app that is using the client.
Expand Down Expand Up @@ -206,21 +206,21 @@ class UserAgentDecorator : ClientCodegenDecorator {
}

is ServiceConfig.BuilderBuild -> writable {
if (runtimeMode.defaultToOrchestrator) {
if (runtimeMode.generateOrchestrator) {
rust("layer.store_put(#T.clone());", ClientRustModule.Meta.toType().resolve("API_METADATA"))
} else {
rust("app_name: self.app_name,")
}
}

is ServiceConfig.ConfigStruct -> writable {
if (runtimeMode.defaultToMiddleware) {
if (runtimeMode.generateMiddleware) {
rustTemplate("app_name: #{Option}<#{AppName}>,", *codegenScope)
}
}

is ServiceConfig.ConfigImpl -> writable {
if (runtimeMode.defaultToOrchestrator) {
if (runtimeMode.generateOrchestrator) {
rustTemplate(
"""
/// Returns the name of the app that is using the client, if it was provided.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DisabledAuthDecorator() : ClientCodegenDecorator {
val optionalOperations = optionalAuth[service.id]!!
return ModelTransformer.create().mapShapes(model) {
if (optionalOperations.contains(it.id) && it is OperationShape) {
if (settings.codegenConfig.enableNewSmithyRuntime.defaultToOrchestrator) {
if (settings.codegenConfig.enableNewSmithyRuntime.generateOrchestrator) {
it.toBuilder().addTrait(OptionalAuthTrait()).build()
} else {
// In middleware, having an empty @auth trait completely disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TimestreamDecorator : ClientCodegenDecorator {
override val order: Byte = -1

private fun applies(codegenContext: ClientCodegenContext): Boolean =
codegenContext.smithyRuntimeMode.defaultToOrchestrator
codegenContext.smithyRuntimeMode.generateOrchestrator

override fun extraSections(codegenContext: ClientCodegenContext): List<AdHocCustomization> =
emptyList<AdHocCustomization>().letIf(applies(codegenContext)) {
Expand Down
4 changes: 2 additions & 2 deletions aws/sdk-codegen/src/test/kotlin/SdkCodegenIntegrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ class SdkCodegenIntegrationTest {
fun smokeTestSdkCodegen() {
awsSdkIntegrationTest(
model,
defaultToOrchestrator = true,
generateOrchestrator = true,
) { _, _ -> /* it should compile */ }
}

@Test
fun smokeTestSdkCodegenMiddleware() {
awsSdkIntegrationTest(
model,
defaultToOrchestrator = false,
generateOrchestrator = false,
) { _, _ -> /* it should compile */ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal class CredentialCacheConfigTest {

@Test
fun `config override for credentials`() {
awsSdkIntegrationTest(model, defaultToOrchestrator = true) { clientCodegenContext, rustCrate ->
awsSdkIntegrationTest(model, generateOrchestrator = true) { clientCodegenContext, rustCrate ->
val runtimeConfig = clientCodegenContext.runtimeConfig
val codegenScope = arrayOf(
*RuntimeType.preludeScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ fun awsTestCodegenContext(model: Model? = null, settings: ClientRustSettings? =
settings = settings ?: testClientRustSettings(runtimeConfig = AwsTestRuntimeConfig),
)

// TODO(enableNewSmithyRuntimeCleanup): Remove defaultToOrchestrator once the runtime switches to the orchestrator
// TODO(enableNewSmithyRuntimeCleanup): Remove generateOrchestrator once the runtime switches to the orchestrator
fun awsSdkIntegrationTest(
model: Model,
defaultToOrchestrator: Boolean = true,
generateOrchestrator: Boolean = true,
test: (ClientCodegenContext, RustCrate) -> Unit = { _, _ -> },
) =
clientIntegrationTest(
Expand All @@ -62,7 +62,7 @@ fun awsSdkIntegrationTest(
"codegen",
ObjectNode.builder()
.withMember("includeFluentClient", false)
.letIf(defaultToOrchestrator) {
.letIf(generateOrchestrator) {
it.withMember("enableNewSmithyRuntime", StringNode.from("orchestrator"))
}
.build(),
Expand Down
4 changes: 2 additions & 2 deletions aws/sra-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ val allCodegenTests = servicesToGenerate.map {
,
"codegen": {
"includeFluentClient": false,
${ ""/* "enableNewSmithyRuntime": "both_default_middleware" */ }
"enableNewSmithyRuntime": "orchestrator"
"enableNewSmithyRuntime": "orchestrator",
"includeEndpointUrlConfig": false
},
"customizationConfig": {
"awsSdk": {
Expand Down
4 changes: 2 additions & 2 deletions aws/sra-test/integration-tests/aws-sdk-s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ aws-types = { path = "../../../rust-runtime/aws-types" }
criterion = { version = "0.4", features = ["async_tokio"] }
http = "0.2.3"
http-body = "0.4.5"
last-release-smithy-client = { version = "0.55", package = "aws-smithy-client", features = ["test-util", "rustls"] }
last-release-s3 = { version = "0.26", package = "aws-sdk-s3", features = ["test-util"] }
last-release-smithy-client = { version = "0.55.3", package = "aws-smithy-client", features = ["test-util", "rustls"] }
last-release-s3 = { version = "0.28", package = "aws-sdk-s3", features = ["test-util"] }
tokio = { version = "1.23.1", features = ["macros", "test-util", "rt-multi-thread"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.15", features = ["env-filter", "json"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#[macro_use]
extern crate criterion;
use aws_sdk_s3 as s3;
use aws_smithy_runtime_api::client::interceptors::InterceptorRegistrar;
use aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
use aws_smithy_types::config_bag::ConfigBag;
use criterion::{BenchmarkId, Criterion};

macro_rules! test_connection {
Expand Down Expand Up @@ -92,7 +89,7 @@ async fn orchestrator(client: &s3::Client) {
.list_objects_v2()
.bucket("test-bucket")
.prefix("prefix~")
.send_orchestrator()
.send()
.await
.expect("successful execution");
}
Expand Down
Loading

0 comments on commit 0e02650

Please sign in to comment.