From 7b5deb95b29483a94bc7cfc24bb20fd0365e8bdc Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Tue, 20 Jun 2023 12:13:21 +0200 Subject: [PATCH 1/3] Deregistered host allows Rollup command --- lib/trento/domain/host/host.ex | 20 ++++++++++---------- test/trento/domain/host/host_test.exs | 10 +++++++++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/trento/domain/host/host.ex b/lib/trento/domain/host/host.ex index b83d2286c6..d50b3cd08e 100644 --- a/lib/trento/domain/host/host.ex +++ b/lib/trento/domain/host/host.ex @@ -197,6 +197,16 @@ defmodule Trento.Domain.Host do ] end + def execute( + %Host{host_id: host_id} = snapshot, + %RollUpHost{} + ) do + %HostRollUpRequested{ + host_id: host_id, + snapshot: snapshot + } + end + def execute( %Host{deregistered_at: deregistered_at}, _ @@ -315,16 +325,6 @@ defmodule Trento.Domain.Host do } end - def execute( - %Host{host_id: host_id} = snapshot, - %RollUpHost{} - ) do - %HostRollUpRequested{ - host_id: host_id, - snapshot: snapshot - } - end - def execute( %Host{host_id: host_id}, %RequestHostDeregistration{requested_at: requested_at} diff --git a/test/trento/domain/host/host_test.exs b/test/trento/domain/host/host_test.exs index 9106bf937e..c5e7e5ce56 100644 --- a/test/trento/domain/host/host_test.exs +++ b/test/trento/domain/host/host_test.exs @@ -744,7 +744,6 @@ defmodule Trento.HostTest do commands_to_reject = [ %DeregisterHost{}, %RequestHostDeregistration{}, - %RollUpHost{}, %UpdateHeartbeat{}, %UpdateProvider{}, %UpdateSlesSubscriptions{} @@ -753,6 +752,15 @@ defmodule Trento.HostTest do for command <- commands_to_reject do assert_error(initial_events, command, {:error, :host_not_registered}) end + + commands_to_accept = [ + %RollUpHost{} + ] + + for command <- commands_to_accept do + assert match?({:ok, _, _}, aggregate_run(initial_events, command)), + "Command #{inspect(command)} should be accepted by a deregistered host" + end end test "should emit the HostDeregistered and HostTombstoned events" do From bb77796ca6f32a7942924130e24cd9b75aa43529 Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Tue, 20 Jun 2023 12:15:33 +0200 Subject: [PATCH 2/3] Deregistered cluster allow rollup command --- lib/trento/domain/cluster/cluster.ex | 20 ++++++++++---------- test/trento/domain/cluster/cluster_test.exs | 10 +++++++++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/trento/domain/cluster/cluster.ex b/lib/trento/domain/cluster/cluster.ex index 9bbc561eda..64f46c3f00 100644 --- a/lib/trento/domain/cluster/cluster.ex +++ b/lib/trento/domain/cluster/cluster.ex @@ -247,6 +247,16 @@ defmodule Trento.Domain.Cluster do |> maybe_update_cluster(command) end + def execute( + %Cluster{cluster_id: cluster_id} = snapshot, + %RollUpCluster{} + ) do + %ClusterRollUpRequested{ + cluster_id: cluster_id, + snapshot: snapshot + } + end + def execute(%Cluster{deregistered_at: deregistered_at}, _) when not is_nil(deregistered_at), do: {:error, :cluster_not_registered} @@ -311,16 +321,6 @@ defmodule Trento.Domain.Cluster do |> Multi.execute(&maybe_emit_cluster_health_changed_event/1) end - def execute( - %Cluster{cluster_id: cluster_id} = snapshot, - %RollUpCluster{} - ) do - %ClusterRollUpRequested{ - cluster_id: cluster_id, - snapshot: snapshot - } - end - def execute( %Cluster{cluster_id: cluster_id} = cluster, %DeregisterClusterHost{ diff --git a/test/trento/domain/cluster/cluster_test.exs b/test/trento/domain/cluster/cluster_test.exs index 5e51ba6d85..9a58b70189 100644 --- a/test/trento/domain/cluster/cluster_test.exs +++ b/test/trento/domain/cluster/cluster_test.exs @@ -914,7 +914,6 @@ defmodule Trento.ClusterTest do commands_to_reject = [ %CompleteChecksExecution{}, %DeregisterClusterHost{}, - %RollUpCluster{}, %SelectChecks{}, %RegisterClusterHost{} ] @@ -923,6 +922,15 @@ defmodule Trento.ClusterTest do assert match?({:error, :cluster_not_registered}, aggregate_run(initial_events, command)), "Command #{inspect(command)} should be rejected by the aggregate" end + + commands_to_accept = [ + %RollUpCluster{} + ] + + for command <- commands_to_accept do + assert match?({:ok, _, _}, aggregate_run(initial_events, command)), + "Command #{inspect(command)} should be accepted by a deregistered cluster" + end end test "should emit the HostRemovedFromCluster event after a DeregisterClusterHost command and remove the host from the cluster aggregate state" do From ba936e94a60257e0b15ba5431782b5c167f7e1bb Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Tue, 20 Jun 2023 12:17:11 +0200 Subject: [PATCH 3/3] Deregistered sap system allows rollup --- lib/trento/domain/sap_system/sap_system.ex | 16 ++++++++-------- .../trento/domain/sap_system/sap_system_test.exs | 15 ++------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/lib/trento/domain/sap_system/sap_system.ex b/lib/trento/domain/sap_system/sap_system.ex index 020785dc55..43894ab599 100644 --- a/lib/trento/domain/sap_system/sap_system.ex +++ b/lib/trento/domain/sap_system/sap_system.ex @@ -277,14 +277,6 @@ defmodule Trento.Domain.SapSystem do |> Multi.execute(&maybe_emit_sap_system_tombstoned_event/1) end - def execute( - %SapSystem{deregistered_at: deregistered_at}, - _ - ) - when not is_nil(deregistered_at) do - {:error, :sap_system_not_registered} - end - def execute( %SapSystem{sap_system_id: sap_system_id} = snapshot, %RollUpSapSystem{} @@ -295,6 +287,14 @@ defmodule Trento.Domain.SapSystem do } end + def execute( + %SapSystem{deregistered_at: deregistered_at}, + _ + ) + when not is_nil(deregistered_at) do + {:error, :sap_system_not_registered} + end + def apply( %SapSystem{sap_system_id: nil}, %DatabaseRegistered{ diff --git a/test/trento/domain/sap_system/sap_system_test.exs b/test/trento/domain/sap_system/sap_system_test.exs index b12889d9f8..be1b51b7ab 100644 --- a/test/trento/domain/sap_system/sap_system_test.exs +++ b/test/trento/domain/sap_system/sap_system_test.exs @@ -1794,25 +1794,14 @@ defmodule Trento.SapSystemTest do build(:register_database_instance_command), build(:register_application_instance_command), build(:deregister_database_instance_command, sap_system_id: sap_system_id), - build(:deregister_application_instance_command, sap_system_id: sap_system_id) + build(:deregister_application_instance_command, sap_system_id: sap_system_id), + build(:rollup_sap_system_command) ] for command <- commands_to_accept do assert match?({:ok, _, _}, aggregate_run(initial_events, command)), "Command #{inspect(command)} should be accepted by a deregistered SAP system" end - - commands_to_reject = [ - build(:rollup_sap_system_command) - ] - - for command <- commands_to_reject do - assert match?( - {:error, :sap_system_not_registered}, - aggregate_run(initial_events, command) - ), - "Command #{inspect(command)} should be rejected by a deregistered SAP system" - end end test "should deregister a Database and SAP system when the Primary database instance is removed" do