use of com.hubspot.singularity.SingularitySlave in project Singularity by HubSpot.
the class SingularityUsageHelper method getSlaveIdsToTrackUsageFor.
public Set<String> getSlaveIdsToTrackUsageFor() {
List<SingularitySlave> slaves = getSlavesToTrackUsageFor();
Set<String> slaveIds = new HashSet<>(slaves.size());
for (SingularitySlave slave : slaves) {
slaveIds.add(slave.getId());
}
return slaveIds;
}
use of com.hubspot.singularity.SingularitySlave in project Singularity by HubSpot.
the class UsageResource method getSlaveCurrentTaskUsage.
@GET
@Path("/slaves/{slaveId}/tasks/current")
public List<SingularityTaskCurrentUsageWithId> getSlaveCurrentTaskUsage(@Auth SingularityUser user, @PathParam("slaveId") String slaveId) {
authorizationHelper.checkAdminAuthorization(user);
Optional<SingularitySlave> slave = slaveManager.getObject(slaveId);
WebExceptions.checkNotFound(slave.isPresent(), "No slave found with id %s", slaveId);
List<SingularityTask> tasksOnSlave = taskManager.getTasksOnSlave(taskManager.getActiveTaskIds(), slave.get());
List<SingularityTaskId> taskIds = new ArrayList<>(tasksOnSlave.size());
for (SingularityTask task : tasksOnSlave) {
taskIds.add(task.getTaskId());
}
return usageManager.getTaskCurrentUsages(taskIds);
}
use of com.hubspot.singularity.SingularitySlave in project Singularity by HubSpot.
the class SingularityMachineStatesTest method testValidTransitionToDecommissioned.
@Test
public void testValidTransitionToDecommissioned() {
initRequest();
initFirstDeploy();
requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
scheduler.drainPendingQueue();
resourceOffers(1);
SingularitySlave slave = slaveManager.getObjects().get(0);
slaveResource.decommissionSlave(singularityUser, slave.getId(), new SingularityMachineChangeRequest(Optional.of(1L), Optional.absent(), Optional.absent(), Optional.of(MachineState.DECOMMISSIONED), Optional.of(true)));
Assert.assertEquals(MachineState.STARTING_DECOMMISSION, slaveManager.getObjects().get(0).getCurrentState().getState());
scheduler.checkForDecomissions();
scheduler.drainPendingQueue();
Assert.assertEquals(TaskCleanupType.DECOMISSIONING, taskManager.getCleanupTasks().get(0).getCleanupType());
expiringUserActionPoller.runActionOnPoll();
Assert.assertEquals(MachineState.DECOMMISSIONED, slaveManager.getObjects().get(0).getCurrentState().getState());
Assert.assertEquals(TaskCleanupType.DECOMMISSION_TIMEOUT, taskManager.getCleanupTasks().get(0).getCleanupType());
}
use of com.hubspot.singularity.SingularitySlave in project Singularity by HubSpot.
the class SingularityMachineStatesTest method testDeadSlavesArePurged.
@Test
public void testDeadSlavesArePurged() {
SingularitySlave liveSlave = new SingularitySlave("1", "h1", "r1", ImmutableMap.of("uniqueAttribute", "1"), Optional.absent());
SingularitySlave deadSlave = new SingularitySlave("2", "h1", "r1", ImmutableMap.of("uniqueAttribute", "2"), Optional.absent());
final long now = System.currentTimeMillis();
liveSlave = liveSlave.changeState(new SingularityMachineStateHistoryUpdate("1", MachineState.ACTIVE, 100, Optional.absent(), Optional.absent()));
deadSlave = deadSlave.changeState(new SingularityMachineStateHistoryUpdate("2", MachineState.DEAD, now - TimeUnit.HOURS.toMillis(10), Optional.absent(), Optional.absent()));
slaveManager.saveObject(liveSlave);
slaveManager.saveObject(deadSlave);
slaveReconciliationPoller.runActionOnPoll();
Assert.assertEquals(1, slaveManager.getObjectsFiltered(MachineState.ACTIVE).size());
Assert.assertEquals(1, slaveManager.getObjectsFiltered(MachineState.DEAD).size());
configuration.setDeleteDeadSlavesAfterHours(1);
slaveReconciliationPoller.runActionOnPoll();
Assert.assertEquals(1, slaveManager.getObjectsFiltered(MachineState.ACTIVE).size());
Assert.assertEquals(0, slaveManager.getObjectsFiltered(MachineState.DEAD).size());
}
use of com.hubspot.singularity.SingularitySlave in project Singularity by HubSpot.
the class SingularityMachineStatesTest method testBadExpiringStateTransition.
@Test(expected = WebApplicationException.class)
public void testBadExpiringStateTransition() {
SingularitySlave slave = getSingleSlave();
slaveResource.decommissionSlave(singularityUser, slave.getId(), new SingularityMachineChangeRequest(Optional.of(1L), Optional.absent(), Optional.absent(), Optional.of(MachineState.FROZEN), Optional.absent()));
}
Aggregations