diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java index 6a34b28d5e..dd714a4d0f 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -72,7 +72,7 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod } @Override - protected boolean shouldParseImagesOnDemand(Injector injector) { + protected boolean shouldEagerlyParseImages(Injector injector) { // If no owners to query, then will never lookup all images String[] amiOwners = injector.getInstance(Key.get(String[].class, Names.named(PROPERTY_EC2_AMI_OWNERS))); return (amiOwners.length > 0); diff --git a/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java index a522f13116..da2c3c3cab 100644 --- a/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java @@ -227,14 +227,14 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule { @Memoized protected Supplier> supplyImageCache(AtomicReference authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, final Supplier> imageSupplier, Injector injector) { - if (shouldParseImagesOnDemand(injector)) { + if (shouldEagerlyParseImages(injector)) { return supplyImageCache(authException, seconds, imageSupplier); } else { return supplyNonParsingImageCache(authException, seconds, imageSupplier, injector); } } - protected boolean shouldParseImagesOnDemand(Injector injector) { + protected boolean shouldEagerlyParseImages(Injector injector) { return true; } diff --git a/core/src/main/java/org/jclouds/config/ValueOfConfigurationKeyOrNull.java b/core/src/main/java/org/jclouds/config/ValueOfConfigurationKeyOrNull.java index ab50c64deb..1f6335f272 100644 --- a/core/src/main/java/org/jclouds/config/ValueOfConfigurationKeyOrNull.java +++ b/core/src/main/java/org/jclouds/config/ValueOfConfigurationKeyOrNull.java @@ -19,7 +19,6 @@ package org.jclouds.config; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.emptyToNull; import static com.google.inject.name.Names.named; import javax.inject.Inject; @@ -47,7 +46,7 @@ public class ValueOfConfigurationKeyOrNull implements Function { public String apply(String configurationKey) { checkNotNull(configurationKey, "configurationKey"); try { - return emptyToNull(injector.getInstance(Key.get(String.class, named(configurationKey)))); + return injector.getInstance(Key.get(String.class, named(configurationKey))); } catch (ConfigurationException e) { return null; } diff --git a/core/src/test/java/org/jclouds/config/ValueOfConfigurationKeyOrNullTest.java b/core/src/test/java/org/jclouds/config/ValueOfConfigurationKeyOrNullTest.java index 1af174d9f0..53c8000b82 100644 --- a/core/src/test/java/org/jclouds/config/ValueOfConfigurationKeyOrNullTest.java +++ b/core/src/test/java/org/jclouds/config/ValueOfConfigurationKeyOrNullTest.java @@ -20,8 +20,6 @@ package org.jclouds.config; import static org.testng.Assert.assertEquals; -import java.util.concurrent.ExecutionException; - import org.testng.annotations.Test; import com.google.inject.AbstractModule; @@ -37,12 +35,12 @@ import com.google.inject.name.Names; public class ValueOfConfigurationKeyOrNullTest { @Test - public void testNotThere() throws InterruptedException, ExecutionException { + public void testNotThere() { assertEquals(new ValueOfConfigurationKeyOrNull(Guice.createInjector()).apply("foo"), null); } @Test - public void testThere() throws InterruptedException, ExecutionException { + public void testThere() { assertEquals(new ValueOfConfigurationKeyOrNull(Guice.createInjector(new AbstractModule() { @Override @@ -53,5 +51,17 @@ public class ValueOfConfigurationKeyOrNullTest { })).apply("foo"), "bar"); } + + @Test + public void testEmptyIsThere() { + assertEquals(new ValueOfConfigurationKeyOrNull(Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + bindConstant().annotatedWith(Names.named("foo")).to(""); + } + + })).apply("foo"), ""); + + } } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java index 8431b17c16..86053927bf 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ApiMetadata.java @@ -19,6 +19,7 @@ package org.jclouds.aws.ec2; import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES; +import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; import java.util.Properties; @@ -67,6 +68,7 @@ public class AWSEC2ApiMetadata extends EC2ApiMetadata { public static Properties defaultProperties() { Properties properties = EC2ApiMetadata.defaultProperties(); + properties.remove(PROPERTY_EC2_AMI_OWNERS); // auth fail sometimes happens in EC2, as the rc.local script that injects the // authorized key executes after ssh has started. properties.setProperty("jclouds.ssh.max-retries", "7"); diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java index 07504d4c1e..78c25d8b8f 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java @@ -22,7 +22,6 @@ import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_AMI_QUE import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY; import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_REGIONS; import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED; -import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; import java.net.URI; import java.util.Properties; @@ -63,7 +62,6 @@ public class AWSEC2ProviderMetadata extends BaseProviderMetadata { // from stopping->stopped state on an ec2 micro properties.setProperty(TIMEOUT_NODE_SUSPENDED, 120 * 1000 + ""); properties.putAll(Region.regionProperties()); - properties.remove(PROPERTY_EC2_AMI_OWNERS); // amazon, alestic, canonical, and rightscale properties.setProperty(PROPERTY_EC2_AMI_QUERY, "owner-id=137112412989,063491364108,099720109477,411009282317;state=available;image-type=machine"); diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java index 654078797a..3368d5c120 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java @@ -102,10 +102,11 @@ public class AWSEC2ComputeServiceContextModule extends BaseComputeServiceContext } @Override - protected boolean shouldParseImagesOnDemand(Injector injector) { + protected boolean shouldEagerlyParseImages(Injector injector) { + Map queries = injector.getInstance(Key.get(new TypeLiteral>() { + }, ImageQuery.class)); // If no queries defined, then will never lookup all images - return injector.getInstance(Key.get(new TypeLiteral>() { - }, ImageQuery.class)).size() > 0; + return queries.size() > 0; } // duplicates EC2ComputeServiceContextModule; but that's easiest thing to do with guice; could extract to common util diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java index e62a5c49cd..e9c159ffe0 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java @@ -18,7 +18,8 @@ */ package org.jclouds.aws.ec2.compute.config; -import static org.jclouds.aws.ec2.reference.AWSEC2Constants.*; +import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_AMI_QUERY; +import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY; import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; import java.util.Map; @@ -63,8 +64,8 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Sets; import com.google.common.collect.ImmutableMap.Builder; +import com.google.common.collect.Sets; import com.google.inject.Provides; import com.google.inject.TypeLiteral; import com.google.inject.assistedinject.FactoryModuleBuilder; @@ -100,18 +101,18 @@ public class AWSEC2ComputeServiceDependenciesModule extends EC2ComputeServiceDep @ImageQuery protected Map imageQuery(ValueOfConfigurationKeyOrNull config) { String amiQuery = Strings.emptyToNull(config.apply(PROPERTY_EC2_AMI_QUERY)); - if (config.apply(PROPERTY_EC2_AMI_OWNERS) != null) { + String owners = config.apply(PROPERTY_EC2_AMI_OWNERS); + if ("".equals(owners)) { + amiQuery = null; + } else if (owners != null) { StringBuilder query = new StringBuilder(); - String owners = config.apply(PROPERTY_EC2_AMI_OWNERS).toString(); if ("*".equals(owners)) query.append("state=available;image-type=machine"); - else if (!"".equals(owners)) + else query.append("owner-id=").append(owners).append(";state=available;image-type=machine"); - else if ("".equals(owners)) - query = new StringBuilder(); Logger.getAnonymousLogger().warning( - String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS, - PROPERTY_EC2_AMI_QUERY, query.toString())); + String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS, + PROPERTY_EC2_AMI_QUERY, query.toString())); amiQuery = query.toString(); } Builder builder = ImmutableMap. builder(); diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/suppliers/AWSEC2ImageSupplier.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/suppliers/AWSEC2ImageSupplier.java index e4cf5b0618..88abe55846 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/suppliers/AWSEC2ImageSupplier.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/suppliers/AWSEC2ImageSupplier.java @@ -97,7 +97,7 @@ public class AWSEC2ImageSupplier implements Supplier> { @Override public Set get() { String amiQuery = queries.get(PROPERTY_EC2_AMI_QUERY); - String ccAmiQuery= queries.get(PROPERTY_EC2_CC_AMI_QUERY); + String ccAmiQuery = queries.get(PROPERTY_EC2_CC_AMI_QUERY); Future> normalImages = images(regions.get(), amiQuery, PROPERTY_EC2_AMI_QUERY); ImmutableSet clusterImages; diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java index bd2e719c94..b693d571cc 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/AWSEC2ContextBuilderTest.java @@ -60,12 +60,11 @@ public class AWSEC2ContextBuilderTest { assertEquals(queries.get(PROPERTY_EC2_AMI_QUERY), "state=available;image-type=machine"); } - public void testStaysPutWhenBlank() { + public void testBlankAmiOwnersRemovesAmiQuery() { Properties input = new Properties(); input.setProperty(PROPERTY_EC2_AMI_OWNERS, ""); Map queries = queriesForProperties(input); assertEquals(queries.get(PROPERTY_EC2_AMI_OWNERS), null); - assertEquals(queries.get(PROPERTY_EC2_AMI_QUERY), new AWSEC2ProviderMetadata().getDefaultProperties() - .getProperty(PROPERTY_EC2_AMI_QUERY)); + assertEquals(queries.get(PROPERTY_EC2_AMI_QUERY), null); } } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java index 55e762f445..02391a390a 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java @@ -59,7 +59,7 @@ import com.google.inject.Module; * * @author Adrian Cole */ -@Test(groups = "live") +@Test(groups = "live", testName = "AWSEC2TemplateBuilderLiveTest") public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { public AWSEC2TemplateBuilderLiveTest() {