diff --git a/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudComputeServiceLiveTest.java b/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudComputeServiceLiveTest.java index 359bd9553b..7720f8b5ea 100644 --- a/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudComputeServiceLiveTest.java +++ b/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudComputeServiceLiveTest.java @@ -29,9 +29,15 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.ssh.jsch.config.JschSshClientModule; +import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.domain.NamedResource; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import com.google.common.base.Predicate; +import com.google.common.collect.Maps; + /** * * @@ -80,4 +86,28 @@ public class BlueLockVCloudComputeServiceLiveTest extends BaseComputeServiceLive public void testReboot() throws Exception { super.testReboot(); } + + @Test + public void testExample() throws Exception { + + // get a synchronous object to use for manipulating vcloud objects in BlueLock + VCloudClient bluelockClient = VCloudClient.class.cast(context.getProviderSpecificContext() + .getApi()); + + // look at only vApp templates in my default vDC + Map vAppTemplatesByName = Maps.filterValues(bluelockClient + .getDefaultVDC().getResourceEntities(), new Predicate() { + + @Override + public boolean apply(NamedResource input) { + return input.getType().equals(VCloudMediaType.VAPPTEMPLATE_XML); + } + + }); + + // get details on a specific template I know by name + bluelockClient.getVAppTemplate(vAppTemplatesByName + .get("Ubuntu904Serverx64 1CPUx1GBx20GB a01").getId()); + + } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java index 4f97aa0054..7ce924b896 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -293,44 +293,44 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { @Provides @Singleton protected Map provideImages(final VCloudClient client, - final Location vDC, LogHolder holder, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, + LogHolder holder, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, Function indexer) throws InterruptedException, ExecutionException, TimeoutException { - // TODO multi-VDC final Set images = Sets.newHashSet(); - holder.logger.debug(">> providing images"); - Map resources = client.getDefaultVDC().getResourceEntities(); - Map> responses = Maps.newHashMap(); + holder.logger.debug(">> providing vAppTemplates"); + for (final NamedResource vDC : client.getDefaultOrganization().getVDCs().values()) { + Map resources = client.getVDC(vDC.getId()).getResourceEntities(); + Map> responses = Maps.newHashMap(); - for (final NamedResource resource : resources.values()) { - if (resource.getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) { - responses.put(resource.getName(), ConcurrentUtils.makeListenable(executor - .submit(new Callable() { - @Override - public Void call() throws Exception { - OsFamily myOs = null; - for (OsFamily os : OsFamily.values()) { - if (resource.getName().toLowerCase().replaceAll("\\s", "").indexOf( - os.toString()) != -1) { - myOs = os; + for (final NamedResource resource : resources.values()) { + if (resource.getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) { + responses.put(resource.getName(), ConcurrentUtils.makeListenable(executor + .submit(new Callable() { + @Override + public Void call() throws Exception { + OsFamily myOs = null; + for (OsFamily os : OsFamily.values()) { + if (resource.getName().toLowerCase().replaceAll("\\s", "") + .indexOf(os.toString()) != -1) { + myOs = os; + } } + Architecture arch = resource.getName().indexOf("64") == -1 ? Architecture.X86_32 + : Architecture.X86_64; + VAppTemplate template = client.getVAppTemplate(resource.getId()); + images.add(new ImageImpl(resource.getId(), template.getName(), vDC + .getId(), template.getLocation(), ImmutableMap + . of(), template.getDescription(), "", myOs, + template.getName(), arch)); + return null; } - Architecture arch = resource.getName().indexOf("64") == -1 ? Architecture.X86_32 - : Architecture.X86_64; - VAppTemplate template = client.getVAppTemplate(resource.getId()); - images.add(new ImageImpl(resource.getId(), template.getName(), vDC - .getId(), template.getLocation(), ImmutableMap - . of(), template.getDescription(), "", myOs, - template.getName(), arch)); - return null; - } - }), executor)); + }), executor)); + } } + ConcurrentUtils.awaitCompletion(responses, executor, null, holder.logger, + "vAppTemplates in " + vDC); } - - ConcurrentUtils.awaitCompletion(responses, executor, null, holder.logger, "images"); return Maps.uniqueIndex(images, indexer); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java index b1641080dc..3349f9e61e 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java @@ -136,7 +136,7 @@ public class VCloudComputeClientLiveTest { if (id != null) computeClient.stop(id); } - + @BeforeGroups(groups = { "live" }) public void setupClient() { String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeServiceLiveTest.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeServiceLiveTest.java index 2f26b8fa96..dfd20a8692 100644 --- a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeServiceLiveTest.java +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeServiceLiveTest.java @@ -49,5 +49,24 @@ public class HostingDotComVCloudComputeServiceLiveTest extends BaseComputeServic protected JschSshClientModule getSshModule() { return new JschSshClientModule(); } + +// //Takes too long +// @Override +// @Test(enabled = false) +// public void testCreate() throws Exception { +// super.testCreate(); +// } +// +// @Override +// @Test(enabled = false) +// public void testGet() throws Exception { +// super.testGet(); +// } +// +// @Override +// @Test(enabled = false) +// public void testReboot() throws Exception { +// super.testReboot(); +// } } \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java index 5ca5347c0a..3f72b513c2 100755 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java @@ -19,7 +19,9 @@ package org.jclouds.vcloud.terremark.compute.config; import java.util.Map; +import java.util.Set; import java.util.SortedSet; +import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeoutException; @@ -30,11 +32,20 @@ import org.jclouds.Constants; import org.jclouds.compute.domain.Architecture; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.internal.ImageImpl; import org.jclouds.compute.domain.internal.SizeImpl; +import org.jclouds.concurrent.ConcurrentUtils; import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.compute.VCloudComputeClient; import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeClient; import org.jclouds.vcloud.terremark.domain.ComputeOptions; @@ -45,6 +56,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import com.google.common.util.concurrent.ListenableFuture; /** * Configures the {@link TerremarkVCloudComputeServiceContext}; requires @@ -71,6 +83,56 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer } } + /** + * Terremark does not provide vApp templates in the vDC resourceEntity list. Rather, you must + * query the catalog. + */ + @Override + protected Map provideImages(final VCloudClient client, + LogHolder holder, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, + Function indexer) throws InterruptedException, + ExecutionException, TimeoutException { + final Set images = Sets.newHashSet(); + holder.logger.debug(">> providing vAppTemplates"); + final VDC vDC = client.getDefaultVDC(); + + Catalog response = client.getDefaultCatalog(); + Map> responses = Maps.newHashMap(); + + for (final NamedResource resource : response.values()) { + if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { + final CatalogItem item = client.getCatalogItem(resource.getId()); + if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) { + responses.put(item.getName(), ConcurrentUtils.makeListenable(executor + .submit(new Callable() { + @Override + public Void call() throws Exception { + OsFamily myOs = null; + for (OsFamily os : OsFamily.values()) { + if (resource.getName().toLowerCase().replaceAll("\\s", "") + .indexOf(os.toString()) != -1) { + myOs = os; + } + } + Architecture arch = resource.getName().indexOf("64") == -1 ? Architecture.X86_32 + : Architecture.X86_64; + VAppTemplate template = client.getVAppTemplate(item.getEntity() + .getId()); + images.add(new ImageImpl(resource.getId(), template.getName(), vDC + .getId(), template.getLocation(), ImmutableMap + . of(), template.getDescription(), "", myOs, + template.getName(), arch)); + return null; + } + }), executor)); + } + } + } + ConcurrentUtils.awaitCompletion(responses, executor, null, holder.logger, "vAppTemplates in " + + vDC); + return Maps.uniqueIndex(images, indexer); + } + @Override protected Map provideSizes(Function indexer, VCloudClient client, Map images, LogHolder holder,