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

Omit an unnecessary query when requesting cluster checks execution #3159

Merged
merged 2 commits into from
Nov 25, 2024
Merged
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
59 changes: 27 additions & 32 deletions lib/trento/clusters.ex
Original file line number Diff line number Diff line change
Expand Up @@ -148,40 +148,18 @@ defmodule Trento.Clusters do
|> select_merge([c, e], %{cib_last_written: e.cib_last_written})
end

defp get_filesystem_type(cluster_id) do
query =
from(c in ClusterReadModel,
where:
c.id == ^cluster_id and c.type == ^ClusterType.ascs_ers() and is_nil(c.deregistered_at)
)

filesystems_list =
query
|> Repo.one!()
|> Map.get(:details, %{})
|> Map.get("sap_systems", [])
|> Enum.map(fn %{"filesystem_resource_based" => filesystem_resource_based} ->
filesystem_resource_based
end)
|> Enum.uniq()

case filesystems_list do
[true] -> FilesystemType.resource_managed()
[false] -> FilesystemType.simple_mount()
_ -> FilesystemType.mixed_fs_types()
end
end

defp maybe_request_checks_execution(%ClusterReadModel{selected_checks: []}),
do: {:error, :no_checks_selected}

defp maybe_request_checks_execution(%ClusterReadModel{
id: cluster_id,
provider: provider,
type: ClusterType.ascs_ers(),
additional_sids: cluster_sids,
selected_checks: selected_checks
}) do
defp maybe_request_checks_execution(
%ClusterReadModel{
id: cluster_id,
provider: provider,
type: ClusterType.ascs_ers(),
additional_sids: cluster_sids,
selected_checks: selected_checks
} = cluster
) do
hosts_data =
Repo.all(
from h in HostReadModel,
Expand All @@ -203,7 +181,7 @@ defmodule Trento.Clusters do
provider: provider,
cluster_type: ClusterType.ascs_ers(),
ensa_version: aggregated_ensa_version,
filesystem_type: get_filesystem_type(cluster_id)
filesystem_type: get_filesystem_type(cluster)
}

Checks.request_execution(
Expand Down Expand Up @@ -248,6 +226,23 @@ defmodule Trento.Clusters do

defp maybe_request_checks_execution(error), do: error

defp get_filesystem_type(%ClusterReadModel{} = cluster) do
filesystems_list =
cluster
|> Map.get(:details, %{})
|> Map.get("sap_systems", [])
|> Enum.map(fn %{"filesystem_resource_based" => filesystem_resource_based} ->
filesystem_resource_based
end)
|> Enum.uniq()

case filesystems_list do
[true] -> FilesystemType.resource_managed()
[false] -> FilesystemType.simple_mount()
_ -> FilesystemType.mixed_fs_types()
end
end

@spec get_cluster_ensa_version([String.t()]) :: ClusterEnsaVersion.t()
defp get_cluster_ensa_version(sap_system_ids) do
ensa_versions =
Expand Down
Loading