Skip to content

Commit

Permalink
Clusters list openapi doc (#522)
Browse files Browse the repository at this point in the history
* Extracted SupportedProviders schema

* Added Cluster and Checks openapi schema

* Wired openapi operation to cluster controller

* Polish schema imports
  • Loading branch information
nelsonkopliku authored May 12, 2022
1 parent ec5f9d3 commit 2a660e1
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 15 deletions.
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
183 changes: 183 additions & 0 deletions lib/trento_web/openapi/schema/cluster.ex
Original file line number Diff line number Diff line change
@@ -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
16 changes: 7 additions & 9 deletions lib/trento_web/openapi/schema/host.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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
}
}
})
Expand Down
Loading

0 comments on commit 2a660e1

Please sign in to comment.