JCLOUDS-662: Support multiple disks with the same size using SoftLayerTemplateOptions

This commit is contained in:
Andrea Turli 2014-08-12 14:45:35 +02:00 committed by Andrew Phillips
parent 204a6c7f3b
commit 8743e947be
4 changed files with 72 additions and 71 deletions

View File

@ -19,7 +19,7 @@ package org.jclouds.softlayer.binders;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Lists;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json; import org.jclouds.json.Json;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
@ -28,7 +28,9 @@ import org.jclouds.softlayer.domain.VirtualGuestBlockDevice;
import org.jclouds.softlayer.domain.VirtualGuestNetworkComponent; import org.jclouds.softlayer.domain.VirtualGuestNetworkComponent;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import java.util.Set; import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
@ -87,15 +89,16 @@ public class VirtualGuestToJson implements Binder {
return json.toJson(ImmutableMap.of("parameters", ImmutableList.of(templateObject))); return json.toJson(ImmutableMap.of("parameters", ImmutableList.of(templateObject)));
} }
private Set<BlockDevice> getBlockDevices(VirtualGuest virtualGuest) { private List<BlockDevice> getBlockDevices(VirtualGuest virtualGuest) {
if (virtualGuest.getVirtualGuestBlockDevices() == null) { if (virtualGuest.getVirtualGuestBlockDevices() == null) {
return null; return null;
} }
ImmutableSortedSet.Builder<BlockDevice> blockDevices = ImmutableSortedSet.orderedBy(new BlockDevicesComparator()); List<BlockDevice> blockDevices = Lists.newArrayList();
for (VirtualGuestBlockDevice blockDevice : virtualGuest.getVirtualGuestBlockDevices()) { for (VirtualGuestBlockDevice blockDevice : virtualGuest.getVirtualGuestBlockDevices()) {
blockDevices.add(new BlockDevice(blockDevice.getDevice(), blockDevice.getVirtualDiskImage().getCapacity())); blockDevices.add(new BlockDevice(blockDevice.getDevice(), blockDevice.getVirtualDiskImage().getCapacity()));
} }
return blockDevices.build(); Collections.sort(blockDevices, new BlockDevicesComparator());
return ImmutableList.copyOf(blockDevices);
} }
private Set<NetworkComponent> getNetworkComponents(VirtualGuest virtualGuest) { private Set<NetworkComponent> getNetworkComponents(VirtualGuest virtualGuest) {
@ -120,12 +123,12 @@ public class VirtualGuestToJson implements Binder {
private final boolean localDiskFlag; private final boolean localDiskFlag;
private final Datacenter datacenter; private final Datacenter datacenter;
private final Set<NetworkComponent> networkComponents; private final Set<NetworkComponent> networkComponents;
private final Set<BlockDevice> blockDevices; private final List<BlockDevice> blockDevices;
private TemplateObject(String hostname, String domain, int startCpus, int maxMemory, boolean hourlyBillingFlag, private TemplateObject(String hostname, String domain, int startCpus, int maxMemory, boolean hourlyBillingFlag,
String operatingSystemReferenceCode, BlockDeviceTemplateGroup blockDeviceTemplateGroup, String operatingSystemReferenceCode, BlockDeviceTemplateGroup blockDeviceTemplateGroup,
boolean localDiskFlag, Datacenter datacenter, Set<NetworkComponent> networkComponents, boolean localDiskFlag, Datacenter datacenter, Set<NetworkComponent> networkComponents,
Set<BlockDevice> blockDevices) { List<BlockDevice> blockDevices) {
this.hostname = hostname; this.hostname = hostname;
this.domain = domain; this.domain = domain;
this.startCpus = startCpus; this.startCpus = startCpus;

View File

@ -16,18 +16,33 @@
*/ */
package org.jclouds.softlayer.compute.strategy; package org.jclouds.softlayer.compute.strategy;
import com.google.common.base.Function; import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.base.Optional; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Predicate; import static com.google.common.base.Preconditions.checkState;
import com.google.common.base.Predicates; import static com.google.common.collect.Iterables.contains;
import com.google.common.base.Supplier; import static com.google.common.collect.Iterables.filter;
import com.google.common.collect.ComparisonChain; import static com.google.common.collect.Iterables.find;
import com.google.common.collect.FluentIterable; import static com.google.common.collect.Iterables.get;
import com.google.common.collect.ImmutableList; import static com.google.common.collect.Iterables.tryFind;
import com.google.common.collect.ImmutableSet.Builder; import static java.lang.Math.round;
import com.google.common.collect.ImmutableSortedSet; import static java.lang.String.format;
import com.google.common.collect.Maps; import static org.jclouds.compute.domain.Volume.Type;
import com.google.common.collect.Sets; import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_INCLUDE_PUBLIC_IMAGES;
import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_ACTIVE_TRANSACTIONS_DELAY;
import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY;
import static org.jclouds.util.Predicates2.retry;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
@ -55,32 +70,19 @@ import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplate;
import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup; import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup;
import org.jclouds.softlayer.domain.VirtualGuestNetworkComponent; import org.jclouds.softlayer.domain.VirtualGuestNetworkComponent;
import javax.annotation.Resource; import com.google.common.base.Function;
import javax.inject.Inject; import com.google.common.base.Optional;
import javax.inject.Named; import com.google.common.base.Predicate;
import javax.inject.Singleton; import com.google.common.base.Predicates;
import java.util.Comparator; import com.google.common.base.Supplier;
import java.util.List; import com.google.common.collect.ComparisonChain;
import java.util.Map; import com.google.common.collect.FluentIterable;
import java.util.Set; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet.Builder;
import static com.google.common.base.Preconditions.checkArgument; import com.google.common.collect.ImmutableSortedSet;
import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.Lists;
import static com.google.common.base.Preconditions.checkState; import com.google.common.collect.Maps;
import static com.google.common.collect.Iterables.contains; import com.google.common.collect.Sets;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Iterables.tryFind;
import static java.lang.Math.round;
import static java.lang.String.format;
import static org.jclouds.compute.domain.Volume.Type;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_INCLUDE_PUBLIC_IMAGES;
import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_ACTIVE_TRANSACTIONS_DELAY;
import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY;
import static org.jclouds.util.Predicates2.retry;
/** /**
* defines the connection between the {@link SoftLayerApi} implementation and * defines the connection between the {@link SoftLayerApi} implementation and
@ -160,7 +162,7 @@ public class SoftLayerComputeServiceAdapter implements
} }
// set multi-disks // set multi-disks
if (templateOptions.getBlockDevices().isPresent()) { if (templateOptions.getBlockDevices().isPresent()) {
Set<VirtualGuestBlockDevice> blockDevices = getBlockDevices(templateOptions.getBlockDevices().get(), diskType); List<VirtualGuestBlockDevice> blockDevices = getBlockDevices(templateOptions.getBlockDevices().get(), diskType);
virtualGuestBuilder.blockDevices(blockDevices); virtualGuestBuilder.blockDevices(blockDevices);
virtualGuestBuilder.localDiskFlag(isLocalDisk(diskType)); virtualGuestBuilder.localDiskFlag(isLocalDisk(diskType));
} }
@ -199,8 +201,8 @@ public class SoftLayerComputeServiceAdapter implements
* @param diskType disks can be LOCAL or SAN * @param diskType disks can be LOCAL or SAN
* @return * @return
*/ */
private Set<VirtualGuestBlockDevice> getBlockDevices(List<Integer> blockDeviceCapacities, String diskType) { private List<VirtualGuestBlockDevice> getBlockDevices(List<Integer> blockDeviceCapacities, String diskType) {
Set<VirtualGuestBlockDevice> blockDevices = Sets.newHashSet(); List<VirtualGuestBlockDevice> blockDevices = Lists.newArrayList();
int devicePosition = 0; int devicePosition = 0;
for (int i = 0; i < blockDeviceCapacities.size(); i++) { for (int i = 0; i < blockDeviceCapacities.size(); i++) {
if (i > 0) { devicePosition = i + 1; } if (i > 0) { devicePosition = i + 1; }

View File

@ -19,6 +19,7 @@ package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties; import java.beans.ConstructorProperties;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
@ -26,6 +27,7 @@ import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.CaseFormat; import com.google.common.base.CaseFormat;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
/** /**
@ -126,7 +128,7 @@ public class VirtualGuest {
protected PowerState powerState; protected PowerState powerState;
protected SoftwareLicense softwareLicense; protected SoftwareLicense softwareLicense;
protected int activeTransactionCount; protected int activeTransactionCount;
protected Set<VirtualGuestBlockDevice> blockDevices; protected List<VirtualGuestBlockDevice> blockDevices;
protected boolean localDiskFlag; protected boolean localDiskFlag;
protected VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup; protected VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup;
protected Set<VirtualGuestNetworkComponent> networkComponents; protected Set<VirtualGuestNetworkComponent> networkComponents;
@ -351,13 +353,13 @@ public class VirtualGuest {
/** /**
* @see VirtualGuest#getVirtualGuestBlockDevices() * @see VirtualGuest#getVirtualGuestBlockDevices()
*/ */
public T blockDevices(Set<VirtualGuestBlockDevice> blockDevices) { public T blockDevices(List<VirtualGuestBlockDevice> blockDevices) {
this.blockDevices = ImmutableSet.copyOf(checkNotNull(blockDevices, "blockDevices")); this.blockDevices = ImmutableList.copyOf(checkNotNull(blockDevices, "blockDevices"));
return self(); return self();
} }
public T blockDevices(VirtualGuestBlockDevice... in) { public T blockDevices(VirtualGuestBlockDevice... in) {
return blockDevices(ImmutableSet.copyOf(checkNotNull(in, "blockDevices"))); return blockDevices(ImmutableList.copyOf(checkNotNull(in, "blockDevices")));
} }
public T localDiskFlag(boolean localDiskFlag) { public T localDiskFlag(boolean localDiskFlag) {
@ -466,7 +468,7 @@ public class VirtualGuest {
private final PowerState powerState; private final PowerState powerState;
private final SoftwareLicense softwareLicense; private final SoftwareLicense softwareLicense;
private final int activeTransactionCount; private final int activeTransactionCount;
private final Set<VirtualGuestBlockDevice> blockDevices; private final List<VirtualGuestBlockDevice> blockDevices;
private final boolean localDiskFlag; private final boolean localDiskFlag;
private final VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup; private final VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup;
private final Set<VirtualGuestNetworkComponent> networkComponents; private final Set<VirtualGuestNetworkComponent> networkComponents;
@ -486,7 +488,7 @@ public class VirtualGuest {
@Nullable String primaryBackendIpAddress, @Nullable String primaryIpAddress, @Nullable BillingItem billingItem, @Nullable String primaryBackendIpAddress, @Nullable String primaryIpAddress, @Nullable BillingItem billingItem,
@Nullable OperatingSystem operatingSystem, @Nullable String operatingSystemReferenceCode, @Nullable OperatingSystem operatingSystem, @Nullable String operatingSystemReferenceCode,
@Nullable Datacenter datacenter, @Nullable PowerState powerState, @Nullable SoftwareLicense softwareLicense, @Nullable Datacenter datacenter, @Nullable PowerState powerState, @Nullable SoftwareLicense softwareLicense,
int activeTransactionCount, @Nullable Set<VirtualGuestBlockDevice> blockDevices, int activeTransactionCount, @Nullable List<VirtualGuestBlockDevice> blockDevices,
boolean localDiskFlag, @Nullable VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup, boolean localDiskFlag, @Nullable VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup,
@Nullable Set<VirtualGuestNetworkComponent> networkComponents, @Nullable Set<VirtualGuestNetworkComponent> networkComponents,
@Nullable Set<TagReference> tagReferences ) { @Nullable Set<TagReference> tagReferences ) {
@ -727,7 +729,7 @@ public class VirtualGuest {
} }
@Nullable @Nullable
public Set<VirtualGuestBlockDevice> getVirtualGuestBlockDevices() { public List<VirtualGuestBlockDevice> getVirtualGuestBlockDevices() {
return blockDevices; return blockDevices;
} }

View File

@ -16,8 +16,12 @@
*/ */
package org.jclouds.softlayer.compute; package org.jclouds.softlayer.compute;
import com.google.common.collect.ImmutableList; import static org.testng.Assert.assertEquals;
import com.google.common.collect.ImmutableSet; import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.ContextBuilder; import org.jclouds.ContextBuilder;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.RunNodesException; import org.jclouds.compute.RunNodesException;
@ -37,11 +41,8 @@ import org.jclouds.ssh.SshClient;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import javax.annotation.Resource; import com.google.common.collect.ImmutableList;
import javax.inject.Named; import com.google.common.collect.ImmutableSet;
import java.util.Set;
import static org.testng.Assert.assertEquals;
@Test(groups = "live", testName = "SoftLayerComputeServiceContextLiveTest") @Test(groups = "live", testName = "SoftLayerComputeServiceContextLiveTest")
public class SoftLayerComputeServiceContextLiveTest extends BaseComputeServiceContextLiveTest { public class SoftLayerComputeServiceContextLiveTest extends BaseComputeServiceContextLiveTest {
@ -65,23 +66,16 @@ public class SoftLayerComputeServiceContextLiveTest extends BaseComputeServiceCo
.build(ComputeServiceContext.class); .build(ComputeServiceContext.class);
TemplateBuilder templateBuilder = context.getComputeService().templateBuilder(); TemplateBuilder templateBuilder = context.getComputeService().templateBuilder();
//templateBuilder.minDisk(15d);
//templateBuilder.hardwareId("cpu=1,memory=4096,disk=100,type=SAN");
//templateBuilder.hardwareId("cpu=1,memory=4096,disk=100,type=LOCAL");
templateBuilder.imageId("CENTOS_6_64"); templateBuilder.imageId("CENTOS_6_64");
//templateBuilder.osFamily(OsFamily.CENTOS); templateBuilder.locationId("ams01");
//templateBuilder.imageId("7bcd78dc-eb11-4e1b-8d93-111c62ed5fd1");
//templateBuilder.locationId("dal01");
//templateBuilder.minRam(8192);
Template template = templateBuilder.build(); Template template = templateBuilder.build();
// test passing custom options // test passing custom options
SoftLayerTemplateOptions options = template.getOptions().as(SoftLayerTemplateOptions.class); SoftLayerTemplateOptions options = template.getOptions().as(SoftLayerTemplateOptions.class);
options.domainName("live.org"); options.domainName("live.org");
//options.diskType("SAN");
//options.portSpeed(10);
// multi-disk option // multi-disk option
options.blockDevices(ImmutableSet.of(100)); options.blockDevices(ImmutableList.of(25, 400, 400));
options.diskType("SAN");
//tags //tags
options.tags(ImmutableList.of("jclouds")); options.tags(ImmutableList.of("jclouds"));