-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP on feat/scheduler-activity-deletion
- Loading branch information
1 parent
327fdec
commit 1a3d737
Showing
38 changed files
with
536 additions
and
109 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
deployment/hasura/migrations/Aerie/12_activity_goal_invocation_id/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
alter table merlin.activity_directive | ||
drop constraint activity_directive_source_invocation_id_exists, | ||
|
||
drop column source_scheduling_goal_invocation_id; | ||
|
||
call migrations.mark_migration_rolled_back('12'); |
13 changes: 13 additions & 0 deletions
13
deployment/hasura/migrations/Aerie/12_activity_goal_invocation_id/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
alter table merlin.activity_directive | ||
add column source_scheduling_goal_invocation_id integer default null, | ||
|
||
add constraint activity_directive_source_invocation_id_exists | ||
foreign key (source_scheduling_goal_invocation_id) | ||
references scheduler.scheduling_specification_goals | ||
on update cascade | ||
on delete set null; | ||
|
||
comment on column merlin.activity_directive.source_scheduling_goal_invocation_id is e'' | ||
'The scheduling goal invocation that this activity_directive was generated by.'; | ||
|
||
call migrations.mark_migration_applied('12'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ava/gov/nasa/jpl/aerie/e2e/procedural/scheduling/procedures/ActivityAutoDeletionGoal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package gov.nasa.jpl.aerie.e2e.procedural.scheduling.procedures; | ||
|
||
import gov.nasa.ammos.aerie.procedural.scheduling.ActivityAutoDelete; | ||
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.DeletedAnchorStrategy; | ||
import gov.nasa.ammos.aerie.procedural.scheduling.plan.EditablePlan; | ||
import gov.nasa.ammos.aerie.procedural.timeline.payloads.activities.DirectiveStart; | ||
import gov.nasa.ammos.aerie.procedural.timeline.plan.Plan; | ||
import gov.nasa.ammos.aerie.procedural.timeline.plan.SimulationResults; | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Creates one activity, and deletes it automatically on subsequent runs. | ||
*/ | ||
@SchedulingProcedure | ||
public record ActivityAutoDeletionGoal(boolean deleteAtBeginning) implements Goal { | ||
@NotNull | ||
@Override | ||
public ActivityAutoDelete shouldDeletePastCreations( | ||
@NotNull final Plan plan, | ||
@Nullable final SimulationResults simResults) | ||
{ | ||
if (deleteAtBeginning) return new ActivityAutoDelete.AtBeginning(DeletedAnchorStrategy.Error, false); | ||
else return new ActivityAutoDelete.JustBefore(DeletedAnchorStrategy.Error); | ||
} | ||
|
||
@Override | ||
public void run(@NotNull final EditablePlan plan) { | ||
plan.create( | ||
"BiteBanana", | ||
new DirectiveStart.Absolute(Duration.MINUTE), | ||
Map.of("biteSize", SerializedValue.of(1)) | ||
); | ||
|
||
plan.commit(); | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/procedural/scheduling/AutoDeletionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package gov.nasa.jpl.aerie.e2e.procedural.scheduling; | ||
|
||
import gov.nasa.jpl.aerie.e2e.types.GoalInvocationId; | ||
import gov.nasa.jpl.aerie.e2e.utils.GatewayRequests; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.json.Json; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class AutoDeletionTests extends ProceduralSchedulingSetup { | ||
private GoalInvocationId edslId; | ||
private GoalInvocationId procedureId; | ||
|
||
@BeforeEach | ||
void localBeforeEach() throws IOException { | ||
try (final var gateway = new GatewayRequests(playwright)) { | ||
final String coexGoalDefinition = | ||
""" | ||
export default function myGoal() { | ||
return Goal.CoexistenceGoal({ | ||
forEach: ActivityExpression.ofType(ActivityTypes.BiteBanana), | ||
activityTemplate: ActivityTemplates.GrowBanana({quantity: 1, growingDuration: Temporal.Duration.from({minutes:1})}), | ||
startsAt:TimingConstraint.singleton(WindowProperty.START).plus(Temporal.Duration.from({ minutes : 5})) | ||
}) | ||
}"""; | ||
|
||
edslId = hasura.createSchedulingSpecGoal( | ||
"Coexistence Scheduling Test Goal", | ||
coexGoalDefinition, | ||
"", | ||
specId, | ||
0, | ||
false | ||
); | ||
|
||
int procedureJarId = gateway.uploadJarFile("build/libs/ActivityAutoDeletionGoal.jar"); | ||
// Add Scheduling Procedure | ||
procedureId = hasura.createSchedulingSpecProcedure( | ||
"Test Scheduling Procedure", | ||
procedureJarId, | ||
specId, | ||
1, | ||
false | ||
); | ||
} | ||
} | ||
|
||
@AfterEach | ||
void localAfterEach() throws IOException { | ||
hasura.deleteSchedulingGoal(procedureId.goalId()); | ||
hasura.deleteSchedulingGoal(edslId.goalId()); | ||
} | ||
|
||
@Test | ||
void createsOneActivityIfRunOnce() throws IOException { | ||
final var args = Json | ||
.createObjectBuilder() | ||
.add("deleteAtBeginning", false) | ||
.build(); | ||
|
||
hasura.updateSchedulingSpecGoalArguments(procedureId.invocationId(), args); | ||
|
||
hasura.awaitScheduling(specId); | ||
|
||
final var plan = hasura.getPlan(planId); | ||
final var activities = plan.activityDirectives(); | ||
|
||
assertEquals(1, activities.size()); | ||
|
||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "BiteBanana") | ||
)); | ||
} | ||
|
||
@Test | ||
void createsTwoActivitiesSteadyState_JustBefore() throws IOException { | ||
final var args = Json | ||
.createObjectBuilder() | ||
.add("deleteAtBeginning", false) | ||
.build(); | ||
|
||
hasura.updateSchedulingSpecGoalArguments(procedureId.invocationId(), args); | ||
|
||
hasura.awaitScheduling(specId); | ||
|
||
for (int i = 0; i < 3; i++) { | ||
hasura.awaitScheduling(specId); | ||
|
||
final var plan = hasura.getPlan(planId); | ||
final var activities = plan.activityDirectives(); | ||
|
||
assertEquals(2, activities.size()); | ||
|
||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "BiteBanana") | ||
)); | ||
|
||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "GrowBanana") | ||
)); | ||
} | ||
} | ||
|
||
@Test | ||
void createsOneActivitySteadyState_AtBeginning() throws IOException { | ||
final var args = Json | ||
.createObjectBuilder() | ||
.add("deleteAtBeginning", true) | ||
.build(); | ||
|
||
hasura.updateSchedulingSpecGoalArguments(procedureId.invocationId(), args); | ||
|
||
hasura.awaitScheduling(specId); | ||
|
||
for (int i = 0; i < 3; i++) { | ||
hasura.awaitScheduling(specId); | ||
|
||
final var plan = hasura.getPlan(planId); | ||
final var activities = plan.activityDirectives(); | ||
|
||
assertEquals(1, activities.size()); | ||
|
||
assertTrue(activities.stream().anyMatch( | ||
it -> Objects.equals(it.type(), "BiteBanana") | ||
)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...heduling/src/main/kotlin/gov/nasa/ammos/aerie/procedural/scheduling/ActivityAutoDelete.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package gov.nasa.ammos.aerie.procedural.scheduling | ||
|
||
import gov.nasa.ammos.aerie.procedural.scheduling.plan.DeletedAnchorStrategy | ||
|
||
sealed interface ActivityAutoDelete { | ||
data class AtBeginning(val anchorStrategy: DeletedAnchorStrategy, val simulateAfter: Boolean): ActivityAutoDelete | ||
data class JustBefore(val anchorStrategy: DeletedAnchorStrategy): ActivityAutoDelete | ||
data object No: ActivityAutoDelete | ||
} |
14 changes: 14 additions & 0 deletions
14
procedural/scheduling/src/main/kotlin/gov/nasa/ammos/aerie/procedural/scheduling/Goal.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.