Skip to content

Commit

Permalink
Addressing review feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
CDimonaco committed Feb 22, 2024
1 parent 3cfdb3f commit 19d291e
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 88 deletions.
2 changes: 1 addition & 1 deletion lib/trento_web/openapi/v1/schema/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do
},
selected_checks: %Schema{
title: "SelectedChecks",
description: "A list of check ids selected for an execution on this cluster",
description: "A list of check ids selected for an execution on this host",
type: :array,
items: %Schema{type: :string}
},
Expand Down
1 change: 1 addition & 0 deletions lib/trento_web/openapi/v1/schema/database.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Database do
description: "Instance Hostname",
nullable: true
},
absent_at: %Schema{type: :string, description: "Absent instance timestamp", format: :datetime, nullable: true},
features: %Schema{type: :string, description: "Instance Features"},
http_port: %Schema{type: :integer, description: "Instance HTTP Port", nullable: true},
https_port: %Schema{type: :integer, description: "Instance HTTPS Port", nullable: true},
Expand Down
6 changes: 6 additions & 0 deletions lib/trento_web/openapi/v1/schema/host.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Host do
type: :array,
items: SlesSubscription
},
selected_checks: %Schema{
title: "SelectedChecks",
description: "A list of check ids selected for an execution on this cluster",
type: :array,
items: %Schema{type: :string}
},
saptune_status: SaptuneStatus,
deregistered_at: %Schema{
title: "DeregisteredAt",
Expand Down
3 changes: 2 additions & 1 deletion lib/trento_web/openapi/v1/schema/sap_system.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do
description: "Instance Hostname",
nullable: true
},
absent_at: %Schema{type: :string, description: "Absent instance timestamp", format: :datetime, nullable: true},
features: %Schema{type: :string, description: "Instance Features"},
http_port: %Schema{type: :integer, description: "Instance HTTP Port", nullable: true},
https_port: %Schema{type: :integer, description: "Instance HTTPS Port", nullable: true},
Expand Down Expand Up @@ -116,7 +117,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do
sapsystem_health: ResourceHealth,
database_health: ResourceHealth,
hosts_health: ResourceHealth,
clusters_heatlh: %Schema{
clusters_health: %Schema{
allOf: [
ResourceHealth,
%Schema{deprecated: true}
Expand Down
2 changes: 2 additions & 0 deletions lib/trento_web/openapi/v2/schema/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do
description: "SAP system managed by a ASCS/ERS cluster",
type: :object,
additionalProperties: false,
required: [:sid],
properties: %{
sid: %Schema{type: :string, description: "SID"},
distributed: %Schema{
type: :boolean,
description: "ASCS and ERS instances are distributed and running in different nodes"
Expand Down
1 change: 0 additions & 1 deletion lib/trento_web/views/v1/host_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ defmodule TrentoWeb.V1.HostView do
|> Map.from_struct()
|> Map.put(:sles_subscriptions, sles_subscriptions)
|> Map.delete(:fully_qualified_domain_name)
|> Map.delete(:selected_checks)
|> Map.delete(:inserted_at)
|> Map.delete(:__meta__)
end
Expand Down
71 changes: 3 additions & 68 deletions lib/trento_web/views/v1/sap_system_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,6 @@ defmodule TrentoWeb.V1.SapSystemView do
end

def render("database_instance.json", %{instance: instance}) do
instance
|> Map.from_struct()
|> Map.delete(:__meta__)
|> Map.delete(:absent_at)
|> Map.delete(:host)
end

def render("broadcast_database.json", %{
database:
%{
database_instances: database_instances
} = database
}) do
rendered_database_instances =
render_many(database_instances, __MODULE__, "broadcast_database_instance.json",
as: :instance
)

database
|> Map.from_struct()
|> Map.delete(:__meta__)
|> Map.put(:database_instances, rendered_database_instances)
|> add_system_replication_status_to_secondary_instance
end

def render("broadcast_database_instance.json", %{instance: instance}) do
instance
|> Map.from_struct()
|> Map.delete(:__meta__)
Expand All @@ -59,7 +33,7 @@ defmodule TrentoWeb.V1.SapSystemView do
instance: instance,
database_instances: database_instances
}) do
"broadcast_database_instance.json"
"database_instance.json"
|> render(%{instance: instance})
|> add_system_replication_status(database_instances)
end
Expand All @@ -73,7 +47,7 @@ defmodule TrentoWeb.V1.SapSystemView do
end

def render("database_restored.json", %{database: database}) do
render("broadcast_database.json", database: database)
render("database.json", database: database)
end

def render("database_health_changed.json", %{health: health}), do: health
Expand Down Expand Up @@ -113,14 +87,6 @@ defmodule TrentoWeb.V1.SapSystemView do
end

def render("application_instance.json", %{instance: instance}) do
instance
|> Map.from_struct()
|> Map.delete(:__meta__)
|> Map.delete(:absent_at)
|> Map.delete(:host)
end

def render("broadcast_application_instance.json", %{instance: instance}) do
instance
|> Map.from_struct()
|> Map.delete(:__meta__)
Expand Down Expand Up @@ -164,37 +130,6 @@ defmodule TrentoWeb.V1.SapSystemView do
|> add_system_replication_status_to_secondary_instance
end

def render("broadcast_sap_system.json", %{
sap_system:
%{
application_instances: application_instances,
database_instances: database_instances
} = sap_system
}) do
rendered_application_instances =
render_many(application_instances, __MODULE__, "broadcast_application_instance.json",
as: :instance
)

rendered_database_instances =
render_many(database_instances, __MODULE__, "broadcast_database_instance.json",
as: :instance
)

sap_system
|> Map.from_struct()
|> Map.delete(:__meta__)
|> Map.put(
:database_instances,
rendered_database_instances
)
|> Map.put(
:application_instances,
rendered_application_instances
)
|> add_system_replication_status_to_secondary_instance
end

def render("sap_system_registered.json", %{sap_system: sap_system}) do
sap_system
|> Map.from_struct()
Expand All @@ -205,7 +140,7 @@ defmodule TrentoWeb.V1.SapSystemView do
end

def render("sap_system_restored.json", %{sap_system: sap_system}) do
render("broadcast_sap_system.json", sap_system: sap_system)
render("sap_system.json", sap_system: sap_system)
end

def render("sap_system_updated.json", %{id: id, ensa_version: ensa_version}),
Expand Down
13 changes: 0 additions & 13 deletions lib/trento_web/views/v2/cluster_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,13 @@ defmodule TrentoWeb.V2.ClusterView do
end

def render("cluster.json", %{cluster: cluster}) do
cluster_details = render("cluster_details.json", %{details: cluster.details})

cluster
|> Map.from_struct()
|> Map.put(:details, cluster_details)
|> Map.delete(:deregistered_at)
|> Map.delete(:__meta__)
end

def render("cluster_details.json", %{details: %{"sap_systems" => sap_systems} = details}) do
sap_systems =
Enum.map(sap_systems, &Map.take(&1, [:distributed, :filesystem_resource_based, :nodes]))

Map.put(details, :sap_systems, sap_systems)
end

def render("cluster_details.json", %{details: details}) do
details
end

def render("cluster_registered.json", %{cluster: cluster}) do
Map.delete(render("cluster.json", %{cluster: cluster}), :tags)
end
Expand Down
6 changes: 2 additions & 4 deletions test/trento_web/views/v1/host_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ defmodule TrentoWeb.V1.HostViewTest do

rendered_host = render(HostView, "host.json", %{host: host})

refute Access.get(rendered_host, "fully_qualified_domain_name")
refute Access.get(rendered_host, "health")
refute Access.get(rendered_host, "selected_checks")
refute Access.get(rendered_host, "inserted_at")
refute Access.get(rendered_host, :fully_qualified_domain_name)
refute Access.get(rendered_host, :inserted_at)
end

test "should render host details relevant information" do
Expand Down

0 comments on commit 19d291e

Please sign in to comment.