aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRajamohan Raj <rajamohan.raj@intel.com>2020-07-17 14:04:19 +0000
committerRajamohan Raj <rajamohan.raj@intel.com>2020-07-17 20:38:24 +0000
commit75178df33f0cc45f46051394ad9d14f6a84cd8e9 (patch)
tree3c89f320e6879c175a2760e41bec634fff5aa22c
parent09ade2b51d5e3d4da5921115a993bec97a905e1b (diff)
Add APIs for getAll DeploymentIntents and GetAll GenericPlacemnetIntents
In this patch, implemented two separate routes for getting all genericPlacemnetIntents and getting all deployment intents. Issue-ID: MULTICLOUD-1128 Signed-off-by: Rajamohan Raj <rajamohan.raj@intel.com> Change-Id: I81fadb126752788da7c459aa43896fafa583310e
-rw-r--r--src/orchestrator/api/api.go7
-rw-r--r--src/orchestrator/api/deployment_intent_groups_handler.go26
-rw-r--r--src/orchestrator/api/generic_placement_intent_handler.go26
-rw-r--r--src/orchestrator/pkg/module/deployment_intent_groups.go45
-rw-r--r--src/orchestrator/pkg/module/generic_placement_intent.go43
5 files changed, 145 insertions, 2 deletions
diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go
index 5f1665ac..097b9ab3 100644
--- a/src/orchestrator/api/api.go
+++ b/src/orchestrator/api/api.go
@@ -128,7 +128,11 @@ func NewRouter(projectClient moduleLib.ProjectManager,
client: genericPlacementIntentClient,
}
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents", genericPlacementIntentHandler.createGenericPlacementIntentHandler).Methods("POST")
+
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents/{intent-name}", genericPlacementIntentHandler.getGenericPlacementHandler).Methods("GET")
+
+ router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents", genericPlacementIntentHandler.getAllGenericPlacementIntentsHandler).Methods("GET")
+
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents/{intent-name}", genericPlacementIntentHandler.deleteGenericPlacementHandler).Methods("DELETE")
//setting routes for AppIntent
@@ -155,6 +159,9 @@ func NewRouter(projectClient moduleLib.ProjectManager,
}
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups", deploymentIntentGrpHandler.createDeploymentIntentGroupHandler).Methods("POST")
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}", deploymentIntentGrpHandler.getDeploymentIntentGroupHandler).Methods("GET")
+
+ router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups", deploymentIntentGrpHandler.getAllDeploymentIntentGroupsHandler).Methods("GET")
+
router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}", deploymentIntentGrpHandler.deleteDeploymentIntentGroupHandler).Methods("DELETE")
// setting routes for AddingIntents
diff --git a/src/orchestrator/api/deployment_intent_groups_handler.go b/src/orchestrator/api/deployment_intent_groups_handler.go
index 3f5b3969..7620737b 100644
--- a/src/orchestrator/api/deployment_intent_groups_handler.go
+++ b/src/orchestrator/api/deployment_intent_groups_handler.go
@@ -22,6 +22,7 @@ import (
"net/http"
moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation"
"github.com/gorilla/mux"
)
@@ -116,6 +117,31 @@ func (h deploymentIntentGroupHandler) getDeploymentIntentGroupHandler(w http.Res
}
+func (h deploymentIntentGroupHandler) getAllDeploymentIntentGroupsHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ pList := []string{"project-name", "composite-app-name", "composite-app-version"}
+ 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"]
+
+ diList, err := h.client.GetAllDeploymentIntentGroups(p, ca, v)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(diList)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
+}
+
func (h deploymentIntentGroupHandler) deleteDeploymentIntentGroupHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
diff --git a/src/orchestrator/api/generic_placement_intent_handler.go b/src/orchestrator/api/generic_placement_intent_handler.go
index e186735c..02dbf0be 100644
--- a/src/orchestrator/api/generic_placement_intent_handler.go
+++ b/src/orchestrator/api/generic_placement_intent_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"
@@ -113,6 +114,31 @@ func (h genericPlacementIntentHandler) getGenericPlacementHandler(w http.Respons
}
}
+func (h genericPlacementIntentHandler) getAllGenericPlacementIntentsHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ pList := []string{"project-name", "composite-app-name", "composite-app-version"}
+ 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"]
+
+ gpList, err := h.client.GetAllGenericPlacementIntents(p, ca, v)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ err = json.NewEncoder(w).Encode(gpList)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
+}
+
// deleteGenericPlacementHandler handles the delete operations on intent
func (h genericPlacementIntentHandler) deleteGenericPlacementHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
diff --git a/src/orchestrator/pkg/module/deployment_intent_groups.go b/src/orchestrator/pkg/module/deployment_intent_groups.go
index 0decb68f..c7237032 100644
--- a/src/orchestrator/pkg/module/deployment_intent_groups.go
+++ b/src/orchestrator/pkg/module/deployment_intent_groups.go
@@ -64,6 +64,7 @@ type DeploymentIntentGroupManager interface {
GetDeploymentIntentGroup(di string, p string, ca string, v string) (DeploymentIntentGroup, error)
GetDeploymentIntentGroupContext(di string, p string, ca string, v string) (appcontext.AppContext, string, error)
DeleteDeploymentIntentGroup(di string, p string, ca string, v string) error
+ GetAllDeploymentIntentGroups(p string, ca string, v string) ([]DeploymentIntentGroup, error)
}
// DeploymentIntentGroupKey consists of Name of the deployment group, project name, CompositeApp name, CompositeApp version
@@ -106,7 +107,7 @@ func (c *DeploymentIntentGroupClient) CreateDeploymentIntentGroup(d DeploymentIn
res, err := c.GetDeploymentIntentGroup(d.MetaData.Name, p, ca, v)
if !reflect.DeepEqual(res, DeploymentIntentGroup{}) {
- return DeploymentIntentGroup{}, pkgerrors.New("AppIntent already exists")
+ return DeploymentIntentGroup{}, pkgerrors.New("DeploymentIntent already exists")
}
//Check if project exists
@@ -164,7 +165,47 @@ func (c *DeploymentIntentGroupClient) GetDeploymentIntentGroup(di string, p stri
}
-// GetDeploymentIntentGroup returns the DeploymentIntentGroup with a given name, project, compositeApp and version of compositeApp
+// GetAllDeploymentIntentGroups returns all the deploymentIntentGroups under a specific project, compositeApp and version
+func (c *DeploymentIntentGroupClient) GetAllDeploymentIntentGroups(p string, ca string, v string) ([]DeploymentIntentGroup, error) {
+
+ key := DeploymentIntentGroupKey{
+ Name: "",
+ Project: p,
+ CompositeApp: ca,
+ Version: v,
+ }
+
+ //Check if project exists
+ _, err := NewProjectClient().GetProject(p)
+ if err != nil {
+ return []DeploymentIntentGroup{}, pkgerrors.Wrap(err, "Unable to find the project")
+ }
+
+ //check if compositeApp exists
+ _, err = NewCompositeAppClient().GetCompositeApp(ca, v, p)
+ if err != nil {
+ return []DeploymentIntentGroup{}, pkgerrors.Wrap(err, "Unable to find the composite-app, check CompositeAppName and Version")
+ }
+ var diList []DeploymentIntentGroup
+ result, err := db.DBconn.Find(c.storeName, key, c.tagMetaData)
+ if err != nil {
+ return []DeploymentIntentGroup{}, pkgerrors.Wrap(err, "Get DeploymentIntentGroup error")
+ }
+
+ for _, value := range result {
+ di := DeploymentIntentGroup{}
+ err = db.DBconn.Unmarshal(value, &di)
+ if err != nil {
+ return []DeploymentIntentGroup{}, pkgerrors.Wrap(err, "Unmarshaling DeploymentIntentGroup")
+ }
+ diList = append(diList, di)
+ }
+
+ return diList, nil
+
+}
+
+// GetDeploymentIntentGroupContext returns the AppContent with a given DeploymentIntentname, project, compositeAppName and version of compositeApp
func (c *DeploymentIntentGroupClient) GetDeploymentIntentGroupContext(di string, p string, ca string, v string) (appcontext.AppContext, string, error) {
key := DeploymentIntentGroupKey{
diff --git a/src/orchestrator/pkg/module/generic_placement_intent.go b/src/orchestrator/pkg/module/generic_placement_intent.go
index 73849474..fb00a6ab 100644
--- a/src/orchestrator/pkg/module/generic_placement_intent.go
+++ b/src/orchestrator/pkg/module/generic_placement_intent.go
@@ -50,6 +50,8 @@ type GenericPlacementIntentManager interface {
compositeAppName string, version string) (GenericPlacementIntent, error)
DeleteGenericPlacementIntent(intentName string, projectName string,
compositeAppName string, version string) error
+
+ GetAllGenericPlacementIntents(p string, ca string, v string) ([]GenericPlacementIntent, error)
}
// GenericPlacementIntentKey is used as the primary key
@@ -148,6 +150,47 @@ func (c *GenericPlacementIntentClient) GetGenericPlacementIntent(i string, p str
}
+// GetAllGenericPlacementIntents returns all the generic placement intents for a given compsoite app name, composite app version and project.
+func (c *GenericPlacementIntentClient) GetAllGenericPlacementIntents(p string, ca string, v string) ([]GenericPlacementIntent, error) {
+
+ //Check if project exists
+ _, err := NewProjectClient().GetProject(p)
+ if err != nil {
+ return []GenericPlacementIntent{}, pkgerrors.Wrap(err, "Unable to find the project")
+ }
+
+ // check if compositeApp exists
+ _, err = NewCompositeAppClient().GetCompositeApp(ca, v, p)
+ if err != nil {
+ return []GenericPlacementIntent{}, pkgerrors.Wrap(err, "Unable to find the composite-app, check compositeApp name and version")
+ }
+
+ key := GenericPlacementIntentKey{
+ Name: "",
+ Project: p,
+ CompositeApp: ca,
+ Version: v,
+ }
+
+ var gpList []GenericPlacementIntent
+ values, err := db.DBconn.Find(c.storeName, key, c.tagMetaData)
+ if err != nil {
+ return []GenericPlacementIntent{}, pkgerrors.Wrap(err, "Getting GenericPlacementIntent")
+ }
+
+ for _, value := range values {
+ gp := GenericPlacementIntent{}
+ err = db.DBconn.Unmarshal(value, &gp)
+ if err != nil {
+ return []GenericPlacementIntent{}, pkgerrors.Wrap(err, "Unmarshaling GenericPlacementIntent")
+ }
+ gpList = append(gpList, gp)
+ }
+
+ return gpList, nil
+
+}
+
// DeleteGenericPlacementIntent the intent from the database
func (c *GenericPlacementIntentClient) DeleteGenericPlacementIntent(i string, p string, ca string, v string) error {
key := GenericPlacementIntentKey{