use of com.hubspot.singularity.SingularityAgent in project Singularity by HubSpot.
the class SingularityMachinesTest method testExpiringMachineState.
@Test
public void testExpiringMachineState() {
MesosMasterStateObject state = getMasterState(1);
singularityAgentAndRackManager.loadAgentsAndRacksFromMaster(state, true);
SingularityAgent agent = agentManager.getObjects().get(0);
agentResource.freezeAgent(singularityUser, agent.getId(), new SingularityMachineChangeRequest(Optional.of(1L), Optional.empty(), Optional.empty(), Optional.of(MachineState.ACTIVE), Optional.empty()));
Assertions.assertEquals(MachineState.FROZEN, agentManager.getObjects().get(0).getCurrentState().getState());
try {
Thread.sleep(10);
} catch (Exception e) {
// didn't see that
}
expiringUserActionPoller.runActionOnPoll();
Assertions.assertEquals(MachineState.ACTIVE, agentManager.getObjects().get(0).getCurrentState().getState());
}
use of com.hubspot.singularity.SingularityAgent in project Singularity by HubSpot.
the class SingularityMachinesTest method testDeadAgentsArePurged.
@Test
public void testDeadAgentsArePurged() {
long previousDeleteDeadAgentsAfterHours = configuration.getDeleteDeadAgentsAfterHours();
SingularityAgent liveAgent = new SingularityAgent("1", "h1", "r1", ImmutableMap.of("uniqueAttribute", "1"), Optional.empty());
SingularityAgent deadAgent = new SingularityAgent("2", "h1", "r1", ImmutableMap.of("uniqueAttribute", "2"), Optional.empty());
final long now = System.currentTimeMillis();
liveAgent = liveAgent.changeState(new SingularityMachineStateHistoryUpdate("1", MachineState.ACTIVE, 100, Optional.empty(), Optional.empty()));
deadAgent = deadAgent.changeState(new SingularityMachineStateHistoryUpdate("2", MachineState.DEAD, now - TimeUnit.HOURS.toMillis(10), Optional.empty(), Optional.empty()));
agentManager.saveObject(liveAgent);
agentManager.saveObject(deadAgent);
agentReconciliationPoller.runActionOnPoll();
Assertions.assertEquals(1, agentManager.getObjectsFiltered(MachineState.ACTIVE).size());
Assertions.assertEquals(1, agentManager.getObjectsFiltered(MachineState.DEAD).size());
configuration.setDeleteDeadAgentsAfterHours(1);
// dead agent should be deleted
agentReconciliationPoller.runActionOnPoll();
Assertions.assertEquals(1, agentManager.getObjectsFiltered(MachineState.ACTIVE).size());
Assertions.assertEquals(0, agentManager.getObjectsFiltered(MachineState.DEAD).size());
// reset config to previous value for subsequent tests
configuration.setDeleteDeadAgentsAfterHours(previousDeleteDeadAgentsAfterHours);
}
use of com.hubspot.singularity.SingularityAgent in project Singularity by HubSpot.
the class SingularityMachinesTest method testSystemChangeClearsExpiringChangeIfInvalid.
@Test
public void testSystemChangeClearsExpiringChangeIfInvalid() {
SingularityAgent agent = getSingleSlave();
agentResource.freezeAgent(singularityUser, agent.getId(), null);
agentResource.activateAgent(singularityUser, agent.getId(), new SingularityMachineChangeRequest(Optional.of(1L), Optional.empty(), Optional.empty(), Optional.of(MachineState.FROZEN), Optional.empty()));
Assertions.assertTrue(agentManager.getExpiringObject(agent.getId()).isPresent());
agentResource.decommissionAgent(singularityUser, agent.getId(), null);
Assertions.assertFalse(agentManager.getExpiringObject(agent.getId()).isPresent());
}
use of com.hubspot.singularity.SingularityAgent in project Singularity by HubSpot.
the class SingularityMachinesTest method itShouldMarkSlavesFromInactiveHostAsDecommissioned.
@Test
public void itShouldMarkSlavesFromInactiveHostAsDecommissioned() {
inactiveAgentManager.deactivateAgent("host1");
resourceOffers();
SingularityAgent agent = agentManager.getObject("agent1").get();
Assertions.assertTrue(agent.getCurrentState().getState().isDecommissioning());
}
use of com.hubspot.singularity.SingularityAgent in project Singularity by HubSpot.
the class SingularityMachinesTest method testMissingAgentsArePurged.
@Test
public void testMissingAgentsArePurged() {
long previousDeleteDeadAgentsAfterHours = configuration.getDeleteDeadAgentsAfterHours();
SingularityAgent liveAgent = new SingularityAgent("3", "h1", "r1", ImmutableMap.of("uniqueAttribute", "3"), Optional.empty());
SingularityAgent missingAgent = new SingularityAgent("4", "h1", "r1", ImmutableMap.of("uniqueAttribute", "4"), Optional.empty());
final long now = System.currentTimeMillis();
liveAgent = liveAgent.changeState(new SingularityMachineStateHistoryUpdate("3", MachineState.ACTIVE, 100, Optional.empty(), Optional.empty()));
missingAgent = missingAgent.changeState(new SingularityMachineStateHistoryUpdate("4", MachineState.MISSING_ON_STARTUP, now - TimeUnit.HOURS.toMillis(10), Optional.empty(), Optional.empty()));
agentManager.saveObject(liveAgent);
agentManager.saveObject(missingAgent);
agentReconciliationPoller.runActionOnPoll();
Assertions.assertEquals(1, agentManager.getObjectsFiltered(MachineState.ACTIVE).size());
Assertions.assertEquals(1, agentManager.getObjectsFiltered(MachineState.MISSING_ON_STARTUP).size());
configuration.setDeleteDeadAgentsAfterHours(1);
// missing agent should be deleted
agentReconciliationPoller.runActionOnPoll();
Assertions.assertEquals(1, agentManager.getObjectsFiltered(MachineState.ACTIVE).size());
Assertions.assertEquals(0, agentManager.getObjectsFiltered(MachineState.MISSING_ON_STARTUP).size());
// reset config to previous value for subsequent tests
configuration.setDeleteDeadAgentsAfterHours(previousDeleteDeadAgentsAfterHours);
}
Aggregations