Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Only close gateway tunnels for interconnect connection status change in the same realm (#2396)

Rich Turnereb4d164005fb
diff --git a/manager/src/main/java/org/openremote/manager/gateway/GatewayClientService.java b/manager/src/main/java/org/openremote/manager/gateway/GatewayClientService.java
index ced5885ab..1ae1fd178 100644
--- a/manager/src/main/java/org/openremote/manager/gateway/GatewayClientService.java
+++ b/manager/src/main/java/org/openremote/manager/gateway/GatewayClientService.java
@@ -422,8 +422,8 @@ public class GatewayClientService extends RouteBuilder implements ContainerServi
LOG.info("Connection status change for gateway IO client '" + connectionStatus + "': " + connection);
clientEventService.publishEvent(new GatewayConnectionStatusEvent(timerService.getCurrentTimeMillis(), connection.getLocalRealm(), connectionStatus));
if (gatewayTunnelFactory != null) {
- LOG.finer("Terminating all gateway tunnel sessions");
- gatewayTunnelFactory.stopAll();
+ LOG.info("Terminating all gateway tunnel sessions for realm: " + connection.getLocalRealm());
+ gatewayTunnelFactory.stopAllInRealm(connection.getLocalRealm());
}
}
diff --git a/manager/src/main/java/org/openremote/manager/gateway/GatewayTunnelFactory.java b/manager/src/main/java/org/openremote/manager/gateway/GatewayTunnelFactory.java
index 54a4b1ce6..64f9d0afc 100644
--- a/manager/src/main/java/org/openremote/manager/gateway/GatewayTunnelFactory.java
+++ b/manager/src/main/java/org/openremote/manager/gateway/GatewayTunnelFactory.java
@@ -39,6 +39,13 @@ public interface GatewayTunnelFactory {
void stopTunnel(GatewayTunnelInfo tunnelInfo) throws Exception;
+ /**
+ * Terminate all tunnel sessions for the given realm; should perform try/catch to prevent any exceptions bubbling
+ * and to ensure termination of each session is attempted.
+ * @param realm the realm for which to terminate all tunnel sessions
+ */
+ void stopAllInRealm(String realm);
+
/**
* Terminate all known tunnel sessions; should perform try/catch to prevent any exceptions bubbling and to ensure
* termination of each session is attempted.
diff --git a/manager/src/main/java/org/openremote/manager/gateway/JSchGatewayTunnelFactory.java b/manager/src/main/java/org/openremote/manager/gateway/JSchGatewayTunnelFactory.java
index d1c79d9a3..8a8ec7493 100644
--- a/manager/src/main/java/org/openremote/manager/gateway/JSchGatewayTunnelFactory.java
+++ b/manager/src/main/java/org/openremote/manager/gateway/JSchGatewayTunnelFactory.java
@@ -78,6 +78,20 @@ public class JSchGatewayTunnelFactory implements GatewayTunnelFactory {
}
}
+ @Override
+ public void stopAllInRealm(String realm) {
+ sessionMap.entrySet().removeIf(entry -> {
+ boolean matches = entry.getKey().getRealm().equalsIgnoreCase(realm);
+ if (matches) {
+ try {
+ entry.getValue().disconnect();
+ } catch (Exception ignored) {
+ }
+ }
+ return matches;
+ });
+ }
+
public void stopAll() {
try {
sessionMap.values()
diff --git a/manager/src/main/resources/logging.properties b/manager/src/main/resources/logging.properties
index fd3a0e09d..90f352093 100644
--- a/manager/src/main/resources/logging.properties
+++ b/manager/src/main/resources/logging.properties
@@ -79,6 +79,7 @@ org.apache.camel.impl.converter.DefaultTypeConverter.level=WARNING
org.apache.camel.impl.DefaultShutdownStrategy.level=SEVERE
org.jeasy.rules.level=WARNING
org.apache.activemq.audit.level=WARNING
+io.netty.level=SEVERE
# Set this to FINEST to log outgoing HTTP traffic
#org.apache.http.level=WARNING