Search in sources :

Example 1 with SingularityExpiringMachineState

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");
}
Also used : SingularityMachineChangeRequest(com.hubspot.singularity.api.SingularityMachineChangeRequest) SingularityExpiringMachineState(com.hubspot.singularity.expiring.SingularityExpiringMachineState) MachineState(com.hubspot.singularity.MachineState)

Example 2 with SingularityExpiringMachineState

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());
    }
}
Also used : SingularityExpiringMachineState(com.hubspot.singularity.expiring.SingularityExpiringMachineState) MachineState(com.hubspot.singularity.MachineState) SingularityExpiringMachineState(com.hubspot.singularity.expiring.SingularityExpiringMachineState)

Aggregations

MachineState (com.hubspot.singularity.MachineState)2 SingularityExpiringMachineState (com.hubspot.singularity.expiring.SingularityExpiringMachineState)2 SingularityMachineChangeRequest (com.hubspot.singularity.api.SingularityMachineChangeRequest)1