Skip to content

Commit

Permalink
Sap systems and Databases openapi (#528)
Browse files Browse the repository at this point in the history
* Added SAPSystem and Database OpenApi schemas

* Added SAP Systems and Databases list operations to controller

* Fixup openapi doc types
  • Loading branch information
nelsonkopliku authored May 16, 2022
1 parent 3ddf506 commit af6ef62
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 32 deletions.
22 changes: 22 additions & 0 deletions lib/trento_web/controllers/sap_system_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ defmodule TrentoWeb.SapSystemController do

alias Trento.Support.StructHelper

use OpenApiSpex.ControllerSpecs

tags ["Landscape"]

operation :list,
summary: "List SAP Systems",
description: "List all the discovered SAP Systems on the target infrastructure",
responses: [
ok:
{"A collection of the discovered SAP Systems", "application/json",
TrentoWeb.OpenApi.Schema.SAPSystem.SAPSystemsCollection}
]

## TODO Fix sanitization
def list(conn, _) do
sap_systems =
Expand All @@ -15,6 +28,15 @@ defmodule TrentoWeb.SapSystemController do
json(conn, sap_systems)
end

operation :list_databases,
summary: "List HANA Databases",
description: "List all the discovered HANA Databases on the target infrastructure",
responses: [
ok:
{"A collection of the discovered HANA Databases", "application/json",
TrentoWeb.OpenApi.Schema.Database.DatabasesCollection}
]

def list_databases(conn, _) do
databases =
SapSystems.get_all_databases()
Expand Down
17 changes: 4 additions & 13 deletions lib/trento_web/openapi/schema/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule TrentoWeb.OpenApi.Schema.Cluster do
require OpenApiSpex
alias OpenApiSpex.Schema

alias TrentoWeb.OpenApi.Schema.{Checks, Provider, Tag}
alias TrentoWeb.OpenApi.Schema.{Checks, Provider, ResourceHealth, Tags}

defmodule ClusterResource do
@moduledoc false
Expand Down Expand Up @@ -120,7 +120,7 @@ defmodule TrentoWeb.OpenApi.Schema.Cluster do
description: "A discovered Pacemaker Cluster on the target infrastructure",
type: :object,
properties: %{
id: %Schema{type: :integer, description: "Cluster ID"},
id: %Schema{type: :string, description: "Cluster ID", format: :uuid},
name: %Schema{type: :string, description: "Cluster name"},
sid: %Schema{type: :string, description: "SID"},
provider: Provider.SupportedProviders,
Expand All @@ -135,11 +135,7 @@ defmodule TrentoWeb.OpenApi.Schema.Cluster do
type: :array,
items: %Schema{type: :string}
},
health: %Schema{
type: :string,
description: "Detected health of the cluster",
enum: [:passing, :warning, :critical, :unknown]
},
health: ResourceHealth,
resources_number: %Schema{type: :integer, description: "Resource number"},
hosts_number: %Schema{type: :integer, description: "Hosts number"},
details: Details,
Expand All @@ -160,12 +156,7 @@ defmodule TrentoWeb.OpenApi.Schema.Cluster do
type: :array,
items: Checks.CheckResult
},
tags: %Schema{
title: "Tags",
description: "A list of tags attached to a resource",
type: :array,
items: Tag
}
tags: Tags
}
})
end
Expand Down
80 changes: 80 additions & 0 deletions lib/trento_web/openapi/schema/database.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
defmodule TrentoWeb.OpenApi.Schema.Database do
@moduledoc false

require OpenApiSpex
alias OpenApiSpex.Schema

alias TrentoWeb.OpenApi.Schema.{ResourceHealth, Tags}

defmodule DatabaseInstance do
@moduledoc false

OpenApiSpex.schema(%{
title: "DatabaseInstance",
description: "A discovered HANA Database Instance on the target infrastructure",
type: :object,
properties: %{
sap_system_id: %Schema{type: :string, description: "SAP System ID", format: :uuid},
sid: %Schema{type: :string, description: "SID"},
tenant: %Schema{type: :string, description: "Tenant"},
instance_number: %Schema{type: :string, description: "Instance Number"},
instance_hostname: %Schema{type: :string, description: "Instance Hostname"},
features: %Schema{type: :string, description: "Instance Features"},
http_port: %Schema{type: :integer, description: "Instance HTTP Port"},
https_port: %Schema{type: :integer, description: "Instance HTTPS Port"},
start_priority: %Schema{type: :string, description: "Instance Start Priority"},
host_id: %Schema{
type: :string,
description: "Identifier of the host where current instance is running",
format: :uuid
},
system_replication: %Schema{type: :string, description: "System Replication"},
system_replication_status: %Schema{
type: :string,
description: "System Replication Status"
},
health: ResourceHealth
}
})
end

defmodule DatabaseInstances do
@moduledoc false

OpenApiSpex.schema(%{
title: "DatabaseInstances",
description:
"A list of DatabaseInstances, part of a complete SAP System, or only a HANA Database",
type: :array,
items: DatabaseInstance
})
end

defmodule DatabaseItem do
@moduledoc false

OpenApiSpex.schema(%{
title: "Database",
description: "A discovered HANA Database on the target infrastructure",
type: :object,
properties: %{
id: %Schema{type: :string, description: "Database ID", format: :uuid},
sid: %Schema{type: :string, description: "SID"},
health: ResourceHealth,
database_instances: DatabaseInstances,
tags: Tags
}
})
end

defmodule DatabasesCollection do
@moduledoc false

