aboutsummaryrefslogtreecommitdiffstats
path: root/src/orchestrator/api/add_intents_handler.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/orchestrator/api/add_intents_handler.go')
-rw-r--r--src/orchestrator/api/add_intents_handler.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/orchestrator/api/add_intents_handler.go b/src/orchestrator/api/add_intents_handler.go
index dfe1a496..fbf9007d 100644
--- a/src/orchestrator/api/add_intents_handler.go
+++ b/src/orchestrator/api/add_intents_handler.go
@@ -21,6 +21,7 @@ import (
"io"
"net/http"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation"
moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module"
"github.com/gorilla/mux"
@@ -70,6 +71,77 @@ func (h intentHandler) addIntentHandler(w http.ResponseWriter, r *http.Request)
}
}
+/*
+getIntentByNameHandler handles the URL
+URL: /v2/projects/{project-name}/composite-apps/{composite-app-name}/{version}/
+deployment-intent-groups/{deployment-intent-group-name}/intents?intent=<intent>
+*/
+func (h intentHandler) getIntentByNameHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ pList := []string{"project-name", "composite-app-name", "composite-app-version", "deployment-intent-group-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"]
+ di := vars["deployment-intent-group-name"]
+
+ iN := r.URL.Query().Get("intent")
+ if iN == "" {
+ http.Error(w, "Missing appName in GET request", http.StatusBadRequest)
+ return
+ }
+
+
+ mapOfIntents, err := h.client.GetIntentByName(iN, p, ca, v, di)
+ 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(mapOfIntents)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+}
+
+/*
+getAllIntentsHandler handles the URL
+URL: /v2/projects/{project-name}/composite-apps/{composite-app-name}/{version}/
+deployment-intent-groups/{deployment-intent-group-name}/intents
+*/
+func (h intentHandler) getAllIntentsHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ pList := []string{"project-name", "composite-app-name", "composite-app-version", "deployment-intent-group-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"]
+ di := vars["deployment-intent-group-name"]
+
+ mapOfIntents, err := h.client.GetAllIntents(p, ca, v, di)
+ 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(mapOfIntents)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+}
+
func (h intentHandler) getIntentHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)