Build related cleanup. Entrypoint to read config from correct place.
[ric-plt/appmgr.git] / cmd / appmgr / api.go
index 2de8b05..7acb7c7 100755 (executable)
@@ -26,6 +26,7 @@ import (
        "github.com/spf13/viper"
        "log"
        "net/http"
+       "time"
 )
 
 // API functions
@@ -42,6 +43,7 @@ func (m *XappManager) Initialize(h Helmer, cm ConfigMapper) {
                {"GET", "/ric/v1/health/ready", m.getHealthStatus},
 
                {"GET", "/ric/v1/xapps", m.getAllXapps},
+               {"GET", "/ric/v1/xapps/search", m.searchAllXapps},
                {"GET", "/ric/v1/xapps/{name}", m.getXappByName},
                {"GET", "/ric/v1/xapps/{name}/instances/{id}", m.getXappInstanceByName},
                {"POST", "/ric/v1/xapps", m.deployXapp},
@@ -155,6 +157,10 @@ func (m *XappManager) getAllXapps(w http.ResponseWriter, r *http.Request) {
        respondWithJSON(w, http.StatusOK, xapps)
 }
 
+func (m *XappManager) searchAllXapps(w http.ResponseWriter, r *http.Request) {
+       respondWithJSON(w, http.StatusOK, m.helm.SearchAll())
+}
+
 func (m *XappManager) deployXapp(w http.ResponseWriter, r *http.Request) {
        if r.Body == nil {
                Logger.Error("No xapp data found in request body - url=%s", r.URL.RequestURI())
@@ -176,6 +182,13 @@ func (m *XappManager) deployXapp(w http.ResponseWriter, r *http.Request) {
                return
        }
 
+       for i := 0; i < 3; i++ {
+               if xapp, err = m.helm.Status(xapp.Name); xapp.Instances != nil {
+                       break
+               }
+               time.Sleep(time.Duration(5) * time.Second)
+       }
+
        respondWithJSON(w, http.StatusCreated, xapp)
 
        m.sd.Publish(xapp, EventType("created"))