Skip to content

Commit

Permalink
Add tests and rework implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-suse committed Aug 29, 2023
1 parent c345e99 commit 2b76bce
Show file tree
Hide file tree
Showing 16 changed files with 571 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ defmodule Trento.Integration.Discovery.SapSystemPolicy do
host_id: instance.host_id,
instance_number: instance.instance_number,
sap_system_id: instance.sap_system_id,
absent: DateTime.utc_now()
absent_at: DateTime.utc_now()
})

%DatabaseInstanceReadModel{} = instance ->
MarkDatabaseInstanceAbsent.new!(%{
host_id: instance.host_id,
instance_number: instance.instance_number,
sap_system_id: instance.sap_system_id,
absent: DateTime.utc_now()
absent_at: DateTime.utc_now()
})
end)
end
Expand Down
50 changes: 0 additions & 50 deletions lib/trento/application/projectors/database_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ defmodule Trento.DatabaseProjector do
DatabaseDeregistered,
DatabaseHealthChanged,
DatabaseInstanceDeregistered,
DatabaseInstanceMarkedAbsent,
DatabaseInstanceHealthChanged,
DatabaseInstanceRegistered,
DatabaseInstanceSystemReplicationChanged,
Expand Down Expand Up @@ -174,29 +173,6 @@ defmodule Trento.DatabaseProjector do
end
)

project(
%DatabaseInstanceMarkedAbsent{
instance_number: instance_number,
host_id: host_id,
sap_system_id: sap_system_id,
absent: absent
},
fn multi ->
changeset =
DatabaseInstanceReadModel
|> Repo.get_by(
sap_system_id: sap_system_id,
instance_number: instance_number,
host_id: host_id
)
|> DatabaseInstanceReadModel.changeset(%{
absent: absent
})

Ecto.Multi.update(multi, :database_instance, changeset)
end
)

project(
%DatabaseInstanceDeregistered{
instance_number: instance_number,
Expand Down Expand Up @@ -345,32 +321,6 @@ defmodule Trento.DatabaseProjector do
)
end

@impl true
def after_update(
%DatabaseInstanceMarkedAbsent{
instance_number: instance_number,
host_id: host_id,
sap_system_id: sap_system_id,
absent: absent
},
_,
%{
database_instance: %DatabaseInstanceReadModel{sid: sid}
}
) do
TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_instance_marked_absent",
SapSystemView.render("instance_marked_absent.json",
instance_number: instance_number,
host_id: host_id,
sap_system_id: sap_system_id,
sid: sid,
absent: absent
)
)
end

@impl true
def after_update(
%DatabaseDeregistered{
Expand Down
50 changes: 0 additions & 50 deletions lib/trento/application/projectors/sap_system_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ defmodule Trento.SapSystemProjector do
alias Trento.Domain.Events.{
ApplicationInstanceDeregistered,
ApplicationInstanceHealthChanged,
ApplicationInstanceMarkedAbsent,
ApplicationInstanceMoved,
ApplicationInstanceRegistered,
SapSystemDeregistered,
Expand Down Expand Up @@ -180,29 +179,6 @@ defmodule Trento.SapSystemProjector do
end
)

project(
%ApplicationInstanceMarkedAbsent{
instance_number: instance_number,
host_id: host_id,
sap_system_id: sap_system_id,
absent: absent
},
fn multi ->
changeset =
ApplicationInstanceReadModel
|> Repo.get_by(
sap_system_id: sap_system_id,
instance_number: instance_number,
host_id: host_id
)
|> ApplicationInstanceReadModel.changeset(%{
absent: absent
})

Ecto.Multi.update(multi, :application_instance, changeset)
end
)

project(
%ApplicationInstanceDeregistered{
instance_number: instance_number,
Expand Down Expand Up @@ -372,32 +348,6 @@ defmodule Trento.SapSystemProjector do
)
end

@impl true
def after_update(
%ApplicationInstanceMarkedAbsent{
instance_number: instance_number,
host_id: host_id,
sap_system_id: sap_system_id,
absent: absent
},
_,
%{
application_instance: %ApplicationInstanceReadModel{sid: sid}
}
) do
TrentoWeb.Endpoint.broadcast(
@sap_systems_topic,
"application_instance_marked_absent",
SapSystemView.render("instance_marked_absent.json",
instance_number: instance_number,
host_id: host_id,
sap_system_id: sap_system_id,
sid: sid,
absent: absent
)
)
end

@impl true
def after_update(
%ApplicationInstanceDeregistered{
Expand Down
1 change: 0 additions & 1 deletion lib/trento/application/read_models/host_read_model.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ defmodule Trento.HostReadModel do
field :last_heartbeat_timestamp, :utc_datetime_usec, virtual: true

field :deregistered_at, :utc_datetime_usec
field :absent, :utc_datetime_usec
end

@spec changeset(t() | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Trento.Domain.Commands.MarkApplicationInstanceAbsent do
@moduledoc """
Mark an application instance as absent from the monitoring system.
Mark an application instance as absent
"""
@required_fields :all

Expand All @@ -10,6 +10,6 @@ defmodule Trento.Domain.Commands.MarkApplicationInstanceAbsent do
field :instance_number, :string
field :host_id, Ecto.UUID
field :sap_system_id, Ecto.UUID
field :absent, :utc_datetime_usec
field :absent_at, :utc_datetime_usec
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Trento.Domain.Commands.MarkDatabaseInstanceAbsent do
@moduledoc """
Mark a database instance as absent from the monitoring system.
Mark a database instance as absent
"""
@required_fields :all

Expand All @@ -10,6 +10,6 @@ defmodule Trento.Domain.Commands.MarkDatabaseInstanceAbsent do
field :instance_number, :string
field :host_id, Ecto.UUID
field :sap_system_id, Ecto.UUID
field :absent, :utc_datetime_usec
field :absent_at, :utc_datetime_usec
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ defmodule Trento.Domain.Events.ApplicationInstanceMarkedAbsent do
field :instance_number, :string
field :host_id, Ecto.UUID
field :sap_system_id, Ecto.UUID
field :absent, :utc_datetime_usec
field :absent_at, :utc_datetime_usec
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Trento.Domain.Events.ApplicationInstanceMarkedPresent do
@moduledoc """
This event is emitted when an application instance is marked as present in the SAP system.
"""

use Trento.Event

defevent do
field :instance_number, :string
field :host_id, Ecto.UUID
field :sap_system_id, Ecto.UUID
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ defmodule Trento.Domain.Events.DatabaseInstanceMarkedAbsent do
field :instance_number, :string
field :host_id, Ecto.UUID
field :sap_system_id, Ecto.UUID
field :absent, :utc_datetime_usec
field :absent_at, :utc_datetime_usec
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Trento.Domain.Events.DatabaseInstanceMarkedPresent do
@moduledoc """
This event is emitted when a database instance is marked as present in the SAP system.
"""

use Trento.Event

defevent do
field :instance_number, :string
field :host_id, Ecto.UUID
field :sap_system_id, Ecto.UUID
end
end
2 changes: 1 addition & 1 deletion lib/trento/domain/sap_system/instance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ defmodule Trento.Domain.SapSystem.Instance do
field :health, Ecto.Enum, values: Health.values()
field :system_replication, :string
field :system_replication_status, :string
field :absent, :utc_datetime_usec
field :absent_at, :utc_datetime_usec
end
end
Loading

0 comments on commit 2b76bce

Please sign in to comment.