aboutsummaryrefslogtreecommitdiffstats
path: root/src/orchestrator/api
diff options
context:
space:
mode:
authorRitu Sood <Ritu.Sood@intel.com>2020-09-01 21:18:45 +0000
committerGerrit Code Review <gerrit@onap.org>2020-09-01 21:18:45 +0000
commite6277404b61f508d6af11b3e8bb067d716ba21c0 (patch)
treef146afe803c008576b07ea353a5bc05541e663db /src/orchestrator/api
parent65e4059d86a5f0dda682ebd879f409be18afa5b0 (diff)
parent645c6a331cd00043fcf9f567f5f261a9db070918 (diff)
Merge "Enhance the status query API"
Diffstat (limited to 'src/orchestrator/api')
-rw-r--r--src/orchestrator/api/api.go2
-rw-r--r--src/orchestrator/api/instantiation_handler.go95
2 files changed, 94 insertions, 3 deletions
diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go
index 72b444b7..de69d163 100644
--- a/src/orchestrator/api/api.go
+++ b/src/orchestrator/api/api.go
@@ -194,6 +194,8 @@ func NewRouter(projectClient moduleLib.ProjectManager,
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/instantiate", instantiationHandler.instantiateHandler).Methods("POST")
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/terminate", instantiationHandler.terminateHandler).Methods("POST")
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/status", instantiationHandler.statusHandler).Methods("GET")
+ router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/status",
+ instantiationHandler.statusHandler).Queries("instance", "{instance}", "type", "{type}", "output", "{output}", "app", "{app}", "cluster", "{cluster}", "resource", "{resource}")
return router
}
diff --git a/src/orchestrator/api/instantiation_handler.go b/src/orchestrator/api/instantiation_handler.go
index eeac8a00..f9f86954 100644
--- a/src/orchestrator/api/instantiation_handler.go
+++ b/src/orchestrator/api/instantiation_handler.go
@@ -19,8 +19,11 @@ package api
import (
"encoding/json"
"net/http"
+ "net/url"
+ "strings"
"github.com/gorilla/mux"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation"
moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module"
)
@@ -90,7 +93,95 @@ func (h instantiationHandler) statusHandler(w http.ResponseWriter, r *http.Reque
v := vars["composite-app-version"]
di := vars["deployment-intent-group-name"]
- status, iErr := h.client.Status(p, ca, v, di)
+ qParams, err := url.ParseQuery(r.URL.RawQuery)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusBadRequest)
+ return
+ }
+
+ var queryInstance string
+ if o, found := qParams["instance"]; found {
+ queryInstance = o[0]
+ if queryInstance == "" {
+ http.Error(w, "Invalid query instance", http.StatusBadRequest)
+ return
+ }
+ } else {
+ queryInstance = "" // default instance value
+ }
+
+ var queryType string
+ if t, found := qParams["type"]; found {
+ queryType = t[0]
+ if queryType != "cluster" && queryType != "rsync" {
+ http.Error(w, "Invalid query type", http.StatusBadRequest)
+ return
+ }
+ } else {
+ queryType = "rsync" // default type
+ }
+
+ var queryOutput string
+ if o, found := qParams["output"]; found {
+ queryOutput = o[0]
+ if queryOutput != "summary" && queryOutput != "all" && queryOutput != "detail" {
+ http.Error(w, "Invalid query output", http.StatusBadRequest)
+ return
+ }
+ } else {
+ queryOutput = "all" // default output format
+ }
+
+ var queryApps []string
+ if a, found := qParams["app"]; found {
+ queryApps = a
+ for _, app := range queryApps {
+ errs := validation.IsValidName(app)
+ if len(errs) > 0 {
+ http.Error(w, "Invalid app query", http.StatusBadRequest)
+ return
+ }
+ }
+ } else {
+ queryApps = make([]string, 0)
+ }
+
+ var queryClusters []string
+ if c, found := qParams["cluster"]; found {
+ queryClusters = c
+ for _, cl := range queryClusters {
+ parts := strings.Split(cl, "+")
+ if len(parts) != 2 {
+ http.Error(w, "Invalid cluster query", http.StatusBadRequest)
+ return
+ }
+ for _, p := range parts {
+ errs := validation.IsValidName(p)
+ if len(errs) > 0 {
+ http.Error(w, "Invalid cluster query", http.StatusBadRequest)
+ return
+ }
+ }
+ }
+ } else {
+ queryClusters = make([]string, 0)
+ }
+
+ var queryResources []string
+ if r, found := qParams["resource"]; found {
+ queryResources = r
+ for _, res := range queryResources {
+ errs := validation.IsValidName(res)
+ if len(errs) > 0 {
+ http.Error(w, "Invalid resources query", http.StatusBadRequest)
+ return
+ }
+ }
+ } else {
+ queryResources = make([]string, 0)
+ }
+
+ status, iErr := h.client.Status(p, ca, v, di, queryInstance, queryType, queryOutput, queryApps, queryClusters, queryResources)
if iErr != nil {
http.Error(w, iErr.Error(), http.StatusInternalServerError)
return
@@ -103,6 +194,4 @@ func (h instantiationHandler) statusHandler(w http.ResponseWriter, r *http.Reque
http.Error(w, iErr.Error(), http.StatusInternalServerError)
return
}
- w.WriteHeader(http.StatusAccepted)
-
}