From 37c4da6489a5bb70c529c3b1bf1385e22e532875 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 16 Sep 2011 17:53:57 -0700 Subject: [PATCH] Issue 158: stubbed in compute service and tested datacenter -> location translation --- sandbox-providers/softlayer/pom.xml | 15 +- .../softlayer/SoftLayerContextBuilder.java | 12 +- .../softlayer/SoftLayerPropertiesBuilder.java | 2 + .../SoftLayerComputeServiceContextModule.java | 70 +++++++++ .../functions/ProductItemPriceToImage.java | 61 ++++++++ .../ProductItemPricesToHardware.java | 48 ++++++ .../functions/VirtualGuestToNodeMetadata.java | 139 ++++++++++++++++++ .../SoftLayerComputeServiceAdapter.java | 129 ++++++++++++++++ .../reference/SoftLayerConstants.java | 32 ++++ .../compute/SoftLayerExperimentLiveTest.java | 72 +++++++++ .../features/BaseSoftLayerClientLiveTest.java | 13 +- 11 files changed, 576 insertions(+), 17 deletions(-) create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPriceToImage.java create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPricesToHardware.java create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadata.java create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java create mode 100644 sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java diff --git a/sandbox-providers/softlayer/pom.xml b/sandbox-providers/softlayer/pom.xml index c204951150..5327ed1298 100644 --- a/sandbox-providers/softlayer/pom.xml +++ b/sandbox-providers/softlayer/pom.xml @@ -56,7 +56,7 @@ org.jclouds - jclouds-core + jclouds-compute ${project.version} @@ -67,9 +67,10 @@ test - log4j - log4j - 1.2.16 + org.jclouds + jclouds-compute + ${project.version} + test-jar test @@ -78,6 +79,12 @@ ${project.version} test + + org.jclouds.driver + jclouds-sshj + ${project.version} + test + diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java index 23f8777f4f..f2b2aaa19f 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java @@ -21,7 +21,8 @@ package org.jclouds.softlayer; import java.util.List; import java.util.Properties; -import org.jclouds.rest.RestContextBuilder; +import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.softlayer.compute.config.SoftLayerComputeServiceContextModule; import org.jclouds.softlayer.config.SoftLayerRestClientModule; import com.google.inject.Module; @@ -30,13 +31,18 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class SoftLayerContextBuilder extends - RestContextBuilder { +public class SoftLayerContextBuilder extends ComputeServiceContextBuilder { public SoftLayerContextBuilder(Properties props) { super(SoftLayerClient.class, SoftLayerAsyncClient.class, props); } + @Override + protected void addContextModule(List modules) { + modules.add(new SoftLayerComputeServiceContextModule()); + } + + @Override protected void addClientModule(List modules) { modules.add(new SoftLayerRestClientModule()); } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerPropertiesBuilder.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerPropertiesBuilder.java index a7c43c428d..b0fd78214b 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerPropertiesBuilder.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerPropertiesBuilder.java @@ -24,6 +24,7 @@ import static org.jclouds.Constants.PROPERTY_ENDPOINT; import java.util.Properties; import org.jclouds.PropertiesBuilder; +import org.jclouds.softlayer.reference.SoftLayerConstants; /** * Builds properties used in SoftLayer Clients @@ -36,6 +37,7 @@ public class SoftLayerPropertiesBuilder extends PropertiesBuilder { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_ENDPOINT, "https://api.softlayer.com/rest"); properties.setProperty(PROPERTY_API_VERSION, "3"); + properties.setProperty(SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME, "Cloud Server"); return properties; } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java new file mode 100644 index 0000000000..575f21a67d --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.config; + +import java.util.Set; + +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.domain.Location; +import org.jclouds.location.suppliers.OnlyLocationOrFirstZone; +import org.jclouds.softlayer.SoftLayerAsyncClient; +import org.jclouds.softlayer.SoftLayerClient; +import org.jclouds.softlayer.compute.functions.DatacenterToLocation; +import org.jclouds.softlayer.compute.functions.ProductItemPriceToImage; +import org.jclouds.softlayer.compute.functions.ProductItemPricesToHardware; +import org.jclouds.softlayer.compute.functions.VirtualGuestToNodeMetadata; +import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.ProductItemPrice; +import org.jclouds.softlayer.domain.VirtualGuest; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +public class SoftLayerComputeServiceContextModule extends + ComputeServiceAdapterContextModule, ProductItemPrice, Datacenter> { + + public SoftLayerComputeServiceContextModule() { + super(SoftLayerClient.class, SoftLayerAsyncClient.class); + } + + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral, ProductItemPrice, Datacenter>>() { + }).to(SoftLayerComputeServiceAdapter.class); + bind(new TypeLiteral>() { + }).to(VirtualGuestToNodeMetadata.class); + bind(new TypeLiteral>() { + }).to(ProductItemPriceToImage.class); + bind(new TypeLiteral, org.jclouds.compute.domain.Hardware>>() { + }).to(ProductItemPricesToHardware.class); + bind(new TypeLiteral>() { + }).to(DatacenterToLocation.class); + bind(new TypeLiteral>() { + }).to(OnlyLocationOrFirstZone.class); + } +} \ No newline at end of file diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPriceToImage.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPriceToImage.java new file mode 100644 index 0000000000..7bf56a6bae --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPriceToImage.java @@ -0,0 +1,61 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.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.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.softlayer.domain.ProductItemPrice; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class ProductItemPriceToImage implements Function { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + @Override + public Image apply(ProductItemPrice from) { + + ImageBuilder builder = new ImageBuilder(); + //TODO +// builder.ids(from.id + ""); +// builder.name(from.name); +// builder.description(from.name); +// +// OsFamily family = null; +// try { +// family = OsFamily.fromValue(from.name); +// builder.operatingSystem(new OperatingSystem.Builder().name(from.name).family(family).build()); +// } catch (IllegalArgumentException e) { +// logger.debug("<< didn't match os(%s)", from); +// } + return builder.build(); + } + +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPricesToHardware.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPricesToHardware.java new file mode 100644 index 0000000000..2b8ba0b0ed --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/ProductItemPricesToHardware.java @@ -0,0 +1,48 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.Set; + +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.softlayer.domain.ProductItemPrice; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class ProductItemPricesToHardware implements Function, Hardware> { + + @Override + public Hardware apply(Set from) { + HardwareBuilder builder = new HardwareBuilder(); +// builder.ids(from.id + ""); +// builder.name(from.name); +// builder.processors(ImmutableList.of(new Processor(from.cores, 1.0))); +// builder.ram(from.ram); +// builder.volumes(ImmutableList. of(new VolumeImpl(from.disk, true, false))); + return builder.build(); + } + +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadata.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadata.java new file mode 100644 index 0000000000..95e4d8fa79 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/functions/VirtualGuestToNodeMetadata.java @@ -0,0 +1,139 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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 org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName; + +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.FindResourceInSet; +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.NodeMetadataBuilder; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.softlayer.domain.VirtualGuest; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * @author Adrian Cole + */ +@Singleton +public class VirtualGuestToNodeMetadata implements Function { + + public static final Map serverStateToNodeState = ImmutableMap + . builder().put(VirtualGuest.State.RUNNING, NodeState.RUNNING)// + .put(VirtualGuest.State.STARTING, NodeState.PENDING)// + .put(VirtualGuest.State.DESTROYED, NodeState.TERMINATED)// + // TODO other states + .put(VirtualGuest.State.UNRECOGNIZED, NodeState.UNRECOGNIZED)// + .build(); + + private final FindHardwareForVirtualGuest findHardwareForVirtualGuest; + private final FindLocationForVirtualGuest findLocationForVirtualGuest; + private final FindImageForVirtualGuest findImageForVirtualGuest; + private final Map credentialStore; + + @Inject + VirtualGuestToNodeMetadata(Map credentialStore, FindHardwareForVirtualGuest findHardwareForVirtualGuest, + FindLocationForVirtualGuest findLocationForVirtualGuest, FindImageForVirtualGuest findImageForVirtualGuest) { + this.credentialStore = checkNotNull(credentialStore, "credentialStore"); + this.findHardwareForVirtualGuest = checkNotNull(findHardwareForVirtualGuest, "findHardwareForVirtualGuest"); + this.findLocationForVirtualGuest = checkNotNull(findLocationForVirtualGuest, "findLocationForVirtualGuest"); + this.findImageForVirtualGuest = checkNotNull(findImageForVirtualGuest, "findImageForVirtualGuest"); + } + + @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.getNotes()); + builder.location(findLocationForVirtualGuest.apply(from)); + builder.group(parseGroupFromName(from.getNotes())); + //TODO determine image id (product price)from virtual guest +// builder.imageId(from.imageId + ""); + Image image = findImageForVirtualGuest.apply(from); + if (image != null) + builder.operatingSystem(image.getOperatingSystem()); + builder.hardware(findHardwareForVirtualGuest.apply(from)); + // TODO get state +// builder.state(serverStateToNodeState.get(from.getState())); + builder.publicAddresses(ImmutableSet. of(from.getPrimaryIpAddress())); + builder.privateAddresses(ImmutableSet. of(from.getPrimaryBackendIpAddress())); + builder.credentials(credentialStore.get("node#"+ from.getId())); + return builder.build(); + } + + @Singleton + public static class FindHardwareForVirtualGuest extends FindResourceInSet { + + @Inject + public FindHardwareForVirtualGuest(@Memoized Supplier> hardware) { + super(hardware); + } + + @Override + public boolean matches(VirtualGuest from, Hardware input) { + return input.getProviderId().equals(from.getId() + ""); + } + } + + @Singleton + public static class FindImageForVirtualGuest extends FindResourceInSet { + + @Inject + public FindImageForVirtualGuest(@Memoized Supplier> hardware) { + super(hardware); + } + + @Override + public boolean matches(VirtualGuest from, Image input) { + // TODO determine the price list from the virtual guest which would have the image in it. + return false; + } + } + + @Singleton + public static class FindLocationForVirtualGuest extends FindResourceInSet { + + @Inject + public FindLocationForVirtualGuest(@Memoized Supplier> hardware) { + super(hardware); + } + + @Override + public boolean matches(VirtualGuest from, Location input) { + // TODO determine the price list from the virtual guest which would have the image in it. + return false; + } + } +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java new file mode 100644 index 0000000000..db1bc6f349 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java @@ -0,0 +1,129 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.domain.Template; +import org.jclouds.domain.Credentials; +import org.jclouds.softlayer.SoftLayerClient; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.ProductItemPrice; +import org.jclouds.softlayer.domain.ProductPackage; +import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.softlayer.predicates.ProductPackagePredicates; +import org.jclouds.softlayer.reference.SoftLayerConstants; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; + +/** + * defines the connection between the {@link SoftLayerClient} implementation and the jclouds + * {@link ComputeService} + * + */ +@Singleton +public class SoftLayerComputeServiceAdapter implements + ComputeServiceAdapter, ProductItemPrice, Datacenter> { + private final SoftLayerClient client; + private final String virtualGuestPackageName; + + @Inject + public SoftLayerComputeServiceAdapter(SoftLayerClient client, + @Named(SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME) String virtualGuestPackageName) { + this.client = checkNotNull(client, "client"); + this.virtualGuestPackageName = checkNotNull(virtualGuestPackageName, "virtualGuestPackageName"); + } + + @Override + public VirtualGuest createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, + Template template, Map credentialStore) { + VirtualGuest from = null; // TODO create the backend object using parameters from the + // template. ex. + // VirtualGuest from = + // client.getVirtualGuestClient().createServerInDC(template.getLocation().getId(), name, + // Long.parseLong(template.getImage().getProviderId()), + // Long.parseLong(template.getHardware().getProviderId())); + // store the credentials so that later functions can use them + // credentialStore.put("node#"+ from.getId() + "", new Credentials(from.loginUser, + // from.password)); + return from; + } + + @Override + public Iterable> listHardwareProfiles() { + // TODO: get the set of product item prices corresponding to the hardware profiles + return ImmutableSet.of(); + } + + @Override + public Iterable listImages() { + // TODO: get the list of product item prices corresponding to images + return ImmutableSet.of(); + } + + @Override + public Iterable listNodes() { + return client.getVirtualGuestClient().listVirtualGuests(); + } + + @Override + public Iterable listLocations() { + // TODO we should be able to specify a filter that gets the datacenters here. + ProductPackage virtualGuestPackage = Iterables.find(client.getAccountClient().getActivePackages(), + ProductPackagePredicates.named(virtualGuestPackageName)); + return client.getProductPackageClient().getProductPackage(virtualGuestPackage.getId()).getDatacenters(); + } + + @Override + public VirtualGuest getNode(String id) { + long serverId = Long.parseLong(id); + return client.getVirtualGuestClient().getVirtualGuest(serverId); + } + + @Override + public void destroyNode(String id) { + // TODO + // client.getVirtualGuestClient().destroyVirtualGuest(Long.parseLong(id)); + } + + @Override + public void rebootNode(String id) { + client.getVirtualGuestClient().rebootHardVirtualGuest(Long.parseLong(id)); + } + + @Override + public void resumeNode(String id) { + client.getVirtualGuestClient().resumeVirtualGuest(Long.parseLong(id)); + } + + @Override + public void suspendNode(String id) { + client.getVirtualGuestClient().pauseVirtualGuest(Long.parseLong(id)); + } +} \ No newline at end of file diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java new file mode 100644 index 0000000000..8640e596a4 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/reference/SoftLayerConstants.java @@ -0,0 +1,32 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.reference; + +/** + * Configuration properties and constants used in SoftLayer connections. + * + * @author Adrian Cole + */ +public interface SoftLayerConstants { + /** + * Name of the product package corresponding to cloud servers + */ + public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME = "jclouds.softlayer.virtualguest.package-name"; + +} diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java new file mode 100644 index 0000000000..6319a8a3d0 --- /dev/null +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerExperimentLiveTest.java @@ -0,0 +1,72 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.softlayer.compute; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertEquals; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.sshj.config.SshjSshClientModule; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "SoftLayerExperimentLiveTest") +public class SoftLayerExperimentLiveTest { + protected String provider = "softlayer"; + protected String identity; + protected String credential; + protected String endpoint; + protected String apiversion; + + @BeforeClass + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); + credential = System.getProperty("test." + provider + ".credential"); + endpoint = System.getProperty("test." + provider + ".endpoint"); + apiversion = System.getProperty("test." + provider + ".apiversion"); + } + + @Test + public void testAndExperiment() { + ComputeServiceContext context = null; + try { + String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity"); + String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential"); + + context = new ComputeServiceContextFactory().createContext("softlayer", identity, credential, ImmutableSet + . of(new Log4JLoggingModule(), new SshjSshClientModule())); + + assertEquals(context.getComputeService().listAssignableLocations().size(), 5); + + } finally { + if (context != null) + context.close(); + } + } + +} \ No newline at end of file diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java index 898daf0551..b1705f53c0 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java @@ -20,15 +20,11 @@ package org.jclouds.softlayer.features; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Properties; - +import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; import org.jclouds.softlayer.SoftLayerAsyncClient; import org.jclouds.softlayer.SoftLayerClient; -import org.jclouds.softlayer.SoftLayerContextBuilder; -import org.jclouds.softlayer.SoftLayerPropertiesBuilder; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -51,12 +47,9 @@ public class BaseSoftLayerClientLiveTest { String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity"); String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential"); - Properties restProperties = new Properties(); - restProperties.setProperty("softlayer.contextbuilder", SoftLayerContextBuilder.class.getName()); - restProperties.setProperty("softlayer.propertiesbuilder", SoftLayerPropertiesBuilder.class.getName()); - context = new RestContextFactory(restProperties).createContext("softlayer", identity, credential, - ImmutableSet. of(new Log4JLoggingModule())); + context = new ComputeServiceContextFactory().createContext("softlayer", identity, credential, + ImmutableSet. of(new Log4JLoggingModule())).getProviderSpecificContext(); }