mirror of https://github.com/apache/jclouds.git
Issue 289: fixed template options classpath woes
This commit is contained in:
parent
7e28286dd0
commit
360af6f42c
|
@ -10,6 +10,7 @@ import javax.inject.Named;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||||
|
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.Size;
|
import org.jclouds.compute.domain.Size;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
|
@ -28,15 +29,35 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
|
||||||
private final ConcurrentMap<RegionAndName, Image> imageMap;
|
private final ConcurrentMap<RegionAndName, Image> imageMap;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected EC2TemplateBuilderImpl(Provider<Set<? extends Location>> locations,
|
protected EC2TemplateBuilderImpl(
|
||||||
Provider<Set<? extends Image>> images, Provider<Set<? extends Size>> sizes,
|
Provider<Set<? extends Location>> locations,
|
||||||
Location defaultLocation, Provider<TemplateOptions> optionsProvider,
|
Provider<Set<? extends Image>> images,
|
||||||
|
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||||
|
Provider<TemplateOptions> optionsProvider,
|
||||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider,
|
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider,
|
||||||
ConcurrentMap<RegionAndName, Image> imageMap) {
|
ConcurrentMap<RegionAndName, Image> imageMap) {
|
||||||
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
|
super(locations, images, sizes, defaultLocation, optionsProvider,
|
||||||
|
defaultTemplateProvider);
|
||||||
this.imageMap = imageMap;
|
this.imageMap = imageMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void copyTemplateOptions(TemplateOptions from, TemplateOptions to) {
|
||||||
|
super.copyTemplateOptions(from, to);
|
||||||
|
if (from instanceof EC2TemplateOptions) {
|
||||||
|
EC2TemplateOptions eFrom = EC2TemplateOptions.class.cast(from);
|
||||||
|
EC2TemplateOptions eTo = EC2TemplateOptions.class.cast(to);
|
||||||
|
if (eFrom.getGroupIds().size() >0)
|
||||||
|
eTo.securityGroups(eFrom.getGroupIds());
|
||||||
|
if (eFrom.getKeyPair() != null)
|
||||||
|
eTo.keyPair(eFrom.getKeyPair());
|
||||||
|
if (!eFrom.shouldAutomaticallyCreateKeyPair())
|
||||||
|
eTo.noKeyPair();
|
||||||
|
if(eFrom.getSubnetId() != null)
|
||||||
|
eTo.subnetId(eFrom.getSubnetId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws NoSuchElementException
|
* @throws NoSuchElementException
|
||||||
* if the image is not found
|
* if the image is not found
|
||||||
|
@ -51,8 +72,8 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
|
||||||
try {
|
try {
|
||||||
return ImmutableList.of(imageMap.get(key));
|
return ImmutableList.of(imageMap.get(key));
|
||||||
} catch (NullPointerException nex) {
|
} catch (NullPointerException nex) {
|
||||||
throw new NoSuchElementException(String.format("image %s/%s not found", key
|
throw new NoSuchElementException(String.format(
|
||||||
.getRegion(), key.getName()));
|
"image %s/%s not found", key.getRegion(), key.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class EC2TemplateOptions extends TemplateOptions {
|
||||||
/**
|
/**
|
||||||
* Specifies the subnetId used to run instances in
|
* Specifies the subnetId used to run instances in
|
||||||
*/
|
*/
|
||||||
public EC2TemplateOptions withSubnetId(String subnetId) {
|
public EC2TemplateOptions subnetId(String subnetId) {
|
||||||
checkNotNull(subnetId, "subnetId cannot be null");
|
checkNotNull(subnetId, "subnetId cannot be null");
|
||||||
Utils.checkNotEmpty(subnetId, "subnetId must be non-empty");
|
Utils.checkNotEmpty(subnetId, "subnetId must be non-empty");
|
||||||
this.subnetId = subnetId;
|
this.subnetId = subnetId;
|
||||||
|
@ -192,9 +192,9 @@ public class EC2TemplateOptions extends TemplateOptions {
|
||||||
/**
|
/**
|
||||||
* @see TemplateOptions#withSubnetId
|
* @see TemplateOptions#withSubnetId
|
||||||
*/
|
*/
|
||||||
public static EC2TemplateOptions withSubnetId(String subnetId) {
|
public static EC2TemplateOptions subnetId(String subnetId) {
|
||||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||||
return EC2TemplateOptions.class.cast(options.withSubnetId(subnetId));
|
return EC2TemplateOptions.class.cast(options.subnetId(subnetId));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -292,6 +292,7 @@ public class EC2TemplateOptions extends TemplateOptions {
|
||||||
result = prime * result + ((groupIds == null) ? 0 : groupIds.hashCode());
|
result = prime * result + ((groupIds == null) ? 0 : groupIds.hashCode());
|
||||||
result = prime * result + ((keyPair == null) ? 0 : keyPair.hashCode());
|
result = prime * result + ((keyPair == null) ? 0 : keyPair.hashCode());
|
||||||
result = prime * result + (noKeyPair ? 1231 : 1237);
|
result = prime * result + (noKeyPair ? 1231 : 1237);
|
||||||
|
result = prime * result + ((subnetId == null) ? 0 : subnetId.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +317,10 @@ public class EC2TemplateOptions extends TemplateOptions {
|
||||||
return false;
|
return false;
|
||||||
if (noKeyPair != other.noKeyPair)
|
if (noKeyPair != other.noKeyPair)
|
||||||
return false;
|
return false;
|
||||||
if (!subnetId.equals(other.subnetId))
|
if (subnetId == null) {
|
||||||
|
if (other.subnetId != null)
|
||||||
|
return false;
|
||||||
|
} else if (!subnetId.equals(other.subnetId))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,7 +216,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||||
|
|
||||||
//options.as(EC2TemplateOptions.class).securityGroups(tag);
|
//options.as(EC2TemplateOptions.class).securityGroups(tag);
|
||||||
options.as(EC2TemplateOptions.class).keyPair(tag);
|
options.as(EC2TemplateOptions.class).keyPair(tag);
|
||||||
options.as(EC2TemplateOptions.class).withSubnetId(subnetId);
|
options.as(EC2TemplateOptions.class).subnetId(subnetId);
|
||||||
|
|
||||||
String startedId = null;
|
String startedId = null;
|
||||||
String nodeId = null;
|
String nodeId = null;
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.util.concurrent.ConcurrentMap;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||||
|
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
||||||
import org.jclouds.compute.domain.Architecture;
|
import org.jclouds.compute.domain.Architecture;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.Size;
|
import org.jclouds.compute.domain.Size;
|
||||||
|
@ -77,28 +78,37 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
knownImage = createNiceMock(Image.class);
|
knownImage = createNiceMock(Image.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TemplateOptions provideTemplateOptions() {
|
||||||
|
return new EC2TemplateOptions();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EC2TemplateBuilderImpl createTemplateBuilder(
|
protected EC2TemplateBuilderImpl createTemplateBuilder(
|
||||||
Provider<Set<? extends Location>> locations, Provider<Set<? extends Image>> images,
|
Provider<Set<? extends Location>> locations,
|
||||||
|
Provider<Set<? extends Image>> images,
|
||||||
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||||
Provider<TemplateOptions> optionsProvider,
|
Provider<TemplateOptions> optionsProvider,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider) {
|
Provider<TemplateBuilder> templateBuilderProvider) {
|
||||||
return new EC2TemplateBuilderImpl(locations, images, sizes, defaultLocation, optionsProvider,
|
return new EC2TemplateBuilderImpl(locations, images, sizes,
|
||||||
templateBuilderProvider, imageMap);
|
defaultLocation, optionsProvider, templateBuilderProvider, imageMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testParseOnDemand() {
|
public void testParseOnDemand() {
|
||||||
Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
|
Location location = new LocationImpl(LocationScope.REGION, "region",
|
||||||
|
"region", null);
|
||||||
|
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(location));
|
.<Set<? extends Location>> of(ImmutableSet.<Location> of(location));
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
Provider<Set<? extends Image>> images = Providers
|
||||||
.<Image> of());
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
.<Size> of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap
|
.<Set<? extends Size>> of(ImmutableSet
|
||||||
.<String, String> of(), 1, 1, 1, ImagePredicates.any())));
|
.<Size> of(new SizeImpl("1", "1", "region/1", location, null,
|
||||||
|
ImmutableMap.<String, String> of(), 1, 1, 1,
|
||||||
|
ImagePredicates.any())));
|
||||||
|
|
||||||
Location defaultLocation = createMock(Location.class);
|
Location defaultLocation = createMock(Location.class);
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
|
@ -116,8 +126,8 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
assertEquals(template.imageId("ami").build().getImage(), knownImage);
|
assertEquals(template.imageId("ami").build().getImage(), knownImage);
|
||||||
|
|
||||||
|
@ -131,15 +141,18 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test(expectedExceptions = NoSuchElementException.class)
|
@Test(expectedExceptions = NoSuchElementException.class)
|
||||||
public void testParseOnDemandNotFound() {
|
public void testParseOnDemandNotFound() {
|
||||||
Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
|
Location location = new LocationImpl(LocationScope.REGION, "region",
|
||||||
|
"region", null);
|
||||||
|
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(location));
|
.<Set<? extends Location>> of(ImmutableSet.<Location> of(location));
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
Provider<Set<? extends Image>> images = Providers
|
||||||
.<Image> of());
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
.<Size> of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap
|
.<Set<? extends Size>> of(ImmutableSet
|
||||||
.<String, String> of(), 1, 1, 1, ImagePredicates.any())));
|
.<Size> of(new SizeImpl("1", "1", "region/1", location, null,
|
||||||
|
ImmutableMap.<String, String> of(), 1, 1, 1,
|
||||||
|
ImagePredicates.any())));
|
||||||
|
|
||||||
Location defaultLocation = createMock(Location.class);
|
Location defaultLocation = createMock(Location.class);
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
|
@ -149,7 +162,8 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
|
|
||||||
expect(defaultLocation.getId()).andReturn("region");
|
expect(defaultLocation.getId()).andReturn("region");
|
||||||
expect(optionsProvider.get()).andReturn(defaultOptions);
|
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||||
expect(knownImage.getArchitecture()).andReturn(Architecture.X86_32).atLeastOnce();
|
expect(knownImage.getArchitecture()).andReturn(Architecture.X86_32)
|
||||||
|
.atLeastOnce();
|
||||||
|
|
||||||
replay(knownImage);
|
replay(knownImage);
|
||||||
replay(defaultOptions);
|
replay(defaultOptions);
|
||||||
|
@ -157,8 +171,8 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
assertEquals(template.imageId("bad").build().getImage(), knownImage);
|
assertEquals(template.imageId("bad").build().getImage(), knownImage);
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.compute.internal;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -67,7 +68,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
private final Provider<Set<? extends Image>> images;
|
private final Provider<Set<? extends Image>> images;
|
||||||
private final Provider<Set<? extends Size>> sizes;
|
private final Provider<Set<? extends Size>> sizes;
|
||||||
private final Provider<Set<? extends Location>> locations;
|
private final Provider<Set<? extends Location>> locations;
|
||||||
private final Provider<TemplateOptions> optionsProvider;
|
protected final Provider<TemplateOptions> optionsProvider;
|
||||||
private final Provider<TemplateBuilder> defaultTemplateProvider;
|
private final Provider<TemplateBuilder> defaultTemplateProvider;
|
||||||
private final Location defaultLocation;
|
private final Location defaultLocation;
|
||||||
|
|
||||||
|
@ -102,8 +103,9 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected TemplateBuilderImpl(Provider<Set<? extends Location>> locations,
|
protected TemplateBuilderImpl(Provider<Set<? extends Location>> locations,
|
||||||
Provider<Set<? extends Image>> images, Provider<Set<? extends Size>> sizes,
|
Provider<Set<? extends Image>> images,
|
||||||
Location defaultLocation, Provider<TemplateOptions> optionsProvider,
|
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||||
|
Provider<TemplateOptions> optionsProvider,
|
||||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
||||||
this.locations = locations;
|
this.locations = locations;
|
||||||
this.images = images;
|
this.images = images;
|
||||||
|
@ -171,8 +173,13 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
else
|
else
|
||||||
returnVal = input.getOsDescription().contains(osDescription)
|
returnVal = input.getOsDescription().contains(osDescription)
|
||||||
|| input.getOsDescription().matches(osDescription); /*
|
|| input.getOsDescription().matches(osDescription); /*
|
||||||
* note: matches()
|
* note:
|
||||||
* expects a regex!
|
* matches
|
||||||
|
* ()
|
||||||
|
* expects
|
||||||
|
* a
|
||||||
|
* regex
|
||||||
|
* !
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
|
@ -188,7 +195,9 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
else
|
else
|
||||||
returnVal = input.getVersion().contains(imageVersion)
|
returnVal = input.getVersion().contains(imageVersion)
|
||||||
|| input.getVersion().matches(imageVersion); /*
|
|| input.getVersion().matches(imageVersion); /*
|
||||||
* note: matches() expects a
|
* note:
|
||||||
|
* matches()
|
||||||
|
* expects a
|
||||||
* regex!
|
* regex!
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@ -204,7 +213,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
returnVal = false;
|
returnVal = false;
|
||||||
else
|
else
|
||||||
returnVal = input.getName().contains(imageName)
|
returnVal = input.getName().contains(imageName)
|
||||||
|| input.getName().matches(imageName); /* note: matches() expects a regex! */
|
|| input.getName().matches(imageName); /*
|
||||||
|
* note: matches()
|
||||||
|
* expects a regex!
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
@ -220,8 +232,13 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
returnVal = input.getDescription().equals(imageDescription)
|
returnVal = input.getDescription().equals(imageDescription)
|
||||||
|| input.getDescription().contains(imageDescription)
|
|| input.getDescription().contains(imageDescription)
|
||||||
|| input.getDescription().matches(imageDescription); /*
|
|| input.getDescription().matches(imageDescription); /*
|
||||||
* note: matches()
|
* note:
|
||||||
* expects a regex!
|
* matches
|
||||||
|
* ()
|
||||||
|
* expects
|
||||||
|
* a
|
||||||
|
* regex
|
||||||
|
* !
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
|
@ -255,13 +272,15 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
return input.getRam() >= TemplateBuilderImpl.this.minRam;
|
return input.getRam() >= TemplateBuilderImpl.this.minRam;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private final Predicate<Size> sizePredicate = Predicates.and(sizeIdPredicate, locationPredicate,
|
private final Predicate<Size> sizePredicate = Predicates.and(
|
||||||
sizeCoresPredicate, sizeRamPredicate);
|
sizeIdPredicate, locationPredicate, sizeCoresPredicate,
|
||||||
|
sizeRamPredicate);
|
||||||
|
|
||||||
static final Ordering<Size> DEFAULT_SIZE_ORDERING = new Ordering<Size>() {
|
static final Ordering<Size> DEFAULT_SIZE_ORDERING = new Ordering<Size>() {
|
||||||
public int compare(Size left, Size right) {
|
public int compare(Size left, Size right) {
|
||||||
return ComparisonChain.start().compare(left.getCores(), right.getCores()).compare(
|
return ComparisonChain.start().compare(left.getCores(),
|
||||||
left.getRam(), right.getRam()).compare(left.getDisk(), right.getDisk()).result();
|
right.getCores()).compare(left.getRam(), right.getRam())
|
||||||
|
.compare(left.getDisk(), right.getDisk()).result();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static final Ordering<Size> BY_CORES_ORDERING = new Ordering<Size>() {
|
static final Ordering<Size> BY_CORES_ORDERING = new Ordering<Size>() {
|
||||||
|
@ -271,12 +290,13 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
};
|
};
|
||||||
static final Ordering<Image> DEFAULT_IMAGE_ORDERING = new Ordering<Image>() {
|
static final Ordering<Image> DEFAULT_IMAGE_ORDERING = new Ordering<Image>() {
|
||||||
public int compare(Image left, Image right) {
|
public int compare(Image left, Image right) {
|
||||||
return ComparisonChain.start().compare(left.getName(), right.getName(),
|
return ComparisonChain.start().compare(left.getName(),
|
||||||
Ordering.<String> natural().nullsLast()).compare(left.getVersion(),
|
right.getName(), Ordering.<String> natural().nullsLast())
|
||||||
right.getVersion(), Ordering.<String> natural().nullsLast()).compare(
|
.compare(left.getVersion(), right.getVersion(),
|
||||||
|
Ordering.<String> natural().nullsLast()).compare(
|
||||||
left.getOsDescription(), right.getOsDescription(),
|
left.getOsDescription(), right.getOsDescription(),
|
||||||
Ordering.<String> natural().nullsLast()).compare(left.getArchitecture(),
|
Ordering.<String> natural().nullsLast()).compare(
|
||||||
right.getArchitecture()).result();
|
left.getArchitecture(), right.getArchitecture()).result();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -414,7 +434,8 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Location resolveLocation() {
|
protected Location resolveLocation() {
|
||||||
Location location = Iterables.find(locations.get(), new Predicate<Location>() {
|
Location location = Iterables.find(locations.get(),
|
||||||
|
new Predicate<Location>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Location input) {
|
public boolean apply(Location input) {
|
||||||
|
@ -426,16 +447,18 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Size resolveSize(Ordering<Size> sizeOrdering, final List<? extends Image> images) {
|
protected Size resolveSize(Ordering<Size> sizeOrdering,
|
||||||
|
final List<? extends Image> images) {
|
||||||
Size size;
|
Size size;
|
||||||
try {
|
try {
|
||||||
Iterable<? extends Size> sizesThatAreCompatibleWithOurImages = Iterables.filter(sizes
|
Iterable<? extends Size> sizesThatAreCompatibleWithOurImages = Iterables
|
||||||
.get(), new Predicate<Size>() {
|
.filter(sizes.get(), new Predicate<Size>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(final Size size) {
|
public boolean apply(final Size size) {
|
||||||
boolean returnVal = false;
|
boolean returnVal = false;
|
||||||
if (size != null)
|
if (size != null)
|
||||||
returnVal = Iterables.any(images, new Predicate<Image>() {
|
returnVal = Iterables.any(images,
|
||||||
|
new Predicate<Image>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Image input) {
|
public boolean apply(Image input) {
|
||||||
|
@ -446,10 +469,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
size = sizeOrdering.max(Iterables.filter(sizesThatAreCompatibleWithOurImages,
|
size = sizeOrdering.max(Iterables.filter(
|
||||||
sizePredicate));
|
sizesThatAreCompatibleWithOurImages, sizePredicate));
|
||||||
} catch (NoSuchElementException exception) {
|
} catch (NoSuchElementException exception) {
|
||||||
throw new NoSuchElementException("size didn't match: " + toString() + "\n" + sizes.get());
|
throw new NoSuchElementException("size didn't match: " + toString()
|
||||||
|
+ "\n" + sizes.get());
|
||||||
}
|
}
|
||||||
logger.debug("<< matched size(%s)", size);
|
logger.debug("<< matched size(%s)", size);
|
||||||
return size;
|
return size;
|
||||||
|
@ -460,7 +484,8 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
if (!biggest)
|
if (!biggest)
|
||||||
sizeOrdering = sizeOrdering.reverse();
|
sizeOrdering = sizeOrdering.reverse();
|
||||||
if (fastest)
|
if (fastest)
|
||||||
sizeOrdering = Ordering.compound(ImmutableList.of(BY_CORES_ORDERING, sizeOrdering));
|
sizeOrdering = Ordering.compound(ImmutableList.of(BY_CORES_ORDERING,
|
||||||
|
sizeOrdering));
|
||||||
return sizeOrdering;
|
return sizeOrdering;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,15 +497,18 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
protected List<? extends Image> resolveImages() {
|
protected List<? extends Image> resolveImages() {
|
||||||
Predicate<Image> imagePredicate = buildImagePredicate();
|
Predicate<Image> imagePredicate = buildImagePredicate();
|
||||||
try {
|
try {
|
||||||
Iterable<? extends Image> matchingImages = Iterables.filter(images.get(), imagePredicate);
|
Iterable<? extends Image> matchingImages = Iterables.filter(images
|
||||||
|
.get(), imagePredicate);
|
||||||
if (logger.isTraceEnabled())
|
if (logger.isTraceEnabled())
|
||||||
logger.trace("<< matched images(%s)", matchingImages);
|
logger.trace("<< matched images(%s)", matchingImages);
|
||||||
List<? extends Image> maxImages = Utils.multiMax(DEFAULT_IMAGE_ORDERING, matchingImages);
|
List<? extends Image> maxImages = Utils.multiMax(
|
||||||
|
DEFAULT_IMAGE_ORDERING, matchingImages);
|
||||||
if (logger.isTraceEnabled())
|
if (logger.isTraceEnabled())
|
||||||
logger.trace("<< best images(%s)", maxImages);
|
logger.trace("<< best images(%s)", maxImages);
|
||||||
return maxImages;
|
return maxImages;
|
||||||
} catch (NoSuchElementException exception) {
|
} catch (NoSuchElementException exception) {
|
||||||
throw new NoSuchElementException("image didn't match: " + toString() + "\n" + images.get());
|
throw new NoSuchElementException("image didn't match: " + toString()
|
||||||
|
+ "\n" + images.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,15 +620,35 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TemplateBuilder options(TemplateOptions options) {
|
public TemplateBuilder options(TemplateOptions options) {
|
||||||
this.options = checkNotNull(options, "options");
|
this.options = optionsProvider.get();
|
||||||
|
copyTemplateOptions(checkNotNull(options, "options"), this.options);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void copyTemplateOptions(TemplateOptions from, TemplateOptions to) {
|
||||||
|
if (!Arrays.equals(to.getInboundPorts(), from.getInboundPorts()))
|
||||||
|
to.inboundPorts(from.getInboundPorts());
|
||||||
|
if (from.getRunScript() != null)
|
||||||
|
to.runScript(from.getRunScript());
|
||||||
|
if (from.getPrivateKey() != null)
|
||||||
|
to.installPrivateKey(from.getPrivateKey());
|
||||||
|
if (from.getPublicKey() != null)
|
||||||
|
to.authorizePublicKey(from.getPublicKey());
|
||||||
|
if (from.getPort() != -1)
|
||||||
|
to.blockOnPort(from.getPort(), from.getSeconds());
|
||||||
|
if (from.isIncludeMetadata())
|
||||||
|
to.withMetadata();
|
||||||
|
if (!from.shouldBlockUntilRunning())
|
||||||
|
to.blockUntilRunning(false);
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean nothingChangedExceptOptions() {
|
boolean nothingChangedExceptOptions() {
|
||||||
return os == null && arch == null && locationId == null && imageId == null && sizeId == null
|
return os == null && arch == null && locationId == null
|
||||||
&& osDescription == null && imageVersion == null && imageName == null
|
&& imageId == null && sizeId == null && osDescription == null
|
||||||
&& imageDescription == null && minCores == 0 && minRam == 0 && !biggest && !fastest;
|
&& imageVersion == null && imageName == null
|
||||||
|
&& imageDescription == null && minCores == 0 && minRam == 0
|
||||||
|
&& !biggest && !fastest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -613,11 +661,12 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[arch=" + arch + ", biggest=" + biggest + ", fastest=" + fastest + ", imageName="
|
return "[arch=" + arch + ", biggest=" + biggest + ", fastest=" + fastest
|
||||||
+ imageName + ", imageDescription=" + imageDescription + ", imageId=" + imageId
|
+ ", imageName=" + imageName + ", imageDescription="
|
||||||
+ ", imageVersion=" + imageVersion + ", location=" + locationId + ", minCores="
|
+ imageDescription + ", imageId=" + imageId + ", imageVersion="
|
||||||
+ minCores + ", minRam=" + minRam + ", os=" + os + ", osDescription="
|
+ imageVersion + ", location=" + locationId + ", minCores="
|
||||||
+ osDescription + ", sizeId=" + sizeId + "]";
|
+ minCores + ", minRam=" + minRam + ", os=" + os
|
||||||
|
+ ", osDescription=" + osDescription + ", sizeId=" + sizeId + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,15 +58,17 @@ public class TemplateBuilderImplTest {
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
Image image2 = createMock(Image.class);
|
Image image2 = createMock(Image.class);
|
||||||
|
|
||||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap
|
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null,
|
||||||
.<String, String> of(), 1.0, 0, 0, ImagePredicates.any());
|
ImmutableMap.<String, String> of(), 1.0, 0, 0, ImagePredicates
|
||||||
|
.any());
|
||||||
|
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(defaultLocation));
|
.<Set<? extends Location>> of(ImmutableSet
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
.<Location> of(defaultLocation));
|
||||||
.<Image> of(image, image2));
|
Provider<Set<? extends Image>> images = Providers
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of(image, image2));
|
||||||
.<Size> of(size));
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
|
.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||||
|
@ -77,8 +79,10 @@ public class TemplateBuilderImplTest {
|
||||||
expect(image2.getVersion()).andReturn("version");
|
expect(image2.getVersion()).andReturn("version");
|
||||||
expect(image.getOsDescription()).andReturn("osDescription");
|
expect(image.getOsDescription()).andReturn("osDescription");
|
||||||
expect(image2.getOsDescription()).andReturn("osDescription");
|
expect(image2.getOsDescription()).andReturn("osDescription");
|
||||||
expect(image.getArchitecture()).andReturn(Architecture.X86_64).atLeastOnce();
|
expect(image.getArchitecture()).andReturn(Architecture.X86_64)
|
||||||
expect(image2.getArchitecture()).andReturn(Architecture.X86_64).atLeastOnce();
|
.atLeastOnce();
|
||||||
|
expect(image2.getArchitecture()).andReturn(Architecture.X86_64)
|
||||||
|
.atLeastOnce();
|
||||||
|
|
||||||
replay(image);
|
replay(image);
|
||||||
replay(image2);
|
replay(image2);
|
||||||
|
@ -87,8 +91,8 @@ public class TemplateBuilderImplTest {
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
assertEquals(template.resolveImages(), images.get());
|
assertEquals(template.resolveImages(), images.get());
|
||||||
|
|
||||||
|
@ -107,15 +111,17 @@ public class TemplateBuilderImplTest {
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
Image image2 = createMock(Image.class);
|
Image image2 = createMock(Image.class);
|
||||||
|
|
||||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap
|
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null,
|
||||||
.<String, String> of(), 1.0, 0, 0, ImagePredicates.any());
|
ImmutableMap.<String, String> of(), 1.0, 0, 0, ImagePredicates
|
||||||
|
.any());
|
||||||
|
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(defaultLocation));
|
.<Set<? extends Location>> of(ImmutableSet
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
.<Location> of(defaultLocation));
|
||||||
.<Image> of(image, image2));
|
Provider<Set<? extends Image>> images = Providers
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of(image, image2));
|
||||||
.<Size> of(size));
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
|
.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||||
|
@ -124,10 +130,12 @@ public class TemplateBuilderImplTest {
|
||||||
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
||||||
|
|
||||||
expect(image.getLocation()).andReturn(defaultLocation).atLeastOnce();
|
expect(image.getLocation()).andReturn(defaultLocation).atLeastOnce();
|
||||||
expect(image.getArchitecture()).andReturn(Architecture.X86_32).atLeastOnce();
|
expect(image.getArchitecture()).andReturn(Architecture.X86_32)
|
||||||
|
.atLeastOnce();
|
||||||
|
|
||||||
expect(image2.getLocation()).andReturn(defaultLocation).atLeastOnce();
|
expect(image2.getLocation()).andReturn(defaultLocation).atLeastOnce();
|
||||||
expect(image2.getArchitecture()).andReturn(Architecture.X86_64).atLeastOnce();
|
expect(image2.getArchitecture()).andReturn(Architecture.X86_64)
|
||||||
|
.atLeastOnce();
|
||||||
|
|
||||||
replay(image);
|
replay(image);
|
||||||
replay(image2);
|
replay(image2);
|
||||||
|
@ -136,10 +144,11 @@ public class TemplateBuilderImplTest {
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
assertEquals(template.smallest().architecture(Architecture.X86_32).build().getImage(), image);
|
assertEquals(template.smallest().architecture(Architecture.X86_32)
|
||||||
|
.build().getImage(), image);
|
||||||
|
|
||||||
verify(image);
|
verify(image);
|
||||||
verify(image2);
|
verify(image2);
|
||||||
|
@ -154,15 +163,17 @@ public class TemplateBuilderImplTest {
|
||||||
public void testSizeWithImageIdPredicateOnlyAcceptsImage() {
|
public void testSizeWithImageIdPredicateOnlyAcceptsImage() {
|
||||||
Location defaultLocation = createMock(Location.class);
|
Location defaultLocation = createMock(Location.class);
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap
|
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null,
|
||||||
.<String, String> of(), 0, 0, 0, ImagePredicates.idEquals("imageId"));
|
ImmutableMap.<String, String> of(), 0, 0, 0, ImagePredicates
|
||||||
|
.idEquals("imageId"));
|
||||||
|
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(defaultLocation));
|
.<Set<? extends Location>> of(ImmutableSet
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
.<Location> of(defaultLocation));
|
||||||
.<Image> of(image));
|
Provider<Set<? extends Image>> images = Providers
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of(image));
|
||||||
.<Size> of(size));
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
|
.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||||
|
@ -184,8 +195,8 @@ public class TemplateBuilderImplTest {
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
template.imageId("imageId").build();
|
template.imageId("imageId").build();
|
||||||
|
|
||||||
|
@ -201,15 +212,17 @@ public class TemplateBuilderImplTest {
|
||||||
public void testSizeWithImageIdPredicateOnlyDoesntImage() {
|
public void testSizeWithImageIdPredicateOnlyDoesntImage() {
|
||||||
Location defaultLocation = createMock(Location.class);
|
Location defaultLocation = createMock(Location.class);
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap
|
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null,
|
||||||
.<String, String> of(), 0, 0, 0, ImagePredicates.idEquals("imageId"));
|
ImmutableMap.<String, String> of(), 0, 0, 0, ImagePredicates
|
||||||
|
.idEquals("imageId"));
|
||||||
|
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(defaultLocation));
|
.<Set<? extends Location>> of(ImmutableSet
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
.<Location> of(defaultLocation));
|
||||||
.<Image> of(image));
|
Provider<Set<? extends Image>> images = Providers
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of(image));
|
||||||
.<Size> of(size));
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
|
.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||||
|
@ -231,8 +244,8 @@ public class TemplateBuilderImplTest {
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
try {
|
try {
|
||||||
template.imageId("notImageId").build();
|
template.imageId("notImageId").build();
|
||||||
assert false;
|
assert false;
|
||||||
|
@ -248,14 +261,15 @@ public class TemplateBuilderImplTest {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testOptionsUsesDefaultTemplateBuilder() {
|
public void testOptionsUsesDefaultTemplateBuilder() {
|
||||||
TemplateOptions options = new TemplateOptions();
|
TemplateOptions options = provideTemplateOptions();
|
||||||
|
TemplateOptions from = provideTemplateOptions();
|
||||||
|
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
Provider<Set<? extends Image>> images = Providers
|
||||||
.<Image> of());
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
.<Size> of());
|
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||||
Location defaultLocation = createMock(Location.class);
|
Location defaultLocation = createMock(Location.class);
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
@ -264,14 +278,15 @@ public class TemplateBuilderImplTest {
|
||||||
expect(templateBuilderProvider.get()).andReturn(defaultTemplate);
|
expect(templateBuilderProvider.get()).andReturn(defaultTemplate);
|
||||||
expect(defaultTemplate.options(options)).andReturn(defaultTemplate);
|
expect(defaultTemplate.options(options)).andReturn(defaultTemplate);
|
||||||
expect(defaultTemplate.build()).andReturn(null);
|
expect(defaultTemplate.build()).andReturn(null);
|
||||||
|
expect(optionsProvider.get()).andReturn(from).atLeastOnce();
|
||||||
|
|
||||||
replay(defaultTemplate);
|
replay(defaultTemplate);
|
||||||
replay(defaultLocation);
|
replay(defaultLocation);
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
template.options(options).build();
|
template.options(options).build();
|
||||||
|
|
||||||
|
@ -287,10 +302,10 @@ public class TemplateBuilderImplTest {
|
||||||
|
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
Provider<Set<? extends Image>> images = Providers
|
||||||
.<Image> of());
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
.<Size> of());
|
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||||
|
|
||||||
Location defaultLocation = createMock(Location.class);
|
Location defaultLocation = createMock(Location.class);
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
|
@ -305,8 +320,8 @@ public class TemplateBuilderImplTest {
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
template.build();
|
template.build();
|
||||||
|
|
||||||
|
@ -316,12 +331,14 @@ public class TemplateBuilderImplTest {
|
||||||
verify(templateBuilderProvider);
|
verify(templateBuilderProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TemplateBuilderImpl createTemplateBuilder(Provider<Set<? extends Location>> locations,
|
protected TemplateBuilderImpl createTemplateBuilder(
|
||||||
Provider<Set<? extends Image>> images, Provider<Set<? extends Size>> sizes,
|
Provider<Set<? extends Location>> locations,
|
||||||
Location defaultLocation, Provider<TemplateOptions> optionsProvider,
|
Provider<Set<? extends Image>> images,
|
||||||
|
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||||
|
Provider<TemplateOptions> optionsProvider,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider) {
|
Provider<TemplateBuilder> templateBuilderProvider) {
|
||||||
TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images, sizes,
|
TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,10 +347,10 @@ public class TemplateBuilderImplTest {
|
||||||
public void testSuppliedLocationWithNoOptions() {
|
public void testSuppliedLocationWithNoOptions() {
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
Provider<Set<? extends Image>> images = Providers
|
||||||
.<Image> of());
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
.<Size> of());
|
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||||
Location defaultLocation = createMock(Location.class);
|
Location defaultLocation = createMock(Location.class);
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
@ -346,8 +363,8 @@ public class TemplateBuilderImplTest {
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
template.imageId("foo").locationId("location").build();
|
template.imageId("foo").locationId("location").build();
|
||||||
|
@ -365,25 +382,30 @@ public class TemplateBuilderImplTest {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testSuppliedLocationAndOptions() {
|
public void testSuppliedLocationAndOptions() {
|
||||||
|
TemplateOptions from = provideTemplateOptions();
|
||||||
|
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
Provider<Set<? extends Image>> images = Providers
|
||||||
.<Image> of());
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
.<Size> of());
|
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||||
Location defaultLocation = createMock(Location.class);
|
Location defaultLocation = createMock(Location.class);
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
|
||||||
|
expect(optionsProvider.get()).andReturn(from).atLeastOnce();
|
||||||
|
|
||||||
replay(defaultLocation);
|
replay(defaultLocation);
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
template.imageId("foo").options(TemplateOptions.NONE).locationId("location").build();
|
template.imageId("foo").options(provideTemplateOptions()).locationId(
|
||||||
|
"location").build();
|
||||||
assert false;
|
assert false;
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
|
|
||||||
|
@ -399,10 +421,10 @@ public class TemplateBuilderImplTest {
|
||||||
public void testDefaultLocationWithNoOptionsNoSuchElement() {
|
public void testDefaultLocationWithNoOptionsNoSuchElement() {
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
Provider<Set<? extends Image>> images = Providers
|
||||||
.<Image> of());
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
.<Size> of());
|
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||||
Location defaultLocation = createMock(Location.class);
|
Location defaultLocation = createMock(Location.class);
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
@ -416,8 +438,8 @@ public class TemplateBuilderImplTest {
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
template.imageId("foo").build();
|
template.imageId("foo").build();
|
||||||
|
@ -432,37 +454,53 @@ public class TemplateBuilderImplTest {
|
||||||
verify(templateBuilderProvider);
|
verify(templateBuilderProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected TemplateOptions provideTemplateOptions() {
|
||||||
|
return new TemplateOptions();
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultLocationWithOptions() {
|
public void testDefaultLocationWithOptions() {
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
Provider<Set<? extends Image>> images = Providers
|
||||||
.<Image> of());
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
.<Size> of());
|
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||||
Location defaultLocation = createMock(Location.class);
|
Location defaultLocation = createMock(Location.class);
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
|
TemplateOptions from = provideTemplateOptions();
|
||||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
|
||||||
expect(defaultLocation.getId()).andReturn("foo");
|
expect(defaultLocation.getId()).andReturn("foo");
|
||||||
|
// expect(defaultLocation.getId()).andReturn("foo");
|
||||||
|
expect(optionsProvider.get()).andReturn(from);
|
||||||
|
// expect(optionsProvider.get()).andReturn(provideTemplateOptions());
|
||||||
|
|
||||||
|
expect(from.getInboundPorts()).andReturn(new int[] { 22 });
|
||||||
|
// expect(from.getRunScript()).andReturn(null);
|
||||||
|
// expect(from.getPrivateKey()).andReturn(null);
|
||||||
|
// expect(from.getPublicKey()).andReturn(null);
|
||||||
|
// expect(from.getPort()).andReturn(null);
|
||||||
|
// expect(from.isIncludeMetadata()).andReturn(false);
|
||||||
|
// expect(from.shouldBlockUntilRunning()).andReturn(true);
|
||||||
|
|
||||||
replay(defaultLocation);
|
replay(defaultLocation);
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
template.imageId("foo").options(TemplateOptions.NONE).build();
|
template.imageId("foo").options(provideTemplateOptions()).build();
|
||||||
assert false;
|
assert false;
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(defaultLocation);
|
verify(defaultLocation);
|
||||||
verify(optionsProvider);
|
// verify(optionsProvider);
|
||||||
verify(templateBuilderProvider);
|
verify(templateBuilderProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,10 +509,10 @@ public class TemplateBuilderImplTest {
|
||||||
public void testImageIdNullsEverythingElse() {
|
public void testImageIdNullsEverythingElse() {
|
||||||
Provider<Set<? extends Location>> locations = Providers
|
Provider<Set<? extends Location>> locations = Providers
|
||||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
Provider<Set<? extends Image>> images = Providers
|
||||||
.<Image> of());
|
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
Provider<Set<? extends Size>> sizes = Providers
|
||||||
.<Size> of());
|
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||||
Location defaultLocation = createMock(Location.class);
|
Location defaultLocation = createMock(Location.class);
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
@ -483,8 +521,8 @@ public class TemplateBuilderImplTest {
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
template.architecture(Architecture.X86_32);
|
template.architecture(Architecture.X86_32);
|
||||||
template.imageDescriptionMatches("imageDescriptionMatches");
|
template.imageDescriptionMatches("imageDescriptionMatches");
|
||||||
|
|
Loading…
Reference in New Issue