Skip to content

Commit

Permalink
Merge pull request #1685 from HubSpot/finished_redeploy
Browse files Browse the repository at this point in the history
Allow a request in FINISHED state to be redeployed
  • Loading branch information
ssalinas committed Dec 21, 2017
2 parents 20c005b + 1d8cf3a commit 9f40fce
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ private void checkDeploy(final SingularityPendingDeploy pendingDeploy, final Lis

Optional<SingularityRequestWithState> maybeRequestWithState = requestManager.getRequest(pendingDeploy.getDeployMarker().getRequestId());

if (!SingularityRequestWithState.isActive(maybeRequestWithState)) {
if (!(maybeRequestWithState.isPresent() && maybeRequestWithState.get().getState() == RequestState.FINISHED)
&& !SingularityRequestWithState.isActive(maybeRequestWithState)) {
LOG.warn("Deploy {} request was {}, removing deploy", pendingDeploy, SingularityRequestWithState.getRequestState(maybeRequestWithState));

if (shouldCancelLoadBalancer(pendingDeploy)) {
Expand Down Expand Up @@ -326,11 +327,20 @@ private void finishDeploy(SingularityRequestWithState requestWithState, Optional
deploy.isPresent() ? deploy.get().getSkipHealthchecksOnDeploy() : Optional.absent(), pendingDeploy.getDeployMarker().getMessage()));
}

if (!request.isDeployable() && !request.isOneOff()) {
if (deployResult.getDeployState() == DeployState.SUCCEEDED) {
if (deployResult.getDeployState() == DeployState.SUCCEEDED) {
if (!request.isDeployable() && !request.isOneOff()) {
// remove the lock on bounces in case we deployed during a bounce
requestManager.markBounceComplete(request.getId());
}
if (requestWithState.getState() == RequestState.FINISHED) {
// A FINISHED request is moved to ACTIVE state so we can reevaluate the schedule
requestManager.activate(
request,
RequestHistoryType.UPDATED,
System.currentTimeMillis(),
deploy.isPresent() ? deploy.get().getUser() : Optional.absent(),
Optional.absent());
}
}

deployManager.saveDeployResult(pendingDeploy.getDeployMarker(), deploy, deployResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,27 @@ public void testSchedulerHandlesFinishedTasks() {
Assert.assertTrue(!taskManager.getPendingTaskIds().isEmpty());
}

@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());
}

@Test
public void testOneOffsDontRunByThemselves() {
SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,20 @@ const RequestAlerts = ({requestId, requestAPI, bounces, activeTasksForRequest, d
);
}

let maybeFinished;
if (requestParent.state == "FINISHED") {
maybeFinished=(
<Alert bsStyle="warning">
<p>Schedule <code>{requestParent.request.quartzSchedule}</code> has no more occurences. Redeploy with a new schedule to continue running tasks for this request</p>
</Alert>
);
}

return (
<div>
{maybeBouncing}
{maybeDeploying}
{maybeFinished}
<Well>
<Row>
<Col md={10} sm={8}>
Expand Down

0 comments on commit 9f40fce

Please sign in to comment.