Skip to content

Commit

Permalink
Add Host Check Selection Domain logic
Browse files Browse the repository at this point in the history
Co-authored-by: Eugen Maksymenko <eugen.maksymenko@suse.com>
  • Loading branch information
nelsonkopliku and EMaksy committed Jun 15, 2023
1 parent 703ab7d commit 02b0e06
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/trento/domain/host/commands/select_host_checks.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Trento.Domain.Commands.SelectHostChecks do
@moduledoc """
Select the checks to be executed on a host.
"""

@required_fields :all

use Trento.Command

defcommand do
field :host_id, Ecto.UUID
field :checks, {:array, :string}
end
end
12 changes: 12 additions & 0 deletions lib/trento/domain/host/events/host_checks_selected.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule Trento.Domain.Events.HostChecksSelected do
@moduledoc """
Event of the checks selected for a host.
"""

use Trento.Event

defevent do
field :host_id, Ecto.UUID
field :checks, {:array, :string}
end
end
29 changes: 29 additions & 0 deletions lib/trento/domain/host/host.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ defmodule Trento.Domain.Host do
alias Trento.Domain.Commands.{
RegisterHost,
RollUpHost,
SelectHostChecks,
UpdateHeartbeat,
UpdateProvider,
UpdateSlesSubscriptions
Expand All @@ -39,6 +40,7 @@ defmodule Trento.Domain.Host do
alias Trento.Domain.Events.{
HeartbeatFailed,
HeartbeatSucceded,
HostChecksSelected,
HostDetailsUpdated,
HostRegistered,
HostRolledUp,
Expand Down Expand Up @@ -66,6 +68,7 @@ defmodule Trento.Domain.Host do
field :installation_source, Ecto.Enum, values: [:community, :suse, :unknown]
field :heartbeat, Ecto.Enum, values: [:passing, :critical, :unknown]
field :rolling_up, :boolean, default: false
field :selected_checks, {:array, :string}, default: []

embeds_many :subscriptions, SlesSubscription

Expand Down Expand Up @@ -267,6 +270,20 @@ defmodule Trento.Domain.Host do
}
end

def execute(
%Host{
host_id: host_id
},
%SelectHostChecks{
checks: selected_checks
}
) do
%HostChecksSelected{
host_id: host_id,
checks: selected_checks
}
end

def apply(
%Host{} = host,
%HostRegistered{
Expand Down Expand Up @@ -373,4 +390,16 @@ defmodule Trento.Domain.Host do
}) do
snapshot
end

def apply(
%Host{} = host,
%HostChecksSelected{
checks: selected_checks
}
) do
%Host{
host
| selected_checks: selected_checks
}
end
end
4 changes: 3 additions & 1 deletion lib/trento/infrastructure/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule Trento.Router do
RollUpHost,
RollUpSapSystem,
SelectChecks,
SelectHostChecks,
UpdateHeartbeat,
UpdateProvider,
UpdateSlesSubscriptions
Expand All @@ -33,7 +34,8 @@ defmodule Trento.Router do
UpdateHeartbeat,
UpdateProvider,
UpdateSlesSubscriptions,
RollUpHost
RollUpHost,
SelectHostChecks
],
to: Host,
lifespan: Host.Lifespan
Expand Down

0 comments on commit 02b0e06

Please sign in to comment.