Add rsync registration changes to ncm too 15/111915/1
authorEric Multanen <eric.w.multanen@intel.com>
Mon, 31 Aug 2020 18:29:22 +0000 (11:29 -0700)
committerEric Multanen <eric.w.multanen@intel.com>
Mon, 31 Aug 2020 18:31:28 +0000 (11:31 -0700)
Changes made to remove dependency of rsyn
registraion from orchestrator need to be added
to ncm as well.

Issue-ID: MULTICLOUD-1196
Signed-off-by: Eric Multanen <eric.w.multanen@intel.com>
Change-Id: Ie572a127fd87cf50a1bb03163d98d3ebe901437e

src/ncm/pkg/scheduler/scheduler.go

index 131113d..f213597 100644 (file)
@@ -18,6 +18,7 @@ package scheduler
 
 import (
        "encoding/json"
+       "fmt"
        "time"
 
        clusterPkg "github.com/onap/multicloud-k8s/src/clm/pkg/cluster"
@@ -28,11 +29,15 @@ import (
        "github.com/onap/multicloud-k8s/src/orchestrator/pkg/grpc/installappclient"
        "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
        log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
+       "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller"
        "github.com/onap/multicloud-k8s/src/orchestrator/pkg/state"
 
        pkgerrors "github.com/pkg/errors"
 )
 
+// rsyncName denotes the name of the rsync controller
+const rsyncName = "rsync"
+
 // ClusterManager is an interface exposes the Cluster functionality
 type SchedulerManager interface {
        ApplyNetworkIntents(clusterProvider, cluster string) error
@@ -65,6 +70,65 @@ func deleteAppContext(ac appcontext.AppContext) {
        }
 }
 
+/*
+queryDBAndSetRsyncInfo queries the MCO db to find the record the sync controller
+and then sets the RsyncInfo global variable.
+*/
+func queryDBAndSetRsyncInfo() (installappclient.RsyncInfo, error) {
+       client := controller.NewControllerClient()
+       vals, _ := client.GetControllers()
+       for _, v := range vals {
+               if v.Metadata.Name == rsyncName {
+                       log.Info("Initializing RPC connection to resource synchronizer", log.Fields{
+                               "Controller": v.Metadata.Name,
+                       })
+                       rsyncInfo := installappclient.NewRsyncInfo(v.Metadata.Name, v.Spec.Host, v.Spec.Port)
+                       return rsyncInfo, nil
+               }
+       }
+       return installappclient.RsyncInfo{}, pkgerrors.Errorf("queryRsyncInfoInMCODB Failed - Could not get find rsync by name : %v", rsyncName)
+}
+
+/*
+callRsyncInstall method shall take in the app context id and invokes the rsync service via grpc
+*/
+func callRsyncInstall(contextid interface{}) error {
+       rsyncInfo, err := queryDBAndSetRsyncInfo()
+       log.Info("Calling the Rsync ", log.Fields{
+               "RsyncName": rsyncInfo.RsyncName,
+       })
+       if err != nil {
+               return err
+       }
+
+       appContextID := fmt.Sprintf("%v", contextid)
+       err = installappclient.InvokeInstallApp(appContextID)
+       if err != nil {
+               return err
+       }
+       return nil
+}
+
+/*
+callRsyncUninstall method shall take in the app context id and invokes the rsync service via grpc
+*/
+func callRsyncUninstall(contextid interface{}) error {
+       rsyncInfo, err := queryDBAndSetRsyncInfo()
+       log.Info("Calling the Rsync ", log.Fields{
+               "RsyncName": rsyncInfo.RsyncName,
+       })
+       if err != nil {
+               return err
+       }
+
+       appContextID := fmt.Sprintf("%v", contextid)
+       err = installappclient.InvokeUninstallApp(appContextID)
+       if err != nil {
+               return err
+       }
+       return nil
+}
+
 // Apply Network Intents associated with a cluster
 func (v *SchedulerClient) ApplyNetworkIntents(clusterProvider, cluster string) error {
 
@@ -162,7 +226,7 @@ func (v *SchedulerClient) ApplyNetworkIntents(clusterProvider, cluster string) e
        }
 
        // call resource synchronizer to instantiate the CRs in the cluster
-       err = installappclient.InvokeInstallApp(ctxVal.(string))
+       err = callRsyncInstall(ctxVal)
        if err != nil {
                deleteAppContext(ac)
                return err
@@ -216,7 +280,7 @@ func (v *SchedulerClient) TerminateNetworkIntents(clusterProvider, cluster strin
 
        // call resource synchronizer to terminate the CRs in the cluster
        contextId := state.GetLastContextIdFromStateInfo(s)
-       err = installappclient.InvokeUninstallApp(contextId)
+       err = callRsyncUninstall(contextId)
        if err != nil {
                return err
        }