Search in sources :

Example 11 with MesosMasterStateObject

use of com.hubspot.mesos.json.MesosMasterStateObject in project Singularity by HubSpot.

the class SingularityMachineStatesTest method getMasterState.

private MesosMasterStateObject getMasterState(int numSlaves) {
    long now = System.currentTimeMillis();
    Map<String, Object> resources = new HashMap<>();
    resources.put("cpus", 10);
    resources.put("mem", 2000);
    Map<String, String> attributes = new HashMap<>();
    attributes.put("testKey", "testValue");
    List<MesosMasterSlaveObject> slaves = new ArrayList<>();
    for (Integer i = 0; i < numSlaves; i++) {
        slaves.add(new MesosMasterSlaveObject(i.toString(), i.toString(), String.format("localhost:505%s", i), now, new MesosResourcesObject(resources), attributes, new MesosResourcesObject(resources), new MesosResourcesObject(resources), new MesosResourcesObject(resources), new MesosResourcesObject(resources), "", true));
    }
    MesosFrameworkObject framework = new MesosFrameworkObject("", "", "", "", "", "", "", now, now, now, true, true, new MesosResourcesObject(resources), new MesosResourcesObject(resources), new MesosResourcesObject(resources), Collections.emptyList());
    return new MesosMasterStateObject("", "", "", "", now, "", now, now, "", "", "", 0, 0, "", "", "", Collections.emptyMap(), slaves, Collections.singletonList(framework));
}
Also used : MesosResourcesObject(com.hubspot.mesos.json.MesosResourcesObject) HashMap(java.util.HashMap) MesosFrameworkObject(com.hubspot.mesos.json.MesosFrameworkObject) MesosMasterSlaveObject(com.hubspot.mesos.json.MesosMasterSlaveObject) ArrayList(java.util.ArrayList) MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject) MesosResourcesObject(com.hubspot.mesos.json.MesosResourcesObject) MesosMasterSlaveObject(com.hubspot.mesos.json.MesosMasterSlaveObject) MesosFrameworkObject(com.hubspot.mesos.json.MesosFrameworkObject) MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject)

Example 12 with MesosMasterStateObject

use of com.hubspot.mesos.json.MesosMasterStateObject in project Singularity by HubSpot.

the class SingularityMachinesTest method testReconcileSlavesOnStartup.

@Test
public void testReconcileSlavesOnStartup() {
    // Load 3 agents on startup
    MesosMasterStateObject state = getMasterState(3);
    singularityAgentAndRackManager.loadAgentsAndRacksFromMaster(state, true);
    // Load 2 agents on startup
    // 2 agents, third has died
    MesosMasterStateObject newState = getMasterState(2);
    singularityAgentAndRackManager.loadAgentsAndRacksFromMaster(newState, true);
    List<SingularityAgent> agents = agentManager.getObjects();
    Assertions.assertEquals(3, agents.size());
    for (SingularityAgent agent : agents) {
        if (agent.getId().equals("2")) {
            Assertions.assertEquals(MachineState.MISSING_ON_STARTUP, agent.getCurrentState().getState());
        } else {
            Assertions.assertEquals(MachineState.ACTIVE, agent.getCurrentState().getState());
        }
    }
}
Also used : MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject) SingularityAgent(com.hubspot.singularity.SingularityAgent) Test(org.junit.jupiter.api.Test)

Example 13 with MesosMasterStateObject

use of com.hubspot.mesos.json.MesosMasterStateObject in project Singularity by HubSpot.

the class SingularityMachinesTest method testLoadSlavesFromMasterDataOnStartup.

@Test
public void testLoadSlavesFromMasterDataOnStartup() {
    MesosMasterStateObject state = getMasterState(3);
    singularityAgentAndRackManager.loadAgentsAndRacksFromMaster(state, true);
    List<SingularityAgent> agents = agentManager.getObjects();
    Assertions.assertEquals(3, agents.size());
    for (SingularityAgent agent : agents) {
        Assertions.assertEquals(MachineState.ACTIVE, agent.getCurrentState().getState());
    }
}
Also used : MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject) SingularityAgent(com.hubspot.singularity.SingularityAgent) Test(org.junit.jupiter.api.Test)

Example 14 with MesosMasterStateObject

use of com.hubspot.mesos.json.MesosMasterStateObject in project Singularity by HubSpot.

the class SingularityMachinesTest method testReconcileSlaves.

@Test
public void testReconcileSlaves() {
    // Load 3 agents on startup
    MesosMasterStateObject state = getMasterState(3);
    singularityAgentAndRackManager.loadAgentsAndRacksFromMaster(state, true);
    // 2 agents, third has died
    MesosMasterStateObject newState = getMasterState(2);
    singularityAgentAndRackManager.loadAgentsAndRacksFromMaster(newState, false);
    List<SingularityAgent> agents = agentManager.getObjects();
    Assertions.assertEquals(3, agents.size());
    for (SingularityAgent agent : agents) {
        if (agent.getId().equals("2")) {
            Assertions.assertEquals(MachineState.DEAD, agent.getCurrentState().getState());
        } else {
            Assertions.assertEquals(MachineState.ACTIVE, agent.getCurrentState().getState());
        }
    }
}
Also used : MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject) SingularityAgent(com.hubspot.singularity.SingularityAgent) Test(org.junit.jupiter.api.Test)

Aggregations

MesosMasterStateObject (com.hubspot.mesos.json.MesosMasterStateObject)14 SingularityAgent (com.hubspot.singularity.SingularityAgent)4 Test (org.junit.jupiter.api.Test)4 SingularitySlave (com.hubspot.singularity.SingularitySlave)3 Test (org.junit.Test)3 MesosFrameworkObject (com.hubspot.mesos.json.MesosFrameworkObject)2 MesosResourcesObject (com.hubspot.mesos.json.MesosResourcesObject)2 SingularityMachineChangeRequest (com.hubspot.singularity.api.SingularityMachineChangeRequest)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 MasterInfo (org.apache.mesos.v1.Protos.MasterInfo)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 MesosMasterAgentObject (com.hubspot.mesos.json.MesosMasterAgentObject)1 MesosMasterSlaveObject (com.hubspot.mesos.json.MesosMasterSlaveObject)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 WebApplicationException (javax.ws.rs.WebApplicationException)1