2 * Copyright (c) 2019 AT&T Intellectual Property.
3 * Copyright (c) 2018-2019 Nokia.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
27 const SupervisionUrl = "/supervision/"
29 func startHttpServer(listener net.Listener, xappnotifUrl string, notif_ch chan []byte, supervision_ch chan chan string) {
30 go runHttpServer(listener, xappnotifUrl, notif_ch, supervision_ch)
33 func runHttpServer(listener net.Listener, xappNotifUrl string, notif_ch chan []byte, supervision_ch chan chan string) {
35 logger.Info("vesmgr http server serving at %s", listener.Addr())
37 http.HandleFunc(xappNotifUrl, func(w http.ResponseWriter, r *http.Request) {
41 logger.Info("httpServer: POST in %s", xappNotifUrl)
42 body, err := ioutil.ReadAll(r.Body)
45 logger.Error("httpServer: Invalid body in POST request")
51 logger.Error("httpServer: Invalid method %s to %s", r.Method, r.URL.Path)
52 http.Error(w, "405 method not allowed", http.StatusMethodNotAllowed)
57 http.HandleFunc(SupervisionUrl, func(w http.ResponseWriter, r *http.Request) {
61 logger.Info("httpServer: GET supervision")
62 supervision_ack_ch := make(chan string)
63 // send supervision to the main loop
64 supervision_ch <- supervision_ack_ch
65 reply := <-supervision_ack_ch
66 logger.Info("httpServer: supervision ack from the main loop: %s", reply)
70 logger.Error("httpServer: invalid method %s to %s", r.Method, r.URL.Path)
71 http.Error(w, "405 method not allowed", http.StatusMethodNotAllowed)
77 http.Serve(listener, nil)