Search in sources :

Example 6 with SingularityMachineChangeRequest

use of com.hubspot.singularity.api.SingularityMachineChangeRequest in project Singularity by HubSpot.

the class SingularityMachineStatesTest method testExpiringMachineState.

@Test
public void testExpiringMachineState() {
    MesosMasterStateObject state = getMasterState(1);
    singularitySlaveAndRackManager.loadSlavesAndRacksFromMaster(state, true);
    SingularitySlave slave = slaveManager.getObjects().get(0);
    slaveResource.freezeSlave(singularityUser, slave.getId(), new SingularityMachineChangeRequest(Optional.of(1L), Optional.absent(), Optional.absent(), Optional.of(MachineState.ACTIVE), Optional.absent()));
    Assert.assertEquals(MachineState.FROZEN, slaveManager.getObjects().get(0).getCurrentState().getState());
    expiringUserActionPoller.runActionOnPoll();
    Assert.assertEquals(MachineState.ACTIVE, slaveManager.getObjects().get(0).getCurrentState().getState());
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) SingularityMachineChangeRequest(com.hubspot.singularity.api.SingularityMachineChangeRequest) MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject) Test(org.junit.Test)

Example 7 with SingularityMachineChangeRequest

use of com.hubspot.singularity.api.SingularityMachineChangeRequest 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)

Aggregations

SingularityMachineChangeRequest (com.hubspot.singularity.api.SingularityMachineChangeRequest)7 SingularitySlave (com.hubspot.singularity.SingularitySlave)6 Test (org.junit.Test)6 MesosMasterStateObject (com.hubspot.mesos.json.MesosMasterStateObject)1 MachineState (com.hubspot.singularity.MachineState)1 SingularityExpiringMachineState (com.hubspot.singularity.expiring.SingularityExpiringMachineState)1