Brooklyn

brooklyn.location.basic.jclouds.pool
[Java] Class MachinePool

java.lang.Object
  brooklyn.location.basic.jclouds.pool.MachinePool

public class MachinePool

Contains details of machines detected at a given cloud (ComputeService), and records claims made against those machines via this pool.

Machine instances themselves are persisted and rescanned as new instances of this class are created. Claims however are specific to this instance of the class, i.e. not persisted.

This class is believed to be thread-safe. Refreshes to the remote detected machines are synchronized on the pool instance. Details of detected and claimed machines are also synchronized on the pool instance. (If it is necessary to claim machines whilst the pool is being rescanned, we can investigate a more sophisticated threading model. Access to some fields is clearly independent and uses a tighter synchonization strategy, e.g. templates. Synchronization of fields within a synch block on the class instance is permitted, but not the other way round, and synching on multiple fields is also not permitted.)

Callers wishing to guarantee results of e.g. ensureUnclaimed remaining available can synchronize on this class for the duration that they wish to have that guarantee (at the cost, of course, of any other threads being able to access this pool).

If underlying provisioning/destroying operations fail, the pool currently may be in an unknown state, currently. If more robustness is needed this can be added.


Field Summary
protected ComputeService computeService

 
Constructor Summary
MachinePool(ComputeService computeService)

 
Method Summary
void addToBlacklist(MachineSet newToBlacklist)

MachineSet all()

all machines matching any templates

MachineSet all(Predicate criterion)

returns all machines matching the given criteria (may be claimed)

MachineSet all(Predicate... ops)

returns all machines matching the given criteria (may be claimed)

MachineSet claim(int count, ReusableMachineTemplate t)

claims the indicated number of machines with the indicated spec, creating if necessary

MachineSet claim(MachineSet set)

claims the indicated set of machines; throws exception if cannot all be claimed; returns the set passed in if successful

MachineSet create(int count, ReusableMachineTemplate template)

creates the given number of machines of the indicated template

int destroy(MachineSet set)

MachineSet ensureExists(ReusableMachineTemplate template)

creates machines if necessary so that this spec exists (may already be claimed however) returns a set of all matching machines, guaranteed non-empty (but possibly some are already claimed)

MachineSet ensureExists(int count, ReusableMachineTemplate template)

creates machines if necessary so that this spec exists (may already be claimed however); returns a set of all matching machines, of size at least count (but possibly some are already claimed).

MachineSet ensureUnclaimed(ReusableMachineTemplate template)

creates machines if necessary so that this spec can subsequently be claimed; returns all such unclaimed machines, guaranteed to be non-empty.

MachineSet ensureUnclaimed(int count, ReusableMachineTemplate template)

creates machines if necessary so that this spec can subsequently be claimed; returns a set of at least count unclaimed machines

protected MachineSet filterForAllowedMachines(MachineSet input)

java.lang.String getPoolName()

pool name is used as a group/label by jclouds, for convenience only; it has no special properties for detecting matching instances (use explicit tags on the templates, for that).

java.util.List getTemplates()

java.util.Set getTemplatesMatchingInstance(NodeMetadata nm)

protected void init()

protected ReusableMachineTemplate newTemplate(java.lang.String name)

void refresh()

refreshes the pool of machines from the server (finding all instances matching the registered templates)

protected void registerNewNodes(MachineSet result, ReusableMachineTemplate template)

protected ReusableMachineTemplate registerTemplate(ReusableMachineTemplate template)

protected void registerTemplates(ReusableMachineTemplate... templatesToReg)

void setBlacklist(MachineSet newBlacklist)

replaces the blacklist set; callers should generally perform a refresh() afterwards, to trigger re-detection of blacklisted machines

void setPoolName(java.lang.String poolName)

int unclaim(MachineSet set)

MachineSet unclaimed()

machines matching any templates which have not been claimed

MachineSet unclaimed(Predicate criterion)

returns unclaimed machines matching the given criteria

MachineSet unclaimed(Predicate... criteria)

returns unclaimed machines matching the given criteria

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

computeService

protected final ComputeService computeService


 
Constructor Detail

MachinePool

public MachinePool(ComputeService computeService)


 
Method Detail

addToBlacklist

public void addToBlacklist(MachineSet newToBlacklist)


all

public MachineSet all()
all machines matching any templates


all

@SuppressWarnings("unchecked")
public MachineSet all(Predicate criterion)
returns all machines matching the given criteria (may be claimed)


all

public MachineSet all(Predicate... ops)
returns all machines matching the given criteria (may be claimed)


claim

public MachineSet claim(int count, ReusableMachineTemplate t)
claims the indicated number of machines with the indicated spec, creating if necessary


claim

public MachineSet claim(MachineSet set)
claims the indicated set of machines; throws exception if cannot all be claimed; returns the set passed in if successful


create

public MachineSet create(int count, ReusableMachineTemplate template)
creates the given number of machines of the indicated template


destroy

public int destroy(MachineSet set)


ensureExists

public MachineSet ensureExists(ReusableMachineTemplate template)
creates machines if necessary so that this spec exists (may already be claimed however) returns a set of all matching machines, guaranteed non-empty (but possibly some are already claimed)


ensureExists

public MachineSet ensureExists(int count, ReusableMachineTemplate template)
creates machines if necessary so that this spec exists (may already be claimed however); returns a set of all matching machines, of size at least count (but possibly some are already claimed). (the pool can change at any point, so this set is a best-effort but may be out of date. see javadoc comments on this class.)


ensureUnclaimed

public MachineSet ensureUnclaimed(ReusableMachineTemplate template)
creates machines if necessary so that this spec can subsequently be claimed; returns all such unclaimed machines, guaranteed to be non-empty. (the pool can change at any point, so this set is a best-effort but may be out of date. see javadoc comments on this class.)


ensureUnclaimed

public MachineSet ensureUnclaimed(int count, ReusableMachineTemplate template)
creates machines if necessary so that this spec can subsequently be claimed; returns a set of at least count unclaimed machines


filterForAllowedMachines

protected MachineSet filterForAllowedMachines(MachineSet input)


getPoolName

public java.lang.String getPoolName()
pool name is used as a group/label by jclouds, for convenience only; it has no special properties for detecting matching instances (use explicit tags on the templates, for that). defaults to name of pool class and user name. callers should set pool name before getting, if using a custom name.


getTemplates

public java.util.List getTemplates()


getTemplatesMatchingInstance

public java.util.Set getTemplatesMatchingInstance(NodeMetadata nm)


init

protected void init()


newTemplate

protected ReusableMachineTemplate newTemplate(java.lang.String name)


refresh

public void refresh()
refreshes the pool of machines from the server (finding all instances matching the registered templates)


registerNewNodes

protected void registerNewNodes(MachineSet result, ReusableMachineTemplate template)


registerTemplate

protected ReusableMachineTemplate registerTemplate(ReusableMachineTemplate template)


registerTemplates

protected void registerTemplates(ReusableMachineTemplate... templatesToReg)


setBlacklist

public void setBlacklist(MachineSet newBlacklist)
replaces the blacklist set; callers should generally perform a refresh() afterwards, to trigger re-detection of blacklisted machines


setPoolName

public void setPoolName(java.lang.String poolName)


unclaim

public int unclaim(MachineSet set)


unclaimed

public MachineSet unclaimed()
machines matching any templates which have not been claimed


unclaimed

@SuppressWarnings("unchecked")
public MachineSet unclaimed(Predicate criterion)
returns unclaimed machines matching the given criteria


unclaimed

public MachineSet unclaimed(Predicate... criteria)
returns unclaimed machines matching the given criteria


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.