mirror of https://github.com/apache/jclouds.git
Changed the way device name is passed
This commit is contained in:
parent
55c8ce03ad
commit
db31695940
|
@ -2,7 +2,6 @@ package org.jclouds.aws.ec2.binders;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.domain.BlockDeviceMapping;
|
import org.jclouds.aws.ec2.domain.BlockDeviceMapping;
|
||||||
import org.jclouds.aws.ec2.domain.RunningInstance;
|
import org.jclouds.aws.ec2.domain.RunningInstance;
|
||||||
import org.jclouds.aws.ec2.domain.UserIdGroupPair;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.rest.Binder;
|
import org.jclouds.rest.Binder;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
@ -30,22 +29,23 @@ public class BindBlockDeviceMappingToIndexedFormParams implements Binder {
|
||||||
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
|
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
|
||||||
|
|
||||||
int amazonOneBasedIndex = 1; //according to docs, counters must start with 1
|
int amazonOneBasedIndex = 1; //according to docs, counters must start with 1
|
||||||
for(RunningInstance.EbsBlockDevice ebsBlockDevice : blockDeviceMapping.getEbsBlockDevices()) {
|
for(String ebsBlockDeviceName : blockDeviceMapping.getEbsBlockDevices().keySet()) {
|
||||||
|
for(RunningInstance.EbsBlockDevice ebsBlockDevice : blockDeviceMapping.getEbsBlockDevices().get(ebsBlockDeviceName)) {
|
||||||
|
|
||||||
//not null by contract
|
//not null by contract
|
||||||
generatedRequest.addFormParam(format(volumeIdPattern, amazonOneBasedIndex),
|
generatedRequest.addFormParam(format(volumeIdPattern, amazonOneBasedIndex),
|
||||||
ebsBlockDevice.getVolumeId());
|
ebsBlockDevice.getVolumeId());
|
||||||
|
|
||||||
if(ebsBlockDevice.getDeviceName() != null) {
|
if(ebsBlockDeviceName != null) {
|
||||||
generatedRequest.addFormParam(format(deviceNamePattern, amazonOneBasedIndex),
|
generatedRequest.addFormParam(format(deviceNamePattern, amazonOneBasedIndex),
|
||||||
ebsBlockDevice.getDeviceName());
|
ebsBlockDeviceName);
|
||||||
}
|
}
|
||||||
|
generatedRequest.addFormParam(format(deleteOnTerminationPattern, amazonOneBasedIndex),
|
||||||
generatedRequest.addFormParam(format(deleteOnTerminationPattern, amazonOneBasedIndex),
|
|
||||||
String.valueOf(ebsBlockDevice.isDeleteOnTermination()));
|
String.valueOf(ebsBlockDevice.isDeleteOnTermination()));
|
||||||
|
|
||||||
|
|
||||||
amazonOneBasedIndex++;
|
amazonOneBasedIndex++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,15 +18,11 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.ec2.domain;
|
package org.jclouds.aws.ec2.domain;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.*;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.inject.internal.Nullable;
|
import com.google.inject.internal.Nullable;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the mapping of volumes for
|
* Defines the mapping of volumes for
|
||||||
* {@link org.jclouds.aws.ec2.services.InstanceClient#setBlockDeviceMappingForInstanceInRegion}.
|
* {@link org.jclouds.aws.ec2.services.InstanceClient#setBlockDeviceMappingForInstanceInRegion}.
|
||||||
|
@ -35,7 +31,8 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class BlockDeviceMapping {
|
public class BlockDeviceMapping {
|
||||||
|
|
||||||
private final List<RunningInstance.EbsBlockDevice> ebsBlockDevices = Lists.newArrayList();
|
private final Multimap<String, RunningInstance.EbsBlockDevice> ebsBlockDevices =
|
||||||
|
LinkedHashMultimap.create();
|
||||||
|
|
||||||
public BlockDeviceMapping() {
|
public BlockDeviceMapping() {
|
||||||
}
|
}
|
||||||
|
@ -45,26 +42,27 @@ public class BlockDeviceMapping {
|
||||||
*
|
*
|
||||||
* This method copies the values of the list.
|
* This method copies the values of the list.
|
||||||
* @param ebsBlockDevices
|
* @param ebsBlockDevices
|
||||||
* devices to be changed for the volume
|
* devices to be changed for the volume. This cannot be null.
|
||||||
*/
|
*/
|
||||||
public BlockDeviceMapping(List<RunningInstance.EbsBlockDevice> ebsBlockDevices) {
|
public BlockDeviceMapping(Multimap<String, RunningInstance.EbsBlockDevice> ebsBlockDevices) {
|
||||||
this.ebsBlockDevices.addAll(checkNotNull(ebsBlockDevices,
|
this.ebsBlockDevices.putAll(checkNotNull(ebsBlockDevices,
|
||||||
/*or throw*/ "EbsBlockDevices can't be null"));
|
/*or throw*/ "EbsBlockDevices can't be null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a {@link RunningInstance.EbsBlockDevice} to the mapping.
|
* Adds a {@link RunningInstance.EbsBlockDevice} to the mapping.
|
||||||
|
* @param deviceName name of the device to apply the mapping. Can be null.
|
||||||
* @param ebsBlockDevice
|
* @param ebsBlockDevice
|
||||||
* ebsBlockDevice to be added
|
* ebsBlockDevice to be added. This cannot be null.
|
||||||
* @return the same instance for method chaining purposes
|
* @return the same instance for method chaining purposes
|
||||||
*/
|
*/
|
||||||
public BlockDeviceMapping addEbsBlockDevice(RunningInstance.EbsBlockDevice ebsBlockDevice) {
|
public BlockDeviceMapping addEbsBlockDevice(@Nullable String deviceName, RunningInstance.EbsBlockDevice ebsBlockDevice) {
|
||||||
this.ebsBlockDevices.add(checkNotNull(ebsBlockDevice,
|
this.ebsBlockDevices.put(deviceName, checkNotNull(ebsBlockDevice,
|
||||||
/*or throw*/ "EbsBlockDevice can't be null"));
|
/*or throw*/ "EbsBlockDevice can't be null"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RunningInstance.EbsBlockDevice> getEbsBlockDevices() {
|
public Multimap<String, RunningInstance.EbsBlockDevice> getEbsBlockDevices() {
|
||||||
return ImmutableList.copyOf(ebsBlockDevices);
|
return ImmutableMultimap.copyOf(ebsBlockDevices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,30 +41,21 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
||||||
|
|
||||||
public static class EbsBlockDevice {
|
public static class EbsBlockDevice {
|
||||||
private final String volumeId;
|
private final String volumeId;
|
||||||
private final String deviceName;
|
|
||||||
private final Attachment.Status attachmentStatus;
|
private final Attachment.Status attachmentStatus;
|
||||||
private final Date attachTime;
|
private final Date attachTime;
|
||||||
private final boolean deleteOnTermination;
|
private final boolean deleteOnTermination;
|
||||||
|
|
||||||
public EbsBlockDevice(String volumeId, Status attachmentStatus, Date attachTime,
|
public EbsBlockDevice(String volumeId, Status attachmentStatus, Date attachTime,
|
||||||
boolean deleteOnTermination) {
|
|
||||||
this(volumeId, null, attachmentStatus, attachTime, deleteOnTermination);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EbsBlockDevice(String volumeId, String deviceName,
|
|
||||||
Status attachmentStatus, Date attachTime,
|
|
||||||
boolean deleteOnTermination) {
|
boolean deleteOnTermination) {
|
||||||
super();
|
super();
|
||||||
this.volumeId = volumeId;
|
this.volumeId = volumeId;
|
||||||
this.attachmentStatus = attachmentStatus;
|
this.attachmentStatus = attachmentStatus;
|
||||||
this.attachTime = attachTime;
|
this.attachTime = attachTime;
|
||||||
this.deleteOnTermination = deleteOnTermination;
|
this.deleteOnTermination = deleteOnTermination;
|
||||||
this.deviceName = deviceName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EbsBlockDevice(String volumeId, String deviceName,
|
public EbsBlockDevice(String volumeId, boolean deleteOnTermination) {
|
||||||
boolean deleteOnTermination) {
|
this(volumeId, null, null, deleteOnTermination);
|
||||||
this(volumeId, deviceName, null, null, deleteOnTermination);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -92,11 +83,6 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
||||||
return false;
|
return false;
|
||||||
} else if (!attachTime.equals(other.attachTime))
|
} else if (!attachTime.equals(other.attachTime))
|
||||||
return false;
|
return false;
|
||||||
if (deviceName == null) {
|
|
||||||
if (other.deviceName != null)
|
|
||||||
return false;
|
|
||||||
} else if (!deviceName.equals(other.deviceName))
|
|
||||||
return false;
|
|
||||||
if (attachmentStatus == null) {
|
if (attachmentStatus == null) {
|
||||||
if (other.attachmentStatus != null)
|
if (other.attachmentStatus != null)
|
||||||
return false;
|
return false;
|
||||||
|
@ -116,10 +102,6 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
||||||
return volumeId;
|
return volumeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDeviceName() {
|
|
||||||
return deviceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Attachment.Status getAttachmentStatus() {
|
public Attachment.Status getAttachmentStatus() {
|
||||||
return attachmentStatus;
|
return attachmentStatus;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,7 @@ public class BlockDeviceMappingHandler extends
|
||||||
} else if (qName.equals("attachTime")) {
|
} else if (qName.equals("attachTime")) {
|
||||||
attachTime = dateService.iso8601DateParse(currentText.toString().trim());
|
attachTime = dateService.iso8601DateParse(currentText.toString().trim());
|
||||||
} else if (qName.equals("item")) {
|
} else if (qName.equals("item")) {
|
||||||
ebsBlockDevices.put(deviceName, new EbsBlockDevice(volumeId, deviceName,
|
ebsBlockDevices.put(deviceName, new EbsBlockDevice(volumeId, attachmentStatus, attachTime, deleteOnTermination));
|
||||||
attachmentStatus, attachTime, deleteOnTermination));
|
|
||||||
this.volumeId = null;
|
this.volumeId = null;
|
||||||
this.deviceName = null;
|
this.deviceName = null;
|
||||||
this.deleteOnTermination = true;
|
this.deleteOnTermination = true;
|
||||||
|
|
|
@ -72,9 +72,9 @@ import com.google.inject.internal.ImmutableMap;
|
||||||
* Adapted from the following sources: {@link http://gist.github.com/249915}, {@link http
|
* Adapted from the following sources: {@link http://gist.github.com/249915}, {@link http
|
||||||
* ://www.capsunlock.net/2009/12/create-ebs-boot-ami.html}
|
* ://www.capsunlock.net/2009/12/create-ebs-boot-ami.html}
|
||||||
* <p/>
|
* <p/>
|
||||||
*
|
*
|
||||||
* Generally disabled, as it incurs higher fees.
|
* Generally disabled, as it incurs higher fees.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", enabled = false, sequential = true, testName = "ec2.EBSBootEC2ClientLiveTest")
|
@Test(groups = "live", enabled = false, sequential = true, testName = "ec2.EBSBootEC2ClientLiveTest")
|
||||||
|
@ -448,9 +448,11 @@ public class EBSBootEC2ClientLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBlockDeviceMappingForInstanceInRegion() {
|
private void setBlockDeviceMappingForInstanceInRegion() {
|
||||||
|
String volumeId = ebsInstance.getEbsBlockDevices().get("/dev/sda1").getVolumeId();
|
||||||
|
|
||||||
BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
|
BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
|
||||||
blockDeviceMapping.addEbsBlockDevice
|
blockDeviceMapping.addEbsBlockDevice
|
||||||
(new RunningInstance.EbsBlockDevice(volume.getId(), "/dev/sda1", false));
|
("/dev/sda1", new RunningInstance.EbsBlockDevice(volumeId, false));
|
||||||
try {
|
try {
|
||||||
client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(Region.DEFAULT,
|
client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(Region.DEFAULT,
|
||||||
ebsInstance.getId(), blockDeviceMapping);
|
ebsInstance.getId(), blockDeviceMapping);
|
||||||
|
@ -459,10 +461,11 @@ public class EBSBootEC2ClientLiveTest {
|
||||||
.getInstanceServices().getBlockDeviceMappingForInstanceInRegion(Region.DEFAULT,
|
.getInstanceServices().getBlockDeviceMappingForInstanceInRegion(Region.DEFAULT,
|
||||||
ebsInstance.getId());
|
ebsInstance.getId());
|
||||||
assertEquals(devices.size(), 1);
|
assertEquals(devices.size(), 1);
|
||||||
|
String deviceName = Iterables.getOnlyElement(devices.keySet());
|
||||||
RunningInstance.EbsBlockDevice device = Iterables.getOnlyElement(devices.values());
|
RunningInstance.EbsBlockDevice device = Iterables.getOnlyElement(devices.values());
|
||||||
|
|
||||||
assertEquals(device.getVolumeId(), volume.getId());
|
assertEquals(device.getVolumeId(), volumeId);
|
||||||
assertEquals(device.getDeviceName(), "/dev/sda1");
|
assertEquals(deviceName, "/dev/sda1");
|
||||||
assertEquals(device.isDeleteOnTermination(), false);
|
assertEquals(device.isDeleteOnTermination(), false);
|
||||||
|
|
||||||
System.out.println("OK: setBlockDeviceMappingForInstanceInRegion");
|
System.out.println("OK: setBlockDeviceMappingForInstanceInRegion");
|
||||||
|
@ -497,7 +500,7 @@ public class EBSBootEC2ClientLiveTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this tests "personality" as the file looked up was sent during instance creation
|
* this tests "personality" as the file looked up was sent during instance creation
|
||||||
*
|
*
|
||||||
* @throws UnknownHostException
|
* @throws UnknownHostException
|
||||||
*/
|
*/
|
||||||
private void sshPing(RunningInstance newDetails) throws UnknownHostException {
|
private void sshPing(RunningInstance newDetails) throws UnknownHostException {
|
||||||
|
|
|
@ -529,7 +529,7 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
|
||||||
|
|
||||||
BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
|
BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
|
||||||
blockDeviceMapping.addEbsBlockDevice
|
blockDeviceMapping.addEbsBlockDevice
|
||||||
(new RunningInstance.EbsBlockDevice("/dev/sda1", "vol-test1", true));
|
("/dev/sda1", new RunningInstance.EbsBlockDevice("vol-test1", true));
|
||||||
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
|
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
|
||||||
Region.DEFAULT, "1", blockDeviceMapping);
|
Region.DEFAULT, "1", blockDeviceMapping);
|
||||||
|
|
||||||
|
@ -538,11 +538,11 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
|
||||||
"Content-Length: 62\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
|
"Content-Length: 62\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
httpMethod,
|
httpMethod,
|
||||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&InstanceId=1&BlockDeviceMapping.1.Ebs.VolumeId=%2Fdev%2Fsda1&BlockDeviceMapping.1.DeviceName=vol-test1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true");
|
"Version=2009-11-30&Action=ModifyInstanceAttribute&InstanceId=1&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true");
|
||||||
filter.filter(httpMethod);// ensure encoding worked properly
|
filter.filter(httpMethod);// ensure encoding worked properly
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
httpMethod,
|
httpMethod,
|
||||||
"Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=vol-test1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=%2Fdev%2Fsda1&InstanceId=1&Signature=Htpx4bm6v0O%2FcYxrsGb74NbTzCJfPtKWeuB8l2TpL%2B0%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2009-11-30&AWSAccessKeyId=user");
|
"Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&InstanceId=1&Signature=ME8%2FNeH5Zs3%2FY4otsKB0Q09mipVwoEkroUEChQ%2FMZao%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2009-11-30&AWSAccessKeyId=user");
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
|
|
@ -46,12 +46,10 @@ public class BlockDeviceMappingHandlerTest extends BaseHandlerTest {
|
||||||
|
|
||||||
DateService dateService = injector.getInstance(DateService.class);
|
DateService dateService = injector.getInstance(DateService.class);
|
||||||
Map<String, EbsBlockDevice> expected = ImmutableMap.<String, EbsBlockDevice> of("/dev/sda1",
|
Map<String, EbsBlockDevice> expected = ImmutableMap.<String, EbsBlockDevice> of("/dev/sda1",
|
||||||
new EbsBlockDevice("vol-d74b82be", "/dev/sda1",
|
new EbsBlockDevice("vol-d74b82be", Attachment.Status.ATTACHED,
|
||||||
Attachment.Status.ATTACHED,
|
|
||||||
dateService.iso8601DateParse("2010-02-20T18:25:26.000Z"), true),
|
dateService.iso8601DateParse("2010-02-20T18:25:26.000Z"), true),
|
||||||
"/dev/sdf",
|
"/dev/sdf",
|
||||||
new EbsBlockDevice("vol-another", "/dev/sdf",
|
new EbsBlockDevice("vol-another", Attachment.Status.DETACHED,
|
||||||
Attachment.Status.DETACHED,
|
|
||||||
dateService.iso8601DateParse("2010-02-20T19:26:26.000Z"), false)
|
dateService.iso8601DateParse("2010-02-20T19:26:26.000Z"), false)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue