diff options
author | Eric Multanen <eric.w.multanen@intel.com> | 2020-07-02 15:34:13 -0700 |
---|---|---|
committer | Eric Multanen <eric.w.multanen@intel.com> | 2020-07-08 14:17:06 -0700 |
commit | 0af31b5e508faa227a36e687346e7905a7a10ed6 (patch) | |
tree | 3a1f0e7565f8ce699f094167009cc68db7e16ad8 /src/orchestrator/pkg/grpc | |
parent | e06b947b03c3fcce2c954feb68890a519c7740c3 (diff) |
Add terminate support to orchestrator and ncm
Complete the basic terminate support for the
orchestrator and ncm services.
1. When terminate REST API is invoked on a deployment
intent group, call the uninstall grpc api to rsync
and then remove the app context.
2. When terminate REST API is invoked on a cluster,
add the uninstall grpc api call to rsync to remove
the network resources from the clusters.
Issue-ID: MULTICLOUD-1040
Signed-off-by: Eric Multanen <eric.w.multanen@intel.com>
Change-Id: I181e891a8c7c973970af061f9ff07d80c3bb64f9
Diffstat (limited to 'src/orchestrator/pkg/grpc')
-rw-r--r-- | src/orchestrator/pkg/grpc/installappclient/client.go | 66 |
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 +} |