From 2d2fd98d704e4b2f4a5cdb017a155560ea766aaf Mon Sep 17 00:00:00 2001 From: tpetr Date: Wed, 17 Feb 2016 16:16:30 -0500 Subject: [PATCH 1/2] ensure run once tasks don't get launched at startup --- .../singularity/SingularityRequest.java | 2 +- .../mesos/SingularityStartupTest.java | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/SingularityBase/src/main/java/com/hubspot/singularity/SingularityRequest.java b/SingularityBase/src/main/java/com/hubspot/singularity/SingularityRequest.java index 6afef7457a..c5c1b89440 100644 --- a/SingularityBase/src/main/java/com/hubspot/singularity/SingularityRequest.java +++ b/SingularityBase/src/main/java/com/hubspot/singularity/SingularityRequest.java @@ -206,7 +206,7 @@ public boolean isAlwaysRunning() { @JsonIgnore public boolean isOneOff() { - return requestType == RequestType.ON_DEMAND; + return requestType == RequestType.ON_DEMAND || requestType == RequestType.RUN_ONCE; } @JsonIgnore diff --git a/SingularityService/src/test/java/com/hubspot/singularity/mesos/SingularityStartupTest.java b/SingularityService/src/test/java/com/hubspot/singularity/mesos/SingularityStartupTest.java index 4577a308a0..1c8d881443 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/mesos/SingularityStartupTest.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/mesos/SingularityStartupTest.java @@ -122,7 +122,7 @@ public void testScheduledTasksDontGetRescheduledDuringRun() { } @Test - public void testOneOffDoesntGetRescheduled() { + public void testOnDemandDoesntGetRescheduled() { saveRequest(new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND).build()); deploy(firstDeployId); deployChecker.checkDeploys(); @@ -142,4 +142,24 @@ public void testOneOffDoesntGetRescheduled() { Assert.assertTrue(requestManager.getPendingRequests().get(0).getPendingType() == PendingType.ONEOFF); } + @Test + public void testRunOnceDoesntGetRescheduled() { + saveRequest(new SingularityRequestBuilder(requestId, RequestType.RUN_ONCE).build()); + deploy(firstDeployId); + deployChecker.checkDeploys(); + + Assert.assertTrue(requestManager.getPendingRequests().isEmpty()); + Assert.assertTrue(taskManager.getPendingTaskIds().isEmpty()); + + startup.checkSchedulerForInconsistentState(); + + Assert.assertTrue(requestManager.getPendingRequests().isEmpty()); + Assert.assertTrue(taskManager.getPendingTaskIds().isEmpty()); + + requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, firstDeployId, System.currentTimeMillis(), Optional. absent(), PendingType.ONEOFF, Optional. absent(), Optional. absent())); + + startup.checkSchedulerForInconsistentState(); + + Assert.assertTrue(requestManager.getPendingRequests().get(0).getPendingType() == PendingType.ONEOFF); + } } From 6cfffe486f92187d95b464c1d7865708ac0dcbdf Mon Sep 17 00:00:00 2001 From: tpetr Date: Wed, 17 Feb 2016 17:10:45 -0500 Subject: [PATCH 2/2] use different approach + fix test --- .../com/hubspot/singularity/SingularityRequest.java | 2 +- .../hubspot/singularity/mesos/SingularityStartup.java | 5 +++-- .../singularity/mesos/SingularityStartupTest.java | 11 ++++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/SingularityBase/src/main/java/com/hubspot/singularity/SingularityRequest.java b/SingularityBase/src/main/java/com/hubspot/singularity/SingularityRequest.java index c5c1b89440..6afef7457a 100644 --- a/SingularityBase/src/main/java/com/hubspot/singularity/SingularityRequest.java +++ b/SingularityBase/src/main/java/com/hubspot/singularity/SingularityRequest.java @@ -206,7 +206,7 @@ public boolean isAlwaysRunning() { @JsonIgnore public boolean isOneOff() { - return requestType == RequestType.ON_DEMAND || requestType == RequestType.RUN_ONCE; + return requestType == RequestType.ON_DEMAND; } @JsonIgnore diff --git a/SingularityService/src/main/java/com/hubspot/singularity/mesos/SingularityStartup.java b/SingularityService/src/main/java/com/hubspot/singularity/mesos/SingularityStartup.java index 1560984bb8..bef94d8d29 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/mesos/SingularityStartup.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/mesos/SingularityStartup.java @@ -18,6 +18,7 @@ import com.hubspot.mesos.MesosUtils; import com.hubspot.mesos.client.MesosClient; import com.hubspot.mesos.json.MesosMasterStateObject; +import com.hubspot.singularity.RequestType; import com.hubspot.singularity.SingularityDeployKey; import com.hubspot.singularity.SingularityPendingDeploy; import com.hubspot.singularity.SingularityPendingRequest; @@ -135,8 +136,8 @@ void checkSchedulerForInconsistentState() { private void checkActiveRequest(SingularityRequestWithState requestWithState, Map deployKeyToPendingTaskId, final long timestamp) { final SingularityRequest request = requestWithState.getRequest(); - if (request.isOneOff()) { - return; + if (request.getRequestType() == RequestType.ON_DEMAND || request.getRequestType() == RequestType.RUN_ONCE) { + return; // There's no situation where we'd want to schedule an On Demand or Run Once request at startup, so don't even bother with them. } Optional requestDeployState = deployManager.getRequestDeployState(request.getId()); diff --git a/SingularityService/src/test/java/com/hubspot/singularity/mesos/SingularityStartupTest.java b/SingularityService/src/test/java/com/hubspot/singularity/mesos/SingularityStartupTest.java index 1c8d881443..1c4979a829 100644 --- a/SingularityService/src/test/java/com/hubspot/singularity/mesos/SingularityStartupTest.java +++ b/SingularityService/src/test/java/com/hubspot/singularity/mesos/SingularityStartupTest.java @@ -148,18 +148,15 @@ public void testRunOnceDoesntGetRescheduled() { deploy(firstDeployId); deployChecker.checkDeploys(); - Assert.assertTrue(requestManager.getPendingRequests().isEmpty()); - Assert.assertTrue(taskManager.getPendingTaskIds().isEmpty()); - - startup.checkSchedulerForInconsistentState(); + scheduler.drainPendingQueue(stateCacheProvider.get()); + resourceOffers(); Assert.assertTrue(requestManager.getPendingRequests().isEmpty()); Assert.assertTrue(taskManager.getPendingTaskIds().isEmpty()); - requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, firstDeployId, System.currentTimeMillis(), Optional. absent(), PendingType.ONEOFF, Optional. absent(), Optional. absent())); - startup.checkSchedulerForInconsistentState(); - Assert.assertTrue(requestManager.getPendingRequests().get(0).getPendingType() == PendingType.ONEOFF); + // assert that SingularityStartup does not enqueue a SingularityPendingRequest (pendingType=STARTUP) for the RUN_ONCE request + Assert.assertTrue(requestManager.getPendingRequests().isEmpty()); } }