X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=cmd%2Fvesmgr%2Fhttpserver.go;h=1ac099903141252b5e044103f043a7f4f2b63388;hb=6ffba08cc1c469c1ae04a6819445760ec75653b1;hp=585319e421e21004e9f4108c40a77e48e2cb5679;hpb=412df96a23a30a82d2a031556888aeaf9604ada8;p=ric-plt%2Fvespamgr.git diff --git a/cmd/vesmgr/httpserver.go b/cmd/vesmgr/httpserver.go index 585319e..1ac0999 100644 --- a/cmd/vesmgr/httpserver.go +++ b/cmd/vesmgr/httpserver.go @@ -13,6 +13,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * This source code is part of the near-RT RIC (RAN Intelligent Controller) + * platform project (RICP). + * */ package main @@ -24,28 +28,47 @@ import ( "net/http" ) -const SupervisionUrl = "/supervision/" +// SupervisionURL is the url where kubernetes posts alive queries +const SupervisionURL = "/supervision/" + +// HTTPServer is the VesMgr HTTP server struct +type HTTPServer struct { + listener net.Listener +} + +func (s *HTTPServer) init(address string) *HTTPServer { + var err error + s.listener, err = net.Listen("tcp", address) + if err != nil { + panic("Cannot listen:" + err.Error()) + } + return s +} + +func (s *HTTPServer) start(notifPath string, notifCh chan []byte, supCh chan chan string) { + go runHTTPServer(s.listener, notifPath, notifCh, supCh) +} -func startHttpServer(listener net.Listener, xappnotifUrl string, notif_ch chan []byte, supervision_ch chan chan string) { - go runHttpServer(listener, xappnotifUrl, notif_ch, supervision_ch) +func (s *HTTPServer) addr() net.Addr { + return s.listener.Addr() } -func runHttpServer(listener net.Listener, xappNotifUrl string, notif_ch chan []byte, supervision_ch chan chan string) { +func runHTTPServer(listener net.Listener, xappNotifURL string, notifCh chan []byte, supervisionCh chan chan string) { logger.Info("vesmgr http server serving at %s", listener.Addr()) - http.HandleFunc(xappNotifUrl, func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc(xappNotifURL, func(w http.ResponseWriter, r *http.Request) { switch r.Method { case "POST": - logger.Info("httpServer: POST in %s", xappNotifUrl) + logger.Info("httpServer: POST in %s", xappNotifURL) body, err := ioutil.ReadAll(r.Body) defer r.Body.Close() if err != nil { logger.Error("httpServer: Invalid body in POST request") return } - notif_ch <- body + notifCh <- body return default: logger.Error("httpServer: Invalid method %s to %s", r.Method, r.URL.Path) @@ -54,15 +77,15 @@ func runHttpServer(listener net.Listener, xappNotifUrl string, notif_ch chan []b } }) - http.HandleFunc(SupervisionUrl, func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc(SupervisionURL, func(w http.ResponseWriter, r *http.Request) { switch r.Method { case "GET": logger.Info("httpServer: GET supervision") - supervision_ack_ch := make(chan string) + supervisionAckCh := make(chan string) // send supervision to the main loop - supervision_ch <- supervision_ack_ch - reply := <-supervision_ack_ch + supervisionCh <- supervisionAckCh + reply := <-supervisionAckCh logger.Info("httpServer: supervision ack from the main loop: %s", reply) fmt.Fprintf(w, reply) return