Unverified Commit 1be3fa3d authored by Al McLean's avatar Al McLean Committed by GitHub
Browse files

Add Batch Service (#452)



* Add Batch service

* Properly deserialize JSON primitives

* Add protocol test

Co-authored-by: default avatarRussell Cohen <rcoh@amazon.com>
parent 4f3af7a6
Loading
Loading
Loading
Loading
+64 −0
Original line number Diff line number Diff line
$version: "1.0"

namespace com.amazonaws.batch
use smithy.test#httpResponseTests
apply DescribeComputeEnvironments @httpResponseTests([
    {
        id: "DeserializeDescribeCompute",
        documentation: "This test case validates a bug where unboxed primitives were incorrectly marked as required",
        body: """
            {
                "computeEnvironments":[{
                    "computeEnvironmentName":"test-batch-compute",
                    "computeEnvironmentArn":"arn",
                    "ecsClusterArn":"clusteran",
                    "tags":{"foo": "bar"},
                    "type":"MANAGED",
                    "state":"ENABLED",
                    "status":"VALID",
                    "statusReason":"ComputeEnvironment Healthy",
                    "computeResources":{
                        "type":"EC2",
                        "minvCpus":0,
                        "maxvCpus":256,
                        "desiredvCpus":0,
                        "instanceTypes":["optimal"],
                        "subnets":["subnet-c745b79c","subnet-d4e24fe8"],
                        "securityGroupIds":["sg-06a55e7b"],
                        "instanceRole":"instancerole",
                        "tags":{"Name":"batch-compute"},
                        "ec2Configuration":[{"imageType":"ECS_AL1"}]
                    },
                    "serviceRole":"arn:aws:iam::432762038596:role/service-role/AWSBatchServiceRole"
                }]
            }
        """,
        code: 200,
        protocol: "aws.protocols#restJson1",
        params: {
                "computeEnvironments":[{
                    "computeEnvironmentName":"test-batch-compute",
                    "computeEnvironmentArn":"arn",
                    "ecsClusterArn":"clusteran",
                    "tags":{"foo": "bar"},
                    "type":"MANAGED",
                    "state":"ENABLED",
                    "status":"VALID",
                    "statusReason":"ComputeEnvironment Healthy",
                    "computeResources":{
                        "type":"EC2",
                        "minvCpus":0,
                        "maxvCpus":256,
                        "desiredvCpus":0,
                        "instanceTypes":["optimal"],
                        "subnets":["subnet-c745b79c","subnet-d4e24fe8"],
                        "securityGroupIds":["sg-06a55e7b"],
                        "instanceRole":"instancerole",
                        "tags":{"Name":"batch-compute"},
                        "ec2Configuration":[{"imageType":"ECS_AL1"}]
                    },
                    "serviceRole":"arn:aws:iam::432762038596:role/service-role/AWSBatchServiceRole"
                }]
            }
    }
])
+3880 −0

File added.

Preview size limit exceeded, changes collapsed.

+14 −0
Original line number Diff line number Diff line
[package]
name = "batch-helloworld"
version = "0.1.0"
authors = ["Alistair McLean <mclean@amazon.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
batch = { package = "aws-sdk-batch", path = "../../build/aws-sdk/batch" }
tokio = { version = "1", features = ["full"] }
# used only to enable basic logging:
env_logger = "0.8.2"
tracing-subscriber = "0.2.18"
 No newline at end of file
+26 −0
Original line number Diff line number Diff line
use batch::Region;

#[tokio::main]
async fn main() -> Result<(), batch::Error> {
    tracing_subscriber::fmt::init();

    let conf = batch::Config::builder()
        .region(Region::new("us-east-2"))
        .build();
    let client = batch::Client::from_conf(conf);
    let rsp = client.describe_compute_environments().send().await?;

    let compute_envs = rsp.compute_environments.unwrap_or_default();
    println!("Compute environments ({}):", compute_envs.len());
    for env in compute_envs {
        let arn = env.compute_environment_arn.as_deref().unwrap_or_default();
        let name = env.compute_environment_name.as_deref().unwrap_or_default();

        println!(
            "  Compute Environment Name : {}, Compute Environment ARN : {}",
            name, arn
        );
    }

    Ok(())
}
+4 −3
Original line number Diff line number Diff line
@@ -15,9 +15,11 @@ import software.amazon.smithy.model.traits.JsonNameTrait
import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.rust.codegen.rustlang.Attribute
import software.amazon.smithy.rust.codegen.rustlang.RustMetadata
import software.amazon.smithy.rust.codegen.smithy.Default
import software.amazon.smithy.rust.codegen.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.smithy.RustSymbolProvider
import software.amazon.smithy.rust.codegen.smithy.SymbolMetadataProvider
import software.amazon.smithy.rust.codegen.smithy.defaultValue
import software.amazon.smithy.rust.codegen.smithy.expectRustMetadata
import software.amazon.smithy.rust.codegen.smithy.isOptional
import software.amazon.smithy.rust.codegen.smithy.letIf
@@ -55,9 +57,8 @@ class JsonSerializerSymbolProvider(
            serializerBuilder.deserializerFor(memberShape)?.also {
                attribs.add(Attribute.Custom("serde(deserialize_with = ${it.fullyQualifiedName().dq()})", listOf(it)))
            }
            if (model.expectShape(memberShape.container) is StructureShape && base.toSymbol(memberShape)
                .isOptional()
            ) {
            val memberSymbol = base.toSymbol(memberShape)
            if (model.expectShape(memberShape.container) is StructureShape && (memberSymbol.isOptional() || memberSymbol.defaultValue() == Default.RustDefault)) {
                attribs.add(Attribute.Custom("serde(default)"))
            }
        }