Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to mark instances as absent #1731

Merged
merged 14 commits into from
Aug 30, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defmodule Trento.Integration.Discovery.SapSystemPolicy do
alias Trento.Domain.Commands.{
DeregisterApplicationInstance,
DeregisterDatabaseInstance,
MarkApplicationInstanceAbsent,
MarkDatabaseInstanceAbsent,
RegisterApplicationInstance,
RegisterDatabaseInstance
}
Expand Down Expand Up @@ -146,21 +148,19 @@ defmodule Trento.Integration.Discovery.SapSystemPolicy do
defp build_deregister_instances_commands(current_instances) do
Enum.map(current_instances, fn
%ApplicationInstanceReadModel{} = instance ->
DeregisterApplicationInstance.new!(%{
sid: instance.sid,
MarkApplicationInstanceAbsent.new!(%{
host_id: instance.host_id,
instance_number: instance.instance_number,
sap_system_id: instance.sap_system_id,
deregistered_at: DateTime.utc_now()
absent_at: DateTime.utc_now()
})

%DatabaseInstanceReadModel{} = instance ->
DeregisterDatabaseInstance.new!(%{
sid: instance.sid,
MarkDatabaseInstanceAbsent.new!(%{
host_id: instance.host_id,
instance_number: instance.instance_number,
sap_system_id: instance.sap_system_id,
deregistered_at: DateTime.utc_now()
absent_at: DateTime.utc_now()
})
end)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Trento.Domain.Commands.MarkApplicationInstanceAbsent do
@moduledoc """
Mark an application instance as absent
"""
@required_fields :all

use Trento.Command

defcommand do
field :instance_number, :string
field :host_id, Ecto.UUID
field :sap_system_id, Ecto.UUID
field :absent_at, :utc_datetime_usec
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Trento.Domain.Commands.MarkDatabaseInstanceAbsent do
@moduledoc """
Mark a database instance as absent
"""
@required_fields :all

use Trento.Command

defcommand do
field :instance_number, :string
field :host_id, Ecto.UUID
field :sap_system_id, Ecto.UUID
field :absent_at, :utc_datetime_usec
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Trento.Domain.Events.ApplicationInstanceMarkedAbsent do
@moduledoc """
This event is emitted when an application instance is marked as absent from the SAP system.
"""

use Trento.Event

defevent do
field :instance_number, :string
field :host_id, Ecto.UUID
field :sap_system_id, Ecto.UUID
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
@@ -0,0 +1,14 @@
defmodule Trento.Domain.Events.DatabaseInstanceMarkedAbsent do
@moduledoc """
This event is emitted when a database instance is marked as absent from the SAP system.
"""

use Trento.Event

defevent do
field :instance_number, :string
field :host_id, Ecto.UUID
field :sap_system_id, Ecto.UUID
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
1 change: 1 addition & 0 deletions lib/trento/domain/sap_system/instance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +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_at, :utc_datetime_usec
end
end
Loading