diff --git a/providers/softlayer/pom.xml b/providers/softlayer/pom.xml index 36bae9794c2..39481efff60 100644 --- a/providers/softlayer/pom.xml +++ b/providers/softlayer/pom.xml @@ -82,15 +82,20 @@ org.apache.jclouds.driver - jclouds-log4j + jclouds-sshj ${project.version} test - org.apache.jclouds.driver - jclouds-sshj - ${project.version} - test + org.apache.jclouds.driver + jclouds-slf4j + ${project.version} + test + + + ch.qos.logback + logback-classic + test diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerApi.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerApi.java index 98383b7a88c..5c579189137 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerApi.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerApi.java @@ -16,43 +16,43 @@ */ package org.jclouds.softlayer; -import java.io.Closeable; - import org.jclouds.rest.annotations.Delegate; import org.jclouds.softlayer.features.AccountApi; import org.jclouds.softlayer.features.DatacenterApi; -import org.jclouds.softlayer.features.ProductPackageApi; +import org.jclouds.softlayer.features.SoftwareDescriptionApi; import org.jclouds.softlayer.features.VirtualGuestApi; +import org.jclouds.softlayer.features.VirtualGuestBlockDeviceTemplateGroupApi; + +import java.io.Closeable; -/** - * Provides synchronous access to SoftLayer. - *

- * - * @see - * @author Adrian Cole - */ public interface SoftLayerApi extends Closeable { /** - * Provides synchronous access to VirtualGuest features. + * Provides access to VirtualGuest features. */ @Delegate VirtualGuestApi getVirtualGuestApi(); /** - * Provides synchronous access to Datacenter features. + * Provides access to Datacenter features. */ @Delegate DatacenterApi getDatacenterApi(); /** - * Provides synchronous access to ProductPackage features. + * Provides access to SoftwareDescription features. + */ + @Delegate + SoftwareDescriptionApi getSoftwareDescriptionApi(); + + /** + * Provides access to VirtualGuestBlockDeviceTemplateGroup features. */ @Delegate - ProductPackageApi getProductPackageApi(); + VirtualGuestBlockDeviceTemplateGroupApi getVirtualGuestBlockDeviceTemplateGroupApi(); /** - * Provides synchronous access to Account features. + * Provides access to Account features. */ @Delegate AccountApi getAccountApi(); diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerApiMetadata.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerApiMetadata.java index 8c62de29387..f6b87365c2d 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerApiMetadata.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerApiMetadata.java @@ -17,7 +17,7 @@ package org.jclouds.softlayer; import static org.jclouds.reflect.Reflection2.typeToken; - +import static org.jclouds.softlayer.reference.SoftLayerConstants.SOFTLAYER_PROVIDER_NAME; import java.net.URI; import java.util.Properties; @@ -30,13 +30,10 @@ import com.google.inject.Module; /** - * Implementation of {@link ApiMetadata} for API - * - * @author Adrian Cole + * Implementation of {@link org.jclouds.apis.ApiMetadata} for API */ public class SoftLayerApiMetadata extends BaseHttpApiMetadata { - @Override public Builder toBuilder() { return new Builder().fromApiMetadata(this); @@ -59,18 +56,18 @@ public static Properties defaultProperties() { public static class Builder extends BaseHttpApiMetadata.Builder { - @SuppressWarnings("deprecation") protected Builder() { - id("softlayer") - .name("SoftLayer API") - .identityName("API Username") - .credentialName("API Key") - .documentation(URI.create("http://sldn.softlayer.com/article/REST")) - .version("3") - .defaultEndpoint("https://api.softlayer.com/rest") - .defaultProperties(SoftLayerApiMetadata.defaultProperties()) - .view(typeToken(ComputeServiceContext.class)) - .defaultModules(ImmutableSet.>of(SoftLayerHttpApiModule.class, SoftLayerComputeServiceContextModule.class)); + id(SOFTLAYER_PROVIDER_NAME) + .name("SoftLayer API") + .identityName("API Username") + .credentialName("API Key") + .documentation(URI.create("http://sldn.softlayer.com/article/REST")) + .version("3") + .defaultEndpoint("https://api.softlayer.com/rest") + .defaultProperties(SoftLayerApiMetadata.defaultProperties()) + .view(typeToken(ComputeServiceContext.class)) + .defaultModules(ImmutableSet.>of(SoftLayerHttpApiModule.class, + SoftLayerComputeServiceContextModule.class)).build(); } @Override diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerProviderMetadata.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerProviderMetadata.java index 7efda6f24c2..e0a8e1b1121 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerProviderMetadata.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerProviderMetadata.java @@ -17,25 +17,17 @@ package org.jclouds.softlayer; import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_DISK0_TYPE; +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.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PORT_SPEED; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES; - import java.net.URI; import java.util.Properties; import org.jclouds.providers.ProviderMetadata; import org.jclouds.providers.internal.BaseProviderMetadata; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableSet; - /** - * Implementation of {@link org.jclouds.types.ProviderMetadata} for SoftLayer. - * @author Adrian Cole + * Implementation of {@link org.jclouds.providers.ProviderMetadata} for SoftLayer. */ public class SoftLayerProviderMetadata extends BaseProviderMetadata { @@ -59,27 +51,9 @@ public SoftLayerProviderMetadata(Builder builder) { public static Properties defaultProperties() { Properties properties = new Properties(); properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY, "" + 60 * 60 * 1000); - properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME, "Cloud Server"); - // ex: for private (ex. don't share hardware) use "Private [0-9]+ x ([.0-9]+) GHz Core[s]?" - // ex: for private and public use ".*[0-9]+ x ([.0-9]+) GHz Core[s]?" - properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX, "[0-9]+ x ([0-9.]+) GHz Core[s]?"); - // SAN or LOCAL - properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_DISK0_TYPE, "LOCAL"); - // 10, 100, 1000 - properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PORT_SPEED, "10"); - ImmutableSet.Builder prices = ImmutableSet.builder(); - prices.add("21"); // 1 IP Address - prices.add("55"); // Host Ping: categoryCode: monitoring, notification - prices.add("57"); // Email and Ticket: categoryCode: notification - prices.add("58"); // Automated Notification: categoryCode: response - prices.add("1800"); // 0 GB Bandwidth: categoryCode: bandwidth - prices.add("905"); // Reboot / Remote Console: categoryCode: remote_management - prices.add("418"); // Nessus Vulnerability Assessment & Reporting: categoryCode: - // vulnerability_scanner - prices.add("420"); // Unlimited SSL VPN Users & 1 PPTP VPN User per account: categoryCode: - // vpn_management - properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES, Joiner.on(',').join(prices.build())); - properties.setProperty(TEMPLATE, "osFamily=UBUNTU,osVersionMatches=1[012].[01][04],os64Bit=true,osDescriptionMatches=.*Minimal Install.*"); + properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_ACTIVE_TRANSACTIONS_DELAY, "" + 3 * 60 * 1000); + properties.setProperty(PROPERTY_SOFTLAYER_INCLUDE_PUBLIC_IMAGES, "false"); + properties.setProperty(TEMPLATE, "osFamily=UBUNTU,osVersionMatches=1[012].[01][04],os64Bit=true"); return properties; } @@ -91,7 +65,7 @@ protected Builder() { .apiMetadata(new SoftLayerApiMetadata()) .homepage(URI.create("http://www.softlayer.com")) .console(URI.create("https://manage.softlayer.com")) - .iso3166Codes("SG","US-CA","US-TX","US-VA","US-WA","US-TX", "NL") + .iso3166Codes("SG","US-CA","US-TX","US-VA","US-WA","US-TX", "NL", "NSFTW-IL") // NSFTW-IL is a weird isoCode returned by Softlayer .endpoint("https://api.softlayer.com/rest") .defaultProperties(SoftLayerProviderMetadata.defaultProperties()); } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/binders/ProductOrderToJson.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/binders/ProductOrderToJson.java deleted file mode 100644 index 5370b11c5be..00000000000 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/binders/ProductOrderToJson.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.binders; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Set; - -import javax.inject.Inject; - -import org.jclouds.http.HttpRequest; -import org.jclouds.json.Json; -import org.jclouds.rest.Binder; -import org.jclouds.softlayer.domain.ProductItemPrice; -import org.jclouds.softlayer.domain.ProductOrder; -import org.jclouds.softlayer.domain.VirtualGuest; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; - -/** - * Converts a ProductOrder into a json string valid for placing an order via the softlayer api The - * String is set into the payload of the HttpRequest - * - * @author Jason King - */ -public class ProductOrderToJson implements Binder { - - private Json json; - - @Inject - public ProductOrderToJson(Json json) { - this.json = json; - } - - @Override - public R bindToRequest(R request, Object input) { - checkNotNull(input, "order"); - ProductOrder order = ProductOrder.class.cast(input); - request.setPayload(buildJson(order)); - return request; - } - - /** - * Builds a Json string suitable for sending to the softlayer api - * - * @param order - * @return - */ - String buildJson(ProductOrder order) { - - Iterable prices = Iterables.transform(order.getPrices(), new Function() { - @Override - public Price apply(ProductItemPrice productItemPrice) { - return new Price(productItemPrice.getId()); - } - }); - - Iterable hosts = Iterables.transform(order.getVirtualGuests(), - new Function() { - @Override - public HostnameAndDomain apply(VirtualGuest virtualGuest) { - return new HostnameAndDomain(virtualGuest.getHostname(), virtualGuest.getDomain()); - } - }); - - OrderData data = new OrderData(order.getPackageId(), order.getLocation(), Sets.newLinkedHashSet(prices), Sets - .newLinkedHashSet(hosts), order.getQuantity(), order.getUseHourlyPricing()); - - return json.toJson(ImmutableMap.of("parameters", ImmutableList. of(data))); - } - - @SuppressWarnings("unused") - private static class OrderData { - private String complexType = "SoftLayer_Container_Product_Order_Virtual_Guest"; - private long packageId = -1; - private String location; - private Set prices; - private Set virtualGuests; - private long quantity; - private boolean useHourlyPricing; - - public OrderData(long packageId, String location, Set prices, Set virtualGuests, - long quantity, boolean useHourlyPricing) { - this.packageId = packageId; - this.location = location; - this.prices = prices; - this.virtualGuests = virtualGuests; - this.quantity = quantity; - this.useHourlyPricing = useHourlyPricing; - } - - } - - @SuppressWarnings("unused") - private static class HostnameAndDomain { - private String hostname; - private String domain; - - public HostnameAndDomain(String hostname, String domain) { - this.hostname = hostname; - this.domain = domain; - } - - } - - @SuppressWarnings("unused") - private static class Price { - private long id; - - public Price(long id) { - this.id = id; - } - } - -} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/binders/TagToJson.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/binders/TagToJson.java new file mode 100644 index 00000000000..bea654cacda --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/binders/TagToJson.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.json.Json; +import org.jclouds.rest.Binder; + +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * Converts a Tag into a json string valid for creating a CCI via softlayer api + * The string is set into the payload of the HttpRequest + * + */ +@Singleton +public class TagToJson implements Binder { + + private final Json json; + + @Inject + public TagToJson(Json json) { + this.json = checkNotNull(json, "json"); + } + + @Override + public R bindToRequest(R request, Object input) { + checkArgument(input instanceof Set); + Set tags = Set.class.cast(checkNotNull(input, "input")); + request.setPayload(buildJson(tags)); + return request; + } + + String buildJson(Set tags) { + return json.toJson(ImmutableMap.of("parameters", ImmutableSet.of(Joiner.on(",").join(tags)))); + } +} 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 new file mode 100644 index 00000000000..abf6ab5269b --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/binders/VirtualGuestToJson.java @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Comparator; +import java.util.Set; + +import javax.inject.Inject; + +import org.jclouds.http.HttpRequest; +import org.jclouds.json.Json; +import org.jclouds.rest.Binder; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.domain.VirtualGuestBlockDevice; +import org.jclouds.softlayer.domain.VirtualGuestNetworkComponent; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedSet; + +/** + * Converts a VirtualGuest into a json string valid for creating a CCI via softlayer api + * The string is set into the payload of the HttpRequest + * + */ +public class VirtualGuestToJson implements Binder { + + private final Json json; + + @Inject + public VirtualGuestToJson(Json json) { + this.json = checkNotNull(json, "json"); + } + + @Override + public R bindToRequest(R request, Object input) { + checkArgument(input instanceof VirtualGuest); + VirtualGuest virtualGuest = VirtualGuest.class.cast(checkNotNull(input, "input")); + request.setPayload(buildJson(virtualGuest)); + return request; + } + + /** + * Builds a Json string suitable for sending to the softlayer api + * + * @param virtualGuest + * @return String + */ + String buildJson(VirtualGuest virtualGuest) { + TemplateObject templateObject = null; + String hostname = checkNotNull(virtualGuest.getHostname(), "hostname"); + String domain = checkNotNull(virtualGuest.getDomain(), "domain"); + int startCpus = checkNotNull(virtualGuest.getStartCpus(), "startCpus"); + int maxMemory = checkNotNull(virtualGuest.getMaxMemory(), "maxMemory"); + boolean localDiskFlag = checkNotNull(virtualGuest.isLocalDiskFlag(), "localDiskFlag"); + String datacenterName = checkNotNull(virtualGuest.getDatacenter().getName(), "datacenterName"); + Set networkComponents = getNetworkComponents(virtualGuest); + if(virtualGuest.getOperatingSystem() != null) { + String operatingSystemReferenceCode = checkNotNull(virtualGuest.getOperatingSystem() + .getOperatingSystemReferenceCode(), "operatingSystemReferenceCode"); + templateObject = new TemplateObject(hostname, domain, startCpus, maxMemory, true, + operatingSystemReferenceCode, null, localDiskFlag, new Datacenter(datacenterName), networkComponents, + getBlockDevices(virtualGuest)); + } else if(virtualGuest.getVirtualGuestBlockDeviceTemplateGroup() != null) { + String globalIdentifier = checkNotNull(virtualGuest.getVirtualGuestBlockDeviceTemplateGroup() + .getGlobalIdentifier(), "blockDeviceTemplateGroup.globalIdentifier"); + templateObject = new TemplateObject(hostname, domain, startCpus, maxMemory, true, null, + new BlockDeviceTemplateGroup(globalIdentifier), localDiskFlag, new Datacenter(datacenterName), + networkComponents, null); + } + return json.toJson(ImmutableMap.of("parameters", ImmutableList.of(templateObject))); + } + + private Set getBlockDevices(VirtualGuest virtualGuest) { + if (virtualGuest.getVirtualGuestBlockDevices() == null) { + return null; + } + ImmutableSortedSet.Builder blockDevices = ImmutableSortedSet.orderedBy(new BlockDevicesComparator()); + for (VirtualGuestBlockDevice blockDevice : virtualGuest.getVirtualGuestBlockDevices()) { + blockDevices.add(new BlockDevice(blockDevice.getDevice(), blockDevice.getVirtualDiskImage().getCapacity())); + } + return blockDevices.build(); + } + + private Set getNetworkComponents(VirtualGuest virtualGuest) { + if (virtualGuest.getVirtualGuestNetworkComponents() == null) { + return null; + } + ImmutableSet.Builder networkComponents = ImmutableSet.builder(); + for (VirtualGuestNetworkComponent networkComponent : virtualGuest.getVirtualGuestNetworkComponents()) { + networkComponents.add(new NetworkComponent(networkComponent.getSpeed())); + } + return networkComponents.build(); + } + + private static class TemplateObject { + private final String hostname; + private final String domain; + private final int startCpus; + private final int maxMemory; + private final boolean hourlyBillingFlag; + private final BlockDeviceTemplateGroup blockDeviceTemplateGroup; + private final String operatingSystemReferenceCode; + private final boolean localDiskFlag; + private final Datacenter datacenter; + private final Set networkComponents; + private final Set 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) { + this.hostname = hostname; + this.domain = domain; + this.startCpus = startCpus; + this.maxMemory = maxMemory; + this.hourlyBillingFlag = hourlyBillingFlag; + this.operatingSystemReferenceCode = operatingSystemReferenceCode; + this.blockDeviceTemplateGroup = blockDeviceTemplateGroup; + this.localDiskFlag = localDiskFlag; + this.datacenter = datacenter; + this.networkComponents = networkComponents; + this.blockDevices = blockDevices; + } + } + + private class Datacenter { + private String name; + + private Datacenter(String name) { + this.name = name; + } + } + + private class NetworkComponent { + private int maxSpeed; + + private NetworkComponent(int maxSpeed) { + this.maxSpeed = maxSpeed; + } + } + + private class BlockDevice { + private String device; + private DiskImage diskImage; + + public String getDevice() { + return device; + } + + public DiskImage getDiskImage() { + return diskImage; + } + + private BlockDevice(String device, float diskImageCapacity) { + this.device = device; + this.diskImage = new DiskImage(diskImageCapacity); + } + } + + private class DiskImage { + private float capacity; + + private DiskImage(float capacity) { + this.capacity = capacity; + } + } + + private class BlockDeviceTemplateGroup { + private String globalIdentifier; + + private BlockDeviceTemplateGroup(String globalIdentifier) { + this.globalIdentifier = globalIdentifier; + } + } + + private class BlockDevicesComparator implements Comparator { + + @Override + public int compare(BlockDevice b1, BlockDevice b2) { + return Integer.valueOf(b1.getDevice()).compareTo(Integer.valueOf(b2.getDevice())); + } + } + +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java index f4c87f168f3..e2bf26a3ee6 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java @@ -16,13 +16,7 @@ */ package org.jclouds.softlayer.compute.config; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.find; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; -import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES; - import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -32,98 +26,75 @@ import org.jclouds.collect.Memoized; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.config.ComputeServiceAdapterContextModule; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.domain.Location; +import org.jclouds.functions.IdentityFunction; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.softlayer.SoftLayerApi; import org.jclouds.softlayer.compute.functions.DatacenterToLocation; -import org.jclouds.softlayer.compute.functions.ProductItemToImage; -import org.jclouds.softlayer.compute.functions.ProductItemsToHardware; +import org.jclouds.softlayer.compute.functions.OperatingSystemToImage; +import org.jclouds.softlayer.compute.functions.VirtualGuestToHardware; import org.jclouds.softlayer.compute.functions.VirtualGuestToNodeMetadata; import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions; import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter; +import org.jclouds.softlayer.domain.ContainerVirtualGuestConfiguration; import org.jclouds.softlayer.domain.Datacenter; -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemPrice; -import org.jclouds.softlayer.domain.ProductPackage; +import org.jclouds.softlayer.domain.OperatingSystem; import org.jclouds.softlayer.domain.VirtualGuest; -import org.jclouds.softlayer.features.AccountApi; -import org.jclouds.softlayer.features.ProductPackageApi; import com.google.common.base.Function; import com.google.common.base.Objects; -import com.google.common.base.Splitter; import com.google.common.base.Supplier; -import com.google.common.collect.Iterables; import com.google.inject.Provides; import com.google.inject.TypeLiteral; -/** - * - * @author Adrian Cole - */ public class SoftLayerComputeServiceContextModule extends - ComputeServiceAdapterContextModule, ProductItem, Datacenter> { + ComputeServiceAdapterContextModule { @Override protected void configure() { super.configure(); - bind(new TypeLiteral, ProductItem, Datacenter>>() { + bind(new TypeLiteral>() { }).to(SoftLayerComputeServiceAdapter.class); bind(new TypeLiteral>() { }).to(VirtualGuestToNodeMetadata.class); - bind(new TypeLiteral>() { - }).to(ProductItemToImage.class); - bind(new TypeLiteral, org.jclouds.compute.domain.Hardware>>() { - }).to(ProductItemsToHardware.class); + bind(new TypeLiteral>() { + }).to(OperatingSystemToImage.class); + bind(new TypeLiteral>() { + }).to(Class.class.cast(IdentityFunction.class)); + bind(new TypeLiteral>() { + }).to(VirtualGuestToHardware.class); bind(new TypeLiteral>() { }).to(DatacenterToLocation.class); bind(TemplateOptions.class).to(SoftLayerTemplateOptions.class); // to have the compute service adapter override default locations - install(new LocationsFromComputeServiceAdapterModule, ProductItem, Datacenter>(){}); + install(new LocationsFromComputeServiceAdapterModule(){}); + } - /** - * Many requests need the same productPackage, which is in this case the package for virtual - * guests. We may at some point need to make an annotation qualifying it as such. ex. @VirtualGuest - */ @Provides @Singleton @Memoized - public Supplier getProductPackage(AtomicReference authException, - @Named(PROPERTY_SESSION_INTERVAL) long seconds, final SoftLayerApi client, - @Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME) final String virtualGuestPackageName) { + public Supplier getCreateObjectOptions( + AtomicReference authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, + final SoftLayerApi api) { return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, - new Supplier() { - @Override - public ProductPackage get() { - AccountApi accountApi = client.getAccountApi(); - ProductPackageApi productPackageApi = client.getProductPackageApi(); - ProductPackage p = find(accountApi.getActivePackages(), named(virtualGuestPackageName)); - return productPackageApi.getProductPackage(p.getId()); - } - - @Override - public String toString() { - return Objects.toStringHelper(client).add("method", "accountClient.getActivePackages") - .add("method", "productPackageClient.getProductPackage").toString(); - } - }, seconds, TimeUnit.SECONDS); - } + new Supplier() { + @Override + public ContainerVirtualGuestConfiguration get() { + return api.getVirtualGuestApi().getCreateObjectOptions(); + } - // TODO: check the prices really do exist - @Provides - @Singleton - public Iterable prices(@Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES) String prices) { - return Iterables.transform(Splitter.on(',').split(checkNotNull(prices, "prices")), - new Function() { - @Override - public ProductItemPrice apply(String arg0) { - return ProductItemPrice.builder().id(Integer.parseInt(arg0)).build(); - } - }); + @Override + public String toString() { + return Objects.toStringHelper(api) + .add("method", "virtualGuestApi.getCreateObjectOptions") + .toString(); + } + }, seconds, TimeUnit.SECONDS); } } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/DatacenterToLocation.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/DatacenterToLocation.java index eadcecaae98..106c584f9bd 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/DatacenterToLocation.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/DatacenterToLocation.java @@ -20,6 +20,7 @@ import static com.google.common.base.Strings.nullToEmpty; import javax.inject.Inject; +import javax.inject.Singleton; import org.jclouds.domain.Location; import org.jclouds.domain.LocationBuilder; @@ -36,7 +37,8 @@ /** * Converts an Datacenter into a Location. */ -public class DatacenterToLocation implements Function { +@Singleton +public class DatacenterToLocation implements Function { private final JustProvider provider; // allow us to lazy discover the provider of a resource @@ -47,12 +49,12 @@ public DatacenterToLocation(JustProvider provider) { @Override public Location apply(Datacenter datacenter) { - return new LocationBuilder().scope(LocationScope.ZONE) - .metadata(ImmutableMap.of()) + return new LocationBuilder().id(datacenter.getName()) .description(datacenter.getLongName()) - .id(Long.toString(datacenter.getId())) + .scope(LocationScope.ZONE) .iso3166Codes(createIso3166Codes(datacenter.getLocationAddress())) .parent(Iterables.getOnlyElement(provider.get())) + .metadata(ImmutableMap.of("name", datacenter.getName())) .build(); } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/OperatingSystemToImage.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/OperatingSystemToImage.java new file mode 100644 index 00000000000..19dfd2ae74b --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/OperatingSystemToImage.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.compute.functions; + +import static com.google.common.base.Optional.fromNullable; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.softlayer.compute.functions.internal.OperatingSystems; +import org.jclouds.softlayer.domain.OperatingSystem; +import org.jclouds.softlayer.domain.SoftwareDescription; +import org.jclouds.softlayer.domain.SoftwareLicense; + +import com.google.common.base.Function; +import com.google.common.base.Objects; +import com.google.common.base.Optional; + +@Singleton +public class OperatingSystemToImage implements Function { + + private static final String UNRECOGNIZED = "UNRECOGNIZED"; + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + @Override + public Image apply(OperatingSystem operatingSystem) { + checkNotNull(operatingSystem, "operatingSystem"); + final SoftwareLicense defaultSoftwareLicense = SoftwareLicense.builder().softwareDescription(SoftwareDescription.builder().build()).build(); + SoftwareLicense softwareLicense = fromNullable(operatingSystem.getSoftwareLicense()).or(defaultSoftwareLicense); + Optional optOSReferenceCode = fromNullable(softwareLicense.getSoftwareDescription().getReferenceCode()); + Optional optVersion = fromNullable(softwareLicense.getSoftwareDescription().getVersion()); + Optional optLongDescription = fromNullable(softwareLicense.getSoftwareDescription().getLongDescription()); + OsFamily osFamily = OsFamily.UNRECOGNIZED; + String osVersion = UNRECOGNIZED; + Integer bits = null; + if(optOSReferenceCode.isPresent()) { + String operatingSystemReferenceCode = optOSReferenceCode.get(); + osFamily = OperatingSystems.osFamily().apply(operatingSystemReferenceCode); + bits = OperatingSystems.bits().apply(operatingSystemReferenceCode); + } + if(optVersion.isPresent()) { + osVersion = OperatingSystems.version().apply(optVersion.get()); + } + if (osFamily == OsFamily.UNRECOGNIZED) { + logger.debug("Cannot determine os family for item: %s", operatingSystem); + } + if (osVersion == null) { + logger.debug("Cannot determine os version for item: %s", operatingSystem); + } + if (bits == null) { + logger.debug("Cannot determine os bits for item: %s", operatingSystem); + } + + org.jclouds.compute.domain.OperatingSystem os = org.jclouds.compute.domain.OperatingSystem.builder() + .description(optLongDescription.or(UNRECOGNIZED)) + .family(osFamily) + .version(osVersion) + .is64Bit(Objects.equal(bits, 64)) + .build(); + + return new ImageBuilder() + .ids(operatingSystem.getId()) + .description(optOSReferenceCode.or(UNRECOGNIZED)) + .operatingSystem(os) + .status(Image.Status.AVAILABLE) + .build(); + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemToImage.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemToImage.java deleted file mode 100644 index 31c4148c61b..00000000000 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemToImage.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.compute.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.ImageBuilder; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.logging.Logger; -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemPrice; - -import com.google.common.base.Function; -import com.google.common.base.Objects; - -/** - * @author Jason King - */ -@Singleton -public class ProductItemToImage implements Function { - - /** - * Pattern to capture the number of bits e.g. "a (32 bit) os" - */ - private static final Pattern OS_BITS_PATTERN = Pattern.compile(".*\\((\\d+) ?bit\\).*"); - - private static final String CENTOS = "CentOS"; - private static final String DEBIAN = "Debian GNU/Linux"; - private static final String FEDORA = "Fedora Release"; - private static final String RHEL = "Red Hat Enterprise Linux"; - private static final String UBUNTU = "Ubuntu Linux"; - private static final String WINDOWS = "Windows Server"; - private static final String CLOUD_LINUX = "CloudLinux"; - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - @Override - public Image apply(ProductItem productItem) { - checkNotNull(productItem, "productItem"); - String description = checkNotNull(productItem.getDescription(), "productItem.description"); - - OsFamily osFamily = osFamily().apply(description); - if (osFamily == OsFamily.UNRECOGNIZED) { - logger.debug("Cannot determine os family for item: %s", productItem); - } - Integer bits = osBits().apply(description); - if (bits == null) { - logger.debug("Cannot determine os bits for item: %s", productItem); - } - String osVersion = osVersion().apply(description); - if (osVersion == null) { - logger.debug("Cannot determine os version for item: %s", productItem); - } - OperatingSystem os = OperatingSystem.builder() - .description(description) - .family(osFamily) - .version(osVersion) - .is64Bit(Objects.equal(bits, 64)) - .build(); - - return new ImageBuilder() - .ids(imageId().apply(productItem)) - .description(description) - .operatingSystem(os) - .status(Image.Status.AVAILABLE) - .build(); - } - - /** - * Parses the item description to determine the OSFamily - * - * @return the @see OsFamily or OsFamily.UNRECOGNIZED - */ - public static Function osFamily() { - return new Function() { - @Override - public OsFamily apply(final String description) { - if (description != null) { - if (description.startsWith(CENTOS)) return OsFamily.CENTOS; - else if (description.startsWith(DEBIAN)) return OsFamily.DEBIAN; - else if (description.startsWith(FEDORA)) return OsFamily.FEDORA; - else if (description.startsWith(RHEL)) return OsFamily.RHEL; - else if (description.startsWith(UBUNTU)) return OsFamily.UBUNTU; - else if (description.startsWith(WINDOWS)) return OsFamily.WINDOWS; - else if (description.startsWith(CLOUD_LINUX)) return OsFamily.CLOUD_LINUX; - } - - return OsFamily.UNRECOGNIZED; - } - }; - } - - /** - * Parses the item description to determine the os version - * - * @return the version or null if the version cannot be determined - */ - public static Function osVersion() { - return new Function() { - @Override - public String apply(final String description) { - OsFamily family = osFamily().apply(description); - - if (Objects.equal(family, OsFamily.CENTOS)) return parseVersion(description, CENTOS); - else if (Objects.equal(family, OsFamily.DEBIAN)) return parseVersion(description, DEBIAN); - else if (Objects.equal(family, OsFamily.FEDORA)) return parseVersion(description, FEDORA); - else if (Objects.equal(family, OsFamily.RHEL)) return parseVersion(description, RHEL); - else if (Objects.equal(family, OsFamily.UBUNTU)) return parseVersion(description, UBUNTU); - else if (Objects.equal(family, OsFamily.WINDOWS)) return parseVersion(description, WINDOWS); - else if (Objects.equal(family, OsFamily.CLOUD_LINUX)) return parseVersion(description, CLOUD_LINUX); - - return null; - } - }; - } - - private static String parseVersion(String description, String os) { - String noOsName = description.replaceFirst(os, "").trim(); - return noOsName.split(" ")[0]; - } - - /** - * Parses the item description to determine the number of OS bits - * Expects the number to be in parenthesis and to contain the word "bit". - * The following return 64: "A (64 bit) OS", "A (64bit) OS" - * - * @return the number of bits or null if the number of bits cannot be determined - */ - public static Function osBits() { - return new Function() { - @Override - public Integer apply(String description) { - if (description != null) { - Matcher m = OS_BITS_PATTERN.matcher(description); - if (m.matches()) { - return Integer.parseInt(m.group(1)); - } - } - - return null; - } - }; - } - - /** - * Generates an id for an Image. - * - * @return the generated id - */ - public static Function imageId() { - return new Function() { - @Override - public String apply(ProductItem productItem) { - checkNotNull(productItem, "productItem"); - ProductItemPrice price = ProductItems.price().apply(productItem); - return "" + price.getId(); - } - }; - } - -} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItems.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItems.java deleted file mode 100644 index 7c551e1e6a4..00000000000 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItems.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.compute.functions; - -import java.util.NoSuchElementException; -import java.util.Set; - -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemCategory; -import org.jclouds.softlayer.domain.ProductItemPrice; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -public class ProductItems { - - /** - * Creates a function to get the capacity from a product item. - */ - public static Function capacity() { - return new Function() { - @Override - public Float apply(ProductItem productItem) { - return productItem.getCapacity(); - } - }; - } - - /** - * Creates a function to get the description from a product item. - */ - public static Function description() { - return new Function() { - @Override - public String apply(ProductItem productItem) { - return productItem.getDescription(); - } - }; - } - - /** - * Creates a function to get the ProductItemPrice for the ProductItem. Currently returns the - * first prices. This will need to be changed if more than one prices is returned. - */ - public static Function price() { - return new Function() { - @Override - public ProductItemPrice apply(ProductItem productItem) { - if (productItem.getPrices().size() < 1) - throw new NoSuchElementException("ProductItem has no prices:" + productItem); - return Iterables.get(productItem.getPrices(), 0); - } - }; - } - - /** - * Creates a function to get the ProductItem for the ProductItemPrice. Copies the category - * information from the prices to the item if necessary The ProductItemPrices must have - * ProductItems. - */ - public static Function item() { - return new Function() { - @Override - public ProductItem apply(ProductItemPrice productItemPrice) { - Set categories = productItemPrice.getCategories(); - ProductItem item = productItemPrice.getItem(); - ProductItem.Builder builder = productItemPrice.getItem().toBuilder(); - if (item.getCategories().size() == 0 && categories.size() != 0) { - builder.categories(categories); - } - - return builder.build(); - } - }; - } -} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemsToHardware.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemsToHardware.java deleted file mode 100644 index 4adee6f6fab..00000000000 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemsToHardware.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.compute.functions; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.get; -import static com.google.common.collect.Iterables.getOnlyElement; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.categoryCode; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.categoryCodeMatches; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.matches; - -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.HardwareBuilder; -import org.jclouds.compute.domain.Processor; -import org.jclouds.compute.domain.Volume; -import org.jclouds.compute.domain.internal.VolumeImpl; -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemPrice; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; - -/** - * Converts a set of ProductItems to Hardware. All cores have a speed of 2.0Ghz The Hardware Id will - * be a comma separated list containing the prices ids: cpus,ram,volume - * - * @author Jason King - */ -@Singleton -public class ProductItemsToHardware implements Function, Hardware> { - - private static final String GUEST_DISK_CATEGORY_REGEX = "guest_disk[0-9]"; - private static final String FIRST_GUEST_DISK = "guest_disk0"; - private static final String STORAGE_AREA_NETWORK = "SAN"; - - private static final String RAM_CATEGORY = "ram"; - - private static final String CPU_DESCRIPTION_REGEX = "(Private )?[0-9]+ x ([.0-9]+) GHz Core[s]?"; - private static final double DEFAULT_CORE_SPEED = 2.0; - - private final Pattern cpuDescriptionRegex; - private final Pattern diskCategoryRegex; - - @Inject - public ProductItemsToHardware() { - this(Pattern.compile(CPU_DESCRIPTION_REGEX), Pattern.compile(GUEST_DISK_CATEGORY_REGEX)); - } - - public ProductItemsToHardware(Pattern cpuDescriptionRegex, Pattern diskCategoryRegex) { - this.cpuDescriptionRegex = checkNotNull(cpuDescriptionRegex, "cpuDescriptionRegex"); - this.diskCategoryRegex = checkNotNull(diskCategoryRegex, "diskCategoryRegex"); - } - - @Override - public Hardware apply(Iterable items) { - - ProductItem coresItem = getOnlyElement(filter(items, matches(cpuDescriptionRegex))); - ProductItem ramItem = getOnlyElement(filter(items, categoryCode(RAM_CATEGORY))); - ProductItem volumeItem = get(filter(items, categoryCode(FIRST_GUEST_DISK)), 0); - - String hardwareId = hardwareId().apply(ImmutableList.of(coresItem, ramItem, volumeItem)); - double cores = ProductItems.capacity().apply(coresItem).doubleValue(); - Matcher cpuMatcher = cpuDescriptionRegex.matcher(coresItem.getDescription()); - double coreSpeed = (cpuMatcher.matches()) ? Double.parseDouble(cpuMatcher.group(cpuMatcher.groupCount())) : DEFAULT_CORE_SPEED; - int ram = ProductItems.capacity().apply(ramItem).intValue() * 1024; - - return new HardwareBuilder().ids(hardwareId).processors(ImmutableList.of(new Processor(cores, coreSpeed))) - .ram(ram).hypervisor("XenServer") - .volumes( - Iterables.transform(filter(items, categoryCodeMatches(diskCategoryRegex)), - new Function() { - @Override - public Volume apply(ProductItem item) { - float volumeSize = ProductItems.capacity().apply(item); - return new VolumeImpl( - item.getId() + "", - item.getDescription().indexOf(STORAGE_AREA_NETWORK) != -1 ? Volume.Type.SAN : Volume.Type.LOCAL, - volumeSize, null, categoryCode(FIRST_GUEST_DISK).apply(item), false); - } - })).build(); - } - - /** - * Generates a hardwareId based on the priceId's of the items in the list - * - * @return comma separated list of priceid's - */ - public static Function, String> hardwareId() { - return new Function, String>() { - @Override - public String apply(List productItems) { - StringBuilder builder = new StringBuilder(); - for (ProductItem item : productItems) { - ProductItemPrice price = ProductItems.price().apply(item); - builder.append(price.getId()).append(","); - } - return builder.toString().substring(0, builder.lastIndexOf(",")); - } - }; - } -} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToHardware.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToHardware.java new file mode 100644 index 00000000000..8afedd7646e --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToHardware.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.compute.functions; + +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.internal.VolumeImpl; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.domain.VirtualGuestBlockDevice; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableList; + +@Singleton +public class VirtualGuestToHardware implements Function { + + @Override + public Hardware apply(final VirtualGuest from) { + HardwareBuilder builder = new HardwareBuilder().ids(from.getId() + "") + .name(from.getHostname()) + .hypervisor("XenServer") + .processors(ImmutableList.of(new Processor(from.getStartCpus(), 2))) + .ram(from.getMaxMemory()); + + if (from.getVirtualGuestBlockDevices() != null) { + builder.volumes( + FluentIterable.from(from.getVirtualGuestBlockDevices()).filter(new Predicate() { + @Override + public boolean apply(VirtualGuestBlockDevice input) { + return input.getMountType().equals("Disk"); + } + }) + .transform(new Function() { + @Override + public Volume apply(VirtualGuestBlockDevice item) { + float volumeSize = item.getVirtualDiskImage().getCapacity(); + return new VolumeImpl( + item.getId() + "", + from.isLocalDiskFlag() ? Volume.Type.LOCAL : Volume.Type.SAN, + volumeSize, null, item.getBootableFlag() == 1, false); + } + }).toSet()); + } + return builder.build(); + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToImage.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToImage.java new file mode 100644 index 00000000000..606da9c126a --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToImage.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.compute.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.softlayer.domain.VirtualGuest; + +import com.google.common.base.Function; +import com.google.inject.Inject; + +@Singleton +public class VirtualGuestToImage implements Function { + + private static final String UNRECOGNIZED = "UNRECOGNIZED"; + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + private final OperatingSystemToImage operatingSystemToImage; + + @Inject + protected VirtualGuestToImage(OperatingSystemToImage operatingSystemToImage) { + this.operatingSystemToImage = checkNotNull(operatingSystemToImage, "operatingSystemToImage"); + } + + @Override + public Image apply(VirtualGuest from) { + checkNotNull(from, "from"); + if (from.getOperatingSystem() == null) { + return new ImageBuilder().ids(from.getId() + "") + .name(from.getHostname()) + .status(Image.Status.UNRECOGNIZED) + .operatingSystem(OperatingSystem.builder() + .family(OsFamily.UNRECOGNIZED) + .version(UNRECOGNIZED) + .description(UNRECOGNIZED) + .build()) + .build(); + } else { + return operatingSystemToImage.apply(from.getOperatingSystem()); + } + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadata.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadata.java index 7c60f8a6cc9..45c28cd179d 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadata.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadata.java @@ -18,42 +18,30 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.FluentIterable.from; - +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.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata.Status; import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.functions.GroupNamingConvention; -import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Location; import org.jclouds.location.predicates.LocationPredicates; -import org.jclouds.logging.Logger; -import org.jclouds.softlayer.SoftLayerApi; -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductOrder; +import org.jclouds.softlayer.domain.TagReference; import org.jclouds.softlayer.domain.VirtualGuest; -import org.jclouds.softlayer.exceptions.SoftLayerOrderItemDuplicateException; -import org.jclouds.softlayer.predicates.ProductItemPredicates; import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; -/** - * @author Adrian Cole - */ @Singleton public class VirtualGuestToNodeMetadata implements Function { @@ -63,107 +51,54 @@ public class VirtualGuestToNodeMetadata implements Function> locations; - private final GetHardwareForVirtualGuest hardware; - private final GetImageForVirtualGuest images; private final GroupNamingConvention nodeNamingConvention; + private final VirtualGuestToImage virtualGuestToImage; + private final VirtualGuestToHardware virtualGuestToHardware; @Inject VirtualGuestToNodeMetadata(@Memoized Supplier> locations, - GetHardwareForVirtualGuest hardware, GetImageForVirtualGuest images, - GroupNamingConvention.Factory namingConvention) { + GroupNamingConvention.Factory namingConvention, VirtualGuestToImage virtualGuestToImage, + VirtualGuestToHardware virtualGuestToHardware) { this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix(); this.locations = checkNotNull(locations, "locations"); - this.hardware = checkNotNull(hardware, "hardware"); - this.images = checkNotNull(images, "images"); + this.virtualGuestToImage = checkNotNull(virtualGuestToImage, "virtualGuestToImage"); + this.virtualGuestToHardware = checkNotNull(virtualGuestToHardware, "virtualGuestToHardware"); } @Override public NodeMetadata apply(VirtualGuest from) { - // convert the result object to a jclouds NodeMetadata NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getHostname()); - builder.hostname(from.getHostname()); - if (from.getDatacenter() != null) + builder.hostname(from.getHostname() + from.getDomain()); + if (from.getDatacenter() != null) { builder.location(from(locations.get()).firstMatch( - LocationPredicates.idEquals(from.getDatacenter().getId() + "")).orNull()); + LocationPredicates.idEquals(from.getDatacenter().getId() + "")).orNull()); + } builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getHostname())); - - Image image = images.getImage(from); + builder.hardware(virtualGuestToHardware.apply(from)); + Image image = virtualGuestToImage.apply(from); if (image != null) { builder.imageId(image.getId()); builder.operatingSystem(image.getOperatingSystem()); } - - builder.hardware(hardware.getHardware(from)); - - builder.status(serverStateToNodeStatus.get(from.getPowerState().getKeyName())); - - // These are null for 'bad' guest orders in the HALTED state. + if (from.getPowerState() != null) { + builder.status(serverStateToNodeStatus.get(from.getPowerState().getKeyName())); + } if (from.getPrimaryIpAddress() != null) - builder.publicAddresses(ImmutableSet. of(from.getPrimaryIpAddress())); + builder.publicAddresses(ImmutableSet.of(from.getPrimaryIpAddress())); if (from.getPrimaryBackendIpAddress() != null) - builder.privateAddresses(ImmutableSet. of(from.getPrimaryBackendIpAddress())); - return builder.build(); - } - - @Singleton - public static class GetHardwareForVirtualGuest { - - private final SoftLayerApi api; - private final Function, Hardware> productItemsToHardware; - - @Inject - public GetHardwareForVirtualGuest(SoftLayerApi api, - Function, Hardware> productItemsToHardware) { - this.api = checkNotNull(api, "api"); - this.productItemsToHardware = checkNotNull(productItemsToHardware, "productItemsToHardware"); - - } - - public Hardware getHardware(VirtualGuest guest) { - // 'bad' orders have no start cpu's and cause the order lookup to fail. - if (guest.getStartCpus() < 1) - return null; - ProductOrder order = api.getVirtualGuestApi().getOrderTemplate(guest.getId()); - if (order == null) - return null; - Iterable items = Iterables.transform(order.getPrices(), ProductItems.item()); - return productItemsToHardware.apply(items); - } - } - - @Singleton - public static class GetImageForVirtualGuest { - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - private SoftLayerApi api; - - @Inject - public GetImageForVirtualGuest(SoftLayerApi api) { - this.api = api; - } - - public Image getImage(VirtualGuest guest) { - ProductOrder order = null; - // 'bad' orders have no start cpu's and cause the order lookup to fail. - if (guest.getStartCpus() < 1) - return null; - try { - order = api.getVirtualGuestApi().getOrderTemplate(guest.getId()); - } catch (SoftLayerOrderItemDuplicateException e) { - // this is a workaround because SoftLayer throws sometimes 500 internal server errors for the above method call - logger.warn(e, "Cannot get order template for virtualGuestId(%s)", guest.getId()); + builder.privateAddresses(ImmutableSet.of(from.getPrimaryBackendIpAddress())); + if (from.getTagReferences() != null && !from.getTagReferences().isEmpty()) { + List tags = Lists.newArrayList(); + for (TagReference tagReference : from.getTagReferences()) { + if (tagReference != null) { + tags.add(tagReference.getTag().getName()); + } } - if (order == null) - return null; - Iterable items = Iterables.transform(order.getPrices(), ProductItems.item()); - ProductItem os = Iterables.find(items, ProductItemPredicates.categoryCode("os")); - return new ProductItemToImage().apply(os); + builder.tags(tags); } + return builder.build(); } } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/internal/OperatingSystems.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/internal/OperatingSystems.java new file mode 100644 index 00000000000..899a529a2c3 --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/internal/OperatingSystems.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.compute.functions.internal; + +import static com.google.common.collect.Iterables.getLast; + +import org.jclouds.compute.domain.OsFamily; + +import com.google.common.base.Function; +import com.google.common.base.Splitter; +import com.google.common.collect.Iterables; +import com.google.common.primitives.Ints; + +public class OperatingSystems { + + protected static final String CENTOS = "CENTOS"; + protected static final String DEBIAN = "DEBIAN"; + protected static final String RHEL = "REDHAT"; + protected static final String UBUNTU = "UBUNTU"; + protected static final String WINDOWS = "WIN_"; + protected static final String CLOUD_LINUX = "CLOUDLINUX"; + protected static final String VYATTACE = "VYATTACE"; + + public static Function osFamily() { + return new Function() { + @Override + public OsFamily apply(final String description) { + if (description != null) { + if (description.startsWith(CENTOS)) return OsFamily.CENTOS; + else if (description.startsWith(DEBIAN)) return OsFamily.DEBIAN; + else if (description.startsWith(RHEL)) return OsFamily.RHEL; + else if (description.startsWith(UBUNTU)) return OsFamily.UBUNTU; + else if (description.startsWith(WINDOWS)) return OsFamily.WINDOWS; + else if (description.startsWith(CLOUD_LINUX)) return OsFamily.CLOUD_LINUX; + else if (description.startsWith(VYATTACE)) return OsFamily.LINUX; + } + return OsFamily.UNRECOGNIZED; + } + }; + } + + public static Function bits() { + return new Function() { + @Override + public Integer apply(String operatingSystemReferenceCode) { + if (operatingSystemReferenceCode != null) { + return Ints.tryParse(getLast(Splitter.on("_").split(operatingSystemReferenceCode))); + } + return null; + } + }; + } + + public static Function version() { + return new Function() { + @Override + public String apply(final String version) { + return parseVersion(version); + } + }; + } + + private static String parseVersion(String version) { + if (version.contains("-")) { + String rawVersion = version.substring(0, version.lastIndexOf("-")); + if (Iterables.size(Splitter.on(".").split(rawVersion)) == 3) { + return rawVersion.substring(0, rawVersion.lastIndexOf(".")); + } else { + return rawVersion; + } + } else if (version.contains(" ")) { + return version.substring(0, version.indexOf(" ")); + } + return null; + } + +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptions.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptions.java index 29e5798bcdf..8c74dec19f8 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptions.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptions.java @@ -18,17 +18,19 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; - +import java.util.List; import java.util.Map; import org.jclouds.compute.options.TemplateOptions; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; import com.google.common.net.InternetDomainName; /** * Contains options supported by the - * {@link ComputeService#createNodesInGroup(String, int, TemplateOptions)} and - * {@link ComputeService#createNodesInGroup(String, int, TemplateOptions)} + * {@link org.jclouds.compute.ComputeService#createNodesInGroup(String, int, TemplateOptions)} and + * {@link org.jclouds.compute.ComputeService#createNodesInGroup(String, int, TemplateOptions)} * operations on the gogrid provider. * *

Usage

The recommended way to instantiate a @@ -44,11 +46,13 @@ * Set<? extends NodeMetadata> set = client.createNodesInGroup(tag, 2, templateBuilder.build()); * * - * @author Adrian Cole */ public class SoftLayerTemplateOptions extends TemplateOptions implements Cloneable { protected String domainName = "jclouds.org"; + protected Optional> blockDevices = Optional.absent(); + protected Optional diskType = Optional.absent(); + protected Optional portSpeed = Optional.absent(); @Override public SoftLayerTemplateOptions clone() { @@ -63,6 +67,15 @@ public void copyTo(TemplateOptions to) { if (to instanceof SoftLayerTemplateOptions) { SoftLayerTemplateOptions eTo = SoftLayerTemplateOptions.class.cast(to); eTo.domainName(domainName); + if(blockDevices.isPresent()) { + eTo.blockDevices(blockDevices.get()); + } + if(diskType.isPresent()) { + eTo.diskType(diskType.get()); + } + if(portSpeed.isPresent()) { + eTo.portSpeed(portSpeed.get()); + } } } @@ -70,7 +83,7 @@ public void copyTo(TemplateOptions to) { * will replace the default domain used when ordering virtual guests. Note * this needs to contain a public suffix! * - * @see VirtualGuestClient#orderVirtualGuest + * @see org.jclouds.softlayer.features.VirtualGuestApi#createVirtualGuest(org.jclouds.softlayer.domain.VirtualGuest) * @see InternetDomainName#hasPublicSuffix */ public TemplateOptions domainName(String domainName) { @@ -81,10 +94,45 @@ public TemplateOptions domainName(String domainName) { return this; } + public TemplateOptions blockDevices(Iterable capacities) { + for (Integer capacity : checkNotNull(capacities, "capacities")) + checkNotNull(capacity, "all block devices must be non-empty"); + this.blockDevices = Optional.> of(ImmutableList.copyOf(capacities)); + return this; + } + + public TemplateOptions blockDevices(Integer... capacities) { + return blockDevices(ImmutableList.copyOf(checkNotNull(capacities, "capacities"))); + } + + public TemplateOptions diskType(String diskType) { + checkNotNull(diskType, "diskType was null"); + this.diskType = Optional.of(diskType); + return this; + } + + public TemplateOptions portSpeed(Integer portSpeed) { + checkNotNull(portSpeed, "portSpeed was null"); + this.portSpeed = Optional.of(portSpeed); + return this; + } + public String getDomainName() { return domainName; } + public Optional> getBlockDevices() { + return blockDevices; + } + + public Optional getDiskType() { + return diskType; + } + + public Optional getPortSpeed() { + return portSpeed; + } + public static final SoftLayerTemplateOptions NONE = new SoftLayerTemplateOptions(); public static class Builder { @@ -97,6 +145,35 @@ public static SoftLayerTemplateOptions domainName(String domainName) { return SoftLayerTemplateOptions.class.cast(options.domainName(domainName)); } + /** + * @see #blockDevices + */ + public static SoftLayerTemplateOptions blockDevices(Integer... capacities) { + SoftLayerTemplateOptions options = new SoftLayerTemplateOptions(); + return SoftLayerTemplateOptions.class.cast(options.blockDevices(capacities)); + } + + public static SoftLayerTemplateOptions blockDevices(Iterable capacities) { + SoftLayerTemplateOptions options = new SoftLayerTemplateOptions(); + return SoftLayerTemplateOptions.class.cast(options.blockDevices(capacities)); + } + + /** + * @see #diskType + */ + public static SoftLayerTemplateOptions diskType(String diskType) { + SoftLayerTemplateOptions options = new SoftLayerTemplateOptions(); + return SoftLayerTemplateOptions.class.cast(options.diskType(diskType)); + } + + /** + * @see #portSpeed + */ + public static SoftLayerTemplateOptions portSpeed(Integer portSpeed) { + SoftLayerTemplateOptions options = new SoftLayerTemplateOptions(); + return SoftLayerTemplateOptions.class.cast(options.portSpeed(portSpeed)); + } + // methods that only facilitate returning the correct object type /** 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 c6a3ba6e429..731e14ad97b 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 @@ -19,22 +19,24 @@ 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.base.Predicates.and; 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 org.jclouds.util.Predicates2.retry; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.capacity; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.categoryCode; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.matches; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX; -import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_DISK0_TYPE; +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.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PORT_SPEED; - +import static org.jclouds.util.Predicates2.retry; +import java.util.Comparator; +import java.util.List; +import java.util.Map; import java.util.Set; -import java.util.regex.Pattern; import javax.annotation.Resource; import javax.inject.Inject; @@ -43,68 +45,82 @@ import org.jclouds.collect.Memoized; import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.internal.VolumeImpl; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.LoginCredentials; import org.jclouds.logging.Logger; import org.jclouds.softlayer.SoftLayerApi; -import org.jclouds.softlayer.compute.functions.ProductItemToImage; import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions; +import org.jclouds.softlayer.domain.ContainerVirtualGuestConfiguration; import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.OperatingSystem; import org.jclouds.softlayer.domain.Password; -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemPrice; -import org.jclouds.softlayer.domain.ProductOrder; -import org.jclouds.softlayer.domain.ProductOrderReceipt; -import org.jclouds.softlayer.domain.ProductPackage; +import org.jclouds.softlayer.domain.SoftwareDescription; +import org.jclouds.softlayer.domain.SoftwareLicense; +import org.jclouds.softlayer.domain.VirtualDiskImage; +import org.jclouds.softlayer.domain.VirtualDiskImageSoftware; import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.domain.VirtualGuestBlockDevice; +import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplate; +import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup; +import org.jclouds.softlayer.domain.VirtualGuestNetworkComponent; +import com.google.common.base.Function; +import com.google.common.base.Optional; import com.google.common.base.Predicate; -import com.google.common.base.Splitter; +import com.google.common.base.Predicates; import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableSet; +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; /** * defines the connection between the {@link SoftLayerApi} implementation and - * the jclouds {@link ComputeService} - * + * the jclouds {@link org.jclouds.compute.ComputeService} + * */ @Singleton public class SoftLayerComputeServiceAdapter implements - ComputeServiceAdapter, ProductItem, Datacenter> { + ComputeServiceAdapter { + + private static final String BOOTABLE_DEVICE = "0"; + public static final String DEFAULT_DISK_TYPE = "LOCAL"; + public static final int DEFAULT_PORT_SPEED = 100; @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; - private final SoftLayerApi client; - private final Supplier productPackageSupplier; + private final SoftLayerApi api; + private final Supplier createObjectOptionsSupplier; private final Predicate loginDetailsTester; private final long guestLoginDelay; - private final Pattern cpuPattern; - private final Pattern disk0Type; - private final float portSpeed; - private final Iterable prices; + private final long activeTransactionsDelay; + private final boolean includePublicImages; @Inject - public SoftLayerComputeServiceAdapter(SoftLayerApi client, + public SoftLayerComputeServiceAdapter(SoftLayerApi api, VirtualGuestHasLoginDetailsPresent virtualGuestHasLoginDetailsPresent, - @Memoized Supplier productPackageSupplier, Iterable prices, - @Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX) String cpuRegex, - @Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_DISK0_TYPE) String disk0Type, - @Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_PORT_SPEED) float portSpeed, - @Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY) long guestLoginDelay) { - this.client = checkNotNull(client, "client"); + @Memoized Supplier createObjectOptionsSupplier, + @Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY) long guestLoginDelay, + @Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_ACTIVE_TRANSACTIONS_DELAY) long activeTransactionsDelay, + @Named(PROPERTY_SOFTLAYER_INCLUDE_PUBLIC_IMAGES) boolean includePublicImages) { + this.api = checkNotNull(api, "api"); this.guestLoginDelay = guestLoginDelay; - this.productPackageSupplier = checkNotNull(productPackageSupplier, "productPackageSupplier"); + this.activeTransactionsDelay = activeTransactionsDelay; + this.includePublicImages = includePublicImages; + this.createObjectOptionsSupplier = checkNotNull(createObjectOptionsSupplier, "createObjectOptionsSupplier"); checkArgument(guestLoginDelay > 500, "guestOrderDelay must be in milliseconds and greater than 500"); this.loginDetailsTester = retry(virtualGuestHasLoginDetailsPresent, guestLoginDelay); - this.cpuPattern = Pattern.compile(checkNotNull(cpuRegex, "cpuRegex")); - this.prices = checkNotNull(prices, "prices"); - this.portSpeed = portSpeed; - checkArgument(portSpeed > 0, "portSpeed must be greater than zero, often 10, 100, 1000, 10000"); - this.disk0Type = Pattern.compile(".*" + checkNotNull(disk0Type, "disk0Type") + ".*"); } @Override @@ -116,148 +132,320 @@ public NodeAndInitialCredentials createNodeWithGroupEncodedIntoNam "options class %s should have been assignable from SoftLayerTemplateOptions", template.getOptions() .getClass()); - String domainName = template.getOptions().as(SoftLayerTemplateOptions.class).getDomainName(); - - VirtualGuest newGuest = VirtualGuest.builder().domain(domainName).hostname(name).build(); + SoftLayerTemplateOptions templateOptions = template.getOptions().as(SoftLayerTemplateOptions.class); + String domainName = templateOptions.getDomainName(); + String diskType = templateOptions.getDiskType().or(DEFAULT_DISK_TYPE); + int portSpeed = templateOptions.getPortSpeed().or(DEFAULT_PORT_SPEED); + + final Datacenter datacenter = Datacenter.builder().name(template.getLocation().getId()).build(); + final String imageId = template.getImage().getId(); + int cores = (int) template.getHardware().getProcessors().get(0).getCores(); + + VirtualGuest.Builder virtualGuestBuilder = VirtualGuest.builder() + .domain(domainName) + .hostname(name) + .startCpus(cores) + .maxMemory(template.getHardware().getRam()) + .datacenter(datacenter) + .networkComponents(VirtualGuestNetworkComponent.builder().speed(portSpeed).build()); + + // set operating system or blockDeviceTemplateGroup + Optional optionalOperatingSystem = tryGetOperatingSystemFrom(imageId); + if (optionalOperatingSystem.isPresent()) { + virtualGuestBuilder.operatingSystem(optionalOperatingSystem.get()); + // the imageId specified is a the id of a public/private/flex image + } else { + VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup = VirtualGuestBlockDeviceTemplateGroup + .builder().globalIdentifier(imageId).build(); + virtualGuestBuilder.blockDeviceTemplateGroup(blockDeviceTemplateGroup).build(); + } + // set multi-disks + if (templateOptions.getBlockDevices().isPresent()) { + Set blockDevices = getBlockDevices(templateOptions.getBlockDevices().get(), diskType); + virtualGuestBuilder.blockDevices(blockDevices); + virtualGuestBuilder.localDiskFlag(isLocalDisk(diskType)); + } - ProductOrder order = ProductOrder.builder().packageId(productPackageSupplier.get().getId()) - .location(template.getLocation().getId()).quantity(1).useHourlyPricing(true).prices(getPrices(template)) - .virtualGuests(newGuest).build(); + VirtualGuest virtualGuest = virtualGuestBuilder.build(); + logger.debug(">> creating new VirtualGuest(%s)", virtualGuest); + VirtualGuest result = api.getVirtualGuestApi().createVirtualGuest(virtualGuest); + logger.trace("<< VirtualGuest(%s)", result.getId()); - logger.debug(">> ordering new virtualGuest domain(%s) hostname(%s)", domainName, name); - ProductOrderReceipt productOrderReceipt = client.getVirtualGuestApi().orderVirtualGuest(order); - VirtualGuest result = get(productOrderReceipt.getOrderDetails().getVirtualGuests(), 0); - logger.trace("<< virtualGuest(%s)", result.getId()); + // tags + if (templateOptions.getTags() != null) { + api.getVirtualGuestApi().setTags(result.getId(), templateOptions.getTags()); + } logger.debug(">> awaiting login details for virtualGuest(%s)", result.getId()); boolean orderInSystem = loginDetailsTester.apply(result); - logger.trace("<< virtualGuest(%s) complete(%s)", result.getId(), orderInSystem); + logger.trace("<< VirtualGuest(%s) complete(%s)", result.getId(), orderInSystem); + + if (!orderInSystem) { + logger.warn("VirtualGuest(%s) doesn't have login details within %sms so it will be destroyed.", result, + Long.toString(guestLoginDelay)); + api.getVirtualGuestApi().deleteVirtualGuest(result.getId()); + throw new IllegalStateException(format("VirtualGuest(%s) is being destroyed as it doesn't have login details" + + " after %sms. Please, try by increasing `jclouds.softlayer.virtualguest.login_details_delay` and " + + " try again", result, Long.toString(guestLoginDelay))); + } + result = api.getVirtualGuestApi().getVirtualGuest(result.getId()); + Password pwd = get(result.getOperatingSystem().getPasswords(), 0); + return new NodeAndInitialCredentials(result, result.getId() + "", + LoginCredentials.builder().user(pwd.getUsername()).password(pwd.getPassword()).build()); + } - checkState(orderInSystem, "order for guest %s doesn't have login details within %sms", result, - Long.toString(guestLoginDelay)); - result = client.getVirtualGuestApi().getVirtualGuest(result.getId()); + /** + * This method will deliberately skip device position 1 as it is reserved to SWAP + * @param blockDeviceCapacities list of blockDevices to be attached + * @param diskType disks can be LOCAL or SAN + * @return + */ + private Set getBlockDevices(List blockDeviceCapacities, String diskType) { + Set blockDevices = Sets.newHashSet(); + int devicePosition = 0; + for (int i = 0; i < blockDeviceCapacities.size(); i++) { + if (i > 0) { devicePosition = i + 1; } + blockDevices.add(VirtualGuestBlockDevice.builder() + .device(devicePosition + "") + .diskImage(VirtualDiskImage.builder() + .capacity(blockDeviceCapacities.get(i)) + .typeId(Type.valueOf(diskType).ordinal()) + .build()) + .build()); + } + return blockDevices; + } - Password pw = get(result.getOperatingSystem().getPasswords(), 0); - return new NodeAndInitialCredentials(result, result.getId() + "", LoginCredentials.builder().user(pw.getUsername()).password( - pw.getPassword()).build()); + private Optional tryGetOperatingSystemFrom(final String imageId) { + Set operatingSystemsAvailable = createObjectOptionsSupplier.get().getVirtualGuestOperatingSystems(); + return tryFind(FluentIterable.from(operatingSystemsAvailable) + .filter(new Predicate() { + @Override + public boolean apply(OperatingSystem input) { + return input.getId().contains(imageId); + } + }), Predicates.notNull()); } - private Iterable getPrices(Template template) { - Builder result = ImmutableSet.builder(); + private boolean isLocalDisk(String diskType) { + return diskType.equalsIgnoreCase(Type.LOCAL.name()); + } - int imageId = Integer.parseInt(template.getImage().getId()); - result.add(ProductItemPrice.builder().id(imageId).build()); + @Override + public Iterable listHardwareProfiles() { + ContainerVirtualGuestConfiguration virtualGuestConfiguration = createObjectOptionsSupplier.get(); + Builder hardware = ImmutableSortedSet.orderedBy(new Comparator() { + @Override + public int compare(Hardware h1, Hardware h2) { + List volumes1 = h1.getVolumes(); + List volumes2 = h2.getVolumes(); + ComparisonChain comparisonChain = ComparisonChain.start().compare(getCores(h1), getCores(h2)) + .compare(h1.getRam(), h2.getRam()) + .compare(getSpace(h1), getSpace(h2)) + .compare(getBootableDeviceType(h1), getBootableDeviceType(h2)); + if(!volumes1.isEmpty() && !volumes2.isEmpty() && volumes1.size() == volumes2.size()) { + for (int i = 0; i < volumes1.size(); i++) { + comparisonChain.compare(volumes1.get(i).getType(), volumes2.get(i).getType()); + } + } + return comparisonChain.result(); + } + }); + for (VirtualGuestBlockDevice blockDevice : virtualGuestConfiguration.getVirtualGuestBlockDevices()) { + float capacity = blockDevice.getVirtualDiskImage().getCapacity(); + Type type = blockDevice.getVirtualGuest().isLocalDiskFlag() ? Type.LOCAL : Type.SAN; + if (blockDevice.getDevice().equals(BOOTABLE_DEVICE)) { + for (Integer cpus : virtualGuestConfiguration.getCpusOfProcessors()) { + for (Integer memory : virtualGuestConfiguration.getMemories()) { + String id = format("cpu=%s,memory=%s,disk=%s,type=%s", cpus, memory, round(capacity), type); + hardware.add(new HardwareBuilder() + .ids(id) + .ram(memory) + .processors(ImmutableList.of(new Processor(cpus, 2))) + .hypervisor("XenServer") + .volumes(ImmutableList.of( + new VolumeImpl(blockDevice.getId() + "", + type, + capacity, + blockDevice.getDevice(), + blockDevice.getBootableFlag() == 1, + true))) + .build()); + } + } + } + } + return hardware.build(); + } - Iterable hardwareIds = Splitter.on(",").split(template.getHardware().getId()); - for (String hardwareId : hardwareIds) { - int id = Integer.parseInt(hardwareId); - result.add(ProductItemPrice.builder().id(id).build()); + private int getBootableDeviceType(Hardware hardware) { + List volumes = hardware.getVolumes(); + Optional optionalBootableVolume = tryFind(volumes, new Predicate() { + @Override + public boolean apply(Volume volume) { + return volume.getDevice().equals(BOOTABLE_DEVICE); + } + }); + if(!optionalBootableVolume.isPresent()) { + return Type.LOCAL.ordinal(); } - ProductItem uplinkItem = find(productPackageSupplier.get().getItems(), - and(capacity(portSpeed), categoryCode("port_speed"))); - result.add(get(uplinkItem.getPrices(), 0)); - result.addAll(prices); - return result.build(); + return optionalBootableVolume.get().getType().ordinal(); } @Override - public Iterable> listHardwareProfiles() { - ProductPackage productPackage = productPackageSupplier.get(); - Set items = productPackage.getItems(); - Builder> result = ImmutableSet.builder(); - for (ProductItem cpuItem : filter(items, matches(cpuPattern))) { - for (ProductItem ramItem : filter(items, categoryCode("ram"))) { - for (ProductItem sanItem : filter(items, and(matches(disk0Type), categoryCode("guest_disk0")))) { - result.add(ImmutableSet.of(cpuItem, ramItem, sanItem)); + public Set listImages() { + Set result = Sets.newHashSet(); + Set unfiltered = api.getSoftwareDescriptionApi().getAllObjects(); + Set operatingSystemsAvailable = createObjectOptionsSupplier.get() + .getVirtualGuestOperatingSystems(); + for (OperatingSystem os : operatingSystemsAvailable) { + final String osReferenceCode = os.getOperatingSystemReferenceCode(); + final String osId = os.getId(); + result.addAll(FluentIterable.from(unfiltered) + .filter(new Predicate() { + @Override + public boolean apply(SoftwareDescription input) { + return isOperatingSystem(input) && input.getReferenceCode().equals(osReferenceCode); + } + }) + .transform(new SoftwareDescriptionToOperatingSystem(osId, osReferenceCode)) + .toSet() + ); + } + + // list private images and transform them to OperatingSystem + Set privateImages = api.getAccountApi().getBlockDeviceTemplateGroups(); + Map privateImagesSoftwareDescriptions = extractSoftwareDescriptions(privateImages); + for (Map.Entry entry : privateImagesSoftwareDescriptions.entrySet()) { + OperatingSystem os = getOperatingSystem(entry); + if (os != null) { + result.add(os); + } + } + // list public images and transform them to OperatingSystem + if (includePublicImages) { + Set publicImages = api.getVirtualGuestBlockDeviceTemplateGroupApi().getPublicImages(); + Map publicImagesSoftwareDescriptions = extractSoftwareDescriptions(publicImages); + for (Map.Entry entry : publicImagesSoftwareDescriptions.entrySet()) { + OperatingSystem os = getOperatingSystem(entry); + if (os != null) { + result.add(os); } } } - return result.build(); + return result; } - @Override - public Iterable listImages() { - return filter(productPackageSupplier.get().getItems(), categoryCode("os")); + private OperatingSystem getOperatingSystem(Map.Entry entry) { + SoftwareDescription softwareDescription = entry.getValue(); + if (isOperatingSystem(softwareDescription)) { + String uuid = entry.getKey(); + return OperatingSystem.builder() + .id(uuid) + .softwareLicense(SoftwareLicense.builder().softwareDescription(softwareDescription).build()) + .operatingSystemReferenceCode(softwareDescription.getReferenceCode()) + .build(); + } + return null; } - - // cheat until we have a getProductItem command - @Override - public ProductItem getImage(final String id) { - return find(listImages(), new Predicate() { - @Override - public boolean apply(ProductItem input) { - return ProductItemToImage.imageId().apply(input).equals(id); + private Map extractSoftwareDescriptions(Set images) { + Map softwareDescriptions = Maps.newHashMap(); + for (VirtualGuestBlockDeviceTemplateGroup image : images) { + final String globalIdentifier = image.getGlobalIdentifier(); + for(VirtualGuestBlockDeviceTemplateGroup child : image.getChildren()) { + for(VirtualGuestBlockDeviceTemplate blockDeviceTemplate : child.getBlockDevices()) { + for(VirtualDiskImageSoftware softwareReference : blockDeviceTemplate.getDiskImage().getSoftwareReferences()) { + softwareDescriptions.put(globalIdentifier, softwareReference.getSoftwareDescription()); + } + } } - - }, null); + } + return softwareDescriptions; } - + @Override - public Iterable listNodes() { - return filter(client.getVirtualGuestApi().listVirtualGuests(), new Predicate() { + public OperatingSystem getImage(final String id) { + return find(listImages(), new Predicate() { @Override - public boolean apply(VirtualGuest arg0) { - boolean hasBillingItem = arg0.getBillingItemId() != -1; - if (hasBillingItem) - return true; - logger.trace("guest invalid, as it has no billing item %s", arg0); - return false; + public boolean apply(OperatingSystem input) { + return input.getId().equals(id); } + }, null); + } - }); + @Override + public Iterable listNodes() { + return api.getAccountApi().listVirtualGuests(); } @Override public Iterable listNodesByIds(final Iterable ids) { return filter(listNodes(), new Predicate() { - @Override - public boolean apply(VirtualGuest server) { - return contains(ids, server.getId()); - } - }); + @Override + public boolean apply(VirtualGuest server) { + return contains(ids, server.getId()); + } + }); } @Override public Iterable listLocations() { - return productPackageSupplier.get().getDatacenters(); + Set result = Sets.newHashSet(); + Set unfiltered = api.getDatacenterApi().listDatacenters(); + Set datacenterAvailable = createObjectOptionsSupplier.get().getVirtualGuestDatacenters(); + for (Datacenter datacenter : datacenterAvailable) { + final String datacenterName = datacenter.getName(); + result.addAll(Sets.newHashSet(filter(unfiltered, + new Predicate() { + @Override + public boolean apply(Datacenter input) { + return input.getName().equals(datacenterName); + } + }))); + } + return result; } @Override public VirtualGuest getNode(String id) { long serverId = Long.parseLong(id); - return client.getVirtualGuestApi().getVirtualGuest(serverId); + return api.getVirtualGuestApi().getVirtualGuest(serverId); } @Override public void destroyNode(String id) { VirtualGuest guest = getNode(id); - if (guest == null) - return; - - if (guest.getBillingItemId() == -1) - throw new IllegalStateException(String.format("no billing item for guest(%s) so we cannot cancel the order", - id)); - - logger.debug(">> canceling service for guest(%s) billingItem(%s)", id, guest.getBillingItemId()); - client.getVirtualGuestApi().cancelService(guest.getBillingItemId()); + if (guest == null) return; + logger.debug(">> awaiting virtualGuest(%s) without active transactions", guest.getId()); + checkState(retry(new Predicate() { + public boolean apply(VirtualGuest guest) { + return getNode(guest.getId() + "").getActiveTransactionCount() == 0; + } + }, activeTransactionsDelay).apply(guest), "%s still has active transactions!", guest); + logger.debug(">> canceling virtualGuest with globalIdentifier(%s)", id); + checkState(api.getVirtualGuestApi().deleteVirtualGuest(guest.getId()), "server(%s) still there after deleting!?", id); } @Override public void rebootNode(String id) { - client.getVirtualGuestApi().rebootHardVirtualGuest(Long.parseLong(id)); + api.getVirtualGuestApi().rebootHardVirtualGuest(Long.parseLong(id)); } @Override public void resumeNode(String id) { - client.getVirtualGuestApi().resumeVirtualGuest(Long.parseLong(id)); + api.getVirtualGuestApi().resumeVirtualGuest(Long.parseLong(id)); } @Override public void suspendNode(String id) { - client.getVirtualGuestApi().pauseVirtualGuest(Long.parseLong(id)); + api.getVirtualGuestApi().pauseVirtualGuest(Long.parseLong(id)); + } + + private boolean isOperatingSystem(SoftwareDescription input) { + return input.getOperatingSystem() == 1; } public static class VirtualGuestHasLoginDetailsPresent implements Predicate { @@ -281,4 +469,22 @@ public boolean apply(VirtualGuest guest) { return hasBackendIp && hasPrimaryIp && hasPasswords; } } + + private static class SoftwareDescriptionToOperatingSystem implements Function { + private final String osId; + private final String operatingSystemReferenceCode; + + public SoftwareDescriptionToOperatingSystem(String osId, String operatingSystemReferenceCode) { + this.osId = osId; + this.operatingSystemReferenceCode = operatingSystemReferenceCode; + } + + @Override + public OperatingSystem apply(SoftwareDescription input) { + return OperatingSystem.builder().id(osId) + .softwareLicense(SoftwareLicense.builder().softwareDescription(input).build()) + .operatingSystemReferenceCode(operatingSystemReferenceCode) + .build(); + } + } } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerHttpApiModule.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerHttpApiModule.java index f20a3f54ca6..bd28b5a49be 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerHttpApiModule.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerHttpApiModule.java @@ -25,7 +25,7 @@ import org.jclouds.location.config.LocationModule; import org.jclouds.location.suppliers.ImplicitLocationSupplier; import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone; -import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.ConfiguresHttpApi; import org.jclouds.rest.config.HttpApiModule; import org.jclouds.softlayer.SoftLayerApi; import org.jclouds.softlayer.handlers.SoftLayerErrorHandler; @@ -34,10 +34,8 @@ /** * Configures the SoftLayer connection. - * - * @author Adrian Cole */ -@ConfiguresRestClient +@ConfiguresHttpApi public class SoftLayerHttpApiModule extends HttpApiModule { @Override diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerParserModule.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerParserModule.java index 537af3e596e..69406248a64 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerParserModule.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerParserModule.java @@ -16,15 +16,11 @@ */ package org.jclouds.softlayer.config; -import org.jclouds.json.config.GsonModule.DateAdapter; -import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; +import static org.jclouds.json.config.GsonModule.DateAdapter; +import static org.jclouds.json.config.GsonModule.Iso8601DateAdapter; import com.google.inject.AbstractModule; -/** - * - * @author Adrian Cole - */ public class SoftLayerParserModule extends AbstractModule { @Override diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Address.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Address.java index f4eafca3cee..e988be3d47c 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Address.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Address.java @@ -18,20 +18,17 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Strings.emptyToNull; - import java.beans.ConstructorProperties; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; +import com.google.inject.name.Named; /** * Class Address * - * @author Jason King - * @see + * @see */ public class Address { @@ -50,6 +47,14 @@ public abstract static class Builder> { protected String country; protected String state; protected String description; + protected int accountId; + @Named("address1") + protected String address; + protected String city; + protected String contactName; + protected int isActive; + protected int locationId; + protected String postalCode; /** * @see Address#getId() @@ -83,8 +88,65 @@ public T description(String description) { return self(); } + /** + * @see org.jclouds.softlayer.domain.Address#getAccountId() + */ + public T accountId(int accountId) { + this.accountId = accountId; + return self(); + } + + /** + * @see org.jclouds.softlayer.domain.Address#getAddress1() + */ + public T address(String address) { + this.address = address; + return self(); + } + + /** + * @see org.jclouds.softlayer.domain.Address#getCity() + */ + public T city(String city) { + this.city = city; + return self(); + } + + /** + * @see org.jclouds.softlayer.domain.Address#getContactName() + */ + public T contactName(String contactName) { + this.contactName = contactName; + return self(); + } + + /** + * @see Address#isActive() + */ + public T isActive(int isActive) { + this.isActive = isActive; + return self(); + } + + /** + * @see org.jclouds.softlayer.domain.Address#getLocationId() + */ + public T locationId(int locationId) { + this.locationId = locationId; + return self(); + } + + /** + * @see org.jclouds.softlayer.domain.Address#getPostalCode() + */ + public T postalCode(String postalCode) { + this.postalCode = postalCode; + return self(); + } + public Address build() { - return new Address(id, country, state, description); + return new Address(id, country, state, description, accountId, address, city, contactName, isActive, + locationId, postalCode); } public T fromAddress(Address in) { @@ -92,7 +154,14 @@ public T fromAddress(Address in) { .id(in.getId()) .country(in.getCountry()) .state(in.getState()) - .description(in.getDescription()); + .description(in.getDescription()) + .accountId(in.getAccountId()) + .address(in.getAddress1()) + .city(in.getCity()) + .contactName(in.getContactName()) + .isActive(in.isActive()) + .locationId(in.getLocationId()) + .postalCode(in.getPostalCode()); } } @@ -107,13 +176,30 @@ protected ConcreteBuilder self() { private final String country; private final String state; private final String description; + private final int accountId; + private final String address; + private final String city; + private final String contactName; + private final int isActive; + private final int locationId; + private final String postalCode; @ConstructorProperties({ - "id", "country", "state", "description" + "id", "country", "state", "description", "accountId", "address1", "city", "contactName", "isActive", + "locationId", "postalCode" }) - protected Address(int id, String country, @Nullable String state, @Nullable String description) { + protected Address(int id, String country, @Nullable String state, @Nullable String description, int accountId, + @Nullable String address, @Nullable String city, @Nullable String contactName, + int isActive, int locationId, @Nullable String postalCode) { this.id = id; - this.country = checkNotNull(emptyToNull(country), "country cannot be null or empty:" + country); + this.accountId = checkNotNull(accountId, "accountId"); + this.address = address; + this.city = city; + this.contactName = contactName; + this.isActive = isActive; + this.locationId = locationId; + this.postalCode = postalCode; + this.country = checkNotNull(emptyToNull(country),"country cannot be null or empty:"+country); this.state = state; this.description = description; } @@ -148,6 +234,62 @@ public String getDescription() { return this.description; } + /** + * @return The id of the account. + */ + @Nullable + public int getAccountId() { + return accountId; + } + + /** + * @return The value of the address. + */ + @Nullable + public String getAddress1() { + return address; + } + + /** + * @return The name of the city. + */ + @Nullable + public String getCity() { + return city; + } + + /** + * @return The name of the contact. + */ + @Nullable + public String getContactName() { + return contactName; + } + + /** + * @return The name of the contact. + */ + @Nullable + public int isActive() { + return isActive; + } + + /** + * @return The id of the location. + */ + @Nullable + public int getLocationId() { + return locationId; + } + + /** + * @return The postal code of the address. + */ + @Nullable + public String getPostalCode() { + return postalCode; + } + @Override public int hashCode() { return Objects.hashCode(id); @@ -161,14 +303,20 @@ public boolean equals(Object obj) { return Objects.equal(this.id, that.id); } - protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("id", id).add("country", country).add("state", state).add("description", description); - } - @Override public String toString() { - return string().toString(); + return Objects.toStringHelper(this) + .add("id", id) + .add("country", country) + .add("state", state) + .add("description", description) + .add("accountId", accountId) + .add("address", address) + .add("city", city) + .add("contactName", contactName) + .add("isActive", isActive) + .add("locationId", locationId) + .add("postalCode", postalCode) + .toString(); } - } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ContainerVirtualGuestConfiguration.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ContainerVirtualGuestConfiguration.java new file mode 100644 index 00000000000..0e097ed4c24 --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ContainerVirtualGuestConfiguration.java @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; +import java.util.Set; + +import com.google.common.base.Function; +import com.google.common.base.Objects; +import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; + +/** + * @see blockDevices; + protected Set datacenters; + protected Set memory; + protected Set networkComponents; + protected Set operatingSystems; + protected Set processors; + + public Builder blockDevices(Set blockDevices) { + this.blockDevices = ImmutableSet.copyOf(checkNotNull(blockDevices, "blockDevices")); + return this; + } + + public Builder blockDevices(ContainerVirtualGuestConfigurationOption... in) { + return blockDevices(ImmutableSet.copyOf(in)); + } + + public Builder datacenters(Set datacenters) { + this.datacenters = ImmutableSet.copyOf(checkNotNull(datacenters, "datacenters")); + return this; + } + + public Builder datacenters(ContainerVirtualGuestConfigurationOption... in) { + return datacenters(ImmutableSet.copyOf(in)); + } + + public Builder memory(Set memory) { + this.memory = ImmutableSet.copyOf(checkNotNull(memory, "memory")); + return this; + } + + public Builder memory(ContainerVirtualGuestConfigurationOption... in) { + return memory(ImmutableSet.copyOf(in)); + } + + public Builder networkComponents(Set networkComponents) { + this.networkComponents = ImmutableSet.copyOf(checkNotNull(networkComponents, "networkComponents")); + return this; + } + + public Builder networkComponents(ContainerVirtualGuestConfigurationOption... in) { + return networkComponents(ImmutableSet.copyOf(in)); + } + + public Builder operatingSystems(Set operatingSystems) { + this.operatingSystems = ImmutableSet.copyOf(checkNotNull(operatingSystems, "operatingSystems")); + return this; + } + + public Builder operatingSystems(ContainerVirtualGuestConfigurationOption... in) { + return operatingSystems(ImmutableSet.copyOf(in)); + } + + public Builder processors(Set processors) { + this.processors = ImmutableSet.copyOf(checkNotNull(processors, "processors")); + return this; + } + + public Builder processors(ContainerVirtualGuestConfigurationOption... in) { + return processors(ImmutableSet.copyOf(in)); + } + + public ContainerVirtualGuestConfiguration build() { + return new ContainerVirtualGuestConfiguration(blockDevices, datacenters, memory, networkComponents, + operatingSystems, processors); + } + + public Builder fromContainerVirtualGuestConfiguration(ContainerVirtualGuestConfiguration in) { + return this + .blockDevices(in.getBlockDevices()) + .datacenters(in.getDatacenters()) + .memory(in.getMemory()) + .networkComponents(in.getNetworkComponents()) + .operatingSystems(in.getOperatingSystems()) + .processors(in.getProcessors()); + } + } + + private final Set blockDevices; + private final Set datacenters; + private final Set memory; + private final Set networkComponents; + private final Set operatingSystems; + private final Set processors; + + @ConstructorProperties({ + "blockDevices", "datacenters", "memory", "networkComponents", "operatingSystems", "processors" + }) + public ContainerVirtualGuestConfiguration(Set blockDevices, + Set datacenters, + Set memory, + Set networkComponents, + Set operatingSystems, + Set processors) { + this.blockDevices = checkNotNull(blockDevices, "blockDevices"); + this.datacenters = checkNotNull(datacenters, "datacenters"); + this.memory = checkNotNull(memory, "memory"); + this.networkComponents = checkNotNull(networkComponents, "networkComponents"); + this.operatingSystems = checkNotNull(operatingSystems, "operatingSystems"); + this.processors = checkNotNull(processors, "processors"); + } + + public Set getBlockDevices() { + return blockDevices; + } + + public Set getDatacenters() { + return datacenters; + } + + public Set getMemory() { + return memory; + } + + public Set getNetworkComponents() { + return networkComponents; + } + + public Set getOperatingSystems() { + return operatingSystems; + } + + public Set getProcessors() { + return processors; + } + + public Set getCpusOfProcessors() { + return Sets.newHashSet(Iterables.transform(processors, new Function() { + @Override + public Integer apply(ContainerVirtualGuestConfigurationOption input) { + return input.getTemplate().getStartCpus(); + } + })); + } + + public Set getMemories() { + return Sets.newHashSet(Iterables.transform(memory, new Function() { + @Override + public Integer apply(ContainerVirtualGuestConfigurationOption input) { + return input.getTemplate().getMaxMemory(); + } + })); + } + + public Set getVirtualGuestDatacenters() { + return Sets.newHashSet(Iterables.transform(datacenters, new Function() { + @Override + public Datacenter apply(ContainerVirtualGuestConfigurationOption input) { + return input.getTemplate().getDatacenter(); + } + })); + } + + public Set getVirtualGuestOperatingSystems() { + return Sets.newHashSet(Iterables.transform(operatingSystems, + new Function() { + @Override + public OperatingSystem apply(ContainerVirtualGuestConfigurationOption input) { + return OperatingSystem.builder() + .id(input.getTemplate().getOperatingSystemReferenceCode()) + .operatingSystemReferenceCode(input.getTemplate().getOperatingSystemReferenceCode()) + .build(); + } + })); + } + + public Set getVirtualGuestBlockDevices() { + if(blockDevices.isEmpty()) return ImmutableSet.of(); + Set virtualGuestBlockDevices = Sets.newHashSet(); + for (final ContainerVirtualGuestConfigurationOption configurationOption : blockDevices) { + virtualGuestBlockDevices.addAll(FluentIterable.from(configurationOption.getTemplate().getVirtualGuestBlockDevices()) + .filter(new Predicate() { + @Override + public boolean apply(VirtualGuestBlockDevice input) { + return !input.getDevice().equals(SWAP_DEVICE); + } + }) + .transform(new Function() { + @Override + public VirtualGuestBlockDevice apply(VirtualGuestBlockDevice input) { + return input.toBuilder().guest(configurationOption.getTemplate()).build(); + } + }) + .toSet()); + } + return virtualGuestBlockDevices; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ContainerVirtualGuestConfiguration that = (ContainerVirtualGuestConfiguration) o; + + return Objects.equal(this.blockDevices, that.blockDevices) && + Objects.equal(this.datacenters, that.datacenters) && + Objects.equal(this.memory, that.memory) && + Objects.equal(this.networkComponents, that.networkComponents) && + Objects.equal(this.operatingSystems, that.operatingSystems) && + Objects.equal(this.processors, that.processors); + } + + @Override + public int hashCode() { + return Objects.hashCode(blockDevices, datacenters, memory, networkComponents, operatingSystems, + processors); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("blockDevices", blockDevices) + .add("datacenters", datacenters) + .add("memory", memory) + .add("networkComponents", networkComponents) + .add("operatingSystems", operatingSystems) + .add("processors", processors) + .toString(); + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ContainerVirtualGuestConfigurationOption.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ContainerVirtualGuestConfigurationOption.java new file mode 100644 index 00000000000..c2201d399b6 --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ContainerVirtualGuestConfigurationOption.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.inject.name.Named; + +/** + * @see + */ +public class ContainerVirtualGuestConfigurationOption { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromContainerVirtualGuestConfigurationOption(this); + } + + public static class Builder { + + protected ProductItemPrice productItemPrice; + protected VirtualGuest template; + + public Builder productItemPrice(ProductItemPrice productItemPrice) { + this.productItemPrice = productItemPrice; + return this; + } + + public Builder template(VirtualGuest template) { + this.template = template; + return this; + } + + public ContainerVirtualGuestConfigurationOption build() { + return new ContainerVirtualGuestConfigurationOption(productItemPrice, template); + } + + public Builder fromContainerVirtualGuestConfigurationOption(ContainerVirtualGuestConfigurationOption in) { + return this + .productItemPrice(in.getProductItemPrice()) + .template(in.getTemplate()); + } + } + + @Named("itemPrice") + private final ProductItemPrice productItemPrice; + private final VirtualGuest template; + + @ConstructorProperties({"itemPrice", "template"}) + public ContainerVirtualGuestConfigurationOption(@Nullable ProductItemPrice productItemPrice, + VirtualGuest template) { + this.productItemPrice = productItemPrice; + this.template = checkNotNull(template, "template"); + } + + public ProductItemPrice getProductItemPrice() { + return productItemPrice; + } + + public VirtualGuest getTemplate() { + return template; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ContainerVirtualGuestConfigurationOption that = (ContainerVirtualGuestConfigurationOption) o; + + return Objects.equal(this.productItemPrice, that.productItemPrice) && + Objects.equal(this.template, that.template); + } + + @Override + public int hashCode() { + return Objects.hashCode(productItemPrice, template); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("productItemPrice", productItemPrice) + .add("template", template) + .toString(); + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Datacenter.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Datacenter.java index 9dcca1a1c07..5180ab63ab7 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Datacenter.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Datacenter.java @@ -17,20 +17,17 @@ package org.jclouds.softlayer.domain; import static com.google.common.base.Preconditions.checkNotNull; - import java.beans.ConstructorProperties; import java.util.Set; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; /** * Class Datacenter * - * @author Adrian Cole * @see */ @@ -177,27 +174,34 @@ public Set getRegions() { return this.regions; } - @Override - public int hashCode() { - return Objects.hashCode(id); - } @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - Datacenter that = Datacenter.class.cast(obj); - return Objects.equal(this.id, that.id); + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Datacenter that = (Datacenter) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.name, that.name) && + Objects.equal(this.longName, that.longName) && + Objects.equal(this.locationAddress, that.locationAddress) && + Objects.equal(this.regions, that.regions); } - protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("id", id).add("name", name).add("longName", longName).add("locationAddress", locationAddress).add("regions", regions); + @Override + public int hashCode() { + return Objects.hashCode(id, name, longName, locationAddress, regions); } @Override public String toString() { - return string().toString(); + return Objects.toStringHelper(this) + .add("id", id) + .add("name", name) + .add("longName", longName) + .add("locationAddress", locationAddress) + .add("regions", regions) + .toString(); } - } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/OperatingSystem.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/OperatingSystem.java index 3a59a68098d..053a91a347d 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/OperatingSystem.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/OperatingSystem.java @@ -17,96 +17,113 @@ package org.jclouds.softlayer.domain; import static com.google.common.base.Preconditions.checkNotNull; - import java.beans.ConstructorProperties; import java.util.Set; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; /** * Extends the SoftLayer_Software_Component data type to include operating system specific properties. * - * @author Jason King - * @see + * @see */ public class OperatingSystem { - public static Builder builder() { - return new ConcreteBuilder(); + public static Builder builder() { + return new Builder(); } - public Builder toBuilder() { - return new ConcreteBuilder().fromOperatingSystem(this); + public Builder toBuilder() { + return builder().fromOperatingSystem(this); } - public abstract static class Builder> { - protected abstract T self(); + public static class Builder { - protected int id; + protected String id; + protected SoftwareLicense softwareLicense; + protected String operatingSystemReferenceCode; protected Set passwords = ImmutableSet.of(); /** * @see OperatingSystem#getId() */ - public T id(int id) { + public Builder id(String id) { this.id = id; - return self(); + return this; + } + + /** + * @see OperatingSystem#getSoftwareLicense() + */ + public Builder softwareLicense(SoftwareLicense softwareLicense) { + this.softwareLicense = softwareLicense; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.OperatingSystem#getOperatingSystemReferenceCode() + */ + public Builder operatingSystemReferenceCode(String operatingSystemReferenceCode) { + this.operatingSystemReferenceCode = operatingSystemReferenceCode; + return this; } /** * @see OperatingSystem#getPasswords() */ - public T passwords(Set passwords) { + public Builder passwords(Set passwords) { this.passwords = ImmutableSet.copyOf(checkNotNull(passwords, "passwords")); - return self(); + return this; } - public T passwords(Password... in) { + public Builder passwords(Password... in) { return passwords(ImmutableSet.copyOf(in)); } public OperatingSystem build() { - return new OperatingSystem(id, passwords); + return new OperatingSystem(id, softwareLicense, operatingSystemReferenceCode, passwords); } - public T fromOperatingSystem(OperatingSystem in) { - return this - .id(in.getId()) - .passwords(in.getPasswords()); + public Builder fromOperatingSystem(OperatingSystem in) { + return this.id(in.getId()).passwords(in.getPasswords()); } - } - private static class ConcreteBuilder extends Builder { - @Override - protected ConcreteBuilder self() { - return this; - } } - private final int id; + private final String id; + private final SoftwareLicense softwareLicense; + private final String operatingSystemReferenceCode; private final Set passwords; @ConstructorProperties({ - "id", "passwords" + "id", "softwareLicense", "operatingSystemReferenceCode", "passwords" }) - protected OperatingSystem(int id, @Nullable Set passwords) { - this.id = id; + protected OperatingSystem(String id, @Nullable SoftwareLicense softwareLicense, + @Nullable String operatingSystemReferenceCode, @Nullable Set passwords) { + this.id = checkNotNull(id, "id"); + this.softwareLicense = softwareLicense; + this.operatingSystemReferenceCode = operatingSystemReferenceCode; this.passwords = passwords == null ? ImmutableSet.of() : ImmutableSet.copyOf(passwords); } /** * @return An ID number identifying this Software Component (Software Installation) */ - public int getId() { + public String getId() { return this.id; } + public SoftwareLicense getSoftwareLicense() { + return softwareLicense; + } + + public String getOperatingSystemReferenceCode() { + return operatingSystemReferenceCode; + } + /** * @return Username/Password pairs used for access to this Software Installation. */ @@ -115,26 +132,30 @@ public Set getPasswords() { } @Override - public int hashCode() { - return Objects.hashCode(id); - } + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - OperatingSystem that = OperatingSystem.class.cast(obj); - return Objects.equal(this.id, that.id); + OperatingSystem that = (OperatingSystem) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.softwareLicense, that.softwareLicense) && + Objects.equal(this.operatingSystemReferenceCode, that.operatingSystemReferenceCode) && + Objects.equal(this.passwords, that.passwords); } - protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("id", id).add("passwords", passwords); + @Override + public int hashCode() { + return Objects.hashCode(id, softwareLicense, operatingSystemReferenceCode, passwords); } @Override public String toString() { - return string().toString(); + return Objects.toStringHelper(this) + .add("id", id) + .add("softwareLicense", softwareLicense) + .add("operatingSystemReferenceCode", operatingSystemReferenceCode) + .add("passwords", passwords) + .toString(); } - } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Password.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Password.java index 60eabebb4d8..66629cff105 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Password.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Password.java @@ -18,18 +18,15 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Strings.emptyToNull; - import java.beans.ConstructorProperties; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; /** * Contains a password for a specific software component instance * - * @author Jason King * @see */ @@ -100,7 +97,7 @@ protected ConcreteBuilder self() { @ConstructorProperties({"id", "username", "password"}) public Password(int id, String username, @Nullable String password) { this.id = id; - this.username = checkNotNull(emptyToNull(username), "username cannot be null or empty:" + username); + this.username = checkNotNull(emptyToNull(username),"username cannot be null or empty:"+username); this.password = password; } @@ -140,13 +137,12 @@ public boolean equals(Object obj) { return Objects.equal(this.id, that.id); } - protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("id", id).add("username", username).add("password", password); - } - @Override public String toString() { - return string().toString(); + return Objects.toStringHelper(this) + .add("id", id) + .add("username", username) + .add("password", password) + .toString(); } } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/PowerState.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/PowerState.java index 5fce3884f10..eb6239420e7 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/PowerState.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/PowerState.java @@ -28,7 +28,6 @@ /** * The power state class provides a common set of values for which a guest's power state will be presented in the SoftLayer API. * - * @author Jason King * @see */ @@ -76,7 +75,7 @@ protected ConcreteBuilder self() { @ConstructorProperties("keyName") public PowerState(VirtualGuest.State keyName) { - this.keyName = checkNotNull(keyName, "keyName cannot be null or empty:" + keyName); + this.keyName = checkNotNull(keyName,"keyName cannot be null or empty:"+keyName); } /** diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItem.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItem.java index a281087a186..79c8d5bc5f9 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItem.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItem.java @@ -16,211 +16,132 @@ */ package org.jclouds.softlayer.domain; -import static com.google.common.base.Preconditions.checkNotNull; - import java.beans.ConstructorProperties; -import java.util.Set; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; -import com.google.common.collect.ImmutableSet; /** - * The SoftLayer_Product_Item data type contains general information relating to - * a single SoftLayer product. - * - * @author Adrian Cole - * @see + * @see builder() { - return new ConcreteBuilder(); + private final int id; + private final String description; + private final String softwareDescriptionId; + private final SoftwareDescription softwareDescription; + + @ConstructorProperties({"id", "description", "softwareDescriptionId", "softwareDescription"}) + public ProductItem(int id, @Nullable String description, @Nullable String softwareDescriptionId, + @Nullable SoftwareDescription softwareDescription) { + this.id = id; + this.description = description; + this.softwareDescriptionId = softwareDescriptionId; + this.softwareDescription = softwareDescription; + } + + public int getId() { + return id; + } + + public String getDescription() { + return description; + } + + public String getSoftwareDescriptionId() { + return softwareDescriptionId; } - public Builder toBuilder() { - return new ConcreteBuilder().fromProductItem(this); + public SoftwareDescription getSoftwareDescription() { + return softwareDescription; } - public abstract static class Builder> { - protected abstract T self(); - protected int id; - protected String description; - protected String units; - protected Float capacity; - protected Set prices = ImmutableSet.of(); - protected Set categories = ImmutableSet.of(); + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ProductItem that = (ProductItem) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.description, that.description) && + Objects.equal(this.softwareDescriptionId, that.softwareDescriptionId) && + Objects.equal(this.softwareDescription, that.softwareDescription); + } + + @Override + public int hashCode() { + return Objects.hashCode(id, description, softwareDescriptionId, softwareDescription); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("id", id) + .add("description", description) + .add("softwareDescriptionId", softwareDescriptionId) + .add("softwareDescription", softwareDescription) + .toString(); + } + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromProductItem(this); + } + + public static class Builder { + private int id; + private String description; + private String softwareDescriptionId; + private SoftwareDescription softwareDescription; /** * @see ProductItem#getId() */ - public T id(int id) { + public Builder id(int id) { this.id = id; - return self(); + return this; } /** - * @see ProductItem#getDescription() + * @see org.jclouds.softlayer.domain.ProductItem#getDescription() () */ - public T description(String description) { + public Builder description(String description) { this.description = description; - return self(); - } - - /** - * @see ProductItem#getUnits() - */ - public T units(String units) { - this.units = units; - return self(); + return this; } /** - * @see ProductItem#getCapacity() + * @see org.jclouds.softlayer.domain.ProductItem#getSoftwareDescriptionId() () */ - public T capacity(Float capacity) { - this.capacity = capacity; - return self(); + public Builder softwareDescriptionId(String softwareDescriptionId) { + this.softwareDescriptionId = softwareDescriptionId; + return this; } /** - * @see ProductItem#getPrices() + * @see ProductItem#getSoftwareDescription() */ - public T prices(Set prices) { - this.prices = ImmutableSet.copyOf(checkNotNull(prices, "prices")); - return self(); - } - - public T prices(ProductItemPrice... in) { - return prices(ImmutableSet.copyOf(in)); - } - - /** - * @see ProductItem#getCategories() - */ - public T categories(Set categories) { - this.categories = ImmutableSet.copyOf(checkNotNull(categories, "categories")); - return self(); - } - - public T categories(ProductItemCategory... in) { - return categories(ImmutableSet.copyOf(in)); + public Builder softwareDescription(SoftwareDescription softwareDescription) { + this.softwareDescription = softwareDescription; + return this; } public ProductItem build() { - return new ProductItem(id, description, units, capacity, prices, categories); + return new ProductItem(id, description, softwareDescriptionId, softwareDescription); } - public T fromProductItem(ProductItem in) { + public Builder fromProductItem(ProductItem in) { return this - .id(in.getId()) - .description(in.getDescription()) - .units(in.getUnits()) - .capacity(in.getCapacity()) - .prices(in.getPrices()) - .categories(in.getCategories()); + .id(in.getId()) + .description(in.getDescription()) + .softwareDescriptionId(in.getSoftwareDescriptionId()) + .softwareDescription(in.getSoftwareDescription()); } } - private static class ConcreteBuilder extends Builder { - @Override - protected ConcreteBuilder self() { - return this; - } - } - - private final int id; - private final String description; - private final String units; - private final Float capacity; - private final Set prices; - private final Set categories; - - @ConstructorProperties({ - "id", "description", "units", "capacity", "prices", "categories" - }) - protected ProductItem(int id, @Nullable String description, @Nullable String units, @Nullable Float capacity, @Nullable Set prices, @Nullable Set categories) { - this.id = id; - this.description = description; - this.units = units; - this.capacity = capacity; - this.prices = prices == null ? ImmutableSet.of() : ImmutableSet.copyOf(prices); - this.categories = categories == null ? ImmutableSet.of() : ImmutableSet.copyOf(categories); - } - - /** - * @return The unique identifier of a specific location. - */ - public int getId() { - return this.id; - } - - /** - * @return A product's description - */ - @Nullable - public String getDescription() { - return this.description; - } - - /** - * @return The unit of measurement that a product item is measured in. - */ - @Nullable - public String getUnits() { - return this.units; - } - - /** - * @return Some Product Items have capacity information such as RAM and - bandwidth, and others. This provides the numerical representation - of the capacity given in the description of this product item. - */ - @Nullable - public Float getCapacity() { - return this.capacity; - } - - /** - * @return A product item's prices. - */ - public Set getPrices() { - return this.prices; - } - - /** - * @return An item's associated item categories. - */ - public Set getCategories() { - return this.categories; - } - - @Override - public int hashCode() { - return Objects.hashCode(id); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - ProductItem that = ProductItem.class.cast(obj); - return Objects.equal(this.id, that.id); - } - - protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("id", id).add("description", description).add("units", units).add("capacity", capacity).add("prices", prices).add("categories", categories); - } - - @Override - public String toString() { - return string().toString(); - } - } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemCategory.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemCategory.java deleted file mode 100644 index 940940e48e4..00000000000 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemCategory.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.domain; - -import java.beans.ConstructorProperties; - -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; - -/** - * The SoftLayer_Product_Item_Category data type contains - * general category information for prices. - * - * @author Jason King - * @see - */ -public class ProductItemCategory { - - public static Builder builder() { - return new ConcreteBuilder(); - } - - public Builder toBuilder() { - return new ConcreteBuilder().fromProductItemCategory(this); - } - - public abstract static class Builder> { - protected abstract T self(); - - protected int id; - protected String name; - protected String categoryCode; - - /** - * @see ProductItemCategory#getId() - */ - public T id(int id) { - this.id = id; - return self(); - } - - /** - * @see ProductItemCategory#getName() - */ - public T name(String name) { - this.name = name; - return self(); - } - - /** - * @see ProductItemCategory#getCategoryCode() - */ - public T categoryCode(String categoryCode) { - this.categoryCode = categoryCode; - return self(); - } - - public ProductItemCategory build() { - return new ProductItemCategory(id, name, categoryCode); - } - - public T fromProductItemCategory(ProductItemCategory in) { - return this - .id(in.getId()) - .name(in.getName()) - .categoryCode(in.getCategoryCode()); - } - } - - private static class ConcreteBuilder extends Builder { - @Override - protected ConcreteBuilder self() { - return this; - } - } - - private final int id; - private final String name; - private final String categoryCode; - - @ConstructorProperties({ - "id", "name", "categoryCode" - }) - protected ProductItemCategory(int id, @Nullable String name, @Nullable String categoryCode) { - this.id = id; - this.name = name; - this.categoryCode = categoryCode; - } - - /** - * @return The unique identifier of a specific location. - */ - public int getId() { - return this.id; - } - - /** - * @return The friendly, descriptive name of the category as seen on the order forms and on invoices. - */ - @Nullable - public String getName() { - return this.name; - } - - /** - * @return The code used to identify this category. - */ - @Nullable - public String getCategoryCode() { - return this.categoryCode; - } - - @Override - public int hashCode() { - return Objects.hashCode(id); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - ProductItemCategory that = ProductItemCategory.class.cast(obj); - return Objects.equal(this.id, that.id); - } - - protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("id", id).add("name", name).add("categoryCode", categoryCode); - } - - @Override - public String toString() { - return string().toString(); - } - -} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemPrice.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemPrice.java index bd359ad2494..8bfc0ec787c 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemPrice.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductItemPrice.java @@ -17,210 +17,129 @@ package org.jclouds.softlayer.domain; import static com.google.common.base.Preconditions.checkNotNull; - import java.beans.ConstructorProperties; -import java.util.Set; - -import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; -import com.google.common.collect.ImmutableSet; /** - * The SoftLayer_Product_Item_Price data type contains general information - * relating to a single SoftLayer product item prices. You can find out what - * packages each prices is in as well as which category under which this prices is - * sold. All prices are returned in Floating point values measured in US Dollars - * ($USD). - * - * @author Adrian Cole - * @see + * @see builder() { - return new ConcreteBuilder(); + private final int id; + private final float hourlyRecurringFee; + private final String recurringFee; + private final ProductItem item; + + @ConstructorProperties({"id", "hourlyRecurringFee", "recurringFee", "item"}) + public ProductItemPrice(int id, float hourlyRecurringFee, String recurringFee, ProductItem item) { + this.id = id; + this.hourlyRecurringFee = hourlyRecurringFee; + this.recurringFee = checkNotNull(recurringFee, "recurringFee"); + this.item = checkNotNull(item, "item"); + } + + public int getId() { + return id; + } + + public float getHourlyRecurringFee() { + return hourlyRecurringFee; + } + + public String getRecurringFee() { + return recurringFee; + } + + public ProductItem getItem() { + return item; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ProductItemPrice that = (ProductItemPrice) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.hourlyRecurringFee, that.hourlyRecurringFee) && + Objects.equal(this.recurringFee, that.recurringFee) && + Objects.equal(this.item, that.item); + } + + @Override + public int hashCode() { + return Objects.hashCode(id, hourlyRecurringFee, recurringFee, item); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("id", id) + .add("hourlyRecurringFee", hourlyRecurringFee) + .add("recurringFee", recurringFee) + .add("item", item) + .toString(); } - public Builder toBuilder() { - return new ConcreteBuilder().fromProductItemPrice(this); + public static Builder builder() { + return new Builder(); } - public abstract static class Builder> { - protected abstract T self(); + public Builder toBuilder() { + return builder().fromProductItemPrice(this); + } - protected int id; - protected long itemId; - protected Float recurringFee; - protected Float hourlyRecurringFee; - protected ProductItem item; - protected Set categories = ImmutableSet.of(); + public static class Builder { + private int id; + private float hourlyRecurringFee; + private String recurringFee; + private ProductItem item; /** * @see ProductItemPrice#getId() */ - public T id(int id) { + public Builder id(int id) { this.id = id; - return self(); + return this; } /** - * @see ProductItemPrice#getItemId() + * @see ProductItemPrice#getHourlyRecurringFee() */ - public T itemId(long itemId) { - this.itemId = itemId; - return self(); + public Builder hourlyRecurringFee(float hourlyRecurringFee) { + this.hourlyRecurringFee = hourlyRecurringFee; + return this; } /** * @see ProductItemPrice#getRecurringFee() */ - public T recurringFee(Float recurringFee) { + public Builder recurringFee(String recurringFee) { this.recurringFee = recurringFee; - return self(); - } - - /** - * @see ProductItemPrice#getHourlyRecurringFee() - */ - public T hourlyRecurringFee(Float hourlyRecurringFee) { - this.hourlyRecurringFee = hourlyRecurringFee; - return self(); + return this; } /** - * @see ProductItemPrice#getItem() + * @see org.jclouds.softlayer.domain.ProductItemPrice#getItem() */ - public T item(ProductItem item) { + public Builder item(ProductItem item) { this.item = item; - return self(); - } - - /** - * @see ProductItemPrice#getCategories() - */ - public T categories(Set categories) { - this.categories = ImmutableSet.copyOf(checkNotNull(categories, "categories")); - return self(); - } - - public T categories(ProductItemCategory... in) { - return categories(ImmutableSet.copyOf(in)); + return this; } public ProductItemPrice build() { - return new ProductItemPrice(id, itemId, recurringFee, hourlyRecurringFee, item, categories); + return new ProductItemPrice(id, hourlyRecurringFee, recurringFee, item); } - public T fromProductItemPrice(ProductItemPrice in) { + public Builder fromProductItemPrice(ProductItemPrice in) { return this - .id(in.getId()) - .itemId(in.getItemId()) - .recurringFee(in.getRecurringFee()) - .hourlyRecurringFee(in.getHourlyRecurringFee()) - .item(in.getItem()) - .categories(in.getCategories()); + .id(in.getId()) + .hourlyRecurringFee(in.getHourlyRecurringFee()) + .recurringFee(in.getRecurringFee()) + .item(in.getItem()); } } - - private static class ConcreteBuilder extends Builder { - @Override - protected ConcreteBuilder self() { - return this; - } - } - - private final int id; - private final long itemId; - private final Float recurringFee; - private final Float hourlyRecurringFee; - private final ProductItem item; - private final Set categories; - - @ConstructorProperties({ - "id", "itemId", "recurringFee", "hourlyRecurringFee", "item", "categories" - }) - protected ProductItemPrice(int id, long itemId, @Nullable Float recurringFee, @Nullable Float hourlyRecurringFee, @Nullable ProductItem item, @Nullable Set categories) { - this.id = id; - this.itemId = itemId; - this.recurringFee = recurringFee; - this.hourlyRecurringFee = hourlyRecurringFee; - this.item = item; - this.categories = categories == null ? ImmutableSet.of() : ImmutableSet.copyOf(categories); - } - - /** - * @return The unique identifier of a Product Item Price. - */ - public int getId() { - return this.id; - } - - /** - * @return The unique identifier for a product Item - */ - public long getItemId() { - return this.itemId; - } - - /** - * @return A recurring fee is a fee that happens every billing period. This - fee is represented as a Floating point decimal in US dollars - ($USD). - */ - @Nullable - public Float getRecurringFee() { - return this.recurringFee; - } - - /** - * @return The hourly prices for this item, should this item be part of an - hourly pricing package. - */ - @Nullable - public Float getHourlyRecurringFee() { - return this.hourlyRecurringFee; - } - - /** - * @return The product item a prices is tied to. - */ - @Nullable - public ProductItem getItem() { - return this.item; - } - - /** - * @return An item's associated item categories. - */ - public Set getCategories() { - return this.categories; - } - - @Override - public int hashCode() { - return Objects.hashCode(id); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - ProductItemPrice that = ProductItemPrice.class.cast(obj); - return Objects.equal(this.id, that.id); - } - - protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("id", id).add("itemId", itemId).add("recurringFee", recurringFee).add("hourlyRecurringFee", hourlyRecurringFee).add("item", item).add("categories", categories); - } - - @Override - public String toString() { - return string().toString(); - } - } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrder.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrder.java deleted file mode 100644 index a0f7072a03d..00000000000 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrder.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.domain; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.beans.ConstructorProperties; -import java.util.Set; - -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; -import com.google.common.collect.ImmutableSet; - -/** - * Class ProductOrder - * - * @author Jason King - * @see - */ -public class ProductOrder { - - public static Builder builder() { - return new ConcreteBuilder(); - } - - public Builder toBuilder() { - return new ConcreteBuilder().fromProductOrder(this); - } - - public abstract static class Builder> { - protected abstract T self(); - - protected int packageId; - protected String location; - protected Set prices = ImmutableSet.of(); - protected Set virtualGuests = ImmutableSet.of(); - protected int quantity; - protected boolean useHourlyPricing; - - /** - * @see ProductOrder#getPackageId() - */ - public T packageId(int packageId) { - this.packageId = packageId; - return self(); - } - - /** - * @see ProductOrder#getLocation() - */ - public T location(String location) { - this.location = location; - return self(); - } - - /** - * @see ProductOrder#getPrices() - */ - public T prices(Iterable prices) { - this.prices = ImmutableSet.copyOf(checkNotNull(prices, "prices")); - return self(); - } - - public T prices(ProductItemPrice... in) { - return prices(ImmutableSet.copyOf(in)); - } - - /** - * @see ProductOrder#getVirtualGuests() - */ - public T virtualGuests(Set virtualGuests) { - this.virtualGuests = ImmutableSet.copyOf(checkNotNull(virtualGuests, "virtualGuests")); - return self(); - } - - public T virtualGuests(VirtualGuest... in) { - return virtualGuests(ImmutableSet.copyOf(in)); - } - - /** - * @see ProductOrder#getQuantity() - */ - public T quantity(int quantity) { - this.quantity = quantity; - return self(); - } - - /** - * @see ProductOrder#getUseHourlyPricing() - */ - public T useHourlyPricing(boolean useHourlyPricing) { - this.useHourlyPricing = useHourlyPricing; - return self(); - } - - public ProductOrder build() { - return new ProductOrder(packageId, location, prices, virtualGuests, quantity, useHourlyPricing); - } - - public T fromProductOrder(ProductOrder in) { - return this - .packageId(in.getPackageId()) - .location(in.getLocation()) - .prices(in.getPrices()) - .virtualGuests(in.getVirtualGuests()) - .quantity(in.getQuantity()) - .useHourlyPricing(in.getUseHourlyPricing()); - } - } - - private static class ConcreteBuilder extends Builder { - @Override - protected ConcreteBuilder self() { - return this; - } - } - - private final int packageId; - private final String location; - private final Set prices; - private final Set virtualGuests; - private final int quantity; - private final boolean useHourlyPricing; - - @ConstructorProperties({ - "packageId", "location", "prices", "virtualGuest", "quantity", "useHourlyPricing" - }) - protected ProductOrder(int packageId, @Nullable String location, @Nullable Set prices, @Nullable Set virtualGuests, int quantity, boolean useHourlyPricing) { - this.packageId = packageId; - this.location = location; - this.prices = prices == null ? ImmutableSet.of() : ImmutableSet.copyOf(prices); - this.virtualGuests = virtualGuests == null ? ImmutableSet.of() : ImmutableSet.copyOf(virtualGuests); - this.quantity = quantity; - this.useHourlyPricing = useHourlyPricing; - } - - /** - * @return The package id of an order. This is required. - */ - public int getPackageId() { - return this.packageId; - } - - /** - * @return The region keyname or specific location keyname where the order should be provisioned. - */ - @Nullable - public String getLocation() { - return this.location; - } - - /** - * Gets the item prices in this order. - * All that is required to be present is the prices ID - * - * @return the prices. - */ - public Set getPrices() { - return this.prices; - } - - /** - * Gets the virtual guests in this order. - * - * @return the the virtual guests. - */ - public Set getVirtualGuests() { - return this.virtualGuests; - } - - public int getQuantity() { - return this.quantity; - } - - public boolean getUseHourlyPricing() { - return this.useHourlyPricing; - } - - @Override - public int hashCode() { - return Objects.hashCode(packageId, location, prices, virtualGuests, quantity, useHourlyPricing); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - ProductOrder that = ProductOrder.class.cast(obj); - return Objects.equal(this.packageId, that.packageId) - && Objects.equal(this.location, that.location) - && Objects.equal(this.prices, that.prices) - && Objects.equal(this.virtualGuests, that.virtualGuests) - && Objects.equal(this.quantity, that.quantity) - && Objects.equal(this.useHourlyPricing, that.useHourlyPricing); - } - - protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("packageId", packageId).add("location", location).add("prices", prices).add("virtualGuests", virtualGuests).add("quantity", quantity).add("useHourlyPricing", useHourlyPricing); - } - - @Override - public String toString() { - return string().toString(); - } - -} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrderReceipt.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrderReceipt.java deleted file mode 100644 index 3954b663237..00000000000 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductOrderReceipt.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.domain; - -import java.beans.ConstructorProperties; - -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; - -/** - * Class ProductOrderReceipt - * - * @author Jason King - * @see - */ -public class ProductOrderReceipt { - - public static Builder builder() { - return new ConcreteBuilder(); - } - - public Builder toBuilder() { - return new ConcreteBuilder().fromProductOrderReceipt(this); - } - - public abstract static class Builder> { - protected abstract T self(); - - protected int orderId; - protected ProductOrder orderDetails; - - /** - * @see ProductOrderReceipt#getOrderId() - */ - public T orderId(int orderId) { - this.orderId = orderId; - return self(); - } - - /** - * @see ProductOrderReceipt#getOrderDetails() - */ - public T orderDetails(ProductOrder orderDetails) { - this.orderDetails = orderDetails; - return self(); - } - - public ProductOrderReceipt build() { - return new ProductOrderReceipt(orderId, orderDetails); - } - - public T fromProductOrderReceipt(ProductOrderReceipt in) { - return this - .orderId(in.getOrderId()) - .orderDetails(in.getOrderDetails()); - } - } - - private static class ConcreteBuilder extends Builder { - @Override - protected ConcreteBuilder self() { - return this; - } - } - - private final int orderId; - private final ProductOrder orderDetails; - - @ConstructorProperties({ - "orderId", "orderDetails" - }) - protected ProductOrderReceipt(int orderId, @Nullable ProductOrder orderDetails) { - this.orderId = orderId; - this.orderDetails = orderDetails; - } - - /** - * @return unique identifier for the order. - */ - public int getOrderId() { - return this.orderId; - } - - /** - * This is a copy of the SoftLayer_Container_Product_Order - * which holds all the data related to an order. - * This will only return when an order is processed successfully. - * It will contain all the items in an order as well as the order totals. - */ - @Nullable - public ProductOrder getOrderDetails() { - return this.orderDetails; - } - - @Override - public int hashCode() { - return Objects.hashCode(orderId, orderDetails); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - ProductOrderReceipt that = ProductOrderReceipt.class.cast(obj); - return Objects.equal(this.orderId, that.orderId) - && Objects.equal(this.orderDetails, that.orderDetails); - } - - protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("orderId", orderId).add("orderDetails", orderDetails); - } - - @Override - public String toString() { - return string().toString(); - } - -} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductPackage.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductPackage.java deleted file mode 100644 index b6a573b17a8..00000000000 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/ProductPackage.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.domain; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.beans.ConstructorProperties; -import java.util.Set; - -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; -import com.google.common.collect.ImmutableSet; - -/** - * The SoftLayer_Product_Package data type contains information about packages - * from which orders can be generated. Packages contain general information - * regarding what is in them, where they are currently sold, availability, and - * pricing. - * - * @author Adrian Cole - * @see - */ -public class ProductPackage { - - public static Builder builder() { - return new ConcreteBuilder(); - } - - public Builder toBuilder() { - return new ConcreteBuilder().fromProductPackage(this); - } - - public abstract static class Builder> { - protected abstract T self(); - - protected int id; - protected String name; - protected String description; - protected Set items = ImmutableSet.of(); - protected Set locations = ImmutableSet.of(); - - /** - * @see ProductPackage#getId() - */ - public T id(int id) { - this.id = id; - return self(); - } - - /** - * @see ProductPackage#getName() - */ - public T name(String name) { - this.name = name; - return self(); - } - - /** - * @see ProductPackage#getDescription() - */ - public T description(String description) { - this.description = description; - return self(); - } - - /** - * @see ProductPackage#getItems() - */ - public T items(Set items) { - this.items = ImmutableSet.copyOf(checkNotNull(items, "items")); - return self(); - } - - public T items(ProductItem... in) { - return items(ImmutableSet.copyOf(in)); - } - - /** - * @see ProductPackage#getDatacenters() - */ - public T datacenters(Set locations) { - this.locations = ImmutableSet.copyOf(checkNotNull(locations, "locations")); - return self(); - } - - public T datacenters(Datacenter... in) { - return datacenters(ImmutableSet.copyOf(in)); - } - - public ProductPackage build() { - return new ProductPackage(id, name, description, items, locations); - } - - public T fromProductPackage(ProductPackage in) { - return this - .id(in.getId()) - .name(in.getName()) - .description(in.getDescription()) - .items(in.getItems()) - .datacenters(in.getDatacenters()); - } - } - - private static class ConcreteBuilder extends Builder { - @Override - protected ConcreteBuilder self() { - return this; - } - } - - private final int id; - private final String name; - private final String description; - private final Set items; - private final Set locations; - - @ConstructorProperties({ - "id", "name", "description", "items", "locations" - }) - protected ProductPackage(int id, @Nullable String name, @Nullable String description, @Nullable Set items, Set locations) { - this.id = id; - this.name = name; - this.description = description; - this.items = items == null ? ImmutableSet.of() : ImmutableSet.copyOf(items); - this.locations = locations == null ? ImmutableSet.of() : ImmutableSet.copyOf(locations); - } - - /** - * @return A package's internal identifier. Everything regarding a - SoftLayer_Product_Package is tied back to this id. - */ - public int getId() { - return this.id; - } - - /** - * @return The description of the package. For server packages, this is - usually a detailed description of processor type and count. - */ - @Nullable - public String getName() { - return this.name; - } - - /** - * @return A generic description of the processor type and count. This - includes HTML, so you may want to strip these tags if you plan to - use it. - */ - @Nullable - public String getDescription() { - return this.description; - } - - /** - * @return A collection of valid items available for purchase in this - package. - */ - public Set getItems() { - return this.items; - } - - public Set getDatacenters() { - return this.locations; - } - - @Override - public int hashCode() { - return Objects.hashCode(id); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - ProductPackage that = ProductPackage.class.cast(obj); - return Objects.equal(this.id, that.id); - } - - protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("id", id).add("name", name).add("description", description).add("items", items).add("locations", locations); - } - - @Override - public String toString() { - return string().toString(); - } - -} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Region.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Region.java index 1be60332523..fa91e82c885 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Region.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Region.java @@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Strings.emptyToNull; - import java.beans.ConstructorProperties; import org.jclouds.javax.annotation.Nullable; @@ -30,7 +29,6 @@ * A region keyname can be used as part of an order. * Check the SoftLayer_Product_Order service for more details. * - * @author Jason King * @see */ @@ -116,8 +114,10 @@ public int hashCode() { @Override public String toString() { - return "[keyname=" + keyname + ", description=" + description + "]"; + return Objects.toStringHelper(this) + .add("sortOrder", sortOrder) + .add("keyname", keyname) + .add("description", description) + .toString(); } - - } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/SoftwareDescription.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/SoftwareDescription.java new file mode 100644 index 00000000000..28827fc9ac0 --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/SoftwareDescription.java @@ -0,0 +1,301 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import java.beans.ConstructorProperties; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; + +public class SoftwareDescription { + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromSoftwareDescription(this); + } + + public static class Builder { + + protected int id; + protected String longDescription; + protected String manufacturer; + protected String name; + protected int operatingSystem; + protected String referenceCode; + protected String requiredUser; + protected String version; + protected int controlPanel; + protected String upgradeSoftwareDescriptionId; + protected String upgradeSwDescId; + protected String virtualLicense; + protected String virtualizationPlatform; + + /** + * @see SoftwareDescription#getId() + */ + public Builder id(int id) { + this.id = id; + return this; + } + + /** + * @see SoftwareDescription#getLongDescription() + */ + public Builder longDescription(String longDescription) { + this.longDescription = longDescription; + return this; + } + + /** + * @see SoftwareDescription#getManufacturer() + */ + public Builder manufacturer(String manufacturer) { + this.manufacturer = manufacturer; + return this; + } + + /** + * @see SoftwareDescription#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see SoftwareDescription#getOperatingSystem() + */ + public Builder operatingSystem(int operatingSystem) { + this.operatingSystem = operatingSystem; + return this; + } + + /** + * @see SoftwareDescription#getReferenceCode() + */ + public Builder referenceCode(String referenceCode) { + this.referenceCode = referenceCode; + return this; + } + + /** + * @see SoftwareDescription#getRequiredUser() + */ + public Builder requiredUser(String requiredUser) { + this.requiredUser = requiredUser; + return this; + } + + /** + * @see SoftwareDescription#getVersion() + */ + public Builder version(String version) { + this.version = version; + return this; + } + + public Builder controlPanel(int controlPanel) { + this.controlPanel = controlPanel; + return this; + } + + public Builder upgradeSoftwareDescriptionId(String upgradeSoftwareDescriptionId) { + this.upgradeSoftwareDescriptionId = upgradeSoftwareDescriptionId; + return this; + } + + public Builder upgradeSwDescId(String upgradeSwDescId) { + this.upgradeSwDescId = upgradeSwDescId; + return this; + } + + public Builder virtualLicense(String virtualLicense) { + this.virtualLicense = virtualLicense; + return this; + } + + public Builder virtualizationPlatform(String virtualizationPlatform) { + this.virtualizationPlatform = virtualizationPlatform; + return this; + } + + public SoftwareDescription build() { + return new SoftwareDescription(id, longDescription, manufacturer, name, operatingSystem, referenceCode, + requiredUser, version, controlPanel, upgradeSoftwareDescriptionId, upgradeSwDescId, virtualLicense, + virtualizationPlatform); + } + + public Builder fromSoftwareDescription(SoftwareDescription in) { + return this + .id(in.getId()) + .longDescription(in.getLongDescription()) + .manufacturer(in.getManufacturer()) + .name(in.getName()) + .operatingSystem(in.getOperatingSystem()) + .referenceCode(in.getReferenceCode()) + .requiredUser(in.getRequiredUser()) + .version(in.getVersion()) + .controlPanel(in.getControlPanel()) + .upgradeSoftwareDescriptionId(in.getUpgradeSoftwareDescriptionId()) + .upgradeSwDescId(in.getUpgradeSwDescId()) + .virtualLicense(in.getVirtualLicense()) + .virtualizationPlatform(in.getVirtualizationPlatform()); + } + } + + private final int id; + private final String longDescription; + private final String manufacturer; + private final String name; + private final int operatingSystem; + private final String referenceCode; + private final String requiredUser; + private final String version; + private final int controlPanel; + private final String upgradeSoftwareDescriptionId; + private final String upgradeSwDescId; + private final String virtualLicense; + private final String virtualizationPlatform; + + @ConstructorProperties({ + "id", "longDescription", "manufacturer", "name", "operatingSystem", "referenceCode", "requiredUser", + "version", "controlPanel", "upgradeSoftwareDescriptionId", "upgradeSwDescId", "virtualLicense", + "virtualizationPlatform" + }) + protected SoftwareDescription(int id, @Nullable String longDescription, @Nullable String manufacturer, + @Nullable String name, int operatingSystem, @Nullable String referenceCode, + @Nullable String requiredUser, @Nullable String version, int controlPanel, + @Nullable String upgradeSoftwareDescriptionId, @Nullable String upgradeSwDescId, + @Nullable String virtualLicense, @Nullable String virtualizationPlatform) { + this.id = id; + this.longDescription = longDescription; + this.manufacturer = manufacturer; + this.name = name; + this.operatingSystem = operatingSystem; + this.referenceCode = referenceCode; + this.requiredUser = requiredUser; + this.version = version; + this.controlPanel = controlPanel; + this.upgradeSoftwareDescriptionId = upgradeSoftwareDescriptionId; + this.upgradeSwDescId = upgradeSwDescId; + this.virtualLicense = virtualLicense; + this.virtualizationPlatform = virtualizationPlatform; + } + + public int getId() { + return id; + } + + public String getLongDescription() { + return longDescription; + } + + public String getManufacturer() { + return manufacturer; + } + + public String getName() { + return name; + } + + public int getOperatingSystem() { + return operatingSystem; + } + + public String getReferenceCode() { + return referenceCode; + } + + public String getRequiredUser() { + return requiredUser; + } + + public String getVersion() { + return version; + } + + public int getControlPanel() { + return controlPanel; + } + + public String getUpgradeSoftwareDescriptionId() { + return upgradeSoftwareDescriptionId; + } + + public String getUpgradeSwDescId() { + return upgradeSwDescId; + } + + public String getVirtualLicense() { + return virtualLicense; + } + + public String getVirtualizationPlatform() { + return virtualizationPlatform; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SoftwareDescription that = (SoftwareDescription) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.longDescription, that.longDescription) && + Objects.equal(this.manufacturer, that.manufacturer) && + Objects.equal(this.name, that.name) && + Objects.equal(this.operatingSystem, that.operatingSystem) && + Objects.equal(this.referenceCode, that.referenceCode) && + Objects.equal(this.requiredUser, that.requiredUser) && + Objects.equal(this.version, that.version) && + Objects.equal(this.controlPanel, that.controlPanel) && + Objects.equal(this.upgradeSoftwareDescriptionId, that.upgradeSoftwareDescriptionId) && + Objects.equal(this.upgradeSwDescId, that.upgradeSwDescId) && + Objects.equal(this.virtualLicense, that.virtualLicense) && + Objects.equal(this.virtualizationPlatform, that.virtualizationPlatform); + } + + @Override + public int hashCode() { + return Objects.hashCode(id, longDescription, manufacturer, name, operatingSystem, referenceCode, + requiredUser, version, controlPanel, upgradeSoftwareDescriptionId, upgradeSwDescId, + virtualLicense, virtualizationPlatform); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("id", id) + .add("longDescription", longDescription) + .add("manufacturer", manufacturer) + .add("name", name) + .add("operatingSystem", operatingSystem) + .add("referenceCode", referenceCode) + .add("requiredUser", requiredUser) + .add("version", version) + .add("controlPanel", controlPanel) + .add("upgradeSoftwareDescriptionId", upgradeSoftwareDescriptionId) + .add("upgradeSwDescId", upgradeSwDescId) + .add("virtualLicense", virtualLicense) + .add("virtualizationPlatform", virtualizationPlatform) + .toString(); + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/SoftwareLicense.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/SoftwareLicense.java new file mode 100644 index 00000000000..ef403a40872 --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/SoftwareLicense.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import com.google.common.base.Objects; +import org.jclouds.javax.annotation.Nullable; + +import java.beans.ConstructorProperties; + +public class SoftwareLicense { + + private final int id; + private final SoftwareDescription softwareDescription; + private final int softwareDescriptionId; + + @ConstructorProperties({ + "id", "softwareDescription", "softwareDescriptionId" + }) + protected SoftwareLicense(int id, @Nullable SoftwareDescription softwareDescription, int softwareDescriptionId) { + this.id = id; + this.softwareDescription = softwareDescription; + this.softwareDescriptionId = softwareDescriptionId; + } + + public int getId() { + return this.id; + } + + @Nullable + public SoftwareDescription getSoftwareDescription() { + return this.softwareDescription; + } + + /** + * @return A longer location description. + */ + @Nullable + public int getSoftwareDescriptionId() { + return this.softwareDescriptionId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SoftwareLicense that = (SoftwareLicense) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.softwareDescription, that.softwareDescription) && + Objects.equal(this.softwareDescriptionId, that.softwareDescriptionId); + } + + @Override + public int hashCode() { + return Objects.hashCode(id, softwareDescription, softwareDescriptionId); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("id", id) + .add("softwareDescription", softwareDescription) + .add("softwareDescriptionId", softwareDescriptionId) + .toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromSoftwareLicense(this); + } + + public static class Builder { + protected int id; + protected SoftwareDescription softwareDescription; + protected int softwareDescriptionId; + + /** + * @see SoftwareLicense#getId() + */ + public Builder id(int id) { + this.id = id; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.SoftwareLicense#getSoftwareDescription() () + */ + public Builder softwareDescription(SoftwareDescription softwareDescription) { + this.softwareDescription = softwareDescription; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.SoftwareLicense#getSoftwareDescriptionId() () + */ + public Builder softwareDescriptionId(int softwareDescriptionId) { + this.softwareDescriptionId = softwareDescriptionId; + return this; + } + + public SoftwareLicense build() { + return new SoftwareLicense(id, softwareDescription, softwareDescriptionId); + } + + public Builder fromSoftwareLicense(SoftwareLicense in) { + return this + .id(in.getId()) + .softwareDescription(in.getSoftwareDescription()) + .softwareDescriptionId(in.getSoftwareDescriptionId()); + } + } + +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Tag.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Tag.java new file mode 100644 index 00000000000..719f11008d1 --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Tag.java @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; + +import com.google.common.base.Objects; + +public class Tag { + private final int accountId; + private final int id; + private final int internal; + private final String name; + + @ConstructorProperties({"accountId", "id", "internal", "name"} ) + public Tag(int accountId, int id, int internal, String name) { + this.accountId = accountId; + this.id = id; + this.internal = internal; + this.name = checkNotNull(name, "name"); + } + + public int getAccountId() { + return accountId; + } + + public int getId() { + return id; + } + + public int getInternal() { + return internal; + } + + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Tag that = (Tag) o; + + return Objects.equal(this.accountId, that.accountId) && + Objects.equal(this.id, that.id) && + Objects.equal(this.internal, that.internal) && + Objects.equal(this.name, that.name); + } + + @Override + public int hashCode() { + return Objects.hashCode(accountId, id, internal, name); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("accountId", accountId) + .add("id", id) + .add("internal", internal) + .add("name", name) + .toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromTag(this); + } + + public static class Builder { + private int accountId; + private int id; + private int internal; + private String name; + + /** + * @see org.jclouds.softlayer.domain.Tag#getAccountId() + */ + public Builder accountId(int accountId) { + this.accountId = accountId; + return this; + } + + /** + * @see Tag#getId() + */ + public Builder id(int id) { + this.id = id; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.Tag#getInternal() + */ + public Builder internal(int internal) { + this.internal = internal; + return this; + } + + /** + * @see Tag#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + public Tag build() { + return new Tag(accountId, id, internal, name); + } + + public Builder fromTag(Tag in) { + return this + .accountId(in.getAccountId()) + .id(in.getId()) + .internal(in.getInternal()) + .name(in.getName()); + } + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/TagReference.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/TagReference.java new file mode 100644 index 00000000000..924e5bc9609 --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/TagReference.java @@ -0,0 +1,218 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import java.beans.ConstructorProperties; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; + +/** + * @see + */ +public class TagReference { + private final int id; + private final int usrRecordId; + private final int tagTypeId; + private final int tagId; + private final int resourceTableId; + private final int empRecordId; + private final Tag tag; + private final TagType tagType; + + @ConstructorProperties({"id", "usrRecordId", "tagTypeId", "tagId", "resourceTableId", "empRecordId", "tag", "tagType"} ) + public TagReference(int id, int usrRecordId, int tagTypeId, int tagId, int resourceTableId, int empRecordId, + @Nullable Tag tag, @Nullable TagType tagType) { + this.id = id; + this.usrRecordId = usrRecordId; + this.tagTypeId = tagTypeId; + this.tagId = tagId; + this.resourceTableId = resourceTableId; + this.empRecordId = empRecordId; + this.tag = tag; + this.tagType = tagType; + } + + public int getId() { + return id; + } + + public int getUsrRecordId() { + return usrRecordId; + } + + public int getTagTypeId() { + return tagTypeId; + } + + public int getTagId() { + return tagId; + } + + public int getResourceTableId() { + return resourceTableId; + } + + public int getEmpRecordId() { + return empRecordId; + } + + public Tag getTag() { + return tag; + } + + public TagType getTagType() { + return tagType; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TagReference that = (TagReference) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.usrRecordId, that.usrRecordId) && + Objects.equal(this.tagTypeId, that.tagTypeId) && + Objects.equal(this.tagId, that.tagId) && + Objects.equal(this.resourceTableId, that.resourceTableId) && + Objects.equal(this.empRecordId, that.empRecordId) && + Objects.equal(this.tag, that.tag) && + Objects.equal(this.tagType, that.tagType); + } + + @Override + public int hashCode() { + return Objects.hashCode(id, usrRecordId, tagTypeId, tagId, resourceTableId, empRecordId, + tag, tagType); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("id", id) + .add("usrRecordId", usrRecordId) + .add("tagTypeId", tagTypeId) + .add("tagId", tagId) + .add("resourceTableId", resourceTableId) + .add("empRecordId", empRecordId) + .add("tag", tag) + .add("tagType", tagType) + .toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromTagReference(this); + } + + public static class Builder { + private int id; + private int usrRecordId; + private int tagTypeId; + private int tagId; + private int resourceTableId; + private int empRecordId; + private Tag tag; + private TagType tagType; + + /** + * @see TagReference#getId() + */ + public Builder id(int id) { + this.id = id; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.TagReference#getUsrRecordId() + */ + public Builder usrRecordId(int usrRecordId) { + this.usrRecordId = usrRecordId; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.TagReference#getTagTypeId() + */ + public Builder tagTypeId(int tagTypeId) { + this.tagTypeId = tagTypeId; + return this; + } + + /** + * @see TagReference#getTagId() + */ + public Builder tagId(int tagId) { + this.tagId = tagId; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.TagReference#getResourceTableId() + */ + public Builder resourceTableId(int resourceTableId) { + this.resourceTableId = resourceTableId; + return this; + } + + /** + * @see TagReference#getEmpRecordId() + */ + public Builder empRecordId(int empRecordId) { + this.empRecordId = empRecordId; + return this; + } + + /** + * @see TagReference#getTag() + */ + public Builder tag(Tag tag) { + this.tag = tag; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.TagReference#getTagType() + */ + public Builder tagType(TagType tagType) { + this.tagType = tagType; + return this; + } + + public TagReference build() { + return new TagReference(id, usrRecordId, tagTypeId, tagId, resourceTableId, empRecordId, tag, tagType); + } + + public Builder fromTagReference(TagReference in) { + return this + .id(in.getId()) + .usrRecordId(in.getUsrRecordId()) + .tagTypeId(in.getTagTypeId()) + .tagId(in.getTagId()) + .resourceTableId(in.getResourceTableId()) + .empRecordId(in.getResourceTableId()) + .tag(in.getTag()) + .tagType(in.getTagType()); + } + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/TagType.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/TagType.java new file mode 100644 index 00000000000..89770c67dcf --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/TagType.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import java.beans.ConstructorProperties; + +import com.google.common.base.Objects; + +public class TagType { + private final String keyName; + private final String description; + + @ConstructorProperties({"keyName", "description"} ) + public TagType(String keyName, String description) { + this.keyName = keyName; + this.description = description; + } + + public String getKeyName() { + return keyName; + } + + public String getDescription() { + return description; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TagType that = (TagType) o; + + return Objects.equal(this.keyName, that.keyName) && + Objects.equal(this.description, that.description); + } + + @Override + public int hashCode() { + return Objects.hashCode(keyName, description); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("keyName", keyName) + .add("description", description) + .toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromTagType(this); + } + + public static class Builder { + private String keyName; + private String description; + + /** + * @see org.jclouds.softlayer.domain.TagType#getKeyName() + */ + public Builder keyName(String keyName) { + this.keyName = keyName; + return this; + } + + /** + * @see TagType#getDescription() + */ + public Builder description(String description) { + this.description = description; + return this; + } + + public TagType build() { + return new TagType(keyName, description); + } + + public Builder fromTagType(TagType in) { + return this + .keyName(in.getKeyName()) + .description(in.getDescription()); + } + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualDiskImage.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualDiskImage.java new file mode 100644 index 00000000000..8bc6f1370b1 --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualDiskImage.java @@ -0,0 +1,249 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOBuilderICE file distributed with + * this work for additional information regarding copyright ownership. + * Builderhe ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WIBuilderHOUBuilder WARRANBuilderIES OR CONDIBuilderIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; +import java.util.Set; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableSet; + +/** + * Class VirtualDiskImage + * + * @see + */ +public class VirtualDiskImage { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromVirtualDiskImage(this); + } + + public static class Builder { + + protected int id; + protected String uuid; + protected float capacity; + protected String units; + protected int typeId; + protected String description; + protected String name; + protected int storageRepositoryId; + protected ImmutableSet.Builder softwareReferences = ImmutableSet.builder(); + + /** + * @see org.jclouds.softlayer.domain.VirtualDiskImage#getId() + */ + public Builder id(int id) { + this.id = id; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualDiskImage#getUuid() + */ + public Builder uuid(String uuid) { + this.uuid = uuid; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualDiskImage#getCapacity() + */ + public Builder capacity(float capacity) { + this.capacity = capacity; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualDiskImage#getUnits() + */ + public Builder units(String units) { + this.units = units; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualDiskImage#getBuilderypeId() + */ + public Builder typeId(int typeId) { + this.typeId = typeId; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualDiskImage#getDescription() + */ + public Builder description(String description) { + this.description = description; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualDiskImage#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualDiskImage#getStorageRepositoryId() + */ + public Builder storageRepositoryId(int storageRepositoryId) { + this.storageRepositoryId = storageRepositoryId; + return this; + } + + public Builder softwareReferences(Set softwareReferences) { + this.softwareReferences.addAll(checkNotNull(softwareReferences, "softwareReferences")); + return this; + } + + public Builder softwareReferences(VirtualDiskImageSoftware... in) { + return softwareReferences(ImmutableSet.copyOf(in)); + } + + public VirtualDiskImage build() { + return new VirtualDiskImage(id, uuid, capacity, units, typeId, description, name, + storageRepositoryId, softwareReferences.build()); + } + + public Builder fromVirtualDiskImage(VirtualDiskImage in) { + return this + .id(in.getId()) + .uuid(in.getUuid()) + .capacity(in.getCapacity()) + .units(in.getUnits()) + .typeId(in.getBuilderypeId()) + .description(in.getDescription()) + .name(in.getName()) + .storageRepositoryId(in.getStorageRepositoryId()) + .softwareReferences(in.getSoftwareReferences()); + } + } + + private final int id; + private final String uuid; + private final float capacity; + private final String units; + private final int typeId; + private final String description; + private final String name; + private final int storageRepositoryId; + private final Set softwareReferences; + + @ConstructorProperties({ + "id", "uuid", "capacity", "units", "typeId", "description", "name", "storageRepositoryId", "softwareReferences" + }) + public VirtualDiskImage(int id, @Nullable String uuid, float capacity, @Nullable String units, int typeId, + @Nullable String description, @Nullable String name, int storageRepositoryId, + @Nullable Set softwareReferences) { + this.id = id; + this.uuid = uuid; + this.capacity = capacity; + this.units = units; + this.typeId = typeId; + this.description = description; + this.name = name; + this.storageRepositoryId = storageRepositoryId; + this.softwareReferences = softwareReferences == null ? ImmutableSet.of() : + ImmutableSet.copyOf(softwareReferences); + } + + public int getId() { + return id; + } + + public String getUuid() { + return uuid; + } + + public float getCapacity() { + return capacity; + } + + public String getUnits() { + return units; + } + + public int getBuilderypeId() { + return typeId; + } + + public String getDescription() { + return description; + } + + public String getName() { + return name; + } + + public int getStorageRepositoryId() { + return storageRepositoryId; + } + + public Set getSoftwareReferences() { + return softwareReferences; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VirtualDiskImage that = (VirtualDiskImage) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.uuid, that.uuid) && + Objects.equal(this.capacity, that.capacity) && + Objects.equal(this.units, that.units) && + Objects.equal(this.typeId, that.typeId) && + Objects.equal(this.description, that.description) && + Objects.equal(this.name, that.name) && + Objects.equal(this.storageRepositoryId, that.storageRepositoryId) && + Objects.equal(this.softwareReferences, that.softwareReferences); + } + + @Override + public int hashCode() { + return Objects.hashCode(id, uuid, capacity, units, typeId, description, + name, storageRepositoryId, softwareReferences); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("id", id) + .add("uuid", uuid) + .add("capacity", capacity) + .add("units", units) + .add("typeId", typeId) + .add("description", description) + .add("name", name) + .add("storageRepositoryId", storageRepositoryId) + .add("softwareReferences", softwareReferences) + .toString(); + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualDiskImageSoftware.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualDiskImageSoftware.java new file mode 100644 index 00000000000..3378d75f057 --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualDiskImageSoftware.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import java.beans.ConstructorProperties; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; + +public class VirtualDiskImageSoftware { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromVirtualDiskImageSoftware(this); + } + + public static class Builder { + + protected int id; + protected int softwareDescriptionId; + protected SoftwareDescription softwareDescription; + + /** + * @see VirtualDiskImageSoftware#getId() + */ + public Builder id(int id) { + this.id = id; + return this; + } + + /** + * @see VirtualDiskImageSoftware#getSoftwareDescriptionId() + */ + public Builder softwareDescriptionId(int softwareDescriptionId) { + this.softwareDescriptionId = softwareDescriptionId; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualDiskImageSoftware#getSoftwareDescription() + */ + public Builder softwareDescription(SoftwareDescription softwareDescription) { + this.softwareDescription = softwareDescription; + return this; + } + + public VirtualDiskImageSoftware build() { + return new VirtualDiskImageSoftware(id, softwareDescriptionId, softwareDescription); + } + + public Builder fromVirtualDiskImageSoftware(VirtualDiskImageSoftware in) { + return this + .id(in.getId()) + .softwareDescriptionId(in.getSoftwareDescriptionId()) + .softwareDescription(in.getSoftwareDescription()); + } + } + + private final int id; + private final int softwareDescriptionId; + private final SoftwareDescription softwareDescription; + + @ConstructorProperties({"id", "softwareDescriptionId", "softwareDescription"}) + public VirtualDiskImageSoftware(int id, int softwareDescriptionId, @Nullable SoftwareDescription softwareDescription) { + this.id = id; + this.softwareDescriptionId = softwareDescriptionId; + this.softwareDescription = softwareDescription; + } + + public int getId() { + return this.id; + } + + public int getSoftwareDescriptionId() { + return this.softwareDescriptionId; + } + + @Nullable + public SoftwareDescription getSoftwareDescription() { + return this.softwareDescription; + } + + @Override + public int hashCode() { + return Objects.hashCode(id, softwareDescriptionId, softwareDescription); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VirtualDiskImageSoftware that = (VirtualDiskImageSoftware) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.softwareDescriptionId, that.softwareDescriptionId) && + Objects.equal(this.softwareDescription, that.softwareDescription); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("id", id) + .add("softwareDescriptionId", softwareDescriptionId) + .add("softwareDescription", softwareDescription) + .toString(); + } +} 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 0bfb1d61da8..b407bbb52ca 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 @@ -17,15 +17,15 @@ package org.jclouds.softlayer.domain; import static com.google.common.base.Preconditions.checkNotNull; - import java.beans.ConstructorProperties; import java.util.Date; +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.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; /** * The virtual guest data type presents the structure in which all virtual guests will be presented. @@ -45,10 +45,7 @@ * Combining the hostname, followed by a period '.', followed by the domain gives the FQDN (fully qualified domain name), * which may not exceed 253 characters in total length. * - * @author Adrian Cole - * @see + * @see */ public class VirtualGuest { @@ -123,8 +120,16 @@ public abstract static class Builder> { protected String primaryIpAddress; protected int billingItemId; protected OperatingSystem operatingSystem; + protected String operatingSystemReferenceCode; protected Datacenter datacenter; protected PowerState powerState; + protected SoftwareLicense softwareLicense; + protected int activeTransactionCount; + protected Set blockDevices; + protected boolean localDiskFlag; + protected VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup; + protected Set networkComponents; + protected Set tagReferences; /** * @see VirtualGuest#getAccountId() @@ -302,6 +307,14 @@ public T operatingSystem(OperatingSystem operatingSystem) { return self(); } + /** + * @see VirtualGuest#getOperatingSystemReferenceCode() + */ + public T operatingSystemReferenceCode(String operatingSystemReferenceCode) { + this.operatingSystemReferenceCode = operatingSystemReferenceCode; + return self(); + } + /** * @see VirtualGuest#getDatacenter() */ @@ -318,11 +331,69 @@ public T powerState(PowerState powerState) { return self(); } + /** + * @see VirtualGuest#getSoftwareLicense() + */ + public T softwareLicense(SoftwareLicense softwareLicense) { + this.softwareLicense = softwareLicense; + return self(); + } + + /** + * @see VirtualGuest#getActiveTransactionCount() + */ + public T activeTransactionCount(int activeTransactionCount) { + this.activeTransactionCount = activeTransactionCount; + return self(); + } + + /** + * @see VirtualGuest#getVirtualGuestBlockDevices() + */ + public T blockDevices(Set blockDevices) { + this.blockDevices = ImmutableSet.copyOf(checkNotNull(blockDevices, "blockDevices")); + return self(); + } + + public T blockDevices(VirtualGuestBlockDevice... in) { + return blockDevices(ImmutableSet.copyOf(checkNotNull(in, "blockDevices"))); + } + + public T localDiskFlag(boolean localDiskFlag) { + this.localDiskFlag = localDiskFlag; + return self(); + } + + public T blockDeviceTemplateGroup(VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup) { + this.blockDeviceTemplateGroup = blockDeviceTemplateGroup; + return self(); + } + + public T networkComponents(Set networkComponents) { + this.networkComponents = ImmutableSet.copyOf(checkNotNull(networkComponents, "networkComponents")); + return self(); + } + + public T networkComponents(VirtualGuestNetworkComponent... in) { + return networkComponents(ImmutableSet.copyOf(checkNotNull(in, "networkComponents"))); + } + + public T tagReferences(Set tagReferences) { + this.tagReferences = ImmutableSet.copyOf(checkNotNull(tagReferences, "tagReferences")); + return self(); + } + + public T tagReferences(TagReference... in) { + return tagReferences(ImmutableSet.copyOf(checkNotNull(in, "tagReferences"))); + } + public VirtualGuest build() { return new VirtualGuest(accountId, createDate, dedicatedAccountHostOnly, domain, fullyQualifiedDomainName, hostname, id, lastVerifiedDate, maxCpu, maxCpuUnits, maxMemory, metricPollDate, modifyDate, notes, privateNetworkOnly, startCpus, statusId, uuid, primaryBackendIpAddress, primaryIpAddress, new BillingItem(billingItemId), - operatingSystem, datacenter, powerState); + operatingSystem, operatingSystemReferenceCode, datacenter, powerState, softwareLicense, + activeTransactionCount, blockDevices, localDiskFlag, blockDeviceTemplateGroup, networkComponents, + tagReferences ); } public T fromVirtualGuest(VirtualGuest in) { @@ -349,8 +420,14 @@ public T fromVirtualGuest(VirtualGuest in) { .primaryIpAddress(in.getPrimaryIpAddress()) .billingItemId(in.getBillingItemId()) .operatingSystem(in.getOperatingSystem()) + .operatingSystemReferenceCode(in.getOperatingSystemReferenceCode()) .datacenter(in.getDatacenter()) - .powerState(in.getPowerState()); + .powerState(in.getPowerState()) + .activeTransactionCount(in.getActiveTransactionCount()) + .localDiskFlag(in.isLocalDiskFlag()) + .blockDeviceTemplateGroup(in.getVirtualGuestBlockDeviceTemplateGroup()) + .networkComponents(in.getVirtualGuestNetworkComponents()) + .tagReferences(in.getTagReferences()); } } @@ -383,18 +460,35 @@ protected ConcreteBuilder self() { private final String primaryIpAddress; private final int billingItemId; private final OperatingSystem operatingSystem; + private final String operatingSystemReferenceCode; private final Datacenter datacenter; private final PowerState powerState; - - @ConstructorProperties({ - "accountId", "createDate", "dedicatedAccountHostOnlyFlag", "domain", "fullyQualifiedDomainName", "hostname", "id", "lastVerifiedDate", "maxCpu", "maxCpuUnits", "maxMemory", "metricPollDate", "modifyDate", "notes", "privateNetworkOnlyFlag", "startCpus", "statusId", "uuid", "primaryBackendIpAddress", "primaryIpAddress", "billingItem", "operatingSystem", "datacenter", "powerState" - }) + private final SoftwareLicense softwareLicense; + private final int activeTransactionCount; + private final Set blockDevices; + private final boolean localDiskFlag; + private final VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup; + private final Set networkComponents; + private final Set tagReferences; + + @ConstructorProperties({ "accountId", "createDate", "dedicatedAccountHostOnlyFlag", "domain", + "fullyQualifiedDomainName", "hostname", "id", "lastVerifiedDate", "maxCpu", "maxCpuUnits", "maxMemory", + "metricPollDate", "modifyDate", "notes", "privateNetworkOnlyFlag", "startCpus", "statusId", "uuid", + "primaryBackendIpAddress", "primaryIpAddress", "billingItem", "operatingSystem", + "operatingSystemReferenceCode", "datacenter", "powerState", "softwareLicense", "activeTransactionCount", + "blockDevices", "localDiskFlag", "blockDeviceTemplateGroup", "networkComponents", "tagReferences" +}) protected VirtualGuest(int accountId, @Nullable Date createDate, boolean dedicatedAccountHostOnly, @Nullable String domain, @Nullable String fullyQualifiedDomainName, @Nullable String hostname, int id, @Nullable Date lastVerifiedDate, int maxCpu, @Nullable String maxCpuUnits, int maxMemory, @Nullable Date metricPollDate, @Nullable Date modifyDate, @Nullable String notes, boolean privateNetworkOnly, int startCpus, int statusId, @Nullable String uuid, @Nullable String primaryBackendIpAddress, @Nullable String primaryIpAddress, @Nullable BillingItem billingItem, - @Nullable OperatingSystem operatingSystem, @Nullable Datacenter datacenter, @Nullable PowerState powerState) { + @Nullable OperatingSystem operatingSystem, @Nullable String operatingSystemReferenceCode, + @Nullable Datacenter datacenter, @Nullable PowerState powerState, @Nullable SoftwareLicense softwareLicense, + int activeTransactionCount, @Nullable Set blockDevices, + boolean localDiskFlag, @Nullable VirtualGuestBlockDeviceTemplateGroup blockDeviceTemplateGroup, + @Nullable Set networkComponents, + @Nullable Set tagReferences ) { this.accountId = accountId; this.createDate = createDate; this.dedicatedAccountHostOnly = dedicatedAccountHostOnly; @@ -415,10 +509,18 @@ protected VirtualGuest(int accountId, @Nullable Date createDate, boolean dedicat this.uuid = uuid; this.primaryBackendIpAddress = primaryBackendIpAddress; this.primaryIpAddress = primaryIpAddress; - this.billingItemId = billingItem == null ? -1 : billingItem.id; + this.blockDevices = blockDevices; + this.billingItemId = billingItem == null ? 0 : billingItem.id; this.operatingSystem = operatingSystem; + this.operatingSystemReferenceCode = operatingSystemReferenceCode; this.datacenter = datacenter; this.powerState = powerState; + this.softwareLicense = softwareLicense; + this.activeTransactionCount = activeTransactionCount; + this.localDiskFlag = localDiskFlag; + this.blockDeviceTemplateGroup = blockDeviceTemplateGroup; + this.networkComponents = networkComponents; + this.tagReferences = tagReferences; } /** @@ -590,6 +692,10 @@ public OperatingSystem getOperatingSystem() { return this.operatingSystem; } + public String getOperatingSystemReferenceCode() { + return this.operatingSystemReferenceCode; + } + /** * @return The guest's datacenter */ @@ -598,6 +704,14 @@ public Datacenter getDatacenter() { return this.datacenter; } + /** + * @return The softwareLicense of a virtual guest. + */ + @Nullable + public SoftwareLicense getSoftwareLicense() { + return this.softwareLicense; + } + /** * @return The current power state of a virtual guest. */ @@ -606,9 +720,41 @@ public PowerState getPowerState() { return this.powerState; } + @Nullable + public int getActiveTransactionCount() { + return activeTransactionCount; + } + + @Nullable + public Set getVirtualGuestBlockDevices() { + return blockDevices; + } + + public boolean isLocalDiskFlag() { + return localDiskFlag; + } + + public VirtualGuestBlockDeviceTemplateGroup getVirtualGuestBlockDeviceTemplateGroup() { + return blockDeviceTemplateGroup; + } + + @Nullable + public Set getVirtualGuestNetworkComponents() { + return networkComponents; + } + + @Nullable + public Set getTagReferences() { + return tagReferences; + } + @Override public int hashCode() { - return Objects.hashCode(accountId, createDate, dedicatedAccountHostOnly, domain, fullyQualifiedDomainName, hostname, id, lastVerifiedDate, maxCpu, maxCpuUnits, maxMemory, metricPollDate, modifyDate, notes, privateNetworkOnly, startCpus, statusId, uuid, primaryBackendIpAddress, primaryIpAddress, billingItemId, operatingSystem, datacenter, powerState); + return Objects.hashCode(accountId, createDate, dedicatedAccountHostOnly, domain, fullyQualifiedDomainName, + hostname, id, lastVerifiedDate, maxCpu, maxCpuUnits, maxMemory, metricPollDate, modifyDate, notes, + privateNetworkOnly, startCpus, statusId, uuid, primaryBackendIpAddress, primaryIpAddress, + billingItemId, operatingSystem, datacenter, powerState, softwareLicense, blockDevices, localDiskFlag, + blockDeviceTemplateGroup, tagReferences); } @Override @@ -638,18 +784,52 @@ public boolean equals(Object obj) { && Objects.equal(this.primaryIpAddress, that.primaryIpAddress) && Objects.equal(this.billingItemId, that.billingItemId) && Objects.equal(this.operatingSystem, that.operatingSystem) + && Objects.equal(this.operatingSystemReferenceCode, that.operatingSystemReferenceCode) && Objects.equal(this.datacenter, that.datacenter) - && Objects.equal(this.powerState, that.powerState); - } - - protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("accountId", accountId).add("createDate", createDate).add("dedicatedAccountHostOnly", dedicatedAccountHostOnly).add("domain", domain).add("fullyQualifiedDomainName", fullyQualifiedDomainName).add("hostname", hostname).add("id", id).add("lastVerifiedDate", lastVerifiedDate).add("maxCpu", maxCpu).add("maxCpuUnits", maxCpuUnits).add("maxMemory", maxMemory).add("metricPollDate", metricPollDate).add("modifyDate", modifyDate).add("notes", notes).add("privateNetworkOnly", privateNetworkOnly).add("startCpus", startCpus).add("statusId", statusId).add("uuid", uuid).add("primaryBackendIpAddress", primaryBackendIpAddress).add("primaryIpAddress", primaryIpAddress).add("billingItemId", billingItemId).add("operatingSystem", operatingSystem).add("datacenter", datacenter).add("powerState", powerState); + && Objects.equal(this.powerState, that.powerState) + && Objects.equal(this.softwareLicense, that.softwareLicense) + && Objects.equal(this.blockDevices, that.blockDevices) + && Objects.equal(this.localDiskFlag, that.localDiskFlag) + && Objects.equal(this.blockDeviceTemplateGroup, that.blockDeviceTemplateGroup) + && Objects.equal(this.networkComponents, that.networkComponents) + && Objects.equal(this.tagReferences, that.tagReferences); } @Override public String toString() { - return string().toString(); + return Objects.toStringHelper(this) + .add("accountId", accountId) + .add("createDate", createDate) + .add("dedicatedAccountHostOnly", dedicatedAccountHostOnly) + .add("domain", domain) + .add("fullyQualifiedDomainName", fullyQualifiedDomainName) + .add("hostname", hostname) + .add("id", id) + .add("lastVerifiedDate", lastVerifiedDate) + .add("maxCpu", maxCpu) + .add("maxCpuUnits", maxCpuUnits) + .add("maxMemory", maxMemory) + .add("metricPollDate", metricPollDate) + .add("modifyDate", modifyDate) + .add("notes", notes) + .add("privateNetworkOnly", privateNetworkOnly) + .add("startCpus", startCpus) + .add("statusId", statusId) + .add("uuid", uuid) + .add("primaryBackendIpAddress", primaryBackendIpAddress) + .add("primaryIpAddress", primaryIpAddress) + .add("billingItemId", billingItemId) + .add("operatingSystem", operatingSystem) + .add("operatingSystemReferenceCode", operatingSystemReferenceCode) + .add("datacenter", datacenter) + .add("powerState", powerState) + .add("softwareLicense", softwareLicense) + .add("activeTransactionCount", activeTransactionCount) + .add("blockDevices", blockDevices) + .add("localDiskFlag", localDiskFlag) + .add("blockDeviceTemplateGroup", blockDeviceTemplateGroup) + .add("networkComponents", networkComponents) + .add("tagReferences", tagReferences) + .toString(); } - } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuestBlockDevice.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuestBlockDevice.java new file mode 100644 index 00000000000..9216634685a --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuestBlockDevice.java @@ -0,0 +1,241 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; + +/** + * Class VirtualGuestBlockDevice + * + * @see + */ +public class VirtualGuestBlockDevice { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromVirtualGuestBlockDevice(this); + } + + public static class Builder { + + protected int id; + protected String uuid; + protected int statusId; + protected String mountType; + protected String mountMode; + protected int bootableFlag; + protected String device; + protected VirtualDiskImage diskImage; + protected VirtualGuest guest; + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDevice#getId() + */ + public Builder id(int id) { + this.id = id; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDevice#getUuid() + */ + public Builder uuid(String uuid) { + this.uuid = uuid; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDevice#getStatusId() + */ + public Builder statusId(int statusId) { + this.statusId = statusId; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDevice#getMountType() + */ + public Builder mountType(String mountType) { + this.mountType = mountType; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDevice#getMountMode() + */ + public Builder mountMode(String mountMode) { + this.mountMode = mountMode; + return this; + } + + /** + * @see VirtualGuestBlockDevice#getBootableFlag() + */ + public Builder bootableFlag(int bootableFlag) { + this.bootableFlag = bootableFlag; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDevice#getDevice() + */ + public Builder device(String device) { + this.device = device; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDevice#getVirtualDiskImage() + */ + public Builder diskImage(VirtualDiskImage diskImage) { + this.diskImage = diskImage; + return this; + } + + public Builder guest(VirtualGuest guest) { + this.guest = guest; + return this; + } + + public VirtualGuestBlockDevice build() { + return new VirtualGuestBlockDevice(id, uuid, statusId, mountType, mountMode, bootableFlag, device, + diskImage, guest); + } + + public Builder fromVirtualGuestBlockDevice(VirtualGuestBlockDevice in) { + return this + .id(in.getId()) + .uuid(in.getUuid()) + .statusId(in.getStatusId()) + .mountMode(in.getMountMode()) + .mountType(in.getMountType()) + .bootableFlag(in.getBootableFlag()) + .device(in.getDevice()) + .diskImage(in.getVirtualDiskImage()) + .guest(in.getVirtualGuest()); + } + } + + private final int id; + private final String uuid; + private final int statusId; + private final String mountType; + private final String mountMode; + private final int bootableFlag; + private final String device; + private final VirtualDiskImage diskImage; + private final VirtualGuest guest; + + @ConstructorProperties({ "id", "uuid", "statusId", "mountType", "mountMode", "bootableFlag", "device", + "diskImage", "guest" }) + protected VirtualGuestBlockDevice(int id, @Nullable String uuid, int statusId, @Nullable String mountType, + @Nullable String mountMode, int bootableFlag, String device, + @Nullable VirtualDiskImage diskImage, @Nullable VirtualGuest guest) { + this.id = id; + this.uuid = uuid; + this.statusId = statusId; + this.mountType = mountType; + this.mountMode = mountMode; + this.bootableFlag = bootableFlag; + this.device = checkNotNull(device, "device"); + this.diskImage = diskImage; + this.guest = guest; + } + + public int getId() { + return id; + } + + public String getUuid() { + return uuid; + } + + public int getStatusId() { + return statusId; + } + + public String getMountType() { + return mountType; + } + + public String getMountMode() { + return mountMode; + } + + public int getBootableFlag() { + return bootableFlag; + } + + public String getDevice() { + return device; + } + + public VirtualDiskImage getVirtualDiskImage() { + return diskImage; + } + + public VirtualGuest getVirtualGuest() { + return guest; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VirtualGuestBlockDevice that = (VirtualGuestBlockDevice) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.uuid, that.uuid) && + Objects.equal(this.statusId, that.statusId) && + Objects.equal(this.mountType, that.mountType) && + Objects.equal(this.mountMode, that.mountMode) && + Objects.equal(this.bootableFlag, that.bootableFlag) && + Objects.equal(this.device, that.device) && + Objects.equal(this.diskImage, that.diskImage) && + Objects.equal(this.guest, that.guest); + } + + @Override + public int hashCode() { + return Objects.hashCode(id, uuid, statusId, mountType, mountMode, bootableFlag, + device, diskImage, guest); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("id", id) + .add("uuid", uuid) + .add("statusId", statusId) + .add("mountType", mountType) + .add("mountMode", mountMode) + .add("bootableFlag", bootableFlag) + .add("device", device) + .add("diskImage", diskImage) + .add("guest", guest) + .toString(); + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuestBlockDeviceTemplate.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuestBlockDeviceTemplate.java new file mode 100644 index 00000000000..f72f8cd3351 --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuestBlockDeviceTemplate.java @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOBuilderICE file distributed with + * this work for additional information regarding copyright ownership. + * Builderhe ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WIBuilderHOUBuilder WARRANBuilderIES OR CONDIBuilderIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; + +import com.google.common.base.Objects; + +/** + * Class VirtualGuestBlockDeviceTemplate + * + * @see + */ +public class VirtualGuestBlockDeviceTemplate { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromVirtualGuestBlockDeviceTemplate(this); + } + + public static class Builder { + + protected int id; + protected String device; + protected int diskImageId; + protected float diskSpace; + protected int groupId; + protected String units; + protected VirtualDiskImage diskImage; + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplate#getId() + */ + public Builder id(int id) { + this.id = id; + return this; + } + + /** + * @see VirtualGuestBlockDeviceTemplate#getDevice() + */ + public Builder device(String device) { + this.device = device; + return this; + } + + /** + * @see VirtualGuestBlockDeviceTemplate#getDiskImage() + */ + public Builder diskImageId(int diskImageId) { + this.diskImageId = diskImageId; + return this; + } + + /** + * @see VirtualGuestBlockDeviceTemplate#getDiskSpace() + */ + public Builder diskSpace(float diskSpace) { + this.diskSpace = diskSpace; + return this; + } + + /** + * @see VirtualGuestBlockDeviceTemplate#getGroupId() + */ + public Builder groupId(int groupId) { + this.groupId = groupId; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplate#getUnits() + */ + public Builder units(String units) { + this.units = units; + return this; + } + + /** + * @see VirtualGuestBlockDeviceTemplate#getDiskImage() + */ + public Builder diskImage(VirtualDiskImage diskImage) { + this.diskImage = diskImage; + return this; + } + + public VirtualGuestBlockDeviceTemplate build() { + return new VirtualGuestBlockDeviceTemplate(id, device, diskImageId, diskSpace, groupId, units, diskImage); + } + + public Builder fromVirtualGuestBlockDeviceTemplate(VirtualGuestBlockDeviceTemplate in) { + return this + .id(in.getId()) + .device(in.getDevice()) + .diskImageId(in.getDiskImageId()) + .diskSpace(in.getDiskSpace()) + .groupId(in.getGroupId()) + .units(in.getUnits()) + .diskImage(in.getDiskImage()); + } + } + + private final int id; + private final String device; + private final int diskImageId; + private final float diskSpace; + private final int groupId; + private final String units; + private final VirtualDiskImage diskImage; + + @ConstructorProperties({ "id", "device", "diskImageId", "diskSpace", "groupId", "units", "diskImage" }) + protected VirtualGuestBlockDeviceTemplate(int id, String device, int diskImageId, float diskSpace, int groupId, + String units, VirtualDiskImage diskImage) { + this.id = id; + this.device = checkNotNull(device, "device"); + this.diskImageId = diskImageId; + this.diskSpace = diskSpace; + this.groupId = groupId; + this.units = units; + this.diskImage = checkNotNull(diskImage, "diskImage"); + } + + public int getId() { + return id; + } + + public String getDevice() { + return device; + } + + public int getDiskImageId() { + return diskImageId; + } + + public float getDiskSpace() { + return diskSpace; + } + + public int getGroupId() { + return groupId; + } + + public String getUnits() { + return units; + } + + public VirtualDiskImage getDiskImage() { + return diskImage; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VirtualGuestBlockDeviceTemplate that = (VirtualGuestBlockDeviceTemplate) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.device, that.device) && + Objects.equal(this.diskImageId, that.diskImageId) && + Objects.equal(this.diskSpace, that.diskSpace) && + Objects.equal(this.groupId, that.groupId) && + Objects.equal(this.units, that.units) && + Objects.equal(this.diskImage, that.diskImage); + } + + @Override + public int hashCode() { + return Objects.hashCode(id, device, diskImageId, diskSpace, groupId, units, diskImage); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("id", id) + .add("device", device) + .add("diskImageId", diskImageId) + .add("diskSpace", diskSpace) + .add("groupId", groupId) + .add("units", units) + .add("diskImage", diskImage) + .toString(); + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuestBlockDeviceTemplateGroup.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuestBlockDeviceTemplateGroup.java new file mode 100644 index 00000000000..09587a6b6b2 --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuestBlockDeviceTemplateGroup.java @@ -0,0 +1,256 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; +import java.util.Set; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableSet; + +/** + * Class VirtualGuestBlockDeviceTemplateGroup + * + * @see + */ +public class VirtualGuestBlockDeviceTemplateGroup { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromVirtualGuestBlockDeviceTemplateGroup(this); + } + + public static class Builder { + + protected int id; + protected String name; + protected String globalIdentifier; + protected int statusId; + protected int accountId; + protected int parentId; + protected String summary; + protected ImmutableSet.Builder children = ImmutableSet.builder(); + protected ImmutableSet.Builder blockDevices = ImmutableSet.builder(); + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup#getId() + */ + public Builder id(int id) { + this.id = id; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup#getGlobalIdentifier() + */ + public Builder globalIdentifier(String globalIdentifier) { + this.globalIdentifier = globalIdentifier; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup#getStatusId() + */ + public Builder statusId(int statusId) { + this.statusId = statusId; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup#getAccountId() + */ + public Builder accountId(int accountId) { + this.accountId = accountId; + return this; + } + + /** + * @see VirtualGuestBlockDeviceTemplateGroup#getParentId() + */ + public Builder parentId(int parentId) { + this.parentId = parentId; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup#getSummary() + */ + public Builder summary(String summary) { + this.summary = summary; + return this; + } + + /** + * @see VirtualGuestBlockDeviceTemplateGroup#getChildren() + */ + public Builder children(Iterable children) { + this.children.addAll(checkNotNull(children, "children")); + return this; + } + + public Builder children(VirtualGuestBlockDeviceTemplateGroup... in) { + return children(ImmutableSet.copyOf(checkNotNull(in, "children"))); + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup#getBlockDevices() + */ + public Builder blockDevices(Set blockDevices) { + this.blockDevices.addAll(checkNotNull(blockDevices, "blockDevices")); + return this; + } + + public Builder blockDevices(VirtualGuestBlockDeviceTemplate... in) { + return blockDevices(ImmutableSet.copyOf(checkNotNull(in, "blockDevices"))); + } + + public VirtualGuestBlockDeviceTemplateGroup build() { + return new VirtualGuestBlockDeviceTemplateGroup(id, name, globalIdentifier, statusId, accountId, parentId, + summary, children.build(), blockDevices.build()); + } + + public Builder fromVirtualGuestBlockDeviceTemplateGroup(VirtualGuestBlockDeviceTemplateGroup in) { + return this + .id(in.getId()) + .name(in.getName()) + .statusId(in.getStatusId()) + .accountId(in.getAccountId()) + .parentId(in.getParentId()) + .summary(in.getSummary()) + .children(in.getChildren()) + .blockDevices(in.getBlockDevices()); + } + } + + private final int id; + private final String name; + private final String globalIdentifier; + private final int statusId; + private final int accountId; + private final int parentId; + private final String summary; + private final Set children; + private final Set blockDevices; + + @ConstructorProperties({ "id", "name", "globalIdentifier", "statusId", "accountId", "parentId", "summary", + "children", "blockDevices" }) + protected VirtualGuestBlockDeviceTemplateGroup(int id, @Nullable String name, @Nullable String globalIdentifier, + int statusId, int accountId, int parentId, @Nullable String summary, + @Nullable Set children, + @Nullable Set blockDevices) { + this.id = id; + this.name = name; + this.globalIdentifier = globalIdentifier; + this.statusId = statusId; + this.accountId = accountId; + this.parentId = parentId; + this.summary = summary; + this.children = children == null ? ImmutableSet.of() : + ImmutableSet.copyOf(children); + this.blockDevices = blockDevices == null ? ImmutableSet.of() : + ImmutableSet.copyOf(blockDevices); + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public String getGlobalIdentifier() { + return globalIdentifier; + } + + public int getStatusId() { + return statusId; + } + + public int getAccountId() { + return accountId; + } + + public int getParentId() { + return parentId; + } + + public String getSummary() { + return summary; + } + + public Set getChildren() { + return children; + } + + public Set getBlockDevices() { + return blockDevices; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VirtualGuestBlockDeviceTemplateGroup that = (VirtualGuestBlockDeviceTemplateGroup) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.name, that.name) && + Objects.equal(this.globalIdentifier, that.globalIdentifier) && + Objects.equal(this.statusId, that.statusId) && + Objects.equal(this.accountId, that.accountId) && + Objects.equal(this.parentId, that.parentId) && + Objects.equal(this.summary, that.summary) && + Objects.equal(this.children, that.children) && + Objects.equal(this.blockDevices, that.blockDevices); + } + + @Override + public int hashCode() { + return Objects.hashCode(id, name, globalIdentifier, statusId, accountId, parentId, summary, children, + blockDevices); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("id", id) + .add("name", name) + .add("globalIdentifier", globalIdentifier) + .add("statusId", statusId) + .add("accountId", accountId) + .add("parentId", parentId) + .add("summary", summary) + .add("children", children) + .add("blockDevices", blockDevices) + .toString(); + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuestNetworkComponent.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuestNetworkComponent.java new file mode 100644 index 00000000000..760c70e941e --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/domain/VirtualGuestNetworkComponent.java @@ -0,0 +1,248 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.domain; + +import java.beans.ConstructorProperties; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; + +/** + * Class VirtualGuestBlockDeviceTemplateGroup + * + * @see + */ +public class VirtualGuestNetworkComponent { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromVirtualGuestNetworkComponent(this); + } + + public static class Builder { + + protected int id; + protected String uuid; + protected int guestId; + protected int networkId; + protected String macAddress; + protected int maxSpeed; + protected String name; + protected int port; + protected int speed; + protected String status; + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestNetworkComponent#getId() + */ + public Builder id(int id) { + this.id = id; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestNetworkComponent#getUuid() + */ + public Builder uuid(String uuid) { + this.uuid = uuid; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestNetworkComponent#getGuestId() + */ + public Builder guestId(int guestId) { + this.guestId = guestId; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestNetworkComponent#getNetworkId() + */ + public Builder networkId(int networkId) { + this.networkId = networkId; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestNetworkComponent#getMacAddress() + */ + public Builder macAddress(String macAddress) { + this.macAddress = macAddress; + return this; + } + + /** + * @see VirtualGuestNetworkComponent#getMaxSpeed() + */ + public Builder maxSpeed(int maxSpeed) { + this.maxSpeed = maxSpeed; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestNetworkComponent#getPort() + */ + public Builder port(int port) { + this.port = port; + return this; + } + + /** + * @see org.jclouds.softlayer.domain.VirtualGuestNetworkComponent#getSpeed() + */ + public Builder speed(int speed) { + this.speed = speed; + return this; + } + + public Builder status(String status) { + this.status = status; + return this; + } + + public VirtualGuestNetworkComponent build() { + return new VirtualGuestNetworkComponent(id, uuid, guestId, networkId, macAddress, maxSpeed, name, port, + speed, status); + } + + public Builder fromVirtualGuestNetworkComponent(VirtualGuestNetworkComponent in) { + return this + .id(in.getId()) + .uuid(in.getUuid()) + .guestId(in.getGuestId()) + .networkId(in.getNetworkId()) + .macAddress(in.getMacAddress()) + .maxSpeed(in.getMaxSpeed()) + .port(in.getPort()) + .speed(in.getSpeed()) + .status(in.getStatus()); + } + } + + private final int id; + private final String uuid; + private final int guestId; + private final int networkId; + private final String macAddress; + private final int maxSpeed; + private final String name; + private final int port; + private final int speed; + private final String status; + + @ConstructorProperties({ "id", "uuid", "guestId", "networkId", "macAddress", "maxSpeed", "name", "port", "speed", "status" }) + protected VirtualGuestNetworkComponent(int id, String uuid, int guestId, int networkId, @Nullable String macAddress, + int maxSpeed, @Nullable String name, int port, int speed, + @Nullable String status) { + this.id = id; + this.uuid = uuid; + this.guestId = guestId; + this.networkId = networkId; + this.macAddress = macAddress; + this.maxSpeed = maxSpeed; + this.name = name; + this.port = port; + this.speed = speed; + this.status = status; + } + + public int getId() { + return id; + } + + public String getUuid() { + return uuid; + } + + public int getGuestId() { + return guestId; + } + + public int getNetworkId() { + return networkId; + } + + public String getMacAddress() { + return macAddress; + } + + public int getMaxSpeed() { + return maxSpeed; + } + + public String getName() { + return name; + } + + public int getPort() { + return port; + } + + public int getSpeed() { + return speed; + } + + public String getStatus() { + return status; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VirtualGuestNetworkComponent that = (VirtualGuestNetworkComponent) o; + + return Objects.equal(this.id, that.id) && + Objects.equal(this.uuid, that.uuid) && + Objects.equal(this.guestId, that.guestId) && + Objects.equal(this.networkId, that.networkId) && + Objects.equal(this.macAddress, that.macAddress) && + Objects.equal(this.maxSpeed, that.maxSpeed) && + Objects.equal(this.name, that.name) && + Objects.equal(this.port, that.port) && + Objects.equal(this.speed, that.speed) && + Objects.equal(this.status, that.status); + } + + @Override + public int hashCode() { + return Objects.hashCode(id, uuid, guestId, networkId, macAddress, maxSpeed, + name, port, speed, status); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("id", id) + .add("uuid", uuid) + .add("guestId", guestId) + .add("networkId", networkId) + .add("macAddress", macAddress) + .add("maxSpeed", maxSpeed) + .add("name", name) + .add("port", port) + .add("speed", speed) + .add("status", status) + .toString(); + } +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/features/AccountApi.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/features/AccountApi.java index 568d8490d7a..967310682d4 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/features/AccountApi.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/features/AccountApi.java @@ -18,6 +18,7 @@ import java.util.Set; +import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -26,34 +27,45 @@ import org.jclouds.Fallbacks; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.softlayer.domain.ProductPackage; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup; /** - * Provides synchronous access to Account. + * Provides access to Account via their REST API. *

- * - * @see - * @author Jason King + * + * @see */ @RequestFilters(BasicAuthentication.class) @Path("/v{jclouds.api-version}") +@Consumes(MediaType.APPLICATION_JSON) public interface AccountApi { + public static String GUEST_MASK = "children.blockDevices.diskImage.softwareReferences.softwareDescription"; + public static String LIST_GUEST_MASK = "powerState;operatingSystem.passwords;datacenter;billingItem;blockDevices" + + ".diskImage;tagReferences"; + + /** + * @return an account's associated virtual guest objects. + */ + @Named("Account:listVirtualGuest") + @GET + @Path("/SoftLayer_Account/VirtualGuests") + @QueryParams(keys = "objectMask", values = LIST_GUEST_MASK) + @Fallback(Fallbacks.EmptySetOnNotFoundOr404.class) + Set listVirtualGuests(); + /** - * - * @return Gets all the active packages. - * This will give you a basic description of the packages that are currently - * active and from which you can order a server or additional services. - * - * Calling ProductPackage.getItems() will return an empty set. - * Use ProductPackageApi.getProductPackage(long id) to obtain items data. - * @see ProductPackageApi#getProductPackage + * @return retrieve block device groups for an account (private images) + * @see */ + @Named("Account:getBlockDeviceTemplateGroups") @GET - @Path("/SoftLayer_Account/ActivePackages.json") - @Consumes(MediaType.APPLICATION_JSON) - @Fallback(Fallbacks.NullOnNotFoundOr404.class) - Set getActivePackages(); + @Path("/SoftLayer_Account/getBlockDeviceTemplateGroups") + @QueryParams(keys = "objectMask", values = GUEST_MASK) + @Fallback(Fallbacks.EmptySetOnNotFoundOr404.class) + Set getBlockDeviceTemplateGroups(); } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/features/DatacenterApi.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/features/DatacenterApi.java index 8e7965a2ff6..7d88e67c724 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/features/DatacenterApi.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/features/DatacenterApi.java @@ -32,38 +32,32 @@ import org.jclouds.softlayer.domain.Datacenter; /** - * Provides synchronous access to LocationDatacenter. + * Provides access to LocationDatacenter via their REST API. *

- * * @see - * @author Adrian Cole */ @RequestFilters(BasicAuthentication.class) @Path("/v{jclouds.api-version}") +@Consumes(MediaType.APPLICATION_JSON) public interface DatacenterApi { /** - * * @return an account's associated datacenter objects. */ @GET - @Path("/SoftLayer_Location_Datacenter/Datacenters.json") + @Path("/SoftLayer_Location_Datacenter/Datacenters") @QueryParams(keys = "objectMask", values = "locationAddress;regions") - @Consumes(MediaType.APPLICATION_JSON) @Fallback(Fallbacks.EmptySetOnNotFoundOr404.class) Set listDatacenters(); /** - * * @param id * id of the datacenter * @return datacenter or null if not found */ @GET - @Path("/SoftLayer_Location_Datacenter/{id}.json") + @Path("/SoftLayer_Location_Datacenter/{id}") @QueryParams(keys = "objectMask", values = "locationAddress;regions") - @Consumes(MediaType.APPLICATION_JSON) @Fallback(Fallbacks.NullOnNotFoundOr404.class) Datacenter getDatacenter(@PathParam("id") long id); - } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/features/ProductPackageApi.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/features/SoftwareDescriptionApi.java similarity index 63% rename from providers/softlayer/src/main/java/org/jclouds/softlayer/features/ProductPackageApi.java rename to providers/softlayer/src/main/java/org/jclouds/softlayer/features/SoftwareDescriptionApi.java index efe1d9a2eb5..fdbc1ca6c23 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/features/ProductPackageApi.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/features/SoftwareDescriptionApi.java @@ -16,10 +16,11 @@ */ package org.jclouds.softlayer.features; +import java.util.Set; + import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; -import javax.ws.rs.PathParam; import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks; @@ -27,31 +28,25 @@ import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.softlayer.domain.ProductPackage; +import org.jclouds.softlayer.domain.SoftwareDescription; /** - * Provides synchronous access to ProductPackage. + * Provides access to Software_Description via their REST API. *

- * - * @see - * @author Adrian Cole + * @see */ @RequestFilters(BasicAuthentication.class) @Path("/v{jclouds.api-version}") -public interface ProductPackageApi { - public static String PRODUCT_MASK = "items.prices;items.categories;locations.locationAddress;locations.regions"; +@Consumes(MediaType.APPLICATION_JSON) +public interface SoftwareDescriptionApi { /** - * - * @param id - * id of the product package - * @return product package or null if not found + * @return all objects. */ @GET - @Path("/SoftLayer_Product_Package/{id}.json") - @QueryParams(keys = "objectMask", values = PRODUCT_MASK) - @Consumes(MediaType.APPLICATION_JSON) - @Fallback(Fallbacks.NullOnNotFoundOr404.class) - ProductPackage getProductPackage(@PathParam("id") long id); + @Path("/SoftLayer_Software_Description/getAllObjects") + @QueryParams(keys = "objectMask", values = "id;name;version;operatingSystem;longDescription;referenceCode") + @Fallback(Fallbacks.EmptySetOnNotFoundOr404.class) + Set getAllObjects(); } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestApi.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestApi.java index 6b768226024..a4bb5fb681c 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestApi.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestApi.java @@ -18,11 +18,13 @@ import java.util.Set; +import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks; @@ -31,148 +33,120 @@ import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.softlayer.binders.ProductOrderToJson; -import org.jclouds.softlayer.domain.ProductOrder; -import org.jclouds.softlayer.domain.ProductOrderReceipt; +import org.jclouds.softlayer.binders.TagToJson; +import org.jclouds.softlayer.binders.VirtualGuestToJson; +import org.jclouds.softlayer.domain.ContainerVirtualGuestConfiguration; import org.jclouds.softlayer.domain.VirtualGuest; /** - * Provides synchronous access to VirtualGuest. + * Provides access to VirtualGuest via their REST API. *

- * - * @see - * @author Adrian Cole + * + * @see */ @RequestFilters(BasicAuthentication.class) @Path("/v{jclouds.api-version}") +@Consumes(MediaType.APPLICATION_JSON) public interface VirtualGuestApi { - public static String LIST_GUEST_MASK = "virtualGuests.powerState;virtualGuests.networkVlans;virtualGuests.operatingSystem.passwords;virtualGuests.datacenter;virtualGuests.billingItem"; - public static String GUEST_MASK = "powerState;networkVlans;operatingSystem.passwords;datacenter;billingItem"; + + public static String GUEST_MASK = "id;hostname;domain;fullyQualifiedDomainName;powerState;maxCpu;maxMemory;" + + "statusId;operatingSystem.passwords;primaryBackendIpAddress;primaryIpAddress;activeTransactionCount;" + + "blockDevices.diskImage;datacenter;tagReferences"; /** - * - * @return an account's associated virtual guest objects. + * Enables the creation of computing instances on an account. + * @param virtualGuest this data type presents the structure in which all virtual guests will be presented. + * @return the new Virtual Guest + * @see */ - @GET - @Path("/SoftLayer_Account/VirtualGuests.json") - @QueryParams(keys = "objectMask", values = LIST_GUEST_MASK) - @Consumes(MediaType.APPLICATION_JSON) - @Fallback(Fallbacks.EmptySetOnNotFoundOr404.class) - Set listVirtualGuests(); + @Named("VirtualGuests:create") + @POST + @Path("SoftLayer_Virtual_Guest") + @Produces(MediaType.APPLICATION_JSON) + @Fallback(Fallbacks.NullOnNotFoundOr404.class) + VirtualGuest createVirtualGuest(@BinderParam(VirtualGuestToJson.class) VirtualGuest virtualGuest); /** - * * @param id * id of the virtual guest * @return virtual guest or null if not found + * @see */ + @Named("VirtualGuests:get") @GET - @Path("/SoftLayer_Virtual_Guest/{id}.json") + @Path("/SoftLayer_Virtual_Guest/{id}/getObject") @QueryParams(keys = "objectMask", values = GUEST_MASK) - @Consumes(MediaType.APPLICATION_JSON) @Fallback(Fallbacks.NullOnNotFoundOr404.class) VirtualGuest getVirtualGuest(@PathParam("id") long id); /** - * hard reboot the guest. - * - * @param id - * id of the virtual guest + * Delete a computing instance + * @param id the id of the virtual guest. + * @return the result of the deletion + * @see */ + @Named("VirtualGuests:delete") @GET - @Path("/SoftLayer_Virtual_Guest/{id}/rebootHard.json") - @Consumes(MediaType.APPLICATION_JSON) - @Fallback(Fallbacks.VoidOnNotFoundOr404.class) - void rebootHardVirtualGuest(@PathParam("id") long id); + @Path("/SoftLayer_Virtual_Guest/{id}/deleteObject") + @Fallback(Fallbacks.FalseOnNotFoundOr404.class) + boolean deleteVirtualGuest(@PathParam("id") long id); /** - * Power off a guest - * - * @param id - * id of the virtual guest + * Determine options available when creating a computing instance + * @see */ + @Named("VirtualGuests:getCreateObjectOptions") @GET - @Path("/SoftLayer_Virtual_Guest/{id}/powerOff.json") - @Consumes(MediaType.APPLICATION_JSON) - @Fallback(Fallbacks.VoidOnNotFoundOr404.class) - void powerOffVirtualGuest(@PathParam("id") long id); + @Path("/SoftLayer_Virtual_Guest/getCreateObjectOptions") + @Fallback(Fallbacks.NullOnNotFoundOr404.class) + ContainerVirtualGuestConfiguration getCreateObjectOptions(); /** - * Power on a guest + * Hard reboot the guest. * * @param id * id of the virtual guest */ + @Named("VirtualGuest:rebootHard") @GET - @Path("/SoftLayer_Virtual_Guest/{id}/powerOn.json") - @Consumes(MediaType.APPLICATION_JSON) + @Path("/SoftLayer_Virtual_Guest/{id}/rebootHard.json") @Fallback(Fallbacks.VoidOnNotFoundOr404.class) - void powerOnVirtualGuest(@PathParam("id") long id); + void rebootHardVirtualGuest(@PathParam("id") long id); /** - * pause the guest. + * Pause the guest. * * @param id * id of the virtual guest */ + @Named("VirtualGuest:pause") @GET @Path("/SoftLayer_Virtual_Guest/{id}/pause.json") - @Consumes(MediaType.APPLICATION_JSON) @Fallback(Fallbacks.VoidOnNotFoundOr404.class) void pauseVirtualGuest(@PathParam("id") long id); /** - * resume the guest. + * Resume the guest. * * @param id * id of the virtual guest */ + @Named("VirtualGuest:resume") @GET @Path("/SoftLayer_Virtual_Guest/{id}/resume.json") - @Consumes(MediaType.APPLICATION_JSON) @Fallback(Fallbacks.VoidOnNotFoundOr404.class) void resumeVirtualGuest(@PathParam("id") long id); /** - * Cancel the resource or service for a billing Item + * Resume the guest. * * @param id - * The id of the billing item to cancel - * @return true or false - */ - @GET - @Path("/SoftLayer_Billing_Item/{id}/cancelService.json") - @Consumes(MediaType.APPLICATION_JSON) - @Fallback(Fallbacks.FalseOnNotFoundOr404.class) - boolean cancelService(@PathParam("id") long id); - - /** - * Use this method for placing server orders and additional services orders. - * @param order - * Details required to order. - * @return A receipt for the order - * @see + * id of the virtual guest */ + @Named("VirtualGuest:setTags") @POST - @Path("/SoftLayer_Product_Order/placeOrder.json") - @Consumes(MediaType.APPLICATION_JSON) - @Fallback(Fallbacks.NullOnNotFoundOr404.class) - ProductOrderReceipt orderVirtualGuest(@BinderParam(ProductOrderToJson.class)ProductOrder order); - - /** - * Obtain an order container that is ready to be sent to the orderVirtualGuest method. - * This container will include all services that the selected computing instance has. - * If desired you may remove prices which were returned. - * @see - * @param id - * The id of the existing Virtual Guest - * @return - * The ProductOrder used to create the VirtualGust or null if not available - */ - @GET - @Path("SoftLayer_Virtual_Guest/{id}/getOrderTemplate/MONTHLY.json") - @Consumes(MediaType.APPLICATION_JSON) - @Fallback(Fallbacks.NullOnNotFoundOr404.class) - ProductOrder getOrderTemplate(@PathParam("id") long id); - + @Path("/SoftLayer_Virtual_Guest/{id}/setTags") + @Produces(MediaType.APPLICATION_JSON) + @Fallback(Fallbacks.FalseOnNotFoundOr404.class) + boolean setTags(@PathParam("id") long id, @BinderParam(TagToJson.class) Set tags); } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApi.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApi.java new file mode 100644 index 00000000000..8daa3306d79 --- /dev/null +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApi.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.features; + +import java.util.Set; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; + +import org.jclouds.Fallbacks; +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup; + +/** + * Provides access to VirtualGuestBlockDeviceTemplateGroup via their REST API. + *

+ * + * @see + */ +@RequestFilters(BasicAuthentication.class) +@Path("/v{jclouds.api-version}") +@Consumes(MediaType.APPLICATION_JSON) +public interface VirtualGuestBlockDeviceTemplateGroupApi { + + public static String LIST_PUBLIC_IMAGES_MASK = "children.blockDevices.diskImage.softwareReferences.softwareDescription"; + + /** + * @return public images + * @see + */ + @Named("VirtualGuestBlockDeviceTemplateGroup:getPublicImages") + @GET + @Path("/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages") + @QueryParams(keys = "objectMask", values = LIST_PUBLIC_IMAGES_MASK) + @Fallback(Fallbacks.EmptySetOnNotFoundOr404.class) + Set getPublicImages(); + +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/handlers/SoftLayerErrorHandler.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/handlers/SoftLayerErrorHandler.java index d665baf5109..d231bc8d2f8 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/handlers/SoftLayerErrorHandler.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/handlers/SoftLayerErrorHandler.java @@ -26,7 +26,6 @@ import org.jclouds.http.HttpResponseException; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.ResourceNotFoundException; -import org.jclouds.softlayer.exceptions.SoftLayerOrderItemDuplicateException; import org.jclouds.util.Closeables2; import org.jclouds.util.Strings2; @@ -34,9 +33,6 @@ /** * This will parse and set an appropriate exception on the command object. - * - * @author Adrian Cole - * */ @Singleton public class SoftLayerErrorHandler implements HttpErrorHandler { @@ -60,13 +56,11 @@ public void handleError(HttpCommand command, HttpResponse response) { } break; case 500: - if (message != null ) { + if (message != null ){ if (message.indexOf("Unable to determine package for") != -1) { exception = new ResourceNotFoundException(message, exception); } else if (message.indexOf("currently an active transaction") != -1) { exception = new IllegalStateException(message, exception); - } else if (message.indexOf("SoftLayer_Exception_Order_Item_Duplicate") != -1) { - exception = new SoftLayerOrderItemDuplicateException(command, response, message); } } } diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/predicates/ProductItemPredicates.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/predicates/ProductItemPredicates.java deleted file mode 100644 index d66b1eea2f5..00000000000 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/predicates/ProductItemPredicates.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.predicates; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.regex.Pattern; - -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemCategory; - -import com.google.common.base.Predicate; - -public class ProductItemPredicates { - - /** - * Tests if the ProductItem contains the required category. - * - * @param category - * @return true if it does, otherwise false. - */ - public static Predicate categoryCode(final String category) { - checkNotNull(category, "category cannot be null"); - return new Predicate() { - @Override - public boolean apply(ProductItem productItem) { - checkNotNull(productItem, "productItem cannot ne null"); - for (ProductItemCategory productItemCategory : productItem.getCategories()) { - if (category.equals(productItemCategory.getCategoryCode())) - return true; - } - return false; - } - - @Override - public String toString() { - return "categoryCode(" + category + ")"; - } - }; - } - - /** - * Tests if the ProductItem contains a category that matches the supplied Pattern - * - * @param category - * @return true if it does, otherwise false. - */ - public static Predicate categoryCodeMatches(final Pattern category) { - checkNotNull(category, "category cannot be null"); - return new Predicate() { - @Override - public boolean apply(ProductItem productItem) { - checkNotNull(productItem, "productItem cannot ne null"); - for (ProductItemCategory productItemCategory : productItem.getCategories()) { - if (category.matcher(productItemCategory.getCategoryCode()).matches()) - return true; - } - return false; - } - - @Override - public String toString() { - return "categoryCodeMatches(" + category + ")"; - } - }; - } - - /** - * Tests if the ProductItem has the required capacity. - * - * @param capacity - * @return true if it does, otherwise false. - */ - public static Predicate capacity(final Float capacity) { - checkNotNull(capacity, "capacity cannot be null"); - return new Predicate() { - @Override - public boolean apply(ProductItem productItem) { - checkNotNull(productItem, "productItem cannot ne null"); - Float productItemCapacity = productItem.getCapacity(); - if (productItemCapacity == null) - return false; - return capacity.equals(productItemCapacity); - } - - @Override - public String toString() { - return "capacity(" + capacity + ")"; - } - }; - } - - /** - * Tests if the ProductItem has the required units. - * - * @param units - * @return true if it does, otherwise false. - */ - public static Predicate units(final String units) { - checkNotNull(units, "units cannot be null"); - return new Predicate() { - @Override - public boolean apply(ProductItem productItem) { - checkNotNull(productItem, "productItem cannot ne null"); - return units.equals(productItem.getUnits()); - } - - @Override - public String toString() { - return "units(" + units + ")"; - } - }; - } - - /** - * Tests if the ProductItem's description matches the supplied regular expression. - * - * @param regex - * a regular expression to match against. - * @return true if it does, otherwise false. - * @throws java.util.regex.PatternSyntaxException - * if the regex is invalid - */ - public static Predicate matches(final Pattern regex) { - checkNotNull(regex, "regex cannot be null"); - - return new Predicate() { - @Override - public boolean apply(ProductItem productItem) { - checkNotNull(productItem, "productItem cannot ne null"); - return regex.matcher(productItem.getDescription()).matches(); - } - - @Override - public String toString() { - return "regex(" + regex + ")"; - } - }; - } -} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java b/providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java index a55e40b59b5..18c15af2d2b 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java +++ b/providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java @@ -20,37 +20,27 @@ * Configuration properties and constants used in SoftLayer connections. * * @author Adrian Cole + * @author Andrea Turli */ public interface SoftLayerConstants { - /** - * Name of the product package corresponding to cloud servers - */ - public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME = "jclouds.softlayer.virtualguest.package-name"; - - /** - * pattern where last group matches core speed - */ - public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX = "jclouds.softlayer.virtualguest.cpu-regex"; - - /** - * Uplink port speed for new guests (10, 100, 1000) - */ - public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_PORT_SPEED = "jclouds.softlayer.virtualguest.port-speed"; + public static final String SOFTLAYER_PROVIDER_NAME = "softlayer"; /** - * Default Boot Disk type (SAN, LOCAL) + * Number of milliseconds to wait for an order to arrive on the api. */ - public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_DISK0_TYPE = "jclouds.softlayer.virtualguest.disk0-type"; + public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY = "jclouds.softlayer.virtualguest" + + ".login_details_delay"; /** - * number of milliseconds to wait for an order to arrive on the api. + * Number of milliseconds to wait for a virtualguest to be without active transactions */ - public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY = "jclouds.softlayer.virtualguest.order-delay"; + public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_ACTIVE_TRANSACTIONS_DELAY = "jclouds.softlayer" + + ".virtualguest.active_transactions_delay"; /** - * standard prices for all new guests. + * By default, list images will now consider the public images */ - public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES = "jclouds.softlayer.virtualguest.prices"; + public static final String PROPERTY_SOFTLAYER_INCLUDE_PUBLIC_IMAGES = "jclouds.softlayer.include_public_images"; } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerApiTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerApiTest.java deleted file mode 100644 index b0458c0925a..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerApiTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -import org.jclouds.http.HttpRequest; -import org.jclouds.softlayer.features.BaseSoftLayerApiTest; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * Tests behavior of {@code SoftLayerApi} - * - * @author Adrian Cole - */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire -@Test(groups = "unit", testName = "SoftLayerApiTest") -public class SoftLayerApiTest extends BaseSoftLayerApiTest { - - private SoftLayerApi syncClient; - - public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException { - assert syncClient.getVirtualGuestApi() != null; - assert syncClient.getDatacenterApi() != null; - assert syncClient.getProductPackageApi() != null; - } - - @BeforeClass - @Override - protected void setupFactory() throws IOException { - super.setupFactory(); - syncClient = injector.getInstance(SoftLayerApi.class); - } - - @Override - protected void checkFilters(HttpRequest request) { - - } -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerProviderTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerProviderTest.java index c324643b610..5b0dc44243d 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerProviderTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerProviderTest.java @@ -19,13 +19,8 @@ import org.jclouds.providers.internal.BaseProviderMetadataTest; import org.testng.annotations.Test; -/** - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "SoftLayerProviderTest") +@Test(groups = "unit", testName = "SoftLayerApiMetadataTest") public class SoftLayerProviderTest extends BaseProviderMetadataTest { - public SoftLayerProviderTest() { super(new SoftLayerProviderMetadata(), new SoftLayerApiMetadata()); } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/binders/ProductOrderToJsonTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/binders/ProductOrderToJsonTest.java deleted file mode 100644 index 8cc51506fb8..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/binders/ProductOrderToJsonTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.binders; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.http.HttpRequest; -import org.jclouds.json.Json; -import org.jclouds.json.internal.GsonWrapper; -import org.jclouds.rest.Binder; -import org.jclouds.softlayer.domain.ProductItemPrice; -import org.jclouds.softlayer.domain.ProductOrder; -import org.jclouds.softlayer.domain.VirtualGuest; -import org.testng.annotations.BeforeGroups; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.gson.Gson; - -/** - * Tests behavior of {@code ProductOrderToJsonTest} - * - * @author Jason King - */ -@Test(groups = "unit") -public class ProductOrderToJsonTest { - - private static final String FORMAT = - "{'parameters':[{'complexType':'SoftLayer_Container_Product_Order_Virtual_Guest'," + - "'packageId':%d," + - "'location':'%s'," + - "'prices':[{'id':%d},{'id':%d}]," + - "'virtualGuests':[{'hostname':'%s','domain':'%s'}]," + - "'quantity':%d," + - "'useHourlyPricing':%b}" + - "]}"; - - private HttpRequest request; - private Binder binder; - - @BeforeGroups(groups = { "unit" }) - public void setup() { - request = HttpRequest.builder().method("GET").endpoint("http://momma").build(); - Json json = new GsonWrapper(new Gson()); - binder = new ProductOrderToJson(json); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testNullOrder() { - binder.bindToRequest(request, null); - } - - @Test - public void testCorrect() { - - ProductItemPrice price1 = ProductItemPrice.builder().id(100).build(); - ProductItemPrice price2 = ProductItemPrice.builder().id(101).build(); - - VirtualGuest guest = VirtualGuest.builder().hostname("myhost") - .domain("mydomain") - .build(); - - ProductOrder order = ProductOrder.builder() - .packageId(123) - .location("loc456") - .quantity(99) - .useHourlyPricing(true) - .prices(ImmutableSet.of(price1,price2)) - .virtualGuests(guest) - .build(); - - String expected = String.format(FORMAT.replaceAll("'","\""), - 123,"loc456",100,101,"myhost","mydomain",99,true); - - HttpRequest req = binder.bindToRequest(request, order); - - assertEquals(req.getPayload().getRawContent(), expected); - - } -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/binders/TagToJsonTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/binders/TagToJsonTest.java new file mode 100644 index 00000000000..58c9624bb42 --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/binders/TagToJsonTest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.binders; + +import static org.testng.Assert.assertEquals; +import java.util.Set; + +import org.jclouds.http.HttpRequest; +import org.jclouds.json.Json; +import org.jclouds.json.internal.GsonWrapper; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.gson.Gson; + +@Test(groups = "unit", testName = "TagToJsonTest") +public class TagToJsonTest { + + private Json json; + + @BeforeClass + public void init() { + json = new GsonWrapper(new Gson()); + } + + @Test + public void testVirtualGuestWithOperatingSystem() { + HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest").build(); + TagToJson binder = new TagToJson(json); + Set tags = ImmutableSet.of("jclouds"); + + request = binder.bindToRequest(request, tags); + + assertEquals(request.getPayload().getRawContent(), "{\"parameters\":[\"jclouds\"]}"); + } +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/binders/VirtualGuestToJsonTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/binders/VirtualGuestToJsonTest.java new file mode 100644 index 00000000000..3adf0dcd79e --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/binders/VirtualGuestToJsonTest.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.binders; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.http.HttpRequest; +import org.jclouds.json.Json; +import org.jclouds.json.internal.GsonWrapper; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.OperatingSystem; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.gson.Gson; + +@Test(groups = "unit", testName = "VirtualGuestToJsonTest") +public class VirtualGuestToJsonTest { + + private Json json; + + @BeforeClass + public void init() { + json = new GsonWrapper(new Gson()); + } + + @Test + public void testVirtualGuestWithOperatingSystem() { + HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest").build(); + VirtualGuestToJson binder = new VirtualGuestToJson(json); + VirtualGuest virtualGuestWithOS = VirtualGuest.builder() + .hostname("hostname") + .domain("domain") + .startCpus(1) + .maxMemory(1024) + .datacenter(Datacenter.builder() + .name("datacenterName") + .build()) + .operatingSystem(OperatingSystem.builder().id("123456789") + .operatingSystemReferenceCode("UBUNTU_12_64") + .build()) + .localDiskFlag(true) + .build(); + + request = binder.bindToRequest(request, virtualGuestWithOS); + + assertEquals(request.getPayload().getRawContent(), + "{" + + "\"parameters\":[" + + "{" + + "\"hostname\":\"hostname\"," + + "\"domain\":\"domain\"," + + "\"startCpus\":1," + + "\"maxMemory\":1024," + + "\"hourlyBillingFlag\":true," + + "\"operatingSystemReferenceCode\":\"UBUNTU_12_64\"," + + "\"localDiskFlag\":true," + + "\"datacenter\":{" + + "\"name\":\"datacenterName\"" + + "}" + + "}" + + "]" + + "}"); + } + + @Test + public void testVirtualGuestWithVirtualGuestBlockDeviceTemplateGroup() { + HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest").build(); + VirtualGuestToJson binder = new VirtualGuestToJson(json); + VirtualGuest virtualGuestWithOS = VirtualGuest.builder() + .hostname("hostname") + .domain("domain") + .startCpus(1) + .maxMemory(1024) + .datacenter(Datacenter.builder() + .name("datacenterName") + .build()) + .blockDeviceTemplateGroup(VirtualGuestBlockDeviceTemplateGroup.builder() + .globalIdentifier("ffaafa98-4b4a-4fa7-b9f7-b1bad5ec50f0") + .build()) + .localDiskFlag(true) + .build(); + + request = binder.bindToRequest(request, virtualGuestWithOS); + + assertEquals(request.getPayload().getRawContent(), + "{" + + "\"parameters\":[{" + + "\"hostname\":\"hostname\"," + + "\"domain\":\"domain\"," + + "\"startCpus\":1," + + "\"maxMemory\":1024," + + "\"hourlyBillingFlag\":true," + + "\"blockDeviceTemplateGroup\":{" + + "\"globalIdentifier\":\"ffaafa98-4b4a-4fa7-b9f7-b1bad5ec50f0\"" + + "}," + + "\"localDiskFlag\":true," + + "\"datacenter\":{" + + "\"name\":\"datacenterName\"" + + "}" + + "}" + + "]" + + "}"); + } + +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java index 61a8b82d11b..327150c6a8c 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java @@ -16,14 +16,15 @@ */ package org.jclouds.softlayer.compute; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; - -import java.util.Properties; -import java.util.Random; - +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; +import com.google.common.net.InetAddresses; +import com.google.inject.Injector; +import com.google.inject.Module; import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials; @@ -32,7 +33,6 @@ import org.jclouds.softlayer.SoftLayerApi; import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions; import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter; -import org.jclouds.softlayer.domain.ProductItem; import org.jclouds.softlayer.domain.VirtualGuest; import org.jclouds.softlayer.features.BaseSoftLayerApiLiveTest; import org.jclouds.ssh.SshClient; @@ -41,12 +41,12 @@ import org.testng.annotations.AfterGroups; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.net.HostAndPort; -import com.google.common.net.InetAddresses; -import com.google.inject.Injector; -import com.google.inject.Module; +import java.util.Properties; +import java.util.Random; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; @Test(groups = "live", singleThreaded = true, testName = "SoftLayerComputeServiceAdapterLiveTest") public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerApiLiveTest { @@ -67,7 +67,12 @@ protected SoftLayerApi create(Properties props, Iterable modules) { @Test public void testListLocations() { - assertFalse(Iterables.isEmpty(adapter.listLocations())); + assertFalse(Iterables.isEmpty(adapter.listLocations()), "locations must not be empty"); + } + + @Test + public void testListImages() { + assertFalse(Iterables.isEmpty(adapter.listImages()), "images must not be empty"); } private static final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate = new PrioritizeCredentialsFromTemplate( @@ -108,19 +113,19 @@ protected void doConnectViaSsh(VirtualGuest guest, LoginCredentials creds) { @Test public void testListHardwareProfiles() { - Iterable> profiles = adapter.listHardwareProfiles(); + Iterable profiles = adapter.listHardwareProfiles(); assertFalse(Iterables.isEmpty(profiles)); - for (Iterable profile : profiles) { - // CPU, RAM and Volume - assertEquals(Iterables.size(profile), 3); + for (Hardware profile : profiles) { + assertNotNull(profile); } } @AfterGroups(groups = "live") protected void tearDown() { - if (guest != null) + if (guest != null) { adapter.destroyNode(guest.getNodeId() + ""); + } super.tearDown(); } @@ -128,4 +133,11 @@ protected void tearDown() { protected Iterable setupModules() { return ImmutableSet. of(getLoggingModule(), new SshjSshClientModule()); } + + @Override + protected Properties setupProperties() { + Properties properties = super.setupProperties(); + properties.setProperty("jclouds.ssh.max-retries", "10"); + return properties; + } } 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 new file mode 100644 index 00000000000..618ed4f0563 --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceContextLiveTest.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.compute; + +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; +import org.jclouds.compute.domain.ComputeMetadata; +import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; +import org.jclouds.softlayer.SoftLayerApi; +import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.domain.VirtualGuestBlockDevice; +import org.jclouds.ssh.SshClient; +import org.jclouds.sshj.config.SshjSshClientModule; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; + +@Test(groups = "live", testName = "SoftLayerComputeServiceContextLiveTest") +public class SoftLayerComputeServiceContextLiveTest extends BaseComputeServiceContextLiveTest { + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + public SoftLayerComputeServiceContextLiveTest() { + provider = "softlayer"; + } + + @Test + public void testLaunchClusterWithMinDisk() throws RunNodesException { + int numNodes = 1; + final String name = "node"; + + ComputeServiceContext context = ContextBuilder.newBuilder("softlayer").credentials(identity, credential) + .modules(ImmutableSet.of(new SLF4JLoggingModule(), + new SshjSshClientModule())) + .build(ComputeServiceContext.class); + + for (ComputeMetadata compute : context.getComputeService().listNodes()) { + System.out.println(compute); + } + + 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); + + 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)); + //tags + options.tags(ImmutableList.of("jclouds")); + + Set nodes = context.getComputeService().createNodesInGroup(name, numNodes, template); + assertEquals(numNodes, nodes.size(), "wrong number of nodes"); + for (NodeMetadata node : nodes) { + logger.debug("Created Node: %s", node); + SshClient client = context.utils().sshForNode().apply(node); + client.connect(); + ExecResponse hello = client.exec("mount"); + logger.debug(hello.getOutput().trim()); + + VirtualGuest virtualGuest = context.unwrapApi(SoftLayerApi.class).getVirtualGuestApi() + .getVirtualGuest(Long.parseLong(node.getId())); + for (VirtualGuestBlockDevice blockDevice : virtualGuest.getVirtualGuestBlockDevices()) { + logger.debug(blockDevice.toString()); + } + + context.getComputeService().destroyNode(node.getId()); + } + } + +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceLiveTest.java index 15824aa646a..d5132406328 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceLiveTest.java @@ -16,6 +16,8 @@ */ package org.jclouds.softlayer.compute; +import java.util.Properties; + import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.sshj.config.SshjSshClientModule; @@ -25,12 +27,10 @@ import com.google.inject.Module; /** - * + * * Generally disabled, as it incurs higher fees. - * - * @author Adrian Cole */ -@Test(groups = "live", enabled = true, sequential = true) +@Test(groups = "live", enabled = true, singleThreaded = true) public class SoftLayerComputeServiceLiveTest extends BaseComputeServiceLiveTest { public SoftLayerComputeServiceLiveTest() { @@ -42,7 +42,7 @@ public SoftLayerComputeServiceLiveTest() { protected Module getSshModule() { return new SshjSshClientModule(); } - + // softlayer does not support metadata @Override protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { @@ -54,4 +54,11 @@ protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap getIso3166Codes() { - return ImmutableSet. of("SG", "US-CA", "US-TX", "US-VA", "US-WA", "NL"); + return ImmutableSet. of("SG", "US-CA", "US-TX", "US-VA", "US-WA", "NL", "NSFTW-IL"); } + @BeforeClass(groups = "live") + @Override + public void setupContext() { + super.setupContext(); + } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/DatacenterToLocationTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/DatacenterToLocationTest.java index 2bf789c1084..cd5970f230f 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/DatacenterToLocationTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/DatacenterToLocationTest.java @@ -33,8 +33,6 @@ /** * Tests {@code DatacenterToLocation} - * - * @author Jason King */ @Test(singleThreaded = true, groups = "unit") public class DatacenterToLocationTest { @@ -46,11 +44,12 @@ public class DatacenterToLocationTest { public void testDatacenterToLocation() { Address address = Address.builder().country("US").state("TX").description("This is Texas!").build(); - Datacenter datacenter = Datacenter.builder().id(1).longName("Texas Datacenter").locationAddress(address).build(); + Datacenter datacenter = Datacenter.builder().id(1).name("Texas").longName("Texas Datacenter") + .locationAddress(address).build(); Location location = function.apply(datacenter); - assertEquals(location.getId(), Long.toString(datacenter.getId())); + assertEquals(location.getId(), datacenter.getName()); Set iso3166Codes = location.getIso3166Codes(); assertEquals(iso3166Codes.size(), 1); assertTrue(iso3166Codes.contains("US-TX")); @@ -58,11 +57,11 @@ public void testDatacenterToLocation() { @Test public void testGetIso3166CodeNoCountryAndState() { - Datacenter datacenter = Datacenter.builder().id(1).longName("Nowhere").build(); + Datacenter datacenter = Datacenter.builder().id(1).name("Nowhere").longName("No where").build(); Location location = function.apply(datacenter); - assertEquals(location.getId(), Long.toString(datacenter.getId())); + assertEquals(location.getId(), datacenter.getName()); Set iso3166Codes = location.getIso3166Codes(); assertEquals(iso3166Codes.size(), 0); } @@ -71,11 +70,12 @@ public void testGetIso3166CodeNoCountryAndState() { public void testGetIso3166CodeCountryOnly() { Address address = Address.builder().country("US").description("This is North America!").build(); - Datacenter datacenter = Datacenter.builder().id(1).longName("Nowhere").locationAddress(address).build(); + Datacenter datacenter = Datacenter.builder().id(1).name("Nowhere").longName("No where").locationAddress(address) + .build(); Location location = function.apply(datacenter); - assertEquals(location.getId(), Long.toString(datacenter.getId())); + assertEquals(location.getId(), datacenter.getName()); Set iso3166Codes = location.getIso3166Codes(); assertEquals(iso3166Codes.size(), 1); assertTrue(iso3166Codes.contains("US")); @@ -86,11 +86,12 @@ public void testGetIso3166CodeWhitespaceTrimmer() { Address address = Address.builder().country(" US ").state(" TX ").description("This is spaced out Texas") .build(); - Datacenter datacenter = Datacenter.builder().id(1).longName("Nowhere").locationAddress(address).build(); + Datacenter datacenter = Datacenter.builder().id(1).name("NoWhere").longName("Nowhere").locationAddress(address) + .build(); Location location = function.apply(datacenter); - assertEquals(location.getId(), Long.toString(datacenter.getId())); + assertEquals(location.getId(), datacenter.getName()); Set iso3166Codes = location.getIso3166Codes(); assertEquals(iso3166Codes.size(), 1); assertTrue(iso3166Codes.contains("US-TX")); diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/OperatingSystemToImageTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/OperatingSystemToImageTest.java new file mode 100644 index 00000000000..dadc9119c1c --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/OperatingSystemToImageTest.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.compute.functions; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import org.jclouds.compute.domain.Image; +import org.jclouds.softlayer.domain.OperatingSystem; +import org.jclouds.softlayer.domain.SoftwareDescription; +import org.jclouds.softlayer.domain.SoftwareLicense; +import org.testng.annotations.Test; + +/** + * Tests the function that transforms SoftLayer OperatingSystem to generic image. + */ +@Test(groups="unit", testName = "OperatingSystemToImageTest") +public class OperatingSystemToImageTest { + + @Test + public void testOperatingSystemToImage() { + OperatingSystem operatingSystem = OperatingSystem.builder() + .id("123456789") + .softwareLicense(SoftwareLicense.builder() + .softwareDescription(SoftwareDescription.builder() + .version("12.04-64 Minimal for CCI") + .referenceCode("UBUNTU_12_64") + .longDescription("Ubuntu Linux 12.04 LTS Precise Pangolin - Minimal Install (64 bit)") + .build()) + .build()) + .build(); + Image image = new OperatingSystemToImage().apply(operatingSystem); + + assertEquals(image.getId(), operatingSystem.getId()); + String referenceCode = operatingSystem.getSoftwareLicense().getSoftwareDescription().getReferenceCode(); + assertEquals(image.getDescription(), referenceCode); + assertTrue(image.getOperatingSystem().getFamily().toString().equalsIgnoreCase("UBUNTU")); + assertEquals(image.getOperatingSystem().getVersion(), "12.04"); + assertEquals(image.getOperatingSystem().is64Bit(), true); + assertEquals(image.getStatus(), Image.Status.AVAILABLE); + } + +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemToImageTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemToImageTest.java deleted file mode 100644 index cb5f7759514..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemToImageTest.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.compute.functions; - -import static org.jclouds.softlayer.compute.functions.ProductItemToImage.imageId; -import static org.jclouds.softlayer.compute.functions.ProductItemToImage.osBits; -import static org.jclouds.softlayer.compute.functions.ProductItemToImage.osFamily; -import static org.jclouds.softlayer.compute.functions.ProductItemToImage.osVersion; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertNotNull; -import static org.testng.AssertJUnit.assertNull; -import static org.testng.AssertJUnit.assertTrue; - -import java.util.Arrays; -import java.util.List; -import java.util.NoSuchElementException; - -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemPrice; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; - -/** - * Tests {@code ProductItemToImage} - * - * @author Jason King - */ -@Test(groups = "unit", testName = "ProductItemToImageTest") -public class ProductItemToImageTest { - // Operating Systems available MAR 2012 - private static final List operatingSystems = Arrays.asList( - "CentOS 5 - LAMP Install (32 bit)", - "CentOS 5 - LAMP Install (64 bit)", - "CentOS 5 - Minimal Install (32 bit)", - "CentOS 5 - Minimal Install (64 bit)", - "CentOS 6.0 - LAMP Install (32 bit)", - "CentOS 6.0 - LAMP Install (64 bit)", - "CentOS 6.0 - Minimal Install (32 bit)", - "CentOS 6.0 - Minimal Install (64 bit)", - "Debian GNU/Linux 5.0 Lenny/Stable - LAMP Install (32 bit)", - "Debian GNU/Linux 5.0 Lenny/Stable - LAMP Install (64 bit)", - "Debian GNU/Linux 5.0 Lenny/Stable - Minimal Install (32 bit)", - "Debian GNU/Linux 5.0 Lenny/Stable - Minimal Install (64 bit)", - "Fedora Release 13 (32bit) - LAMP Install", - "Fedora Release 13 (32bit) - Minimal Install", - "Fedora Release 13 (64bit) - LAMP Install", - "Fedora Release 13 (64bit) - Minimal Install", - "Fedora Release 15 (32bit) - LAMP Install", - "Fedora Release 15 (32bit) - Minimal Install", - "Fedora Release 15 (64bit) - LAMP Install", - "Fedora Release 15 (64bit) - Minimal Install", - "Red Hat Enterprise Linux 5 - LAMP Install (32 bit)", - "Red Hat Enterprise Linux 5 - LAMP Install (64 bit)", - "Red Hat Enterprise Linux 5 - Minimal Install (64 bit)", - "Red Hat Enterprise Linux 6 - LAMP Install (32 bit)", - "Red Hat Enterprise Linux 6 - LAMP Install (64 bit)", - "Red Hat Enterprise Linux 6 - Minimal Install (32 bit)", - "Red Hat Enterprise Linux 6 - Minimal Install (64 bit)", - "Ubuntu Linux 10.04 LTS Lucid Lynx - LAMP Install (32 bit)", - "Ubuntu Linux 10.04 LTS Lucid Lynx - LAMP Install (64 bit)", - "Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install (32 bit)", - "Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install (64 bit)", - "Ubuntu Linux 8 LTS Hardy Heron - LAMP Install (32 bit)", - "Ubuntu Linux 8 LTS Hardy Heron - LAMP Install (64 bit)", - "Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (32 bit)", - "Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)", - "CloudLinux 6 (32 bit)", - "CloudLinux 6 (64 bit)", - "Windows Server 2003 Datacenter SP2 with R2 (32 bit)", - "Windows Server 2003 Datacenter SP2 with R2 (64 bit)", - "Windows Server 2003 Enterprise SP2 with R2 (64 bit)", - "Windows Server 2003 Standard SP2 with R2 (64 bit)", - "Windows Server 2008 Datacenter Edition SP2 (32bit)", - "Windows Server 2008 Datacenter Edition SP2 (64bit)", - "Windows Server 2008 Enterprise Edition SP2 (32bit)", - "Windows Server 2008 Enterprise Edition SP2 (64bit)", - "Windows Server 2008 R2 Datacenter Edition (64bit)", - "Windows Server 2008 R2 Enterprise Edition (64bit)", - "Windows Server 2008 R2 Standard Edition (64bit)", - "Windows Server 2008 Standard Edition SP2 (32bit)", - "Windows Server 2008 Standard Edition SP2 (64bit)"); - - @Test - public void testConversion() { - for ( String description : operatingSystems ) - { - ProductItem item = ProductItem.builder() - .description(description) - .prices(ProductItemPrice.builder().id(1234).build()) - .build(); - Image i = new ProductItemToImage().apply(item); - OperatingSystem os = i.getOperatingSystem(); - assertNotNull(os); - assertNotNull(os.getFamily()); - assertFalse(os.getFamily().equals(OsFamily.UNRECOGNIZED)); - assertNotNull(os.getVersion()); - } - } - - @Test - public void testUbuntu() { - ProductItem item = ProductItem.builder() - .description("Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install (64 bit)") - .prices(ProductItemPrice.builder().id(1234).build()) - .build(); - Image i = new ProductItemToImage().apply(item); - OperatingSystem os = i.getOperatingSystem(); - assertNotNull(os); - assertEquals(OsFamily.UBUNTU, os.getFamily()); - assertEquals("10.04",os.getVersion()); - assertTrue(os.is64Bit()); - } - - @Test - public void testUbuntuNoBitCount() { - ProductItem item = ProductItem.builder() - .description("Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install") - .prices(ProductItemPrice.builder().id(1234).build()) - .build(); - Image i = new ProductItemToImage().apply(item); - OperatingSystem os = i.getOperatingSystem(); - assertNotNull(os); - assertEquals(OsFamily.UBUNTU, os.getFamily()); - assertEquals("10.04",os.getVersion()); - assertFalse(os.is64Bit()); - } - - - @Test - public void testCompletelyUnknown() { - ProductItem item = ProductItem.builder() - .description("This fails to match anything!!!") - .prices(ProductItemPrice.builder().id(1234).build()) - .build(); - Image i = new ProductItemToImage().apply(item); - OperatingSystem os = i.getOperatingSystem(); - assertNotNull(os); - assertEquals(OsFamily.UNRECOGNIZED, os.getFamily()); - assertNull(os.getVersion()); - assertFalse(os.is64Bit()); - } - - @Test - public void test64BitUnknown() { - ProductItem item = ProductItem.builder() - .description("This only has the bit-count (64 bit)") - .prices(ProductItemPrice.builder().id(1234).build()) - .build(); - Image i = new ProductItemToImage().apply(item); - OperatingSystem os = i.getOperatingSystem(); - assertNotNull(os); - assertEquals(OsFamily.UNRECOGNIZED, os.getFamily()); - assertNull(os.getVersion()); - assertTrue(os.is64Bit()); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testNull() { - new ProductItemToImage().apply(null); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testNoDescription() { - ProductItem item = ProductItem.builder() - .prices(ProductItemPrice.builder().id(1234).build()) - .build(); - new ProductItemToImage().apply(item); - } - - @Test - public void testId() { - ProductItemPrice price = ProductItemPrice.builder().id(1234).build(); - ProductItem item = ProductItem.builder().prices(price).build(); - assertEquals("1234",imageId().apply(item)); - } - - @Test - public void testIdManyPrices() { - ProductItemPrice price1 = ProductItemPrice.builder().id(1234).build(); - ProductItemPrice price2 = ProductItemPrice.builder().id(5678).build(); - ProductItem item = ProductItem.builder().prices(ImmutableSet.of(price1,price2)).build(); - assertEquals("1234",imageId().apply(item)); - } - - @Test(expectedExceptions = NoSuchElementException.class) - public void testIdMissingPrices() { - ProductItem item = ProductItem.builder().build(); - imageId().apply(item); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testIdNull() { - imageId().apply(null); - } - - @Test - public void testOsFamily() { - assertEquals(OsFamily.UBUNTU,osFamily().apply("Ubuntu Linux os")); - } - - @Test - public void testOsFamilyUnrecognized() { - assertEquals(OsFamily.UNRECOGNIZED,osFamily().apply("not a known operating system")); - } - - @Test - public void testOsFamilyNull() { - assertEquals(OsFamily.UNRECOGNIZED,osFamily().apply(null)); - } - - @Test - public void testOsBitsWithSpace() { - assertEquals(osBits().apply("a (32 bit) os"),Integer.valueOf(32)); - } - - @Test - public void testOsBitsNoSpace() { - assertEquals(osBits().apply("a (64bit) os"),Integer.valueOf(64)); - } - - @Test - public void testOsBitsMissing() { - assertNull(osBits().apply("an os")); - } - - @Test - public void testOsBitsNull() { - assertNull(osBits().apply(null)); - } - - @Test - public void testOsVersion() { - assertEquals("2099",osVersion().apply("Windows Server 2099 (256 bit)")); - } - - @Test - public void testOsVersionMissing() { - assertNull(osVersion().apply("asd Server")); - } - - @Test - public void testOsVersionNull() { - assertNull(osVersion().apply(null)); - } -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemsTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemsTest.java deleted file mode 100644 index ea235742491..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemsTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.compute.functions; - -import static org.jclouds.softlayer.compute.functions.ProductItems.capacity; -import static org.jclouds.softlayer.compute.functions.ProductItems.description; -import static org.jclouds.softlayer.compute.functions.ProductItems.item; -import static org.jclouds.softlayer.compute.functions.ProductItems.price; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; - -import java.util.NoSuchElementException; - -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemCategory; -import org.jclouds.softlayer.domain.ProductItemPrice; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; - -/** - * Tests {@code ProductItems} - * - * @author Jason King - */ -@Test(groups = "unit") -public class ProductItemsTest { - - private ProductItemCategory category; - private ProductItemPrice price; - private ProductItem item; - - @BeforeMethod - public void setup() { - - category = ProductItemCategory.builder().id(1).categoryCode("category").build(); - - price = ProductItemPrice.builder().id(1).build(); - - item = ProductItem.builder().id(1) - .capacity(2.0f) - .description("an item") - .prices(price) - .build(); - } - - @Test - public void testCapacity() { - assertEquals(capacity().apply(item), 2.0f); - } - - @Test - public void testCapacityMissing() { - ProductItem item = ProductItem.builder().id(1).build(); - assertNull(capacity().apply(item)); - } - - @Test - public void testDescription() { - assertEquals(description().apply(item),"an item"); - } - - @Test - public void testDescriptionMissing() { - ProductItem item = ProductItem.builder().id(1).build(); - assertNull(description().apply(item)); - } - - @Test - public void testPrice() { - assertEquals(price().apply(item),price); - } - - @Test - public void testPriceMultiplePrices() { - ImmutableSet prices = ImmutableSet.of(price, ProductItemPrice.builder().id(2).build()); - ProductItem item2 = ProductItem.builder().prices(prices).build(); - assertEquals(price().apply(item2),price); - } - - @Test(expectedExceptions = NoSuchElementException.class) - public void testPriceMissing() { - ProductItem noPriceItem = ProductItem.builder().id(1).build(); - price().apply(noPriceItem); - } - - @Test - public void testItemCallGetsCategory() { - ProductItemPrice price = ProductItemPrice.builder().id(1) - .categories(category) - .item(item) - .build(); - ProductItem newItem = item().apply(price); - assertEquals(newItem.getCategories(), ImmutableSet.of(category)); - } - - @Test - public void testItemCallNoCategoryOnPrice() { - - ProductItem item1 = item.toBuilder().categories(ImmutableSet.of(category)).build(); - - ProductItemPrice price = ProductItemPrice.builder().id(1) - .item(item1) - .build(); - ProductItem newItem = item().apply(price); - assertEquals(newItem.getCategories(), ImmutableSet.of(category)); - } - - @Test - public void testItemCallCategoryExists() { - - ProductItemCategory category2 = ProductItemCategory.builder() - .id(12) - .categoryCode("new category") - .build(); - - ProductItem item1 = item.toBuilder().categories(ImmutableSet.of(category2)).build(); - - ProductItemPrice price = ProductItemPrice.builder().id(1) - .categories(category) - .item(item1) - .build(); - ProductItem newItem = item().apply(price); - assertEquals(newItem.getCategories(), ImmutableSet.of(category2)); - } - - -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemsToHardwareTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemsToHardwareTest.java deleted file mode 100644 index cac6159fb4e..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/ProductItemsToHardwareTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.compute.functions; - -import static com.google.inject.name.Names.bindProperties; -import static org.jclouds.softlayer.compute.functions.ProductItemsToHardware.hardwareId; -import static org.testng.AssertJUnit.assertEquals; - -import java.util.List; - -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.Processor; -import org.jclouds.compute.domain.Volume; -import org.jclouds.softlayer.SoftLayerProviderMetadata; -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemCategory; -import org.jclouds.softlayer.domain.ProductItemPrice; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; - -/** - * Tests {@code ProductItemsToHardware} - * - * @author Jason King - */ -@Test(groups = "unit") -public class ProductItemsToHardwareTest { - - private ProductItemsToHardware toHardware; - private ProductItem cpuItem; - private ProductItem ramItem; - private ProductItem volumeItem; - - @BeforeMethod - public void setup() { - - toHardware = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bindProperties(binder(), new SoftLayerProviderMetadata().getDefaultProperties()); - } - }).getInstance(ProductItemsToHardware.class); - - - cpuItem = ProductItem.builder() - .id(1) - .description("2 x 2.0 GHz Cores") - .capacity(2F) - .categories(ProductItemCategory.builder().categoryCode("guest_core").build()) - .prices(ProductItemPrice.builder().id(123).build()) - .build(); - - ramItem = ProductItem.builder().id(2).description("2GB ram").capacity(2F).categories( - ProductItemCategory.builder().categoryCode("ram").build()).prices( - ProductItemPrice.builder().id(456).build()).build(); - - volumeItem = ProductItem.builder().id(3).description("100 GB (SAN)").capacity(100F).prices( - ProductItemPrice.builder().id(789).build()).categories( - ProductItemCategory.builder().categoryCode("guest_disk0").build()).build(); - - - } - - @Test - public void testHardwareId() { - ProductItem item1 = ProductItem.builder().prices(ProductItemPrice.builder().id(123).build()).build(); - ProductItem item2 = ProductItem.builder().prices(ProductItemPrice.builder().id(456).build()).build(); - ProductItem item3 = ProductItem.builder().prices(ProductItemPrice.builder().id(789).build()).build(); - - String id = hardwareId().apply(ImmutableList.of(item1, item2, item3)); - assertEquals("123,456,789", id); - } - - @Test - public void testHardware() { - - Hardware hardware = toHardware.apply(ImmutableSet.of(cpuItem, ramItem, volumeItem)); - - assertEquals("123,456,789", hardware.getId()); - - List processors = hardware.getProcessors(); - assertEquals(1, processors.size()); - assertEquals(2.0, processors.get(0).getCores()); - - assertEquals(2048, hardware.getRam()); - - List volumes = hardware.getVolumes(); - assertEquals(1, volumes.size()); - Volume volume = volumes.get(0); - assertEquals(100F, volume.getSize()); - assertEquals(Volume.Type.SAN, volume.getType()); - assertEquals(true, volume.isBootDevice()); - - } - - @Test - public void testHardwareWithPrivateCore() { - - cpuItem = cpuItem.toBuilder() - .description("Private 2 x 2.0 GHz Cores") - .build(); - - Hardware hardware = toHardware.apply(ImmutableSet.of(cpuItem, ramItem, volumeItem)); - - assertEquals("123,456,789", hardware.getId()); - - List processors = hardware.getProcessors(); - assertEquals(1, processors.size()); - assertEquals(2.0, processors.get(0).getCores()); - - assertEquals(2048, hardware.getRam()); - - List volumes = hardware.getVolumes(); - assertEquals(1, volumes.size()); - assertEquals(100F, volumes.get(0).getSize()); - } - - @Test - public void testHardwareWithTwoDisks() { - ProductItem localVolumeItem = ProductItem.builder().id(4).description("25 GB").capacity(25F).prices( - ProductItemPrice.builder().id(987).build()).categories( - ProductItemCategory.builder().categoryCode("guest_disk1").build()).build(); - - Hardware hardware = toHardware.apply(ImmutableSet.of(cpuItem, ramItem, volumeItem,localVolumeItem)); - - List volumes = hardware.getVolumes(); - assertEquals(2, volumes.size()); - Volume volume = volumes.get(0); - assertEquals(100F, volume.getSize()); - assertEquals(Volume.Type.SAN, volume.getType()); - assertEquals(true, volume.isBootDevice()); - - Volume volume1 = volumes.get(1); - assertEquals(25F, volume1.getSize()); - assertEquals(Volume.Type.LOCAL, volume1.getType()); - assertEquals(false, volume1.isBootDevice()); - } -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToHardwareTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToHardwareTest.java new file mode 100644 index 00000000000..108c437c0fd --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToHardwareTest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.compute.functions; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.compute.domain.Hardware; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.OperatingSystem; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * Tests the function that transforms SoftLayer VirtualGuest to generic hardware. + */ +@Test(groups="unit", testName = "VirtualGuestToHardwareTest") +public class VirtualGuestToHardwareTest { + + @Test + public void testVirtualGuestToHardware() { + VirtualGuest virtualGuest = createVirtualGuest(); + Hardware hardware = new VirtualGuestToHardware().apply(virtualGuest); + assertNotNull(hardware); + assertEquals(hardware.getRam(), virtualGuest.getMaxMemory()); + assertTrue(hardware.getProcessors().size() == 1); + assertEquals(Iterables.get(hardware.getProcessors(), 0).getCores(), (double) virtualGuest.getStartCpus()); + } + + private VirtualGuest createVirtualGuest() { + return VirtualGuest.builder() + .domain("example.com") + .hostname("host1") + .id(1301396) + .maxMemory(1024) + .startCpus(1) + .localDiskFlag(true) + .operatingSystem(OperatingSystem.builder().id("UBUNTU_LATEST") + .operatingSystemReferenceCode("UBUNTU_LATEST") + .build()) + .datacenter(Datacenter.builder().name("test").build()) + .build(); + } +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToImageTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToImageTest.java new file mode 100644 index 00000000000..b903a378edd --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToImageTest.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.compute.functions; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.OperatingSystem; +import org.jclouds.softlayer.domain.SoftwareDescription; +import org.jclouds.softlayer.domain.SoftwareLicense; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.testng.annotations.Test; + +import com.google.inject.Guice; + +/** + * Tests the function that transforms SoftLayer VirtualGuest to generic image. + */ +@Test(groups="unit", testName = "VirtualGuestToImageTest") +public class VirtualGuestToImageTest { + + OperatingSystemToImage operatingSystemToImage = Guice.createInjector().getInstance(OperatingSystemToImage.class); + + @Test + public void testVirtualGuestToImageWhenOperatingSystemIsNull() { + VirtualGuest virtualGuest = createVirtualGuestWithoutOperatingSystem(); + Image image = new VirtualGuestToImage(operatingSystemToImage).apply(virtualGuest); + assertNotNull(image); + assertEquals(image.getStatus(), Image.Status.UNRECOGNIZED); + assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UNRECOGNIZED); + assertEquals(image.getOperatingSystem().getVersion(), "UNRECOGNIZED"); + } + + @Test + public void testVirtualGuestToImageWhenVirtualGuestIsSoftwareLicense() { + VirtualGuest virtualGuest = createVirtualGuestWithoutSoftwareLicenseDetails(); + Image image = new VirtualGuestToImage(operatingSystemToImage).apply(virtualGuest); + assertNotNull(image); + assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UNRECOGNIZED); + assertEquals(image.getOperatingSystem().getVersion(), "UNRECOGNIZED"); + } + + @Test + public void testVirtualGuestToImageWithSoftwareLicense() { + VirtualGuest virtualGuest = createVirtualGuestWithSoftwareLicenseDetails(); + Image image = new VirtualGuestToImage(operatingSystemToImage).apply(virtualGuest); + assertNotNull(image); + assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU); + assertEquals(image.getOperatingSystem().getVersion(), "12.04"); + assertEquals(image.getOperatingSystem().is64Bit(), true); + } + + private VirtualGuest createVirtualGuestWithoutOperatingSystem() { + return VirtualGuest.builder() + .domain("example.com") + .hostname("host1") + .id(1301396) + .maxMemory(1024) + .startCpus(1) + .localDiskFlag(true) + .datacenter(Datacenter.builder().name("test").build()) + .softwareLicense(SoftwareLicense.builder().build()) + .build(); + } + + private VirtualGuest createVirtualGuestWithoutSoftwareLicenseDetails() { + return VirtualGuest.builder() + .domain("example.com") + .hostname("host1") + .id(1301396) + .maxMemory(1024) + .startCpus(1) + .localDiskFlag(true) + .operatingSystem(OperatingSystem.builder().id("UBUNTU_LATEST") + .operatingSystemReferenceCode("UBUNTU_LATEST") + .build()) + .datacenter(Datacenter.builder().name("test").build()) + .build(); + } + + private VirtualGuest createVirtualGuestWithSoftwareLicenseDetails() { + return VirtualGuest.builder() + .domain("example.com") + .hostname("host1") + .id(1301396) + .maxMemory(1024) + .startCpus(1) + .localDiskFlag(true) + .operatingSystem(OperatingSystem.builder().id("UBUNTU_LATEST") + .operatingSystemReferenceCode("UBUNTU_LATEST") + .softwareLicense(SoftwareLicense.builder() + .softwareDescription(SoftwareDescription.builder() + .version("12.04-64 Minimal for CCI") + .referenceCode("UBUNTU_12_64") + .longDescription("Ubuntu Linux 12.04 LTS Precise Pangolin - Minimal Install (64 bit)") + .build()) + .build()) + .build()) + .datacenter(Datacenter.builder().name("test").build()) + .build(); + } +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadataTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadataTest.java index aac0081d431..637333bd113 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadataTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadataTest.java @@ -16,201 +16,85 @@ */ package org.jclouds.softlayer.compute.functions; -import static org.easymock.EasyMock.createNiceMock; import static org.testng.Assert.assertEquals; - +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import java.util.Set; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.HardwareBuilder; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeMetadata.Status; -import org.jclouds.compute.domain.NodeMetadataBuilder; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.functions.GroupNamingConvention; import org.jclouds.domain.Location; -import org.jclouds.softlayer.SoftLayerApi; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.OperatingSystem; +import org.jclouds.softlayer.domain.PowerState; +import org.jclouds.softlayer.domain.SoftwareDescription; +import org.jclouds.softlayer.domain.SoftwareLicense; import org.jclouds.softlayer.domain.VirtualGuest; -import org.jclouds.softlayer.parse.ParseBadVirtualGuest; -import org.jclouds.softlayer.parse.ParseVirtualGuestHaltedTest; -import org.jclouds.softlayer.parse.ParseVirtualGuestPausedTest; -import org.jclouds.softlayer.parse.ParseVirtualGuestRunningTest; -import org.jclouds.softlayer.parse.ParseVirtualGuestWithNoPasswordTest; import org.testng.annotations.Test; -import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import com.google.inject.Guice; /** - * @author Adrian Cole + * Tests the function that transforms SoftLayer VirtualGuest to NodeMetadata. */ -@Test(groups = "unit", testName = "VirtualGuestToNodeMetadataTest") +@Test(groups="unit", testName = "VirtualGuestToNodeMetadataTest") public class VirtualGuestToNodeMetadataTest { - GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class); - - @Test - public void testApplyWhereVirtualGuestWithNoPassword() { - - // notice if we've already parsed this properly here, we can rely on it. - VirtualGuest guest = new ParseVirtualGuestWithNoPasswordTest().expected(); - - // setup so that we have an expected Location to be parsed from the guest. - Location expectedLocation = DatacenterToLocationTest.function.apply(guest.getDatacenter()); - Supplier> locationSupplier = Suppliers.> ofInstance(ImmutableSet - . of(expectedLocation)); - - VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata( - locationSupplier, new GetHardwareForVirtualGuestMock(), new GetImageForVirtualGuestMock(), namingConvention); - - NodeMetadata node = parser.apply(guest); - - assertEquals( - node, - new NodeMetadataBuilder().ids("416788").name("node1000360500").hostname("node1000360500") - .location(expectedLocation).status(Status.PENDING) - .publicAddresses(ImmutableSet.of("173.192.29.186")) - .privateAddresses(ImmutableSet.of("10.37.102.194")) - .hardware(new GetHardwareForVirtualGuestMock().getHardware(guest)) - .imageId(new GetImageForVirtualGuestMock().getImage(guest).getId()) - .operatingSystem(new GetImageForVirtualGuestMock().getImage(guest).getOperatingSystem()).build()); - - } - - @Test - public void testApplyWhereVirtualIsBad() { - - // notice if we've already parsed this properly here, we can rely on it. - VirtualGuest guest = new ParseBadVirtualGuest().expected(); - - // no location here - Supplier> locationSupplier = Suppliers.> ofInstance(ImmutableSet - . of()); - - VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(locationSupplier, - new GetHardwareForVirtualGuestMock(), new GetImageForVirtualGuestMock(), namingConvention); - - NodeMetadata node = parser.apply(guest); - - assertEquals( - node, - new NodeMetadataBuilder().ids("413348").name("foo-ef4").hostname("foo-ef4").group("foo") - .status(Status.PENDING).hardware(new GetHardwareForVirtualGuestMock().getHardware(guest)) - .imageId(new GetImageForVirtualGuestMock().getImage(guest).getId()) - .operatingSystem(new GetImageForVirtualGuestMock().getImage(guest).getOperatingSystem()).build()); - - } - - @Test - public void testApplyWhereVirtualGuestIsHalted() { - - // notice if we've already parsed this properly here, we can rely on it. - VirtualGuest guest = new ParseVirtualGuestHaltedTest().expected(); - // setup so that we have an expected Location to be parsed from the guest. - Location expectedLocation = DatacenterToLocationTest.function.apply(guest.getDatacenter()); - Supplier> locationSupplier = Suppliers.> ofInstance(ImmutableSet - . of(expectedLocation)); - - VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(locationSupplier, - new GetHardwareForVirtualGuestMock(), new GetImageForVirtualGuestMock(), namingConvention); - - NodeMetadata node = parser.apply(guest); - - assertEquals( - node, - new NodeMetadataBuilder().ids("416700").name("node1703810489").hostname("node1703810489") - .location(expectedLocation).status(Status.PENDING) - .publicAddresses(ImmutableSet.of("173.192.29.187")) - .privateAddresses(ImmutableSet.of("10.37.102.195")) - .hardware(new GetHardwareForVirtualGuestMock().getHardware(guest)) - .imageId(new GetImageForVirtualGuestMock().getImage(guest).getId()) - .operatingSystem(new GetImageForVirtualGuestMock().getImage(guest).getOperatingSystem()).build()); - - } - - @Test - public void testApplyWhereVirtualGuestIsPaused() { - - // notice if we've already parsed this properly here, we can rely on it. - VirtualGuest guest = new ParseVirtualGuestPausedTest().expected(); - - // setup so that we have an expected Location to be parsed from the guest. - Location expectedLocation = DatacenterToLocationTest.function.apply(guest.getDatacenter()); - Supplier> locationSupplier = Suppliers.> ofInstance(ImmutableSet - . of(expectedLocation)); - - VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(locationSupplier, - new GetHardwareForVirtualGuestMock(), new GetImageForVirtualGuestMock(), namingConvention); - - NodeMetadata node = parser.apply(guest); - - assertEquals( - node, - new NodeMetadataBuilder().ids("416700").name("node1703810489").hostname("node1703810489") - .location(expectedLocation).status(Status.SUSPENDED) - .publicAddresses(ImmutableSet.of("173.192.29.187")) - .privateAddresses(ImmutableSet.of("10.37.102.195")) - .hardware(new GetHardwareForVirtualGuestMock().getHardware(guest)) - .imageId(new GetImageForVirtualGuestMock().getImage(guest).getId()) - .operatingSystem(new GetImageForVirtualGuestMock().getImage(guest).getOperatingSystem()).build()); + VirtualGuestToImage virtualGuestToImage = Guice.createInjector().getInstance(VirtualGuestToImage.class); + VirtualGuestToHardware virtualGuestToHardware = Guice.createInjector().getInstance(VirtualGuestToHardware.class); + GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class); - } + Location location = new LocationBuilder().id("123456789") + .description("example") + .scope(LocationScope.ZONE) + .build(); + Supplier> locationSupplier = Suppliers.> ofInstance(ImmutableSet.of(location)); @Test - public void testApplyWhereVirtualGuestIsRunning() { - - // notice if we've already parsed this properly here, we can rely on it. - VirtualGuest guest = new ParseVirtualGuestRunningTest().expected(); - - // setup so that we have an expected Location to be parsed from the guest. - Location expectedLocation = DatacenterToLocationTest.function.apply(guest.getDatacenter()); - Supplier> locationSupplier = Suppliers.> ofInstance(ImmutableSet - . of(expectedLocation)); - - VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(locationSupplier, - new GetHardwareForVirtualGuestMock(), new GetImageForVirtualGuestMock(), namingConvention); - - NodeMetadata node = parser.apply(guest); - - assertEquals( - node, - new NodeMetadataBuilder().ids("416700").name("node1703810489").hostname("node1703810489") - .location(expectedLocation).status(Status.RUNNING) - .publicAddresses(ImmutableSet.of("173.192.29.187")) - .privateAddresses(ImmutableSet.of("10.37.102.195")) - .hardware(new GetHardwareForVirtualGuestMock().getHardware(guest)) - .imageId(new GetImageForVirtualGuestMock().getImage(guest).getId()) - .operatingSystem(new GetImageForVirtualGuestMock().getImage(guest).getOperatingSystem()).build()); - + public void testVirtualGuestToNodeMetadata() { + + VirtualGuest virtualGuest = createVirtualGuest(); + NodeMetadata nodeMetadata = new VirtualGuestToNodeMetadata(locationSupplier, namingConvention, + virtualGuestToImage, virtualGuestToHardware).apply(virtualGuest); + assertNotNull(nodeMetadata); + assertEquals(nodeMetadata.getName(), virtualGuest.getHostname()); + assertEquals(nodeMetadata.getHostname(), virtualGuest.getHostname() + virtualGuest.getDomain()); + assertEquals(nodeMetadata.getHardware().getRam(), virtualGuest.getMaxMemory()); + assertTrue(nodeMetadata.getHardware().getProcessors().size() == 1); + assertEquals(Iterables.get(nodeMetadata.getHardware().getProcessors(), 0).getCores(), (double) virtualGuest.getStartCpus()); + assertEquals(nodeMetadata.getOperatingSystem().getFamily(), OsFamily.UBUNTU); + assertEquals(nodeMetadata.getOperatingSystem().getVersion(), "12.04"); + assertEquals(nodeMetadata.getOperatingSystem().is64Bit(), true); } - private static class GetHardwareForVirtualGuestMock extends VirtualGuestToNodeMetadata.GetHardwareForVirtualGuest { - @SuppressWarnings("unchecked") - public GetHardwareForVirtualGuestMock() { - super(createNiceMock(SoftLayerApi.class), createNiceMock(Function.class)); - } - - @Override - public Hardware getHardware(VirtualGuest guest) { - return new HardwareBuilder().ids("mocked hardware").build(); - } + private VirtualGuest createVirtualGuest() { + return VirtualGuest.builder() + .domain("example.com") + .hostname("host1") + .id(1301396) + .maxMemory(1024) + .startCpus(1) + .localDiskFlag(true) + .operatingSystem(OperatingSystem.builder().id("UBUNTU_LATEST") + .operatingSystemReferenceCode("UBUNTU_LATEST") + .softwareLicense(SoftwareLicense.builder() + .softwareDescription(SoftwareDescription.builder() + .version("12.04-64 Minimal for CCI") + .referenceCode("UBUNTU_12_64") + .longDescription("Ubuntu Linux 12.04 LTS Precise Pangolin - Minimal Install (64 bit)") + .build()) + .build()) + .build()) + .datacenter(Datacenter.builder().name("test").build()) + .powerState(PowerState.builder().keyName(VirtualGuest.State.RUNNING).build()) + .build(); } - private static class GetImageForVirtualGuestMock extends VirtualGuestToNodeMetadata.GetImageForVirtualGuest { - public GetImageForVirtualGuestMock() { - super(null); - } - - @Override - public Image getImage(VirtualGuest guest) { - return new ImageBuilder().ids("123").description("mocked image") - .operatingSystem(OperatingSystem.builder().description("foo os").build()) - .status(Image.Status.AVAILABLE).build(); - } - } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/internal/OperatingSystemsTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/internal/OperatingSystemsTest.java new file mode 100644 index 00000000000..6bda6f0ec2c --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/internal/OperatingSystemsTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.compute.functions.internal; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.compute.domain.OsFamily; +import org.testng.annotations.Test; + +@Test(singleThreaded = true, groups = "unit") +public class OperatingSystemsTest { + + @Test + public void testOsFamily() { + assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.CENTOS), OsFamily.CENTOS); + assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.DEBIAN), OsFamily.DEBIAN); + assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.RHEL), OsFamily.RHEL); + assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.UBUNTU), OsFamily.UBUNTU); + assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.WINDOWS), OsFamily.WINDOWS); + assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.CLOUD_LINUX), OsFamily.CLOUD_LINUX); + assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.VYATTACE), OsFamily.LINUX); + } + + @Test + public void testOsBits() { + assertEquals(OperatingSystems.bits().apply("UBUNTU_12_64").intValue(), 64); + assertEquals(OperatingSystems.bits().apply("UBUNTU_12_32").intValue(), 32); + } + + @Test + public void testOsVersion() { + assertEquals(OperatingSystems.version().apply("12.04-64 Minimal for VSI"), "12.04"); + assertEquals(OperatingSystems.version().apply("STD 32 bit"), "STD"); + } + +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptionsTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptionsTest.java index c2649e73800..7ccdafcf540 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptionsTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptionsTest.java @@ -26,8 +26,6 @@ /** * Tests possible uses of {@code SoftLayerTemplateOptions} and {@code * SoftLayerTemplateOptions.Builder.*}. - * - * @author Adrian Cole */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "SoftLayerTemplateOptionsTest") diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/domain/AddressTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/domain/AddressTest.java index 6b3bfaabe1f..47f8b3d300a 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/domain/AddressTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/domain/AddressTest.java @@ -18,11 +18,6 @@ import org.testng.annotations.Test; -/** - * Tests {@code Address} - * - * @author Jason King - */ @Test(singleThreaded = true, groups = "unit") public class AddressTest { diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiExpectTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiExpectTest.java new file mode 100644 index 00000000000..407e8124db7 --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiExpectTest.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.softlayer.SoftLayerApi; +import org.jclouds.softlayer.parse.GetVirtualGuestBlockDeviceTemplateGroupsResponseTest; +import org.jclouds.softlayer.parse.ListVirtualGuestsResponseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +@Test(groups = "unit", testName = "AccountApiExpectTest") +public class AccountApiExpectTest extends BaseSoftLayerApiExpectTest { + + public void testListVirtualGuestsWhenResponseIs2xx() { + + HttpRequest listVirtualGuestsRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests?objectMask=powerState%3BoperatingSystem.passwords%3Bdatacenter%3BbillingItem%3BblockDevices.diskImage%3BtagReferences") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse listVirtualGuestsResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/account_list.json")).build(); + + SoftLayerApi api = requestSendsResponse(listVirtualGuestsRequest, listVirtualGuestsResponse); + + assertEquals(api.getAccountApi().listVirtualGuests(), + new ListVirtualGuestsResponseTest().expected()); + } + + public void testListVirtualGuestsWhenResponseIs4xx() { + + HttpRequest listVirtualGuestsRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests?objectMask=powerState%3BoperatingSystem.passwords%3Bdatacenter%3BbillingItem%3BblockDevices.diskImage%3BtagReferences") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse listVirtualGuestsResponse = HttpResponse.builder().statusCode(404).build(); + + SoftLayerApi api = requestSendsResponse(listVirtualGuestsRequest, listVirtualGuestsResponse); + + assertTrue(Iterables.isEmpty(api.getAccountApi().listVirtualGuests())); + } + + public void testGetBlockDeviceTemplateGroupsWhenResponseIs2xx() { + + HttpRequest getVirtualGuestBlockDeviceTemplateGroup = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse getVirtualGuestBlockDeviceTemplateGroupResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/account_get_block_devices_template_groups.json")).build(); + + SoftLayerApi api = requestSendsResponse(getVirtualGuestBlockDeviceTemplateGroup, getVirtualGuestBlockDeviceTemplateGroupResponse); + + assertEquals(api.getAccountApi().getBlockDeviceTemplateGroups(), + new GetVirtualGuestBlockDeviceTemplateGroupsResponseTest().expected()); + } + + public void testGetBlockDeviceTemplateGroupsWhenResponseIs4xx() { + + HttpRequest getObjectRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse getObjectResponse = HttpResponse.builder().statusCode(404).build(); + + SoftLayerApi api = requestSendsResponse(getObjectRequest, getObjectResponse); + + assertTrue(Iterables.isEmpty(api.getAccountApi().getBlockDeviceTemplateGroups())); + } + +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiLiveTest.java index f80b0cc487b..fd3d3b442d4 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiLiveTest.java @@ -16,32 +16,57 @@ */ package org.jclouds.softlayer.features; +import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; - import java.util.Set; -import org.jclouds.softlayer.domain.ProductPackage; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup; import org.testng.annotations.Test; /** * Tests behavior of {@code AccountApi} - * - * @author Jason King */ @Test(groups = "live") public class AccountApiLiveTest extends BaseSoftLayerApiLiveTest { @Test - public void testGetActivePackages() { - Set response = api.getAccountApi().getActivePackages(); - assert null != response; + public void testGetBlockDeviceTemplateGroups() { + Set privateImages = api().getBlockDeviceTemplateGroups(); + assertNotNull(privateImages); + for (VirtualGuestBlockDeviceTemplateGroup privateImage : privateImages) { + assertTrue(privateImage.getId() > 0, "id must be greater than 0"); + assertTrue(privateImage.getStatusId() > 0, "status id must be greater than 0"); + assertTrue(privateImage.getAccountId() > 0, "id must be greater than 0"); + } + } + @Test + public void testListVirtualGuests() throws Exception { + Set response = api().listVirtualGuests(); assertTrue(response.size() >= 0); - for (ProductPackage productPackage: response) { - assert productPackage.getId() > 0 : response; - assert productPackage.getName() != null : response; - assert productPackage.getDescription() != null : response; - assertTrue(productPackage.getItems().isEmpty()); + for (VirtualGuest vg : response) { + checkVirtualGuest(vg); + } + } + + private AccountApi api() { + return api.getAccountApi(); + } + + private void checkVirtualGuest(VirtualGuest vg) { + if (vg.getActiveTransactionCount() == 0) { + assertNotNull(vg.getDomain(), "domain must be not null"); + assertNotNull(vg.getFullyQualifiedDomainName(), "fullyQualifiedDomainName must be not null"); + assertNotNull(vg.getHostname(), "hostname must be not null"); + assertTrue(vg.getId() > 0, "id must be greater than 0"); + assertTrue(vg.getMaxCpu() > 0, "maxCpu must be greater than 0"); + assertNotNull(vg.getMaxCpuUnits(), "maxCpuUnits must be not null"); + assertTrue(vg.getMaxMemory() > 0, "maxMemory must be greater than 0"); + assertTrue(vg.getStartCpus() > 0, "startCpus must be greater than 0"); + assertTrue(vg.getStatusId() > 0, "statusId must be greater than 0"); + assertNotNull(vg.getUuid(), "uuid must be not null"); } } + } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiTest.java deleted file mode 100644 index ccee098910c..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.features; - -import static org.jclouds.reflect.Reflection2.method; - -import java.io.IOException; - -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.reflect.Invokable; -/** - * Tests annotation parsing of {@code AccountApi} - * - * @author Jason King - */ -@Test(groups = "unit") -public class AccountApiTest extends BaseSoftLayerApiTest { - - public void testGetActivePackages() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(AccountApi.class, "getActivePackages"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals( - httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Account/ActivePackages.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ParseJson.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiExpectTest.java similarity index 67% rename from providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiTest.java rename to providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiExpectTest.java index 31da8ffd274..8a6a23adb72 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiExpectTest.java @@ -16,24 +16,12 @@ */ package org.jclouds.softlayer.features; -import static org.testng.Assert.assertEquals; - -import org.jclouds.http.HttpRequest; -import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.providers.ProviderMetadata; -import org.jclouds.rest.internal.BaseAsyncClientTest; +import org.jclouds.rest.internal.BaseRestApiExpectTest; +import org.jclouds.softlayer.SoftLayerApi; import org.jclouds.softlayer.SoftLayerProviderMetadata; -/** - * @author Adrian Cole - */ -public abstract class BaseSoftLayerApiTest extends BaseAsyncClientTest { - - @Override - protected void checkFilters(HttpRequest request) { - assertEquals(request.getFilters().size(), 1); - assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); - } +public abstract class BaseSoftLayerApiExpectTest extends BaseRestApiExpectTest { @Override public ProviderMetadata createProviderMetadata() { diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiLiveTest.java index 3bf529f82f8..bda65dfae82 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiLiveTest.java @@ -22,8 +22,6 @@ /** * Tests behavior of {@code SoftLayerApi} - * - * @author Adrian Cole */ @Test(groups = "live") public class BaseSoftLayerApiLiveTest extends BaseApiLiveTest { @@ -31,4 +29,5 @@ public class BaseSoftLayerApiLiveTest extends BaseApiLiveTest { public BaseSoftLayerApiLiveTest() { this.provider = "softlayer"; } + } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiExpectTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiExpectTest.java new file mode 100644 index 00000000000..2317a3ac574 --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiExpectTest.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.softlayer.parse.GetDatacenterResponseTest; +import org.jclouds.softlayer.parse.ListDatacentersResponseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * Tests annotation parsing of {@code DatacenterAsyncClient} + */ +@Test(groups = "unit") +public class DatacenterApiExpectTest extends BaseSoftLayerApiExpectTest { + + public void testListDatacentersWhenResponseIs2xx() { + + HttpRequest listDatacentersRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters?objectMask=locationAddress%3Bregions") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse listDatacentersResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/datacenter_list.json")).build(); + + DatacenterApi api = requestSendsResponse(listDatacentersRequest, listDatacentersResponse).getDatacenterApi(); + + assertEquals(api.listDatacenters(), + new ListDatacentersResponseTest().expected()); + } + + public void testListDatacenterWhenResponseIs4xx() { + + HttpRequest listDatacentersRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters?objectMask=locationAddress%3Bregions") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse listDatacentersResponse = HttpResponse.builder().statusCode(404).build(); + + DatacenterApi api = requestSendsResponse(listDatacentersRequest, listDatacentersResponse).getDatacenterApi(); + + assertTrue(Iterables.isEmpty(api.listDatacenters())); + } + + public void testGetDatacenterWhenResponseIs2xx() { + + HttpRequest getDatacenterRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/265592?objectMask=locationAddress%3Bregions") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse getDatacenterResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/datacenter_get.json")).build(); + + DatacenterApi api = requestSendsResponse(getDatacenterRequest, getDatacenterResponse).getDatacenterApi(); + + assertEquals(api.getDatacenter(265592), + new GetDatacenterResponseTest().expected()); + } + + public void testGetDatacenterWhenResponseIs4xx() { + + HttpRequest getDatacenterRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/265592?objectMask=locationAddress%3Bregions") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse getDatacenterResponse = HttpResponse.builder().statusCode(404).build(); + + DatacenterApi api = requestSendsResponse(getDatacenterRequest, getDatacenterResponse).getDatacenterApi(); + + assertNull(api.getDatacenter(265592)); + } +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiLiveTest.java index 1bcfe2b2ef0..f93e5507fa7 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiLiveTest.java @@ -17,6 +17,7 @@ package org.jclouds.softlayer.features; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import java.util.Set; @@ -31,8 +32,6 @@ /** * Tests behavior of {@code DatacenterApi} - * - * @author Adrian Cole */ @Test(groups = "live") public class DatacenterApiLiveTest extends BaseSoftLayerApiLiveTest { @@ -40,7 +39,7 @@ public class DatacenterApiLiveTest extends BaseSoftLayerApiLiveTest { @Test public void testListDatacenters() { Set response = api().listDatacenters(); - assert null != response; + assertNotNull(response); assertTrue(response.size() >= 0); for (Datacenter vg : response) { Datacenter newDetails = api().getDatacenter(vg.getId()); @@ -53,29 +52,31 @@ public void testListDatacenters() { public void testListDatacentersContent() { Builder builder = ImmutableSet.builder(); builder.add(Datacenter.builder().id(265592).name("ams01").longName("Amsterdam 1").build()); + builder.add(Datacenter.builder().id(358698).name("wdc03").longName("Ashburn, VA 3").build()); builder.add(Datacenter.builder().id(3).name("dal01").longName("Dallas").build()); - builder.add(Datacenter.builder().id(18171).name("sea01").longName("Seattle").build()); - builder.add(Datacenter.builder().id(168642).name("sjc01").longName("San Jose 1").build()); - builder.add(Datacenter.builder().id(2).name("dal00").longName("Corporate HQ").build()); - builder.add(Datacenter.builder().id(37473).name("wdc01").longName("Washington, DC").build()); builder.add(Datacenter.builder().id(154770).name("dal02").longName("Dallas 2").build()); - builder.add(Datacenter.builder().id(138124).name("dal05").longName("Dallas 5").build()); - builder.add(Datacenter.builder().id(167093).name("hou01").longName("Houston 1").build()); - builder.add(Datacenter.builder().id(167094).name("lon01").longName("London 1").build()); builder.add(Datacenter.builder().id(167092).name("dal04").longName("Dallas 4").build()); - builder.add(Datacenter.builder().id(224092).name("sng01").longName("Singapore 1").build()); - builder.add(Datacenter.builder().id(142775).name("hou02").longName("Houston 2").build()); - builder.add(Datacenter.builder().id(142776).name("dal07").longName("Dallas 7").build()); + builder.add(Datacenter.builder().id(138124).name("dal05").longName("Dallas 5").build()); builder.add(Datacenter.builder().id(154820).name("dal06").longName("Dallas 6").build()); + builder.add(Datacenter.builder().id(142776).name("dal07").longName("Dallas 7").build()); + builder.add(Datacenter.builder().id(352392).name("dal08").longName("Dallas 8").build()); + builder.add(Datacenter.builder().id(352494).name("hkg02").longName("Hong Kong 2").build()); + builder.add(Datacenter.builder().id(142775).name("hou02").longName("Houston 2").build()); + builder.add(Datacenter.builder().id(358694).name("lon02").longName("London 2").build()); + builder.add(Datacenter.builder().id(18171).name("sea01").longName("Seattle").build()); + builder.add(Datacenter.builder().id(168642).name("sjc01").longName("San Jose 1").build()); + builder.add(Datacenter.builder().id(224092).name("sng01").longName("Singapore 1").build()); + builder.add(Datacenter.builder().id(37473).name("wdc01").longName("Washington, DC 1").build()); + builder.add(Datacenter.builder().id(224092).name("sng01").longName("Singapore 1").build()); + Set response = api().listDatacenters(); Set expected = builder.build(); - assertEquals(response.size(),expected.size()); - assertTrue(response.containsAll(expected)); + assertEquals(response.size(), expected.size()); - for (Datacenter datacenter: response) { + for(Datacenter datacenter: response) { Address address = datacenter.getLocationAddress(); - if (address != null) checkAddress(address); + if(address!=null) checkAddress(address); } } @@ -84,19 +85,19 @@ private DatacenterApi api() { } private void checkDatacenter(Datacenter dc) { - assert dc.getId() > 0 : dc; - assert dc.getName() != null : dc; - assert dc.getLongName() != null : dc; - for ( Region region: dc.getRegions()) checkRegion(region); + assertNotNull(dc.getId()); + assertNotNull(dc.getName()); + assertNotNull(dc.getLongName()); + for( Region region: dc.getRegions()) checkRegion(region); } private void checkRegion(Region region) { - assert !region.getDescription().isEmpty() : region; - assert !region.getKeyname().isEmpty() : region; + assertNotNull(region.getDescription()); + assertNotNull(region.getKeyname()); } private void checkAddress(Address address) { - assert address.getId() >0 : address; - assert address.getCountry() != null : address; + assertNotNull(address.getId()); + assertNotNull(address.getCountry()); } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiTest.java deleted file mode 100644 index 7a7a37aee1e..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.features; - -import static org.jclouds.reflect.Reflection2.method; - -import java.io.IOException; - -import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404; -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.reflect.Invokable; -/** - * Tests annotation parsing of {@code DatacenterApi} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class DatacenterApiTest extends BaseSoftLayerApiTest { - - public void testListDatacenters() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(DatacenterApi.class, "listDatacenters"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters.json?objectMask=locationAddress%3Bregions HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - // now make sure request filters apply by replaying - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters.json?objectMask=locationAddress%3Bregions HTTP/1.1"); - // for example, using basic authentication, we should get "only one" - // header - assertNonPayloadHeadersEqual(httpRequest, - "Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ParseJson.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testGetDatacenter() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(DatacenterApi.class, "getDatacenter", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList. of(1234)); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/1234.json?objectMask=locationAddress%3Bregions HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ParseJson.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiLiveTest.java deleted file mode 100644 index 90172f18945..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiLiveTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.features; - -import static org.jclouds.softlayer.predicates.ProductItemPredicates.capacity; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.categoryCode; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.units; -import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.Map; -import java.util.Set; - -import org.jclouds.softlayer.compute.functions.ProductItems; -import org.jclouds.softlayer.domain.Address; -import org.jclouds.softlayer.domain.Datacenter; -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemCategory; -import org.jclouds.softlayer.domain.ProductItemPrice; -import org.jclouds.softlayer.domain.ProductPackage; -import org.jclouds.softlayer.domain.Region; -import org.testng.annotations.BeforeGroups; -import org.testng.annotations.Test; - -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; - -/** - * Tests behavior of {@code ProductPackageApi} - * - * @author Adrian Cole - */ -@Test(groups = "live", singleThreaded = true, testName = "ProductPackageApiLiveTest") -public class ProductPackageApiLiveTest extends BaseSoftLayerApiLiveTest { - - /** - * Name of the package used for ordering virtual guests. For real this is - * passed in using the property - * - * @{code org.jclouds.softlayer.reference.SoftLayerConstants. - * PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME} - */ - public static final String CLOUD_SERVER_PACKAGE_NAME = "Cloud Server"; - - @BeforeGroups(groups = { "live" }) - public void setup() { - super.setup(); - client = api.getProductPackageApi(); - accountApi = api.getAccountApi(); - - // This is used several times, so cache to speed up the test. - cloudServerPackageId = Iterables.find(accountApi.getActivePackages(), named(CLOUD_SERVER_PACKAGE_NAME)) - .getId(); - cloudServerProductPackage = client.getProductPackage(cloudServerPackageId); - } - - private ProductPackageApi client; - private AccountApi accountApi; - - private int cloudServerPackageId; - private ProductPackage cloudServerProductPackage; - - @Test - public void testGetProductPackage() { - for (ProductPackage productPackage : accountApi.getActivePackages()) { - ProductPackage response = client.getProductPackage(productPackage.getId()); - - assert null != response; - assert response.getId() > 0 : response; - assert response.getName() != null : response; - assert response.getDescription() != null : response; - - assertTrue(response.getItems().size() >= 0); - for (ProductItem item : response.getItems()) { - // ProductItem newDetails = client.getProductItem(item.getId()); - // assertEquals(item.getId(), newDetails.getId()); - checkProductItem(item); - } - - assertTrue(response.getDatacenters().size() > 0); - for (Datacenter datacenter : response.getDatacenters()) { - checkDatacenter(datacenter); - } - } - } - - @Test - public void testDatacentersForCloudLayer() { - - ImmutableSet.Builder builder = ImmutableSet.builder(); - builder.add(Datacenter.builder().id(18171).name("sea01").longName("Seattle").build()); - builder.add(Datacenter.builder().id(37473).name("wdc01").longName("Washington, DC").build()); - builder.add(Datacenter.builder().id(138124).name("dal05").longName("Dallas 5").build()); - builder.add(Datacenter.builder().id(168642).name("sjc01").longName("San Jose 1").build()); - builder.add(Datacenter.builder().id(224092).name("sng01").longName("Singapore 1").build()); - builder.add(Datacenter.builder().id(265592).name("ams01").longName("Amsterdam 1").build()); - - Set expected = builder.build(); - - Set datacenters = cloudServerProductPackage.getDatacenters(); - assert datacenters.size() == expected.size() : datacenters; - assertTrue(datacenters.containsAll(expected)); - - for (Datacenter dataCenter : datacenters) { - Address address = dataCenter.getLocationAddress(); - assertNotNull(address); - checkAddress(address); - } - } - - @Test - public void testGetOneGBRamPrice() { - // Predicate p = - // Predicates.and(ProductItemPredicates.categoryCode("ram"),ProductItemPredicates.capacity(1.0f)); - Iterable ramItems = Iterables.filter(cloudServerProductPackage.getItems(), - Predicates.and(categoryCode("ram"), capacity(1.0f))); - - // capacity is key in GB (1Gb = 1.0f) - Map ramToProductItem = Maps.uniqueIndex(ramItems, ProductItems.capacity()); - - ProductItemPrice price = ProductItems.price().apply(ramToProductItem.get(1.0f)); - assert Integer.valueOf(1644).equals(price.getId()); - } - - @Test - public void testGetTwoCPUCoresPrice() { - // If use ProductItemPredicates.categoryCode("guest_core") get duplicate - // capacities (units = - // PRIVATE_CORE and N/A) - Iterable cpuItems = Iterables.filter(cloudServerProductPackage.getItems(), - Predicates.and(units("PRIVATE_CORE"), capacity(2.0f))); - - // number of cores is the key - Map coresToProductItem = Maps.uniqueIndex(cpuItems, ProductItems.capacity()); - - ProductItemPrice price = ProductItems.price().apply(coresToProductItem.get(2.0f)); - assert Integer.valueOf(1963).equals(price.getId()); - } - - @Test - public void testGetUbuntuPrice() { - Iterable operatingSystems = Iterables.filter(cloudServerProductPackage.getItems(), - categoryCode("os")); - - Map osToProductItem = Maps.uniqueIndex(operatingSystems, ProductItems.description()); - - ProductItemPrice price = ProductItems.price().apply( - osToProductItem.get("Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)")); - assert Integer.valueOf(1693).equals(price.getId()); - } - - private void checkProductItem(ProductItem item) { - assert item.getId() > 0 : item; - assert item.getDescription() != null : item; - checkCategories(item.getCategories()); - // units and capacity may be null - - assertTrue(item.getPrices().size() >= 0); - - for (ProductItemPrice price : item.getPrices()) { - // ProductItemPrice newDetails = - // client.getProductItemPrice(prices.getId()); - // assertEquals(item.getId(), newDetails.getId()); - checkPrice(price); - } - } - - private void checkPrice(ProductItemPrice price) { - assert price.getId() > 0 : price; - assert price.getItemId() > 0 : price; - assert price.getRecurringFee() != null || price.getHourlyRecurringFee() != null : price; - } - - private void checkDatacenter(Datacenter datacenter) { - assert datacenter.getId() > 0 : datacenter; - assert datacenter.getName() != null : datacenter; - assert datacenter.getLongName() != null : datacenter; - for (Region region : datacenter.getRegions()) - checkRegion(region); - } - - private void checkRegion(Region region) { - assert !region.getDescription().isEmpty() : region; - assert !region.getKeyname().isEmpty() : region; - } - - private void checkAddress(Address address) { - assert address.getId() > 0 : address; - assert address.getCountry() != null : address; - if (!ImmutableSet.of("SG", "NL").contains(address.getCountry())) - assert address.getState() != null : address; - } - - private void checkCategories(Set categories) { - for (ProductItemCategory category : categories) { - assert category.getId() > 0 : category; - assert category.getName() != null : category; - assert category.getCategoryCode() != null : category; - } - } -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiTest.java deleted file mode 100644 index 196a99ef6c3..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.features; - -import static org.jclouds.reflect.Reflection2.method; - -import java.io.IOException; - -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.reflect.Invokable; -/** - * Tests annotation parsing of {@code ProductPackageApi} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ProductPackageApiTest extends BaseSoftLayerApiTest { - - public void testGetProductPackage() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(ProductPackageApi.class, "getProductPackage", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList. of(1234)); - - assertRequestLineEquals( - httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/1234.json?objectMask=items.prices%3Bitems.categories%3Blocations.locationAddress%3Blocations.regions HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ParseJson.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiExpectTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiExpectTest.java new file mode 100644 index 00000000000..c8286c27d51 --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiExpectTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.softlayer.parse.GetAllObjectsResponseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * Tests annotation parsing of {@code DatacenterAsyncClient} + */ +@Test(groups = "unit") +public class SoftwareDescriptionApiExpectTest extends BaseSoftLayerApiExpectTest { + + public void testGetAllObjectsWhenResponseIs2xx() { + + HttpRequest getAllObjectsRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Software_Description/getAllObjects?objectMask=id%3Bname%3Bversion%3BoperatingSystem%3BlongDescription%3BreferenceCode") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + HttpResponse getAllObjectsResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/software_description_list.json")).build(); + SoftwareDescriptionApi api = requestSendsResponse(getAllObjectsRequest, getAllObjectsResponse).getSoftwareDescriptionApi(); + assertEquals(api.getAllObjects(), new GetAllObjectsResponseTest().expected()); + } + + public void testGetAllObjectsWhenResponseIs4xx() { + + HttpRequest getAllObjectsRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Software_Description/getAllObjects?objectMask=id%3Bname%3Bversion%3BoperatingSystem%3BlongDescription%3BreferenceCode") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + HttpResponse getAllObjectsResponse = HttpResponse.builder().statusCode(404).build(); + SoftwareDescriptionApi api = requestSendsResponse(getAllObjectsRequest, getAllObjectsResponse).getSoftwareDescriptionApi(); + assertTrue(Iterables.isEmpty(api.getAllObjects())); + } + +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/predicates/ProductPackagePredicatesTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiLiveTest.java similarity index 56% rename from providers/softlayer/src/test/java/org/jclouds/softlayer/predicates/ProductPackagePredicatesTest.java rename to providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiLiveTest.java index 624d8cef47c..0948c6f0ef8 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/predicates/ProductPackagePredicatesTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiLiveTest.java @@ -14,31 +14,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jclouds.softlayer.predicates; +package org.jclouds.softlayer.features; -import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; +import java.util.Set; -import org.jclouds.softlayer.domain.ProductPackage; +import org.jclouds.softlayer.domain.SoftwareDescription; import org.testng.annotations.Test; /** - * Tests {@code ProductPackagePredicates} - * - * @author Jason King + * Tests behavior of {@code SoftwareDescriptionApi} */ -@Test(sequential = true,groups = "unit") -public class ProductPackagePredicatesTest { +@Test(groups = "live") +public class SoftwareDescriptionApiLiveTest extends BaseSoftLayerApiLiveTest { @Test - public void testMatches() { - ProductPackage productPackage = ProductPackage.builder().name("foo").build(); - assertTrue(ProductPackagePredicates.named("foo").apply(productPackage)); + public void testGetAllObjects() { + Set response = api().getAllObjects(); + assertNotNull(response); + assertTrue(response.size() >= 0); } - @Test - public void testDoesNotMatch() { - ProductPackage productPackage = ProductPackage.builder().name("foo").build(); - assertFalse(ProductPackagePredicates.named("bar").apply(productPackage)); + private SoftwareDescriptionApi api() { + return api.getSoftwareDescriptionApi(); } + } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiExpectTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiExpectTest.java index b35c139e907..cfba677d7f5 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiExpectTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiExpectTest.java @@ -16,43 +16,261 @@ */ package org.jclouds.softlayer.features; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import javax.ws.rs.core.MediaType; + import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.rest.internal.BaseRestClientExpectTest; import org.jclouds.softlayer.SoftLayerApi; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.OperatingSystem; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.parse.CreateVirtualGuestResponseTest; +import org.jclouds.softlayer.parse.GetCreateObjectOptionsResponseTest; +import org.jclouds.softlayer.parse.GetVirtualGuestResponseTest; import org.testng.annotations.Test; -/** - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "SoftLayerClientExpectTest") -public class VirtualGuestApiExpectTest extends BaseRestClientExpectTest { +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit", testName = "VirtualGuestApiExpectTest") +public class VirtualGuestApiExpectTest extends BaseSoftLayerApiExpectTest { + + public void testGetVirtualGuestWhenResponseIs2xx() { + + HttpRequest getVirtualGuest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/3001812/getObject?objectMask=id%3Bhostname%3Bdomain%3BfullyQualifiedDomainName%3BpowerState%3BmaxCpu%3BmaxMemory%3BstatusId%3BoperatingSystem.passwords%3BprimaryBackendIpAddress%3BprimaryIpAddress%3BactiveTransactionCount%3BblockDevices.diskImage%3Bdatacenter%3BtagReferences") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse getVirtualGuestResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/virtual_guest_get.json")).build(); + + SoftLayerApi api = requestSendsResponse(getVirtualGuest, getVirtualGuestResponse); + + assertEquals(api.getVirtualGuestApi().getVirtualGuest(3001812), + new GetVirtualGuestResponseTest().expected()); + } + + public void testGetVirtualGuestWhenResponseIs4xx() { + + HttpRequest getObjectRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/3001812/getObject?objectMask=id%3Bhostname%3Bdomain%3BfullyQualifiedDomainName%3BpowerState%3BmaxCpu%3BmaxMemory%3BstatusId%3BoperatingSystem.passwords%3BprimaryBackendIpAddress%3BprimaryIpAddress%3BactiveTransactionCount%3BblockDevices.diskImage%3Bdatacenter%3BtagReferences") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse getObjectResponse = HttpResponse.builder().statusCode(404).build(); + SoftLayerApi api = requestSendsResponse(getObjectRequest, getObjectResponse); + assertNull(api.getVirtualGuestApi().getVirtualGuest(3001812)); + } + + public void testCreateVirtualGuestWhenResponseIs2xx() { + + HttpRequest createVirtualGuest = HttpRequest.builder().method("POST") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") + .payload(payloadFromResourceWithContentType("/virtual_guest_create.json", MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse createVirtualGuestResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/virtual_guest_create_response.json")).build(); + VirtualGuestApi api = requestSendsResponse(createVirtualGuest, createVirtualGuestResponse).getVirtualGuestApi(); + VirtualGuest virtualGuest = createVirtualGuest(); + VirtualGuest result = api.createVirtualGuest(virtualGuest); + assertEquals(result, new CreateVirtualGuestResponseTest().expected()); + } + + public void testCreateVirtualGuestWhenResponseIs4xx() { + + HttpRequest createVirtualGuest = HttpRequest.builder().method("POST") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") + .payload(payloadFromResourceWithContentType("/virtual_guest_create.json", MediaType.APPLICATION_JSON)) + .build(); - public VirtualGuestApiExpectTest() { - provider = "softlayer"; + HttpResponse createVirtualGuestResponse = HttpResponse.builder().statusCode(404).build(); + SoftLayerApi api = requestSendsResponse(createVirtualGuest, createVirtualGuestResponse); + VirtualGuest virtualGuest = createVirtualGuest(); + assertNull(api.getVirtualGuestApi().createVirtualGuest(virtualGuest)); } - - public void testCancelGuestReturnsTrueOn200AndFalseOn404() { - - HttpRequest cancelGuest11 = HttpRequest.builder().method("GET") - .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Billing_Item/11/cancelService.json") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); - HttpResponse found = HttpResponse.builder().statusCode(200).build(); + public void testDeleteVirtualGuestWhenResponseIs2xx() { - SoftLayerApi clientWhenServiceExists = requestSendsResponse(cancelGuest11, found); - - assert clientWhenServiceExists.getVirtualGuestApi().cancelService(11l); + HttpRequest deleteVirtualGuest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/deleteObject") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") + .build(); + HttpResponse deleteVirtualGuestResponse = HttpResponse.builder().statusCode(200).build(); + + VirtualGuestApi api = requestSendsResponse(deleteVirtualGuest, deleteVirtualGuestResponse).getVirtualGuestApi(); + assertTrue(api.deleteVirtualGuest(1301396)); + } + + public void testDeleteVirtualGuestWhenResponseIs4xx() { + + HttpRequest deleteVirtualGuest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/deleteObject") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") + .build(); + + HttpResponse deleteVirtualGuestResponse = HttpResponse.builder().statusCode(404).build(); + VirtualGuestApi api = requestSendsResponse(deleteVirtualGuest, deleteVirtualGuestResponse).getVirtualGuestApi(); + assertFalse(api.deleteVirtualGuest(1301396)); + } + + private VirtualGuest createVirtualGuest() { + return VirtualGuest.builder() + .domain("example.com") + .hostname("host1") + .id(1301396) + .maxMemory(1024) + .startCpus(1) + .localDiskFlag(true) + .operatingSystem(OperatingSystem.builder().id("UBUNTU_LATEST") + .operatingSystemReferenceCode("UBUNTU_LATEST") + .build()) + .datacenter(Datacenter.builder().name("test").build()) + .build(); + } + + public void testGetCreateObjectOptionsWhenResponseIs2xx() { + + HttpRequest getVirtualGuest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/getCreateObjectOptions") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse getVirtualGuestResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/container_virtual_guest_configuration.json")).build(); + + SoftLayerApi api = requestSendsResponse(getVirtualGuest, getVirtualGuestResponse); + + assertEquals(api.getVirtualGuestApi().getCreateObjectOptions(), + new GetCreateObjectOptionsResponseTest().expected()); + } + + public void testGetCreateObjectOptionsWhenResponseIs4xx() { + + HttpRequest getObjectRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/getCreateObjectOptions") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse getObjectResponse = HttpResponse.builder().statusCode(404).build(); + SoftLayerApi api = requestSendsResponse(getObjectRequest, getObjectResponse); + assertNull(api.getVirtualGuestApi().getCreateObjectOptions()); + } + + public void testRebootHardVirtualGuestWhenResponseIs2xx() { + + HttpRequest rebootHardVirtualGuest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/rebootHard.json") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse rebootHardVirtualGuestResponse = HttpResponse.builder().statusCode(200).build(); + SoftLayerApi api = requestSendsResponse(rebootHardVirtualGuest, rebootHardVirtualGuestResponse); + api.getVirtualGuestApi().rebootHardVirtualGuest(1301396); + } + + public void testRebootHardVirtualGuestWhenResponseIs4xx() { + + HttpRequest rebootHardVirtualGuest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/rebootHard.json") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse rebootHardVirtualGuestResponse = HttpResponse.builder().statusCode(404).build(); + SoftLayerApi api = requestSendsResponse(rebootHardVirtualGuest, rebootHardVirtualGuestResponse); + api.getVirtualGuestApi().rebootHardVirtualGuest(1301396); + } + + public void testPauseVirtualGuestWhenResponseIs2xx() { + + HttpRequest pauseVirtualGuest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/pause.json") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse pauseVirtualGuestResponse = HttpResponse.builder().statusCode(200).build(); + SoftLayerApi api = requestSendsResponse(pauseVirtualGuest, pauseVirtualGuestResponse); + api.getVirtualGuestApi().pauseVirtualGuest(1301396); + } + + public void testPauseVirtualGuestWhenResponseIs4xx() { + + HttpRequest pauseVirtualGuest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/pause.json") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse pauseVirtualGuestResponse = HttpResponse.builder().statusCode(404).build(); + SoftLayerApi api = requestSendsResponse(pauseVirtualGuest, pauseVirtualGuestResponse); + api.getVirtualGuestApi().pauseVirtualGuest(1301396); + } + + public void testResumeVirtualGuestWhenResponseIs2xx() { + + HttpRequest resumeVirtualGuest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/resume.json") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse resumeVirtualGuestResponse = HttpResponse.builder().statusCode(200).build(); + SoftLayerApi api = requestSendsResponse(resumeVirtualGuest, resumeVirtualGuestResponse); + api.getVirtualGuestApi().resumeVirtualGuest(1301396); + } + + public void testResumeVirtualGuestWhenResponseIs4xx() { + + HttpRequest resumeVirtualGuest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/resume.json") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse resumeVirtualGuestResponse = HttpResponse.builder().statusCode(404).build(); + SoftLayerApi api = requestSendsResponse(resumeVirtualGuest, resumeVirtualGuestResponse); + api.getVirtualGuestApi().resumeVirtualGuest(1301396); + } + + public void testSetTagsOnVirtualGuestWhenResponseIs2xx() { + + HttpRequest setTagsOnVirtualGuest = HttpRequest.builder().method("POST") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/setTags") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") + .payload(payloadFromResourceWithContentType("/virtual_guest_set_tags.json", MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse setTagsOnVirtualGuestResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/virtual_guest_set_tags_response.json")).build(); + + SoftLayerApi api = requestSendsResponse(setTagsOnVirtualGuest, setTagsOnVirtualGuestResponse); + VirtualGuest virtualGuest = createVirtualGuest(); + assertTrue(api.getVirtualGuestApi().setTags(virtualGuest.getId(), ImmutableSet.of("test1", "test2", "test3"))); + } - HttpResponse notFound = HttpResponse.builder().statusCode(404).build(); + public void testSetTagsOnVirtualGuestWhenResponseIs4xx() { - SoftLayerApi clientWhenServiceDoesntExist = requestSendsResponse(cancelGuest11, notFound); - - assert !clientWhenServiceDoesntExist.getVirtualGuestApi().cancelService(11l); + HttpRequest setTagsOnVirtualGuest = HttpRequest.builder().method("POST") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/setTags") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==") + .payload(payloadFromResourceWithContentType("/virtual_guest_set_tags.json", MediaType.APPLICATION_JSON)) + .build(); + HttpResponse setTagsOnVirtualGuestResponse = HttpResponse.builder().statusCode(404).build(); + SoftLayerApi api = requestSendsResponse(setTagsOnVirtualGuest, setTagsOnVirtualGuestResponse); + VirtualGuest virtualGuest = createVirtualGuest(); + assertFalse(api.getVirtualGuestApi().setTags(virtualGuest.getId(), ImmutableSet.of("test1", "test2", "test3"))); } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiLiveTest.java index fb69a7ce15b..81948b568f7 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiLiveTest.java @@ -16,128 +16,148 @@ */ package org.jclouds.softlayer.features; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.capacity; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.categoryCode; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.units; -import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named; +import static com.google.common.base.Preconditions.checkState; +import static org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter.VirtualGuestHasLoginDetailsPresent; +import static org.jclouds.util.Predicates2.retry; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; - -import java.util.Map; import java.util.Properties; -import java.util.Random; import java.util.Set; import org.jclouds.softlayer.SoftLayerApi; -import org.jclouds.softlayer.compute.functions.ProductItems; -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemPrice; -import org.jclouds.softlayer.domain.ProductOrder; -import org.jclouds.softlayer.domain.ProductOrderReceipt; -import org.jclouds.softlayer.domain.ProductPackage; +import org.jclouds.softlayer.domain.ContainerVirtualGuestConfiguration; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.OperatingSystem; +import org.jclouds.softlayer.domain.TagReference; import org.jclouds.softlayer.domain.VirtualGuest; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.base.Predicates; +import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; import com.google.inject.Injector; -import com.google.inject.Key; import com.google.inject.Module; -import com.google.inject.TypeLiteral; /** * Tests behavior of {@code VirtualGuestApi} - * - * @author Adrian Cole */ @Test(groups = "live") public class VirtualGuestApiLiveTest extends BaseSoftLayerApiLiveTest { - private static final String TEST_HOSTNAME_PREFIX = "livetest"; + public static final String DATACENTER = "dal05"; - @Test - public void testListVirtualGuests() throws Exception { - Set response = api().listVirtualGuests(); - assert null != response; - assertTrue(response.size() >= 0); - for (VirtualGuest vg : response) { - VirtualGuest newDetails = api().getVirtualGuest(vg.getId()); - assertEquals(vg.getId(), newDetails.getId()); - checkVirtualGuest(vg); - } - } + private VirtualGuestApi virtualGuestApi; + private Predicate loginDetailsTester; + private VirtualGuestHasLoginDetailsPresent virtualGuestHasLoginDetailsPresent; + private long guestLoginDelay = 60 * 60 * 1000; - @Test(enabled = false, groups = "live") - public void testCancelAndPlaceOrder() { + private VirtualGuest virtualGuest = null; - // This method was not working needs testing out. + @BeforeClass(groups = {"integration", "live"}) + @Override + public void setup() { + super.setup(); + virtualGuestApi = api.getVirtualGuestApi(); + } - // TODO: Should also check if there are active transactions before trying to cancel. - // objectMask: virtualGuests.activeTransaction - for (VirtualGuest guest : api().listVirtualGuests()) { - if (guest.getHostname().startsWith(TEST_HOSTNAME_PREFIX)) { - if (guest.getBillingItemId() != -1) { - api().cancelService(guest.getBillingItemId()); - } - } + @AfterClass(groups = {"integration", "live"}) + protected void tearDownContext() { + if (virtualGuest != null) { + destroyMachine(virtualGuest); + virtualGuest = null; } + } - int pkgId = Iterables.find(api.getAccountApi().getActivePackages(), - named(ProductPackageApiLiveTest.CLOUD_SERVER_PACKAGE_NAME)).getId(); - ProductPackage productPackage = api.getProductPackageApi().getProductPackage(pkgId); - - Iterable ramItems = Iterables.filter(productPackage.getItems(), Predicates.and(categoryCode("ram"), - capacity(2.0f))); - - Map ramToProductItem = Maps.uniqueIndex(ramItems, ProductItems.capacity()); - - ProductItemPrice ramPrice = ProductItems.price().apply(ramToProductItem.get(2.0f)); - - Iterable cpuItems = Iterables.filter(productPackage.getItems(), Predicates.and( - units("PRIVATE_CORE"), capacity(2.0f))); - Map coresToProductItem = Maps.uniqueIndex(cpuItems, ProductItems.capacity()); - - ProductItemPrice cpuPrice = ProductItems.price().apply(coresToProductItem.get(2.0f)); - - Iterable operatingSystems = Iterables.filter(productPackage.getItems(), categoryCode("os")); - Map osToProductItem = Maps.uniqueIndex(operatingSystems, ProductItems.description()); - ProductItemPrice osPrice = ProductItems.price().apply( - osToProductItem.get("Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)")); - - Builder prices = ImmutableSet.builder(); - prices.addAll(defaultPrices); - prices.add(ramPrice); - prices.add(cpuPrice); - prices.add(osPrice); + @Override + protected SoftLayerApi create(Properties props, Iterable modules) { + Injector injector = newBuilder().modules(modules).overrides(props).buildInjector(); + virtualGuestHasLoginDetailsPresent = injector.getInstance(VirtualGuestHasLoginDetailsPresent.class); + loginDetailsTester = retry(virtualGuestHasLoginDetailsPresent, guestLoginDelay); + return injector.getInstance(SoftLayerApi.class); + } - VirtualGuest guest = VirtualGuest.builder().domain("jclouds.org").hostname( - TEST_HOSTNAME_PREFIX + new Random().nextInt()).build(); + @Test + public void testGetCreateObjectOptions() { + ContainerVirtualGuestConfiguration configurationOption = api().getCreateObjectOptions(); + assertNotNull(configurationOption); + } - ProductOrder order = ProductOrder.builder().packageId(pkgId).quantity(1).useHourlyPricing(true).prices( - prices.build()).virtualGuests(guest).build(); + @Test + public void testCreateVirtualGuest() throws Exception { + VirtualGuest virtualGuestRequest = VirtualGuest.builder() + .domain("jclouds.org") + .hostname("virtualGuestApiLiveTest") + .startCpus(1) + .maxMemory(1024) + .operatingSystem(OperatingSystem.builder().id("CENTOS_6_64").operatingSystemReferenceCode("CENTOS_6_64").build()) + .datacenter(Datacenter.builder().name(DATACENTER).build()) + .build(); + + virtualGuest = virtualGuestApi.createVirtualGuest(virtualGuestRequest); + boolean orderInSystem = loginDetailsTester.apply(virtualGuest); + checkState(orderInSystem, "order for guest %s doesn't have login details within %sms", virtualGuest, + Long.toString(guestLoginDelay)); + virtualGuest = virtualGuestApi.getVirtualGuest(virtualGuest.getId()); + checkVirtualGuest(virtualGuest); + assertNotNull(virtualGuest.getPrimaryIpAddress(), "primaryIpAddress must be not null"); + assertNotNull(virtualGuest.getPrimaryBackendIpAddress(), "backendIpAddress must be not null"); + } - ProductOrderReceipt receipt = api().orderVirtualGuest(order); - ProductOrder order2 = receipt.getOrderDetails(); - VirtualGuest result = Iterables.get(order2.getVirtualGuests(), 0); + @Test(dependsOnMethods = "testCreateVirtualGuest") + public void testGetVirtualGuest() throws Exception { + VirtualGuest found = virtualGuestApi.getVirtualGuest(virtualGuest.getId()); + assertEquals(found, virtualGuest); + } - ProductOrder order3 = api().getOrderTemplate(result.getId()); + @Test(dependsOnMethods = "testGetVirtualGuest") + public void testSetTagsOnVirtualGuest() throws Exception { + ImmutableSet tags = ImmutableSet.of("test", "jclouds"); + assertTrue(virtualGuestApi.setTags(virtualGuest.getId(), tags)); + VirtualGuest found = virtualGuestApi.getVirtualGuest(virtualGuest.getId()); + Set tagReferences = found.getTagReferences(); + assertNotNull(tagReferences); + for (String tag : tags) { + Iterables.contains(tagReferences, tag); + } + } - assertEquals(order.getPrices(), order3.getPrices()); - assertNotNull(receipt); + @Test(dependsOnMethods = "testSetTagsOnVirtualGuest") + public void testPauseVirtualGuest() throws Exception { + virtualGuestApi.pauseVirtualGuest(virtualGuest.getId()); + checkState(retry(new Predicate() { + public boolean apply(VirtualGuest guest) { + guest = api().getVirtualGuest(virtualGuest.getId()); + return guest.getPowerState().getKeyName() == VirtualGuest.State.PAUSED; + } + }, 5*60*1000).apply(virtualGuest), "%s still not paused!", virtualGuest); + VirtualGuest found = virtualGuestApi.getVirtualGuest(virtualGuest.getId()); + assertTrue(found.getPowerState().getKeyName() == VirtualGuest.State.PAUSED); } - private Iterable defaultPrices; + @Test(dependsOnMethods = "testPauseVirtualGuest") + public void testResumeVirtualGuest() throws Exception { + virtualGuestApi.resumeVirtualGuest(virtualGuest.getId()); + checkState(retry(new Predicate() { + public boolean apply(VirtualGuest guest) { + guest = api().getVirtualGuest(virtualGuest.getId()); + return guest.getPowerState().getKeyName() == VirtualGuest.State.RUNNING; + } + }, 5*60*1000).apply(virtualGuest), "%s still not running!", virtualGuest); + VirtualGuest found = virtualGuestApi.getVirtualGuest(virtualGuest.getId()); + assertTrue(found.getPowerState().getKeyName() == VirtualGuest.State.RUNNING); + } - @Override - protected SoftLayerApi create(Properties props, Iterable modules) { - Injector injector = newBuilder().modules(modules).overrides(props).buildInjector(); - defaultPrices = injector.getInstance(Key.get(new TypeLiteral>() { - })); - return injector.getInstance(SoftLayerApi.class); + private void destroyMachine(final VirtualGuest virtualGuest) { + checkState(retry(new Predicate() { + public boolean apply(VirtualGuest guest) { + guest = api().getVirtualGuest(virtualGuest.getId()); + return guest.getActiveTransactionCount() == 0; + } + }, 5*60*1000).apply(virtualGuest), "%s still has active transactions!", virtualGuest); + assertTrue(api().deleteVirtualGuest(virtualGuest.getId())); } private VirtualGuestApi api() { @@ -145,25 +165,15 @@ private VirtualGuestApi api() { } private void checkVirtualGuest(VirtualGuest vg) { - if (vg.getBillingItemId() == -1) - return;// Quotes and shutting down guests - - assert vg.getAccountId() > 0 : vg; - assert vg.getCreateDate() != null : vg; - assert vg.getDomain() != null : vg; - assert vg.getFullyQualifiedDomainName() != null : vg; - assert vg.getHostname() != null : vg; - assert vg.getId() > 0 : vg; - assert vg.getMaxCpu() > 0 : vg; - assert vg.getMaxCpuUnits() != null : vg; - assert vg.getMaxMemory() > 0 : vg; - assert vg.getMetricPollDate() != null : vg; - assert vg.getModifyDate() != null : vg; - assert vg.getStartCpus() > 0 : vg; - assert vg.getStatusId() >= 0 : vg; - assert vg.getUuid() != null : vg; - assert vg.getPrimaryBackendIpAddress() != null : vg; - assert vg.getPrimaryIpAddress() != null : vg; + if (vg.getActiveTransactionCount() == 0) { + assertNotNull(vg.getDomain(), "domain must be not null"); + assertNotNull(vg.getFullyQualifiedDomainName(), "fullyQualifiedDomainName must be not null"); + assertNotNull(vg.getHostname(), "hostname must be not null"); + assertTrue(vg.getId() > 0, "id must be greater than 0"); + assertTrue(vg.getMaxCpu() > 0, "maxCpu must be greater than 0"); + assertTrue(vg.getMaxMemory() > 0, "maxMemory must be greater than 0"); + assertTrue(vg.getStatusId() > 0, "statusId must be greater than 0"); + } } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiTest.java deleted file mode 100644 index 499c0181d5b..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiTest.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.features; - -import static org.jclouds.reflect.Reflection2.method; - -import java.io.IOException; - -import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404; -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.Fallbacks.VoidOnNotFoundOr404; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.http.functions.ReleasePayloadAndReturn; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.reflect.Invokable; -/** - * Tests annotation parsing of {@code VirtualGuestApi} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class VirtualGuestApiTest extends BaseSoftLayerApiTest { - - public void testListVirtualGuests() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(VirtualGuestApi.class, "listVirtualGuests"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals( - httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json?objectMask=virtualGuests.powerState%3BvirtualGuests.networkVlans%3BvirtualGuests.operatingSystem.passwords%3BvirtualGuests.datacenter%3BvirtualGuests.billingItem HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - // now make sure request filters apply by replaying - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - - assertRequestLineEquals( - httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json?objectMask=virtualGuests.powerState%3BvirtualGuests.networkVlans%3BvirtualGuests.operatingSystem.passwords%3BvirtualGuests.datacenter%3BvirtualGuests.billingItem HTTP/1.1"); - // for example, using basic authentication, we should get "only one" - // header - assertNonPayloadHeadersEqual(httpRequest, - "Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ParseJson.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testGetVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(VirtualGuestApi.class, "getVirtualGuest", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList. of(1234)); - - assertRequestLineEquals( - httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234.json?objectMask=powerState%3BnetworkVlans%3BoperatingSystem.passwords%3Bdatacenter%3BbillingItem HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ParseJson.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testRebootHardVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(VirtualGuestApi.class, "rebootHardVirtualGuest", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList. of(1234)); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/rebootHard.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testPowerOffVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(VirtualGuestApi.class, "powerOffVirtualGuest", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList. of(1234)); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/powerOff.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testPowerOnVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(VirtualGuestApi.class, "powerOnVirtualGuest", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList. of(1234)); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/powerOn.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testPauseVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(VirtualGuestApi.class, "pauseVirtualGuest", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList. of(1234)); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/pause.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testResumeVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = method(VirtualGuestApi.class, "resumeVirtualGuest", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList. of(1234)); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/resume.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApiExpectTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApiExpectTest.java new file mode 100644 index 00000000000..ba92f382630 --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApiExpectTest.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.softlayer.SoftLayerApi; +import org.jclouds.softlayer.parse.ListPublicImagesResponseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +@Test(groups = "unit", testName = "VirtualGuestBlockDeviceTemplateGroupApiExpectTest") +public class VirtualGuestBlockDeviceTemplateGroupApiExpectTest extends BaseSoftLayerApiExpectTest { + + public void testListPublicImagesWhenResponseIs2xx() { + + HttpRequest listPublicImagesRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse listPublicImagesResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/virtualGuestBlockDeviceTemplateGroup_public_images.json")).build(); + + SoftLayerApi api = requestSendsResponse(listPublicImagesRequest, listPublicImagesResponse); + + assertEquals(api.getVirtualGuestBlockDeviceTemplateGroupApi().getPublicImages(), + new ListPublicImagesResponseTest().expected()); + } + + public void testListPublicImagesWhenResponseIs4xx() { + + HttpRequest listPublicImagesRequest = HttpRequest.builder().method("GET") + .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); + + HttpResponse listPublicImagesResponse = HttpResponse.builder().statusCode(404).build(); + SoftLayerApi api = requestSendsResponse(listPublicImagesRequest, listPublicImagesResponse); + assertTrue(Iterables.isEmpty(api.getVirtualGuestBlockDeviceTemplateGroupApi().getPublicImages())); + } + + +} diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/predicates/ProductPackagePredicates.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApiLiveTest.java similarity index 52% rename from providers/softlayer/src/main/java/org/jclouds/softlayer/predicates/ProductPackagePredicates.java rename to providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApiLiveTest.java index 30081741bdd..4751cbc17aa 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/predicates/ProductPackagePredicates.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApiLiveTest.java @@ -14,28 +14,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jclouds.softlayer.predicates; +package org.jclouds.softlayer.features; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertNotNull; +import java.util.Set; -import org.jclouds.softlayer.domain.ProductPackage; +import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup; +import org.testng.annotations.Test; -import com.google.common.base.Predicate; +/** + * Tests behavior of {@code VirtualGuestBlockDeviceTemplateGroupApi} + */ +@Test(groups = "live") +public class VirtualGuestBlockDeviceTemplateGroupApiLiveTest extends BaseSoftLayerApiLiveTest { -public class ProductPackagePredicates { + @Test + public void testGetBlockDeviceTemplateGroups() { + Set publicImages = api().getPublicImages(); + assertNotNull(publicImages); + } - /** - * Tests if the product package name equals the packageName - * @param packageName - * @return true if the name is equal, otherwise false. - */ - public static Predicate named(final String packageName) { - return new Predicate() { - public boolean apply(ProductPackage productPackage) { - checkNotNull(productPackage, "productPackage cannot be null"); - return productPackage.getName().equals(packageName); - } - }; + private VirtualGuestBlockDeviceTemplateGroupApi api() { + return api.getVirtualGuestBlockDeviceTemplateGroupApi(); } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/handlers/SoftLayerErrorHandlerTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/handlers/SoftLayerErrorHandlerTest.java index 957a64fd845..a4974822236 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/handlers/SoftLayerErrorHandlerTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/handlers/SoftLayerErrorHandlerTest.java @@ -34,10 +34,6 @@ import com.google.inject.Guice; -/** - * - * @author Adrian Cole - */ @Test(groups = { "unit" }) public class SoftLayerErrorHandlerTest { diff --git a/providers/softlayer/src/main/java/org/jclouds/softlayer/exceptions/SoftLayerOrderItemDuplicateException.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/internal/BaseSoftLayerParseTest.java similarity index 63% rename from providers/softlayer/src/main/java/org/jclouds/softlayer/exceptions/SoftLayerOrderItemDuplicateException.java rename to providers/softlayer/src/test/java/org/jclouds/softlayer/internal/BaseSoftLayerParseTest.java index 859baa50017..a58010c7cb8 100644 --- a/providers/softlayer/src/main/java/org/jclouds/softlayer/exceptions/SoftLayerOrderItemDuplicateException.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/internal/BaseSoftLayerParseTest.java @@ -14,16 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jclouds.softlayer.exceptions; +package org.jclouds.softlayer.internal; -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseException; +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.softlayer.config.SoftLayerParserModule; -public class SoftLayerOrderItemDuplicateException extends HttpResponseException { +import com.google.inject.Guice; +import com.google.inject.Injector; - public SoftLayerOrderItemDuplicateException(HttpCommand command, HttpResponse response, String message) { - super(command, response, message); +public abstract class BaseSoftLayerParseTest extends BaseItemParserTest { + + @Override + protected Injector injector() { + return Guice.createInjector(new GsonModule(), new SoftLayerParserModule()); } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseBadVirtualGuest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/CreateVirtualGuestResponseTest.java similarity index 50% rename from providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseBadVirtualGuest.java rename to providers/softlayer/src/test/java/org/jclouds/softlayer/parse/CreateVirtualGuestResponseTest.java index 26299b37ed9..be1a138c9af 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseBadVirtualGuest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/CreateVirtualGuestResponseTest.java @@ -20,44 +20,41 @@ import javax.ws.rs.core.MediaType; import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.json.BaseItemParserTest; -import org.jclouds.json.config.GsonModule; -import org.jclouds.softlayer.config.SoftLayerParserModule; -import org.jclouds.softlayer.domain.PowerState; import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.internal.BaseSoftLayerParseTest; import org.testng.annotations.Test; -import com.google.inject.Guice; -import com.google.inject.Injector; - /** - * - * @author Adrian Cole + * @author Andrea Turli */ -@Test(groups = "unit", testName = "ParseVirtualGuestWithNoPasswordTest") -public class ParseBadVirtualGuest extends BaseItemParserTest { +@Test(groups = "unit") +public class CreateVirtualGuestResponseTest extends BaseSoftLayerParseTest { @Override public String resource() { - return "/virtual_guest_bad_halted.json"; + return "/virtual_guest_create_response.json"; } @Override @Consumes(MediaType.APPLICATION_JSON) public VirtualGuest expected() { - return VirtualGuest - .builder() - .id(413348).accountId(93750).billingItemId(-1) - .createDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-09-28T01:52:45-08:00")) - .domain("jclouds.org").fullyQualifiedDomainName("foo-ef4.jclouds.org") - .hostname("foo-ef4").maxCpu(0).maxCpuUnits("CORE").maxMemory(256) - .statusId(1001).startCpus(0) - //TODO: maybe powerState can be flattened like billingItemId - .powerState(new PowerState(VirtualGuest.State.HALTED)).build(); - } - - protected Injector injector() { - return Guice.createInjector(new SoftLayerParserModule(), new GsonModule()); + return VirtualGuest.builder() + .accountId(232298) + .createDate(new SimpleDateFormatDateService().iso8601DateParse("2012-11-30T22:28:17.000Z")) + .dedicatedAccountHostOnly(false) + .domain("example.com") + .hostname("host1") + .id(1301396) + .maxCpu(1) + .maxCpuUnits("CORE") + .maxMemory(1024) + .privateNetworkOnly(false) + .startCpus(1) + .privateNetworkOnly(false) + .statusId(1001) + .billingItemId(0) + .operatingSystem(null) + .datacenter(null) + .build(); } - } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetAllObjectsResponseTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetAllObjectsResponseTest.java new file mode 100644 index 00000000000..3a3af172ff3 --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetAllObjectsResponseTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.parse; + +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.softlayer.domain.SoftwareDescription; +import org.jclouds.softlayer.internal.BaseSoftLayerParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * @author Andrea Turli + */ +@Test(groups = "unit") +public class GetAllObjectsResponseTest extends BaseSoftLayerParseTest> { + + @Override + public String resource() { + return "/software_description_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Set expected() { + return ImmutableSet.of( + SoftwareDescription.builder() + .version("6.0-64 LAMP for CCI") + .referenceCode("CENTOS_6_64") + .operatingSystem(1) + .longDescription("CentOS / CentOS / 6.0-64 LAMP for CCI") + .build(), + SoftwareDescription.builder() + .version("WEB 64 bit") + .referenceCode("WIN_2008-WEB-R2_64") + .operatingSystem(1) + .longDescription("Microsoft / Windows 2008 FULL WEB 64 bit R2 / WEB 64 bit") + .build(), + SoftwareDescription.builder() + .version("12.04-32 Minimal for CCI") + .referenceCode("UBUNTU_12_32") + .operatingSystem(1) + .longDescription("Ubuntu / Ubuntu / 12.04-32 Minimal for CCI") + .build() + ); + } +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetCreateObjectOptionsResponseTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetCreateObjectOptionsResponseTest.java new file mode 100644 index 00000000000..3e488bd445b --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetCreateObjectOptionsResponseTest.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.parse; + +import org.jclouds.softlayer.domain.ContainerVirtualGuestConfiguration; +import org.jclouds.softlayer.domain.ContainerVirtualGuestConfigurationOption; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.ProductItem; +import org.jclouds.softlayer.domain.ProductItemPrice; +import org.jclouds.softlayer.domain.VirtualDiskImage; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.domain.VirtualGuestBlockDevice; +import org.jclouds.softlayer.domain.VirtualGuestNetworkComponent; +import org.jclouds.softlayer.internal.BaseSoftLayerParseTest; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +/** + * @author Andrea Turli + */ +public class GetCreateObjectOptionsResponseTest extends BaseSoftLayerParseTest { + + @Override + public String resource() { + return "/container_virtual_guest_configuration.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ContainerVirtualGuestConfiguration expected() { + return ContainerVirtualGuestConfiguration.builder() + .blockDevices(ContainerVirtualGuestConfigurationOption.builder() + .productItemPrice(ProductItemPrice.builder() + .hourlyRecurringFee(0) + .recurringFee("0") + .item(ProductItem.builder().description("25 GB (SAN)").build()) + .build()) + .template(VirtualGuest.builder() + .blockDevices(VirtualGuestBlockDevice.builder() + .device("0") + .diskImage(VirtualDiskImage.builder().capacity(25).build()) + .build()) + .localDiskFlag(false) + .build()) + .build()) + .datacenters(ContainerVirtualGuestConfigurationOption.builder() + .template(VirtualGuest.builder().datacenter(Datacenter.builder().name("ams01").build()).build()) + .build()) + .memory(ContainerVirtualGuestConfigurationOption.builder() + .productItemPrice(ProductItemPrice.builder() + .hourlyRecurringFee(.02f) + .recurringFee("14") + .item(ProductItem.builder().description("1 GB").build()) + .build()) + .template(VirtualGuest.builder().maxMemory(1024).build()) + .build()) + .networkComponents(ContainerVirtualGuestConfigurationOption.builder() + .productItemPrice(ProductItemPrice.builder() + .hourlyRecurringFee(0) + .recurringFee("0") + .item(ProductItem.builder().description("10 Mbps Public & Private Networks").build()) + .build()) + .template(VirtualGuest.builder().networkComponents( + VirtualGuestNetworkComponent.builder() + .maxSpeed(10) + .build()) + .build()) + .build()) + .operatingSystems(ContainerVirtualGuestConfigurationOption.builder() + .productItemPrice(ProductItemPrice.builder() + .hourlyRecurringFee(0) + .recurringFee("0") + .item(ProductItem.builder().description("CentOS 6.x - Minimal Install (64 bit)").build()) + .build()) + .template(VirtualGuest.builder() + .operatingSystemReferenceCode("CENTOS_6_64") + .build()) + .build()) + .processors(ContainerVirtualGuestConfigurationOption.builder() + .productItemPrice(ProductItemPrice.builder() + .hourlyRecurringFee(.022f) + .recurringFee("15") + .item(ProductItem.builder().description("1 x 2.0 GHz Core").build()) + .build()) + .template(VirtualGuest.builder().startCpus(1).build()) + .build()) + .build(); + } + +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetDatacenterResponseTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetDatacenterResponseTest.java new file mode 100644 index 00000000000..6678d436536 --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetDatacenterResponseTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.parse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.softlayer.domain.Address; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.Region; +import org.jclouds.softlayer.internal.BaseSoftLayerParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * @author Andrea Turli + */ +@Test(groups = "unit") +public class GetDatacenterResponseTest extends BaseSoftLayerParseTest { + + @Override + public String resource() { + return "/datacenter_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Datacenter expected() { + return Datacenter.builder() + .id(265592) + .longName("Amsterdam 1") + .name("ams01") + .locationAddress(Address.builder() + .address("Paul van Vlissingenstraat 16") + .accountId(1) + .city("Amsterdam") + .contactName("SoftLayer") + .country("NL") + .description("Amsterdam - AMS01") + .id(3322) + .isActive(1) + .locationId(265592) + .postalCode("1096 BK") + .build()) + .regions(ImmutableSet.of(Region.builder().keyname("AMSTERDAM") + .description("AMS01 - Amsterdam - Western Europe") + .build())) + .build(); + } +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetVirtualGuestBlockDeviceTemplateGroupsResponseTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetVirtualGuestBlockDeviceTemplateGroupsResponseTest.java new file mode 100644 index 00000000000..90e20f71335 --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetVirtualGuestBlockDeviceTemplateGroupsResponseTest.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.parse; + +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.softlayer.domain.SoftwareDescription; +import org.jclouds.softlayer.domain.VirtualDiskImage; +import org.jclouds.softlayer.domain.VirtualDiskImageSoftware; +import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplate; +import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup; +import org.jclouds.softlayer.internal.BaseSoftLayerParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * @author Andrea Turli + */ +@Test(groups = "unit") +public class + GetVirtualGuestBlockDeviceTemplateGroupsResponseTest extends + BaseSoftLayerParseTest> { + + @Override + public String resource() { + return "/account_get_block_devices_template_groups.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Set expected() { + return ImmutableSet.of(VirtualGuestBlockDeviceTemplateGroup.builder() + .id(82898) + .name("Backup template for disk migration of 'ljvsilauncher1.scic.ibm.com'.") + .globalIdentifier("e4055a07-13f5-4fa9-ab46-b023b65c47d2") + .statusId(1) + .accountId(278184) + .children(VirtualGuestBlockDeviceTemplateGroup.builder() + .id(82900) + .name("Backup template for disk migration of 'ljvsilauncher1.scic.ibm.com'.") + .statusId(1) + .accountId(278184) + .parentId(82898) + .blockDevices(ImmutableSet.of( + VirtualGuestBlockDeviceTemplate.builder() + .id(108100) + .device("0") + .diskSpace(21832020480f) + .diskImageId(2190750) + .groupId(82900) + .units("B") + .diskImage(VirtualDiskImage.builder() + .id(2190750) + .uuid("42423638-a54e-4d82-9b23-25af5fb13547") + .capacity(25f) + .units("GB") + .typeId(241) + .description("ljvsilauncher1.scic.ibm.com") + .name("ljvsilauncher1.scic.ibm.com") + .storageRepositoryId(906427) + .softwareReferences(ImmutableSet.of( + VirtualDiskImageSoftware.builder() + .id(1498856) + .softwareDescriptionId(1076) + .softwareDescription( + SoftwareDescription.builder() + .id(1076) + .longDescription("Microsoft / Windows 2012 FULL STD 64 bit / STD x64") + .manufacturer("Microsoft") + .name("Windows 2012 FULL STD 64 bit") + .operatingSystem(1) + .referenceCode("WIN_2012-STD_64") + .requiredUser("Administrator") + .version("STD x64") + .controlPanel(0) + .virtualLicense("0") + .virtualizationPlatform("0") + .build()) + .build(), + VirtualDiskImageSoftware.builder() + .id(1498858) + .softwareDescriptionId(106) + .softwareDescription( + SoftwareDescription.builder() + .id(106) + .longDescription("Microsoft / Windows Firewall / 1") + .manufacturer("Microsoft") + .name("Windows Firewall") + .operatingSystem(0) + .version("1") + .controlPanel(0) + .virtualLicense("0") + .virtualizationPlatform("0") + .build()) + .build())) + .build()) + .build(), VirtualGuestBlockDeviceTemplate.builder() + .id(108102) + .device("1") + .diskImageId(2190752) + .groupId(82900) + .diskImage(VirtualDiskImage.builder() + .id(2190752) + .name("3334230-SWAP") + .uuid("9f087bfb-3ed4-4985-a8b7-ac67bd8316e6") + .capacity(2f) + .units("GB") + .typeId(246) + .description("3334230-SWAP") + .storageRepositoryId(906427) + .build()) + .build())) + .build()) + .build()); + } +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetVirtualGuestResponseTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetVirtualGuestResponseTest.java new file mode 100644 index 00000000000..fd754920a07 --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/GetVirtualGuestResponseTest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.parse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.internal.BaseSoftLayerParseTest; +import org.testng.annotations.Test; + +/** + * @author Andrea Turli + */ +@Test(groups = "unit") +public class GetVirtualGuestResponseTest extends BaseSoftLayerParseTest { + + @Override + public String resource() { + return "/virtual_guest_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public VirtualGuest expected() { + return VirtualGuest.builder() + .accountId(278184) + .createDate(new SimpleDateFormatDateService().iso8601DateParse("2013-07-26T14:08:21.552-07:00")) + .dedicatedAccountHostOnly(false) + .domain("test.com") + .fullyQualifiedDomainName("my.test.com") + .hostname("my") + .id(3001812) + .lastVerifiedDate(null) + .maxCpu(1) + .maxCpuUnits("CORE") + .maxMemory(1024) + .metricPollDate(null) + .modifyDate(new SimpleDateFormatDateService().iso8601DateParse("2013-07-26T14:10:21.552-07:00")) + .privateNetworkOnly(false) + .startCpus(1) + .statusId(1001) + .uuid("92102aff-93c9-05f1-b3f2-50787e865344") + .primaryBackendIpAddress("10.32.23.74") + .primaryIpAddress("174.37.252.118") + .billingItemId(0) + .operatingSystem(null) + .datacenter(null) + .powerState(null) + .softwareLicense(null) + .build(); + } +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ListDatacentersResponseTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ListDatacentersResponseTest.java new file mode 100644 index 00000000000..983f1516885 --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ListDatacentersResponseTest.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.parse; + +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.internal.BaseSoftLayerParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * @author Andrea Turli + */ +@Test(groups = "unit") +public class ListDatacentersResponseTest extends BaseSoftLayerParseTest> { + + @Override + public String resource() { + return "/datacenter_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Set expected() { + return ImmutableSet.of( + Datacenter.builder() + .id(265592) + .longName("Amsterdam 1") + .name("ams01") + .build(), + Datacenter.builder() + .id(3) + .longName("Dallas 1") + .name("dal01") + .build(), + Datacenter.builder() + .id(154770) + .longName("Dallas 2") + .name("dal02") + .build(), + Datacenter.builder() + .id(167092) + .longName("Dallas 4") + .name("dal04") + .build(), + Datacenter.builder() + .id(138124) + .longName("Dallas 5") + .name("dal05") + .build(), + Datacenter.builder() + .id(154820) + .longName("Dallas 6") + .name("dal06") + .build(), + Datacenter.builder() + .id(142776) + .longName("Dallas 7") + .name("dal07") + .build(), + Datacenter.builder() + .id(352392) + .longName("Dallas 8") + .name("dal08") + .build(), + Datacenter.builder() + .id(352494) + .longName("Hong Kong 2") + .name("hkg02") + .build(), + Datacenter.builder() + .id(142775) + .longName("Houston 2") + .name("hou02") + .build(), + Datacenter.builder() + .id(168642) + .longName("San Jose 1") + .name("sjc01") + .build(), + Datacenter.builder() + .id(18171) + .longName("Seattle") + .name("sea01") + .build(), + Datacenter.builder() + .id(224092) + .longName("Singapore 1") + .name("sng01") + .build(), + Datacenter.builder() + .id(37473) + .longName("Washington, DC") + .name("wdc01") + .build() + ); + } +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ListPublicImagesResponseTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ListPublicImagesResponseTest.java new file mode 100644 index 00000000000..01857f7d54f --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ListPublicImagesResponseTest.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.parse; + +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.softlayer.domain.SoftwareDescription; +import org.jclouds.softlayer.domain.VirtualDiskImage; +import org.jclouds.softlayer.domain.VirtualDiskImageSoftware; +import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplate; +import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup; +import org.jclouds.softlayer.internal.BaseSoftLayerParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * @author Andrea Turli + */ +@Test(groups = "unit") +public class ListPublicImagesResponseTest extends + BaseSoftLayerParseTest> { + + @Override + public String resource() { + return "/virtualGuestBlockDeviceTemplateGroup_public_images.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Set expected() { + return ImmutableSet.of(VirtualGuestBlockDeviceTemplateGroup.builder() + .id(33352) + .name("25G CentOS 6 32-bit") + .statusId(1) + .accountId(208938) + .parentId(10616) + .blockDevices(ImmutableSet.of( + VirtualGuestBlockDeviceTemplate.builder() + .id(42678) + .device("0") + .diskSpace(2597196288f) + .diskImageId(1692629) + .groupId(33352) + .units("B") + .diskImage(VirtualDiskImage.builder() + .id(1692629) + .uuid("3764c062-43d7-4488-8119-0cf847c3e4db") + .capacity(25f) + .units("GB") + .typeId(241) + .description("25G CentOS 6 32-bit") + .name("25G CentOS 6 32-bit") + .storageRepositoryId(863078) + .softwareReferences( + VirtualDiskImageSoftware.builder() + .id(1227351) + .softwareDescriptionId(885) + .softwareDescription( + SoftwareDescription.builder() + .id(885) + .longDescription("CentOS / CentOS / 6.0-32 Minimal for CCI") + .manufacturer("CentOS") + .name("CentOS") + .operatingSystem(1) + .referenceCode("CENTOS_6_32") + .requiredUser("root") + .version("6.0-32 Minimal for CCI") + .controlPanel(0) + .virtualLicense("0") + .virtualizationPlatform("0") + .build()) + .build()) + .build()) + .build(), VirtualGuestBlockDeviceTemplate.builder() + .id(42679) + .device("1") + .diskImageId(1692630) + .diskSpace(0f) + .groupId(33352) + .diskImage(VirtualDiskImage.builder() + .id(1692630) + .name("10617-SWAP") + .uuid("ae3d12c3-f624-4c3a-80f5-ceeea2259c16") + .capacity(2f) + .units("GB") + .typeId(246) + .description("10617-SWAP") + .storageRepositoryId(863078) + .build()) + .build())) + .build()); + } +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ListVirtualGuestsResponseTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ListVirtualGuestsResponseTest.java new file mode 100644 index 00000000000..8989d59b07a --- /dev/null +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ListVirtualGuestsResponseTest.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.softlayer.parse; + +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.internal.BaseSoftLayerParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * @author Andrea Turli + */ +@Test(groups = "unit") +public class ListVirtualGuestsResponseTest extends BaseSoftLayerParseTest> { + + @Override + public String resource() { + return "/account_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Set expected() { + return ImmutableSet.of( + VirtualGuest.builder() + .accountId(278184) + .createDate(new SimpleDateFormatDateService().iso8601DateParse("2013-07-26T14:08:21.552-07:00")) + .dedicatedAccountHostOnly(false) + .domain("test.com") + .fullyQualifiedDomainName("my.test.com") + .hostname("my") + .id(3001812) + .lastVerifiedDate(null) + .maxCpu(1) + .maxCpuUnits("CORE") + .maxMemory(1024) + .metricPollDate(null) + .modifyDate(new SimpleDateFormatDateService().iso8601DateParse("2013-07-26T14:10:21.552-07:00")) + .privateNetworkOnly(false) + .startCpus(1) + .statusId(1001) + .uuid("92102aff-93c9-05f1-b3f2-50787e865344") + .primaryBackendIpAddress("10.32.23.74") + .primaryIpAddress("174.37.252.118") + .billingItemId(0) + .operatingSystem(null) + .datacenter(null) + .powerState(null) + .softwareLicense(null) + .build()); + } +} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseProductOrderTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseProductOrderTest.java deleted file mode 100644 index 6d58c351eea..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseProductOrderTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.parse; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.util.Set; - -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; - -import org.jclouds.http.HttpResponse; -import org.jclouds.json.BaseItemParserTest; -import org.jclouds.json.config.GsonModule; -import org.jclouds.softlayer.compute.functions.ProductItems; -import org.jclouds.softlayer.config.SoftLayerParserModule; -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemPrice; -import org.jclouds.softlayer.domain.ProductOrder; -import org.jclouds.softlayer.predicates.ProductItemPredicates; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * - * @author Jason King - */ -@Test(groups = "unit", testName = "ParseProductOrderTest") -public class ParseProductOrderTest extends BaseItemParserTest { - - @Override - public String resource() { - return "/product_order_template.json"; - } - - @Override - @Consumes(MediaType.APPLICATION_JSON) - public ProductOrder expected() { - - Set prices = ImmutableSet.builder() - .add(ProductItemPrice.builder().id(1962).itemId(1045).recurringFee(0F).hourlyRecurringFee(0F).build()) - .add(ProductItemPrice.builder().id(1644).itemId(861).recurringFee(0F).hourlyRecurringFee(0F).build()) - .add(ProductItemPrice.builder().id(905).itemId(503).recurringFee(0F).hourlyRecurringFee(0F).build()) - .add(ProductItemPrice.builder().id(274).itemId(188).recurringFee(0F).hourlyRecurringFee(0F).build()) - .add(ProductItemPrice.builder().id(1800).itemId(439).recurringFee(0F).hourlyRecurringFee(0F).build()) - .add(ProductItemPrice.builder().id(21).itemId(15).recurringFee(0F).hourlyRecurringFee(0F).build()) - .add(ProductItemPrice.builder().id(1639).itemId(865).recurringFee(0F).hourlyRecurringFee(0F).build()) - .add(ProductItemPrice.builder().id(1693).itemId(884).recurringFee(0F).hourlyRecurringFee(0F).build()) - .add(ProductItemPrice.builder().id(55).itemId(49).recurringFee(0F).hourlyRecurringFee(0F).build()) - .add(ProductItemPrice.builder().id(57).itemId(51).recurringFee(0F).hourlyRecurringFee(0F).build()) - .add(ProductItemPrice.builder().id(58).itemId(52).recurringFee(0F).hourlyRecurringFee(0F).build()) - .add(ProductItemPrice.builder().id(420).itemId(309).recurringFee(0F).hourlyRecurringFee(0F).build()) - .add(ProductItemPrice.builder().id(418).itemId(307).recurringFee(0F).hourlyRecurringFee(0F).build()) - .build(); - - ProductOrder order = ProductOrder.builder() - .quantity(0) - .packageId(46) - .useHourlyPricing(true) - .prices(prices) - .build(); - - return order; - } - - @Test - public void test() { - ProductOrder expects = expected(); - Function parser = parser(injector()); - ProductOrder response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(payload()).build()); - assertEquals(response,expects); - hasOs(response); - } - - private void hasOs(ProductOrder order) { - Iterable items = Iterables.transform(order.getPrices(), ProductItems.item()); - ProductItem os = Iterables.find(ImmutableSet.copyOf(items), ProductItemPredicates.categoryCode("os")); - assertNotNull(os); - } - - protected Injector injector() { - return Guice.createInjector(new SoftLayerParserModule(), new GsonModule()); - } - -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseVirtualGuestHaltedTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseVirtualGuestHaltedTest.java deleted file mode 100644 index aa719099e49..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseVirtualGuestHaltedTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.parse; - -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; - -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.json.BaseItemParserTest; -import org.jclouds.json.config.GsonModule; -import org.jclouds.softlayer.config.SoftLayerParserModule; -import org.jclouds.softlayer.domain.Datacenter; -import org.jclouds.softlayer.domain.OperatingSystem; -import org.jclouds.softlayer.domain.Password; -import org.jclouds.softlayer.domain.PowerState; -import org.jclouds.softlayer.domain.VirtualGuest; -import org.testng.annotations.Test; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "ParseVirtualGuestWithNoPasswordTest") -public class ParseVirtualGuestHaltedTest extends BaseItemParserTest { - - @Override - public String resource() { - return "/virtual_guest_good_halted.json"; - } - - @Override - @Consumes(MediaType.APPLICATION_JSON) - public VirtualGuest expected() { - return VirtualGuest - .builder() - .id(416700).accountId(93750).billingItemId(7184019) - .createDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-01T11:47:35-08:00")) - .metricPollDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T02:32:00-08:00")) - .dedicatedAccountHostOnly(true).domain("me.org").fullyQualifiedDomainName("node1703810489.me.org") - .hostname("node1703810489").maxCpu(1).maxCpuUnits("CORE").maxMemory(1024) - .modifyDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T03:19:43-08:00")) - .primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001) - .uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8") - .operatingSystem(OperatingSystem.builder().id(913824) - .passwords(Password.builder().id(729122).username("root").password("KnJqhC2l").build()) - .build()) - .datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build()) - //TODO: maybe powerState can be flattened like billingItemId - .powerState(new PowerState(VirtualGuest.State.HALTED)).build(); - } - - protected Injector injector() { - return Guice.createInjector(new SoftLayerParserModule(), new GsonModule()); - } - -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseVirtualGuestPausedTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseVirtualGuestPausedTest.java deleted file mode 100644 index bc5cb514fc5..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseVirtualGuestPausedTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.parse; - -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; - -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.json.BaseItemParserTest; -import org.jclouds.json.config.GsonModule; -import org.jclouds.softlayer.config.SoftLayerParserModule; -import org.jclouds.softlayer.domain.Datacenter; -import org.jclouds.softlayer.domain.OperatingSystem; -import org.jclouds.softlayer.domain.Password; -import org.jclouds.softlayer.domain.PowerState; -import org.jclouds.softlayer.domain.VirtualGuest; -import org.testng.annotations.Test; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "ParseVirtualGuestWithNoPasswordTest") -public class ParseVirtualGuestPausedTest extends BaseItemParserTest { - - @Override - public String resource() { - return "/virtual_guest_paused.json"; - } - - @Override - @Consumes(MediaType.APPLICATION_JSON) - public VirtualGuest expected() { - return VirtualGuest - .builder() - .id(416700).accountId(93750).billingItemId(7184019) - .createDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-01T11:47:35-08:00")) - .metricPollDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T02:32:00-08:00")) - .dedicatedAccountHostOnly(true).domain("me.org").fullyQualifiedDomainName("node1703810489.me.org") - .hostname("node1703810489").maxCpu(1).maxCpuUnits("CORE").maxMemory(1024) - .modifyDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T03:18:12-08:00")) - .primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001) - .uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8") - .operatingSystem(OperatingSystem.builder().id(913824) - .passwords(Password.builder().id(729122).username("root").password("KnJqhC2l").build()) - .build()) - .datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build()) - //TODO: maybe powerState can be flattened like billingItemId - .powerState(new PowerState(VirtualGuest.State.PAUSED)).build(); - } - - protected Injector injector() { - return Guice.createInjector(new SoftLayerParserModule(), new GsonModule()); - } - -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseVirtualGuestRunningTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseVirtualGuestRunningTest.java deleted file mode 100644 index 5ce779a5779..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseVirtualGuestRunningTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.parse; - -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; - -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.json.BaseItemParserTest; -import org.jclouds.json.config.GsonModule; -import org.jclouds.softlayer.config.SoftLayerParserModule; -import org.jclouds.softlayer.domain.Datacenter; -import org.jclouds.softlayer.domain.OperatingSystem; -import org.jclouds.softlayer.domain.Password; -import org.jclouds.softlayer.domain.PowerState; -import org.jclouds.softlayer.domain.VirtualGuest; -import org.testng.annotations.Test; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "ParseVirtualGuestWithNoPasswordTest") -public class ParseVirtualGuestRunningTest extends BaseItemParserTest { - - @Override - public String resource() { - return "/virtual_guest_running.json"; - } - - @Override - @Consumes(MediaType.APPLICATION_JSON) - public VirtualGuest expected() { - return VirtualGuest - .builder() - .id(416700).accountId(93750).billingItemId(7184019) - .createDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-01T11:47:35-08:00")) - .metricPollDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T02:32:00-08:00")) - .dedicatedAccountHostOnly(true).domain("me.org").fullyQualifiedDomainName("node1703810489.me.org") - .hostname("node1703810489").maxCpu(1).maxCpuUnits("CORE").maxMemory(1024) - .modifyDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T02:32:40-08:00")) - .primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001) - .uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8") - .operatingSystem(OperatingSystem.builder().id(913824) - .passwords(Password.builder().id(729122).username("root").password("KnJqhC2l").build()) - .build()) - .datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build()) - //TODO: maybe powerState can be flattened like billingItemId - .powerState(new PowerState(VirtualGuest.State.RUNNING)).build(); - } - - protected Injector injector() { - return Guice.createInjector(new SoftLayerParserModule(), new GsonModule()); - } - -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseVirtualGuestWithNoPasswordTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseVirtualGuestWithNoPasswordTest.java deleted file mode 100644 index 9ff252fd190..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/parse/ParseVirtualGuestWithNoPasswordTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.parse; - -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; - -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.json.BaseItemParserTest; -import org.jclouds.json.config.GsonModule; -import org.jclouds.softlayer.config.SoftLayerParserModule; -import org.jclouds.softlayer.domain.Datacenter; -import org.jclouds.softlayer.domain.OperatingSystem; -import org.jclouds.softlayer.domain.PowerState; -import org.jclouds.softlayer.domain.VirtualGuest; -import org.testng.annotations.Test; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "ParseVirtualGuestWithNoPasswordTest") -public class ParseVirtualGuestWithNoPasswordTest extends BaseItemParserTest { - - @Override - public String resource() { - return "/virtual_guest_no_password.json"; - } - - @Override - @Consumes(MediaType.APPLICATION_JSON) - public VirtualGuest expected() { - return VirtualGuest - .builder() - .id(416788).accountId(93750).billingItemId(7185261) - .createDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T03:24:43-08:00")) - .dedicatedAccountHostOnly(true).domain("me.org").fullyQualifiedDomainName("node1000360500.me.org") - .hostname("node1000360500").maxCpu(1).maxCpuUnits("CORE").maxMemory(1024) - .modifyDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T03:25:33-08:00")) - .primaryBackendIpAddress("10.37.102.194").primaryIpAddress("173.192.29.186").startCpus(1).statusId(1001) - .uuid("96fe22ad-8182-924d-ce51-a037e477dd83") - .operatingSystem(OperatingSystem.builder().id(913960).build()) - .datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build()) - //TODO: maybe powerState can be flattened like billingItemId - .powerState(new PowerState(VirtualGuest.State.HALTED)).build(); - } - - protected Injector injector() { - return Guice.createInjector(new SoftLayerParserModule(), new GsonModule()); - } - -} diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/predicates/ProductItemPredicatesTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/predicates/ProductItemPredicatesTest.java deleted file mode 100644 index 5296479911f..00000000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/predicates/ProductItemPredicatesTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.softlayer.predicates; - -import static org.testng.Assert.assertFalse; - -import java.util.regex.Pattern; - -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemCategory; -import org.testng.annotations.BeforeGroups; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; - -@Test(singleThreaded = true, groups = "unit") -public class ProductItemPredicatesTest { - - private ProductItemCategory ramCategory; - private ProductItem item; - private ProductItem emptyItem; - - @BeforeGroups(groups = { "unit" }) - public void setupContext() { - ramCategory = ProductItemCategory.builder().id(1).categoryCode("ram").build(); - - item = ProductItem.builder().id(1).description("a test item").categories(ImmutableSet.of(ramCategory)).capacity( - 2.0f).units("GB").build(); - - emptyItem = ProductItem.builder().id(1).build(); - } - - @Test - public void testCategoryCodePresent() { - assert ProductItemPredicates.categoryCode("ram").apply(item); - } - - @Test - public void testCategoryCodePresentTwoCategories() { - ProductItemCategory osCategory = ProductItemCategory.builder().id(2).categoryCode("os").build(); - - ProductItem item = ProductItem.builder().categories(ImmutableSet.of(ramCategory, osCategory)).build(); - - assert ProductItemPredicates.categoryCode("ram").apply(item); - } - - @Test - public void testCategoryCodeMissing() { - assertFalse(ProductItemPredicates.categoryCode("missing").apply(emptyItem)); - } - - @Test - public void testCategoryCodeMatches() { - ProductItemPredicates.categoryCodeMatches(Pattern.compile("ra.*")).apply(item); - } - - - @Test - public void testCapacityPresent() { - assert ProductItemPredicates.capacity(2.0f).apply(item); - } - - @Test - public void testCapacityMissing() { - assertFalse(ProductItemPredicates.capacity(1.0f).apply(item)); - } - - @Test - public void testUnitsPresent() { - assert ProductItemPredicates.units("GB").apply(item); - } - - @Test - public void testUnitsMissing() { - assertFalse(ProductItemPredicates.units("Kg").apply(item)); - } - - @Test - public void testMatchesRegex() { - assert ProductItemPredicates.matches(Pattern.compile(".*test.*")).apply(item); - } - - @Test - public void testNoMatchRegex() { - assertFalse(ProductItemPredicates.matches(Pattern.compile("no match")).apply(item)); - } -} diff --git a/providers/softlayer/src/test/resources/account_get_block_devices_template_groups.json b/providers/softlayer/src/test/resources/account_get_block_devices_template_groups.json new file mode 100644 index 00000000000..60fe4b8d45e --- /dev/null +++ b/providers/softlayer/src/test/resources/account_get_block_devices_template_groups.json @@ -0,0 +1,110 @@ +[ + { + "accountId": 278184, + "createDate": "2014-01-30T13:00:23+00:00", + "id": 82898, + "name": "Backup template for disk migration of 'ljvsilauncher1.scic.ibm.com'.", + "note": "This is a backup template for the disk migration of 'ljvsilauncher1.scic.ibm.com' and is not required. This image may be removed at any time.", + "parentId": null, + "statusId": 1, + "transactionId": null, + "userRecordId": null, + "children": [ + { + "accountId": 278184, + "createDate": "2014-01-30T13:00:53+00:00", + "id": 82900, + "name": "Backup template for disk migration of 'ljvsilauncher1.scic.ibm.com'.", + "note": "This is a backup template for the disk migration of 'ljvsilauncher1.scic.ibm.com' and is not required. This image may be removed at any time.", + "parentId": 82898, + "statusId": 1, + "transactionId": null, + "userRecordId": null, + "blockDevices": [ + { + "device": "0", + "diskImageId": 2190750, + "diskSpace": 21832020480, + "groupId": 82900, + "id": 108100, + "units": "B", + "diskImage": { + "capacity": 25, + "checksum": "304a9bce56437af567444567e612506d", + "createDate": "2014-01-30T13:00:53+00:00", + "description": "ljvsilauncher1.scic.ibm.com", + "id": 2190750, + "modifyDate": "2014-01-30T13:14:09+00:00", + "name": "ljvsilauncher1.scic.ibm.com", + "parentId": null, + "storageRepositoryId": 906427, + "typeId": 241, + "units": "GB", + "uuid": "42423638-a54e-4d82-9b23-25af5fb13547", + "softwareReferences": [ + { + "id": 1498856, + "softwareDescriptionId": 1076, + "softwareDescription": { + "controlPanel": 0, + "id": 1076, + "longDescription": "Microsoft / Windows 2012 FULL STD 64 bit / STD x64", + "manufacturer": "Microsoft", + "name": "Windows 2012 FULL STD 64 bit", + "operatingSystem": 1, + "referenceCode": "WIN_2012-STD_64", + "upgradeSoftwareDescriptionId": null, + "upgradeSwDescId": null, + "version": "STD x64", + "virtualLicense": 0, + "virtualizationPlatform": 0, + "requiredUser": "Administrator" + } + }, + { + "id": 1498858, + "softwareDescriptionId": 106, + "softwareDescription": { + "controlPanel": 0, + "id": 106, + "longDescription": "Microsoft / Windows Firewall / 1", + "manufacturer": "Microsoft", + "name": "Windows Firewall", + "operatingSystem": 0, + "upgradeSoftwareDescriptionId": null, + "upgradeSwDescId": null, + "version": "1", + "virtualLicense": 0, + "virtualizationPlatform": 0 + } + } + ] + } + }, + { + "device": "1", + "diskImageId": 2190752, + "groupId": 82900, + "id": 108102, + "diskImage": { + "capacity": 2, + "createDate": "2014-01-30T13:00:58+00:00", + "description": "3334230-SWAP", + "id": 2190752, + "modifyDate": null, + "name": "3334230-SWAP", + "parentId": null, + "storageRepositoryId": 906427, + "typeId": 246, + "units": "GB", + "uuid": "9f087bfb-3ed4-4985-a8b7-ac67bd8316e6", + "softwareReferences": [] + } + } + ], + "children": [] + } + ], + "globalIdentifier": "e4055a07-13f5-4fa9-ab46-b023b65c47d2" + } +] \ No newline at end of file diff --git a/providers/softlayer/src/test/resources/account_list.json b/providers/softlayer/src/test/resources/account_list.json new file mode 100644 index 00000000000..1910e624b83 --- /dev/null +++ b/providers/softlayer/src/test/resources/account_list.json @@ -0,0 +1,24 @@ +[ + { + "primaryIpAddress": "174.37.252.118", + "primaryBackendIpAddress": "10.32.23.74", + "globalIdentifier": "da2b9f87-2319-4a12-91a5-f7f732061dcc", + "uuid": "92102aff-93c9-05f1-b3f2-50787e865344", + "lastPowerStateId": null, + "id": 3001812, + "hostname": "my", + "fullyQualifiedDomainName": "my.test.com", + "domain": "test.com", + "dedicatedAccountHostOnlyFlag": false, + "createDate": "2013-07-26T14:08:21.552-07:00", + "accountId": 278184, + "lastVerifiedDate": null, + "maxCpu": 1, + "maxCpuUnits": "CORE", + "maxMemory": 1024, + "metricPollDate": null, + "modifyDate": "2013-07-26T14:10:21.552-07:00", + "startCpus": 1, + "statusId": 1001 + } +] \ No newline at end of file diff --git a/providers/softlayer/src/test/resources/container_virtual_guest_configuration.json b/providers/softlayer/src/test/resources/container_virtual_guest_configuration.json new file mode 100644 index 00000000000..f517eb7be13 --- /dev/null +++ b/providers/softlayer/src/test/resources/container_virtual_guest_configuration.json @@ -0,0 +1,93 @@ +{ + "blockDevices": [ + { + "itemPrice": { + "hourlyRecurringFee": "0", + "recurringFee": "0", + "item": { + "description": "25 GB (SAN)" + } + }, + "template": { + "blockDevices": [ + { + "device": "0", + "diskImage": { + "capacity": 25 + } + } + ], + "localDiskFlag": false + } + } + ], + "datacenters": [ + { + "template": { + "datacenter": { + "name": "ams01" + } + } + } + ], + "memory": [ + { + "itemPrice": { + "hourlyRecurringFee": ".02", + "recurringFee": "14", + "item": { + "description": "1 GB" + } + }, + "template": { + "maxMemory": 1024 + } + } + ], + "networkComponents": [ + { + "itemPrice": { + "hourlyRecurringFee": "0", + "recurringFee": "0", + "item": { + "description": "10 Mbps Public & Private Networks" + } + }, + "template": { + "networkComponents": [ + { + "maxSpeed": 10 + } + ] + } + } + ], + "operatingSystems": [ + { + "itemPrice": { + "hourlyRecurringFee": "0", + "recurringFee": "0", + "item": { + "description": "CentOS 6.x - Minimal Install (64 bit)" + } + }, + "template": { + "operatingSystemReferenceCode": "CENTOS_6_64" + } + } + ], + "processors": [ + { + "itemPrice": { + "hourlyRecurringFee": ".022", + "recurringFee": "15", + "item": { + "description": "1 x 2.0 GHz Core" + } + }, + "template": { + "startCpus": 1 + } + } + ] +} \ No newline at end of file diff --git a/providers/softlayer/src/test/resources/datacenter_get.json b/providers/softlayer/src/test/resources/datacenter_get.json new file mode 100644 index 00000000000..02eb38c2593 --- /dev/null +++ b/providers/softlayer/src/test/resources/datacenter_get.json @@ -0,0 +1,30 @@ +{ + "id": 265592, + "longName": "Amsterdam 1", + "name": "ams01", + "locationAddress": { + "accountId": 1, + "address1": "Paul van Vlissingenstraat 16", + "city": "Amsterdam", + "contactName": "SoftLayer", + "country": "NL", + "description": "Amsterdam - AMS01", + "id": 3322, + "isActive": 1, + "locationId": 265592, + "postalCode": "1096 BK", + "type": { + "createDate": "2010-04-06T04:49:15+01:00", + "id": 1, + "keyName": "SOFTLAYER_DATACENTER", + "name": "SoftLayer Datacenter (accepts customer DTS shipments)" + } + }, + "regions": [ + { + "description": "AMS01 - Amsterdam - Western Europe", + "keyname": "AMSTERDAM", + "sortOrder": 0 + } + ] +} \ No newline at end of file diff --git a/providers/softlayer/src/test/resources/datacenter_list.json b/providers/softlayer/src/test/resources/datacenter_list.json new file mode 100644 index 00000000000..1ed61f8e364 --- /dev/null +++ b/providers/softlayer/src/test/resources/datacenter_list.json @@ -0,0 +1,72 @@ +[ + { + "id": 265592, + "longName": "Amsterdam 1", + "name": "ams01" + }, + { + "id": 3, + "longName": "Dallas 1", + "name": "dal01" + }, + { + "id": 154770, + "longName": "Dallas 2", + "name": "dal02" + }, + { + "id": 167092, + "longName": "Dallas 4", + "name": "dal04" + }, + { + "id": 138124, + "longName": "Dallas 5", + "name": "dal05" + }, + { + "id": 154820, + "longName": "Dallas 6", + "name": "dal06" + }, + { + "id": 142776, + "longName": "Dallas 7", + "name": "dal07" + }, + { + "id": 352392, + "longName": "Dallas 8", + "name": "dal08" + }, + { + "id": 352494, + "longName": "Hong Kong 2", + "name": "hkg02" + }, + { + "id": 142775, + "longName": "Houston 2", + "name": "hou02" + }, + { + "id": 168642, + "longName": "San Jose 1", + "name": "sjc01" + }, + { + "id": 18171, + "longName": "Seattle", + "name": "sea01" + }, + { + "id": 224092, + "longName": "Singapore 1", + "name": "sng01" + }, + { + "id": 37473, + "longName": "Washington, DC", + "name": "wdc01" + } +] \ No newline at end of file diff --git a/providers/softlayer/src/test/resources/log4j.xml b/providers/softlayer/src/test/resources/log4j.xml deleted file mode 100644 index 63810d3ca09..00000000000 --- a/providers/softlayer/src/test/resources/log4j.xml +++ /dev/null @@ -1,151 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/providers/softlayer/src/test/resources/logback.xml b/providers/softlayer/src/test/resources/logback.xml new file mode 100644 index 00000000000..ea05a2d33c2 --- /dev/null +++ b/providers/softlayer/src/test/resources/logback.xml @@ -0,0 +1,34 @@ + + + + + + - %msg%n + + + + + + + + + + + \ No newline at end of file diff --git a/providers/softlayer/src/test/resources/product_order_template.json b/providers/softlayer/src/test/resources/product_order_template.json deleted file mode 100644 index 0e5bc1c9d29..00000000000 --- a/providers/softlayer/src/test/resources/product_order_template.json +++ /dev/null @@ -1,1337 +0,0 @@ -{"billingOrderItemId":null,"isManagedOrder":null,"itemCategoryQuestionAnswers":[],"packageId":46,"postTaxRecurring":"0","postTaxSetup":"0","preTaxRecurring":"0","preTaxSetup":"0","prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":1962, - "itemId":1045, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":10, - "categories":[ - { - "categoryCode":"guest_core", - "id":80, - "name":"Computing Instance", - "quantityLimit":20, - "questions":[] - } - ], - "item":{ - "capacity":"1", - "description":"Private 1 x 2.0 GHz Core", - "id":1045, - "softwareDescriptionId":null, - "units":"PRIVATE_CORE", - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[], - "conflicts":[], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":".3", - "id":1962, - "itemId":1045, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":10, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"guest_core", - "id":80, - "name":"Computing Instance", - "quantityLimit":20, - "questions":[] - } - ], - "item":null, - "orderPremiums":[ - {} - ] - } - ], - "requirements":[] - }, - "orderPremiums":[ - {} - ] - }, - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":1644, - "itemId":861, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":0, - "categories":[ - { - "categoryCode":"ram", - "id":3, - "name":"Ram", - "quantityLimit":0, - "questions":[] - } - ], - "item":{ - "capacity":"1", - "description":"1 GB", - "id":861, - "softwareDescriptionId":null, - "units":"GB", - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[], - "conflicts":[], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":1644, - "itemId":861, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"ram", - "id":3, - "name":"Ram", - "quantityLimit":0, - "questions":[] - } - ], - "item":null, - "orderPremiums":[] - } - ], - "requirements":[] - }, - "orderPremiums":[] - }, - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":905, - "itemId":503, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":0, - "categories":[ - { - "categoryCode":"remote_management", - "id":46, - "name":"Remote Management", - "quantityLimit":0, - "questions":[] - } - ], - "item":{ - "description":"Reboot \/ Remote Console", - "id":503, - "softwareDescriptionId":null, - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[], - "conflicts":[], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":905, - "itemId":503, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"remote_management", - "id":46, - "name":"Remote Management", - "quantityLimit":0, - "questions":[] - } - ], - "item":null, - "orderPremiums":[] - } - ], - "requirements":[] - }, - "orderPremiums":[] - }, - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":274, - "itemId":188, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":0, - "categories":[ - { - "categoryCode":"port_speed", - "id":26, - "name":"Uplink Port Speeds", - "quantityLimit":0, - "questions":[] - } - ], - "item":{ - "capacity":"1000", - "description":"1000 Mbps Public & Private Networks", - "id":188, - "softwareDescriptionId":null, - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[ - { - "bundleItemId":188, - "id":1607, - "itemPriceId":276, - "category":{ - "categoryCode":"public_port", - "id":8, - "name":"Public Network Port", - "quantityLimit":0 - }, - "itemPrice":{ - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":276, - "itemId":27, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "item":{ - "capacity":"1000", - "description":"1000 Mbps public uplink", - "id":27, - "softwareDescriptionId":null, - "upgradeItemId":null - } - } - }, - { - "bundleItemId":188, - "id":2841, - "itemPriceId":278, - "category":{ - "categoryCode":"service_port", - "id":9, - "name":"Private Network Port", - "quantityLimit":0 - }, - "itemPrice":{ - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":278, - "itemId":48, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "item":{ - "capacity":"1000", - "description":"1000 Mbps private uplink", - "id":48, - "softwareDescriptionId":null, - "upgradeItemId":null - } - } - } - ], - "conflicts":[], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":".04", - "id":274, - "itemId":188, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"port_speed", - "id":26, - "name":"Uplink Port Speeds", - "quantityLimit":0, - "questions":[] - } - ], - "item":null, - "orderPremiums":[] - } - ], - "requirements":[] - }, - "orderPremiums":[] - }, - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":1800, - "itemId":439, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":0, - "categories":[ - { - "categoryCode":"bandwidth", - "id":10, - "name":"Public Bandwidth", - "quantityLimit":0, - "questions":[] - } - ], - "item":{ - "capacity":"0", - "description":"0 GB Bandwidth", - "id":439, - "softwareDescriptionId":null, - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[], - "conflicts":[], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":1800, - "itemId":439, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"bandwidth", - "id":10, - "name":"Public Bandwidth", - "quantityLimit":0, - "questions":[] - } - ], - "item":null, - "orderPremiums":[] - } - ], - "requirements":[] - }, - "orderPremiums":[] - }, - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":21, - "itemId":15, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":0, - "categories":[ - { - "categoryCode":"pri_ip_addresses", - "id":13, - "name":"Primary IP Addresses", - "quantityLimit":0, - "questions":[] - } - ], - "item":{ - "capacity":"1", - "description":"1 IP Address", - "id":15, - "softwareDescriptionId":null, - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[], - "conflicts":[], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":21, - "itemId":15, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"pri_ip_addresses", - "id":13, - "name":"Primary IP Addresses", - "quantityLimit":0, - "questions":[] - } - ], - "item":null, - "orderPremiums":[] - } - ], - "requirements":[] - }, - "orderPremiums":[] - }, - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":1639, - "itemId":865, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":0, - "categories":[ - { - "categoryCode":"guest_disk0", - "id":81, - "name":"First Disk", - "quantityLimit":0, - "questions":[] - } - ], - "item":{ - "capacity":"100", - "description":"100 GB (SAN)", - "id":865, - "softwareDescriptionId":null, - "units":"GB", - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[], - "conflicts":[], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":1639, - "itemId":865, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"guest_disk0", - "id":81, - "name":"First Disk", - "quantityLimit":0, - "questions":[] - } - ], - "item":null, - "orderPremiums":[] - } - ], - "requirements":[] - }, - "orderPremiums":[] - }, - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":1693, - "itemId":884, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":2, - "categories":[ - { - "categoryCode":"os", - "id":12, - "name":"Operating System", - "quantityLimit":0, - "questions":[] - } - ], - "item":{ - "capacity":"0", - "description":"Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)", - "id":884, - "softwareDescriptionId":408, - "units":"N\/A", - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[], - "conflicts":[ - { - "conflictItemId":1198, - "id":26607, - "itemId":884 - }, - { - "conflictItemId":21, - "id":26636, - "itemId":884 - }, - { - "conflictItemId":735, - "id":26673, - "itemId":884 - }, - { - "conflictItemId":779, - "id":26634, - "itemId":884 - }, - { - "conflictItemId":527, - "id":26665, - "itemId":884 - }, - { - "conflictItemId":1199, - "id":26608, - "itemId":884 - }, - { - "conflictItemId":1197, - "id":26606, - "itemId":884 - }, - { - "conflictItemId":145, - "id":26614, - "itemId":884 - }, - { - "conflictItemId":777, - "id":26629, - "itemId":884 - }, - { - "conflictItemId":89, - "id":26639, - "itemId":884 - }, - { - "conflictItemId":758, - "id":26659, - "itemId":884 - }, - { - "conflictItemId":516, - "id":26661, - "itemId":884 - }, - { - "conflictItemId":756, - "id":26671, - "itemId":884 - }, - { - "conflictItemId":764, - "id":26619, - "itemId":884 - }, - { - "conflictItemId":267, - "id":26650, - "itemId":884 - }, - { - "conflictItemId":760, - "id":26664, - "itemId":884 - }, - { - "conflictItemId":1200, - "id":26609, - "itemId":884 - }, - { - "conflictItemId":1201, - "id":26610, - "itemId":884 - }, - { - "conflictItemId":1194, - "id":26611, - "itemId":884 - }, - { - "conflictItemId":928, - "id":26613, - "itemId":884 - }, - { - "conflictItemId":146, - "id":26616, - "itemId":884 - }, - { - "conflictItemId":148, - "id":26617, - "itemId":884 - }, - { - "conflictItemId":763, - "id":26618, - "itemId":884 - }, - { - "conflictItemId":772, - "id":26621, - "itemId":884 - }, - { - "conflictItemId":773, - "id":26622, - "itemId":884 - }, - { - "conflictItemId":766, - "id":26624, - "itemId":884 - }, - { - "conflictItemId":768, - "id":26626, - "itemId":884 - }, - { - "conflictItemId":775, - "id":26627, - "itemId":884 - }, - { - "conflictItemId":776, - "id":26628, - "itemId":884 - }, - { - "conflictItemId":771, - "id":26632, - "itemId":884 - }, - { - "conflictItemId":780, - "id":26635, - "itemId":884 - }, - { - "conflictItemId":85, - "id":26637, - "itemId":884 - }, - { - "conflictItemId":87, - "id":26638, - "itemId":884 - }, - { - "conflictItemId":152, - "id":26641, - "itemId":884 - }, - { - "conflictItemId":88, - "id":26644, - "itemId":884 - }, - { - "conflictItemId":90, - "id":26645, - "itemId":884 - }, - { - "conflictItemId":218, - "id":26646, - "itemId":884 - }, - { - "conflictItemId":212, - "id":26647, - "itemId":884 - }, - { - "conflictItemId":213, - "id":26649, - "itemId":884 - }, - { - "conflictItemId":753, - "id":26652, - "itemId":884 - }, - { - "conflictItemId":525, - "id":26653, - "itemId":884 - }, - { - "conflictItemId":521, - "id":26655, - "itemId":884 - }, - { - "conflictItemId":523, - "id":26658, - "itemId":884 - }, - { - "conflictItemId":754, - "id":26660, - "itemId":884 - }, - { - "conflictItemId":517, - "id":26663, - "itemId":884 - }, - { - "conflictItemId":526, - "id":26666, - "itemId":884 - }, - { - "conflictItemId":757, - "id":26667, - "itemId":884 - }, - { - "conflictItemId":678, - "id":26670, - "itemId":884 - }, - { - "conflictItemId":734, - "id":26672, - "itemId":884 - }, - { - "conflictItemId":140, - "id":26675, - "itemId":884 - }, - { - "conflictItemId":155, - "id":26678, - "itemId":884 - }, - { - "conflictItemId":156, - "id":26679, - "itemId":884 - }, - { - "conflictItemId":365, - "id":26681, - "itemId":884 - }, - { - "conflictItemId":366, - "id":26682, - "itemId":884 - }, - { - "conflictItemId":371, - "id":26683, - "itemId":884 - }, - { - "conflictItemId":367, - "id":26685, - "itemId":884 - }, - { - "conflictItemId":368, - "id":26686, - "itemId":884 - }, - { - "conflictItemId":369, - "id":26687, - "itemId":884 - }, - { - "conflictItemId":505, - "id":26689, - "itemId":884 - }, - { - "conflictItemId":96, - "id":26612, - "itemId":884 - }, - { - "conflictItemId":1192, - "id":26604, - "itemId":884 - }, - { - "conflictItemId":147, - "id":26615, - "itemId":884 - }, - { - "conflictItemId":765, - "id":26620, - "itemId":884 - }, - { - "conflictItemId":774, - "id":26623, - "itemId":884 - }, - { - "conflictItemId":769, - "id":26630, - "itemId":884 - }, - { - "conflictItemId":778, - "id":26633, - "itemId":884 - }, - { - "conflictItemId":151, - "id":26640, - "itemId":884 - }, - { - "conflictItemId":20, - "id":26642, - "itemId":884 - }, - { - "conflictItemId":91, - "id":26643, - "itemId":884 - }, - { - "conflictItemId":211, - "id":26648, - "itemId":884 - }, - { - "conflictItemId":268, - "id":26651, - "itemId":884 - }, - { - "conflictItemId":759, - "id":26656, - "itemId":884 - }, - { - "conflictItemId":524, - "id":26657, - "itemId":884 - }, - { - "conflictItemId":515, - "id":26662, - "itemId":884 - }, - { - "conflictItemId":755, - "id":26668, - "itemId":884 - }, - { - "conflictItemId":677, - "id":26669, - "itemId":884 - }, - { - "conflictItemId":139, - "id":26674, - "itemId":884 - }, - { - "conflictItemId":141, - "id":26676, - "itemId":884 - }, - { - "conflictItemId":142, - "id":26677, - "itemId":884 - }, - { - "conflictItemId":364, - "id":26680, - "itemId":884 - }, - { - "conflictItemId":370, - "id":26684, - "itemId":884 - }, - { - "conflictItemId":506, - "id":26688, - "itemId":884 - }, - { - "conflictItemId":767, - "id":26625, - "itemId":884 - }, - { - "conflictItemId":770, - "id":26631, - "itemId":884 - }, - { - "conflictItemId":1193, - "id":26605, - "itemId":884 - }, - { - "conflictItemId":522, - "id":26654, - "itemId":884 - }, - { - "conflictItemId":1305, - "id":26933, - "itemId":884 - }, - { - "conflictItemId":1306, - "id":27263, - "itemId":884 - } - ], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":1693, - "itemId":884, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":2, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"os", - "id":12, - "name":"Operating System", - "quantityLimit":0, - "questions":[] - } - ], - "item":null, - "orderPremiums":[] - } - ], - "requirements":[], - "softwareDescription":{ - "controlPanel":0, - "id":408, - "manufacturer":"Ubuntu", - "name":"Ubuntu ", - "operatingSystem":1, - "requiredUser":"root", - "upgradeSwDescId":null, - "version":"8.04-64 Minimal for CCI", - "virtualLicense":0, - "virtualizationPlatform":0 - } - }, - "orderPremiums":[] - }, - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":55, - "itemId":49, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":0, - "categories":[ - { - "categoryCode":"monitoring", - "id":20, - "name":"Monitoring", - "quantityLimit":0, - "questions":[] - } - ], - "item":{ - "description":"Host Ping", - "id":49, - "softwareDescriptionId":null, - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[], - "conflicts":[], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":55, - "itemId":49, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"monitoring", - "id":20, - "name":"Monitoring", - "quantityLimit":0, - "questions":[] - } - ], - "item":null, - "orderPremiums":[] - } - ], - "requirements":[] - }, - "orderPremiums":[] - }, - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":57, - "itemId":51, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":0, - "categories":[ - { - "categoryCode":"notification", - "id":21, - "name":"Notification", - "quantityLimit":0, - "questions":[] - } - ], - "item":{ - "description":"Email and Ticket", - "id":51, - "softwareDescriptionId":null, - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[], - "conflicts":[], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":57, - "itemId":51, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"notification", - "id":21, - "name":"Notification", - "quantityLimit":0, - "questions":[] - } - ], - "item":null, - "orderPremiums":[] - } - ], - "requirements":[] - }, - "orderPremiums":[] - }, - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":58, - "itemId":52, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":0, - "categories":[ - { - "categoryCode":"response", - "id":22, - "name":"Response", - "quantityLimit":0, - "questions":[] - } - ], - "item":{ - "description":"Automated Notification", - "id":52, - "softwareDescriptionId":null, - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[], - "conflicts":[], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":58, - "itemId":52, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"response", - "id":22, - "name":"Response", - "quantityLimit":0, - "questions":[] - } - ], - "item":null, - "orderPremiums":[] - } - ], - "requirements":[] - }, - "orderPremiums":[] - }, - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":420, - "itemId":309, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":0, - "categories":[ - { - "categoryCode":"vpn_management", - "id":31, - "name":"VPN Management - Private Network", - "quantityLimit":0, - "questions":[] - } - ], - "item":{ - "description":"Unlimited SSL VPN Users & 1 PPTP VPN User per account", - "id":309, - "softwareDescriptionId":null, - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[], - "conflicts":[], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":420, - "itemId":309, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"vpn_management", - "id":31, - "name":"VPN Management - Private Network", - "quantityLimit":0, - "questions":[] - } - ], - "item":null, - "orderPremiums":[] - } - ], - "requirements":[] - }, - "orderPremiums":[] - }, - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":418, - "itemId":307, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "oneTimeFeeTax":"0", - "proratedRecurringFee":"0", - "proratedRecurringFeeTax":"0", - "recurringFee":"0", - "recurringFeeTax":"0", - "setupFee":"0", - "sort":0, - "categories":[ - { - "categoryCode":"vulnerability_scanner", - "id":32, - "name":"Vulnerability Assessments & Management", - "quantityLimit":0, - "questions":[] - } - ], - "item":{ - "description":"Nessus Vulnerability Assessment & Reporting", - "id":307, - "softwareDescriptionId":null, - "upgradeItemId":null, - "activePresaleEvents":[], - "bundle":[], - "conflicts":[], - "prices":[ - { - "currentPriceFlag":null, - "hourlyRecurringFee":"0", - "id":418, - "itemId":307, - "laborFee":"0", - "onSaleFlag":null, - "oneTimeFee":"0", - "recurringFee":"0", - "setupFee":"0", - "sort":0, - "accountRestrictions":[], - "categories":[ - { - "categoryCode":"vulnerability_scanner", - "id":32, - "name":"Vulnerability Assessments & Management", - "quantityLimit":0, - "questions":[] - } - ], - "item":null, - "orderPremiums":[] - } - ], - "requirements":[] - }, - "orderPremiums":[] - } -],"primaryDiskPartitionId":1,"proratedInitialCharge":"0","proratedOrderTotal":"0","sendQuoteEmailFlag":null,"totalRecurringTax":"0","totalSetupTax":"0","useHourlyPricing":true,"imageTemplateId":null,"sourceVirtualGuestId":null} \ No newline at end of file diff --git a/providers/softlayer/src/test/resources/software_description_list.json b/providers/softlayer/src/test/resources/software_description_list.json new file mode 100644 index 00000000000..95a3979ad82 --- /dev/null +++ b/providers/softlayer/src/test/resources/software_description_list.json @@ -0,0 +1,21 @@ +[ + { + "version": "6.0-64 LAMP for CCI", + "referenceCode": "CENTOS_6_64", + "operatingSystem": 1, + "longDescription": "CentOS / CentOS / 6.0-64 LAMP for CCI" + }, + + { + "version": "WEB 64 bit", + "referenceCode": "WIN_2008-WEB-R2_64", + "operatingSystem": 1, + "longDescription": "Microsoft / Windows 2008 FULL WEB 64 bit R2 / WEB 64 bit" + }, + { + "version": "12.04-32 Minimal for CCI", + "referenceCode": "UBUNTU_12_32", + "operatingSystem": 1, + "longDescription": "Ubuntu / Ubuntu / 12.04-32 Minimal for CCI" + }, +] diff --git a/providers/softlayer/src/test/resources/virtualGuestBlockDeviceTemplateGroup_public_images.json b/providers/softlayer/src/test/resources/virtualGuestBlockDeviceTemplateGroup_public_images.json new file mode 100644 index 00000000000..707d8035ffe --- /dev/null +++ b/providers/softlayer/src/test/resources/virtualGuestBlockDeviceTemplateGroup_public_images.json @@ -0,0 +1,98 @@ +[ +{ + "accountId": 208938, + "createDate": "2013-07-31T11:02:09+01:00", + "id": 33352, + "name": "25G CentOS 6 32-bit", + "parentId": 10616, + "statusId": 1, + "transactionId": null, + "userRecordId": null, + "accountReferences": [], + "blockDevices": [ + { + "device": "0", + "diskImageId": 1692629, + "diskSpace": 2597196288, + "groupId": 33352, + "id": 42678, + "units": "B", + "diskImage": { + "capacity": 25, + "createDate": "2013-07-31T11:02:09+01:00", + "description": "25G CentOS 6 32-bit", + "id": 1692629, + "modifyDate": null, + "name": "25G CentOS 6 32-bit", + "parentId": null, + "storageRepositoryId": 863078, + "typeId": 241, + "units": "GB", + "uuid": "3764c062-43d7-4488-8119-0cf847c3e4db", + "softwareReferences": [ + { + "id": 1227351, + "softwareDescriptionId": 885, + "softwareDescription": { + "controlPanel": 0, + "id": 885, + "longDescription": "CentOS / CentOS / 6.0-32 Minimal for CCI", + "manufacturer": "CentOS", + "name": "CentOS", + "operatingSystem": 1, + "referenceCode": "CENTOS_6_32", + "upgradeSoftwareDescriptionId": null, + "upgradeSwDescId": null, + "version": "6.0-32 Minimal for CCI", + "virtualLicense": 0, + "virtualizationPlatform": 0, + "requiredUser": "root" + } + } + ], + "storageRepository": { + "description": "SL208938 Public", + "id": 863078, + "name": "SL208938 Public", + "publicFlag": 1, + "typeId": 181 + } + } + }, + { + "device": "1", + "diskImageId": 1692630, + "groupId": 33352, + "id": 42679, + "diskImage": { + "capacity": 2, + "createDate": "2013-07-31T11:02:09+01:00", + "description": "10617-SWAP", + "id": 1692630, + "modifyDate": null, + "name": "10617-SWAP", + "parentId": null, + "storageRepositoryId": 863078, + "typeId": 246, + "units": "GB", + "uuid": "ae3d12c3-f624-4c3a-80f5-ceeea2259c16", + "softwareReferences": [], + "storageRepository": { + "description": "SL208938 Public", + "id": 863078, + "name": "SL208938 Public", + "publicFlag": 1, + "typeId": 181 + } + } + } + ], + "storageRepository": { + "description": "SL208938 Public", + "id": 863078, + "name": "SL208938 Public", + "publicFlag": 1, + "typeId": 181 + } +} +] \ No newline at end of file diff --git a/providers/softlayer/src/test/resources/virtual_guest_bad_halted.json b/providers/softlayer/src/test/resources/virtual_guest_bad_halted.json deleted file mode 100644 index 923d4e7d569..00000000000 --- a/providers/softlayer/src/test/resources/virtual_guest_bad_halted.json +++ /dev/null @@ -1,4 +0,0 @@ -{"accountId":93750,"createDate":"2011-09-28T01:52:45-08:00","dedicatedAccountHostOnlyFlag":false,"domain":"jclouds.org","fullyQualifiedDomainName":"foo-ef4.jclouds.org","hostname":"foo-ef4","id":413348,"lastVerifiedDate":null,"maxCpu":null,"maxCpuUnits":"CORE","maxMemory":256,"metricPollDate":null,"modifyDate":null,"privateNetworkOnlyFlag":false,"startCpus":null,"statusId":1001,"globalIdentifier":"9a8b20f0-a758-4c1f-b65b-0e63b791009f","managedResourceFlag":false,"networkVlans":[],"powerState":{ - "keyName":"HALTED", - "name":"Halted" -}} diff --git a/providers/softlayer/src/test/resources/virtual_guest_create.json b/providers/softlayer/src/test/resources/virtual_guest_create.json new file mode 100644 index 00000000000..24625dbfbc9 --- /dev/null +++ b/providers/softlayer/src/test/resources/virtual_guest_create.json @@ -0,0 +1 @@ +{"parameters":[{"hostname":"host1","domain":"example.com","startCpus":1,"maxMemory":1024,"hourlyBillingFlag":true,"operatingSystemReferenceCode":"UBUNTU_LATEST","localDiskFlag":true,"datacenter":{"name":"test"}}]} \ No newline at end of file diff --git a/providers/softlayer/src/test/resources/virtual_guest_create_response.json b/providers/softlayer/src/test/resources/virtual_guest_create_response.json new file mode 100644 index 00000000000..25b0ab40f84 --- /dev/null +++ b/providers/softlayer/src/test/resources/virtual_guest_create_response.json @@ -0,0 +1,19 @@ +{ + "accountId": 232298, + "createDate": "2012-11-30T16:28:17-06:00", + "dedicatedAccountHostOnlyFlag": false, + "domain": "example.com", + "hostname": "host1", + "id": 1301396, + "lastPowerStateId": null, + "lastVerifiedDate": null, + "maxCpu": 1, + "maxCpuUnits": "CORE", + "maxMemory": 1024, + "metricPollDate": null, + "modifyDate": null, + "privateNetworkOnlyFlag": false, + "startCpus": 1, + "statusId": 1001, + "globalIdentifier": "2d203774-0ee1-49f5-9599-6ef67358dd31" +} \ No newline at end of file diff --git a/providers/softlayer/src/test/resources/virtual_guest_get.json b/providers/softlayer/src/test/resources/virtual_guest_get.json new file mode 100644 index 00000000000..1eaa3a8bfaf --- /dev/null +++ b/providers/softlayer/src/test/resources/virtual_guest_get.json @@ -0,0 +1,22 @@ +{ + "primaryIpAddress": "174.37.252.118", + "primaryBackendIpAddress": "10.32.23.74", + "globalIdentifier": "da2b9f87-2319-4a12-91a5-f7f732061dcc", + "uuid": "92102aff-93c9-05f1-b3f2-50787e865344", + "lastPowerStateId": null, + "id": 3001812, + "hostname": "my", + "fullyQualifiedDomainName": "my.test.com", + "domain": "test.com", + "dedicatedAccountHostOnlyFlag": false, + "createDate": "2013-07-26T14:08:21.552-07:00", + "accountId": 278184, + "lastVerifiedDate": null, + "maxCpu": 1, + "maxCpuUnits": "CORE", + "maxMemory": 1024, + "metricPollDate": null, + "modifyDate": "2013-07-26T14:10:21.552-07:00", + "startCpus": 1, + "statusId": 1001 +} \ No newline at end of file diff --git a/providers/softlayer/src/test/resources/virtual_guest_good_halted.json b/providers/softlayer/src/test/resources/virtual_guest_good_halted.json deleted file mode 100644 index 2311387011d..00000000000 --- a/providers/softlayer/src/test/resources/virtual_guest_good_halted.json +++ /dev/null @@ -1,117 +0,0 @@ -{"accountId":93750,"createDate":"2011-10-01T11:47:35-08:00","dedicatedAccountHostOnlyFlag":true,"domain":"me.org","fullyQualifiedDomainName":"node1703810489.me.org","hostname":"node1703810489","id":416700,"lastVerifiedDate":null,"maxCpu":1,"maxCpuUnits":"CORE","maxMemory":1024,"metricPollDate":"2011-10-02T02:32:00-08:00","modifyDate":"2011-10-02T03:19:43-08:00","privateNetworkOnlyFlag":false,"startCpus":1,"statusId":1001,"uuid":"02ddbbba-9225-3d54-6de5-fc603b309dd8","billingItem":{ - "cancellationDate":null, - "categoryCode":"guest_core", - "createDate":"2011-10-01T11:48:10-08:00", - "currentHourlyCharge":"0", - "cycleStartDate":"2011-10-01T11:58:26-08:00", - "description":"Private 1 x 2.0 GHz Core", - "domainName":"me.org", - "hostName":"node1703810489", - "hourlyRecurringFee":"0", - "hoursUsed":"16", - "id":7184019, - "laborFee":"0", - "laborFeeTaxRate":"0", - "lastBillDate":"2011-10-01T11:58:26-08:00", - "modifyDate":"2011-10-01T11:58:26-08:00", - "nextBillDate":"2011-10-17T21:00:00-08:00", - "oneTimeFee":"0", - "oneTimeFeeTaxRate":"0", - "orderItemId":8021579, - "parentId":null, - "recurringFee":"0", - "recurringFeeTaxRate":"0", - "recurringMonths":1, - "serviceProviderId":1, - "setupFee":"0", - "setupFeeTaxRate":"0", - "resourceTableId":416700 -},"datacenter":{ - "id":3, - "longName":"Dallas", - "name":"dal01" -},"globalIdentifier":"0ea2db7f-800d-479a-88e0-8e276e500b80","managedResourceFlag":false,"networkVlans":[ - { - "accountId":93750, - "id":144615, - "modifyDate":"2011-09-30T11:35:27-08:00", - "networkVrfId":null, - "primarySubnetId":171267, - "vlanNumber":1673 - }, - { - "accountId":93750, - "id":144616, - "modifyDate":"2011-09-30T11:35:30-08:00", - "networkVrfId":null, - "primarySubnetId":329652, - "vlanNumber":1622 - } -],"operatingSystem":{ - "hardwareId":null, - "id":913824, - "manufacturerLicenseInstance":"", - "passwords":[ - { - "createDate":"2011-10-01T11:48:52-08:00", - "id":729122, - "modifyDate":"2011-10-01T11:48:52-08:00", - "password":"KnJqhC2l", - "port":null, - "softwareId":913824, - "username":"root", - "software":{ - "hardwareId":null, - "id":913824, - "manufacturerLicenseInstance":"", - "passwords":[ - { - "createDate":"2011-10-01T11:48:52-08:00", - "id":729122, - "modifyDate":"2011-10-01T11:48:52-08:00", - "password":"KnJqhC2l", - "port":null, - "softwareId":913824, - "username":"root", - "software":null - } - ], - "softwareLicense":{ - "id":427, - "softwareDescriptionId":408, - "softwareDescription":{ - "controlPanel":0, - "id":408, - "manufacturer":"Ubuntu", - "name":"Ubuntu ", - "operatingSystem":1, - "requiredUser":"root", - "upgradeSwDescId":null, - "version":"8.04-64 Minimal for CCI", - "virtualLicense":0, - "virtualizationPlatform":0 - } - } - } - } - ], - "softwareLicense":{ - "id":427, - "softwareDescriptionId":408, - "softwareDescription":{ - "controlPanel":0, - "id":408, - "manufacturer":"Ubuntu", - "name":"Ubuntu ", - "operatingSystem":1, - "requiredUser":"root", - "upgradeSwDescId":null, - "version":"8.04-64 Minimal for CCI", - "virtualLicense":0, - "virtualizationPlatform":0 - } - } -},"powerState":{ - "keyName":"HALTED", - "name":"Halted" -},"primaryBackendIpAddress":"10.37.102.195","primaryIpAddress":"173.192.29.187"} diff --git a/providers/softlayer/src/test/resources/virtual_guest_no_password.json b/providers/softlayer/src/test/resources/virtual_guest_no_password.json deleted file mode 100644 index d4c234173ac..00000000000 --- a/providers/softlayer/src/test/resources/virtual_guest_no_password.json +++ /dev/null @@ -1,74 +0,0 @@ -{"accountId":93750,"createDate":"2011-10-02T03:24:43-08:00","dedicatedAccountHostOnlyFlag":true,"domain":"me.org","fullyQualifiedDomainName":"node1000360500.me.org","hostname":"node1000360500","id":416788,"lastVerifiedDate":null,"maxCpu":1,"maxCpuUnits":"CORE","maxMemory":1024,"metricPollDate":null,"modifyDate":"2011-10-02T03:25:33-08:00","privateNetworkOnlyFlag":false,"startCpus":1,"statusId":1001,"uuid":"96fe22ad-8182-924d-ce51-a037e477dd83","billingItem":{ - "cancellationDate":null, - "categoryCode":"guest_core", - "createDate":"2011-10-02T03:25:12-08:00", - "currentHourlyCharge":"0", - "cycleStartDate":"2011-10-02T03:25:12-08:00", - "description":"Private 1 x 2.0 GHz Core", - "domainName":"me.org", - "hostName":"node1000360500", - "hourlyRecurringFee":"0", - "hoursUsed":"1", - "id":7185261, - "laborFee":"0", - "laborFeeTaxRate":"0", - "lastBillDate":"2011-10-02T03:25:12-08:00", - "modifyDate":"2011-10-02T03:25:51-08:00", - "nextBillDate":"2011-10-17T21:00:00-08:00", - "oneTimeFee":"0", - "oneTimeFeeTaxRate":"0", - "orderItemId":8023216, - "parentId":null, - "recurringFee":"0", - "recurringFeeTaxRate":"0", - "recurringMonths":1, - "serviceProviderId":1, - "setupFee":"0", - "setupFeeTaxRate":"0", - "resourceTableId":416788 -},"datacenter":{ - "id":3, - "longName":"Dallas", - "name":"dal01" -},"globalIdentifier":"0a07b4fc-2b3c-4053-9220-55992de14d21","managedResourceFlag":false,"networkVlans":[ - { - "accountId":93750, - "id":144615, - "modifyDate":"2011-09-30T11:35:27-08:00", - "networkVrfId":null, - "primarySubnetId":171267, - "vlanNumber":1673 - }, - { - "accountId":93750, - "id":144616, - "modifyDate":"2011-09-30T11:35:30-08:00", - "networkVrfId":null, - "primarySubnetId":329652, - "vlanNumber":1622 - } -],"operatingSystem":{ - "hardwareId":null, - "id":913960, - "manufacturerLicenseInstance":"", - "passwords":[], - "softwareLicense":{ - "id":427, - "softwareDescriptionId":408, - "softwareDescription":{ - "controlPanel":0, - "id":408, - "manufacturer":"Ubuntu", - "name":"Ubuntu ", - "operatingSystem":1, - "requiredUser":"root", - "upgradeSwDescId":null, - "version":"8.04-64 Minimal for CCI", - "virtualLicense":0, - "virtualizationPlatform":0 - } - } -},"powerState":{ - "keyName":"HALTED", - "name":"Halted" -},"primaryBackendIpAddress":"10.37.102.194","primaryIpAddress":"173.192.29.186"} diff --git a/providers/softlayer/src/test/resources/virtual_guest_paused.json b/providers/softlayer/src/test/resources/virtual_guest_paused.json deleted file mode 100644 index 15d1667194d..00000000000 --- a/providers/softlayer/src/test/resources/virtual_guest_paused.json +++ /dev/null @@ -1,117 +0,0 @@ -{"accountId":93750,"createDate":"2011-10-01T11:47:35-08:00","dedicatedAccountHostOnlyFlag":true,"domain":"me.org","fullyQualifiedDomainName":"node1703810489.me.org","hostname":"node1703810489","id":416700,"lastVerifiedDate":null,"maxCpu":1,"maxCpuUnits":"CORE","maxMemory":1024,"metricPollDate":"2011-10-02T02:32:00-08:00","modifyDate":"2011-10-02T03:18:12-08:00","privateNetworkOnlyFlag":false,"startCpus":1,"statusId":1001,"uuid":"02ddbbba-9225-3d54-6de5-fc603b309dd8","billingItem":{ - "cancellationDate":null, - "categoryCode":"guest_core", - "createDate":"2011-10-01T11:48:10-08:00", - "currentHourlyCharge":"0", - "cycleStartDate":"2011-10-01T11:58:26-08:00", - "description":"Private 1 x 2.0 GHz Core", - "domainName":"me.org", - "hostName":"node1703810489", - "hourlyRecurringFee":"0", - "hoursUsed":"16", - "id":7184019, - "laborFee":"0", - "laborFeeTaxRate":"0", - "lastBillDate":"2011-10-01T11:58:26-08:00", - "modifyDate":"2011-10-01T11:58:26-08:00", - "nextBillDate":"2011-10-17T21:00:00-08:00", - "oneTimeFee":"0", - "oneTimeFeeTaxRate":"0", - "orderItemId":8021579, - "parentId":null, - "recurringFee":"0", - "recurringFeeTaxRate":"0", - "recurringMonths":1, - "serviceProviderId":1, - "setupFee":"0", - "setupFeeTaxRate":"0", - "resourceTableId":416700 -},"datacenter":{ - "id":3, - "longName":"Dallas", - "name":"dal01" -},"globalIdentifier":"0ea2db7f-800d-479a-88e0-8e276e500b80","managedResourceFlag":false,"networkVlans":[ - { - "accountId":93750, - "id":144615, - "modifyDate":"2011-09-30T11:35:27-08:00", - "networkVrfId":null, - "primarySubnetId":171267, - "vlanNumber":1673 - }, - { - "accountId":93750, - "id":144616, - "modifyDate":"2011-09-30T11:35:30-08:00", - "networkVrfId":null, - "primarySubnetId":329652, - "vlanNumber":1622 - } -],"operatingSystem":{ - "hardwareId":null, - "id":913824, - "manufacturerLicenseInstance":"", - "passwords":[ - { - "createDate":"2011-10-01T11:48:52-08:00", - "id":729122, - "modifyDate":"2011-10-01T11:48:52-08:00", - "password":"KnJqhC2l", - "port":null, - "softwareId":913824, - "username":"root", - "software":{ - "hardwareId":null, - "id":913824, - "manufacturerLicenseInstance":"", - "passwords":[ - { - "createDate":"2011-10-01T11:48:52-08:00", - "id":729122, - "modifyDate":"2011-10-01T11:48:52-08:00", - "password":"KnJqhC2l", - "port":null, - "softwareId":913824, - "username":"root", - "software":null - } - ], - "softwareLicense":{ - "id":427, - "softwareDescriptionId":408, - "softwareDescription":{ - "controlPanel":0, - "id":408, - "manufacturer":"Ubuntu", - "name":"Ubuntu ", - "operatingSystem":1, - "requiredUser":"root", - "upgradeSwDescId":null, - "version":"8.04-64 Minimal for CCI", - "virtualLicense":0, - "virtualizationPlatform":0 - } - } - } - } - ], - "softwareLicense":{ - "id":427, - "softwareDescriptionId":408, - "softwareDescription":{ - "controlPanel":0, - "id":408, - "manufacturer":"Ubuntu", - "name":"Ubuntu ", - "operatingSystem":1, - "requiredUser":"root", - "upgradeSwDescId":null, - "version":"8.04-64 Minimal for CCI", - "virtualLicense":0, - "virtualizationPlatform":0 - } - } -},"powerState":{ - "keyName":"PAUSED", - "name":"Paused" -},"primaryBackendIpAddress":"10.37.102.195","primaryIpAddress":"173.192.29.187"} diff --git a/providers/softlayer/src/test/resources/virtual_guest_running.json b/providers/softlayer/src/test/resources/virtual_guest_running.json deleted file mode 100644 index 39731bc3c96..00000000000 --- a/providers/softlayer/src/test/resources/virtual_guest_running.json +++ /dev/null @@ -1,117 +0,0 @@ -{"accountId":93750,"createDate":"2011-10-01T11:47:35-08:00","dedicatedAccountHostOnlyFlag":true,"domain":"me.org","fullyQualifiedDomainName":"node1703810489.me.org","hostname":"node1703810489","id":416700,"lastVerifiedDate":null,"maxCpu":1,"maxCpuUnits":"CORE","maxMemory":1024,"metricPollDate":"2011-10-02T02:32:00-08:00","modifyDate":"2011-10-02T02:32:40-08:00","privateNetworkOnlyFlag":false,"startCpus":1,"statusId":1001,"uuid":"02ddbbba-9225-3d54-6de5-fc603b309dd8","billingItem":{ - "cancellationDate":null, - "categoryCode":"guest_core", - "createDate":"2011-10-01T11:48:10-08:00", - "currentHourlyCharge":"0", - "cycleStartDate":"2011-10-01T11:58:26-08:00", - "description":"Private 1 x 2.0 GHz Core", - "domainName":"me.org", - "hostName":"node1703810489", - "hourlyRecurringFee":"0", - "hoursUsed":"16", - "id":7184019, - "laborFee":"0", - "laborFeeTaxRate":"0", - "lastBillDate":"2011-10-01T11:58:26-08:00", - "modifyDate":"2011-10-01T11:58:26-08:00", - "nextBillDate":"2011-10-17T21:00:00-08:00", - "oneTimeFee":"0", - "oneTimeFeeTaxRate":"0", - "orderItemId":8021579, - "parentId":null, - "recurringFee":"0", - "recurringFeeTaxRate":"0", - "recurringMonths":1, - "serviceProviderId":1, - "setupFee":"0", - "setupFeeTaxRate":"0", - "resourceTableId":416700 -},"datacenter":{ - "id":3, - "longName":"Dallas", - "name":"dal01" -},"globalIdentifier":"0ea2db7f-800d-479a-88e0-8e276e500b80","managedResourceFlag":false,"networkVlans":[ - { - "accountId":93750, - "id":144615, - "modifyDate":"2011-09-30T11:35:27-08:00", - "networkVrfId":null, - "primarySubnetId":171267, - "vlanNumber":1673 - }, - { - "accountId":93750, - "id":144616, - "modifyDate":"2011-09-30T11:35:30-08:00", - "networkVrfId":null, - "primarySubnetId":329652, - "vlanNumber":1622 - } -],"operatingSystem":{ - "hardwareId":null, - "id":913824, - "manufacturerLicenseInstance":"", - "passwords":[ - { - "createDate":"2011-10-01T11:48:52-08:00", - "id":729122, - "modifyDate":"2011-10-01T11:48:52-08:00", - "password":"KnJqhC2l", - "port":null, - "softwareId":913824, - "username":"root", - "software":{ - "hardwareId":null, - "id":913824, - "manufacturerLicenseInstance":"", - "passwords":[ - { - "createDate":"2011-10-01T11:48:52-08:00", - "id":729122, - "modifyDate":"2011-10-01T11:48:52-08:00", - "password":"KnJqhC2l", - "port":null, - "softwareId":913824, - "username":"root", - "software":null - } - ], - "softwareLicense":{ - "id":427, - "softwareDescriptionId":408, - "softwareDescription":{ - "controlPanel":0, - "id":408, - "manufacturer":"Ubuntu", - "name":"Ubuntu ", - "operatingSystem":1, - "requiredUser":"root", - "upgradeSwDescId":null, - "version":"8.04-64 Minimal for CCI", - "virtualLicense":0, - "virtualizationPlatform":0 - } - } - } - } - ], - "softwareLicense":{ - "id":427, - "softwareDescriptionId":408, - "softwareDescription":{ - "controlPanel":0, - "id":408, - "manufacturer":"Ubuntu", - "name":"Ubuntu ", - "operatingSystem":1, - "requiredUser":"root", - "upgradeSwDescId":null, - "version":"8.04-64 Minimal for CCI", - "virtualLicense":0, - "virtualizationPlatform":0 - } - } -},"powerState":{ - "keyName":"RUNNING", - "name":"Running" -},"primaryBackendIpAddress":"10.37.102.195","primaryIpAddress":"173.192.29.187"} diff --git a/providers/softlayer/src/test/resources/virtual_guest_set_tags.json b/providers/softlayer/src/test/resources/virtual_guest_set_tags.json new file mode 100644 index 00000000000..a2541e27b98 --- /dev/null +++ b/providers/softlayer/src/test/resources/virtual_guest_set_tags.json @@ -0,0 +1 @@ +{"parameters":["test1,test2,test3"]} \ No newline at end of file diff --git a/providers/softlayer/src/test/resources/virtual_guest_set_tags_response.json b/providers/softlayer/src/test/resources/virtual_guest_set_tags_response.json new file mode 100644 index 00000000000..e942432aa3f --- /dev/null +++ b/providers/softlayer/src/test/resources/virtual_guest_set_tags_response.json @@ -0,0 +1 @@ +"true" \ No newline at end of file