From b278433452983989f48c233334d8937a06e8af03 Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Mon, 19 Jun 2023 17:50:46 +0200 Subject: [PATCH 1/9] Database restoration in sap system aggregate --- .../sap_system/events/database_restored.ex | 15 + lib/trento/domain/sap_system/sap_system.ex | 76 +++ .../domain/sap_system/sap_system_test.exs | 640 ++++++++++++++++++ 3 files changed, 731 insertions(+) create mode 100644 lib/trento/domain/sap_system/events/database_restored.ex diff --git a/lib/trento/domain/sap_system/events/database_restored.ex b/lib/trento/domain/sap_system/events/database_restored.ex new file mode 100644 index 0000000000..98ba6d8c16 --- /dev/null +++ b/lib/trento/domain/sap_system/events/database_restored.ex @@ -0,0 +1,15 @@ +defmodule Trento.Domain.Events.DatabaseRestored do + @moduledoc """ + This event is emitted when a database is restored. + """ + + use Trento.Event + + require Trento.Domain.Enums.Health, as: Health + + defevent do + field :sap_system_id, Ecto.UUID + field :sid, :string + field :health, Ecto.Enum, values: Health.values() + end +end diff --git a/lib/trento/domain/sap_system/sap_system.ex b/lib/trento/domain/sap_system/sap_system.ex index dcc81cf94f..7e6ff7cd70 100644 --- a/lib/trento/domain/sap_system/sap_system.ex +++ b/lib/trento/domain/sap_system/sap_system.ex @@ -77,6 +77,7 @@ defmodule Trento.Domain.SapSystem do DatabaseInstanceRegistered, DatabaseInstanceSystemReplicationChanged, DatabaseRegistered, + DatabaseRestored, SapSystemDeregistered, SapSystemHealthChanged, SapSystemRegistered, @@ -161,6 +162,61 @@ defmodule Trento.Domain.SapSystem do ] end + # Database restore + def execute( + %SapSystem{database: %Database{deregistered_at: deregistered_at}}, + %RegisterDatabaseInstance{ + system_replication: "Secondary" + } + ) + when not is_nil(deregistered_at), + do: {:error, :sap_system_not_registered} + + # When a deregistered database is present, we add the new database instance + # and restore the database, the conditions are the same as registration + def execute( + %SapSystem{database: %Database{deregistered_at: deregistered_at}}, + %RegisterDatabaseInstance{ + sap_system_id: sap_system_id, + sid: sid, + tenant: tenant, + host_id: host_id, + instance_number: instance_number, + instance_hostname: instance_hostname, + features: features, + http_port: http_port, + https_port: https_port, + start_priority: start_priority, + system_replication: system_replication, + system_replication_status: system_replication_status, + health: health + } + ) + when not is_nil(deregistered_at) do + [ + %DatabaseRestored{ + sap_system_id: sap_system_id, + health: health, + sid: sid + }, + %DatabaseInstanceRegistered{ + sap_system_id: sap_system_id, + sid: sid, + tenant: tenant, + instance_number: instance_number, + instance_hostname: instance_hostname, + features: features, + http_port: http_port, + https_port: https_port, + start_priority: start_priority, + host_id: host_id, + system_replication: system_replication, + system_replication_status: system_replication_status, + health: health + } + ] + end + # When a RegisterDatabaseInstance command is received by an existing SAP System aggregate, # the SAP System aggregate registers the Database instance if it is not already registered # and updates the health when needed. @@ -615,6 +671,26 @@ defmodule Trento.Domain.SapSystem do } end + def apply( + %SapSystem{database: database} = sap_system, + %DatabaseRestored{ + sap_system_id: sap_system_id, + health: health, + sid: sid + } + ) do + %SapSystem{ + sap_system + | sap_system_id: sap_system_id, + database: %Database{ + database + | health: health, + sid: sid, + deregistered_at: nil + } + } + end + def apply( %SapSystem{} = sap_system, %SapSystemDeregistered{ diff --git a/test/trento/domain/sap_system/sap_system_test.exs b/test/trento/domain/sap_system/sap_system_test.exs index 23c5218e27..78b8e17825 100644 --- a/test/trento/domain/sap_system/sap_system_test.exs +++ b/test/trento/domain/sap_system/sap_system_test.exs @@ -25,6 +25,7 @@ defmodule Trento.SapSystemTest do DatabaseInstanceRegistered, DatabaseInstanceSystemReplicationChanged, DatabaseRegistered, + DatabaseRestored, SapSystemDeregistered, SapSystemHealthChanged, SapSystemRegistered, @@ -1817,6 +1818,645 @@ defmodule Trento.SapSystemTest do end describe "deregistration" do + test "should not restore a deregistered database when the registering database instance has Secondary role" do + sap_system_id = UUID.uuid4() + + primary_database_host_id = UUID.uuid4() + secondary_database_host_id = UUID.uuid4() + + deregistered_at = DateTime.utc_now() + + db_instance_number_1 = "00" + db_instance_number_2 = "01" + + db_sid = fake_sid() + application_sid = fake_sid() + + message_server_host_id = UUID.uuid4() + message_server_instance_number = "00" + abap_host_id = UUID.uuid4() + abap_instance_number = "01" + + initial_events = [ + build( + :database_registered_event, + sap_system_id: sap_system_id, + sid: db_sid + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + sid: db_sid, + instance_number: db_instance_number_1, + system_replication: "Primary" + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: secondary_database_host_id, + instance_number: db_instance_number_2, + system_replication: "Secondary", + sid: db_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "MESSAGESERVER|ENQUE", + host_id: message_server_host_id, + instance_number: message_server_instance_number, + sid: application_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "ABAP|GATEWAY|ICMAN|IGS", + host_id: abap_host_id, + instance_number: abap_instance_number, + sid: application_sid + ), + build( + :sap_system_registered_event, + sap_system_id: sap_system_id, + sid: application_sid + ), + build(:database_instance_deregistered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + instance_number: db_instance_number_1, + deregistered_at: deregistered_at + ), + build(:database_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ), + build(:sap_system_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ) + ] + + command = + build(:register_database_instance_command, + system_replication: "Secondary", + sid: db_sid, + sap_system_id: sap_system_id + ) + + assert_error( + initial_events, + command, + {:error, :sap_system_not_registered} + ) + end + + test "should restore a deregistered database when the registering database instance has system replication disabled, with database instance leftovers" do + sap_system_id = UUID.uuid4() + + primary_database_host_id = UUID.uuid4() + secondary_database_host_id = UUID.uuid4() + + deregistered_at = DateTime.utc_now() + + db_instance_number_1 = "00" + db_instance_number_2 = "01" + + db_sid = fake_sid() + application_sid = fake_sid() + + message_server_host_id = UUID.uuid4() + message_server_instance_number = "00" + abap_host_id = UUID.uuid4() + abap_instance_number = "01" + + initial_events = [ + build( + :database_registered_event, + sap_system_id: sap_system_id, + sid: db_sid + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + sid: db_sid, + instance_number: db_instance_number_1, + system_replication: "Primary" + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: secondary_database_host_id, + instance_number: db_instance_number_2, + system_replication: "Secondary", + sid: db_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "MESSAGESERVER|ENQUE", + host_id: message_server_host_id, + instance_number: message_server_instance_number, + sid: application_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "ABAP|GATEWAY|ICMAN|IGS", + host_id: abap_host_id, + instance_number: abap_instance_number, + sid: application_sid + ), + build( + :sap_system_registered_event, + sap_system_id: sap_system_id, + sid: application_sid + ), + build(:database_instance_deregistered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + instance_number: db_instance_number_1, + deregistered_at: deregistered_at + ), + build(:database_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ), + build(:sap_system_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ) + ] + + %{features: features, instance_number: instance_number, health: health} = + command = + build(:register_database_instance_command, + system_replication: nil, + sid: db_sid, + sap_system_id: sap_system_id + ) + + assert_events_and_state( + initial_events, + command, + [ + %DatabaseRestored{ + sap_system_id: sap_system_id, + sid: db_sid, + health: command.health + }, + %DatabaseInstanceRegistered{ + sap_system_id: sap_system_id, + sid: db_sid, + tenant: command.tenant, + instance_number: command.instance_number, + instance_hostname: command.instance_hostname, + features: command.features, + http_port: command.http_port, + https_port: command.https_port, + start_priority: command.start_priority, + host_id: command.host_id, + system_replication: command.system_replication, + system_replication_status: command.system_replication_status, + health: command.health + } + ], + fn sap_system -> + assert %SapSystem{ + deregistered_at: ^deregistered_at, + database: %Database{ + deregistered_at: nil, + sid: ^db_sid, + instances: [ + %Instance{ + sid: ^db_sid, + instance_number: ^instance_number, + features: ^features, + health: ^health + }, + %Instance{} + ] + } + } = sap_system + end + ) + end + + test "should restore a deregistered database when the registering database instance has system replication disabled, without database instance leftovers" do + sap_system_id = UUID.uuid4() + + primary_database_host_id = UUID.uuid4() + secondary_database_host_id = UUID.uuid4() + + deregistered_at = DateTime.utc_now() + + db_instance_number_1 = "00" + db_instance_number_2 = "01" + + db_sid = fake_sid() + application_sid = fake_sid() + + message_server_host_id = UUID.uuid4() + message_server_instance_number = "00" + abap_host_id = UUID.uuid4() + abap_instance_number = "01" + + initial_events = [ + build( + :database_registered_event, + sap_system_id: sap_system_id, + sid: db_sid + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + sid: db_sid, + instance_number: db_instance_number_1, + system_replication: "Primary" + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: secondary_database_host_id, + instance_number: db_instance_number_2, + system_replication: "Secondary", + sid: db_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "MESSAGESERVER|ENQUE", + host_id: message_server_host_id, + instance_number: message_server_instance_number, + sid: application_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "ABAP|GATEWAY|ICMAN|IGS", + host_id: abap_host_id, + instance_number: abap_instance_number, + sid: application_sid + ), + build( + :sap_system_registered_event, + sap_system_id: sap_system_id, + sid: application_sid + ), + build(:database_instance_deregistered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + instance_number: db_instance_number_1, + deregistered_at: deregistered_at + ), + build(:database_instance_deregistered_event, + sap_system_id: sap_system_id, + host_id: secondary_database_host_id, + instance_number: db_instance_number_2, + deregistered_at: deregistered_at + ), + build(:database_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ), + build(:sap_system_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ) + ] + + %{features: features, instance_number: instance_number, health: health} = + command = + build(:register_database_instance_command, + system_replication: nil, + sid: db_sid, + sap_system_id: sap_system_id + ) + + assert_events_and_state( + initial_events, + command, + [ + %DatabaseRestored{ + sap_system_id: sap_system_id, + sid: db_sid, + health: command.health + }, + %DatabaseInstanceRegistered{ + sap_system_id: sap_system_id, + sid: db_sid, + tenant: command.tenant, + instance_number: command.instance_number, + instance_hostname: command.instance_hostname, + features: command.features, + http_port: command.http_port, + https_port: command.https_port, + start_priority: command.start_priority, + host_id: command.host_id, + system_replication: command.system_replication, + system_replication_status: command.system_replication_status, + health: command.health + } + ], + fn sap_system -> + assert Kernel.length(sap_system.database.instances) == 1 + + assert %SapSystem{ + deregistered_at: ^deregistered_at, + database: %Database{ + deregistered_at: nil, + sid: ^db_sid, + instances: [ + %Instance{ + sid: ^db_sid, + instance_number: ^instance_number, + features: ^features, + health: ^health, + system_replication: nil + } + ] + } + } = sap_system + end + ) + end + + test "should restore a deregistered database when the registering database instance is a primary, without database instance leftovers" do + sap_system_id = UUID.uuid4() + + primary_database_host_id = UUID.uuid4() + secondary_database_host_id = UUID.uuid4() + + deregistered_at = DateTime.utc_now() + + db_instance_number_1 = "00" + db_instance_number_2 = "01" + + db_sid = fake_sid() + application_sid = fake_sid() + + message_server_host_id = UUID.uuid4() + message_server_instance_number = "00" + abap_host_id = UUID.uuid4() + abap_instance_number = "01" + + initial_events = [ + build( + :database_registered_event, + sap_system_id: sap_system_id, + sid: db_sid + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + sid: db_sid, + instance_number: db_instance_number_1, + system_replication: "Primary" + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: secondary_database_host_id, + instance_number: db_instance_number_2, + system_replication: "Secondary", + sid: db_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "MESSAGESERVER|ENQUE", + host_id: message_server_host_id, + instance_number: message_server_instance_number, + sid: application_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "ABAP|GATEWAY|ICMAN|IGS", + host_id: abap_host_id, + instance_number: abap_instance_number, + sid: application_sid + ), + build( + :sap_system_registered_event, + sap_system_id: sap_system_id, + sid: application_sid + ), + build(:database_instance_deregistered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + instance_number: db_instance_number_1, + deregistered_at: deregistered_at + ), + build(:database_instance_deregistered_event, + sap_system_id: sap_system_id, + host_id: secondary_database_host_id, + instance_number: db_instance_number_2, + deregistered_at: deregistered_at + ), + build(:database_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ), + build(:sap_system_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ) + ] + + %{features: features, instance_number: instance_number, health: health} = + command = + build(:register_database_instance_command, + system_replication: "Primary", + sid: db_sid, + sap_system_id: sap_system_id + ) + + assert_events_and_state( + initial_events, + command, + [ + %DatabaseRestored{ + sap_system_id: sap_system_id, + sid: db_sid, + health: command.health + }, + %DatabaseInstanceRegistered{ + sap_system_id: sap_system_id, + sid: db_sid, + tenant: command.tenant, + instance_number: command.instance_number, + instance_hostname: command.instance_hostname, + features: command.features, + http_port: command.http_port, + https_port: command.https_port, + start_priority: command.start_priority, + host_id: command.host_id, + system_replication: command.system_replication, + system_replication_status: command.system_replication_status, + health: command.health + } + ], + fn sap_system -> + assert Kernel.length(sap_system.database.instances) == 1 + + assert %SapSystem{ + deregistered_at: ^deregistered_at, + database: %Database{ + deregistered_at: nil, + sid: ^db_sid, + instances: [ + %Instance{ + sid: ^db_sid, + instance_number: ^instance_number, + features: ^features, + health: ^health, + system_replication: "Primary" + } + ] + } + } = sap_system + end + ) + end + + test "should restore a deregistered database when the registering database instance is a primary, with database instance leftovers" do + sap_system_id = UUID.uuid4() + + primary_database_host_id = UUID.uuid4() + secondary_database_host_id = UUID.uuid4() + + deregistered_at = DateTime.utc_now() + + db_instance_number_1 = "00" + db_instance_number_2 = "01" + + db_sid = fake_sid() + application_sid = fake_sid() + + message_server_host_id = UUID.uuid4() + message_server_instance_number = "00" + abap_host_id = UUID.uuid4() + abap_instance_number = "01" + + initial_events = [ + build( + :database_registered_event, + sap_system_id: sap_system_id, + sid: db_sid + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + sid: db_sid, + instance_number: db_instance_number_1, + system_replication: "Primary" + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: secondary_database_host_id, + instance_number: db_instance_number_2, + system_replication: "Secondary", + sid: db_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "MESSAGESERVER|ENQUE", + host_id: message_server_host_id, + instance_number: message_server_instance_number, + sid: application_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "ABAP|GATEWAY|ICMAN|IGS", + host_id: abap_host_id, + instance_number: abap_instance_number, + sid: application_sid + ), + build( + :sap_system_registered_event, + sap_system_id: sap_system_id, + sid: application_sid + ), + build(:database_instance_deregistered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + instance_number: db_instance_number_1, + deregistered_at: deregistered_at + ), + build(:database_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ), + build(:sap_system_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ) + ] + + %{features: features, instance_number: instance_number, health: health} = + command = + build(:register_database_instance_command, + system_replication: "Primary", + sid: db_sid, + sap_system_id: sap_system_id + ) + + assert_events_and_state( + initial_events, + command, + [ + %DatabaseRestored{ + sap_system_id: sap_system_id, + sid: db_sid, + health: command.health + }, + %DatabaseInstanceRegistered{ + sap_system_id: sap_system_id, + sid: db_sid, + tenant: command.tenant, + instance_number: command.instance_number, + instance_hostname: command.instance_hostname, + features: command.features, + http_port: command.http_port, + https_port: command.https_port, + start_priority: command.start_priority, + host_id: command.host_id, + system_replication: command.system_replication, + system_replication_status: command.system_replication_status, + health: command.health + } + ], + fn sap_system -> + assert Kernel.length(sap_system.database.instances) == 2 + + assert %SapSystem{ + deregistered_at: ^deregistered_at, + database: %Database{ + deregistered_at: nil, + sid: ^db_sid, + instances: [ + %Instance{ + sid: ^db_sid, + instance_number: ^instance_number, + features: ^features, + health: ^health, + system_replication: "Primary" + }, + %Instance{} + ] + } + } = sap_system + end + ) + end + test "should reject all the commands except for the registration/instance deregistration ones, when the SAP system is deregistered" do sap_system_id = UUID.uuid4() From 02449d6a4a9313c97791cbd08d4bcc594056f7fb Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Mon, 19 Jun 2023 18:10:47 +0200 Subject: [PATCH 2/9] Database restore projection --- .../projectors/database_projector.ex | 37 ++++++++++++++++++- .../projectors/database_projector_test.exs | 33 ++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/lib/trento/application/projectors/database_projector.ex b/lib/trento/application/projectors/database_projector.ex index 944e5d0ca6..3e38fb4e2e 100644 --- a/lib/trento/application/projectors/database_projector.ex +++ b/lib/trento/application/projectors/database_projector.ex @@ -22,7 +22,8 @@ defmodule Trento.DatabaseProjector do DatabaseInstanceHealthChanged, DatabaseInstanceRegistered, DatabaseInstanceSystemReplicationChanged, - DatabaseRegistered + DatabaseRegistered, + DatabaseRestored } alias Trento.Repo @@ -160,6 +161,25 @@ defmodule Trento.DatabaseProjector do end ) + project( + %DatabaseRestored{ + sap_system_id: sap_system_id, + sid: sid, + health: health + }, + fn multi -> + db = Repo.get!(DatabaseReadModel, sap_system_id) + + changeset = + DatabaseReadModel.changeset( + db, + %{deregistered_at: nil, sid: sid, health: health} + ) + + Ecto.Multi.update(multi, :database, changeset) + end + ) + project( %DatabaseInstanceDeregistered{ instance_number: instance_number, @@ -279,6 +299,21 @@ defmodule Trento.DatabaseProjector do ) end + @impl true + def after_update( + %DatabaseRestored{sap_system_id: sap_system_id}, + _, + _ + ) do + database = Repo.get!(DatabaseReadModel, sap_system_id) + + TrentoWeb.Endpoint.broadcast( + @databases_topic, + "database_registered", + SapSystemView.render("database_registered.json", database: database) + ) + end + @impl true def after_update( %DatabaseDeregistered{ diff --git a/test/trento/application/projectors/database_projector_test.exs b/test/trento/application/projectors/database_projector_test.exs index dc994d5ecb..a553cf31de 100644 --- a/test/trento/application/projectors/database_projector_test.exs +++ b/test/trento/application/projectors/database_projector_test.exs @@ -18,7 +18,8 @@ defmodule Trento.DatabaseProjectorTest do DatabaseHealthChanged, DatabaseInstanceDeregistered, DatabaseInstanceHealthChanged, - DatabaseInstanceSystemReplicationChanged + DatabaseInstanceSystemReplicationChanged, + DatabaseRestored } alias Trento.ProjectorTestHelper @@ -305,4 +306,34 @@ defmodule Trento.DatabaseProjectorTest do }, 1000 end + + test "should restore a deregistered database when DatabaseRestored is received" do + insert(:database, + id: sap_system_id = Faker.UUID.v4(), + sid: "NWD", + deregistered_at: DateTime.utc_now(), + health: :critical + ) + + event = %DatabaseRestored{ + sap_system_id: sap_system_id, + sid: "NWD", + health: :passing + } + + ProjectorTestHelper.project(DatabaseProjector, event, "database_projector") + + projection = Repo.get(DatabaseReadModel, sap_system_id) + assert nil == projection.deregistered_at + assert "NWD" == projection.sid + assert :passing == projection.health + + assert_broadcast "database_registered", + %{ + health: :passing, + id: ^sap_system_id, + sid: "NWD" + }, + 1000 + end end From a9c4cc6ee51a28e0986058df4f5285063674265a Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Tue, 20 Jun 2023 11:12:19 +0200 Subject: [PATCH 3/9] Sap system restore domain --- .../sap_system/events/sap_system_restored.ex | 17 ++ lib/trento/domain/sap_system/sap_system.ex | 55 ++++ test/support/factory.ex | 19 ++ .../domain/sap_system/sap_system_test.exs | 270 ++++++++++++++++++ 4 files changed, 361 insertions(+) create mode 100644 lib/trento/domain/sap_system/events/sap_system_restored.ex diff --git a/lib/trento/domain/sap_system/events/sap_system_restored.ex b/lib/trento/domain/sap_system/events/sap_system_restored.ex new file mode 100644 index 0000000000..581f016e09 --- /dev/null +++ b/lib/trento/domain/sap_system/events/sap_system_restored.ex @@ -0,0 +1,17 @@ +defmodule Trento.Domain.Events.SapSystemRestored do + @moduledoc """ + This event is emitted when a sap system is restored. + """ + + use Trento.Event + + require Trento.Domain.Enums.Health, as: Health + + defevent do + field :sap_system_id, Ecto.UUID + field :sid, :string + field :tenant, :string + field :db_host, :string + field :health, Ecto.Enum, values: Health.values() + end +end diff --git a/lib/trento/domain/sap_system/sap_system.ex b/lib/trento/domain/sap_system/sap_system.ex index 7e6ff7cd70..6e04e109a9 100644 --- a/lib/trento/domain/sap_system/sap_system.ex +++ b/lib/trento/domain/sap_system/sap_system.ex @@ -81,6 +81,7 @@ defmodule Trento.Domain.SapSystem do SapSystemDeregistered, SapSystemHealthChanged, SapSystemRegistered, + SapSystemRestored, SapSystemRolledUp, SapSystemRollUpRequested, SapSystemTombstoned, @@ -241,6 +242,27 @@ defmodule Trento.Domain.SapSystem do |> Multi.execute(&maybe_emit_sap_system_health_changed_event/1) end + # Restore sap system + # Same registration rules + def execute( + %SapSystem{deregistered_at: deregistered_at} = sap_system, + %RegisterApplicationInstance{} = instance + ) + when not is_nil(deregistered_at) do + sap_system + |> Multi.new() + |> Multi.execute(fn sap_system -> + emit_application_instance_registered_or_application_instance_health_changed( + sap_system, + instance + ) + end) + |> Multi.execute(fn sap_system -> + maybe_emit_sap_system_restored_event(sap_system, instance) + end) + |> Multi.execute(&maybe_emit_sap_system_health_changed_event/1) + end + # SAP system not registered, application already present # If the instance is not one of MESSAGESERVER or ABAP we discard. # Otherwise if the instance we want register together with already present instances @@ -703,6 +725,18 @@ defmodule Trento.Domain.SapSystem do } end + def apply(%SapSystem{} = sap_system, %SapSystemRestored{ + sid: sid, + health: health + }) do + %SapSystem{ + sap_system + | sid: sid, + health: health, + deregistered_at: nil + } + end + def apply(%SapSystem{} = sap_system, %SapSystemTombstoned{}), do: sap_system defp maybe_emit_database_instance_registered_event( @@ -905,6 +939,27 @@ defmodule Trento.Domain.SapSystem do end end + defp maybe_emit_sap_system_restored_event( + %SapSystem{application: %Application{instances: instances}}, + %RegisterApplicationInstance{ + sap_system_id: sap_system_id, + sid: sid, + tenant: tenant, + db_host: db_host, + health: health + } + ) do + if instances_have_abap?(instances) and instances_have_messageserver?(instances) do + %SapSystemRestored{ + db_host: db_host, + health: health, + sap_system_id: sap_system_id, + sid: sid, + tenant: tenant + } + end + end + defp maybe_emit_sap_system_registered_or_updated_event( %SapSystem{sid: nil, application: %Application{instances: instances}}, %RegisterApplicationInstance{ diff --git a/test/support/factory.ex b/test/support/factory.ex index 9691fe54d1..973bd29004 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -21,6 +21,7 @@ defmodule Trento.Factory do } alias Trento.Domain.Events.{ + ApplicationInstanceDeregistered, ApplicationInstanceRegistered, ClusterDeregistered, ClusterRegistered, @@ -29,6 +30,7 @@ defmodule Trento.Factory do DatabaseInstanceDeregistered, DatabaseInstanceRegistered, DatabaseRegistered, + DatabaseRestored, HostAddedToCluster, HostDetailsUpdated, HostRegistered, @@ -267,6 +269,14 @@ defmodule Trento.Factory do }) end + def database_restored_event_factory do + DatabaseRestored.new!(%{ + sap_system_id: Faker.UUID.v4(), + sid: Faker.UUID.v4(), + health: Health.passing() + }) + end + def deregister_database_instance_command_factory do DeregisterDatabaseInstance.new!(%{ sap_system_id: Faker.UUID.v4(), @@ -298,6 +308,15 @@ defmodule Trento.Factory do } end + def application_instance_deregistered_event_factory do + ApplicationInstanceDeregistered.new!(%{ + sap_system_id: Faker.UUID.v4(), + deregistered_at: DateTime.utc_now(), + instance_number: "00", + host_id: Faker.UUID.v4() + }) + end + def deregister_application_instance_command_factory do DeregisterApplicationInstance.new!(%{ sap_system_id: Faker.UUID.v4(), diff --git a/test/trento/domain/sap_system/sap_system_test.exs b/test/trento/domain/sap_system/sap_system_test.exs index 78b8e17825..a6adc8ea00 100644 --- a/test/trento/domain/sap_system/sap_system_test.exs +++ b/test/trento/domain/sap_system/sap_system_test.exs @@ -29,6 +29,7 @@ defmodule Trento.SapSystemTest do SapSystemDeregistered, SapSystemHealthChanged, SapSystemRegistered, + SapSystemRestored, SapSystemRolledUp, SapSystemRollUpRequested, SapSystemTombstoned, @@ -2457,6 +2458,275 @@ defmodule Trento.SapSystemTest do ) end + test "should not restore a sap system when no abap/messageserver instances are present" do + sap_system_id = UUID.uuid4() + + primary_database_host_id = UUID.uuid4() + secondary_database_host_id = UUID.uuid4() + + deregistered_at = DateTime.utc_now() + + db_instance_number_1 = "00" + db_instance_number_2 = "01" + + db_sid = fake_sid() + application_sid = fake_sid() + + message_server_host_id = UUID.uuid4() + message_server_instance_number = "00" + abap_host_id = UUID.uuid4() + abap_instance_number = "01" + + initial_events = [ + build( + :database_registered_event, + sap_system_id: sap_system_id, + sid: db_sid + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + sid: db_sid, + instance_number: db_instance_number_1, + system_replication: "Primary" + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: secondary_database_host_id, + instance_number: db_instance_number_2, + system_replication: "Secondary", + sid: db_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "MESSAGESERVER|ENQUE", + host_id: message_server_host_id, + instance_number: message_server_instance_number, + sid: application_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "ABAP|GATEWAY|ICMAN|IGS", + host_id: abap_host_id, + instance_number: abap_instance_number, + sid: application_sid + ), + build( + :sap_system_registered_event, + sap_system_id: sap_system_id, + sid: application_sid + ), + build(:database_instance_deregistered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + instance_number: db_instance_number_1, + deregistered_at: deregistered_at + ), + build(:database_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ), + build(:sap_system_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ), + build(:application_instance_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at, + instance_number: message_server_instance_number, + host_id: message_server_host_id + ), + build(:database_instance_registered_event, + system_replication: "Primary", + sid: db_sid, + sap_system_id: sap_system_id + ), + build(:database_restored_event, + sap_system_id: sap_system_id, + sid: db_sid + ) + ] + + command = + build( + :register_application_instance_command, + sap_system_id: sap_system_id, + sid: application_sid, + db_host: primary_database_host_id, + features: "IGS" + ) + + assert_events_and_state( + initial_events, + command, + [ + %ApplicationInstanceRegistered{ + sap_system_id: sap_system_id, + sid: application_sid, + host_id: command.host_id, + instance_number: command.instance_number, + instance_hostname: command.instance_hostname, + features: command.features, + http_port: command.http_port, + https_port: command.https_port, + start_priority: command.start_priority, + health: command.health + } + ], + fn sap_system -> + assert %SapSystem{ + deregistered_at: ^deregistered_at, + database: %Database{ + deregistered_at: nil, + sid: ^db_sid + } + } = sap_system + end + ) + end + + test "should restore a sap system when abap/messageserver instances are present" do + sap_system_id = UUID.uuid4() + + primary_database_host_id = UUID.uuid4() + secondary_database_host_id = UUID.uuid4() + + deregistered_at = DateTime.utc_now() + + db_instance_number_1 = "00" + db_instance_number_2 = "01" + + db_sid = fake_sid() + application_sid = fake_sid() + + message_server_host_id = UUID.uuid4() + message_server_instance_number = "00" + abap_host_id = UUID.uuid4() + abap_instance_number = "01" + + initial_events = [ + build( + :database_registered_event, + sap_system_id: sap_system_id, + sid: db_sid + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + sid: db_sid, + instance_number: db_instance_number_1, + system_replication: "Primary" + ), + build( + :database_instance_registered_event, + sap_system_id: sap_system_id, + host_id: secondary_database_host_id, + instance_number: db_instance_number_2, + system_replication: "Secondary", + sid: db_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "MESSAGESERVER|ENQUE", + host_id: message_server_host_id, + instance_number: message_server_instance_number, + sid: application_sid + ), + build( + :application_instance_registered_event, + sap_system_id: sap_system_id, + features: "ABAP|GATEWAY|ICMAN|IGS", + host_id: abap_host_id, + instance_number: abap_instance_number, + sid: application_sid + ), + build( + :sap_system_registered_event, + sap_system_id: sap_system_id, + sid: application_sid + ), + build(:database_instance_deregistered_event, + sap_system_id: sap_system_id, + host_id: primary_database_host_id, + instance_number: db_instance_number_1, + deregistered_at: deregistered_at + ), + build(:database_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ), + build(:sap_system_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at + ), + build(:application_instance_deregistered_event, + sap_system_id: sap_system_id, + deregistered_at: deregistered_at, + instance_number: message_server_instance_number, + host_id: message_server_host_id + ), + build(:database_instance_registered_event, + system_replication: "Primary", + sid: db_sid, + sap_system_id: sap_system_id + ), + build(:database_restored_event, + sap_system_id: sap_system_id, + sid: db_sid + ) + ] + + command = + build( + :register_application_instance_command, + sap_system_id: sap_system_id, + sid: application_sid, + db_host: primary_database_host_id, + features: "MESSAGESERVER" + ) + + assert_events_and_state( + initial_events, + command, + [ + %ApplicationInstanceRegistered{ + sap_system_id: sap_system_id, + sid: application_sid, + host_id: command.host_id, + instance_number: command.instance_number, + instance_hostname: command.instance_hostname, + features: command.features, + http_port: command.http_port, + https_port: command.https_port, + start_priority: command.start_priority, + health: command.health + }, + %SapSystemRestored{ + sap_system_id: sap_system_id, + sid: application_sid, + tenant: command.tenant, + db_host: command.db_host, + health: command.health + } + ], + fn sap_system -> + assert %SapSystem{ + deregistered_at: nil, + database: %Database{ + deregistered_at: nil, + sid: ^db_sid + } + } = sap_system + end + ) + end + test "should reject all the commands except for the registration/instance deregistration ones, when the SAP system is deregistered" do sap_system_id = UUID.uuid4() From f63f23fceb920b5ad01121dae7de9e2e88653901 Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Thu, 22 Jun 2023 16:54:38 +0200 Subject: [PATCH 4/9] Sap system restore projection --- .../projectors/sap_system_projector.ex | 41 +++++++++++++++++++ .../projectors/sap_system_projector_test.exs | 33 +++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/lib/trento/application/projectors/sap_system_projector.ex b/lib/trento/application/projectors/sap_system_projector.ex index c85a9f3914..f063cef0ba 100644 --- a/lib/trento/application/projectors/sap_system_projector.ex +++ b/lib/trento/application/projectors/sap_system_projector.ex @@ -15,6 +15,7 @@ defmodule Trento.SapSystemProjector do SapSystemDeregistered, SapSystemHealthChanged, SapSystemRegistered, + SapSystemRestored, SapSystemUpdated } @@ -134,6 +135,30 @@ defmodule Trento.SapSystemProjector do end ) + project( + %SapSystemRestored{ + sap_system_id: sap_system_id, + sid: sid, + tenant: tenant, + db_host: db_host, + health: health + }, + fn multi -> + sap_system = Repo.get!(SapSystemReadModel, sap_system_id) + + changeset = + SapSystemReadModel.changeset(sap_system, %{ + sid: sid, + tenant: tenant, + db_host: db_host, + health: health, + deregistered_at: nil + }) + + Ecto.Multi.update(multi, :sap_system, changeset) + end + ) + project( %ApplicationInstanceDeregistered{ instance_number: instance_number, @@ -170,6 +195,7 @@ defmodule Trento.SapSystemProjector do @sap_systems_topic "monitoring:sap_systems" @impl true + @spec after_update(any, any, any) :: :ok | {:error, any} def after_update( %SapSystemRegistered{}, _, @@ -258,6 +284,21 @@ defmodule Trento.SapSystemProjector do ) end + @impl true + def after_update( + %SapSystemRestored{sap_system_id: sap_system_id}, + _, + _ + ) do + sap_system = Repo.get!(SapSystemReadModel, sap_system_id) + + TrentoWeb.Endpoint.broadcast( + @sap_systems_topic, + "sap_system_registered", + SapSystemView.render("sap_system_registered.json", sap_system: sap_system) + ) + end + @impl true def after_update( %ApplicationInstanceDeregistered{ diff --git a/test/trento/application/projectors/sap_system_projector_test.exs b/test/trento/application/projectors/sap_system_projector_test.exs index 2543aa274b..d34be57237 100644 --- a/test/trento/application/projectors/sap_system_projector_test.exs +++ b/test/trento/application/projectors/sap_system_projector_test.exs @@ -20,6 +20,7 @@ defmodule Trento.SapSystemProjectorTest do ApplicationInstanceHealthChanged, SapSystemDeregistered, SapSystemHealthChanged, + SapSystemRestored, SapSystemUpdated } @@ -188,6 +189,38 @@ defmodule Trento.SapSystemProjectorTest do assert deregistered_at == projection.deregistered_at end + test "should restore a SAP system when SapSystemRestored is received" do + %{tenant: tenant, id: sap_system_id, sid: sid} = + insert(:sap_system, deregistered_at: DateTime.utc_now()) + + new_db_host = Faker.Internet.ip_v4_address() + new_health = :passing + + event = %SapSystemRestored{ + sap_system_id: sap_system_id, + tenant: tenant, + db_host: new_db_host, + health: new_health, + sid: sid + } + + ProjectorTestHelper.project(SapSystemProjector, event, "sap_system_projector") + + projection = Repo.get(SapSystemReadModel, sap_system_id) + + assert_broadcast "sap_system_registered", + %{ + db_host: ^new_db_host, + health: ^new_health, + id: ^sap_system_id, + sid: ^sid, + tenant: ^tenant + }, + 1000 + + assert nil == projection.deregistered_at + end + test "should remove an application instance from the read model after a deregistration" do deregistered_at = DateTime.utc_now() From 7d07f84c13707ca4a5bd02de61b9bd842e50ec6e Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Thu, 22 Jun 2023 17:39:58 +0200 Subject: [PATCH 5/9] Emit application instance registered or moved in restore --- lib/trento/domain/sap_system/sap_system.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/trento/domain/sap_system/sap_system.ex b/lib/trento/domain/sap_system/sap_system.ex index 6e04e109a9..46f736ede1 100644 --- a/lib/trento/domain/sap_system/sap_system.ex +++ b/lib/trento/domain/sap_system/sap_system.ex @@ -252,7 +252,7 @@ defmodule Trento.Domain.SapSystem do sap_system |> Multi.new() |> Multi.execute(fn sap_system -> - emit_application_instance_registered_or_application_instance_health_changed( + maybe_emit_application_instance_registered_or_moved_event( sap_system, instance ) From dfc875ed7cea89aaf300152a9bf767d2ca4c4248 Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Thu, 22 Jun 2023 17:41:22 +0200 Subject: [PATCH 6/9] Removed health multi change on sap system restoration --- lib/trento/domain/sap_system/sap_system.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/trento/domain/sap_system/sap_system.ex b/lib/trento/domain/sap_system/sap_system.ex index 46f736ede1..a1f77e41cd 100644 --- a/lib/trento/domain/sap_system/sap_system.ex +++ b/lib/trento/domain/sap_system/sap_system.ex @@ -260,7 +260,6 @@ defmodule Trento.Domain.SapSystem do |> Multi.execute(fn sap_system -> maybe_emit_sap_system_restored_event(sap_system, instance) end) - |> Multi.execute(&maybe_emit_sap_system_health_changed_event/1) end # SAP system not registered, application already present From 281a2be915c94fbbcefc4d3bd2e7ab47f11bb7c3 Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Thu, 22 Jun 2023 17:43:22 +0200 Subject: [PATCH 7/9] Remove sap_system_id setting in database restored apply --- lib/trento/domain/sap_system/sap_system.ex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/trento/domain/sap_system/sap_system.ex b/lib/trento/domain/sap_system/sap_system.ex index a1f77e41cd..4586e5e92d 100644 --- a/lib/trento/domain/sap_system/sap_system.ex +++ b/lib/trento/domain/sap_system/sap_system.ex @@ -695,15 +695,13 @@ defmodule Trento.Domain.SapSystem do def apply( %SapSystem{database: database} = sap_system, %DatabaseRestored{ - sap_system_id: sap_system_id, health: health, sid: sid } ) do %SapSystem{ sap_system - | sap_system_id: sap_system_id, - database: %Database{ + | database: %Database{ database | health: health, sid: sid, From e4a62823d2150a2a3199d5adbf2cd1546891b461 Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Thu, 22 Jun 2023 17:57:51 +0200 Subject: [PATCH 8/9] Removed sid from DatabaseRestored event --- .../application/projectors/database_projector.ex | 3 +-- .../domain/sap_system/events/database_restored.ex | 1 - lib/trento/domain/sap_system/sap_system.ex | 7 ++----- test/support/factory.ex | 1 - .../application/projectors/database_projector_test.exs | 2 -- test/trento/domain/sap_system/sap_system_test.exs | 10 ++-------- 6 files changed, 5 insertions(+), 19 deletions(-) diff --git a/lib/trento/application/projectors/database_projector.ex b/lib/trento/application/projectors/database_projector.ex index 3e38fb4e2e..d74233b7a5 100644 --- a/lib/trento/application/projectors/database_projector.ex +++ b/lib/trento/application/projectors/database_projector.ex @@ -164,7 +164,6 @@ defmodule Trento.DatabaseProjector do project( %DatabaseRestored{ sap_system_id: sap_system_id, - sid: sid, health: health }, fn multi -> @@ -173,7 +172,7 @@ defmodule Trento.DatabaseProjector do changeset = DatabaseReadModel.changeset( db, - %{deregistered_at: nil, sid: sid, health: health} + %{deregistered_at: nil, health: health} ) Ecto.Multi.update(multi, :database, changeset) diff --git a/lib/trento/domain/sap_system/events/database_restored.ex b/lib/trento/domain/sap_system/events/database_restored.ex index 98ba6d8c16..e486ab69ef 100644 --- a/lib/trento/domain/sap_system/events/database_restored.ex +++ b/lib/trento/domain/sap_system/events/database_restored.ex @@ -9,7 +9,6 @@ defmodule Trento.Domain.Events.DatabaseRestored do defevent do field :sap_system_id, Ecto.UUID - field :sid, :string field :health, Ecto.Enum, values: Health.values() end end diff --git a/lib/trento/domain/sap_system/sap_system.ex b/lib/trento/domain/sap_system/sap_system.ex index 4586e5e92d..a465941a0a 100644 --- a/lib/trento/domain/sap_system/sap_system.ex +++ b/lib/trento/domain/sap_system/sap_system.ex @@ -197,8 +197,7 @@ defmodule Trento.Domain.SapSystem do [ %DatabaseRestored{ sap_system_id: sap_system_id, - health: health, - sid: sid + health: health }, %DatabaseInstanceRegistered{ sap_system_id: sap_system_id, @@ -695,8 +694,7 @@ defmodule Trento.Domain.SapSystem do def apply( %SapSystem{database: database} = sap_system, %DatabaseRestored{ - health: health, - sid: sid + health: health } ) do %SapSystem{ @@ -704,7 +702,6 @@ defmodule Trento.Domain.SapSystem do | database: %Database{ database | health: health, - sid: sid, deregistered_at: nil } } diff --git a/test/support/factory.ex b/test/support/factory.ex index 973bd29004..185aef2204 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -272,7 +272,6 @@ defmodule Trento.Factory do def database_restored_event_factory do DatabaseRestored.new!(%{ sap_system_id: Faker.UUID.v4(), - sid: Faker.UUID.v4(), health: Health.passing() }) end diff --git a/test/trento/application/projectors/database_projector_test.exs b/test/trento/application/projectors/database_projector_test.exs index a553cf31de..9f76bb4daa 100644 --- a/test/trento/application/projectors/database_projector_test.exs +++ b/test/trento/application/projectors/database_projector_test.exs @@ -317,7 +317,6 @@ defmodule Trento.DatabaseProjectorTest do event = %DatabaseRestored{ sap_system_id: sap_system_id, - sid: "NWD", health: :passing } @@ -325,7 +324,6 @@ defmodule Trento.DatabaseProjectorTest do projection = Repo.get(DatabaseReadModel, sap_system_id) assert nil == projection.deregistered_at - assert "NWD" == projection.sid assert :passing == projection.health assert_broadcast "database_registered", diff --git a/test/trento/domain/sap_system/sap_system_test.exs b/test/trento/domain/sap_system/sap_system_test.exs index a6adc8ea00..1cefe67e20 100644 --- a/test/trento/domain/sap_system/sap_system_test.exs +++ b/test/trento/domain/sap_system/sap_system_test.exs @@ -2003,7 +2003,6 @@ defmodule Trento.SapSystemTest do [ %DatabaseRestored{ sap_system_id: sap_system_id, - sid: db_sid, health: command.health }, %DatabaseInstanceRegistered{ @@ -2141,7 +2140,6 @@ defmodule Trento.SapSystemTest do [ %DatabaseRestored{ sap_system_id: sap_system_id, - sid: db_sid, health: command.health }, %DatabaseInstanceRegistered{ @@ -2281,7 +2279,6 @@ defmodule Trento.SapSystemTest do [ %DatabaseRestored{ sap_system_id: sap_system_id, - sid: db_sid, health: command.health }, %DatabaseInstanceRegistered{ @@ -2415,7 +2412,6 @@ defmodule Trento.SapSystemTest do [ %DatabaseRestored{ sap_system_id: sap_system_id, - sid: db_sid, health: command.health }, %DatabaseInstanceRegistered{ @@ -2546,8 +2542,7 @@ defmodule Trento.SapSystemTest do sap_system_id: sap_system_id ), build(:database_restored_event, - sap_system_id: sap_system_id, - sid: db_sid + sap_system_id: sap_system_id ) ] @@ -2677,8 +2672,7 @@ defmodule Trento.SapSystemTest do sap_system_id: sap_system_id ), build(:database_restored_event, - sap_system_id: sap_system_id, - sid: db_sid + sap_system_id: sap_system_id ) ] From 70b8b81097ca9669a9c8f5cc13d8f7d8774ba4b6 Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Thu, 22 Jun 2023 18:01:43 +0200 Subject: [PATCH 9/9] Removed sid field from SapSytemRestored event --- lib/trento/application/projectors/sap_system_projector.ex | 2 -- lib/trento/domain/sap_system/events/sap_system_restored.ex | 1 - lib/trento/domain/sap_system/sap_system.ex | 6 +----- .../application/projectors/sap_system_projector_test.exs | 3 +-- test/trento/domain/sap_system/sap_system_test.exs | 1 - 5 files changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/trento/application/projectors/sap_system_projector.ex b/lib/trento/application/projectors/sap_system_projector.ex index f063cef0ba..86d7d73683 100644 --- a/lib/trento/application/projectors/sap_system_projector.ex +++ b/lib/trento/application/projectors/sap_system_projector.ex @@ -138,7 +138,6 @@ defmodule Trento.SapSystemProjector do project( %SapSystemRestored{ sap_system_id: sap_system_id, - sid: sid, tenant: tenant, db_host: db_host, health: health @@ -148,7 +147,6 @@ defmodule Trento.SapSystemProjector do changeset = SapSystemReadModel.changeset(sap_system, %{ - sid: sid, tenant: tenant, db_host: db_host, health: health, diff --git a/lib/trento/domain/sap_system/events/sap_system_restored.ex b/lib/trento/domain/sap_system/events/sap_system_restored.ex index 581f016e09..cae01e3908 100644 --- a/lib/trento/domain/sap_system/events/sap_system_restored.ex +++ b/lib/trento/domain/sap_system/events/sap_system_restored.ex @@ -9,7 +9,6 @@ defmodule Trento.Domain.Events.SapSystemRestored do defevent do field :sap_system_id, Ecto.UUID - field :sid, :string field :tenant, :string field :db_host, :string field :health, Ecto.Enum, values: Health.values() diff --git a/lib/trento/domain/sap_system/sap_system.ex b/lib/trento/domain/sap_system/sap_system.ex index a465941a0a..7944dda8cc 100644 --- a/lib/trento/domain/sap_system/sap_system.ex +++ b/lib/trento/domain/sap_system/sap_system.ex @@ -720,13 +720,11 @@ defmodule Trento.Domain.SapSystem do end def apply(%SapSystem{} = sap_system, %SapSystemRestored{ - sid: sid, health: health }) do %SapSystem{ sap_system - | sid: sid, - health: health, + | health: health, deregistered_at: nil } end @@ -937,7 +935,6 @@ defmodule Trento.Domain.SapSystem do %SapSystem{application: %Application{instances: instances}}, %RegisterApplicationInstance{ sap_system_id: sap_system_id, - sid: sid, tenant: tenant, db_host: db_host, health: health @@ -948,7 +945,6 @@ defmodule Trento.Domain.SapSystem do db_host: db_host, health: health, sap_system_id: sap_system_id, - sid: sid, tenant: tenant } end diff --git a/test/trento/application/projectors/sap_system_projector_test.exs b/test/trento/application/projectors/sap_system_projector_test.exs index d34be57237..0cc3f066a5 100644 --- a/test/trento/application/projectors/sap_system_projector_test.exs +++ b/test/trento/application/projectors/sap_system_projector_test.exs @@ -200,8 +200,7 @@ defmodule Trento.SapSystemProjectorTest do sap_system_id: sap_system_id, tenant: tenant, db_host: new_db_host, - health: new_health, - sid: sid + health: new_health } ProjectorTestHelper.project(SapSystemProjector, event, "sap_system_projector") diff --git a/test/trento/domain/sap_system/sap_system_test.exs b/test/trento/domain/sap_system/sap_system_test.exs index 1cefe67e20..83025c1b44 100644 --- a/test/trento/domain/sap_system/sap_system_test.exs +++ b/test/trento/domain/sap_system/sap_system_test.exs @@ -2703,7 +2703,6 @@ defmodule Trento.SapSystemTest do }, %SapSystemRestored{ sap_system_id: sap_system_id, - sid: application_sid, tenant: command.tenant, db_host: command.db_host, health: command.health