Class Machine
- java.lang.Object
-
- com.elastisys.scale.cloudpool.api.types.Machine
-
public class Machine extends java.lang.ObjectRepresents a machine that is a member of aMachinePoolmanaged by aCloudPool. As explained in the cloud pool REST API, aMachinehas three different states of interest:- The machine state, being the execution state of the machine as reported by the cloud API.
- The membership status, indicating if the machine is to be given special treatment in the pool. This includes protecting it from termination and/or marking it in need of a replacement.
- The service state, being the operational state of the service running on the machine.
- See Also:
MachinePool,CloudPool
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMachine.ActiveMemberPredicateAPredicatethat returnstruewhen passed aMachinethat is an active pool member -- it has been allocated from the underlying infrastructure (MachineState.REQUESTED,MachineState.PENDINGorMachineState.RUNNING) and is an active pool member (MembershipStatus.isActive()).static classMachine.AllocatedMachinePredicateAPredicatethat returnstruewhen passed aMachinethat has been allocated from the underlying infrastructure (machine stateMachineState.REQUESTED,MachineState.PENDINGorMachineState.RUNNING).static classMachine.BuilderA builder for creatingMachineinstances.static classMachine.EvictableMemberPredicatestatic classMachine.MachineWithStatestatic classMachine.StartedMachinePredicateAPredicatethat returnstruewhen passed aMachinethat has been started by the underlying infrastructure (machine state isMachineState.PENDINGorMachineState.RUNNING).static classMachine.ToShortMachineFormatstatic classMachine.ToShortMachineString
-
Field Summary
Fields Modifier and Type Field Description static java.util.Set<MachineState>allocatedStatesThe collection ofMachineStates for which machines are considered to have been allocated from the underlying infrastructure.
-
Constructor Summary
Constructors Modifier Constructor Description protectedMachine(java.lang.String id, MachineState machineState, MembershipStatus membershipStatus, ServiceState serviceState, java.lang.String cloudProvider, java.lang.String region, java.lang.String machineSize, org.joda.time.DateTime requestTime, org.joda.time.DateTime launchTime, java.util.List<java.lang.String> publicIps, java.util.List<java.lang.String> privateIps, com.google.gson.JsonElement metadata)Constructs a newMachine.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Machine.Builderbuilder()Creates aMachine.Builderobject for generatingMachineinstances.booleanequals(java.lang.Object obj)java.lang.StringgetCloudProvider()Returns The name of the cloud provider that this machine originates from, for exampleAWS-EC2.java.lang.StringgetId()Returns the identifier of theMachine.org.joda.time.DateTimegetLaunchTime()Returns the launch time of theMachineif it has been launched.java.lang.StringgetMachineSize()Return the size (or type) of theMachine.MachineStategetMachineState()Returns the execution state of theMachine.MembershipStatusgetMembershipStatus()Returns the pool membership status of thisMachine.com.google.gson.JsonElementgetMetadata()Returns any additional cloud provider-specific meta data about theMachineif set, otherwisenull.java.util.List<java.lang.String>getPrivateIps()Returns the list of private IP addresses associated with thisMachine.java.util.List<java.lang.String>getPublicIps()Returns the list of public IP addresses associated with thisMachine.java.lang.StringgetRegion()Returns the name of the cloud region/zone/data center where this machine is located.org.joda.time.DateTimegetRequestTime()Returns the request time of theMachine.ServiceStategetServiceState()Returns the service state of theMachine.inthashCode()static java.util.function.Predicate<? super Machine>inState(MachineState state)static java.util.function.Predicate<Machine>isActiveMember()Returns aPredicatethat returnstruewhen passed aMachinethat is an active pool member -- it has been allocated from the underlying infrastructure (MachineState.REQUESTED,MachineState.PENDINGorMachineState.RUNNING) and is an active pool member (MembershipStatus.isActive()).static java.util.function.Predicate<Machine>isAllocated()Returns aPredicatethat returnstruewhen passed aMachinethat has been allocated from the underlying infrastructure (machine stateMachineState.REQUESTED,MachineState.PENDINGorMachineState.RUNNING).static java.util.function.Predicate<Machine>isEvictable()static java.util.function.Predicate<Machine>isStarted()APredicatethat returnstruewhen passed aMachinethat has been started by the underlying infrastructure (machine state isMachineState.PENDINGorMachineState.RUNNING).voidsetMachineState(MachineState machineState)Sets the execution state of theMachine.static java.util.List<Machine>sort(java.util.Collection<Machine> machines, java.util.Comparator<Machine> comparator)Sorts a collection ofMachines according to the order prescribed by a certainComparator.static java.util.function.Function<Machine,Machine>toShortFormat()Factory method for theMachine.ToShortMachineFormatFunction.static java.util.function.Function<Machine,java.lang.String>toShortString()Factory method for theMachine.ToShortMachineStringFunction.java.lang.StringtoString()MachinewithMetadata(com.google.gson.JsonObject metadata)Creates a copy of thisMachinewith a different value for the metadata field.
-
-
-
Field Detail
-
allocatedStates
public static final java.util.Set<MachineState> allocatedStates
The collection ofMachineStates for which machines are considered to have been allocated from the underlying infrastructure.
-
-
Constructor Detail
-
Machine
protected Machine(java.lang.String id, MachineState machineState, MembershipStatus membershipStatus, ServiceState serviceState, java.lang.String cloudProvider, java.lang.String region, java.lang.String machineSize, org.joda.time.DateTime requestTime, org.joda.time.DateTime launchTime, java.util.List<java.lang.String> publicIps, java.util.List<java.lang.String> privateIps, com.google.gson.JsonElement metadata)Constructs a newMachine.- Parameters:
id- The identifier of theMachine.machineState- The execution state of theMachine.membershipStatus- The pool membership status of thisMachine.serviceState- The operational state of the service running on theMachine.cloudProvider- The name of the cloud provider that thisMachineoriginates from. For example,AWS-EC2.region- The name of the cloud region/zone/data center where this machine is located. For example,us-east-1.machineSize- The size (or type) of theMachine. For example,m1.mediumfor an Amazon EC2CloudPool.requestTime- The request time of theMachine, if this time is known. If the time when the machine was initially and successfully requested is not known, this attribute shall benull.launchTime- The launch time of theMachineif it has been launched. This attribute may benull, depending on the state of theMachine.publicIps- The list of public IP addresses associated with thisMachine. If the machine hasn't (yet) been assigned any IP addresses, this attribute can be set tonullor an empty list.privateIps- The list of private IP addresses associated with thisMachine. If the machine hasn't (yet) been assigned any IP addresses, this attribute can be set tonullor an empty list.metadata- Additional cloud provider-specific meta data about theMachine. May benull.
-
-
Method Detail
-
getId
public java.lang.String getId()
Returns the identifier of theMachine.- Returns:
-
getMachineState
public MachineState getMachineState()
Returns the execution state of theMachine.- Returns:
-
setMachineState
public void setMachineState(MachineState machineState)
Sets the execution state of theMachine.- Parameters:
machineState-
-
getMembershipStatus
public MembershipStatus getMembershipStatus()
Returns the pool membership status of thisMachine.- Returns:
-
getServiceState
public ServiceState getServiceState()
Returns the service state of theMachine.- Returns:
-
getCloudProvider
public java.lang.String getCloudProvider()
Returns The name of the cloud provider that this machine originates from, for exampleAWS-EC2. It might not be immediately apparent why this field is required since the cloud pool itself states which cloud provider it supports, but it is useful to distinguish where different machines originate from in multi-cloud scenarios where multiple down-stream cloud pools are abstracted by an upstream aggregating cloud pool (such as a splitter pool). Without this field, an autoscaler would not be able to tell from which clouds different machines originate (which it may need to know, from an accounting/billing perspective).- Returns:
-
getRegion
public java.lang.String getRegion()
Returns the name of the cloud region/zone/data center where this machine is located. For example,us-east-1.- Returns:
-
getMachineSize
public java.lang.String getMachineSize()
- Returns:
-
getLaunchTime
public org.joda.time.DateTime getLaunchTime()
Returns the launch time of theMachineif it has been launched. This attribute may benull, depending on the state of theMachine.- Returns:
-
getRequestTime
public org.joda.time.DateTime getRequestTime()
Returns the request time of theMachine. This attribute shall be set immediately when a VM has been successfully requested from the cloud backend. It may be null, if the cloud pool has no way of determining the correct value, e.g., if it was started with a pool of VMs already allocated and there is no way to find out when they were requested.- Returns:
- A
DateTimeobject with the request time if set. Otherwisenull.
-
getPublicIps
public java.util.List<java.lang.String> getPublicIps()
Returns the list of public IP addresses associated with thisMachine. Depending on the state of theMachine, this list may be empty.- Returns:
-
getPrivateIps
public java.util.List<java.lang.String> getPrivateIps()
Returns the list of private IP addresses associated with thisMachine. Depending on the state of theMachine, this list may be empty.- Returns:
-
getMetadata
public com.google.gson.JsonElement getMetadata()
Returns any additional cloud provider-specific meta data about theMachineif set, otherwisenull.- Returns:
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
withMetadata
public Machine withMetadata(com.google.gson.JsonObject metadata)
Creates a copy of thisMachinewith a different value for the metadata field.- Parameters:
metadata- Metadata to set for theMachinecopy, ornullif no metadata is desired.- Returns:
- A copy
-
inState
public static java.util.function.Predicate<? super Machine> inState(MachineState state)
- Parameters:
state- TheMachineStatefor which thisPredicatewill returntrue.- Returns:
-
isActiveMember
public static java.util.function.Predicate<Machine> isActiveMember()
Returns aPredicatethat returnstruewhen passed aMachinethat is an active pool member -- it has been allocated from the underlying infrastructure (MachineState.REQUESTED,MachineState.PENDINGorMachineState.RUNNING) and is an active pool member (MembershipStatus.isActive()).- Returns:
-
isAllocated
public static java.util.function.Predicate<Machine> isAllocated()
Returns aPredicatethat returnstruewhen passed aMachinethat has been allocated from the underlying infrastructure (machine stateMachineState.REQUESTED,MachineState.PENDINGorMachineState.RUNNING).- Returns:
-
isStarted
public static java.util.function.Predicate<Machine> isStarted()
APredicatethat returnstruewhen passed aMachinethat has been started by the underlying infrastructure (machine state isMachineState.PENDINGorMachineState.RUNNING).- See Also:
MachineState
-
isEvictable
public static java.util.function.Predicate<Machine> isEvictable()
- Returns:
-
sort
public static java.util.List<Machine> sort(java.util.Collection<Machine> machines, java.util.Comparator<Machine> comparator)
Sorts a collection ofMachines according to the order prescribed by a certainComparator.- Parameters:
machines-comparator-- Returns:
-
toShortFormat
public static java.util.function.Function<Machine,Machine> toShortFormat()
Factory method for theMachine.ToShortMachineFormatFunction.- Returns:
-
toShortString
public static java.util.function.Function<Machine,java.lang.String> toShortString()
Factory method for theMachine.ToShortMachineStringFunction.- Returns:
-
builder
public static Machine.Builder builder()
Creates aMachine.Builderobject for generatingMachineinstances.- Returns:
-
-