aboutsummaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'src/orchestrator/pkg')
-rw-r--r--src/orchestrator/pkg/grpc/installappclient/client.go50
-rw-r--r--src/orchestrator/pkg/module/instantiation_scheduler_helper.go43
2 files changed, 75 insertions, 18 deletions
diff --git a/src/orchestrator/pkg/grpc/installappclient/client.go b/src/orchestrator/pkg/grpc/installappclient/client.go
index 0e9141a6..7292ddd5 100644
--- a/src/orchestrator/pkg/grpc/installappclient/client.go
+++ b/src/orchestrator/pkg/grpc/installappclient/client.go
@@ -15,39 +15,57 @@ package installappclient
import (
"context"
+ "sync"
"time"
log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/rpc"
- "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller"
installpb "github.com/onap/multicloud-k8s/src/rsync/pkg/grpc/installapp"
pkgerrors "github.com/pkg/errors"
)
const rsyncName = "rsync"
+/*
+RsyncInfo consists of rsyncName, hostName and portNumber.
+*/
+type RsyncInfo struct {
+ RsyncName string
+ hostName string
+ portNumber int
+}
+
+var rsyncInfo RsyncInfo
+var mutex = &sync.Mutex{}
+
// InitRsyncClient initializes connctions to the Resource Synchronizer service
func initRsyncClient() bool {
- client := controller.NewControllerClient()
-
- vals, _ := client.GetControllers()
- found := false
- for _, v := range vals {
- if v.Metadata.Name == rsyncName {
- log.Info("Initializing RPC connection to resource synchronizer", log.Fields{
- "Controller": v.Metadata.Name,
- })
- rpc.UpdateRpcConn(v.Metadata.Name, v.Spec.Host, v.Spec.Port)
- found = true
- break
- }
+ if (RsyncInfo{}) == rsyncInfo {
+ mutex.Lock()
+ defer mutex.Unlock()
+ log.Error("RsyncInfo not set. InitRsyncClient failed", log.Fields{
+ "Rsyncname": rsyncInfo.RsyncName,
+ "Hostname": rsyncInfo.hostName,
+ "PortNumber": rsyncInfo.portNumber,
+ })
+ return false
}
- return found
+ rpc.UpdateRpcConn(rsyncInfo.RsyncName, rsyncInfo.hostName, rsyncInfo.portNumber)
+ return true
+}
+
+// NewRsyncInfo shall return a newly created RsyncInfo object
+func NewRsyncInfo(rName, h string, pN int) RsyncInfo {
+ mutex.Lock()
+ defer mutex.Unlock()
+ rsyncInfo = RsyncInfo{RsyncName: rName, hostName: h, portNumber: pN}
+ return rsyncInfo
+
}
// InvokeInstallApp will make the grpc call to the resource synchronizer
// or rsync controller.
-// rsync will deply the resources in the app context to the clusters as
+// rsync will deploy the resources in the app context to the clusters as
// prepared in the app context.
func InvokeInstallApp(appContextId string) error {
var err error
diff --git a/src/orchestrator/pkg/module/instantiation_scheduler_helper.go b/src/orchestrator/pkg/module/instantiation_scheduler_helper.go
index 184d6972..9f29dc38 100644
--- a/src/orchestrator/pkg/module/instantiation_scheduler_helper.go
+++ b/src/orchestrator/pkg/module/instantiation_scheduler_helper.go
@@ -27,6 +27,7 @@ import (
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"
+ pkgerrors "github.com/pkg/errors"
)
// ControllerTypePlacement denotes "placement" Controller Type
@@ -35,6 +36,9 @@ const ControllerTypePlacement string = "placement"
// ControllerTypeAction denotes "action" Controller Type
const ControllerTypeAction string = "action"
+// rsyncName denotes the name of the rsync controller
+const rsyncName = "rsync"
+
// ControllerElement consists of controller and an internal field - index
type ControllerElement struct {
controller controller.Controller
@@ -192,11 +196,38 @@ func callGrpcForControllerList(cl []controller.Controller, mc map[string]string,
}
/*
+queryDBAndSetRsyncInfo queries the MCO db to find the record the sync controller
+and then sets the RsyncInfo global variable.
+*/
+func queryDBAndSetRsyncInfo() (rsyncclient.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 := rsyncclient.NewRsyncInfo(v.Metadata.Name, v.Spec.Host, v.Spec.Port)
+ return rsyncInfo, nil
+ }
+ }
+ return rsyncclient.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 := rsyncclient.InvokeInstallApp(appContextID)
+ err = rsyncclient.InvokeInstallApp(appContextID)
if err != nil {
return err
}
@@ -207,8 +238,16 @@ func callRsyncInstall(contextid interface{}) error {
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 := rsyncclient.InvokeUninstallApp(appContextID)
+ err = rsyncclient.InvokeUninstallApp(appContextID)
if err != nil {
return err
}