From 1e5858f4ab510acd71272a53cfddce8d945daad0 Mon Sep 17 00:00:00 2001 From: Rajamohan Raj Date: Sun, 7 Jun 2020 22:42:04 +0000 Subject: Make GRPC calls and delete extra cluster handles 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 Change-Id: I4b946f5f130300628ef4f655213639a2444be2cc --- src/orchestrator/pkg/module/instantiation.go | 21 +++++++++ .../pkg/module/instantiation_scheduler_helper.go | 53 ++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/src/orchestrator/pkg/module/instantiation.go b/src/orchestrator/pkg/module/instantiation.go index 27990cee..76be2a2d 100644 --- a/src/orchestrator/pkg/module/instantiation.go +++ b/src/orchestrator/pkg/module/instantiation.go @@ -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 } diff --git a/src/orchestrator/pkg/module/instantiation_scheduler_helper.go b/src/orchestrator/pkg/module/instantiation_scheduler_helper.go index cbc1b31d..e4bbbfac 100644 --- a/src/orchestrator/pkg/module/instantiation_scheduler_helper.go +++ b/src/orchestrator/pkg/module/instantiation_scheduler_helper.go @@ -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 +} -- cgit 1.2.3-korg