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 extends Volume> volumes1 = h1.getVolumes();
+ List extends Volume> 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 extends Volume> volumes = hardware.getVolumes();
+ Optional extends Volume> 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