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());
}
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;
}
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);
}
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);
}
}
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());
}
}
Aggregations