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

Clusters list openapi doc #522

Merged
merged 4 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 19 additions & 0 deletions lib/trento_web/controllers/cluster_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,27 @@ defmodule TrentoWeb.ClusterController do

alias Trento.Integration.Checks

use OpenApiSpex.ControllerSpecs

tags ["Landscape"]

operation :list,
summary: "List Pacemaker Clusters",
description: "List all the discovered Pacemaker Clusters on the target infrastructure",
responses: [
ok:
{"A collection of the discovered Pacemaker Clusters", "application/json",
TrentoWeb.OpenApi.Schema.Cluster.PacemakerClustersCollection}
]

@spec list(Plug.Conn.t(), map) :: Plug.Conn.t()
def list(conn, _) do
clusters = Clusters.get_all_clusters()

json(conn, clusters)
end

operation :request_checks_execution, false
@spec request_checks_execution(Plug.Conn.t(), map) :: Plug.Conn.t()
def request_checks_execution(conn, %{"cluster_id" => cluster_id}) do
case Clusters.request_checks_execution(cluster_id) do
Expand All @@ -27,6 +41,8 @@ defmodule TrentoWeb.ClusterController do
end
end

operation :runner_callback, false
@spec runner_callback(Plug.Conn.t(), map) :: Plug.Conn.t()
def runner_callback(conn, params) do
case Checks.handle_callback(params) do
:ok ->
Expand All @@ -41,6 +57,7 @@ defmodule TrentoWeb.ClusterController do
end
end

operation :select_checks, false
@spec select_checks(Plug.Conn.t(), map) :: Plug.Conn.t()
def select_checks(conn, %{"cluster_id" => cluster_id, "checks" => checks}) do
case Clusters.select_checks(cluster_id, checks) do
Expand All @@ -56,6 +73,7 @@ defmodule TrentoWeb.ClusterController do
end
end

operation :get_connection_settings, false
@spec get_connection_settings(Plug.Conn.t(), map) :: Plug.Conn.t()
def get_connection_settings(conn, %{"cluster_id" => cluster_id}) do
settings = Hosts.get_all_connection_settings_by_cluster_id(cluster_id)
Expand All @@ -65,6 +83,7 @@ defmodule TrentoWeb.ClusterController do
|> json(settings)
end

