From 5e5f50516adf0719a0e9cca34b26b139647844c2 Mon Sep 17 00:00:00 2001 From: Andrea Turli Date: Tue, 12 Aug 2014 14:45:35 +0200 Subject: [PATCH] JCLOUDS-662: Support multiple disks with the same size using SoftLayerTemplateOptions --- .../softlayer/binders/VirtualGuestToJson.java | 15 ++-- .../SoftLayerComputeServiceAdapter.java | 84 ++++++++++--------- .../softlayer/domain/VirtualGuest.java | 16 ++-- ...oftLayerComputeServiceContextLiveTest.java | 28 +++---- 4 files changed, 72 insertions(+), 71 deletions(-) diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/binders/VirtualGuestToJson.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/binders/VirtualGuestToJson.java index a9025e233f..ddb9fdcd87 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/binders/VirtualGuestToJson.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/binders/VirtualGuestToJson.java @@ -19,7 +19,7 @@ package org.jclouds.softlayer.binders; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; 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.json.Json; import org.jclouds.rest.Binder; @@ -28,7 +28,9 @@ import org.jclouds.softlayer.domain.VirtualGuestBlockDevice; import org.jclouds.softlayer.domain.VirtualGuestNetworkComponent; import javax.inject.Inject; +import java.util.Collections; import java.util.Comparator; +import java.util.List; import java.util.Set; 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))); } - private Set getBlockDevices(VirtualGuest virtualGuest) { + private List getBlockDevices(VirtualGuest virtualGuest) { if (virtualGuest.getVirtualGuestBlockDevices() == null) { return null; } - ImmutableSortedSet.Builder blockDevices = ImmutableSortedSet.orderedBy(new BlockDevicesComparator()); + List blockDevices = Lists.newArrayList(); for (VirtualGuestBlockDevice blockDevice : virtualGuest.getVirtualGuestBlockDevices()) { blockDevices.add(new BlockDevice(blockDevice.getDevice(), blockDevice.getVirtualDiskImage().getCapacity())); } - return blockDevices.build(); + Collections.sort(blockDevices, new BlockDevicesComparator()); + return ImmutableList.copyOf(blockDevices); } private Set getNetworkComponents(VirtualGuest virtualGuest) { @@ -120,12 +123,12 @@ public class VirtualGuestToJson implements Binder { private final boolean localDiskFlag; private final Datacenter datacenter; private final Set networkComponents; - private final Set blockDevices; + private final List blockDevices; private TemplateObject(String hostname, String domain, int startCpus, int maxMemory, boolean hourlyBillingFlag, String operatingSystemReferenceCode, BlockDeviceTemplateGroup blockDeviceTemplateGroup, boolean localDiskFlag, Datacenter datacenter, Set networkComponents, - Set blockDevices) { + List blockDevices) { this.hostname = hostname; this.domain = domain; this.startCpus = startCpus; diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java index 976e8bb74b..7ef331bf2c 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java @@ -16,18 +16,33 @@ */ package org.jclouds.softlayer.compute.strategy; -import com.google.common.base.Function; -import com.google.common.base.Optional; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.base.Supplier; -import com.google.common.collect.ComparisonChain; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet.Builder; -import com.google.common.collect.ImmutableSortedSet; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.Iterables.contains; +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; +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.compute.ComputeServiceAdapter; 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.VirtualGuestNetworkComponent; -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.collect.Iterables.contains; -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; +import com.google.common.base.Function; +import com.google.common.base.Optional; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.base.Supplier; +import com.google.common.collect.ComparisonChain; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet.Builder; +import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; /** * defines the connection between the {@link SoftLayerApi} implementation and @@ -160,7 +162,7 @@ public class SoftLayerComputeServiceAdapter implements } // set multi-disks if (templateOptions.getBlockDevices().isPresent()) { - Set blockDevices = getBlockDevices(templateOptions.getBlockDevices().get(), diskType); + List blockDevices = getBlockDevices(templateOptions.getBlockDevices().get(), diskType); virtualGuestBuilder.blockDevices(blockDevices); virtualGuestBuilder.localDiskFlag(isLocalDisk(diskType)); } @@ -199,8 +201,8 @@ public class SoftLayerComputeServiceAdapter implements * @param diskType disks can be LOCAL or SAN * @return */ - private Set getBlockDevices(List blockDeviceCapacities, String diskType) { - Set blockDevices = Sets.newHashSet(); + private List getBlockDevices(List blockDeviceCapacities, String diskType) { + List blockDevices = Lists.newArrayList(); int devicePosition = 0; for (int i = 0; i < blockDeviceCapacities.size(); i++) { if (i > 0) { devicePosition = i + 1; } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuest.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuest.java index b407bbb52c..9d1f248fce 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuest.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuest.java @@ -19,12 +19,14 @@ package org.jclouds.softlayer.domain; import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; import java.util.Date; +import java.util.List; import java.util.Set; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.CaseFormat; import com.google.common.base.Objects; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; /** @@ -125,7 +127,7 @@ public class VirtualGuest { protected PowerState powerState; protected SoftwareLicense softwareLicense; protected int activeTransactionCount; - protected Set blockDevices; + protected List blockDevices; protected boolean localDiskFlag; protected VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup; protected Set networkComponents; @@ -350,13 +352,13 @@ public class VirtualGuest { /** * @see VirtualGuest#getVirtualGuestBlockDevices() */ - public T blockDevices(Set blockDevices) { - this.blockDevices = ImmutableSet.copyOf(checkNotNull(blockDevices, "blockDevices")); + public T blockDevices(List blockDevices) { + this.blockDevices = ImmutableList.copyOf(checkNotNull(blockDevices, "blockDevices")); return self(); } public T blockDevices(VirtualGuestBlockDevice... in) { - return blockDevices(ImmutableSet.copyOf(checkNotNull(in, "blockDevices"))); + return blockDevices(ImmutableList.copyOf(checkNotNull(in, "blockDevices"))); } public T localDiskFlag(boolean localDiskFlag) { @@ -465,7 +467,7 @@ public class VirtualGuest { private final PowerState powerState; private final SoftwareLicense softwareLicense; private final int activeTransactionCount; - private final Set blockDevices; + private final List blockDevices; private final boolean localDiskFlag; private final VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup; private final Set networkComponents; @@ -485,7 +487,7 @@ public class VirtualGuest { @Nullable String primaryBackendIpAddress, @Nullable String primaryIpAddress, @Nullable BillingItem billingItem, @Nullable OperatingSystem operatingSystem, @Nullable String operatingSystemReferenceCode, @Nullable Datacenter datacenter, @Nullable PowerState powerState, @Nullable SoftwareLicense softwareLicense, - int activeTransactionCount, @Nullable Set blockDevices, + int activeTransactionCount, @Nullable List blockDevices, boolean localDiskFlag, @Nullable VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup, @Nullable Set networkComponents, @Nullable Set tagReferences ) { @@ -726,7 +728,7 @@ public class VirtualGuest { } @Nullable - public Set getVirtualGuestBlockDevices() { + public List getVirtualGuestBlockDevices() { return blockDevices; } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceContextLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceContextLiveTest.java index 6c6fb51757..854d01a5b2 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceContextLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceContextLiveTest.java @@ -16,8 +16,12 @@ */ package org.jclouds.softlayer.compute; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; +import static org.testng.Assert.assertEquals; +import java.util.Set; + +import javax.annotation.Resource; +import javax.inject.Named; + import org.jclouds.ContextBuilder; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.RunNodesException; @@ -37,11 +41,8 @@ import org.jclouds.ssh.SshClient; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.Test; -import javax.annotation.Resource; -import javax.inject.Named; -import java.util.Set; - -import static org.testng.Assert.assertEquals; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; @Test(groups = "live", testName = "SoftLayerComputeServiceContextLiveTest") public class SoftLayerComputeServiceContextLiveTest extends BaseComputeServiceContextLiveTest { @@ -65,23 +66,16 @@ public class SoftLayerComputeServiceContextLiveTest extends BaseComputeServiceCo .build(ComputeServiceContext.class); 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.osFamily(OsFamily.CENTOS); - //templateBuilder.imageId("7bcd78dc-eb11-4e1b-8d93-111c62ed5fd1"); - //templateBuilder.locationId("dal01"); - //templateBuilder.minRam(8192); + templateBuilder.locationId("ams01"); Template template = templateBuilder.build(); // test passing custom options SoftLayerTemplateOptions options = template.getOptions().as(SoftLayerTemplateOptions.class); options.domainName("live.org"); - //options.diskType("SAN"); - //options.portSpeed(10); // multi-disk option - options.blockDevices(ImmutableSet.of(100)); + options.blockDevices(ImmutableList.of(25, 400, 400)); + options.diskType("SAN"); //tags options.tags(ImmutableList.of("jclouds"));