aboutsummaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg/gpic/gpic.go
diff options
context:
space:
mode:
authorRajamohan Raj <rajamohan.raj@intel.com>2020-05-26 20:08:58 +0000
committerRajamohan Raj <rajamohan.raj@intel.com>2020-06-01 18:45:54 +0000
commitc257a136355a794f5bf778f670c041e8958c3608 (patch)
treee642dae19b2dd8fade13de9342a9dee76d884589 /src/orchestrator/pkg/gpic/gpic.go
parent7959bd4c6fd403cf4ba58bf572b1259267b3c76d (diff)
Adding cluster meta data and saving in etcd
As part of this patch, we assign groupNumbers for the set of clusters which are under anyOf, or in other words are optional for deployement of app. Also refactored the instantiation flow by separating out the etcd interactions Issue-ID: MULTICLOUD-1064 Signed-off-by: Rajamohan Raj <rajamohan.raj@intel.com> Change-Id: I21ece189daf6e6b3a7cfdba5df22d57b3d33ca78
Diffstat (limited to 'src/orchestrator/pkg/gpic/gpic.go')
-rw-r--r--src/orchestrator/pkg/gpic/gpic.go45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/orchestrator/pkg/gpic/gpic.go b/src/orchestrator/pkg/gpic/gpic.go
index 256d3b41..78b547da 100644
--- a/src/orchestrator/pkg/gpic/gpic.go
+++ b/src/orchestrator/pkg/gpic/gpic.go
@@ -25,11 +25,19 @@ import (
ncmmodule "github.com/onap/multicloud-k8s/src/ncm/pkg/module"
pkgerrors "github.com/pkg/errors"
"log"
+ "strconv"
)
-// Clusters has 1 field - a list of ClusterNames
-type Clusters struct {
- ClustersWithName []ClusterWithName
+// ClusterList consists of mandatoryClusters and clusterGroups
+type ClusterList struct {
+ MandatoryClusters []ClusterWithName
+ ClusterGroups []ClusterGroup
+}
+
+//ClusterGroup consists of a list of optionalClusters and a groupNumber. All the clusters under the optional clusters belong to same groupNumber
+type ClusterGroup struct {
+ OptionalClusters []ClusterWithName
+ GroupNumber string
}
// ClusterWithName has two fields - ProviderName and ClusterName
@@ -89,32 +97,41 @@ func intentResolverHelper(pn, cn, cln string, clustersWithName []ClusterWithName
}
// IntentResolver shall help to resolve the given intent into 2 lists of clusters where the app need to be deployed.
-func IntentResolver(intent IntentStruc) (Clusters, error) {
- var clustersWithName []ClusterWithName
+func IntentResolver(intent IntentStruc) (ClusterList, error) {
+ var mc []ClusterWithName
var err error
-
+ var cg []ClusterGroup
+ index := 0
for _, eachAllOf := range intent.AllOfArray {
- clustersWithName, err = intentResolverHelper(eachAllOf.ProviderName, eachAllOf.ClusterName, eachAllOf.ClusterLabelName, clustersWithName)
+ mc, err = intentResolverHelper(eachAllOf.ProviderName, eachAllOf.ClusterName, eachAllOf.ClusterLabelName, mc)
if err != nil {
- return Clusters{}, pkgerrors.Wrap(err, "intentResolverHelper error")
+ return ClusterList{}, pkgerrors.Wrap(err, "intentResolverHelper error")
}
if len(eachAllOf.AnyOfArray) > 0 {
for _, eachAnyOf := range eachAllOf.AnyOfArray {
- clustersWithName, err = intentResolverHelper(eachAnyOf.ProviderName, eachAnyOf.ClusterName, eachAnyOf.ClusterLabelName, clustersWithName)
+ var opc []ClusterWithName
+ opc, err = intentResolverHelper(eachAnyOf.ProviderName, eachAnyOf.ClusterName, eachAnyOf.ClusterLabelName, opc)
+ index++
if err != nil {
- return Clusters{}, pkgerrors.Wrap(err, "intentResolverHelper error")
+ return ClusterList{}, pkgerrors.Wrap(err, "intentResolverHelper error")
}
+ eachClustergroup := ClusterGroup{OptionalClusters: opc, GroupNumber: strconv.Itoa(index)}
+ cg = append(cg, eachClustergroup)
}
}
}
if len(intent.AnyOfArray) > 0 {
+ var opc []ClusterWithName
for _, eachAnyOf := range intent.AnyOfArray {
- clustersWithName, err = intentResolverHelper(eachAnyOf.ProviderName, eachAnyOf.ClusterName, eachAnyOf.ClusterLabelName, clustersWithName)
+ opc, err = intentResolverHelper(eachAnyOf.ProviderName, eachAnyOf.ClusterName, eachAnyOf.ClusterLabelName, opc)
+ index++
if err != nil {
- return Clusters{}, pkgerrors.Wrap(err, "intentResolverHelper error")
+ return ClusterList{}, pkgerrors.Wrap(err, "intentResolverHelper error")
}
+ eachClustergroup := ClusterGroup{OptionalClusters: opc, GroupNumber: strconv.Itoa(index)}
+ cg = append(cg, eachClustergroup)
}
}
- clusters := Clusters{clustersWithName}
- return clusters, nil
+ clusterList := ClusterList{MandatoryClusters: mc, ClusterGroups: cg}
+ return clusterList, nil
}