summaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg/grpc
diff options
context:
space:
mode:
Diffstat (limited to 'src/orchestrator/pkg/grpc')
-rw-r--r--src/orchestrator/pkg/grpc/installappclient/client.go66
1 files changed, 65 insertions, 1 deletions
diff --git a/src/orchestrator/pkg/grpc/installappclient/client.go b/src/orchestrator/pkg/grpc/installappclient/client.go
index 4c652a84..0e9141a6 100644
--- a/src/orchestrator/pkg/grpc/installappclient/client.go
+++ b/src/orchestrator/pkg/grpc/installappclient/client.go
@@ -19,10 +19,32 @@ import (
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"
+
+// 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
+ }
+ }
+ return found
+}
+
// 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
@@ -34,7 +56,11 @@ func InvokeInstallApp(appContextId string) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
- conn := rpc.GetRpcConn("rsync")
+ conn := rpc.GetRpcConn(rsyncName)
+ if conn == nil {
+ initRsyncClient()
+ conn = rpc.GetRpcConn(rsyncName)
+ }
if conn != nil {
rpcClient = installpb.NewInstallappClient(conn)
@@ -64,3 +90,41 @@ func InvokeInstallApp(appContextId string) error {
}
return err
}
+
+func InvokeUninstallApp(appContextId string) error {
+ var err error
+ var rpcClient installpb.InstallappClient
+ var uninstallRes *installpb.UninstallAppResponse
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ defer cancel()
+
+ conn := rpc.GetRpcConn("rsync")
+
+ if conn != nil {
+ rpcClient = installpb.NewInstallappClient(conn)
+ uninstallReq := new(installpb.UninstallAppRequest)
+ uninstallReq.AppContext = appContextId
+ uninstallRes, err = rpcClient.UninstallApp(ctx, uninstallReq)
+ if err == nil {
+ log.Info("Response from UninstappApp GRPC call", log.Fields{
+ "Succeeded": uninstallRes.AppContextUninstalled,
+ "Message": uninstallRes.AppContextUninstallMessage,
+ })
+ }
+ } else {
+ return pkgerrors.Errorf("UninstallApp Failed - Could not get InstallAppClient: %v", "rsync")
+ }
+
+ if err == nil {
+ if uninstallRes.AppContextUninstalled {
+ log.Info("UninstallApp Success", log.Fields{
+ "AppContext": appContextId,
+ "Message": uninstallRes.AppContextUninstallMessage,
+ })
+ return nil
+ } else {
+ return pkgerrors.Errorf("UninstallApp Failed: %v", uninstallRes.AppContextUninstallMessage)
+ }
+ }
+ return err
+}