From c4e5e1d7228d882b7a928ae44628e60dde9d43ca Mon Sep 17 00:00:00 2001 From: pranav-super Date: Mon, 18 Nov 2024 10:11:28 -0800 Subject: [PATCH] remove all references to external_source_type_allowed_event_types.sql --- ...ernal_source_type_allowed_event_types.yaml | 37 --- .../metadata/databases/tables/tables.yaml | 1 - .../postgres-init-db/sql/init_merlin.sql | 1 - ...ternal_source_type_allowed_event_types.sql | 24 -- .../jpl/aerie/e2e/ExternalEventsTests.java | 252 ++++++++---------- .../gov/nasa/jpl/aerie/e2e/utils/GQL.java | 13 - .../jpl/aerie/e2e/utils/HasuraRequests.java | 13 - 7 files changed, 111 insertions(+), 230 deletions(-) delete mode 100644 deployment/hasura/metadata/databases/tables/merlin/external_source_type_allowed_event_types.yaml delete mode 100644 deployment/postgres-init-db/sql/tables/merlin/external_events/external_source_type_allowed_event_types.sql diff --git a/deployment/hasura/metadata/databases/tables/merlin/external_source_type_allowed_event_types.yaml b/deployment/hasura/metadata/databases/tables/merlin/external_source_type_allowed_event_types.yaml deleted file mode 100644 index 49ffba23a7..0000000000 --- a/deployment/hasura/metadata/databases/tables/merlin/external_source_type_allowed_event_types.yaml +++ /dev/null @@ -1,37 +0,0 @@ -table: - name: external_source_type_allowed_event_types - schema: merlin -configuration: - custom_name: "external_source_type_allowed_event_types" -object_relationships: -- name: event_type - using: - foreign_key_constraint_on: external_event_type -- name: source_type - using: - foreign_key_constraint_on: external_source_type -select_permissions: - - role: aerie_admin - permission: - columns: '*' - filter: {} - allow_aggregations: true - - role: user - permission: - columns: '*' - filter: {} - allow_aggregations: true - - role: viewer - permission: - columns: '*' - filter: {} - allow_aggregations: true -insert_permissions: - - role: aerie_admin - permission: - columns: [external_event_type, external_source_type] - check: {} -delete_permissions: - - role: aerie_admin - permission: - filter: {} diff --git a/deployment/hasura/metadata/databases/tables/tables.yaml b/deployment/hasura/metadata/databases/tables/tables.yaml index 8c32e0f684..40b07b3cf3 100644 --- a/deployment/hasura/metadata/databases/tables/tables.yaml +++ b/deployment/hasura/metadata/databases/tables/tables.yaml @@ -104,7 +104,6 @@ - "!include merlin/external_event_type.yaml" - "!include merlin/external_source.yaml" - "!include merlin/external_source_type.yaml" -- "!include merlin/external_source_type_allowed_event_types.yaml" - "!include merlin/plan_derivation_group.yaml" # Constraints diff --git a/deployment/postgres-init-db/sql/init_merlin.sql b/deployment/postgres-init-db/sql/init_merlin.sql index 3c1df927c2..eca054c4c5 100644 --- a/deployment/postgres-init-db/sql/init_merlin.sql +++ b/deployment/postgres-init-db/sql/init_merlin.sql @@ -75,7 +75,6 @@ begin; -- External Events \ir tables/merlin/external_events/external_source_type.sql \ir tables/merlin/external_events/external_event_type.sql - \ir tables/merlin/external_events/external_source_type_allowed_event_types.sql \ir tables/merlin/external_events/derivation_group.sql \ir tables/merlin/external_events/external_source.sql \ir tables/merlin/external_events/external_event.sql diff --git a/deployment/postgres-init-db/sql/tables/merlin/external_events/external_source_type_allowed_event_types.sql b/deployment/postgres-init-db/sql/tables/merlin/external_events/external_source_type_allowed_event_types.sql deleted file mode 100644 index 070d76ee18..0000000000 --- a/deployment/postgres-init-db/sql/tables/merlin/external_events/external_source_type_allowed_event_types.sql +++ /dev/null @@ -1,24 +0,0 @@ -create table merlin.external_source_type_allowed_event_types ( - external_source_type text not null, - external_event_type text not null, - - constraint external_source_type_allowed_event_types_pkey - primary key (external_source_type, external_event_type), - - constraint external_event_type_exists - foreign key (external_event_type) - references merlin.external_event_type(name) - on delete restrict, - constraint external_source_type_exists - foreign key (external_source_type) - references merlin.external_source_type(name) - on delete cascade -); - -comment on table merlin.external_source_type_allowed_event_types is e'' - 'Describes which event types are allowed in association with a given source type.'; - - comment on column merlin.external_source_type_allowed_event_types.external_source_type is e'' - 'The external source type that is specifying what event types it may include.'; - comment on column merlin.external_source_type_allowed_event_types.external_event_type is e'' - 'An allowed event type for a given external source.'; diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ExternalEventsTests.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ExternalEventsTests.java index 9a0bcc237f..3fb4e06f5f 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ExternalEventsTests.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ExternalEventsTests.java @@ -8,12 +8,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; -import org.postgresql.util.PSQLException; import javax.json.Json; import javax.json.JsonObject; import java.io.IOException; -import java.sql.SQLException; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -37,7 +35,7 @@ void beforeAll() { } // need a method to create external event type - void uploadExternalEventType(String externalEventTypeName) throws IOException { + void uploadExternalEventType( ) throws IOException { final JsonObject schema = Json.createObjectBuilder() .add("$schema", "http://json-schema.org/draft-07/schema") .add("title", "TestEventType") @@ -59,7 +57,7 @@ void uploadExternalEventType(String externalEventTypeName) throws IOException { .build(); try (final var gateway = new GatewayRequests(playwright)) { - gateway.uploadExternalEventType(externalEventTypeName, schema); + gateway.uploadExternalEventType("TestEventType", schema); } } @@ -94,16 +92,12 @@ void uploadExternalSourceType() throws IOException { @BeforeEach void beforeEach() throws IOException { // upload types - uploadExternalEventType("TestEventType"); - uploadExternalEventType("TestEventTypeUnallowed"); + uploadExternalEventType(); uploadExternalSourceType(); } @AfterEach void afterEach() throws IOException { - // delete type associations - hasura.deleteExternalSourceTypeAllowedEventType("TestSourceType", "TestEventType"); - // delete events hasura.deleteEventsBySource("TestExternalSourceKey", "TestDerivationGroup"); @@ -116,7 +110,6 @@ void afterEach() throws IOException { // delete types hasura.deleteExternalSourceType("TestSourceType"); hasura.deleteExternalEventType("TestEventType"); - hasura.deleteExternalEventType("TestEventTypeUnallowed"); } // test that a source goes in including all the attributes @@ -135,19 +128,21 @@ void correctSourceAndEventAttributes() throws IOException { ); final var externalSource = Json.createObjectBuilder() - .add("attributes", Json.createObjectBuilder() - .add("version", 1) - .add("operator", "alpha") - ) - .add("derivation_group_name", "TestDerivationGroup") - .add("end_time", "2024-01-28T00:00:00+00:00") - .add("external_events", Json.createObjectBuilder() - .add("data", externalEvents) + .add("source", Json.createObjectBuilder() + .add("attributes", Json.createObjectBuilder() + .add("version", 1) + .add("operator", "alpha") + ) + .add("derivation_group_name", "TestDerivationGroup") + .add("period", Json.createObjectBuilder() + .add("start_time", "2024-01-21T00:00:00+00:00") + .add("end_time", "2024-01-28T00:00:00+00:00") + ) + .add("key", "TestExternalSourceKey") + .add("source_type_name", "TestSourceType") + .add("valid_at", "2024-01-19T00:00:00+00:00") ) - .add("key", "TestExternalSourceKey") - .add("source_type_name", "TestSourceType") - .add("start_time", "2024-01-21T00:00:00+00:00") - .add("valid_at", "2024-01-19T00:00:00+00:00") + .add("external_events", externalEvents) .build(); try (final var gateway = new GatewayRequests(playwright)) { @@ -171,19 +166,21 @@ void sourceMissingAttribute() throws IOException { ); final var externalSource = Json.createObjectBuilder() - .add("attributes", Json.createObjectBuilder() - .add("version", 1) - // missing: operator - ) - .add("derivation_group_name", "TestDerivationGroup") - .add("end_time", "2024-01-28T00:00:00+00:00") - .add("external_events", Json.createObjectBuilder() - .add("data", externalEvents) - ) - .add("key", "TestExternalSourceKey") - .add("source_type_name", "TestSourceType") - .add("start_time", "2024-01-21T00:00:00+00:00") - .add("valid_at", "2024-01-19T00:00:00+00:00") + .add("source", Json.createObjectBuilder() + .add("attributes", Json.createObjectBuilder() + .add("version", 1) + // missing: operator + ) + .add("derivation_group_name", "TestDerivationGroup") + .add("period", Json.createObjectBuilder() + .add("start_time", "2024-01-21T00:00:00+00:00") + .add("end_time", "2024-01-28T00:00:00+00:00") + ) + .add("key", "TestExternalSourceKey") + .add("source_type_name", "TestSourceType") + .add("valid_at", "2024-01-19T00:00:00+00:00") + ) + .add("external_events", externalEvents) .build(); final var gateway = new GatewayRequests(playwright); @@ -207,20 +204,22 @@ void sourceExtraAttribute() throws IOException { ); final var externalSource = Json.createObjectBuilder() - .add("attributes", Json.createObjectBuilder() - .add("version", 1) - .add("operator", "alpha") - .add("extra", "attribute") // extra - ) - .add("derivation_group_name", "TestDerivationGroup") - .add("end_time", "2024-01-28T00:00:00+00:00") - .add("external_events", Json.createObjectBuilder() - .add("data", externalEvents) - ) - .add("key", "TestExternalSourceKey") - .add("source_type_name", "TestSourceType") - .add("start_time", "2024-01-21T00:00:00+00:00") - .add("valid_at", "2024-01-19T00:00:00+00:00") + .add("source", Json.createObjectBuilder() + .add("attributes", Json.createObjectBuilder() + .add("version", 1) + .add("operator", "alpha") + .add("extra", "attribute") // extra + ) + .add("derivation_group_name", "TestDerivationGroup") + .add("period", Json.createObjectBuilder() + .add("start_time", "2024-01-21T00:00:00+00:00") + .add("end_time", "2024-01-28T00:00:00+00:00") + ) + .add("key", "TestExternalSourceKey") + .add("source_type_name", "TestSourceType") + .add("valid_at", "2024-01-19T00:00:00+00:00") + ) + .add("external_events", externalEvents) .build(); final var gateway = new GatewayRequests(playwright); @@ -244,19 +243,21 @@ void sourceWrongTypeAttribute() throws IOException { ); final var externalSource = Json.createObjectBuilder() - .add("attributes", Json.createObjectBuilder() - .add("version", "string") // expects int - .add("operator", "alpha") - ) - .add("derivation_group_name", "TestDerivationGroup") - .add("end_time", "2024-01-28T00:00:00+00:00") - .add("external_events", Json.createObjectBuilder() - .add("data", externalEvents) - ) - .add("key", "TestExternalSourceKey") - .add("source_type_name", "TestSourceType") - .add("start_time", "2024-01-21T00:00:00+00:00") - .add("valid_at", "2024-01-19T00:00:00+00:00") + .add("source", Json.createObjectBuilder() + .add("attributes", Json.createObjectBuilder() + .add("version", "string") // expects int + .add("operator", "alpha") + ) + .add("derivation_group_name", "TestDerivationGroup") + .add("period", Json.createObjectBuilder() + .add("start_time", "2024-01-21T00:00:00+00:00") + .add("end_time", "2024-01-28T00:00:00+00:00") + ) + .add("key", "TestExternalSourceKey") + .add("source_type_name", "TestSourceType") + .add("valid_at", "2024-01-19T00:00:00+00:00") + ) + .add("external_events", externalEvents) .build(); final var gateway = new GatewayRequests(playwright); @@ -280,25 +281,27 @@ void eventMissingAttribute() throws IOException { ); final var externalSource = Json.createObjectBuilder() - .add("attributes", Json.createObjectBuilder() - .add("version", 1) - .add("operator", "alpha") - ) - .add("derivation_group_name", "TestDerivationGroup") - .add("end_time", "2024-01-28T00:00:00+00:00") - .add("external_events", Json.createObjectBuilder() - .add("data", externalEvents) - ) - .add("key", "TestExternalSourceKey") - .add("source_type_name", "TestSourceType") - .add("start_time", "2024-01-21T00:00:00+00:00") - .add("valid_at", "2024-01-19T00:00:00+00:00") + .add("source", Json.createObjectBuilder() + .add("attributes", Json.createObjectBuilder() + .add("version", 1) + .add("operator", "alpha") + ) + .add("derivation_group_name", "TestDerivationGroup") + .add("period", Json.createObjectBuilder() + .add("start_time", "2024-01-21T00:00:00+00:00") + .add("end_time", "2024-01-28T00:00:00+00:00") + ) + .add("key", "TestExternalSourceKey") + .add("source_type_name", "TestSourceType") + .add("valid_at", "2024-01-19T00:00:00+00:00") + ) + .add("external_events", externalEvents) .build(); final var gateway = new GatewayRequests(playwright); final IOException ex = assertThrows(IOException.class, () -> gateway.uploadExternalSource(externalSource)); assertTrue(ex.getMessage().contains("External Event")); - assertTrue(ex.getMessage().contains("does not have a valid set of attributes, per it's type's schema.")); + assertTrue(ex.getMessage().contains("does not have a valid set of attributes, per it's type's schema:")); } // test that an event fails with an extra attribute @@ -318,25 +321,27 @@ void eventExtraAttribute() throws IOException { ); final var externalSource = Json.createObjectBuilder() - .add("attributes", Json.createObjectBuilder() - .add("version", 1) - .add("operator", "alpha") - ) - .add("derivation_group_name", "TestDerivationGroup") - .add("end_time", "2024-01-28T00:00:00+00:00") - .add("external_events", Json.createObjectBuilder() - .add("data", externalEvents) - ) - .add("key", "TestExternalSourceKey") - .add("source_type_name", "TestSourceType") - .add("start_time", "2024-01-21T00:00:00+00:00") - .add("valid_at", "2024-01-19T00:00:00+00:00") + .add("source", Json.createObjectBuilder() + .add("attributes", Json.createObjectBuilder() + .add("version", 1) + .add("operator", "alpha") + ) + .add("derivation_group_name", "TestDerivationGroup") + .add("period", Json.createObjectBuilder() + .add("start_time", "2024-01-21T00:00:00+00:00") + .add("end_time", "2024-01-28T00:00:00+00:00") + ) + .add("key", "TestExternalSourceKey") + .add("source_type_name", "TestSourceType") + .add("valid_at", "2024-01-19T00:00:00+00:00") + ) + .add("external_events", externalEvents) .build(); final var gateway = new GatewayRequests(playwright); final IOException ex = assertThrows(IOException.class, () -> gateway.uploadExternalSource(externalSource)); assertTrue(ex.getMessage().contains("External Event")); - assertTrue(ex.getMessage().contains("does not have a valid set of attributes, per it's type's schema.")); + assertTrue(ex.getMessage().contains("does not have a valid set of attributes, per it's type's schema:")); } // test that an event fails with an attribute of the wrong type @@ -355,61 +360,26 @@ void eventWrongTypeAttribute() throws IOException { ); final var externalSource = Json.createObjectBuilder() - .add("attributes", Json.createObjectBuilder() - .add("version", 1) - .add("operator", "alpha") - ) - .add("derivation_group_name", "TestDerivationGroup") - .add("end_time", "2024-01-28T00:00:00+00:00") - .add("external_events", Json.createObjectBuilder() - .add("data", externalEvents) - ) - .add("key", "TestExternalSourceKey") - .add("source_type_name", "TestSourceType") - .add("start_time", "2024-01-21T00:00:00+00:00") - .add("valid_at", "2024-01-19T00:00:00+00:00") + .add("source", Json.createObjectBuilder() + .add("attributes", Json.createObjectBuilder() + .add("version", 1) + .add("operator", "alpha") + ) + .add("derivation_group_name", "TestDerivationGroup") + .add("period", Json.createObjectBuilder() + .add("start_time", "2024-01-21T00:00:00+00:00") + .add("end_time", "2024-01-28T00:00:00+00:00") + ) + .add("key", "TestExternalSourceKey") + .add("source_type_name", "TestSourceType") + .add("valid_at", "2024-01-19T00:00:00+00:00") + ) + .add("external_events", externalEvents) .build(); final var gateway = new GatewayRequests(playwright); final IOException ex = assertThrows(IOException.class, () -> gateway.uploadExternalSource(externalSource)); assertTrue(ex.getMessage().contains("External Event")); - assertTrue(ex.getMessage().contains("does not have a valid set of attributes, per it's type's schema.")); - } - - // test that an event fails going into a source if the type isn't allowed - @Test - void wrongEventTypeForSource() throws IOException { - final var externalEvents = Json.createArrayBuilder() - .add(Json.createObjectBuilder() - .add("attributes", Json.createObjectBuilder() - .add("projectUser", "UserA") - .add("code", "A") - ) - .add("duration", "01:00:00") - .add("event_type_name", "TestEventTypeUnallowed") - .add("key", "Event_01") - .add("start_time", "2024-01-21T01:00:00+00:00") - ); - - final var externalSource = Json.createObjectBuilder() - .add("attributes", Json.createObjectBuilder() - .add("version", 1) - .add("operator", "alpha") - ) - .add("derivation_group_name", "TestDerivationGroup") - .add("end_time", "2024-01-28T00:00:00+00:00") - .add("external_events", Json.createObjectBuilder() - .add("data", externalEvents) - ) - .add("key", "TestExternalSourceKey") - .add("source_type_name", "TestSourceType") - .add("start_time", "2024-01-21T00:00:00+00:00") - .add("valid_at", "2024-01-19T00:00:00+00:00") - .build(); - - final var gateway = new GatewayRequests(playwright); - final IOException ex = assertThrows(IOException.class, () -> gateway.uploadExternalSource(externalSource)); - assertTrue(ex.getMessage().contains("An event uses event type")); - assertTrue(ex.getMessage().contains("which is not defined for source type TestSourceType.")); + assertTrue(ex.getMessage().contains("does not have a valid set of attributes, per it's type's schema:")); } } 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 b5ae94fa0e..19d0fbe958 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 @@ -212,19 +212,6 @@ mutation DeleteExternalEventsBySource($externalSourceKey: String!, $derivationGr } } }"""), - DELETE_EXTERNAL_SOURCE_TYPE_ALLOWED_EVENT_TYPES(""" - mutation DeleteExternalSourceTypeAllowedEventType( - $externalSourceType: String!, - $externalEventType: String! - ) { - deleteExternalSourceTypeAllowedEventTypes: delete_external_source_type_allowed_event_types_by_pk( - external_source_type: $externalSourceType, - external_event_type: $externalEventType - ) { - external_source_type - external_event_type - } - }"""), DELETE_EXTERNAL_SOURCE_TYPE(""" mutation DeleteExternalSourceType($name: String!) { deleteExternalSourceType: delete_external_source_type_by_pk(name: $name) { diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/HasuraRequests.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/HasuraRequests.java index 3552ca37a8..98013312bc 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/HasuraRequests.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/HasuraRequests.java @@ -1090,19 +1090,6 @@ public String insertPlanDerivationGroupAssociation( .getString("derivation_group_name"); } - public String deleteExternalSourceTypeAllowedEventType( - String externalSourceType, - String externalEventType - ) throws IOException { - final var variables = Json.createObjectBuilder() - .add("externalSourceType", externalSourceType) - .add("externalEventType", externalEventType) - .build(); - var result = makeRequest(GQL.DELETE_EXTERNAL_SOURCE_TYPE_ALLOWED_EVENT_TYPES, variables) - .getJsonObject("deleteExternalSourceTypeAllowedEventTypes"); - return result.getString("external_event_type") + ", " + result.getString("external_source_type"); - } - public String deleteExternalSourceType( String name ) throws IOException {