diff --git a/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/goals/Procedure.java b/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/goals/Procedure.java index a4ed23538d..42dde11280 100644 --- a/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/goals/Procedure.java +++ b/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/goals/Procedure.java @@ -19,15 +19,16 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.function.Function; import static gov.nasa.jpl.aerie.scheduler.plan.InMemoryEditablePlan.toSchedulingActivity; public class Procedure extends Goal { private final Path jarPath; - private final SerializedValue args; + private final Map args; - public Procedure(final PlanningHorizon planningHorizon, Path jarPath, SerializedValue args, boolean simulateAfter) { + public Procedure(final PlanningHorizon planningHorizon, Path jarPath, Map args, boolean simulateAfter) { this.simulateAfter = simulateAfter; this.planHorizon = planningHorizon; this.jarPath = jarPath; @@ -57,7 +58,7 @@ public void run(Evaluation eval, Plan plan, MissionModel missionModel, Functi lookupActivityType::apply ); - procedureMapper.deserialize(this.args).run(editablePlan); + procedureMapper.deserialize(SerializedValue.of(this.args)).run(editablePlan); if (!editablePlan.getUncommittedChanges().isEmpty()) { throw new IllegalStateException("procedural goal %s had changes that were not committed or rolled back".formatted(jarPath.getFileName())); diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/http/SchedulerParsers.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/http/SchedulerParsers.java index 260a846a41..cad88bc85f 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/http/SchedulerParsers.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/http/SchedulerParsers.java @@ -8,6 +8,10 @@ import gov.nasa.jpl.aerie.types.MissionModelId; import gov.nasa.jpl.aerie.types.Timestamp; +import javax.json.Json; +import javax.json.stream.JsonParsingException; +import java.io.StringReader; +import java.util.List; import java.util.Optional; import static gov.nasa.jpl.aerie.json.BasicParsers.anyP; @@ -121,4 +125,16 @@ private static JsonParser> hasura .map( untuple(HasuraAction.HasuraSchedulingGoalEvent::new), $ -> tuple($.goalId(), $.revision())); + + public static T parseJson(final String jsonStr, final JsonParser parser) + throws InvalidJsonException, InvalidEntityException + { + try (final var reader = Json.createReader(new StringReader(jsonStr))) { + final var requestJson = reader.readValue(); + final var result = parser.parse(requestJson); + return result.getSuccessOrThrow(reason -> new InvalidEntityException(List.of(reason))); + } catch (JsonParsingException e) { + throw new InvalidJsonException(e); + } + } } diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/GoalInvocationRecord.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/GoalInvocationRecord.java new file mode 100644 index 0000000000..bb048ddbf8 --- /dev/null +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/GoalInvocationRecord.java @@ -0,0 +1,12 @@ +package gov.nasa.jpl.aerie.scheduler.server.models; + +import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue; + +import java.util.Map; + +public record GoalInvocationRecord( + GoalId id, + String name, + GoalType type, + Map args, + boolean simulateAfter) {} diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/GoalRecord.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/GoalRecord.java deleted file mode 100644 index 94bbbf1828..0000000000 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/GoalRecord.java +++ /dev/null @@ -1,10 +0,0 @@ -package gov.nasa.jpl.aerie.scheduler.server.models; - -import java.nio.file.Path; -import java.util.Optional; - -public record GoalRecord( - GoalId id, - String name, - GoalType type, - boolean simulateAfter) {} diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/GoalType.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/GoalType.java index 0aa89e456a..c4381a884e 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/GoalType.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/GoalType.java @@ -1,9 +1,8 @@ package gov.nasa.jpl.aerie.scheduler.server.models; -import javax.json.JsonObject; import java.nio.file.Path; public sealed interface GoalType { record EDSL(GoalSource source) implements GoalType {} - record JAR(Path path, String args) implements GoalType {} + record JAR(Path path) implements GoalType {} } 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 45a65d30b8..37e3907d51 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 @@ -302,7 +302,7 @@ record GoalApplyWhen( ) implements GoalSpecifier {} record Procedure( Path jarPath, - SerializedValue arguments + Map arguments ) implements GoalSpecifier {} } diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/Specification.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/Specification.java index 42d471e34f..2c034c9d32 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/Specification.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/models/Specification.java @@ -15,6 +15,6 @@ public record Specification( Timestamp horizonEndTimestamp, Map simulationArguments, boolean analysisOnly, - List goalsByPriority, + List goalsByPriority, List schedulingConditions ) {} diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/SpecificationRepository.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/SpecificationRepository.java index 1cb1436f77..8c3d192eea 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/SpecificationRepository.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/SpecificationRepository.java @@ -5,7 +5,7 @@ import gov.nasa.jpl.aerie.scheduler.server.exceptions.NoSuchSpecificationException; import gov.nasa.jpl.aerie.scheduler.server.exceptions.SpecificationLoadException; import gov.nasa.jpl.aerie.scheduler.server.models.GoalId; -import gov.nasa.jpl.aerie.scheduler.server.models.GoalRecord; +import gov.nasa.jpl.aerie.scheduler.server.models.GoalType; 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.remotes.postgres.SpecificationRevisionData; @@ -15,6 +15,6 @@ public interface SpecificationRepository { Specification getSpecification(SpecificationId specificationId) throws NoSuchSpecificationException, SpecificationLoadException; SpecificationRevisionData getSpecificationRevisionData(SpecificationId specificationId) throws NoSuchSpecificationException; - GoalRecord getGoal(GoalId goalId) throws NoSuchSchedulingGoalException; + GoalType getGoal(GoalId goalId) throws NoSuchSchedulingGoalException; void updateGoalParameterSchema(GoalId goalId, ValueSchema schema); } diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/GetSchedulingGoalAction.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/GetSchedulingGoalAction.java index 4e40e1a9f4..40c8b1ee0b 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/GetSchedulingGoalAction.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/GetSchedulingGoalAction.java @@ -1,7 +1,6 @@ package gov.nasa.jpl.aerie.scheduler.server.remotes.postgres; import gov.nasa.jpl.aerie.scheduler.server.models.GoalId; -import gov.nasa.jpl.aerie.scheduler.server.models.GoalRecord; import gov.nasa.jpl.aerie.scheduler.server.models.GoalSource; import gov.nasa.jpl.aerie.scheduler.server.models.GoalType; import org.intellij.lang.annotations.Language; @@ -14,7 +13,7 @@ /*package-local*/ final class GetSchedulingGoalAction implements AutoCloseable { private final @Language("SQL") String sql = """ - select gd.goal_id, gd.revision, gm.name, gd.definition, gd.type, encode(f.path, 'escape') as path + select gd.definition, gd.type, encode(f.path, 'escape') as path from scheduler.scheduling_goal_definition gd left join scheduler.scheduling_goal_metadata gm on gd.goal_id = gm.id left join merlin.uploaded_file f on gd.uploaded_jar_id = f.id @@ -27,24 +26,18 @@ public GetSchedulingGoalAction(final Connection connection) throws SQLException this.statement = connection.prepareStatement(sql); } - public Optional get(final GoalId goalId) throws SQLException { + public Optional get(final GoalId goalId) throws SQLException { this.statement.setLong(1, goalId.id()); this.statement.setLong(2, goalId.revision()); final var resultSet = this.statement.executeQuery(); if (!resultSet.next()) return Optional.empty(); - final var name = resultSet.getString("name"); final var definition = resultSet.getString("definition"); final var type = resultSet.getString("type"); final var path = resultSet.getString("path"); - return Optional.of(new GoalRecord( - goalId, - name, - type.equals("JAR") ? new GoalType.JAR(Path.of(path), "" /* TODO this is a property of the specification, not the goal */) : new GoalType.EDSL(new GoalSource(definition)), - true // TODO this is not a property of the goal, but rather of the specification - )); + return Optional.of(type.equals("JAR") ? new GoalType.JAR(Path.of(path)) : new GoalType.EDSL(new GoalSource(definition))); } @Override diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/GetSpecificationGoalsAction.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/GetSpecificationGoalsAction.java index ec6f14f762..d6968b78be 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/GetSpecificationGoalsAction.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/GetSpecificationGoalsAction.java @@ -1,7 +1,10 @@ package gov.nasa.jpl.aerie.scheduler.server.remotes.postgres; +import gov.nasa.jpl.aerie.merlin.driver.json.SerializedValueJsonParser; +import gov.nasa.jpl.aerie.scheduler.server.http.InvalidEntityException; +import gov.nasa.jpl.aerie.scheduler.server.http.InvalidJsonException; import gov.nasa.jpl.aerie.scheduler.server.models.GoalId; -import gov.nasa.jpl.aerie.scheduler.server.models.GoalRecord; +import gov.nasa.jpl.aerie.scheduler.server.models.GoalInvocationRecord; import gov.nasa.jpl.aerie.scheduler.server.models.GoalSource; import gov.nasa.jpl.aerie.scheduler.server.models.GoalType; import org.intellij.lang.annotations.Language; @@ -14,6 +17,8 @@ import java.util.List; import java.util.Optional; +import static gov.nasa.jpl.aerie.scheduler.server.http.SchedulerParsers.parseJson; + /*package-local*/ final class GetSpecificationGoalsAction implements AutoCloseable { private final @Language("SQL") String sql = """ select s.goal_id, gd.revision, gm.name, gd.definition, s.goal_invocation_id, s.simulate_after, gd.type, encode(f.path, 'escape') as path, s.arguments @@ -37,30 +42,36 @@ public GetSpecificationGoalsAction(final Connection connection) throws SQLExcept this.statement = connection.prepareStatement(sql); } - public List get(final long specificationId) throws SQLException { + public List get(final long specificationId) throws SQLException { this.statement.setLong(1, specificationId); final var resultSet = this.statement.executeQuery(); - final var goals = new ArrayList(); - while (resultSet.next()) { - final var id = resultSet.getLong("goal_id"); - final var goalInvocationId = resultSet.getLong("goal_invocation_id"); - final var revision = resultSet.getLong("revision"); - final var name = resultSet.getString("name"); - final var definition = resultSet.getString("definition"); - final var simulateAfter = resultSet.getBoolean("simulate_after"); - final var type = resultSet.getString("type"); - final var path = resultSet.getString("path"); - final var args = resultSet.getString("arguments"); - goals.add(new GoalRecord( + try { + + final var goals = new ArrayList(); + while (resultSet.next()) { + final var id = resultSet.getLong("goal_id"); + final var goalInvocationId = resultSet.getLong("goal_invocation_id"); + final var revision = resultSet.getLong("revision"); + final var name = resultSet.getString("name"); + final var definition = resultSet.getString("definition"); + final var simulateAfter = resultSet.getBoolean("simulate_after"); + final var type = resultSet.getString("type"); + final var path = resultSet.getString("path"); + final var args = parseJson(resultSet.getString("arguments"), new SerializedValueJsonParser()); + + goals.add(new GoalInvocationRecord( new GoalId(id, revision, Optional.of(goalInvocationId)), name, - type.equals("JAR") ? new GoalType.JAR(Path.of(path), args) : new GoalType.EDSL(new GoalSource(definition)), + type.equals("JAR") ? new GoalType.JAR(Path.of(path)) : new GoalType.EDSL(new GoalSource(definition)), + args.asMap().get(), simulateAfter - )); + )); + } + return goals; + } catch (InvalidJsonException | InvalidEntityException e) { + throw new RuntimeException(e); } - - return goals; } @Override diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/PostgresSpecificationRepository.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/PostgresSpecificationRepository.java index 5f97edc0bc..3338460c64 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/PostgresSpecificationRepository.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/PostgresSpecificationRepository.java @@ -4,8 +4,9 @@ import gov.nasa.jpl.aerie.scheduler.server.exceptions.NoSuchSchedulingGoalException; import gov.nasa.jpl.aerie.scheduler.server.exceptions.NoSuchSpecificationException; import gov.nasa.jpl.aerie.scheduler.server.models.GoalId; +import gov.nasa.jpl.aerie.scheduler.server.models.GoalType; import gov.nasa.jpl.aerie.scheduler.server.models.SchedulingConditionRecord; -import gov.nasa.jpl.aerie.scheduler.server.models.GoalRecord; +import gov.nasa.jpl.aerie.scheduler.server.models.GoalInvocationRecord; import gov.nasa.jpl.aerie.scheduler.server.models.PlanId; import gov.nasa.jpl.aerie.scheduler.server.models.Specification; import gov.nasa.jpl.aerie.scheduler.server.models.SpecificationId; @@ -28,7 +29,7 @@ public Specification getSpecification(final SpecificationId specificationId) { final SpecificationRecord specificationRecord; final PlanId planId; - final List goals; + final List goals; final List schedulingConditions; try (final var connection = this.dataSource.getConnection(); final var getSpecificationAction = new GetSpecificationAction(connection); @@ -77,7 +78,7 @@ public SpecificationRevisionData getSpecificationRevisionData(final Specificatio } @Override - public GoalRecord getGoal(final GoalId goalId) throws NoSuchSchedulingGoalException { + public GoalType getGoal(final GoalId goalId) throws NoSuchSchedulingGoalException { try (final var connection = this.dataSource.getConnection()) { try (final var getGoalAction = new GetSchedulingGoalAction(connection)) { return getGoalAction diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/UpdateSchedulingGoalParameterSchemaAction.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/UpdateSchedulingGoalParameterSchemaAction.java index 579291ad5d..27dce53309 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/UpdateSchedulingGoalParameterSchemaAction.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/remotes/postgres/UpdateSchedulingGoalParameterSchemaAction.java @@ -3,20 +3,16 @@ import gov.nasa.jpl.aerie.merlin.driver.json.ValueSchemaJsonParser; import gov.nasa.jpl.aerie.merlin.protocol.types.ValueSchema; import gov.nasa.jpl.aerie.scheduler.server.models.GoalId; -import gov.nasa.jpl.aerie.scheduler.server.models.GoalRecord; -import gov.nasa.jpl.aerie.scheduler.server.models.GoalType; import org.intellij.lang.annotations.Language; -import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; -import java.util.Optional; /*package-local*/ final class UpdateSchedulingGoalParameterSchemaAction implements AutoCloseable { private final @Language("SQL") String sql = """ update scheduler.scheduling_goal_definition gd - set parameter_schema=?::jsonb + set parameter_schema=?::jsonb where gd.goal_id = ? and gd.revision = ?; """; diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/SpecificationService.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/SpecificationService.java index 63c06b0efd..9fe6fad93e 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/SpecificationService.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/SpecificationService.java @@ -1,15 +1,11 @@ package gov.nasa.jpl.aerie.scheduler.server.services; -import gov.nasa.jpl.aerie.merlin.driver.DirectiveTypeRegistry; -import gov.nasa.jpl.aerie.merlin.driver.MissionModelLoader; -import gov.nasa.jpl.aerie.merlin.protocol.model.ModelType; import gov.nasa.ammos.aerie.procedural.scheduling.ProcedureMapper; import gov.nasa.jpl.aerie.scheduler.ProcedureLoader; import gov.nasa.jpl.aerie.scheduler.server.exceptions.NoSuchSchedulingGoalException; import gov.nasa.jpl.aerie.scheduler.server.exceptions.NoSuchSpecificationException; import gov.nasa.jpl.aerie.scheduler.server.exceptions.SpecificationLoadException; import gov.nasa.jpl.aerie.scheduler.server.models.GoalId; -import gov.nasa.jpl.aerie.scheduler.server.models.GoalRecord; import gov.nasa.jpl.aerie.scheduler.server.models.GoalType; import gov.nasa.jpl.aerie.scheduler.server.models.Specification; import gov.nasa.jpl.aerie.scheduler.server.models.SpecificationId; @@ -17,7 +13,6 @@ import gov.nasa.jpl.aerie.scheduler.server.remotes.postgres.SpecificationRevisionData; import java.nio.file.Path; -import java.util.HashMap; public record SpecificationService(SpecificationRepository specificationRepository) { // Queries @@ -34,13 +29,13 @@ public SpecificationRevisionData getSpecificationRevisionData(final Specificatio } public void refreshSchedulingProcedureParameterTypes(long goalId, long revision) { - final GoalRecord goal; + final GoalType goal; try { goal = specificationRepository.getGoal(new GoalId(goalId, revision)); } catch (NoSuchSchedulingGoalException e) { throw new RuntimeException(e); } - switch (goal.type()) { + switch (goal) { case GoalType.EDSL edsl -> { // Do nothing } 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 7d159ad975..5d046daeca 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 @@ -3,7 +3,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.io.StringReader; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; @@ -21,12 +20,10 @@ import java.util.jar.JarFile; import java.util.stream.Collectors; -import gov.nasa.jpl.aerie.json.JsonParser; import gov.nasa.jpl.aerie.merlin.driver.MissionModel; import gov.nasa.jpl.aerie.merlin.driver.MissionModelLoader; import gov.nasa.jpl.aerie.merlin.driver.SimulationEngineConfiguration; import gov.nasa.jpl.aerie.merlin.driver.SimulationResults; -import gov.nasa.jpl.aerie.merlin.driver.json.SerializedValueJsonParser; import gov.nasa.jpl.aerie.merlin.protocol.model.SchedulerModel; import gov.nasa.jpl.aerie.merlin.protocol.model.SchedulerPlugin; import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; @@ -47,13 +44,12 @@ import gov.nasa.jpl.aerie.scheduler.server.exceptions.NoSuchSpecificationException; import gov.nasa.jpl.aerie.scheduler.server.exceptions.ResultsProtocolFailure; import gov.nasa.jpl.aerie.scheduler.server.exceptions.SpecificationLoadException; -import gov.nasa.jpl.aerie.scheduler.server.http.InvalidEntityException; import gov.nasa.jpl.aerie.scheduler.server.http.InvalidJsonException; import gov.nasa.jpl.aerie.scheduler.server.http.ResponseSerializers; 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.GoalRecord; +import gov.nasa.jpl.aerie.scheduler.server.models.GoalInvocationRecord; import gov.nasa.jpl.aerie.scheduler.server.models.GoalSource; import gov.nasa.jpl.aerie.scheduler.server.models.GoalType; import gov.nasa.jpl.aerie.scheduler.server.models.MerlinPlan; @@ -80,9 +76,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.json.Json; -import javax.json.stream.JsonParsingException; - /** * agent that handles posed scheduling requests by blocking the requester thread until scheduling is complete * @@ -194,7 +187,7 @@ public void schedule( final var orderedGoals = new ArrayList(); final var goals = new HashMap(); - final var compiledGoals = new ArrayList>(); + final var compiledGoals = new ArrayList>(); final var failedGoals = new ArrayList>>(); for (final var goalRecord : specification.goalsByPriority()) { switch (goalRecord.type()) { @@ -216,12 +209,7 @@ public void schedule( } } case GoalType.JAR jar -> { - try { - final var serializedValue = parseJson(jar.args(), new SerializedValueJsonParser()); - compiledGoals.add(Pair.of(goalRecord, new SchedulingDSL.GoalSpecifier.Procedure(modelJarsDir.resolve(jar.path()), serializedValue))); - } catch (InvalidJsonException | InvalidEntityException e) { - throw new RuntimeException(e); - } + compiledGoals.add(Pair.of(goalRecord, new SchedulingDSL.GoalSpecifier.Procedure(modelJarsDir.resolve(jar.path()), goalRecord.args()))); } } } @@ -661,16 +649,4 @@ private ScheduleResults collectResults(final Plan plan, Map T parseJson(final String jsonStr, final JsonParser parser) - throws InvalidJsonException, InvalidEntityException - { - try (final var reader = Json.createReader(new StringReader(jsonStr))) { - final var requestJson = reader.readValue(); - final var result = parser.parse(requestJson); - return result.getSuccessOrThrow(reason -> new InvalidEntityException(List.of(reason))); - } catch (JsonParsingException e) { - throw new InvalidJsonException(e); - } - } } diff --git a/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/MockSpecificationRepository.java b/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/MockSpecificationRepository.java index 058266be50..9547dbc82a 100644 --- a/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/MockSpecificationRepository.java +++ b/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/MockSpecificationRepository.java @@ -6,7 +6,7 @@ import gov.nasa.jpl.aerie.merlin.protocol.types.ValueSchema; import gov.nasa.jpl.aerie.scheduler.server.exceptions.NoSuchSpecificationException; import gov.nasa.jpl.aerie.scheduler.server.models.GoalId; -import gov.nasa.jpl.aerie.scheduler.server.models.GoalRecord; +import gov.nasa.jpl.aerie.scheduler.server.models.GoalType; 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.remotes.SpecificationRepository; @@ -38,7 +38,7 @@ public SpecificationRevisionData getSpecificationRevisionData(final Specificatio } @Override - public GoalRecord getGoal(final GoalId goalId) { + public GoalType getGoal(final GoalId goalId) { return null; } diff --git a/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingEdslIntegrationTests.java b/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingEdslIntegrationTests.java index 2596655641..b7dda0af9a 100644 --- a/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingEdslIntegrationTests.java +++ b/scheduler-worker/src/test/java/gov/nasa/jpl/aerie/scheduler/worker/services/SchedulingEdslIntegrationTests.java @@ -43,7 +43,7 @@ import gov.nasa.jpl.aerie.scheduler.server.models.SchedulingConditionRecord; import gov.nasa.jpl.aerie.scheduler.server.models.SchedulingConditionSource; import gov.nasa.jpl.aerie.scheduler.server.models.GoalId; -import gov.nasa.jpl.aerie.scheduler.server.models.GoalRecord; +import gov.nasa.jpl.aerie.scheduler.server.models.GoalInvocationRecord; import gov.nasa.jpl.aerie.scheduler.server.models.GoalSource; import gov.nasa.jpl.aerie.scheduler.server.models.PlanId; import gov.nasa.jpl.aerie.scheduler.server.models.ResourceType; @@ -2195,10 +2195,10 @@ private SchedulingRunResults runScheduler( mockMerlinService.setPlanningHorizon(planningHorizon); externalProfiles.ifPresent(mockMerlinService::setExternalDataset); final var planId = new PlanId(1L); - final var goalsByPriority = new ArrayList(); + final var goalsByPriority = new ArrayList(); for (final var goal : goals) { - goalsByPriority.add(new GoalRecord(goal.goalId(), "test goal", new GoalType.EDSL(new GoalSource(goal.definition())), goal.simulateAfter())); + goalsByPriority.add(new GoalInvocationRecord(goal.goalId(), "test goal", new GoalType.EDSL(new GoalSource(goal.definition())), Map.of(), goal.simulateAfter())); } final var specificationService = new SpecificationService(new MockSpecificationRepository(Map.of(new SpecificationId(1L), new Specification( new SpecificationId(1L),