mirror of https://github.com/apache/jclouds.git
fixed aws-ec2 image parsing
This commit is contained in:
parent
eda3f05c8e
commit
f1010e13a4
|
@ -72,7 +72,7 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean shouldParseImagesOnDemand(Injector injector) {
|
protected boolean shouldEagerlyParseImages(Injector injector) {
|
||||||
// If no owners to query, then will never lookup all images
|
// 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)));
|
String[] amiOwners = injector.getInstance(Key.get(String[].class, Names.named(PROPERTY_EC2_AMI_OWNERS)));
|
||||||
return (amiOwners.length > 0);
|
return (amiOwners.length > 0);
|
||||||
|
|
|
@ -227,14 +227,14 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
||||||
@Memoized
|
@Memoized
|
||||||
protected Supplier<Set<? extends Image>> supplyImageCache(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
protected Supplier<Set<? extends Image>> supplyImageCache(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||||
final Supplier<Set<? extends Image>> imageSupplier, Injector injector) {
|
final Supplier<Set<? extends Image>> imageSupplier, Injector injector) {
|
||||||
if (shouldParseImagesOnDemand(injector)) {
|
if (shouldEagerlyParseImages(injector)) {
|
||||||
return supplyImageCache(authException, seconds, imageSupplier);
|
return supplyImageCache(authException, seconds, imageSupplier);
|
||||||
} else {
|
} else {
|
||||||
return supplyNonParsingImageCache(authException, seconds, imageSupplier, injector);
|
return supplyNonParsingImageCache(authException, seconds, imageSupplier, injector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean shouldParseImagesOnDemand(Injector injector) {
|
protected boolean shouldEagerlyParseImages(Injector injector) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
package org.jclouds.config;
|
package org.jclouds.config;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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 static com.google.inject.name.Names.named;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -47,7 +46,7 @@ public class ValueOfConfigurationKeyOrNull implements Function<String, String> {
|
||||||
public String apply(String configurationKey) {
|
public String apply(String configurationKey) {
|
||||||
checkNotNull(configurationKey, "configurationKey");
|
checkNotNull(configurationKey, "configurationKey");
|
||||||
try {
|
try {
|
||||||
return emptyToNull(injector.getInstance(Key.get(String.class, named(configurationKey))));
|
return injector.getInstance(Key.get(String.class, named(configurationKey)));
|
||||||
} catch (ConfigurationException e) {
|
} catch (ConfigurationException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,6 @@ package org.jclouds.config;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
|
@ -37,12 +35,12 @@ import com.google.inject.name.Names;
|
||||||
public class ValueOfConfigurationKeyOrNullTest {
|
public class ValueOfConfigurationKeyOrNullTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotThere() throws InterruptedException, ExecutionException {
|
public void testNotThere() {
|
||||||
assertEquals(new ValueOfConfigurationKeyOrNull(Guice.createInjector()).apply("foo"), null);
|
assertEquals(new ValueOfConfigurationKeyOrNull(Guice.createInjector()).apply("foo"), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThere() throws InterruptedException, ExecutionException {
|
public void testThere() {
|
||||||
assertEquals(new ValueOfConfigurationKeyOrNull(Guice.createInjector(new AbstractModule() {
|
assertEquals(new ValueOfConfigurationKeyOrNull(Guice.createInjector(new AbstractModule() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,4 +52,16 @@ public class ValueOfConfigurationKeyOrNullTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmptyIsThere() {
|
||||||
|
assertEquals(new ValueOfConfigurationKeyOrNull(Guice.createInjector(new AbstractModule() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bindConstant().annotatedWith(Names.named("foo")).to("");
|
||||||
|
}
|
||||||
|
|
||||||
|
})).apply("foo"), "");
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.jclouds.aws.ec2;
|
package org.jclouds.aws.ec2;
|
||||||
|
|
||||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES;
|
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;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ public class AWSEC2ApiMetadata extends EC2ApiMetadata {
|
||||||
|
|
||||||
public static Properties defaultProperties() {
|
public static Properties defaultProperties() {
|
||||||
Properties properties = EC2ApiMetadata.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
|
// auth fail sometimes happens in EC2, as the rc.local script that injects the
|
||||||
// authorized key executes after ssh has started.
|
// authorized key executes after ssh has started.
|
||||||
properties.setProperty("jclouds.ssh.max-retries", "7");
|
properties.setProperty("jclouds.ssh.max-retries", "7");
|
||||||
|
|
|
@ -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_AMI_QUERY;
|
||||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_REGIONS;
|
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.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
||||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -63,7 +62,6 @@ public class AWSEC2ProviderMetadata extends BaseProviderMetadata {
|
||||||
// from stopping->stopped state on an ec2 micro
|
// from stopping->stopped state on an ec2 micro
|
||||||
properties.setProperty(TIMEOUT_NODE_SUSPENDED, 120 * 1000 + "");
|
properties.setProperty(TIMEOUT_NODE_SUSPENDED, 120 * 1000 + "");
|
||||||
properties.putAll(Region.regionProperties());
|
properties.putAll(Region.regionProperties());
|
||||||
properties.remove(PROPERTY_EC2_AMI_OWNERS);
|
|
||||||
// amazon, alestic, canonical, and rightscale
|
// amazon, alestic, canonical, and rightscale
|
||||||
properties.setProperty(PROPERTY_EC2_AMI_QUERY,
|
properties.setProperty(PROPERTY_EC2_AMI_QUERY,
|
||||||
"owner-id=137112412989,063491364108,099720109477,411009282317;state=available;image-type=machine");
|
"owner-id=137112412989,063491364108,099720109477,411009282317;state=available;image-type=machine");
|
||||||
|
|
|
@ -102,10 +102,11 @@ public class AWSEC2ComputeServiceContextModule extends BaseComputeServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean shouldParseImagesOnDemand(Injector injector) {
|
protected boolean shouldEagerlyParseImages(Injector injector) {
|
||||||
|
Map<String, String> queries = injector.getInstance(Key.get(new TypeLiteral<Map<String, String>>() {
|
||||||
|
}, ImageQuery.class));
|
||||||
// If no queries defined, then will never lookup all images
|
// If no queries defined, then will never lookup all images
|
||||||
return injector.getInstance(Key.get(new TypeLiteral<Map<String, String>>() {
|
return queries.size() > 0;
|
||||||
}, ImageQuery.class)).size() > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// duplicates EC2ComputeServiceContextModule; but that's easiest thing to do with guice; could extract to common util
|
// duplicates EC2ComputeServiceContextModule; but that's easiest thing to do with guice; could extract to common util
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.ec2.compute.config;
|
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 static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||||
|
|
||||||
import java.util.Map;
|
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.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.google.common.collect.ImmutableMap.Builder;
|
import com.google.common.collect.ImmutableMap.Builder;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||||
|
@ -100,18 +101,18 @@ public class AWSEC2ComputeServiceDependenciesModule extends EC2ComputeServiceDep
|
||||||
@ImageQuery
|
@ImageQuery
|
||||||
protected Map<String, String> imageQuery(ValueOfConfigurationKeyOrNull config) {
|
protected Map<String, String> imageQuery(ValueOfConfigurationKeyOrNull config) {
|
||||||
String amiQuery = Strings.emptyToNull(config.apply(PROPERTY_EC2_AMI_QUERY));
|
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();
|
StringBuilder query = new StringBuilder();
|
||||||
String owners = config.apply(PROPERTY_EC2_AMI_OWNERS).toString();
|
|
||||||
if ("*".equals(owners))
|
if ("*".equals(owners))
|
||||||
query.append("state=available;image-type=machine");
|
query.append("state=available;image-type=machine");
|
||||||
else if (!"".equals(owners))
|
else
|
||||||
query.append("owner-id=").append(owners).append(";state=available;image-type=machine");
|
query.append("owner-id=").append(owners).append(";state=available;image-type=machine");
|
||||||
else if ("".equals(owners))
|
|
||||||
query = new StringBuilder();
|
|
||||||
Logger.getAnonymousLogger().warning(
|
Logger.getAnonymousLogger().warning(
|
||||||
String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS,
|
String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS,
|
||||||
PROPERTY_EC2_AMI_QUERY, query.toString()));
|
PROPERTY_EC2_AMI_QUERY, query.toString()));
|
||||||
amiQuery = query.toString();
|
amiQuery = query.toString();
|
||||||
}
|
}
|
||||||
Builder<String, String> builder = ImmutableMap.<String, String> builder();
|
Builder<String, String> builder = ImmutableMap.<String, String> builder();
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class AWSEC2ImageSupplier implements Supplier<Set<? extends Image>> {
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends Image> get() {
|
public Set<? extends Image> get() {
|
||||||
String amiQuery = queries.get(PROPERTY_EC2_AMI_QUERY);
|
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<Iterable<Image>> normalImages = images(regions.get(), amiQuery, PROPERTY_EC2_AMI_QUERY);
|
Future<Iterable<Image>> normalImages = images(regions.get(), amiQuery, PROPERTY_EC2_AMI_QUERY);
|
||||||
ImmutableSet<Image> clusterImages;
|
ImmutableSet<Image> clusterImages;
|
||||||
|
|
|
@ -60,12 +60,11 @@ public class AWSEC2ContextBuilderTest {
|
||||||
assertEquals(queries.get(PROPERTY_EC2_AMI_QUERY), "state=available;image-type=machine");
|
assertEquals(queries.get(PROPERTY_EC2_AMI_QUERY), "state=available;image-type=machine");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStaysPutWhenBlank() {
|
public void testBlankAmiOwnersRemovesAmiQuery() {
|
||||||
Properties input = new Properties();
|
Properties input = new Properties();
|
||||||
input.setProperty(PROPERTY_EC2_AMI_OWNERS, "");
|
input.setProperty(PROPERTY_EC2_AMI_OWNERS, "");
|
||||||
Map<String, String> queries = queriesForProperties(input);
|
Map<String, String> queries = queriesForProperties(input);
|
||||||
assertEquals(queries.get(PROPERTY_EC2_AMI_OWNERS), null);
|
assertEquals(queries.get(PROPERTY_EC2_AMI_OWNERS), null);
|
||||||
assertEquals(queries.get(PROPERTY_EC2_AMI_QUERY), new AWSEC2ProviderMetadata().getDefaultProperties()
|
assertEquals(queries.get(PROPERTY_EC2_AMI_QUERY), null);
|
||||||
.getProperty(PROPERTY_EC2_AMI_QUERY));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ import com.google.inject.Module;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live")
|
@Test(groups = "live", testName = "AWSEC2TemplateBuilderLiveTest")
|
||||||
public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest {
|
public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest {
|
||||||
|
|
||||||
public AWSEC2TemplateBuilderLiveTest() {
|
public AWSEC2TemplateBuilderLiveTest() {
|
||||||
|
|
Loading…
Reference in New Issue