use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class ValidatorTest method whenRunNowItForbidsTooLongRunIds.
@Test(expected = WebApplicationException.class)
public void whenRunNowItForbidsTooLongRunIds() {
String deployID = "deploy";
Optional<String> userEmail = Optional.absent();
SingularityRequest request = new SingularityRequestBuilder("request2", RequestType.SERVICE).build();
Optional<SingularityRunNowRequest> runNowRequest = Optional.of(runNowRequest(tooLongId()));
List<SingularityTaskId> activeTasks = Collections.emptyList();
List<SingularityPendingTaskId> pendingTasks = Collections.emptyList();
validator.checkRunNowRequest(deployID, userEmail, request, runNowRequest, activeTasks, pendingTasks);
}
use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class SingularityMesosOfferSchedulerTest method itAccountsForExpectedTaskUsage.
@Test
public void itAccountsForExpectedTaskUsage() {
initRequest();
double cpuReserved = 2;
double memMbReserved = 1000;
initFirstDeployWithResources(cpuReserved, memMbReserved);
saveAndSchedule(requestManager.getRequest(requestId).get().getRequest().toBuilder().setInstances(Optional.of(1)));
resourceOffers(3);
SingularityTaskId taskId = taskManager.getActiveTaskIds().get(0);
String t1 = taskId.getId();
// 2 cpus used
MesosTaskMonitorObject t1u1 = getTaskMonitor(t1, 10, TimeUnit.MILLISECONDS.toSeconds(taskId.getStartedAt()) + 5, 1000);
mesosClient.setSlaveResourceUsage("host1", Collections.singletonList(t1u1));
usagePoller.runActionOnPoll();
Map<ResourceUsageType, Number> longRunningTasksUsage = new HashMap<>();
longRunningTasksUsage.put(ResourceUsageType.CPU_USED, 0.1);
longRunningTasksUsage.put(ResourceUsageType.MEMORY_BYTES_USED, 0.1);
longRunningTasksUsage.put(ResourceUsageType.DISK_BYTES_USED, 0.1);
SingularitySlaveUsage smallUsage = new SingularitySlaveUsage(0.1, 0.1, Optional.of(10.0), 1, 1, Optional.of(30L), 1, 1, Optional.of(1024L), longRunningTasksUsage, 1, System.currentTimeMillis(), 1, 30000, 10, 0, 0, 0, 0, 107374182);
usageManager.saveSpecificSlaveUsageAndSetCurrent("host1", smallUsage);
usageManager.saveSpecificSlaveUsageAndSetCurrent("host2", smallUsage);
usageManager.saveSpecificSlaveUsageAndSetCurrent("host3", smallUsage);
requestResource.scale(requestId, new SingularityScaleRequest(Optional.of(3), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent()), SingularityUser.DEFAULT_USER);
Assert.assertEquals(2.0, usageManager.getRequestUtilizations().get(requestId).getCpuUsed(), 0.001);
Offer host2Offer = createOffer(6, 30000, 107374182, "host2", "host2");
slaveAndRackManager.checkOffer(host2Offer);
Offer host3Offer = createOffer(6, 30000, 107374182, "host3", "host3");
slaveAndRackManager.checkOffer(host3Offer);
Collection<SingularityOfferHolder> offerHolders = offerScheduler.checkOffers(Arrays.asList(host2Offer, host3Offer));
Assert.assertEquals(2, offerHolders.size());
// A single offer should only ever get a single task even though both have room for both tasks here. Adding a task should reduce the score for the next check
for (SingularityOfferHolder offerHolder : offerHolders) {
Assert.assertEquals(1, offerHolder.getAcceptedTasks().size());
}
}
use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class SingularitySchedulerTestBase method prepTask.
protected SingularityTask prepTask(SingularityRequest request, SingularityDeploy deploy, long launchTime, int instanceNo, boolean separateHosts, Optional<String> runId) {
SingularityPendingTask pendingTask = buildPendingTask(request, deploy, launchTime, instanceNo, runId);
SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
Offer offer;
if (separateHosts) {
offer = createOffer(125, 1024, 2048, String.format("slave%s", instanceNo), String.format("host%s", instanceNo));
} else {
offer = createOffer(125, 1024, 2048);
}
SingularityTaskId taskId = new SingularityTaskId(request.getId(), deploy.getId(), launchTime, instanceNo, offer.getHostname(), "rack1");
TaskID taskIdProto = TaskID.newBuilder().setValue(taskId.toString()).build();
TaskInfo taskInfo = TaskInfo.newBuilder().setAgentId(offer.getAgentId()).setExecutor(ExecutorInfo.newBuilder().setExecutorId(ExecutorID.newBuilder().setValue("executorID"))).setTaskId(taskIdProto).setName("name").build();
SingularityTask task = new SingularityTask(taskRequest, taskId, Collections.singletonList(mesosProtosUtils.offerFromProtos(offer)), mesosProtosUtils.taskFromProtos(taskInfo), Optional.of("rack1"));
taskManager.savePendingTask(pendingTask);
return task;
}
use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class SingularityDeploysTest method testDeployWithManualStep.
@Test
public void testDeployWithManualStep() {
initRequest();
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
initFirstDeploy();
SingularityTask firstTask = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
SingularityTask secondTask = launchTask(request, firstDeploy, 2, TaskState.TASK_RUNNING);
deploy(secondDeployId, Optional.<Boolean>absent(), Optional.of(1), Optional.of(false), false);
deployChecker.checkDeploys();
scheduler.drainPendingQueue();
Assert.assertEquals(1, taskManager.getPendingTaskIds().size());
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).size());
SingularityTaskId firstNewTaskId = taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).get(0);
statusUpdate(taskManager.getTask(firstNewTaskId).get(), TaskState.TASK_RUNNING);
deployChecker.checkDeploys();
Assert.assertEquals(1, taskManager.getCleanupTaskIds().size());
Assert.assertTrue(taskManager.getCleanupTaskIds().contains(firstTask.getTaskId()));
SingularityDeployProgress deployProgressStepOne = deployManager.getPendingDeploys().get(0).getDeployProgress().get();
Assert.assertTrue(deployProgressStepOne.isStepComplete());
Assert.assertEquals(1, deployProgressStepOne.getTargetActiveInstances());
cleaner.drainCleanupQueue();
statusUpdate(firstTask, TaskState.TASK_KILLED);
deployChecker.checkDeploys();
// Deploy should not have moved to next step even though instances are launched
deployProgressStepOne = deployManager.getPendingDeploys().get(0).getDeployProgress().get();
Assert.assertTrue(deployProgressStepOne.isStepComplete());
Assert.assertEquals(1, deployProgressStepOne.getTargetActiveInstances());
// Add the 'ok' to move to the next step
deployResource.updatePendingDeploy(singularityUser, new SingularityUpdatePendingDeployRequest(requestId, secondDeployId, 2));
deployChecker.checkDeploys();
SingularityDeployProgress deployProgressStepTwo = deployManager.getPendingDeploys().get(0).getDeployProgress().get();
Assert.assertFalse(deployProgressStepTwo.isStepComplete());
Assert.assertEquals(2, deployProgressStepTwo.getTargetActiveInstances());
scheduler.drainPendingQueue();
Assert.assertEquals(1, taskManager.getPendingTaskIds().size());
resourceOffers();
Assert.assertEquals(2, taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).size());
for (SingularityTaskId taskId : taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId)) {
statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
}
deployChecker.checkDeploys();
Assert.assertEquals(2, taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).size());
Assert.assertEquals(DeployState.SUCCEEDED, deployManager.getDeployResult(requestId, secondDeployId).get().getDeployState());
}
use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class SingularityDeploysTest method testIncrementalDeployCancel.
@Test
public void testIncrementalDeployCancel() {
initRequest();
// Set up incremental deploy that is partly finished
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
initFirstDeploy();
SingularityTask firstTask = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
launchTask(request, firstDeploy, 2, TaskState.TASK_RUNNING);
deploy(secondDeployId, Optional.<Boolean>absent(), Optional.of(1), Optional.<Boolean>absent(), false);
deployChecker.checkDeploys();
scheduler.drainPendingQueue();
resourceOffers();
SingularityTaskId firstNewTaskId = taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).get(0);
statusUpdate(taskManager.getTask(firstNewTaskId).get(), TaskState.TASK_RUNNING);
deployChecker.checkDeploys();
cleaner.drainCleanupQueue();
statusUpdate(firstTask, TaskState.TASK_KILLED);
deployChecker.checkDeploys();
scheduler.drainPendingQueue();
resourceOffers();
// End in-progress incremental deploy setup
deployResource.cancelDeploy(singularityUser, requestId, secondDeployId);
deployChecker.checkDeploys();
Assert.assertEquals(taskManager.getCleanupTasks().get(0).getCleanupType(), TaskCleanupType.INCREMENTAL_DEPLOY_CANCELLED);
// Incremental deploy task should not be shut down while active deploy is below target instances
cleaner.drainCleanupQueue();
Assert.assertTrue(taskManager.getKilledTaskIdRecords().isEmpty());
Assert.assertEquals(taskManager.getCleanupTasks().get(0).getCleanupType(), TaskCleanupType.INCREMENTAL_DEPLOY_CANCELLED);
launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
cleaner.drainCleanupQueue();
Assert.assertFalse(taskManager.getKilledTaskIdRecords().isEmpty());
}
Aggregations