Search in sources :

Example 1 with MesosMasterStateObject

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

the class SingularityMachineStatesTest method testLoadSlavesFromMasterDataOnStartup.

@Test
public void testLoadSlavesFromMasterDataOnStartup() {
    MesosMasterStateObject state = getMasterState(3);
    singularitySlaveAndRackManager.loadSlavesAndRacksFromMaster(state, true);
    List<SingularitySlave> slaves = slaveManager.getObjects();
    Assert.assertEquals(3, slaves.size());
    for (SingularitySlave slave : slaves) {
        Assert.assertEquals(MachineState.ACTIVE, slave.getCurrentState().getState());
    }
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject) Test(org.junit.Test)

Example 2 with MesosMasterStateObject

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

the class SingularityMachineStatesTest method testReconcileSlaves.

@Test
public void testReconcileSlaves() {
    // Load 3 slaves on startup
    MesosMasterStateObject state = getMasterState(3);
    singularitySlaveAndRackManager.loadSlavesAndRacksFromMaster(state, true);
    // 2 slaves, third has died
    MesosMasterStateObject newState = getMasterState(2);
    singularitySlaveAndRackManager.loadSlavesAndRacksFromMaster(newState, false);
    List<SingularitySlave> slaves = slaveManager.getObjects();
    Assert.assertEquals(3, slaves.size());
    for (SingularitySlave slave : slaves) {
        if (slave.getId().equals("2")) {
            Assert.assertEquals(MachineState.DEAD, slave.getCurrentState().getState());
        } else {
            Assert.assertEquals(MachineState.ACTIVE, slave.getCurrentState().getState());
        }
    }
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject) Test(org.junit.Test)

Example 3 with MesosMasterStateObject

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

the class SingularityAgentReconciliationPoller method refereshAgentsAndRacks.

private void refereshAgentsAndRacks() {
    try {
        Optional<MasterInfo> maybeMasterInfo = mesosScheduler.getMaster();
        if (maybeMasterInfo.isPresent()) {
            final String uri = mesosClient.getMasterUri(MesosUtils.getMasterHostAndPort(maybeMasterInfo.get()));
            MesosMasterStateObject state = mesosClient.getMasterState(uri);
            agentAndRackManager.loadAgentsAndRacksFromMaster(state, false);
        }
    } catch (Exception e) {
        LOG.error("Could not refresh agent data", e);
    }
}
Also used : MasterInfo(org.apache.mesos.v1.Protos.MasterInfo) MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject)

Example 4 with MesosMasterStateObject

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

the class SingularityStartup method startup.

public void startup(MasterInfo masterInfo) {
    final long start = System.currentTimeMillis();
    final String uri = mesosClient.getMasterUri(MesosUtils.getMasterHostAndPort(masterInfo));
    LOG.info("Starting up... fetching state data from: " + uri);
    MesosMasterStateObject state = mesosClient.getMasterState(uri);
    agentAndRackManager.checkDecommissionedAgentsFromMaster(state, true);
    agentAndRackManager.loadAgentsAndRacksFromMaster(state, true);
    ExecutorService startupExecutor = Executors.newFixedThreadPool(configuration.getSchedulerStartupConcurrency(), new ThreadFactoryBuilder().setNameFormat("startup-%d").build());
    List<CompletableFuture<Void>> checkFutures = checkSchedulerForInconsistentState(startupExecutor);
    CompletableFutures.allOf(enqueueHealthAndNewTaskChecks(startupExecutor)).join();
    CompletableFutures.allOf(checkFutures).join();
    startupExecutor.shutdown();
    if (!disasterManager.isDisabled(SingularityAction.STARTUP_TASK_RECONCILIATION)) {
        taskReconciliation.startReconciliation();
    }
    LOG.info("Finished startup after {}", JavaUtils.duration(start));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ExecutorService(java.util.concurrent.ExecutorService) MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder)

Example 5 with MesosMasterStateObject

use of com.hubspot.mesos.json.MesosMasterStateObject 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)

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