Skip to content

Commit

Permalink
Handle requests for software updates discoveries from Host aggregate (#…
Browse files Browse the repository at this point in the history
…2507)

* Handle requests for software updates discoveries from Host aggregate

* Improve tests coverage for software updates discovery domain logic

* Remove Multi usage when emitting software updates discovery events
  • Loading branch information
nelsonkopliku authored Apr 12, 2024
1 parent d63407f commit b3a7b64
Show file tree
Hide file tree
Showing 3 changed files with 400 additions and 72 deletions.
107 changes: 70 additions & 37 deletions lib/trento/hosts/host.ex
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,21 @@ defmodule Trento.Hosts.Host do
installation_source: installation_source
}
) do
%HostRegistered{
host_id: host_id,
hostname: hostname,
ip_addresses: ip_addresses,
agent_version: agent_version,
cpu_count: cpu_count,
total_memory_mb: total_memory_mb,
socket_count: socket_count,
os_version: os_version,
installation_source: installation_source,
fully_qualified_domain_name: fully_qualified_domain_name,
heartbeat: :unknown
}
[
%HostRegistered{
host_id: host_id,
hostname: hostname,
ip_addresses: ip_addresses,
agent_version: agent_version,
cpu_count: cpu_count,
total_memory_mb: total_memory_mb,
socket_count: socket_count,
os_version: os_version,
installation_source: installation_source,
fully_qualified_domain_name: fully_qualified_domain_name,
heartbeat: :unknown
}
] ++ maybe_emit_software_updates_discovery_events(host_id, nil, fully_qualified_domain_name)
end

# Reject all the commands, except for the registration ones when the host_id does not exists
Expand Down Expand Up @@ -223,15 +225,16 @@ defmodule Trento.Hosts.Host do
}
)
when not is_nil(deregistered_at) do
%HostRestored{
host_id: host_id
}
[
%HostRestored{host_id: host_id}
] ++ maybe_emit_software_updates_discovery_events(host_id, nil, fully_qualified_domain_name)
end

def execute(
%Host{
host_id: host_id,
deregistered_at: deregistered_at
deregistered_at: deregistered_at,
fully_qualified_domain_name: current_fully_qualified_domain_name
},
%RegisterHost{
hostname: hostname,
Expand All @@ -241,15 +244,13 @@ defmodule Trento.Hosts.Host do
total_memory_mb: total_memory_mb,
socket_count: socket_count,
os_version: os_version,
fully_qualified_domain_name: fully_qualified_domain_name,
fully_qualified_domain_name: new_fully_qualified_domain_name,
installation_source: installation_source
}
)
when not is_nil(deregistered_at) do
[
%HostRestored{
host_id: host_id
},
%HostRestored{host_id: host_id},
%HostDetailsUpdated{
host_id: host_id,
hostname: hostname,
Expand All @@ -259,10 +260,15 @@ defmodule Trento.Hosts.Host do
total_memory_mb: total_memory_mb,
socket_count: socket_count,
os_version: os_version,
fully_qualified_domain_name: fully_qualified_domain_name,
fully_qualified_domain_name: new_fully_qualified_domain_name,
installation_source: installation_source
}
]
] ++
maybe_emit_software_updates_discovery_events(
host_id,
current_fully_qualified_domain_name,
new_fully_qualified_domain_name
)
end

def execute(
Expand Down Expand Up @@ -312,11 +318,13 @@ defmodule Trento.Hosts.Host do
end

def execute(
%Host{},
%Host{
fully_qualified_domain_name: current_fully_qualified_domain_name
},
%RegisterHost{
host_id: host_id,
hostname: hostname,
fully_qualified_domain_name: fully_qualified_domain_name,
fully_qualified_domain_name: new_fully_qualified_domain_name,
ip_addresses: ip_addresses,
agent_version: agent_version,
cpu_count: cpu_count,
Expand All @@ -326,18 +334,25 @@ defmodule Trento.Hosts.Host do
installation_source: installation_source
}
) do
%HostDetailsUpdated{
host_id: host_id,
hostname: hostname,
fully_qualified_domain_name: fully_qualified_domain_name,
ip_addresses: ip_addresses,
agent_version: agent_version,
cpu_count: cpu_count,
total_memory_mb: total_memory_mb,
socket_count: socket_count,
os_version: os_version,
installation_source: installation_source
}
[
%HostDetailsUpdated{
host_id: host_id,
hostname: hostname,
fully_qualified_domain_name: new_fully_qualified_domain_name,
ip_addresses: ip_addresses,
agent_version: agent_version,
cpu_count: cpu_count,
total_memory_mb: total_memory_mb,
socket_count: socket_count,
os_version: os_version,
installation_source: installation_source
}
] ++
maybe_emit_software_updates_discovery_events(
host_id,
current_fully_qualified_domain_name,
new_fully_qualified_domain_name
)
end

def execute(
Expand Down Expand Up @@ -827,6 +842,24 @@ defmodule Trento.Hosts.Host do
end
end

def maybe_emit_software_updates_discovery_events(_host_id, nil, nil), do: []
def maybe_emit_software_updates_discovery_events(_host_id, fqdn, fqdn), do: []

def maybe_emit_software_updates_discovery_events(host_id, _old_fqdn, nil),
do: [
%SoftwareUpdatesDiscoveryCleared{
host_id: host_id
}
]

def maybe_emit_software_updates_discovery_events(host_id, _old_fqdn, new_fqdn),
do: [
%SoftwareUpdatesDiscoveryRequested{
host_id: host_id,
fully_qualified_domain_name: new_fqdn
}
]

defp compute_saptune_health(nil), do: Health.warning()

defp compute_saptune_health(%{package_version: package_version, tuning_state: tuning_state}) do
Expand Down
3 changes: 2 additions & 1 deletion test/support/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,8 @@ defmodule Trento.Factory do
total_memory_mb: Enum.random(1..128),
socket_count: Enum.random(1..16),
os_version: Faker.App.semver(),
installation_source: Enum.random([:community, :suse, :unknown])
installation_source: Enum.random([:community, :suse, :unknown]),
fully_qualified_domain_name: Faker.Internet.domain_name()
})
end

Expand Down
Loading

0 comments on commit b3a7b64

Please sign in to comment.