From 7fc603a5eedcd6a84860c881a1228309a308805f Mon Sep 17 00:00:00 2001 From: Eric Multanen Date: Fri, 15 May 2020 07:09:16 -0700 Subject: Add appcontext instructions during intent apply Create AppContext instruction records at the app and resource levels when handling the apply api for network and providernetwork intents. Issue-ID: MULTICLOUD-1029 Signed-off-by: Eric Multanen Change-Id: I3c82087273278b2503959664f0a8ee4e34eb0cd2 --- src/ncm/pkg/module/cluster.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/ncm/pkg') diff --git a/src/ncm/pkg/module/cluster.go b/src/ncm/pkg/module/cluster.go index 7a35eb16..5d1f577f 100644 --- a/src/ncm/pkg/module/cluster.go +++ b/src/ncm/pkg/module/cluster.go @@ -18,6 +18,7 @@ package module import ( "context" + "encoding/json" "time" "github.com/onap/multicloud-k8s/src/ncm/pkg/grpc" @@ -503,6 +504,24 @@ 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 := ac.AddCluster(apphandle, provider+SEPARATOR+name) if err != nil { @@ -517,7 +536,17 @@ 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 { + orderinstr.Resorder = append(orderinstr.Resorder, resource.name) + resdep[resource.name] = "go" _, err = ac.AddResource(clusterhandle, resource.name, resource.value) if err != nil { cleanuperr := ac.DeleteCompositeApp() @@ -531,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{ -- cgit 1.2.3-korg