summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/orchestrator/api/api.go1
-rw-r--r--src/orchestrator/api/projecthandler.go25
-rw-r--r--src/orchestrator/api/projecthandler_test.go4
-rw-r--r--src/orchestrator/pkg/module/project.go24
-rw-r--r--src/rsync/pkg/context/context.go4
5 files changed, 56 insertions, 2 deletions
diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go
index 5abbb96d..9194419c 100644
--- a/src/orchestrator/api/api.go
+++ b/src/orchestrator/api/api.go
@@ -57,6 +57,7 @@ func NewRouter(projectClient moduleLib.ProjectManager,
}
router.HandleFunc("/projects", projHandler.createHandler).Methods("POST")
router.HandleFunc("/projects/{project-name}", projHandler.getHandler).Methods("GET")
+ router.HandleFunc("/projects", projHandler.getHandler).Methods("GET")
router.HandleFunc("/projects/{project-name}", projHandler.deleteHandler).Methods("DELETE")
//setting routes for compositeApp
diff --git a/src/orchestrator/api/projecthandler.go b/src/orchestrator/api/projecthandler.go
index 1e78c676..09b24096 100644
--- a/src/orchestrator/api/projecthandler.go
+++ b/src/orchestrator/api/projecthandler.go
@@ -75,6 +75,31 @@ func (h projectHandler) getHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
name := vars["project-name"]
+ // handle for get all projects
+ if len(name) == 0 {
+ var pList []moduleLib.Project
+
+ projects, err := h.client.GetAllProjects()
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ for _, p := range projects {
+ pList = append(pList, moduleLib.Project{MetaData: p.MetaData})
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(pList)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ return
+
+ }
+
ret, err := h.client.GetProject(name)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
diff --git a/src/orchestrator/api/projecthandler_test.go b/src/orchestrator/api/projecthandler_test.go
index 0212e57a..dae87e2b 100644
--- a/src/orchestrator/api/projecthandler_test.go
+++ b/src/orchestrator/api/projecthandler_test.go
@@ -60,6 +60,10 @@ func (m *mockProjectManager) DeleteProject(name string) error {
return m.Err
}
+func (m *mockProjectManager) GetAllProjects() ([]moduleLib.Project, error) {
+ return []moduleLib.Project{}, m.Err
+}
+
func TestProjectCreateHandler(t *testing.T) {
testCases := []struct {
label string
diff --git a/src/orchestrator/pkg/module/project.go b/src/orchestrator/pkg/module/project.go
index a6f59254..02f6d827 100644
--- a/src/orchestrator/pkg/module/project.go
+++ b/src/orchestrator/pkg/module/project.go
@@ -58,6 +58,7 @@ type ProjectManager interface {
CreateProject(pr Project) (Project, error)
GetProject(name string) (Project, error)
DeleteProject(name string) error
+ GetAllProjects() ([]Project, error)
}
// ProjectClient implements the ProjectManager
@@ -123,6 +124,29 @@ func (v *ProjectClient) GetProject(name string) (Project, error) {
return Project{}, pkgerrors.New("Error getting Project")
}
+// GetAllProjects returns all the projects
+func (v *ProjectClient) GetAllProjects() ([]Project, error) {
+ key := ProjectKey{
+ ProjectName: "",
+ }
+
+ var res []Project
+ values, err := db.DBconn.Find(v.storeName, key, v.tagMeta)
+ if err != nil {
+
+ }
+
+ for _, value := range values {
+ p := Project{}
+ err = db.DBconn.Unmarshal(value, &p)
+ if err != nil {
+ return []Project{}, pkgerrors.Wrap(err, "Unmarshaling Project")
+ }
+ res = append(res, p)
+ }
+ return res, nil
+}
+
// DeleteProject the Project from database
func (v *ProjectClient) DeleteProject(name string) error {
diff --git a/src/rsync/pkg/context/context.go b/src/rsync/pkg/context/context.go
index 3ce6ee9b..f6a33ad8 100644
--- a/src/rsync/pkg/context/context.go
+++ b/src/rsync/pkg/context/context.go
@@ -74,7 +74,7 @@ func terminateResource(ac appcontext.AppContext, c *kubeclient.Client, name stri
}
logutils.Info("Deleted::", logutils.Fields{
"cluster": cluster,
- "resource": res,
+ "resource": name,
})
return nil
}
@@ -124,7 +124,7 @@ func instantiateResource(ac appcontext.AppContext, c *kubeclient.Client, name st
}
logutils.Info("Installed::", logutils.Fields{
"cluster": cluster,
- "resource": res,
+ "resource": name,
})
return nil
}