aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRitu Sood <ritu.sood@intel.com>2020-10-05 22:45:20 +0000
committerGerrit Code Review <gerrit@onap.org>2020-10-05 22:45:20 +0000
commit9966f6af186676f38754c64759496eef0a1bc508 (patch)
treef52cdb3da9c6bf6f5f430b7f8b003b35cccc3f9e /src
parente70a776fd2d16d7d386af0354afd3e086068ef00 (diff)
parentd4b89af411ec7444b554a8b0ddeb7e239fa0fc73 (diff)
Merge "Modify GenericPlacement APIs to include DepIntGrp"
Diffstat (limited to 'src')
-rw-r--r--src/orchestrator/api/api.go18
-rw-r--r--src/orchestrator/api/app_intent_handler.go26
-rw-r--r--src/orchestrator/api/generic_placement_intent_handler.go17
-rw-r--r--src/orchestrator/json-schemas/deployment-group-intent.json13
-rw-r--r--src/orchestrator/json-schemas/generic-placement-intent.json15
-rw-r--r--src/orchestrator/pkg/module/app_intent.go49
-rw-r--r--src/orchestrator/pkg/module/app_intent_test.go43
-rw-r--r--src/orchestrator/pkg/module/deployment_intent_groups.go1
-rw-r--r--src/orchestrator/pkg/module/deployment_intent_groups_test.go8
-rw-r--r--src/orchestrator/pkg/module/generic_placement_intent.go44
-rw-r--r--src/orchestrator/pkg/module/generic_placement_intent_test.go56
-rw-r--r--src/orchestrator/pkg/module/instantiation.go2
12 files changed, 204 insertions, 88 deletions
diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go
index de69d163..07f8fe34 100644
--- a/src/orchestrator/api/api.go
+++ b/src/orchestrator/api/api.go
@@ -128,13 +128,13 @@ func NewRouter(projectClient moduleLib.ProjectManager,
genericPlacementIntentHandler := genericPlacementIntentHandler{
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}/deployment-intent-groups/{deployment-intent-group-name}/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}/deployment-intent-groups/{deployment-intent-group-name}/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}/deployment-intent-groups/{deployment-intent-group-name}/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")
+ router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/generic-placement-intents/{intent-name}", genericPlacementIntentHandler.deleteGenericPlacementHandler).Methods("DELETE")
//setting routes for AppIntent
if appIntentClient == nil {
@@ -145,11 +145,11 @@ func NewRouter(projectClient moduleLib.ProjectManager,
client: appIntentClient,
}
- 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")
+ router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/generic-placement-intents/{intent-name}/app-intents", appIntentHandler.createAppIntentHandler).Methods("POST")
+ router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/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}/deployment-intent-groups/{deployment-intent-group-name}/generic-placement-intents/{intent-name}/app-intents", appIntentHandler.getAllAppIntentsHandler).Methods("GET")
+ router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/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}/deployment-intent-groups/{deployment-intent-group-name}/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 1d48f8a6..3d0d5bad 100644
--- a/src/orchestrator/api/app_intent_handler.go
+++ b/src/orchestrator/api/app_intent_handler.go
@@ -62,8 +62,9 @@ func (h appIntentHandler) createAppIntentHandler(w http.ResponseWriter, r *http.
compositeAppName := vars["composite-app-name"]
version := vars["composite-app-version"]
intent := vars["intent-name"]
+ digName := vars["deployment-intent-group-name"]
- appIntent, createErr := h.client.CreateAppIntent(a, projectName, compositeAppName, version, intent)
+ appIntent, createErr := h.client.CreateAppIntent(a, projectName, compositeAppName, version, intent, digName)
if createErr != nil {
http.Error(w, createErr.Error(), http.StatusInternalServerError)
return
@@ -104,13 +105,19 @@ func (h appIntentHandler) getAppIntentHandler(w http.ResponseWriter, r *http.Req
return
}
+ dig := vars["deployment-intent-group-name"]
+ if dig == "" {
+ http.Error(w, "Missing deploymentIntentGroupName in GET request", http.StatusBadRequest)
+ return
+ }
+
ai := vars["app-intent-name"]
if ai == "" {
http.Error(w, "Missing appIntentName in GET request", http.StatusBadRequest)
return
}
- appIntent, err := h.client.GetAppIntent(ai, p, ca, v, i)
+ appIntent, err := h.client.GetAppIntent(ai, p, ca, v, i,dig)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -128,7 +135,7 @@ 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>
+/v2/project/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/generic-placement-intent/{intent-name}/app-intents?app-name=<app-name>
*/
func (h appIntentHandler) getAllIntentsByAppHandler(w http.ResponseWriter, r *http.Request) {
@@ -142,13 +149,15 @@ func (h appIntentHandler) getAllIntentsByAppHandler(w http.ResponseWriter, r *ht
ca := vars["composite-app-name"]
v := vars["composite-app-version"]
i := vars["intent-name"]
+ digName := vars["deployment-intent-group-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)
+ specData, err := h.client.GetAllIntentsByApp(aN, p, ca, v, i, digName)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -166,7 +175,7 @@ func (h appIntentHandler) getAllIntentsByAppHandler(w http.ResponseWriter, r *ht
/*
getAllAppIntentsHandler handles the URL:
-/v2/project/{project-name}/composite-apps/{composite-app-name}/{version}/generic-placement-intent/{intent-name}/app-intents
+/v2/project/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/generic-placement-intent/{intent-name}/app-intents
*/
func (h appIntentHandler) getAllAppIntentsHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
@@ -179,8 +188,9 @@ func (h appIntentHandler) getAllAppIntentsHandler(w http.ResponseWriter, r *http
ca := vars["composite-app-name"]
v := vars["composite-app-version"]
i := vars["intent-name"]
+ digName := vars["deployment-intent-group-name"]
- applicationsAndClusterInfo, err := h.client.GetAllAppIntents(p, ca, v, i)
+ applicationsAndClusterInfo, err := h.client.GetAllAppIntents(p, ca, v, i, digName)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -205,8 +215,10 @@ func (h appIntentHandler) deleteAppIntentHandler(w http.ResponseWriter, r *http.
v := vars["composite-app-version"]
i := vars["intent-name"]
ai := vars["app-intent-name"]
+ digName := vars["deployment-intent-group-name"]
+
- err := h.client.DeleteAppIntent(ai, p, ca, v, i)
+ err := h.client.DeleteAppIntent(ai, p, ca, v, i, digName)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
diff --git a/src/orchestrator/api/generic_placement_intent_handler.go b/src/orchestrator/api/generic_placement_intent_handler.go
index 2415ae2c..cb23776a 100644
--- a/src/orchestrator/api/generic_placement_intent_handler.go
+++ b/src/orchestrator/api/generic_placement_intent_handler.go
@@ -62,8 +62,9 @@ func (h genericPlacementIntentHandler) createGenericPlacementIntentHandler(w htt
projectName := vars["project-name"]
compositeAppName := vars["composite-app-name"]
version := vars["composite-app-version"]
+ digName := vars["deployment-intent-group-name"]
- gPIntent, createErr := h.client.CreateGenericPlacementIntent(g, projectName, compositeAppName, version)
+ gPIntent, createErr := h.client.CreateGenericPlacementIntent(g, projectName, compositeAppName, version, digName)
if createErr != nil {
http.Error(w, createErr.Error(), http.StatusInternalServerError)
return
@@ -103,7 +104,13 @@ func (h genericPlacementIntentHandler) getGenericPlacementHandler(w http.Respons
return
}
- gPIntent, err := h.client.GetGenericPlacementIntent(intentName, projectName, compositeAppName, version)
+ dig := vars["deployment-intent-group-name"]
+ if dig == "" {
+ http.Error(w, "Missing deploymentIntentGroupName in GET request", http.StatusBadRequest)
+ return
+ }
+
+ gPIntent, err := h.client.GetGenericPlacementIntent(intentName, projectName, compositeAppName, version, dig)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -128,8 +135,9 @@ func (h genericPlacementIntentHandler) getAllGenericPlacementIntentsHandler(w ht
p := vars["project-name"]
ca := vars["composite-app-name"]
v := vars["composite-app-version"]
+ digName := vars["deployment-intent-group-name"]
- gpList, err := h.client.GetAllGenericPlacementIntents(p, ca, v)
+ gpList, err := h.client.GetAllGenericPlacementIntents(p, ca, v, digName)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
@@ -150,8 +158,9 @@ func (h genericPlacementIntentHandler) deleteGenericPlacementHandler(w http.Resp
p := vars["project-name"]
ca := vars["composite-app-name"]
v := vars["composite-app-version"]
+ digName := vars["deployment-intent-group-name"]
- err := h.client.DeleteGenericPlacementIntent(i, p, ca, v)
+ err := h.client.DeleteGenericPlacementIntent(i, p, ca, v, digName)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
diff --git a/src/orchestrator/json-schemas/deployment-group-intent.json b/src/orchestrator/json-schemas/deployment-group-intent.json
index 2740747b..00b1f32f 100644
--- a/src/orchestrator/json-schemas/deployment-group-intent.json
+++ b/src/orchestrator/json-schemas/deployment-group-intent.json
@@ -5,7 +5,8 @@
"spec": {
"required": [
"profile",
- "version"
+ "version",
+ "logical-cloud"
],
"type": "object",
"description": "DepSpecData has profile, version, OverrideValuesObj",
@@ -42,6 +43,16 @@
"type": "string",
"maxLength": 128,
"pattern": "[-_0-9a-zA-Z]+$"
+ },
+ "logical-cloud": {
+ "description": "Logical Cloud to use for this intent",
+ "required": [
+ "logical-cloud"
+ ],
+ "type": "string",
+ "example": "cloud1",
+ "maxLength": 128,
+ "pattern": "[-_0-9a-zA-Z]+$"
}
}
},
diff --git a/src/orchestrator/json-schemas/generic-placement-intent.json b/src/orchestrator/json-schemas/generic-placement-intent.json
index 44df9087..b1d8e229 100644
--- a/src/orchestrator/json-schemas/generic-placement-intent.json
+++ b/src/orchestrator/json-schemas/generic-placement-intent.json
@@ -2,21 +2,6 @@
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
- "spec": {
- "type": "object",
- "description": "Spec",
- "properties": {
- "logical-cloud": {
- "description": "Logical Cloud to use for this intent",
- "required": [
- "logical-cloud"
- ],
- "type": "string",
- "example": "cloud1",
- "maxLength": 128
- }
- }
- },
"metadata": {
"required": ["name"],
"properties": {
diff --git a/src/orchestrator/pkg/module/app_intent.go b/src/orchestrator/pkg/module/app_intent.go
index 9da252e5..f2f4e070 100644
--- a/src/orchestrator/pkg/module/app_intent.go
+++ b/src/orchestrator/pkg/module/app_intent.go
@@ -53,11 +53,11 @@ type SpecData struct {
// AppIntentManager is an interface which exposes the
// AppIntentManager functionalities
type AppIntentManager interface {
- CreateAppIntent(a AppIntent, p string, ca string, v string, i string) (AppIntent, error)
- GetAppIntent(ai string, p string, ca string, v string, i string) (AppIntent, error)
- GetAllIntentsByApp(aN, p, ca, v, i string) (SpecData, error)
- GetAllAppIntents(p, ca, v, i string) (ApplicationsAndClusterInfo, error)
- DeleteAppIntent(ai string, p string, ca string, v string, i string) error
+ CreateAppIntent(a AppIntent, p string, ca string, v string, i string, digName string) (AppIntent, error)
+ GetAppIntent(ai string, p string, ca string, v string, i string, digName string) (AppIntent, error)
+ GetAllIntentsByApp(aN, p, ca, v, i, digName string) (SpecData, error)
+ GetAllAppIntents(p, ca, v, i, digName string) (ApplicationsAndClusterInfo, error)
+ DeleteAppIntent(ai string, p string, ca string, v string, i string, digName string) error
}
//AppIntentQueryKey required for query
@@ -72,6 +72,7 @@ type AppIntentKey struct {
CompositeApp string `json:"compositeapp"`
Version string `json:"compositeappversion"`
Intent string `json:"genericplacement"`
+ DeploymentIntentGroupName string `json:"deploymentintentgroupname"`
}
// AppIntentFindByAppKey required for query
@@ -80,6 +81,7 @@ type AppIntentFindByAppKey struct {
CompositeApp string `json:"compositeapp"`
CompositeAppVersion string `json:"compositeappversion"`
Intent string `json:"genericplacement"`
+ DeploymentIntentGroupName string `json:"deploymentintentgroupname"`
AppName string `json:"app-name"`
}
@@ -121,11 +123,11 @@ func NewAppIntentClient() *AppIntentClient {
}
// CreateAppIntent creates an entry for AppIntent in the db.
-// Other input parameters for it - projectName, compositeAppName, version, intentName.
-func (c *AppIntentClient) CreateAppIntent(a AppIntent, p string, ca string, v string, i string) (AppIntent, error) {
+// Other input parameters for it - projectName, compositeAppName, version, intentName and deploymentIntentGroupName.
+func (c *AppIntentClient) CreateAppIntent(a AppIntent, p string, ca string, v string, i string, digName string) (AppIntent, error) {
//Check for the AppIntent already exists here.
- res, err := c.GetAppIntent(a.MetaData.Name, p, ca, v, i)
+ res, err := c.GetAppIntent(a.MetaData.Name, p, ca, v, i, digName)
if !reflect.DeepEqual(res, AppIntent{}) {
return AppIntent{}, pkgerrors.New("AppIntent already exists")
}
@@ -143,17 +145,24 @@ func (c *AppIntentClient) CreateAppIntent(a AppIntent, p string, ca string, v st
}
// check if Intent exists
- _, err = NewGenericPlacementIntentClient().GetGenericPlacementIntent(i, p, ca, v)
+ _, err = NewGenericPlacementIntentClient().GetGenericPlacementIntent(i, p, ca, v, digName)
if err != nil {
return AppIntent{}, pkgerrors.New("Unable to find the intent")
}
+ // check if the deploymentIntentGrpName exists
+ _, err = NewDeploymentIntentGroupClient().GetDeploymentIntentGroup(digName,p, ca, v)
+ if err != nil {
+ return AppIntent{}, pkgerrors.New("Unable to find the deployment-intent-group-name")
+ }
+
akey := AppIntentKey{
Name: a.MetaData.Name,
Project: p,
CompositeApp: ca,
Version: v,
Intent: i,
+ DeploymentIntentGroupName: digName,
}
qkey := AppIntentQueryKey{
@@ -164,12 +173,12 @@ func (c *AppIntentClient) CreateAppIntent(a AppIntent, p string, ca string, v st
if err != nil {
return AppIntent{}, pkgerrors.Wrap(err, "Create DB entry error")
}
-
+
return a, nil
}
-// GetAppIntent shall take arguments - name of the app intent, name of the project, name of the composite app, version of the composite app and intent name. It shall return the AppIntent
-func (c *AppIntentClient) GetAppIntent(ai string, p string, ca string, v string, i string) (AppIntent, error) {
+// GetAppIntent shall take arguments - name of the app intent, name of the project, name of the composite app, version of the composite app,intent name and deploymentIntentGroupName. It shall return the AppIntent
+func (c *AppIntentClient) GetAppIntent(ai string, p string, ca string, v string, i string, digName string) (AppIntent, error) {
k := AppIntentKey{
Name: ai,
@@ -177,6 +186,7 @@ func (c *AppIntentClient) GetAppIntent(ai string, p string, ca string, v string,
CompositeApp: ca,
Version: v,
Intent: i,
+ DeploymentIntentGroupName: digName,
}
result, err := db.DBconn.Find(c.storeName, k, c.tagMetaData)
@@ -197,16 +207,17 @@ func (c *AppIntentClient) GetAppIntent(ai string, p string, ca string, v string,
}
/*
-GetAllIntentsByApp takes in parameters AppName, CompositeAppName, CompositeNameVersion
-and GenericPlacementIntentName. Returns SpecData which contains
+GetAllIntentsByApp queries intent by AppName, it takes in parameters AppName, CompositeAppName, CompositeNameVersion,
+GenericPlacementIntentName & DeploymentIntentGroupName. Returns SpecData which contains
all the intents for the app.
*/
-func (c *AppIntentClient) GetAllIntentsByApp(aN, p, ca, v, i string) (SpecData, error) {
+func (c *AppIntentClient) GetAllIntentsByApp(aN, p, ca, v, i, digName string) (SpecData, error) {
k := AppIntentFindByAppKey{
Project: p,
CompositeApp: ca,
CompositeAppVersion: v,
Intent: i,
+ DeploymentIntentGroupName: digName,
AppName: aN,
}
result, err := db.DBconn.Find(c.storeName, k, c.tagMetaData)
@@ -224,15 +235,16 @@ func (c *AppIntentClient) GetAllIntentsByApp(aN, p, ca, v, i string) (SpecData,
/*
GetAllAppIntents takes in paramaters ProjectName, CompositeAppName, CompositeNameVersion
-and GenericPlacementIntentName. Returns the ApplicationsAndClusterInfo Object - an array of AppClusterInfo
+and GenericPlacementIntentName,DeploymentIntentGroupName. Returns the ApplicationsAndClusterInfo Object - an array of AppClusterInfo
*/
-func (c *AppIntentClient) GetAllAppIntents(p, ca, v, i string) (ApplicationsAndClusterInfo, error) {
+func (c *AppIntentClient) GetAllAppIntents(p, ca, v, i, digName string) (ApplicationsAndClusterInfo, error) {
k := AppIntentKey{
Name: "",
Project: p,
CompositeApp: ca,
Version: v,
Intent: i,
+ DeploymentIntentGroupName: digName,
}
result, err := db.DBconn.Find(c.storeName, k, c.tagMetaData)
if err != nil {
@@ -262,13 +274,14 @@ func (c *AppIntentClient) GetAllAppIntents(p, ca, v, i string) (ApplicationsAndC
}
// DeleteAppIntent delete an AppIntent
-func (c *AppIntentClient) DeleteAppIntent(ai string, p string, ca string, v string, i string) error {
+func (c *AppIntentClient) DeleteAppIntent(ai string, p string, ca string, v string, i string, digName string) error {
k := AppIntentKey{
Name: ai,
Project: p,
CompositeApp: ca,
Version: v,
Intent: i,
+ DeploymentIntentGroupName: digName,
}
err := db.DBconn.Remove(c.storeName, k)
diff --git a/src/orchestrator/pkg/module/app_intent_test.go b/src/orchestrator/pkg/module/app_intent_test.go
index 089f09ff..a2e295ea 100644
--- a/src/orchestrator/pkg/module/app_intent_test.go
+++ b/src/orchestrator/pkg/module/app_intent_test.go
@@ -33,6 +33,7 @@ func TestCreateAppIntent(t *testing.T) {
inputCompositeApp string
inputCompositeAppVersion string
inputGenericPlacementIntent string
+ inputDeploymentIntentGrpName string
expectedError string
mockdb *db.MockDB
expected AppIntent
@@ -81,6 +82,7 @@ func TestCreateAppIntent(t *testing.T) {
inputCompositeApp: "testCompositeApp",
inputCompositeAppVersion: "testCompositeAppVersion",
inputGenericPlacementIntent: "testIntent",
+ inputDeploymentIntentGrpName: "testDeploymentIntentGroup",
expected: AppIntent{
MetaData: MetaData{
Name: "testAppIntent",
@@ -142,6 +144,7 @@ func TestCreateAppIntent(t *testing.T) {
Project: "testProject",
CompositeApp: "testCompositeApp",
Version: "testCompositeAppVersion",
+ DigName: "testDeploymentIntentGroup",
}.String(): {
"genericplacementintentmetadata": []byte(
"{\"metadata\":{\"Name\":\"testIntent\"," +
@@ -150,6 +153,39 @@ func TestCreateAppIntent(t *testing.T) {
"\"UserData2\": \"userData2\"}," +
"\"spec\":{\"Logical-Cloud\": \"logicalCloud1\"}}"),
},
+ DeploymentIntentGroupKey{
+ Name: "testDeploymentIntentGroup",
+ Project: "testProject",
+ CompositeApp: "testCompositeApp",
+ Version: "testCompositeAppVersion",
+ }.String(): {
+ "deploymentintentgroupmetadata": []byte(
+ "{\"metadata\":{\"name\":\"testDeploymentIntentGroup\"," +
+ "\"description\":\"DescriptionTestDeploymentIntentGroup\"," +
+ "\"userData1\": \"userData1\"," +
+ "\"userData2\": \"userData2\"}," +
+ "\"spec\":{\"profile\": \"Testprofile\"," +
+ "\"version\": \"version of deployment\"," +
+ "\"override-values\":[" +
+ "{" +
+ "\"app-name\": \"TestAppName\"," +
+ "\"values\": " +
+ "{" +
+ "\"imageRepository\":\"registry.hub.docker.com\"" +
+ "}" +
+ "}," +
+ "{" +
+ "\"app-name\": \"TestAppName\"," +
+ "\"values\": " +
+ "{" +
+ "\"imageRepository\":\"registry.hub.docker.com\"" +
+ "}" +
+ "}" +
+ "]," +
+ "\"logical-cloud\": \"cloud1\"" +
+ "}"+
+ "}"),
+ },
},
},
},
@@ -158,7 +194,7 @@ func TestCreateAppIntent(t *testing.T) {
t.Run(testCase.label, func(t *testing.T) {
db.DBconn = testCase.mockdb
appIntentCli := NewAppIntentClient()
- got, err := appIntentCli.CreateAppIntent(testCase.inputAppIntent, testCase.inputProject, testCase.inputCompositeApp, testCase.inputCompositeAppVersion, testCase.inputGenericPlacementIntent)
+ got, err := appIntentCli.CreateAppIntent(testCase.inputAppIntent, testCase.inputProject, testCase.inputCompositeApp, testCase.inputCompositeAppVersion, testCase.inputGenericPlacementIntent, testCase.inputDeploymentIntentGrpName)
if err != nil {
if testCase.expectedError == "" {
t.Fatalf("CreateAppIntent returned an unexpected error %s, ", err)
@@ -186,6 +222,7 @@ func TestGetAppIntent(t *testing.T) {
compositeAppName string
compositeAppVersion string
genericPlacementIntent string
+ deploymentIntentgrpName string
}{
{
label: "Get Intent",
@@ -194,6 +231,7 @@ func TestGetAppIntent(t *testing.T) {
compositeAppName: "testCompositeApp",
compositeAppVersion: "testCompositeAppVersion",
genericPlacementIntent: "testIntent",
+ deploymentIntentgrpName: "testDeploymentIntentGroup",
expected: AppIntent{
MetaData: MetaData{
Name: "testAppIntent",
@@ -234,6 +272,7 @@ func TestGetAppIntent(t *testing.T) {
CompositeApp: "testCompositeApp",
Version: "testCompositeAppVersion",
Intent: "testIntent",
+ DeploymentIntentGroupName: "testDeploymentIntentGroup",
}.String(): {
"appintentmetadata": []byte(
"{\"metadata\":{\"Name\":\"testAppIntent\"," +
@@ -270,7 +309,7 @@ func TestGetAppIntent(t *testing.T) {
db.DBconn = testCase.mockdb
appIntentCli := NewAppIntentClient()
got, err := appIntentCli.GetAppIntent(testCase.appIntentName, testCase.projectName, testCase.compositeAppName, testCase.compositeAppVersion,
- testCase.genericPlacementIntent)
+ testCase.genericPlacementIntent, testCase.deploymentIntentgrpName)
if err != nil {
if testCase.expectedError == "" {
t.Fatalf("GetAppIntent returned an unexpected error: %s", err)
diff --git a/src/orchestrator/pkg/module/deployment_intent_groups.go b/src/orchestrator/pkg/module/deployment_intent_groups.go
index dec6391f..f8e434f4 100644
--- a/src/orchestrator/pkg/module/deployment_intent_groups.go
+++ b/src/orchestrator/pkg/module/deployment_intent_groups.go
@@ -47,6 +47,7 @@ type DepSpecData struct {
Profile string `json:"profile"`
Version string `json:"version"`
OverrideValuesObj []OverrideValues `json:"override-values"`
+ LogicalCloud string `json:"logical-cloud"`
}
// OverrideValues has appName and ValuesObj
diff --git a/src/orchestrator/pkg/module/deployment_intent_groups_test.go b/src/orchestrator/pkg/module/deployment_intent_groups_test.go
index 0fdeb4a1..86ae49df 100644
--- a/src/orchestrator/pkg/module/deployment_intent_groups_test.go
+++ b/src/orchestrator/pkg/module/deployment_intent_groups_test.go
@@ -57,6 +57,7 @@ func TestCreateDeploymentIntentGroup(t *testing.T) {
"imageRepository": "registry.hub.docker.com",
}},
},
+ LogicalCloud: "cloud1",
},
},
inputProject: "testProject",
@@ -82,6 +83,7 @@ func TestCreateDeploymentIntentGroup(t *testing.T) {
"imageRepository": "registry.hub.docker.com",
}},
},
+ LogicalCloud: "cloud1",
},
},
expectedError: "",
@@ -167,6 +169,7 @@ func TestGetDeploymentIntentGroup(t *testing.T) {
"imageRepository": "registry.hub.docker.com",
}},
},
+ LogicalCloud: "cloud1",
},
},
expectedError: "",
@@ -200,7 +203,10 @@ func TestGetDeploymentIntentGroup(t *testing.T) {
"\"imageRepository\":\"registry.hub.docker.com\"" +
"}" +
"}" +
- "]}}"),
+ "]," +
+ "\"logical-cloud\": \"cloud1\"" +
+ "}"+
+ "}"),
},
},
},
diff --git a/src/orchestrator/pkg/module/generic_placement_intent.go b/src/orchestrator/pkg/module/generic_placement_intent.go
index fb00a6ab..eb9ed796 100644
--- a/src/orchestrator/pkg/module/generic_placement_intent.go
+++ b/src/orchestrator/pkg/module/generic_placement_intent.go
@@ -26,7 +26,6 @@ import (
// GenericPlacementIntent shall have 2 fields - metadata and spec
type GenericPlacementIntent struct {
MetaData GenIntentMetaData `json:"metadata"`
- Spec GenIntentSpecData `json:"spec"`
}
// GenIntentMetaData has name, description, userdata1, userdata2
@@ -37,21 +36,19 @@ type GenIntentMetaData struct {
UserData2 string `json:"userData2"`
}
-// GenIntentSpecData has logical-cloud-name
-type GenIntentSpecData struct {
- LogicalCloud string `json:"logical-cloud"`
-}
+
+
// GenericPlacementIntentManager is an interface which exposes the GenericPlacementIntentManager functionality
type GenericPlacementIntentManager interface {
CreateGenericPlacementIntent(g GenericPlacementIntent, p string, ca string,
- v string) (GenericPlacementIntent, error)
+ v string, digName string) (GenericPlacementIntent, error)
GetGenericPlacementIntent(intentName string, projectName string,
- compositeAppName string, version string) (GenericPlacementIntent, error)
+ compositeAppName string, version string, digName string) (GenericPlacementIntent, error)
DeleteGenericPlacementIntent(intentName string, projectName string,
- compositeAppName string, version string) error
+ compositeAppName string, version string, digName string) error
- GetAllGenericPlacementIntents(p string, ca string, v string) ([]GenericPlacementIntent, error)
+ GetAllGenericPlacementIntents(p string, ca string, v string, digName string) ([]GenericPlacementIntent, error)
}
// GenericPlacementIntentKey is used as the primary key
@@ -60,6 +57,7 @@ type GenericPlacementIntentKey struct {
Project string `json:"project"`
CompositeApp string `json:"compositeapp"`
Version string `json:"compositeappversion"`
+ DigName string `json:"deploymentintentgroupname"`
}
// We will use json marshalling to convert to string to
@@ -86,12 +84,12 @@ func NewGenericPlacementIntentClient() *GenericPlacementIntentClient {
}
}
-// CreateGenericPlacementIntent creates an entry for GenericPlacementIntent in the database. Other Input parameters for it - projectName, compositeAppName, version
+// CreateGenericPlacementIntent creates an entry for GenericPlacementIntent in the database. Other Input parameters for it - projectName, compositeAppName, version and deploymentIntentGroupName
func (c *GenericPlacementIntentClient) CreateGenericPlacementIntent(g GenericPlacementIntent, p string, ca string,
- v string) (GenericPlacementIntent, error) {
+ v string, digName string) (GenericPlacementIntent, error) {
// check if the genericPlacement already exists.
- res, err := c.GetGenericPlacementIntent(g.MetaData.Name, p, ca, v)
+ res, err := c.GetGenericPlacementIntent(g.MetaData.Name, p, ca, v, digName)
if res != (GenericPlacementIntent{}) {
return GenericPlacementIntent{}, pkgerrors.New("Intent already exists")
}
@@ -108,11 +106,19 @@ func (c *GenericPlacementIntentClient) CreateGenericPlacementIntent(g GenericPla
return GenericPlacementIntent{}, pkgerrors.New("Unable to find the composite-app")
}
+ // check if the deploymentIntentGrpName exists
+ _, err = NewDeploymentIntentGroupClient().GetDeploymentIntentGroup(digName, p, ca, v)
+ if err != nil {
+ return GenericPlacementIntent{}, pkgerrors.New("Unable to find the deployment-intent-group-name")
+ }
+
+
gkey := GenericPlacementIntentKey{
Name: g.MetaData.Name,
Project: p,
CompositeApp: ca,
Version: v,
+ DigName: digName,
}
err = db.DBconn.Insert(c.storeName, gkey, nil, c.tagMetaData, g)
@@ -123,13 +129,14 @@ func (c *GenericPlacementIntentClient) CreateGenericPlacementIntent(g GenericPla
return g, nil
}
-// GetGenericPlacementIntent shall take arguments - name of the intent, name of the project, name of the composite app and version of the composite app. It shall return the genericPlacementIntent if its present.
-func (c *GenericPlacementIntentClient) GetGenericPlacementIntent(i string, p string, ca string, v string) (GenericPlacementIntent, error) {
+// GetGenericPlacementIntent shall take arguments - name of the intent, name of the project, name of the composite app, version of the composite app and deploymentIntentGroupName. It shall return the genericPlacementIntent if its present.
+func (c *GenericPlacementIntentClient) GetGenericPlacementIntent(i string, p string, ca string, v string, digName string) (GenericPlacementIntent, error) {
key := GenericPlacementIntentKey{
Name: i,
Project: p,
CompositeApp: ca,
Version: v,
+ DigName: digName,
}
result, err := db.DBconn.Find(c.storeName, key, c.tagMetaData)
@@ -150,8 +157,8 @@ 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) {
+// GetAllGenericPlacementIntents returns all the generic placement intents for a given compsoite app name, composite app version, project and deploymentIntentGroupName
+func (c *GenericPlacementIntentClient) GetAllGenericPlacementIntents(p string, ca string, v string, digName string) ([]GenericPlacementIntent, error) {
//Check if project exists
_, err := NewProjectClient().GetProject(p)
@@ -170,6 +177,8 @@ func (c *GenericPlacementIntentClient) GetAllGenericPlacementIntents(p string, c
Project: p,
CompositeApp: ca,
Version: v,
+ DigName: digName,
+
}
var gpList []GenericPlacementIntent
@@ -192,12 +201,13 @@ func (c *GenericPlacementIntentClient) GetAllGenericPlacementIntents(p string, c
}
// DeleteGenericPlacementIntent the intent from the database
-func (c *GenericPlacementIntentClient) DeleteGenericPlacementIntent(i string, p string, ca string, v string) error {
+func (c *GenericPlacementIntentClient) DeleteGenericPlacementIntent(i string, p string, ca string, v string, digName string) error {
key := GenericPlacementIntentKey{
Name: i,
Project: p,
CompositeApp: ca,
Version: v,
+ DigName: digName,
}
err := db.DBconn.Remove(c.storeName, key)
diff --git a/src/orchestrator/pkg/module/generic_placement_intent_test.go b/src/orchestrator/pkg/module/generic_placement_intent_test.go
index d779e81f..59c1cac5 100644
--- a/src/orchestrator/pkg/module/generic_placement_intent_test.go
+++ b/src/orchestrator/pkg/module/generic_placement_intent_test.go
@@ -31,6 +31,7 @@ func TestCreateGenericPlacementIntent(t *testing.T) {
inputProject string
inputCompositeApp string
inputCompositeAppVersion string
+ inputDepIntGrpName string
expectedError string
mockdb *db.MockDB
expected GenericPlacementIntent
@@ -44,13 +45,11 @@ func TestCreateGenericPlacementIntent(t *testing.T) {
UserData1: "userData1",
UserData2: "userData2",
},
- Spec: GenIntentSpecData{
- LogicalCloud: "logicalCloud1",
- },
},
inputProject: "testProject",
inputCompositeApp: "testCompositeApp",
inputCompositeAppVersion: "testCompositeAppVersion",
+ inputDepIntGrpName: "testDeploymentIntentGroup",
expected: GenericPlacementIntent{
MetaData: GenIntentMetaData{
Name: "testGenericPlacement",
@@ -58,9 +57,6 @@ func TestCreateGenericPlacementIntent(t *testing.T) {
UserData1: "userData1",
UserData2: "userData2",
},
- Spec: GenIntentSpecData{
- LogicalCloud: "logicalCloud1",
- },
},
expectedError: "",
mockdb: &db.MockDB{
@@ -82,6 +78,40 @@ func TestCreateGenericPlacementIntent(t *testing.T) {
"\"spec\":{" +
"\"version\":\"version of the composite app\"}}"),
},
+ DeploymentIntentGroupKey{
+ Name: "testDeploymentIntentGroup",
+ Project: "testProject",
+ CompositeApp: "testCompositeApp",
+ Version: "testCompositeAppVersion",
+ }.String(): {
+ "deploymentintentgroupmetadata": []byte(
+ "{\"metadata\":{\"name\":\"testDeploymentIntentGroup\"," +
+ "\"description\":\"DescriptionTestDeploymentIntentGroup\"," +
+ "\"userData1\": \"userData1\"," +
+ "\"userData2\": \"userData2\"}," +
+ "\"spec\":{\"profile\": \"Testprofile\"," +
+ "\"version\": \"version of deployment\"," +
+ "\"override-values\":[" +
+ "{" +
+ "\"app-name\": \"TestAppName\"," +
+ "\"values\": " +
+ "{" +
+ "\"imageRepository\":\"registry.hub.docker.com\"" +
+ "}" +
+ "}," +
+ "{" +
+ "\"app-name\": \"TestAppName\"," +
+ "\"values\": " +
+ "{" +
+ "\"imageRepository\":\"registry.hub.docker.com\"" +
+ "}" +
+ "}" +
+ "]," +
+ "\"logical-cloud\": \"cloud1\"" +
+ "}"+
+ "}"),
+ },
+
},
},
},
@@ -91,7 +121,7 @@ func TestCreateGenericPlacementIntent(t *testing.T) {
t.Run(testCase.label, func(t *testing.T) {
db.DBconn = testCase.mockdb
intentCli := NewGenericPlacementIntentClient()
- got, err := intentCli.CreateGenericPlacementIntent(testCase.inputIntent, testCase.inputProject, testCase.inputCompositeApp, testCase.inputCompositeAppVersion)
+ got, err := intentCli.CreateGenericPlacementIntent(testCase.inputIntent, testCase.inputProject, testCase.inputCompositeApp, testCase.inputCompositeAppVersion, testCase.inputDepIntGrpName)
if err != nil {
if testCase.expectedError == "" {
t.Fatalf("CreateGenericPlacementIntent returned an unexpected error %s", err)
@@ -120,6 +150,7 @@ func TestGetGenericPlacementIntent(t *testing.T) {
projectName string
compositeAppName string
compositeAppVersion string
+ deploymentIntentGroupName string
}{
{
label: "Get Intent",
@@ -127,6 +158,7 @@ func TestGetGenericPlacementIntent(t *testing.T) {
projectName: "testProject",
compositeAppName: "testCompositeApp",
compositeAppVersion: "testVersion",
+ deploymentIntentGroupName: "testDeploymentIntentGroup",
expected: GenericPlacementIntent{
MetaData: GenIntentMetaData{
Name: "testIntent",
@@ -134,9 +166,6 @@ func TestGetGenericPlacementIntent(t *testing.T) {
UserData1: "userData1",
UserData2: "userData2",
},
- Spec: GenIntentSpecData{
- LogicalCloud: "logicalCloud1",
- },
},
expectedError: "",
mockdb: &db.MockDB{
@@ -146,13 +175,14 @@ func TestGetGenericPlacementIntent(t *testing.T) {
Project: "testProject",
CompositeApp: "testCompositeApp",
Version: "testVersion",
+ DigName: "testDeploymentIntentGroup",
}.String(): {
"genericplacementintentmetadata": []byte(
"{\"metadata\":{\"Name\":\"testIntent\"," +
"\"Description\":\"A sample intent for testing\"," +
"\"UserData1\": \"userData1\"," +
- "\"UserData2\": \"userData2\"}," +
- "\"spec\":{\"Logical-Cloud\": \"logicalCloud1\"}}"),
+ "\"UserData2\": \"userData2\"}" +
+ "}"),
},
},
},
@@ -163,7 +193,7 @@ func TestGetGenericPlacementIntent(t *testing.T) {
t.Run(testCase.label, func(t *testing.T) {
db.DBconn = testCase.mockdb
intentCli := NewGenericPlacementIntentClient()
- got, err := intentCli.GetGenericPlacementIntent(testCase.intentName, testCase.projectName, testCase.compositeAppName, testCase.compositeAppVersion)
+ got, err := intentCli.GetGenericPlacementIntent(testCase.intentName, testCase.projectName, testCase.compositeAppName, testCase.compositeAppVersion, testCase.deploymentIntentGroupName)
if err != nil {
if testCase.expectedError == "" {
t.Fatalf("GetGenericPlacementIntent returned an unexpected error: %s", err)
diff --git a/src/orchestrator/pkg/module/instantiation.go b/src/orchestrator/pkg/module/instantiation.go
index 0ae76006..4375a90b 100644
--- a/src/orchestrator/pkg/module/instantiation.go
+++ b/src/orchestrator/pkg/module/instantiation.go
@@ -338,7 +338,7 @@ func (c InstantiationClient) Instantiate(p string, ca string, v string, di strin
defer cleanTmpfiles(sortedTemplates)
- specData, err := NewAppIntentClient().GetAllIntentsByApp(eachApp.Metadata.Name, p, ca, v, gIntent)
+ specData, err := NewAppIntentClient().GetAllIntentsByApp(eachApp.Metadata.Name, p, ca, v, gIntent, di)
if err != nil {
deleteAppContext(context)
return pkgerrors.Wrap(err, "Unable to get the intents for app")