diff options
author | Ritu Sood <Ritu.Sood@intel.com> | 2020-04-13 20:38:39 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-04-13 20:38:39 +0000 |
commit | 7945fcd8ed65792eeb174d999138b99dbc936a6f (patch) | |
tree | 01baba65c845f5af830e724f746357e640b63599 /src/orchestrator/pkg/module | |
parent | c8ba8f21b68b64b4068f188614dd7c891edf035f (diff) | |
parent | f65daf54a4ab24be9e2c82236a511cedc3bdf230 (diff) |
Merge "Adding query APIs for AppIntents"
Diffstat (limited to 'src/orchestrator/pkg/module')
-rw-r--r-- | src/orchestrator/pkg/module/add_intents.go | 5 | ||||
-rw-r--r-- | src/orchestrator/pkg/module/app_intent.go | 112 | ||||
-rw-r--r-- | src/orchestrator/pkg/module/app_intent_test.go | 46 | ||||
-rw-r--r-- | src/orchestrator/pkg/module/app_profile.go | 2 |
4 files changed, 147 insertions, 18 deletions
diff --git a/src/orchestrator/pkg/module/add_intents.go b/src/orchestrator/pkg/module/add_intents.go index 20fba189..609f65ab 100644 --- a/src/orchestrator/pkg/module/add_intents.go +++ b/src/orchestrator/pkg/module/add_intents.go @@ -16,6 +16,11 @@ package module +/* +This files deals with the backend implementation of adding +genericPlacementIntents to deployementIntentGroup +*/ + import ( "encoding/json" "reflect" diff --git a/src/orchestrator/pkg/module/app_intent.go b/src/orchestrator/pkg/module/app_intent.go index a3f4b832..2b2c0fa5 100644 --- a/src/orchestrator/pkg/module/app_intent.go +++ b/src/orchestrator/pkg/module/app_intent.go @@ -16,6 +16,11 @@ package module +/* +This file deals with the backend implementation of +Adding/Querying AppIntents for each application in the composite-app +*/ + import ( "encoding/json" "reflect" @@ -41,13 +46,15 @@ type MetaData struct { // AllOf consists of AnyOfArray and ClusterNames array type AllOf struct { + ProviderName string `json:"provider-name,omitempty"` ClusterName string `json:"cluster-name,omitempty"` ClusterLabelName string `json:"cluster-label-name,omitempty"` AnyOfArray []AnyOf `json:"anyOf,omitempty"` } -// AnyOf consists of Array of ClusterLabelNames +// AnyOf consists of Array of ProviderName & ClusterLabelNames type AnyOf struct { + ProviderName string `json:"provider-name,omitempty"` ClusterName string `json:"cluster-name,omitempty"` ClusterLabelName string `json:"cluster-label-name,omitempty"` } @@ -69,9 +76,16 @@ type SpecData struct { 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 } +//AppIntentQueryKey required for query +type AppIntentQueryKey struct { + AppName string `json:"app-name"` +} + // AppIntentKey is used as primary key type AppIntentKey struct { Name string `json:"appintent"` @@ -81,6 +95,28 @@ type AppIntentKey struct { Intent string `json:"genericplacement"` } +// AppIntentFindByAppKey required for query +type AppIntentFindByAppKey struct { + Project string `json:"project"` + CompositeApp string `json:"compositeapp"` + CompositeAppVersion string `json:"compositeappversion"` + Intent string `json:"genericplacement"` + AppName string `json:"app-name"` +} + +// ApplicationsAndClusterInfo type represents the list of +type ApplicationsAndClusterInfo struct { + ArrayOfAppClusterInfo []AppClusterInfo `json:"applications"` +} + +// AppClusterInfo is a type linking the app and the clusters +// on which they need to be installed. +type AppClusterInfo struct { + Name string `json:"name"` + AllOfArray []AllOf `json:"allOf,omitempty"` + AnyOfArray []AnyOf `json:"anyOf,omitempty"` +} + // We will use json marshalling to convert to string to // preserve the underlying structure. func (ak AppIntentKey) String() string { @@ -105,7 +141,8 @@ func NewAppIntentClient() *AppIntentClient { } } -// CreateAppIntent creates an entry for AppIntent in the db. Other input parameters for it - projectName, compositeAppName, version, intentName. +// 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) { //Check for the AppIntent already exists here. @@ -140,7 +177,11 @@ func (c *AppIntentClient) CreateAppIntent(a AppIntent, p string, ca string, v st Intent: i, } - err = db.DBconn.Insert(c.storeName, akey, nil, c.tagMetaData, a) + qkey := AppIntentQueryKey{ + AppName: a.Spec.AppName, + } + + err = db.DBconn.Insert(c.storeName, akey, qkey, c.tagMetaData, a) if err != nil { return AppIntent{}, pkgerrors.Wrap(err, "Create DB entry error") } @@ -176,6 +217,71 @@ func (c *AppIntentClient) GetAppIntent(ai string, p string, ca string, v string, return AppIntent{}, pkgerrors.New("Error getting AppIntent") } +/* +GetAllIntentsByApp takes in parameters AppName, CompositeAppName, CompositeNameVersion +and GenericPlacementIntentName. Returns SpecData which contains +all the intents for the app. +*/ +func (c *AppIntentClient) GetAllIntentsByApp(aN, p, ca, v, i string) (SpecData, error) { + k := AppIntentFindByAppKey{ + Project: p, + CompositeApp: ca, + CompositeAppVersion: v, + Intent: i, + AppName: aN, + } + result, err := db.DBconn.Find(c.storeName, k, c.tagMetaData) + if err != nil { + return SpecData{}, pkgerrors.Wrap(err, "Get SpecData error") + } + var a AppIntent + err = db.DBconn.Unmarshal(result[0], &a) + if err != nil { + return SpecData{}, pkgerrors.Wrap(err, "Unmarshalling SpecData") + } + return a.Spec, nil + +} + +/* +GetAllAppIntents takes in paramaters ProjectName, CompositeAppName, CompositeNameVersion +and GenericPlacementIntentName. Returns the ApplicationsAndClusterInfo Object - an array of AppClusterInfo +*/ +func (c *AppIntentClient) GetAllAppIntents(p, ca, v, i string) (ApplicationsAndClusterInfo, error) { + k := AppIntentKey{ + Name: "", + Project: p, + CompositeApp: ca, + Version: v, + Intent: i, + } + result, err := db.DBconn.Find(c.storeName, k, c.tagMetaData) + if err != nil { + return ApplicationsAndClusterInfo{}, pkgerrors.Wrap(err, "Get AppClusterInfo error") + } + + var a AppIntent + var appClusterInfoArray []AppClusterInfo + + if len(result) != 0 { + for i := range result { + a = AppIntent{} + err = db.DBconn.Unmarshal(result[i], &a) + if err != nil { + return ApplicationsAndClusterInfo{}, pkgerrors.Wrap(err, "Unmarshalling AppIntent") + } + appName := a.Spec.AppName + allOfArray := a.Spec.Intent.AllOfArray + anyOfArray := a.Spec.Intent.AnyOfArray + appClusterInfo := AppClusterInfo{appName, allOfArray, + anyOfArray} + appClusterInfoArray = append(appClusterInfoArray, appClusterInfo) + } + } + applicationsAndClusterInfo := ApplicationsAndClusterInfo{appClusterInfoArray} + return applicationsAndClusterInfo, err +} + // DeleteAppIntent delete an AppIntent func (c *AppIntentClient) DeleteAppIntent(ai string, p string, ca string, v string, i string) error { k := AppIntentKey{ diff --git a/src/orchestrator/pkg/module/app_intent_test.go b/src/orchestrator/pkg/module/app_intent_test.go index 6cbdf15f..726ce0a3 100644 --- a/src/orchestrator/pkg/module/app_intent_test.go +++ b/src/orchestrator/pkg/module/app_intent_test.go @@ -50,17 +50,21 @@ func TestCreateAppIntent(t *testing.T) { Intent: IntentStruc{ AllOfArray: []AllOf{ { - ClusterName: "edge1", + ProviderName: "aws", + ClusterName: "edge1", //ClusterLabelName: "edge1", }, { - ClusterName: "edge2", + ProviderName: "aws", + ClusterName: "edge2", //ClusterLabelName: "edge2", }, { AnyOfArray: []AnyOf{ - {ClusterLabelName: "east-us1"}, - {ClusterLabelName: "east-us2"}, + {ProviderName: "aws", + ClusterLabelName: "east-us1"}, + {ProviderName: "aws", + ClusterLabelName: "east-us2"}, //{ClusterName: "east-us1"}, //{ClusterName: "east-us2"}, }, @@ -88,17 +92,21 @@ func TestCreateAppIntent(t *testing.T) { Intent: IntentStruc{ AllOfArray: []AllOf{ { - ClusterName: "edge1", + ProviderName: "aws", + ClusterName: "edge1", //ClusterLabelName: "edge1", }, { - ClusterName: "edge2", + ProviderName: "aws", + ClusterName: "edge2", //ClusterLabelName: "edge2", }, { AnyOfArray: []AnyOf{ - {ClusterLabelName: "east-us1"}, - {ClusterLabelName: "east-us2"}, + {ProviderName: "aws", + ClusterLabelName: "east-us1"}, + {ProviderName: "aws", + ClusterLabelName: "east-us2"}, //{ClusterName: "east-us1"}, //{ClusterName: "east-us2"}, }, @@ -197,15 +205,19 @@ func TestGetAppIntent(t *testing.T) { Intent: IntentStruc{ AllOfArray: []AllOf{ { - ClusterName: "edge1", + ProviderName: "aws", + ClusterName: "edge1", }, { - ClusterName: "edge2", + ProviderName: "aws", + ClusterName: "edge2", }, { AnyOfArray: []AnyOf{ - {ClusterLabelName: "east-us1"}, - {ClusterLabelName: "east-us2"}, + {ProviderName: "aws", + ClusterLabelName: "east-us1"}, + {ProviderName: "aws", + ClusterLabelName: "east-us2"}, }, }, }, @@ -230,13 +242,19 @@ func TestGetAppIntent(t *testing.T) { "\"spec\":{\"app-name\": \"SampleApp\"," + "\"intent\": {" + "\"allOf\":[" + - "{\"cluster-name\":\"edge1\"}," + - "{\"cluster-name\":\"edge2\"}," + + "{" + + "\"provider-name\":\"aws\"," + + "\"cluster-name\":\"edge1\"}," + + "{" + + "\"provider-name\":\"aws\"," + + "\"cluster-name\":\"edge2\"}," + "{" + "\"anyOf\":[" + "{" + + "\"provider-name\":\"aws\"," + "\"cluster-label-name\":\"east-us1\"}," + "{" + + "\"provider-name\":\"aws\"," + "\"cluster-label-name\":\"east-us2\"}" + "]}]" + "}}}"), diff --git a/src/orchestrator/pkg/module/app_profile.go b/src/orchestrator/pkg/module/app_profile.go index 77835fb4..6600ed24 100644 --- a/src/orchestrator/pkg/module/app_profile.go +++ b/src/orchestrator/pkg/module/app_profile.go @@ -122,7 +122,7 @@ func (c *AppProfileClient) CreateAppProfile(project, compositeApp, compositeAppV //Check if composite profile exists (success assumes existance of all higher level 'parent' objects) _, err = NewCompositeProfileClient().GetCompositeProfile(compositeProfile, project, compositeApp, compositeAppVersion) if err != nil { - return AppProfile{}, pkgerrors.New("Unable to find the project") + return AppProfile{}, pkgerrors.New("Unable to find the compositeProfile") } // TODO: (after app api is ready) check that the app Spec.AppName exists as part of the composite app |