Skip to content

Commit

Permalink
Send explicit restoration events from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-suse committed Jul 27, 2023
1 parent cb0cee2 commit c50ee6b
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/trento/application/projectors/cluster_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ defmodule Trento.ClusterProjector do

TrentoWeb.Endpoint.broadcast(
"monitoring:clusters",
"cluster_registered",
"cluster_restored",
ClusterView.render("cluster_restored.json", cluster: restored_cluster)
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trento/application/projectors/database_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ defmodule Trento.DatabaseProjector do

TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_registered",
"database_restored",
SapSystemView.render("database_restored.json", database: database)
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trento/application/projectors/host_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ defmodule Trento.HostProjector do

TrentoWeb.Endpoint.broadcast(
"monitoring:hosts",
"host_registered",
"host_restored",
HostView.render("host_restored.json", host: host)
)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/trento/application/projectors/sap_system_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ defmodule Trento.SapSystemProjector do
sap_system =
SapSystemReadModel
|> Repo.get!(sap_system_id)
|> Repo.preload([:tags])
|> Repo.preload([:tags, :database_instances, :application_instances])

TrentoWeb.Endpoint.broadcast(
@sap_systems_topic,
"sap_system_registered",
"sap_system_restored",
SapSystemView.render("sap_system_restored.json", sap_system: sap_system)
)
end
Expand Down
6 changes: 1 addition & 5 deletions lib/trento_web/views/v1/sap_system_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ defmodule TrentoWeb.V1.SapSystemView do
end

def render("sap_system_restored.json", %{sap_system: sap_system}) do
sap_system
|> Map.from_struct()
|> Map.delete(:__meta__)
|> Map.delete(:database_instances)
|> Map.delete(:application_instances)
render("sap_system.json", sap_system: sap_system)
end

def render("sap_system_updated.json", %{id: id, ensa_version: ensa_version}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ defmodule Trento.ClusterProjectorTest do

assert nil == cluster_projection.deregistered_at

assert_broadcast "cluster_registered",
assert_broadcast "cluster_restored",
%{
cib_last_written: nil,
id: ^cluster_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ defmodule Trento.DatabaseProjectorTest do
assert nil == projection.deregistered_at
assert :passing == projection.health

assert_broadcast "database_registered",
assert_broadcast "database_restored",
%{
health: :passing,
id: ^sap_system_id,
Expand Down
2 changes: 1 addition & 1 deletion test/trento/application/projectors/host_projector_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ defmodule Trento.HostProjectorTest do

assert nil == deregistered_at

assert_broadcast "host_registered",
assert_broadcast "host_restored",
%{
agent_version: ^agent_version,
cluster_id: ^cluster_id,
Expand Down
16 changes: 15 additions & 1 deletion test/trento/application/projectors/sap_system_projector_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ defmodule Trento.SapSystemProjectorTest do
%{tenant: tenant, id: sap_system_id, sid: sid} =
insert(:sap_system, deregistered_at: DateTime.utc_now())

database_instance =
insert(:database_instance_without_host, sap_system_id: sap_system_id)
|> Map.from_struct()
|> Map.delete(:__meta__)
|> Map.delete(:host)

application_instance =
insert(:application_instance_without_host, sap_system_id: sap_system_id)
|> Map.from_struct()
|> Map.delete(:__meta__)
|> Map.delete(:host)

insert_list(5, :tag, resource_id: sap_system_id)

new_db_host = Faker.Internet.ip_v4_address()
Expand All @@ -261,13 +273,15 @@ defmodule Trento.SapSystemProjectorTest do
|> Repo.preload([:tags])

assert_broadcast(
"sap_system_registered",
"sap_system_restored",
%{
db_host: ^new_db_host,
health: ^new_health,
id: ^sap_system_id,
sid: ^sid,
tenant: ^tenant,
database_instances: [^database_instance],
application_instances: [^application_instance],
tags: ^tags
},
1000
Expand Down

0 comments on commit c50ee6b

Please sign in to comment.