Skip to content

Commit

Permalink
Avoid needlessly reobtaining specification data
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythicaeda committed Feb 1, 2024
1 parent 96dfeb1 commit 4e71d94
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import gov.nasa.jpl.aerie.scheduler.server.remotes.postgres.GoalBuilder;
import gov.nasa.jpl.aerie.scheduler.server.services.MerlinService;
import gov.nasa.jpl.aerie.scheduler.server.services.MerlinServiceException;
import gov.nasa.jpl.aerie.scheduler.server.services.RevisionData;
import gov.nasa.jpl.aerie.scheduler.server.services.ScheduleRequest;
import gov.nasa.jpl.aerie.scheduler.server.services.ScheduleResults;
import gov.nasa.jpl.aerie.scheduler.server.services.SchedulerAgent;
Expand Down Expand Up @@ -118,8 +117,8 @@ public void schedule(

final var specification = specificationService.getSpecification(request.specificationId());
final var planMetadata = merlinService.getPlanMetadata(specification.planId());
ensureRequestIsCurrent(request);
ensurePlanRevisionMatch(specification, planMetadata.planRev());
ensureRequestIsCurrent(specification, request);
//create scheduler problem seeded with initial plan
final var schedulerMissionModel = loadMissionModel(planMetadata);
final var planningHorizon = new PlanningHorizon(
Expand Down Expand Up @@ -359,17 +358,18 @@ private long getMerlinPlanRev(final PlanId planId)
{
return merlinService.getPlanRevision(planId);
}

/**
* confirms that specification revision still matches that expected by the scheduling request
*
* @param request the original request for scheduling, containing an intended starting specification revision
* @throws ResultsProtocolFailure when the requested specification revision does not match the actual revision
*/
private void ensureRequestIsCurrent(final ScheduleRequest request) throws NoSuchSpecificationException {
final var currentRevisionData = specificationService.getSpecificationRevisionData(request.specificationId());
if (currentRevisionData.matches(request.specificationRev()) instanceof final RevisionData.MatchResult.Failure failure) {
throw new ResultsProtocolFailure("schedule specification with id %s is stale: %s".formatted(
request.specificationId(), failure));
private void ensureRequestIsCurrent(final Specification specification, final ScheduleRequest request)
throws NoSuchSpecificationException {
if (specification.specificationRevision() != request.specificationRev().specificationRevision()) {
throw new ResultsProtocolFailure("schedule specification with id %s is no longer at revision %d".formatted(
request.specificationId(), request.specificationRev().specificationRevision()));
}
}

Expand Down

0 comments on commit 4e71d94

Please sign in to comment.