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 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.Size;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
|
@ -28,15 +29,35 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
|
|||
private final ConcurrentMap<RegionAndName, Image> imageMap;
|
||||
|
||||
@Inject
|
||||
protected EC2TemplateBuilderImpl(Provider<Set<? extends Location>> locations,
|
||||
Provider<Set<? extends Image>> images, Provider<Set<? extends Size>> sizes,
|
||||
Location defaultLocation, Provider<TemplateOptions> optionsProvider,
|
||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider,
|
||||
ConcurrentMap<RegionAndName, Image> imageMap) {
|
||||
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
|
||||
protected EC2TemplateBuilderImpl(
|
||||
Provider<Set<? extends Location>> locations,
|
||||
Provider<Set<? extends Image>> images,
|
||||
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider,
|
||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider,
|
||||
ConcurrentMap<RegionAndName, Image> imageMap) {
|
||||
super(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
defaultTemplateProvider);
|
||||
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
|
||||
* if the image is not found
|
||||
|
@ -51,8 +72,8 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
|
|||
try {
|
||||
return ImmutableList.of(imageMap.get(key));
|
||||
} catch (NullPointerException nex) {
|
||||
throw new NoSuchElementException(String.format("image %s/%s not found", key
|
||||
.getRegion(), key.getName()));
|
||||
throw new NoSuchElementException(String.format(
|
||||
"image %s/%s not found", key.getRegion(), key.getName()));
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
|
|
|
@ -99,7 +99,7 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
/**
|
||||
* Specifies the subnetId used to run instances in
|
||||
*/
|
||||
public EC2TemplateOptions withSubnetId(String subnetId) {
|
||||
public EC2TemplateOptions subnetId(String subnetId) {
|
||||
checkNotNull(subnetId, "subnetId cannot be null");
|
||||
Utils.checkNotEmpty(subnetId, "subnetId must be non-empty");
|
||||
this.subnetId = subnetId;
|
||||
|
@ -192,9 +192,9 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
/**
|
||||
* @see TemplateOptions#withSubnetId
|
||||
*/
|
||||
public static EC2TemplateOptions withSubnetId(String subnetId) {
|
||||
public static EC2TemplateOptions subnetId(String subnetId) {
|
||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||
return EC2TemplateOptions.class.cast(options.withSubnetId(subnetId));
|
||||
return EC2TemplateOptions.class.cast(options.subnetId(subnetId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -286,14 +286,15 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((groupIds == null) ? 0 : groupIds.hashCode());
|
||||
result = prime * result + ((keyPair == null) ? 0 : keyPair.hashCode());
|
||||
result = prime * result + (noKeyPair ? 1231 : 1237);
|
||||
return result;
|
||||
}
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((groupIds == null) ? 0 : groupIds.hashCode());
|
||||
result = prime * result + ((keyPair == null) ? 0 : keyPair.hashCode());
|
||||
result = prime * result + (noKeyPair ? 1231 : 1237);
|
||||
result = prime * result + ((subnetId == null) ? 0 : subnetId.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
@ -316,7 +317,10 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
return false;
|
||||
if (noKeyPair != other.noKeyPair)
|
||||
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 true;
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
|
||||
//options.as(EC2TemplateOptions.class).securityGroups(tag);
|
||||
options.as(EC2TemplateOptions.class).keyPair(tag);
|
||||
options.as(EC2TemplateOptions.class).withSubnetId(subnetId);
|
||||
options.as(EC2TemplateOptions.class).subnetId(subnetId);
|
||||
|
||||
String startedId = null;
|
||||
String nodeId = null;
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.util.concurrent.ConcurrentMap;
|
|||
import javax.inject.Provider;
|
||||
|
||||
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.Image;
|
||||
import org.jclouds.compute.domain.Size;
|
||||
|
@ -64,41 +65,50 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
Image knownImage = createNiceMock(Image.class);
|
||||
|
||||
ConcurrentMap<RegionAndName, Image> imageMap = new MapMaker()
|
||||
.makeComputingMap(new Function<RegionAndName, Image>() {
|
||||
@Override
|
||||
public Image apply(RegionAndName from) {
|
||||
return from.equals(knownRegionAndName) ? knownImage : null;
|
||||
}
|
||||
.makeComputingMap(new Function<RegionAndName, Image>() {
|
||||
@Override
|
||||
public Image apply(RegionAndName from) {
|
||||
return from.equals(knownRegionAndName) ? knownImage : null;
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@BeforeTest
|
||||
void setup() {
|
||||
knownImage = createNiceMock(Image.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TemplateOptions provideTemplateOptions() {
|
||||
return new EC2TemplateOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EC2TemplateBuilderImpl createTemplateBuilder(
|
||||
Provider<Set<? extends Location>> locations, Provider<Set<? extends Image>> images,
|
||||
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider,
|
||||
Provider<TemplateBuilder> templateBuilderProvider) {
|
||||
return new EC2TemplateBuilderImpl(locations, images, sizes, defaultLocation, optionsProvider,
|
||||
templateBuilderProvider, imageMap);
|
||||
Provider<Set<? extends Location>> locations,
|
||||
Provider<Set<? extends Image>> images,
|
||||
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider,
|
||||
Provider<TemplateBuilder> templateBuilderProvider) {
|
||||
return new EC2TemplateBuilderImpl(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider, imageMap);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
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
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(location));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap
|
||||
.<String, String> of(), 1, 1, 1, ImagePredicates.any())));
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(location));
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of(new SizeImpl("1", "1", "region/1", location, null,
|
||||
ImmutableMap.<String, String> of(), 1, 1, 1,
|
||||
ImagePredicates.any())));
|
||||
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
|
@ -116,8 +126,8 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
|
||||
assertEquals(template.imageId("ami").build().getImage(), knownImage);
|
||||
|
||||
|
@ -131,15 +141,18 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Test(expectedExceptions = NoSuchElementException.class)
|
||||
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
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(location));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap
|
||||
.<String, String> of(), 1, 1, 1, ImagePredicates.any())));
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(location));
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of(new SizeImpl("1", "1", "region/1", location, null,
|
||||
ImmutableMap.<String, String> of(), 1, 1, 1,
|
||||
ImagePredicates.any())));
|
||||
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
|
@ -149,7 +162,8 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
|
||||
expect(defaultLocation.getId()).andReturn("region");
|
||||
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||
expect(knownImage.getArchitecture()).andReturn(Architecture.X86_32).atLeastOnce();
|
||||
expect(knownImage.getArchitecture()).andReturn(Architecture.X86_32)
|
||||
.atLeastOnce();
|
||||
|
||||
replay(knownImage);
|
||||
replay(defaultOptions);
|
||||
|
@ -157,8 +171,8 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
|
||||
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 java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
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 Size>> sizes;
|
||||
private final Provider<Set<? extends Location>> locations;
|
||||
private final Provider<TemplateOptions> optionsProvider;
|
||||
protected final Provider<TemplateOptions> optionsProvider;
|
||||
private final Provider<TemplateBuilder> defaultTemplateProvider;
|
||||
private final Location defaultLocation;
|
||||
|
||||
|
@ -102,9 +103,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
|
||||
@Inject
|
||||
protected TemplateBuilderImpl(Provider<Set<? extends Location>> locations,
|
||||
Provider<Set<? extends Image>> images, Provider<Set<? extends Size>> sizes,
|
||||
Location defaultLocation, Provider<TemplateOptions> optionsProvider,
|
||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
||||
Provider<Set<? extends Image>> images,
|
||||
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider,
|
||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
||||
this.locations = locations;
|
||||
this.images = images;
|
||||
this.sizes = sizes;
|
||||
|
@ -170,10 +172,15 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
returnVal = false;
|
||||
else
|
||||
returnVal = input.getOsDescription().contains(osDescription)
|
||||
|| input.getOsDescription().matches(osDescription); /*
|
||||
* note: matches()
|
||||
* expects a regex!
|
||||
*/
|
||||
|| input.getOsDescription().matches(osDescription); /*
|
||||
* note:
|
||||
* matches
|
||||
* ()
|
||||
* expects
|
||||
* a
|
||||
* regex
|
||||
* !
|
||||
*/
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
|
@ -187,10 +194,12 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
returnVal = false;
|
||||
else
|
||||
returnVal = input.getVersion().contains(imageVersion)
|
||||
|| input.getVersion().matches(imageVersion); /*
|
||||
* note: matches() expects a
|
||||
* regex!
|
||||
*/
|
||||
|| input.getVersion().matches(imageVersion); /*
|
||||
* note:
|
||||
* matches()
|
||||
* expects a
|
||||
* regex!
|
||||
*/
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
|
@ -204,7 +213,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
returnVal = false;
|
||||
else
|
||||
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;
|
||||
}
|
||||
|
@ -218,11 +230,16 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
returnVal = false;
|
||||
else
|
||||
returnVal = input.getDescription().equals(imageDescription)
|
||||
|| input.getDescription().contains(imageDescription)
|
||||
|| input.getDescription().matches(imageDescription); /*
|
||||
* note: matches()
|
||||
* expects a regex!
|
||||
*/
|
||||
|| input.getDescription().contains(imageDescription)
|
||||
|| input.getDescription().matches(imageDescription); /*
|
||||
* note:
|
||||
* matches
|
||||
* ()
|
||||
* expects
|
||||
* a
|
||||
* regex
|
||||
* !
|
||||
*/
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
|
@ -255,13 +272,15 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
return input.getRam() >= TemplateBuilderImpl.this.minRam;
|
||||
}
|
||||
};
|
||||
private final Predicate<Size> sizePredicate = Predicates.and(sizeIdPredicate, locationPredicate,
|
||||
sizeCoresPredicate, sizeRamPredicate);
|
||||
private final Predicate<Size> sizePredicate = Predicates.and(
|
||||
sizeIdPredicate, locationPredicate, sizeCoresPredicate,
|
||||
sizeRamPredicate);
|
||||
|
||||
static final Ordering<Size> DEFAULT_SIZE_ORDERING = new Ordering<Size>() {
|
||||
public int compare(Size left, Size right) {
|
||||
return ComparisonChain.start().compare(left.getCores(), right.getCores()).compare(
|
||||
left.getRam(), right.getRam()).compare(left.getDisk(), right.getDisk()).result();
|
||||
return ComparisonChain.start().compare(left.getCores(),
|
||||
right.getCores()).compare(left.getRam(), right.getRam())
|
||||
.compare(left.getDisk(), right.getDisk()).result();
|
||||
}
|
||||
};
|
||||
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>() {
|
||||
public int compare(Image left, Image right) {
|
||||
return ComparisonChain.start().compare(left.getName(), right.getName(),
|
||||
Ordering.<String> natural().nullsLast()).compare(left.getVersion(),
|
||||
right.getVersion(), Ordering.<String> natural().nullsLast()).compare(
|
||||
left.getOsDescription(), right.getOsDescription(),
|
||||
Ordering.<String> natural().nullsLast()).compare(left.getArchitecture(),
|
||||
right.getArchitecture()).result();
|
||||
return ComparisonChain.start().compare(left.getName(),
|
||||
right.getName(), Ordering.<String> natural().nullsLast())
|
||||
.compare(left.getVersion(), right.getVersion(),
|
||||
Ordering.<String> natural().nullsLast()).compare(
|
||||
left.getOsDescription(), right.getOsDescription(),
|
||||
Ordering.<String> natural().nullsLast()).compare(
|
||||
left.getArchitecture(), right.getArchitecture()).result();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -414,42 +434,46 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
}
|
||||
|
||||
protected Location resolveLocation() {
|
||||
Location location = Iterables.find(locations.get(), new Predicate<Location>() {
|
||||
Location location = Iterables.find(locations.get(),
|
||||
new Predicate<Location>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Location input) {
|
||||
return input.getId().equals(locationId);
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Location input) {
|
||||
return input.getId().equals(locationId);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
logger.debug("<< matched location(%s)", 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;
|
||||
try {
|
||||
Iterable<? extends Size> sizesThatAreCompatibleWithOurImages = Iterables.filter(sizes
|
||||
.get(), new Predicate<Size>() {
|
||||
@Override
|
||||
public boolean apply(final Size size) {
|
||||
boolean returnVal = false;
|
||||
if (size != null)
|
||||
returnVal = Iterables.any(images, new Predicate<Image>() {
|
||||
Iterable<? extends Size> sizesThatAreCompatibleWithOurImages = Iterables
|
||||
.filter(sizes.get(), new Predicate<Size>() {
|
||||
@Override
|
||||
public boolean apply(final Size size) {
|
||||
boolean returnVal = false;
|
||||
if (size != null)
|
||||
returnVal = Iterables.any(images,
|
||||
new Predicate<Image>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Image input) {
|
||||
return size.supportsImage(input);
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Image input) {
|
||||
return size.supportsImage(input);
|
||||
}
|
||||
|
||||
});
|
||||
return returnVal;
|
||||
}
|
||||
});
|
||||
size = sizeOrdering.max(Iterables.filter(sizesThatAreCompatibleWithOurImages,
|
||||
sizePredicate));
|
||||
});
|
||||
return returnVal;
|
||||
}
|
||||
});
|
||||
size = sizeOrdering.max(Iterables.filter(
|
||||
sizesThatAreCompatibleWithOurImages, sizePredicate));
|
||||
} 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);
|
||||
return size;
|
||||
|
@ -460,7 +484,8 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
if (!biggest)
|
||||
sizeOrdering = sizeOrdering.reverse();
|
||||
if (fastest)
|
||||
sizeOrdering = Ordering.compound(ImmutableList.of(BY_CORES_ORDERING, sizeOrdering));
|
||||
sizeOrdering = Ordering.compound(ImmutableList.of(BY_CORES_ORDERING,
|
||||
sizeOrdering));
|
||||
return sizeOrdering;
|
||||
}
|
||||
|
||||
|
@ -472,15 +497,18 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
protected List<? extends Image> resolveImages() {
|
||||
Predicate<Image> imagePredicate = buildImagePredicate();
|
||||
try {
|
||||
Iterable<? extends Image> matchingImages = Iterables.filter(images.get(), imagePredicate);
|
||||
Iterable<? extends Image> matchingImages = Iterables.filter(images
|
||||
.get(), imagePredicate);
|
||||
if (logger.isTraceEnabled())
|
||||
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())
|
||||
logger.trace("<< best images(%s)", maxImages);
|
||||
return maxImages;
|
||||
} 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
|
||||
public TemplateBuilder options(TemplateOptions options) {
|
||||
this.options = checkNotNull(options, "options");
|
||||
this.options = optionsProvider.get();
|
||||
copyTemplateOptions(checkNotNull(options, "options"), this.options);
|
||||
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
|
||||
boolean nothingChangedExceptOptions() {
|
||||
return os == null && arch == null && locationId == null && imageId == null && sizeId == null
|
||||
&& osDescription == null && imageVersion == null && imageName == null
|
||||
&& imageDescription == null && minCores == 0 && minRam == 0 && !biggest && !fastest;
|
||||
return os == null && arch == null && locationId == null
|
||||
&& imageId == null && sizeId == null && osDescription == null
|
||||
&& imageVersion == null && imageName == null
|
||||
&& imageDescription == null && minCores == 0 && minRam == 0
|
||||
&& !biggest && !fastest;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -613,11 +661,12 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[arch=" + arch + ", biggest=" + biggest + ", fastest=" + fastest + ", imageName="
|
||||
+ imageName + ", imageDescription=" + imageDescription + ", imageId=" + imageId
|
||||
+ ", imageVersion=" + imageVersion + ", location=" + locationId + ", minCores="
|
||||
+ minCores + ", minRam=" + minRam + ", os=" + os + ", osDescription="
|
||||
+ osDescription + ", sizeId=" + sizeId + "]";
|
||||
return "[arch=" + arch + ", biggest=" + biggest + ", fastest=" + fastest
|
||||
+ ", imageName=" + imageName + ", imageDescription="
|
||||
+ imageDescription + ", imageId=" + imageId + ", imageVersion="
|
||||
+ imageVersion + ", location=" + locationId + ", minCores="
|
||||
+ minCores + ", minRam=" + minRam + ", os=" + os
|
||||
+ ", osDescription=" + osDescription + ", sizeId=" + sizeId + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -339,53 +339,53 @@ public class TemplateOptions {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (blockUntilRunning ? 1231 : 1237);
|
||||
result = prime * result + Arrays.hashCode(inboundPorts);
|
||||
result = prime * result + (includeMetadata ? 1231 : 1237);
|
||||
result = prime * result + port;
|
||||
result = prime * result
|
||||
+ ((privateKey == null) ? 0 : privateKey.hashCode());
|
||||
result = prime * result
|
||||
+ ((publicKey == null) ? 0 : publicKey.hashCode());
|
||||
result = prime * result + Arrays.hashCode(script);
|
||||
result = prime * result + seconds;
|
||||
return result;
|
||||
}
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (blockUntilRunning ? 1231 : 1237);
|
||||
result = prime * result + Arrays.hashCode(inboundPorts);
|
||||
result = prime * result + (includeMetadata ? 1231 : 1237);
|
||||
result = prime * result + port;
|
||||
result = prime * result
|
||||
+ ((privateKey == null) ? 0 : privateKey.hashCode());
|
||||
result = prime * result
|
||||
+ ((publicKey == null) ? 0 : publicKey.hashCode());
|
||||
result = prime * result + Arrays.hashCode(script);
|
||||
result = prime * result + seconds;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TemplateOptions other = (TemplateOptions) obj;
|
||||
if (blockUntilRunning != other.blockUntilRunning)
|
||||
return false;
|
||||
if (!Arrays.equals(inboundPorts, other.inboundPorts))
|
||||
return false;
|
||||
if (includeMetadata != other.includeMetadata)
|
||||
return false;
|
||||
if (port != other.port)
|
||||
return false;
|
||||
if (privateKey == null) {
|
||||
if (other.privateKey != null)
|
||||
return false;
|
||||
} else if (!privateKey.equals(other.privateKey))
|
||||
return false;
|
||||
if (publicKey == null) {
|
||||
if (other.publicKey != null)
|
||||
return false;
|
||||
} else if (!publicKey.equals(other.publicKey))
|
||||
return false;
|
||||
if (!Arrays.equals(script, other.script))
|
||||
return false;
|
||||
if (seconds != other.seconds)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TemplateOptions other = (TemplateOptions) obj;
|
||||
if (blockUntilRunning != other.blockUntilRunning)
|
||||
return false;
|
||||
if (!Arrays.equals(inboundPorts, other.inboundPorts))
|
||||
return false;
|
||||
if (includeMetadata != other.includeMetadata)
|
||||
return false;
|
||||
if (port != other.port)
|
||||
return false;
|
||||
if (privateKey == null) {
|
||||
if (other.privateKey != null)
|
||||
return false;
|
||||
} else if (!privateKey.equals(other.privateKey))
|
||||
return false;
|
||||
if (publicKey == null) {
|
||||
if (other.publicKey != null)
|
||||
return false;
|
||||
} else if (!publicKey.equals(other.publicKey))
|
||||
return false;
|
||||
if (!Arrays.equals(script, other.script))
|
||||
return false;
|
||||
if (seconds != other.seconds)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,15 +58,17 @@ public class TemplateBuilderImplTest {
|
|||
Image image = createMock(Image.class);
|
||||
Image image2 = createMock(Image.class);
|
||||
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap
|
||||
.<String, String> of(), 1.0, 0, 0, ImagePredicates.any());
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null,
|
||||
ImmutableMap.<String, String> of(), 1.0, 0, 0, ImagePredicates
|
||||
.any());
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of(image, image2));
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of(size));
|
||||
.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of(image, image2));
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||
|
@ -77,8 +79,10 @@ public class TemplateBuilderImplTest {
|
|||
expect(image2.getVersion()).andReturn("version");
|
||||
expect(image.getOsDescription()).andReturn("osDescription");
|
||||
expect(image2.getOsDescription()).andReturn("osDescription");
|
||||
expect(image.getArchitecture()).andReturn(Architecture.X86_64).atLeastOnce();
|
||||
expect(image2.getArchitecture()).andReturn(Architecture.X86_64).atLeastOnce();
|
||||
expect(image.getArchitecture()).andReturn(Architecture.X86_64)
|
||||
.atLeastOnce();
|
||||
expect(image2.getArchitecture()).andReturn(Architecture.X86_64)
|
||||
.atLeastOnce();
|
||||
|
||||
replay(image);
|
||||
replay(image2);
|
||||
|
@ -87,8 +91,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
|
||||
assertEquals(template.resolveImages(), images.get());
|
||||
|
||||
|
@ -107,15 +111,17 @@ public class TemplateBuilderImplTest {
|
|||
Image image = createMock(Image.class);
|
||||
Image image2 = createMock(Image.class);
|
||||
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap
|
||||
.<String, String> of(), 1.0, 0, 0, ImagePredicates.any());
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null,
|
||||
ImmutableMap.<String, String> of(), 1.0, 0, 0, ImagePredicates
|
||||
.any());
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of(image, image2));
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of(size));
|
||||
.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of(image, image2));
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||
|
@ -124,10 +130,12 @@ public class TemplateBuilderImplTest {
|
|||
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
||||
|
||||
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.getArchitecture()).andReturn(Architecture.X86_64).atLeastOnce();
|
||||
expect(image2.getArchitecture()).andReturn(Architecture.X86_64)
|
||||
.atLeastOnce();
|
||||
|
||||
replay(image);
|
||||
replay(image2);
|
||||
|
@ -136,10 +144,11 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
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(image2);
|
||||
|
@ -154,15 +163,17 @@ public class TemplateBuilderImplTest {
|
|||
public void testSizeWithImageIdPredicateOnlyAcceptsImage() {
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Image image = createMock(Image.class);
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap
|
||||
.<String, String> of(), 0, 0, 0, ImagePredicates.idEquals("imageId"));
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null,
|
||||
ImmutableMap.<String, String> of(), 0, 0, 0, ImagePredicates
|
||||
.idEquals("imageId"));
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of(image));
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of(size));
|
||||
.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of(image));
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||
|
@ -184,8 +195,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
|
||||
template.imageId("imageId").build();
|
||||
|
||||
|
@ -201,15 +212,17 @@ public class TemplateBuilderImplTest {
|
|||
public void testSizeWithImageIdPredicateOnlyDoesntImage() {
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Image image = createMock(Image.class);
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap
|
||||
.<String, String> of(), 0, 0, 0, ImagePredicates.idEquals("imageId"));
|
||||
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null,
|
||||
ImmutableMap.<String, String> of(), 0, 0, 0, ImagePredicates
|
||||
.idEquals("imageId"));
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of(image));
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of(size));
|
||||
.<Set<? extends Location>> of(ImmutableSet
|
||||
.<Location> of(defaultLocation));
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of(image));
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of(size));
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||
|
@ -231,8 +244,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
try {
|
||||
template.imageId("notImageId").build();
|
||||
assert false;
|
||||
|
@ -248,14 +261,15 @@ public class TemplateBuilderImplTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testOptionsUsesDefaultTemplateBuilder() {
|
||||
TemplateOptions options = new TemplateOptions();
|
||||
TemplateOptions options = provideTemplateOptions();
|
||||
TemplateOptions from = provideTemplateOptions();
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of());
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
@ -264,14 +278,15 @@ public class TemplateBuilderImplTest {
|
|||
expect(templateBuilderProvider.get()).andReturn(defaultTemplate);
|
||||
expect(defaultTemplate.options(options)).andReturn(defaultTemplate);
|
||||
expect(defaultTemplate.build()).andReturn(null);
|
||||
expect(optionsProvider.get()).andReturn(from).atLeastOnce();
|
||||
|
||||
replay(defaultTemplate);
|
||||
replay(defaultLocation);
|
||||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
|
||||
template.options(options).build();
|
||||
|
||||
|
@ -286,11 +301,11 @@ public class TemplateBuilderImplTest {
|
|||
public void testNothingUsesDefaultTemplateBuilder() {
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of());
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
|
@ -305,8 +320,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
|
||||
template.build();
|
||||
|
||||
|
@ -316,12 +331,14 @@ public class TemplateBuilderImplTest {
|
|||
verify(templateBuilderProvider);
|
||||
}
|
||||
|
||||
protected TemplateBuilderImpl createTemplateBuilder(Provider<Set<? extends Location>> locations,
|
||||
Provider<Set<? extends Image>> images, Provider<Set<? extends Size>> sizes,
|
||||
Location defaultLocation, Provider<TemplateOptions> optionsProvider,
|
||||
Provider<TemplateBuilder> templateBuilderProvider) {
|
||||
TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
protected TemplateBuilderImpl createTemplateBuilder(
|
||||
Provider<Set<? extends Location>> locations,
|
||||
Provider<Set<? extends Image>> images,
|
||||
Provider<Set<? extends Size>> sizes, Location defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider,
|
||||
Provider<TemplateBuilder> templateBuilderProvider) {
|
||||
TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
return template;
|
||||
}
|
||||
|
||||
|
@ -329,11 +346,11 @@ public class TemplateBuilderImplTest {
|
|||
@Test
|
||||
public void testSuppliedLocationWithNoOptions() {
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of());
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
@ -346,8 +363,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
|
||||
try {
|
||||
template.imageId("foo").locationId("location").build();
|
||||
|
@ -365,25 +382,30 @@ public class TemplateBuilderImplTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSuppliedLocationAndOptions() {
|
||||
TemplateOptions from = provideTemplateOptions();
|
||||
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of());
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
||||
expect(optionsProvider.get()).andReturn(from).atLeastOnce();
|
||||
|
||||
replay(defaultLocation);
|
||||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
|
||||
try {
|
||||
template.imageId("foo").options(TemplateOptions.NONE).locationId("location").build();
|
||||
template.imageId("foo").options(provideTemplateOptions()).locationId(
|
||||
"location").build();
|
||||
assert false;
|
||||
} catch (NoSuchElementException e) {
|
||||
|
||||
|
@ -398,11 +420,11 @@ public class TemplateBuilderImplTest {
|
|||
@Test
|
||||
public void testDefaultLocationWithNoOptionsNoSuchElement() {
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of());
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
@ -416,8 +438,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
|
||||
try {
|
||||
template.imageId("foo").build();
|
||||
|
@ -432,37 +454,53 @@ public class TemplateBuilderImplTest {
|
|||
verify(templateBuilderProvider);
|
||||
}
|
||||
|
||||
protected TemplateOptions provideTemplateOptions() {
|
||||
return new TemplateOptions();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testDefaultLocationWithOptions() {
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of());
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
TemplateOptions from = provideTemplateOptions();
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
||||
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(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
|
||||
try {
|
||||
template.imageId("foo").options(TemplateOptions.NONE).build();
|
||||
template.imageId("foo").options(provideTemplateOptions()).build();
|
||||
assert false;
|
||||
} catch (NoSuchElementException e) {
|
||||
|
||||
}
|
||||
|
||||
verify(defaultLocation);
|
||||
verify(optionsProvider);
|
||||
// verify(optionsProvider);
|
||||
verify(templateBuilderProvider);
|
||||
}
|
||||
|
||||
|
@ -470,11 +508,11 @@ public class TemplateBuilderImplTest {
|
|||
@Test
|
||||
public void testImageIdNullsEverythingElse() {
|
||||
Provider<Set<? extends Location>> locations = Providers
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
|
||||
.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers.<Set<? extends Size>> of(ImmutableSet
|
||||
.<Size> of());
|
||||
.<Set<? extends Location>> of(ImmutableSet.<Location> of());
|
||||
Provider<Set<? extends Image>> images = Providers
|
||||
.<Set<? extends Image>> of(ImmutableSet.<Image> of());
|
||||
Provider<Set<? extends Size>> sizes = Providers
|
||||
.<Set<? extends Size>> of(ImmutableSet.<Size> of());
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
@ -483,8 +521,8 @@ public class TemplateBuilderImplTest {
|
|||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
|
||||
defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
TemplateBuilderImpl template = createTemplateBuilder(locations, images,
|
||||
sizes, defaultLocation, optionsProvider, templateBuilderProvider);
|
||||
|
||||
template.architecture(Architecture.X86_32);
|
||||
template.imageDescriptionMatches("imageDescriptionMatches");
|
||||
|
|
Loading…
Reference in New Issue