Add cluster endpoint for listing the nodes

This commit is contained in:
Ingo Oppermann
2022-08-15 16:03:08 +03:00
parent 249cba1ad6
commit 96d8d51a7d
5 changed files with 167 additions and 37 deletions

View File

@@ -209,6 +209,38 @@ const docTemplate = `{
} }
} }
}, },
"/api/v3/cluster": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "List of nodes in the cluster",
"produces": [
"application/json"
],
"summary": "List of nodes in the cluster",
"operationId": "cluster-3-get-cluster",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterNode"
}
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/api.Error"
}
}
}
}
},
"/api/v3/cluster/node": { "/api/v3/cluster/node": {
"post": { "post": {
"security": [ "security": [
@@ -2142,7 +2174,10 @@ const docTemplate = `{
"schema": { "schema": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/api.SRTChannels" "type": "array",
"items": {
"$ref": "#/definitions/api.SRTChannel"
}
} }
} }
} }
@@ -2509,6 +2544,12 @@ const docTemplate = `{
"address": { "address": {
"type": "string" "type": "string"
}, },
"id": {
"type": "string"
},
"last_update": {
"type": "integer"
},
"state": { "state": {
"type": "string" "type": "string"
} }
@@ -3755,7 +3796,7 @@ const docTemplate = `{
} }
} }
}, },
"api.SRTChannels": { "api.SRTChannel": {
"type": "object", "type": "object",
"properties": { "properties": {
"connections": { "connections": {
@@ -3773,19 +3814,16 @@ const docTemplate = `{
} }
} }
}, },
"publisher": { "name": {
"type": "object", "type": "string"
"additionalProperties": { },
"type": "integer" "socketid": {
} "type": "integer"
}, },
"subscriber": { "subscriber": {
"type": "object", "type": "array",
"additionalProperties": { "items": {
"type": "array", "type": "integer"
"items": {
"type": "integer"
}
} }
} }
} }

View File

@@ -201,6 +201,38 @@
} }
} }
}, },
"/api/v3/cluster": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "List of nodes in the cluster",
"produces": [
"application/json"
],
"summary": "List of nodes in the cluster",
"operationId": "cluster-3-get-cluster",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterNode"
}
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/api.Error"
}
}
}
}
},
"/api/v3/cluster/node": { "/api/v3/cluster/node": {
"post": { "post": {
"security": [ "security": [
@@ -2134,7 +2166,10 @@
"schema": { "schema": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/api.SRTChannels" "type": "array",
"items": {
"$ref": "#/definitions/api.SRTChannel"
}
} }
} }
} }
@@ -2501,6 +2536,12 @@
"address": { "address": {
"type": "string" "type": "string"
}, },
"id": {
"type": "string"
},
"last_update": {
"type": "integer"
},
"state": { "state": {
"type": "string" "type": "string"
} }
@@ -3747,7 +3788,7 @@
} }
} }
}, },
"api.SRTChannels": { "api.SRTChannel": {
"type": "object", "type": "object",
"properties": { "properties": {
"connections": { "connections": {
@@ -3765,19 +3806,16 @@
} }
} }
}, },
"publisher": { "name": {
"type": "object", "type": "string"
"additionalProperties": { },
"type": "integer" "socketid": {
} "type": "integer"
}, },
"subscriber": { "subscriber": {
"type": "object", "type": "array",
"additionalProperties": { "items": {
"type": "array", "type": "integer"
"items": {
"type": "integer"
}
} }
} }
} }

View File

@@ -60,6 +60,10 @@ definitions:
properties: properties:
address: address:
type: string type: string
id:
type: string
last_update:
type: integer
state: state:
type: string type: string
type: object type: object
@@ -879,7 +883,7 @@ definitions:
name: name:
type: string type: string
type: object type: object
api.SRTChannels: api.SRTChannel:
properties: properties:
connections: connections:
additionalProperties: additionalProperties:
@@ -891,16 +895,14 @@ definitions:
$ref: '#/definitions/api.SRTLog' $ref: '#/definitions/api.SRTLog'
type: array type: array
type: object type: object
publisher: name:
additionalProperties: type: string
type: integer socketid:
type: object type: integer
subscriber: subscriber:
additionalProperties: items:
items: type: integer
type: integer type: array
type: array
type: object
type: object type: object
api.SRTConnection: api.SRTConnection:
properties: properties:
@@ -1867,6 +1869,26 @@ paths:
schema: schema:
type: string type: string
summary: Swagger UI for this API summary: Swagger UI for this API
/api/v3/cluster:
get:
description: List of nodes in the cluster
operationId: cluster-3-get-cluster
produces:
- application/json
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/api.ClusterNode'
type: array
"404":
description: Not Found
schema:
$ref: '#/definitions/api.Error'
security:
- ApiKeyAuth: []
summary: List of nodes in the cluster
/api/v3/cluster/node: /api/v3/cluster/node:
post: post:
consumes: consumes:
@@ -3131,7 +3153,9 @@ paths:
description: OK description: OK
schema: schema:
items: items:
$ref: '#/definitions/api.SRTChannels' items:
$ref: '#/definitions/api.SRTChannel'
type: array
type: array type: array
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []

View File

@@ -22,6 +22,35 @@ func NewCluster(cluster cluster.Cluster) *ClusterHandler {
} }
} }
// GetCluster returns the list of nodes in the cluster
// @Summary List of nodes in the cluster
// @Description List of nodes in the cluster
// @ID cluster-3-get-cluster
// @Produce json
// @Success 200 {array} api.ClusterNode
// @Failure 404 {object} api.Error
// @Security ApiKeyAuth
// @Router /api/v3/cluster [get]
func (h *ClusterHandler) GetCluster(c echo.Context) error {
nodes := h.cluster.ListNodes()
list := []api.ClusterNode{}
for _, node := range nodes {
state := node.State()
n := api.ClusterNode{
Address: node.Address(),
ID: state.ID,
LastUpdate: state.LastUpdate.Unix(),
State: state.State,
}
list = append(list, n)
}
return c.JSON(http.StatusOK, list)
}
// AddNode adds a new node // AddNode adds a new node
// @Summary Add a new node // @Summary Add a new node
// @Description Add a new node to the cluster // @Description Add a new node to the cluster

View File

@@ -659,6 +659,7 @@ func (s *server) setRoutesV3(v3 *echo.Group) {
// v3 Cluster // v3 Cluster
if s.v3handler.cluster != nil { if s.v3handler.cluster != nil {
v3.GET("/cluster", s.v3handler.cluster.GetCluster)
v3.GET("/cluster/node/:id", s.v3handler.cluster.GetNode) v3.GET("/cluster/node/:id", s.v3handler.cluster.GetNode)
v3.GET("/cluster/node/:id/proxy", s.v3handler.cluster.GetNodeProxy) v3.GET("/cluster/node/:id/proxy", s.v3handler.cluster.GetNodeProxy)