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

Handle requests for software updates discoveries from Host aggregate #2507

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this 2nd argument be nil here?
I mean, I understood that in this circunstance we don't want to emit the Cleared event, but if the new fqdn is nil, and we had a value before (current), it would be emitted, or not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I guess I missed that test.
Here we go #2518
Thanks!

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
Loading