Class CloudProvisioningState
java.lang.Object
org.jenkinsci.plugins.vsphere.tools.CloudProvisioningState
Utility class that works out what agents we should start up in response to
Jenkins asking us to start things.
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGiven a set of templates, returns the equivalent records.intCounts all the known nodes, active, in-progress and being-deleted, across all templates.getOrCreateRecord(vSphereCloudSlaveTemplate template) Gets the record for the given template.Calculates the current list of "existing but unwanted" VMs, in priority order.isOkToDeleteUnwantedVM(String nodeName) To be called before commencing the deletion of a VM.voidprovisionedSlaveNowActive(CloudProvisioningRecord provisionable, String nodeName) To be called when a newly created node (previously promised toprovisioningStarted(CloudProvisioningRecord, String)) comes up.voidprovisionedSlaveNowUnwanted(String nodeName, boolean willAttemptImmediateDeletion) To be called when a node we created (previously told toprovisionedSlaveNowActive(CloudProvisioningRecord, String)) is no longer wanted and should be deleted.voidprovisioningEndedInError(CloudProvisioningRecord provisionable, String nodeName) To be called when a node that we previously promised to create (by callingprovisioningStarted(CloudProvisioningRecord, String)) failed to start.voidprovisioningStarted(CloudProvisioningRecord provisionable, String nodeName) To be called when we've decided to create a new node.voidTo be called every now and again to ensure that we're not caching records that will never be valid again.voidrecordExistingUnwantedVM(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.voidunwantedSlaveNotDeleted(String nodeName) MUST be called when a node previously declared to be unwanted (previously told toprovisionedSlaveNowUnwanted(String, boolean)) and that we were given clearance to delete (isOkToDeleteUnwantedVM(String)returned true) failed to be removed.voidunwantedSlaveNowDeleted(String nodeName) MUST be called when a node previously declared to be unwanted (previously told toprovisionedSlaveNowUnwanted(String, boolean)) and that we were given clearance to delete (isOkToDeleteUnwantedVM(String)returned true) has been successfully removed.
-
Constructor Details
-
CloudProvisioningState
-
-
Method Details
-
provisioningStarted
To be called when we've decided to create a new node. Callers MUST ensure thatprovisionedSlaveNowActive(CloudProvisioningRecord, String)orprovisioningEndedInError(CloudProvisioningRecord, String)gets called later.- Parameters:
provisionable- Our record for the template for the named node.nodeName- The name of the VM.
-
provisionedSlaveNowActive
To be called when a newly created node (previously promised toprovisioningStarted(CloudProvisioningRecord, String)) comes up. Callers MUST ensure thatprovisionedSlaveNowUnwanted(String, boolean)gets called later when we do not want it anymore.- Parameters:
provisionable- Our record for the template for the named node.nodeName- The name of the VM.
-
provisionedSlaveNowUnwanted
To be called when a node we created (previously told toprovisionedSlaveNowActive(CloudProvisioningRecord, String)) is no longer wanted and should be deleted.- Parameters:
nodeName- The name of the VM.willAttemptImmediateDeletion- If true then the caller must attempt to delete the agent and guarantee that they will callunwantedSlaveNotDeleted(String)orunwantedSlaveNowDeleted(String)as appropriate (just as if they'd calledisOkToDeleteUnwantedVM(String)and been told True). If false then the caller is under no such obligation.
-
isOkToDeleteUnwantedVM
To be called before commencing the deletion of a VM.- Parameters:
nodeName- The name of the VM being deleted.- Returns:
- null if the VM is not unwanted (it may have recently been
deleted). false if another thread is currently trying to delete
it. true if deletion should be attempted, in which case the
caller MUST later call
unwantedSlaveNowDeleted(String)orunwantedSlaveNotDeleted(String).
-
unwantedSlaveNowDeleted
MUST be called when a node previously declared to be unwanted (previously told toprovisionedSlaveNowUnwanted(String, boolean)) and that we were given clearance to delete (isOkToDeleteUnwantedVM(String)returned true) has been successfully removed.- Parameters:
nodeName- The name of the VM that was successfully deleted.
-
unwantedSlaveNotDeleted
MUST be called when a node previously declared to be unwanted (previously told toprovisionedSlaveNowUnwanted(String, boolean)) and that we were given clearance to delete (isOkToDeleteUnwantedVM(String)returned true) failed to be removed.- Parameters:
nodeName- The name of the VM that failed to delete
-
recordExistingUnwantedVM
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.- Parameters:
template- The template to which the node belonged.nodeName- The name of the node that exists (despite our wishes).
-
provisioningEndedInError
To be called when a node that we previously promised to create (by callingprovisioningStarted(CloudProvisioningRecord, String)) failed to start.- Parameters:
provisionable- Our record for the template for the named node.nodeName- The name of the VM.
-
pruneUnwantedRecords
public void pruneUnwantedRecords()To be called every now and again to ensure that we're not caching records that will never be valid again. -
calculateProvisionableTemplates
public List<CloudProvisioningRecord> calculateProvisionableTemplates(Iterable<vSphereCloudSlaveTemplate> templates) Given a set of templates, returns the equivalent records.- Parameters:
templates- The templates we are interested in.- Returns:
- A list of
CloudProvisioningRecord.
-
countNodes
public int countNodes()Counts all the known nodes, active, in-progress and being-deleted, across all templates.- Returns:
- The number of nodes that exist (or will do).
-
getOrCreateRecord
Gets the record for the given template. If we didn't have one before, we create one.- Parameters:
template- The template in question.- Returns:
- The one-and-only record for this template.
-
getUnwantedVMsThatNeedDeleting
Calculates the current list of "existing but unwanted" VMs, in priority order. Note: The returned data is not "live", it's a copy, so callers are free to edit theListthey are given.- Returns:
- A copy of the list of VMs that we know exist but no longer want, and which aren't in the process of being deleted by anyone.
-