OpenApiSpex.schema(%{
title: "DatabasesCollection",
description: "A list of the discovered HANA Databases",
type: :array,
items: DatabaseItem
})
end
end
12 changes: 12 additions & 0 deletions lib/trento_web/openapi/schema/health.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule TrentoWeb.OpenApi.Schema.ResourceHealth do
@moduledoc false

require OpenApiSpex

OpenApiSpex.schema(%{
title: "ResourceHealth",
type: :string,
description: "Detected health of a Resource",
enum: [:passing, :warning, :critical, :unknown]
})
end
11 changes: 3 additions & 8 deletions lib/trento_web/openapi/schema/host.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule TrentoWeb.OpenApi.Schema.Host do
require OpenApiSpex
alias OpenApiSpex.Schema

alias TrentoWeb.OpenApi.Schema.{Provider, SlesSubscription, Tag}
alias TrentoWeb.OpenApi.Schema.{Provider, SlesSubscription, Tags}

defmodule IPv4 do
@moduledoc false
Expand Down Expand Up @@ -34,7 +34,7 @@ defmodule TrentoWeb.OpenApi.Schema.Host do
description: "A discovered host on the target infrastructure",
type: :object,
properties: %{
id: %Schema{type: :integer, description: "Host ID"},
id: %Schema{type: :string, description: "Host ID", format: :uuid},
hostname: %Schema{type: :string, description: "Host name"},
ip_addresses: %Schema{
type: :array,
Expand Down Expand Up @@ -64,12 +64,7 @@ defmodule TrentoWeb.OpenApi.Schema.Host do
},
provider: Provider.SupportedProviders,
provider_data: Provider.ProviderData,
tags: %Schema{
title: "Tags",
description: "A list of tags attached to a resource",
type: :array,
items: Tag
},
tags: Tags,
sles_subscriptions: %Schema{
title: "SlesSubscriptions",
description: "A list of the available SLES Subscriptions on a host",
Expand Down
70 changes: 70 additions & 0 deletions lib/trento_web/openapi/schema/sap_system.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
defmodule TrentoWeb.OpenApi.Schema.SAPSystem do
@moduledoc false

require OpenApiSpex
alias OpenApiSpex.Schema

alias TrentoWeb.OpenApi.Schema.{Database, ResourceHealth, Tags}

defmodule ApplicationInstance do
@moduledoc false

OpenApiSpex.schema(%{
title: "ApplicationInstance",
description: "A discovered Application Instance on the target infrastructure",
type: :object,
properties: %{
sap_system_id: %Schema{type: :string, description: "SAP System ID", format: :uuid},
sid: %Schema{type: :string, description: "SID"},
instance_number: %Schema{type: :string, description: "Instance Number"},
instance_hostname: %Schema{type: :string, description: "Instance Hostname"},
features: %Schema{type: :string, description: "Instance Features"},
http_port: %Schema{type: :integer, description: "Instance HTTP Port"},
https_port: %Schema{type: :integer, description: "Instance HTTPS Port"},
start_priority: %Schema{type: :string, description: "Instance Start Priority"},
host_id: %Schema{
type: :string,
description: "Identifier of the host where current instance is running",
format: :uuid
},
health: ResourceHealth
}
})
end

defmodule SAPSystemItem do
@moduledoc false

OpenApiSpex.schema(%{
title: "SAPSystem",
description: "A discovered SAP System on the target infrastructure",
type: :object,
properties: %{
id: %Schema{type: :string, description: "SAP System ID", format: :uuid},
sid: %Schema{type: :string, description: "SID"},
tenant: %Schema{type: :string, description: "Tenant"},
db_host: %Schema{type: :string, description: "Address of the connected Database"},
health: ResourceHealth,
application_instances: %Schema{
title: "ApplicationInstances",
description: "A list of the discovered Application Instances for current SAP Systems",
type: :array,
items: ApplicationInstance
},
database_instances: Database.DatabaseInstances,
tags: Tags
}
})
end

defmodule SAPSystemsCollection do
@moduledoc false

OpenApiSpex.schema(%{
title: "SAPSystemsCollection",
description: "A list of the discovered SAP Systems",
type: :array,
items: SAPSystemItem
})
end
end
35 changes: 24 additions & 11 deletions lib/trento_web/openapi/schema/tag.ex
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
defmodule TrentoWeb.OpenApi.Schema.Tag do
defmodule TrentoWeb.OpenApi.Schema.Tags do
@moduledoc false

require OpenApiSpex
alias OpenApiSpex.Schema

defmodule Tag do
@moduledoc false

require OpenApiSpex
alias OpenApiSpex.Schema

OpenApiSpex.schema(%{
title: "Tag",
description: "A tag attached to a resource",
type: :object,
properties: %{
id: %Schema{type: :integer},
resource_id: %Schema{type: :string, format: :uuid},
resource_type: %Schema{type: :string, enum: [:host, :cluster, :sap_system, :database]},
value: %Schema{type: :string}
}
})
end

OpenApiSpex.schema(%{
title: "Tag",
description: "A tag attached to a resource",
type: :object,
properties: %{
id: %Schema{type: :integer},
resource_id: %Schema{type: :string, format: :uuid},
resource_type: %Schema{type: :string, enum: [:host, :cluster, :sap_system, :database]},
value: %Schema{type: :string}
}
title: "Tags",
description: "A list of tags attached to a resource",
type: :array,
items: Tag
})
end

0 comments on commit af6ef62

Please sign in to comment.