aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ncm/pkg/scheduler/scheduler.go68
-rw-r--r--src/orchestrator/pkg/grpc/installappclient/client.go50
-rw-r--r--src/orchestrator/pkg/module/instantiation_scheduler_helper.go43
-rw-r--r--src/rsync/cmd/main.go6
-rw-r--r--src/rsync/go.mod8
-rw-r--r--src/rsync/pkg/client/client.go2
-rw-r--r--src/rsync/pkg/grpc/installappserver/installappserver.go3
-rw-r--r--src/rsync/pkg/grpc/register.go40
8 files changed, 148 insertions, 72 deletions
diff --git a/src/ncm/pkg/scheduler/scheduler.go b/src/ncm/pkg/scheduler/scheduler.go
index 131113db..f2135974 100644
--- a/src/ncm/pkg/scheduler/scheduler.go
+++ b/src/ncm/pkg/scheduler/scheduler.go
@@ -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
}
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
}
diff --git a/src/rsync/cmd/main.go b/src/rsync/cmd/main.go
index 95c36e20..3e6c4df7 100644
--- a/src/rsync/cmd/main.go
+++ b/src/rsync/cmd/main.go
@@ -15,12 +15,12 @@ package main
import (
"fmt"
- "log"
- "math/rand"
- "net"
register "github.com/onap/multicloud-k8s/src/rsync/pkg/grpc"
installpb "github.com/onap/multicloud-k8s/src/rsync/pkg/grpc/installapp"
"github.com/onap/multicloud-k8s/src/rsync/pkg/grpc/installappserver"
+ "log"
+ "math/rand"
+ "net"
"strings"
"time"
diff --git a/src/rsync/go.mod b/src/rsync/go.mod
index 973895a3..0fd2c787 100644
--- a/src/rsync/go.mod
+++ b/src/rsync/go.mod
@@ -3,16 +3,13 @@ module github.com/onap/multicloud-k8s/src/rsync
go 1.13
require (
- //client
- github.com/evanphx/json-patch v4.5.0+incompatible // indirect
github.com/ghodss/yaml v1.0.0
github.com/golang/protobuf v1.4.1
github.com/googleapis/gnostic v0.4.0
github.com/jonboulle/clockwork v0.1.0
github.com/onap/multicloud-k8s/src/clm v0.0.0-00010101000000-000000000000
- github.com/onap/multicloud-k8s/src/monitor v0.0.0-20200708223327-9a9a6aedbd7a
- github.com/onap/multicloud-k8s/src/orchestrator v0.0.0-20200721211210-783ed87fb39a
- //github.com/onap/multicloud-k8s/src/orchestrator v0.0.0-20200601021239-7959bd4c6fd4
+ github.com/onap/multicloud-k8s/src/monitor v0.0.0-20200818155723-a5ffa8aadf49
+ github.com/onap/multicloud-k8s/src/orchestrator v0.0.0-20200818155723-a5ffa8aadf49
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.5.0
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
@@ -30,7 +27,6 @@ require (
replace (
github.com/onap/multicloud-k8s/src/clm => ../clm
github.com/onap/multicloud-k8s/src/monitor => ../monitor
- github.com/onap/multicloud-k8s/src/orchestrator => ../orchestrator
k8s.io/api => k8s.io/api v0.17.3
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.17.3
k8s.io/apimachinery => k8s.io/apimachinery v0.17.3
diff --git a/src/rsync/pkg/client/client.go b/src/rsync/pkg/client/client.go
index 0eaded22..a489b951 100644
--- a/src/rsync/pkg/client/client.go
+++ b/src/rsync/pkg/client/client.go
@@ -187,4 +187,4 @@ func (c *Client) IsReachable() error {
return fmt.Errorf("Kubernetes cluster unreachable")
}
return nil
-} \ No newline at end of file
+}
diff --git a/src/rsync/pkg/grpc/installappserver/installappserver.go b/src/rsync/pkg/grpc/installappserver/installappserver.go
index d70000c0..3a24dab8 100644
--- a/src/rsync/pkg/grpc/installappserver/installappserver.go
+++ b/src/rsync/pkg/grpc/installappserver/installappserver.go
@@ -16,10 +16,9 @@ package installappserver
import (
"context"
"encoding/json"
- "log"
-
con "github.com/onap/multicloud-k8s/src/rsync/pkg/context"
"github.com/onap/multicloud-k8s/src/rsync/pkg/grpc/installapp"
+ "log"
)
type installappServer struct {
diff --git a/src/rsync/pkg/grpc/register.go b/src/rsync/pkg/grpc/register.go
index fb462505..60bd50d6 100644
--- a/src/rsync/pkg/grpc/register.go
+++ b/src/rsync/pkg/grpc/register.go
@@ -19,8 +19,6 @@ import (
"strings"
log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
- controller "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller"
- mtypes "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/types"
)
const default_host = "localhost"
@@ -58,41 +56,3 @@ func GetServerHostPort() (string, int) {
}
return host, port
}
-
-func RegisterGrpcServer(host string, port int) error {
- // expect name of this rsync program to be in env variable "RSYNC_NAME" - e.g. RSYNC_NAME="rsync"
- // This will be the name of the controller that is registered in the orchestrator controller API
- // This same name will be used as the key name for intents in the deployment intent group
- serviceName := os.Getenv(ENV_RSYNC_NAME)
- if serviceName == "" {
- serviceName = default_rsync_name
- log.Info("Using default name for rsync service name", log.Fields{
- "Name": serviceName,
- })
- }
-
- client := controller.NewControllerClient()
-
- // Create or update the controller entry
- controller := controller.Controller{
- Metadata: mtypes.Metadata{
- Name: serviceName,
- },
- Spec: controller.ControllerSpec{
- Host: host,
- Port: port,
- Type: controller.CONTROLLER_TYPE_ACTION,
- Priority: controller.MinControllerPriority,
- },
- }
- _, err := client.CreateController(controller, true)
- if err != nil {
- log.Error("Failed to create/update a gRPC controller", log.Fields{
- "Error": err,
- "Controller": serviceName,
- })
- return err
- }
-
- return nil
-}