Search in sources :

Example 1 with SingularityMachineStateHistoryUpdate

use of com.hubspot.singularity.SingularityMachineStateHistoryUpdate in project Singularity by HubSpot.

the class AbstractMachineManager method changeState.

public StateChangeResult changeState(T object, MachineState newState, Optional<String> message, Optional<String> user) {
    Optional<StateChangeResult> maybeInvalidStateChange = getInvalidStateChangeResult(object.getCurrentState().getState(), newState, false);
    if (maybeInvalidStateChange.isPresent()) {
        return maybeInvalidStateChange.get();
    }
    clearExpiringStateChangeIfInvalid(object, newState);
    SingularityMachineStateHistoryUpdate newStateUpdate = new SingularityMachineStateHistoryUpdate(object.getId(), newState, System.currentTimeMillis(), user, message);
    LOG.debug("{} changing state from {} to {} by {}", object.getId(), object.getCurrentState().getState(), newState, user);
    saveObject(object.changeState(newStateUpdate));
    return StateChangeResult.SUCCESS;
}
Also used : SingularityMachineStateHistoryUpdate(com.hubspot.singularity.SingularityMachineStateHistoryUpdate)

Example 2 with SingularityMachineStateHistoryUpdate

use of com.hubspot.singularity.SingularityMachineStateHistoryUpdate in project Singularity by HubSpot.

the class SingularityMachineStatesTest method testDeadSlavesArePurged.

@Test
public void testDeadSlavesArePurged() {
    SingularitySlave liveSlave = new SingularitySlave("1", "h1", "r1", ImmutableMap.of("uniqueAttribute", "1"), Optional.absent());
    SingularitySlave deadSlave = new SingularitySlave("2", "h1", "r1", ImmutableMap.of("uniqueAttribute", "2"), Optional.absent());
    final long now = System.currentTimeMillis();
    liveSlave = liveSlave.changeState(new SingularityMachineStateHistoryUpdate("1", MachineState.ACTIVE, 100, Optional.absent(), Optional.absent()));
    deadSlave = deadSlave.changeState(new SingularityMachineStateHistoryUpdate("2", MachineState.DEAD, now - TimeUnit.HOURS.toMillis(10), Optional.absent(), Optional.absent()));
    slaveManager.saveObject(liveSlave);
    slaveManager.saveObject(deadSlave);
    slaveReconciliationPoller.runActionOnPoll();
    Assert.assertEquals(1, slaveManager.getObjectsFiltered(MachineState.ACTIVE).size());
    Assert.assertEquals(1, slaveManager.getObjectsFiltered(MachineState.DEAD).size());
    configuration.setDeleteDeadSlavesAfterHours(1);
    slaveReconciliationPoller.runActionOnPoll();
    Assert.assertEquals(1, slaveManager.getObjectsFiltered(MachineState.ACTIVE).size());
    Assert.assertEquals(0, slaveManager.getObjectsFiltered(MachineState.DEAD).size());
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) SingularityMachineStateHistoryUpdate(com.hubspot.singularity.SingularityMachineStateHistoryUpdate) Test(org.junit.Test)

Aggregations

SingularityMachineStateHistoryUpdate (com.hubspot.singularity.SingularityMachineStateHistoryUpdate)2 SingularitySlave (com.hubspot.singularity.SingularitySlave)1 Test (org.junit.Test)1