Search in sources :

Example 16 with SingularitySlave

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;
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) HashSet(java.util.HashSet)

Example 17 with SingularitySlave

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);
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) SingularityTask(com.hubspot.singularity.SingularityTask) ArrayList(java.util.ArrayList) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 18 with SingularitySlave

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());
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) SingularityMachineChangeRequest(com.hubspot.singularity.api.SingularityMachineChangeRequest) Test(org.junit.Test)

Example 19 with SingularitySlave

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());
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) SingularityMachineStateHistoryUpdate(com.hubspot.singularity.SingularityMachineStateHistoryUpdate) Test(org.junit.Test)

Example 20 with SingularitySlave

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()));
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) SingularityMachineChangeRequest(com.hubspot.singularity.api.SingularityMachineChangeRequest) Test(org.junit.Test)

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