aboutsummaryrefslogtreecommitdiffstats
path: root/src/ncm/pkg/module/cluster.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/ncm/pkg/module/cluster.go')
-rw-r--r--src/ncm/pkg/module/cluster.go89
1 files changed, 77 insertions, 12 deletions
diff --git a/src/ncm/pkg/module/cluster.go b/src/ncm/pkg/module/cluster.go
index 2397a091..5d1f577f 100644
--- a/src/ncm/pkg/module/cluster.go
+++ b/src/ncm/pkg/module/cluster.go
@@ -17,9 +17,16 @@
package module
import (
- "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
+ "context"
+ "encoding/json"
+ "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 +481,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,
@@ -497,10 +504,28 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error {
return pkgerrors.Wrap(err, "Error adding App to AppContext")
}
+ // Add an app order instruction
+ appinstr := struct {
+ Apporder []string `json:"apporder"`
+ }{
+ []string{CONTEXT_CLUSTER_APP},
+ }
+ jinstr, _ := json.Marshal(appinstr)
+
+ appdepinstr := struct {
+ Appdep map[string]string `json:"appdependency"`
+ }{
+ map[string]string{CONTEXT_CLUSTER_APP: "go"},
+ }
+ jdep, _ := json.Marshal(appdepinstr)
+
+ _, err = ac.AddInstruction(handle, "app", "order", string(jinstr))
+ _, err = ac.AddInstruction(handle, "app", "dependency", string(jdep))
+
// 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,
@@ -511,10 +536,20 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error {
}
// add the resources to the app context
+
+ var orderinstr struct {
+ Resorder []string `json:"resorder"`
+ }
+ var depinstr struct {
+ Resdep map[string]string `json:"resdependency"`
+ }
+ resdep := make(map[string]string)
for _, resource := range resources {
- _, err = context.AddResource(clusterhandle, resource.name, resource.value)
+ orderinstr.Resorder = append(orderinstr.Resorder, resource.name)
+ resdep[resource.name] = "go"
+ _, 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,
@@ -525,6 +560,11 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error {
return pkgerrors.Wrap(err, "Error adding Resource to AppContext")
}
}
+ jresord, _ := json.Marshal(orderinstr)
+ depinstr.Resdep = resdep
+ jresdep, _ := json.Marshal(depinstr)
+ _, err = ac.AddInstruction(clusterhandle, "resource", "order", string(jresord))
+ _, err = ac.AddInstruction(clusterhandle, "resource", "dependency", string(jresdep))
// save the context in the cluster db record
key := ClusterKey{
@@ -533,7 +573,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 +583,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
}