Skip to content

Commit

Permalink
Use MissionModelId class instead of String
Browse files Browse the repository at this point in the history
Change done now as we expect users of the Orchestration Library to be referencing our Plan class

Co-authored-by: Ryan Goetz <[email protected]>
  • Loading branch information
Mythicaeda and goetzrrGit committed Aug 15, 2024
1 parent da20c73 commit e038b8b
Show file tree
Hide file tree
Showing 25 changed files with 151 additions and 147 deletions.
14 changes: 7 additions & 7 deletions deployment/hasura/metadata/actions.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ type Mutation {
}

type Query {
getModelEffectiveArguments(missionModelId: ID!, modelArguments: ModelArguments!): EffectiveArgumentsResponse
getModelEffectiveArguments(missionModelId: Int!, modelArguments: ModelArguments!): EffectiveArgumentsResponse
}

type Query {
getActivityEffectiveArguments(
missionModelId: ID!
missionModelId: Int!
activityTypeName: String!
activityArguments: ActivityArguments!
): EffectiveArgumentsResponse
Expand All @@ -67,7 +67,7 @@ type Query {

type Query {
getActivityEffectiveArgumentsBulk(
missionModelId: ID!
missionModelId: Int!
activities: [EffectiveArgumentsInput!]!
): [EffectiveArgumentsResponse!]!
}
Expand All @@ -81,7 +81,7 @@ type Query {
}

type Query {
resourceTypes(missionModelId: ID!): [ResourceType!]!
resourceTypes(missionModelId: Int!): [ResourceType!]!
}

type Query {
Expand All @@ -93,7 +93,7 @@ type Query {
}

type Query {
constraintsDslTypescript(missionModelId: ID!, planId: Int): DslTypescriptResponse
constraintsDslTypescript(missionModelId: Int!, planId: Int): DslTypescriptResponse
}

type Query {
Expand All @@ -111,13 +111,13 @@ type Query {
type Query {
validateActivityArguments(
activityTypeName: String!
missionModelId: ID!
missionModelId: Int!
activityArguments: ActivityArguments!
): ValidationResponse
}

type Query {
validateModelArguments(missionModelId: ID!, modelArguments: ModelArguments!): ValidationResponse
validateModelArguments(missionModelId: Int!, modelArguments: ModelArguments!): ValidationResponse
}

type Query {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void noSuchMissionModelError() throws IOException, InterruptedException {
final var activityValidations = hasura.getActivityValidations(planId);
final ActivityValidation activityValidation = activityValidations.get((long) activityId);
assertEquals(
new ActivityValidation.NoSuchMissionModelFailure("no such mission model", "0"),
new ActivityValidation.NoSuchMissionModelFailure("no such mission model", 0),
activityValidation
);
}
Expand Down
22 changes: 11 additions & 11 deletions e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/BindingsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ void invalidMissionModelId() {
final String data = Json.createObjectBuilder()
.add("action", Json.createObjectBuilder().add("name", "validateActivityArguments"))
.add("input", Json.createObjectBuilder()
.add("missionModelId", String.valueOf(-1))
.add("missionModelId", -1)
.add("activityTypeName", "BiteBanana")
.add("activityArguments", JsonValue.EMPTY_JSON_OBJECT))
.add("request_query", "")
Expand All @@ -577,7 +577,7 @@ void valid() {
final String data = Json.createObjectBuilder()
.add("action", Json.createObjectBuilder().add("name", "validateActivityArguments"))
.add("input", Json.createObjectBuilder()
.add("missionModelId", String.valueOf(modelId))
.add("missionModelId", modelId)
.add("activityTypeName", "BiteBanana")
.add("activityArguments", JsonValue.EMPTY_JSON_OBJECT))
.add("request_query", "")
Expand All @@ -599,7 +599,7 @@ void invalidMissionModelId() {
final String data = Json.createObjectBuilder()
.add("action", Json.createObjectBuilder().add("name", "validateModelArguments"))
.add("input", Json.createObjectBuilder()
.add("missionModelId", String.valueOf(-1))
.add("missionModelId", -1)
.add("modelArguments", JsonValue.EMPTY_JSON_OBJECT))
.add("request_query", "")
.add("session_variables", admin.getSession())
Expand All @@ -616,7 +616,7 @@ void valid() {
final String data = Json.createObjectBuilder()
.add("action", Json.createObjectBuilder().add("name", "validateModelArguments"))
.add("input", Json.createObjectBuilder()
.add("missionModelId", String.valueOf(modelId))
.add("missionModelId", modelId)
.add("modelArguments", JsonValue.EMPTY_JSON_OBJECT))
.add("request_query", "")
.add("session_variables", admin.getSession())
Expand Down Expand Up @@ -671,7 +671,7 @@ void invalidMissionModelId() {
final String data = Json.createObjectBuilder()
.add("action", Json.createObjectBuilder().add("name", "getModelEffectiveArguments"))
.add("input", Json.createObjectBuilder()
.add("missionModelId", "-1")
.add("missionModelId", -1)
.add("modelArguments", JsonValue.EMPTY_JSON_OBJECT))
.add("request_query", "")
.add("session_variables", admin.getSession())
Expand All @@ -688,7 +688,7 @@ void valid() {
final String data = Json.createObjectBuilder()
.add("action", Json.createObjectBuilder().add("name", "getModelEffectiveArguments"))
.add("input", Json.createObjectBuilder()
.add("missionModelId", String.valueOf(modelId))
.add("missionModelId", modelId)
.add("modelArguments", JsonValue.EMPTY_JSON_OBJECT))
.add("request_query", "")
.add("session_variables", admin.getSession())
Expand Down Expand Up @@ -723,7 +723,7 @@ void invalidMissionModelId() {
final String data = Json.createObjectBuilder()
.add("action", Json.createObjectBuilder().add("name", "getActivityEffectiveArgumentsBulk"))
.add("input", Json.createObjectBuilder()
.add("missionModelId", "-1")
.add("missionModelId", -1)
.add("activities", JsonValue.EMPTY_JSON_ARRAY))
.add("request_query", "")
.add("session_variables", admin.getSession())
Expand All @@ -748,7 +748,7 @@ void valid() {
final String data = Json.createObjectBuilder()
.add("action", Json.createObjectBuilder().add("name", "getActivityEffectiveArgumentsBulk"))
.add("input", Json.createObjectBuilder()
.add("missionModelId", String.valueOf(modelId))
.add("missionModelId", modelId)
.add("activities", activitiesBuilder))
.add("request_query", "")
.add("session_variables", admin.getSession())
Expand Down Expand Up @@ -912,7 +912,7 @@ void invalidMissionModelId() {
final String data = Json.createObjectBuilder()
.add("action", Json.createObjectBuilder().add("name", "constraintsDslTypescript"))
.add("input", Json.createObjectBuilder()
.add("missionModelId", "-1")
.add("missionModelId", -1)
.add("planId", JsonValue.NULL))
.add("request_query", "")
.add("session_variables", admin.getSession())
Expand Down Expand Up @@ -942,7 +942,7 @@ void invalidPlanId() {
final String data = Json.createObjectBuilder()
.add("action", Json.createObjectBuilder().add("name", "constraintsDslTypescript"))
.add("input", Json.createObjectBuilder()
.add("missionModelId", String.valueOf(modelId))
.add("missionModelId", modelId)
.add("planId", -1))
.add("request_query", "")
.add("session_variables", admin.getSession())
Expand All @@ -963,7 +963,7 @@ void valid() {
final String data = Json.createObjectBuilder()
.add("action", Json.createObjectBuilder().add("name", "constraintsDslTypescript"))
.add("input", Json.createObjectBuilder()
.add("missionModelId", String.valueOf(modelId))
.add("missionModelId", modelId)
.add("planId", JsonValue.NULL))
.add("request_query", "")
.add("session_variables", admin.getSession())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ record Success() implements ActivityValidation {}
record InstantiationFailure(List<String> extraneousArguments, List<String> missingArguments, List<?> unconstructableArguments) implements ActivityValidation {}
record ValidationFailure(List<ValidationNotice> notices) implements ActivityValidation {}
record NoSuchActivityTypeFailure(String message, String activityType) implements ActivityValidation {}
record NoSuchMissionModelFailure(String message, String modelId) implements ActivityValidation {}
record NoSuchMissionModelFailure(String message, long modelId) implements ActivityValidation {}

record ValidationNotice(List<String> subjects, String message) { }
record UnconstructableArgument(String name, String failure) { }
Expand Down Expand Up @@ -47,7 +47,7 @@ static ActivityValidation fromJSON(JsonObject obj) {
case "NO_SUCH_ACTIVITY_TYPE" -> new NoSuchActivityTypeFailure(errors.getJsonObject("noSuchActivityError").getString("message"), errors.getJsonObject("noSuchActivityError").getString("activity_type"));
case "NO_SUCH_MISSION_MODEL" -> new NoSuchMissionModelFailure(
errors.getJsonObject("noSuchMissionModelError").getString("message"),
errors.getJsonObject("noSuchMissionModelError").getString("mission_model_id")
errors.getJsonObject("noSuchMissionModelError").getJsonNumber("mission_model_id").longValue()
);
default -> throw new RuntimeException("Unhandled error type: " + type);
};
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ query getConstraintRuns($simulationDatasetId: Int!) {
}
}"""),
GET_EFFECTIVE_ACTIVITY_ARGUMENTS_BULK("""
query GetEffectiveActivityArgumentsBulk($modelId: ID!, $activities: [EffectiveArgumentsInput!]!) {
query GetEffectiveActivityArgumentsBulk($modelId: Int!, $activities: [EffectiveArgumentsInput!]!) {
getActivityEffectiveArgumentsBulk(
missionModelId: $modelId,
activities: $activities
Expand All @@ -239,7 +239,7 @@ query GetActivityValidations($planId: Int!) {
}
}"""),
GET_EFFECTIVE_MODEL_ARGUMENTS("""
query GetEffectiveModelArguments($modelId: ID!, $modelArgs: ModelArguments!) {
query GetEffectiveModelArguments($modelId: Int!, $modelArgs: ModelArguments!) {
getModelEffectiveArguments(missionModelId: $modelId, modelArguments: $modelArgs) {
arguments
errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import static gov.nasa.jpl.aerie.json.BasicParsers.boolP;
import static gov.nasa.jpl.aerie.json.BasicParsers.listP;
import static gov.nasa.jpl.aerie.json.BasicParsers.longP;
import static gov.nasa.jpl.aerie.json.BasicParsers.mapP;
import static gov.nasa.jpl.aerie.json.BasicParsers.nullableP;
import static gov.nasa.jpl.aerie.json.BasicParsers.productP;
Expand All @@ -18,6 +17,7 @@
import static gov.nasa.jpl.aerie.json.Uncurry.untuple;
import static gov.nasa.jpl.aerie.merlin.driver.json.SerializedValueJsonParser.serializedValueP;
import static gov.nasa.jpl.aerie.merlin.server.http.MerlinParsers.datasetIdP;
import static gov.nasa.jpl.aerie.merlin.server.http.MerlinParsers.missionModelIdP;
import static gov.nasa.jpl.aerie.merlin.server.http.MerlinParsers.planIdP;
import static gov.nasa.jpl.aerie.merlin.server.http.MerlinParsers.simulationDatasetIdP;
import static gov.nasa.jpl.aerie.merlin.server.http.MerlinParsers.timestampP;
Expand Down Expand Up @@ -47,7 +47,7 @@ private static <I extends HasuraAction.Input> JsonParser<HasuraAction<I>> hasura

public static final JsonParser<HasuraAction<HasuraAction.MissionModelInput>> hasuraMissionModelActionP
= hasuraActionF(productP
.field("missionModelId", stringP)
.field("missionModelId", missionModelIdP)
.map(HasuraAction.MissionModelInput::new, HasuraAction.MissionModelInput::missionModelId));

public static final JsonParser<HasuraAction<HasuraAction.PlanInput>> hasuraPlanActionP
Expand Down Expand Up @@ -82,7 +82,7 @@ private static <I extends HasuraAction.Input> JsonParser<HasuraAction<I>> hasura
public static final JsonParser<HasuraAction<HasuraAction.ConstraintsInput>> hasuraConstraintsCodeAction
= hasuraActionF(
productP
.field("missionModelId", stringP)
.field("missionModelId", missionModelIdP)
.optionalField("planId", nullableP(planIdP))
.map(
untuple((modelId, planId) -> new HasuraAction.ConstraintsInput(modelId, planId.flatMap($ -> $))),
Expand All @@ -95,18 +95,18 @@ private static <I extends HasuraAction.Input> JsonParser<HasuraAction<I>> hasura
.field("event", productP
.field("data", productP
.field("new", productP
.field("id", longP)
.field("id", missionModelIdP)
.rest())
.rest())
.rest())
.rest()
.map(
untuple(missionModelId -> new HasuraMissionModelEvent(String.valueOf(missionModelId))),
$ -> tuple(Long.parseLong($.missionModelId())));
untuple(HasuraMissionModelEvent::new),
$ -> tuple($.missionModelId()));

private static final JsonParser<HasuraAction.MissionModelArgumentsInput> hasuraMissionModelArgumentsInputP
= productP
.field("missionModelId", stringP)
.field("missionModelId", missionModelIdP)
.field("modelArguments", mapP(serializedValueP))
.map(
untuple(HasuraAction.MissionModelArgumentsInput::new),
Expand All @@ -117,7 +117,7 @@ private static <I extends HasuraAction.Input> JsonParser<HasuraAction<I>> hasura

private static final JsonParser<HasuraAction.ActivityInput> hasuraActivityInputP
= productP
.field("missionModelId", stringP)
.field("missionModelId", missionModelIdP)
.field("activityTypeName", stringP)
.field("activityArguments", mapP(serializedValueP))
.map(
Expand All @@ -135,7 +135,7 @@ private static <I extends HasuraAction.Input> JsonParser<HasuraAction<I>> hasura
public static final JsonParser<HasuraAction<HasuraAction.ActivityBulkInput>> hasuraActivityBulkActionP
= hasuraActionF(
productP
.field("missionModelId", stringP)
.field("missionModelId", missionModelIdP)
.field("activities", listP(hasuraActivityBulkItemP))
.map(
untuple(HasuraAction.ActivityBulkInput::new),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package gov.nasa.jpl.aerie.merlin.server.http;

import gov.nasa.jpl.aerie.constraints.model.Violation;
import gov.nasa.jpl.aerie.json.JsonParseResult;
import gov.nasa.jpl.aerie.json.JsonParser;
import gov.nasa.jpl.aerie.json.SchemaCache;
import gov.nasa.jpl.aerie.merlin.driver.ActivityDirectiveId;
import gov.nasa.jpl.aerie.merlin.driver.SimulationFailure;
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration;
import gov.nasa.jpl.aerie.merlin.server.models.DatasetId;
import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId;
import gov.nasa.jpl.aerie.merlin.server.models.PlanId;
import gov.nasa.jpl.aerie.merlin.server.models.SimulationDatasetId;
import gov.nasa.jpl.aerie.merlin.server.models.Timestamp;
Expand Down Expand Up @@ -69,6 +69,12 @@ public JsonValue unparse(final Timestamp value) {
ActivityDirectiveId::new,
ActivityDirectiveId::id);

public static final JsonParser<MissionModelId> missionModelIdP
= longP
. map(
MissionModelId::new,
MissionModelId::id);

public static final JsonParser<PlanId> planIdP
= longP
. map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ public static JsonValue serializeNoSuchPlanDatasetException(final NoSuchPlanData
public static JsonValue serializeNoSuchMissionModelException(final MissionModelService.NoSuchMissionModelException ex) {
return Json.createObjectBuilder()
.add("message", "no such mission model")
.add("mission_model_id", ex.missionModelId)
.add("mission_model_id", ex.missionModelId.id())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public record Session(String hasuraRole, String hasuraUserId) { }

public sealed interface Input { }

public record MissionModelInput(String missionModelId) implements Input { }
public record MissionModelInput(MissionModelId missionModelId) implements Input { }
public record PlanInput(PlanId planId) implements Input { }
public record SimulateInput(PlanId planId, Optional<Boolean> force) implements Input {}
public record ConstraintViolationsInput(PlanId planId, Optional<SimulationDatasetId> simulationDatasetId) implements Input { }
public record ActivityInput(String missionModelId,
public record ActivityInput(MissionModelId missionModelId,
String activityTypeName,
Map<String, SerializedValue> arguments) implements Input {}
public record ActivityBulkInput(String missionModelId, List<SerializedActivity> activities) implements Input {}
public record MissionModelArgumentsInput(String missionModelId,
public record ActivityBulkInput(MissionModelId missionModelId, List<SerializedActivity> activities) implements Input {}
public record MissionModelArgumentsInput(MissionModelId missionModelId,
Map<String, SerializedValue> arguments) implements Input {}
public record UploadExternalDatasetInput(PlanId planId,
Optional<SimulationDatasetId> simulationDatasetId,
Expand All @@ -30,5 +30,5 @@ public record UploadExternalDatasetInput(PlanId planId,
public record ExtendExternalDatasetInput(DatasetId datasetId,
ProfileSet profileSet) implements Input {}

public record ConstraintsInput(String missionModelId, Optional<PlanId> planId) implements Input {}
public record ConstraintsInput(MissionModelId missionModelId, Optional<PlanId> planId) implements Input {}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package gov.nasa.jpl.aerie.merlin.server.models;

public record HasuraMissionModelEvent(String missionModelId) { }
public record HasuraMissionModelEvent(MissionModelId missionModelId) { }
Loading

0 comments on commit e038b8b

Please sign in to comment.