diff --git a/lib/trento_web/controllers/cluster_controller.ex b/lib/trento_web/controllers/cluster_controller.ex index 3c631f43a2..632f55641a 100644 --- a/lib/trento_web/controllers/cluster_controller.ex +++ b/lib/trento_web/controllers/cluster_controller.ex @@ -5,6 +5,19 @@ 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() @@ -12,6 +25,7 @@ defmodule TrentoWeb.ClusterController do 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 @@ -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 -> @@ -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 @@ -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) @@ -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, diff --git a/lib/trento_web/openapi/schema/checks.ex b/lib/trento_web/openapi/schema/checks.ex new file mode 100644 index 0000000000..c22c7e5e73 --- /dev/null +++ b/lib/trento_web/openapi/schema/checks.ex @@ -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 diff --git a/lib/trento_web/openapi/schema/cluster.ex b/lib/trento_web/openapi/schema/cluster.ex new file mode 100644 index 0000000000..1d4addf0b0 --- /dev/null +++ b/lib/trento_web/openapi/schema/cluster.ex @@ -0,0 +1,183 @@ +defmodule TrentoWeb.OpenApi.Schema.Cluster do + @moduledoc false + + require OpenApiSpex + alias OpenApiSpex.Schema + + alias TrentoWeb.OpenApi.Schema.{Checks, Provider, Tag} + + 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: 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: Checks.HostChecksExecution + }, + checks_results: %Schema{ + title: "CheckResults", + description: "A list of tags attached to a resource", + type: :array, + items: Checks.CheckResult + }, + tags: %Schema{ + title: "Tags", + description: "A list of tags attached to a resource", + type: :array, + items: 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 diff --git a/lib/trento_web/openapi/schema/host.ex b/lib/trento_web/openapi/schema/host.ex index 616cfe6b95..d232e7edfa 100644 --- a/lib/trento_web/openapi/schema/host.ex +++ b/lib/trento_web/openapi/schema/host.ex @@ -4,6 +4,8 @@ defmodule TrentoWeb.OpenApi.Schema.Host do require OpenApiSpex alias OpenApiSpex.Schema + alias TrentoWeb.OpenApi.Schema.{Provider, SlesSubscription, Tag} + defmodule IPv4 do @moduledoc false @@ -45,7 +47,7 @@ defmodule TrentoWeb.OpenApi.Schema.Host do ] } }, - ssh_address: TrentoWeb.OpenApi.Schema.Host.IPv4, + ssh_address: IPv4, agent_version: %Schema{ type: :string, description: "Version of the agent installed on the host" @@ -60,23 +62,19 @@ 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_data: TrentoWeb.OpenApi.Schema.Provider.ProviderData, + provider: Provider.SupportedProviders, + provider_data: Provider.ProviderData, tags: %Schema{ title: "Tags", description: "A list of tags attached to a resource", type: :array, - items: TrentoWeb.OpenApi.Schema.Tag + items: Tag }, sles_subscriptions: %Schema{ title: "SlesSubscriptions", description: "A list of the available SLES Subscriptions on a host", type: :array, - items: TrentoWeb.OpenApi.Schema.SlesSubscription + items: SlesSubscription } } }) diff --git a/lib/trento_web/openapi/schema/provider.ex b/lib/trento_web/openapi/schema/provider.ex index 8eadef009b..a4cff84d6d 100644 --- a/lib/trento_web/openapi/schema/provider.ex +++ b/lib/trento_web/openapi/schema/provider.ex @@ -4,15 +4,14 @@ defmodule TrentoWeb.OpenApi.Schema.Provider do require OpenApiSpex alias OpenApiSpex.Schema - defmodule ProviderData do + defmodule SupportedProviders do @moduledoc false OpenApiSpex.schema(%{ - title: "ProviderMetadata", - description: "Detected metadata for any provider", - oneOf: [ - TrentoWeb.OpenApi.Schema.Provider.AzureProviderData - ] + title: "SupportedProviders", + type: :string, + description: "Detected Provider where the resource is running", + enum: [:azure, :aws, :gcp, :unknown] }) end @@ -34,4 +33,16 @@ defmodule TrentoWeb.OpenApi.Schema.Provider do } }) end + + defmodule ProviderData do + @moduledoc false + + OpenApiSpex.schema(%{ + title: "ProviderMetadata", + description: "Detected metadata for any provider", + oneOf: [ + AzureProviderData + ] + }) + end end