Class CloudPoolClient
- java.lang.Object
-
- com.elastisys.scale.cloudpool.api.client.CloudPoolClient
-
-
Constructor Summary
Constructors Constructor Description CloudPoolClient(com.elastisys.scale.commons.net.http.client.AuthenticatedHttpClient httpClient, java.lang.String cloudPoolHost, int cloudPoolPort)Constructs aCloudPoolClientfor a givenCloudPoolendpoint, using a givenAuthenticatedHttpClientfor communication.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidattachMachine(java.lang.String machineId)Attaches an already running machine instance to the pool, growing the pool with a new member.voidconfigure(com.google.gson.JsonObject configuration)Updates the configuration for thisCloudPool.voiddetachMachine(java.lang.String machineId, boolean decrementDesiredSize)Removes a member from the pool without terminating it.java.util.Optional<com.google.gson.JsonObject>getConfiguration()Returns the configuration currently set for thisCloudPool, if one has been set.MachinePoolgetMachinePool()Returns a list of the members of the cloud pool.PoolSizeSummarygetPoolSize()Returns the current size of theMachinePool-- both in terms of the desired size and the actual size (as these may differ at any time).CloudPoolStatusgetStatus()Returns the execution status for theCloudPool.java.util.concurrent.Future<?>setDesiredSize(int desiredSize)Sets the desired number of machines in the machine pool.voidsetMembershipStatus(java.lang.String machineId, MembershipStatus membershipStatus)Sets the membership status of a given pool member.voidsetServiceState(java.lang.String machineId, ServiceState serviceState)Sets the service state of a given machine pool member.voidstart()Starts theCloudPool.voidstop()Stops theCloudPool.voidterminateMachine(java.lang.String machineId, boolean decrementDesiredSize)Terminates a particular machine pool member.
-
-
-
Constructor Detail
-
CloudPoolClient
public CloudPoolClient(com.elastisys.scale.commons.net.http.client.AuthenticatedHttpClient httpClient, java.lang.String cloudPoolHost, int cloudPoolPort)Constructs aCloudPoolClientfor a givenCloudPoolendpoint, using a givenAuthenticatedHttpClientfor communication.
-
-
Method Detail
-
configure
public void configure(com.google.gson.JsonObject configuration) throws java.lang.IllegalArgumentException, CloudPoolExceptionDescription copied from interface:CloudPoolUpdates the configuration for thisCloudPool. This operation does not change theCloudPool's started state -- if theCloudPoolis started it should remain started, and if it is in a stopped state it should remain stopped. The configuration is passed as a JSON object. It is up to theCloudPoolto validate and apply the contents of the configuration as well as to perform whatever changes are needed for the new configuration to take effect.- Specified by:
configurein interfaceCloudPool- Parameters:
configuration- The JSON configuration to be set.- Throws:
java.lang.IllegalArgumentException- If the received configuration was invalid.CloudPoolException- If the configuration could not be applied.
-
getConfiguration
public java.util.Optional<com.google.gson.JsonObject> getConfiguration()
Description copied from interface:CloudPoolReturns the configuration currently set for thisCloudPool, if one has been set.- Specified by:
getConfigurationin interfaceCloudPool- Returns:
- A JSON configuration if set,
Optional#absent()otherwise.
-
start
public void start() throws NotConfiguredExceptionDescription copied from interface:CloudPoolStarts theCloudPool. This will set theCloudPoolin an activated state where it will start to accept requests to query or modify the machine pool. If theCloudPoolhas not been configured the method will fail. If theCloudPoolis already started this is a no-op.- Specified by:
startin interfaceCloudPool- Throws:
NotConfiguredException- If theCloudPoolhas not been configured.
-
stop
public void stop()
Description copied from interface:CloudPool
-
getStatus
public CloudPoolStatus getStatus()
Description copied from interface:CloudPoolReturns the execution status for theCloudPool.
-
getMachinePool
public MachinePool getMachinePool() throws CloudPoolException, NotStartedException
Description copied from interface:CloudPoolReturns a list of the members of the cloud pool. Note, that the response may include machines in anyMachineState, even machines that are in the process of terminating. TheMembershipStatusof a machine in an allocated/started state determines if it is to be considered an active member of the pool.The active size of the machine pool should be interpreted as the number of allocated machines (in any of the non-terminal machine statesREQUESTED,PENDINGorRUNNINGthat have not been marked with an inactiveMembershipStatus. SeeMachine.isActiveMember(). The service state should be set to UNKNOWN for all machine instances for which no service state has been reported (seeCloudPool.setServiceState(String, ServiceState)). Similarly, theMembershipStatusshould be set toMembershipStatus.defaultStatus()for all machine instances for which no membership status has been reported (seeCloudPool.setMembershipStatus(String, MembershipStatus)).- Specified by:
getMachinePoolin interfaceCloudPool- Returns:
- A list of cloud pool members.
- Throws:
CloudPoolException- If the operation could not be completed.NotStartedException- If theCloudPoolis not started.
-
getPoolSize
public PoolSizeSummary getPoolSize() throws CloudPoolException, NotStartedException
Description copied from interface:CloudPoolReturns the current size of theMachinePool-- both in terms of the desired size and the actual size (as these may differ at any time).- Specified by:
getPoolSizein interfaceCloudPool- Returns:
- The current
PoolSizeSummary. - Throws:
CloudPoolException- If the operation could not be completed.NotStartedException- If theCloudPoolis not started.
-
setDesiredSize
public java.util.concurrent.Future<?> setDesiredSize(int desiredSize) throws java.lang.IllegalArgumentException, CloudPoolException, NotStartedExceptionDescription copied from interface:CloudPoolSets the desired number of machines in the machine pool. This method is asynchronous and returns immediately after updating the desired size. There may be a delay before the changes take effect and are reflected in the machine pool. The method returns aFuturethat the caller can use if it needs to wait for the size update to be applied to the pool. Note: theCloudPoolimplementation should take measures to ensure that requested machines are recognized as pool members. The specific mechanism to mark pool members, which may depend on the features offered by the particular cloud API, is left to the implementation but could, for example, make use of tags.- Specified by:
setDesiredSizein interfaceCloudPool- Parameters:
desiredSize- The desired number of machines in the pool.- Returns:
- A
Futurethat the caller can use to wait for the size update to be applied to the pool. - Throws:
java.lang.IllegalArgumentException- If the desired size is illegal.CloudPoolException- If the operation could not be completed.NotStartedException- If theCloudPoolis not started.
-
terminateMachine
public void terminateMachine(java.lang.String machineId, boolean decrementDesiredSize) throws NotFoundException, CloudPoolException, NotStartedExceptionDescription copied from interface:CloudPoolTerminates a particular machine pool member. The caller can control if a replacement machine is to be provisioned via thedecrementDesiredSizeparameter. Note: a machine that is protected from removal by a membership status withevictable: falsecan not be terminated.- Specified by:
terminateMachinein interfaceCloudPool- Parameters:
machineId- The machine to terminate.decrementDesiredSize- If the desired pool size should be decremented (true) or left at its current size (false).- Throws:
NotFoundException- If the specified machine is not a member of the pool.NotEvictableException- If the specified machine has aMembershipStatusthat prevents it from being removed.CloudPoolException- If the operation could not be completed.NotStartedException- If theCloudPoolis not started.
-
setServiceState
public void setServiceState(java.lang.String machineId, ServiceState serviceState) throws NotFoundException, CloudPoolException, NotStartedExceptionDescription copied from interface:CloudPoolSets the service state of a given machine pool member. Setting the service state does not have any functional implications on the pool member, but should be seen as way to supply operational information about the service running on the machine to third-party services (such as load balancers).- Specified by:
setServiceStatein interfaceCloudPool- Parameters:
machineId- The id of the machine whose service state is to be updated.serviceState- TheServiceStateto assign to the machine.- Throws:
NotFoundException- If the specified machine is not a member of the pool.CloudPoolException- If the operation could not be completed.NotStartedException- If theCloudPoolis not started.
-
setMembershipStatus
public void setMembershipStatus(java.lang.String machineId, MembershipStatus membershipStatus) throws NotFoundException, CloudPoolException, NotStartedExceptionDescription copied from interface:CloudPoolSets the membership status of a given pool member. The membership status for a machine can be set to protect the machine from being terminated (by setting its evictability status) and/or to mark a machine as being in need of replacement by flagging it as an inactive pool member.- Specified by:
setMembershipStatusin interfaceCloudPool- Parameters:
machineId- The id of the machine whose status is to be updated.membershipStatus- TheMembershipStatusto set.- Throws:
NotFoundExceptionCloudPoolExceptionNotStartedException- If theCloudPoolis not started.
-
attachMachine
public void attachMachine(java.lang.String machineId) throws NotFoundException, CloudPoolException, NotStartedExceptionDescription copied from interface:CloudPoolAttaches an already running machine instance to the pool, growing the pool with a new member. This operation implies that the desired size of the pool is incremented by one.- Specified by:
attachMachinein interfaceCloudPool- Parameters:
machineId- The identifier of the machine to attach to the pool.- Throws:
NotFoundException- If the specified machine does not exist.CloudPoolException- If the operation could not be completed.NotStartedException- If theCloudPoolis not started.
-
detachMachine
public void detachMachine(java.lang.String machineId, boolean decrementDesiredSize) throws NotFoundException, CloudPoolException, NotStartedExceptionDescription copied from interface:CloudPoolRemoves a member from the pool without terminating it. The machine keeps running but is no longer considered a pool member and, therefore, needs to be managed independently. The caller can control if a replacement machine is to be provisioned via thedecrementDesiredSizeparameter. Note: a machine that is protected from removal by a membership status withevictable: falsecan not be terminated.- Specified by:
detachMachinein interfaceCloudPool- Parameters:
machineId- The identifier of the machine to detach from the pool.decrementDesiredSize- If the desired pool size should be decremented (true) or left at its current size (false).- Throws:
NotFoundException- If the specified machine is not a member of the pool.NotEvictableException- If the specified machine has aMembershipStatusthat prevents it from being removed.CloudPoolException- If the operation could not be completed.NotStartedException- If theCloudPoolis not started.
-
-