Class Machine


  • public class Machine
    extends java.lang.Object
    Represents a machine that is a member of a MachinePool managed by a CloudPool.

    As explained in the cloud pool REST API, a Machine has 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
    • Field Detail

      • allocatedStates

        public static final java.util.Set<MachineState> allocatedStates
        The collection of MachineStates 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 new Machine.
        Parameters:
        id - The identifier of the Machine.
        machineState - The execution state of the Machine.
        membershipStatus - The pool membership status of this Machine.
        serviceState - The operational state of the service running on the Machine.
        cloudProvider - The name of the cloud provider that this Machine originates 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 the Machine. For example, m1.medium for an Amazon EC2 CloudPool.
        requestTime - The request time of the Machine, if this time is known. If the time when the machine was initially and successfully requested is not known, this attribute shall be null.
        launchTime - The launch time of the Machine if it has been launched. This attribute may be null, depending on the state of the Machine.
        publicIps - The list of public IP addresses associated with this Machine. If the machine hasn't (yet) been assigned any IP addresses, this attribute can be set to null or an empty list.
        privateIps - The list of private IP addresses associated with this Machine. If the machine hasn't (yet) been assigned any IP addresses, this attribute can be set to null or an empty list.
        metadata - Additional cloud provider-specific meta data about the Machine. May be null.
    • Method Detail

      • getId

        public java.lang.String getId()
        Returns the identifier of the Machine.
        Returns:
      • getMachineState

        public MachineState getMachineState()
        Returns the execution state of the Machine.
        Returns:
      • setMachineState

        public void setMachineState​(MachineState machineState)
        Sets the execution state of the Machine.
        Parameters:
        machineState -
      • getMembershipStatus

        public MembershipStatus getMembershipStatus()
        Returns the pool membership status of this Machine.
        Returns:
      • getServiceState

        public ServiceState getServiceState()
        Returns the service state of the Machine.
        Returns:
      • getCloudProvider

        public java.lang.String getCloudProvider()
        Returns The name of the cloud provider that this machine originates from, for example AWS-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()
        Return the size (or type) of the Machine. For example, m1.medium for an Amazon EC2 CloudPool.
        Returns:
      • getLaunchTime

        public org.joda.time.DateTime getLaunchTime()
        Returns the launch time of the Machine if it has been launched. This attribute may be null, depending on the state of the Machine.
        Returns:
      • getRequestTime

        public org.joda.time.DateTime getRequestTime()
        Returns the request time of the Machine. 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 DateTime object with the request time if set. Otherwise null.
      • getPublicIps

        public java.util.List<java.lang.String> getPublicIps()
        Returns the list of public IP addresses associated with this Machine. Depending on the state of the Machine, this list may be empty.
        Returns:
      • getPrivateIps

        public java.util.List<java.lang.String> getPrivateIps()
        Returns the list of private IP addresses associated with this Machine. Depending on the state of the Machine, this list may be empty.
        Returns:
      • getMetadata

        public com.google.gson.JsonElement getMetadata()
        Returns any additional cloud provider-specific meta data about the Machine if set, otherwise null.
        Returns:
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • withMetadata

        public Machine withMetadata​(com.google.gson.JsonObject metadata)
        Creates a copy of this Machine with a different value for the metadata field.
        Parameters:
        metadata - Metadata to set for the Machine copy, or null if no metadata is desired.
        Returns:
        A copy
      • inState

        public static java.util.function.Predicate<? super Machine> inState​(MachineState state)
        Returns a Predicate that returns true when passed a Machine in a given MachineState.
        Parameters:
        state - The MachineState for which this Predicate will return true.
        Returns:
      • isEvictable

        public static java.util.function.Predicate<Machine> isEvictable()
        Returns a Predicate that returns true for any Machine with an evictable MembershipStatus.
        Returns:
      • sort

        public static java.util.List<Machine> sort​(java.util.Collection<Machine> machines,
                                                   java.util.Comparator<Machine> comparator)
        Sorts a collection of Machines according to the order prescribed by a certain Comparator.
        Parameters:
        machines -
        comparator -
        Returns:
      • toShortString

        public static java.util.function.Function<Machine,​java.lang.String> toShortString()
        Factory method for the Machine.ToShortMachineString Function.
        Returns: