Search in sources :

Example 31 with SingularityDeployBuilder

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

the class SingularitySchedulerTest method testFinishedRequestCanBeDeployed.

@Test
public void testFinishedRequestCanBeDeployed() {
    initScheduledRequest();
    initFirstDeploy();
    schedule = "*/1 * * * * ? 1995";
    // cause it to be pending
    requestResource.postRequest(request.toBuilder().setQuartzSchedule(Optional.of(schedule)).build(), singularityUser);
    scheduler.drainPendingQueue();
    Assert.assertTrue(requestResource.getActiveRequests(singularityUser, false, false, false, 10, Collections.emptyList()).isEmpty());
    Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.FINISHED);
    SingularityDeployBuilder db = new SingularityDeployBuilder(requestId, secondDeployId);
    initDeploy(db, System.currentTimeMillis());
    deployChecker.checkDeploys();
    Assert.assertEquals(RequestState.ACTIVE, requestManager.getRequest(requestId).get().getState());
    Assert.assertEquals(1, requestManager.getPendingRequests().size());
}
Also used : SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Example 32 with SingularityDeployBuilder

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

the class SingularitySchedulerTest method testDecommissionDoesntKillPendingDeploy.

@Test
public void testDecommissionDoesntKillPendingDeploy() {
    initRequest();
    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.getNumActiveTasks());
    slaveResource.decommissionSlave(singularityUser, taskManager.getActiveTasks().get(0).getAgentId().getValue(), null);
    scheduler.checkForDecomissions();
    cleaner.drainCleanupQueue();
    killKilledTasks();
    Assert.assertEquals(1, taskManager.getNumActiveTasks());
    Assert.assertEquals(1, taskManager.getNumCleanupTasks());
    Assert.assertEquals(0, taskManager.getKilledTaskIdRecords().size());
    configuration.setPendingDeployHoldTaskDuringDecommissionMillis(1);
    try {
        Thread.sleep(2);
    } catch (InterruptedException e) {
    }
    cleaner.drainCleanupQueue();
    killKilledTasks();
    Assert.assertEquals(0, taskManager.getNumActiveTasks());
    Assert.assertEquals(0, taskManager.getNumCleanupTasks());
}
Also used : SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Example 33 with SingularityDeployBuilder

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

the class SingularitySchedulerTest method testRunOnceRunOnlyOnce.

@Test
public void testRunOnceRunOnlyOnce() {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.RUN_ONCE);
    request = bldr.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.assertTrue(deployManager.getRequestDeployState(requestId).get().getActiveDeploy().isPresent());
    Assert.assertTrue(!deployManager.getRequestDeployState(requestId).get().getPendingDeploy().isPresent());
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
    statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
    resourceOffers();
    Assert.assertTrue(taskManager.getActiveTaskIds().isEmpty());
    deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(requestId, "d2").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
    scheduler.drainPendingQueue();
    deployChecker.checkDeploys();
    resourceOffers();
    Assert.assertTrue(deployManager.getRequestDeployState(requestId).get().getActiveDeploy().isPresent());
    Assert.assertTrue(!deployManager.getRequestDeployState(requestId).get().getPendingDeploy().isPresent());
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
    statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_FINISHED);
    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 34 with SingularityDeployBuilder

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

the class SingularitySchedulerTest method testRequestedPorts.

@Test
public void testRequestedPorts() {
    final SingularityDeployBuilder deployBuilder = dockerDeployWithPorts();
    initRequest();
    initAndFinishDeploy(request, deployBuilder, Optional.of(new Resources(1, 64, 3, 0)));
    requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
    scheduler.drainPendingQueue();
    String[] portRangeWithNoRequestedPorts = { "65:70" };
    sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRangeWithNoRequestedPorts)));
    Assert.assertEquals(0, taskManager.getActiveTasks().size());
    String[] portRangeWithSomeRequestedPorts = { "80:82" };
    sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRangeWithSomeRequestedPorts)));
    Assert.assertEquals(0, taskManager.getActiveTasks().size());
    String[] portRangeWithRequestedButNotEnoughPorts = { "80:80", "8080:8080" };
    sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRangeWithRequestedButNotEnoughPorts)));
    Assert.assertEquals(0, taskManager.getActiveTasks().size());
    String[] portRangeWithNeededPorts = { "80:83", "8080:8080" };
    sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRangeWithNeededPorts)));
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
}
Also used : SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) Test(org.junit.Test)

Example 35 with SingularityDeployBuilder

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

the class SingularitySchedulerTestBase method initSecondDeploy.

protected SingularityDeployMarker initSecondDeploy() {
    secondDeployMarker = new SingularityDeployMarker(requestId, secondDeployId, System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent());
    secondDeploy = new SingularityDeployBuilder(requestId, secondDeployId).setCommand(Optional.of("sleep 100")).build();
    deployManager.saveDeploy(request, secondDeployMarker, secondDeploy);
    startDeploy(secondDeployMarker, System.currentTimeMillis());
    return secondDeployMarker;
}
Also used : SingularityDeployMarker(com.hubspot.singularity.SingularityDeployMarker) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder)

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