From c9f49bd5123a73fc6b087fe2ab417da35606c0ef Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 11 Jul 2012 00:09:05 -0700 Subject: [PATCH] Issue 309: initial support for amazon rds --- labs/aws-rds/pom.xml | 114 +++++ .../aws/rds/AWSRDSProviderMetadata.java | 109 +++++ .../org.jclouds.providers.ProviderMetadata | 1 + .../jclouds/aws/rds/AWSRDSProviderTest.java | 36 ++ .../features/AWSInstanceClientLiveTest.java | 35 ++ .../AWSSecurityGroupClientLiveTest.java | 35 ++ .../AWSSubnetGroupClientLiveTest.java | 35 ++ labs/pom.xml | 2 + labs/rds/pom.xml | 107 +++++ .../src/main/java/org/jclouds/rds/RDS.java | 117 +++++ .../java/org/jclouds/rds/RDSApiMetadata.java | 97 ++++ .../java/org/jclouds/rds/RDSAsyncClient.java | 89 ++++ .../main/java/org/jclouds/rds/RDSClient.java | 86 ++++ .../rds/config/RDSRestClientModule.java | 53 +++ .../jclouds/rds/domain/EC2SecurityGroup.java | 165 +++++++ .../java/org/jclouds/rds/domain/IPRange.java | 126 +++++ .../java/org/jclouds/rds/domain/Instance.java | 434 ++++++++++++++++++ .../org/jclouds/rds/domain/SecurityGroup.java | 251 ++++++++++ .../java/org/jclouds/rds/domain/Subnet.java | 144 ++++++ .../org/jclouds/rds/domain/SubnetGroup.java | 212 +++++++++ .../rds/features/InstanceAsyncClient.java | 92 ++++ .../jclouds/rds/features/InstanceClient.java | 90 ++++ .../features/SecurityGroupAsyncClient.java | 92 ++++ .../rds/features/SecurityGroupClient.java | 90 ++++ .../rds/features/SubnetGroupAsyncClient.java | 92 ++++ .../rds/features/SubnetGroupClient.java | 92 ++++ .../rds/options/ListInstancesOptions.java | 143 ++++++ .../options/ListSecurityGroupsOptions.java | 102 ++++ .../rds/options/ListSubnetGroupsOptions.java | 102 ++++ .../xml/DescribeDBInstancesResultHandler.java | 111 +++++ ...DescribeDBSecurityGroupsResultHandler.java | 107 +++++ .../DescribeDBSubnetGroupsResultHandler.java | 107 +++++ .../rds/xml/EC2SecurityGroupHandler.java | 77 ++++ .../org/jclouds/rds/xml/IPRangeHandler.java | 73 +++ .../org/jclouds/rds/xml/InstanceHandler.java | 160 +++++++ .../jclouds/rds/xml/SecurityGroupHandler.java | 125 +++++ .../jclouds/rds/xml/SubnetGroupHandler.java | 110 +++++ .../org/jclouds/rds/xml/SubnetHandler.java | 75 +++ .../services/org.jclouds.apis.ApiMetadata | 1 + .../org/jclouds/rds/RDSApiMetadataTest.java | 39 ++ .../test/java/org/jclouds/rds/RDSTest.java | 124 +++++ .../features/InstanceClientExpectTest.java | 197 ++++++++ .../rds/features/InstanceClientLiveTest.java | 73 +++ .../SecurityGroupClientExpectTest.java | 197 ++++++++ .../features/SecurityGroupClientLiveTest.java | 79 ++++ .../features/SubnetGroupClientExpectTest.java | 197 ++++++++ .../features/SubnetGroupClientLiveTest.java | 79 ++++ .../BaseRDSAsyncClientExpectTest.java | 38 ++ .../rds/internal/BaseRDSClientExpectTest.java | 30 ++ .../rds/internal/BaseRDSClientLiveTest.java | 46 ++ .../rds/internal/BaseRDSExpectTest.java | 78 ++++ .../rds/options/ListInstancesOptionsTest.java | 57 +++ .../ListSecurityGroupsOptionsTest.java | 46 ++ .../options/ListSubnetGroupsOptionsTest.java | 46 ++ .../DescribeDBInstancesResponseTest.java | 74 +++ .../DescribeDBSecurityGroupsResponseTest.java | 79 ++++ .../DescribeDBSubnetGroupsResponseTest.java | 93 ++++ .../rds/parse/GetInstanceResponseTest.java | 69 +++ .../parse/GetSecurityGroupResponseTest.java | 62 +++ .../rds/parse/GetSubnetGroupResponseTest.java | 71 +++ .../src/test/resources/describe_instances.xml | 45 ++ .../resources/describe_securitygroups.xml | 49 ++ .../test/resources/describe_subnetgroups.xml | 70 +++ labs/rds/src/test/resources/get_instance.xml | 45 ++ .../src/test/resources/get_securitygroup.xml | 28 ++ .../src/test/resources/get_subnetgroup.xml | 40 ++ labs/rds/src/test/resources/logback.xml | 38 ++ 67 files changed, 6178 insertions(+) create mode 100644 labs/aws-rds/pom.xml create mode 100644 labs/aws-rds/src/main/java/org/jclouds/aws/rds/AWSRDSProviderMetadata.java create mode 100644 labs/aws-rds/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata create mode 100644 labs/aws-rds/src/test/java/org/jclouds/aws/rds/AWSRDSProviderTest.java create mode 100644 labs/aws-rds/src/test/java/org/jclouds/aws/rds/features/AWSInstanceClientLiveTest.java create mode 100644 labs/aws-rds/src/test/java/org/jclouds/aws/rds/features/AWSSecurityGroupClientLiveTest.java create mode 100644 labs/aws-rds/src/test/java/org/jclouds/aws/rds/features/AWSSubnetGroupClientLiveTest.java create mode 100644 labs/rds/pom.xml create mode 100644 labs/rds/src/main/java/org/jclouds/rds/RDS.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/RDSApiMetadata.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/RDSAsyncClient.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/RDSClient.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/config/RDSRestClientModule.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/domain/EC2SecurityGroup.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/domain/IPRange.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/domain/Instance.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/domain/SecurityGroup.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/domain/Subnet.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/domain/SubnetGroup.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/features/InstanceAsyncClient.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/features/InstanceClient.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/features/SecurityGroupAsyncClient.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/features/SecurityGroupClient.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/features/SubnetGroupAsyncClient.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/features/SubnetGroupClient.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/options/ListInstancesOptions.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/options/ListSecurityGroupsOptions.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/options/ListSubnetGroupsOptions.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/xml/DescribeDBInstancesResultHandler.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/xml/DescribeDBSecurityGroupsResultHandler.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/xml/DescribeDBSubnetGroupsResultHandler.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/xml/EC2SecurityGroupHandler.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/xml/IPRangeHandler.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/xml/InstanceHandler.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/xml/SecurityGroupHandler.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/xml/SubnetGroupHandler.java create mode 100644 labs/rds/src/main/java/org/jclouds/rds/xml/SubnetHandler.java create mode 100644 labs/rds/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata create mode 100644 labs/rds/src/test/java/org/jclouds/rds/RDSApiMetadataTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/RDSTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/features/InstanceClientExpectTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/features/InstanceClientLiveTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/features/SecurityGroupClientExpectTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/features/SecurityGroupClientLiveTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/features/SubnetGroupClientExpectTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/features/SubnetGroupClientLiveTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSAsyncClientExpectTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSClientExpectTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSClientLiveTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSExpectTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/options/ListInstancesOptionsTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/options/ListSecurityGroupsOptionsTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/options/ListSubnetGroupsOptionsTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/parse/DescribeDBInstancesResponseTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/parse/DescribeDBSecurityGroupsResponseTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/parse/DescribeDBSubnetGroupsResponseTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/parse/GetInstanceResponseTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/parse/GetSecurityGroupResponseTest.java create mode 100644 labs/rds/src/test/java/org/jclouds/rds/parse/GetSubnetGroupResponseTest.java create mode 100644 labs/rds/src/test/resources/describe_instances.xml create mode 100644 labs/rds/src/test/resources/describe_securitygroups.xml create mode 100644 labs/rds/src/test/resources/describe_subnetgroups.xml create mode 100644 labs/rds/src/test/resources/get_instance.xml create mode 100644 labs/rds/src/test/resources/get_securitygroup.xml create mode 100644 labs/rds/src/test/resources/get_subnetgroup.xml create mode 100644 labs/rds/src/test/resources/logback.xml diff --git a/labs/aws-rds/pom.xml b/labs/aws-rds/pom.xml new file mode 100644 index 0000000000..50fb5f5973 --- /dev/null +++ b/labs/aws-rds/pom.xml @@ -0,0 +1,114 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.5.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.labs + aws-rds + jclouds Amazon Relational Database Service provider + Relational Database Service implementation targeted to Amazon Web Services + bundle + + + https://rds.us-east-1.amazonaws.com + 2012-04-23 + + ${test.aws.identity} + ${test.aws.credential} + + org.jclouds.aws.rds*;version="${project.version}" + org.jclouds*;version="${project.version}",* + + + + + org.jclouds.labs + rds + ${project.version} + jar + + + org.jclouds.labs + rds + ${project.version} + test-jar + test + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds.driver + jclouds-slf4j + ${project.version} + test + + + ch.qos.logback + logback-classic + 1.0.0 + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + ${test.aws-rds.endpoint} + ${test.aws-rds.api-version} + ${test.aws-rds.build-version} + ${test.aws-rds.identity} + ${test.aws-rds.credential} + + + + + + + + + + + diff --git a/labs/aws-rds/src/main/java/org/jclouds/aws/rds/AWSRDSProviderMetadata.java b/labs/aws-rds/src/main/java/org/jclouds/aws/rds/AWSRDSProviderMetadata.java new file mode 100644 index 0000000000..b1359a53ee --- /dev/null +++ b/labs/aws-rds/src/main/java/org/jclouds/aws/rds/AWSRDSProviderMetadata.java @@ -0,0 +1,109 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.rds; + +import static org.jclouds.aws.domain.Region.AP_NORTHEAST_1; +import static org.jclouds.aws.domain.Region.AP_SOUTHEAST_1; +import static org.jclouds.aws.domain.Region.EU_WEST_1; +import static org.jclouds.aws.domain.Region.SA_EAST_1; +import static org.jclouds.aws.domain.Region.US_EAST_1; +import static org.jclouds.aws.domain.Region.US_WEST_1; +import static org.jclouds.aws.domain.Region.US_WEST_2; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_ZONECLIENT_ENDPOINT; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.aws.domain.Region; +import org.jclouds.rds.RDSApiMetadata; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; + +/** + * Implementation of @ link org.jclouds.types.ProviderMetadata} for Amazon's Elastic Load Balancing + * provider. + * + * @author Adrian Cole + */ +public class AWSRDSProviderMetadata extends BaseProviderMetadata { + + /** The serialVersionUID */ + private static final long serialVersionUID = 7750012233546655021L; + + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return Builder.class.cast(builder().fromProviderMetadata(this)); + } + + public AWSRDSProviderMetadata() { + super(builder()); + } + + public AWSRDSProviderMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = new Properties(); + properties.putAll(Region.regionProperties()); + properties.setProperty(PROPERTY_REGION + "." + US_EAST_1 + ".endpoint", + "https://rds.us-east-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + US_WEST_1 + ".endpoint", + "https://rds.us-west-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + US_WEST_2 + ".endpoint", + "https://rds.us-west-2.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + SA_EAST_1 + ".endpoint", + "https://rds.sa-east-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + EU_WEST_1 + ".endpoint", + "https://rds.eu-west-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + AP_SOUTHEAST_1 + ".endpoint", + "https://rds.ap-southeast-1.amazonaws.com"); + properties.setProperty(PROPERTY_REGION + "." + AP_NORTHEAST_1 + ".endpoint", + "https://rds.ap-northeast-1.amazonaws.com"); + properties.setProperty(PROPERTY_ZONECLIENT_ENDPOINT, "https://ec2.us-east-1.amazonaws.com"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder { + + protected Builder(){ + id("aws-rds") + .name("Amazon Relational Database Service") + .endpoint("https://rds.us-east-1.amazonaws.com") + .homepage(URI.create("http://aws.amazon.com/rds")) + .console(URI.create("https://console.aws.amazon.com/ec2/home")) + .linkedServices("aws-ec2", "aws-rds", "aws-elb", "aws-iam","aws-cloudwatch", "aws-s3", "aws-simpledb") + .iso3166Codes("US-VA", "US-CA", "BR-SP", "US-OR", "IE", "SG", "JP-13") + .apiMetadata(new RDSApiMetadata()) + .defaultProperties(AWSRDSProviderMetadata.defaultProperties()); + } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } + } +} diff --git a/labs/aws-rds/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/labs/aws-rds/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata new file mode 100644 index 0000000000..5db1e216dd --- /dev/null +++ b/labs/aws-rds/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -0,0 +1 @@ +org.jclouds.aws.rds.AWSRDSProviderMetadata diff --git a/labs/aws-rds/src/test/java/org/jclouds/aws/rds/AWSRDSProviderTest.java b/labs/aws-rds/src/test/java/org/jclouds/aws/rds/AWSRDSProviderTest.java new file mode 100644 index 0000000000..506d9fd252 --- /dev/null +++ b/labs/aws-rds/src/test/java/org/jclouds/aws/rds/AWSRDSProviderTest.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.rds; + +import org.jclouds.rds.RDSApiMetadata; +import org.jclouds.providers.internal.BaseProviderMetadataTest; +import org.testng.annotations.Test; + +/** + * The AWSRDSProviderTest tests the org.jclouds.providers.AWSRDSProvider class. + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "AWSRDSProviderTest") +public class AWSRDSProviderTest extends BaseProviderMetadataTest { + + public AWSRDSProviderTest() { + super(new AWSRDSProviderMetadata(), new RDSApiMetadata()); + } +} diff --git a/labs/aws-rds/src/test/java/org/jclouds/aws/rds/features/AWSInstanceClientLiveTest.java b/labs/aws-rds/src/test/java/org/jclouds/aws/rds/features/AWSInstanceClientLiveTest.java new file mode 100644 index 0000000000..9211511cc4 --- /dev/null +++ b/labs/aws-rds/src/test/java/org/jclouds/aws/rds/features/AWSInstanceClientLiveTest.java @@ -0,0 +1,35 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.rds.features; + +import org.jclouds.rds.features.InstanceClientLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "AWSInstanceClientLiveTest") +public class AWSInstanceClientLiveTest extends InstanceClientLiveTest { + + public AWSInstanceClientLiveTest() { + provider = "aws-rds"; + } + +} diff --git a/labs/aws-rds/src/test/java/org/jclouds/aws/rds/features/AWSSecurityGroupClientLiveTest.java b/labs/aws-rds/src/test/java/org/jclouds/aws/rds/features/AWSSecurityGroupClientLiveTest.java new file mode 100644 index 0000000000..db892fbdf4 --- /dev/null +++ b/labs/aws-rds/src/test/java/org/jclouds/aws/rds/features/AWSSecurityGroupClientLiveTest.java @@ -0,0 +1,35 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.rds.features; + +import org.jclouds.rds.features.SecurityGroupClientLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "AWSSecurityGroupClientLiveTest") +public class AWSSecurityGroupClientLiveTest extends SecurityGroupClientLiveTest { + + public AWSSecurityGroupClientLiveTest() { + provider = "aws-rds"; + } + +} diff --git a/labs/aws-rds/src/test/java/org/jclouds/aws/rds/features/AWSSubnetGroupClientLiveTest.java b/labs/aws-rds/src/test/java/org/jclouds/aws/rds/features/AWSSubnetGroupClientLiveTest.java new file mode 100644 index 0000000000..d1ed871322 --- /dev/null +++ b/labs/aws-rds/src/test/java/org/jclouds/aws/rds/features/AWSSubnetGroupClientLiveTest.java @@ -0,0 +1,35 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.aws.rds.features; + +import org.jclouds.rds.features.SubnetGroupClientLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "AWSSubnetGroupClientLiveTest") +public class AWSSubnetGroupClientLiveTest extends SubnetGroupClientLiveTest { + + public AWSSubnetGroupClientLiveTest() { + provider = "aws-rds"; + } + +} diff --git a/labs/pom.xml b/labs/pom.xml index f304e72b58..c5a4f19e2b 100644 --- a/labs/pom.xml +++ b/labs/pom.xml @@ -53,5 +53,7 @@ iam aws-iam nodepool + rds + aws-rds diff --git a/labs/rds/pom.xml b/labs/rds/pom.xml new file mode 100644 index 0000000000..822518f760 --- /dev/null +++ b/labs/rds/pom.xml @@ -0,0 +1,107 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.5.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.labs + rds + jcloud rds api + jclouds components to access an implementation of Relational Database Service + bundle + + + https://rds.us-east-1.amazonaws.com + 2012-04-23 + + ${test.aws.identity} + ${test.aws.credential} + + org.jclouds.rds*;version="${project.version}" + org.jclouds*;version="${project.version}",* + + + + + org.jclouds.common + aws-common + ${project.version} + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds.driver + jclouds-slf4j + ${project.version} + test + + + ch.qos.logback + logback-classic + 1.0.0 + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + ${test.rds.endpoint} + ${test.rds.api-version} + ${test.rds.build-version} + ${test.rds.identity} + ${test.rds.credential} + + + + + + + + + + + + diff --git a/labs/rds/src/main/java/org/jclouds/rds/RDS.java b/labs/rds/src/main/java/org/jclouds/rds/RDS.java new file mode 100644 index 0000000000..b6d72e9199 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/RDS.java @@ -0,0 +1,117 @@ +package org.jclouds.rds; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.collect.PaginatedIterables; +import org.jclouds.rds.domain.Instance; +import org.jclouds.rds.domain.SecurityGroup; +import org.jclouds.rds.domain.SubnetGroup; +import org.jclouds.rds.features.InstanceClient; +import org.jclouds.rds.features.SecurityGroupClient; +import org.jclouds.rds.features.SubnetGroupClient; +import org.jclouds.rds.options.ListInstancesOptions; +import org.jclouds.rds.options.ListSecurityGroupsOptions; +import org.jclouds.rds.options.ListSubnetGroupsOptions; + +import com.google.common.base.Function; + +/** + * Utilities for using RDS. + * + * @author Adrian Cole + */ +public class RDS { + + /** + * List instances based on the criteria in the {@link ListInstancesOptions} passed in. + * + * @param instanceClient + * the {@link InstanceClient} to use for the request + * @param options + * the {@link ListInstancesOptions} describing the ListInstances request + * + * @return iterable of instances fitting the criteria + */ + public static Iterable listInstances(final InstanceClient instanceClient, + final ListInstancesOptions options) { + return PaginatedIterables.lazyContinue(instanceClient.list(options), + new Function>() { + + @Override + public PaginatedIterable apply(Object input) { + return instanceClient.list(options.clone().afterMarker(input)); + } + + @Override + public String toString() { + return "listInstances(" + options + ")"; + } + }); + } + + public static Iterable listInstances(InstanceClient instanceClient) { + return listInstances(instanceClient, new ListInstancesOptions()); + } + + /** + * List securityGroups based on the criteria in the {@link ListSecurityGroupsOptions} passed in. + * + * @param securityGroupClient + * the {@link SecurityGroupClient} to use for the request + * @param options + * the {@link ListSecurityGroupsOptions} describing the ListSecurityGroups request + * + * @return iterable of securityGroups fitting the criteria + */ + public static Iterable listSecurityGroups(final SecurityGroupClient securityGroupClient, + final ListSecurityGroupsOptions options) { + return PaginatedIterables.lazyContinue(securityGroupClient.list(options), + new Function>() { + + @Override + public PaginatedIterable apply(Object input) { + return securityGroupClient.list(options.clone().afterMarker(input)); + } + + @Override + public String toString() { + return "listSecurityGroups(" + options + ")"; + } + }); + } + + public static Iterable listSecurityGroups(SecurityGroupClient securityGroupClient) { + return listSecurityGroups(securityGroupClient, new ListSecurityGroupsOptions()); + } + + /** + * List subnetGroups based on the criteria in the {@link ListSubnetGroupsOptions} passed in. + * + * @param subnetGroupClient + * the {@link SubnetGroupClient} to use for the request + * @param options + * the {@link ListSubnetGroupsOptions} describing the ListSubnetGroups request + * + * @return iterable of subnetGroups fitting the criteria + */ + public static Iterable listSubnetGroups(final SubnetGroupClient subnetGroupClient, + final ListSubnetGroupsOptions options) { + return PaginatedIterables.lazyContinue(subnetGroupClient.list(options), + new Function>() { + + @Override + public PaginatedIterable apply(Object input) { + return subnetGroupClient.list(options.clone().afterMarker(input)); + } + + @Override + public String toString() { + return "listSubnetGroups(" + options + ")"; + } + }); + } + + public static Iterable listSubnetGroups(SubnetGroupClient subnetGroupClient) { + return listSubnetGroups(subnetGroupClient, new ListSubnetGroupsOptions()); + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/RDSApiMetadata.java b/labs/rds/src/main/java/org/jclouds/rds/RDSApiMetadata.java new file mode 100644 index 0000000000..8b148968fc --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/RDSApiMetadata.java @@ -0,0 +1,97 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds; + +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; +import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.rds.config.RDSRestClientModule; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.BaseRestApiMetadata; + +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; +import com.google.inject.Module; + +/** + * Implementation of {@link ApiMetadata} for Amazon's Relational Database Service api. + * + * @author Adrian Cole + */ +public class RDSApiMetadata extends BaseRestApiMetadata { + + /** The serialVersionUID */ + private static final long serialVersionUID = -7077953935392202824L; + + public static final TypeToken> CONTEXT_TOKEN = new TypeToken>() { + private static final long serialVersionUID = -5070937833892503232L; + }; + + @Override + public Builder toBuilder() { + return new Builder(getApi(), getAsyncApi()).fromApiMetadata(this); + } + + public RDSApiMetadata() { + this(new Builder(RDSClient.class, RDSAsyncClient.class)); + } + + protected RDSApiMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = BaseRestApiMetadata.defaultProperties(); + properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); + properties.setProperty(PROPERTY_HEADER_TAG, "amz"); + return properties; + } + + public static class Builder extends BaseRestApiMetadata.Builder { + + protected Builder(Class client, Class asyncClient) { + super(client, asyncClient); + id("rds") + .name("Amazon Relational Database Service Api") + .identityName("Access Key ID") + .credentialName("Secret Access Key") + .version("2012-04-23") + .defaultProperties(RDSApiMetadata.defaultProperties()) + .defaultEndpoint("https://rds.us-east-1.amazonaws.com") + .documentation(URI.create("http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference")) + .defaultModules(ImmutableSet.>of(RDSRestClientModule.class)); + } + + @Override + public RDSApiMetadata build() { + return new RDSApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(ApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/RDSAsyncClient.java b/labs/rds/src/main/java/org/jclouds/rds/RDSAsyncClient.java new file mode 100644 index 0000000000..8ca159a664 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/RDSAsyncClient.java @@ -0,0 +1,89 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds; + +import java.util.Set; + +import javax.annotation.Nullable; + +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.location.Region; +import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; +import org.jclouds.rds.features.InstanceAsyncClient; +import org.jclouds.rds.features.SecurityGroupAsyncClient; +import org.jclouds.rds.features.SubnetGroupAsyncClient; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.rest.annotations.EndpointParam; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.VirtualHost; + +import com.google.common.annotations.Beta; +import com.google.inject.Provides; + +/** + * Provides access to EC2 Elastic Load Balancer via REST API. + *

