Search in sources :

Example 6 with SingularitySlave

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

the class InactiveSlaveManagerTest method itShouldMarkSlavesFromInactiveHostAsDecommissioned.

@Test
public void itShouldMarkSlavesFromInactiveHostAsDecommissioned() {
    inactiveSlaveManager.deactivateSlave("host1");
    resourceOffers();
    SingularitySlave slave = slaveManager.getObject("slave1").get();
    Assert.assertTrue(slave.getCurrentState().getState().isDecommissioning());
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) Test(org.junit.Test)

Example 7 with SingularitySlave

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

the class SingularityUsageHelper method getSlavesToTrackUsageFor.

public List<SingularitySlave> getSlavesToTrackUsageFor() {
    List<SingularitySlave> slaves = slaveManager.getObjects();
    List<SingularitySlave> slavesToTrack = new ArrayList<>(slaves.size());
    for (SingularitySlave slave : slaves) {
        if (slave.getCurrentState().getState().isInactive() || slave.getCurrentState().getState() == MachineState.DECOMMISSIONED) {
            continue;
        }
        slavesToTrack.add(slave);
    }
    return slavesToTrack;
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) ArrayList(java.util.ArrayList)

Example 8 with SingularitySlave

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

the class SingularityDisasterDetectionPoller method collectDisasterStats.

private SingularityDisasterDataPoint collectDisasterStats() {
    long now = System.currentTimeMillis();
    int numActiveTasks = taskManager.getNumActiveTasks();
    List<SingularityPendingTaskId> pendingTasks = taskManager.getPendingTaskIds();
    int numPendingTasks = pendingTasks.size();
    int numLateTasks = 0;
    long totalTaskLagMillis = 0;
    int numPastDueTasks = 0;
    for (SingularityPendingTaskId pendingTask : pendingTasks) {
        long taskLagMillis = now - pendingTask.getNextRunAt();
        if (taskLagMillis > 0) {
            numPastDueTasks++;
            totalTaskLagMillis += taskLagMillis;
            if (taskLagMillis > configuration.getDeltaAfterWhichTasksAreLateMillis()) {
                numLateTasks++;
            }
        }
    }
    long avgTaskLagMillis = totalTaskLagMillis / Math.max(numPastDueTasks, 1);
    List<SingularitySlave> slaves = slaveManager.getObjects();
    int numRunningSlaves = 0;
    for (SingularitySlave slave : slaves) {
        if (slave.getCurrentState().getState() != MachineState.DEAD && slave.getCurrentState().getState() != MachineState.MISSING_ON_STARTUP) {
            numRunningSlaves++;
        }
    }
    int numLostSlaves = activeSlavesLost.getAndSet(0);
    int numLostTasks = 0;
    for (Reason lostTaskReason : disasterConfiguration.getLostTaskReasons()) {
        numLostTasks += taskLostReasons.count(lostTaskReason);
    }
    taskLostReasons.clear();
    return new SingularityDisasterDataPoint(now, numActiveTasks, numPendingTasks, numLateTasks, avgTaskLagMillis, numLostTasks, numRunningSlaves, numLostSlaves);
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityDisasterDataPoint(com.hubspot.singularity.SingularityDisasterDataPoint) SingularityDisasterDataPoint(com.hubspot.singularity.SingularityDisasterDataPoint) Reason(org.apache.mesos.v1.Protos.TaskStatus.Reason)

Example 9 with SingularitySlave

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

the class SingularitySlaveAndRackManager method slaveLost.

void slaveLost(AgentID slaveIdObj) {
    final String slaveId = slaveIdObj.getValue();
    Optional<SingularitySlave> slave = slaveManager.getObject(slaveId);
    if (slave.isPresent()) {
        MachineState previousState = slave.get().getCurrentState().getState();
        slaveManager.changeState(slave.get(), MachineState.DEAD, Optional.absent(), Optional.absent());
        if (configuration.getDisasterDetection().isEnabled()) {
            updateDisasterCounter(previousState);
        }
        checkRackAfterSlaveLoss(slave.get());
    } else {
        LOG.warn("Lost a slave {}, but didn't know about it", slaveId);
    }
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) MachineState(com.hubspot.singularity.MachineState)

Example 10 with SingularitySlave

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

the class SingularitySlaveAndRackManager method checkRackAfterSlaveLoss.

private void checkRackAfterSlaveLoss(SingularitySlave lostSlave) {
    List<SingularitySlave> slaves = slaveManager.getObjectsFiltered(MachineState.ACTIVE);
    int numInRack = 0;
    for (SingularitySlave slave : slaves) {
        if (slave.getRackId().equals(lostSlave.getRackId())) {
            numInRack++;
        }
    }
    LOG.info("Found {} slaves left in rack {}", numInRack, lostSlave.getRackId());
    if (numInRack == 0) {
        rackManager.changeState(lostSlave.getRackId(), MachineState.DEAD, Optional.absent(), Optional.absent());
    }
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave)

Aggregations

SingularitySlave (com.hubspot.singularity.SingularitySlave)22 Test (org.junit.Test)10 SingularityMachineChangeRequest (com.hubspot.singularity.api.SingularityMachineChangeRequest)6 SingularityRack (com.hubspot.singularity.SingularityRack)4 MesosMasterStateObject (com.hubspot.mesos.json.MesosMasterStateObject)3 ArrayList (java.util.ArrayList)3 MachineState (com.hubspot.singularity.MachineState)2 SingularityTask (com.hubspot.singularity.SingularityTask)2 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)2 HashSet (java.util.HashSet)2 Timed (com.codahale.metrics.annotation.Timed)1 Optional (com.google.common.base.Optional)1 MesosMasterSlaveObject (com.hubspot.mesos.json.MesosMasterSlaveObject)1 SingularityDeleteResult (com.hubspot.singularity.SingularityDeleteResult)1 SingularityDeployMarker (com.hubspot.singularity.SingularityDeployMarker)1 SingularityDisasterDataPoint (com.hubspot.singularity.SingularityDisasterDataPoint)1 SingularityHostState (com.hubspot.singularity.SingularityHostState)1 SingularityMachineStateHistoryUpdate (com.hubspot.singularity.SingularityMachineStateHistoryUpdate)1 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)1 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)1