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

Discover angi architecture #2761

Merged
merged 9 commits into from
Jul 10, 2024
7 changes: 7 additions & 0 deletions lib/trento/clusters/enums/hana_architecture_type.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule Trento.Clusters.Enums.HanaArchitectureType do
@moduledoc """
Type that represents the supported HANA architecture types.
"""

use Trento.Support.Enum, values: [:classic, :angi]
end
3 changes: 3 additions & 0 deletions lib/trento/clusters/value_objects/hana_cluster_details.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ defmodule Trento.Clusters.ValueObjects.HanaClusterDetails do

use Trento.Support.Type

require Trento.Clusters.Enums.HanaArchitectureType, as: HanaArchitectureType

alias Trento.Clusters.ValueObjects.{
ClusterResource,
HanaClusterNode,
Expand All @@ -20,6 +22,7 @@ defmodule Trento.Clusters.ValueObjects.HanaClusterDetails do
}

deftype do
field :architecture_type, Ecto.Enum, values: HanaArchitectureType.values()
field :system_replication_mode, :string
field :system_replication_operation_mode, :string
field :secondary_sync_state, :string
Expand Down
53 changes: 47 additions & 6 deletions lib/trento/discovery/payloads/cluster/cluster_discovery_payload.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ defmodule Trento.Discovery.Payloads.Cluster.ClusterDiscoveryPayload do
"""

@required_fields [:dc, :provider, :id, :cluster_type]
@required_fields_hana [:sid]
@required_fields_hana [:sid, :hana_architecture_type]
@required_fields_ascs_ers [:additional_sids]

use Trento.Support.Type

require Trento.Enums.Provider, as: Provider
require Trento.Clusters.Enums.ClusterType, as: ClusterType
require Trento.Clusters.Enums.HanaArchitectureType, as: HanaArchitectureType

alias Trento.Discovery.Payloads.Cluster.{
CibDiscoveryPayload,
Expand All @@ -28,6 +29,7 @@ defmodule Trento.Discovery.Payloads.Cluster.ClusterDiscoveryPayload do
field :id, :string
field :name, :string
field :cluster_type, Ecto.Enum, values: ClusterType.values()
field :hana_architecture_type, Ecto.Enum, values: HanaArchitectureType.values()
field :sid, :string
field :additional_sids, {:array, :string}

Expand All @@ -41,6 +43,7 @@ defmodule Trento.Discovery.Payloads.Cluster.ClusterDiscoveryPayload do
attrs
|> enrich_cluster_type
|> enrich_cluster_sid
|> enrich_hana_architecture_type

cluster
|> cast(enriched_attributes, fields())
Expand All @@ -66,6 +69,19 @@ defmodule Trento.Discovery.Payloads.Cluster.ClusterDiscoveryPayload do
|> Map.put("additional_sids", parse_cluster_additional_sids(attrs))
end

defp enrich_hana_architecture_type(%{"cluster_type" => cluster_type} = attrs)
arbulu89 marked this conversation as resolved.
Show resolved Hide resolved
when cluster_type in [ClusterType.hana_scale_up(), ClusterType.hana_scale_out()] do
hana_architecture_type =
case parse_hana_glob_topology(attrs) do
nil -> HanaArchitectureType.classic()
_ -> HanaArchitectureType.angi()
end

Map.put(attrs, "hana_architecture_type", hana_architecture_type)
end

defp enrich_hana_architecture_type(attrs), do: attrs

defp parse_cluster_type(%{"crmmon" => %{"clones" => nil, "groups" => nil}}),
do: ClusterType.unknown()

Expand All @@ -80,7 +96,9 @@ defmodule Trento.Discovery.Payloads.Cluster.ClusterDiscoveryPayload do
do_detect_cluster_type(sap_instance_count)
end

defp parse_cluster_type(%{"crmmon" => %{"clones" => clones}}) do
defp parse_cluster_type(%{"crmmon" => %{"clones" => clones}} = payload) do
has_hana_glop_topology = parse_hana_glob_topology(payload)

has_sap_hana_topology =
Enum.any?(clones, fn %{"resources" => resources} ->
Enum.any?(resources, fn %{"agent" => agent} -> agent == "ocf::suse:SAPHanaTopology" end)
Expand All @@ -98,14 +116,37 @@ defmodule Trento.Discovery.Payloads.Cluster.ClusterDiscoveryPayload do
end)
end)

do_detect_cluster_type(has_sap_hana_topology, has_sap_hana, has_sap_hana_controller)
do_detect_cluster_type(
arbulu89 marked this conversation as resolved.
Show resolved Hide resolved
has_hana_glop_topology,
has_sap_hana_topology,
has_sap_hana,
has_sap_hana_controller
)
end

defp parse_cluster_type(_), do: ClusterType.unknown()

defp do_detect_cluster_type(true, true, _), do: ClusterType.hana_scale_up()
defp do_detect_cluster_type(true, _, true), do: ClusterType.hana_scale_out()
defp do_detect_cluster_type(_, _, _), do: ClusterType.unknown()
defp parse_hana_glob_topology(%{
arbulu89 marked this conversation as resolved.
Show resolved Hide resolved
"cib" => %{
"configuration" => %{"crm_config" => %{"cluster_properties" => cluster_properties}}
}
}) do
Enum.find_value(cluster_properties, nil, fn
%{"name" => name, "value" => value} ->
if String.ends_with?(name, "_glob_topology"), do: value

_ ->
nil
end)
end

# Angi architecture
defp do_detect_cluster_type("ScaleUp", _, _, _), do: ClusterType.hana_scale_up()
defp do_detect_cluster_type("ScaleOut", _, _, _), do: ClusterType.hana_scale_out()
# Classic architecture
defp do_detect_cluster_type(_, true, true, _), do: ClusterType.hana_scale_up()
defp do_detect_cluster_type(_, true, _, true), do: ClusterType.hana_scale_out()
defp do_detect_cluster_type(_, _, _, _), do: ClusterType.unknown()

defp do_detect_cluster_type(count) when count >= 2 and rem(count, 2) == 0,
do: ClusterType.ascs_ers()
Expand Down
Loading