service map get endpoint logic

This commit is contained in:
Gustavo Massaneiro
2022-01-01 21:36:10 -03:00
parent ed0282d554
commit 394deac576
2 changed files with 30 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"sync"
"github.com/up9inc/mizu/shared"
"github.com/up9inc/mizu/shared/logger"
)
@@ -28,6 +29,7 @@ type serviceMap struct {
type ServiceMap interface {
AddEdge(source, destination id, protocol string)
GetNodes() []string
GetEdges() []shared.ServiceMapEdge
PrintNodes()
PrintAdjacentEdges()
GetEntriesProcessedCount() int
@@ -113,6 +115,21 @@ func (s *serviceMap) GetNodes() []string {
return nodes
}
func (s *serviceMap) GetEdges() []shared.ServiceMapEdge {
var edges []shared.ServiceMapEdge
for u, m := range s.graph.Edges {
for v := range m {
edges = append(edges, shared.ServiceMapEdge{
Source: string(u),
Destination: string(v),
Count: s.graph.Edges[u][v].count,
Protocol: s.graph.Edges[u][v].protocol,
})
}
}
return edges
}
func (s *serviceMap) PrintNodes() {
fmt.Println("Printing all nodes...")
@@ -140,5 +157,11 @@ func (s *serviceMap) GetNodesCount() int {
}
func (s *serviceMap) GetEdgesCount() int {
return len(s.graph.Edges)
var count int
for _, m := range s.graph.Edges {
for range m {
count++
}
}
return count
}

View File

@@ -26,7 +26,12 @@ func (s *ServiceMapController) Status(c *gin.Context) {
}
func (s *ServiceMapController) Get(c *gin.Context) {
c.JSON(http.StatusNotImplemented, nil)
serviceMap := api.GetServiceMapInstance()
response := &shared.ServiceMapResponse{
Nodes: serviceMap.GetNodes(),
Edges: serviceMap.GetEdges(),
}
c.JSON(http.StatusNotImplemented, response)
}
func (s *ServiceMapController) Reset(c *gin.Context) {