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 e0a6df1544
commit 5e5f50516a
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.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<BlockDevice> getBlockDevices(VirtualGuest virtualGuest) {
private List<BlockDevice> getBlockDevices(VirtualGuest virtualGuest) {
if (virtualGuest.getVirtualGuestBlockDevices() == null) {
return null;
}
ImmutableSortedSet.Builder<BlockDevice> blockDevices = ImmutableSortedSet.orderedBy(new BlockDevicesComparator());
List<BlockDevice> 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<NetworkComponent> getNetworkComponents(VirtualGuest virtualGuest) {
@ -120,12 +123,12 @@ public class VirtualGuestToJson implements Binder {
private final boolean localDiskFlag;
private final Datacenter datacenter;
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,
String operatingSystemReferenceCode, BlockDeviceTemplateGroup blockDeviceTemplateGroup,
boolean localDiskFlag, Datacenter datacenter, Set<NetworkComponent> networkComponents,
Set<BlockDevice> blockDevices) {
List<BlockDevice> blockDevices) {
this.hostname = hostname;
this.domain = domain;
this.startCpus = startCpus;

View File

@ -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<VirtualGuestBlockDevice> blockDevices = getBlockDevices(templateOptions.getBlockDevices().get(), diskType);
List<VirtualGuestBlockDevice> 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<VirtualGuestBlockDevice> getBlockDevices(List<Integer> blockDeviceCapacities, String diskType) {
Set<VirtualGuestBlockDevice> blockDevices = Sets.newHashSet();
private List<VirtualGuestBlockDevice> getBlockDevices(List<Integer> blockDeviceCapacities, String diskType) {
List<VirtualGuestBlockDevice> blockDevices = Lists.newArrayList();
int devicePosition = 0;
for (int i = 0; i < blockDeviceCapacities.size(); i++) {
if (i > 0) { devicePosition = i + 1; }

View File

@ -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<VirtualGuestBlockDevice> blockDevices;
protected List<VirtualGuestBlockDevice> blockDevices;
protected boolean localDiskFlag;
protected VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup;
protected Set<VirtualGuestNetworkComponent> networkComponents;
@ -350,13 +352,13 @@ public class VirtualGuest {
/**
* @see VirtualGuest#getVirtualGuestBlockDevices()
*/
public T blockDevices(Set<VirtualGuestBlockDevice> blockDevices) {
this.blockDevices = ImmutableSet.copyOf(checkNotNull(blockDevices, "blockDevices"));
public T blockDevices(List<VirtualGuestBlockDevice> 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<VirtualGuestBlockDevice> blockDevices;
private final List<VirtualGuestBlockDevice> blockDevices;
private final boolean localDiskFlag;
private final VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup;
private final Set<VirtualGuestNetworkComponent> 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<VirtualGuestBlockDevice> blockDevices,
int activeTransactionCount, @Nullable List<VirtualGuestBlockDevice> blockDevices,
boolean localDiskFlag, @Nullable VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup,
@Nullable Set<VirtualGuestNetworkComponent> networkComponents,
@Nullable Set<TagReference> tagReferences ) {
@ -726,7 +728,7 @@ public class VirtualGuest {
}
@Nullable
public Set<VirtualGuestBlockDevice> getVirtualGuestBlockDevices() {
public List<VirtualGuestBlockDevice> getVirtualGuestBlockDevices() {
return blockDevices;
}

View File

@ -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"));