use of com.hubspot.singularity.expiring.SingularityExpiringMachineState in project Singularity by HubSpot.
the class SingularityValidator method validateExpiringMachineStateChange.
public void validateExpiringMachineStateChange(Optional<SingularityMachineChangeRequest> maybeChangeRequest, MachineState currentState, Optional<SingularityExpiringMachineState> currentExpiringObject) {
if (!maybeChangeRequest.isPresent() || !maybeChangeRequest.get().getDurationMillis().isPresent()) {
return;
}
SingularityMachineChangeRequest changeRequest = maybeChangeRequest.get();
checkBadRequest(changeRequest.getRevertToState().isPresent(), "Must include a machine state to revert to for an expiring machine state change");
MachineState newState = changeRequest.getRevertToState().get();
checkConflict(!currentExpiringObject.isPresent(), "A current expiring object already exists, delete it first");
checkBadRequest(!(newState == MachineState.STARTING_DECOMMISSION && currentState.isDecommissioning()), "Cannot start decommission when it has already been started");
checkBadRequest(!(((newState == MachineState.DECOMMISSIONING) || (newState == MachineState.DECOMMISSIONED)) && (currentState == MachineState.FROZEN)), "Cannot transition from FROZEN to DECOMMISSIONING or DECOMMISSIONED");
checkBadRequest(!(((newState == MachineState.DECOMMISSIONING) || (newState == MachineState.DECOMMISSIONED)) && (currentState == MachineState.ACTIVE)), "Cannot transition from ACTIVE to DECOMMISSIONING or DECOMMISSIONED");
checkBadRequest(!(newState == MachineState.FROZEN && currentState.isDecommissioning()), "Cannot transition from a decommissioning state to FROZEN");
List<MachineState> systemOnlyStateTransitions = ImmutableList.of(MachineState.DEAD, MachineState.MISSING_ON_STARTUP, MachineState.DECOMMISSIONING);
checkBadRequest(!systemOnlyStateTransitions.contains(newState), "States {} are reserved for system usage, you cannot manually transition to {}", systemOnlyStateTransitions, newState);
checkBadRequest(!(newState == MachineState.DECOMMISSIONED && !changeRequest.isKillTasksOnDecommissionTimeout()), "Must specify that all tasks on slave get killed if transitioning to DECOMMISSIONED state");
}
use of com.hubspot.singularity.expiring.SingularityExpiringMachineState in project Singularity by HubSpot.
the class AbstractMachineManager method clearExpiringStateChangeIfInvalid.
private void clearExpiringStateChangeIfInvalid(T object, MachineState newState) {
Optional<SingularityExpiringMachineState> maybeExpiring = getExpiringObject(object.getId());
if (!maybeExpiring.isPresent()) {
return;
}
MachineState targetExpiringState = maybeExpiring.get().getRevertToState();
Optional<StateChangeResult> maybeInvalidStateChange = getInvalidStateChangeResult(newState, targetExpiringState, true);
if (maybeInvalidStateChange.isPresent()) {
LOG.info("Cannot complete expiring state transition from {} to {}, removing expiring action for {}", newState, targetExpiringState, object.getId());
deleteExpiringObject(object.getId());
}
}
Aggregations