Make GRPC calls and delete extra cluster handles 72/108872/1
authorRajamohan Raj <rajamohan.raj@intel.com>
Sun, 7 Jun 2020 22:42:04 +0000 (22:42 +0000)
committerRajamohan Raj <rajamohan.raj@intel.com>
Sun, 7 Jun 2020 22:52:37 +0000 (22:52 +0000)
The patch makes grpc calls for context updation
for a given list of controllers and deletes the
    extra set of cluster handles for each anyOf
    cluster after context updation

Issue-ID: MULTICLOUD-1064
Signed-off-by: Rajamohan Raj <rajamohan.raj@intel.com>
Change-Id: I4b946f5f130300628ef4f655213639a2444be2cc

src/orchestrator/pkg/module/instantiation.go
src/orchestrator/pkg/module/instantiation_scheduler_helper.go

index 27990ce..76be2a2 100644 (file)
@@ -276,11 +276,32 @@ func (c InstantiationClient) Instantiate(p string, ca string, v string, di strin
        // BEGIN: scheduler code
 
        pl, mapOfControllers, err := getPrioritizedControllerList(p, ca, v, di)
+       if err != nil {
+               return err
+       }
        log.Info("Priority Based List ", log.Fields{"PlacementControllers::": pl.pPlaCont,
                "ActionControllers::": pl.pActCont, "mapOfControllers::": mapOfControllers})
 
+       err = callGrpcForControllerList(pl.pPlaCont, mapOfControllers, ctxval)
+       if err != nil {
+               return err
+       }
+
+       err = deleteExtraClusters(allApps, context)
+       if err != nil {
+               return err
+       }
+
+       err = callGrpcForControllerList(pl.pActCont, mapOfControllers, ctxval)
+       if err != nil {
+               return err
+       }
+
        // END: Scheduler code
 
+       // BEGIN : Rsync code
+       // END : Rsyc code
+
        log.Info(":: Done with instantiation... ::", log.Fields{"CompositeAppName": ca})
        return err
 }
index cbc1b31..e4bbbfa 100644 (file)
@@ -18,6 +18,11 @@ package module
 
 import (
        "container/heap"
+
+       "fmt"
+
+       "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
+       client "github.com/onap/multicloud-k8s/src/orchestrator/pkg/grpc/contextupdateclient"
        log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
        "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller"
        mtypes "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/types"
@@ -167,3 +172,51 @@ func getPrioritizedControllerList(p, ca, v, di string) (PrioritizedControlList,
        return prioritizedControlList, mapOfControllers, nil
 
 }
+
+/*
+callGrpcForControllerList method shall take in a list of controllers, a map of contollers to controllerIntentNames and contextID. It invokes the context
+updation through the grpc client for the given list of controllers.
+*/
+func callGrpcForControllerList(cl []controller.Controller, mc map[string]string, contextid interface{}) error {
+       for _, c := range cl {
+               controller := c.Metadata.Name
+               controllerIntentName := mc[controller]
+               appContextID := fmt.Sprintf("%v", contextid)
+               err := client.InvokeContextUpdate(controller, controllerIntentName, appContextID)
+               if err != nil {
+                       return err
+               }
+       }
+       return nil
+}
+
+/*
+deleteExtraClusters method shall delete the extra cluster handles for each AnyOf cluster present in the etcd after the grpc call for context updation.
+*/
+func deleteExtraClusters(apps []App, ct appcontext.AppContext) error {
+       for _, app := range apps {
+               an := app.Metadata.Name
+               gmap, err := ct.GetClusterGroupMap(an)
+               if err != nil {
+                       return err
+               }
+               for gr, cl := range gmap {
+                       for i, cn := range cl {
+                               // avoids deleting the first cluster
+                               if i > 0 {
+                                       ch, err := ct.GetClusterHandle(an, cn)
+                                       if err != nil {
+                                               return err
+                                       }
+                                       err = ct.DeleteCluster(ch)
+                                       if err != nil {
+                                               return err
+                                       }
+                                       log.Info("::Deleted cluster for::", log.Fields{"appName": an, "GroupNumber": gr, "ClusterName": cn})
+                               }
+                       }
+
+               }
+       }
+       return nil
+}