Search in sources :

Example 16 with SingularityPendingRequest

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

the class SingularityCachedOffersTest method testLeftoverCachedOffersAreReturnedToCache.

@Test
public void testLeftoverCachedOffersAreReturnedToCache() throws Exception {
    configuration.setCacheOffers(true);
    Offer neededOffer = createOffer(1, 128, 1024, "agent1", "host1", Optional.empty(), Collections.emptyMap(), new String[] { "80:81" });
    Offer extraOffer = createOffer(4, 256, 1024, "agent1", "host1", Optional.empty(), Collections.emptyMap(), new String[] { "83:84" });
    sms.resourceOffers(ImmutableList.of(neededOffer, extraOffer)).join();
    initRequest();
    firstDeploy = initAndFinishDeploy(request, new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")), Optional.of(new Resources(1, 128, 2, 0)));
    requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, firstDeployId, System.currentTimeMillis(), Optional.empty(), PendingType.TASK_DONE, Optional.empty(), Optional.empty()));
    schedulerPoller.runActionOnPoll();
    List<Offer> cachedOffers = offerCache.peekOffers();
    Assertions.assertEquals(1, cachedOffers.size());
}
Also used : SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) Offer(org.apache.mesos.v1.Protos.Offer) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) Test(org.junit.jupiter.api.Test)

Example 17 with SingularityPendingRequest

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

the class SingularityCachedOffersTest method testLeftoverNewOffersAreCached.

@Test
public void testLeftoverNewOffersAreCached() {
    configuration.setCacheOffers(true);
    Offer neededOffer = createOffer(1, 128, 1024, "agent1", "host1");
    Offer extraOffer = createOffer(4, 256, 0, "agent1", "host1");
    initRequest();
    initFirstDeploy();
    requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, firstDeployId, System.currentTimeMillis(), Optional.empty(), PendingType.TASK_DONE, Optional.empty(), Optional.empty()));
    scheduler.drainPendingQueue();
    sms.resourceOffers(ImmutableList.of(neededOffer, extraOffer)).join();
    List<Offer> cachedOffers = offerCache.peekOffers();
    Assertions.assertEquals(1, cachedOffers.size());
}
Also used : SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) Offer(org.apache.mesos.v1.Protos.Offer) Test(org.junit.jupiter.api.Test)

Example 18 with SingularityPendingRequest

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

the class SingularitySchedulerTest method testNewlyDeployedScheduledTasksAreScheduledAfterStartup.

@Test
public void testNewlyDeployedScheduledTasksAreScheduledAfterStartup() {
    initScheduledRequest();
    initFirstDeploy();
    SingularityTask runningTask = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
    long now = System.currentTimeMillis();
    initSecondDeploy();
    requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, secondDeployId, now, Optional.empty(), PendingType.STARTUP, Optional.empty(), Optional.empty()));
    deployChecker.checkDeploys();
    resourceOffers();
    // There's an instance running, so we shouldn't schedule a pending task yet
    Assertions.assertTrue(taskManager.getPendingTaskIds().isEmpty());
    statusUpdate(runningTask, TaskState.TASK_FINISHED);
    scheduler.drainPendingQueue();
    // Now a pending task should be scheduled with the new deploy
    Assertions.assertEquals(1, taskManager.getPendingTaskIds().size());
    Assertions.assertEquals(PendingType.NEW_DEPLOY, taskManager.getPendingTaskIds().get(0).getPendingType());
    Assertions.assertEquals(secondDeployId, taskManager.getPendingTaskIds().get(0).getDeployId());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) Test(org.junit.jupiter.api.Test)

Example 19 with SingularityPendingRequest

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

the class SingularitySchedulerTestBase method saveAndSchedule.

protected void saveAndSchedule(SingularityRequestBuilder bldr) {
    SingularityRequest build = bldr.build();
    requestManager.activate(build, RequestHistoryType.UPDATED, System.currentTimeMillis(), Optional.<String>empty(), Optional.<String>empty());
    requestManager.addToPendingQueue(new SingularityPendingRequest(build.getId(), firstDeployId, System.currentTimeMillis(), Optional.<String>empty(), PendingType.UPDATED_REQUEST, Optional.<Boolean>empty(), Optional.<String>empty()));
    scheduler.drainPendingQueue();
}
Also used : SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityRequest(com.hubspot.singularity.SingularityRequest)

Example 20 with SingularityPendingRequest

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

the class SingularitySchedulerTest method testImmediateRequestsAreConsistentlyDeleted.

@Test
public void testImmediateRequestsAreConsistentlyDeleted() {
    long now = System.currentTimeMillis();
    initRequestWithType(RequestType.SCHEDULED, false);
    startFirstDeploy();
    SingularityPendingRequest pendingDeployRequest = new SingularityPendingRequest(requestId, firstDeploy.getId(), now, Optional.empty(), PendingType.NEW_DEPLOY, firstDeploy.getSkipHealthchecksOnDeploy(), Optional.empty());
    SingularityPendingRequest pendingRunNowRequest = new SingularityPendingRequest(requestId, firstDeploy.getId(), now + 200, Optional.empty(), PendingType.IMMEDIATE, firstDeploy.getSkipHealthchecksOnDeploy(), Optional.empty());
    requestManager.addToPendingQueue(pendingDeployRequest);
    requestManager.addToPendingQueue(pendingRunNowRequest);
    // Pending queue has two requests: NEW_DEPLOY & IMMEDIATE
    Assertions.assertEquals(2, requestManager.getPendingRequests().size());
    requestManager.deletePendingRequest(pendingDeployRequest);
    // Just the immediate run
    Assertions.assertEquals(1, requestManager.getPendingRequests().size());
    requestManager.deletePendingRequest(pendingRunNowRequest);
    // Immediate run was successfully deleted
    Assertions.assertEquals(0, requestManager.getPendingRequests().size());
}
Also used : SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) Test(org.junit.jupiter.api.Test)

Aggregations

SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)53 Test (org.junit.jupiter.api.Test)18 SingularityRequest (com.hubspot.singularity.SingularityRequest)12 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)11 SingularityTask (com.hubspot.singularity.SingularityTask)9 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)9 SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)8 SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)8 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)7 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)7 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)7 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)7 Resources (com.hubspot.mesos.Resources)6 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)6 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)6 PendingType (com.hubspot.singularity.SingularityPendingRequest.PendingType)6 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)6