From a8443400ffc11f5812ce2ff2dbb227f98e154acf Mon Sep 17 00:00:00 2001 From: JoelCourtney Date: Wed, 25 Sep 2024 09:46:06 -0700 Subject: [PATCH 1/2] Save activity names in db --- .../scheduler/model/SchedulingActivity.java | 34 ++++++++++++------- .../scheduler/solver/PrioritySolver.java | 3 +- .../scheduler/plan/InMemoryEditablePlan.kt | 3 +- .../GraphQLMerlinDatabaseService.java | 2 ++ 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/model/SchedulingActivity.java b/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/model/SchedulingActivity.java index aee1d433e5..b756022cac 100644 --- a/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/model/SchedulingActivity.java +++ b/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/model/SchedulingActivity.java @@ -41,7 +41,8 @@ public record SchedulingActivity( ActivityDirectiveId topParent, ActivityDirectiveId anchorId, boolean anchoredToStart, - boolean isNew + boolean isNew, + String name ) { public static SchedulingActivity of( @@ -62,7 +63,8 @@ public static SchedulingActivity of( null, anchorId, anchoredToStart, - isNew + isNew, + null ); } @@ -86,12 +88,13 @@ public static SchedulingActivity of( topParent, anchorId, anchoredToStart, - isNew + isNew, + null ); } public SchedulingActivity withNewDuration(Duration duration){ - return SchedulingActivity.of( + return new SchedulingActivity( this.id, this.type, this.startOffset, @@ -100,12 +103,13 @@ public SchedulingActivity withNewDuration(Duration duration){ this.topParent, this.anchorId, this.anchoredToStart, - this.isNew() + this.isNew(), + this.name ); } public SchedulingActivity withNewAnchor(ActivityDirectiveId anchorId, boolean anchoredToStart, Duration startOffset) { - return SchedulingActivity.of( + return new SchedulingActivity( this.id, this.type, startOffset, @@ -114,12 +118,13 @@ public SchedulingActivity withNewAnchor(ActivityDirectiveId anchorId, boolean an this.topParent, anchorId, anchoredToStart, - this.isNew + this.isNew, + this.name ); } public SchedulingActivity withNewDirectiveId(ActivityDirectiveId id) { - return SchedulingActivity.of( + return new SchedulingActivity( id, this.type, startOffset, @@ -128,12 +133,13 @@ public SchedulingActivity withNewDirectiveId(ActivityDirectiveId id) { this.topParent, this.anchorId, this.anchoredToStart, - this.isNew + this.isNew, + this.name ); } public SchedulingActivity withNewTopParent(ActivityDirectiveId topParent) { - return SchedulingActivity.of( + return new SchedulingActivity( this.id, this.type, startOffset, @@ -142,12 +148,13 @@ public SchedulingActivity withNewTopParent(ActivityDirectiveId topParent) { topParent, this.anchorId, this.anchoredToStart, - this.isNew + this.isNew, + this.name ); } public static SchedulingActivity fromExistingActivityDirective(ActivityDirectiveId id, ActivityDirective activity, ActivityType type, Duration duration){ - return SchedulingActivity.of( + return new SchedulingActivity( id, type, activity.startOffset(), @@ -156,7 +163,8 @@ public static SchedulingActivity fromExistingActivityDirective(ActivityDirective null, activity.anchorId(), activity.anchoredToStart(), - false + false, + null ); } diff --git a/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/solver/PrioritySolver.java b/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/solver/PrioritySolver.java index 3d5fdec293..cc9a5f14c9 100644 --- a/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/solver/PrioritySolver.java +++ b/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/solver/PrioritySolver.java @@ -1230,7 +1230,8 @@ public Duration valueAt(Duration start, final EquationSolvingAlgorithms.History< null, null, true, - true + true, + null ); Duration computedDuration = null; try { diff --git a/scheduler-driver/src/main/kotlin/gov/nasa/jpl/aerie/scheduler/plan/InMemoryEditablePlan.kt b/scheduler-driver/src/main/kotlin/gov/nasa/jpl/aerie/scheduler/plan/InMemoryEditablePlan.kt index 2652c03abf..275a2c39e1 100644 --- a/scheduler-driver/src/main/kotlin/gov/nasa/jpl/aerie/scheduler/plan/InMemoryEditablePlan.kt +++ b/scheduler-driver/src/main/kotlin/gov/nasa/jpl/aerie/scheduler/plan/InMemoryEditablePlan.kt @@ -122,7 +122,8 @@ data class InMemoryEditablePlan( is DirectiveStart.Absolute -> true is DirectiveStart.Anchor -> s.anchorPoint == DirectiveStart.Anchor.AnchorPoint.Start }, - isNew + isNew, + name ) } } diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GraphQLMerlinDatabaseService.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GraphQLMerlinDatabaseService.java index e9795dedc8..11ee8ef064 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GraphQLMerlinDatabaseService.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GraphQLMerlinDatabaseService.java @@ -582,6 +582,8 @@ mutation createAllPlanActivityDirectives($activities: [activity_directive_insert .add("start_offset", act.startOffset().toString()) .add("anchored_to_start", act.anchoredToStart()); + if (act.name() != null) insertionObject = insertionObject.add("name", act.name()); + //add duration to parameters if controllable final var insertionObjectArguments = Json.createObjectBuilder(); if(act.getType().getDurationType() instanceof DurationType.Controllable durationType){ From 4328d4b0520d1f85d709eaec8f47ab36fe92bfab Mon Sep 17 00:00:00 2001 From: JoelCourtney Date: Wed, 25 Sep 2024 09:46:14 -0700 Subject: [PATCH 2/2] Test activity names saved in db --- .../gov/nasa/jpl/aerie/e2e/SchedulingTests.java | 17 +++++++++++++++++ .../java/gov/nasa/jpl/aerie/e2e/types/Plan.java | 6 ++++-- .../java/gov/nasa/jpl/aerie/e2e/utils/GQL.java | 1 + .../procedures/SampleProcedure.java | 11 ++++++++--- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/SchedulingTests.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/SchedulingTests.java index 7251b504b4..681a68e067 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/SchedulingTests.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/SchedulingTests.java @@ -1156,5 +1156,22 @@ void executeEDSLAndProcedure() throws IOException { assertEquals(52, activities.size()); } + + /** + * Run a spec with one procedure and make sure the activity names are saved to the database + */ + @Test + void saveActivityName() throws IOException { + final var args = Json.createObjectBuilder().add("quantity", 2).build(); + hasura.updateSchedulingSpecGoalArguments(procedureId.invocationId(), args); + + final var resp = hasura.awaitScheduling(specId); + + final var plan = hasura.getPlan(planId); + final var activities = plan.activityDirectives(); + + assertEquals(2, activities.size()); + assertEquals("It's a bite banana activity", activities.getFirst().name()); + } } } diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/Plan.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/Plan.java index 02f19dbb7e..4fb0d3ee80 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/Plan.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/Plan.java @@ -12,14 +12,16 @@ public record Plan( int revision, List activityDirectives ) { - public record ActivityDirective(int id, int planId, String type, String startOffset, JsonObject arguments) { + public record ActivityDirective(int id, int planId, String type, String startOffset, JsonObject arguments, String name) { public static ActivityDirective fromJSON(JsonObject json){ return new ActivityDirective( json.getInt("id"), json.getInt("plan_id"), json.getString("type"), json.getString("startOffset"), - json.getJsonObject("arguments")); + json.getJsonObject("arguments"), + json.getString("name") + ); } } diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GQL.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GQL.java index 0aea2e3564..3de72613b4 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GQL.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GQL.java @@ -327,6 +327,7 @@ query GetPlan($id: Int!) { plan_id startOffset: start_offset type + name } constraint_specification { constraint_id diff --git a/procedural/examples/foo-procedures/src/main/java/gov/nasa/ammos/aerie/procedural/examples/fooprocedures/procedures/SampleProcedure.java b/procedural/examples/foo-procedures/src/main/java/gov/nasa/ammos/aerie/procedural/examples/fooprocedures/procedures/SampleProcedure.java index 2e75c80566..9a2f1cd290 100644 --- a/procedural/examples/foo-procedures/src/main/java/gov/nasa/ammos/aerie/procedural/examples/fooprocedures/procedures/SampleProcedure.java +++ b/procedural/examples/foo-procedures/src/main/java/gov/nasa/ammos/aerie/procedural/examples/fooprocedures/procedures/SampleProcedure.java @@ -3,6 +3,8 @@ import gov.nasa.ammos.aerie.procedural.scheduling.plan.EditablePlan; import gov.nasa.ammos.aerie.procedural.scheduling.Goal; import gov.nasa.ammos.aerie.procedural.scheduling.annotations.SchedulingProcedure; +import gov.nasa.ammos.aerie.procedural.scheduling.plan.NewDirective; +import gov.nasa.ammos.aerie.procedural.timeline.payloads.activities.AnyDirective; import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; import gov.nasa.ammos.aerie.procedural.timeline.payloads.activities.DirectiveStart; import org.jetbrains.annotations.NotNull; @@ -19,9 +21,12 @@ public void run(@NotNull final EditablePlan plan) { var currentTime = firstTime; for (var i = 0; i < quantity; i++) { plan.create( - "BiteBanana", - new DirectiveStart.Absolute(currentTime), - Map.of() + new NewDirective( + new AnyDirective(Map.of()), + "It's a bite banana activity", + "BiteBanana", + new DirectiveStart.Absolute(currentTime) + ) ); currentTime = currentTime.plus(step); }