From a5abb14d20e3c7d5325c48e40877142edc692975 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 24 May 2010 14:56:59 -0700 Subject: [PATCH] made nullcredentials default and refined usage changing the vcloud api version --- .../compute/internal/TemplateBuilderImpl.java | 4 ++-- ...ateDefaultLoginCredentialsForImageStrategy.java | 4 ++++ .../strategy/impl/ReturnNullCredentials.java | 5 ----- .../BlueLockVCloudComputeServiceContextModule.java | 7 +++++-- .../BlueLockVCloudComputeServiceLiveTest.java | 11 +++++++++++ .../jclouds/vcloud/VCloudPropertiesBuilder.java | 9 ++++++++- .../config/providers/VCloudImageProvider.java | 14 +++++++++----- ...ingDotComVCloudComputeServiceContextModule.java | 3 --- 8 files changed, 39 insertions(+), 18 deletions(-) diff --git a/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java b/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java index 7a8be1d971..e4f96eff69 100644 --- a/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java +++ b/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java @@ -449,7 +449,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { size = sizeOrdering.max(Iterables.filter(sizesThatAreCompatibleWithOurImages, sizePredicate)); } catch (NoSuchElementException exception) { - throw new NoSuchElementException("size didn't match: " + toString() + "\n" + sizes); + throw new NoSuchElementException("size didn't match: " + toString() + "\n" + sizes.get()); } logger.debug("<< matched size(%s)", size); return size; @@ -480,7 +480,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { logger.trace("<< best images(%s)", maxImages); return maxImages; } catch (NoSuchElementException exception) { - throw new NoSuchElementException("image didn't match: " + toString() + "\n" + images); + throw new NoSuchElementException("image didn't match: " + toString() + "\n" + images.get()); } } diff --git a/compute/src/main/java/org/jclouds/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java b/compute/src/main/java/org/jclouds/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java index d512c4f94c..3c17a412f5 100644 --- a/compute/src/main/java/org/jclouds/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java @@ -18,11 +18,15 @@ */ package org.jclouds.compute.strategy; +import org.jclouds.compute.strategy.impl.ReturnNullCredentials; import org.jclouds.domain.Credentials; +import com.google.inject.ImplementedBy; + /** * @author Oleksiy Yarmula */ +@ImplementedBy(ReturnNullCredentials.class) public interface PopulateDefaultLoginCredentialsForImageStrategy { /** diff --git a/compute/src/main/java/org/jclouds/compute/strategy/impl/ReturnNullCredentials.java b/compute/src/main/java/org/jclouds/compute/strategy/impl/ReturnNullCredentials.java index f983f3feb2..68bed2fd9e 100644 --- a/compute/src/main/java/org/jclouds/compute/strategy/impl/ReturnNullCredentials.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/impl/ReturnNullCredentials.java @@ -1,7 +1,5 @@ package org.jclouds.compute.strategy.impl; -import java.util.regex.Pattern; - import javax.inject.Singleton; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; @@ -13,9 +11,6 @@ import org.jclouds.domain.Credentials; @Singleton public class ReturnNullCredentials implements PopulateDefaultLoginCredentialsForImageStrategy { - public static final Pattern USER_PASSWORD_PATTERN = Pattern - .compile(".*[Uu]sername: ([a-z]+) ?.*\n[Pp]assword: ([^ ]+) ?\n.*"); - @Override public Credentials execute(Object resourceToAuthenticate) { return null; diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudComputeServiceContextModule.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudComputeServiceContextModule.java index 929dce4a30..2c00ec9b32 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudComputeServiceContextModule.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudComputeServiceContextModule.java @@ -75,10 +75,13 @@ public class BlueLockVCloudComputeServiceContextModule extends VCloudComputeServ private static class BlueLockVCloudImageProvider extends VCloudImageProvider { @Inject - protected BlueLockVCloudImageProvider(VCloudClient client, + protected BlueLockVCloudImageProvider( + VCloudClient client, FindLocationForResourceInVDC findLocationForResourceInVDC, + PopulateDefaultLoginCredentialsForImageStrategy populateDefaultLoginCredentialsForImageStrategy, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { - super(client, findLocationForResourceInVDC, executor); + super(client, findLocationForResourceInVDC, + populateDefaultLoginCredentialsForImageStrategy, executor); } // Extremely important, as otherwise the size encoded into the name will throw off the 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 d28978f90f..4bcdc81c2e 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 @@ -22,8 +22,10 @@ package org.jclouds.vcloud.bluelock.compute; import static org.testng.Assert.assertEquals; import org.jclouds.compute.domain.Architecture; +import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.http.HttpResponseException; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.compute.VCloudComputeServiceLiveTest; @@ -52,6 +54,15 @@ public class BlueLockVCloudComputeServiceLiveTest extends VCloudComputeServiceLi assertEquals(defaultTemplate.getSize().getCores(), 1.0d); } + @Override + protected Template buildTemplate(TemplateBuilder templateBuilder) { + Template template = super.buildTemplate(templateBuilder); + Image image = template.getImage(); + assert image.getDefaultCredentials().account != null : image; + assert image.getDefaultCredentials().key != null : image; + return template; + } + @Test public void testErrorWhereAllNetworksReturn403() throws Exception { VCloudClient bluelockClient = VCloudClient.class.cast(context.getProviderSpecificContext() diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java index 567e13060b..d1c6d9d108 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java @@ -46,7 +46,6 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8"); properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 8 * 60 + ""); - properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v0.8"); properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); properties.setProperty(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED, "false"); @@ -58,10 +57,18 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder { public VCloudPropertiesBuilder(Properties properties) { super(properties); + setNs(); + } + + private void setNs() { + if (properties.getProperty(PROPERTY_VCLOUD_XML_NAMESPACE) == null) + properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v" + + properties.getProperty(PROPERTY_VCLOUD_VERSION)); } public VCloudPropertiesBuilder(URI endpoint, String id, String secret) { super(); + setNs(); withCredentials(id, secret); withEndpoint(endpoint); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/providers/VCloudImageProvider.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/providers/VCloudImageProvider.java index de0fb7b738..4fe3a364e3 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/providers/VCloudImageProvider.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/providers/VCloudImageProvider.java @@ -35,8 +35,8 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.internal.ImageImpl; import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.concurrent.ConcurrentUtils; -import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.logging.Logger; import org.jclouds.vcloud.VCloudClient; @@ -61,17 +61,19 @@ public class VCloudImageProvider implements Provider> { private final VCloudClient client; private final FindLocationForResourceInVDC findLocationForResourceInVDC; - + private final PopulateDefaultLoginCredentialsForImageStrategy populateDefaultLoginCredentialsForImageStrategy; private final ExecutorService executor; @Inject - protected VCloudImageProvider(VCloudClient client, + protected VCloudImageProvider( + VCloudClient client, FindLocationForResourceInVDC findLocationForResourceInVDC, + PopulateDefaultLoginCredentialsForImageStrategy populateDefaultLoginCredentialsForImageStrategy, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.client = client; this.findLocationForResourceInVDC = findLocationForResourceInVDC; + this.populateDefaultLoginCredentialsForImageStrategy = populateDefaultLoginCredentialsForImageStrategy; this.executor = executor; - } @Override @@ -105,7 +107,9 @@ public class VCloudImageProvider implements Provider> { images.add(new ImageImpl(resource.getId(), name, resource.getId(), location, template.getLocation(), ImmutableMap . of(), template.getDescription(), - "", myOs, name, arch, new Credentials("root", null))); + "", myOs, name, arch, + populateDefaultLoginCredentialsForImageStrategy + .execute(template))); return null; } }), executor)); diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/config/HostingDotComVCloudComputeServiceContextModule.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/config/HostingDotComVCloudComputeServiceContextModule.java index 1903a05736..90e4f49a5a 100755 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/config/HostingDotComVCloudComputeServiceContextModule.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/config/HostingDotComVCloudComputeServiceContextModule.java @@ -21,8 +21,6 @@ package org.jclouds.vcloud.hostingdotcom.compute.config; import static org.jclouds.compute.domain.OsFamily.CENTOS; import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; -import org.jclouds.compute.strategy.impl.ReturnNullCredentials; import org.jclouds.vcloud.compute.VCloudComputeClient; import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule; import org.jclouds.vcloud.hostingdotcom.compute.HostingDotComVCloudComputeClient; @@ -44,7 +42,6 @@ public class HostingDotComVCloudComputeServiceContextModule extends protected void configure() { super.configure(); bind(VCloudComputeClient.class).to(HostingDotComVCloudComputeClient.class); - bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(ReturnNullCredentials.class); } @Override