diff --git a/lib/trento/application/usecases/sap_systems/dto/health_summary_dto.ex b/lib/trento/application/usecases/sap_systems/dto/health_summary_dto.ex index a982aaf18c..1f2838b12e 100644 --- a/lib/trento/application/usecases/sap_systems/dto/health_summary_dto.ex +++ b/lib/trento/application/usecases/sap_systems/dto/health_summary_dto.ex @@ -15,6 +15,8 @@ defmodule Trento.Application.UseCases.SapSystems.HealthSummaryDto do field :sapsystem_health, Ecto.Enum, values: Health.values() field :database_health, Ecto.Enum, values: Health.values() field :clusters_health, Ecto.Enum, values: Health.values() + field :cluster_id, Ecto.UUID + field :database_id, Ecto.UUID field :hosts_health, Ecto.Enum, values: [:passing, :critical, :unknown] end end diff --git a/lib/trento/application/usecases/sap_systems/health_summary_service.ex b/lib/trento/application/usecases/sap_systems/health_summary_service.ex index f28e5a57ed..521ab46d7c 100644 --- a/lib/trento/application/usecases/sap_systems/health_summary_service.ex +++ b/lib/trento/application/usecases/sap_systems/health_summary_service.ex @@ -48,7 +48,9 @@ defmodule Trento.SapSystems.HealthSummaryService do sapsystem_health: health, database_health: compute_database_health(database_instances), clusters_health: compute_clusters_health(all_instances), - hosts_health: compute_hosts_health(all_instances) + hosts_health: compute_hosts_health(all_instances), + cluster_id: extract_cluster_id(database_instances), + database_id: extract_database_id(database_instances) }) end @@ -70,6 +72,18 @@ defmodule Trento.SapSystems.HealthSummaryService do |> HealthService.compute_aggregated_health() end + @spec extract_database_id([DatabaseInstanceReadModel.t()]) :: String.t() + defp extract_database_id([]), do: nil + + defp extract_database_id([%DatabaseInstanceReadModel{sap_system_id: sap_system_id} | _]), + do: sap_system_id + + @spec extract_cluster_id([DatabaseInstanceReadModel.t()]) :: String.t() + defp extract_cluster_id([]), do: nil + + defp extract_cluster_id([%DatabaseInstanceReadModel{host: %{cluster_id: cluster_id}} | _]), + do: cluster_id + @spec clusters_from_instance(instance_list) :: [ClusterReadModel.t()] defp clusters_from_instance(instances) do instances diff --git a/test/support/factory.ex b/test/support/factory.ex index 3fe8838f05..d3fc886232 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -433,61 +433,4 @@ defmodule Trento.Factory do msg: Faker.StarWars.planet() } end - - def sap_system_with_cluster_and_hosts do - %ClusterReadModel{id: cluster_id} = - insert(:cluster, type: ClusterType.hana_scale_up(), health: Health.passing()) - - %ClusterReadModel{id: another_cluster_id} = - insert(:cluster, type: ClusterType.hana_scale_up(), health: Health.warning()) - - %HostReadModel{id: host_1_id} = insert(:host, cluster_id: cluster_id, heartbeat: :unknown) - - %HostReadModel{id: host_2_id} = - insert(:host, cluster_id: another_cluster_id, heartbeat: :passing) - - database_sid = "HDD" - - %SapSystemReadModel{ - id: sap_system_id, - sid: sid - } = insert(:sap_system, health: Health.passing()) - - insert( - :database_instance_without_host, - sap_system_id: sap_system_id, - sid: database_sid, - host_id: host_1_id, - health: Health.warning() - ) - - insert( - :database_instance_without_host, - sap_system_id: sap_system_id, - sid: database_sid, - host_id: host_2_id, - health: Health.critical() - ) - - insert( - :application_instance_without_host, - sap_system_id: sap_system_id, - sid: sid, - host_id: host_1_id, - health: Health.passing() - ) - - insert( - :application_instance_without_host, - sap_system_id: sap_system_id, - sid: sid, - host_id: host_2_id, - health: Health.warning() - ) - - %{ - sap_system_id: sap_system_id, - sid: sid - } - end end diff --git a/test/trento/application/usecases/health_summary_service_test.exs b/test/trento/application/usecases/health_summary_service_test.exs index 444050d776..23f6ec6ba7 100644 --- a/test/trento/application/usecases/health_summary_service_test.exs +++ b/test/trento/application/usecases/health_summary_service_test.exs @@ -8,6 +8,8 @@ defmodule Trento.HealthSummaryServiceTest do alias Trento.Application.UseCases.SapSystems.HealthSummaryDto alias Trento.SapSystems.HealthSummaryService + require Trento.Domain.Enums.Health, as: Health + require Trento.Domain.Enums.ClusterType, as: ClusterType alias Trento.{ HostReadModel, @@ -47,19 +49,43 @@ defmodule Trento.HealthSummaryServiceTest do end test "should determine health summary for a SAP System" do - %{ - sap_system_id: sap_system_id, + %Trento.ClusterReadModel{id: cluster_id} = + insert(:cluster, type: ClusterType.hana_scale_up(), health: Health.passing()) + + %Trento.HostReadModel{id: host_1_id} = + insert(:host, cluster_id: cluster_id, heartbeat: :unknown) + + %Trento.SapSystemReadModel{ + id: sap_system_id, sid: sid - } = sap_system_with_cluster_and_hosts() + } = insert(:sap_system, health: Health.critical()) + + insert( + :database_instance_without_host, + sap_system_id: sap_system_id, + sid: "HDD", + host_id: host_1_id, + health: Health.warning() + ) + + insert( + :application_instance_without_host, + sap_system_id: sap_system_id, + sid: sid, + host_id: host_1_id, + health: Health.critical() + ) assert [ %HealthSummaryDto{ id: ^sap_system_id, sid: ^sid, - sapsystem_health: :passing, - database_health: :critical, - clusters_health: :warning, - hosts_health: :unknown + sapsystem_health: :critical, + database_health: :warning, + clusters_health: :passing, + hosts_health: :unknown, + database_id: ^sap_system_id, + cluster_id: ^cluster_id } ] = HealthSummaryService.get_health_summary() end diff --git a/test/trento_web/controllers/health_overview_controller_test.exs b/test/trento_web/controllers/health_overview_controller_test.exs index 81e7164578..342cd78aaf 100644 --- a/test/trento_web/controllers/health_overview_controller_test.exs +++ b/test/trento_web/controllers/health_overview_controller_test.exs @@ -2,12 +2,36 @@ defmodule TrentoWeb.HealthOverviewControllerTest do use TrentoWeb.ConnCase, async: true import Trento.Factory + require Trento.Domain.Enums.Health, as: Health + require Trento.Domain.Enums.ClusterType, as: ClusterType test "should return the expected overview", %{conn: conn} do - %{ - sap_system_id: sap_system_id, + %Trento.ClusterReadModel{id: cluster_id} = + insert(:cluster, type: ClusterType.hana_scale_up(), health: Health.passing()) + + %Trento.HostReadModel{id: host_1_id} = + insert(:host, cluster_id: cluster_id, heartbeat: :unknown) + + %Trento.SapSystemReadModel{ + id: sap_system_id, sid: sid - } = sap_system_with_cluster_and_hosts() + } = insert(:sap_system, health: Health.critical()) + + insert( + :database_instance_without_host, + sap_system_id: sap_system_id, + sid: "HDD", + host_id: host_1_id, + health: Health.warning() + ) + + insert( + :application_instance_without_host, + sap_system_id: sap_system_id, + sid: sid, + host_id: host_1_id, + health: Health.critical() + ) conn = get(conn, Routes.health_overview_path(conn, :overview)) @@ -17,10 +41,12 @@ defmodule TrentoWeb.HealthOverviewControllerTest do %{ "id" => "#{sap_system_id}", "sid" => "#{sid}", - "sapsystem_health" => "passing", - "database_health" => "critical", - "clusters_health" => "warning", - "hosts_health" => "unknown" + "sapsystem_health" => "critical", + "database_health" => "warning", + "clusters_health" => "passing", + "hosts_health" => "unknown", + "database_id" => "#{sap_system_id}", + "cluster_id" => "#{cluster_id}" } ] == json_response(conn, 200) end