Skip to content

armgit / core

Public Imported from GitHub
0

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

Load testing (#858)

Rich Turner2f849c44a748
diff --git a/.ci_cd/aws/cloudformation-create-ec2.yml b/.ci_cd/aws/cloudformation-create-ec2.yml
index d28a75626..ca0461f2b 100644
--- a/.ci_cd/aws/cloudformation-create-ec2.yml
+++ b/.ci_cd/aws/cloudformation-create-ec2.yml
@@ -748,39 +748,3 @@ Resources:
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
-
- HealthCheckAlarm:
- Type: AWS::CloudWatch::Alarm
- Condition: CreateHealthChecks
- Properties:
- Namespace: AWS/Route53
- MetricName: HealthCheckStatus
- Statistic: Sum
- Period: 60
- EvaluationPeriods: 15
- ComparisonOperator: LessThanThreshold
- Threshold: 1
- AlarmActions:
- - !Ref SnsTopic
- OKActions:
- - !Ref SnsTopic
- Dimensions:
- - Name: HealthCheckId
- Value: !Ref HealthCheck
-
- HealthCheck:
- Type: AWS::Route53::HealthCheck
- Condition: CreateHealthChecks
- DependsOn: EC2Instance
- Properties:
- HealthCheckConfig:
- Port: 443
- Type: HTTPS
- ResourcePath: '/api/master/info'
- FullyQualifiedDomainName: !Sub ${Host}
- RequestInterval: 30
- FailureThreshold: 10
- HealthCheckTags:
- - Key: Name
- Value: !Sub ${Host}
-
diff --git a/.ci_cd/aws/cloudformation-healthcheck-alarm.yml b/.ci_cd/aws/cloudformation-healthcheck-alarm.yml
new file mode 100644
index 000000000..6edc5cc9d
--- /dev/null
+++ b/.ci_cd/aws/cloudformation-healthcheck-alarm.yml
@@ -0,0 +1,56 @@
+# ---------------------------------------------------------------------------------------------------------------------
+# Creates an alarm for Route53 health check - must be run in the us-east-1 region
+# ---------------------------------------------------------------------------------------------------------------------
+AWSTemplateFormatVersion: '2010-09-09'
+Description: 'Route 53 Healthcheck alarm'
+
+Parameters:
+ Host:
+ Description: FQDN for host
+ Type: String
+
+Resources:
+
+ HealthCheck:
+ Type: AWS::Route53::HealthCheck
+ Properties:
+ HealthCheckConfig:
+ Port: 443
+ Type: HTTPS
+ ResourcePath: '/api/master/info'
+ FullyQualifiedDomainName: !Sub ${Host}
+ RequestInterval: 30
+ FailureThreshold: 10
+ HealthCheckTags:
+ - Key: Name
+ Value: !Sub ${Host}
+
+ EmailSubscription:
+ Type: AWS::SNS::Subscription
+ Properties:
+ Endpoint: [email protected]
+ Protocol: email
+ TopicArn: !Ref SnsTopic
+
+ SnsTopic:
+ Type: AWS::SNS::Topic
+ Properties:
+ DisplayName: !Ref Host
+
+ HealthCheckAlarm:
+ Type: AWS::CloudWatch::Alarm
+ Properties:
+ Namespace: AWS/Route53
+ MetricName: HealthCheckStatus
+ Statistic: Sum
+ Period: 60
+ EvaluationPeriods: 15
+ ComparisonOperator: LessThanThreshold
+ Threshold: 1
+ AlarmActions:
+ - !Ref SnsTopic
+ OKActions:
+ - !Ref SnsTopic
+ Dimensions:
+ - Name: HealthCheckId
+ Value: !Ref HealthCheck
diff --git a/.ci_cd/aws/provision_host.sh b/.ci_cd/aws/provision_host.sh
index 78f4b1d93..bcc46743c 100644
--- a/.ci_cd/aws/provision_host.sh
+++ b/.ci_cd/aws/provision_host.sh
@@ -2,9 +2,15 @@
# Provisions the standard stack of resources using CloudFormation template (cloudformation-create-ec2.yml) in the
# specified AWS member account; if no account specified then the account of the authenticated user will be used.
-# The account must already exist and be provisioned in the standard way (see provision_account.sh). To access the
-# account the $AWS_ROLE_NAME role in that account will be assumed (this role must exist and must have sufficient
-# privileges to run the commands contained in this script). This script will determine the DNS hosted
+# The account must already exist and be provisioned in the standard way (see provision_account.sh).
+# Also provisions an SMTP user in the caller account using CloudFormation template (cloudformation-create-smtp-user.yml)
+# so this user can be used to send emails from the newly provisioned host (credentials are injected into the host
+# environment variables).
+# Also provisions a Route 53 Healthcheck alarm using CloudFormation template (cloudformation-healthcheck-alarm.yml) in
+# the same AWS member account but in the us-east-1 region (this is the region where Route 53 health checks are
+# automatically created).
+# To access the account the $AWS_ROLE_NAME role in that account will be assumed (this role must exist and must have
+# sufficient privileges to run the commands contained in this script). This script will determine the DNS hosted
# zone into which the A record for the host should be inserted by searching up the domain levels of the hosts FQDN.
# Will also provision an S3 bucket with the name of host (periods replaced with hyphens) unless set to false.
#
@@ -59,6 +65,7 @@ fi
STACK_NAME=$(tr '.' '-' <<< "$HOST")
SMTP_STACK_NAME="$STACK_NAME-smtp"
+HEALTH_STACK_NAME="$STACK_NAME-healthcheck"
# Provision SMTP user using cloud formation (if stack doesn't already exist)
echo "Provisioning SMTP user"
@@ -271,3 +278,54 @@ if [ "$PROVISION_S3_BUCKET" != 'false' ]; then
fi
fi
fi
+
+# Provision Route 53 healthcheck alarm cloud formation (if stack doesn't already exist) - must be in the us-east-1 region
+echo "Provisioning Healthcheck Alarm"
+STATUS=$(aws cloudformation describe-stacks --stack-name $HEALTH_STACK_NAME --query "Stacks[0].StackStatus" --output text $ACCOUNT_PROFILE --region us-east-1 2>/dev/null)
+
+if [ -n "$STATUS" ] && [ "$STATUS" != 'DELETE_COMPLETE' ]; then
+ echo "Stack already exists for this host's Healthcheck '$HEALTH_STACK_NAME' current status is '$STATUS'"
+ STACK_ID=$(aws cloudformation describe-stacks --stack-name $HEALTH_STACK_NAME --query "Stacks[0].StackId" --output text $ACCOUNT_PROFILE --region us-east-1 2>/dev/null)
+else
+
+ if [ -f "${awsDir}cloudformation-healthcheck-alarm.yml" ]; then
+ HEALTH_TEMPLATE_PATH="${awsDir}cloudformation-healthcheck-alarm.yml"
+ elif [ -f ".ci_cd/aws/cloudformation-healthcheck-alarm.yml" ]; then
+ HEALTH_TEMPLATE_PATH=".ci_cd/aws/cloudformation-healthcheck-alarm.yml"
+ elif [ -f "openremote/.ci_cd/aws/cloudformation-healthcheck-alarm.yml" ]; then
+ HEALTH_TEMPLATE_PATH="openremote/.ci_cd/aws/cloudformation-healthcheck-alarm.yml"
+ else
+ echo "Cannot determine location of cloudformation-healthcheck-alarm.yml"
+ exit 1
+ fi
+
+ #Configure parameters
+ PARAMS="ParameterKey=Host,ParameterValue='$HOST'"
+
+ # Create standard stack resources in specified account in us-east-1 region
+ STACK_ID=$(aws cloudformation create-stack --stack-name $HEALTH_STACK_NAME --template-body file://$HEALTH_TEMPLATE_PATH --parameters $PARAMS --output text $ACCOUNT_PROFILE --region us-east-1)
+
+ if [ $? -ne 0 ]; then
+ echo "Create stack failed"
+ exit 1
+ fi
+
+ if [ "$WAIT_FOR_STACK" != 'false' ]; then
+ # Wait for cloud formation stack status to be CREATE_*
+ echo "Waiting for stack to be created"
+ STATUS=$(aws cloudformation describe-stacks --stack-name $HEALTH_STACK_NAME --query "Stacks[?StackId=='$STACK_ID'].StackStatus" --output text $ACCOUNT_PROFILE --region us-east-1 2>/dev/null)
+
+ while [[ "$STATUS" == 'CREATE_IN_PROGRESS' ]]; do
+ echo "Stack creation is still in progress .. Sleeping 30 seconds"
+ sleep 30
+ STATUS=$(aws cloudformation describe-stacks --stack-name $HEALTH_STACK_NAME --query "Stacks[?StackId=='$STACK_ID'].StackStatus" --output text $ACCOUNT_PROFILE --region us-east-1 2>/dev/null)
+ done
+
+ if [ "$STATUS" != 'CREATE_COMPLETE' ]; then
+ echo "Stack creation has failed status is '$STATUS'"
+ exit 1
+ else
+ echo "Stack creation is complete"
+ fi
+ fi
+fi
diff --git a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
index 9665b5254..a4d981c0b 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
@@ -21,8 +21,8 @@ package org.openremote.agent.protocol;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
import org.openremote.container.concurrent.GlobalLock;
-import org.openremote.container.message.MessageBrokerContext;
import org.openremote.container.message.MessageBrokerService;
import org.openremote.container.timer.TimerService;
import org.openremote.model.Container;
@@ -76,7 +76,7 @@ public abstract class AbstractProtocol<T extends Agent<T, ?, U>, U extends Agent
private static final Logger LOG = SyslogCategory.getLogger(PROTOCOL, AbstractProtocol.class);
protected final Map<AttributeRef, Attribute<?>> linkedAttributes = new HashMap<>();
protected final Set<AttributeRef> dynamicAttributes = new HashSet<>();
- protected MessageBrokerContext messageBrokerContext;
+ protected DefaultCamelContext messageBrokerContext;
protected ProducerTemplate producerTemplate;
protected TimerService timerService;
protected ScheduledExecutorService executorService;
diff --git a/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOClient.java b/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOClient.java
index 6127eb4b1..9a54cd8ac 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOClient.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/io/AbstractNettyIOClient.java
@@ -363,6 +363,7 @@ public abstract class AbstractNettyIOClient<T, U extends SocketAddress> implemen
workerGroup = null;
}
}
+ LOG.finer("Disconnect done: " + getClientUri());
}
@Override
@@ -469,14 +470,16 @@ public abstract class AbstractNettyIOClient<T, U extends SocketAddress> implemen
protected void onConnectionStatusChanged(ConnectionStatus connectionStatus) {
this.connectionStatus = connectionStatus;
-
+ if (connectionStatusConsumers.size() > 0) {
+ LOG.finest("Notifying connection status consumers: count=" + connectionStatusConsumers.size());
+ }
executorService.submit(() -> {
connectionStatusConsumers.forEach(
consumer -> {
try {
consumer.accept(connectionStatus);
} catch (Exception e) {
- LOG.log(Level.WARNING, "Connection status change handler threw an exception: " + getClientUri(), e);
+ LOG.log(Level.INFO, "Connection status change handler threw an exception: " + getClientUri(), e);
}
});
});
diff --git a/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java
index 57e21c259..abc7236dd 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java
@@ -125,14 +125,8 @@ public class SimulatorProtocol extends AbstractProtocol<SimulatorAgent, Simulato
* Call this to simulate a sensor update using the specified timestamp
*/
public void updateSensor(AttributeRef attributeRef, Object value, long timestamp) {
- Attribute<?> attribute = getLinkedAttributes().get(attributeRef);
AttributeState state = new AttributeState(attributeRef, value);
- if (attribute == null) {
- LOG.info("Attempt to update unlinked attribute: " + state);
- return;
- }
-
updateLinkedAttribute(state, timestamp);
}
diff --git a/agent/src/main/java/org/openremote/agent/protocol/simulator/storage/StorageSimulatorProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/simulator/storage/StorageSimulatorProtocol.java
index 6300fc17e..e1f524f94 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/simulator/storage/StorageSimulatorProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/simulator/storage/StorageSimulatorProtocol.java
@@ -93,13 +93,6 @@ public class StorageSimulatorProtocol extends AbstractProtocol<StorageSimulatorA
}
updateLinkedAttribute(new AttributeState(event.getAttributeRef(), processedValue));
-
- // Push write value into the asset and update
- String assetId = event.getAssetId();
- ((Attribute<Object>) attribute).setValue(processedValue);
- ElectricityStorageAsset asset = assetService.findAsset(assetId, ElectricityStorageAsset.class);
- asset.addOrReplaceAttributes(attribute);
- updateStorageAsset(asset);
}
protected void updateStorageAsset(ElectricityStorageAsset storageAsset) {
diff --git a/container/build.gradle b/container/build.gradle
index 9ef3948cf..b354a9e84 100644
--- a/container/build.gradle
+++ b/container/build.gradle
@@ -45,6 +45,7 @@ dependencies {
api "org.apache.camel:camel-core:$camelVersion"
api "org.apache.camel:camel-jackson:$camelVersion"
api "org.apache.camel:camel-snmp:$camelVersion"
+ api "org.apache.camel:camel-health:$camelVersion"
api("com.fasterxml.uuid:java-uuid-generator:$uuidGeneratorVersion") {
exclude group: "log4j"
diff --git a/container/src/main/java/org/openremote/container/message/MessageBrokerContext.java b/container/src/main/java/org/openremote/container/message/MessageBrokerContext.java
deleted file mode 100644
index 93fd62e40..000000000
--- a/container/src/main/java/org/openremote/container/message/MessageBrokerContext.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.container.message;
-
-import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.impl.PropertyPlaceholderDelegateRegistry;
-import org.apache.camel.impl.SimpleRegistry;
-import org.apache.camel.spi.Registry;
-
-@SuppressWarnings("unchecked")
-public class MessageBrokerContext extends DefaultCamelContext {
-
- @Override
- protected Registry createRegistry() {
- return new SimpleRegistry();
- }
-
- @Override
- public SimpleRegistry getRegistry() {
- return (SimpleRegistry) ((PropertyPlaceholderDelegateRegistry) super.getRegistry()).getRegistry();
- }
-}
diff --git a/container/src/main/java/org/openremote/container/message/MessageBrokerService.java b/container/src/main/java/org/openremote/container/message/MessageBrokerService.java
index 35f6176ca..dd0db8109 100644
--- a/container/src/main/java/org/openremote/container/message/MessageBrokerService.java
+++ b/container/src/main/java/org/openremote/container/message/MessageBrokerService.java
@@ -19,22 +19,35 @@
*/
package org.openremote.container.message;
-import org.apache.camel.Processor;
+import org.apache.camel.CamelContext;
+import org.apache.camel.FluentProducerTemplate;
import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.DefaultErrorHandlerBuilder;
import org.apache.camel.component.snmp.SnmpComponent;
-import org.apache.camel.impl.DefaultStreamCachingStrategy;
-import org.apache.camel.spi.*;
+import org.apache.camel.health.HealthCheckRegistry;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.engine.DefaultHealthCheckResolver;
+import org.apache.camel.impl.engine.DefaultStreamCachingStrategy;
+import org.apache.camel.impl.health.ConsumersHealthCheckRepository;
+import org.apache.camel.impl.health.ContextHealthCheck;
+import org.apache.camel.impl.health.DefaultHealthCheckRegistry;
+import org.apache.camel.impl.health.RoutesHealthCheckRepository;
+import org.apache.camel.spi.ExecutorServiceManager;
+import org.apache.camel.spi.StreamCachingStrategy;
+import org.apache.camel.spi.ThreadPoolFactory;
+import org.apache.camel.spi.ThreadPoolProfile;
+import org.apache.camel.support.DefaultRegistry;
+import org.apache.camel.support.SimpleRegistry;
import org.apache.camel.util.StringHelper;
import org.apache.camel.util.concurrent.CamelThreadFactory;
-import org.openremote.model.Container;
-import org.openremote.model.ContainerService;
import org.openremote.container.concurrent.ContainerExecutor;
import org.openremote.container.concurrent.ContainerScheduledExecutor;
-import org.openremote.container.security.IdentityService;
import org.openremote.container.web.DefaultWebsocketComponent;
-import org.openremote.container.web.WebService;
import org.openremote.container.web.socket.WebsocketComponent;
+import org.openremote.model.Container;
+import org.openremote.model.ContainerService;
+import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
@@ -50,7 +63,8 @@ public class MessageBrokerService implements ContainerService {
public static final int PRIORITY = ContainerService.HIGH_PRIORITY;
protected ProducerTemplate producerTemplate;
- protected MessageBrokerContext context;
+ protected FluentProducerTemplate fluentProducerTemplate;
+ protected DefaultCamelContext context;
@Override
public int getPriority() {
@@ -61,7 +75,7 @@ public class MessageBrokerService implements ContainerService {
@Override
public void init(Container container) throws Exception {
- context = new MessageBrokerContext();
+ context = new DefaultCamelContext();
final ExecutorServiceManager executorServiceManager = context.getExecutorServiceManager();
executorServiceManager.setThreadNamePattern("#counter# #name#");
@@ -113,6 +127,15 @@ public class MessageBrokerService implements ContainerService {
// Don't use JMS, we do our own correlation
context.setUseBreadcrumb(false);
+ // Enable health checks - Have to manually add built in ones for some reason
+ context.setLoadHealthChecks(true);
+ final var checkRegistry = new DefaultHealthCheckRegistry();
+ checkRegistry.setExposureLevel("full");
+ checkRegistry.register(new RoutesHealthCheckRepository());
+ checkRegistry.register(new ConsumersHealthCheckRepository());
+ checkRegistry.register(new ContextHealthCheck());
+ context.setExtension(HealthCheckRegistry.class, checkRegistry);
+
// Force a quick shutdown of routes with in-flight exchanges
context.getShutdownStrategy().setTimeout(1);
context.getShutdownStrategy().setSuppressLoggingOnTimeout(true);
@@ -122,15 +145,9 @@ public class MessageBrokerService implements ContainerService {
streamCachingStrategy.setSpoolThreshold(524288); // Half megabyte
context.setStreamCachingStrategy(streamCachingStrategy);
- context.setErrorHandlerBuilder(new org.apache.camel.builder.LoggingErrorHandlerBuilder() {
- @Override
- public Processor createErrorHandler(RouteContext routeContext, Processor processor) {
- // TODO: Custom error handler?
- return super.createErrorHandler(routeContext, processor);
- }
- });
+ context.setErrorHandlerFactory(new DefaultErrorHandlerBuilder());
- context.getRegistry().put(Container.class.getName(), container);
+ ((SimpleRegistry)((DefaultRegistry)context.getRegistry()).getFallbackRegistry()).put("OpenRemote", Map.of(Container.class, container));
String allowedOrigin = getString(container.getConfig(), MESSAGE_SESSION_ALLOWED_ORIGIN, MESSAGE_SESSION_ALLOWED_ORIGIN_DEFAULT);
WebsocketComponent websocketComponent = new DefaultWebsocketComponent(
@@ -145,6 +162,7 @@ public class MessageBrokerService implements ContainerService {
@Override
public void start(Container container) throws Exception {
producerTemplate = context.createProducerTemplate();
+ fluentProducerTemplate = context.createFluentProducerTemplate();
LOG.info("Starting Camel message broker");
context.start();
}
@@ -156,7 +174,7 @@ public class MessageBrokerService implements ContainerService {
}
}
- public MessageBrokerContext getContext() {
+ public DefaultCamelContext getContext() {
return context;
}
@@ -164,6 +182,10 @@ public class MessageBrokerService implements ContainerService {
return producerTemplate;
}
+ public FluentProducerTemplate getFluentProducerTemplate() {
+ return fluentProducerTemplate;
+ }
+
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
diff --git a/container/src/main/java/org/openremote/container/persistence/PersistenceHealthStatusProvider.java b/container/src/main/java/org/openremote/container/persistence/PersistenceHealthStatusProvider.java
index d2386dda1..14cad6545 100644
--- a/container/src/main/java/org/openremote/container/persistence/PersistenceHealthStatusProvider.java
+++ b/container/src/main/java/org/openremote/container/persistence/PersistenceHealthStatusProvider.java
@@ -40,7 +40,6 @@ public class PersistenceHealthStatusProvider implements HealthStatusProvider, Co
private static final Logger LOG = Logger.getLogger(PersistenceHealthStatusProvider.class.getName());
public static final String NAME = "db";
- public static final String VERSION = "1.0";
protected PersistenceService persistenceService;
@Override
@@ -68,11 +67,6 @@ public class PersistenceHealthStatusProvider implements HealthStatusProvider, Co
return NAME;
}
- @Override
- public String getHealthStatusVersion() {
- return VERSION;
- }
-
@Override
public Object getHealthStatus() {
if (persistenceService.persistenceUnitProperties == null) {
diff --git a/container/src/main/java/org/openremote/container/persistence/PersistenceService.java b/container/src/main/java/org/openremote/container/persistence/PersistenceService.java
index c4c35109e..e181597ca 100644
--- a/container/src/main/java/org/openremote/container/persistence/PersistenceService.java
+++ b/container/src/main/java/org/openremote/container/persistence/PersistenceService.java
@@ -20,6 +20,7 @@
package org.openremote.container.persistence;
import org.apache.camel.ExchangePattern;
+import org.apache.camel.FluentProducerTemplate;
import org.apache.camel.Predicate;
import org.apache.camel.ProducerTemplate;
import org.flywaydb.core.Flyway;
@@ -457,14 +458,12 @@ public class PersistenceService implements ContainerService, Consumer<Persistenc
// Fire persistence event although we don't use database for Realm CUD but call Keycloak API
PersistenceEvent<?> persistenceEvent = new PersistenceEvent<>(cause, entity, propertyNames, currentState, previousState);
- if (messageBrokerService.getProducerTemplate() != null) {
- messageBrokerService.getProducerTemplate().sendBodyAndHeader(
- PERSISTENCE_TOPIC,
- ExchangePattern.InOnly,
- persistenceEvent,
- HEADER_ENTITY_TYPE,
- persistenceEvent.getEntity().getClass()
- );
+ if (messageBrokerService.getFluentProducerTemplate() != null) {
+ messageBrokerService.getFluentProducerTemplate()
+ .withBody(persistenceEvent)
+ .withHeader(HEADER_ENTITY_TYPE, persistenceEvent.getEntity().getClass())
+ .to(PERSISTENCE_TOPIC)
+ .asyncSend();
}
}
@@ -526,16 +525,14 @@ public class PersistenceService implements ContainerService, Consumer<Persistenc
@Override
public void accept(PersistenceEvent<?> persistenceEvent) {
- ProducerTemplate producerTemplate = messageBrokerService.getProducerTemplate();
+ FluentProducerTemplate producerTemplate = messageBrokerService.getFluentProducerTemplate();
if (producerTemplate != null) {
- producerTemplate.sendBodyAndHeader(
- PersistenceService.PERSISTENCE_TOPIC,
- ExchangePattern.InOnly,
- persistenceEvent,
- PersistenceService.HEADER_ENTITY_TYPE,
- persistenceEvent.getEntity().getClass()
- );
+ producerTemplate
+ .withBody(persistenceEvent)
+ .withHeader(HEADER_ENTITY_TYPE, persistenceEvent.getEntity().getClass())
+ .to(PERSISTENCE_TOPIC)
+ .asyncSend();
}
}
diff --git a/container/src/main/java/org/openremote/container/web/socket/MemoryWebsocketSessions.java b/container/src/main/java/org/openremote/container/web/socket/MemoryWebsocketSessions.java
index 7b1dd89c2..f9cb48573 100644
--- a/container/src/main/java/org/openremote/container/web/socket/MemoryWebsocketSessions.java
+++ b/container/src/main/java/org/openremote/container/web/socket/MemoryWebsocketSessions.java
@@ -46,12 +46,12 @@ public class MemoryWebsocketSessions extends ConcurrentHashMap<String, Session>
}
@Override
- public void start() throws Exception {
+ public void start() {
// noop
}
@Override
- public void stop() throws Exception {
+ public void stop() {
clear();
}
}
diff --git a/container/src/main/java/org/openremote/container/web/socket/WebsocketComponent.java b/container/src/main/java/org/openremote/container/web/socket/WebsocketComponent.java
index 9970e7f46..595aae21d 100644
--- a/container/src/main/java/org/openremote/container/web/socket/WebsocketComponent.java
+++ b/container/src/main/java/org/openremote/container/web/socket/WebsocketComponent.java
@@ -20,8 +20,8 @@
package org.openremote.container.web.socket;
import org.apache.camel.Endpoint;
-import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.util.ServiceHelper;
+import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.service.ServiceHelper;
import java.util.HashMap;
import java.util.Map;
diff --git a/container/src/main/java/org/openremote/container/web/socket/WebsocketConsumer.java b/container/src/main/java/org/openremote/container/web/socket/WebsocketConsumer.java
index 3dd6d79d2..6d31d06cf 100644
--- a/container/src/main/java/org/openremote/container/web/socket/WebsocketConsumer.java
+++ b/container/src/main/java/org/openremote/container/web/socket/WebsocketConsumer.java
@@ -21,7 +21,7 @@ package org.openremote.container.web.socket;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
-import org.apache.camel.impl.DefaultConsumer;
+import org.apache.camel.support.DefaultConsumer;
import java.util.function.Consumer;
diff --git a/container/src/main/java/org/openremote/container/web/socket/WebsocketEndpoint.java b/container/src/main/java/org/openremote/container/web/socket/WebsocketEndpoint.java
index db3e6480a..221ff0dcc 100644
--- a/container/src/main/java/org/openremote/container/web/socket/WebsocketEndpoint.java
+++ b/container/src/main/java/org/openremote/container/web/socket/WebsocketEndpoint.java
@@ -22,7 +22,7 @@ package org.openremote.container.web.socket;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
-import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.support.DefaultEndpoint;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
@@ -37,7 +37,7 @@ public class WebsocketEndpoint extends DefaultEndpoint {
private WebsocketComponent component;
@UriPath
- @Metadata(required = "true")
+ @Metadata(required = true)
private String resourceUri;
@UriParam
diff --git a/container/src/main/java/org/openremote/container/web/socket/WebsocketProducer.java b/container/src/main/java/org/openremote/container/web/socket/WebsocketProducer.java
index 18c875f64..9f1a755ff 100644
--- a/container/src/main/java/org/openremote/container/web/socket/WebsocketProducer.java
+++ b/container/src/main/java/org/openremote/container/web/socket/WebsocketProducer.java
@@ -22,7 +22,7 @@ package org.openremote.container.web.socket;
import org.apache.camel.CamelExchangeException;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
-import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.support.DefaultProducer;
import org.openremote.container.web.ConnectionConstants;
import javax.websocket.Session;
diff --git a/gradle.properties b/gradle.properties
index 30d272b90..6b9191966 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -24,7 +24,7 @@ junitVersion = 4.13.2
spockVersion = 2.0-groovy-3.0
byteBuddyVersion = 1.11.0
objenesisVersion = 3.2
-camelVersion = 2.25.4
+camelVersion = 3.19.0
sunriseSunsetCalculatorVersion = 1.2
easyRulesVersion = 4.1.0
quartzVersion= 2.3.2
diff --git a/manager/Dockerfile b/manager/Dockerfile
index ff9288325..1dc4bd6e6 100644
--- a/manager/Dockerfile
+++ b/manager/Dockerfile
@@ -55,11 +55,10 @@ ENV OR_RULE_EVENT_EXPIRES ${OR_RULE_EVENT_EXPIRES:-PT1H}
ENV OR_IDENTITY_PROVIDER ${OR_IDENTITY_PROVIDER:-keycloak}
ENV OR_IDENTITY_SESSION_MAX_MINUTES ${OR_IDENTITY_SESSION_MAX_MINUTES:-1440}
ENV OR_IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES ${OR_IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES:-2628000}
-ENV OR_JAVA_OPTS ${OR_JAVA_OPTS:--Xms400m -Xmx400m \
- -XX:CompressedClassSpaceSize=25m -XX:MaxMetaspaceSize=150m \
- -XX:InitialCodeCacheSize=50m -XX:ReservedCodeCacheSize=50m \
- -XX:MaxDirectMemorySize=25m -XX:NativeMemoryTracking=summary \
- -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/javadump.core.hprof}
+ENV OR_JAVA_OPTS ${OR_JAVA_OPTS:--Xms500m -Xmx2g \
+ -XX:NativeMemoryTracking=summary \
+ -Xlog:all=warning:stdout:uptime,level,tags \
+ -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof}
RUN mkdir -p /deployment/manager/extensions
diff --git a/manager/build.gradle b/manager/build.gradle
index 7fcb69a6c..ba8848a61 100644
--- a/manager/build.gradle
+++ b/manager/build.gradle
@@ -35,6 +35,7 @@ dependencies {
implementation("org.apache.activemq:artemis-mqtt-protocol:$activeMQVersion") {
exclude group: "org.osgi"
+ exclude group: "org.jboss.logging"
}
// Needed for reference in tests
diff --git a/manager/src/main/java/org/openremote/manager/agent/AgentHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/agent/AgentHealthStatusProvider.java
index 2363dc6c3..ef0bb3a3a 100644
--- a/manager/src/main/java/org/openremote/manager/agent/AgentHealthStatusProvider.java
+++ b/manager/src/main/java/org/openremote/manager/agent/AgentHealthStatusProvider.java
@@ -32,7 +32,6 @@ import java.util.concurrent.atomic.AtomicInteger;
public class AgentHealthStatusProvider implements HealthStatusProvider, ContainerService {
public static final String NAME = "agents";
- public static final String VERSION = "1.0";
protected AgentService agentService;
@Override
@@ -60,11 +59,6 @@ public class AgentHealthStatusProvider implements HealthStatusProvider, Containe
return NAME;
}
- @Override
- public String getHealthStatusVersion() {
- return VERSION;
- }
-
@Override
public Object getHealthStatus() {
AtomicInteger connectedCount = new AtomicInteger(0);
diff --git a/manager/src/main/java/org/openremote/manager/agent/AgentService.java b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
index 24d71b619..0f4cc74de 100644
--- a/manager/src/main/java/org/openremote/manager/agent/AgentService.java
+++ b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
@@ -566,12 +566,11 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
.map(agentLink -> {
LOG.finer("Attribute write for agent linked attribute: agent=" + agentLink.getId() + ", asset=" + asset.getId() + ", attribute=" + attribute.getName());
- messageBrokerService.getProducerTemplate().sendBodyAndHeader(
- ACTUATOR_TOPIC,
- attributeEvent,
- Protocol.ACTUATOR_TOPIC_TARGET_PROTOCOL,
- getProtocolInstance(agentLink.getId())
- );
+ messageBrokerService.getFluentProducerTemplate()
+ .withBody(attributeEvent)
+ .withHeader(Protocol.ACTUATOR_TOPIC_TARGET_PROTOCOL, getProtocolInstance(agentLink.getId()))
+ .to(ACTUATOR_TOPIC)
+ .asyncSend();
return true; // Processing complete, skip other processors
}).orElse(false) // This is a regular attribute so allow the processing to continue
);
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
index ef3239ce3..5d3da840e 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
@@ -20,6 +20,7 @@
package org.openremote.manager.asset;
import org.apache.camel.Exchange;
+import org.apache.camel.FluentProducerTemplate;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.openremote.container.message.MessageBrokerService;
@@ -167,7 +168,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
}
// Make the exception available if MEP is InOut
- exchange.getOut().setBody(exception);
+ exchange.getMessage().setBody(exception);
};
}
@@ -439,7 +440,11 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
if (attributeEvent.getTimestamp() <= 0) {
attributeEvent.setTimestamp(timerService.getCurrentTimeMillis());
}
- messageBrokerService.getProducerTemplate().sendBodyAndHeader(ASSET_QUEUE, attributeEvent, HEADER_SOURCE, source);
+ messageBrokerService.getFluentProducerTemplate()
+ .withHeader(HEADER_SOURCE, source)
+ .withBody(attributeEvent)
+ .to(ASSET_QUEUE)
+ .asyncSend();
}
/**
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
index de82a89f8..22e9b4afe 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
@@ -596,8 +596,11 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
}
// Process synchronously
- Object result = messageBrokerService.getProducerTemplate().requestBodyAndHeader(
- AssetProcessingService.ASSET_QUEUE, event, AttributeEvent.HEADER_SOURCE, CLIENT);
+ Object result = messageBrokerService.getFluentProducerTemplate()
+ .withBody(event)
+ .withHeader(AttributeEvent.HEADER_SOURCE, CLIENT)
+ .to(AssetProcessingService.ASSET_QUEUE)
+ .request();
if (result instanceof AssetProcessingException) {
AssetProcessingException processingException = (AssetProcessingException) result;
diff --git a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointHealthStatusProvider.java
index 66f2692d5..1ef7af997 100644
--- a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointHealthStatusProvider.java
+++ b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointHealthStatusProvider.java
@@ -28,7 +28,6 @@ import org.openremote.model.util.ValueUtil;
public class AssetDatapointHealthStatusProvider implements HealthStatusProvider, ContainerService {
public static final String NAME = "datapoints";
- public static final String VERSION = "1.0";
protected AssetDatapointService assetDatapointService;
@Override
@@ -56,11 +55,6 @@ public class AssetDatapointHealthStatusProvider implements HealthStatusProvider,
return NAME;
}
- @Override
- public String getHealthStatusVersion() {
- return VERSION;
- }
-
@Override
public Object getHealthStatus() {
ObjectNode value = ValueUtil.JSON.createObjectNode();
diff --git a/manager/src/main/java/org/openremote/manager/datapoint/AssetPredictedDatapointHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/datapoint/AssetPredictedDatapointHealthStatusProvider.java
index 41f537432..1f2930231 100644
--- a/manager/src/main/java/org/openremote/manager/datapoint/AssetPredictedDatapointHealthStatusProvider.java
+++ b/manager/src/main/java/org/openremote/manager/datapoint/AssetPredictedDatapointHealthStatusProvider.java
@@ -27,7 +27,6 @@ import org.openremote.model.util.ValueUtil;
public class AssetPredictedDatapointHealthStatusProvider implements HealthStatusProvider, ContainerService {
public static final String NAME = "predicted";
- public static final String VERSION = "1.0";
protected AssetPredictedDatapointService assetPredictedDatapointService;
@Override
@@ -55,11 +54,6 @@ public class AssetPredictedDatapointHealthStatusProvider implements HealthStatus
return NAME;
}
- @Override
- public String getHealthStatusVersion() {
- return VERSION;
- }
-
@Override
public Object getHealthStatus() {
ObjectNode value = ValueUtil.JSON.createObjectNode();
diff --git a/manager/src/main/java/org/openremote/manager/event/ClientEventService.java b/manager/src/main/java/org/openremote/manager/event/ClientEventService.java
index cef3d8e51..3a20f3654 100644
--- a/manager/src/main/java/org/openremote/manager/event/ClientEventService.java
+++ b/manager/src/main/java/org/openremote/manager/event/ClientEventService.java
@@ -26,6 +26,7 @@ import org.openremote.container.security.AuthContext;
import org.openremote.container.timer.TimerService;
import org.openremote.container.web.ConnectionConstants;
import org.openremote.manager.gateway.GatewayService;
+import org.openremote.manager.mqtt.DefaultMQTTHandler;
import org.openremote.manager.mqtt.MQTTBrokerService;
import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.manager.web.ManagerWebService;
@@ -42,10 +43,10 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;
import java.util.logging.Logger;
-import static org.apache.camel.builder.Builder.header;
import static org.apache.camel.builder.PredicateBuilder.or;
import static org.openremote.container.web.ConnectionConstants.SESSION_TERMINATOR;
@@ -91,7 +92,7 @@ import static org.openremote.container.web.ConnectionConstants.SESSION_TERMINATO
* </p></dd>
* </dl>
*/
-public class ClientEventService implements ContainerService {
+public class ClientEventService extends RouteBuilder implements ContainerService {
protected static class SessionInfo {
String connectionType;
@@ -115,13 +116,16 @@ public class ClientEventService implements ContainerService {
// TODO: Some of these options should be configurable depending on expected load etc.
public static final String CLIENT_EVENT_TOPIC = "seda://ClientEventTopic?multipleConsumers=true&concurrentConsumers=1&waitForTaskToComplete=NEVER&purgeWhenStopping=true&discardIfNoConsumers=true&limitConcurrentConsumers=false&size=1000";
- public static final String CLIENT_EVENT_QUEUE = "seda://ClientEventQueue?multipleConsumers=false&waitForTaskToComplete=NEVER&purgeWhenStopping=true&discardIfNoConsumers=true&size=25000";
+// public static final String CLIENT_EVENT_QUEUE = "seda://ClientEventQueue?multipleConsumers=false&waitForTaskToComplete=NEVER&purgeWhenStopping=true&discardIfNoConsumers=true&size=25000";
+ // A direct endpoint with threading which then makes it async
+ public static final String CLIENT_EVENT_QUEUE = "direct://ClientEventQueue";
final protected Collection<EventSubscriptionAuthorizer> eventSubscriptionAuthorizers = new CopyOnWriteArraySet<>();
final protected Collection<EventAuthorizer> eventAuthorizers = new CopyOnWriteArraySet<>();
final protected Collection<Consumer<Exchange>> exchangeInterceptors = new CopyOnWriteArraySet<>();
protected ConcurrentMap<String, SessionInfo> sessionKeyInfoMap = new ConcurrentHashMap<>();
protected TimerService timerService;
+ protected ExecutorService executorService;
protected MessageBrokerService messageBrokerService;
protected ManagerIdentityService identityService;
protected EventSubscriptions eventSubscriptions;
@@ -133,11 +137,11 @@ public class ClientEventService implements ContainerService {
* Method to stop further processing of the exchange
*/
public static void stopMessage(Exchange exchange) {
- exchange.setProperty(Exchange.ROUTE_STOP, Boolean.TRUE);
+ exchange.setRouteStop(true);
}
public static boolean isInbound(Exchange exchange) {
- return header(HEADER_CONNECTION_TYPE).isNotNull().matches(exchange);
+ return org.apache.camel.builder.Builder.header(HEADER_CONNECTION_TYPE).isNotNull().matches(exchange);
}
public static String getSessionKey(Exchange exchange) {
@@ -163,6 +167,7 @@ public class ClientEventService implements ContainerService {
messageBrokerService = container.getService(MessageBrokerService.class);
identityService = container.getService(ManagerIdentityService.class);
gatewayService = container.getService(GatewayService.class);
+ executorService = container.getExecutorService();
eventSubscriptions = new EventSubscriptions(
container.getService(TimerService.class)
@@ -172,131 +177,7 @@ public class ClientEventService implements ContainerService {
new EventTypeConverters()
);
- // TODO: Remove prefix and just use event type then use a subscription wrapper to pass subscription ID around
- messageBrokerService.getContext().addRoutes(new RouteBuilder() {
- @Override
- public void configure() throws Exception {
-
- from("websocket://" + WEBSOCKET_EVENTS)
- .routeId("FromClientWebsocketEvents")
- .process(exchange -> {
- exchange.getIn().setHeader(HEADER_CONNECTION_TYPE, HEADER_CONNECTION_TYPE_WEBSOCKET);
-
- // Do basic formatting of exchange
- EventRequestResponseWrapper<?> requestResponse = null;
- if (exchange.getIn().getBody() instanceof EventRequestResponseWrapper) {
- requestResponse = exchange.getIn().getBody(EventRequestResponseWrapper.class);
- } else if (exchange.getIn().getBody() instanceof String && exchange.getIn().getBody(String.class).startsWith(EventRequestResponseWrapper.MESSAGE_PREFIX)) {
- requestResponse = exchange.getIn().getBody(EventRequestResponseWrapper.class);
- }
- if (requestResponse != null) {
- SharedEvent event = requestResponse.getEvent();
- exchange.getIn().setHeader(HEADER_REQUEST_RESPONSE_MESSAGE_ID, requestResponse.getMessageId());
- exchange.getIn().setBody(event);
- }
-
- if (exchange.getIn().getBody() instanceof String) {
- String bodyStr = exchange.getIn().getBody(String.class);
- if (bodyStr.startsWith(EventSubscription.SUBSCRIBE_MESSAGE_PREFIX)) {
- exchange.getIn().setBody(exchange.getIn().getBody(EventSubscription.class));
- } else if (bodyStr.startsWith(CancelEventSubscription.MESSAGE_PREFIX)) {
- exchange.getIn().setBody(exchange.getIn().getBody(CancelEventSubscription.class));
- } else if (bodyStr.startsWith(SharedEvent.MESSAGE_PREFIX)) {
- exchange.getIn().setBody(exchange.getIn().getBody(SharedEvent.class));
- }
- }
-
- // Perform authorisation
- if (exchange.getIn().getBody() instanceof SharedEvent) {
- SharedEvent event = exchange.getIn().getBody(SharedEvent.class);
- AuthContext authContext = exchange.getIn().getHeader(Constants.AUTH_CONTEXT, AuthContext.class);
- String realm = exchange.getIn().getHeader(Constants.REALM_PARAM_NAME, String.class);
-
- if (!authorizeEventWrite(realm, authContext, event)) {
- stopMessage(exchange);
- }
- } else if (exchange.getIn().getBody() instanceof EventSubscription<?>) {
- EventSubscription<?> subscription = exchange.getIn().getBody(EventSubscription.class);
- AuthContext authContext = exchange.getIn().getHeader(Constants.AUTH_CONTEXT, AuthContext.class);
- String realm = exchange.getIn().getHeader(Constants.REALM_PARAM_NAME, String.class);
- String sessionKey = getSessionKey(exchange);
-
- if (!authorizeEventSubscription(realm, authContext, subscription)) {
- sendToSession(sessionKey, new UnauthorizedEventSubscription<>(subscription));
- stopMessage(exchange);
- }
- }
- })
- .to(ClientEventService.CLIENT_EVENT_QUEUE)
- .end();
-
- from(ClientEventService.CLIENT_EVENT_QUEUE)
- .routeId("ClientEvents")
- .choice()
- .when(header(ConnectionConstants.SESSION_OPEN))
- .process(exchange -> {
- String sessionKey = getSessionKey(exchange);
- sessionKeyInfoMap.put(sessionKey, createSessionInfo(sessionKey, exchange));
- passToInterceptors(exchange);
- })
- .stop()
- .when(or(
- header(ConnectionConstants.SESSION_CLOSE),
- header(ConnectionConstants.SESSION_CLOSE_ERROR)
- ))
- .process(exchange -> {
- String sessionKey = getSessionKey(exchange);
- sessionKeyInfoMap.remove(sessionKey);
- eventSubscriptions.cancelAll(sessionKey);
- passToInterceptors(exchange);
- })
- .stop()
- .end()
- .process(exchange -> {
- // Set timestamp if not set
- if (exchange.getIn().getBody() instanceof SharedEvent) {
- SharedEvent event = exchange.getIn().getBody(SharedEvent.class);
- // If there is no timestamp in event, set to system time
- if (event.getTimestamp() <= 0) {
- event.setTimestamp(timerService.getCurrentTimeMillis());
- }
- }
- })
- .process(exchange -> passToInterceptors(exchange))
- .choice()
- .when(body().isInstanceOf(EventSubscription.class))
- .process(exchange -> {
- String sessionKey = getSessionKey(exchange);
- EventSubscription<?> subscription = exchange.getIn().getBody(EventSubscription.class);
- eventSubscriptions.createOrUpdate(sessionKey, subscription);
- subscription.setSubscribed(true);
- sendToSession(sessionKey, subscription);
- })
- .stop()
- .when(body().isInstanceOf(CancelEventSubscription.class))
- .process(exchange -> {
- String sessionKey = getSessionKey(exchange);
- eventSubscriptions.cancel(sessionKey, exchange.getIn().getBody(CancelEventSubscription.class));
- })
- .stop()
- .when(body().isInstanceOf(SharedEvent.class))
- .choice()
- .when(header(HEADER_CONNECTION_TYPE).isNotNull()) // Inbound messages from client
- .to(ClientEventService.CLIENT_EVENT_TOPIC)
- .stop()
- .when(header(HEADER_CONNECTION_TYPE).isNull()) // Outbound message to clients
- .split(method(eventSubscriptions, "splitForSubscribers"))
- .process(exchange -> {
- String sessionKey = getSessionKey(exchange);
- sendToSession(sessionKey, exchange.getIn().getBody());
- })
- .stop()
- .endChoice()
- .otherwise()
- .process(exchange -> LOG.fine("Unsupported message body: " + exchange.getIn().getBody()))
- .end();
- }
- });
+ messageBrokerService.getContext().addRoutes(this);
// Add pending internal subscriptions
if (!pendingInternalSubscriptions.isEmpty()) {
@@ -307,6 +188,132 @@ public class ClientEventService implements ContainerService {
pendingInternalSubscriptions = null;
}
+ // TODO: Remove prefix and just use event type then use a subscription wrapper to pass subscription ID around
+ @Override
+ public void configure() throws Exception {
+ from("websocket://" + WEBSOCKET_EVENTS)
+ .routeId("FromClientWebsocketEvents")
+ .process(exchange -> {
+ exchange.getIn().setHeader(HEADER_CONNECTION_TYPE, HEADER_CONNECTION_TYPE_WEBSOCKET);
+
+ // Do basic formatting of exchange
+ EventRequestResponseWrapper<?> requestResponse = null;
+ if (exchange.getIn().getBody() instanceof EventRequestResponseWrapper) {
+ requestResponse = exchange.getIn().getBody(EventRequestResponseWrapper.class);
+ } else if (exchange.getIn().getBody() instanceof String && exchange.getIn().getBody(String.class).startsWith(EventRequestResponseWrapper.MESSAGE_PREFIX)) {
+ requestResponse = exchange.getIn().getBody(EventRequestResponseWrapper.class);
+ }
+ if (requestResponse != null) {
+ SharedEvent event = requestResponse.getEvent();
+ exchange.getIn().setHeader(HEADER_REQUEST_RESPONSE_MESSAGE_ID, requestResponse.getMessageId());
+ exchange.getIn().setBody(event);
+ }
+
+ if (exchange.getIn().getBody() instanceof String) {
+ String bodyStr = exchange.getIn().getBody(String.class);
+ if (bodyStr.startsWith(EventSubscription.SUBSCRIBE_MESSAGE_PREFIX)) {
+ exchange.getIn().setBody(exchange.getIn().getBody(EventSubscription.class));
+ } else if (bodyStr.startsWith(CancelEventSubscription.MESSAGE_PREFIX)) {
+ exchange.getIn().setBody(exchange.getIn().getBody(CancelEventSubscription.class));
+ } else if (bodyStr.startsWith(SharedEvent.MESSAGE_PREFIX)) {
+ exchange.getIn().setBody(exchange.getIn().getBody(SharedEvent.class));
+ }
+ }
+
+ // Perform authorisation
+ if (exchange.getIn().getBody() instanceof SharedEvent) {
+ SharedEvent event = exchange.getIn().getBody(SharedEvent.class);
+ AuthContext authContext = exchange.getIn().getHeader(Constants.AUTH_CONTEXT, AuthContext.class);
+ String realm = exchange.getIn().getHeader(Constants.REALM_PARAM_NAME, String.class);
+
+ if (!authorizeEventWrite(realm, authContext, event)) {
+ stopMessage(exchange);
+ }
+ } else if (exchange.getIn().getBody() instanceof EventSubscription<?>) {
+ EventSubscription<?> subscription = exchange.getIn().getBody(EventSubscription.class);
+ AuthContext authContext = exchange.getIn().getHeader(Constants.AUTH_CONTEXT, AuthContext.class);
+ String realm = exchange.getIn().getHeader(Constants.REALM_PARAM_NAME, String.class);
+ String sessionKey = getSessionKey(exchange);
+
+ if (!authorizeEventSubscription(realm, authContext, subscription)) {
+ sendToSession(sessionKey, new UnauthorizedEventSubscription<>(subscription));
+ stopMessage(exchange);
+ }
+ }
+ })
+ .to(ClientEventService.CLIENT_EVENT_QUEUE)
+ .end();
+
+ from(ClientEventService.CLIENT_EVENT_QUEUE)
+ .routeId("ClientEvents")
+ .threads().executorService(executorService)
+ .choice()
+ .when(header(ConnectionConstants.SESSION_OPEN))
+ .process(exchange -> {
+ String sessionKey = getSessionKey(exchange);
+ LOG.fine("Adding session: " + sessionKey);
+ sessionKeyInfoMap.put(sessionKey, createSessionInfo(sessionKey, exchange));
+ passToInterceptors(exchange);
+ })
+ .stop()
+ .when(or(
+ header(ConnectionConstants.SESSION_CLOSE),
+ header(ConnectionConstants.SESSION_CLOSE_ERROR)
+ ))
+ .process(exchange -> {
+ String sessionKey = getSessionKey(exchange);
+ LOG.fine("Removing session: " + sessionKey);
+ sessionKeyInfoMap.remove(sessionKey);
+ eventSubscriptions.cancelAll(sessionKey);
+ passToInterceptors(exchange);
+ })
+ .stop()
+ .end()
+ .process(exchange -> {
+ // Set timestamp if not set
+ if (exchange.getIn().getBody() instanceof SharedEvent) {
+ SharedEvent event = exchange.getIn().getBody(SharedEvent.class);
+ // If there is no timestamp in event, set to system time
+ if (event.getTimestamp() <= 0) {
+ event.setTimestamp(timerService.getCurrentTimeMillis());
+ }
+ }
+ })
+ .process(this::passToInterceptors)
+ .choice()
+ .when(body().isInstanceOf(EventSubscription.class))
+ .process(exchange -> {
+ String sessionKey = getSessionKey(exchange);
+ EventSubscription<?> subscription = exchange.getIn().getBody(EventSubscription.class);
+ eventSubscriptions.createOrUpdate(sessionKey, subscription);
+ subscription.setSubscribed(true);
+ sendToSession(sessionKey, subscription);
+ })
+ .stop()
+ .when(body().isInstanceOf(CancelEventSubscription.class))
+ .process(exchange -> {
+ String sessionKey = getSessionKey(exchange);
+ eventSubscriptions.cancel(sessionKey, exchange.getIn().getBody(CancelEventSubscription.class));
+ })
+ .stop()
+ .when(body().isInstanceOf(SharedEvent.class))
+ .choice()
+ .when(header(HEADER_CONNECTION_TYPE).isNotNull()) // Inbound messages from client
+ .to(ClientEventService.CLIENT_EVENT_TOPIC)
+ .stop()
+ .when(header(HEADER_CONNECTION_TYPE).isNull()) // Outbound message to clients
+ .split(method(eventSubscriptions, "splitForSubscribers"))
+ .process(exchange -> {
+ String sessionKey = getSessionKey(exchange);
+ sendToSession(sessionKey, exchange.getIn().getBody());
+ })
+ .stop()
+ .endChoice()
+ .otherwise()
+ .process(exchange -> LOG.fine("Unsupported message body: " + exchange.getIn().getBody()))
+ .end();
+ }
+
/**
* Make an internal subscription to {@link SharedEvent}s sent on the client event bus
*/
@@ -404,18 +411,20 @@ public class ClientEventService implements ContainerService {
return;
}
- if (messageBrokerService != null && messageBrokerService.getProducerTemplate() != null) {
+ if (messageBrokerService != null && messageBrokerService.getFluentProducerTemplate() != null) {
// Don't log that we are publishing a syslog event,
if (!(event instanceof SyslogEvent)) {
LOG.finer("Publishing: " + event);
}
- messageBrokerService.getProducerTemplate()
- .sendBody(CLIENT_EVENT_QUEUE, event);
+ messageBrokerService.getFluentProducerTemplate()
+ .withBody(event)
+ .to(CLIENT_EVENT_QUEUE)
+ .asyncSend();
}
}
public void sendToSession(String sessionKey, Object data) {
- if (messageBrokerService != null && messageBrokerService.getProducerTemplate() != null) {
+ if (messageBrokerService != null && messageBrokerService.getFluentProducerTemplate() != null) {
LOG.finer("Sending to session '" + sessionKey + "': " + data);
SessionInfo sessionInfo = sessionKeyInfoMap.get(sessionKey);
if (sessionInfo == null) {
@@ -423,17 +432,17 @@ public class ClientEventService implements ContainerService {
return;
}
if (sessionInfo.connectionType.equals(HEADER_CONNECTION_TYPE_WEBSOCKET)) {
- messageBrokerService.getProducerTemplate().sendBodyAndHeader(
- "websocket://" + WEBSOCKET_EVENTS,
- data,
- ConnectionConstants.SESSION_KEY, sessionKey
- );
+ messageBrokerService.getFluentProducerTemplate()
+ .withBody(data)
+ .withHeader(ConnectionConstants.SESSION_KEY, sessionKey)
+ .to("websocket://" + WEBSOCKET_EVENTS)
+ .asyncSend();
} else if (sessionInfo.connectionType.equals(HEADER_CONNECTION_TYPE_MQTT)) {
- messageBrokerService.getProducerTemplate().sendBodyAndHeader(
- MQTTBrokerService.MQTT_CLIENT_QUEUE,
- data,
- ConnectionConstants.SESSION_KEY, sessionKey
- );
+ messageBrokerService.getFluentProducerTemplate()
+ .withBody(data)
+ .withHeader(ConnectionConstants.SESSION_KEY, sessionKey)
+ .to(DefaultMQTTHandler.CLIENT_QUEUE)
+ .asyncSend();
}
}
}
@@ -453,7 +462,7 @@ public class ClientEventService implements ContainerService {
// Pass to each interceptor and stop if any interceptor marks the exchange as stop routing
if (exchangeInterceptors.stream().anyMatch(interceptor -> {
interceptor.accept(exchange);
- boolean stop = exchange.getProperty(Exchange.ROUTE_STOP, false, Boolean.class);
+ boolean stop = exchange.isRouteStop();
if (stop) {
LOG.finer("Client event interceptor marked exchange as `stop routing`");
}
diff --git a/manager/src/main/java/org/openremote/manager/event/EventSubscriptions.java b/manager/src/main/java/org/openremote/manager/event/EventSubscriptions.java
index 726ff82cf..f83d940cf 100644
--- a/manager/src/main/java/org/openremote/manager/event/EventSubscriptions.java
+++ b/manager/src/main/java/org/openremote/manager/event/EventSubscriptions.java
@@ -21,7 +21,7 @@ package org.openremote.manager.event;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
-import org.apache.camel.impl.DefaultMessage;
+import org.apache.camel.support.DefaultMessage;
import org.openremote.container.timer.TimerService;
import org.openremote.container.web.ConnectionConstants;
import org.openremote.model.event.TriggeredEventSubscription;
diff --git a/manager/src/main/java/org/openremote/manager/gateway/GatewayConnector.java b/manager/src/main/java/org/openremote/manager/gateway/GatewayConnector.java
index 264715a19..5362c6ae4 100644
--- a/manager/src/main/java/org/openremote/manager/gateway/GatewayConnector.java
+++ b/manager/src/main/java/org/openremote/manager/gateway/GatewayConnector.java
@@ -150,11 +150,14 @@ public class GatewayConnector {
/**
* Start the connector and initiate synchronisation of assets
*/
- synchronized public void connect(Consumer<Object> gatewayMessageConsumer, Runnable disconnectRunnable) {
- if (this.gatewayMessageConsumer != null) {
- return;
+ public void connect(Consumer<Object> gatewayMessageConsumer, Runnable disconnectRunnable) {
+ synchronized (this) {
+ if (this.gatewayMessageConsumer != null) {
+ return;
+ }
+ this.gatewayMessageConsumer = gatewayMessageConsumer;
}
- this.gatewayMessageConsumer = gatewayMessageConsumer;
+
this.disconnectRunnable = disconnectRunnable;
initialSyncInProgress = true;
@@ -175,14 +178,15 @@ public class GatewayConnector {
/**
* Stop the connector and prevent further communication with the gateway
*/
- synchronized public void disconnect() {
- if (this.gatewayMessageConsumer == null) {
- return;
+ public void disconnect() {
+ synchronized (this) {
+ if (this.gatewayMessageConsumer == null) {
+ return;
+ }
+ this.gatewayMessageConsumer = null;
}
LOG.fine("Gateway connector disconnected: Gateway ID=" + gatewayId);
-
- this.gatewayMessageConsumer = null;
Runnable disconnectRunnable = this.disconnectRunnable;
this.disconnectRunnable = null;
initialSyncInProgress = false;
diff --git a/manager/src/main/java/org/openremote/manager/mqtt/ActiveMQORSecurityManager.java b/manager/src/main/java/org/openremote/manager/mqtt/ActiveMQORSecurityManager.java
index cfad8cd37..0c3640507 100644
--- a/manager/src/main/java/org/openremote/manager/mqtt/ActiveMQORSecurityManager.java
+++ b/manager/src/main/java/org/openremote/manager/mqtt/ActiveMQORSecurityManager.java
@@ -42,7 +42,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import static org.apache.activemq.artemis.core.remoting.CertificateUtil.getCertsFromConnection;
-import static org.openremote.manager.mqtt.MQTTBrokerService.connectionToString;
import static org.openremote.model.syslog.SyslogCategory.API;
/**
@@ -181,7 +180,7 @@ public class ActiveMQORSecurityManager extends ActiveMQJAASSecurityManager {
// See if a custom handler wants to handle authorisation for this topic pub/sub
for (MQTTHandler handler : brokerService.getCustomHandlers()) {
if (handler.handlesTopic(topic)) {
- LOG.fine("Passing topic to handler for " + (isWrite ? "pub" : "sub") + ": handler=" + handler.getName() + ", topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Passing topic to handler for " + (isWrite ? "pub" : "sub") + ": handler=" + handler.getName() + ", topic=" + topic + ", " + brokerService.connectionToString(connection));
boolean result;
if (isWrite) {
@@ -191,16 +190,16 @@ public class ActiveMQORSecurityManager extends ActiveMQJAASSecurityManager {
}
if (LOG.isLoggable(Level.FINE)) {
if (result) {
- LOG.fine("Handler has authorised " + (isWrite ? "pub" : "sub") + ": topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Handler has authorised " + (isWrite ? "pub" : "sub") + ": topic=" + topic + ", " + brokerService.connectionToString(connection));
} else {
- LOG.fine("Handler has not authorised " + (isWrite ? "pub" : "sub") + ": topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Handler has not authorised " + (isWrite ? "pub" : "sub") + ": topic=" + topic + ", " + brokerService.connectionToString(connection));
}
}
return result;
}
}
- LOG.fine("No handler has allowed " + (isWrite ? "pub" : "sub") + ": topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("No handler has allowed " + (isWrite ? "pub" : "sub") + ": topic=" + topic + ", " + brokerService.connectionToString(connection));
return false;
}
diff --git a/manager/src/main/java/org/openremote/manager/mqtt/DefaultMQTTHandler.java b/manager/src/main/java/org/openremote/manager/mqtt/DefaultMQTTHandler.java
index 0bc0bf506..c40328c49 100644
--- a/manager/src/main/java/org/openremote/manager/mqtt/DefaultMQTTHandler.java
+++ b/manager/src/main/java/org/openremote/manager/mqtt/DefaultMQTTHandler.java
@@ -20,9 +20,9 @@
package org.openremote.manager.mqtt;
import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelId;
import io.netty.handler.codec.mqtt.MqttQoS;
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
+import org.apache.camel.builder.RouteBuilder;
import org.keycloak.KeycloakSecurityContext;
import org.openremote.container.security.AuthContext;
import org.openremote.container.web.ConnectionConstants;
@@ -33,6 +33,7 @@ import org.openremote.model.Container;
import org.openremote.model.asset.AssetEvent;
import org.openremote.model.asset.AssetFilter;
import org.openremote.model.attribute.AttributeEvent;
+import org.openremote.model.event.TriggeredEventSubscription;
import org.openremote.model.event.shared.CancelEventSubscription;
import org.openremote.model.event.shared.EventSubscription;
import org.openremote.model.event.shared.SharedEvent;
@@ -42,13 +43,14 @@ import org.openremote.model.util.ValueUtil;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.ConcurrentMap;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.logging.Logger;
import java.util.regex.Pattern;
-import static org.openremote.manager.mqtt.MQTTBrokerService.connectionToString;
+import static org.openremote.manager.event.ClientEventService.CLIENT_EVENT_QUEUE;
+import static org.openremote.manager.mqtt.MQTTBrokerService.getConnectionIDString;
import static org.openremote.model.Constants.ASSET_ID_REGEXP;
import static org.openremote.model.syslog.SyslogCategory.API;
@@ -58,6 +60,25 @@ import static org.openremote.model.syslog.SyslogCategory.API;
*/
public class DefaultMQTTHandler extends MQTTHandler {
+ public static class SubscriberInfo {
+ protected Map<String, Consumer<SharedEvent>> topicSubscriptionMap;
+
+ public SubscriberInfo(String topic, Consumer<SharedEvent> subscriptionConsumer) {
+ this.topicSubscriptionMap = new HashMap<>();
+ this.topicSubscriptionMap.put(topic, subscriptionConsumer);
+ }
+
+ protected void add(String topic, Consumer<SharedEvent> subscriptionConsumer) {
+ topicSubscriptionMap.put(topic, subscriptionConsumer);
+ }
+
+ protected int remove(String topic) {
+ topicSubscriptionMap.remove(topic);
+ return topicSubscriptionMap.size();
+ }
+ }
+
+ public static final String CLIENT_QUEUE = "seda://MQTTDefaultHandlerQueue?waitForTaskToComplete=IfReplyExpected&timeout=10000&purgeWhenStopping=true&discardIfNoConsumers=false&size=25000";
public static final int PRIORITY = Integer.MIN_VALUE + 1000;
public static final String ASSET_TOPIC = "asset";
public static final String ATTRIBUTE_TOPIC = "attribute";
@@ -65,7 +86,7 @@ public class DefaultMQTTHandler extends MQTTHandler {
public static final String ATTRIBUTE_VALUE_WRITE_TOPIC = "writeattributevalue";
private static final Logger LOG = SyslogCategory.getLogger(API, DefaultMQTTHandler.class);
protected AssetStorageService assetStorageService;
- protected final Map<RemotingConnection, Integer> subscribedConnections = new HashMap<>();
+ protected final ConcurrentMap<String, SubscriberInfo> connectionSubscriberInfoMap = new ConcurrentHashMap<>();
@Override
public int getPriority() {
@@ -73,6 +94,42 @@ public class DefaultMQTTHandler extends MQTTHandler {
return PRIORITY;
}
+ @Override
+ public void init(Container container) throws Exception {
+ super.init(container);
+ messageBrokerService.getContext().addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(CLIENT_QUEUE)
+ .routeId("MQTTDefaultHandlerQueue")
+ .choice()
+ .when(body().isInstanceOf(TriggeredEventSubscription.class))
+ .process(exchange -> {
+ // Get the subscriber consumer
+ String connectionID = exchange.getIn().getHeader(ConnectionConstants.SESSION_KEY, String.class);
+ if (connectionID == null) {
+ LOG.warning("No connection ID for triggered subscription so cannot deliver");
+ } else {
+ SubscriberInfo subscriberInfo = connectionSubscriberInfoMap.get(connectionID);
+ if (subscriberInfo != null) {
+ TriggeredEventSubscription<?> triggeredEventSubscription = exchange.getIn().getBody(TriggeredEventSubscription.class);
+ String topic = triggeredEventSubscription.getSubscriptionId();
+ // Should only be a single event in here
+ SharedEvent event = triggeredEventSubscription.getEvents().get(0);
+ Consumer<SharedEvent> eventConsumer = subscriberInfo.topicSubscriptionMap.get(topic);
+ if (eventConsumer != null) {
+ eventConsumer.accept(event);
+ }
+ }
+ }
+ })
+ .otherwise()
+ .process(exchange -> LOG.fine("Unsupported message body: " + exchange.getIn().getBody()))
+ .end();
+ }
+ });
+ }
+
@Override
public void start(Container container) throws Exception {
super.start(container);
@@ -88,11 +145,15 @@ public class DefaultMQTTHandler extends MQTTHandler {
// Put a close connection runnable into the headers for the client event service
Runnable closeRunnable = () -> {
if (mqttBrokerService != null) {
+ LOG.fine("Calling client session closed force disconnect runnable: " + mqttBrokerService.connectionToString(connection));
mqttBrokerService.doForceDisconnect(connection);
}
};
headers.put(ConnectionConstants.SESSION_TERMINATOR, closeRunnable);
- messageBrokerService.getProducerTemplate().sendBodyAndHeaders(ClientEventService.CLIENT_EVENT_QUEUE, null, headers);
+ messageBrokerService.getFluentProducerTemplate()
+ .withHeaders(headers)
+ .to(CLIENT_EVENT_QUEUE)
+ .asyncSend();
return true;
}
@@ -102,8 +163,11 @@ public class DefaultMQTTHandler extends MQTTHandler {
Map<String, Object> headers = prepareHeaders(null, connection);
headers.put(ConnectionConstants.SESSION_CLOSE, true);
- messageBrokerService.getProducerTemplate().sendBodyAndHeaders(ClientEventService.CLIENT_EVENT_QUEUE, null, headers);
- subscribedConnections.remove(connection);
+ messageBrokerService.getFluentProducerTemplate()
+ .withHeaders(headers)
+ .to(CLIENT_EVENT_QUEUE)
+ .asyncSend();
+ connectionSubscriberInfoMap.remove(getConnectionIDString(connection));
}
@Override
@@ -111,8 +175,11 @@ public class DefaultMQTTHandler extends MQTTHandler {
super.onConnectionLost(connection);
Map<String, Object> headers = prepareHeaders(null, connection);
headers.put(ConnectionConstants.SESSION_CLOSE_ERROR, true);
- messageBrokerService.getProducerTemplate().sendBodyAndHeaders(ClientEventService.CLIENT_EVENT_QUEUE, null, headers);
- subscribedConnections.remove(connection);
+ messageBrokerService.getFluentProducerTemplate()
+ .withHeaders(headers)
+ .to(CLIENT_EVENT_QUEUE)
+ .asyncSend();
+ connectionSubscriberInfoMap.remove(getConnectionIDString(connection));
}
@Override
@@ -137,7 +204,7 @@ public class DefaultMQTTHandler extends MQTTHandler {
AuthContext authContext = getAuthContextFromSecurityContext(securityContext);
if (authContext == null) {
- LOG.fine("Anonymous connection not supported: topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Anonymous connection not supported: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
@@ -145,58 +212,58 @@ public class DefaultMQTTHandler extends MQTTHandler {
boolean isAssetTopic = isAssetTopic(topic);
if (!isAssetTopic && !isAttributeTopic) {
- LOG.fine("Topic must have 3 or more tokens and third token must be 'asset, attribute or attributevalue': topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Topic must have 3 or more tokens and third token must be 'asset, attribute or attributevalue': topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
if (isAssetTopic) {
if (topic.getTokens().size() < 4 || topic.getTokens().size() > 5) {
- LOG.fine("Asset subscribe token count should be 4 or 5: topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Asset subscribe token count should be 4 or 5: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
if (topic.getTokens().size() == 4) {
if (!Pattern.matches(ASSET_ID_REGEXP, topicTokenIndexToString(topic, 3))
&& !TOKEN_MULTI_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 3))
&& !TOKEN_SINGLE_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 3))) {
- LOG.fine("Asset subscribe forth token must be an asset ID or wildcard: topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Asset subscribe forth token must be an asset ID or wildcard: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
} else if (topic.getTokens().size() == 5) {
if (!Pattern.matches(ASSET_ID_REGEXP, topicTokenIndexToString(topic, 3))) {
- LOG.fine("Asset subscribe forth token must be an asset ID: topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Asset subscribe forth token must be an asset ID: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
if (!TOKEN_MULTI_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 4))
&& !TOKEN_SINGLE_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 4))) {
- LOG.fine("Asset subscribe fifth token must be a wildcard: topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Asset subscribe fifth token must be a wildcard: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
}
} else {
// Attribute topic
if (topic.getTokens().size() < 5 || topic.getTokens().size() > 6) {
- LOG.fine("Attribute subscribe token count should be 5 or 6: topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Attribute subscribe token count should be 5 or 6: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
if (topic.getTokens().size() == 5) {
if (TOKEN_MULTI_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 3))) {
- LOG.fine("Attribute subscribe multi level wildcard must be last token: topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Attribute subscribe multi level wildcard must be last token: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
if (!Pattern.matches(ASSET_ID_REGEXP, topicTokenIndexToString(topic, 4))
&& !TOKEN_MULTI_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 4))
&& !TOKEN_SINGLE_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 4))) {
- LOG.fine("Attribute subscribe fifth token must be an asset ID or a wildcard: topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Attribute subscribe fifth token must be an asset ID or a wildcard: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
} else if (topic.getTokens().size() == 6) {
if (!Pattern.matches(ASSET_ID_REGEXP, topicTokenIndexToString(topic, 4))) {
- LOG.fine("Attribute subscribe fifth token must be an asset ID: topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Attribute subscribe fifth token must be an asset ID: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
if (!TOKEN_MULTI_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 5))
&& !TOKEN_SINGLE_LEVEL_WILDCARD.equals(topicTokenIndexToString(topic, 5))) {
- LOG.fine("Attribute subscribe sixth token must be a wildcard: topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Attribute subscribe sixth token must be a wildcard: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
}
@@ -206,7 +273,7 @@ public class DefaultMQTTHandler extends MQTTHandler {
AssetFilter<?> filter = buildAssetFilter(topic);
if (filter == null) {
- LOG.fine("Failed to process subscription topic: topic=" + topic + ", " + connectionToString(connection));
+ LOG.fine("Failed to process subscription topic: topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
@@ -257,13 +324,13 @@ public class DefaultMQTTHandler extends MQTTHandler {
AuthContext authContext = getAuthContextFromSecurityContext(securityContext);
if (authContext == null) {
- LOG.fine("Anonymous publish not supported: topic=" + topic + ", connection=" + connectionToString(connection));
+ LOG.fine("Anonymous publish not supported: topic=" + topic + ", connection=" + mqttBrokerService.connectionToString(connection));
return false;
}
if (isAttributeValueWriteTopic(topic)) {
if (topic.getTokens().size() != 5 || !Pattern.matches(ASSET_ID_REGEXP, topicTokenIndexToString(topic, 4))) {
- LOG.fine("Publish attribute value topic should be {realm}/{clientId}/writeattributevalue/{attributeName}/{assetId}: topic=" + topic + ", connection=" + connectionToString(connection));
+ LOG.fine("Publish attribute value topic should be {realm}/{clientId}/writeattributevalue/{attributeName}/{assetId}: topic=" + topic + ", connection=" + mqttBrokerService.connectionToString(connection));
return false;
}
} else {
@@ -299,25 +366,30 @@ public class DefaultMQTTHandler extends MQTTHandler {
EventSubscription subscription = new EventSubscription(
subscriptionClass,
filter,
- subscriptionId,
- eventConsumer
+ subscriptionId
);
Map<String, Object> headers = prepareHeaders(topicRealm(topic), connection);
- messageBrokerService.getProducerTemplate().sendBodyAndHeaders(ClientEventService.CLIENT_EVENT_QUEUE, subscription, headers);
+ messageBrokerService.getFluentProducerTemplate()
+ .withHeaders(headers)
+ .withBody(subscription)
+ .to(CLIENT_EVENT_QUEUE)
+ .asyncSend();
// Track connection subscriptions for restricted user asset link changes (to determine if the client should be disconnected)
- synchronized (subscribedConnections) {
- subscribedConnections.compute(connection, (existingConnection, subscriptionCount) -> {
- if (subscriptionCount == null) {
- subscriptionCount = 0;
+ synchronized (connectionSubscriberInfoMap) {
+ connectionSubscriberInfoMap.compute(getConnectionIDString(connection), (connectionID, subscriberInfo) -> {
+ if (subscriberInfo == null) {
+ return new SubscriberInfo(topic.getString(), eventConsumer);
+ } else {
+ subscriberInfo.add(topic.getString(), eventConsumer);
+ return subscriberInfo;
}
- return subscriptionCount + 1;
});
}
}
- @SuppressWarnings({"unchecked", "rawtypes", "ConstantConditions"})
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void onUnsubscribe(RemotingConnection connection, Topic topic) {
String subscriptionId = topic.toString();
@@ -325,15 +397,19 @@ public class DefaultMQTTHandler extends MQTTHandler {
Map<String, Object> headers = prepareHeaders(topicRealm(topic), connection);
Class<SharedEvent> subscriptionClass = (Class) (isAssetTopic ? AssetEvent.class : AttributeEvent.class);
CancelEventSubscription cancelEventSubscription = new CancelEventSubscription(subscriptionClass, subscriptionId);
- messageBrokerService.getProducerTemplate().sendBodyAndHeaders(ClientEventService.CLIENT_EVENT_QUEUE, cancelEventSubscription, headers);
+ messageBrokerService.getFluentProducerTemplate()
+ .withHeaders(headers)
+ .withBody(cancelEventSubscription)
+ .to(CLIENT_EVENT_QUEUE)
+ .asyncSend();
// Track connection subscriptions for restricted user asset link changes (to determine if the client should be disconnected)
- synchronized (subscribedConnections) {
- subscribedConnections.compute(connection, (existingConnection, subscriptionCount) -> {
- if (subscriptionCount == 1) {
+ synchronized (connectionSubscriberInfoMap) {
+ connectionSubscriberInfoMap.computeIfPresent(getConnectionIDString(connection), (connectionID, subscriberInfo) -> {
+ if (subscriberInfo.remove(topic.getString()) == 0) {
return null;
}
- return subscriptionCount - 1;
+ return subscriberInfo;
});
}
}
@@ -352,13 +428,17 @@ public class DefaultMQTTHandler extends MQTTHandler {
Object value = ValueUtil.parse(payloadContent).orElse(null);
AttributeEvent attributeEvent = buildAttributeEvent(topicTokens, value);
Map<String, Object> headers = prepareHeaders(topicRealm(topic), connection);
- messageBrokerService.getProducerTemplate().sendBodyAndHeaders(ClientEventService.CLIENT_EVENT_QUEUE, attributeEvent, headers);
+ messageBrokerService.getFluentProducerTemplate()
+ .withHeaders(headers)
+ .withBody(attributeEvent)
+ .to(CLIENT_EVENT_QUEUE)
+ .asyncSend();
}
@Override
public void onUserAssetLinksChanged(RemotingConnection connection) {
- if (subscribedConnections.containsKey(connection)) {
- LOG.fine("User asset links have changed for a connected user with active subscriptions so force disconnecting them: " + connectionToString(connection));
+ if (connectionSubscriberInfoMap.containsKey(getConnectionIDString(connection))) {
+ LOG.fine("User asset links have changed for a connected user with active subscriptions so force disconnecting them: " + mqttBrokerService.connectionToString(connection));
mqttBrokerService.doForceDisconnect(connection);
}
}
@@ -518,7 +598,7 @@ public class DefaultMQTTHandler extends MQTTHandler {
protected static Map<String, Object> prepareHeaders(String requestRealm, RemotingConnection connection) {
Map<String, Object> headers = new HashMap<>();
- headers.put(ConnectionConstants.SESSION_KEY, MQTTBrokerService.getConnectionIDString(connection));
+ headers.put(ConnectionConstants.SESSION_KEY, getConnectionIDString(connection));
headers.put(ClientEventService.HEADER_CONNECTION_TYPE, ClientEventService.HEADER_CONNECTION_TYPE_MQTT);
headers.put(Constants.REALM_PARAM_NAME, requestRealm);
return headers;
diff --git a/manager/src/main/java/org/openremote/manager/mqtt/MQTTBrokerService.java b/manager/src/main/java/org/openremote/manager/mqtt/MQTTBrokerService.java
index 4f413c72b..1feda1afd 100644
--- a/manager/src/main/java/org/openremote/manager/mqtt/MQTTBrokerService.java
+++ b/manager/src/main/java/org/openremote/manager/mqtt/MQTTBrokerService.java
@@ -19,6 +19,8 @@
*/
package org.openremote.manager.mqtt;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
import io.netty.channel.ChannelId;
import io.netty.handler.codec.mqtt.MqttQoS;
import org.apache.activemq.artemis.api.core.ActiveMQException;
@@ -43,6 +45,7 @@ import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
import org.apache.activemq.artemis.spi.core.security.jaas.GuestLoginModule;
import org.apache.activemq.artemis.spi.core.security.jaas.PrincipalConversionLoginModule;
import org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal;
+import org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal;
import org.apache.camel.builder.RouteBuilder;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.http.client.utils.URIBuilder;
@@ -70,10 +73,12 @@ import org.openremote.model.util.ValueUtil;
import javax.security.auth.Subject;
import javax.security.auth.login.AppConfigurationEntry;
+import java.security.Principal;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -91,9 +96,9 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
public static final String MQTT_FORCE_USER_DISCONNECT_DEBOUNCE_MILLIS = "MQTT_FORCE_USER_DISCONNECT_DEBOUNCE_MILLIS";
public static int MQTT_FORCE_USER_DISCONNECT_DEBOUNCE_MILLIS_DEFAULT = 5000;
public static final int PRIORITY = MED_PRIORITY;
- public static final String MQTT_CLIENT_QUEUE = "seda://MqttClientQueue?waitForTaskToComplete=IfReplyExpected&timeout=10000&purgeWhenStopping=true&discardIfNoConsumers=false&size=25000";
public static final String MQTT_SERVER_LISTEN_HOST = "MQTT_SERVER_LISTEN_HOST";
public static final String MQTT_SERVER_LISTEN_PORT = "MQTT_SERVER_LISTEN_PORT";
+ public static final String ANONYMOUS_USERNAME = "anonymous";
protected final WildcardConfiguration wildcardConfiguration = new WildcardConfiguration();
protected static final Logger LOG = SyslogCategory.getLogger(API, MQTTBrokerService.class);
@@ -105,10 +110,13 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
protected TimerService timerService;
protected List<MQTTHandler> customHandlers = new ArrayList<>();
protected ConcurrentMap<String, RemotingConnection> clientIDConnectionMap = new ConcurrentHashMap<>();
+ protected ConcurrentMap<String, RemotingConnection> connectionIDConnectionMap = new ConcurrentHashMap<>();
// TODO: Make auto provisioning clients disconnect and reconnect with credentials
// Temp to prevent breaking existing auto provisioning API
protected ConcurrentMap<Object, Triple<String, String, String>> transientCredentials = new ConcurrentHashMap<>();
protected Debouncer<String> userAssetDisconnectDebouncer;
+ // Stores disconnected connections for a short period to allow last will publishes to be processed
+ protected Cache<String, RemotingConnection> disconnectedConnectionCache;
protected boolean active;
protected String host;
@@ -134,6 +142,10 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
executorService = container.getExecutorService();
timerService = container.getService(TimerService.class);
userAssetDisconnectDebouncer = new Debouncer<>(executorService, this::processUserAssetLinkChange, debounceMillis);
+ disconnectedConnectionCache = CacheBuilder.newBuilder()
+ .maximumSize(10000)
+ .expireAfterWrite(10000, TimeUnit.MILLISECONDS)
+ .build();
if (!identityService.isKeycloakEnabled()) {
LOG.warning("MQTT connections are not supported when not using Keycloak identity provider");
@@ -143,6 +155,21 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
identityProvider = (ManagerKeycloakIdentityProvider) identityService.getIdentityProvider();
container.getService(MessageBrokerService.class).getContext().addRoutes(this);
}
+
+ // Load custom handlers
+ this.customHandlers = stream(ServiceLoader.load(MQTTHandler.class).spliterator(), false)
+ .sorted(Comparator.comparingInt(MQTTHandler::getPriority))
+ .collect(Collectors.toList());
+
+ // Init each custom handler
+ for (MQTTHandler handler : customHandlers) {
+ try {
+ handler.init(container);
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "MQTT custom handler threw an exception whilst initialising: handler=" + handler.getName(), e);
+ throw e;
+ }
+ }
}
@Override
@@ -172,13 +199,13 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
server.setSecurityManager(new ActiveMQORSecurityManager(authorisationService, this, realm -> identityProvider.getKeycloakDeployment(realm, KEYCLOAK_CLIENT_ID), "", new SecurityConfiguration() {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
- return new AppConfigurationEntry[] {
- new AppConfigurationEntry(GuestLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, Map.of("debug", "true", "credentialsInvalidate", "true")),
- new AppConfigurationEntry(MultiTenantClientCredentialsGrantsLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.REQUISITE, Map.of(
- MultiTenantClientCredentialsGrantsLoginModule.INCLUDE_REALM_ROLES_OPTION, "true",
- AbstractKeycloakLoginModule.ROLE_PRINCIPAL_CLASS_OPTION, RolePrincipal.class.getName()
- )),
- new AppConfigurationEntry(PrincipalConversionLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.REQUISITE, Map.of(PrincipalConversionLoginModule.PRINCIPAL_CLASS_LIST, KeycloakPrincipal.class.getName()))
+ return new AppConfigurationEntry[]{
+ new AppConfigurationEntry(GuestLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, Map.of("debug", "true", "credentialsInvalidate", "true", "org.apache.activemq.jaas.guest.user", ANONYMOUS_USERNAME, "org.apache.activemq.jaas.guest.role", ANONYMOUS_USERNAME)),
+ new AppConfigurationEntry(MultiTenantClientCredentialsGrantsLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.REQUISITE, Map.of(
+ MultiTenantClientCredentialsGrantsLoginModule.INCLUDE_REALM_ROLES_OPTION, "true",
+ AbstractKeycloakLoginModule.ROLE_PRINCIPAL_CLASS_OPTION, RolePrincipal.class.getName()
+ )),
+ new AppConfigurationEntry(PrincipalConversionLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.REQUISITE, Map.of(PrincipalConversionLoginModule.PRINCIPAL_CLASS_LIST, KeycloakPrincipal.class.getName()))
};
}
}));
@@ -220,11 +247,6 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
// Create producer
producer = internalSession.createProducer();
- // Load custom handlers
- this.customHandlers = stream(ServiceLoader.load(MQTTHandler.class).spliterator(), false)
- .sorted(Comparator.comparingInt(MQTTHandler::getPriority))
- .collect(Collectors.toList());
-
// Start each custom handler
for (MQTTHandler handler : customHandlers) {
try {
@@ -240,39 +262,39 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
@Override
public void configure() throws Exception {
from(PERSISTENCE_TOPIC)
- .routeId("UserPersistenceChanges")
- .filter(body().isInstanceOf(PersistenceEvent.class))
- .process(exchange -> {
- PersistenceEvent<?> persistenceEvent = (PersistenceEvent<?>)exchange.getIn().getBody(PersistenceEvent.class);
-
- if (persistenceEvent.getEntity() instanceof User user) {
-
- if (!user.isServiceAccount()) {
- return;
- }
-
- boolean forceDisconnect = persistenceEvent.getCause() == PersistenceEvent.Cause.DELETE;
-
- if (persistenceEvent.getCause() == PersistenceEvent.Cause.UPDATE) {
- // Force disconnect if certain properties have changed
- forceDisconnect = Arrays.stream(persistenceEvent.getPropertyNames()).anyMatch((propertyName) ->
- (propertyName.equals("enabled") && !user.getEnabled())
- || propertyName.equals("username")
- || propertyName.equals("secret"));
+ .routeId("UserPersistenceChanges")
+ .filter(body().isInstanceOf(PersistenceEvent.class))
+ .process(exchange -> {
+ PersistenceEvent<?> persistenceEvent = (PersistenceEvent<?>) exchange.getIn().getBody(PersistenceEvent.class);
+
+ if (persistenceEvent.getEntity() instanceof User user) {
+
+ if (!user.isServiceAccount()) {
+ return;
+ }
+
+ boolean forceDisconnect = persistenceEvent.getCause() == PersistenceEvent.Cause.DELETE;
+
+ if (persistenceEvent.getCause() == PersistenceEvent.Cause.UPDATE) {
+ // Force disconnect if certain properties have changed
+ forceDisconnect = Arrays.stream(persistenceEvent.getPropertyNames()).anyMatch((propertyName) ->
+ (propertyName.equals("enabled") && !user.getEnabled())
+ || propertyName.equals("username")
+ || propertyName.equals("secret"));
+ }
+
+ if (forceDisconnect) {
+ LOG.fine("User modified or deleted so force closing any sessions for this user: " + user);
+ // Find existing connection for this user
+ getUserConnections(user.getId()).forEach(this::doForceDisconnect);
+ }
+
+ } else if (persistenceEvent.getEntity() instanceof UserAssetLink userAssetLink) {
+ String userID = userAssetLink.getId().getUserId();
+ // Debounce force disconnect check of this user's sessions as there could be many asset links changing
+ userAssetDisconnectDebouncer.call(userID);
}
-
- if (forceDisconnect) {
- LOG.fine("User modified or deleted so force closing any sessions for this user: " + user);
- // Find existing connection for this user
- getUserConnections(user.getId()).forEach(this::doForceDisconnect);
- }
-
- } else if (persistenceEvent.getEntity() instanceof UserAssetLink userAssetLink) {
- String userID = userAssetLink.getId().getUserId();
- // Debounce force disconnect check of this user's sessions as there could be many asset links changing
- userAssetDisconnectDebouncer.call(userID);
- }
- });
+ });
}
@Override
@@ -284,20 +306,20 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
LOG.fine("Stopped MQTT broker");
stream(ServiceLoader.load(MQTTHandler.class).spliterator(), false)
- .sorted(Comparator.comparingInt(MQTTHandler::getPriority).reversed())
- .forEach(handler -> {
- try {
- handler.stop();
- } catch (Exception e) {
- LOG.log(Level.WARNING, "MQTT custom handler threw an exception whilst stopping: handler=" + handler.getName(), e);
- }
- });
+ .sorted(Comparator.comparingInt(MQTTHandler::getPriority).reversed())
+ .forEach(handler -> {
+ try {
+ handler.stop();
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "MQTT custom handler threw an exception whilst stopping: handler=" + handler.getName(), e);
+ }
+ });
}
@Override
public void afterCreateConnection(RemotingConnection connection) throws ActiveMQException {
- LOG.fine("New client connection: "+ connectionToString(connection));
+ LOG.info("Client connection created: " + connectionToString(connection));
// MQTT seems to only use failure callback even if closed gracefully (need to look at the exception for details)
connection.addFailureListener(new FailureListener() {
@@ -312,35 +334,46 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
if (exception.getType() == ActiveMQExceptionType.REMOTE_DISCONNECT) {// Seems to be the type for graceful close of connection
// Notify handlers of connection close
+ LOG.info("Client connection closed: " + connectionToString(connection));
for (MQTTHandler handler : getCustomHandlers()) {
handler.onDisconnect(connection);
}
} else {
// Notify handlers of connection failure
+ LOG.info("Client connection failed: " + connectionToString(connection));
for (MQTTHandler handler : getCustomHandlers()) {
handler.onConnectionLost(connection);
}
}
+ connectionIDConnectionMap.remove(getConnectionIDString(connection));
+
if (connection.getClientID() != null) {
- clientIDConnectionMap.remove(connection.getClientID());
+ RemotingConnection remotingConnection = clientIDConnectionMap.remove(connection.getClientID());
+ if (remotingConnection != null) {
+ disconnectedConnectionCache.put(connection.getClientID(), remotingConnection);
+ }
}
}
});
}
+ // We do this here as connection plugin afterCreateConnection callback fires before client ID and subject are populated
+ // For each connection multiple sessions are created but we only want to call custom handlers onConnect once
@Override
public void afterCreateSession(ServerSession session) throws ActiveMQException {
RemotingConnection remotingConnection = session.getRemotingConnection();
- if (remotingConnection == null || remotingConnection.getClientID() == null) {
+ // Ignore internal connections or ones without a client ID
+ if (remotingConnection == null || remotingConnection.getClientID() == null || remotingConnection.getTransportConnection() instanceof InVMConnection) {
return;
}
- if (!clientIDConnectionMap.containsKey(remotingConnection.getClientID())) {
- clientIDConnectionMap.put(remotingConnection.getClientID(), remotingConnection);
+ String connectionID = getConnectionIDString(remotingConnection);
+ clientIDConnectionMap.put(remotingConnection.getClientID(), remotingConnection);
- // We do this here as connection plugin afterCreateConnection callback fires before client ID and subject are populated
+ if (!connectionIDConnectionMap.containsKey(connectionID)) {
+ connectionIDConnectionMap.put(connectionID, remotingConnection);
for (MQTTHandler handler : getCustomHandlers()) {
handler.onConnect(remotingConnection);
}
@@ -349,7 +382,6 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
@Override
public void afterDestroyConnection(RemotingConnection connection) throws ActiveMQException {
- LOG.fine("Destroyed client connection: " + connectionToString(connection));
}
public void onSubscribe(RemotingConnection connection, String topicStr) {
@@ -359,6 +391,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
if (handler.handlesTopic(topic)) {
LOG.fine("Handler has handled subscribe: handler=" + handler.getName() + ", topic=" + topic + ", " + connectionToString(connection));
handler.onSubscribe(connection, topic);
+ LOG.info("Client subscribed '" + topicStr + "': " + connectionToString(connection));
break;
}
}
@@ -371,6 +404,7 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
if (handler.handlesTopic(topic)) {
LOG.fine("Handler has handled unsubscribe: handler=" + handler.getName() + ", topic=" + topic + ", " + connectionToString(connection));
handler.onUnsubscribe(connection, topic);
+ LOG.info("Client unsubscribed '" + topicStr + "': " + connectionToString(connection));
break;
}
}
@@ -422,17 +456,20 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
}
protected void doForceDisconnect(RemotingConnection connection) {
- LOG.fine("Force disconnecting client connection: " + connectionToString(connection));
+ LOG.info("Force disconnecting client connection: " + connectionToString(connection));
connection.disconnect(false);
}
public void publishMessage(String topic, Object data, MqttQoS qoS) {
try {
if (internalSession != null) {
- ClientMessage message = internalSession.createMessage(false);
- message.putIntProperty(MQTT_QOS_LEVEL_KEY, qoS.value());
- message.writeBodyBufferBytes(ValueUtil.asJSON(data).map(String::getBytes).orElseThrow(() -> new IllegalStateException("Failed to convert payload to JSON string: " + data)));
- producer.send(MQTTUtil.convertMqttTopicFilterToCoreAddress(topic, server.getConfiguration().getWildcardConfiguration()), message);
+ // Artemis' sessions are not threadsafe
+ synchronized (internalSession) {
+ ClientMessage message = internalSession.createMessage(false);
+ message.putIntProperty(MQTT_QOS_LEVEL_KEY, qoS.value());
+ message.writeBodyBufferBytes(ValueUtil.asJSON(data).map(String::getBytes).orElseThrow(() -> new IllegalStateException("Failed to convert payload to JSON string: " + data)));
+ producer.send(MQTTUtil.convertMqttTopicFilterToCoreAddress(topic, server.getConfiguration().getWildcardConfiguration()), message);
+ }
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Couldn't send AttributeEvent to MQTT client", e);
@@ -449,14 +486,33 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
}
Object ID = connection.getID();
- return ID instanceof ChannelId ? ((ChannelId)ID).asLongText() : ID.toString();
+ return ID instanceof ChannelId ? ((ChannelId) ID).asLongText() : ID.toString();
}
- public static String connectionToString(RemotingConnection connection) {
+ public String connectionToString(RemotingConnection connection) {
if (connection == null) {
return "";
}
- return "connection=" + connection.getRemoteAddress() + ", clientID=" + connection.getClientID() + ", subject=" + connection.getSubject();
+
+ String username = null;
+ Subject subject = connection.getSubject();
+
+ if (subject != null) {
+ username = getSubjectName(subject);
+ }
+
+ if (username == null || ANONYMOUS_USERNAME.equals(username)) {
+ // Check if there are transient credentials for this connection
+ Triple<String, String, String> userIDNameAndPassword = transientCredentials.get(connection.getID());
+ if (userIDNameAndPassword != null) {
+ username = userIDNameAndPassword.getMiddle();
+ }
+ }
+ return "connection=" + connection.getRemoteAddress() + ", clientID=" + connection.getClientID() + ", subject=" + username;
+ }
+
+ public static String getSubjectName(Subject subject) {
+ return subject.getPrincipals().stream().filter(principal -> principal instanceof UserPrincipal).findFirst().map(Principal::getName).orElse(KeycloakIdentityProvider.getSubjectName(subject));
}
public RemotingConnection getConnectionFromClientID(String clientID) {
@@ -478,10 +534,16 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
}
}
+ if (connection == null) {
+ // Look in the recently disconnected cache
+ connection = disconnectedConnectionCache.getIfPresent(clientID);
+ }
+
return connection;
}
// TODO: Remove this if/when ActiveMQ implements https://issues.apache.org/jira/browse/ARTEMIS-4059
+
/**
* Tries to find the correct {@link RemotingConnection} for the specified subject with the assumption that the
* client ID is contained in the address (this is important for multiple connections from the same subject)
@@ -495,23 +557,23 @@ public class MQTTBrokerService extends RouteBuilder implements ContainerService,
return server.getActiveMQServer().getRemotingService().getConnections().stream().filter(connection ->
connection.getSubject() == subject && Objects.equals(clientID, connection.getClientID())
- )
- .findFirst()
- .orElse(null);
+ )
+ .findFirst()
+ .orElse(null);
}
// TODO: Remove this
public void addTransientCredentials(RemotingConnection connection, Triple<String, String, String> userIDNameAndPassword) {
LOG.fine("Adding transient user credentials: connection ID=" + connection.getID() + " ,username=" + userIDNameAndPassword.getMiddle());
transientCredentials.put(connection.getID(), userIDNameAndPassword);
- ((SecurityStoreImpl)server.getActiveMQServer().getSecurityStore()).invalidateAuthenticationCache();
+ ((SecurityStoreImpl) server.getActiveMQServer().getSecurityStore()).invalidateAuthenticationCache();
}
// TODO: Remove this
public void removeTransientCredentials(RemotingConnection connection) {
LOG.fine("Removing transient user credentials: connection ID=" + connection.getID());
transientCredentials.remove(connection.getID());
- ((SecurityStoreImpl)server.getActiveMQServer().getSecurityStore()).invalidateAuthenticationCache();
- ((SecurityStoreImpl)server.getActiveMQServer().getSecurityStore()).invalidateAuthorizationCache();
+ ((SecurityStoreImpl) server.getActiveMQServer().getSecurityStore()).invalidateAuthenticationCache();
+ ((SecurityStoreImpl) server.getActiveMQServer().getSecurityStore()).invalidateAuthorizationCache();
}
}
diff --git a/manager/src/main/java/org/openremote/manager/mqtt/MQTTHandler.java b/manager/src/main/java/org/openremote/manager/mqtt/MQTTHandler.java
index f33c33269..0ae2a95ca 100644
--- a/manager/src/main/java/org/openremote/manager/mqtt/MQTTHandler.java
+++ b/manager/src/main/java/org/openremote/manager/mqtt/MQTTHandler.java
@@ -44,7 +44,7 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
-import static org.openremote.manager.mqtt.MQTTBrokerService.connectionToString;
+import static org.openremote.manager.mqtt.MQTTBrokerService.LOG;
/**
* This allows custom handlers to be discovered by the {@link MQTTBrokerService} during system startup using the
@@ -79,7 +79,7 @@ public abstract class MQTTHandler {
/**
* Called when the system starts to allow for initialisation.
*/
- public void start(Container container) throws Exception {
+ public void init(Container container) throws Exception {
mqttBrokerService = container.getService(MQTTBrokerService.class);
clientEventService = container.getService(ClientEventService.class);
messageBrokerService = container.getService(MessageBrokerService.class);
@@ -92,7 +92,12 @@ public abstract class MQTTHandler {
isKeycloak = true;
identityProvider = (ManagerKeycloakIdentityProvider) identityService.getIdentityProvider();
}
+ }
+ /**
+ * Called when the system starts to allow for initialisation.
+ */
+ public void start(Container container) throws Exception {
Set<String> publishListenerTopics = getPublishListenerTopics();
if (publishListenerTopics != null) {
publishListenerTopics.forEach(this::addPublishConsumer);
@@ -109,7 +114,14 @@ public abstract class MQTTHandler {
Topic publishTopic = Topic.parse(MQTTUtil.convertCoreAddressToMqttTopicFilter(message.getAddress(), mqttBrokerService.wildcardConfiguration));
String clientID = message.getStringProperty(MessageUtil.CONNECTION_ID_PROPERTY_NAME);
RemotingConnection connection = mqttBrokerService.getConnectionFromClientID(clientID);
+
+ if (connection == null) {
+ LOG.warning("Failed to find connection for connected client so dropping publish to topic '" + topic + "': clientID=" + clientID);
+ return;
+ }
+
onPublish(connection, publishTopic, message.getReadOnlyBodyBuffer().byteBuf());
+ getLogger().info("Client published '" + topic + "': " + mqttBrokerService.connectionToString(connection));
});
} catch (ActiveMQException e) {
getLogger().log(Level.WARNING, "Failed to create handler consumer for topic '" + topic + "': handler=" + getName(), e);
@@ -167,11 +179,11 @@ public abstract class MQTTHandler {
*/
public boolean checkCanSubscribe(RemotingConnection connection, KeycloakSecurityContext securityContext, Topic topic) {
if (securityContext == null) {
- getLogger().finest("Anonymous connection subscriptions not supported by this handler, topic=" + topic + ", " + connectionToString(connection));
+ getLogger().finest("Anonymous connection subscriptions not supported by this handler, topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
if (!topicRealmAllowed(securityContext, topic) || !topicClientIdMatches(connection, topic)) {
- getLogger().fine("Topic realm and client ID tokens must match the connection, topic=" + topic + ", " + connectionToString(connection));
+ getLogger().fine("Topic realm and client ID tokens must match the connection, topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
return canSubscribe(connection, securityContext, topic);
@@ -183,11 +195,11 @@ public abstract class MQTTHandler {
*/
public boolean checkCanPublish(RemotingConnection connection, KeycloakSecurityContext securityContext, Topic topic) {
if (securityContext == null) {
- getLogger().fine("Anonymous connection publishes not supported by this handler, topic=" + topic + ", " + connectionToString(connection));
+ getLogger().fine("Anonymous connection publishes not supported by this handler, topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
if (!topicRealmAllowed(securityContext, topic) || !topicClientIdMatches(connection, topic)) {
- getLogger().fine("Topic realm and client ID tokens must match the connection, topic=" + topic + ", " + connectionToString(connection));
+ getLogger().fine("Topic realm and client ID tokens must match the connection, topic=" + topic + ", " + mqttBrokerService.connectionToString(connection));
return false;
}
return canPublish(connection, securityContext, topic);
diff --git a/manager/src/main/java/org/openremote/manager/notification/NotificationResourceImpl.java b/manager/src/main/java/org/openremote/manager/notification/NotificationResourceImpl.java
index f9b747b1f..f23225789 100644
--- a/manager/src/main/java/org/openremote/manager/notification/NotificationResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/notification/NotificationResourceImpl.java
@@ -113,8 +113,11 @@ public class NotificationResourceImpl extends WebResource implements Notificatio
headers.put(Constants.AUTH_CONTEXT, getAuthContext());
}
- boolean success = messageBrokerService.getProducerTemplate().requestBodyAndHeaders(
- NotificationService.NOTIFICATION_QUEUE, notification, headers, Boolean.class);
+ boolean success = messageBrokerService.getFluentProducerTemplate()
+ .withBody(notification)
+ .withHeaders(headers)
+ .to(NotificationService.NOTIFICATION_QUEUE)
+ .request(Boolean.class);
if (!success) {
throw new WebApplicationException(BAD_REQUEST);
diff --git a/manager/src/main/java/org/openremote/manager/notification/NotificationService.java b/manager/src/main/java/org/openremote/manager/notification/NotificationService.java
index d8253840f..82accaed9 100644
--- a/manager/src/main/java/org/openremote/manager/notification/NotificationService.java
+++ b/manager/src/main/java/org/openremote/manager/notification/NotificationService.java
@@ -99,7 +99,7 @@ public class NotificationService extends RouteBuilder implements ContainerServic
logger.log(Level.WARNING, error.toString(), exception);
}
- exchange.getOut().setBody(false);
+ exchange.getMessage().setBody(false);
};
}
@@ -292,7 +292,7 @@ public class NotificationService extends RouteBuilder implements ContainerServic
}
);
- exchange.getOut().setBody(success.get());
+ exchange.getMessage().setBody(success.get());
})
.endDoTry()
.doCatch(NotificationProcessingException.class)
@@ -307,7 +307,7 @@ public class NotificationService extends RouteBuilder implements ContainerServic
Map<String, Object> headers = new HashMap<>();
headers.put(Notification.HEADER_SOURCE, source);
headers.put(Notification.HEADER_SOURCE_ID, sourceId);
- return messageBrokerService.getProducerTemplate().requestBodyAndHeaders(NotificationService.NOTIFICATION_QUEUE, notification, headers, Boolean.class);
+ return messageBrokerService.getFluentProducerTemplate().withBody(notification).withHeaders(headers).to(NotificationService.NOTIFICATION_QUEUE).request(Boolean.class);
}
public void setNotificationDelivered(long id) {
diff --git a/manager/src/main/java/org/openremote/manager/provisioning/UserAssetProvisioningMQTTHandler.java b/manager/src/main/java/org/openremote/manager/provisioning/UserAssetProvisioningMQTTHandler.java
index d9ca33588..bcbd7a283 100644
--- a/manager/src/main/java/org/openremote/manager/provisioning/UserAssetProvisioningMQTTHandler.java
+++ b/manager/src/main/java/org/openremote/manager/provisioning/UserAssetProvisioningMQTTHandler.java
@@ -58,7 +58,6 @@ import java.util.logging.Logger;
import static org.openremote.container.persistence.PersistenceService.PERSISTENCE_TOPIC;
import static org.openremote.container.persistence.PersistenceService.isPersistenceEventForEntityType;
-import static org.openremote.manager.mqtt.MQTTBrokerService.connectionToString;
import static org.openremote.model.Constants.RESTRICTED_USER_REALM_ROLE;
import static org.openremote.model.syslog.SyslogCategory.API;
@@ -219,7 +218,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {
ProvisioningMessage provisioningMessage = ValueUtil.parse(payloadContent, ProvisioningMessage.class)
.orElseGet(() -> {
- LOG.fine("Failed to parse message from client: topic=" + topic+ connectionToString(connection));
+ LOG.fine("Failed to parse message from client: topic=" + topic+ mqttBrokerService.connectionToString(connection));
mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.MESSAGE_INVALID), MqttQoS.AT_MOST_ONCE);
return null;
});
@@ -263,10 +262,10 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {
protected void processX509ProvisioningMessage(RemotingConnection connection, Topic topic, X509ProvisioningMessage provisioningMessage) {
- LOG.finer("Processing provisioning message on: topic=" + topic + connectionToString(connection));
+ LOG.finer("Processing provisioning message on: topic=" + topic + mqttBrokerService.connectionToString(connection));
if (TextUtil.isNullOrEmpty(provisioningMessage.getCert())) {
- LOG.info("Certificate is missing from X509 provisioning message: topic=" + topic + connectionToString(connection));
+ LOG.info("Certificate is missing from X509 provisioning message: topic=" + topic + mqttBrokerService.connectionToString(connection));
mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.CERTIFICATE_INVALID), MqttQoS.AT_MOST_ONCE);
return;
}
@@ -276,7 +275,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {
try {
clientCertificate = ProvisioningUtil.getX509Certificate(provisioningMessage.getCert());
} catch (CertificateException e) {
- LOG.log(Level.INFO, "Failed to parse client X.509 certificate: topic=" + topic+ connectionToString(connection), e);
+ LOG.log(Level.INFO, "Failed to parse client X.509 certificate: topic=" + topic+ mqttBrokerService.connectionToString(connection), e);
mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.CERTIFICATE_INVALID), MqttQoS.AT_MOST_ONCE);
return;
}
@@ -284,14 +283,14 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {
X509ProvisioningConfig matchingConfig = getMatchingX509ProvisioningConfig(connection, clientCertificate);
if (matchingConfig == null) {
- LOG.fine("No matching provisioning config found for client certificate: topic=" + topic+ connectionToString(connection));
+ LOG.fine("No matching provisioning config found for client certificate: topic=" + topic+ mqttBrokerService.connectionToString(connection));
mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.UNAUTHORIZED), MqttQoS.AT_MOST_ONCE);
return;
}
// Check if config is disabled
if (matchingConfig.isDisabled()) {
- LOG.fine("Matching provisioning config is disabled for client certificate: topic=" + topic+ connectionToString(connection));
+ LOG.fine("Matching provisioning config is disabled for client certificate: topic=" + topic+ mqttBrokerService.connectionToString(connection));
mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.CONFIG_DISABLED), MqttQoS.AT_MOST_ONCE);
return;
}
@@ -301,13 +300,13 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {
String uniqueId = topicTokenIndexToString(topic, 1);
if (TextUtil.isNullOrEmpty(certUniqueId)) {
- LOG.info("Client X.509 certificate missing unique ID in subject CN: topic=" + topic+ connectionToString(connection));
+ LOG.info("Client X.509 certificate missing unique ID in subject CN: topic=" + topic+ mqttBrokerService.connectionToString(connection));
mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.UNIQUE_ID_MISMATCH), MqttQoS.AT_MOST_ONCE);
return;
}
if (TextUtil.isNullOrEmpty(uniqueId) || !certUniqueId.equals(uniqueId)) {
- LOG.info("Client X.509 certificate unique ID doesn't match topic unique ID: topic=" + topic+ connectionToString(connection));
+ LOG.info("Client X.509 certificate unique ID doesn't match topic unique ID: topic=" + topic+ mqttBrokerService.connectionToString(connection));
mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.UNIQUE_ID_MISMATCH), MqttQoS.AT_MOST_ONCE);
return;
}
@@ -327,7 +326,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {
if (serviceUser != null) {
if (!serviceUser.getEnabled()) {
- LOG.info("Client service user has been disabled: topic=" + topic+ connectionToString(connection));
+ LOG.info("Client service user has been disabled: topic=" + topic+ mqttBrokerService.connectionToString(connection));
mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.USER_DISABLED), MqttQoS.AT_MOST_ONCE);
return;
}
@@ -335,7 +334,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {
serviceUser = createClientServiceUser(realm, serviceUsername, matchingConfig);
}
} catch (Exception e) {
- LOG.log(Level.WARNING, "Failed to retrieve/create service user: topic=" + topic+ connectionToString(connection), e);
+ LOG.log(Level.WARNING, "Failed to retrieve/create service user: topic=" + topic+ mqttBrokerService.connectionToString(connection), e);
mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.SERVER_ERROR), MqttQoS.AT_MOST_ONCE);
return;
}
@@ -344,17 +343,17 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {
// Prepend realm name to unique ID to generate asset ID to further improve uniqueness
String assetId = UniqueIdentifierGenerator.generateId(matchingConfig.getRealm() + uniqueId);
- LOG.fine("Client unique ID '" + uniqueId + "' mapped to asset ID '" + assetId + "': topic=" + topic+ connectionToString(connection));
+ LOG.fine("Client unique ID '" + uniqueId + "' mapped to asset ID '" + assetId + "': topic=" + topic+ mqttBrokerService.connectionToString(connection));
try {
// Look for existing asset
asset = assetStorageService.find(assetId);
if (asset != null) {
- LOG.finer("Client asset found: topic=" + topic+ connectionToString(connection) + ", assetId=" + assetId);
+ LOG.finer("Client asset found: topic=" + topic+ mqttBrokerService.connectionToString(connection) + ", assetId=" + assetId);
if (!matchingConfig.getRealm().equals(asset.getRealm())) {
- LOG.info("Client asset realm mismatch : topic=" + topic+ connectionToString(connection) + ", assetId=" + assetId);
+ LOG.info("Client asset realm mismatch : topic=" + topic+ mqttBrokerService.connectionToString(connection) + ", assetId=" + assetId);
mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.ASSET_ERROR), MqttQoS.AT_MOST_ONCE);
return;
}
@@ -362,12 +361,12 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {
asset = createClientAsset(realm, assetId, uniqueId, serviceUser, matchingConfig);
}
} catch (Exception e) {
- LOG.log(Level.WARNING, "Failed to retrieve/create asset: topic=" + topic+ connectionToString(connection) + ", config=" + matchingConfig, e);
+ LOG.log(Level.WARNING, "Failed to retrieve/create asset: topic=" + topic+ mqttBrokerService.connectionToString(connection) + ", config=" + matchingConfig, e);
mqttBrokerService.publishMessage(getResponseTopic(topic), new ErrorResponseMessage(ErrorResponseMessage.Error.SERVER_ERROR), MqttQoS.AT_MOST_ONCE);
return;
}
- LOG.fine("Client successfully initialised: topic=" + topic+ connectionToString(connection) + ", config=" + matchingConfig);
+ LOG.fine("Client successfully initialised: topic=" + topic+ mqttBrokerService.connectionToString(connection) + ", config=" + matchingConfig);
// Update connection with service user credentials
mqttBrokerService.addTransientCredentials(connection, new ImmutableTriple<>(serviceUser.getId(), realm + ":" + serviceUser.getUsername(), serviceUser.getSecret()));
@@ -489,6 +488,7 @@ public class UserAssetProvisioningMQTTHandler extends MQTTHandler {
// Force disconnect of each connection and the disconnect handler will remove the connection from the map
connections.forEach(connection -> {
try {
+ LOG.finer("Force disconnecting client that is using provisioning config ID '" + provisioningConfigId + "': " + mqttBrokerService.connectionToString(connection));
connection.disconnect(false);
} catch (Exception e) {
getLogger().log(Level.INFO, "Failed to disconnect client: connection=" + connection, e);
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java
index e8d42f02c..e83b92591 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java
@@ -30,8 +30,6 @@ import org.openremote.model.util.ValueUtil;
public class RulesHealthStatusProvider implements HealthStatusProvider, ContainerService {
public static final String NAME = "rules";
- public static final String VERSION = "1.0";
-
protected RulesService rulesService;
@Override
@@ -59,11 +57,6 @@ public class RulesHealthStatusProvider implements HealthStatusProvider, Containe
return NAME;
}
- @Override
- public String getHealthStatusVersion() {
- return VERSION;
- }
-
@Override
public Object getHealthStatus() {
int totalEngines = rulesService.realmEngines.size() + rulesService.assetEngines.size();
diff --git a/manager/src/main/java/org/openremote/manager/system/CamelHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/system/CamelHealthStatusProvider.java
new file mode 100644
index 000000000..765223d6e
--- /dev/null
+++ b/manager/src/main/java/org/openremote/manager/system/CamelHealthStatusProvider.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2022, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.system;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.camel.Endpoint;
+import org.apache.camel.component.seda.SedaEndpoint;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.support.service.BaseService;
+import org.openremote.container.message.MessageBrokerService;
+import org.openremote.model.Container;
+import org.openremote.model.ContainerService;
+import org.openremote.model.system.HealthStatusProvider;
+import org.openremote.model.util.ValueUtil;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class CamelHealthStatusProvider implements HealthStatusProvider, ContainerService {
+
+ public static final String NAME = "camel";
+ protected MessageBrokerService brokerService;
+
+ @Override
+ public void init(Container container) throws Exception {
+ brokerService = container.getService(MessageBrokerService.class);
+ // Add mixin for health check results
+ ValueUtil.JSON.addMixIn(HealthCheck.Result.class, HealthCheckResultMixin.class);
+ }
+
+ @Override
+ public void start(Container container) throws Exception {
+
+ }
+
+ @Override
+ public void stop(Container container) throws Exception {
+
+ }
+
+ @Override
+ public String getHealthStatusName() {
+ return NAME;
+ }
+
+ @Override
+ public Object getHealthStatus() {
+ Map<String, Object> result = new HashMap<>();
+ ArrayNode endpointInfos = ValueUtil.JSON.createArrayNode();
+
+ for (Endpoint endpoint : brokerService.getContext().getEndpoints()) {
+ ObjectNode endpointInfo = ValueUtil.createJsonObject();
+ endpointInfo.put("uri", endpoint.getEndpointUri());
+ if (endpoint instanceof BaseService baseService) {
+ endpointInfo.put("status", baseService.getStatus().name());
+ }
+ if (endpoint instanceof SedaEndpoint sedaEndpoint) {
+ endpointInfo.put("queueSize", sedaEndpoint.getCurrentQueueSize());
+ endpointInfo.put("queueMax", sedaEndpoint.getSize());
+ }
+ endpointInfos.add(endpointInfo);
+ }
+
+ result.put("healthChecks", HealthCheckHelper.invoke(brokerService.getContext()));
+ result.put("endpoints", endpointInfos);
+ return result;
+ }
+}
diff --git a/manager/src/main/java/org/openremote/manager/system/HealthCheckResultMixin.java b/manager/src/main/java/org/openremote/manager/system/HealthCheckResultMixin.java
new file mode 100644
index 000000000..2c08099cf
--- /dev/null
+++ b/manager/src/main/java/org/openremote/manager/system/HealthCheckResultMixin.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2022, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.system;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer;
+import org.apache.camel.health.HealthCheck;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Optional;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public interface HealthCheckResultMixin {
+
+ class HealthCheckSerializer extends StdScalarSerializer<HealthCheck> {
+ public HealthCheckSerializer() {
+ super(HealthCheck.class, false);
+ }
+
+ @Override
+ public void serialize(HealthCheck value, JsonGenerator g, SerializerProvider provider) throws IOException
+ {
+ g.writeString(value.getClass().getSimpleName());
+ }
+ }
+
+ @JsonSerialize(using = HealthCheckSerializer.class)
+ @JsonProperty("type")
+ HealthCheck getCheck();
+
+ @JsonProperty
+ HealthCheck.State getState();
+
+ @JsonProperty
+ Optional<String> getMessage();
+
+ @JsonProperty
+ Optional<Throwable> getError();
+
+ @JsonProperty
+ Map<String, Object> getDetails();
+}
diff --git a/manager/src/main/java/org/openremote/manager/system/JvmHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/system/JvmHealthStatusProvider.java
index 4cd1d972e..9fc8f785f 100644
--- a/manager/src/main/java/org/openremote/manager/system/JvmHealthStatusProvider.java
+++ b/manager/src/main/java/org/openremote/manager/system/JvmHealthStatusProvider.java
@@ -33,7 +33,6 @@ import java.lang.management.ThreadMXBean;
public class JvmHealthStatusProvider implements HealthStatusProvider, ContainerService {
public static final String NAME = "jvm";
- public static final String VERSION = "1.0";
@Override
public int getPriority() {
@@ -60,11 +59,6 @@ public class JvmHealthStatusProvider implements HealthStatusProvider, ContainerS
return NAME;
}
- @Override
- public String getHealthStatusVersion() {
- return VERSION;
- }
-
@Override
public Object getHealthStatus() {
ObjectNode objectValue = ValueUtil.createJsonObject();
diff --git a/manager/src/main/java/org/openremote/manager/system/SslHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/system/SslHealthStatusProvider.java
index 3cd1372ed..1d138344e 100644
--- a/manager/src/main/java/org/openremote/manager/system/SslHealthStatusProvider.java
+++ b/manager/src/main/java/org/openremote/manager/system/SslHealthStatusProvider.java
@@ -43,7 +43,6 @@ import static org.openremote.container.util.MapAccess.getString;
public class SslHealthStatusProvider implements X509TrustManager, HealthStatusProvider, ContainerService {
public static final String NAME = "ssl";
- public static final String VERSION = "1.0";
protected static final Logger LOG = Logger.getLogger(SslHealthStatusProvider.class.getName());
protected String host;
protected int SSLPort;
@@ -85,11 +84,6 @@ public class SslHealthStatusProvider implements X509TrustManager, HealthStatusPr
return NAME;
}
- @Override
- public String getHealthStatusVersion() {
- return VERSION;
- }
-
@Override
public Object getHealthStatus() {
if (SSLContext == null) {
diff --git a/manager/src/main/java/org/openremote/manager/system/StatusResourceImpl.java b/manager/src/main/java/org/openremote/manager/system/StatusResourceImpl.java
index b106fa4c1..7504516ea 100644
--- a/manager/src/main/java/org/openremote/manager/system/StatusResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/system/StatusResourceImpl.java
@@ -69,7 +69,6 @@ public class StatusResourceImpl implements StatusResource {
healthStatusProviderList.forEach(healthStatusProvider -> {
ObjectNode providerValue = ValueUtil.JSON.createObjectNode();
- providerValue.put("version", healthStatusProvider.getHealthStatusVersion());
providerValue.putPOJO("data", healthStatusProvider.getHealthStatus());
objectValue.set(healthStatusProvider.getHealthStatusName(), providerValue);
}
diff --git a/manager/src/main/java/org/openremote/manager/system/SystemHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/system/SystemHealthStatusProvider.java
index bca6cafa7..5b9575da3 100644
--- a/manager/src/main/java/org/openremote/manager/system/SystemHealthStatusProvider.java
+++ b/manager/src/main/java/org/openremote/manager/system/SystemHealthStatusProvider.java
@@ -31,7 +31,6 @@ import java.lang.management.ManagementFactory;
public class SystemHealthStatusProvider implements HealthStatusProvider, ContainerService {
public static final String NAME = "system";
- public static final String VERSION = "1.0";
@Override
public int getPriority() {
@@ -58,11 +57,6 @@ public class SystemHealthStatusProvider implements HealthStatusProvider, Contain
return NAME;
}
- @Override
- public String getHealthStatusVersion() {
- return VERSION;
- }
-
@Override
public Object getHealthStatus() {
ObjectNode objectValue = ValueUtil.JSON.createObjectNode();
diff --git a/manager/src/main/resources/META-INF/services/org.openremote.model.system.HealthStatusProvider b/manager/src/main/resources/META-INF/services/org.openremote.model.system.HealthStatusProvider
index 88c14ee45..bdbbc87f0 100644
--- a/manager/src/main/resources/META-INF/services/org.openremote.model.system.HealthStatusProvider
+++ b/manager/src/main/resources/META-INF/services/org.openremote.model.system.HealthStatusProvider
@@ -5,3 +5,4 @@ org.openremote.manager.rules.RulesHealthStatusProvider
org.openremote.manager.agent.AgentHealthStatusProvider
org.openremote.manager.datapoint.AssetDatapointHealthStatusProvider
org.openremote.manager.datapoint.AssetPredictedDatapointHealthStatusProvider
+org.openremote.manager.system.CamelHealthStatusProvider
diff --git a/manager/src/main/resources/logging.properties b/manager/src/main/resources/logging.properties
index ac3433fe6..4cef6ba20 100644
--- a/manager/src/main/resources/logging.properties
+++ b/manager/src/main/resources/logging.properties
@@ -79,3 +79,5 @@ org.apache.camel.impl.converter.DefaultTypeConverter.level=WARNING
org.apache.camel.impl.DefaultShutdownStrategy.level=SEVERE
org.jeasy.rules.level=WARNING
org.postgresql.jdbc.level=INFO
+org.apache.activemq.audit.resource.level=INFO
+org.apache.activemq.audit.level=INFO
diff --git a/model/src/main/java/org/openremote/model/event/shared/EventSubscription.java b/model/src/main/java/org/openremote/model/event/shared/EventSubscription.java
index 5938a162b..a8faab0df 100644
--- a/model/src/main/java/org/openremote/model/event/shared/EventSubscription.java
+++ b/model/src/main/java/org/openremote/model/event/shared/EventSubscription.java
@@ -21,7 +21,6 @@ package org.openremote.model.event.shared;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openremote.model.event.Event;
-import org.openremote.model.event.TriggeredEventSubscription;
import java.util.function.Consumer;
diff --git a/model/src/main/java/org/openremote/model/event/shared/SharedEvent.java b/model/src/main/java/org/openremote/model/event/shared/SharedEvent.java
index 386ebebc8..e94b547cf 100644
--- a/model/src/main/java/org/openremote/model/event/shared/SharedEvent.java
+++ b/model/src/main/java/org/openremote/model/event/shared/SharedEvent.java
@@ -19,7 +19,6 @@
*/
package org.openremote.model.event.shared;
-import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.openremote.model.asset.*;
diff --git a/model/src/main/java/org/openremote/model/system/HealthStatusProvider.java b/model/src/main/java/org/openremote/model/system/HealthStatusProvider.java
index 96ca239e1..f6a0fb95a 100644
--- a/model/src/main/java/org/openremote/model/system/HealthStatusProvider.java
+++ b/model/src/main/java/org/openremote/model/system/HealthStatusProvider.java
@@ -26,7 +26,5 @@ public interface HealthStatusProvider {
String getHealthStatusName();
- String getHealthStatusVersion();
-
Object getHealthStatus();
}
diff --git a/profile/deploy.yml b/profile/deploy.yml
index 9ce0913c5..120cc0954 100644
--- a/profile/deploy.yml
+++ b/profile/deploy.yml
@@ -295,12 +295,13 @@ services:
# API key for the API of ForecastSolar: https://forecast.solar
# OR_FORECAST_SOLAR_API_KEY
- # Custom JVM options (increase heap size if required)
- OR_JAVA_OPTS: ${OR_JAVA_OPTS:--Xms400m -Xmx400m
- -XX:CompressedClassSpaceSize=25m -XX:MaxMetaspaceSize=150m
- -XX:InitialCodeCacheSize=50m -XX:ReservedCodeCacheSize=50m
- -XX:MaxDirectMemorySize=25m -XX:NativeMemoryTracking=summary
- -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/javadump.core.hprof}
+ # Custom JVM options (override default manager options)
+# OR_JAVA_OPTS: ${OR_JAVA_OPTS:--Xms500m -Xmx2g
+# -XX:NativeMemoryTracking=summary
+# -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10
+# -XX:GCLogFileSize=50M -Xloggc:/gc.log
+# -XX:OnOutOfMemoryError="shutdown -r" -d64
+# -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dump.hprof}
# Custom JVM tool options (for remote debugging)
#JAVA_TOOL_OPTIONS: '-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n'
diff --git a/setup/src/load1/java/org/openremote/setup/load1/AttributeValueGeneratorService.java b/setup/src/load1/java/org/openremote/setup/load1/AttributeValueGeneratorService.java
new file mode 100644
index 000000000..610748d33
--- /dev/null
+++ b/setup/src/load1/java/org/openremote/setup/load1/AttributeValueGeneratorService.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2022, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.setup.load1;
+
+import org.apache.activemq.artemis.utils.collections.ConcurrentHashSet;
+import org.apache.camel.builder.RouteBuilder;
+import org.openremote.container.message.MessageBrokerService;
+import org.openremote.manager.asset.AssetProcessingService;
+import org.openremote.model.Container;
+import org.openremote.model.ContainerService;
+import org.openremote.model.PersistenceEvent;
+import org.openremote.model.asset.Asset;
+import org.openremote.model.asset.impl.WeatherAsset;
+import org.openremote.model.attribute.AttributeEvent;
+
+import java.util.Set;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Logger;
+
+import static org.apache.camel.builder.PredicateBuilder.and;
+import static org.openremote.container.persistence.PersistenceService.PERSISTENCE_TOPIC;
+import static org.openremote.container.persistence.PersistenceService.isPersistenceEventForEntityType;
+
+/**
+ * This service listens for {@link org.openremote.model.asset.impl.WeatherAsset}s to be added to the system then
+ * it generates attribute updates for the {@link WeatherAsset#RAINFALL} and {@link WeatherAsset#TEMPERATURE} attributes
+ * periodically
+ */
+public class AttributeValueGeneratorService extends RouteBuilder implements ContainerService {
+
+ protected final int UPDATE_MILLIS = 5000;
+ protected static final Logger LOG = Logger.getLogger(AttributeValueGeneratorService.class.getName());
+ protected AssetProcessingService assetProcessingService;
+ protected ScheduledExecutorService executorService;
+ protected Set<String> assetIds = new ConcurrentHashSet<>();
+ protected ScheduledFuture<?> updater;
+
+ @Override
+ public void init(Container container) throws Exception {
+ assetProcessingService = container.getService(AssetProcessingService.class);
+ executorService = container.getExecutorService();
+ container.getService(MessageBrokerService.class).getContext().addRoutes(this);
+ }
+
+ @Override
+ public void start(Container container) throws Exception {
+ updater = executorService.scheduleWithFixedDelay(this::sendValues, UPDATE_MILLIS, UPDATE_MILLIS, TimeUnit.MILLISECONDS);
+ }
+
+ @Override
+ public void stop(Container container) throws Exception {
+ if (updater != null) {
+ updater.cancel(true);
+ }
+ updater = null;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void configure() throws Exception {
+ // If any asset was modified in the database, detect changed attributes
+ from(PERSISTENCE_TOPIC)
+ .routeId("WeatherAssetChanges")
+ .filter(and(isPersistenceEventForEntityType(Asset.class), exchange -> {
+ PersistenceEvent<Asset<?>> persistenceEvent = exchange.getIn().getBody(PersistenceEvent.class);
+ return persistenceEvent.getEntity() instanceof WeatherAsset && persistenceEvent.getCause() == PersistenceEvent.Cause.CREATE;
+ }))
+ .process(exchange -> {
+ PersistenceEvent<Asset<?>> persistenceEvent = exchange.getIn().getBody(PersistenceEvent.class);
+ onAssetCreated((WeatherAsset)persistenceEvent.getEntity());
+ });
+ }
+
+ protected void onAssetCreated(WeatherAsset weatherAsset) {
+ assetIds.add(weatherAsset.getId());
+ }
+
+ protected void sendValues() {
+ for (String assetId : assetIds) {
+ LOG.fine("Updating attributes on asset ID: " + assetId);
+ assetProcessingService.sendAttributeEvent(new AttributeEvent(assetId, WeatherAsset.TEMPERATURE, Math.random()*40));
+ assetProcessingService.sendAttributeEvent(new AttributeEvent(assetId, WeatherAsset.RAINFALL, Math.random()*10));
+ }
+ }
+}
diff --git a/setup/src/load1/java/org/openremote/setup/load1/ManagerSetup.java b/setup/src/load1/java/org/openremote/setup/load1/ManagerSetup.java
index 9cd0a159c..d51f42da9 100644
--- a/setup/src/load1/java/org/openremote/setup/load1/ManagerSetup.java
+++ b/setup/src/load1/java/org/openremote/setup/load1/ManagerSetup.java
@@ -22,12 +22,14 @@ package org.openremote.setup.load1;
import org.apache.commons.io.IOUtils;
import org.openremote.manager.provisioning.ProvisioningService;
+import org.openremote.model.Constants;
import org.openremote.model.Container;
import org.openremote.model.asset.impl.WeatherAsset;
import org.openremote.model.attribute.Attribute;
import org.openremote.model.attribute.MetaItem;
import org.openremote.model.provisioning.X509ProvisioningConfig;
import org.openremote.model.provisioning.X509ProvisioningData;
+import org.openremote.model.rules.RealmRuleset;
import org.openremote.model.security.ClientRole;
import org.openremote.model.util.ValueUtil;
import org.openremote.model.value.MetaItemType;
@@ -36,6 +38,7 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import static org.openremote.manager.provisioning.UserAssetProvisioningMQTTHandler.UNIQUE_ID_PLACEHOLDER;
+import static org.openremote.model.rules.Ruleset.Lang.GROOVY;
import static org.openremote.model.value.ValueType.NUMBER;
public class ManagerSetup extends org.openremote.manager.setup.ManagerSetup {
@@ -88,5 +91,13 @@ public class ManagerSetup extends org.openremote.manager.setup.ManagerSetup {
});
provisioningConfig = provisioningService.merge(provisioningConfig);
+
+ RealmRuleset ruleset = new RealmRuleset(
+ Constants.MASTER_REALM,
+ "Weather calculations",
+ GROOVY,
+ IOUtils.toString(getClass().getResource("/org/openremote/setup/load1/WeatherAssetCalculations.groovy"), StandardCharsets.UTF_8)
+ );
+ ruleset = rulesetStorageService.merge(ruleset);
}
}
diff --git a/setup/src/load1/resources/META-INF/services/org.openremote.model.ContainerService b/setup/src/load1/resources/META-INF/services/org.openremote.model.ContainerService
new file mode 100644
index 000000000..f0d4d9cf8
--- /dev/null
+++ b/setup/src/load1/resources/META-INF/services/org.openremote.model.ContainerService
@@ -0,0 +1 @@
+org.openremote.setup.load1.AttributeValueGeneratorService
diff --git a/setup/src/load1/resources/org/openremote/setup/load1/WeatherAssetCalculations.groovy b/setup/src/load1/resources/org/openremote/setup/load1/WeatherAssetCalculations.groovy
new file mode 100644
index 000000000..f1a955259
--- /dev/null
+++ b/setup/src/load1/resources/org/openremote/setup/load1/WeatherAssetCalculations.groovy
@@ -0,0 +1,63 @@
+package org.openremote.setup.load1
+
+import org.openremote.manager.rules.RulesBuilder
+import org.openremote.model.asset.impl.WeatherAsset
+import org.openremote.model.attribute.AttributeEvent
+import org.openremote.model.query.AssetQuery
+import org.openremote.model.rules.AssetState
+import org.openremote.model.rules.Assets
+import org.openremote.model.rules.Notifications
+import org.openremote.model.rules.Users
+
+import java.util.logging.Logger
+import java.util.stream.Collectors
+
+Logger LOG = binding.LOG
+RulesBuilder rules = binding.rules
+Users users = binding.users
+Notifications notifications = binding.notifications
+Assets assets = binding.assets
+
+// This rule updates an attribute called calculated for WeatherAssets by adding the rainfall and temperature attributes
+// (no practical use for this calculation, it is just for testing purposes). Whenever either of these values change
+// for an asset then the calculated attribute is updated.
+
+rules.add()
+ .name("Calculate weather asset calculated attribute")
+ .when(
+ { facts ->
+
+ List<AttributeEvent> updates = []
+
+ // Get weather asset rainfall and/or temperature states that have changed value
+ facts.matchAssetState(
+ new AssetQuery()
+ .types(WeatherAsset)
+ .attributeNames(WeatherAsset.TEMPERATURE.name, WeatherAsset.RAINFALL.name)
+ ).collect(Collectors.groupingBy{AssetState<?> state -> state.id})
+ .forEach{id, states ->
+ // See if either attribute has changed for this asset
+ if (states.any {state -> !Objects.equals(state.value.orElse(null), state.oldValue.orElse(null))}) {
+ def value1 = states[0].value.orElse(0) as float
+ def value2 = states[1].value.orElse(0) as float
+ def calculated = value1+value2
+ LOG.fine("Calculated new value for '$id': $calculated")
+ updates.add(new AttributeEvent(id, "calculated", calculated))
+ }
+ }
+
+ if (!updates.isEmpty()) {
+ facts.bind("updates", updates)
+ }
+
+ // Trigger the rule action if we have one or more changes to process
+ return !updates.isEmpty()
+ })
+ .then(
+ { facts ->
+ def updates = facts.bound("updates") as List<AttributeEvent>
+
+ updates.forEach {
+ assets.dispatch(it)
+ }
+ })
diff --git a/setup/src/load1/resources/org/openremote/setup/load1/ca.srl b/setup/src/load1/resources/org/openremote/setup/load1/ca.srl
new file mode 100644
index 000000000..6dc742638
--- /dev/null
+++ b/setup/src/load1/resources/org/openremote/setup/load1/ca.srl
@@ -0,0 +1 @@
+542AE76EF6F52D185F1EF1332339AD042EDA348D
diff --git a/test/load1/.gitignore b/test/load1/.gitignore
new file mode 100644
index 000000000..497f205c9
--- /dev/null
+++ b/test/load1/.gitignore
@@ -0,0 +1,2 @@
+output/**
+jmeter.log
diff --git a/test/load1/README.md b/test/load1/README.md
new file mode 100644
index 000000000..8413801cb
--- /dev/null
+++ b/test/load1/README.md
@@ -0,0 +1,27 @@
+# Load Test
+A load test that uses [Taurus](https://gettaurus.org/) to simulate:
+
+* 1 x Realm (master)
+* 1 x Auto provisioning config (WeatherAsset with a custom `calculated` attribute)
+* 1 x Realm rule that performs a simple calculation to calculate the `calculated` attribute value of WeatherAssets based
+on changes to `rainfall` and `temperature` attributes
+* N x auto provisioning MQTT devices connecting to the MQTT broker and:
+ * Subscribing to the auto provisioning response topic (1-N devices in M minutes)
+ * Publishing their provisioning config requests (1-N devices in M minutes with initial delay of 10s)
+ * Publishing two attribute values (temperature and rainfall)
+
+# Prerequisites
+
+* Bash shell
+* Java 17+
+* Taurus
+
+# Usage
+
+1. Run the `device_generator.sh COUNT` script to generate auto provisioning device X.509 certificates which are output to `tmp/devices.csv`
+the COUNT value is the number of devices to generate certificates for (default: 100)
+3. Run the manager using the `load1` setup
+4. Run Taurus:
+```
+bzt mqtt_auto_provision.yml
+```
diff --git a/test/load1/device_generator.sh b/test/load1/device_generator.sh
new file mode 100644
index 000000000..4ee1ece57
--- /dev/null
+++ b/test/load1/device_generator.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# Generates a CSV file of devices with device ID and X509 cert for each
+
+CA_KEY_PATH=../../setup/src/load1/resources/org/openremote/setup/load1/ca.key
+CA_PEM_PATH=../../setup/src/load1/resources/org/openremote/setup/load1/ca.pem
+DEVICE_PREFIX=device
+TEMP_CERT_DIR=tmp
+CSV_PATH="$TEMP_CERT_DIR/devices.csv"
+COUNT=${1,,}
+
+if [ -z "$COUNT" ]; then
+ COUNT=100
+fi
+
+if [ -f "$CSV_PATH" ]; then
+ echo "CSV file '$CSV_PATH' already exists"
+ exit 1
+fi
+
+if [ -d "$TEMP_CERT_DIR" ]; then
+ rm -f $TEMP_CERT_DIR
+fi
+
+mkdir $TEMP_CERT_DIR
+touch $CSV_PATH
+
+echo "Generating CSV file '$CSV_NAME' for $COUNT devices..."
+
+ i=1
+ while [ $i -le $COUNT ]; do
+ echo "Generating $DEVICE_PREFIX$i..."
+ openssl req -nodes --newkey rsa:4096 -keyout $TEMP_CERT_DIR/$DEVICE_PREFIX$i.key -subj "/C=NL/ST=North Brabant/O=OpenRemote/CN=$DEVICE_PREFIX$i" -out $TEMP_CERT_DIR/$DEVICE_PREFIX$i.csr
+ openssl x509 -req -in $TEMP_CERT_DIR/$DEVICE_PREFIX$i.csr -CA $CA_PEM_PATH -CAkey $CA_KEY_PATH -CAcreateserial -out $TEMP_CERT_DIR/$DEVICE_PREFIX$i.pem -days 500 -sha256
+
+ if [ $? -ne 0 ]; then
+ echo "Failed to sign device certificate"
+ exit 1
+ fi
+
+ echo -n "$DEVICE_PREFIX$i," >> $CSV_PATH
+ awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' $TEMP_CERT_DIR/$DEVICE_PREFIX$i.pem >> $CSV_PATH
+ echo "" >> $CSV_PATH
+ i=$((i+1))
+ done
+
+
diff --git a/test/load1/devices.csv b/test/load1/devices.csv
deleted file mode 100644
index 83fbb01ac..000000000
--- a/test/load1/devices.csv
+++ /dev/null
@@ -1,10 +0,0 @@
-device1,-----BEGIN CERTIFICATE-----\nMIIFYDCCA0gCFAFINYMIOiLOII64AG+rMJ6/ECraMA0GCSqGSIb3DQEBCwUAMIGM\nMQswCQYDVQQGEwJOTDEWMBQGA1UECAwNTm9ydGggQnJhYmFudDESMBAGA1UEBwwJ\nRWluZGhvdmVuMRMwEQYDVQQKDApPcGVuUmVtb3RlMRYwFAYDVQQDDA1vcGVucmVt\nb3RlLmlvMSQwIgYJKoZIhvcNAQkBFhVzdXBwb3J0QG9wZW5yZW1vdGUuaW8wHhcN\nMjIxMDI1MTMzNTExWhcNMjQwMzA4MTMzNTExWjBMMQswCQYDVQQGEwJOTDEWMBQG\nA1UECAwNTm9ydGggQnJhYmFudDETMBEGA1UECgwKT3BlblJlbW90ZTEQMA4GA1UE\nAwwHZGV2aWNlMTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAL3aC2do\nRh0U5OvxfFMgmwp6Y7itfv6uE8d0KU18PBsh+rxwcsqlesW/i/q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RX0lCc52onsb+VKbdsDJjNcMpEoZfjS/UCc5x/s1+8h3\nx8N16vOW6m3/OwqPBdrIIb4SV1L/8VjDMXTGn+hqE13G4y4qz1PbJsrOONZ3YQh7\n1YqGl5gbIUIlkxKl1aD8IS4fMsUj7+NKqIlQWkjEYzUhrwPxcXe8bUdPPeeH6DNL\nF1/gFXipzBWYRuaPlw1s2OL29FXMbVhtYwt1QnyHA+iriOMlBiIGj/uOWRtSjJXH\ncy0emozcKLcg527K6FKJH/nS1q+jM15TgHLb89Q0XHlDjROUVEb54vNAa3XmjUwi\n8C2NVYrGy+zq3EwdxJomTlpCTFggWRIvQpoph8IDz/0E875/W0BXe5wOwyOtulRJ\n0zAvCsn8SHSDyjm1dAZDKYnjqXZxaPCWKZ1P6x3iKBDtkiCqmKUUYQoYnImIaMsz\nwWBpz3N9/uHdLq7abQTxZOB/WGFWSDIorRAfqr39M2p/Q/pPVWvp1F6R1uSU7ncq\najPjjcJyD+Dq6hs2wWTRZiltYVavc0dQrsfxnWdl9Aj9/nli1w==\n-----END CERTIFICATE-----\n
diff --git a/test/load1/mqtt_auto_provision.yml b/test/load1/mqtt_auto_provision.yml
index bf144ae1b..b7c7f67a5 100644
--- a/test/load1/mqtt_auto_provision.yml
+++ b/test/load1/mqtt_auto_provision.yml
@@ -1,49 +1,40 @@
+settings:
+ artifacts-dir: ./output/%Y-%m-%d_%H-%M-%S.%f
+
+modules:
+ jmeter:
+ properties:
+ logfile: ./output/jmeter.log
+
execution:
-- concurrency: 1
- ramp-up: 1m
- hold-for: 5m
- scenario: mqtt-client-auto-provision-sub
-- concurrency: 1
- hold-for: 15s
+- concurrency: 20
+ ramp-up: 40s
+ iterations: 1
scenario: mqtt-client-auto-provision-pub
scenarios:
- mqtt-client-auto-provision-sub:
+ mqtt-client-auto-provision-pub:
protocol: mqtt
requests:
- cmd: connect
- addr: 127.0.0.1
+ addr: localhost
+ clientId: ${id}
+ - cmd: publish
+ topic: provisioning/${id}/request
+ message: "{\"type\":\"x509\",\"cert\":\"${cert}\"}"
- cmd: subscribe
- topic: provisioning/${id}/response
- time: 5s
+ topic: master/${id}/attributevalue/+/#
+ time: 10s
min-count: 1
+ think-time: 10s
- cmd: disconnect
data-sources:
- - devices.csv
+ - path: ./tmp/devices.csv
delimiter: ','
quoted: false
encoding: "utf-8"
- loop: true
+ loop: false
variable-names: id,cert
random-order: false
-
- mqtt-client-auto-provision-pub:
- protocol: mqtt
- requests:
- - cmd: connect
- addr: 127.0.0.1
- - cmd: publish
- topic: provisioning/${id}/request
- message: { "type" : "x509", "cert" : "${cert}"}
- - cmd: disconnect
-
- data-sources:
- - devices.csv
- delimiter: ','
- quoted: false
- encoding: "utf-8"
- loop: true
- variable-names: id,cert
- random-order: false
\ No newline at end of file
diff --git a/test/src/test/groovy/org/openremote/test/assets/AttributeLinkingTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AttributeLinkingTest.groovy
index c0809414b..2e576f7d9 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AttributeLinkingTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AttributeLinkingTest.groovy
@@ -82,6 +82,7 @@ class AttributeLinkingTest extends Specification implements ManagerContainerTrai
new AttributeState(new AttributeRef(asset1.id, "button"), "PRESSED")
)
assetProcessingService.sendAttributeEvent(buttonPressed)
+ Thread.sleep(200)
advancePseudoClock(1, TimeUnit.SECONDS, container)
def buttonReleased = new AttributeEvent(
new AttributeState(new AttributeRef(asset1.id, "button"), "RELEASED")
diff --git a/test/src/test/groovy/org/openremote/test/provisioning/UserAndAssetProvisioningTest.groovy b/test/src/test/groovy/org/openremote/test/provisioning/UserAndAssetProvisioningTest.groovy
index 2f7dee89a..a676d3846 100644
--- a/test/src/test/groovy/org/openremote/test/provisioning/UserAndAssetProvisioningTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/provisioning/UserAndAssetProvisioningTest.groovy
@@ -436,7 +436,7 @@ class UserAndAssetProvisioningTest extends Specification implements ManagerConta
then: "the connection should be removed from the broker"
conditions.eventually {
- assert mqttBrokerService.getConnectionFromClientID(mqttDeviceNClientId) == null
+ assert mqttBrokerService.clientIDConnectionMap.get(mqttDeviceNClientId) == null
assert deviceNClient.getConnectionStatus() == ConnectionStatus.DISCONNECTED
}
@@ -485,7 +485,7 @@ class UserAndAssetProvisioningTest extends Specification implements ManagerConta
then: "the connection should be removed from the broker"
conditions.eventually {
- assert mqttBrokerService.getConnectionFromClientID(mqttDeviceNClientId) == null
+ assert mqttBrokerService.clientIDConnectionMap.get(mqttDeviceNClientId) == null
assert deviceNClient.getConnectionStatus() == ConnectionStatus.DISCONNECTED
}
@@ -538,7 +538,7 @@ class UserAndAssetProvisioningTest extends Specification implements ManagerConta
then: "the connection should be removed from the broker"
conditions.eventually {
- assert mqttBrokerService.getConnectionFromClientID(mqttDeviceNClientId) == null
+ assert mqttBrokerService.clientIDConnectionMap.get(mqttDeviceNClientId) == null
assert deviceNClient.getConnectionStatus() == ConnectionStatus.DISCONNECTED
}
@@ -617,7 +617,7 @@ class UserAndAssetProvisioningTest extends Specification implements ManagerConta
then: "the connection should be removed from the broker"
conditions.eventually {
- assert mqttBrokerService.getConnectionFromClientID(mqttDeviceNClientId) == null
+ assert mqttBrokerService.clientIDConnectionMap.get(mqttDeviceNClientId) == null
assert deviceNClient.getConnectionStatus() == ConnectionStatus.DISCONNECTED
}
diff --git a/test/src/testFixtures/groovy/org/openremote/test/ContainerTrait.groovy b/test/src/testFixtures/groovy/org/openremote/test/ContainerTrait.groovy
index 81f256ed7..7762b21fb 100644
--- a/test/src/testFixtures/groovy/org/openremote/test/ContainerTrait.groovy
+++ b/test/src/testFixtures/groovy/org/openremote/test/ContainerTrait.groovy
@@ -200,6 +200,17 @@ trait ContainerTrait {
}
}
+ // Wait for system to settle down
+ def assetProcessingService = container.hasService(AssetProcessingService.class) ? container.getService(AssetProcessingService.class) : null
+ if (assetProcessingService != null) {
+ println("Waiting for the system to settle down")
+ def j=0
+ while (j < 100 && !noEventProcessedIn(assetProcessingService, 300)) {
+ Thread.sleep(100)
+ j++
+ }
+ }
+
// Reset assets
if (container.hasService(AgentService.class) && container.hasService(AssetStorageService.class)) {
def currentAssets = getAssets().collect { it.getId() }