aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/orchestrator/pkg/grpc/installappclient/client.go66
-rw-r--r--src/orchestrator/pkg/module/instantiation.go25
-rw-r--r--src/orchestrator/pkg/module/instantiation_appcontext_helper.go34
-rw-r--r--src/orchestrator/pkg/module/instantiation_scheduler_helper.go13
4 files changed, 125 insertions, 13 deletions
diff --git a/src/orchestrator/pkg/grpc/installappclient/client.go b/src/orchestrator/pkg/grpc/installappclient/client.go
new file mode 100644
index 00000000..4c652a84
--- /dev/null
+++ b/src/orchestrator/pkg/grpc/installappclient/client.go
@@ -0,0 +1,66 @@
+/*
+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 installappclient
+
+import (
+ "context"
+ "time"
+
+ 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"
+ pkgerrors "github.com/pkg/errors"
+)
+
+// 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
+// prepared in the app context.
+func InvokeInstallApp(appContextId string) error {
+ var err error
+ var rpcClient installpb.InstallappClient
+ var installRes *installpb.InstallAppResponse
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ defer cancel()
+
+ conn := rpc.GetRpcConn("rsync")
+
+ if conn != nil {
+ rpcClient = installpb.NewInstallappClient(conn)
+ installReq := new(installpb.InstallAppRequest)
+ installReq.AppContext = appContextId
+ 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", "rsync")
+ }
+
+ if err == nil {
+ if installRes.AppContextInstalled {
+ log.Info("InstallApp Success", log.Fields{
+ "AppContext": appContextId,
+ "Message": installRes.AppContextInstallMessage,
+ })
+ return nil
+ } else {
+ return pkgerrors.Errorf("InstallApp Failed: %v", installRes.AppContextInstallMessage)
+ }
+ }
+ return err
+}
diff --git a/src/orchestrator/pkg/module/instantiation.go b/src/orchestrator/pkg/module/instantiation.go
index 76be2a2d..043b80f2 100644
--- a/src/orchestrator/pkg/module/instantiation.go
+++ b/src/orchestrator/pkg/module/instantiation.go
@@ -18,7 +18,9 @@ package module
import (
"encoding/base64"
+ "encoding/json"
"fmt"
+
gpic "github.com/onap/multicloud-k8s/src/orchestrator/pkg/gpic"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
@@ -200,11 +202,20 @@ func (c InstantiationClient) Instantiate(p string, ca string, v string, di strin
ctxval := cca.ctxval
compositeHandle := cca.compositeAppHandle
- var appOrder []string
+ var appOrderInstr struct {
+ Apporder []string `json:"apporder"`
+ }
+
+ var appDepInstr struct {
+ Appdep map[string]string `json:"appdependency"`
+ }
+ appdep := make(map[string]string)
// Add composite app using appContext
for _, eachApp := range allApps {
- appOrder = append(appOrder, eachApp.Metadata.Name)
+ appOrderInstr.Apporder = append(appOrderInstr.Apporder, eachApp.Metadata.Name)
+ appdep[eachApp.Metadata.Name] = "go"
+
sortedTemplates, err := GetSortedTemplateForApp(eachApp.Metadata.Name, p, ca, v, rName, cp, overrideValues)
if err != nil {
@@ -250,7 +261,11 @@ func (c InstantiationClient) Instantiate(p string, ca string, v string, di strin
}
}
- context.AddInstruction(compositeHandle, "app", "order", appOrder)
+ jappOrderInstr, _ := json.Marshal(appOrderInstr)
+ appDepInstr.Appdep = appdep
+ jappDepInstr, _ := json.Marshal(appDepInstr)
+ context.AddInstruction(compositeHandle, "app", "order", string(jappOrderInstr))
+ context.AddInstruction(compositeHandle, "app", "dependency", string(jappDepInstr))
//END: storing into etcd
// BEGIN:: save the context in the orchestrator db record
@@ -300,6 +315,10 @@ func (c InstantiationClient) Instantiate(p string, ca string, v string, di strin
// END: Scheduler code
// BEGIN : Rsync code
+ err = callRsync(ctxval)
+ if err != nil {
+ return err
+ }
// END : Rsyc code
log.Info(":: Done with instantiation... ::", log.Fields{"CompositeAppName": ca})
diff --git a/src/orchestrator/pkg/module/instantiation_appcontext_helper.go b/src/orchestrator/pkg/module/instantiation_appcontext_helper.go
index 1734a0c8..43ddd6df 100644
--- a/src/orchestrator/pkg/module/instantiation_appcontext_helper.go
+++ b/src/orchestrator/pkg/module/instantiation_appcontext_helper.go
@@ -22,19 +22,21 @@ It contains methods for creating appContext, saving cluster and resource details
*/
import (
+ "encoding/json"
+ "io/ioutil"
+
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
gpic "github.com/onap/multicloud-k8s/src/orchestrator/pkg/gpic"
log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
"github.com/onap/multicloud-k8s/src/orchestrator/utils"
"github.com/onap/multicloud-k8s/src/orchestrator/utils/helm"
pkgerrors "github.com/pkg/errors"
- "io/ioutil"
)
// resource consists of name of reource
type resource struct {
name string
- filecontent []byte
+ filecontent string
}
type contextForCompositeApp struct {
@@ -81,17 +83,27 @@ func getResources(st []helm.KubernetesResourceTemplate) ([]resource, error) {
}
n := yamlStruct.Metadata.Name + SEPARATOR + yamlStruct.Kind
- resources = append(resources, resource{name: n, filecontent: yamlFile})
+ resources = append(resources, resource{name: n, filecontent: string(yamlFile)})
log.Info(":: Added resource into resource-order ::", log.Fields{"ResourceName": n})
}
return resources, nil
}
-func addResourcesToCluster(ct appcontext.AppContext, ch interface{}, resources []resource, resourceOrder []string) error {
+func addResourcesToCluster(ct appcontext.AppContext, ch interface{}, resources []resource) error {
+
+ var resOrderInstr struct {
+ Resorder []string `json:"resorder"`
+ }
+
+ var resDepInstr struct {
+ Resdep map[string]string `json:"resdependency"`
+ }
+ resdep := make(map[string]string)
for _, resource := range resources {
- resourceOrder = append(resourceOrder, resource.name)
+ resOrderInstr.Resorder = append(resOrderInstr.Resorder, resource.name)
+ resdep[resource.name] = "go"
_, err := ct.AddResource(ch, resource.name, resource.filecontent)
if err != nil {
cleanuperr := ct.DeleteCompositeApp()
@@ -100,7 +112,11 @@ func addResourcesToCluster(ct appcontext.AppContext, ch interface{}, resources [
}
return pkgerrors.Wrapf(err, "Error adding resource ::%s to AppContext", resource.name)
}
- _, err = ct.AddInstruction(ch, "resource", "order", resourceOrder)
+ jresOrderInstr, _ := json.Marshal(resOrderInstr)
+ resDepInstr.Resdep = resdep
+ jresDepInstr, _ := json.Marshal(resDepInstr)
+ _, err = ct.AddInstruction(ch, "resource", "order", string(jresOrderInstr))
+ _, err = ct.AddInstruction(ch, "resource", "dependency", string(jresDepInstr))
if err != nil {
cleanuperr := ct.DeleteCompositeApp()
if cleanuperr != nil {
@@ -120,7 +136,6 @@ func addClustersToAppContext(l gpic.ClusterList, ct appcontext.AppContext, appHa
for _, c := range mc {
p := c.ProviderName
n := c.ClusterName
- var resourceOrder []string
clusterhandle, err := ct.AddCluster(appHandle, p+SEPARATOR+n)
if err != nil {
cleanuperr := ct.DeleteCompositeApp()
@@ -130,7 +145,7 @@ func addClustersToAppContext(l gpic.ClusterList, ct appcontext.AppContext, appHa
return pkgerrors.Wrapf(err, "Error adding Cluster(provider::%s and name::%s) to AppContext", p, n)
}
- err = addResourcesToCluster(ct, clusterhandle, resources, resourceOrder)
+ err = addResourcesToCluster(ct, clusterhandle, resources)
if err != nil {
return pkgerrors.Wrapf(err, "Error adding Resources to Cluster(provider::%s and name::%s) to AppContext", p, n)
}
@@ -144,7 +159,6 @@ func addClustersToAppContext(l gpic.ClusterList, ct appcontext.AppContext, appHa
p := eachCluster.ProviderName
n := eachCluster.ClusterName
- var resourceOrder []string
clusterhandle, err := ct.AddCluster(appHandle, p+SEPARATOR+n)
if err != nil {
@@ -164,7 +178,7 @@ func addClustersToAppContext(l gpic.ClusterList, ct appcontext.AppContext, appHa
return pkgerrors.Wrapf(err, "Error adding Cluster(provider::%s and name::%s) to AppContext", p, n)
}
- err = addResourcesToCluster(ct, clusterhandle, resources, resourceOrder)
+ err = addResourcesToCluster(ct, clusterhandle, resources)
if err != nil {
return pkgerrors.Wrapf(err, "Error adding Resources to Cluster(provider::%s, name::%s and groupName:: %s) to AppContext", p, n, gn)
}
diff --git a/src/orchestrator/pkg/module/instantiation_scheduler_helper.go b/src/orchestrator/pkg/module/instantiation_scheduler_helper.go
index e4bbbfac..3d9d851c 100644
--- a/src/orchestrator/pkg/module/instantiation_scheduler_helper.go
+++ b/src/orchestrator/pkg/module/instantiation_scheduler_helper.go
@@ -23,6 +23,7 @@ import (
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
client "github.com/onap/multicloud-k8s/src/orchestrator/pkg/grpc/contextupdateclient"
+ rsyncclient "github.com/onap/multicloud-k8s/src/orchestrator/pkg/grpc/installappclient"
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"
@@ -191,6 +192,18 @@ func callGrpcForControllerList(cl []controller.Controller, mc map[string]string,
}
/*
+callRsync method shall take in the app context id and invokes the rsync service via grpc
+*/
+func callRsync(contextid interface{}) error {
+ appContextID := fmt.Sprintf("%v", contextid)
+ err := rsyncclient.InvokeInstallApp(appContextID)
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+/*
deleteExtraClusters method shall delete the extra cluster handles for each AnyOf cluster present in the etcd after the grpc call for context updation.
*/
func deleteExtraClusters(apps []App, ct appcontext.AppContext) error {