Search in sources :

Example 11 with SingularityDeploy

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

the class HistoryPersisterTest method testDeployCountPurging.

@Test
public void testDeployCountPurging() {
    SingularityRequest requestOne = buildRequest("request1");
    SingularityRequest requestTwo = buildRequest("request2");
    SingularityDeploy requestOneDeployOne = initAndFinishDeploy(requestOne, "r1d1");
    SingularityDeploy requestOneDeployTwo = initAndFinishDeploy(requestOne, "r1d2");
    SingularityDeploy requestOneDeployThree = initAndFinishDeploy(requestOne, "r1d3");
    // r1d4 is the active deploy, not eligible for purging
    SingularityDeploy requestOneDeployFour = initAndFinishDeploy(requestOne, "r1d4");
    SingularityDeploy requestTwoDeployOne = initAndFinishDeploy(requestTwo, "r2d1");
    // r2d2 is the active deploy, not eligible for purging
    SingularityDeploy requestTwoDeployTwo = initAndFinishDeploy(requestTwo, "r2d2");
    configuration.setMaxStaleDeploysPerRequestInZkWhenNoDatabase(Optional.of(2));
    deployHistoryPersister.runActionOnPoll();
    Assert.assertTrue(!deployManager.getDeployHistory(requestOneDeployOne.getRequestId(), requestOneDeployOne.getId(), true).isPresent());
    Assert.assertTrue(deployManager.getDeployHistory(requestOneDeployTwo.getRequestId(), requestOneDeployTwo.getId(), true).isPresent());
    Assert.assertTrue(deployManager.getDeployHistory(requestOneDeployThree.getRequestId(), requestOneDeployThree.getId(), true).isPresent());
    Assert.assertTrue(deployManager.getDeployHistory(requestOneDeployFour.getRequestId(), requestOneDeployFour.getId(), true).isPresent());
    Assert.assertTrue(deployManager.getDeployHistory(requestTwoDeployOne.getRequestId(), requestTwoDeployOne.getId(), true).isPresent());
    Assert.assertTrue(deployManager.getDeployHistory(requestTwoDeployTwo.getRequestId(), requestTwoDeployTwo.getId(), true).isPresent());
}
Also used : SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 12 with SingularityDeploy

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

the class SingularityDeploysTest method testUsesNewRequestDataFromPendingDeploy.

@Test
public void testUsesNewRequestDataFromPendingDeploy() {
    initRequest();
    initFirstDeploy();
    saveAndSchedule(request.toBuilder().setInstances(Optional.of(2)));
    scheduler.drainPendingQueue();
    Assert.assertEquals(2, taskManager.getPendingTaskIds().size());
    Assert.assertEquals(2, requestManager.getRequest(requestId).get().getRequest().getInstancesSafe());
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    SingularityRequest newRequest = request.toBuilder().setInstances(Optional.of(1)).build();
    String deployId = "test_new_request_data";
    SingularityDeploy deploy = new SingularityDeployBuilder(request.getId(), deployId).setCommand(Optional.of("sleep 100")).build();
    deployResource.deploy(new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent(), Optional.of(newRequest)), singularityUser);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    List<SingularityPendingTaskId> pendingTaskIdsForNewDeploy = new ArrayList<>();
    for (SingularityPendingTaskId pendingTaskId : taskManager.getPendingTaskIds()) {
        if (pendingTaskId.getDeployId().equals(deployId)) {
            pendingTaskIdsForNewDeploy.add(pendingTaskId);
        }
    }
    Assert.assertEquals(1, pendingTaskIdsForNewDeploy.size());
    Assert.assertEquals(2, requestManager.getRequest(requestId).get().getRequest().getInstancesSafe());
    resourceOffers();
    for (SingularityTaskId taskId : taskManager.getActiveTaskIdsForDeploy(requestId, deployId)) {
        statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
    }
    deployChecker.checkDeploys();
    Assert.assertEquals(1, requestManager.getRequest(requestId).get().getRequest().getInstancesSafe());
}
Also used : SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) ArrayList(java.util.ArrayList) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 13 with SingularityDeploy

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

