From: Oscar J Rodriguez Date: Tue, 9 May 2023 06:57:13 +0000 (-0700) Subject: catching up and managing some of the future packages X-Git-Url: https://git.josue.xyz/?a=commitdiff_plain;h=a49b19ea760f5c6493e0145320f2bf37dd3a96ca;p=VSCPweb%2F.git catching up and managing some of the future packages --- diff --git a/go.mod b/go.mod index d720aa0..f12f975 100644 --- a/go.mod +++ b/go.mod @@ -3,3 +3,23 @@ module VSCPweb go 1.19 require github.com/go-chi/chi/v5 v5.0.7 + +require healthHandlers v0.0.0 + +replace healthHandlers v0.0.0 => ./handlers/health/ + +require controllerHandlers v0.0.0 + +replace controllerHandlers v0.0.0 => ./handlers/controller/ + +require managementHandlers v0.0.0 + +replace managementHandlers v0.0.0 => ./handlers/management/ + +require virtualAPIHandlers v0.0.0 + +replace virtualAPIHandlers v0.0.0 => ./handlers/virtualapi/ + +require staticHandlers v0.0.0 + +replace staticHandlers v0.0.0 => ./handlers/static/ diff --git a/handlers/controller/controllerHandlers.go b/handlers/controller/controllerHandlers.go new file mode 100644 index 0000000..f01514a --- /dev/null +++ b/handlers/controller/controllerHandlers.go @@ -0,0 +1,18 @@ +package controllerHandlers +import ( + "fmt" + + "net/http" + ) + +//TODO(josuer08): get mpstat idle stat for every machine, as well as the ifstat +//and also the temperatures of every one of the servers working for the cluster. + +// This might include a textproto where we have all of the info of every node and +// then with their addresses we can go ahead and query that info from them with +// the special agent that each of them will already have installed in order to +// connect to the cluster. +func MasterHealthHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf("Ëverything should be okay my boi") +} + diff --git a/handlers/controller/go.mod b/handlers/controller/go.mod new file mode 100644 index 0000000..e69de29 diff --git a/handlers/health/go.mod b/handlers/health/go.mod new file mode 100644 index 0000000..e69de29 diff --git a/handlers/health/healthHandlers.go b/handlers/health/healthHandlers.go new file mode 100644 index 0000000..7e054da --- /dev/null +++ b/handlers/health/healthHandlers.go @@ -0,0 +1,21 @@ +// healthHandlers package is the package with all of the handlers for the healt +// route of the system, it gets info from all of the workers of the cluster as +// well as the master server +package healthHandlers + +import ( + "fmt" + + "net/http" +) + +//TODO(josuer08): get mpstat idle stat for every machine, as well as the ifstat +//and also the temperatures of every one of the servers working for the cluster. + +// This might include a textproto where we have all of the info of every node and +// then with their addresses we can go ahead and query that info from them with +// the special agent that each of them will already have installed in order to +// connect to the cluster. +func MasterHealthHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf("Ëverything should be okay my boi") +} diff --git a/handlers/management/go.mod b/handlers/management/go.mod new file mode 100644 index 0000000..e69de29 diff --git a/handlers/management/managementHandlers.go b/handlers/management/managementHandlers.go new file mode 100644 index 0000000..869cf9e --- /dev/null +++ b/handlers/management/managementHandlers.go @@ -0,0 +1,18 @@ +package managementHandlers +import ( + "fmt" + + "net/http" + ) + +//TODO(josuer08): get mpstat idle stat for every machine, as well as the ifstat +//and also the temperatures of every one of the servers working for the cluster. + +// This might include a textproto where we have all of the info of every node and +// then with their addresses we can go ahead and query that info from them with +// the special agent that each of them will already have installed in order to +// connect to the cluster. +func MasterHealthHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf("Ëverything should be okay my boi") +} + diff --git a/handlers/static/go.mod b/handlers/static/go.mod new file mode 100644 index 0000000..e69de29 diff --git a/handlers/static/staticHandlers.go b/handlers/static/staticHandlers.go new file mode 100644 index 0000000..7b182db --- /dev/null +++ b/handlers/static/staticHandlers.go @@ -0,0 +1,18 @@ +package staticHandlers +import ( + "fmt" + + "net/http" + ) + +//TODO(josuer08): get mpstat idle stat for every machine, as well as the ifstat +//and also the temperatures of every one of the servers working for the cluster. + +// This might include a textproto where we have all of the info of every node and +// then with their addresses we can go ahead and query that info from them with +// the special agent that each of them will already have installed in order to +// connect to the cluster. +func MasterHealthHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf("Ëverything should be okay my boi") +} + diff --git a/handlers/virtualapi/go.mod b/handlers/virtualapi/go.mod new file mode 100644 index 0000000..e69de29 diff --git a/handlers/virtualapi/virtualapiHandlers.go b/handlers/virtualapi/virtualapiHandlers.go new file mode 100644 index 0000000..264e910 --- /dev/null +++ b/handlers/virtualapi/virtualapiHandlers.go @@ -0,0 +1,18 @@ +package virtualAPIHandlers +import ( + "fmt" + + "net/http" + ) + +//TODO(josuer08): get mpstat idle stat for every machine, as well as the ifstat +//and also the temperatures of every one of the servers working for the cluster. + +// This might include a textproto where we have all of the info of every node and +// then with their addresses we can go ahead and query that info from them with +// the special agent that each of them will already have installed in order to +// connect to the cluster. +func MasterHealthHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf("Ëverything should be okay my boi") +} + diff --git a/main.go b/main.go deleted file mode 100644 index bfa0f36..0000000 --- a/main.go +++ /dev/null @@ -1,137 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - - "github.com/go-chi/chi/v5" - "github.com/go-chi/chi/v5/middleware" -) - -func main() { -//create a new server and mount the handlers: - s := CreateNewServer() - s.MountHandlers() -//staring up the server: - http.ListenAndServe(":8000", s.Router) -} - - -type server struct { - Router *chi.Mux - //suggestion to add config settings or DB in here -} - -func CreateNewServer() *server { - s := &server{} - s.Router = chi.NewRouter() - return s -} - -func (s *server) MountHandlers() { - -//Creation of the router: - //logging enables as a middleware - s.Router.Use(middleware.Logger) - //recover from panics and send a 500 internal error - s.Router.Use(middleware.Recoverer) - //a middleware to check if the server is alive - s.Router.Use(middleware.Heartbeat("/ping")) - //a profiler to check healt of server - s.Router.Mount("/debug", middleware.Profiler()) - //personalized 404 - s.Router.NotFound(GenericHandler404) - //personalized 405 - s.Router.MethodNotAllowed(GenericHandler405) - -//example: - //example of a get function and its handler - s.Router.Get("/example/{first}/{second:[0-9]+}", ExampleHandler) - -//Creating subrouters: - //healthRouter check on the health of nodes or main server - healthRouter := chi.NewRouter() - //controllerRouter Agnostic openVswitch controller bridge - controllerRouter := chi.NewRouter() - //managementRouter Start, stop, monitoring of the core (mininet) - managementRouter := chi.NewRouter() - //mininetApiRouter Interface with the virtual environment inside the core (mininet) - mininetApiRouter := chi.NewRouter() - //might want to check https://go-chi.io/#/pages/routing?id=routing-groups - //in order to make groups where you have other middleware like authentication - -//////////////////////////////////possible routing///////////////////////////// - //s.Router.Connect(pattern string, h http.HandlerFunc) - //s.Router.Delete(pattern string, h http.HandlerFunc) - //s.Router.Get(pattern string, h http.HandlerFunc) - //s.Router.Head(pattern string, h http.HandlerFunc) - //s.Router.Options(pattern string, h http.HandlerFunc) - //s.Router.Patch(pattern string, h http.HandlerFunc) - //s.Router.Post(pattern string, h http.HandlerFunc) - //s.Router.Put(pattern string, h http.HandlerFunc) - //s.Router.Trace(pattern string, h http.HandlerFunc) -/////////////////////////////////////////////////////////////////////////////// - -//generic ryu version at first... - //s.Router.Get("/", ) - //s.Router.Get("/access", ) - //s.Router.Get("/stats", ) - //s.Router.Get("/topology", ) - //s.Router.Get("/mpstat", )//DEPRECATED see: /masterHealth - //s.Router.Get("/ifstat", )//DEPRECATED see: /masterHealth - //s.Router.Get("/showtemp", )//DEPRECATED see: /masterHealth - //healthRouter.Get("/", )//this renders the health page "/health" - //healthRouter.Get("/masterHealth", )//return a JSON with healt of the master "/free" - //controllerRouter.Delete("/flow", )//this is an external request "/flowdel" - //controllerRouter.Get("/topology", )// "/gettopo" - //mininetApiRouter.Get("/net", ) - //healthRouter.Get("/ping", )// "/rpiping" - //mininetApiRouter.Get("/nodes", ) - //mininetApiRouter.Get("/status", )// "/statusnodes" - //mininetApiRouter.Get("/intfs", ) - //mininetApiRouter.Get("/iperf", ) - //mininetApiRouter.Get("/pingall", ) - //mininetApiRouter.Get("/placement", ) - //managementRouter.Get("/vscpData", )// "/getvsorcdata" - //managementRouter.Get("/controllerData", ) // "/getcontrollerdata" - //controllerRouter.Get("/resetflows", )//not sure if here or managementRouter - //controllerRouter.Get("/listswitch", ) - //controllerRouter.Get("/status", ) - //controllerRouter.Get("/tablestatus", ) - //controllerRouter.Get("/portDescription", )// "/portsdesc" - //controllerRouter.Get("/portStatus", )// "/portsstat" - //managementRouter.Get("/startController", )// "/startcontroller" - //managementRouter.Get("/startcontrollerAPI", )// "/startcontrollerrouter" - //managementRouter.Get("/stopController", )// "/stopcontroller" - //mininetApiRouter.Get("/sendCommand", )// "/sendcommand" - //managementRouter.Get("/cancel", )// "/cancel" - //managementRouter.Get("/startVsorc", )// "/startvsorc" - //managementRouter.Get("/stopVsorc", )// "/stopvsorc" - //http.Handle("/", r) - -//Mounting all of the subrouters: - s.Router.Mount("/health", healthRouter) - s.Router.Mount("/controller", controllerRouter) - s.Router.Mount("/management", managementRouter) - s.Router.Mount("/virtualAPI", mininetApiRouter) - -} - - - -//GenericHandler404 is the universal 404 response of this front end -func GenericHandler404(w http.ResponseWriter, r *http.Request){ - w.WriteHeader(404) - w.Write([]byte("route does not exist")) -} -//GenericHandler405 is the universal 405 response of this front end -func GenericHandler405(w http.ResponseWriter, r *http.Request){ - w.WriteHeader(405) - w.Write([]byte("Method not valid")) -} -func ExampleHandler(w http.ResponseWriter, r *http.Request) { - var1 := chi.URLParam(r, "first") - var2 := chi.URLParam(r, "second") - w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, "First: %v\nSecond: %v", var1, var2) -} diff --git a/vscpweb.go b/vscpweb.go new file mode 100644 index 0000000..69dc1d1 --- /dev/null +++ b/vscpweb.go @@ -0,0 +1,144 @@ +// This is a system for playing with SDN based openvswitches using a simple web +// interface. This project will be combined with a CLI version or probably just +// made compatible with a core version in the future. +package vscpweb + +import ( + "fmt" + "net/http" + + hh "healthHandlers" + + "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5/middleware" +) + +// mh "managementHandlers" +// sh "staticHandlers" +// vh "virtualAPIHandlers" +// ch "controllerHandlers" +func main() { + //create a new server and mount the handlers: + s := CreateNewServer() + s.MountHandlers() + //staring up the server: + http.ListenAndServe(":8000", s.Router) +} + +type server struct { + Router *chi.Mux + //suggestion to add config settings or DB in here +} + +func CreateNewServer() *server { + s := &server{} + s.Router = chi.NewRouter() + return s +} + +func (s *server) MountHandlers() { + + //Creation of the router: + //logging enables as a middleware + s.Router.Use(middleware.Logger) + //recover from panics and send a 500 internal error + s.Router.Use(middleware.Recoverer) + //a middleware to check if the server is alive + s.Router.Use(middleware.Heartbeat("/ping")) + //a profiler to check healt of server + s.Router.Mount("/debug", middleware.Profiler()) + //personalized 404 + s.Router.NotFound(GenericHandler404) + //personalized 405 + s.Router.MethodNotAllowed(GenericHandler405) + + //example: + //example of a get function and its handler + s.Router.Get("/example/{first}/{second:[0-9]+}", ExampleHandler) + + //Creating subrouters: + //healthRouter check on the health of nodes or main server + healthRouter := chi.NewRouter() + //controllerRouter Agnostic openVswitch controller bridge + controllerRouter := chi.NewRouter() + //managementRouter Start, stop, monitoring of the core (mininet) + managementRouter := chi.NewRouter() + //mininetApiRouter Interface with the virtual environment inside the core (mininet) + mininetApiRouter := chi.NewRouter() + //might want to check https://go-chi.io/#/pages/routing?id=routing-groups + //in order to make groups where you have other middleware like authentication + + //////////////////////////////////possible routing///////////////////////////// + //s.Router.Connect(pattern string, h http.HandlerFunc) + //s.Router.Delete(pattern string, h http.HandlerFunc) + //s.Router.Get(pattern string, h http.HandlerFunc) + //s.Router.Head(pattern string, h http.HandlerFunc) + //s.Router.Options(pattern string, h http.HandlerFunc) + //s.Router.Patch(pattern string, h http.HandlerFunc) + //s.Router.Post(pattern string, h http.HandlerFunc) + //s.Router.Put(pattern string, h http.HandlerFunc) + //s.Router.Trace(pattern string, h http.HandlerFunc) + /////////////////////////////////////////////////////////////////////////////// + + //generic ryu version at first... + //s.Router.Get("/", ) + //s.Router.Get("/access", ) + //s.Router.Get("/stats", ) + //s.Router.Get("/topology", ) + //s.Router.Get("/mpstat", )//DEPRECATED see: /masterHealth + //s.Router.Get("/ifstat", )//DEPRECATED see: /masterHealth + //s.Router.Get("/showtemp", )//DEPRECATED see: /masterHealth + //healthRouter.Get("/", )//this renders the health page "/health" + //healthRouter.Get("/ping", )// "/rpiping" + healthRouter.Get("/masterHealth", hh.MasterHealthHandler) //return a JSON with healt of the master "/free" + //controllerRouter.Delete("/flow", )//this is an external request "/flowdel" + //controllerRouter.Get("/resetflows", )//not sure if here or managementRouter + //controllerRouter.Get("/listswitch", ) + //controllerRouter.Get("/portDescription", )// "/portsdesc" + //controllerRouter.Get("/portStatus", )// "/portsstat" + //controllerRouter.Get("/tablestatus", ) + //controllerRouter.Get("/topology", )// "/gettopo" + //controllerRouter.Get("/status", ) + //mininetApiRouter.Get("/net", ) + //mininetApiRouter.Get("/nodes", ) + //mininetApiRouter.Get("/status", )// "/statusnodes" + //mininetApiRouter.Get("/intfs", ) + //mininetApiRouter.Get("/iperf", ) + //mininetApiRouter.Get("/pingall", ) + //mininetApiRouter.Get("/sendCommand", )// "/sendcommand" + //mininetApiRouter.Get("/placement", ) + //managementRouter.Get("/controllerData", ) // "/getcontrollerdata" + //managementRouter.Get("/vscpData", )// "/getvsorcdata" + //managementRouter.Get("/startController", )// "/startcontroller" + //managementRouter.Get("/startcontrollerAPI", )// "/startcontrollerrouter" + //managementRouter.Get("/stopController", )// "/stopcontroller" + //managementRouter.Get("/cancel", )// "/cancel" + //managementRouter.Get("/startVsorc", )// "/startvsorc" + //managementRouter.Get("/stopVsorc", )// "/stopvsorc" + //http.Handle("/", r) + + //Mounting all of the subrouters: + s.Router.Mount("/health", healthRouter) + s.Router.Mount("/controller", controllerRouter) + s.Router.Mount("/management", managementRouter) + s.Router.Mount("/virtualAPI", mininetApiRouter) + +} + +// GenericHandler404 is the universal 404 response of this front end +func GenericHandler404(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(404) + w.Write([]byte("route does not exist")) +} + +// GenericHandler405 is the universal 405 response of this front end +func GenericHandler405(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(405) + w.Write([]byte("Method not valid")) +} +func ExampleHandler(w http.ResponseWriter, r *http.Request) { + var1 := chi.URLParam(r, "first") + var2 := chi.URLParam(r, "second") + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, "First: %v\nSecond: %v", var1, var2) +}