Search in sources :

Example 1 with SingularityDeployBuilder

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

the class SingularitySchedulerTest method testRetries.

@Test
public void testRetries() {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.RUN_ONCE);
    request = bldr.setNumRetriesOnFailure(Optional.of(2)).build();
    saveRequest(request);
    deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(requestId, "d1").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
    scheduler.drainPendingQueue();
    deployChecker.checkDeploys();
    resourceOffers();
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
    statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
    resourceOffers();
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
    statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
    resourceOffers();
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
    statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
    resourceOffers();
    Assert.assertTrue(taskManager.getActiveTaskIds().isEmpty());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Example 2 with SingularityDeployBuilder

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

the class SingularitySchedulerTest method testCronScheduleChanges.

@Test
public void testCronScheduleChanges() throws Exception {
    final String requestId = "test-change-cron";
    final String oldSchedule = "*/5 * * * *";
    final String oldScheduleQuartz = "0 */5 * * * ?";
    final String newSchedule = "*/30 * * * *";
    final String newScheduleQuartz = "0 */30 * * * ?";
    SingularityRequest request = new SingularityRequestBuilder(requestId, RequestType.SCHEDULED).setSchedule(Optional.of(oldSchedule)).build();
    request = validator.checkSingularityRequest(request, Optional.<SingularityRequest>absent(), Optional.<SingularityDeploy>absent(), Optional.<SingularityDeploy>absent());
    saveRequest(request);
    Assert.assertEquals(oldScheduleQuartz, requestManager.getRequest(requestId).get().getRequest().getQuartzScheduleSafe());
    initAndFinishDeploy(request, "1");
    scheduler.drainPendingQueue();
    final SingularityRequest newRequest = request.toBuilder().setSchedule(Optional.of(newSchedule)).setQuartzSchedule(Optional.<String>absent()).build();
    final SingularityDeploy newDeploy = new SingularityDeployBuilder(request.getId(), "2").setCommand(Optional.of("sleep 100")).build();
    deployResource.deploy(new SingularityDeployRequest(newDeploy, Optional.absent(), Optional.absent(), Optional.of(newRequest)), singularityUser);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    Assert.assertEquals(newScheduleQuartz, requestManager.getRequest(requestId).get().getRequest().getQuartzScheduleSafe());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) 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 3 with SingularityDeployBuilder

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

the class SingularitySchedulerTest method dockerDeployWithPorts.

private SingularityDeployBuilder dockerDeployWithPorts() {
    final SingularityDockerPortMapping literalMapping = new SingularityDockerPortMapping(Optional.<SingularityPortMappingType>absent(), 80, Optional.of(SingularityPortMappingType.LITERAL), 8080, Optional.<String>absent());
    final SingularityDockerPortMapping offerMapping = new SingularityDockerPortMapping(Optional.<SingularityPortMappingType>absent(), 81, Optional.of(SingularityPortMappingType.FROM_OFFER), 0, Optional.of("udp"));
    final SingularityContainerInfo containerInfo = new SingularityContainerInfo(SingularityContainerType.DOCKER, Optional.<List<SingularityVolume>>absent(), Optional.of(new SingularityDockerInfo("docker-image", true, SingularityDockerNetworkType.BRIDGE, Optional.of(Arrays.asList(literalMapping, offerMapping)), Optional.of(false), Optional.of(ImmutableMap.of("env", "var=value")), Optional.absent())));
    final SingularityDeployBuilder deployBuilder = new SingularityDeployBuilder(requestId, "test-docker-ports-deploy");
    deployBuilder.setContainerInfo(Optional.of(containerInfo));
    return deployBuilder;
}
Also used : SingularityContainerInfo(com.hubspot.mesos.SingularityContainerInfo) SingularityVolume(com.hubspot.mesos.SingularityVolume) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDockerPortMapping(com.hubspot.mesos.SingularityDockerPortMapping) SingularityDockerInfo(com.hubspot.mesos.SingularityDockerInfo)

Example 4 with SingularityDeployBuilder

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

the class SingularitySchedulerTest method testCleanerFindsTasksWithSkippedHealthchecks.

