From af31b9ac9558506ec9d8913a4d566d15940d76ab 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 ++-- .../strategy/SoftLayerComputeServiceAdapter.java | 84 +++++++++++----------- .../org/jclouds/softlayer/domain/VirtualGuest.java | 16 +++-- .../SoftLayerComputeServiceContextLiveTest.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 a9025e2..ddb9fdc 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 @@ 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.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 @@ String buildJson(VirtualGuest virtualGuest) { 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 @@ String buildJson(VirtualGuest virtualGuest) { 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 976e8bb..7ef331b 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.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 SoftLayerComputeServiceAdapter(SoftLayerApi api, } // 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 SoftLayerComputeServiceAdapter(SoftLayerApi api, * @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 39b99c1..e01b5a3 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,6 +19,7 @@ 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; @@ -26,6 +27,7 @@ import com.google.common.base.CaseFormat; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; /** @@ -126,7 +128,7 @@ public String toString() { protected PowerState powerState; protected SoftwareLicense softwareLicense; protected int activeTransactionCount; - protected Set blockDevices; + protected List blockDevices; protected boolean localDiskFlag; protected VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup; protected Set networkComponents; @@ -351,13 +353,13 @@ public T activeTransactionCount(int activeTransactionCount) { /** * @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) { @@ -466,7 +468,7 @@ protected ConcreteBuilder self() { 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; @@ -486,7 +488,7 @@ protected VirtualGuest(int accountId, @Nullable Date createDate, boolean dedicat @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 ) { @@ -727,7 +729,7 @@ public int getActiveTransactionCount() { } @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 6c6fb51..854d01a 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.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 void testLaunchClusterWithMinDisk() throws RunNodesException { .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")); -- 2.0.3