Class GatewayService

java.lang.Object
org.apache.camel.builder.BuilderSupport
org.apache.camel.builder.RouteBuilder
org.openremote.manager.gateway.GatewayService
All Implemented Interfaces:
org.apache.camel.builder.ModelRoutesBuilder, org.apache.camel.CamelContextAware, org.apache.camel.Ordered, org.apache.camel.RoutesBuilder, org.apache.camel.spi.HasCamelContext, org.apache.camel.spi.ResourceAware, org.openremote.model.ContainerService

public class GatewayService extends org.apache.camel.builder.RouteBuilder implements org.openremote.model.ContainerService
Manages GatewayAssets in the local instance by creating Keycloak clients for them and handles the connection logic of gateways; it is the gateways responsibility to connect to this instance, it is then up to this instance to authenticate the gateway and to initiate synchronisation of gateway assets.

Also adds an AttributeEventInterceptor to consume any AttributeEvent destined for a GatewayAsset descendant Asset and routes them to the underlying gateway for handling; the underlying gateway then notifies us if/when the action has succeeded.

  • Field Details

    • PRIORITY

      public static final int PRIORITY
      See Also:
    • GATEWAY_CLIENT_ID_PREFIX

      public static final String GATEWAY_CLIENT_ID_PREFIX
      See Also:
    • OR_GATEWAY_TUNNEL_SSH_KEY_FILE

      public static final String OR_GATEWAY_TUNNEL_SSH_KEY_FILE
      See Also:
    • OR_GATEWAY_TUNNEL_SSH_HOSTNAME

      public static final String OR_GATEWAY_TUNNEL_SSH_HOSTNAME
      See Also:
    • OR_GATEWAY_TUNNEL_SSH_PORT

      public static final String OR_GATEWAY_TUNNEL_SSH_PORT
      See Also:
    • OR_GATEWAY_TUNNEL_TCP_START

      public static final String OR_GATEWAY_TUNNEL_TCP_START
      See Also:
    • OR_GATEWAY_TUNNEL_HOSTNAME

      public static final String OR_GATEWAY_TUNNEL_HOSTNAME
      See Also:
    • OR_GATEWAY_TUNNEL_AUTO_CLOSE_MINUTES

      public static final String OR_GATEWAY_TUNNEL_AUTO_CLOSE_MINUTES
      See Also:
    • OR_GATEWAY_TUNNEL_TCP_START_DEFAULT

      public static final int OR_GATEWAY_TUNNEL_TCP_START_DEFAULT
      See Also:
    • assetStorageService

      protected AssetStorageService assetStorageService
    • assetProcessingService

      protected AssetProcessingService assetProcessingService
    • identityService

      protected ManagerIdentityService identityService
    • identityProvider

      protected ManagerKeycloakIdentityProvider identityProvider
    • clientEventService

      protected ClientEventService clientEventService
    • rulesetStorageService

      protected RulesetStorageService rulesetStorageService
    • rulesService

      protected RulesService rulesService
    • executorService

      protected ExecutorService executorService
    • scheduledExecutorService

      protected ScheduledExecutorService scheduledExecutorService
    • timerService

      protected org.openremote.container.timer.TimerService timerService
    • tunnelSSHHostname

      protected String tunnelSSHHostname
    • tunnelHostname

      protected String tunnelHostname
    • tunnelSSHPort

      protected int tunnelSSHPort
    • tunnelTCPStart

      protected int tunnelTCPStart
    • tunnelAutoCloseMinutes

      protected int tunnelAutoCloseMinutes
    • gatewayConnectorMap

      protected final Map<String,GatewayConnector> gatewayConnectorMap
      Maps gateway asset IDs to connections; note that gateway asset IDs are stored lower case so that they can be matched up to the service user client ID (which needs to be all lower case); this could technically cause an ID collision but for now the odds of that are low enough to not be a concern.
    • assetIdGatewayIdMap

      protected final Map<String,String> assetIdGatewayIdMap
    • active

      protected boolean active
    • realmIds

      protected List<String> realmIds
    • tunnelInfos

      protected Map<String,org.openremote.model.gateway.GatewayTunnelInfo> tunnelInfos
    • pendingTunnelCounter

      protected AtomicInteger pendingTunnelCounter
  • Constructor Details

    • GatewayService

      public GatewayService()
  • Method Details

    • isNotForGateway

      public static org.apache.camel.Predicate isNotForGateway(GatewayService gatewayService)
    • isGatewayClientId

      protected static boolean isGatewayClientId(String clientId)
    • getGatewayIdFromClientId

      public static String getGatewayIdFromClientId(String clientId)
    • getPriority

      public int getPriority()
      Specified by:
      getPriority in interface org.openremote.model.ContainerService
    • init

      public void init(org.openremote.model.Container container) throws Exception
      Specified by:
      init in interface org.openremote.model.ContainerService
      Throws:
      Exception
    • start

      public void start(org.openremote.model.Container container) throws Exception
      Specified by:
      start in interface org.openremote.model.ContainerService
      Throws:
      Exception
    • stop

      public void stop(org.openremote.model.Container container) throws Exception
      Specified by:
      stop in interface org.openremote.model.ContainerService
      Throws:
      Exception
    • configure

      public void configure() throws Exception
      Specified by:
      configure in class org.apache.camel.builder.RouteBuilder
      Throws:
      Exception
    • onGatewayMessageIntercept

      protected void onGatewayMessageIntercept(org.apache.camel.Exchange exchange)
      This method by-passes the standard client event authorization so all consumers within the GatewayConnector must handle authorization and/or ensure operations can only be conducted on gateway descendants.
    • onAttributeEventIntercepted

      public boolean onAttributeEventIntercepted(jakarta.persistence.EntityManager em, org.openremote.model.attribute.AttributeEvent event) throws AssetProcessingException
      Throws:
      AssetProcessingException
    • deleteGateway

      public boolean deleteGateway(String gatewayId)
    • getTunnelInfos

      public Collection<org.openremote.model.gateway.GatewayTunnelInfo> getTunnelInfos()
    • tunnellingSupported

      protected boolean tunnellingSupported()
    • startTunnel

      public org.openremote.model.gateway.GatewayTunnelInfo startTunnel(org.openremote.model.gateway.GatewayTunnelInfo tunnelInfo) throws IllegalArgumentException, IllegalStateException
      Throws:
      IllegalArgumentException
      IllegalStateException
    • stopTunnel

      public void stopTunnel(org.openremote.model.gateway.GatewayTunnelInfo tunnelInfo) throws IllegalArgumentException, IllegalStateException
      Throws:
      IllegalArgumentException
      IllegalStateException
    • isLocallyRegisteredGateway

      public boolean isLocallyRegisteredGateway(String assetId)
      Check if asset ID is a gateway asset registered locally on this manager
    • getLocallyRegisteredGatewayId

      public String getLocallyRegisteredGatewayId(String assetId, String parentId)
      Check if the specified asset ID or parent ID is a known gateway or descendant of a gateway.
    • processGatewayConnected

      protected void processGatewayConnected(String gatewayClientId, String sessionId)
    • processGatewayDisconnected

      protected void processGatewayDisconnected(String gatewayClientId, String sessionId)
    • processGatewayMessage

      protected void processGatewayMessage(String gatewayId, String sessionId, org.openremote.model.event.shared.SharedEvent event)
    • processGatewayChange

      protected void processGatewayChange(org.openremote.model.asset.impl.GatewayAsset gateway, org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> persistenceEvent)
    • processGatewayChildAssetChange

      protected void processGatewayChildAssetChange(String gatewayId, org.openremote.model.asset.Asset<?> childAsset, org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> persistenceEvent)
    • isGatewayConnected

      protected boolean isGatewayConnected(String gatewayId)
    • getGatewayClientId

      public static String getGatewayClientId(String gatewayAssetId)
    • createUpdateGatewayServiceUser

      protected void createUpdateGatewayServiceUser(org.openremote.model.asset.impl.GatewayAsset gateway)
    • removeGatewayServiceUser

      protected void removeGatewayServiceUser(org.openremote.model.asset.impl.GatewayAsset gateway)
    • createConnectorMessageConsumer

      protected Consumer<Object> createConnectorMessageConsumer(String sessionId)
    • getTunnelTCPStart

      public int getTunnelTCPStart()
    • autoCloseTunnel

      protected void autoCloseTunnel(String tunnelId)
    • toString

      public String toString()
      Overrides:
      toString in class org.apache.camel.builder.RouteBuilder