use of com.hubspot.singularity.SingularityRequest in project Singularity by HubSpot.
the class SingularityDeploysTest method testLbUpdatesAfterEachDeployStep.
@Test
public void testLbUpdatesAfterEachDeployStep() {
initLoadBalancedRequest();
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.<Boolean>absent(), true);
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();
SingularityPendingDeploy pendingDeploy = deployManager.getPendingDeploy(requestId).get();
Assert.assertEquals(DeployState.WAITING, pendingDeploy.getCurrentDeployState());
testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING);
deployChecker.checkDeploys();
pendingDeploy = deployManager.getPendingDeploy(requestId).get();
Assert.assertEquals(DeployState.WAITING, pendingDeploy.getCurrentDeployState());
testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS);
deployChecker.checkDeploys();
Assert.assertTrue(taskManager.getCleanupTaskIds().contains(firstTask.getTaskId()));
pendingDeploy = deployManager.getPendingDeploy(requestId).get();
SingularityDeployProgress deployProgressStepOne = pendingDeploy.getDeployProgress().get();
Assert.assertTrue(deployProgressStepOne.isStepComplete());
Assert.assertEquals(1, deployProgressStepOne.getTargetActiveInstances());
cleaner.drainCleanupQueue();
statusUpdate(firstTask, TaskState.TASK_KILLED);
deployChecker.checkDeploys();
pendingDeploy = deployManager.getPendingDeploy(requestId).get();
Assert.assertFalse(pendingDeploy.getDeployProgress().get().isStepComplete());
Assert.assertEquals(2, pendingDeploy.getDeployProgress().get().getTargetActiveInstances());
scheduler.drainPendingQueue();
Assert.assertEquals(1, taskManager.getPendingTaskIds().size());
resourceOffers();
Assert.assertEquals(2, taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).size());
SingularityTaskId secondNewTaskId = null;
for (SingularityTaskId taskId : taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId)) {
if (taskId.getInstanceNo() == 2) {
secondNewTaskId = taskId;
}
}
statusUpdate(taskManager.getTask(secondNewTaskId).get(), TaskState.TASK_RUNNING);
testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING);
deployChecker.checkDeploys();
pendingDeploy = deployManager.getPendingDeploy(requestId).get();
Assert.assertEquals(DeployState.WAITING, pendingDeploy.getCurrentDeployState());
testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS);
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.SingularityRequest in project Singularity by HubSpot.
the class SingularityOfferPerformanceTestRunner method testSchedulerPerformance.
@Test(timeout = 600000L)
@Ignore
public void testSchedulerPerformance() {
long start = System.currentTimeMillis();
int numRequests = 4500;
int numOffers = 2500;
Random r = new Random();
Iterator<Double> cpuIterator = r.doubles(1, 5).iterator();
Iterator<Double> memoryIterator = r.doubles(15, 20000).iterator();
Iterator<Double> diskIterator = r.doubles(30, 50000).iterator();
for (int i = 0; i < numRequests; i++) {
SingularityRequestBuilder bldr = new SingularityRequestBuilder("request-" + i, RequestType.SERVICE);
bldr.setInstances(Optional.of(5));
bldr.setSlavePlacement(Optional.of(SlavePlacement.GREEDY));
SingularityRequest request = bldr.build();
saveRequest(request);
deployRequest(request, cpuIterator.next(), memoryIterator.next());
}
List<Offer> offers = new ArrayList<>(numOffers);
for (int i = 0; i < numOffers; i++) {
offers.add(createOffer(cpuIterator.next(), memoryIterator.next(), diskIterator.next(), "slave-" + i, "host-" + i));
}
System.out.println("Starting after " + JavaUtils.duration(start));
start = System.currentTimeMillis();
sms.resourceOffers(offers);
final long duration = System.currentTimeMillis() - start;
int activeTasks = taskManager.getActiveTaskIds().size();
System.out.println(String.format("Launched %s tasks on %s offers in %s", activeTasks, numOffers, JavaUtils.durationFromMillis(duration)));
start = System.currentTimeMillis();
ExecutorService statusUpadtes = Executors.newFixedThreadPool(100);
CompletableFuture<Void>[] updateFutures = new CompletableFuture[taskManager.getActiveTaskIds().size() * 5];
AtomicInteger i = new AtomicInteger(0);
for (SingularityTaskId taskId : taskManager.getActiveTaskIds()) {
updateFutures[i.getAndIncrement()] = CompletableFuture.supplyAsync(() -> {
statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_STAGING);
return null;
}, statusUpadtes);
updateFutures[i.getAndIncrement()] = CompletableFuture.supplyAsync(() -> {
statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_STARTING);
return null;
}, statusUpadtes);
updateFutures[i.getAndIncrement()] = CompletableFuture.supplyAsync(() -> {
statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
return null;
}, statusUpadtes);
updateFutures[i.getAndIncrement()] = CompletableFuture.supplyAsync(() -> {
statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_FAILED);
return null;
}, statusUpadtes);
updateFutures[i.getAndIncrement()] = CompletableFuture.supplyAsync(() -> {
statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_FAILED);
return null;
}, statusUpadtes);
}
CompletableFuture.allOf(updateFutures).join();
System.out.println(String.format("Ran %s status updates in %s", activeTasks * 5, JavaUtils.durationFromMillis(System.currentTimeMillis() - start)));
}
use of com.hubspot.singularity.SingularityRequest in project Singularity by HubSpot.
the class SingularitySchedulerTestBase method buildRequest.
protected SingularityRequest buildRequest(String requestId) {
SingularityRequest request = new SingularityRequestBuilder(requestId, RequestType.WORKER).build();
saveRequest(request);
return request;
}
use of com.hubspot.singularity.SingularityRequest in project Singularity by HubSpot.
the class StateManagerTest method itDoesntCountCleaningTasks.
@Test
public void itDoesntCountCleaningTasks() {
initRequest();
initFirstDeploy();
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
saveAndSchedule(request.toBuilder().setInstances(Optional.of(3)));
resourceOffers();
Assert.assertEquals(3, taskManager.getActiveTaskIds().size());
Assert.assertEquals(0, stateManager.getState(true, false).getOverProvisionedRequests());
Assert.assertEquals(0, stateManager.getState(true, false).getUnderProvisionedRequests());
SingularityTask task = taskManager.getActiveTasks().get(0);
statusUpdate(task, TaskState.TASK_KILLED);
scheduler.drainPendingQueue();
taskManager.createTaskCleanup(new SingularityTaskCleanup(Optional.absent(), TaskCleanupType.BOUNCING, 1L, task.getTaskId(), Optional.absent(), Optional.absent(), Optional.absent()));
Assert.assertEquals(2, taskManager.getActiveTaskIds().size());
Assert.assertEquals(0, stateManager.getState(true, false).getOverProvisionedRequests());
Assert.assertEquals(1, stateManager.getState(true, false).getUnderProvisionedRequests());
launchTask(request, firstDeploy, 4, TaskState.TASK_RUNNING);
launchTask(request, firstDeploy, 5, TaskState.TASK_RUNNING);
Assert.assertEquals(4, taskManager.getActiveTaskIds().size());
Assert.assertEquals(0, stateManager.getState(true, false).getUnderProvisionedRequests());
Assert.assertEquals(1, stateManager.getState(true, false).getOverProvisionedRequests());
}
use of com.hubspot.singularity.SingularityRequest in project Singularity by HubSpot.
the class ValidatorTest method itForbidsRunNowOfScheduledWhenAlreadyRunning.
@Test(expected = WebApplicationException.class)
public void itForbidsRunNowOfScheduledWhenAlreadyRunning() {
String deployID = "deploy";
Optional<String> userEmail = Optional.absent();
SingularityRequest request = new SingularityRequestBuilder("request2", RequestType.SCHEDULED).setInstances(Optional.of(1)).build();
Optional<SingularityRunNowRequest> runNowRequest = Optional.absent();
List<SingularityTaskId> activeTasks = Collections.singletonList(activeTask());
List<SingularityPendingTaskId> pendingTasks = Collections.emptyList();
validator.checkRunNowRequest(deployID, userEmail, request, runNowRequest, activeTasks, pendingTasks);
}
Aggregations