Search in sources :

Example 26 with SingularityTaskId

use of com.hubspot.singularity.SingularityTaskId 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());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityPendingDeploy(com.hubspot.singularity.SingularityPendingDeploy) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployProgress(com.hubspot.singularity.SingularityDeployProgress) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 27 with SingularityTaskId

use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.

the class SingularityHealthchecksTest method testPortIndices.

@Test
public void testPortIndices() {
    try {
        setConfigurationForNoDelay();
        initRequest();
        HealthcheckOptions options = new HealthcheckOptionsBuilder("http://uri").setPortIndex(Optional.of(1)).setStartupDelaySeconds(Optional.of(0)).build();
        firstDeploy = initAndFinishDeploy(request, new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")).setHealthcheck(Optional.of(options)), Optional.of(new Resources(1, 64, 3, 0)));
        requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
        scheduler.drainPendingQueue();
        String[] portRange = { "80:82" };
        sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRange)));
        SingularityTaskId firstTaskId = taskManager.getActiveTaskIdsForRequest(requestId).get(0);
        SingularityTask firstTask = taskManager.getTask(firstTaskId).get();
        statusUpdate(firstTask, TaskState.TASK_RUNNING);
        newTaskChecker.enqueueNewTaskCheck(firstTask, requestManager.getRequest(requestId), healthchecker);
        Awaitility.await("healthcheck present").atMost(5, TimeUnit.SECONDS).until(() -> taskManager.getLastHealthcheck(firstTask.getTaskId()).isPresent());
        Assert.assertTrue(taskManager.getLastHealthcheck(firstTask.getTaskId()).get().toString().contains("host1:81"));
    } finally {
        unsetConfigurationForNoDelay();
    }
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 28 with SingularityTaskId

use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.

the class SingularityHealthchecksTest method testPortNumber.

@Test
public void testPortNumber() {
    try {
        setConfigurationForNoDelay();
        initRequest();
        HealthcheckOptions options = new HealthcheckOptionsBuilder("http://uri").setPortNumber(Optional.of(81L)).setStartupDelaySeconds(Optional.of(0)).build();
        firstDeploy = initAndFinishDeploy(request, new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")).setResources(Optional.of(new Resources(1, 64, 3, 0))).setHealthcheck(Optional.of(options)), Optional.absent());
        requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
        scheduler.drainPendingQueue();
        String[] portRange = { "80:82" };
        sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRange)));
        SingularityTaskId firstTaskId = taskManager.getActiveTaskIdsForRequest(requestId).get(0);
        SingularityTask firstTask = taskManager.getTask(firstTaskId).get();
        statusUpdate(firstTask, TaskState.TASK_RUNNING);
        newTaskChecker.enqueueNewTaskCheck(firstTask, requestManager.getRequest(requestId), healthchecker);
        Awaitility.await("healthcheck present").atMost(5, TimeUnit.SECONDS).until(() -> taskManager.getLastHealthcheck(firstTask.getTaskId()).isPresent());
        Assert.assertTrue(taskManager.getLastHealthcheck(firstTask.getTaskId()).get().toString().contains("host1:81"));
    } finally {
        unsetConfigurationForNoDelay();
    }
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 29 with SingularityTaskId

use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.

the class SingularityHealthchecksTest method testSkipHealthchecksDuringBounce.

@Test
public void testSkipHealthchecksDuringBounce() {
    try {
        initRequest();
        initHCDeploy();
        SingularityTask firstTask = startTask(firstDeploy, 1);
        requestResource.bounce(requestId, Optional.of(new SingularityBounceRequest(Optional.absent(), Optional.of(true), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent())), singularityUser);
        setConfigurationForNoDelay();
        cleaner.drainCleanupQueue();
        resourceOffers();
        List<SingularityTaskId> taskIds = taskManager.getAllTaskIds();
        taskIds.remove(firstTask.getTaskId());
        SingularityTaskId secondTaskId = taskIds.get(0);
        SingularityTask secondTask = taskManager.getTask(secondTaskId).get();
        statusUpdate(secondTask, TaskState.TASK_RUNNING);
        Assert.assertTrue(healthchecker.cancelHealthcheck(firstTask.getTaskId().getId()));
        newTaskChecker.cancelNewTaskCheck(firstTask.getTaskId().getId());
        finishHealthchecks();
        finishNewTaskChecks();
        Assert.assertTrue(!taskManager.getLastHealthcheck(secondTask.getTaskId()).isPresent());
        cleaner.drainCleanupQueue();
        killKilledTasks();
        Assert.assertEquals(0, taskManager.getNumCleanupTasks());
        Assert.assertEquals(1, taskManager.getNumActiveTasks());
    } finally {
        unsetConfigurationForNoDelay();
    }
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 30 with SingularityTaskId

use of com.hubspot.singularity.SingularityTaskId 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)));
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityRequest(com.hubspot.singularity.SingularityRequest) ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) Random(java.util.Random) Offer(org.apache.mesos.v1.Protos.Offer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SingularityTaskId (com.hubspot.singularity.SingularityTaskId)106 Test (org.junit.Test)44 SingularityTask (com.hubspot.singularity.SingularityTask)34 SingularityRequest (com.hubspot.singularity.SingularityRequest)26 ArrayList (java.util.ArrayList)26 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)14 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)13 MesosTaskMonitorObject (com.hubspot.mesos.json.MesosTaskMonitorObject)12 List (java.util.List)11 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)10 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)9 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)9 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)9 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)8 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)7 SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)7 SingularityTaskShellCommandRequestId (com.hubspot.singularity.SingularityTaskShellCommandRequestId)7 HashMap (java.util.HashMap)7 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)6 SingularitySlaveUsage (com.hubspot.singularity.SingularitySlaveUsage)6