Skip to content

Commit

Permalink
Add ability to mark instances as absent (#1731)
Browse files Browse the repository at this point in the history
* Mark hosts as absent on backend

* Revert changes to cluster

* Add tests and rework implementation

* Abstract repeated code into a private helper function

* Reordering tests

* Move test for initial conditions into pre-existing tests

* Separate database/application instance tests

* Refactor `update_instance()` to use pattern-matching

* Revert formatting

* Use namespaced `Kernel.struct()`

* Renaming

* Remove `SapSystem` namespace

* Remove redundant initialisation of default fields

* Renaming
  • Loading branch information
jamie-suse authored Aug 30, 2023
1 parent f574b4a commit 8a4da21
Show file tree
Hide file tree
Showing 12 changed files with 689 additions and 19 deletions.
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

0 comments on commit 8a4da21

Please sign in to comment.