public class CloudProvisioningState extends Object
We do this by keeping a record of every agent we start, and every agent we have active. That way, we can avoid over-provisioning.
The idea is that we are told what agents that the cloud is going to create, when the cloud has created them (or failed to) and when those agents have died. This way we can keep track of everything, in order to allow the cloud to make accurate decisions regarding what to create next.
Note: This is not thread-safe. Callers must do their own synchronization.Constructor and Description |
---|
CloudProvisioningState(vSphereCloud parent) |
Modifier and Type | Method and Description |
---|---|
List<CloudProvisioningRecord> |
calculateProvisionableTemplates(Iterable<vSphereCloudSlaveTemplate> templates)
Given a set of templates, returns the equivalent records.
|
int |
countNodes()
Counts all the known nodes, active, in-progress and being-deleted, across
all templates.
|
CloudProvisioningRecord |
getOrCreateRecord(vSphereCloudSlaveTemplate template)
Gets the record for the given template.
|
List<String> |
getUnwantedVMsThatNeedDeleting()
Calculates the current list of "existing but unwanted" VMs, in priority
order.
|
Boolean |
isOkToDeleteUnwantedVM(String nodeName)
To be called before commencing the deletion of a VM.
|
void |
provisionedSlaveNowActive(CloudProvisioningRecord provisionable,
String nodeName)
To be called when a newly created node (previously promised to
provisioningStarted(CloudProvisioningRecord, String) ) comes up. |
void |
provisionedSlaveNowUnwanted(String nodeName,
boolean willAttemptImmediateDeletion)
To be called when a node we created (previously told to
provisionedSlaveNowActive(CloudProvisioningRecord, String) ) is
no longer wanted and should be deleted. |
void |
provisioningEndedInError(CloudProvisioningRecord provisionable,
String nodeName)
To be called when a node that we previously promised to create (by
calling
provisioningStarted(CloudProvisioningRecord, String) )
failed to start. |
void |
provisioningStarted(CloudProvisioningRecord provisionable,
String nodeName)
To be called when we've decided to create a new node.
|
void |
pruneUnwantedRecords()
To be called every now and again to ensure that we're not caching records
that will never be valid again.
|
void |
recordExistingUnwantedVM(vSphereCloudSlaveTemplate template,
String nodeName)
To be called if we become aware that there is a VM that exist in vSphere
(that we created) which we don't want anymore.
|
void |
unwantedSlaveNotDeleted(String nodeName)
MUST be called when a node previously declared to be unwanted (previously
told to
provisionedSlaveNowUnwanted(String, boolean) ) and that
we were given clearance to delete
(isOkToDeleteUnwantedVM(String) returned true) failed to be
removed. |
void |
unwantedSlaveNowDeleted(String nodeName)
MUST be called when a node previously declared to be unwanted (previously
told to
provisionedSlaveNowUnwanted(String, boolean) ) and that
we were given clearance to delete
(isOkToDeleteUnwantedVM(String) returned true) has been
successfully removed. |
public CloudProvisioningState(vSphereCloud parent)
public void provisioningStarted(CloudProvisioningRecord provisionable, String nodeName)
provisionedSlaveNowActive(CloudProvisioningRecord, String)
or provisioningEndedInError(CloudProvisioningRecord, String)
gets called later.provisionable
- Our record for the template for the named node.nodeName
- The name of the VM.public void provisionedSlaveNowActive(CloudProvisioningRecord provisionable, String nodeName)
provisioningStarted(CloudProvisioningRecord, String)
) comes up.
Callers MUST ensure that
provisionedSlaveNowUnwanted(String, boolean)
gets called later
when we do not want it anymore.provisionable
- Our record for the template for the named node.nodeName
- The name of the VM.public void provisionedSlaveNowUnwanted(String nodeName, boolean willAttemptImmediateDeletion)
provisionedSlaveNowActive(CloudProvisioningRecord, String)
) is
no longer wanted and should be deleted.nodeName
- The name of the VM.willAttemptImmediateDeletion
- If true then the caller must attempt to delete the agent and
guarantee that they will call
unwantedSlaveNotDeleted(String)
or
unwantedSlaveNowDeleted(String)
as appropriate (just
as if they'd called isOkToDeleteUnwantedVM(String)
and been told True). If false then the caller is under no such
obligation.public Boolean isOkToDeleteUnwantedVM(String nodeName)
nodeName
- The name of the VM being deleted.unwantedSlaveNowDeleted(String)
or unwantedSlaveNotDeleted(String)
.public void unwantedSlaveNowDeleted(String nodeName)
provisionedSlaveNowUnwanted(String, boolean)
) and that
we were given clearance to delete
(isOkToDeleteUnwantedVM(String)
returned true) has been
successfully removed.nodeName
- The name of the VM that was successfully deleted.public void unwantedSlaveNotDeleted(String nodeName)
provisionedSlaveNowUnwanted(String, boolean)
) and that
we were given clearance to delete
(isOkToDeleteUnwantedVM(String)
returned true) failed to be
removed.nodeName
- The name of the VM that failed to deletepublic void recordExistingUnwantedVM(vSphereCloudSlaveTemplate template, String nodeName)
template
- The template to which the node belonged.nodeName
- The name of the node that exists (despite our wishes).public void provisioningEndedInError(CloudProvisioningRecord provisionable, String nodeName)
provisioningStarted(CloudProvisioningRecord, String)
)
failed to start.provisionable
- Our record for the template for the named node.nodeName
- The name of the VM.public void pruneUnwantedRecords()
public List<CloudProvisioningRecord> calculateProvisionableTemplates(Iterable<vSphereCloudSlaveTemplate> templates)
templates
- The templates we are interested in.CloudProvisioningRecord
.public int countNodes()
public CloudProvisioningRecord getOrCreateRecord(vSphereCloudSlaveTemplate template)
template
- The template in question.public List<String> getUnwantedVMsThatNeedDeleting()
List
they are given.Copyright © 2016–2022. All rights reserved.