mirror of https://github.com/apache/jclouds.git
Merge upstream changes to template builder
This commit is contained in:
parent
39e21ad652
commit
bd675a22eb
|
@ -181,6 +181,11 @@ public interface TemplateBuilder {
|
||||||
*/
|
*/
|
||||||
TemplateBuilder minRam(int megabytes);
|
TemplateBuilder minRam(int megabytes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure this template with required minimum disk space in gigabytes
|
||||||
|
*/
|
||||||
|
TemplateBuilder minDisk(double gigabytes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate an immutable template from the current builder.
|
* Generate an immutable template from the current builder.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -140,6 +140,7 @@ public class TemplateBuilderSpec implements Serializable {
|
||||||
.put("hardwareId", new HardwareIdParser())
|
.put("hardwareId", new HardwareIdParser())
|
||||||
.put("minCores", new MinCoresParser())
|
.put("minCores", new MinCoresParser())
|
||||||
.put("minRam", new MinRamParser())
|
.put("minRam", new MinRamParser())
|
||||||
|
.put("minDisk", new MinDiskParser())
|
||||||
.put("hypervisorMatches", new HypervisorMatchesMatchesParser())
|
.put("hypervisorMatches", new HypervisorMatchesMatchesParser())
|
||||||
.put("imageId", new ImageIdParser())
|
.put("imageId", new ImageIdParser())
|
||||||
.put("imageNameMatches", new ImageNameMatchesParser())
|
.put("imageNameMatches", new ImageNameMatchesParser())
|
||||||
|
@ -160,6 +161,8 @@ public class TemplateBuilderSpec implements Serializable {
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Integer minRam;
|
Integer minRam;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
Double minDisk;
|
||||||
|
@VisibleForTesting
|
||||||
String hypervisorMatches;
|
String hypervisorMatches;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
String imageId;
|
String imageId;
|
||||||
|
@ -238,6 +241,9 @@ public class TemplateBuilderSpec implements Serializable {
|
||||||
if (minRam != null) {
|
if (minRam != null) {
|
||||||
builder.minRam(minRam);
|
builder.minRam(minRam);
|
||||||
}
|
}
|
||||||
|
if (minDisk != null) {
|
||||||
|
builder.minDisk(minDisk);
|
||||||
|
}
|
||||||
if (hypervisorMatches != null) {
|
if (hypervisorMatches != null) {
|
||||||
builder.hypervisorMatches(hypervisorMatches);
|
builder.hypervisorMatches(hypervisorMatches);
|
||||||
}
|
}
|
||||||
|
@ -435,6 +441,16 @@ public class TemplateBuilderSpec implements Serializable {
|
||||||
spec.minRam = value;
|
spec.minRam = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Parse minDisk */
|
||||||
|
static class MinDiskParser extends DoubleParser {
|
||||||
|
@Override
|
||||||
|
protected void parseDouble(TemplateBuilderSpec spec, double value) {
|
||||||
|
checkArgument(spec.minDisk == null, "min disk was already set to ", spec.minDisk);
|
||||||
|
checkArgument(spec.hardwareId == null, "hardware id was already set to ", spec.hardwareId);
|
||||||
|
spec.minDisk = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Parse hypervisorMatches */
|
/** Parse hypervisorMatches */
|
||||||
static class HypervisorMatchesMatchesParser extends StringParser {
|
static class HypervisorMatchesMatchesParser extends StringParser {
|
||||||
|
|
|
@ -119,6 +119,8 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected int minRam;
|
protected int minRam;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
protected double minDisk;
|
||||||
|
@VisibleForTesting
|
||||||
protected boolean biggest;
|
protected boolean biggest;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected boolean fastest;
|
protected boolean fastest;
|
||||||
|
@ -392,6 +394,18 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final Predicate<Hardware> hardwareDiskPredicate = new Predicate<Hardware>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(Hardware input) {
|
||||||
|
return getSpace(input) >= TemplateBuilderImpl.this.minDisk;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "minDisk(" + minDisk + ")";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private final Predicate<Hardware> hardwareRamPredicate = new Predicate<Hardware>() {
|
private final Predicate<Hardware> hardwareRamPredicate = new Predicate<Hardware>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Hardware input) {
|
public boolean apply(Hardware input) {
|
||||||
|
@ -480,6 +494,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
this.location = hardware.getLocation();
|
this.location = hardware.getLocation();
|
||||||
this.minCores = getCores(hardware);
|
this.minCores = getCores(hardware);
|
||||||
this.minRam = hardware.getRam();
|
this.minRam = hardware.getRam();
|
||||||
|
this.minDisk = getSpace(hardware);
|
||||||
this.hypervisor = hardware.getHypervisor();
|
this.hypervisor = hardware.getHypervisor();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -932,6 +947,15 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TemplateBuilder minDisk(double gigabytes) {
|
||||||
|
this.minDisk = gigabytes;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -984,7 +1008,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
return osFamily == null && location == null && imageId == null && hardwareId == null && hypervisor == null
|
return osFamily == null && location == null && imageId == null && hardwareId == null && hypervisor == null
|
||||||
&& osName == null && imagePredicate == null && osDescription == null && imageVersion == null
|
&& osName == null && imagePredicate == null && osDescription == null && imageVersion == null
|
||||||
&& osVersion == null && osArch == null && os64Bit == null && imageName == null && imageDescription == null
|
&& osVersion == null && osArch == null && os64Bit == null && imageName == null && imageDescription == null
|
||||||
&& minCores == 0 && minRam == 0 && !biggest && !fastest;
|
&& minCores == 0 && minRam == 0 && minDisk == 0 && !biggest && !fastest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -53,6 +53,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -72,6 +73,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertEquals(spec.hardwareId, "m1.small");
|
assertEquals(spec.hardwareId, "m1.small");
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -122,6 +124,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertEquals(32, spec.minCores.intValue());
|
assertEquals(32, spec.minCores.intValue());
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -164,6 +167,26 @@ public class TemplateBuilderSpecTest {
|
||||||
assertTemplateBuilderEquivalence(templateBuilders.get().minRam(10), templateBuilders.get().from(spec));
|
assertTemplateBuilderEquivalence(templateBuilders.get().minRam(10), templateBuilders.get().from(spec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testParse_minDisk() {
|
||||||
|
TemplateBuilderSpec spec = parse("minDisk=10");
|
||||||
|
assertNull(spec.hardwareId);
|
||||||
|
assertNull(spec.minCores);
|
||||||
|
assertNull(spec.minRam);
|
||||||
|
assertEquals(spec.minDisk.doubleValue(), 10.0);
|
||||||
|
assertNull(spec.hypervisorMatches);
|
||||||
|
assertNull(spec.imageId);
|
||||||
|
assertNull(spec.imageNameMatches);
|
||||||
|
assertNull(spec.osFamily);
|
||||||
|
assertNull(spec.osVersionMatches);
|
||||||
|
assertNull(spec.os64Bit);
|
||||||
|
assertNull(spec.osArchMatches);
|
||||||
|
assertNull(spec.osDescriptionMatches);
|
||||||
|
assertNull(spec.loginUser);
|
||||||
|
assertNull(spec.authenticateSudo);
|
||||||
|
assertNull(spec.locationId);
|
||||||
|
assertTemplateBuilderEquivalence(templateBuilders.get().minRam(10), templateBuilders.get().from(spec));
|
||||||
|
}
|
||||||
|
|
||||||
public void testParse_minRamRepeated() {
|
public void testParse_minRamRepeated() {
|
||||||
try {
|
try {
|
||||||
parse("minRam=10, minRam=20");
|
parse("minRam=10, minRam=20");
|
||||||
|
@ -178,6 +201,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertEquals(spec.hypervisorMatches, "OpenVZ");
|
assertEquals(spec.hypervisorMatches, "OpenVZ");
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -206,6 +230,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertEquals(spec.imageId, "us-east-1/ami-fffffff");
|
assertEquals(spec.imageId, "us-east-1/ami-fffffff");
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -275,6 +300,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertEquals(spec.imageNameMatches, ".*w/ None.*");
|
assertEquals(spec.imageNameMatches, ".*w/ None.*");
|
||||||
|
@ -303,6 +329,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -332,6 +359,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -360,6 +388,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -388,6 +417,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -416,6 +446,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -444,6 +475,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -474,6 +506,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -505,6 +538,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
|
@ -536,6 +570,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
@ -565,6 +600,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertNull(spec.minRam);
|
assertNull(spec.minRam);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertEquals(spec.imageNameMatches, ".*w/ None.*");
|
assertEquals(spec.imageNameMatches, ".*w/ None.*");
|
||||||
|
@ -585,6 +621,7 @@ public class TemplateBuilderSpecTest {
|
||||||
assertNull(spec.hardwareId);
|
assertNull(spec.hardwareId);
|
||||||
assertNull(spec.minCores);
|
assertNull(spec.minCores);
|
||||||
assertEquals(spec.minRam.intValue(), 10);
|
assertEquals(spec.minRam.intValue(), 10);
|
||||||
|
assertNull(spec.minDisk);
|
||||||
assertNull(spec.hypervisorMatches);
|
assertNull(spec.hypervisorMatches);
|
||||||
assertNull(spec.imageId);
|
assertNull(spec.imageId);
|
||||||
assertNull(spec.imageNameMatches);
|
assertNull(spec.imageNameMatches);
|
||||||
|
|
Loading…
Reference in New Issue