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

Cluster node status #2341

Merged
merged 4 commits into from
Feb 22, 2024
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
1 change: 1 addition & 0 deletions lib/trento/clusters/value_objects/ascs_ers_cluster_node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule Trento.Clusters.ValueObjects.AscsErsClusterNode do
field :virtual_ips, {:array, :string}
field :filesystems, {:array, :string}
field :attributes, {:map, :string}
field :status, :string

embeds_many :resources, ClusterResource
end
Expand Down
1 change: 1 addition & 0 deletions lib/trento/clusters/value_objects/hana_cluster_node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule Trento.Clusters.ValueObjects.HanaClusterNode do
field :virtual_ip, :string
field :nameserver_actual_role, :string
field :indexserver_actual_role, :string
field :status, :string

embeds_many :resources, ClusterResource
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ defmodule Trento.Discovery.Payloads.Cluster.CrmmonDiscoveryPayload do
field :name, :string
field :online, :boolean
field :unclean, :boolean
field :standby, :boolean
field :standby_on_fail, :boolean
field :maintenance, :boolean
field :pending, :boolean
field :shutdown, :boolean
end

embeds_many :resources, CrmmonResource
Expand Down Expand Up @@ -215,7 +220,17 @@ defmodule Trento.Discovery.Payloads.Cluster.CrmmonDiscoveryPayload do

defp nodes_changeset(nodes, attrs) do
nodes
|> cast(attrs, [:id, :name, :online, :unclean])
|> cast(attrs, [
:id,
:name,
:online,
:unclean,
:standby,
:standby_on_fail,
:maintenance,
:pending,
:shutdown
])
|> validate_required([:id, :name])
end

Expand Down
20 changes: 16 additions & 4 deletions lib/trento/discovery/policies/cluster_policy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ defmodule Trento.Discovery.Policies.ClusterPolicy do
},
sid
) do
Enum.map(nodes, fn %{name: name} ->
Enum.map(nodes, fn %{name: name} = node ->
attributes =
nodes_with_attributes
|> Enum.find_value([], fn
Expand Down Expand Up @@ -250,7 +250,8 @@ defmodule Trento.Discovery.Policies.ClusterPolicy do
hana_status: "Unknown",
virtual_ip: virtual_ip,
nameserver_actual_role: nameserver_actual_role,
indexserver_actual_role: indexserver_actual_role
indexserver_actual_role: indexserver_actual_role,
status: parse_node_status(node)
}

hana_status =
Expand Down Expand Up @@ -290,6 +291,16 @@ defmodule Trento.Discovery.Policies.ClusterPolicy do
%{indexserver_actual_role: "", nameserver_actual_role: ""}
end

defp parse_node_status(%{online: false}), do: "Offline"
defp parse_node_status(%{unclean: true}), do: "Unclean"
defp parse_node_status(%{standby: true}), do: "Standby"
defp parse_node_status(%{maintenance: true}), do: "Maintenance"
defp parse_node_status(%{shutdown: true}), do: "Shutdown"
defp parse_node_status(%{pending: true}), do: "Pending"
defp parse_node_status(%{standby_on_fail: true}), do: "Standby on fail"
defp parse_node_status(%{online: true}), do: "Online"
defp parse_node_status(_), do: "Unknown"

defp parse_hana_scale_up_system_replication_mode([%{attributes: attributes} | _], sid) do
Map.get(attributes, "hana_#{String.downcase(sid)}_srmode", "")
end
Expand Down Expand Up @@ -812,7 +823,7 @@ defmodule Trento.Discovery.Policies.ClusterPolicy do
},
cib_resources_by_sid
) do
Enum.map(nodes, fn %{name: node_name} ->
Enum.map(nodes, fn %{name: node_name} = node ->
cib_resource_ids = Enum.map(cib_resources_by_sid, fn %{id: id} -> id end)

crm_node_resources =
Expand Down Expand Up @@ -851,7 +862,8 @@ defmodule Trento.Discovery.Policies.ClusterPolicy do
virtual_ips: parse_resource_by_type(cib_node_resources, virtual_ip_type, "ip"),
filesystems: parse_resource_by_type(cib_node_resources, "Filesystem", "directory"),
attributes: attributes,
resources: crm_node_resources
resources: crm_node_resources,
status: parse_node_status(node)
}
end)
end
Expand Down
5 changes: 5 additions & 0 deletions lib/trento_web/openapi/v2/schema/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do
indexserver_actual_role: %Schema{type: :string, nullable: true},
nameserver_actual_role: %Schema{type: :string, nullable: true},
hana_status: %Schema{type: :string, deprecated: true},
status: %Schema{type: :string},
attributes: %Schema{
type: :object,
description: "Node attributes",
Expand Down Expand Up @@ -121,6 +122,10 @@ defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do
type: :string,
description: "Node name"
},
status: %Schema{
type: :string,
description: "Node status"
},
resources: %Schema{
type: :array,
items: Cluster.ClusterResource,
Expand Down
2 changes: 1 addition & 1 deletion lib/trento_web/views/v1/cluster_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule TrentoWeb.V1.ClusterView do
defp adapt_v1(%{type: type, details: %{nodes: nodes} = details} = cluster)
when type in [:hana_scale_up, :hana_scale_out] do
adapted_nodes =
Enum.map(nodes, &Map.drop(&1, [:indexserver_actual_role, :nameserver_actual_role]))
Enum.map(nodes, &Map.drop(&1, [:indexserver_actual_role, :nameserver_actual_role, :status]))

adapted_details =
details
Expand Down
Loading
Loading