aboutsummaryrefslogtreecommitdiffstats
path: root/src/ncm/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'src/ncm/pkg')
-rw-r--r--src/ncm/pkg/grpc/rsyncclient.go41
-rw-r--r--src/ncm/pkg/module/cluster.go55
2 files changed, 84 insertions, 12 deletions
diff --git a/src/ncm/pkg/grpc/rsyncclient.go b/src/ncm/pkg/grpc/rsyncclient.go
new file mode 100644
index 00000000..5eb870a7
--- /dev/null
+++ b/src/ncm/pkg/grpc/rsyncclient.go
@@ -0,0 +1,41 @@
+/*
+Copyright 2020 Intel Corporation.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package grpc
+
+import (
+ log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/rpc"
+ controller "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller"
+)
+
+const RsyncName = "rsync"
+
+// InitRsyncClient initializes connctions to the Resource Synchronizer serivice
+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
+ }
+ }
+ return found
+}
diff --git a/src/ncm/pkg/module/cluster.go b/src/ncm/pkg/module/cluster.go
index 2397a091..7a35eb16 100644
--- a/src/ncm/pkg/module/cluster.go
+++ b/src/ncm/pkg/module/cluster.go
@@ -17,9 +17,15 @@
package module
import (
- "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
+ "context"
+ "time"
+
+ "github.com/onap/multicloud-k8s/src/ncm/pkg/grpc"
+ appcontext "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
"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/infra/rpc"
+ installpb "github.com/onap/multicloud-k8s/src/rsync/pkg/grpc/installapp"
"gopkg.in/yaml.v2"
pkgerrors "github.com/pkg/errors"
@@ -474,20 +480,20 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error {
}
// Make an app context for the network intent resources
- context := appcontext.AppContext{}
- ctxVal, err := context.InitAppContext()
+ ac := appcontext.AppContext{}
+ ctxVal, err := ac.InitAppContext()
if err != nil {
return pkgerrors.Wrap(err, "Error creating AppContext")
}
- handle, err := context.CreateCompositeApp()
+ handle, err := ac.CreateCompositeApp()
if err != nil {
return pkgerrors.Wrap(err, "Error creating AppContext CompositeApp")
}
// Add an app (fixed value) to the app context
- apphandle, err := context.AddApp(handle, CONTEXT_CLUSTER_APP)
+ apphandle, err := ac.AddApp(handle, CONTEXT_CLUSTER_APP)
if err != nil {
- cleanuperr := context.DeleteCompositeApp()
+ cleanuperr := ac.DeleteCompositeApp()
if cleanuperr != nil {
log.Warn("Error cleaning AppContext CompositeApp create failure", log.Fields{
"cluster-provider": provider,
@@ -498,9 +504,9 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error {
}
// Add a cluster to the app
- clusterhandle, err := context.AddCluster(apphandle, provider+SEPARATOR+name)
+ clusterhandle, err := ac.AddCluster(apphandle, provider+SEPARATOR+name)
if err != nil {
- cleanuperr := context.DeleteCompositeApp()
+ cleanuperr := ac.DeleteCompositeApp()
if cleanuperr != nil {
log.Warn("Error cleaning AppContext after add cluster failure", log.Fields{
"cluster-provider": provider,
@@ -512,9 +518,9 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error {
// add the resources to the app context
for _, resource := range resources {
- _, err = context.AddResource(clusterhandle, resource.name, resource.value)
+ _, err = ac.AddResource(clusterhandle, resource.name, resource.value)
if err != nil {
- cleanuperr := context.DeleteCompositeApp()
+ cleanuperr := ac.DeleteCompositeApp()
if cleanuperr != nil {
log.Warn("Error cleaning AppContext after add resource failure", log.Fields{
"cluster-provider": provider,
@@ -533,7 +539,7 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error {
}
err = db.DBconn.Insert(v.db.storeName, key, nil, v.db.tagContext, ctxVal)
if err != nil {
- cleanuperr := context.DeleteCompositeApp()
+ cleanuperr := ac.DeleteCompositeApp()
if cleanuperr != nil {
log.Warn("Error cleaning AppContext after DB insert failure", log.Fields{
"cluster-provider": provider,
@@ -543,7 +549,32 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error {
return pkgerrors.Wrap(err, "Error adding AppContext to DB")
}
- // TODO: call resource synchronizer to instantiate the CRs in the cluster
+ // call resource synchronizer to instantiate the CRs in the cluster
+ conn := rpc.GetRpcConn(grpc.RsyncName)
+ if conn == nil {
+ grpc.InitRsyncClient()
+ conn = rpc.GetRpcConn(grpc.RsyncName)
+ }
+
+ var rpcClient installpb.InstallappClient
+ var installRes *installpb.InstallAppResponse
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ defer cancel()
+
+ if conn != nil {
+ rpcClient = installpb.NewInstallappClient(conn)
+ installReq := new(installpb.InstallAppRequest)
+ installReq.AppContext = ctxVal.(string)
+ installRes, err = rpcClient.InstallApp(ctx, installReq)
+ if err == nil {
+ log.Info("Response from InstappApp GRPC call", log.Fields{
+ "Succeeded": installRes.AppContextInstalled,
+ "Message": installRes.AppContextInstallMessage,
+ })
+ }
+ } else {
+ return pkgerrors.Errorf("InstallApp Failed - Could not get InstallAppClient: %v", grpc.RsyncName)
+ }
return nil
}