+ * + * @see RDS + * documentation + * @author Adrian Cole + */ +@Beta +@RequestFilters(FormSigner.class) +@VirtualHost +public interface RDSAsyncClient { + /** + * + * @return the Region codes configured + */ + @Provides + @Region + Set getConfiguredRegions(); + + /** + * Provides asynchronous access to Instance features. + */ + @Delegate + InstanceAsyncClient getInstanceClient(); + + @Delegate + InstanceAsyncClient getInstanceClientForRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + + /** + * Provides asynchronous access to SecurityGroup features. + */ + @Delegate + SecurityGroupAsyncClient getSecurityGroupClient(); + + @Delegate + SecurityGroupAsyncClient getSecurityGroupClientForRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + + /** + * Provides asynchronous access to SubnetGroup features. + */ + @Delegate + SubnetGroupAsyncClient getSubnetGroupClient(); + + @Delegate + SubnetGroupAsyncClient getSubnetGroupClientForRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/RDSClient.java b/labs/rds/src/main/java/org/jclouds/rds/RDSClient.java new file mode 100644 index 0000000000..a2d557b5b9 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/RDSClient.java @@ -0,0 +1,86 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import javax.annotation.Nullable; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.location.Region; +import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; +import org.jclouds.rds.features.InstanceClient; +import org.jclouds.rds.features.SecurityGroupClient; +import org.jclouds.rds.features.SubnetGroupClient; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.rest.annotations.EndpointParam; + +import com.google.common.annotations.Beta; +import com.google.inject.Provides; + +/** + * Provides access to EC2 Elastic Load Balancer via their REST API. + *

+ * + * @author Adrian Cole + * @see RDSAsyncClient + */ +@Beta +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface RDSClient { + /** + * + * @return the Region codes configured + */ + @Provides + @Region + Set getConfiguredRegions(); + + /** + * Provides synchronous access to Instance features. + */ + @Delegate + InstanceClient getInstanceClient(); + + @Delegate + InstanceClient getInstanceClientForRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + + /** + * Provides synchronous access to SecurityGroup features. + */ + @Delegate + SecurityGroupClient getSecurityGroupClient(); + + @Delegate + SecurityGroupClient getSecurityGroupClientForRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + + /** + * Provides synchronous access to SubnetGroup features. + */ + @Delegate + SubnetGroupClient getSubnetGroupClient(); + + @Delegate + SubnetGroupClient getSubnetGroupClientForRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/config/RDSRestClientModule.java b/labs/rds/src/main/java/org/jclouds/rds/config/RDSRestClientModule.java new file mode 100644 index 0000000000..83b561f5dc --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/config/RDSRestClientModule.java @@ -0,0 +1,53 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.config; + +import java.util.Map; + +import org.jclouds.aws.config.FormSigningRestClientModule; +import org.jclouds.rds.RDSAsyncClient; +import org.jclouds.rds.RDSClient; +import org.jclouds.rds.features.InstanceAsyncClient; +import org.jclouds.rds.features.InstanceClient; +import org.jclouds.rds.features.SecurityGroupAsyncClient; +import org.jclouds.rds.features.SecurityGroupClient; +import org.jclouds.rds.features.SubnetGroupAsyncClient; +import org.jclouds.rds.features.SubnetGroupClient; +import org.jclouds.rest.ConfiguresRestClient; + +import com.google.common.collect.ImmutableMap; +import com.google.common.reflect.TypeToken; + +/** + * Configures the RDS connection. + * + * @author Adrian Cole + */ +@ConfiguresRestClient +public class RDSRestClientModule extends FormSigningRestClientModule { + public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// + .put(InstanceClient.class, InstanceAsyncClient.class) + .put(SecurityGroupClient.class, SecurityGroupAsyncClient.class) + .put(SubnetGroupClient.class, SubnetGroupAsyncClient.class) + .build(); + + public RDSRestClientModule() { + super(TypeToken.of(RDSClient.class), TypeToken.of(RDSAsyncClient.class), DELEGATE_MAP); + } +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/domain/EC2SecurityGroup.java b/labs/rds/src/main/java/org/jclouds/rds/domain/EC2SecurityGroup.java new file mode 100644 index 0000000000..13efdf969b --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/domain/EC2SecurityGroup.java @@ -0,0 +1,165 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Objects; +import com.google.common.base.Optional; + +/** + * + * @see doc + * + * @author Adrian Cole + */ +public class EC2SecurityGroup { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromEC2SecurityGroup(this); + } + + public static class Builder { + + protected Optional id = Optional.absent(); + protected String name; + protected String ownerId; + protected String status; + + /** + * @see EC2SecurityGroup#getId() + */ + public Builder id(String id) { + this.id = Optional.fromNullable(id); + return this; + } + + /** + * @see EC2SecurityGroup#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see EC2SecurityGroup#getOwnerId() + */ + public Builder ownerId(String ownerId) { + this.ownerId = ownerId; + return this; + } + + /** + * @see EC2SecurityGroup#getStatus() + */ + public Builder status(String status) { + this.status = status; + return this; + } + + public EC2SecurityGroup build() { + return new EC2SecurityGroup(id, name, ownerId, status); + } + + public Builder fromEC2SecurityGroup(EC2SecurityGroup in) { + return this.id(in.getId().orNull()).name(in.getName()).ownerId(in.getOwnerId()).status(in.getStatus()); + } + } + + protected final Optional id; + protected final String name; + protected final String ownerId; + protected final String status; + + protected EC2SecurityGroup(Optional id, String name, String ownerId, String status) { + this.id = checkNotNull(id, "id"); + this.name = checkNotNull(name, "name"); + this.ownerId = checkNotNull(ownerId, "ownerId"); + this.status = checkNotNull(status, "status"); + } + + /** + * Specifies the id of the EC2 Security Group. + */ + public Optional getId() { + return id; + } + + /** + * Specifies the name of the EC2 Security Group. + */ + public String getName() { + return name; + } + + /** + * Specifies the AWS ID of the owner of the EC2 security group specified as {@link #getName()} + */ + public String getOwnerId() { + return ownerId; + } + + /** + * Provides the status of the EC2 security group. + */ + public String getStatus() { + return status; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(id, name, ownerId); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + EC2SecurityGroup other = EC2SecurityGroup.class.cast(obj); + return Objects.equal(this.id, other.id) && Objects.equal(this.name, other.name) + && Objects.equal(this.ownerId, other.ownerId); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id.orNull()).add("name", name) + .add("ownerId", ownerId).add("status", status).toString(); + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/domain/IPRange.java b/labs/rds/src/main/java/org/jclouds/rds/domain/IPRange.java new file mode 100644 index 0000000000..76f70e7b0a --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/domain/IPRange.java @@ -0,0 +1,126 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Objects; + +/** + * + * @see doc + * + * @author Adrian Cole + */ +public class IPRange { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromIPRange(this); + } + + public static class Builder { + + protected String cidrIp; + protected String status; + + /** + * @see IPRange#getAvailabilityZone() + */ + public Builder cidrIp(String cidrIp) { + this.cidrIp = cidrIp; + return this; + } + + /** + * @see IPRange#getStatus() + */ + public Builder status(String status) { + this.status = status; + return this; + } + + public IPRange build() { + return new IPRange(cidrIp, status); + } + + public Builder fromIPRange(IPRange in) { + return this.cidrIp(in.getCIDRIP()).status(in.getStatus()); + } + } + + protected final String cidrIp; + protected final String status; + + protected IPRange(String cidrIp, String status) { + this.cidrIp = checkNotNull(cidrIp, "cidrIp"); + this.status = checkNotNull(status, "status"); + } + + /** + * Specifies the IP range. + */ + public String getCIDRIP() { + return cidrIp; + } + + /** + * Specifies the status of the IP range. + */ + public String getStatus() { + return status; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(cidrIp, status); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + IPRange other = IPRange.class.cast(obj); + return Objects.equal(this.cidrIp, other.cidrIp) && Objects.equal(this.status, other.status); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("cidrIp", cidrIp) + .add("status", status).toString(); + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/domain/Instance.java b/labs/rds/src/main/java/org/jclouds/rds/domain/Instance.java new file mode 100644 index 0000000000..bd2716cdc6 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/domain/Instance.java @@ -0,0 +1,434 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Date; +import java.util.Map; + +import com.google.common.base.Objects; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableMap; +import com.google.common.net.HostAndPort; + +/** + * A DB Instance is an isolated database environment running in the cloud. A DB Instance can contain + * multiple user-created databases, and can be accessed using the same tools and applications as a + * stand-alone database instance. + * + * + *

Note

+ * + * Amazon RDS supports access from any standard SQL client application. Amazon RDS does not allow + * direct host access via Telnet, Secure Shell (SSH), or Windows Remote Desktop Connection. + * + * + * DB Instances are simple to create and modify with the Amazon RDS command line tools, APIs, or the + * AWS Management Console. + * + * + * Amazon RDS creates a master user account for your DB Instance as part of the creation process. + * This master user has permissions to create databases and to perform create, delete, select, + * update and insert operations on tables the master user creates. You must set the master user + * password when you create a DB Instance, but you can change it at any time using the Amazon RDS + * command line tools, APIs, or the AWS Management Console. You can also change the master user + * password and manage users using standard SQL commands. + * + * @see doc + * + * @author Adrian Cole + */ +public class Instance { + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromInstance(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String id; + protected Optional name = Optional.absent(); + protected String instanceClass; + protected HostAndPort endpoint; + protected String status; + protected String availabilityZone; + protected boolean multiAZ; + protected String engine; + protected String engineVersion; + protected String licenseModel; + protected String masterUsername; + protected int allocatedStorageGB; + protected Date createdTime; + protected Optional subnetGroup = Optional.absent(); + protected ImmutableMap.Builder securityGroupNameToStatus = ImmutableMap + . builder(); + + /** + * @see Instance#getId() + */ + public T id(String id) { + this.id = id; + return self(); + } + + /** + * @see Instance#getName() + */ + public T name(String name) { + this.name = Optional.fromNullable(name); + return self(); + } + + /** + * @see Instance#getInstanceClass() + */ + public T instanceClass(String instanceClass) { + this.instanceClass = instanceClass; + return self(); + } + + /** + * @see Instance#getEndpoint() + */ + public T endpoint(HostAndPort endpoint) { + this.endpoint = endpoint; + return self(); + } + + /** + * @see Instance#getStatus() + */ + public T status(String status) { + this.status = status; + return self(); + } + + /** + * @see Instance#getAvailabilityZone() + */ + public T availabilityZone(String availabilityZone) { + this.availabilityZone = availabilityZone; + return self(); + } + + /** + * @see Instance#isMultiAZ() + */ + public T multiAZ(boolean multiAZ) { + this.multiAZ = multiAZ; + return self(); + } + + /** + * @see Instance#getEngine() + */ + public T engine(String engine) { + this.engine = engine; + return self(); + } + + /** + * @see Instance#getEngineVersion() + */ + public T engineVersion(String engineVersion) { + this.engineVersion = engineVersion; + return self(); + } + + /** + * @see Instance#getLicenseModel() + */ + public T licenseModel(String licenseModel) { + this.licenseModel = licenseModel; + return self(); + } + + /** + * @see Instance#getMasterUsername() + */ + public T masterUsername(String masterUsername) { + this.masterUsername = masterUsername; + return self(); + } + + /** + * @see Instance#getAllocatedStorageGB() + */ + public T allocatedStorageGB(int allocatedStorageGB) { + this.allocatedStorageGB = allocatedStorageGB; + return self(); + } + + /** + * @see Instance#getCreatedTime() + */ + public T createdTime(Date createdTime) { + this.createdTime = createdTime; + return self(); + } + + /** + * @see Instance#getSubnetGroup() + */ + public T subnetGroup(SubnetGroup subnetGroup) { + this.subnetGroup = Optional.fromNullable(subnetGroup); + return self(); + } + + /** + * @see Instance#getSecurityGroupNameToStatus() + */ + public T securityGroupNameToStatus(Map securityGroupNameToStatus) { + this.securityGroupNameToStatus.putAll(checkNotNull(securityGroupNameToStatus, "securityGroupNameToStatus")); + return self(); + } + + /** + * @see Instance#getSecurityGroupNameToStatus() + */ + public T securityGroupNameToStatus(String securityGroupName, String status) { + this.securityGroupNameToStatus.put(checkNotNull(securityGroupName, "securityGroupName"), + checkNotNull(status, "status")); + return self(); + } + + public Instance build() { + return new Instance(id, name, instanceClass, endpoint, status, availabilityZone, multiAZ, engine, + engineVersion, licenseModel, masterUsername, allocatedStorageGB, createdTime, subnetGroup, + securityGroupNameToStatus.build()); + } + + public T fromInstance(Instance in) { + return this.id(in.getId()).name(in.getName().orNull()).instanceClass(in.getInstanceClass()) + .endpoint(in.getEndpoint()).status(in.getStatus()).availabilityZone(in.getAvailabilityZone()) + .multiAZ(in.isMultiAZ()).engine(in.getEngine()).engineVersion(in.getEngineVersion()) + .licenseModel(in.getLicenseModel()).masterUsername(in.getMasterUsername()) + .allocatedStorageGB(in.getAllocatedStorageGB()).createdTime(in.getCreatedTime()) + .subnetGroup(in.getSubnetGroup().orNull()) + .securityGroupNameToStatus(in.getSecurityGroupNameToStatus()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + protected final String id; + protected final Optional name; + protected final String instanceClass; + protected final HostAndPort endpoint; + protected final String status; + protected final String availabilityZone; + protected final boolean multiAZ; + protected final String engine; + protected final String engineVersion; + protected final String licenseModel; + protected final String masterUsername; + protected int allocatedStorageGB; + protected final Date createdTime; + protected final Optional subnetGroup; + protected final Map securityGroupNameToStatus; + + protected Instance(String id, Optional name, String instanceClass, HostAndPort endpoint, String status, + String availabilityZone, boolean multiAZ, String engine, String engineVersion, String licenseModel, + String masterUsername, int allocatedStorageGB, Date createdTime, Optional subnetGroup, + Map securityGroupNameToStatus) { + this.id = checkNotNull(id, "id"); + this.name = checkNotNull(name, "name of %s", id); + this.endpoint = checkNotNull(endpoint, "endpoint of %s", id); + this.status = checkNotNull(status, "status of %s", id); + this.instanceClass = checkNotNull(instanceClass, "instanceClass of %s", id); + this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone of %s", id); + this.multiAZ = multiAZ; + this.engine = checkNotNull(engine, "engine of %s", id); + this.engineVersion = checkNotNull(engineVersion, "engineVersion of %s", id); + this.licenseModel = checkNotNull(licenseModel, "licenseModel of %s", id); + this.masterUsername = checkNotNull(masterUsername, "masterUsername of %s", id); + this.allocatedStorageGB = allocatedStorageGB; + this.createdTime = checkNotNull(createdTime, "createdTime of %s", id); + this.subnetGroup = checkNotNull(subnetGroup, "subnetGroup of %s", id); + this.securityGroupNameToStatus = ImmutableMap.copyOf(checkNotNull(securityGroupNameToStatus, + "securityGroupNameToStatus of %s", id)); + } + + /** + * Contains a user-supplied database identifier. This is the unique key that identifies a DB + * Instance. + */ + public String getId() { + return id; + } + + /** + * The meaning of this parameter differs according to the database engine you use. + * + *

MySQL

+ * + * Contains the name of the initial database of this instance that was provided at create time, + * if one was specified when the DB Instance was created. This same name is returned for the life + * of the DB Instance. + * + *

Oracle

+ * + * Contains the Oracle System ID (SID) of the created DB Instance. + */ + public Optional getName() { + return name; + } + + /** + * Specifies the current state of this database. + */ + public String getStatus() { + return status; + } + + /** + * Contains the name of the compute and memory capacity class of the DB Instance. + */ + public String getInstanceClass() { + return instanceClass; + } + + /** + * Specifies the connection endpoint. + */ + public HostAndPort getEndpoint() { + return endpoint; + } + + /** + * Specifies the name of the Availability Zone the DB Instance is located in. + */ + public String getAvailabilityZone() { + return availabilityZone; + } + + /** + * Specifies the name of the Availability Zone the DB Instance is located in. + */ + public boolean isMultiAZ() { + return multiAZ; + } + + /** + * Provides the name of the database engine to be used for this DB Instance. + */ + public String getEngine() { + return engine; + } + + /** + * Indicates the database engine version. + */ + public String getEngineVersion() { + return engineVersion; + } + + /** + * License model information for this DB Instance. + */ + public String getLicenseModel() { + return licenseModel; + } + + /** + * Contains the master username for the DB Instance. + */ + public String getMasterUsername() { + return masterUsername; + } + + /** + * Specifies the allocated storage size specified in gigabytes. + */ + public int getAllocatedStorageGB() { + return allocatedStorageGB; + } + + /** + * Provides the date and time the DB Instance was created. + */ + public Date getCreatedTime() { + return createdTime; + } + + /** + * Provides the information of the subnet group associated with the DB instance, including the + * name, description and subnets in the subnet group. + */ + public Optional getSubnetGroup() { + return subnetGroup; + } + + /** + * SecurityGroupName -> Status + */ + public Map getSecurityGroupNameToStatus() { + return securityGroupNameToStatus; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(id, createdTime); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Instance other = (Instance) obj; + return Objects.equal(this.id, other.id) && Objects.equal(this.createdTime, other.createdTime); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id).add("name", name.orNull()) + .add("instanceClass", instanceClass).add("endpoint", endpoint).add("status", status) + .add("availabilityZone", availabilityZone).add("multiAZ", multiAZ).add("engine", engine) + .add("engineVersion", engineVersion).add("licenseModel", licenseModel) + .add("masterUsername", masterUsername).add("allocatedStorageGB", allocatedStorageGB) + .add("createdTime", createdTime).add("subnetGroup", subnetGroup.orNull()) + .add("securityGroupNameToStatus", securityGroupNameToStatus).toString(); + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/domain/SecurityGroup.java b/labs/rds/src/main/java/org/jclouds/rds/domain/SecurityGroup.java new file mode 100644 index 0000000000..6e03a4a170 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/domain/SecurityGroup.java @@ -0,0 +1,251 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import com.google.common.base.Objects; +import com.google.common.base.Optional; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; + +/** + * Amazon RDS allows you to control access to your DB Instances using DB Security Groups. A DB + * Security Group acts like a firewall controlling network access to your DB Instance. By default, + * network access is turned off to your DB Instances. If you want your applications to access your + * DB Instance you can allow access from specific EC2 security groups or IP ranges. Once ingress is + * configured, the same rules apply to all DB Instances associated with that DBSecurityGroup. + * + *

Important

+ * + * Please ensure you authorize only specific IP ranges or EC2 security groups. We highly discourage + * authorizing broad IP ranges (for example, 0.0.0.0/0). + * + * Note that you cannot use Amazon RDS DB Security Groups to restrict access to your Amazon EC2 + * instances. Similarly, you cannot apply an Amazon EC2 security group to your Amazon RDS DB + * Instance. + * + * + * + * @see doc + * + * @author Adrian Cole + */ +public class SecurityGroup { + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromSecurityGroup(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String name; + protected String description; + protected ImmutableSet.Builder ec2SecurityGroups = ImmutableSet. builder(); + protected ImmutableSet.Builder ipRanges = ImmutableSet. builder(); + protected String ownerId; + protected Optional vpcId = Optional.absent(); + + /** + * @see SecurityGroup#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } + + /** + * @see SecurityGroup#getDescription() + */ + public T description(String description) { + this.description = description; + return self(); + } + + /** + * @see SecurityGroup#getEC2SecurityGroups() + */ + public T ec2SecurityGroups(Iterable ec2SecurityGroups) { + this.ec2SecurityGroups.addAll(checkNotNull(ec2SecurityGroups, "ec2SecurityGroups")); + return self(); + } + + /** + * @see SecurityGroup#getEC2SecurityGroups() + */ + public T ec2SecurityGroup(EC2SecurityGroup ec2SecurityGroup) { + this.ec2SecurityGroups.add(checkNotNull(ec2SecurityGroup, "ec2SecurityGroup")); + return self(); + } + + /** + * @see SecurityGroup#getEC2SecurityGroups() + */ + public T ipRanges(Iterable ipRanges) { + this.ipRanges.addAll(checkNotNull(ipRanges, "ipRanges")); + return self(); + } + + /** + * @see SecurityGroup#getEC2SecurityGroups() + */ + public T ipRange(IPRange ipRange) { + this.ipRanges.add(checkNotNull(ipRange, "ipRange")); + return self(); + } + + /** + * @see SecurityGroup#getOwnerId() + */ + public T ownerId(String ownerId) { + this.ownerId = ownerId; + return self(); + } + + /** + * @see SecurityGroupGroup#getVpcId() + */ + public T vpcId(String vpcId) { + this.vpcId = Optional.fromNullable(vpcId); + return self(); + } + + public SecurityGroup build() { + return new SecurityGroup(name, description, ec2SecurityGroups.build(), ipRanges.build(), ownerId, vpcId); + } + + public T fromSecurityGroup(SecurityGroup in) { + return this.name(in.getName()).description(in.getDescription()).ec2SecurityGroups(in.getEC2SecurityGroups()) + .ipRanges(in.getIPRanges()).ownerId(in.getOwnerId()).vpcId(in.getVpcId().orNull()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + protected final String name; + protected final String description; + protected final Set ec2SecurityGroups; + protected final Set ipRanges; + protected final String ownerId; + protected final Optional vpcId; + + protected SecurityGroup(String name, String description, Iterable ec2SecurityGroups, + Iterable ipRanges, String ownerId, Optional vpcId) { + this.name = checkNotNull(name, "name"); + this.description = checkNotNull(description, "description"); + this.ownerId = checkNotNull(ownerId, "ownerId"); + this.ec2SecurityGroups = ImmutableSet.copyOf(checkNotNull(ec2SecurityGroups, "ec2SecurityGroups")); + this.ipRanges = ImmutableSet.copyOf(checkNotNull(ipRanges, "ipRanges")); + this.vpcId = checkNotNull(vpcId, "vpcId"); + } + + /** + * Specifies the name of the DB Security Group. + */ + public String getName() { + return name; + } + + /** + * Provides the description of the DB Security Group. + */ + public String getDescription() { + return description; + } + + /** + * Contains a list of EC2SecurityGroup elements. + */ + public Set getEC2SecurityGroups() { + return ec2SecurityGroups; + } + + /** + * Contains a list of IPRange elements. + */ + public Set getIPRanges() { + return ipRanges; + } + + /** + * Provides the AWS ID of the owner of a specific DB Security Group.. + */ + public String getOwnerId() { + return ownerId; + } + + /** + * Provides the VpcId of the DB Security Group. + */ + public Optional getVpcId() { + return vpcId; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(name); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SecurityGroup other = (SecurityGroup) obj; + return Objects.equal(this.name, other.name); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this).omitNullValues().add("name", name).add("description", description) + .add("ec2SecurityGroups", ec2SecurityGroups).add("ipRanges", ipRanges).add("ownerId", ownerId) + .add("vpcId", vpcId.orNull()); + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/domain/Subnet.java b/labs/rds/src/main/java/org/jclouds/rds/domain/Subnet.java new file mode 100644 index 0000000000..105f9106ae --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/domain/Subnet.java @@ -0,0 +1,144 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Objects; + +/** + * + * @see doc + * + * @author Adrian Cole + */ +public class Subnet { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromSubnet(this); + } + + public static class Builder { + + protected String id; + protected String availabilityZone; + protected String status; + + /** + * @see Subnet#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see Subnet#getAvailabilityZone() + */ + public Builder availabilityZone(String availabilityZone) { + this.availabilityZone = availabilityZone; + return this; + } + + /** + * @see Subnet#getStatus() + */ + public Builder status(String status) { + this.status = status; + return this; + } + + public Subnet build() { + return new Subnet(id, availabilityZone, status); + } + + public Builder fromSubnet(Subnet in) { + return this.id(in.getId()).availabilityZone(in.getAvailabilityZone()).status(in.getStatus()); + } + } + + protected final String id; + protected final String availabilityZone; + protected final String status; + + protected Subnet(String id, String availabilityZone, String status) { + this.id = checkNotNull(id, "id"); + this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone"); + this.status = checkNotNull(status, "status"); + } + + /** + * Specifies the identifier of the subnet. + */ + public String getId() { + return id; + } + + /** + * The name of the availability zone. + */ + public String getAvailabilityZone() { + return availabilityZone; + } + + /** + * Specifies the current status of the securityGroup. + */ + public String getStatus() { + return status; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(id); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Subnet other = Subnet.class.cast(obj); + return Objects.equal(this.id, other.id); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("id", id).add("availabilityZone", availabilityZone) + .add("status", status).toString(); + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/domain/SubnetGroup.java b/labs/rds/src/main/java/org/jclouds/rds/domain/SubnetGroup.java new file mode 100644 index 0000000000..e1cb319150 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/domain/SubnetGroup.java @@ -0,0 +1,212 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; + +/** + * Relational Database Service routinely checks the health of each load-balanced Amazon EC2 + * securityGroup based on the configurations that you specify. If Relational Database Service finds + * an unhealthy securityGroup, it stops sending traffic to the securityGroup and reroutes traffic to + * healthy securityGroups. + * + * + * @see doc + * + * @author Adrian Cole + */ +public class SubnetGroup { + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromSubnetGroup(this); + } + + public static abstract class Builder> { + protected abstract T self(); + + protected String name; + protected String description; + protected String status; + protected ImmutableSet.Builder subnets = ImmutableSet. builder(); + protected Optional vpcId = Optional.absent(); + + /** + * @see SubnetGroup#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } + + /** + * @see SubnetGroup#getDescription() + */ + public T description(String description) { + this.description = description; + return self(); + } + + /** + * @see SubnetGroup#getStatus() + */ + public T status(String status) { + this.status = status; + return self(); + } + + /** + * @see Instance#getSubnets() + */ + public T subnets(Iterable subnets) { + this.subnets.addAll(checkNotNull(subnets, "subnets")); + return self(); + } + + /** + * @see Instance#getSubnets() + */ + public T subnet(Subnet subnet) { + this.subnets.add(checkNotNull(subnet, "subnet")); + return self(); + } + + /** + * @see SubnetGroup#getVpcId() + */ + public T vpcId(String vpcId) { + this.vpcId = Optional.fromNullable(vpcId); + return self(); + } + + public SubnetGroup build() { + return new SubnetGroup(name, description, status, subnets.build(), vpcId); + } + + public T fromSubnetGroup(SubnetGroup in) { + return this.name(in.getName()).description(in.getDescription()).status(in.getStatus()) + .subnets(in.getSubnets()).vpcId(in.getVpcId().orNull()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + protected final String name; + protected final String description; + protected final String status; + protected final Set subnets; + protected final Optional vpcId; + + protected SubnetGroup(String name, String description, String status, Iterable subnets, Optional vpcId) { + this.name = checkNotNull(name, "name"); + this.description = checkNotNull(description, "description"); + this.status = checkNotNull(status, "status"); + this.subnets = ImmutableSet.copyOf(checkNotNull(subnets, "subnets")); + this.vpcId = checkNotNull(vpcId, "vpcId"); + } + + /** + * Specifies the name of the DB Subnet Group. + */ + public String getName() { + return name; + } + + /** + * Provides the description of the DB Subnet Group. + */ + public String getDescription() { + return description; + } + + /** + * Provides the status of the DB Subnet Group. + */ + public String getStatus() { + return status; + } + + /** + * Provides the Subnets of the DB Subnet Group. + */ + public Set getSubnets() { + return subnets; + } + + /** + * Provides the VpcId of the DB Subnet Group. + */ + public Optional getVpcId() { + return vpcId; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(name, vpcId); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SubnetGroup other = (SubnetGroup) obj; + return Objects.equal(this.name, other.name) && Objects.equal(this.vpcId, other.vpcId); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this).omitNullValues().add("name", name).add("description", description) + .add("status", status).add("subnets", subnets).add("vpcId", vpcId.orNull()); + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/features/InstanceAsyncClient.java b/labs/rds/src/main/java/org/jclouds/rds/features/InstanceAsyncClient.java new file mode 100644 index 0000000000..c32aedf191 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/features/InstanceAsyncClient.java @@ -0,0 +1,92 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.features; + +import static org.jclouds.aws.reference.FormParameters.ACTION; + +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.rds.domain.Instance; +import org.jclouds.rds.options.ListInstancesOptions; +import org.jclouds.rds.xml.DescribeDBInstancesResultHandler; +import org.jclouds.rds.xml.InstanceHandler; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.FormParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides access to Amazon RDS via the Query API + *

+ * + * @see doc + * @see InstanceClient + * @author Adrian Cole + */ +@RequestFilters(FormSigner.class) +@VirtualHost +public interface InstanceAsyncClient { + + /** + * @see InstanceClient#get() + */ + @POST + @Path("/") + @XMLResponseParser(InstanceHandler.class) + @FormParams(keys = "Action", values = "DescribeDBInstances") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture get(@FormParam("DBInstanceIdentifier") String id); + + /** + * @see InstanceClient#list() + */ + @POST + @Path("/") + @XMLResponseParser(DescribeDBInstancesResultHandler.class) + @FormParams(keys = "Action", values = "DescribeDBInstances") + ListenableFuture> list(); + + /** + * @see InstanceClient#list(ListInstancesOptions) + */ + @POST + @Path("/") + @XMLResponseParser(DescribeDBInstancesResultHandler.class) + @FormParams(keys = "Action", values = "DescribeDBInstances") + ListenableFuture> list(ListInstancesOptions options); + + /** + * @see InstanceClient#delete() + */ + @POST + @Path("/") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + @FormParams(keys = ACTION, values = "DeleteDBInstance") + ListenableFuture delete(@FormParam("DBInstanceIdentifier") String id); +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/features/InstanceClient.java b/labs/rds/src/main/java/org/jclouds/rds/features/InstanceClient.java new file mode 100644 index 0000000000..11cdf040fc --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/features/InstanceClient.java @@ -0,0 +1,90 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.concurrent.Timeout; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.rds.domain.Instance; +import org.jclouds.rds.options.ListInstancesOptions; + +/** + * Provides access to Amazon RDS via the Query API + *

+ * + * @see doc + * @see InstanceAsyncClient + * @author Adrian Cole + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface InstanceClient { + + /** + * Retrieves information about the specified instance. + * + * @param id + * The user-supplied instance identifier. If this parameter is specified, information + * from only the specific DB Instance is returned. This parameter isn't case sensitive. + * + * @return null if not found + */ + @Nullable + Instance get(String id); + + /** + * Returns information about provisioned RDS instances. If there are none, the action returns an + * empty list. + * + *
+ * You can paginate the results using the {@link ListInstancesOptions parameter} + * + * @param options + * the options describing the instances query + * + * @return the response object + */ + PaginatedIterable list(ListInstancesOptions options); + + /** + * Returns information about provisioned RDS instances. + * + * @return the response object + */ + PaginatedIterable list(); + + /** + * Deletes the specified Instance. + * + *

+ * The DeleteDBInstance API deletes a previously provisioned RDS instance. A successful response + * from the web service indicates the request was received correctly. If a final DBSnapshot is + * requested the status of the RDS instance will be "deleting" until the DBSnapshot is created. + * DescribeDBInstance is used to monitor the status of this operation. This cannot be canceled or + * reverted once submitted. + * + * + * @param id + * The DB Instance identifier for the DB Instance to be deleted. This parameter isn't + * case sensitive. + */ + void delete(String id); + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/features/SecurityGroupAsyncClient.java b/labs/rds/src/main/java/org/jclouds/rds/features/SecurityGroupAsyncClient.java new file mode 100644 index 0000000000..d906f9eff9 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/features/SecurityGroupAsyncClient.java @@ -0,0 +1,92 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.features; + +import static org.jclouds.aws.reference.FormParameters.ACTION; + +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.rds.domain.SecurityGroup; +import org.jclouds.rds.options.ListSecurityGroupsOptions; +import org.jclouds.rds.xml.DescribeDBSecurityGroupsResultHandler; +import org.jclouds.rds.xml.SecurityGroupHandler; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.FormParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides access to Amazon RDS via the Query API + *

+ * + * @see doc + * @see SecurityGroupClient + * @author Adrian Cole + */ +@RequestFilters(FormSigner.class) +@VirtualHost +public interface SecurityGroupAsyncClient { + + /** + * @see SecurityGroupClient#get() + */ + @POST + @Path("/") + @XMLResponseParser(SecurityGroupHandler.class) + @FormParams(keys = "Action", values = "DescribeDBSecurityGroups") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture get(@FormParam("DBSecurityGroupName") String name); + + /** + * @see SecurityGroupClient#list() + */ + @POST + @Path("/") + @XMLResponseParser(DescribeDBSecurityGroupsResultHandler.class) + @FormParams(keys = "Action", values = "DescribeDBSecurityGroups") + ListenableFuture> list(); + + /** + * @see SecurityGroupClient#list(ListSecurityGroupsOptions) + */ + @POST + @Path("/") + @XMLResponseParser(DescribeDBSecurityGroupsResultHandler.class) + @FormParams(keys = "Action", values = "DescribeDBSecurityGroups") + ListenableFuture> list(ListSecurityGroupsOptions options); + + /** + * @see SecurityGroupClient#delete() + */ + @POST + @Path("/") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + @FormParams(keys = ACTION, values = "DeleteDBSecurityGroup") + ListenableFuture delete(@FormParam("DBSecurityGroupName") String name); +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/features/SecurityGroupClient.java b/labs/rds/src/main/java/org/jclouds/rds/features/SecurityGroupClient.java new file mode 100644 index 0000000000..699b7507f4 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/features/SecurityGroupClient.java @@ -0,0 +1,90 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.concurrent.Timeout; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.rds.domain.SecurityGroup; +import org.jclouds.rds.options.ListSecurityGroupsOptions; + +/** + * Provides access to Amazon RDS via the Query API + *

+ * + * @see doc + * @see SecurityGroupAsyncClient + * @author Adrian Cole + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface SecurityGroupClient { + + /** + * Retrieves information about the specified {@link SecurityGroup}. + * + * @param name + * Name of the security group to get information about. + * @return null if not found + */ + @Nullable + SecurityGroup get(String name); + + /** + * Returns a list of {@link SecurityGroup}s. + * + *
+ * You can paginate the results using the {@link ListSecurityGroupsOptions parameter} + * + * @param options + * the options describing the security groups query + * + * @return the response object + */ + PaginatedIterable list(ListSecurityGroupsOptions options); + + /** + * Returns a list of {@link SecurityGroup}s. + * + * @return the response object + */ + PaginatedIterable list(); + + /** + * Deletes a DB security group. + * + *

Naming Constraints

+ * + *
    + *
  • Must be 1 to 255 alphanumeric characters
  • + *
  • First character must be a letter
  • + *
  • Cannot end with a hyphen or contain two consecutive hyphens
  • + *
+ * + * @param name + * The name of the database security group to delete. + * + *

Note

+ * + * You cannot delete the default security group. + */ + void delete(String name); + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/features/SubnetGroupAsyncClient.java b/labs/rds/src/main/java/org/jclouds/rds/features/SubnetGroupAsyncClient.java new file mode 100644 index 0000000000..63a70023a6 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/features/SubnetGroupAsyncClient.java @@ -0,0 +1,92 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.features; + +import static org.jclouds.aws.reference.FormParameters.ACTION; + +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.aws.filters.FormSigner; +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.rds.domain.SubnetGroup; +import org.jclouds.rds.options.ListSubnetGroupsOptions; +import org.jclouds.rds.xml.DescribeDBSubnetGroupsResultHandler; +import org.jclouds.rds.xml.SubnetGroupHandler; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.FormParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides access to Amazon RDS via the Query API + *

+ * + * @see doc + * @see SubnetGroupClient + * @author Adrian Cole + */ +@RequestFilters(FormSigner.class) +@VirtualHost +public interface SubnetGroupAsyncClient { + + /** + * @see SubnetGroupClient#get() + */ + @POST + @Path("/") + @XMLResponseParser(SubnetGroupHandler.class) + @FormParams(keys = "Action", values = "DescribeDBSubnetGroups") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture get(@FormParam("DBSubnetGroupName") String name); + + /** + * @see SubnetGroupClient#list() + */ + @POST + @Path("/") + @XMLResponseParser(DescribeDBSubnetGroupsResultHandler.class) + @FormParams(keys = "Action", values = "DescribeDBSubnetGroups") + ListenableFuture> list(); + + /** + * @see SubnetGroupClient#list(ListSubnetGroupsOptions) + */ + @POST + @Path("/") + @XMLResponseParser(DescribeDBSubnetGroupsResultHandler.class) + @FormParams(keys = "Action", values = "DescribeDBSubnetGroups") + ListenableFuture> list(ListSubnetGroupsOptions options); + + /** + * @see SubnetGroupClient#delete() + */ + @POST + @Path("/") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + @FormParams(keys = ACTION, values = "DeleteDBSubnetGroup") + ListenableFuture delete(@FormParam("DBSubnetGroupName") String name); +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/features/SubnetGroupClient.java b/labs/rds/src/main/java/org/jclouds/rds/features/SubnetGroupClient.java new file mode 100644 index 0000000000..1960e6b9d5 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/features/SubnetGroupClient.java @@ -0,0 +1,92 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.concurrent.Timeout; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.rds.domain.SubnetGroup; +import org.jclouds.rds.options.ListSubnetGroupsOptions; + +/** + * Provides access to Amazon RDS via the Query API + *

+ * + * @see doc + * @see SubnetGroupAsyncClient + * @author Adrian Cole + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface SubnetGroupClient { + + /** + * Retrieves information about the specified {@link SubnetGroup}. + * + * @param name + * Name of the subnet group to get information about. + * @return null if not found + */ + @Nullable + SubnetGroup get(String name); + + /** + * Returns a list of {@link SubnetGroup}s. + * + *
+ * You can paginate the results using the {@link ListSubnetGroupsOptions parameter} + * + * @param options + * the options describing the subnet groups query + * + * @return the response object + */ + PaginatedIterable list(ListSubnetGroupsOptions options); + + /** + * Returns a list of {@link SubnetGroup}s. + * + * @return the response object + */ + PaginatedIterable list(); + + /** + * Deletes a DB subnet group. + * + *

Note

+ * + * The specified database subnet group must not be associated with any DB instances. + * + *

Note

+ * + * By design, if the SubnetGroup does not exist or has already been deleted, DeleteSubnetGroup + * still succeeds. + * + * + * @param name + * The name of the database subnet group to delete. + * + *

Note

+ * + * You cannot delete the default subnet group. + */ + void delete(String name); + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/options/ListInstancesOptions.java b/labs/rds/src/main/java/org/jclouds/rds/options/ListInstancesOptions.java new file mode 100644 index 0000000000..339cbc5ab0 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/options/ListInstancesOptions.java @@ -0,0 +1,143 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.options; + +import java.util.Set; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.google.common.base.Objects; +import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; + +/** + * Options used to list available instances. + * + * @see docs + * + * @author Adrian Cole + */ +public class ListInstancesOptions extends BaseHttpRequestOptions implements Cloneable { + + private Object marker; + private Set names = Sets.newLinkedHashSet(); + + /** + * Use this parameter only when paginating results, and only in a subsequent request after you've + * received a response where the results are truncated. Set it to the value of the Marker element + * in the response you just received. + */ + public ListInstancesOptions afterMarker(Object marker) { + this.marker = marker; + return this; + } + + /** + * list of names associated with the Instances at creation time. + */ + public ListInstancesOptions names(Set names) { + this.names = names; + return this; + } + + /** + * @see #names + */ + public ListInstancesOptions name(String name) { + this.names.add(name); + return this; + } + + public static class Builder { + + /** + * @see ListInstancesOptions#getMarker() + */ + public static ListInstancesOptions afterMarker(Object marker) { + return new ListInstancesOptions().afterMarker(marker); + } + + /** + * @see ListInstancesOptions#getNames() + */ + public static ListInstancesOptions name(String name) { + return new ListInstancesOptions().name(name); + } + + /** + * @see ListInstancesOptions#getNames() + */ + public static ListInstancesOptions names(Set names) { + return new ListInstancesOptions().names(names); + } + } + + @Override + public Multimap buildFormParameters() { + Multimap params = super.buildFormParameters(); + if (marker != null) + params.put("Marker", marker.toString()); + if (names.size() > 0) { + int nameIndex = 1; + for (String name : names) { + params.put("InstanceNames.member." + nameIndex, name); + nameIndex++; + } + } + return params; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(marker, names); + } + + @Override + public ListInstancesOptions clone() { + return new ListInstancesOptions().afterMarker(marker).names(names); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ListInstancesOptions other = ListInstancesOptions.class.cast(obj); + return Objects.equal(this.marker, other.marker) && Objects.equal(this.names, other.names); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("marker", marker).add("names", names).toString(); + } +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/options/ListSecurityGroupsOptions.java b/labs/rds/src/main/java/org/jclouds/rds/options/ListSecurityGroupsOptions.java new file mode 100644 index 0000000000..a1335602f7 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/options/ListSecurityGroupsOptions.java @@ -0,0 +1,102 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.google.common.base.Objects; +import com.google.common.collect.Multimap; + +/** + * Options used to list available instances. + * + * @see docs + * + * @author Adrian Cole + */ +public class ListSecurityGroupsOptions extends BaseHttpRequestOptions implements Cloneable { + + private Object marker; + + /** + * Use this parameter only when paginating results, and only in a subsequent request after you've + * received a response where the results are truncated. Set it to the value of the Marker element + * in the response you just received. + */ + public ListSecurityGroupsOptions afterMarker(Object marker) { + this.marker = marker; + return this; + } + + public static class Builder { + + /** + * @see ListSecurityGroupsOptions#getMarker() + */ + public static ListSecurityGroupsOptions afterMarker(Object marker) { + return new ListSecurityGroupsOptions().afterMarker(marker); + } + } + + @Override + public Multimap buildFormParameters() { + Multimap params = super.buildFormParameters(); + if (marker != null) + params.put("Marker", marker.toString()); + return params; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(marker); + } + + @Override + public ListSecurityGroupsOptions clone() { + return new ListSecurityGroupsOptions().afterMarker(marker); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ListSecurityGroupsOptions other = ListSecurityGroupsOptions.class.cast(obj); + return Objects.equal(this.marker, other.marker); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("marker", marker).toString(); + } +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/options/ListSubnetGroupsOptions.java b/labs/rds/src/main/java/org/jclouds/rds/options/ListSubnetGroupsOptions.java new file mode 100644 index 0000000000..3875bdc594 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/options/ListSubnetGroupsOptions.java @@ -0,0 +1,102 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.google.common.base.Objects; +import com.google.common.collect.Multimap; + +/** + * Options used to list available instances. + * + * @see docs + * + * @author Adrian Cole + */ +public class ListSubnetGroupsOptions extends BaseHttpRequestOptions implements Cloneable { + + private Object marker; + + /** + * Use this parameter only when paginating results, and only in a subsequent request after you've + * received a response where the results are truncated. Set it to the value of the Marker element + * in the response you just received. + */ + public ListSubnetGroupsOptions afterMarker(Object marker) { + this.marker = marker; + return this; + } + + public static class Builder { + + /** + * @see ListSubnetGroupsOptions#getMarker() + */ + public static ListSubnetGroupsOptions afterMarker(Object marker) { + return new ListSubnetGroupsOptions().afterMarker(marker); + } + } + + @Override + public Multimap buildFormParameters() { + Multimap params = super.buildFormParameters(); + if (marker != null) + params.put("Marker", marker.toString()); + return params; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(marker); + } + + @Override + public ListSubnetGroupsOptions clone() { + return new ListSubnetGroupsOptions().afterMarker(marker); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ListSubnetGroupsOptions other = ListSubnetGroupsOptions.class.cast(obj); + return Objects.equal(this.marker, other.marker); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("marker", marker).toString(); + } +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/xml/DescribeDBInstancesResultHandler.java b/labs/rds/src/main/java/org/jclouds/rds/xml/DescribeDBInstancesResultHandler.java new file mode 100644 index 0000000000..0fa702140e --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/xml/DescribeDBInstancesResultHandler.java @@ -0,0 +1,111 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import java.util.Set; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.collect.PaginatedIterables; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rds.domain.Instance; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.Sets; +import com.google.inject.Inject; + +/** + * @see docs + * + * @author Adrian Cole + */ +public class DescribeDBInstancesResultHandler extends + ParseSax.HandlerForGeneratedRequestWithResult> { + + private final InstanceHandler instanceHandler; + + private StringBuilder currentText = new StringBuilder(); + private Set instances = Sets.newLinkedHashSet(); + private boolean inInstances; + private String marker; + + protected int memberDepth; + + @Inject + public DescribeDBInstancesResultHandler(InstanceHandler instanceHandler) { + this.instanceHandler = instanceHandler; + } + + /** + * {@inheritDoc} + */ + @Override + public PaginatedIterable getResult() { + return PaginatedIterables.forwardWithMarker(instances, marker); + } + + /** + * {@inheritDoc} + */ + @Override + public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException { + if (equalsOrSuffix(qName, "DBInstances")) { + inInstances = true; + } + if (inInstances) { + instanceHandler.startElement(url, name, qName, attributes); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void endElement(String uri, String name, String qName) throws SAXException { + if (equalsOrSuffix(qName, "DBInstances")) { + inInstances = false; + } else if (equalsOrSuffix(qName, "DBInstance")) { + instances.add(instanceHandler.getResult()); + } else if (equalsOrSuffix(qName, "Marker")) { + marker = currentOrNull(currentText); + } else if (inInstances) { + instanceHandler.endElement(uri, name, qName); + } + + currentText = new StringBuilder(); + } + + /** + * {@inheritDoc} + */ + @Override + public void characters(char ch[], int start, int length) { + if (inInstances) { + instanceHandler.characters(ch, start, length); + } else { + currentText.append(ch, start, length); + } + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/xml/DescribeDBSecurityGroupsResultHandler.java b/labs/rds/src/main/java/org/jclouds/rds/xml/DescribeDBSecurityGroupsResultHandler.java new file mode 100644 index 0000000000..de8aa755d4 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/xml/DescribeDBSecurityGroupsResultHandler.java @@ -0,0 +1,107 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.collect.PaginatedIterables; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rds.domain.SecurityGroup; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; +import com.google.inject.Inject; + +/** + * @see docs + * + * @author Adrian Cole + */ +public class DescribeDBSecurityGroupsResultHandler extends + ParseSax.HandlerForGeneratedRequestWithResult> { + + private final SecurityGroupHandler securityGroupHander; + + private StringBuilder currentText = new StringBuilder(); + private Builder securityGroups = ImmutableSet. builder(); + private boolean inSecurityGroups; + private String marker; + + @Inject + public DescribeDBSecurityGroupsResultHandler(SecurityGroupHandler securityGroupHander) { + this.securityGroupHander = securityGroupHander; + } + + /** + * {@inheritDoc} + */ + @Override + public PaginatedIterable getResult() { + return PaginatedIterables.forwardWithMarker(securityGroups.build(), marker); + } + + /** + * {@inheritDoc} + */ + @Override + public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException { + if (equalsOrSuffix(qName, "DBSecurityGroups")) { + inSecurityGroups = true; + } + if (inSecurityGroups) { + securityGroupHander.startElement(url, name, qName, attributes); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void endElement(String uri, String name, String qName) throws SAXException { + if (equalsOrSuffix(qName, "DBSecurityGroups")) { + inSecurityGroups = false; + } else if (equalsOrSuffix(qName, "DBSecurityGroup")) { + securityGroups.add(securityGroupHander.getResult()); + } else if (equalsOrSuffix(qName, "Marker")) { + marker = currentOrNull(currentText); + } else if (inSecurityGroups) { + securityGroupHander.endElement(uri, name, qName); + } + currentText = new StringBuilder(); + } + + /** + * {@inheritDoc} + */ + @Override + public void characters(char ch[], int start, int length) { + if (inSecurityGroups) { + securityGroupHander.characters(ch, start, length); + } else { + currentText.append(ch, start, length); + } + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/xml/DescribeDBSubnetGroupsResultHandler.java b/labs/rds/src/main/java/org/jclouds/rds/xml/DescribeDBSubnetGroupsResultHandler.java new file mode 100644 index 0000000000..5862ea38f6 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/xml/DescribeDBSubnetGroupsResultHandler.java @@ -0,0 +1,107 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.collect.PaginatedIterables; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rds.domain.SubnetGroup; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; +import com.google.inject.Inject; + +/** + * @see docs + * + * @author Adrian Cole + */ +public class DescribeDBSubnetGroupsResultHandler extends + ParseSax.HandlerForGeneratedRequestWithResult> { + + private final SubnetGroupHandler subnetGroupHander; + + private StringBuilder currentText = new StringBuilder(); + private Builder subnetGroups = ImmutableSet. builder(); + private boolean inSubnetGroups; + private String marker; + + @Inject + public DescribeDBSubnetGroupsResultHandler(SubnetGroupHandler subnetGroupHander) { + this.subnetGroupHander = subnetGroupHander; + } + + /** + * {@inheritDoc} + */ + @Override + public PaginatedIterable getResult() { + return PaginatedIterables.forwardWithMarker(subnetGroups.build(), marker); + } + + /** + * {@inheritDoc} + */ + @Override + public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException { + if (equalsOrSuffix(qName, "DBSubnetGroups")) { + inSubnetGroups = true; + } + if (inSubnetGroups) { + subnetGroupHander.startElement(url, name, qName, attributes); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void endElement(String uri, String name, String qName) throws SAXException { + if (equalsOrSuffix(qName, "DBSubnetGroups")) { + inSubnetGroups = false; + } else if (equalsOrSuffix(qName, "DBSubnetGroup")) { + subnetGroups.add(subnetGroupHander.getResult()); + } else if (equalsOrSuffix(qName, "Marker")) { + marker = currentOrNull(currentText); + } else if (inSubnetGroups) { + subnetGroupHander.endElement(uri, name, qName); + } + currentText = new StringBuilder(); + } + + /** + * {@inheritDoc} + */ + @Override + public void characters(char ch[], int start, int length) { + if (inSubnetGroups) { + subnetGroupHander.characters(ch, start, length); + } else { + currentText.append(ch, start, length); + } + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/xml/EC2SecurityGroupHandler.java b/labs/rds/src/main/java/org/jclouds/rds/xml/EC2SecurityGroupHandler.java new file mode 100644 index 0000000000..84ce687fa6 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/xml/EC2SecurityGroupHandler.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import org.jclouds.rds.domain.EC2SecurityGroup; +import org.jclouds.http.functions.ParseSax; +import org.xml.sax.SAXException; + +/** + * @see xml + * + * @author Adrian Cole + */ +public class EC2SecurityGroupHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + + private StringBuilder currentText = new StringBuilder(); + private EC2SecurityGroup.Builder builder = EC2SecurityGroup.builder(); + + /** + * {@inheritDoc} + */ + @Override + public EC2SecurityGroup getResult() { + try { + return builder.build(); + } finally { + builder = EC2SecurityGroup.builder(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void endElement(String uri, String name, String qName) throws SAXException { + if (equalsOrSuffix(qName, "EC2SecurityGroupId")) { + builder.id(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "EC2SecurityGroupName")) { + builder.name(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "EC2SecurityGroupOwnerId")) { + builder.ownerId(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Status")) { + builder.status(currentOrNull(currentText)); + } + currentText = new StringBuilder(); + } + + /** + * {@inheritDoc} + */ + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/xml/IPRangeHandler.java b/labs/rds/src/main/java/org/jclouds/rds/xml/IPRangeHandler.java new file mode 100644 index 0000000000..bc52f65e9a --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/xml/IPRangeHandler.java @@ -0,0 +1,73 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import org.jclouds.rds.domain.IPRange; +import org.jclouds.http.functions.ParseSax; +import org.xml.sax.SAXException; + +/** + * @see xml + * + * @author Adrian Cole + */ +public class IPRangeHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + + private StringBuilder currentText = new StringBuilder(); + private IPRange.Builder builder = IPRange.builder(); + + /** + * {@inheritDoc} + */ + @Override + public IPRange getResult() { + try { + return builder.build(); + } finally { + builder = IPRange.builder(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void endElement(String uri, String name, String qName) throws SAXException { + if (equalsOrSuffix(qName, "CIDRIP")) { + builder.cidrIp(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Status")) { + builder.status(currentOrNull(currentText)); + } + currentText = new StringBuilder(); + } + + /** + * {@inheritDoc} + */ + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/xml/InstanceHandler.java b/labs/rds/src/main/java/org/jclouds/rds/xml/InstanceHandler.java new file mode 100644 index 0000000000..3a19ffc5d4 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/xml/InstanceHandler.java @@ -0,0 +1,160 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import javax.inject.Inject; + +import org.jclouds.date.DateService; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rds.domain.Instance; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableMap; +import com.google.common.net.HostAndPort; + +/** + * @see + * + * @author Adrian Cole + */ +public class InstanceHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + + protected final DateService dateService; + protected final SubnetGroupHandler subnetGroupHandler; + + @Inject + protected InstanceHandler(DateService dateService, SubnetGroupHandler subnetGroupHandler) { + this.dateService = dateService; + this.subnetGroupHandler = subnetGroupHandler; + } + + private StringBuilder currentText = new StringBuilder(); + private Instance.Builder builder = Instance.builder(); + + private boolean inSubnetGroup; + + private String address; + private Integer port; + + private ImmutableMap.Builder securityGroupBuilder = ImmutableMap. builder(); + + private String groupName; + private String status; + + /** + * {@inheritDoc} + */ + @Override + public Instance getResult() { + try { + return builder.build(); + } finally { + builder = Instance.builder(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException { + if (equalsOrSuffix(qName, "DBSubnetGroup")) { + inSubnetGroup = true; + } + if (inSubnetGroup) { + subnetGroupHandler.startElement(url, name, qName, attributes); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void endElement(String uri, String name, String qName) throws SAXException { + + if (equalsOrSuffix(qName, "SubnetGroup")) { + builder.subnetGroup(subnetGroupHandler.getResult()); + inSubnetGroup = false; + } else if (equalsOrSuffix(qName, "DBInstanceIdentifier")) { + builder.id(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "InstanceCreateTime")) { + builder.createdTime(dateService.iso8601DateParse(currentOrNull(currentText))); + } else if (equalsOrSuffix(qName, "DBName")) { + builder.name(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "AllocatedStorage")) { + builder.allocatedStorageGB(Integer.parseInt(currentOrNull(currentText))); + } else if (equalsOrSuffix(qName, "DBInstanceStatus")) { + builder.status(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Address")) { + address = currentOrNull(currentText); + } else if (equalsOrSuffix(qName, "Port")) { + port = new Integer(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Endpoint")) { + builder.endpoint(HostAndPort.fromParts(address, port)); + address = null; + port = null; + } else if (equalsOrSuffix(qName, "DBSecurityGroupName")) { + groupName = currentOrNull(currentText); + } else if (equalsOrSuffix(qName, "Status")) { + status = currentOrNull(currentText); + } else if (equalsOrSuffix(qName, "DBSecurityGroup")) { + securityGroupBuilder.put(groupName, status); + groupName = status = null; + } else if (equalsOrSuffix(qName, "DBSecurityGroups")) { + builder.securityGroupNameToStatus(securityGroupBuilder.build()); + securityGroupBuilder = ImmutableMap. builder(); + } else if (equalsOrSuffix(qName, "DBInstanceClass")) { + builder.instanceClass(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "AvailabilityZone")) { + builder.availabilityZone(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "MultiAZ")) { + builder.multiAZ(Boolean.parseBoolean(currentOrNull(currentText))); + } else if (equalsOrSuffix(qName, "Engine")) { + builder.engine(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "EngineVersion")) { + builder.engineVersion(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "LicenseModel")) { + builder.licenseModel(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "MasterUsername")) { + builder.masterUsername(currentOrNull(currentText)); + } else if (inSubnetGroup) { + subnetGroupHandler.endElement(uri, name, qName); + } + currentText = new StringBuilder(); + } + + /** + * {@inheritDoc} + */ + @Override + public void characters(char ch[], int start, int length) { + if (inSubnetGroup) { + subnetGroupHandler.characters(ch, start, length); + } else { + currentText.append(ch, start, length); + } + } + +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/xml/SecurityGroupHandler.java b/labs/rds/src/main/java/org/jclouds/rds/xml/SecurityGroupHandler.java new file mode 100644 index 0000000000..46e23e7e36 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/xml/SecurityGroupHandler.java @@ -0,0 +1,125 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import javax.inject.Inject; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rds.domain.SecurityGroup; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @see xml + * + * @author Adrian Cole + */ +public class SecurityGroupHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + protected final EC2SecurityGroupHandler ec2SecurityGroupHandler; + protected final IPRangeHandler ipRangeHandler; + + @Inject + protected SecurityGroupHandler(EC2SecurityGroupHandler ec2SecurityGroupHandler, IPRangeHandler ipRangeHandler) { + this.ec2SecurityGroupHandler = ec2SecurityGroupHandler; + this.ipRangeHandler = ipRangeHandler; + } + + private StringBuilder currentText = new StringBuilder(); + private SecurityGroup.Builder builder = SecurityGroup.builder(); + + private boolean inEC2SecurityGroups; + private boolean inIPRanges; + + /** + * {@inheritDoc} + */ + @Override + public SecurityGroup getResult() { + try { + return builder.build(); + } finally { + builder = SecurityGroup.builder(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException { + if (equalsOrSuffix(qName, "EC2SecurityGroups")) { + inEC2SecurityGroups = true; + } else if (equalsOrSuffix(qName, "IPRanges")) { + inIPRanges = true; + } + if (inEC2SecurityGroups) { + ec2SecurityGroupHandler.startElement(url, name, qName, attributes); + } else if (inIPRanges) { + ipRangeHandler.startElement(url, name, qName, attributes); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void endElement(String uri, String name, String qName) throws SAXException { + if (equalsOrSuffix(qName, "EC2SecurityGroups")) { + inEC2SecurityGroups = false; + } else if (equalsOrSuffix(qName, "IPRanges")) { + inIPRanges = false; + } else if (equalsOrSuffix(qName, "DBSecurityGroupName")) { + builder.name(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "DBSecurityGroupDescription")) { + builder.description(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "EC2SecurityGroup")) { + builder.ec2SecurityGroup(ec2SecurityGroupHandler.getResult()); + } else if (equalsOrSuffix(qName, "IPRange")) { + builder.ipRange(ipRangeHandler.getResult()); + } else if (equalsOrSuffix(qName, "OwnerId")) { + builder.ownerId(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "VpcId")) { + builder.vpcId(currentOrNull(currentText)); + } else if (inEC2SecurityGroups) { + ec2SecurityGroupHandler.endElement(uri, name, qName); + } else if (inIPRanges) { + ipRangeHandler.endElement(uri, name, qName); + } + currentText = new StringBuilder(); + } + + /** + * {@inheritDoc} + */ + @Override + public void characters(char ch[], int start, int length) { + if (inEC2SecurityGroups) { + ec2SecurityGroupHandler.characters(ch, start, length); + } else if (inIPRanges) { + ipRangeHandler.characters(ch, start, length); + } else { + currentText.append(ch, start, length); + } + } +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/xml/SubnetGroupHandler.java b/labs/rds/src/main/java/org/jclouds/rds/xml/SubnetGroupHandler.java new file mode 100644 index 0000000000..87e29b3498 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/xml/SubnetGroupHandler.java @@ -0,0 +1,110 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import javax.inject.Inject; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rds.domain.SubnetGroup; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @see xml + * + * @author Adrian Cole + */ +public class SubnetGroupHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + protected final SubnetHandler subnetHandler; + + @Inject + protected SubnetGroupHandler(SubnetHandler subnetHandler) { + this.subnetHandler = subnetHandler; + } + + private StringBuilder currentText = new StringBuilder(); + private SubnetGroup.Builder builder = SubnetGroup.builder(); + + private boolean inSubnets; + + /** + * {@inheritDoc} + */ + @Override + public SubnetGroup getResult() { + try { + return builder.build(); + } finally { + builder = SubnetGroup.builder(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException { + if (equalsOrSuffix(qName, "Subnets")) { + inSubnets = true; + } + if (inSubnets) { + subnetHandler.startElement(url, name, qName, attributes); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void endElement(String uri, String name, String qName) throws SAXException { + if (equalsOrSuffix(qName, "Subnets")) { + inSubnets = false; + } else if (equalsOrSuffix(qName, "DBSubnetGroupName")) { + builder.name(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "DBSubnetGroupDescription")) { + builder.description(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "SubnetGroupStatus")) { + builder.status(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Subnet")) { + builder.subnet(subnetHandler.getResult()); + } else if (equalsOrSuffix(qName, "VpcId")) { + builder.vpcId(currentOrNull(currentText)); + } else if (inSubnets) { + subnetHandler.endElement(uri, name, qName); + } + currentText = new StringBuilder(); + } + + /** + * {@inheritDoc} + */ + @Override + public void characters(char ch[], int start, int length) { + if (inSubnets) { + subnetHandler.characters(ch, start, length); + } else { + currentText.append(ch, start, length); + } + } +} diff --git a/labs/rds/src/main/java/org/jclouds/rds/xml/SubnetHandler.java b/labs/rds/src/main/java/org/jclouds/rds/xml/SubnetHandler.java new file mode 100644 index 0000000000..2846fde0b3 --- /dev/null +++ b/labs/rds/src/main/java/org/jclouds/rds/xml/SubnetHandler.java @@ -0,0 +1,75 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import org.jclouds.rds.domain.Subnet; +import org.jclouds.http.functions.ParseSax; +import org.xml.sax.SAXException; + +/** + * @see xml + * + * @author Adrian Cole + */ +public class SubnetHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + + private StringBuilder currentText = new StringBuilder(); + private Subnet.Builder builder = Subnet.builder(); + + /** + * {@inheritDoc} + */ + @Override + public Subnet getResult() { + try { + return builder.build(); + } finally { + builder = Subnet.builder(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void endElement(String uri, String name, String qName) throws SAXException { + if (equalsOrSuffix(qName, "SubnetIdentifier")) { + builder.id(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Name")) { + builder.availabilityZone(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "SubnetStatus")) { + builder.status(currentOrNull(currentText)); + } + currentText = new StringBuilder(); + } + + /** + * {@inheritDoc} + */ + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} diff --git a/labs/rds/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/labs/rds/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata new file mode 100644 index 0000000000..b74808af17 --- /dev/null +++ b/labs/rds/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata @@ -0,0 +1 @@ +org.jclouds.rds.RDSApiMetadata \ No newline at end of file diff --git a/labs/rds/src/test/java/org/jclouds/rds/RDSApiMetadataTest.java b/labs/rds/src/test/java/org/jclouds/rds/RDSApiMetadataTest.java new file mode 100644 index 0000000000..c37b1b8daf --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/RDSApiMetadataTest.java @@ -0,0 +1,39 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds; + +import org.jclouds.View; +import org.jclouds.rest.internal.BaseRestApiMetadataTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "RDSApiMetadataTest") +public class RDSApiMetadataTest extends BaseRestApiMetadataTest { + + // no database abstraction, yet + public RDSApiMetadataTest() { + super(new RDSApiMetadata(), ImmutableSet.> of()); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/RDSTest.java b/labs/rds/src/test/java/org/jclouds/rds/RDSTest.java new file mode 100644 index 0000000000..75cc251f7b --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/RDSTest.java @@ -0,0 +1,124 @@ +package org.jclouds.rds; + +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; + +import org.easymock.EasyMock; +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.collect.PaginatedIterables; +import org.jclouds.rds.domain.Instance; +import org.jclouds.rds.domain.SecurityGroup; +import org.jclouds.rds.domain.SubnetGroup; +import org.jclouds.rds.features.InstanceClient; +import org.jclouds.rds.features.SecurityGroupClient; +import org.jclouds.rds.features.SubnetGroupClient; +import org.jclouds.rds.options.ListInstancesOptions; +import org.jclouds.rds.options.ListSecurityGroupsOptions; +import org.jclouds.rds.options.ListSubnetGroupsOptions; +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; + +/** + * Tests behavior of {@code RDS}. + * + * @author Adrian Cole + */ +@Test(testName = "RDSTest") +public class RDSTest { + + @Test + public void testSinglePageResultInstance() throws Exception { + InstanceClient instanceClient = createMock(InstanceClient.class); + ListInstancesOptions options = new ListInstancesOptions(); + PaginatedIterable response = PaginatedIterables.forward(ImmutableSet.of(createMock(Instance.class))); + + expect(instanceClient.list(options)).andReturn(response).once(); + + EasyMock.replay(instanceClient); + + Assert.assertEquals(1, Iterables.size(RDS.listInstances(instanceClient, options))); + } + + @Test + public void testMultiPageResultInstance() throws Exception { + InstanceClient instanceClient = createMock(InstanceClient.class); + ListInstancesOptions options = new ListInstancesOptions(); + PaginatedIterable response1 = PaginatedIterables.forwardWithMarker( + ImmutableSet.of(createMock(Instance.class)), "NEXTTOKEN"); + PaginatedIterable response2 = PaginatedIterables.forward(ImmutableSet.of(createMock(Instance.class))); + + expect(instanceClient.list(anyObject(ListInstancesOptions.class))).andReturn(response1).once(); + expect(instanceClient.list(anyObject(ListInstancesOptions.class))).andReturn(response2).once(); + + EasyMock.replay(instanceClient); + + Assert.assertEquals(2, Iterables.size(RDS.listInstances(instanceClient, options))); + } + + @Test + public void testSinglePageResultSubnetGroup() throws Exception { + SubnetGroupClient subnetGroupClient = createMock(SubnetGroupClient.class); + ListSubnetGroupsOptions options = new ListSubnetGroupsOptions(); + PaginatedIterable response = PaginatedIterables.forward(ImmutableSet + .of(createMock(SubnetGroup.class))); + + expect(subnetGroupClient.list(options)).andReturn(response).once(); + + EasyMock.replay(subnetGroupClient); + + Assert.assertEquals(1, Iterables.size(RDS.listSubnetGroups(subnetGroupClient, options))); + } + + @Test + public void testMultiPageResultSubnetGroup() throws Exception { + SubnetGroupClient subnetGroupClient = createMock(SubnetGroupClient.class); + ListSubnetGroupsOptions options = new ListSubnetGroupsOptions(); + PaginatedIterable response1 = PaginatedIterables.forwardWithMarker( + ImmutableSet.of(createMock(SubnetGroup.class)), "NEXTTOKEN"); + PaginatedIterable response2 = PaginatedIterables.forward(ImmutableSet + .of(createMock(SubnetGroup.class))); + + expect(subnetGroupClient.list(anyObject(ListSubnetGroupsOptions.class))).andReturn(response1).once(); + expect(subnetGroupClient.list(anyObject(ListSubnetGroupsOptions.class))).andReturn(response2).once(); + + EasyMock.replay(subnetGroupClient); + + Assert.assertEquals(2, Iterables.size(RDS.listSubnetGroups(subnetGroupClient, options))); + } + + @Test + public void testSinglePageResultSecurityGroup() throws Exception { + SecurityGroupClient securityGroupClient = createMock(SecurityGroupClient.class); + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions(); + PaginatedIterable response = PaginatedIterables.forward(ImmutableSet + .of(createMock(SecurityGroup.class))); + + expect(securityGroupClient.list(options)).andReturn(response).once(); + + EasyMock.replay(securityGroupClient); + + Assert.assertEquals(1, Iterables.size(RDS.listSecurityGroups(securityGroupClient, options))); + } + + @Test + public void testMultiPageResultSecurityGroup() throws Exception { + SecurityGroupClient securityGroupClient = createMock(SecurityGroupClient.class); + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions(); + PaginatedIterable response1 = PaginatedIterables.forwardWithMarker( + ImmutableSet.of(createMock(SecurityGroup.class)), "NEXTTOKEN"); + PaginatedIterable response2 = PaginatedIterables.forward(ImmutableSet + .of(createMock(SecurityGroup.class))); + + expect(securityGroupClient.list(anyObject(ListSecurityGroupsOptions.class))).andReturn(response1).once(); + expect(securityGroupClient.list(anyObject(ListSecurityGroupsOptions.class))).andReturn(response2).once(); + + EasyMock.replay(securityGroupClient); + + Assert.assertEquals(2, Iterables.size(RDS.listSecurityGroups(securityGroupClient, options))); + } + +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/features/InstanceClientExpectTest.java b/labs/rds/src/test/java/org/jclouds/rds/features/InstanceClientExpectTest.java new file mode 100644 index 0000000000..ba3922ba5b --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/features/InstanceClientExpectTest.java @@ -0,0 +1,197 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unles required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either expres or implied. See the License for the + * specific language governing permisions and limitations + * under the License. + */ +package org.jclouds.rds.features; + +import static org.jclouds.rds.options.ListInstancesOptions.Builder.afterMarker; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.net.URI; +import java.util.TimeZone; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.rds.RDSClient; +import org.jclouds.rds.internal.BaseRDSClientExpectTest; +import org.jclouds.rds.parse.DescribeDBInstancesResponseTest; +import org.jclouds.rds.parse.GetInstanceResponseTest; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMultimap; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "InstanceClientExpectTest") +public class InstanceClientExpectTest extends BaseRDSClientExpectTest { + + public InstanceClientExpectTest() { + TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); + } + + HttpRequest get = HttpRequest.builder() + .method("POST") + .endpoint(URI.create("https://rds.us-east-1.amazonaws.com/")) + .headers(ImmutableMultimap. builder() + .put("Host", "rds.us-east-1.amazonaws.com") + .build()) + .payload( + payloadFromStringWithContentType( + "Action=DescribeDBInstances" + + "&DBInstanceIdentifier=id" + + "&Signature=jcvzapwazR2OuWnMILEt48ycu226NOn2AuEBKSxV2O0%3D" + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=2009-11-08T15%3A54%3A08.897Z" + + "&Version=2012-04-23" + + "&AWSAccessKeyId=identity", + "application/x-www-form-urlencoded")) + .build(); + + + public void testGetWhenResponseIs2xx() throws Exception { + + HttpResponse getResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/get_instance.xml", "text/xml")).build(); + + RDSClient clientWhenExist = requestSendsResponse( + get, getResponse); + + assertEquals(clientWhenExist.getInstanceClient().get("id").toString(), new GetInstanceResponseTest().expected().toString()); + } + + public void testGetWhenResponseIs404() throws Exception { + + HttpResponse getResponse = HttpResponse.builder().statusCode(404).build(); + + RDSClient clientWhenDontExist = requestSendsResponse( + get, getResponse); + + assertNull(clientWhenDontExist.getInstanceClient().get("id")); + } + + HttpRequest list = HttpRequest.builder() + .method("POST") + .endpoint(URI.create("https://rds.us-east-1.amazonaws.com/")) + .headers(ImmutableMultimap. builder() + .put("Host", "rds.us-east-1.amazonaws.com") + .build()) + .payload( + payloadFromStringWithContentType( + "Action=DescribeDBInstances" + + "&Signature=SnClCujZG9Sq9sMdf59xZWsjQxIbMOp5YEF%2FFBsurf4%3D" + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=2009-11-08T15%3A54%3A08.897Z" + + "&Version=2012-04-23" + + "&AWSAccessKeyId=identity", + "application/x-www-form-urlencoded")) + .build(); + + public void testListWhenResponseIs2xx() throws Exception { + + HttpResponse listResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/describe_instances.xml", "text/xml")).build(); + + RDSClient clientWhenExist = requestSendsResponse( + list, listResponse); + + assertEquals(clientWhenExist.getInstanceClient().list().toString(), new DescribeDBInstancesResponseTest().expected().toString()); + } + + // TODO: this should really be an empty set + @Test(expectedExceptions = ResourceNotFoundException.class) + public void testListWhenResponseIs404() throws Exception { + + HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); + + RDSClient clientWhenDontExist = requestSendsResponse( + list, listResponse); + + clientWhenDontExist.getInstanceClient().list(); + } + + public void testListWithOptionsWhenResponseIs2xx() throws Exception { + HttpRequest listWithOptions = + HttpRequest.builder() + .method("POST") + .endpoint(URI.create("https://rds.us-east-1.amazonaws.com/")) + .headers(ImmutableMultimap.builder() + .put("Host", "rds.us-east-1.amazonaws.com") + .build()) + .payload(payloadFromStringWithContentType( + "Action=DescribeDBInstances" + + "&Marker=MARKER" + + "&Signature=TFW8vaU2IppmBey0ZHttbWz4rMFh%2F5ACWl6Xyt58sQU%3D" + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=2009-11-08T15%3A54%3A08.897Z" + + "&Version=2012-04-23" + + "&AWSAccessKeyId=identity", + "application/x-www-form-urlencoded")) + .build(); + + HttpResponse listWithOptionsResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/describe_instances.xml", "text/xml")).build(); + + RDSClient clientWhenWithOptionsExist = requestSendsResponse(listWithOptions, + listWithOptionsResponse); + + assertEquals(clientWhenWithOptionsExist.getInstanceClient().list(afterMarker("MARKER")).toString(), + new DescribeDBInstancesResponseTest().expected().toString()); + } + + HttpRequest delete = HttpRequest.builder() + .method("POST") + .endpoint(URI.create("https://rds.us-east-1.amazonaws.com/")) + .headers(ImmutableMultimap. builder() + .put("Host", "rds.us-east-1.amazonaws.com") + .build()) + .payload( + payloadFromStringWithContentType( + "Action=DeleteDBInstance" + + "&DBInstanceIdentifier=id" + + "&Signature=3UFxv5zaG%2B3dZRAhinJZ10De0LAxkJtr3Nb6kfspC7w%3D" + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=2009-11-08T15%3A54%3A08.897Z" + + "&Version=2012-04-23" + + "&AWSAccessKeyId=identity", + "application/x-www-form-urlencoded")) + .build(); + + public void testDeleteWhenResponseIs2xx() throws Exception { + + HttpResponse deleteResponse = HttpResponse.builder().statusCode(200).build(); + + RDSClient clientWhenExist = requestSendsResponse(delete, deleteResponse); + + clientWhenExist.getInstanceClient().delete("id"); + } + + public void testDeleteWhenResponseIs404() throws Exception { + + HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); + + RDSClient clientWhenDontExist = requestSendsResponse(delete, deleteResponse); + + clientWhenDontExist.getInstanceClient().delete("id"); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/features/InstanceClientLiveTest.java b/labs/rds/src/test/java/org/jclouds/rds/features/InstanceClientLiveTest.java new file mode 100644 index 0000000000..eaa7ac0746 --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/features/InstanceClientLiveTest.java @@ -0,0 +1,73 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.features; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.rds.domain.Instance; +import org.jclouds.rds.internal.BaseRDSClientLiveTest; +import org.jclouds.rds.options.ListInstancesOptions; +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * @author Adrian Cole + */ +@Test(groups = "live", testName = "InstanceClientLiveTest") +public class InstanceClientLiveTest extends BaseRDSClientLiveTest { + + private void checkInstance(Instance instance) { + checkNotNull(instance.getId(), "Id cannot be null for a Instance: %s", instance); + checkNotNull(instance.getCreatedTime(), "CreatedTime cannot be null for a Instance: %s", instance); + checkNotNull(instance.getName(), "While Name can be null for a Instance, its Optional wrapper cannot: %s", + instance); + checkNotNull(instance.getSubnetGroup(), + "While SubnetGroup can be null for a Instance, its Optional wrapper cannot: %s", instance); + // TODO: other checks + if (instance.getSubnetGroup().isPresent()) + SubnetGroupClientLiveTest.checkSubnetGroup(instance.getSubnetGroup().get()); + } + + @Test + protected void testDescribeInstances() { + PaginatedIterable response = client().list(); + + for (Instance instance : response) { + checkInstance(instance); + } + + if (Iterables.size(response) > 0) { + Instance instance = response.iterator().next(); + Assert.assertEquals(client().get(instance.getId()), instance); + } + + // Test with a Marker, even if it's null + response = client().list(ListInstancesOptions.Builder.afterMarker(response.getNextMarker())); + for (Instance instance : response) { + checkInstance(instance); + } + } + + protected InstanceClient client() { + return context.getApi().getInstanceClient(); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/features/SecurityGroupClientExpectTest.java b/labs/rds/src/test/java/org/jclouds/rds/features/SecurityGroupClientExpectTest.java new file mode 100644 index 0000000000..3773a0e016 --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/features/SecurityGroupClientExpectTest.java @@ -0,0 +1,197 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unles required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either expres or implied. See the License for the + * specific language governing permisions and limitations + * under the License. + */ +package org.jclouds.rds.features; + +import static org.jclouds.rds.options.ListSecurityGroupsOptions.Builder.afterMarker; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.net.URI; +import java.util.TimeZone; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.rds.RDSClient; +import org.jclouds.rds.internal.BaseRDSClientExpectTest; +import org.jclouds.rds.parse.DescribeDBSecurityGroupsResponseTest; +import org.jclouds.rds.parse.GetSecurityGroupResponseTest; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMultimap; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "SecurityGroupClientExpectTest") +public class SecurityGroupClientExpectTest extends BaseRDSClientExpectTest { + + public SecurityGroupClientExpectTest() { + TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); + } + + HttpRequest get = HttpRequest.builder() + .method("POST") + .endpoint(URI.create("https://rds.us-east-1.amazonaws.com/")) + .headers(ImmutableMultimap. builder() + .put("Host", "rds.us-east-1.amazonaws.com") + .build()) + .payload( + payloadFromStringWithContentType( + "Action=DescribeDBSecurityGroups" + + "&DBSecurityGroupName=name" + + "&Signature=F019%2B74qM%2FivsW6ngZWfILFBss4RqPGlppawtAjwUPg%3D" + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=2009-11-08T15%3A54%3A08.897Z" + + "&Version=2012-04-23" + + "&AWSAccessKeyId=identity", + "application/x-www-form-urlencoded")) + .build(); + + + public void testGetWhenResponseIs2xx() throws Exception { + + HttpResponse getResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/get_securitygroup.xml", "text/xml")).build(); + + RDSClient clientWhenExist = requestSendsResponse( + get, getResponse); + + assertEquals(clientWhenExist.getSecurityGroupClient().get("name").toString(), new GetSecurityGroupResponseTest().expected().toString()); + } + + public void testGetWhenResponseIs404() throws Exception { + + HttpResponse getResponse = HttpResponse.builder().statusCode(404).build(); + + RDSClient clientWhenDontExist = requestSendsResponse( + get, getResponse); + + assertNull(clientWhenDontExist.getSecurityGroupClient().get("name")); + } + + HttpRequest list = HttpRequest.builder() + .method("POST") + .endpoint(URI.create("https://rds.us-east-1.amazonaws.com/")) + .headers(ImmutableMultimap. builder() + .put("Host", "rds.us-east-1.amazonaws.com") + .build()) + .payload( + payloadFromStringWithContentType( + "Action=DescribeDBSecurityGroups" + + "&Signature=6PMtOHuBCxE%2FuujPnvn%2FnN8NIZrwcx9X0Jy6hz%2FRXtg%3D" + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=2009-11-08T15%3A54%3A08.897Z" + + "&Version=2012-04-23" + + "&AWSAccessKeyId=identity", + "application/x-www-form-urlencoded")) + .build(); + + public void testListWhenResponseIs2xx() throws Exception { + + HttpResponse listResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/describe_securitygroups.xml", "text/xml")).build(); + + RDSClient clientWhenExist = requestSendsResponse( + list, listResponse); + + assertEquals(clientWhenExist.getSecurityGroupClient().list().toString(), new DescribeDBSecurityGroupsResponseTest().expected().toString()); + } + + // TODO: this should really be an empty set + @Test(expectedExceptions = ResourceNotFoundException.class) + public void testListWhenResponseIs404() throws Exception { + + HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); + + RDSClient clientWhenDontExist = requestSendsResponse( + list, listResponse); + + clientWhenDontExist.getSecurityGroupClient().list(); + } + + public void testListWithOptionsWhenResponseIs2xx() throws Exception { + HttpRequest listWithOptions = + HttpRequest.builder() + .method("POST") + .endpoint(URI.create("https://rds.us-east-1.amazonaws.com/")) + .headers(ImmutableMultimap.builder() + .put("Host", "rds.us-east-1.amazonaws.com") + .build()) + .payload(payloadFromStringWithContentType( + "Action=DescribeDBSecurityGroups" + + "&Marker=MARKER" + + "&Signature=DeZcA5ViQu%2FbB3PY9EmRZavRgYxLFMvdbq7topMKKhw%3D" + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=2009-11-08T15%3A54%3A08.897Z" + + "&Version=2012-04-23" + + "&AWSAccessKeyId=identity", + "application/x-www-form-urlencoded")) + .build(); + + HttpResponse listWithOptionsResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/describe_securitygroups.xml", "text/xml")).build(); + + RDSClient clientWhenWithOptionsExist = requestSendsResponse(listWithOptions, + listWithOptionsResponse); + + assertEquals(clientWhenWithOptionsExist.getSecurityGroupClient().list(afterMarker("MARKER")).toString(), + new DescribeDBSecurityGroupsResponseTest().expected().toString()); + } + + HttpRequest delete = HttpRequest.builder() + .method("POST") + .endpoint(URI.create("https://rds.us-east-1.amazonaws.com/")) + .headers(ImmutableMultimap. builder() + .put("Host", "rds.us-east-1.amazonaws.com") + .build()) + .payload( + payloadFromStringWithContentType( + "Action=DeleteDBSecurityGroup" + + "&DBSecurityGroupName=name" + + "&Signature=7lQqK7wJUuc7nONYnXdHVibudxqnfJPFrfdnzwEEKxE%3D" + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=2009-11-08T15%3A54%3A08.897Z" + + "&Version=2012-04-23" + + "&AWSAccessKeyId=identity", + "application/x-www-form-urlencoded")) + .build(); + + public void testDeleteWhenResponseIs2xx() throws Exception { + + HttpResponse deleteResponse = HttpResponse.builder().statusCode(200).build(); + + RDSClient clientWhenExist = requestSendsResponse(delete, deleteResponse); + + clientWhenExist.getSecurityGroupClient().delete("name"); + } + + public void testDeleteWhenResponseIs404() throws Exception { + + HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); + + RDSClient clientWhenDontExist = requestSendsResponse(delete, deleteResponse); + + clientWhenDontExist.getSecurityGroupClient().delete("name"); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/features/SecurityGroupClientLiveTest.java b/labs/rds/src/test/java/org/jclouds/rds/features/SecurityGroupClientLiveTest.java new file mode 100644 index 0000000000..3a4c3c5ea5 --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/features/SecurityGroupClientLiveTest.java @@ -0,0 +1,79 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.features; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.rds.domain.EC2SecurityGroup; +import org.jclouds.rds.domain.SecurityGroup; +import org.jclouds.rds.internal.BaseRDSClientLiveTest; +import org.jclouds.rds.options.ListSecurityGroupsOptions; +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * @author Adrian Cole + */ +@Test(groups = "live", testName = "SecurityGroupClientLiveTest") +public class SecurityGroupClientLiveTest extends BaseRDSClientLiveTest { + + static void checkSecurityGroup(SecurityGroup securityGroup) { + checkNotNull(securityGroup.getName(), "Name cannot be null for a SecurityGroup: %s", securityGroup); + checkNotNull(securityGroup.getDescription(), "Description cannot be null for a SecurityGroup: %s", securityGroup); + checkNotNull(securityGroup.getOwnerId(), "OwnerId cannot be null for a SecurityGroup: %s", securityGroup); + checkNotNull(securityGroup.getVpcId(), "VpcId cannot be null for a SecurityGroup: %s", securityGroup); + for (EC2SecurityGroup security : securityGroup.getEC2SecurityGroups()) { + checkEC2SecurityGroup(security); + } + } + + static void checkEC2SecurityGroup(EC2SecurityGroup security) { + checkNotNull(security.getId(), "Id can be null for a SecurityGroup, but its Optional Wrapper cannot: %s", security); + checkNotNull(security.getStatus(), "Status cannot be null for a SecurityGroup: %s", security); + checkNotNull(security.getName(), "Name cannot be null for a SecurityGroup: %s", security); + checkNotNull(security.getOwnerId(), "Name cannot be null for a SecurityGroup: %s", security); + } + + @Test + protected void testDescribeSecurityGroups() { + PaginatedIterable response = client().list(); + + for (SecurityGroup securityGroup : response) { + checkSecurityGroup(securityGroup); + } + + if (Iterables.size(response) > 0) { + SecurityGroup securityGroup = response.iterator().next(); + Assert.assertEquals(client().get(securityGroup.getName()), securityGroup); + } + + // Test with a Marker, even if it's null + response = client().list(ListSecurityGroupsOptions.Builder.afterMarker(response.getNextMarker())); + for (SecurityGroup securityGroup : response) { + checkSecurityGroup(securityGroup); + } + } + + protected SecurityGroupClient client() { + return context.getApi().getSecurityGroupClient(); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/features/SubnetGroupClientExpectTest.java b/labs/rds/src/test/java/org/jclouds/rds/features/SubnetGroupClientExpectTest.java new file mode 100644 index 0000000000..adc59cd137 --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/features/SubnetGroupClientExpectTest.java @@ -0,0 +1,197 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unles required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either expres or implied. See the License for the + * specific language governing permisions and limitations + * under the License. + */ +package org.jclouds.rds.features; + +import static org.jclouds.rds.options.ListSubnetGroupsOptions.Builder.afterMarker; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.net.URI; +import java.util.TimeZone; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.rds.RDSClient; +import org.jclouds.rds.internal.BaseRDSClientExpectTest; +import org.jclouds.rds.parse.DescribeDBSubnetGroupsResponseTest; +import org.jclouds.rds.parse.GetSubnetGroupResponseTest; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMultimap; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "SubnetGroupClientExpectTest") +public class SubnetGroupClientExpectTest extends BaseRDSClientExpectTest { + + public SubnetGroupClientExpectTest() { + TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); + } + + HttpRequest get = HttpRequest.builder() + .method("POST") + .endpoint(URI.create("https://rds.us-east-1.amazonaws.com/")) + .headers(ImmutableMultimap. builder() + .put("Host", "rds.us-east-1.amazonaws.com") + .build()) + .payload( + payloadFromStringWithContentType( + "Action=DescribeDBSubnetGroups" + + "&DBSubnetGroupName=name" + + "&Signature=U7DwaG%2BDARTb1iQxztQN%2BBe042ywyD7wxEVUlm4%2FA20%3D" + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=2009-11-08T15%3A54%3A08.897Z" + + "&Version=2012-04-23" + + "&AWSAccessKeyId=identity", + "application/x-www-form-urlencoded")) + .build(); + + + public void testGetWhenResponseIs2xx() throws Exception { + + HttpResponse getResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/get_subnetgroup.xml", "text/xml")).build(); + + RDSClient clientWhenExist = requestSendsResponse( + get, getResponse); + + assertEquals(clientWhenExist.getSubnetGroupClient().get("name").toString(), new GetSubnetGroupResponseTest().expected().toString()); + } + + public void testGetWhenResponseIs404() throws Exception { + + HttpResponse getResponse = HttpResponse.builder().statusCode(404).build(); + + RDSClient clientWhenDontExist = requestSendsResponse( + get, getResponse); + + assertNull(clientWhenDontExist.getSubnetGroupClient().get("name")); + } + + HttpRequest list = HttpRequest.builder() + .method("POST") + .endpoint(URI.create("https://rds.us-east-1.amazonaws.com/")) + .headers(ImmutableMultimap. builder() + .put("Host", "rds.us-east-1.amazonaws.com") + .build()) + .payload( + payloadFromStringWithContentType( + "Action=DescribeDBSubnetGroups" + + "&Signature=KLYL7jWGWT2ItwBv2z0ZNAFv1KAnPwNUhVqTHm0nWcI%3D" + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=2009-11-08T15%3A54%3A08.897Z" + + "&Version=2012-04-23" + + "&AWSAccessKeyId=identity", + "application/x-www-form-urlencoded")) + .build(); + + public void testListWhenResponseIs2xx() throws Exception { + + HttpResponse listResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/describe_subnetgroups.xml", "text/xml")).build(); + + RDSClient clientWhenExist = requestSendsResponse( + list, listResponse); + + assertEquals(clientWhenExist.getSubnetGroupClient().list().toString(), new DescribeDBSubnetGroupsResponseTest().expected().toString()); + } + + // TODO: this should really be an empty set + @Test(expectedExceptions = ResourceNotFoundException.class) + public void testListWhenResponseIs404() throws Exception { + + HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); + + RDSClient clientWhenDontExist = requestSendsResponse( + list, listResponse); + + clientWhenDontExist.getSubnetGroupClient().list(); + } + + public void testListWithOptionsWhenResponseIs2xx() throws Exception { + HttpRequest listWithOptions = + HttpRequest.builder() + .method("POST") + .endpoint(URI.create("https://rds.us-east-1.amazonaws.com/")) + .headers(ImmutableMultimap.builder() + .put("Host", "rds.us-east-1.amazonaws.com") + .build()) + .payload(payloadFromStringWithContentType( + "Action=DescribeDBSubnetGroups" + + "&Marker=MARKER" + + "&Signature=1yK3VgSfUKDNHEwicyYbnMvSPAeJ7DZvi52gQeUUFSQ%3D" + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=2009-11-08T15%3A54%3A08.897Z" + + "&Version=2012-04-23" + + "&AWSAccessKeyId=identity", + "application/x-www-form-urlencoded")) + .build(); + + HttpResponse listWithOptionsResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/describe_subnetgroups.xml", "text/xml")).build(); + + RDSClient clientWhenWithOptionsExist = requestSendsResponse(listWithOptions, + listWithOptionsResponse); + + assertEquals(clientWhenWithOptionsExist.getSubnetGroupClient().list(afterMarker("MARKER")).toString(), + new DescribeDBSubnetGroupsResponseTest().expected().toString()); + } + + HttpRequest delete = HttpRequest.builder() + .method("POST") + .endpoint(URI.create("https://rds.us-east-1.amazonaws.com/")) + .headers(ImmutableMultimap. builder() + .put("Host", "rds.us-east-1.amazonaws.com") + .build()) + .payload( + payloadFromStringWithContentType( + "Action=DeleteDBSubnetGroup" + + "&DBSubnetGroupName=name" + + "&Signature=BbT14zD9UyRQzelQYzg%2F0FVcX%2Fs46ZyRtyxsdylOw7o%3D" + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=2009-11-08T15%3A54%3A08.897Z" + + "&Version=2012-04-23" + + "&AWSAccessKeyId=identity", + "application/x-www-form-urlencoded")) + .build(); + + public void testDeleteWhenResponseIs2xx() throws Exception { + + HttpResponse deleteResponse = HttpResponse.builder().statusCode(200).build(); + + RDSClient clientWhenExist = requestSendsResponse(delete, deleteResponse); + + clientWhenExist.getSubnetGroupClient().delete("name"); + } + + public void testDeleteWhenResponseIs404() throws Exception { + + HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); + + RDSClient clientWhenDontExist = requestSendsResponse(delete, deleteResponse); + + clientWhenDontExist.getSubnetGroupClient().delete("name"); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/features/SubnetGroupClientLiveTest.java b/labs/rds/src/test/java/org/jclouds/rds/features/SubnetGroupClientLiveTest.java new file mode 100644 index 0000000000..ef7bc993e9 --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/features/SubnetGroupClientLiveTest.java @@ -0,0 +1,79 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.features; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.rds.domain.Subnet; +import org.jclouds.rds.domain.SubnetGroup; +import org.jclouds.rds.internal.BaseRDSClientLiveTest; +import org.jclouds.rds.options.ListSubnetGroupsOptions; +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * @author Adrian Cole + */ +@Test(groups = "live", testName = "SubnetGroupClientLiveTest") +public class SubnetGroupClientLiveTest extends BaseRDSClientLiveTest { + + static void checkSubnetGroup(SubnetGroup subnetGroup) { + checkNotNull(subnetGroup.getName(), "Name cannot be null for a SubnetGroup: %s", subnetGroup); + checkNotNull(subnetGroup.getDescription(), "Description cannot be null for a SubnetGroup: %s", subnetGroup); + checkNotNull(subnetGroup.getStatus(), "Status cannot be null for a SubnetGroup: %s", subnetGroup); + checkState(subnetGroup.getSubnets().size() > 0, "Subnets must have at least one one: %s", subnetGroup); + for (Subnet subnet : subnetGroup.getSubnets()) { + checkSubnet(subnet); + } + } + + static void checkSubnet(Subnet subnet) { + checkNotNull(subnet.getId(), "Id cannot be null for a SubnetGroup: %s", subnet); + checkNotNull(subnet.getStatus(), "Status cannot be null for a SubnetGroup: %s", subnet); + checkNotNull(subnet.getAvailabilityZone(), "AvailabilityZone cannot be null for a SubnetGroup: %s", subnet); + } + + @Test + protected void testDescribeSubnetGroups() { + PaginatedIterable response = client().list(); + + for (SubnetGroup subnetGroup : response) { + checkSubnetGroup(subnetGroup); + } + + if (Iterables.size(response) > 0) { + SubnetGroup subnetGroup = response.iterator().next(); + Assert.assertEquals(client().get(subnetGroup.getName()), subnetGroup); + } + + // Test with a Marker, even if it's null + response = client().list(ListSubnetGroupsOptions.Builder.afterMarker(response.getNextMarker())); + for (SubnetGroup subnetGroup : response) { + checkSubnetGroup(subnetGroup); + } + } + + protected SubnetGroupClient client() { + return context.getApi().getSubnetGroupClient(); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSAsyncClientExpectTest.java b/labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSAsyncClientExpectTest.java new file mode 100644 index 0000000000..b9b5725bc5 --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSAsyncClientExpectTest.java @@ -0,0 +1,38 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.internal; + +import java.util.Properties; + +import org.jclouds.rds.RDSAsyncClient; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; + +import com.google.common.base.Function; +import com.google.inject.Module; + +/** + * + * @author Adrian Cole + */ +public class BaseRDSAsyncClientExpectTest extends BaseRDSExpectTest { + public RDSAsyncClient createClient(Function fn, Module module, Properties props) { + return createInjector(fn, module, props).getInstance(RDSAsyncClient.class); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSClientExpectTest.java b/labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSClientExpectTest.java new file mode 100644 index 0000000000..ef6484d48e --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSClientExpectTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.internal; + +import org.jclouds.rds.RDSClient; + + +/** + * + * @author Adrian Cole + */ +public class BaseRDSClientExpectTest extends BaseRDSExpectTest { + +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSClientLiveTest.java b/labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSClientLiveTest.java new file mode 100644 index 0000000000..2cfc057a7d --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSClientLiveTest.java @@ -0,0 +1,46 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.internal; + +import org.jclouds.apis.BaseContextLiveTest; +import org.jclouds.rds.RDSApiMetadata; +import org.jclouds.rds.RDSAsyncClient; +import org.jclouds.rds.RDSClient; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class BaseRDSClientLiveTest extends BaseContextLiveTest> { + + public BaseRDSClientLiveTest() { + provider = "rds"; + } + + @Override + protected TypeToken> contextType() { + return RDSApiMetadata.CONTEXT_TOKEN; + } + +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSExpectTest.java b/labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSExpectTest.java new file mode 100644 index 0000000000..3222cb1b75 --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/internal/BaseRDSExpectTest.java @@ -0,0 +1,78 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.internal; + +import static com.google.common.collect.Maps.transformValues; + +import java.net.URI; +import java.util.Map; + +import org.jclouds.aws.domain.Region; +import org.jclouds.date.DateService; +import org.jclouds.rds.config.RDSRestClientModule; +import org.jclouds.location.config.LocationModule; +import org.jclouds.location.suppliers.RegionIdToURISupplier; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.internal.BaseRestClientExpectTest; +import org.jclouds.util.Suppliers2; + +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; +import com.google.inject.Module; + +/** + * + * @author Adrian Cole + */ +public class BaseRDSExpectTest extends BaseRestClientExpectTest { + + public BaseRDSExpectTest() { + provider = "rds"; + } + + @ConfiguresRestClient + private static final class TestRDSRestClientModule extends RDSRestClientModule { + + @Override + protected void installLocations() { + install(new LocationModule()); + bind(RegionIdToURISupplier.class).toInstance(new RegionIdToURISupplier() { + + @Override + public Map> get() { + return transformValues(ImmutableMap. of(Region.EU_WEST_1, URI + .create("https://rds.eu-west-1.amazonaws.com"), Region.US_EAST_1, URI + .create("https://rds.us-east-1.amazonaws.com"), Region.US_WEST_1, URI + .create("https://rds.us-west-1.amazonaws.com")), Suppliers2. ofInstanceFunction()); + } + + }); + } + + @Override + protected String provideTimeStamp(final DateService dateService) { + return "2009-11-08T15:54:08.897Z"; + } + } + + @Override + protected Module createModule() { + return new TestRDSRestClientModule(); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/options/ListInstancesOptionsTest.java b/labs/rds/src/test/java/org/jclouds/rds/options/ListInstancesOptionsTest.java new file mode 100644 index 0000000000..04820bf664 --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/options/ListInstancesOptionsTest.java @@ -0,0 +1,57 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.options; + +import static org.jclouds.rds.options.ListInstancesOptions.Builder.afterMarker; +import static org.jclouds.rds.options.ListInstancesOptions.Builder.name; +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of {@code ListInstancesOptions} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "ListInstancesOptionsTest") +public class ListInstancesOptionsTest { + + public void testMarker() { + ListInstancesOptions options = new ListInstancesOptions().afterMarker("FFFFF"); + assertEquals(ImmutableSet.of("FFFFF"), options.buildFormParameters().get("Marker")); + } + + public void testMarkerStatic() { + ListInstancesOptions options = afterMarker("FFFFF"); + assertEquals(ImmutableSet.of("FFFFF"), options.buildFormParameters().get("Marker")); + } + + public void testName() { + ListInstancesOptions options = new ListInstancesOptions().name("my-load-balancer"); + assertEquals(ImmutableSet.of("my-load-balancer"), options.buildFormParameters().get("InstanceNames.member.1")); + } + + public void testNameStatic() { + ListInstancesOptions options = name("my-load-balancer"); + assertEquals(ImmutableSet.of("my-load-balancer"), options.buildFormParameters().get("InstanceNames.member.1")); + } + +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/options/ListSecurityGroupsOptionsTest.java b/labs/rds/src/test/java/org/jclouds/rds/options/ListSecurityGroupsOptionsTest.java new file mode 100644 index 0000000000..c949faf8ec --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/options/ListSecurityGroupsOptionsTest.java @@ -0,0 +1,46 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.options; + +import static org.jclouds.rds.options.ListSecurityGroupsOptions.Builder.afterMarker; +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of {@code ListSecurityGroupsOptions} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "ListSecurityGroupsOptionsTest") +public class ListSecurityGroupsOptionsTest { + + public void testMarker() { + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions().afterMarker("FFFFF"); + assertEquals(ImmutableSet.of("FFFFF"), options.buildFormParameters().get("Marker")); + } + + public void testMarkerStatic() { + ListSecurityGroupsOptions options = afterMarker("FFFFF"); + assertEquals(ImmutableSet.of("FFFFF"), options.buildFormParameters().get("Marker")); + } + +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/options/ListSubnetGroupsOptionsTest.java b/labs/rds/src/test/java/org/jclouds/rds/options/ListSubnetGroupsOptionsTest.java new file mode 100644 index 0000000000..82041beea1 --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/options/ListSubnetGroupsOptionsTest.java @@ -0,0 +1,46 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.options; + +import static org.jclouds.rds.options.ListSubnetGroupsOptions.Builder.afterMarker; +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of {@code ListSubnetGroupsOptions} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "ListSubnetGroupsOptionsTest") +public class ListSubnetGroupsOptionsTest { + + public void testMarker() { + ListSubnetGroupsOptions options = new ListSubnetGroupsOptions().afterMarker("FFFFF"); + assertEquals(ImmutableSet.of("FFFFF"), options.buildFormParameters().get("Marker")); + } + + public void testMarkerStatic() { + ListSubnetGroupsOptions options = afterMarker("FFFFF"); + assertEquals(ImmutableSet.of("FFFFF"), options.buildFormParameters().get("Marker")); + } + +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/parse/DescribeDBInstancesResponseTest.java b/labs/rds/src/test/java/org/jclouds/rds/parse/DescribeDBInstancesResponseTest.java new file mode 100644 index 0000000000..fbe4181180 --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/parse/DescribeDBInstancesResponseTest.java @@ -0,0 +1,74 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.collect.PaginatedIterables; +import org.jclouds.date.DateService; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.rds.domain.Instance; +import org.jclouds.rds.xml.DescribeDBInstancesResultHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.net.HostAndPort; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "DescribeDBInstancesResponseTest") +public class DescribeDBInstancesResponseTest extends BaseHandlerTest { + protected final DateService dateService = new SimpleDateFormatDateService(); + + public void test() { + InputStream is = getClass().getResourceAsStream("/describe_instances.xml"); + + PaginatedIterable expected = expected(); + + DescribeDBInstancesResultHandler handler = injector.getInstance(DescribeDBInstancesResultHandler.class); + PaginatedIterable result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + + } + + public PaginatedIterable expected() { + return PaginatedIterables.forward(ImmutableSet.builder() + .add(Instance.builder() + .engine("mysql") + .multiAZ(false) + .licenseModel("general-public-license") + .status("available") + .engineVersion("5.1.50") + .endpoint(HostAndPort.fromParts("simcoprod01.cu7u2t4uz396.us-east-1.rds.amazonaws.com", 3306)) + .id("simcoprod01") + .securityGroupNameToStatus("default", "active") + .availabilityZone("us-east-1a") + .createdTime(dateService.iso8601DateParse("2011-05-23T06:06:43.110Z")) + .allocatedStorageGB(10) + .instanceClass("db.m1.large") + .masterUsername("master").build()).build()); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/parse/DescribeDBSecurityGroupsResponseTest.java b/labs/rds/src/test/java/org/jclouds/rds/parse/DescribeDBSecurityGroupsResponseTest.java new file mode 100644 index 0000000000..b5a51ceecd --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/parse/DescribeDBSecurityGroupsResponseTest.java @@ -0,0 +1,79 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.collect.PaginatedIterables; +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.rds.domain.EC2SecurityGroup; +import org.jclouds.rds.domain.IPRange; +import org.jclouds.rds.domain.SecurityGroup; +import org.jclouds.rds.xml.DescribeDBSecurityGroupsResultHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "DescribeDBSecurityGroupsResponseTest") +public class DescribeDBSecurityGroupsResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/describe_securitygroups.xml"); + + PaginatedIterable expected = expected(); + + DescribeDBSecurityGroupsResultHandler handler = injector.getInstance(DescribeDBSecurityGroupsResultHandler.class); + PaginatedIterable result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + + } + + public PaginatedIterable expected() { + return PaginatedIterables.forward(ImmutableSet.builder() + .add(SecurityGroup.builder() + .ec2SecurityGroup(EC2SecurityGroup.builder() + .status("authorized") + .name("myec2securitygroup") + .ownerId("054794666394").build()) + .description("default") + .ipRange(IPRange.builder().cidrIp("127.0.0.1/30").status("authorized").build()) + .ownerId("621567473609") + .name("default") + .vpcId("vpc-1ab2c3d4").build()) + .add(SecurityGroup.builder() + .description("My new DBSecurityGroup") + .ipRange(IPRange.builder().cidrIp("192.168.1.1/24").status("authorized").build()) + .ownerId("621567473609") + .name("mydbsecuritygroup") + .vpcId("vpc-1ab2c3d5").build()) + .add(SecurityGroup.builder() + .description("My new DBSecurityGroup") + .ownerId("621567473609") + .name("mydbsecuritygroup4") + .vpcId("vpc-1ab2c3d6").build()).build()); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/parse/DescribeDBSubnetGroupsResponseTest.java b/labs/rds/src/test/java/org/jclouds/rds/parse/DescribeDBSubnetGroupsResponseTest.java new file mode 100644 index 0000000000..889ffe612c --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/parse/DescribeDBSubnetGroupsResponseTest.java @@ -0,0 +1,93 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.collect.PaginatedIterable; +import org.jclouds.collect.PaginatedIterables; +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.rds.domain.Subnet; +import org.jclouds.rds.domain.SubnetGroup; +import org.jclouds.rds.xml.DescribeDBSubnetGroupsResultHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "DescribeDBSubnetGroupsResponseTest") +public class DescribeDBSubnetGroupsResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/describe_subnetgroups.xml"); + + PaginatedIterable expected = expected(); + + DescribeDBSubnetGroupsResultHandler handler = injector.getInstance(DescribeDBSubnetGroupsResultHandler.class); + PaginatedIterable result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + + } + + public PaginatedIterable expected() { + return PaginatedIterables.forward(ImmutableSet.builder() + .add(SubnetGroup.builder() + .vpcId("990524496922") + .status("Complete") + .description("description") + .name("subnet_grp1") + .subnets(ImmutableSet.builder() + .add(Subnet.builder() + .status("Active") + .id("subnet-7c5b4115") + .availabilityZone("us-east-1c").build()) + .add(Subnet.builder() + .status("Active") + .id("subnet-7b5b4112") + .availabilityZone("us-east-1b").build()) + .add(Subnet.builder() + .status("Active") + .id("subnet-3ea6bd57") + .availabilityZone("us-east-1d").build()).build()).build()) + .add(SubnetGroup.builder() + .vpcId("990524496922") + .status("Complete") + .description("description") + .name("subnet_grp2") + .subnets(ImmutableSet.builder() + .add(Subnet.builder() + .status("Active") + .id("subnet-7c5b4115") + .availabilityZone("us-east-1c").build()) + .add(Subnet.builder() + .status("Active") + .id("subnet-7b5b4112") + .availabilityZone("us-east-1b").build()) + .add(Subnet.builder() + .status("Active") + .id("subnet-3ea6bd57") + .availabilityZone("us-east-1d").build()).build()).build()).build()); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/parse/GetInstanceResponseTest.java b/labs/rds/src/test/java/org/jclouds/rds/parse/GetInstanceResponseTest.java new file mode 100644 index 0000000000..603c43ca96 --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/parse/GetInstanceResponseTest.java @@ -0,0 +1,69 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.date.DateService; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.rds.domain.Instance; +import org.jclouds.rds.xml.InstanceHandler; +import org.testng.annotations.Test; + +import com.google.common.net.HostAndPort; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "GetInstanceResponseTest") +public class GetInstanceResponseTest extends BaseHandlerTest { + protected final DateService dateService = new SimpleDateFormatDateService(); + + public void test() { + InputStream is = getClass().getResourceAsStream("/get_instance.xml"); + + Instance expected = expected(); + + InstanceHandler handler = injector.getInstance(InstanceHandler.class); + Instance result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + } + + public Instance expected() { + return Instance.builder() + .engine("mysql") + .multiAZ(false) + .licenseModel("general-public-license") + .status("available") + .engineVersion("5.1.50") + .endpoint(HostAndPort.fromParts("simcoprod01.cu7u2t4uz396.us-east-1.rds.amazonaws.com", 3306)) + .id("simcoprod01") + .securityGroupNameToStatus("default", "active") + .availabilityZone("us-east-1a") + .createdTime(dateService.iso8601DateParse("2011-05-23T06:06:43.110Z")) + .allocatedStorageGB(10) + .instanceClass("db.m1.large") + .masterUsername("master").build(); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/parse/GetSecurityGroupResponseTest.java b/labs/rds/src/test/java/org/jclouds/rds/parse/GetSecurityGroupResponseTest.java new file mode 100644 index 0000000000..16c53e5f4c --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/parse/GetSecurityGroupResponseTest.java @@ -0,0 +1,62 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.rds.domain.EC2SecurityGroup; +import org.jclouds.rds.domain.IPRange; +import org.jclouds.rds.domain.SecurityGroup; +import org.jclouds.rds.xml.SecurityGroupHandler; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "GetSecurityGroupResponseTest") +public class GetSecurityGroupResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/get_securitygroup.xml"); + + SecurityGroup expected = expected(); + + SecurityGroupHandler handler = injector.getInstance(SecurityGroupHandler.class); + SecurityGroup result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + } + + public SecurityGroup expected() { + return SecurityGroup.builder() + .ec2SecurityGroup(EC2SecurityGroup.builder() + .status("authorized") + .name("myec2securitygroup") + .ownerId("054794666394").build()) + .description("default") + .ipRange(IPRange.builder().cidrIp("127.0.0.1/30").status("authorized").build()) + .ownerId("621567473609") + .name("default") + .vpcId("vpc-1ab2c3d4").build(); + } +} diff --git a/labs/rds/src/test/java/org/jclouds/rds/parse/GetSubnetGroupResponseTest.java b/labs/rds/src/test/java/org/jclouds/rds/parse/GetSubnetGroupResponseTest.java new file mode 100644 index 0000000000..15e40174bd --- /dev/null +++ b/labs/rds/src/test/java/org/jclouds/rds/parse/GetSubnetGroupResponseTest.java @@ -0,0 +1,71 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rds.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.rds.domain.Subnet; +import org.jclouds.rds.domain.SubnetGroup; +import org.jclouds.rds.xml.SubnetGroupHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "GetSubnetGroupResponseTest") +public class GetSubnetGroupResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/get_subnetgroup.xml"); + + SubnetGroup expected = expected(); + + SubnetGroupHandler handler = injector.getInstance(SubnetGroupHandler.class); + SubnetGroup result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + } + + public SubnetGroup expected() { + return SubnetGroup.builder() + .vpcId("990524496922") + .status("Complete") + .description("description") + .name("subnet_grp1") + .subnets(ImmutableSet.builder() + .add(Subnet.builder() + .status("Active") + .id("subnet-7c5b4115") + .availabilityZone("us-east-1c").build()) + .add(Subnet.builder() + .status("Active") + .id("subnet-7b5b4112") + .availabilityZone("us-east-1b").build()) + .add(Subnet.builder() + .status("Active") + .id("subnet-3ea6bd57") + .availabilityZone("us-east-1d").build()).build()).build(); + } +} diff --git a/labs/rds/src/test/resources/describe_instances.xml b/labs/rds/src/test/resources/describe_instances.xml new file mode 100644 index 0000000000..416d3b5588 --- /dev/null +++ b/labs/rds/src/test/resources/describe_instances.xml @@ -0,0 +1,45 @@ + + + + + + 2011-05-23T06:50:00Z + mysql + + 1 + false + general-public-license + available + 5.1.50 + + 3306 +
simcoprod01.cu7u2t4uz396.us-east-1.rds.amazonaws.com
+
+ simcoprod01 + + + in-sync + default.mysql5.1 + + + + + active + default + + + 00:00-00:30 + true + sat:07:30-sat:08:00 + us-east-1a + 2011-05-23T06:06:43.110Z + 10 + db.m1.large + master +
+
+
+ + 9135fff3-8509-11e0-bd9b-a7b1ece36d51 + +
\ No newline at end of file diff --git a/labs/rds/src/test/resources/describe_securitygroups.xml b/labs/rds/src/test/resources/describe_securitygroups.xml new file mode 100644 index 0000000000..b9b60c559a --- /dev/null +++ b/labs/rds/src/test/resources/describe_securitygroups.xml @@ -0,0 +1,49 @@ + + + + + + + authorized + myec2securitygroup + 054794666394 + + + default + + + 127.0.0.1/30 + authorized + + + 621567473609 + default + vpc-1ab2c3d4 + + + + My new DBSecurityGroup + + + 192.168.1.1/24 + authorized + + + 621567473609 + mydbsecuritygroup + vpc-1ab2c3d5 + + + + My new DBSecurityGroup + + 621567473609 + mydbsecuritygroup4 + vpc-1ab2c3d6 + + + + + bbdad154-bf42-11de-86a4-97241dfaadff + + \ No newline at end of file diff --git a/labs/rds/src/test/resources/describe_subnetgroups.xml b/labs/rds/src/test/resources/describe_subnetgroups.xml new file mode 100644 index 0000000000..7e3d999020 --- /dev/null +++ b/labs/rds/src/test/resources/describe_subnetgroups.xml @@ -0,0 +1,70 @@ + + + + + 990524496922 + Complete + description + + subnet_grp1 + + + Active + subnet-7c5b4115 + + us-east-1c + + + + Active + subnet-7b5b4112 + + us-east-1b + + + + Active + subnet-3ea6bd57 + + us-east-1d + + + + + + 990524496922 + Complete + description + + subnet_grp2 + + + Active + subnet-7c5b4115 + + us-east-1c + + + + Active + subnet-7b5b4112 + + us-east-1b + + + + Active + subnet-3ea6bd57 + + us-east-1d + + + + + + + + 31d0faee-229b-11e1-81f1-df3a2a803dad + + \ No newline at end of file diff --git a/labs/rds/src/test/resources/get_instance.xml b/labs/rds/src/test/resources/get_instance.xml new file mode 100644 index 0000000000..416d3b5588 --- /dev/null +++ b/labs/rds/src/test/resources/get_instance.xml @@ -0,0 +1,45 @@ + + + + + + 2011-05-23T06:50:00Z + mysql + + 1 + false + general-public-license + available + 5.1.50 + + 3306 +
simcoprod01.cu7u2t4uz396.us-east-1.rds.amazonaws.com
+
+ simcoprod01 + + + in-sync + default.mysql5.1 + + + + + active + default + + + 00:00-00:30 + true + sat:07:30-sat:08:00 + us-east-1a + 2011-05-23T06:06:43.110Z + 10 + db.m1.large + master +
+
+
+ + 9135fff3-8509-11e0-bd9b-a7b1ece36d51 + +
\ No newline at end of file diff --git a/labs/rds/src/test/resources/get_securitygroup.xml b/labs/rds/src/test/resources/get_securitygroup.xml new file mode 100644 index 0000000000..fdb1681d7b --- /dev/null +++ b/labs/rds/src/test/resources/get_securitygroup.xml @@ -0,0 +1,28 @@ + + + + + + + authorized + myec2securitygroup + 054794666394 + + + default + + + 127.0.0.1/30 + authorized + + + 621567473609 + default + vpc-1ab2c3d4 + + + + + bbdad154-bf42-11de-86a4-97241dfaadff + + \ No newline at end of file diff --git a/labs/rds/src/test/resources/get_subnetgroup.xml b/labs/rds/src/test/resources/get_subnetgroup.xml new file mode 100644 index 0000000000..98a5d8263f --- /dev/null +++ b/labs/rds/src/test/resources/get_subnetgroup.xml @@ -0,0 +1,40 @@ + + + + + 990524496922 + Complete + description + + subnet_grp1 + + + Active + subnet-7c5b4115 + + us-east-1c + + + + Active + subnet-7b5b4112 + + us-east-1b + + + + Active + subnet-3ea6bd57 + + us-east-1d + + + + + + + + 31d0faee-229b-11e1-81f1-df3a2a803dad + + \ No newline at end of file diff --git a/labs/rds/src/test/resources/logback.xml b/labs/rds/src/test/resources/logback.xml new file mode 100644 index 0000000000..50b810a91e --- /dev/null +++ b/labs/rds/src/test/resources/logback.xml @@ -0,0 +1,38 @@ + + + + target/test-data/jclouds.log + + + %d %-5p [%c] [%thread] %m%n + + + + + target/test-data/jclouds-wire.log + + + %d %-5p [%c] [%thread] %m%n + + + + + + + + + + + + + + + + + + + + + + +