summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/orchestrator/api/api.go1
-rw-r--r--src/orchestrator/api/composite_app_handler.go26
-rw-r--r--src/orchestrator/pkg/module/compositeapp.go33
-rw-r--r--src/orchestrator/pkg/module/instantiation_appcontext_helper.go2
4 files changed, 61 insertions, 1 deletions
diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go
index 9194419c..5f1665ac 100644
--- a/src/orchestrator/api/api.go
+++ b/src/orchestrator/api/api.go
@@ -69,6 +69,7 @@ func NewRouter(projectClient moduleLib.ProjectManager,
}
router.HandleFunc("/projects/{project-name}/composite-apps", compAppHandler.createHandler).Methods("POST")
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{version}", compAppHandler.getHandler).Methods("GET")
+ router.HandleFunc("/projects/{project-name}/composite-apps", compAppHandler.getAllCompositeAppsHandler).Methods("GET")
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{version}", compAppHandler.deleteHandler).Methods("DELETE")
if appClient == nil {
diff --git a/src/orchestrator/api/composite_app_handler.go b/src/orchestrator/api/composite_app_handler.go
index b54c488e..ab052f00 100644
--- a/src/orchestrator/api/composite_app_handler.go
+++ b/src/orchestrator/api/composite_app_handler.go
@@ -95,6 +95,32 @@ func (h compositeAppHandler) getHandler(w http.ResponseWriter, r *http.Request)
}
}
+// getAllCompositeAppsHandler handles the GetAllComppositeApps, returns a list of compositeApps under a project
+func (h compositeAppHandler) getAllCompositeAppsHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ pName := vars["project-name"]
+
+ var caList []moduleLib.CompositeApp
+
+ cApps, err := h.client.GetAllCompositeApps(pName)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
+
+ for _, cApp := range cApps {
+ caList = append(caList, moduleLib.CompositeApp{Metadata: cApp.Metadata, Spec: cApp.Spec})
+ }
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(caList)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
+ return
+}
+
// deleteHandler handles DELETE operations on a particular CompositeApp Name
func (h compositeAppHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
diff --git a/src/orchestrator/pkg/module/compositeapp.go b/src/orchestrator/pkg/module/compositeapp.go
index 70502367..5bf7ddec 100644
--- a/src/orchestrator/pkg/module/compositeapp.go
+++ b/src/orchestrator/pkg/module/compositeapp.go
@@ -64,6 +64,7 @@ func (cK CompositeAppKey) String() string {
type CompositeAppManager interface {
CreateCompositeApp(c CompositeApp, p string) (CompositeApp, error)
GetCompositeApp(name string, version string, p string) (CompositeApp, error)
+ GetAllCompositeApps(p string) ([]CompositeApp, error)
DeleteCompositeApp(name string, version string, p string) error
}
@@ -140,6 +141,38 @@ func (v *CompositeAppClient) GetCompositeApp(name string, version string, p stri
return CompositeApp{}, pkgerrors.New("Error getting composite application")
}
+// GetAllCompositeApps returns all the compositeApp for a given project
+func (v *CompositeAppClient) GetAllCompositeApps(p string) ([]CompositeApp, error) {
+
+ _, err := NewProjectClient().GetProject(p)
+ if err != nil {
+ return []CompositeApp{}, pkgerrors.New("Unable to find the project")
+ }
+
+ key := CompositeAppKey{
+ CompositeAppName: "",
+ Version: "",
+ Project: p,
+ }
+
+ var caList []CompositeApp
+ values, err := db.DBconn.Find(v.storeName, key, v.tagMeta)
+ if err != nil {
+ return []CompositeApp{}, pkgerrors.Wrap(err, "Getting CompositeApps")
+ }
+
+ for _, value := range values {
+ ca := CompositeApp{}
+ err = db.DBconn.Unmarshal(value, &ca)
+ if err != nil {
+ return []CompositeApp{}, pkgerrors.Wrap(err, "Unmarshaling CompositeApp")
+ }
+ caList = append(caList, ca)
+ }
+
+ return caList, nil
+}
+
// DeleteCompositeApp deletes the CompositeApp from database
func (v *CompositeAppClient) DeleteCompositeApp(name string, version string, p string) error {
diff --git a/src/orchestrator/pkg/module/instantiation_appcontext_helper.go b/src/orchestrator/pkg/module/instantiation_appcontext_helper.go
index 1cb3f23d..a8c6eda7 100644
--- a/src/orchestrator/pkg/module/instantiation_appcontext_helper.go
+++ b/src/orchestrator/pkg/module/instantiation_appcontext_helper.go
@@ -89,7 +89,7 @@ func getResources(st []helm.KubernetesResourceTemplate) ([]resource, error) {
// This might happen when the rendered file just has some comments inside, no real k8s object.
if n == SEPARATOR {
log.Info(":: Ignoring, Unable to render the template ::", log.Fields{"YAML PATH": t.FilePath})
- continue;
+ continue
}
resources = append(resources, resource{name: n, filecontent: string(yamlFile)})