Issue 29: added DescribeInstanceAttribute functions

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2557 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-12-31 06:53:32 +00:00
parent 093d1ce393
commit 6fc03a9b01
16 changed files with 747 additions and 35 deletions

View File

@ -43,6 +43,28 @@ import com.google.common.collect.Sets;
*/
public class Volume implements Comparable<Volume> {
/**
* Specifies whether the instance's Amazon EBS volumes are stopped or terminated when the
* instance is shut down.
*
* @author Adrian Cole
*/
public static enum InstanceInitiatedShutdownBehavior {
STOP, TERMINATE;
public String value() {
return name().toLowerCase();
}
@Override
public String toString() {
return value();
}
public static InstanceInitiatedShutdownBehavior fromValue(String status) {
return valueOf(checkNotNull(status, "status").toUpperCase());
}
}
public static enum Status {
CREATING, AVAILABLE, IN_USE, DELETING;
public String value() {

View File

@ -26,6 +26,7 @@ package org.jclouds.aws.ec2.services;
import static org.jclouds.aws.ec2.reference.EC2Parameters.ACTION;
import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;
@ -38,14 +39,23 @@ import org.jclouds.aws.ec2.binders.BindInstanceIdsToIndexedFormParams;
import org.jclouds.aws.ec2.binders.IfNotNullBindAvailabilityZoneToFormParam;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.InstanceStateChange;
import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.aws.ec2.domain.Region;
import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.aws.ec2.domain.Image.EbsBlockDevice;
import org.jclouds.aws.ec2.domain.Volume.InstanceInitiatedShutdownBehavior;
import org.jclouds.aws.ec2.filters.FormSigner;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;
import org.jclouds.aws.ec2.options.RunInstancesOptions;
import org.jclouds.aws.ec2.xml.BlockDeviceMappingHandler;
import org.jclouds.aws.ec2.xml.BooleanValueHandler;
import org.jclouds.aws.ec2.xml.DescribeInstancesResponseHandler;
import org.jclouds.aws.ec2.xml.InstanceInitiatedShutdownBehaviorHandler;
import org.jclouds.aws.ec2.xml.InstanceStateChangeHandler;
import org.jclouds.aws.ec2.xml.InstanceTypeHandler;
import org.jclouds.aws.ec2.xml.RunInstancesResponseHandler;
import org.jclouds.aws.ec2.xml.StringValueHandler;
import org.jclouds.aws.ec2.xml.UnencodeStringValueHandler;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.FormParams;
@ -128,9 +138,10 @@ public interface InstanceAsyncClient {
@POST
@Path("/")
@FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute", "userData" })
@XMLResponseParser(UnencodeStringValueHandler.class)
Future<String> getUserDataForInstanceInRegion(
@EndpointParam(parser = RegionToEndpoint.class) Region region,
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
@FormParam("InstanceId") String instanceId);
/**
* @see AMIClient#getRootDeviceNameForInstanceInRegion
@ -139,9 +150,10 @@ public interface InstanceAsyncClient {
@Path("/")
@FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute",
"rootDeviceName" })
@XMLResponseParser(StringValueHandler.class)
Future<String> getRootDeviceNameForInstanceInRegion(
@EndpointParam(parser = RegionToEndpoint.class) Region region,
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
@FormParam("InstanceId") String instanceId);
/**
* @see AMIClient#getRamdiskForInstanceInRegion
@ -149,9 +161,10 @@ public interface InstanceAsyncClient {
@POST
@Path("/")
@FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute", "ramdisk" })
@XMLResponseParser(StringValueHandler.class)
Future<String> getRamdiskForInstanceInRegion(
@EndpointParam(parser = RegionToEndpoint.class) Region region,
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
@FormParam("InstanceId") String instanceId);
/**
* @see AMIClient#getDisableApiTerminationForInstanceInRegion
@ -160,9 +173,10 @@ public interface InstanceAsyncClient {
@Path("/")
@FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute",
"disableApiTermination" })
Future<String> getDisableApiTerminationForInstanceInRegion(
@XMLResponseParser(BooleanValueHandler.class)
Future<Boolean> getDisableApiTerminationForInstanceInRegion(
@EndpointParam(parser = RegionToEndpoint.class) Region region,
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
@FormParam("InstanceId") String instanceId);
/**
* @see AMIClient#getKernelForInstanceInRegion
@ -170,9 +184,10 @@ public interface InstanceAsyncClient {
@POST
@Path("/")
@FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute", "kernel" })
@XMLResponseParser(StringValueHandler.class)
Future<String> getKernelForInstanceInRegion(
@EndpointParam(parser = RegionToEndpoint.class) Region region,
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
@FormParam("InstanceId") String instanceId);
/**
* @see AMIClient#getInstanceTypeForInstanceInRegion
@ -181,9 +196,10 @@ public interface InstanceAsyncClient {
@Path("/")
@FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute",
"instanceType" })
Future<String> getInstanceTypeForInstanceInRegion(
@XMLResponseParser(InstanceTypeHandler.class)
Future<InstanceType> getInstanceTypeForInstanceInRegion(
@EndpointParam(parser = RegionToEndpoint.class) Region region,
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
@FormParam("InstanceId") String instanceId);
/**
* @see AMIClient#getInstanceInitiatedShutdownBehaviorForInstanceInRegion
@ -192,9 +208,10 @@ public interface InstanceAsyncClient {
@Path("/")
@FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute",
"instanceInitiatedShutdownBehavior" })
Future<String> getInstanceInitiatedShutdownBehaviorForInstanceInRegion(
@XMLResponseParser(InstanceInitiatedShutdownBehaviorHandler.class)
Future<InstanceInitiatedShutdownBehavior> getInstanceInitiatedShutdownBehaviorForInstanceInRegion(
@EndpointParam(parser = RegionToEndpoint.class) Region region,
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
@FormParam("InstanceId") String instanceId);
/**
* @see AMIClient#getBlockDeviceMappingForInstanceInRegion
@ -203,8 +220,9 @@ public interface InstanceAsyncClient {
@Path("/")
@FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute",
"blockDeviceMapping" })
Future<String> getBlockDeviceMappingForInstanceInRegion(
@XMLResponseParser(BlockDeviceMappingHandler.class)
Future<? extends Map<String, EbsBlockDevice>> getBlockDeviceMappingForInstanceInRegion(
@EndpointParam(parser = RegionToEndpoint.class) Region region,
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
@FormParam("InstanceId") String instanceId);
}

View File

@ -23,6 +23,7 @@
*/
package org.jclouds.aws.ec2.services;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -30,8 +31,11 @@ import javax.annotation.Nullable;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.InstanceStateChange;
import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.aws.ec2.domain.Region;
import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.aws.ec2.domain.Image.EbsBlockDevice;
import org.jclouds.aws.ec2.domain.Volume.InstanceInitiatedShutdownBehavior;
import org.jclouds.aws.ec2.options.RunInstancesOptions;
import org.jclouds.concurrent.Timeout;
@ -226,21 +230,97 @@ public interface InstanceClient {
*/
Set<InstanceStateChange> startInstancesInRegion(Region region, String... instanceIds);
String getUserDataForInstanceInRegion(Region region, String... instanceIds);
/**
*
* @param region
* Instances are tied to Availability Zones. However, the instance ID is tied to the
* Region.
* @param instanceId
* which instance to describe the attribute of
* @return unencoded user data
*/
String getUserDataForInstanceInRegion(Region region, String instanceId);
String getRootDeviceNameForInstanceInRegion(Region region, String... instanceIds);
/**
*
* @param region
* Instances are tied to Availability Zones. However, the instance ID is tied to the
* Region.
* @param instanceId
* which instance to describe the attribute of
* @return The root device name (e.g., /dev/sda1).
*/
String getRootDeviceNameForInstanceInRegion(Region region, String instanceId);
String getRamdiskForInstanceInRegion(Region region, String... instanceIds);
/**
*
* @param region
* Instances are tied to Availability Zones. However, the instance ID is tied to the
* Region.
* @param instanceId
* which instance to describe the attribute of
* @return the ID of the RAM disk associated with the AMI.
*/
String getRamdiskForInstanceInRegion(Region region, String instanceId);
String getDisableApiTerminationForInstanceInRegion(Region region, String... instanceIds);
/**
*
* @param region
* Instances are tied to Availability Zones. However, the instance ID is tied to the
* Region.
* @param instanceId
* which instance to describe the attribute of
* @return Specifies whether the instance can be terminated using the APIs. You must modify this
* attribute before you can terminate any "locked" instances from the APIs.
*/
boolean getDisableApiTerminationForInstanceInRegion(Region region, String instanceId);
String getKernelForInstanceInRegion(Region region, String... instanceIds);
/**
*
* @param region
* Instances are tied to Availability Zones. However, the instance ID is tied to the
* Region.
* @param instanceId
* which instance to describe the attribute of
* @return the ID of the kernel associated with the AMI.
*/
String getKernelForInstanceInRegion(Region region, String instanceId);
String getInstanceTypeForInstanceInRegion(Region region, String... instanceIds);
/**
*
* @param region
* Instances are tied to Availability Zones. However, the instance ID is tied to the
* Region.
* @param instanceId
* which instance to describe the attribute of
* @return The instance type of the instance.
*/
InstanceType getInstanceTypeForInstanceInRegion(Region region, String instanceId);
String getInstanceInitiatedShutdownBehaviorForInstanceInRegion(Region region,
String... instanceIds);
/**
*
* @param region
* Instances are tied to Availability Zones. However, the instance ID is tied to the
* Region.
* @param instanceId
* which instance to describe the attribute of
* @return whether the instance's Amazon EBS volumes are stopped or terminated when the instance
* is shut down.
*/
InstanceInitiatedShutdownBehavior getInstanceInitiatedShutdownBehaviorForInstanceInRegion(
Region region, String instanceId);
String getBlockDeviceMappingForInstanceInRegion(Region region, String... instanceIds);
/**
*
* @param region
* Instances are tied to Availability Zones. However, the instance ID is tied to the
* Region.
* @param instanceId
* which instance to describe the attribute of
* @return Describes the mapping that defines native device names to use when exposing virtual
* devices.
*/
Map<String, EbsBlockDevice> getBlockDeviceMappingForInstanceInRegion(Region region,
String instanceId);
}

View File

@ -0,0 +1,53 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.ec2.xml;
import org.jclouds.http.functions.ParseSax;
/**
*
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeInstanceAttribute.html"
* />
* @author Adrian Cole
*/
public class BooleanValueHandler extends ParseSax.HandlerWithResult<Boolean> {
private StringBuilder currentText = new StringBuilder();
private boolean value;
public Boolean getResult() {
return value;
}
public void endElement(String uri, String name, String qName) {
if (qName.equalsIgnoreCase("value")) {
this.value = Boolean.parseBoolean(currentText.toString().trim());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -0,0 +1,55 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.ec2.xml;
import org.jclouds.aws.ec2.domain.Volume.InstanceInitiatedShutdownBehavior;
import org.jclouds.http.functions.ParseSax;
/**
*
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeInstanceAttribute.html"
* />
* @author Adrian Cole
*/
public class InstanceInitiatedShutdownBehaviorHandler extends
ParseSax.HandlerWithResult<InstanceInitiatedShutdownBehavior> {
private StringBuilder currentText = new StringBuilder();
private InstanceInitiatedShutdownBehavior behavior;
public InstanceInitiatedShutdownBehavior getResult() {
return behavior;
}
public void endElement(String uri, String name, String qName) {
if (qName.equalsIgnoreCase("value")) {
this.behavior = InstanceInitiatedShutdownBehavior.fromValue(currentText.toString().trim());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -0,0 +1,55 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.ec2.xml;
import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.http.functions.ParseSax;
/**
*
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeInstanceAttribute.html"
* />
* @author Adrian Cole
*/
public class InstanceTypeHandler extends
ParseSax.HandlerWithResult<InstanceType> {
private StringBuilder currentText = new StringBuilder();
private InstanceType type;
public InstanceType getResult() {
return type;
}
public void endElement(String uri, String name, String qName) {
if (qName.equalsIgnoreCase("value")) {
this.type = InstanceType.fromValue(currentText.toString().trim());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -0,0 +1,54 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.ec2.xml;
import org.jclouds.http.functions.ParseSax;
/**
*
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeInstanceAttribute.html"
* />
* @author Adrian Cole
*/
public class StringValueHandler extends
ParseSax.HandlerWithResult<String> {
private StringBuilder currentText = new StringBuilder();
private String value;
public String getResult() {
return value;
}
public void endElement(String uri, String name, String qName) {
if (qName.equalsIgnoreCase("value")) {
this.value = currentText.toString().trim();
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -0,0 +1,48 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.ec2.xml;
import javax.inject.Inject;
import org.jclouds.encryption.EncryptionService;
import com.google.common.base.Charsets;
/**
*
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeInstanceAttribute.html"
* />
* @author Adrian Cole
*/
public class UnencodeStringValueHandler extends StringValueHandler {
@Inject
private EncryptionService encryptionService;
@Override
public String getResult() {
return super.getResult() == null ? null : new String(encryptionService.fromBase64String(super
.getResult()), Charsets.UTF_8);
}
}

View File

@ -47,6 +47,8 @@ import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair;
import org.jclouds.aws.ec2.domain.Region;
import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.domain.Image.EbsBlockDevice;
import org.jclouds.aws.ec2.domain.Volume.InstanceInitiatedShutdownBehavior;
import org.jclouds.aws.ec2.predicates.InstanceStateRunning;
import org.jclouds.encryption.internal.Base64;
import org.jclouds.http.HttpResponseException;
@ -63,6 +65,7 @@ import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.inject.Injector;
@ -75,7 +78,7 @@ import com.google.inject.Injector;
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = false, sequential = true, testName = "ec2.CloudApplicationArchitecturesEC2ClientLiveTest")
@Test(groups = "live", enabled = true, sequential = true, testName = "ec2.CloudApplicationArchitecturesEC2ClientLiveTest")
public class CloudApplicationArchitecturesEC2ClientLiveTest {
private EC2Client client;
@ -103,7 +106,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
TimeUnit.SECONDS);
}
@Test(enabled = false)
@Test(enabled = true)
void testCreateSecurityGroupIngressCidr() throws InterruptedException, ExecutionException,
TimeoutException {
securityGroupName = instancePrefix + "ingress";
@ -122,7 +125,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
}
}
@Test(enabled = false)
@Test(enabled = true)
void testCreateKeyPair() throws InterruptedException, ExecutionException, TimeoutException {
String keyName = instancePrefix + "1";
try {
@ -139,12 +142,9 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
assertEquals(keyPair.getKeyName(), keyName);
}
@Test(enabled = false, dependsOnMethods = { "testCreateKeyPair",
@Test(enabled = true, dependsOnMethods = { "testCreateKeyPair",
"testCreateSecurityGroupIngressCidr" })
public void testCreateRunningInstance() throws Exception {
RunningInstance instance = null;
while (instance == null) {
try {
String script = new ScriptBuilder() // lamp install script
.addStatement(exec("runurl run.alestic.com/apt/upgrade"))//
.addStatement(exec("runurl run.alestic.com/install/lamp"))//
@ -152,6 +152,9 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
// userData must be base 64 encoded
String encodedScript = Base64.encodeBytes(script.getBytes());
RunningInstance instance = null;
while (instance == null) {
try {
System.out.printf("%d: running instance%n", System.currentTimeMillis());
Reservation reservation = client.getInstanceServices().runInstancesInRegion(
@ -176,12 +179,41 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
instanceId = instance.getId();
assertEquals(instance.getInstanceState(), InstanceState.PENDING);
instance = blockUntilWeCanSshIntoInstance(instance);
verifyInstanceProperties(script);
sshPing(instance);
System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instanceId);
}
@Test(enabled = false, dependsOnMethods = "testCreateRunningInstance")
private void verifyInstanceProperties(String script) {
assertEquals(script, client.getInstanceServices().getUserDataForInstanceInRegion(
Region.DEFAULT, instanceId));
assertEquals(null, client.getInstanceServices().getRootDeviceNameForInstanceInRegion(
Region.DEFAULT, instanceId));
assert client.getInstanceServices().getRamdiskForInstanceInRegion(Region.DEFAULT, instanceId)
.startsWith("ari-");
assertEquals(false, client.getInstanceServices().getDisableApiTerminationForInstanceInRegion(
Region.DEFAULT, instanceId));
assert client.getInstanceServices().getKernelForInstanceInRegion(Region.DEFAULT, instanceId)
.startsWith("aki-");
assertEquals(InstanceType.M1_SMALL, client.getInstanceServices()
.getInstanceTypeForInstanceInRegion(Region.DEFAULT, instanceId));
assertEquals(InstanceInitiatedShutdownBehavior.TERMINATE, client.getInstanceServices()
.getInstanceInitiatedShutdownBehaviorForInstanceInRegion(Region.DEFAULT, instanceId));
assertEquals(ImmutableMap.<String, EbsBlockDevice> of(), client.getInstanceServices()
.getBlockDeviceMappingForInstanceInRegion(Region.DEFAULT, instanceId));
}
@Test(enabled = true, dependsOnMethods = "testCreateRunningInstance")
void testElasticIpAddress() throws InterruptedException, ExecutionException, TimeoutException,
IOException {
address = client.getElasticIPAddressServices().allocateAddressInRegion(Region.DEFAULT);

View File

@ -38,9 +38,15 @@ import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Region;
import org.jclouds.aws.ec2.filters.FormSigner;
import org.jclouds.aws.ec2.options.RunInstancesOptions;
import org.jclouds.aws.ec2.xml.BlockDeviceMappingHandler;
import org.jclouds.aws.ec2.xml.BooleanValueHandler;
import org.jclouds.aws.ec2.xml.DescribeInstancesResponseHandler;
import org.jclouds.aws.ec2.xml.RunInstancesResponseHandler;
import org.jclouds.aws.ec2.xml.InstanceInitiatedShutdownBehaviorHandler;
import org.jclouds.aws.ec2.xml.InstanceStateChangeHandler;
import org.jclouds.aws.ec2.xml.InstanceTypeHandler;
import org.jclouds.aws.ec2.xml.RunInstancesResponseHandler;
import org.jclouds.aws.ec2.xml.StringValueHandler;
import org.jclouds.aws.ec2.xml.UnencodeStringValueHandler;
import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.ParseSax;
@ -65,7 +71,6 @@ import com.google.inject.TypeLiteral;
*/
@Test(groups = "unit", testName = "ec2.InstanceAsyncClientTest")
public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient> {
public void testDescribeInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("describeInstancesInRegion",
Region.class, Array.newInstance(String.class, 0).getClass());
@ -206,6 +211,168 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
checkFilters(httpMethod);
}
public void testGetUserDataForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("getUserDataForInstanceInRegion",
Region.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.DEFAULT, "1");
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 83\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=userData&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, UnencodeStringValueHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testGetRootDeviceNameForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("getRootDeviceNameForInstanceInRegion",
Region.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.DEFAULT, "1");
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=rootDeviceName&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testGetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException,
IOException {
Method method = InstanceAsyncClient.class.getMethod("getRamdiskForInstanceInRegion",
Region.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.DEFAULT, "1");
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 82\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=ramdisk&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testGetDisableApiTerminationForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod(
"getDisableApiTerminationForInstanceInRegion", Region.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.DEFAULT, "1");
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 96\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=disableApiTermination&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, BooleanValueHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testGetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException,
IOException {
Method method = InstanceAsyncClient.class.getMethod("getKernelForInstanceInRegion",
Region.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.DEFAULT, "1");
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 81\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=kernel&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testGetInstanceTypeForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("getInstanceTypeForInstanceInRegion",
Region.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.DEFAULT, "1");
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceType&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceTypeHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testGetInstanceInitiatedShutdownBehaviorForInstanceInRegion()
throws SecurityException, NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod(
"getInstanceInitiatedShutdownBehaviorForInstanceInRegion", Region.class,
String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.DEFAULT, "1");
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 108\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(
httpMethod,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceInitiatedShutdownBehaviorHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testGetBlockDeviceMappingForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod(
"getBlockDeviceMappingForInstanceInRegion", Region.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.DEFAULT, "1");
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(httpMethod,
"Content-Length: 93\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
@Override
protected void checkFilters(GeneratedHttpRequest<InstanceAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1);

View File

@ -0,0 +1,88 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.ec2.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.aws.ec2.domain.Volume.InstanceInitiatedShutdownBehavior;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code InstanceInitiatedShutdownBehaviorHandler}, {@code InstanceTypeHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ec2.DescribeInstanceAttributeTest")
public class DescribeInstanceAttributeTest extends BaseHandlerTest {
public void testInstanceInitiatedShutdownBehaviorHandler() {
InputStream is = getClass().getResourceAsStream("/ec2/instanceInitiatedShutdownBehavior.xml");
InstanceInitiatedShutdownBehaviorHandler handler = injector
.getInstance(InstanceInitiatedShutdownBehaviorHandler.class);
InstanceInitiatedShutdownBehavior result = factory.create(handler).parse(is);
assertEquals(result, InstanceInitiatedShutdownBehavior.STOP);
}
public void testInstanceTypeHandler() {
InputStream is = getClass().getResourceAsStream("/ec2/instanceType.xml");
InstanceTypeHandler handler = injector.getInstance(InstanceTypeHandler.class);
InstanceType result = factory.create(handler).parse(is);
assertEquals(result, InstanceType.M1_SMALL);
}
public void testBooleanValueHandler() {
InputStream is = getClass().getResourceAsStream("/ec2/disableApiTermination.xml");
BooleanValueHandler handler = injector.getInstance(BooleanValueHandler.class);
Boolean result = factory.create(handler).parse(is);
assert !result;
}
public void testStringValueHandler() {
InputStream is = getClass().getResourceAsStream("/ec2/ramdisk.xml");
StringValueHandler handler = injector.getInstance(StringValueHandler.class);
String result = factory.create(handler).parse(is);
assertEquals(result, "ari-a51cf9cc");
}
public void testUnencodeStringValueHandler() {
InputStream is = getClass().getResourceAsStream("/ec2/userData.xml");
UnencodeStringValueHandler handler = injector.getInstance(UnencodeStringValueHandler.class);
String result = factory.create(handler).parse(is);
assertEquals(result, "#!/bin/bash\n");
}
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<DescribeInstanceAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
<requestId>b47e8cff-0647-4260-adfe-022c878b1f7d</requestId>
<instanceId>i-e9290f81</instanceId>
<disableApiTermination>
<value>false</value>
</disableApiTermination>
</DescribeInstanceAttributeResponse>

View File

@ -0,0 +1,7 @@
<DescribeInstanceAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
<requestId>564827a8-c70d-4a76-bb9b-87fb5e5a6cee</requestId>
<instanceId>i-7736101f</instanceId>
<instanceInitiatedShutdownBehavior>
<value>stop</value>
</instanceInitiatedShutdownBehavior>
</DescribeInstanceAttributeResponse>

View File

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<DescribeInstanceAttributeResponse
xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
<requestId>947779ee-439a-46b5-82db-5f015f75b6d0</requestId>
<instanceId>i-7736101f</instanceId>
<instanceType>
<value>m1.small</value>
</instanceType>
</DescribeInstanceAttributeResponse>

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<DescribeInstanceAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
<requestId>94174289-29d5-40d2-95f2-2b3d3005d58c</requestId>
<instanceId>i-c72d0baf</instanceId>
<ramdisk>
<value>ari-a51cf9cc</value>
</ramdisk>
</DescribeInstanceAttributeResponse>

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<DescribeInstanceAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
<requestId>0d0ca353-fba3-402c-8516-005e2b41d0ba</requestId>
<instanceId>i-c72d0baf</instanceId>
<userData>
<value>IyEvYmluL2Jhc2gKc</value>
</userData>
</DescribeInstanceAttributeResponse>