-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add V2 scope to /api/clusters endpoint #1492
Changes from all commits
99932fc
8db7f01
a80d262
f78e773
727b09a
ab2b1e0
b6a586a
1839f40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule TrentoWeb.V2.ClusterController do | ||
use TrentoWeb, :controller | ||
use OpenApiSpex.ControllerSpecs | ||
|
||
alias Trento.Clusters | ||
|
||
alias TrentoWeb.OpenApi.V2.Schema | ||
|
||
plug OpenApiSpex.Plug.CastAndValidate, json_render_error_v2: true | ||
action_fallback TrentoWeb.FallbackController | ||
|
||
operation :list, | ||
summary: "List Pacemaker Clusters", | ||
tags: ["Target Infrastructure"], | ||
description: "List all the discovered Pacemaker Clusters on the target infrastructure", | ||
responses: [ | ||
ok: | ||
{"A collection of the discovered Pacemaker Clusters", "application/json", | ||
Schema.Cluster.PacemakerClustersCollection} | ||
] | ||
|
||
def list(conn, _) do | ||
clusters = Clusters.get_all_clusters() | ||
|
||
render(conn, "clusters.json", clusters: clusters) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do | |
@moduledoc false | ||
|
||
require OpenApiSpex | ||
require Trento.Domain.Enums.ClusterType, as: ClusterType | ||
|
||
alias OpenApiSpex.Schema | ||
|
||
|
@@ -37,13 +36,12 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do | |
site: %Schema{type: :string}, | ||
hana_status: %Schema{type: :string}, | ||
attributes: %Schema{ | ||
title: "ClusterNodeAttributes", | ||
type: :array, | ||
items: %Schema{type: :string} | ||
type: :object, | ||
arbulu89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description: "Node attributes", | ||
additionalProperties: %Schema{type: :string} | ||
}, | ||
virtual_ip: %Schema{type: :string}, | ||
resources: %Schema{ | ||
title: "ClustrNodeResources", | ||
description: "A list of Cluster resources", | ||
type: :array, | ||
items: ClusterResource | ||
|
@@ -57,7 +55,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do | |
|
||
OpenApiSpex.schema(%{ | ||
title: "SbdDevice", | ||
description: "Ad Sbd Device", | ||
description: "SBD Device", | ||
type: :object, | ||
properties: %{ | ||
device: %Schema{type: :string}, | ||
|
@@ -83,30 +81,28 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do | |
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: HanaClusterNode | ||
}, | ||
sbd_devices: %Schema{ | ||
title: "SbdDevice", | ||
type: :array, | ||
items: SbdDevice | ||
} | ||
} | ||
}, | ||
required: [:nodes] | ||
}) | ||
end | ||
|
||
defmodule Details do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "PacemakerClusterDetail", | ||
title: "PacemakerClusterDetails", | ||
description: "Details of the detected PacemakerCluster", | ||
nullable: true, | ||
oneOf: [ | ||
|
@@ -135,11 +131,11 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do | |
type: %Schema{ | ||
type: :string, | ||
description: "Detected type of the cluster", | ||
enum: ClusterType.values() | ||
enum: [:hana_scale_up, :hana_scale_out, :unknown] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using hardcoded values as they cannot be changed without adding non backward compatible changes. |
||
}, | ||
selected_checks: %Schema{ | ||
title: "SelectedChecks", | ||
description: "A list ids of the checks selected for execution on this cluster", | ||
description: "A list of check ids selected for an execution on this cluster", | ||
type: :array, | ||
items: %Schema{type: :string} | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule TrentoWeb.OpenApi.V2.ApiSpec do | ||
@moduledoc """ | ||
OpenApi specification entry point for V2 version | ||
""" | ||
|
||
use TrentoWeb.OpenApi.ApiSpec, | ||
api_version: "v2" | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do | ||
@moduledoc false | ||
|
||
require OpenApiSpex | ||
require Trento.Domain.Enums.ClusterType, as: ClusterType | ||
|
||
alias OpenApiSpex.Schema | ||
|
||
alias TrentoWeb.OpenApi.V1.Schema.{Cluster, Provider, ResourceHealth, Tags} | ||
|
||
defmodule AscsErsClusterNode do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "AscsErsClusterNode", | ||
description: "ASCS/ERS Cluster Node", | ||
type: :object, | ||
properties: %{ | ||
attributes: %Schema{ | ||
type: :object, | ||
arbulu89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description: "Node attributes", | ||
additionalProperties: %Schema{type: :string} | ||
}, | ||
filesystems: %Schema{ | ||
type: :array, | ||
items: %Schema{type: :string}, | ||
description: "List of filesystems managed in this node" | ||
}, | ||
name: %Schema{ | ||
type: :string, | ||
description: "Node name" | ||
}, | ||
resources: %Schema{ | ||
type: :array, | ||
items: Cluster.ClusterResource, | ||
description: "A list of Cluster resources" | ||
}, | ||
roles: %Schema{ | ||
type: :array, | ||
items: %Schema{type: :string, enum: ["ascs", "ers"]}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This mean that we can have at most two roles, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, one node can have from 0 to 2 roles for each SAP system. |
||
description: "List of roles managed in this node" | ||
}, | ||
virtual_ips: %Schema{ | ||
type: :array, | ||
items: %Schema{type: :string}, | ||
description: "List of virtual IPs managed in this node" | ||
} | ||
} | ||
}) | ||
end | ||
|
||
defmodule AscsErsClusterSAPSystem do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "AscsErsClusterSAPSystem", | ||
description: "SAP system managed by a ASCS/ERS cluster", | ||
type: :object, | ||
properties: %{ | ||
distributed: %Schema{ | ||
type: :boolean, | ||
description: "ASCS and ERS instances are distributed and running in different nodes" | ||
}, | ||
filesystem_resource_based: %Schema{ | ||
type: :boolean, | ||
description: | ||
"ASCS and ERS filesystems are handled by the cluster with the Filesystem resource agent" | ||
}, | ||
nodes: %Schema{ | ||
type: :array, | ||
items: AscsErsClusterNode, | ||
description: "List of ASCS/ERS nodes for this SAP system" | ||
} | ||
} | ||
}) | ||
end | ||
|
||
defmodule AscsErsClusterDetails do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "AscsErsClusterDetails", | ||
description: "Details of a ASCS/ERS Pacemaker Cluster", | ||
type: :object, | ||
properties: %{ | ||
fencing_type: %Schema{ | ||
type: :string, | ||
description: "Fencing type" | ||
}, | ||
sap_systems: %Schema{ | ||
type: :array, | ||
items: AscsErsClusterSAPSystem, | ||
description: "List of managed SAP systems in a single or multi SID cluster" | ||
}, | ||
sbd_devices: %Schema{ | ||
type: :array, | ||
items: Cluster.SbdDevice, | ||
description: "List of SBD devices used in the cluster" | ||
}, | ||
stopped_resources: %Schema{ | ||
type: :array, | ||
items: Cluster.ClusterResource, | ||
description: "List of the stopped resources on this HANA Cluster" | ||
} | ||
}, | ||
required: [:sap_systems] | ||
}) | ||
end | ||
|
||
defmodule Details do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "PacemakerClusterDetails", | ||
description: "Details of the detected PacemakerCluster", | ||
nullable: true, | ||
oneOf: [ | ||
AscsErsClusterDetails, | ||
Cluster.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: :string, description: "Cluster ID", format: :uuid}, | ||
name: %Schema{type: :string, description: "Cluster name"}, | ||
sid: %Schema{type: :string, description: "SID"}, | ||
additional_sids: %Schema{ | ||
type: :array, | ||
items: %Schema{type: :string}, | ||
description: "Additionally discovered SIDs, such as ASCS/ERS cluster SIDs" | ||
}, | ||
provider: Provider.SupportedProviders, | ||
type: %Schema{ | ||
type: :string, | ||
description: "Detected type of the cluster", | ||
enum: ClusterType.values() | ||
}, | ||
selected_checks: %Schema{ | ||
title: "SelectedChecks", | ||
description: "A list of check ids selected for an execution on this cluster", | ||
type: :array, | ||
items: %Schema{type: :string} | ||
}, | ||
health: ResourceHealth, | ||
resources_number: %Schema{type: :integer, description: "Resource number", nullable: true}, | ||
hosts_number: %Schema{type: :integer, description: "Hosts number", nullable: true}, | ||
cib_last_written: %Schema{ | ||
type: :string, | ||
description: "CIB last written date", | ||
nullable: true | ||
}, | ||
details: Details, | ||
tags: Tags | ||
} | ||
}) | ||
end | ||
|
||
defmodule PacemakerClustersCollection do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "PacemakerClustersCollection", | ||
description: "A list of the discovered Pacemaker Clusters", | ||
type: :array, | ||
items: PacemakerCluster | ||
}) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess for now this is enough.
However at a certain point I'd find it of great help having something like
yield call(getV2, '/clusters');
Feel free to keep it as you did for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. I wanted to keep the current changes minimalist.
This wouldn't require many changes, simply to add 4 new functions (get, post, del, put) with that naming.
Let's keep it on the radar