summaryrefslogtreecommitdiffstats
path: root/src/orchestrator
diff options
context:
space:
mode:
authorSrivahni Chivukula <srivahni.chivukula@intel.com>2020-03-12 15:50:42 -0700
committerSrivahni Chivukula <srivahni.chivukula@intel.com>2020-03-12 15:59:21 -0700
commit3b848c7b4b6a4a49658bd9275a0baa6a08effe2a (patch)
tree2dc70d3fe52215dfacb624ab0ade71f8895c4b2a /src/orchestrator
parent9c63ce2a7b2b66b3e3fce5d1f553f327148df83f (diff)
Added getAllApps functionality in App api
Issue-ID: MULTICLOUD-994 Signed-off-by: Srivahni Chivukula <srivahni.chivukula@intel.com> Change-Id: I459504c45b9bedea0e6bc15ca57e7876d5f59d28
Diffstat (limited to 'src/orchestrator')
-rw-r--r--src/orchestrator/api/api.go1
-rw-r--r--src/orchestrator/api/apphandler.go24
-rw-r--r--src/orchestrator/pkg/module/app.go29
3 files changed, 54 insertions, 0 deletions
diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go
index 70b40d96..a261319c 100644
--- a/src/orchestrator/api/api.go
+++ b/src/orchestrator/api/api.go
@@ -84,6 +84,7 @@ func NewRouter(projectClient moduleLib.ProjectManager,
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{version}/apps", appHandler.createAppHandler).Methods("POST")
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{version}/apps/{app-name}", appHandler.getAppHandler).Methods("GET")
+ router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{version}/apps", appHandler.getAppHandler).Methods("GET")
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{version}/apps/{app-name}", appHandler.deleteAppHandler).Methods("DELETE")
if compositeProfileClient == nil {
diff --git a/src/orchestrator/api/apphandler.go b/src/orchestrator/api/apphandler.go
index 3cd2dbc8..06341e7e 100644
--- a/src/orchestrator/api/apphandler.go
+++ b/src/orchestrator/api/apphandler.go
@@ -129,6 +129,30 @@ func (h appHandler) getAppHandler(w http.ResponseWriter, r *http.Request) {
compositeAppVersion := vars["version"]
name := vars["app-name"]
+ // handle the get all apps case - return a list of only the json parts
+ if len(name) == 0 {
+ var retList []moduleLib.App
+
+ ret, err := h.client.GetApps(projectName, compositeAppName, compositeAppVersion)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ for _, app := range ret {
+ retList = append(retList, moduleLib.App{Metadata: app.Metadata})
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(retList)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ return
+ }
+
accepted, _, err := mime.ParseMediaType(r.Header.Get("Accept"))
if err != nil {
http.Error(w, err.Error(), http.StatusNotAcceptable)
diff --git a/src/orchestrator/pkg/module/app.go b/src/orchestrator/pkg/module/app.go
index c25a1b51..1e1a5974 100644
--- a/src/orchestrator/pkg/module/app.go
+++ b/src/orchestrator/pkg/module/app.go
@@ -65,6 +65,7 @@ type AppManager interface {
CreateApp(a App, ac AppContent, p string, cN string, cV string) (App, error)
GetApp(name string, p string, cN string, cV string) (App, error)
GetAppContent(name string, p string, cN string, cV string) (AppContent, error)
+ GetApps(p string, cN string, cV string) ([]App, error)
DeleteApp(name string, p string, cN string, cV string) error
}
@@ -183,6 +184,34 @@ func (v *AppClient) GetAppContent(name string, p string, cN string, cV string) (
return AppContent{}, pkgerrors.New("Error getting app content")
}
+// GetApps returns all Apps for given composite App
+func (v *AppClient) GetApps(project, compositeApp, compositeAppVersion string) ([]App, error) {
+
+ key := AppKey{
+ App: "",
+ Project: project,
+ CompositeApp: compositeApp,
+ CompositeAppVersion: compositeAppVersion,
+ }
+
+ var resp []App
+ values, err := db.DBconn.Find(v.storeName, key, v.tagMeta)
+ if err != nil {
+ return []App{}, pkgerrors.Wrap(err, "Get Apps")
+ }
+
+ for _, value := range values {
+ a := App{}
+ err = db.DBconn.Unmarshal(value, &a)
+ if err != nil {
+ return []App{}, pkgerrors.Wrap(err, "Unmarshaling Value")
+ }
+ resp = append(resp, a)
+ }
+
+ return resp, nil
+}
+
// DeleteApp deletes the App from database
func (v *AppClient) DeleteApp(name string, p string, cN string, cV string) error {