summaryrefslogtreecommitdiffstats
path: root/src/orchestrator/api
diff options
context:
space:
mode:
authorRitu Sood <Ritu.Sood@intel.com>2020-04-13 20:38:39 +0000
committerGerrit Code Review <gerrit@onap.org>2020-04-13 20:38:39 +0000
commit7945fcd8ed65792eeb174d999138b99dbc936a6f (patch)
tree01baba65c845f5af830e724f746357e640b63599 /src/orchestrator/api
parentc8ba8f21b68b64b4068f188614dd7c891edf035f (diff)
parentf65daf54a4ab24be9e2c82236a511cedc3bdf230 (diff)
Merge "Adding query APIs for AppIntents"
Diffstat (limited to 'src/orchestrator/api')
-rw-r--r--src/orchestrator/api/api.go3
-rw-r--r--src/orchestrator/api/app_intent_handler.go76
-rw-r--r--src/orchestrator/api/app_profilehandler.go8
3 files changed, 80 insertions, 7 deletions
diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go
index fbd29563..3e3f3eaa 100644
--- a/src/orchestrator/api/api.go
+++ b/src/orchestrator/api/api.go
@@ -137,8 +137,9 @@ func NewRouter(projectClient moduleLib.ProjectManager,
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents/{intent-name}/app-intents", appIntentHandler.createAppIntentHandler).Methods("POST")
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents/{intent-name}/app-intents/{app-intent-name}", appIntentHandler.getAppIntentHandler).Methods("GET")
+ router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents/{intent-name}/app-intents", appIntentHandler.getAllAppIntentsHandler).Methods("GET")
+ router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents/{intent-name}/app-intents/", appIntentHandler.getAllIntentsByAppHandler).Queries("app-name", "{app-name}")
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents/{intent-name}/app-intents/{app-intent-name}", appIntentHandler.deleteAppIntentHandler).Methods("DELETE")
-
//setting routes for deploymentIntentGroup
if deploymentIntentGrpClient == nil {
deploymentIntentGrpClient = moduleClient.DeploymentIntentGroup
diff --git a/src/orchestrator/api/app_intent_handler.go b/src/orchestrator/api/app_intent_handler.go
index ab510c8e..4b3282ef 100644
--- a/src/orchestrator/api/app_intent_handler.go
+++ b/src/orchestrator/api/app_intent_handler.go
@@ -18,10 +18,12 @@ package api
import (
"encoding/json"
- "github.com/gorilla/mux"
- moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module"
"io"
"net/http"
+
+ "github.com/gorilla/mux"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation"
+ moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module"
)
/* Used to store backend implementation objects
@@ -120,6 +122,76 @@ func (h appIntentHandler) getAppIntentHandler(w http.ResponseWriter, r *http.Req
}
+/*
+getAllIntentsByAppHandler handles the URL:
+/v2/project/{project-name}/composite-apps/{composite-app-name}/{version}/generic-placement-intent/{intent-name}/app-intents?app-name=<app-name>
+*/
+func (h appIntentHandler) getAllIntentsByAppHandler(w http.ResponseWriter, r *http.Request) {
+
+ vars := mux.Vars(r)
+ pList := []string{"project-name", "composite-app-name", "composite-app-version", "intent-name"}
+ err := validation.IsValidParameterPresent(vars, pList)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusBadRequest)
+ }
+ p := vars["project-name"]
+ ca := vars["composite-app-name"]
+ v := vars["composite-app-version"]
+ i := vars["intent-name"]
+ aN := r.URL.Query().Get("app-name")
+ if aN == "" {
+ http.Error(w, "Missing appName in GET request", http.StatusBadRequest)
+ return
+ }
+
+ specData, err := h.client.GetAllIntentsByApp(aN, p, ca, v, i)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(specData)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ return
+
+}
+
+/* getAllAppIntentsHandler handles the URL:
+/v2/project/{project-name}/composite-apps/{composite-app-name}/{version}/generic-placement-intent/{intent-name}/app-intents
+*/
+func (h appIntentHandler) getAllAppIntentsHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ pList := []string{"project-name", "composite-app-name", "composite-app-version", "intent-name"}
+ err := validation.IsValidParameterPresent(vars, pList)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusBadRequest)
+ }
+ p := vars["project-name"]
+ ca := vars["composite-app-name"]
+ v := vars["composite-app-version"]
+ i := vars["intent-name"]
+
+ applicationsAndClusterInfo, err := h.client.GetAllAppIntents(p, ca, v, i)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(applicationsAndClusterInfo)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ return
+
+}
+
func (h appIntentHandler) deleteAppIntentHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
diff --git a/src/orchestrator/api/app_profilehandler.go b/src/orchestrator/api/app_profilehandler.go
index ef7833de..f2475e23 100644
--- a/src/orchestrator/api/app_profilehandler.go
+++ b/src/orchestrator/api/app_profilehandler.go
@@ -210,12 +210,12 @@ func (h appProfileHandler) getAppProfileHandler(w http.ResponseWriter, r *http.R
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- kc_bytes, err := base64.StdEncoding.DecodeString(retAppProfileContent.Profile)
+ kcBytes, err := base64.StdEncoding.DecodeString(retAppProfileContent.Profile)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- _, err = pw.Write(kc_bytes)
+ _, err = pw.Write(kcBytes)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -231,12 +231,12 @@ func (h appProfileHandler) getAppProfileHandler(w http.ResponseWriter, r *http.R
case "application/octet-stream":
w.Header().Set("Content-Type", "application/octet-stream")
w.WriteHeader(http.StatusOK)
- kc_bytes, err := base64.StdEncoding.DecodeString(retAppProfileContent.Profile)
+ kcBytes, err := base64.StdEncoding.DecodeString(retAppProfileContent.Profile)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- _, err = w.Write(kc_bytes)
+ _, err = w.Write(kcBytes)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return