protected class EC2Provider.SpotGroupAllocator extends Object
Modifier and Type | Field and Description |
---|---|
protected int |
allocatedInstanceCount
The number of allocated instances (including reused orphans).
|
protected int |
minCount
The minimum number of instances to allocate if not all resources can be allocated.
|
protected Date |
priceChangeDeadlineTime
The latest time to wait for a Spot price change when it is known that the current Spot price
exceeds the Spot bid.
|
protected Date |
requestExpirationTime
The latest time to wait for Spot instance request fulfillment.
|
protected Map<String,EC2Provider.SpotAllocationRecord> |
spotAllocationRecordsByVirtualInstanceId
The map from virtual instance IDs to the corresponding Spot allocation records.
|
protected Map<String,String> |
spotInstancesByUntaggedSpotInstanceRequestId
The map from untagged Spot instance request IDs to the corresponding Spot instances.
|
protected EC2InstanceTemplate |
template
The instance template.
|
protected Collection<String> |
virtualInstanceIds
The virtual instance IDs.
|
Modifier | Constructor and Description |
---|---|
protected |
SpotGroupAllocator(EC2InstanceTemplate template,
Collection<String> virtualInstanceIds,
int minCount,
Date requestExpirationTime,
Date priceChangeDeadline)
Creates a Spot group allocator with the specified parameters.
|
Modifier and Type | Method and Description |
---|---|
protected void |
allocate()
Allocates Spot instances.
|
protected void |
cancelSpotRequests(com.cloudera.director.spi.v1.model.exception.PluginExceptionConditionAccumulator accumulator)
Cancels any outstanding Spot requests (includes discovered orphans and created requests).
|
protected void |
checkForOrphanedInstances()
Identifies reusable Spot instances orphaned by a previous call.
|
protected Set<String> |
checkForOrphanedSpotInstanceRequests()
Identifies reusable Spot instance requests orphaned by a previous call.
|
protected String |
determineClientToken(Set<String> virtualInstanceIds)
Determines the idempotency client token for the specified virtual instance IDs.
|
protected Set<String> |
determineVirtualInstanceIdsNeedingSpotInstanceRequest()
Determines which virtual instance IDs require a Spot instance request.
|
protected String |
getErrorMessage(Exception e)
Returns the error message for the specified exception.
|
protected EC2Provider.SpotAllocationRecord |
getSpotAllocationRecord(String virtualInstanceId)
Returns the Spot allocation record corresponding to the specified virtual instance ID.
|
protected Map<String,EC2Provider.SpotAllocationRecord> |
initializeSpotAllocationRecordMap(Collection<String> virtualInstanceIds)
Initializes the map from virtual instance IDs to the corresponding Spot allocation records.
|
protected com.amazonaws.services.ec2.model.RequestSpotInstancesRequest |
newRequestSpotInstancesRequest(Collection<String> virtualInstanceIds,
String clientToken)
Builds a
RequestSpotInstancesRequest for the specified virtual instance IDs. |
protected Set<String> |
requestSpotInstances(com.amazonaws.services.ec2.model.RequestSpotInstancesRequest requestSpotInstancesRequest)
Requests Spot instances, and returns the resulting Spot instance request IDs.
|
protected boolean |
spotInstanceRequestExists(String spotInstanceRequestId)
Checks whether the specified Spot instance request is visible, i.e. can
be located by a describe Spot instance request call.
|
protected void |
tagSpotInstanceRequest(List<com.amazonaws.services.ec2.model.Tag> userDefinedTags,
String spotInstanceRequestId,
String virtualInstanceId)
Tags an EC2 Spot instance request.
|
protected void |
tagSpotInstanceRequests(Collection<String> spotInstanceRequestIds,
Collection<String> virtualInstanceIds)
Tags the Spot instance requests with the specified IDs with the corresponding virtual
instance IDs.
|
protected void |
tagSpotInstances()
Tags provisioned Spot instances.
|
protected void |
terminateSpotInstances(com.cloudera.director.spi.v1.model.exception.PluginExceptionConditionAccumulator accumulator)
Terminates any running Spot instances (includes discovered orphans and allocated instances).
|
protected void |
waitForPrivateIpAddresses()
Waits for provisioned Spot instances to have a private IP address.
|
protected void |
waitForSpotInstances(Set<String> pendingRequestIds,
boolean cancelling)
Waits for pending Spot instance requests to be fulfilled.
|
protected final EC2InstanceTemplate template
protected final Collection<String> virtualInstanceIds
protected final int minCount
protected final Date requestExpirationTime
protected final Date priceChangeDeadlineTime
protected final Map<String,EC2Provider.SpotAllocationRecord> spotAllocationRecordsByVirtualInstanceId
protected final Map<String,String> spotInstancesByUntaggedSpotInstanceRequestId
protected int allocatedInstanceCount
protected SpotGroupAllocator(EC2InstanceTemplate template, Collection<String> virtualInstanceIds, int minCount, Date requestExpirationTime, Date priceChangeDeadline)
template
- the instance templatevirtualInstanceIds
- the virtual instance IDsminCount
- the minimum number of instances to allocate if not all resources can
be allocatedrequestExpirationTime
- the latest time to wait for Spot instance request fulfillmentpriceChangeDeadline
- the latest time to wait for a Spot price change when it is known
that the current Spot price exceeds the Spot bidprotected Map<String,EC2Provider.SpotAllocationRecord> initializeSpotAllocationRecordMap(Collection<String> virtualInstanceIds)
virtualInstanceIds
- the virtual instance IDsprotected EC2Provider.SpotAllocationRecord getSpotAllocationRecord(String virtualInstanceId)
virtualInstanceId
- the virtual instance IDprotected void allocate() throws InterruptedException
InterruptedException
- if the operation is interruptedprotected void checkForOrphanedInstances() throws InterruptedException
Identifies reusable Spot instances orphaned by a previous call.
Note: because of AWS's eventual consistency policies, we are not guaranteed to be able to detect all orphans here, but we make a best-faith effort.
InterruptedException
- if operation is interruptedprotected Set<String> checkForOrphanedSpotInstanceRequests()
protected Set<String> determineVirtualInstanceIdsNeedingSpotInstanceRequest()
protected String determineClientToken(Set<String> virtualInstanceIds)
virtualInstanceIds
- the virtual instance IDsprotected com.amazonaws.services.ec2.model.RequestSpotInstancesRequest newRequestSpotInstancesRequest(Collection<String> virtualInstanceIds, String clientToken)
RequestSpotInstancesRequest
for the specified virtual instance IDs.virtualInstanceIds
- the virtual instance IDsclientToken
- the idempotency client tokenRequestSpotInstancesRequest
protected Set<String> requestSpotInstances(com.amazonaws.services.ec2.model.RequestSpotInstancesRequest requestSpotInstancesRequest)
requestSpotInstancesRequest
- the RequestSpotInstancesRequest
protected void tagSpotInstanceRequests(Collection<String> spotInstanceRequestIds, Collection<String> virtualInstanceIds) throws InterruptedException
spotInstanceRequestIds
- the Spot instance request IDsvirtualInstanceIds
- the corresponding virtual instance IDsInterruptedException
- if the operation is interruptedprotected void tagSpotInstanceRequest(List<com.amazonaws.services.ec2.model.Tag> userDefinedTags, String spotInstanceRequestId, String virtualInstanceId) throws InterruptedException
userDefinedTags
- the user-defined tagsspotInstanceRequestId
- the Spot instance request IDvirtualInstanceId
- the virtual instance IDInterruptedException
- if the operation is interruptedprotected boolean spotInstanceRequestExists(String spotInstanceRequestId)
spotInstanceRequestId
- the Spot instance request IDprotected void waitForSpotInstances(Set<String> pendingRequestIds, boolean cancelling) throws InterruptedException
pendingRequestIds
- the pending Spot instance request IDscancelling
- whether we are in the process of cancellingInterruptedException
- if the operation is interruptedprotected void tagSpotInstances() throws InterruptedException
InterruptedException
- if the operation is interruptedprotected void waitForPrivateIpAddresses() throws InterruptedException
InterruptedException
- if the operation is interruptedprotected void terminateSpotInstances(com.cloudera.director.spi.v1.model.exception.PluginExceptionConditionAccumulator accumulator) throws InterruptedException
accumulator
- the exception condition accumulatorInterruptedException
- if operation is interruptedprotected void cancelSpotRequests(com.cloudera.director.spi.v1.model.exception.PluginExceptionConditionAccumulator accumulator) throws InterruptedException
accumulator
- the exception condition accumulatorInterruptedException
- if the operation is interruptedCopyright © 2016. All rights reserved.