From e234bd9c967e19dccc0abebe804b829288df34c9 Mon Sep 17 00:00:00 2001 From: Tamas Veingartner Date: Mon, 10 Aug 2020 09:51:24 +0100 Subject: [PATCH] =?UTF-8?q?fix=20for=20Could=20not=20reconnect=20to=20the?= =?UTF-8?q?=20RPC=20server=E2=80=9C=20error=20on=20shutdown=20via=20Shell-?= =?UTF-8?q?Cli=20(#6595)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit an RPCUtils created to centralize method name related operations --- .../client/rpc/internal/RPCClientProxyHandler.kt | 3 ++- .../net/corda/client/rpc/internal/RPCUtils.kt | 15 +++++++++++++++ .../rpc/internal/ReconnectingCordaRPCOps.kt | 5 ++--- .../net/corda/tools/shell/InteractiveShell.kt | 5 ++--- 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 client/rpc/src/main/kotlin/net/corda/client/rpc/internal/RPCUtils.kt diff --git a/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/RPCClientProxyHandler.kt b/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/RPCClientProxyHandler.kt index 678abe5338..8c36cc73ae 100644 --- a/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/RPCClientProxyHandler.kt +++ b/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/RPCClientProxyHandler.kt @@ -10,6 +10,7 @@ import net.corda.client.rpc.ConnectionFailureException import net.corda.client.rpc.CordaRPCClientConfiguration import net.corda.client.rpc.RPCException import net.corda.client.rpc.RPCSinceVersion +import net.corda.client.rpc.internal.RPCUtils.isShutdownCmd import net.corda.core.context.Actor import net.corda.core.context.Trace import net.corda.core.context.Trace.InvocationId @@ -342,7 +343,7 @@ internal class RPCClientProxyHandler( "Generated several RPC requests with same ID $replyId" } - if (request.methodName.equals("terminate", true)){ + if (request.isShutdownCmd()){ terminating = true } diff --git a/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/RPCUtils.kt b/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/RPCUtils.kt new file mode 100644 index 0000000000..3d15a66d40 --- /dev/null +++ b/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/RPCUtils.kt @@ -0,0 +1,15 @@ +package net.corda.client.rpc.internal + +import net.corda.nodeapi.RPCApi +import java.lang.reflect.Method + +object RPCUtils { + fun isShutdownMethodName(methodName: String) = + methodName.equals("shutdown", true) || + methodName.equals("gracefulShutdown", true) || + methodName.equals("terminate", true) + + fun RPCApi.ClientToServer.RpcRequest.isShutdownCmd() = isShutdownMethodName(methodName) + fun Method.isShutdown() = isShutdownMethodName(name) + fun Method.isStartFlow() = name.startsWith("startFlow") || name.startsWith("startTrackedFlow") +} \ No newline at end of file diff --git a/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/ReconnectingCordaRPCOps.kt b/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/ReconnectingCordaRPCOps.kt index 4b4945f4f6..3c5085eb5a 100644 --- a/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/ReconnectingCordaRPCOps.kt +++ b/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/ReconnectingCordaRPCOps.kt @@ -10,6 +10,8 @@ import net.corda.client.rpc.PermissionException import net.corda.client.rpc.RPCConnection import net.corda.client.rpc.RPCException import net.corda.client.rpc.UnrecoverableRPCException +import net.corda.client.rpc.internal.RPCUtils.isShutdown +import net.corda.client.rpc.internal.RPCUtils.isStartFlow import net.corda.client.rpc.internal.ReconnectingCordaRPCOps.ReconnectingRPCConnection.CurrentState.CLOSED import net.corda.client.rpc.internal.ReconnectingCordaRPCOps.ReconnectingRPCConnection.CurrentState.CONNECTED import net.corda.client.rpc.internal.ReconnectingCordaRPCOps.ReconnectingRPCConnection.CurrentState.CONNECTING @@ -292,9 +294,6 @@ class ReconnectingCordaRPCOps private constructor( fun isClosed(): Boolean = currentState == CLOSED } private class ErrorInterceptingHandler(val reconnectingRPCConnection: ReconnectingRPCConnection) : InvocationHandler { - private fun Method.isStartFlow() = name.startsWith("startFlow") || name.startsWith("startTrackedFlow") - private fun Method.isShutdown() = name == "shutdown" || name == "gracefulShutdown" || name == "terminate" - private fun checkIfIsStartFlow(method: Method, e: InvocationTargetException) { if (method.isStartFlow()) { // Don't retry flows diff --git a/tools/shell/src/main/kotlin/net/corda/tools/shell/InteractiveShell.kt b/tools/shell/src/main/kotlin/net/corda/tools/shell/InteractiveShell.kt index d78f4be24f..fa7519b206 100644 --- a/tools/shell/src/main/kotlin/net/corda/tools/shell/InteractiveShell.kt +++ b/tools/shell/src/main/kotlin/net/corda/tools/shell/InteractiveShell.kt @@ -14,6 +14,7 @@ import net.corda.client.rpc.CordaRPCClientConfiguration import net.corda.client.rpc.CordaRPCConnection import net.corda.client.rpc.GracefulReconnect import net.corda.client.rpc.PermissionException +import net.corda.client.rpc.internal.RPCUtils.isShutdownMethodName import net.corda.client.rpc.notUsed import net.corda.core.CordaException import net.corda.core.concurrent.CordaFuture @@ -111,8 +112,6 @@ object InteractiveShell { YAML } - private fun isShutdownCmd(cmd: String) = cmd == "shutdown" || cmd == "gracefulShutdown" || cmd == "terminate" - fun startShell(configuration: ShellConfiguration, classLoader: ClassLoader? = null, standalone: Boolean = false) { makeRPCConnection = { username: String, password: String -> val connection = if (standalone) { @@ -625,7 +624,7 @@ object InteractiveShell { throw e.rootCause } } - if (isShutdownCmd(cmd)) { + if (isShutdownMethodName(cmd)) { out.println("Called 'shutdown' on the node.\nQuitting the shell now.").also { out.flush() } onExit.invoke() }