Skip to content

armgit / core

Public Imported from GitHub
0

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

Added support for gateway tunnelling to use different hostname (#1360)

Rich Turnerc197de6d10f9
diff --git a/manager/src/main/java/org/openremote/manager/dashboard/DashboardStorageService.java b/manager/src/main/java/org/openremote/manager/dashboard/DashboardStorageService.java
index d6c7bb3f1..1ca5d7b86 100644
--- a/manager/src/main/java/org/openremote/manager/dashboard/DashboardStorageService.java
+++ b/manager/src/main/java/org/openremote/manager/dashboard/DashboardStorageService.java
@@ -88,6 +88,7 @@ public class DashboardStorageService extends RouteBuilder implements ContainerSe
* @param dashboardQuery see {@link DashboardQuery} for specification
* @return List of dashboards present in the database
*/
+ @SuppressWarnings({"unchecked", "SqlSourceToSinkFlow"})
protected Dashboard[] query(DashboardQuery dashboardQuery, String userId) {
return (Dashboard[]) persistenceService.doReturningTransaction((em) -> {
diff --git a/manager/src/main/java/org/openremote/manager/gateway/GatewayService.java b/manager/src/main/java/org/openremote/manager/gateway/GatewayService.java
index 07e247f3f..e01ac5479 100644
--- a/manager/src/main/java/org/openremote/manager/gateway/GatewayService.java
+++ b/manager/src/main/java/org/openremote/manager/gateway/GatewayService.java
@@ -93,6 +93,7 @@ public class GatewayService extends RouteBuilder implements ContainerService {
public static final String OR_GATEWAY_TUNNEL_SSH_HOSTNAME = "OR_GATEWAY_TUNNEL_SSH_HOSTNAME";
public static final String OR_GATEWAY_TUNNEL_SSH_PORT = "OR_GATEWAY_TUNNEL_SSH_PORT";
public static final String OR_GATEWAY_TUNNEL_TCP_START = "OR_GATEWAY_TUNNEL_TCP_START";
+ public static final String OR_GATEWAY_TUNNEL_HOSTNAME = "OR_GATEWAY_TUNNEL_HOSTNAME";
public static final int OR_GATEWAY_TUNNEL_TCP_START_DEFAULT = 9000;
protected AssetStorageService assetStorageService;
protected AssetProcessingService assetProcessingService;
@@ -104,6 +105,7 @@ public class GatewayService extends RouteBuilder implements ContainerService {
protected ScheduledExecutorService executorService;
protected TimerService timerService;
protected String tunnelSSHHostname;
+ protected String tunnelHostname;
protected int tunnelSSHPort;
protected int tunnelTCPStart;
@@ -227,6 +229,7 @@ public class GatewayService extends RouteBuilder implements ContainerService {
tunnelSSHHostname = getString(container.getConfig(), OR_GATEWAY_TUNNEL_SSH_HOSTNAME, null);
tunnelSSHPort = getInteger(container.getConfig(), OR_GATEWAY_TUNNEL_SSH_PORT, 0);
tunnelTCPStart = getInteger(container.getConfig(), OR_GATEWAY_TUNNEL_TCP_START, OR_GATEWAY_TUNNEL_TCP_START_DEFAULT);
+ tunnelHostname = getString(container.getConfig(), OR_GATEWAY_TUNNEL_HOSTNAME, null);
}
@Override
@@ -560,6 +563,9 @@ public class GatewayService extends RouteBuilder implements ContainerService {
int assignedPort = tunnelTCPStart + Math.toIntExact(pendingTunnelCounter.get() + tunnelInfos.values().stream().filter(ti -> ti.getType() == GatewayTunnelInfo.Type.TCP).count());
tunnelInfo.setAssignedPort(assignedPort);
}
+ if (!TextUtil.isNullOrEmpty(tunnelHostname)) {
+ tunnelInfo.setHostname(tunnelHostname);
+ }
CompletableFuture<Void> startFuture = connector.startTunnel(tunnelInfo);
try {
pendingTunnelCounter.incrementAndGet();
diff --git a/model/src/main/java/org/openremote/model/gateway/GatewayTunnelInfo.java b/model/src/main/java/org/openremote/model/gateway/GatewayTunnelInfo.java
index a949bbbb0..a5b1c2746 100644
--- a/model/src/main/java/org/openremote/model/gateway/GatewayTunnelInfo.java
+++ b/model/src/main/java/org/openremote/model/gateway/GatewayTunnelInfo.java
@@ -20,6 +20,7 @@ public class GatewayTunnelInfo {
protected int targetPort = 443;
protected String target = "localhost";
protected Integer assignedPort = null;
+ protected String hostname;
protected Type type = Type.HTTPS;
@JsonCreator
@@ -90,6 +91,15 @@ public class GatewayTunnelInfo {
return this;
}
+ public String getHostname() {
+ return hostname;
+ }
+
+ public GatewayTunnelInfo setHostname(String hostname) {
+ this.hostname = hostname;
+ return this;
+ }
+
@JsonProperty
public String getId() {
String seed = gatewayId + target + targetPort;
diff --git a/profile/deploy.yml b/profile/deploy.yml
index f06a98b73..e783777ce 100644
--- a/profile/deploy.yml
+++ b/profile/deploy.yml
@@ -188,6 +188,8 @@ services:
# Configure the central instance for Gateway SSH tunnelling (if these are set then gateway tunnelling support is enabled on the central instance)
OR_GATEWAY_TUNNEL_SSH_HOSTNAME:
OR_GATEWAY_TUNNEL_SSH_PORT:
+ # Use a different hostname to the central manager instance
+ OR_GATEWAY_TUNNEL_HOSTNAME:
OR_GATEWAY_TUNNEL_TCP_START: # First TCP port that can be allocated for raw TCP connections (should be start of an assigned contiguous block e.g. 9000-10000 = 9000)
# Configure the edge instance for Gateway SSH tunnelling (if SSH_KEY_FILE is set ten gateway tunnelling support is enabled on te edge instance)
OR_GATEWAY_TUNNEL_SSH_KEY_FILE: # SSH key file in RSA (not openSSH) format (use ssh-keygen -p -f ~/.ssh/id_rsa -m pem) to convert from openSSH
diff --git a/ui/app/manager/src/pages/page-gateway-tunnel.ts b/ui/app/manager/src/pages/page-gateway-tunnel.ts
index 9fbf01d7c..013ef63a6 100644
--- a/ui/app/manager/src/pages/page-gateway-tunnel.ts
+++ b/ui/app/manager/src/pages/page-gateway-tunnel.ts
@@ -377,9 +377,9 @@ export class PageGatewayTunnel extends Page<AppStateKeyed> {
switch (info.type) {
case GatewayTunnelInfoType.HTTPS:
case GatewayTunnelInfoType.HTTP:
- return "//" + info.id + "." + window.location.host;
+ return "//" + info.id + "." + (info.hostname ? info.hostname : window.location.hostname);
case GatewayTunnelInfoType.TCP:
- return window.location.hostname + ":" + info.assignedPort;
+ return (info.hostname ? info.hostname : window.location.hostname) + ":" + info.assignedPort;
}
}