@Test
public void testCleanerFindsTasksWithSkippedHealthchecks() {
    initRequest();
    // set up slaves so scale validate will pass
    resourceOffers(2);
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    long now = System.currentTimeMillis();
    requestManager.saveHistory(new SingularityRequestHistory(now, Optional.<String>absent(), RequestHistoryType.UPDATED, request.toBuilder().setSkipHealthchecks(Optional.of(true)).setInstances(Optional.of(2)).build(), Optional.<String>absent()));
    firstDeploy = initDeploy(new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")).setHealthcheckUri(Optional.of("http://uri")), System.currentTimeMillis());
    SingularityTask taskOne = launchTask(request, firstDeploy, now + 1000, now + 2000, 1, TaskState.TASK_RUNNING);
    finishDeploy(new SingularityDeployMarker(requestId, firstDeployId, now + 2000, Optional.<String>absent(), Optional.<String>absent()), firstDeploy);
    SingularityRequest updatedRequest = request.toBuilder().setSkipHealthchecks(Optional.<Boolean>absent()).setInstances(Optional.of(2)).build();
    requestManager.saveHistory(new SingularityRequestHistory(now + 3000, Optional.<String>absent(), RequestHistoryType.UPDATED, updatedRequest, Optional.<String>absent()));
    SingularityTask newTaskTwoWithCheck = prepTask(updatedRequest, firstDeploy, now + 4000, 2);
    taskManager.createTaskAndDeletePendingTask(newTaskTwoWithCheck);
    statusUpdate(newTaskTwoWithCheck, TaskState.TASK_RUNNING, Optional.of(now + 5000));
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), now + 6000, Optional.<String>absent(), Optional.<String>absent(), newTaskTwoWithCheck.getTaskId(), Optional.<Boolean>absent()));
    SingularityTask unhealthyTaskThree = prepTask(updatedRequest, firstDeploy, now + 4000, 3);
    taskManager.createTaskAndDeletePendingTask(unhealthyTaskThree);
    statusUpdate(unhealthyTaskThree, TaskState.TASK_RUNNING, Optional.of(now + 5000));
    List<SingularityTaskId> activeTaskIds = taskManager.getActiveTaskIdsForRequest(requestId);
    List<SingularityTaskId> healthyTaskIds = deployHealthHelper.getHealthyTasks(updatedRequest, Optional.of(firstDeploy), activeTaskIds, false);
    Assert.assertTrue(!healthyTaskIds.contains(unhealthyTaskThree.getTaskId()));
    // Healthchecked and skip-healthchecked tasks should both be here
    Assert.assertEquals(2, healthyTaskIds.size());
    Assert.assertEquals(DeployHealth.WAITING, deployHealthHelper.getDeployHealth(updatedRequest, Optional.of(firstDeploy), activeTaskIds, false));
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), now + 6000, Optional.<String>absent(), Optional.<String>absent(), unhealthyTaskThree.getTaskId(), Optional.<Boolean>absent()));
    Assert.assertEquals(DeployHealth.HEALTHY, deployHealthHelper.getDeployHealth(updatedRequest, Optional.of(firstDeploy), activeTaskIds, false));
}
Also used : SingularityRequestHistory(com.hubspot.singularity.SingularityRequestHistory) SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityDeployMarker(com.hubspot.singularity.SingularityDeployMarker) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 5 with SingularityDeployBuilder

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

the class SingularitySchedulerTest method testRemovedRequestData.

@Test
public void testRemovedRequestData() {
    long now = System.currentTimeMillis();
    initRequest();
    SingularityDeployBuilder db = new SingularityDeployBuilder(requestId, firstDeployId);
    db.setMaxTaskRetries(Optional.of(1));
    initDeploy(db, now);
    deployChecker.checkDeploys();
    Assert.assertEquals(DeployState.WAITING, deployManager.getPendingDeploys().get(0).getCurrentDeployState());
    requestManager.startDeletingRequest(request, Optional.absent(), Optional.<String>absent(), Optional.<String>absent(), Optional.<String>absent());
    requestManager.markDeleted(request, now, Optional.<String>absent(), Optional.<String>absent());
    deployChecker.checkDeploys();
    SingularityDeployResult deployResult = deployManager.getDeployResult(requestId, firstDeployId).get();
    Assert.assertEquals(DeployState.FAILED, deployResult.getDeployState());
    Assert.assertTrue(deployResult.getMessage().get().contains("MISSING"));
}
Also used : SingularityDeployResult(com.hubspot.singularity.SingularityDeployResult) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Aggregations

SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)47 Test (org.junit.Test)39 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)27 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)17 SingularityRequest (com.hubspot.singularity.SingularityRequest)16 SingularityTask (com.hubspot.singularity.SingularityTask)15 SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)15 HealthcheckOptions (com.hubspot.deploy.HealthcheckOptions)10 Resources (com.hubspot.mesos.Resources)10 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)10 HealthcheckOptionsBuilder (com.hubspot.deploy.HealthcheckOptionsBuilder)9 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)8 SingularityMesosTaskHolder (com.hubspot.singularity.helpers.SingularityMesosTaskHolder)8 SingularityContainerInfo (com.hubspot.mesos.SingularityContainerInfo)6 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)6 SingularityDockerInfo (com.hubspot.mesos.SingularityDockerInfo)4 SingularityDockerPortMapping (com.hubspot.mesos.SingularityDockerPortMapping)4 SingularityVolume (com.hubspot.mesos.SingularityVolume)4 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)3 Protos (org.apache.mesos.v1.Protos)3