diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/SchedulerAppDriver.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/SchedulerAppDriver.java index 22fa976077..3f87b46791 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/SchedulerAppDriver.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/SchedulerAppDriver.java @@ -61,7 +61,7 @@ public static void main(final String[] args) { final var schedulerService = new CachedSchedulerService(stores.results()); final var scheduleAction = new ScheduleAction(specificationService, schedulerService); - final var generateSchedulingLibAction = new GenerateSchedulingLibAction(merlinService, merlinService); + final var generateSchedulingLibAction = new GenerateSchedulingLibAction(merlinService); //establish bindings to the service layers final var bindings = new SchedulerBindings( diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/http/ActivityTemplateJsonParser.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/http/ActivityTemplateJsonParser.java index 25ccb01a0b..9f39ec076f 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/http/ActivityTemplateJsonParser.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/http/ActivityTemplateJsonParser.java @@ -11,7 +11,7 @@ import gov.nasa.jpl.aerie.json.SchemaCache; import gov.nasa.jpl.aerie.scheduler.server.models.ActivityType; import gov.nasa.jpl.aerie.scheduler.server.models.SchedulingDSL; -import gov.nasa.jpl.aerie.scheduler.server.services.MissionModelService; +import gov.nasa.jpl.aerie.scheduler.server.services.MerlinService; import static gov.nasa.jpl.aerie.constraints.json.ConstraintParsers.profileExpressionP; import static gov.nasa.jpl.aerie.constraints.json.ConstraintParsers.structExpressionF; @@ -20,7 +20,7 @@ public class ActivityTemplateJsonParser implements JsonParser activityTypesByName = new HashMap<>(); - public ActivityTemplateJsonParser(MissionModelService.MissionModelTypes activityTypes){ + public ActivityTemplateJsonParser(MerlinService.MissionModelTypes activityTypes){ activityTypes.activityTypes().forEach((actType)-> activityTypesByName.put(actType.name(), actType)); } diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/SchedulingDSL.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/SchedulingDSL.java index 8fef7b3b97..3f235bc5a2 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/SchedulingDSL.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/SchedulingDSL.java @@ -12,7 +12,7 @@ import gov.nasa.jpl.aerie.scheduler.TimeUtility; import gov.nasa.jpl.aerie.scheduler.constraints.timeexpressions.TimeAnchor; import gov.nasa.jpl.aerie.scheduler.server.http.ActivityTemplateJsonParser; -import gov.nasa.jpl.aerie.scheduler.server.services.MissionModelService; +import gov.nasa.jpl.aerie.scheduler.server.services.MerlinService; import org.apache.commons.lang3.tuple.Pair; import java.util.List; @@ -57,7 +57,7 @@ public class SchedulingDSL { $ -> tuple($.duration(), $.occurrence())); private static JsonObjectParser recurrenceGoalDefinitionP( - MissionModelService.MissionModelTypes activityTypes) + MerlinService.MissionModelTypes activityTypes) { return productP .field("activityTemplate", new ActivityTemplateJsonParser(activityTypes)) @@ -112,7 +112,7 @@ private static JsonObjectParser recurren (TimingConstraint.ActivityTimingConstraintFlexibleRange $) -> tuple($.lowerBound(), $.upperBound(), $.singleton())); private static final JsonObjectParser coexistenceGoalDefinitionP( - MissionModelService.MissionModelTypes activityTypes) + MerlinService.MissionModelTypes activityTypes) { return productP @@ -146,7 +146,7 @@ private static final JsonObjectParser c } private static final JsonObjectParser cardinalityGoalDefinitionP( - MissionModelService.MissionModelTypes activityTypes) { + MerlinService.MissionModelTypes activityTypes) { return productP .field("activityTemplate", new ActivityTemplateJsonParser(activityTypes)) @@ -195,7 +195,7 @@ private static JsonObjectParser goalApplyWhenF(fina } - private static JsonParser goalSpecifierF(MissionModelService.MissionModelTypes missionModelTypes) { + private static JsonParser goalSpecifierF(MerlinService.MissionModelTypes missionModelTypes) { return recursiveP(self -> SumParsers.sumP("kind", GoalSpecifier.class, List.of( SumParsers.variant( "ActivityRecurrenceGoal", @@ -243,7 +243,7 @@ private static JsonObjectParser conditionAndF(f globalSchedulingConditionP) ))); - public static final JsonParser schedulingJsonP(MissionModelService.MissionModelTypes missionModelTypes){ + public static final JsonParser schedulingJsonP(MerlinService.MissionModelTypes missionModelTypes){ return goalSpecifierF(missionModelTypes); } diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/ConstraintsTypescriptCodeGenerationHelper.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/ConstraintsTypescriptCodeGenerationHelper.java index 55b0920c94..79469321c4 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/ConstraintsTypescriptCodeGenerationHelper.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/ConstraintsTypescriptCodeGenerationHelper.java @@ -9,7 +9,7 @@ public final class ConstraintsTypescriptCodeGenerationHelper { private ConstraintsTypescriptCodeGenerationHelper() { } - public static Map activityTypes(final MissionModelService.MissionModelTypes missionModelTypes) { + public static Map activityTypes(final MerlinService.MissionModelTypes missionModelTypes) { return missionModelTypes .activityTypes() .stream() @@ -27,7 +27,7 @@ public static Map activity .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } - public static Map resources(final MissionModelService.MissionModelTypes missionModelTypes) { + public static Map resources(final MerlinService.MissionModelTypes missionModelTypes) { return missionModelTypes .resourceTypes() .stream() diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GenerateSchedulingLibAction.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GenerateSchedulingLibAction.java index 06cb4fd5ad..f0a8099a5c 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GenerateSchedulingLibAction.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GenerateSchedulingLibAction.java @@ -14,11 +14,10 @@ import gov.nasa.jpl.aerie.scheduler.server.models.PlanId; public record GenerateSchedulingLibAction( - MissionModelService missionModelService, - PlanService.ReaderRole planService + MerlinService.ReaderRole merlinService ) { public GenerateSchedulingLibAction { - Objects.requireNonNull(planService); + Objects.requireNonNull(merlinService); } /** @@ -46,10 +45,10 @@ public Response run(final MissionModelId missionModelId, final Optional final var temporalPolyfillTypes = getTypescriptResource("constraints/TemporalPolyfillTypes.ts"); - var missionModelTypes = missionModelService.getMissionModelTypes(missionModelId); + var missionModelTypes = merlinService.getMissionModelTypes(missionModelId); if(planId.isPresent()) { - final var allResourceTypes = planService.getResourceTypes(planId.get()); - missionModelTypes = new MissionModelService.MissionModelTypes(missionModelTypes.activityTypes(), allResourceTypes); + final var allResourceTypes = merlinService.getResourceTypes(planId.get()); + missionModelTypes = new MerlinService.MissionModelTypes(missionModelTypes.activityTypes(), allResourceTypes); } final var generatedSchedulerCode = TypescriptCodeGenerationService.generateTypescriptTypesFromMissionModel(missionModelTypes); @@ -66,7 +65,7 @@ public Response run(final MissionModelId missionModelId, final Optional "file:///mission-model-generated-code.ts", generatedConstraintsCode, "file:///%s".formatted(temporalPolyfillTypes.basename), temporalPolyfillTypes.source )); - } catch (final IOException | MissionModelService.MissionModelServiceException | PlanServiceException | + } catch (final IOException | PlanServiceException | NoSuchPlanException | NoSuchMissionModelException e) { return new Response.Failure(e.getMessage()); } diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GraphQLMerlinService.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GraphQLMerlinService.java index 6c77d6d210..fd3d1606db 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GraphQLMerlinService.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GraphQLMerlinService.java @@ -93,9 +93,7 @@ * * @param merlinGraphqlURI endpoint of the merlin graphql service that should be used to access all plan data */ -public record GraphQLMerlinService(URI merlinGraphqlURI, String hasuraGraphQlAdminSecret) implements PlanService.OwnerRole, - MissionModelService -{ +public record GraphQLMerlinService(URI merlinGraphqlURI, String hasuraGraphQlAdminSecret) implements MerlinService.OwnerRole { /** * timeout for http graphql requests issued to aerie @@ -605,8 +603,8 @@ mutation createAllPlanActivityDirectives($activities: [activity_directive_insert } @Override - public MissionModelTypes getMissionModelTypes(final PlanId planId) - throws IOException, MissionModelServiceException + public MerlinService.MissionModelTypes getMissionModelTypes(final PlanId planId) + throws IOException, PlanServiceException { final var request = """ query GetActivityTypesForPlan { @@ -626,11 +624,8 @@ public MissionModelTypes getMissionModelTypes(final PlanId planId) } """.formatted(planId.id()); final JsonObject response; - try { - response = postRequest(request).get(); - } catch (PlanServiceException e) { - throw new MissionModelServiceException("Failed to get mission model types for plan id %s".formatted(planId), e); - } + response = postRequest(request).get(); + final var activityTypesJsonArray = response.getJsonObject("data") .getJsonObject("plan_by_pk") @@ -643,7 +638,7 @@ public MissionModelTypes getMissionModelTypes(final PlanId planId) .getJsonObject("mission_model") .getInt("id")); - return new MissionModelTypes(activityTypes, getResourceTypes(missionModelId)); + return new MerlinService.MissionModelTypes(activityTypes, getResourceTypes(missionModelId)); } private static List parseActivityTypes(final JsonArray activityTypesJsonArray) { @@ -684,8 +679,8 @@ private static List parseActivityTypes(final JsonArray activityTyp } @Override - public MissionModelTypes getMissionModelTypes(final MissionModelId missionModelId) - throws IOException, MissionModelServiceException, NoSuchMissionModelException + public MerlinService.MissionModelTypes getMissionModelTypes(final MissionModelId missionModelId) + throws IOException, NoSuchMissionModelException, PlanServiceException { final var request = """ query GetActivityTypesFromMissionModel{ @@ -702,11 +697,7 @@ public MissionModelTypes getMissionModelTypes(final MissionModelId missionModelI } """.formatted(missionModelId.id()); final JsonObject response; - try { - response = postRequest(request).get(); - } catch (PlanServiceException e) { - throw new MissionModelServiceException("Failed to get mission model types for model id %s".formatted(missionModelId), e); - } + response = postRequest(request).get(); final var data = response.getJsonObject("data"); if (data.get("mission_model_by_pk").getValueType().equals(JsonValue.ValueType.NULL)) throw new NoSuchMissionModelException(missionModelId); final var activityTypesJsonArray = data @@ -714,11 +705,11 @@ public MissionModelTypes getMissionModelTypes(final MissionModelId missionModelI .getJsonArray("activity_types"); final var activityTypes = parseActivityTypes(activityTypesJsonArray); - return new MissionModelTypes(activityTypes, getResourceTypes(missionModelId)); + return new MerlinService.MissionModelTypes(activityTypes, getResourceTypes(missionModelId)); } public Collection getResourceTypes(final MissionModelId missionModelId) - throws IOException, MissionModelServiceException + throws IOException, PlanServiceException { final var request = """ query GetResourceTypes { @@ -729,11 +720,7 @@ public Collection getResourceTypes(final MissionModelId missionMod } """.formatted(missionModelId.id()); final JsonObject response; - try { - response = postRequest(request).get(); - } catch (PlanServiceException e) { - throw new MissionModelServiceException("Failed to get mission model types for model id %s".formatted(missionModelId), e); - } + response = postRequest(request).get(); final var data = response.getJsonObject("data"); final var resourceTypesJsonArray = data.getJsonArray("resourceTypes"); @@ -761,7 +748,7 @@ public Collection getResourceTypes(final MissionModelId missionMod */ @Override public Collection getResourceTypes(final PlanId planId) - throws IOException, MissionModelServiceException, PlanServiceException, NoSuchPlanException + throws IOException, PlanServiceException, NoSuchPlanException { final var missionModelId = this.getPlanMetadata(planId).modelId(); final var missionModelResourceTypes = getResourceTypes(new MissionModelId(missionModelId)); diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/PlanService.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/MerlinService.java similarity index 92% rename from scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/PlanService.java rename to scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/MerlinService.java index e02a9ce165..0037d7246d 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/PlanService.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/MerlinService.java @@ -9,12 +9,15 @@ import gov.nasa.jpl.aerie.scheduler.model.SchedulingActivityDirective; import gov.nasa.jpl.aerie.scheduler.model.SchedulingActivityDirectiveId; import gov.nasa.jpl.aerie.scheduler.server.exceptions.NoSuchActivityInstanceException; +import gov.nasa.jpl.aerie.scheduler.server.exceptions.NoSuchMissionModelException; import gov.nasa.jpl.aerie.scheduler.server.exceptions.NoSuchPlanException; import gov.nasa.jpl.aerie.scheduler.server.http.InvalidJsonException; +import gov.nasa.jpl.aerie.scheduler.server.models.ActivityType; import gov.nasa.jpl.aerie.scheduler.server.models.DatasetId; import gov.nasa.jpl.aerie.scheduler.server.models.ExternalProfiles; import gov.nasa.jpl.aerie.scheduler.server.models.GoalId; import gov.nasa.jpl.aerie.scheduler.server.models.MerlinPlan; +import gov.nasa.jpl.aerie.scheduler.server.models.MissionModelId; import gov.nasa.jpl.aerie.scheduler.server.models.PlanId; import gov.nasa.jpl.aerie.scheduler.server.models.PlanMetadata; import gov.nasa.jpl.aerie.scheduler.server.models.ResourceType; @@ -26,8 +29,17 @@ import java.util.Map; import java.util.Optional; -public interface PlanService { +public interface MerlinService { + record MissionModelTypes(Collection activityTypes, Collection resourceTypes) {} + interface ReaderRole { + + MerlinService.MissionModelTypes getMissionModelTypes(final PlanId planId) + throws IOException, PlanServiceException; + MerlinService.MissionModelTypes getMissionModelTypes(final MissionModelId missionModelId) + throws IOException, PlanServiceException, + NoSuchMissionModelException; + /** * fetch current revision number of the target plan stored in aerie * @@ -91,12 +103,11 @@ ExternalProfiles getExternalProfiles(final PlanId planId) * Gets resource types associated to a plan, those coming from the mission model as well as those coming from external dataset resources * @param planId the plan id * @throws IOException - * @throws MissionModelService.MissionModelServiceException * @throws PlanServiceException * @throws NoSuchPlanException */ Collection getResourceTypes(final PlanId planId) - throws IOException, MissionModelService.MissionModelServiceException, PlanServiceException, NoSuchPlanException; + throws IOException, PlanServiceException, NoSuchPlanException; } interface WriterRole { diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/MissionModelService.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/MissionModelService.java deleted file mode 100644 index 330067b283..0000000000 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/MissionModelService.java +++ /dev/null @@ -1,30 +0,0 @@ -package gov.nasa.jpl.aerie.scheduler.server.services; - -import gov.nasa.jpl.aerie.scheduler.server.models.ActivityType; -import gov.nasa.jpl.aerie.scheduler.server.exceptions.NoSuchMissionModelException; -import gov.nasa.jpl.aerie.scheduler.server.models.MissionModelId; -import gov.nasa.jpl.aerie.scheduler.server.models.PlanId; -import gov.nasa.jpl.aerie.scheduler.server.models.ResourceType; - -import java.io.IOException; -import java.util.Collection; - -public interface MissionModelService { - MissionModelTypes getMissionModelTypes(final PlanId planId) - throws IOException, MissionModelServiceException; - MissionModelTypes getMissionModelTypes(final MissionModelId missionModelId) - throws IOException, MissionModelServiceException, - NoSuchMissionModelException; - - class MissionModelServiceException extends Exception { - MissionModelServiceException(final String message) { - super(message); - } - - public MissionModelServiceException(final String message, final Throwable cause) { - super(message, cause); - } - } - - record MissionModelTypes(Collection activityTypes, Collection resourceTypes) {} -} diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/TypescriptCodeGenerationService.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/TypescriptCodeGenerationService.java index f27f80ed24..ab93b554a6 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/TypescriptCodeGenerationService.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/TypescriptCodeGenerationService.java @@ -17,7 +17,7 @@ public final class TypescriptCodeGenerationService { private TypescriptCodeGenerationService() { } - public static String generateTypescriptTypesFromMissionModel(final MissionModelService.MissionModelTypes missionModelTypes) { + public static String generateTypescriptTypesFromMissionModel(final MerlinService.MissionModelTypes missionModelTypes) { final var activityTypeCodes = new ArrayList(); for (final var activityType : missionModelTypes.activityTypes()) { activityTypeCodes.add(getActivityTypeInformation(activityType)); diff --git a/scheduler-server/src/testFixtures/java/gov/nasa/jpl/aerie/scheduler/server/services/TypescriptCodeGenerationServiceTestFixtures.java b/scheduler-server/src/testFixtures/java/gov/nasa/jpl/aerie/scheduler/server/services/TypescriptCodeGenerationServiceTestFixtures.java index 50689f1136..c64557a89a 100644 --- a/scheduler-server/src/testFixtures/java/gov/nasa/jpl/aerie/scheduler/server/services/TypescriptCodeGenerationServiceTestFixtures.java +++ b/scheduler-server/src/testFixtures/java/gov/nasa/jpl/aerie/scheduler/server/services/TypescriptCodeGenerationServiceTestFixtures.java @@ -10,8 +10,8 @@ public final class TypescriptCodeGenerationServiceTestFixtures { - public static final MissionModelService.MissionModelTypes MISSION_MODEL_TYPES = - new MissionModelService.MissionModelTypes( + public static final MerlinService.MissionModelTypes MISSION_MODEL_TYPES = + new MerlinService.MissionModelTypes( List.of( new ActivityType( "SampleActivity1", diff --git a/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/SchedulerWorkerAppDriver.java b/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/SchedulerWorkerAppDriver.java index 0cc7cbd3df..f1682b818b 100644 --- a/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/SchedulerWorkerAppDriver.java +++ b/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/SchedulerWorkerAppDriver.java @@ -63,7 +63,6 @@ public static void main(String[] args) throws Exception { final var specificationService = new LocalSpecificationService(stores.specifications()); final var scheduleAgent = new SynchronousSchedulerAgent(specificationService, - merlinService, merlinService, config.merlinFileStore(), config.missionRuleJarPath(), diff --git a/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingDSLCompilationService.java b/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingDSLCompilationService.java index db877e6ee7..8aae835202 100644 --- a/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingDSLCompilationService.java +++ b/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingDSLCompilationService.java @@ -8,7 +8,8 @@ import gov.nasa.jpl.aerie.scheduler.server.models.SchedulingCompilationError; import gov.nasa.jpl.aerie.scheduler.server.models.SchedulingDSL; import gov.nasa.jpl.aerie.scheduler.server.services.ConstraintsTypescriptCodeGenerationHelper; -import gov.nasa.jpl.aerie.scheduler.server.services.MissionModelService; +import gov.nasa.jpl.aerie.scheduler.server.services.MerlinService; +import gov.nasa.jpl.aerie.scheduler.server.services.PlanServiceException; import gov.nasa.jpl.aerie.scheduler.server.services.TypescriptCodeGenerationService; import javax.json.Json; @@ -49,21 +50,21 @@ public void close() { this.nodeProcess.destroy(); } - public SchedulingDSLCompilationResult compileGlobalSchedulingCondition(final MissionModelService missionModelService, final PlanId planId, final String conditionTypescript, final + public SchedulingDSLCompilationResult compileGlobalSchedulingCondition(final MerlinService.ReaderRole missionModelService, final PlanId planId, final String conditionTypescript, final Collection additionalResourceTypes) { try{ final var missionModelTypes = missionModelService.getMissionModelTypes(planId); final var aggregatedResourceTypes = new ArrayList<>(missionModelTypes.resourceTypes()); aggregatedResourceTypes.addAll(additionalResourceTypes); - final var planTypes = new MissionModelService.MissionModelTypes(missionModelTypes.activityTypes(), aggregatedResourceTypes); + final var planTypes = new MerlinService.MissionModelTypes(missionModelTypes.activityTypes(), aggregatedResourceTypes); return compile(planTypes, conditionTypescript, SchedulingDSL.conditionSpecifierP, "GlobalSchedulingCondition"); - } catch (IOException | MissionModelService.MissionModelServiceException e) { + } catch (IOException | PlanServiceException e) { throw new Error(e); } } public SchedulingDSLCompilationResult compileSchedulingGoalDSL( - final MissionModelService missionModelService, + final MerlinService.ReaderRole missionModelService, final PlanId planId, final String goalTypescript){ return compileSchedulingGoalDSL(missionModelService, planId, goalTypescript, List.of()); @@ -73,7 +74,7 @@ public SchedulingDSLCompilationResult compileSchedu * NOTE: This method is not re-entrant (assumes only one call to this method is running at any given time) */ public SchedulingDSLCompilationResult compileSchedulingGoalDSL( - final MissionModelService missionModelService, + final MerlinService.ReaderRole missionModelService, final PlanId planId, final String goalTypescript, final Collection additionalResourceTypes) @@ -82,15 +83,15 @@ public SchedulingDSLCompilationResult compileSchedu final var missionModelTypes = missionModelService.getMissionModelTypes(planId); final var aggregatedResourceTypes = new ArrayList<>(missionModelTypes.resourceTypes()); aggregatedResourceTypes.addAll(additionalResourceTypes); - final var augmentedMissionModelTypes = new MissionModelService.MissionModelTypes(missionModelTypes.activityTypes(), aggregatedResourceTypes); + final var augmentedMissionModelTypes = new MerlinService.MissionModelTypes(missionModelTypes.activityTypes(), aggregatedResourceTypes); return compile(augmentedMissionModelTypes, goalTypescript, SchedulingDSL.schedulingJsonP(augmentedMissionModelTypes), "Goal"); - } catch (IOException | MissionModelService.MissionModelServiceException e) { + } catch (IOException | PlanServiceException e) { throw new Error(e); } } private SchedulingDSLCompilationResult compile( - final MissionModelService.MissionModelTypes missionModelTypes, + final MerlinService.MissionModelTypes missionModelTypes, final String goalTypescript, final JsonParser parser, final String expectedReturnType) diff --git a/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/services/SynchronousSchedulerAgent.java b/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/services/SynchronousSchedulerAgent.java index 4f69996dd7..4ac1d7d251 100644 --- a/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/services/SynchronousSchedulerAgent.java +++ b/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/services/SynchronousSchedulerAgent.java @@ -59,8 +59,7 @@ import gov.nasa.jpl.aerie.scheduler.server.models.SchedulingDSL; import gov.nasa.jpl.aerie.scheduler.server.models.Specification; import gov.nasa.jpl.aerie.scheduler.server.remotes.postgres.GoalBuilder; -import gov.nasa.jpl.aerie.scheduler.server.services.MissionModelService; -import gov.nasa.jpl.aerie.scheduler.server.services.PlanService; +import gov.nasa.jpl.aerie.scheduler.server.services.MerlinService; import gov.nasa.jpl.aerie.scheduler.server.services.PlanServiceException; import gov.nasa.jpl.aerie.scheduler.server.services.RevisionData; import gov.nasa.jpl.aerie.scheduler.server.services.ScheduleRequest; @@ -76,7 +75,6 @@ * agent that handles posed scheduling requests by blocking the requester thread until scheduling is complete * * @param planService interface for querying plan details from merlin - * @param missionModelService interface for querying mission model details from merlin * @param modelJarsDir path to parent directory for mission model jars (interim backdoor jar file access) * @param goalsJarPath path to jar file to load scheduling goals from (interim solution for user input goals) * @param outputMode how the scheduling output should be returned to aerie (eg overwrite or new container) @@ -84,8 +82,7 @@ //TODO: will eventually need scheduling goal service arg to pull goals from scheduler's own data store public record SynchronousSchedulerAgent( SpecificationService specificationService, - PlanService.OwnerRole planService, - MissionModelService missionModelService, + MerlinService.OwnerRole planService, Path modelJarsDir, Path goalsJarPath, PlanOutputMode outputMode, @@ -95,7 +92,6 @@ public record SynchronousSchedulerAgent( { public SynchronousSchedulerAgent { Objects.requireNonNull(planService); - Objects.requireNonNull(missionModelService); Objects.requireNonNull(modelJarsDir); Objects.requireNonNull(goalsJarPath); Objects.requireNonNull(schedulingDSLCompilationService); @@ -145,7 +141,7 @@ public void schedule(final ScheduleRequest request, final ResultsProtocol.Writer specification.globalSchedulingConditions().forEach($ -> { if (!$.enabled()) return; final var result = schedulingDSLCompilationService.compileGlobalSchedulingCondition( - missionModelService, + planService, planMetadata.planId(), $.source().source(), externalProfiles.resourceTypes()); @@ -179,7 +175,7 @@ public void schedule(final ScheduleRequest request, final ResultsProtocol.Writer for (final var goalRecord : specification.goalsByPriority()) { if (!goalRecord.enabled()) continue; final var result = compileGoalDefinition( - missionModelService, + planService, planMetadata.planId(), goalRecord.definition(), schedulingDSLCompilationService, @@ -322,7 +318,7 @@ private Optional storeSimulationResults(PlanningHorizon planningHoriz } private static SchedulingDSLCompilationService.SchedulingDSLCompilationResult compileGoalDefinition( - final MissionModelService missionModelService, + final MerlinService.ReaderRole missionModelService, final PlanId planId, final GoalSource goalDefinition, final SchedulingDSLCompilationService schedulingDSLCompilationService, diff --git a/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/MockMerlinService.java b/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/MockMerlinService.java index fd779c2ae9..bd5b005f66 100644 --- a/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/MockMerlinService.java +++ b/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/MockMerlinService.java @@ -20,8 +20,7 @@ import gov.nasa.jpl.aerie.scheduler.server.models.PlanId; import gov.nasa.jpl.aerie.scheduler.server.models.PlanMetadata; import gov.nasa.jpl.aerie.scheduler.server.models.ResourceType; -import gov.nasa.jpl.aerie.scheduler.server.services.MissionModelService; -import gov.nasa.jpl.aerie.scheduler.server.services.PlanService; +import gov.nasa.jpl.aerie.scheduler.server.services.MerlinService; import org.apache.commons.lang3.tuple.Pair; import java.nio.file.Path; @@ -33,7 +32,7 @@ import java.util.Map; import java.util.Optional; -class MockMerlinService implements MissionModelService, PlanService.OwnerRole { +class MockMerlinService implements MerlinService.OwnerRole { private Optional planningHorizon; private ExternalProfiles externalProfiles = new ExternalProfiles(Map.of(), Map.of(), List.of()); @@ -42,7 +41,7 @@ public void setExternalDataset(ExternalProfiles externalProfiles) { this.externalProfiles = externalProfiles; } - record MissionModelInfo(Path libPath, Path modelPath, String modelName, MissionModelTypes types, Map config) {} + record MissionModelInfo(Path libPath, Path modelPath, String modelName, MerlinService.MissionModelTypes types, Map config) {} private Optional missionModelInfo = Optional.empty(); private MerlinPlan initialPlan; @@ -185,14 +184,14 @@ public DatasetId storeSimulationResults( } @Override - public MissionModelTypes getMissionModelTypes(final PlanId planId) + public MerlinService.MissionModelTypes getMissionModelTypes(final PlanId planId) { if (this.missionModelInfo.isEmpty()) throw new RuntimeException("Make sure to call setMissionModel before running a test"); return this.missionModelInfo.get().types(); } @Override - public MissionModelTypes getMissionModelTypes(final MissionModelId missionModelId) + public MerlinService.MissionModelTypes getMissionModelTypes(final MissionModelId missionModelId) { if (this.missionModelInfo.isEmpty()) throw new RuntimeException("Make sure to call setMissionModel before running a test"); return this.missionModelInfo.get().types(); diff --git a/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingDSLCompilationServiceTests.java b/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingDSLCompilationServiceTests.java index 99a8f6c724..5588de23a9 100644 --- a/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingDSLCompilationServiceTests.java +++ b/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingDSLCompilationServiceTests.java @@ -22,20 +22,31 @@ import gov.nasa.jpl.aerie.constraints.tree.StructExpressionAt; import gov.nasa.jpl.aerie.constraints.tree.ValueAt; import gov.nasa.jpl.aerie.constraints.tree.WindowsFromSpans; +import gov.nasa.jpl.aerie.merlin.driver.SimulationResults; import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; +import gov.nasa.jpl.aerie.merlin.protocol.types.InstantiationException; import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue; import gov.nasa.jpl.aerie.scheduler.TimeUtility; import gov.nasa.jpl.aerie.scheduler.constraints.timeexpressions.TimeAnchor; +import gov.nasa.jpl.aerie.scheduler.model.Problem; +import gov.nasa.jpl.aerie.scheduler.server.exceptions.NoSuchPlanException; +import gov.nasa.jpl.aerie.scheduler.server.http.InvalidJsonException; +import gov.nasa.jpl.aerie.scheduler.server.models.ExternalProfiles; +import gov.nasa.jpl.aerie.scheduler.server.models.MerlinPlan; import gov.nasa.jpl.aerie.scheduler.server.models.MissionModelId; import gov.nasa.jpl.aerie.scheduler.server.models.PlanId; +import gov.nasa.jpl.aerie.scheduler.server.models.PlanMetadata; +import gov.nasa.jpl.aerie.scheduler.server.models.ResourceType; import gov.nasa.jpl.aerie.scheduler.server.models.SchedulingDSL; -import gov.nasa.jpl.aerie.scheduler.server.services.MissionModelService; +import gov.nasa.jpl.aerie.scheduler.server.services.MerlinService; +import gov.nasa.jpl.aerie.scheduler.server.services.PlanServiceException; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import java.io.IOException; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; @@ -51,18 +62,61 @@ @TestInstance(TestInstance.Lifecycle.PER_CLASS) class SchedulingDSLCompilationServiceTests { private static final PlanId PLAN_ID = new PlanId(1L); - private static final MissionModelService missionModelService = new MissionModelService() { + private static final MerlinService.ReaderRole missionModelService = new MerlinService.ReaderRole() { @Override - public MissionModelTypes getMissionModelTypes(final PlanId missionModelId) + public MerlinService.MissionModelTypes getMissionModelTypes(final PlanId missionModelId) { return MISSION_MODEL_TYPES; } @Override - public MissionModelTypes getMissionModelTypes(final MissionModelId missionModelId) + public MerlinService.MissionModelTypes getMissionModelTypes(final MissionModelId missionModelId) { return MISSION_MODEL_TYPES; } + + @Override + public long getPlanRevision(final PlanId planId) throws IOException, NoSuchPlanException, PlanServiceException { + return 0; + } + + @Override + public PlanMetadata getPlanMetadata(final PlanId planId) + throws IOException, NoSuchPlanException, PlanServiceException + { + return null; + } + + @Override + public MerlinPlan getPlanActivityDirectives(final PlanMetadata planMetadata, final Problem mission) + throws IOException, NoSuchPlanException, PlanServiceException, InvalidJsonException, InstantiationException + { + return null; + } + + @Override + public void ensurePlanExists(final PlanId planId) throws IOException, NoSuchPlanException, PlanServiceException { + + } + + @Override + public Optional getSimulationResults(final PlanMetadata planMetadata) + throws PlanServiceException, IOException, InvalidJsonException + { + return Optional.empty(); + } + + @Override + public ExternalProfiles getExternalProfiles(final PlanId planId) throws PlanServiceException, IOException { + return null; + } + + @Override + public Collection getResourceTypes(final PlanId planId) + throws IOException, PlanServiceException, NoSuchPlanException + { + return null; + } }; SchedulingDSLCompilationService schedulingDSLCompilationService; diff --git a/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingIntegrationTests.java b/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingIntegrationTests.java index e2a386eaca..825388ea1f 100644 --- a/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingIntegrationTests.java +++ b/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingIntegrationTests.java @@ -22,14 +22,11 @@ import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.MINUTE; import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.MINUTES; import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.SECOND; -import static gov.nasa.jpl.aerie.merlin.protocol.types.Duration.ZERO; import static org.junit.jupiter.api.Assertions.*; import gov.nasa.jpl.aerie.constraints.model.DiscreteProfile; import gov.nasa.jpl.aerie.constraints.time.Interval; import gov.nasa.jpl.aerie.constraints.time.Segment; -import gov.nasa.jpl.aerie.constraints.tree.DiscreteResource; -import gov.nasa.jpl.aerie.foomissionmodel.mappers.FooValueMappers; import gov.nasa.jpl.aerie.merlin.driver.ActivityDirective; import gov.nasa.jpl.aerie.merlin.driver.ActivityDirectiveId; import gov.nasa.jpl.aerie.merlin.driver.MissionModelLoader; @@ -40,7 +37,6 @@ import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue; import gov.nasa.jpl.aerie.merlin.protocol.types.ValueSchema; import gov.nasa.jpl.aerie.scheduler.TimeUtility; -import gov.nasa.jpl.aerie.scheduler.model.ActivityType; import gov.nasa.jpl.aerie.scheduler.model.PlanningHorizon; import gov.nasa.jpl.aerie.scheduler.server.config.PlanOutputMode; import gov.nasa.jpl.aerie.scheduler.server.http.SchedulerParsers; @@ -55,7 +51,7 @@ import gov.nasa.jpl.aerie.scheduler.server.models.Specification; import gov.nasa.jpl.aerie.scheduler.server.models.SpecificationId; import gov.nasa.jpl.aerie.scheduler.server.models.Timestamp; -import gov.nasa.jpl.aerie.scheduler.server.services.MissionModelService; +import gov.nasa.jpl.aerie.scheduler.server.services.MerlinService; 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; @@ -2027,7 +2023,6 @@ private SchedulingRunResults runScheduler( final var agent = new SynchronousSchedulerAgent( specificationService, mockMerlinService, - mockMerlinService, desc.libPath(), Path.of(""), PlanOutputMode.UpdateInputPlanWithNewActivities, @@ -2047,7 +2042,7 @@ private SchedulingRunResults runScheduler( record SchedulingRunResults(ScheduleResults scheduleResults, Collection updatedPlan, Plan plan, Map idToAct) {} - static MissionModelService.MissionModelTypes loadMissionModelTypesFromJar( + static MerlinService.MissionModelTypes loadMissionModelTypesFromJar( final String jarPath, final Map configuration) throws MissionModelLoader.MissionModelLoadException @@ -2081,7 +2076,7 @@ static MissionModelService.MissionModelTypes loadMissionModelTypesFromJar( resourceTypes.add(new ResourceType(name, resource.getOutputType().getSchema())); } - return new MissionModelService.MissionModelTypes(activityTypes, resourceTypes); + return new MerlinService.MissionModelTypes(activityTypes, resourceTypes); } @Test