diff options
author | Rajamohan Raj <rajamohan.raj@intel.com> | 2020-04-10 05:02:58 +0000 |
---|---|---|
committer | Rajamohan Raj <rajamohan.raj@intel.com> | 2020-04-13 20:47:18 +0000 |
commit | f853b30cdc2655f6889f24214ba21791351c0787 (patch) | |
tree | e9b51952b48f6889526084acba7ccd622af213d3 /src/orchestrator/api | |
parent | 7945fcd8ed65792eeb174d999138b99dbc936a6f (diff) |
Added query routes for deploymentIntentGroup
In this patch added a route which
can query allIntents belonging to a DeploymentIntentGroup
and another route for querying all intents under an intent
in a deploymentIntentGroup
Issue-ID: MULTICLOUD-1049
Signed-off-by: Rajamohan Raj <rajamohan.raj@intel.com>
Change-Id: I06ec4d2ee8dae2aeca77e4db3ca690863014cc62
Diffstat (limited to 'src/orchestrator/api')
-rw-r--r-- | src/orchestrator/api/add_intents_handler.go | 72 | ||||
-rw-r--r-- | src/orchestrator/api/api.go | 2 | ||||
-rw-r--r-- | src/orchestrator/api/app_intent_handler.go | 3 |
3 files changed, 76 insertions, 1 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) diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go index 3e3f3eaa..6277d994 100644 --- a/src/orchestrator/api/api.go +++ b/src/orchestrator/api/api.go @@ -163,6 +163,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}/intents", intentHandler.addIntentHandler).Methods("POST") router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/intents/{intent-name}", intentHandler.getIntentHandler).Methods("GET") + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/intents", intentHandler.getAllIntentsHandler).Methods("GET") + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/intents/", intentHandler.getIntentByNameHandler).Queries("intent", "{intent}") router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/intents/{intent-name}", intentHandler.deleteIntentHandler).Methods("DELETE") // setting routes for Instantiation diff --git a/src/orchestrator/api/app_intent_handler.go b/src/orchestrator/api/app_intent_handler.go index 4b3282ef..56811d2d 100644 --- a/src/orchestrator/api/app_intent_handler.go +++ b/src/orchestrator/api/app_intent_handler.go @@ -160,7 +160,8 @@ func (h appIntentHandler) getAllIntentsByAppHandler(w http.ResponseWriter, r *ht } -/* getAllAppIntentsHandler handles the URL: +/* +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) { |