+1
-1
@@ -226,7 +226,7 @@ func main() {
|
||||
graphView := graphGroup.Group("")
|
||||
graphView.Use(handlers.RequireView())
|
||||
{
|
||||
graphView.GET("", graphHandlers.GetYAML)
|
||||
graphView.GET("", graphHandlers.GetGraph)
|
||||
graphView.GET("/order", graphHandlers.StartupOrder)
|
||||
graphView.GET("/cycle", graphHandlers.CycleCheck)
|
||||
graphView.GET("/failure", graphHandlers.GetFailureRootCause)
|
||||
|
||||
@@ -1001,19 +1001,20 @@ const docTemplate = `{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"description": "Returns the service dependency graph as raw YAML text",
|
||||
"description": "Returns the service dependency graph as JSON",
|
||||
"produces": [
|
||||
"text/plain"
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"graph"
|
||||
],
|
||||
"summary": "Get dependency graph YAML",
|
||||
"summary": "Get dependency graph",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "YAML content",
|
||||
"description": "Dependency graph",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -990,19 +990,20 @@
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"description": "Returns the service dependency graph as raw YAML text",
|
||||
"description": "Returns the service dependency graph as JSON",
|
||||
"produces": [
|
||||
"text/plain"
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"graph"
|
||||
],
|
||||
"summary": "Get dependency graph YAML",
|
||||
"summary": "Get dependency graph",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "YAML content",
|
||||
"description": "Dependency graph",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1181,17 +1181,18 @@ paths:
|
||||
- auth
|
||||
/graph:
|
||||
get:
|
||||
description: Returns the service dependency graph as raw YAML text
|
||||
description: Returns the service dependency graph as JSON
|
||||
produces:
|
||||
- text/plain
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: YAML content
|
||||
description: Dependency graph
|
||||
schema:
|
||||
type: string
|
||||
additionalProperties: true
|
||||
type: object
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Get dependency graph YAML
|
||||
summary: Get dependency graph
|
||||
tags:
|
||||
- graph
|
||||
put:
|
||||
|
||||
@@ -53,25 +53,52 @@ func (h *GraphHandlers) reload() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetGraph returns the current parsed graph.
|
||||
func (h *GraphHandlers) GetGraph() *graph.Graph {
|
||||
// LoadedGraph returns the current parsed graph.
|
||||
func (h *GraphHandlers) LoadedGraph() *graph.Graph {
|
||||
h.mu.RLock()
|
||||
defer h.mu.RUnlock()
|
||||
return h.loaded
|
||||
}
|
||||
|
||||
// GetYAML returns the raw YAML content.
|
||||
// @Summary Get dependency graph YAML
|
||||
// @Description Returns the service dependency graph as raw YAML text
|
||||
// GetGraph returns the current dependency graph as JSON.
|
||||
// @Summary Get dependency graph
|
||||
// @Description Returns the service dependency graph as JSON
|
||||
// @Tags graph
|
||||
// @Produce plain
|
||||
// @Success 200 {string} string "YAML content"
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]interface{} "Dependency graph"
|
||||
// @Security Bearer
|
||||
// @Router /graph [get]
|
||||
func (h *GraphHandlers) GetYAML(c *gin.Context) {
|
||||
func (h *GraphHandlers) GetGraph(c *gin.Context) {
|
||||
h.mu.RLock()
|
||||
defer h.mu.RUnlock()
|
||||
c.Data(http.StatusOK, "text/yaml", h.yamlData)
|
||||
|
||||
g := h.loaded
|
||||
if g == nil {
|
||||
c.JSON(http.StatusOK, gin.H{"nodes": map[string]interface{}{}})
|
||||
return
|
||||
}
|
||||
|
||||
nodes := make(map[string]interface{})
|
||||
for _, node := range g.Nodes() {
|
||||
services := make(map[string]interface{})
|
||||
for _, svc := range node.Services {
|
||||
deps := make([]map[string]interface{}, 0)
|
||||
for _, dep := range svc.Dependencies {
|
||||
deps = append(deps, map[string]interface{}{
|
||||
"target": dep.Target,
|
||||
"condition": dep.Condition,
|
||||
})
|
||||
}
|
||||
services[svc.Name] = map[string]interface{}{
|
||||
"dependencies": deps,
|
||||
}
|
||||
}
|
||||
nodes[node.ID] = map[string]interface{}{
|
||||
"services": services,
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"nodes": nodes})
|
||||
}
|
||||
|
||||
// UpdateYAML updates the graph from new YAML text.
|
||||
|
||||
Reference in New Issue
Block a user