Search in sources :

Example 6 with SingularityAgent

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());
}
Also used : SingularityMachineChangeRequest(com.hubspot.singularity.api.SingularityMachineChangeRequest) MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject) SingularityAgent(com.hubspot.singularity.SingularityAgent) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.jupiter.api.Test)

Example 7 with SingularityAgent

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);
}
Also used : SingularityMachineStateHistoryUpdate(com.hubspot.singularity.SingularityMachineStateHistoryUpdate) SingularityAgent(com.hubspot.singularity.SingularityAgent) Test(org.junit.jupiter.api.Test)

Example 8 with SingularityAgent

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());
}
Also used : SingularityMachineChangeRequest(com.hubspot.singularity.api.SingularityMachineChangeRequest) SingularityAgent(com.hubspot.singularity.SingularityAgent) Test(org.junit.jupiter.api.Test)

Example 9 with SingularityAgent

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());
}
Also used : SingularityAgent(com.hubspot.singularity.SingularityAgent) Test(org.junit.jupiter.api.Test)

Example 10 with SingularityAgent

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);
}
Also used : SingularityMachineStateHistoryUpdate(com.hubspot.singularity.SingularityMachineStateHistoryUpdate) SingularityAgent(com.hubspot.singularity.SingularityAgent) Test(org.junit.jupiter.api.Test)

Aggregations

SingularityAgent (com.hubspot.singularity.SingularityAgent)26 Test (org.junit.jupiter.api.Test)13 SingularityMachineChangeRequest (com.hubspot.singularity.api.SingularityMachineChangeRequest)6 MesosMasterStateObject (com.hubspot.mesos.json.MesosMasterStateObject)4 MachineState (com.hubspot.singularity.MachineState)4 SingularityRack (com.hubspot.singularity.SingularityRack)4 ArrayList (java.util.ArrayList)4 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)3 MesosMasterAgentObject (com.hubspot.mesos.json.MesosMasterAgentObject)2 SingularityMachineStateHistoryUpdate (com.hubspot.singularity.SingularityMachineStateHistoryUpdate)2 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)2 SingularityTask (com.hubspot.singularity.SingularityTask)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 Timed (com.codahale.metrics.annotation.Timed)1 HashMultiset (com.google.common.collect.HashMultiset)1 Multiset (com.google.common.collect.Multiset)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 AgentPlacement (com.hubspot.singularity.AgentPlacement)1