aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRajamohan Raj <rajamohan.raj@intel.com>2020-04-10 05:02:58 +0000
committerRajamohan Raj <rajamohan.raj@intel.com>2020-04-13 20:47:18 +0000
commitf853b30cdc2655f6889f24214ba21791351c0787 (patch)
treee9b51952b48f6889526084acba7ccd622af213d3 /src
parent7945fcd8ed65792eeb174d999138b99dbc936a6f (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')
-rw-r--r--src/orchestrator/api/add_intents_handler.go72
-rw-r--r--src/orchestrator/api/api.go2
-rw-r--r--src/orchestrator/api/app_intent_handler.go3
-rw-r--r--src/orchestrator/pkg/module/add_intents.go88
-rw-r--r--src/orchestrator/pkg/module/app_intent.go4
5 files changed, 155 insertions, 14 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) {
diff --git a/src/orchestrator/pkg/module/add_intents.go b/src/orchestrator/pkg/module/add_intents.go
index 609f65ab..a4d677b7 100644
--- a/src/orchestrator/pkg/module/add_intents.go
+++ b/src/orchestrator/pkg/module/add_intents.go
@@ -46,23 +46,22 @@ type IntentMetaData struct {
// IntentSpecData has Intent
type IntentSpecData struct {
- Intent IntentObj `json:"intent"`
+ Intent map[string]string `json:"intent"`
}
-// IntentObj has name of the generic placement intent
-type IntentObj struct {
- Generic string `json:"generic"`
-}
// ListOfIntents is a list of intents
type ListOfIntents struct {
ListOfIntents []map[string]string `json:"intent"`
}
+
// IntentManager is an interface which exposes the IntentManager functionality
type IntentManager interface {
AddIntent(a Intent, p string, ca string, v string, di string) (Intent, error)
GetIntent(i string, p string, ca string, v string, di string) (Intent, error)
+ GetAllIntents(p, ca, v, di string) (ListOfIntents, error)
+ GetIntentByName(i, p, ca, v, di string) (IntentSpecData, error)
DeleteIntent(i string, p string, ca string, v string, di string) error
}
@@ -100,13 +99,16 @@ func NewIntentClient() *IntentClient {
}
}
-// AddIntent adds a given intent to the deployment-intent-group and stores in the db. Other input parameters for it - projectName, compositeAppName, version, DeploymentIntentgroupName
+/*
+AddIntent adds a given intent to the deployment-intent-group and stores in the db.
+Other input parameters for it - projectName, compositeAppName, version, DeploymentIntentgroupName
+*/
func (c *IntentClient) AddIntent(a Intent, p string, ca string, v string, di string) (Intent, error) {
//Check for the AddIntent already exists here.
res, err := c.GetIntent(a.MetaData.Name, p, ca, v, di)
if !reflect.DeepEqual(res, Intent{}) {
- return Intent{}, pkgerrors.New("AppIntent already exists")
+ return Intent{}, pkgerrors.New("Intent already exists")
}
//Check if project exists
@@ -142,7 +144,10 @@ func (c *IntentClient) AddIntent(a Intent, p string, ca string, v string, di str
return a, nil
}
-// GetIntent returns an Intent
+/*
+GetIntent takes in an IntentName, ProjectName, CompositeAppName, Version and DeploymentIntentGroup.
+It returns the Intent.
+*/
func (c *IntentClient) GetIntent(i string, p string, ca string, v string, di string) (Intent, error) {
k := IntentKey{
@@ -155,7 +160,7 @@ func (c *IntentClient) GetIntent(i string, p string, ca string, v string, di str
result, err := db.DBconn.Find(c.storeName, k, c.tagMetaData)
if err != nil {
- return Intent{}, pkgerrors.Wrap(err, "Get AppIntent error")
+ return Intent{}, pkgerrors.Wrap(err, "Get Intent error")
}
if result != nil {
@@ -167,9 +172,71 @@ func (c *IntentClient) GetIntent(i string, p string, ca string, v string, di str
return a, nil
}
- return Intent{}, pkgerrors.New("Error getting AppIntent")
+ return Intent{}, pkgerrors.New("Error getting Intent")
+}
+
+
+/*
+GetIntentByName takes in IntentName, projectName, CompositeAppName, CompositeAppVersion
+and deploymentIntentGroupName returns the list of intents under the IntentName.
+*/
+func (c IntentClient) GetIntentByName(i string, p string, ca string, v string, di string) (IntentSpecData, error) {
+ k := IntentKey{
+ Name: i,
+ Project: p,
+ CompositeApp: ca,
+ Version: v,
+ DeploymentIntentGroup: di,
+ }
+ result, err := db.DBconn.Find(c.storeName, k, c.tagMetaData)
+ if err != nil {
+ return IntentSpecData{}, pkgerrors.Wrap(err, "Get AppIntent error")
+ }
+ var a Intent
+ err = db.DBconn.Unmarshal(result[0], &a)
+ if err != nil {
+ return IntentSpecData{}, pkgerrors.Wrap(err, "Unmarshalling Intent")
+ }
+ return a.Spec, nil
+}
+
+
+/*
+GetAllIntents takes in projectName, CompositeAppName, CompositeAppVersion,
+DeploymentIntentName . It returns ListOfIntents.
+*/
+func (c IntentClient) GetAllIntents(p string, ca string, v string, di string) (ListOfIntents, error) {
+ k := IntentKey{
+ Name: "",
+ Project: p,
+ CompositeApp: ca,
+ Version: v,
+ DeploymentIntentGroup: di,
+ }
+
+ result, err := db.DBconn.Find(c.storeName, k, c.tagMetaData)
+ if err != nil {
+ return ListOfIntents{}, pkgerrors.Wrap(err, "Get AppIntent error")
+ }
+ var a Intent
+ var listOfMapOfIntents []map[string]string
+
+ if len(result) != 0 {
+ for i := range result {
+ a = Intent{}
+ err = db.DBconn.Unmarshal(result[i], &a)
+ if err != nil {
+ return ListOfIntents{}, pkgerrors.Wrap(err, "Unmarshalling Intent")
+ }
+ //mapOfIntents := ListOfIntents{a.Spec.Intent.ListOfIntents}
+ listOfMapOfIntents = append(listOfMapOfIntents, a.Spec.Intent)
+ }
+ return ListOfIntents{listOfMapOfIntents}, nil
+ }
+ return ListOfIntents{}, err
}
+
// DeleteIntent deletes a given intent tied to project, composite app and deployment intent group
func (c IntentClient) DeleteIntent(i string, p string, ca string, v string, di string) error {
k := IntentKey{
@@ -185,5 +252,4 @@ func (c IntentClient) DeleteIntent(i string, p string, ca string, v string, di s
return pkgerrors.Wrap(err, "Delete Project entry;")
}
return nil
-
}
diff --git a/src/orchestrator/pkg/module/app_intent.go b/src/orchestrator/pkg/module/app_intent.go
index 2b2c0fa5..5f4acb4d 100644
--- a/src/orchestrator/pkg/module/app_intent.go
+++ b/src/orchestrator/pkg/module/app_intent.go
@@ -232,12 +232,12 @@ func (c *AppIntentClient) GetAllIntentsByApp(aN, p, ca, v, i string) (SpecData,
}
result, err := db.DBconn.Find(c.storeName, k, c.tagMetaData)
if err != nil {
- return SpecData{}, pkgerrors.Wrap(err, "Get SpecData error")
+ return SpecData{}, pkgerrors.Wrap(err, "Get AppIntent error")
}
var a AppIntent
err = db.DBconn.Unmarshal(result[0], &a)
if err != nil {
- return SpecData{}, pkgerrors.Wrap(err, "Unmarshalling SpecData")
+ return SpecData{}, pkgerrors.Wrap(err, "Unmarshalling AppIntent")
}
return a.Spec, nil