com.elastisys.scale.cloudpool.commons.basepool.driver.StartMachinesException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloudpool.commons Show documentation
Show all versions of cloudpool.commons Show documentation
Common utility classes for building cloud pools.
package com.elastisys.scale.cloudpool.commons.basepool.driver;
import java.util.List;
import com.elastisys.scale.cloudpool.api.types.Machine;
/**
* Exception thrown by a {@link CloudPoolDriver} to signal that a request to
* start a number of machines failed before being entirely complete.
*
* The error indicates the set of {@link Machine}s that were started (if any)
* before the error occurred.
*/
public class StartMachinesException extends CloudPoolDriverException {
/** Default serial version UID. */
private static final long serialVersionUID = 1L;
/** The number of {@link Machine}s that were requested. */
private final int requestedMachines;
/** {@link Machine}s that were started before the request failed. */
private final List startedMachines;
/**
* Constructs a new {@link StartMachinesException}.
*
* @param requestedMachines
* The number of {@link Machine}s that were requested.
* @param startedMachines
* {@link Machine}s that were started before the request failed.
* @param cause
* The error that caused the request to fail.
*/
public StartMachinesException(int requestedMachines, List startedMachines, Throwable cause) {
this(requestedMachines, startedMachines, cause, defaultErrorMessage(requestedMachines, startedMachines, cause));
}
/**
* Constructs a new {@link StartMachinesException} with a custom error
* detail message.
*
* @param requestedMachines
* The number of {@link Machine}s that were requested.
* @param startedMachines
* {@link Machine}s that were started before the request failed.
* @param cause
* The error that caused the request to fail.
* @param message
* The detail message.
*/
public StartMachinesException(int requestedMachines, List startedMachines, Throwable cause,
String message) {
super(message, cause);
this.requestedMachines = requestedMachines;
this.startedMachines = startedMachines;
}
/**
* Returns the number of {@link Machine}s that were requested.
*
* @return
*/
public int getRequestedMachines() {
return this.requestedMachines;
}
/**
* Returns the list of {@link Machine}s that were started before the request
* failed.
*
* @return
*/
public List getStartedMachines() {
return this.startedMachines;
}
private static String defaultErrorMessage(int numRequestedMachines, List startedMachines,
Throwable cause) {
String message = String.format(
"failure to complete request to start %d machine(s) " + "(%d machine(s) were launched): %s",
numRequestedMachines, startedMachines.size(), cause.getMessage());
return message;
}
}