Skip to content
Snippets Groups Projects
Commit 5f14cd69 authored by Malte Bauch's avatar Malte Bauch
Browse files

a few simple fixes for goSDN-tview

- changed status check of grpc and database
- reordered commandlist
parent c01d2ad2
No related branches found
No related tags found
3 merge requests!90Develop,!70Resolve "Add command-line flags to goSDN-tview",!53V.0.1.0 Codename Threadbare
Pipeline #53118 passed with warnings
......@@ -22,17 +22,16 @@ type command struct {
//CommandList contains the specific goSDN gRPC calls
var CommandList = []command{
{"hello", "test connection to goSDN controller", goSDNSayHello},
{"shutdown", "request goSDN controller to shutdown", goSDNShutdown},
{"hello", "test connection to controller", goSDNSayHello},
{"testdb", "test all database connections", goSDNTestDB},
{"tapigetedge", "get list of edges", TAPIGetEdge},
{"tapigetedgenode", "get list of edgenodes", TAPIGetEdgeNode},
{"tapigetlink", "get list of links", TAPIGetLink},
{"tapiGetDevices", "creates devices", TAPIGetEdge},
{"tapiGetInterfaces", "creates interfaces", TAPIGetEdgeNode},
{"tapiGetLinks", "creates links between devices", TAPIGetLink},
{"shutdown", "request controller to shutdown", goSDNShutdown},
}
//Connect creates a new connection to the gRPC server
func Connect(address string) (*grpc.ClientConn, error) {
//address := "141.100.70.170:55066"
return grpc.Dial(address, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second), grpc.WithBlock())
}
......@@ -51,7 +50,7 @@ func GoSDNLogStream(conn *grpc.ClientConn, clv *tview.TextView) error {
streamError = err
break
}
response := []byte(msg.Log + "\n")
response := []byte(msg.Log)
clv.Write(response)
}
}(stream)
......
......@@ -35,7 +35,7 @@ func (cv *CommandListView) GetContent() tview.Primitive {
func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
conn *grpc.ClientConn) {
//TODO: create own command in grpc -> commands
cv.commandsList.AddItem("AddPND", "closes the application", 'a', func() {
cv.commandsList.AddItem("addPND", "closes the application", 'a', func() {
rv.ChangeContentView("addPND")
app.SetFocus(rv.GetContent())
})
......@@ -50,7 +50,7 @@ func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
})
}
cv.commandsList.AddItem("Show Log", "shows the log of goSDN", 'l', func() {
cv.commandsList.AddItem("log", "shows the log of goSDN", 'l', func() {
rv.ChangeContentView("log")
})
......
......@@ -3,7 +3,7 @@ package views
import (
"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
"github.com/rivo/tview"
"time"
//"time"
)
//DatabaseStatusView is an application view to display the current status of
......@@ -24,8 +24,9 @@ func NewDatabaseStatusView(app *app.App) *DatabaseStatusView {
SetBorder(true).
SetTitle("Database")
// run the periodical refresh in a new go routine
go databaseTicker(dv)
//TODO: dummy text at the moment. database status check has to be initilized
//here
dv.databaseStatusView.SetText("[green]" + "connected")
return dv
}
......@@ -40,11 +41,3 @@ func (dv *DatabaseStatusView) SetContent(s string) {
dv.databaseStatusView.Clear()
dv.databaseStatusView.SetText(s)
}
func databaseTicker(dv *DatabaseStatusView) {
//TODO see gRPCStatusView!
ticker := time.NewTicker(5 * time.Second)
for t := range ticker.C {
dv.SetContent(t.String())
}
}
......@@ -49,13 +49,18 @@ func (sv *GRPCStatusView) SetContent(s string) {
}
func gRPCTicker(sv *GRPCStatusView, conn *grpc.ClientConn) {
sv.SetContent(checkStatus(conn))
//TODO: refactor -> get rid of hardcoded values
ticker := time.NewTicker(5 * time.Second)
for range ticker.C {
if str := conn.GetState().String(); str == "READY" || str == "IDLE" {
sv.SetContent("[green]" + "connected")
} else {
sv.SetContent("[red]" + "disconnected")
}
sv.SetContent(checkStatus(conn))
}
}
func checkStatus(conn *grpc.ClientConn) string {
if str := conn.GetState().String(); str == "READY" || str == "IDLE" {
return "[green]" + "connected"
} else {
return "[red]" + "disconnected"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment