Package org.openremote.manager.gateway
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 Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected AssetProcessingServiceprotected AssetStorageServiceprotected ClientEventServiceprotected ExecutorServicestatic final Stringprotected final Map<String, GatewayConnector> 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.protected ManagerKeycloakIdentityProviderprotected ManagerIdentityServicestatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intprotected AtomicIntegerstatic final intprotected RulesetStorageServiceprotected RulesServiceprotected ScheduledExecutorServiceprotected org.openremote.container.timer.TimerServiceprotected intprotected Stringprotected Stringprotected intprotected intFields inherited from class org.apache.camel.builder.RouteBuilder
logFields inherited from interface org.openremote.model.ContainerService
DEFAULT_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY, MED_PRIORITYFields inherited from interface org.apache.camel.Ordered
HIGHEST, LOWEST -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidautoCloseTunnel(String tunnelId) voidcreateConnectorMessageConsumer(String sessionId) protected voidcreateUpdateGatewayServiceUser(org.openremote.model.asset.impl.GatewayAsset gateway) booleandeleteGateway(String gatewayId) static StringgetGatewayClientId(String gatewayAssetId) static StringgetGatewayIdFromClientId(String clientId) getLocallyRegisteredGatewayId(String assetId, String parentId) Check if the specified asset ID or parent ID is a known gateway or descendant of a gateway.intCollection<org.openremote.model.gateway.GatewayTunnelInfo> intvoidinit(org.openremote.model.Container container) protected static booleanisGatewayClientId(String clientId) protected booleanisGatewayConnected(String gatewayId) booleanisLocallyRegisteredGateway(String assetId) Check if asset ID is a gateway asset registered locally on this managerstatic org.apache.camel.PredicateisNotForGateway(GatewayService gatewayService) booleanonAttributeEventIntercepted(jakarta.persistence.EntityManager em, org.openremote.model.attribute.AttributeEvent event) protected voidonGatewayMessageIntercept(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.protected voidprocessGatewayChange(org.openremote.model.asset.impl.GatewayAsset gateway, org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> persistenceEvent) protected voidprocessGatewayChildAssetChange(String gatewayId, org.openremote.model.asset.Asset<?> childAsset, org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> persistenceEvent) protected voidprocessGatewayConnected(String gatewayClientId, String sessionId) protected voidprocessGatewayDisconnected(String gatewayClientId, String sessionId) protected voidprocessGatewayMessage(String gatewayId, String sessionId, org.openremote.model.event.shared.SharedEvent event) protected voidremoveGatewayServiceUser(org.openremote.model.asset.impl.GatewayAsset gateway) voidstart(org.openremote.model.Container container) org.openremote.model.gateway.GatewayTunnelInfostartTunnel(org.openremote.model.gateway.GatewayTunnelInfo tunnelInfo) voidstop(org.openremote.model.Container container) voidstopTunnel(org.openremote.model.gateway.GatewayTunnelInfo tunnelInfo) toString()protected booleanMethods inherited from class org.apache.camel.builder.RouteBuilder
addLifecycleInterceptor, addRoutes, addRoutesToCamelContext, addTemplatedRoutesToCamelContext, bindToRegistry, bindToRegistry, checkInitialized, configuration, configureRest, configureRests, configureRoute, configureRouteConfiguration, configureRoutes, configureRouteTemplate, configureTemplatedRoute, customize, customize, dataFormat, errorHandler, errorHandler, expression, from, from, from, fromF, fromV, fromV, getBeans, getOrder, getResource, getRestCollection, getRestConfiguration, getRests, getRouteCollection, getRoutes, getRouteTemplateCollection, getTemplatedRouteCollection, initializeCamelContext, intercept, interceptFrom, interceptFrom, interceptSendToEndpoint, loadRoutesBuilder, loadRoutesBuilder, onCompletion, onException, onException, populateBeans, populateOrUpdateRoutes, populateRests, populateRoutes, populateRouteTemplates, populateTemplatedRoutes, populateTransformers, populateValidators, prepareModel, property, propertyInject, removeLifecycleInterceptor, rest, rest, restConfiguration, routeTemplate, setErrorHandlerFactory, setResource, setRestCollection, setRouteTemplateCollection, setTemplatedRouteCollection, templatedRoute, tokenizer, transformer, updateRoutesToCamelContext, validatorMethods inherited from class org.apache.camel.builder.BuilderSupport
body, bodyAs, constant, constant, constant, createErrorHandlerBuilder, csimple, csimple, datasonnet, datasonnet, datasonnet, deadLetterChannel, deadLetterChannel, defaultErrorHandler, endpoint, endpoint, exceptionMessage, exchangeProperty, expression, getCamelContext, getContext, getErrorHandlerFactory, hasErrorHandlerFactory, header, java, java, joor, joor, jq, jq, jsonpath, jsonpath, jtaTransactionErrorHandler, jtaTransactionErrorHandler, jtaTransactionErrorHandler, method, method, method, method, noErrorHandler, regexReplaceAll, regexReplaceAll, setCamelContext, simple, simple, simpleF, simpleF, springTransactionErrorHandler, springTransactionErrorHandler, springTransactionErrorHandler, systemProperty, systemProperty, variable, xpath, xpath, xpath, xpath
-
Field Details
-
PRIORITY
public static final int PRIORITY- See Also:
-
GATEWAY_CLIENT_ID_PREFIX
- See Also:
-
OR_GATEWAY_TUNNEL_SSH_KEY_FILE
- See Also:
-
OR_GATEWAY_TUNNEL_SSH_HOSTNAME
- See Also:
-
OR_GATEWAY_TUNNEL_SSH_PORT
- See Also:
-
OR_GATEWAY_TUNNEL_TCP_START
- See Also:
-
OR_GATEWAY_TUNNEL_HOSTNAME
- See Also:
-
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
-
assetProcessingService
-
identityService
-
identityProvider
-
clientEventService
-
rulesetStorageService
-
rulesService
-
executorService
-
scheduledExecutorService
-
timerService
protected org.openremote.container.timer.TimerService timerService -
tunnelSSHHostname
-
tunnelHostname
-
tunnelSSHPort
protected int tunnelSSHPort -
tunnelTCPStart
protected int tunnelTCPStart -
tunnelAutoCloseMinutes
protected int tunnelAutoCloseMinutes -
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
-
active
protected boolean active -
realmIds
-
tunnelInfos
-
pendingTunnelCounter
-
-
Constructor Details
-
GatewayService
public GatewayService()
-
-
Method Details
-
isNotForGateway
-
isGatewayClientId
-
getGatewayIdFromClientId
-
getPriority
public int getPriority()- Specified by:
getPriorityin interfaceorg.openremote.model.ContainerService
-
init
- Specified by:
initin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
start
- Specified by:
startin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
stop
- Specified by:
stopin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
configure
- Specified by:
configurein classorg.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
-
getTunnelInfos
-
tunnellingSupported
protected boolean tunnellingSupported() -
startTunnel
public org.openremote.model.gateway.GatewayTunnelInfo startTunnel(org.openremote.model.gateway.GatewayTunnelInfo tunnelInfo) throws IllegalArgumentException, IllegalStateException -
stopTunnel
public void stopTunnel(org.openremote.model.gateway.GatewayTunnelInfo tunnelInfo) throws IllegalArgumentException, IllegalStateException -
isLocallyRegisteredGateway
Check if asset ID is a gateway asset registered locally on this manager -
getLocallyRegisteredGatewayId
Check if the specified asset ID or parent ID is a known gateway or descendant of a gateway. -
processGatewayConnected
-
processGatewayDisconnected
-
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
-
getGatewayClientId
-
createUpdateGatewayServiceUser
protected void createUpdateGatewayServiceUser(org.openremote.model.asset.impl.GatewayAsset gateway) -
removeGatewayServiceUser
protected void removeGatewayServiceUser(org.openremote.model.asset.impl.GatewayAsset gateway) -
createConnectorMessageConsumer
-
getTunnelTCPStart
public int getTunnelTCPStart() -
autoCloseTunnel
-
toString
- Overrides:
toStringin classorg.apache.camel.builder.RouteBuilder
-