Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../tools.mk

.PHONY: generate
generate:
goa gen github.com/pgEdge/control-plane/api/design
130 changes: 130 additions & 0 deletions api/design/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package design

import (
g "goa.design/goa/v3/dsl"
)

var _ = g.API("control-plane", func() {
g.Title("pgEdge Control Plane API")
g.Description("Service for creating, modifying, and operating pgEdge databases.")
g.Server("control-plane", func() {
g.Host("localhost", func() {
g.URI("http://localhost:3000")
})
})
})

var _ = g.Service("control-plane", func() {
g.Method("inspect-cluster", func() {
g.Description("Returns information about the cluster.")
g.Result(Cluster)

g.HTTP(func() {
g.GET("/cluster")
})
})

g.Method("list-hosts", func() {
g.Description("Lists all hosts within the cluster.")
g.Result(g.ArrayOf(Host))

g.HTTP(func() {
g.GET("/hosts")
})
})

g.Method("inspect-host", func() {
g.Description("Returns information about a particular host in the cluster.")
g.Payload(func() {
g.Attribute("host_id", g.String, func() {
g.Description("ID of the host to inspect.")
g.Example("de3b1388-1f0c-42f1-a86c-59ab72f255ec")
})
})
g.Result(Host)

g.HTTP(func() {
g.GET("/hosts/{host_id}")
})
})

g.Method("remove-host", func() {
g.Description("Removes a host from the cluster.")
g.Payload(func() {
g.Attribute("host_id", g.String, func() {
g.Description("ID of the host to remove.")
g.Example("de3b1388-1f0c-42f1-a86c-59ab72f255ec")
})
})
g.HTTP(func() {
g.DELETE("/hosts/{host_id}")
})
})

g.Method("list-databases", func() {
g.Description("Lists all databases in the cluster.")
g.Result(g.ArrayOf(Database))

g.HTTP(func() {
g.GET("/databases")
})
})

g.Method("create-database", func() {
g.Description("Creates a new database in the cluster.")
g.Payload(CreateDatabaseRequest)
g.Result(Database)

g.HTTP(func() {
g.POST("/databases")
})
})

g.Method("inspect-database", func() {
g.Description("Returns information about a particular database in the cluster.")
g.Payload(func() {
g.Attribute("database_id", g.String, func() {
g.Description("ID of the database to inspect.")
g.Example("02f1a7db-fca8-4521-b57a-2a375c1ced51")
})
})
g.Result(Database)

g.HTTP(func() {
g.GET("/databases/{database_id}")
})
})

g.Method("update-database", func() {
g.Description("Updates a database with the given specification.")
g.Payload(func() {
g.Attribute("database_id", g.String, func() {
g.Description("ID of the database to update.")
g.Example("02f1a7db-fca8-4521-b57a-2a375c1ced51")
})
g.Attribute("request", UpdateDatabaseRequest)
})
g.Result(Database)

g.HTTP(func() {
g.POST("/databases/{database_id}")
g.Body("request")
})
})

g.Method("delete-database", func() {
g.Description("Deletes a database from the cluster.")
g.Payload(func() {
g.Attribute("database_id", g.String, func() {
g.Description("ID of the database to delete.")
g.Example("02f1a7db-fca8-4521-b57a-2a375c1ced51")
})
})
g.HTTP(func() {
g.DELETE("/databases/{database_id}")
})
})

// Serves the OpenAPI spec as a static file
g.Files("/openapi.json", "./gen/http/openapi.json")
})
33 changes: 33 additions & 0 deletions api/design/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package design

import (
g "goa.design/goa/v3/dsl"
)

var ClusterStatus = g.Type("ClusterStatus", func() {
g.Attribute("state", g.String, func() {
g.Description("The current state of the cluster.")
g.Enum("available", "error")
})

g.Required("state")
})

var Cluster = g.Type("Cluster", func() {
g.Attribute("id", g.String, func() {
g.Description("Unique identifier for the cluster.")
g.Example("a67cbb36-c3c3-49c9-8aac-f4a0438a883d")
})
g.Attribute("tenant_id", g.String, func() {
g.Description("Unique identifier for the cluster's owner.")
g.Example("8210ec10-2dca-406c-ac4a-0661d2189954")
})
g.Attribute("status", ClusterStatus, func() {
g.Description("Current status of the cluster.")
})
g.Attribute("hosts", g.ArrayOf(Host), func() {
g.Description("All of the hosts in the cluster.")
})

g.Required("id", "tenant_id", "status", "hosts")
})
Loading