From 8edb2fd3fe2253d89aba2c0b51200d70338f4e6a Mon Sep 17 00:00:00 2001 From: Matthew Dailis Date: Thu, 14 Mar 2024 22:13:21 -0700 Subject: [PATCH] Declare Merlin Plugin Version --- .../aerie/banananation/SimulationUtility.java | 3 ++- .../foomissionmodel/SimulateMapSchedule.java | 3 ++- .../jpl/aerie/merlin/driver/MissionModel.java | 10 ++++++++- .../merlin/driver/MissionModelBuilder.java | 15 ++++++++----- .../merlin/driver/MissionModelLoader.java | 8 ++++--- .../aerie/merlin/driver/SimulationDriver.java | 22 +++++++++++++++++-- .../driver/engine/SimulationEngine.java | 9 ++++++++ .../merlin/driver/AnchorSimulationTest.java | 4 +++- .../aerie/merlin/driver/CellExpiryTest.java | 3 ++- .../framework/junit/MerlinExtension.java | 3 ++- .../generator/MissionModelGenerator.java | 11 ++++++++++ .../merlin/protocol/MerlinPluginVersion.java | 10 +++++++++ .../merlin/protocol/model/MerlinPlugin.java | 12 ++++++++++ .../merlin/protocol/model/ModelType.java | 1 + .../simulation/ResumableSimulationDriver.java | 7 ++++-- .../aerie/scheduler/SimulationUtility.java | 6 +++-- .../simulation/AnchorSchedulerTest.java | 4 +++- 17 files changed, 109 insertions(+), 22 deletions(-) create mode 100644 merlin-sdk/src/main/java/gov/nasa/jpl/aerie/merlin/protocol/MerlinPluginVersion.java diff --git a/examples/banananation/src/test/java/gov/nasa/jpl/aerie/banananation/SimulationUtility.java b/examples/banananation/src/test/java/gov/nasa/jpl/aerie/banananation/SimulationUtility.java index 65adba4bc1..2e86fac7b3 100644 --- a/examples/banananation/src/test/java/gov/nasa/jpl/aerie/banananation/SimulationUtility.java +++ b/examples/banananation/src/test/java/gov/nasa/jpl/aerie/banananation/SimulationUtility.java @@ -3,6 +3,7 @@ import gov.nasa.jpl.aerie.banananation.generated.GeneratedModelType; import gov.nasa.jpl.aerie.merlin.driver.*; import gov.nasa.jpl.aerie.merlin.driver.ActivityDirectiveId; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; import org.apache.commons.lang3.tuple.Pair; @@ -17,7 +18,7 @@ private static MissionModel makeMissionModel(final MissionModelBuilder builde final var registry = DirectiveTypeRegistry.extract(factory); // TODO: [AERIE-1516] Teardown the model to release any system resources (e.g. threads). final var model = factory.instantiate(planStart, config, builder); - return builder.build(model, registry); + return builder.build(model, registry, MerlinPluginVersion.V1); } public static SimulationResults diff --git a/examples/foo-missionmodel/src/test/java/gov/nasa/jpl/aerie/foomissionmodel/SimulateMapSchedule.java b/examples/foo-missionmodel/src/test/java/gov/nasa/jpl/aerie/foomissionmodel/SimulateMapSchedule.java index 767b61d1ae..63d4bc641c 100644 --- a/examples/foo-missionmodel/src/test/java/gov/nasa/jpl/aerie/foomissionmodel/SimulateMapSchedule.java +++ b/examples/foo-missionmodel/src/test/java/gov/nasa/jpl/aerie/foomissionmodel/SimulateMapSchedule.java @@ -4,6 +4,7 @@ import gov.nasa.jpl.aerie.merlin.driver.*; import gov.nasa.jpl.aerie.merlin.driver.ActivityDirectiveId; import gov.nasa.jpl.aerie.merlin.driver.json.JsonEncoding; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue; import org.apache.commons.lang3.tuple.Pair; @@ -27,7 +28,7 @@ public static void main(final String[] args) { final var factory = new GeneratedModelType(); final var registry = DirectiveTypeRegistry.extract(factory); final var model = factory.instantiate(planStart, config, builder); - return builder.build(model, registry); + return builder.build(model, registry, MerlinPluginVersion.V1); } private static diff --git a/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/MissionModel.java b/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/MissionModel.java index d53ee219a4..dfc9510373 100644 --- a/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/MissionModel.java +++ b/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/MissionModel.java @@ -1,6 +1,7 @@ package gov.nasa.jpl.aerie.merlin.driver; import gov.nasa.jpl.aerie.merlin.driver.timeline.LiveCells; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; import gov.nasa.jpl.aerie.merlin.protocol.driver.Topic; import gov.nasa.jpl.aerie.merlin.protocol.model.OutputType; import gov.nasa.jpl.aerie.merlin.protocol.model.Resource; @@ -21,6 +22,7 @@ public final class MissionModel { private final List> topics; private final DirectiveTypeRegistry directiveTypes; private final List> daemons; + private final MerlinPluginVersion merlinPluginVersion; public MissionModel( final Model model, @@ -28,7 +30,8 @@ public MissionModel( final Map> resources, final List> topics, final List> daemons, - final DirectiveTypeRegistry directiveTypes) + final DirectiveTypeRegistry directiveTypes, + final MerlinPluginVersion merlinPluginVersion) { this.model = Objects.requireNonNull(model); this.initialCells = Objects.requireNonNull(initialCells); @@ -36,6 +39,7 @@ public MissionModel( this.topics = Collections.unmodifiableList(topics); this.directiveTypes = Objects.requireNonNull(directiveTypes); this.daemons = Collections.unmodifiableList(daemons); + this.merlinPluginVersion = merlinPluginVersion; } public Model getModel() { @@ -81,4 +85,8 @@ public record SerializableTopic ( Topic topic, OutputType outputType ) {} + + public MerlinPluginVersion getMerlinPluginVersion() { + return this.merlinPluginVersion; + } } diff --git a/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/MissionModelBuilder.java b/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/MissionModelBuilder.java index 4818d5cf0e..90b3bbdbca 100644 --- a/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/MissionModelBuilder.java +++ b/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/MissionModelBuilder.java @@ -7,6 +7,7 @@ import gov.nasa.jpl.aerie.merlin.driver.timeline.Query; import gov.nasa.jpl.aerie.merlin.driver.timeline.RecursiveEventGraphEvaluator; import gov.nasa.jpl.aerie.merlin.driver.timeline.Selector; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; import gov.nasa.jpl.aerie.merlin.protocol.driver.CellId; import gov.nasa.jpl.aerie.merlin.protocol.driver.Initializer; import gov.nasa.jpl.aerie.merlin.protocol.driver.Topic; @@ -62,15 +63,16 @@ public void daemon(final TaskFactory task) { } public - MissionModel build(final Model model, final DirectiveTypeRegistry registry) { - return this.state.build(model, registry); + MissionModel build(final Model model, final DirectiveTypeRegistry registry, final MerlinPluginVersion merlinPluginVersion) { + return this.state.build(model, registry, merlinPluginVersion); } private interface MissionModelBuilderState extends Initializer { MissionModel build( Model model, - DirectiveTypeRegistry registry); + DirectiveTypeRegistry registry, + MerlinPluginVersion merlinPluginVersion); } private final class UnbuiltState implements MissionModelBuilderState { @@ -137,14 +139,15 @@ public void daemon(final TaskFactory task) { @Override public - MissionModel build(final Model model, final DirectiveTypeRegistry registry) { + MissionModel build(final Model model, final DirectiveTypeRegistry registry, final MerlinPluginVersion merlinPluginVersion) { final var missionModel = new MissionModel<>( model, this.initialCells, this.resources, this.topics, this.daemons, - registry); + registry, + MerlinPluginVersion.V0); MissionModelBuilder.this.state = new BuiltState(); @@ -192,7 +195,7 @@ public void daemon(final TaskFactory task) { @Override public - MissionModel build(final Model model, final DirectiveTypeRegistry registry) { + MissionModel build(final Model model, final DirectiveTypeRegistry registry, final MerlinPluginVersion merlinPluginVersion) { throw new IllegalStateException("Cannot build a builder multiple times"); } } diff --git a/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/MissionModelLoader.java b/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/MissionModelLoader.java index dc455b4c7c..87f829bab2 100644 --- a/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/MissionModelLoader.java +++ b/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/MissionModelLoader.java @@ -1,5 +1,6 @@ package gov.nasa.jpl.aerie.merlin.driver; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; import gov.nasa.jpl.aerie.merlin.protocol.model.MerlinPlugin; import gov.nasa.jpl.aerie.merlin.protocol.model.ModelType; import gov.nasa.jpl.aerie.merlin.protocol.types.InstantiationException; @@ -35,7 +36,7 @@ public static MissionModel loadMissionModel( final var service = loadMissionModelProvider(path, name, version); final var modelType = service.getModelType(); final var builder = new MissionModelBuilder(); - return loadMissionModel(planStart, missionModelConfig, modelType, builder); + return loadMissionModel(planStart, missionModelConfig, modelType, builder, service.getMerlinPluginVersion()); } private static @@ -43,7 +44,8 @@ MissionModel loadMissionModel( final Instant planStart, final SerializedValue missionModelConfig, final ModelType modelType, - final MissionModelBuilder builder) + final MissionModelBuilder builder, + final MerlinPluginVersion merlinPluginVersion) { try { final var serializedConfigMap = missionModelConfig.asMap().orElseThrow(() -> @@ -52,7 +54,7 @@ MissionModel loadMissionModel( final var config = modelType.getConfigurationType().instantiate(serializedConfigMap); final var registry = DirectiveTypeRegistry.extract(modelType); final var model = modelType.instantiate(planStart, config, builder); - return builder.build(model, registry); + return builder.build(model, registry, merlinPluginVersion); } catch (final InstantiationException ex) { throw new MissionModelInstantiationException(ex); } diff --git a/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/SimulationDriver.java b/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/SimulationDriver.java index 0859608108..a2b9eedc48 100644 --- a/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/SimulationDriver.java +++ b/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/SimulationDriver.java @@ -3,6 +3,7 @@ import gov.nasa.jpl.aerie.merlin.driver.engine.SimulationEngine; import gov.nasa.jpl.aerie.merlin.driver.timeline.LiveCells; import gov.nasa.jpl.aerie.merlin.driver.timeline.TemporalEventSource; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; import gov.nasa.jpl.aerie.merlin.protocol.driver.Topic; import gov.nasa.jpl.aerie.merlin.protocol.model.TaskFactory; import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; @@ -14,8 +15,10 @@ import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.function.Consumer; import java.util.function.Supplier; @@ -53,7 +56,7 @@ SimulationResults simulate( final Supplier simulationCanceled, final Consumer simulationExtentConsumer ) { - try (final var engine = new SimulationEngine()) { + try (final var engine = makeSimulationEngine(missionModel)) { /* The top-level simulation timeline. */ var timeline = new TemporalEventSource(); var cells = new LiveCells(timeline, missionModel.getInitialCells()); @@ -141,7 +144,7 @@ SimulationResults simulate( public static void simulateTask(final MissionModel missionModel, final TaskFactory task) { - try (final var engine = new SimulationEngine()) { + try (final var engine = makeSimulationEngine(missionModel)) { /* The top-level simulation timeline. */ var timeline = new TemporalEventSource(); var cells = new LiveCells(timeline, missionModel.getInitialCells()); @@ -186,6 +189,21 @@ void simulateTask(final MissionModel missionModel, final TaskFactory SimulationEngine makeSimulationEngine(MissionModel missionModel) { + if (missionModel.getMerlinPluginVersion().equals(MerlinPluginVersion.V0)) { + final var topicsToTriggerPushSpan = new HashSet>(); + for (final var topic : missionModel.getTopics()) { + if (!topic.name().startsWith("ActivityType.Input.")) continue; + topicsToTriggerPushSpan.add(topic.topic()); + } + return new SimulationEngine( + true, + topicsToTriggerPushSpan); + } else { + return new SimulationEngine(false, Set.of()); + } + } + private static void scheduleActivities( final Map schedule, diff --git a/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/engine/SimulationEngine.java b/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/engine/SimulationEngine.java index 0999200466..7475aa98f6 100644 --- a/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/engine/SimulationEngine.java +++ b/merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/engine/SimulationEngine.java @@ -51,6 +51,9 @@ * A representation of the work remaining to do during a simulation, and its accumulated results. */ public final class SimulationEngine implements AutoCloseable { + /* Controls automatic pushing of spans when certain topics receive events */ + private final boolean createSpanOnEmit; + private final Set> topicsToTriggerPushSpan; /** The set of all jobs waiting for time to pass. */ private final JobSchedule scheduledJobs = new JobSchedule<>(); /** The set of all jobs waiting on a condition. */ @@ -77,6 +80,11 @@ public final class SimulationEngine implements AutoCloseable { /** A thread pool that modeled tasks can use to keep track of their state between steps. */ private final ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor(); + public SimulationEngine(final boolean createSpanOnEmit, final Set> topicsToTriggerPushSpan) { + this.createSpanOnEmit = createSpanOnEmit; + this.topicsToTriggerPushSpan = topicsToTriggerPushSpan; + } + /** Schedule a new task to be performed at the given time. */ public SpanId scheduleTask(final Duration startTime, final TaskFactory state) { if (startTime.isNegative()) throw new IllegalArgumentException("Cannot schedule a task before the start time of the simulation"); @@ -667,6 +675,7 @@ public State get(final CellId token) { @Override public void emit(final EventType event, final Topic topic) { + if (SimulationEngine.this.createSpanOnEmit && SimulationEngine.this.topicsToTriggerPushSpan.contains(topic)) this.pushSpan(); // Append this event to the timeline. this.frame.emit(Event.create(topic, event, this.span)); diff --git a/merlin-driver/src/test/java/gov/nasa/jpl/aerie/merlin/driver/AnchorSimulationTest.java b/merlin-driver/src/test/java/gov/nasa/jpl/aerie/merlin/driver/AnchorSimulationTest.java index fac9709efb..b35384817d 100644 --- a/merlin-driver/src/test/java/gov/nasa/jpl/aerie/merlin/driver/AnchorSimulationTest.java +++ b/merlin-driver/src/test/java/gov/nasa/jpl/aerie/merlin/driver/AnchorSimulationTest.java @@ -1,6 +1,7 @@ package gov.nasa.jpl.aerie.merlin.driver; import gov.nasa.jpl.aerie.merlin.driver.timeline.LiveCells; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; import gov.nasa.jpl.aerie.merlin.protocol.driver.Initializer; import gov.nasa.jpl.aerie.merlin.protocol.driver.Topic; import gov.nasa.jpl.aerie.merlin.protocol.model.DirectiveType; @@ -1221,7 +1222,8 @@ public Object instantiate( return new Object(); } } - ) + ), + MerlinPluginVersion.V1 ); //endregion } diff --git a/merlin-driver/src/test/java/gov/nasa/jpl/aerie/merlin/driver/CellExpiryTest.java b/merlin-driver/src/test/java/gov/nasa/jpl/aerie/merlin/driver/CellExpiryTest.java index 8db50f1676..61246b949d 100644 --- a/merlin-driver/src/test/java/gov/nasa/jpl/aerie/merlin/driver/CellExpiryTest.java +++ b/merlin-driver/src/test/java/gov/nasa/jpl/aerie/merlin/driver/CellExpiryTest.java @@ -1,6 +1,7 @@ package gov.nasa.jpl.aerie.merlin.driver; import gov.nasa.jpl.aerie.merlin.driver.engine.ProfileSegment; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; import gov.nasa.jpl.aerie.merlin.protocol.driver.Querier; import gov.nasa.jpl.aerie.merlin.protocol.driver.Topic; import gov.nasa.jpl.aerie.merlin.protocol.model.CellType; @@ -147,6 +148,6 @@ public String getDynamics(final Querier querier) { initializer.resource(resourceName, resource); - return initializer.build(ref, new DirectiveTypeRegistry<>(Map.of())); + return initializer.build(ref, new DirectiveTypeRegistry<>(Map.of()), MerlinPluginVersion.V1); } } diff --git a/merlin-framework-junit/src/main/java/gov/nasa/jpl/aerie/merlin/framework/junit/MerlinExtension.java b/merlin-framework-junit/src/main/java/gov/nasa/jpl/aerie/merlin/framework/junit/MerlinExtension.java index e91b733cdf..8067d1ba70 100644 --- a/merlin-framework-junit/src/main/java/gov/nasa/jpl/aerie/merlin/framework/junit/MerlinExtension.java +++ b/merlin-framework-junit/src/main/java/gov/nasa/jpl/aerie/merlin/framework/junit/MerlinExtension.java @@ -7,6 +7,7 @@ import gov.nasa.jpl.aerie.merlin.framework.InitializationContext; import gov.nasa.jpl.aerie.merlin.framework.ModelActions; import gov.nasa.jpl.aerie.merlin.framework.Registrar; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; import gov.nasa.jpl.aerie.merlin.protocol.types.Unit; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.extension.BeforeAllCallback; @@ -131,7 +132,7 @@ public T constructModel(final Invocation invocation) throws Throwable { throw ex.wrapped; } - this.missionModel = this.builder.build(Unit.UNIT, new DirectiveTypeRegistry<>(Map.of())); + this.missionModel = this.builder.build(Unit.UNIT, new DirectiveTypeRegistry<>(Map.of()), MerlinPluginVersion.V0); // Clear the builder; it shouldn't be used from here on, and if it is, an error should be raised. this.builder = null; diff --git a/merlin-framework-processor/src/main/java/gov/nasa/jpl/aerie/merlin/processor/generator/MissionModelGenerator.java b/merlin-framework-processor/src/main/java/gov/nasa/jpl/aerie/merlin/processor/generator/MissionModelGenerator.java index 08af87e754..43187ec6c2 100644 --- a/merlin-framework-processor/src/main/java/gov/nasa/jpl/aerie/merlin/processor/generator/MissionModelGenerator.java +++ b/merlin-framework-processor/src/main/java/gov/nasa/jpl/aerie/merlin/processor/generator/MissionModelGenerator.java @@ -23,6 +23,7 @@ import gov.nasa.jpl.aerie.merlin.processor.metamodel.EffectModelRecord; import gov.nasa.jpl.aerie.merlin.processor.metamodel.InputTypeRecord; import gov.nasa.jpl.aerie.merlin.processor.metamodel.MissionModelRecord; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; import gov.nasa.jpl.aerie.merlin.protocol.driver.Initializer; import gov.nasa.jpl.aerie.merlin.protocol.driver.Topic; import gov.nasa.jpl.aerie.merlin.protocol.model.InputType; @@ -82,6 +83,16 @@ public JavaFile generateMerlinPlugin(final MissionModelRecord missionModel) { "return new $T()", missionModel.getModelTypeName()) .build()) + .addMethod( + MethodSpec + .methodBuilder("getMerlinPluginVersion") + .addAnnotation(Override.class) + .addModifiers(Modifier.PUBLIC) + .returns(MerlinPluginVersion.class) + .addStatement( + "return $T.V1", + MerlinPluginVersion.class) + .build()) .build(); return JavaFile diff --git a/merlin-sdk/src/main/java/gov/nasa/jpl/aerie/merlin/protocol/MerlinPluginVersion.java b/merlin-sdk/src/main/java/gov/nasa/jpl/aerie/merlin/protocol/MerlinPluginVersion.java new file mode 100644 index 0000000000..24fe9db607 --- /dev/null +++ b/merlin-sdk/src/main/java/gov/nasa/jpl/aerie/merlin/protocol/MerlinPluginVersion.java @@ -0,0 +1,10 @@ +package gov.nasa.jpl.aerie.merlin.protocol; + +public enum MerlinPluginVersion { + V0, + + /** + * Added pushSpan and popSpan + */ + V1 +} diff --git a/merlin-sdk/src/main/java/gov/nasa/jpl/aerie/merlin/protocol/model/MerlinPlugin.java b/merlin-sdk/src/main/java/gov/nasa/jpl/aerie/merlin/protocol/model/MerlinPlugin.java index 1d1613bebc..c27de58711 100644 --- a/merlin-sdk/src/main/java/gov/nasa/jpl/aerie/merlin/protocol/model/MerlinPlugin.java +++ b/merlin-sdk/src/main/java/gov/nasa/jpl/aerie/merlin/protocol/model/MerlinPlugin.java @@ -1,5 +1,7 @@ package gov.nasa.jpl.aerie.merlin.protocol.model; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; + /** * A reflection-friendly service for interacting with a simulation model. * @@ -21,4 +23,14 @@ public interface MerlinPlugin { * The model type associated with this plugin. */ ModelType getModelType(); + + /** + * Gets the version of the merlin plugin against which this plugin was compiled + * + * @return + * The version of the merlin plugin against which this plugin was compiled + */ + default MerlinPluginVersion getMerlinPluginVersion() { + return MerlinPluginVersion.V0; + } } diff --git a/merlin-sdk/src/main/java/gov/nasa/jpl/aerie/merlin/protocol/model/ModelType.java b/merlin-sdk/src/main/java/gov/nasa/jpl/aerie/merlin/protocol/model/ModelType.java index c3e8e7735a..6cffc44dc3 100644 --- a/merlin-sdk/src/main/java/gov/nasa/jpl/aerie/merlin/protocol/model/ModelType.java +++ b/merlin-sdk/src/main/java/gov/nasa/jpl/aerie/merlin/protocol/model/ModelType.java @@ -1,5 +1,6 @@ package gov.nasa.jpl.aerie.merlin.protocol.model; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; import gov.nasa.jpl.aerie.merlin.protocol.driver.Initializer; import java.time.Instant; diff --git a/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/simulation/ResumableSimulationDriver.java b/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/simulation/ResumableSimulationDriver.java index a214abb44a..4785d74992 100644 --- a/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/simulation/ResumableSimulationDriver.java +++ b/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/simulation/ResumableSimulationDriver.java @@ -33,6 +33,8 @@ import java.util.Set; import java.util.function.Supplier; +import static gov.nasa.jpl.aerie.merlin.driver.SimulationDriver.makeSimulationEngine; + public class ResumableSimulationDriver implements AutoCloseable { private final Supplier canceledListener; @@ -42,7 +44,7 @@ public class ResumableSimulationDriver implements AutoCloseable { /* The current real time. All the tasks before and at this time have been performed. Simulation has not started so it is set to MIN_VALUE. */ private Duration curTime = Duration.MIN_VALUE; - private SimulationEngine engine = new SimulationEngine(); + private SimulationEngine engine; private LiveCells cells; private TemporalEventSource timeline = new TemporalEventSource(); private final MissionModel missionModel; @@ -74,6 +76,7 @@ public ResumableSimulationDriver( Duration planDuration, Supplier canceledListener ){ + this.engine = makeSimulationEngine(missionModel); this.missionModel = missionModel; plannedDirectiveToTask = new HashMap<>(); toCheckForDependencyScheduling = new HashMap<>(); @@ -105,7 +108,7 @@ private void printTimeSpent(){ lastSimResultsEnd = Duration.ZERO; long before = System.nanoTime(); if (this.engine != null) this.engine.close(); - this.engine = new SimulationEngine(); + this.engine = makeSimulationEngine(missionModel); batch = null; /* The top-level simulation timeline. */ this.timeline = new TemporalEventSource(); diff --git a/scheduler-driver/src/test/java/gov/nasa/jpl/aerie/scheduler/SimulationUtility.java b/scheduler-driver/src/test/java/gov/nasa/jpl/aerie/scheduler/SimulationUtility.java index 468fb7bcde..871135039c 100644 --- a/scheduler-driver/src/test/java/gov/nasa/jpl/aerie/scheduler/SimulationUtility.java +++ b/scheduler-driver/src/test/java/gov/nasa/jpl/aerie/scheduler/SimulationUtility.java @@ -13,13 +13,15 @@ import java.nio.file.Path; import java.time.Instant; +import static gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion.V1; + public final class SimulationUtility { private static MissionModel makeMissionModel(final MissionModelBuilder builder, final Configuration config) { final var factory = new gov.nasa.jpl.aerie.banananation.generated.GeneratedModelType(); final var registry = DirectiveTypeRegistry.extract(factory); final var model = factory.instantiate(Instant.EPOCH, config, builder); - return builder.build(model, registry); + return builder.build(model, registry, V1); } public static MissionModel @@ -29,7 +31,7 @@ private static MissionModel makeMissionModel(final MissionModelBuilder builde final var registry = DirectiveTypeRegistry.extract(factory); final var builder = new MissionModelBuilder(); final var model = factory.instantiate(Instant.EPOCH, config, builder); - return builder.build(model, registry); + return builder.build(model, registry, V1); } public static Problem buildProblemFromFoo(final PlanningHorizon planningHorizon){ diff --git a/scheduler-driver/src/test/java/gov/nasa/jpl/aerie/scheduler/simulation/AnchorSchedulerTest.java b/scheduler-driver/src/test/java/gov/nasa/jpl/aerie/scheduler/simulation/AnchorSchedulerTest.java index 24f668ef9f..4fcb892452 100644 --- a/scheduler-driver/src/test/java/gov/nasa/jpl/aerie/scheduler/simulation/AnchorSchedulerTest.java +++ b/scheduler-driver/src/test/java/gov/nasa/jpl/aerie/scheduler/simulation/AnchorSchedulerTest.java @@ -9,6 +9,7 @@ import gov.nasa.jpl.aerie.merlin.driver.SimulatedActivityId; import gov.nasa.jpl.aerie.merlin.driver.SimulationResults; import gov.nasa.jpl.aerie.merlin.driver.timeline.LiveCells; +import gov.nasa.jpl.aerie.merlin.protocol.MerlinPluginVersion; import gov.nasa.jpl.aerie.merlin.protocol.driver.Initializer; import gov.nasa.jpl.aerie.merlin.protocol.driver.Topic; import gov.nasa.jpl.aerie.merlin.protocol.model.DirectiveType; @@ -804,7 +805,8 @@ public Object instantiate( return new Object(); } } - ) + ), + MerlinPluginVersion.V1 ); //endregion }