aboutsummaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg/gpic/gpic.go
diff options
context:
space:
mode:
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
}