Class TemplateBuilderImpl
- java.lang.Object
-
- org.jclouds.compute.domain.internal.TemplateBuilderImpl
-
- All Implemented Interfaces:
TemplateBuilder
- Direct Known Subclasses:
ArbitraryCpuRamTemplateBuilderImpl
,EC2TemplateBuilderImpl
public class TemplateBuilderImpl extends Object implements TemplateBuilder
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
biggest
protected com.google.common.base.Supplier<Location>
defaultLocation
protected javax.inject.Provider<TemplateBuilder>
defaultTemplateProvider
protected boolean
fastest
protected Boolean
forceCacheReload
protected String
hardwareId
protected com.google.common.base.Supplier<Set<? extends Hardware>>
hardwares
protected String
hypervisor
protected com.google.common.base.Function<Iterable<? extends Image>,Image>
imageChooser
protected String
imageDescription
protected String
imageId
protected String
imageName
protected com.google.common.base.Predicate<Image>
imagePredicate
protected ImageCacheSupplier
images
protected String
imageVersion
protected Location
location
protected com.google.common.base.Supplier<Set<? extends Location>>
locations
protected Logger
logger
protected double
minCores
protected double
minDisk
protected int
minRam
protected TemplateOptions
options
protected javax.inject.Provider<TemplateOptions>
optionsProvider
protected Boolean
os64Bit
protected String
osArch
protected String
osDescription
protected OsFamily
osFamily
protected String
osName
protected String
osVersion
-
Constructor Summary
Constructors Modifier Constructor Description protected
TemplateBuilderImpl(com.google.common.base.Supplier<Set<? extends Location>> locations, com.google.common.base.Supplier<Set<? extends Image>> images, com.google.common.base.Supplier<Set<? extends Hardware>> hardwares, com.google.common.base.Supplier<Location> defaultLocation, javax.inject.Provider<TemplateOptions> optionsProvider, javax.inject.Provider<TemplateBuilder> defaultTemplateProvider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TemplateBuilder
any()
prime this builder with parameters known to work on the current compute provider.TemplateBuilder
biggest()
configure this template to the largest hardware, based on cores, ram, then diskTemplate
build()
Generate an immutable template from the current builder.TemplateBuilder
fastest()
configure this template to the fastest hardware, based on cpuprotected Hardware
findHardwareWithId(Set<? extends Hardware> hardwaresToSearch)
TemplateBuilder
forceCacheReload()
Forces an image lookup against the provider to reload the image cache.TemplateBuilder
from(String spec)
Configure and return this template, updating it with the populated values of the givenspec
.TemplateBuilder
from(TemplateBuilderSpec spec)
Configure and return this template, updating it with the populated values of the givenspec
.TemplateBuilder
fromHardware(Hardware hardware)
Configure this template to require the minimum hardware of the parameter.TemplateBuilder
fromImage(Image image)
Configure this template to fuzzy-match on the image parameterTemplateBuilder
fromTemplate(Template template)
Configure this template to match the resources of the template parameter.protected Set<? extends Image>
getImages()
TemplateBuilder
hardwareId(String hardwareId)
Configure this template to require a specific hardwareId.protected com.google.common.collect.Ordering<Hardware>
hardwareSorter()
TemplateBuilder
hypervisorMatches(String hypervisor)
Configure this template to have an hypervisor that matches the regular expressionprotected com.google.common.base.Function<Iterable<? extends Image>,Image>
imageChooser()
TemplateBuilderImpl
imageChooser(com.google.common.base.Function<Iterable<? extends Image>,Image> imageChooser)
Configure this template with a specific preference function which operates on images which match the other criteria.TemplateBuilder
imageDescriptionMatches(String descriptionRegex)
Configure this template to have an image description that matches the regular expressionTemplateBuilder
imageId(String imageId)
Configure this template to require a specific imageId.TemplateBuilder
imageMatches(com.google.common.base.Predicate<Image> condition)
Configure this template to have an image that matches the supplied condition ex.TemplateBuilder
imageNameMatches(String nameRegex)
Configure this template to have an image name that matches the regular expressionTemplateBuilder
imageVersionMatches(String imageVersionRegex)
Configure this template to have an image version that matches the regular expressionTemplateBuilder
locationId(String locationId)
Configure this template to start in a specific locationTemplateBuilder
minCores(double minCores)
Configure this template to require the minimum cores belowTemplateBuilder
minDisk(double gigabytes)
Configure this template with required minimum disk space in gigabytesTemplateBuilder
minRam(int megabytes)
Configure this template to require the minimum ram in megabytes belowTemplateBuilder
options(TemplateOptions options)
Sets options on the template (i.e.TemplateBuilder
os64Bit(boolean is64Bit)
Configure this template to require a 64 bit operating system.TemplateBuilder
osArchMatches(String osArchitectureRegex)
Configure this template to require a specific architecture.TemplateBuilder
osDescriptionMatches(String osDescriptionRegex)
Configure this template to have an operating system description that matches the regular expressionTemplateBuilder
osFamily(OsFamily os)
Configure this template to use a specific operating system image.TemplateBuilder
osNameMatches(String osNameRegex)
Configure this template to have an operating system name that matches the regular expressionTemplateBuilder
osVersionMatches(String osVersionRegex)
Configure this template to have an os version that matches the regular expressionprotected Hardware
resolveHardware(Set<? extends Hardware> hardwarel, Iterable<? extends Image> images)
protected Image
resolveImage(Hardware hardware, Iterable<? extends Image> supportedImages)
TemplateBuilder
smallest()
configure this template to the smallest hardware, based on cores, ram, then diskprotected com.google.common.base.MoreObjects.ToStringHelper
string()
protected NoSuchElementException
throwNoSuchElementExceptionAfterLoggingHardwareIds(String message, Iterable<? extends Hardware> hardwares)
protected NoSuchElementException
throwNoSuchElementExceptionAfterLoggingImageIds(String message, Iterable<? extends Image> images)
String
toString()
-
-
-
Field Detail
-
logger
@Named("jclouds.compute") protected Logger logger
-
images
protected final ImageCacheSupplier images
-
defaultLocation
protected final com.google.common.base.Supplier<Location> defaultLocation
-
optionsProvider
protected final javax.inject.Provider<TemplateOptions> optionsProvider
-
defaultTemplateProvider
protected final javax.inject.Provider<TemplateBuilder> defaultTemplateProvider
-
location
protected Location location
-
imageId
protected String imageId
-
hardwareId
protected String hardwareId
-
hypervisor
protected String hypervisor
-
imageVersion
protected String imageVersion
-
osFamily
protected OsFamily osFamily
-
osVersion
protected String osVersion
-
os64Bit
protected Boolean os64Bit
-
osName
protected String osName
-
osDescription
protected String osDescription
-
osArch
protected String osArch
-
imageName
protected String imageName
-
imageDescription
protected String imageDescription
-
imagePredicate
protected com.google.common.base.Predicate<Image> imagePredicate
-
imageChooser
protected com.google.common.base.Function<Iterable<? extends Image>,Image> imageChooser
-
minCores
protected double minCores
-
minRam
protected int minRam
-
minDisk
protected double minDisk
-
biggest
protected boolean biggest
-
fastest
protected boolean fastest
-
options
protected TemplateOptions options
-
forceCacheReload
protected Boolean forceCacheReload
-
-
Constructor Detail
-
TemplateBuilderImpl
@Inject protected TemplateBuilderImpl(com.google.common.base.Supplier<Set<? extends Location>> locations, com.google.common.base.Supplier<Set<? extends Image>> images, com.google.common.base.Supplier<Set<? extends Hardware>> hardwares, com.google.common.base.Supplier<Location> defaultLocation, @Named("DEFAULT") javax.inject.Provider<TemplateOptions> optionsProvider, @Named("DEFAULT") javax.inject.Provider<TemplateBuilder> defaultTemplateProvider)
-
-
Method Detail
-
fromTemplate
public TemplateBuilder fromTemplate(Template template)
Configure this template to match the resources of the template parameter.- Specified by:
fromTemplate
in interfaceTemplateBuilder
-
fromHardware
public TemplateBuilder fromHardware(Hardware hardware)
Configure this template to require the minimum hardware of the parameter.- Specified by:
fromHardware
in interfaceTemplateBuilder
-
fromImage
public TemplateBuilder fromImage(Image image)
Configure this template to fuzzy-match on the image parameter- Specified by:
fromImage
in interfaceTemplateBuilder
-
smallest
public TemplateBuilder smallest()
configure this template to the smallest hardware, based on cores, ram, then disk- Specified by:
smallest
in interfaceTemplateBuilder
-
biggest
public TemplateBuilder biggest()
configure this template to the largest hardware, based on cores, ram, then disk- Specified by:
biggest
in interfaceTemplateBuilder
-
fastest
public TemplateBuilder fastest()
configure this template to the fastest hardware, based on cpu- Specified by:
fastest
in interfaceTemplateBuilder
-
locationId
public TemplateBuilder locationId(String locationId)
Configure this template to start in a specific location- Specified by:
locationId
in interfaceTemplateBuilder
-
osFamily
public TemplateBuilder osFamily(OsFamily os)
Configure this template to use a specific operating system image.- Specified by:
osFamily
in interfaceTemplateBuilder
-
build
public Template build()
Generate an immutable template from the current builder.- Specified by:
build
in interfaceTemplateBuilder
-
findHardwareWithId
protected Hardware findHardwareWithId(Set<? extends Hardware> hardwaresToSearch)
-
throwNoSuchElementExceptionAfterLoggingImageIds
protected NoSuchElementException throwNoSuchElementExceptionAfterLoggingImageIds(String message, Iterable<? extends Image> images)
-
throwNoSuchElementExceptionAfterLoggingHardwareIds
protected NoSuchElementException throwNoSuchElementExceptionAfterLoggingHardwareIds(String message, Iterable<? extends Hardware> hardwares)
-
resolveHardware
protected Hardware resolveHardware(Set<? extends Hardware> hardwarel, Iterable<? extends Image> images)
-
imageChooser
protected com.google.common.base.Function<Iterable<? extends Image>,Image> imageChooser()
-
hardwareSorter
protected com.google.common.collect.Ordering<Hardware> hardwareSorter()
-
resolveImage
protected Image resolveImage(Hardware hardware, Iterable<? extends Image> supportedImages)
- Parameters:
hardware
-supportedImages
-- Throws:
NoSuchElementException
- if there's no image that matches the predicate
-
imageId
public TemplateBuilder imageId(String imageId)
Configure this template to require a specific imageId. Note that image Ids are often scoped tolocation
- Specified by:
imageId
in interfaceTemplateBuilder
-
imageNameMatches
public TemplateBuilder imageNameMatches(String nameRegex)
Configure this template to have an image name that matches the regular expression- Specified by:
imageNameMatches
in interfaceTemplateBuilder
-
imageDescriptionMatches
public TemplateBuilder imageDescriptionMatches(String descriptionRegex)
Configure this template to have an image description that matches the regular expression- Specified by:
imageDescriptionMatches
in interfaceTemplateBuilder
-
imageMatches
public TemplateBuilder imageMatches(com.google.common.base.Predicate<Image> condition)
Configure this template to have an image that matches the supplied condition ex.builder.imageMatches(ImagePredicates.userMetadataContains("author", "sue"));
- Specified by:
imageMatches
in interfaceTemplateBuilder
-
imageChooser
public TemplateBuilderImpl imageChooser(com.google.common.base.Function<Iterable<? extends Image>,Image> imageChooser)
Configure this template with a specific preference function which operates on images which match the other criteria.If no function is supplied, jclouds will select one according to an internal strategy. This strategy may change from version to version.
- Specified by:
imageChooser
in interfaceTemplateBuilder
-
imageVersionMatches
public TemplateBuilder imageVersionMatches(String imageVersionRegex)
Configure this template to have an image version that matches the regular expression- Specified by:
imageVersionMatches
in interfaceTemplateBuilder
-
osVersionMatches
public TemplateBuilder osVersionMatches(String osVersionRegex)
Configure this template to have an os version that matches the regular expression- Specified by:
osVersionMatches
in interfaceTemplateBuilder
-
osArchMatches
public TemplateBuilder osArchMatches(String osArchitectureRegex)
Configure this template to require a specific architecture. ex. virtualizationType or- Specified by:
osArchMatches
in interfaceTemplateBuilder
-
minCores
public TemplateBuilder minCores(double minCores)
Configure this template to require the minimum cores below- Specified by:
minCores
in interfaceTemplateBuilder
-
minRam
public TemplateBuilder minRam(int megabytes)
Configure this template to require the minimum ram in megabytes below- Specified by:
minRam
in interfaceTemplateBuilder
-
minDisk
public TemplateBuilder minDisk(double gigabytes)
Configure this template with required minimum disk space in gigabytes- Specified by:
minDisk
in interfaceTemplateBuilder
-
osNameMatches
public TemplateBuilder osNameMatches(String osNameRegex)
Configure this template to have an operating system name that matches the regular expression- Specified by:
osNameMatches
in interfaceTemplateBuilder
-
osDescriptionMatches
public TemplateBuilder osDescriptionMatches(String osDescriptionRegex)
Configure this template to have an operating system description that matches the regular expression- Specified by:
osDescriptionMatches
in interfaceTemplateBuilder
-
hardwareId
public TemplateBuilder hardwareId(String hardwareId)
Configure this template to require a specific hardwareId.- Specified by:
hardwareId
in interfaceTemplateBuilder
-
hypervisorMatches
public TemplateBuilder hypervisorMatches(String hypervisor)
Configure this template to have an hypervisor that matches the regular expression- Specified by:
hypervisorMatches
in interfaceTemplateBuilder
-
options
public TemplateBuilder options(TemplateOptions options)
Sets options on the template (i.e. items which adorn a created node rather than restricting selection of the node). Note that this method typically replaces any options previously specified in the builder. Normal usage is to build up all options and pass them to the builder with a single call to this method.- Specified by:
options
in interfaceTemplateBuilder
-
any
public TemplateBuilder any()
prime this builder with parameters known to work on the current compute provider.- Specified by:
any
in interfaceTemplateBuilder
-
string
protected com.google.common.base.MoreObjects.ToStringHelper string()
- Since:
- 1.5
-
os64Bit
public TemplateBuilder os64Bit(boolean is64Bit)
Description copied from interface:TemplateBuilder
Configure this template to require a 64 bit operating system.- Specified by:
os64Bit
in interfaceTemplateBuilder
-
from
public TemplateBuilder from(TemplateBuilderSpec spec)
Description copied from interface:TemplateBuilder
Configure and return this template, updating it with the populated values of the givenspec
.- Specified by:
from
in interfaceTemplateBuilder
-
from
public TemplateBuilder from(String spec)
Description copied from interface:TemplateBuilder
Configure and return this template, updating it with the populated values of the givenspec
. This is especially useful for command-line configuration of aTemplateBuilder
.- Specified by:
from
in interfaceTemplateBuilder
- Parameters:
spec
- a String in the format specified byTemplateBuilderSpec
-
forceCacheReload
public TemplateBuilder forceCacheReload()
Description copied from interface:TemplateBuilder
Forces an image lookup against the provider to reload the image cache.Use with caution. In some providers getting the list of images is an expensive operation, and the use of the image cache is recommended. If there is a need to minimize the amount of time the images are cached, consider configuring the cache expiration time by setting the
Constants.PROPERTY_SESSION_INTERVAL
property.- Specified by:
forceCacheReload
in interfaceTemplateBuilder
-
-