the class SingularityDeploysTest method testCannotUpdateRequestDuringPendingDeployWithNewData.

@Test(expected = WebApplicationException.class)
public void testCannotUpdateRequestDuringPendingDeployWithNewData() {
    initRequest();
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    SingularityRequest newRequest = request.toBuilder().setInstances(Optional.of(1)).build();
    String deployId = "test_new_request_data";
    SingularityDeploy deploy = new SingularityDeployBuilder(request.getId(), deployId).setCommand(Optional.of("sleep 100")).build();
    deployResource.deploy(new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent(), Optional.of(newRequest)), singularityUser);
    requestResource.postRequest(newRequest, singularityUser);
}
Also used : SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 14 with SingularityDeploy

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

the class SingularityDeploysTest method testDeployFailsAfterMaxTaskRetries.

@Test
public void testDeployFailsAfterMaxTaskRetries() {
    initRequest();
    SingularityDeployBuilder db = new SingularityDeployBuilder(requestId, firstDeployId);
    db.setMaxTaskRetries(Optional.of(1));
    SingularityDeploy deploy = initDeploy(db, System.currentTimeMillis());
    deployChecker.checkDeploys();
    Assert.assertTrue(!deployManager.getDeployResult(requestId, firstDeployId).isPresent());
    SingularityTask task = launchTask(request, deploy, System.currentTimeMillis(), 1, TaskState.TASK_FAILED);
    deployChecker.checkDeploys();
    Assert.assertEquals(deployManager.getPendingDeploys().get(0).getCurrentDeployState(), DeployState.WAITING);
    SingularityTask taskTryTwo = launchTask(request, deploy, System.currentTimeMillis(), 1, TaskState.TASK_FAILED);
    deployChecker.checkDeploys();
    Assert.assertEquals(deployManager.getDeployResult(requestId, firstDeployId).get().getDeployState(), DeployState.FAILED);
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 15 with SingularityDeploy

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

the class SingularityDeploysTest method testDeployWithImmediateRunSchedulesAfterRunningImmediately.

@Test
public void testDeployWithImmediateRunSchedulesAfterRunningImmediately() {
    initRequestWithType(RequestType.SCHEDULED, false);
    String deployId = "d1";
    SingularityRunNowRequest runNowRequest = new SingularityRunNowRequestBuilder().setMessage("Message").build();
    SingularityDeploy deploy = new SingularityDeployBuilder(requestId, deployId).setRunImmediately(Optional.of(runNowRequest)).setCommand(Optional.of("printenv > tmp.txt")).build();
    SingularityDeployRequest deployRequest = new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent());
    deployResource.deploy(deployRequest, singularityUser);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    resourceOffers();
    SingularityTaskId taskId = taskManager.getActiveTaskIdsForDeploy(requestId, deployId).get(0);
    SingularityTask task = taskManager.getTask(taskId).get();
    statusUpdate(task, TaskState.TASK_RUNNING);
    statusUpdate(task, TaskState.TASK_FINISHED);
    scheduler.drainPendingQueue();
    resourceOffers();
    Assert.assertEquals(0, taskManager.getNumActiveTasks());
    Assert.assertEquals(1, taskManager.getNumScheduledTasks());
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Aggregations

SingularityDeploy (com.hubspot.singularity.SingularityDeploy)52 Test (org.junit.Test)38 SingularityRequest (com.hubspot.singularity.SingularityRequest)30 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)27 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)22 SingularityTask (com.hubspot.singularity.SingularityTask)12 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)11 SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)10 HealthcheckOptions (com.hubspot.deploy.HealthcheckOptions)9 HealthcheckOptionsBuilder (com.hubspot.deploy.HealthcheckOptionsBuilder)9 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)8 SingularityMesosTaskHolder (com.hubspot.singularity.helpers.SingularityMesosTaskHolder)8 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)7 Resources (com.hubspot.mesos.Resources)6 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)6 SingularityDeployMarker (com.hubspot.singularity.SingularityDeployMarker)5 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)5 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)5 ArrayList (java.util.ArrayList)5 SingularityContainerInfo (com.hubspot.mesos.SingularityContainerInfo)4