operation :save_connection_settings, false
@spec save_connection_settings(Plug.Conn.t(), map) :: Plug.Conn.t()
def save_connection_settings(
conn,
Expand Down
75 changes: 75 additions & 0 deletions lib/trento_web/openapi/schema/checks.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
defmodule TrentoWeb.OpenApi.Schema.Checks do
@moduledoc false

require OpenApiSpex
alias OpenApiSpex.Schema

defmodule HostChecksExecution do
@moduledoc false

OpenApiSpex.schema(%{
title: "HostChecksExecution",
description:
"Representation of the current check execution on a specific host of a Cluster",
type: :object,
properties: %{
cluster_id: %Schema{
type: :string,
description: "Cluster's ID",
format: :uuid
},
host_id: %Schema{
type: :string,
description: "Host's ID",
format: :uuid
},
reachable: %Schema{
type: :boolean,
description:
"Indicates whether the host was reachable during the connection to run selected checks"
},
msg: %Schema{
type: :string,
description: "A message"
}
}
})
end

defmodule CheckResult do
@moduledoc false

OpenApiSpex.schema(%{
title: "CheckResult",
description: "Representation of the result of a spectific check on a host of a cluster",
type: :object,
properties: %{
cluster_id: %Schema{
type: :string,
description: "Cluster's ID",
format: :uuid
},
host_id: %Schema{
type: :string,
description: "Host's ID",
format: :uuid
},
check_id: %Schema{
type: :string,
description: "The identifier of the executed check"
},
result: %Schema{
type: :string,
description: "Host's last heartbeat status",
enum: [:passing, :warning, :critical, :skipped, :unknown]
},
inserted_at: %Schema{
type: :string,
description: "Creation timestamp",
format: :"date-time"
},
updated_at: %Schema{type: :string, description: "Update timestamp", format: :"date-time"}
}
})
end
end
181 changes: 181 additions & 0 deletions lib/trento_web/openapi/schema/cluster.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
defmodule TrentoWeb.OpenApi.Schema.Cluster do
@moduledoc false

require OpenApiSpex
alias OpenApiSpex.Schema

defmodule ClusterResource do
@moduledoc false

OpenApiSpex.schema(%{
title: "ClusterResource",
description: "A Cluster Resource",
type: :object,
properties: %{
id: %Schema{type: :string},
type: %Schema{type: :string},
role: %Schema{type: :string},
status: %Schema{type: :string},
fail_count: %Schema{type: :integer}
}
})
end

defmodule ClusterNode do
@moduledoc false

OpenApiSpex.schema(%{
title: "ClusterNode",
description: "A Cluster Node",
type: :object,
properties: %{
name: %Schema{type: :string},
site: %Schema{type: :string},
hana_status: %Schema{type: :string},
attributes: %Schema{
title: "ClusterNodeAttributes",
type: :array,
items: %Schema{type: :string}
},
virtual_ip: %Schema{type: :string},
resources: %Schema{
title: "ClustrNodeResources",
description: "A list of ClusterNodes",
type: :array,
items: ClusterResource
}
}
})
end

defmodule SbdDevice do
@moduledoc false

OpenApiSpex.schema(%{
title: "SbdDevice",
description: "Ad Sbd Device",
type: :object,
properties: %{
device: %Schema{type: :string},
status: %Schema{type: :string}
}
})
end

defmodule HanaClusterDetails do
@moduledoc false

OpenApiSpex.schema(%{
title: "HanaClusterDetails",
description: "Details of a HANA Pacemaker Cluster",
type: :object,
properties: %{
system_replication_mode: %Schema{type: :string, description: "System Replication Mode"},
system_replication_operation_mode: %Schema{
type: :string,
description: "System Replication Operation Mode"
},
secondary_sync_state: %Schema{type: :string, description: "Secondary Sync State"},
sr_health_state: %Schema{type: :string, description: "SR health state"},
fencing_type: %Schema{type: :string, description: "Fencing Type"},
stopped_resources: %Schema{
title: "ClusterResource",
description: "A list of the stopped resources on this HANA Cluster",
type: :array,
items: ClusterResource
},
nodes: %Schema{
title: "HanaClusterNodes",
type: :array,
items: ClusterNode
},
sbd_devices: %Schema{
title: "SbdDevice",
type: :array,
items: SbdDevice
}
}
})
end

defmodule Details do
@moduledoc false

OpenApiSpex.schema(%{
title: "PacemakerClusterDetail",
description: "Details of the detected PacemakerCluster",
oneOf: [
HanaClusterDetails
]
})
end

defmodule PacemakerCluster do
@moduledoc false

OpenApiSpex.schema(%{
title: "PacemakerCluster",
description: "A discovered Pacemaker Cluster on the target infrastructure",
type: :object,
properties: %{
id: %Schema{type: :integer, description: "Cluster ID"},
name: %Schema{type: :string, description: "Cluster name"},
sid: %Schema{type: :string, description: "SID"},
provider: TrentoWeb.OpenApi.Schema.Provider.SupportedProviders,
type: %Schema{
type: :string,
description: "Detected type of the cluster",
enum: [:hana_scale_up, :hana_scale_out, :unknown]
},
selected_checks: %Schema{
title: "SelectedChecks",
description: "A list ids of the checks selected for execution on this cluster",
type: :array,
items: %Schema{type: :string}
},
health: %Schema{
type: :string,
description: "Detected health of the cluster",
enum: [:passing, :warning, :critical, :unknown]
},
resources_number: %Schema{type: :integer, description: "Resource number"},
hosts_number: %Schema{type: :integer, description: "Hosts number"},
details: Details,
checks_execution: %Schema{
type: :string,
description: "Current status of the checks execution for this cluster",
enum: [:not_running, :requested, :running]
},
hosts_executions: %Schema{
title: "HostChecksExecutions",
description: "A list of tags attached to a resource",
type: :array,
items: TrentoWeb.OpenApi.Schema.Checks.HostChecksExecution
},
checks_results: %Schema{
title: "CheckResults",
description: "A list of tags attached to a resource",
type: :array,
items: TrentoWeb.OpenApi.Schema.Checks.CheckResult
},
tags: %Schema{
title: "Tags",
description: "A list of tags attached to a resource",
type: :array,
items: TrentoWeb.OpenApi.Schema.Tag
}
}
})
end

defmodule PacemakerClustersCollection do
@moduledoc false

OpenApiSpex.schema(%{
title: "PacemakerClustersCollection",
description: "A list of the discovered Pacemaker Clusters",
type: :array,
items: PacemakerCluster
})
end
end
6 changes: 1 addition & 5 deletions lib/trento_web/openapi/schema/host.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ defmodule TrentoWeb.OpenApi.Schema.Host do
description: "Host's last heartbeat status",
enum: [:critical, :passing, :unknown]
},
provider: %Schema{
type: :string,
description: "Detected Provider on which the host is running",
enum: [:azure, :aws, :gcp, :unknown]
},
provider: TrentoWeb.OpenApi.Schema.Provider.SupportedProviders,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use aliases for this long module names (maybe just aliasing TrentoWeb.OpenApi.Schema)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, made some polishing here f372b79

provider_data: TrentoWeb.OpenApi.Schema.Provider.ProviderData,
tags: %Schema{
title: "Tags",
Expand Down
11 changes: 11 additions & 0 deletions lib/trento_web/openapi/schema/provider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ defmodule TrentoWeb.OpenApi.Schema.Provider do
require OpenApiSpex
alias OpenApiSpex.Schema

defmodule SupportedProviders do
@moduledoc false

OpenApiSpex.schema(%{
title: "SupportedProviders",
type: :string,
description: "Detected Provider where the resource is running",
enum: [:azure, :aws, :gcp, :unknown]
})
end

defmodule ProviderData do
@moduledoc false

Expand Down