Skip to content

armgit / core

Public Imported from GitHub
0

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

Renamed rules meta items and AssetUpdate to AssetState

Christian Bauerdc2f2bf0d406
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
index 8ff57773b..641274ff4 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
@@ -54,7 +54,7 @@ import static org.openremote.model.asset.AssetType.AGENT;
/**
* Finds all {@link AssetType#AGENT} and {@link AssetType#THING} assets and starts the protocols for them.
*/
-public class AgentService extends RouteBuilder implements ContainerService, Consumer<AssetUpdate> {
+public class AgentService extends RouteBuilder implements ContainerService, Consumer<AssetState> {
private static final Logger LOG = Logger.getLogger(AgentService.class.getName());
protected Container container;
@@ -384,39 +384,39 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
*
*/
@Override
- public void accept(AssetUpdate assetUpdate) {
+ public void accept(AssetState assetState) {
// If update was initiated by a protocol ignore it
- if (assetUpdate.isNorthbound()) {
- LOG.fine("Ignoring asset update as it came from a protocol:" + assetUpdate);
+ if (assetState.isNorthbound()) {
+ LOG.fine("Ignoring as it came from a protocol:" + assetState);
return;
}
- AttributeRef protocolRef = ThingAttribute.getProtocolRef(assetUpdate.getAttribute());
+ AttributeRef protocolRef = ThingAttribute.getProtocolRef(assetState.getAttribute());
if (protocolRef != null) {
// Check attribute is linked to an actual agent
ProtocolConfiguration protocolConfiguration = protocolConfigurationResolver.apply(protocolRef);
if (protocolConfiguration == null) {
- LOG.warning("Cannot process asset update as agent link is invalid:" + assetUpdate);
- assetUpdate.setError(new RuntimeException("Attribute has an invalid agent link:" + assetUpdate.getAttribute()));
- assetUpdate.setStatus(AssetUpdate.Status.ERROR);
+ LOG.warning("Cannot process as agent link is invalid:" + assetState);
+ assetState.setError(new RuntimeException("Attribute has an invalid agent link:" + assetState.getAttribute()));
+ assetState.setProcessingStatus(AssetState.ProcessingStatus.ERROR);
return;
}
} else {
// This is just a non protocol attribute so allow the processing to continue
- LOG.fine("Ignoring asset update as it is not for an attribute linked to an agent:" + assetUpdate);
+ LOG.fine("Ignoring as it is not for an attribute linked to an agent:" + assetState);
return;
}
// Its' a send to actuator - push the update to the protocol
- LOG.fine("Processing asset update: " + assetUpdate);
+ LOG.fine("Processing: " + assetState);
messageBrokerService.getProducerTemplate().sendBody(
ACTUATOR_TOPIC,
- assetUpdate.getAttribute().getStateEvent()
+ assetState.getAttribute().getStateEvent()
);
- assetUpdate.setStatus(AssetUpdate.Status.HANDLED);
+ assetState.setProcessingStatus(AssetState.ProcessingStatus.HANDLED);
}
public Function<AttributeRef, ProtocolConfiguration> getProtocolConfigurationResolver() {
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java
index c8c2ec6c9..fa3103296 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java
@@ -40,9 +40,7 @@ import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
-import static org.openremote.agent3.protocol.Protocol.ACTUATOR_TOPIC;
import static org.openremote.agent3.protocol.Protocol.SENSOR_TOPIC;
-import static org.openremote.manager.server.event.EventService.INCOMING_EVENT_TOPIC;
/**
* Receives {@link AttributeEvent}s and processes them.
@@ -54,7 +52,7 @@ import static org.openremote.manager.server.event.EventService.INCOMING_EVENT_TO
* <li>Rules ({@link org.openremote.model.rules.Assets#dispatch})</li>
* </ul>
* The {@link AttributeEvent}s are first validated (link and value type checking) then they are
- * converted into {@link AssetUpdate} messages which are then passed through the processing chain of consumers.
+ * converted into {@link AssetState} messages which are then passed through the processing chain of consumers.
* <p>
* The regular processing chain is:
* <ul>
@@ -63,20 +61,24 @@ import static org.openremote.manager.server.event.EventService.INCOMING_EVENT_TO
* <li>{@link AssetStorageService}</li>
* <li>{@link AssetDatapointService}</li>
* </ul>
- * <em>Rules Service processing logic</em>
+ * <h2>Rules Service processing logic</h2>
* <p>
- * Checks if attribute is {@link AssetAttribute#isRulesFact} or {@link AssetAttribute#isRulesEvent}, and if
- * it does then the message is passed through the rule engines that are in scope for the asset. Rules have the ability
- * to change the status and new value of {@link AssetUpdate} messages to either prevent them from progressing through
- * the processing chain or changing the value that progresses through the processing chain. Rules can also set a status
- * of {@link AssetUpdate.Status#RULES_HANDLED} which means that the message shouldn't be processed by any more rule
- * engines but it should continue through the processing chain. For {@link org.openremote.model.rules.AssetEvent}
- * messages, they are inserted in the rules sessions in scope and expired automatically either by a) the rules session
- * if no time-pattern can possibly match the event timestamp anymore or b) by the rules service if the event lifetime
- * set in {@link RulesService#RULES_EVENT_EXPIRES} is reached or c) by the rules service if the event lifetime set in
- * the attribute {@link AssetMeta#RULES_EVENT_EXPIRES} is reached.
+ * Checks if attribute is {@link AssetAttribute#isRuleState} or {@link AssetAttribute#isRuleEvent}, and if
+ * it does then the message is passed through the rule engines that are in scope for the asset.
* <p>
- * <em>Agent service processing logic</em>
+ * Rules have the ability to change the processing status and new value of {@link AssetState} messages to either
+ * prevent them from progressing through the processing chain (by setting {@link AssetState.ProcessingStatus#HANDLED)}
+ * or changing the value that progresses through the processing chain. Rules can also set
+ * {@link AssetState.ProcessingStatus#RULES_HANDLED}, which means that the message shouldn't be processed by any
+ * more rule engines but it should continue through the processing chain and ultimately result in an update of the
+ * asset database.
+ * <p>
+ * For {@link AssetEvent} messages, they are inserted in the rules sessions in scope
+ * and expired automatically either by a) the rules session if no time-pattern can possibly match the event source
+ * timestamp anymore or b) by the rules service if the event lifetime set in {@link RulesService#RULE_EVENT_EXPIRES} is
+ * reached or c) by the rules service if the event lifetime set in the attribute {@link AssetMeta#RULE_EVENT_EXPIRES}
+ * is reached.
+ * <h2>Agent service processing logic</h2>
* <p>
* When the attribute event came from a Protocol (i.e. generated by a call from
* {@link org.openremote.agent3.protocol.AbstractProtocol#onSensorUpdate} then
@@ -86,7 +88,7 @@ import static org.openremote.manager.server.event.EventService.INCOMING_EVENT_TO
* to a {@link AssetType#THING} and if so it will check if the attribute is linked to an {@link AssetType#AGENT}.
* If it is not linked to an agent then it ignores the message and just passes it to the next consumer. If it
* is linked to an agent and the agent link is invalid then the message status is set to
- * {@link AssetUpdate.Status#ERROR} and the message will not be able to progress through the processing chain.
+ * {@link AssetState.ProcessingStatus#ERROR} and the message will not be able to progress through the processing chain.
* <p>
* If the message is for a valid linked agent then an {@link AttributeEvent} is sent on the
* {@link org.openremote.agent3.protocol.AbstractProtocol#ACTUATOR_TOPIC} which the protocol will receive in
@@ -99,13 +101,11 @@ import static org.openremote.manager.server.event.EventService.INCOMING_EVENT_TO
* with a new sensor read, or they might send a separate sensor changed message or both or neither (fire and
* forget). The protocol must decide what the best course of action is based on the 'things' it communicates with
* and the transport layer it uses etc.
- * <p>
- * <em>Asset Storage Service processing logic</em>
+ * <h2>Asset Storage Service processing logic</h2>
* <p>
* Always tries to persist the attribute value in the DB and allows the message to continue if the commit was
* successful.
- * <p>
- * <em>Asset Datapoint Service processing logic</em>
+ * <h2>Asset Datapoint Service processing logic</h2>
* <p>
* Checks if attribute has {@link org.openremote.model.asset.AssetMeta#STORE_DATA_POINTS} meta item with a value of true
* and if it does then the {@link AttributeEvent} is stored in a time series DB. Then allows the message to continue
@@ -123,7 +123,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
protected MessageBrokerService messageBrokerService;
protected EventService eventService;
- final protected List<Consumer<AssetUpdate>> processors = new ArrayList<>();
+ final protected List<Consumer<AssetState>> processors = new ArrayList<>();
@Override
public void init(Container container) throws Exception {
@@ -215,7 +215,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
* This is the entry point for any attribute value change event in the entire system. This deals
* with single attribute value changes and pushes them through the attribute event processing chain
* where each consumer is given the opportunity to consume the event or allow it progress to the
- * next consumer {@link AssetUpdate.Status}.
+ * next consumer {@link AssetState.ProcessingStatus}.
* <p>
* NOTE: An attribute value can be changed during Asset CRUD but this does not come through
* this route but is handled separately see {@link AssetResourceImpl}. Any attribute values
@@ -337,7 +337,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
}
processUpdate(
- new AssetUpdate(
+ new AssetState(
asset,
attribute,
lastStateEvent.getValue(),
@@ -346,43 +346,43 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
);
}
- protected void processUpdate(AssetUpdate assetUpdate) {
+ protected void processUpdate(AssetState assetState) {
try {
- LOG.fine(">>> Processing start: " + assetUpdate);
+ LOG.fine(">>> Processing start: " + assetState);
processorLoop:
- for (Consumer<AssetUpdate> processor : processors) {
+ for (Consumer<AssetState> processor : processors) {
try {
- LOG.fine("Processor " + processor + " accepts: " + assetUpdate);
- processor.accept(assetUpdate);
+ LOG.fine("Processor " + processor + " accepts: " + assetState);
+ processor.accept(assetState);
} catch (Throwable t) {
- LOG.log(Level.SEVERE, "Asset update consumer '" + processor + "' threw an exception whilst consuming the update:" + assetUpdate, t);
- assetUpdate.setStatus(AssetUpdate.Status.ERROR);
- assetUpdate.setError(t);
+ LOG.log(Level.SEVERE, "Asset update consumer '" + processor + "' threw an exception whilst consuming the update:" + assetState, t);
+ assetState.setProcessingStatus(AssetState.ProcessingStatus.ERROR);
+ assetState.setError(t);
}
- switch (assetUpdate.getStatus()) {
+ switch (assetState.getProcessingStatus()) {
case HANDLED:
- LOG.fine("Processor " + processor + " finally handled: " + assetUpdate);
+ LOG.fine("Processor " + processor + " finally handled: " + assetState);
break processorLoop;
case ERROR:
// TODO Better error handling, not sure we need rewind?
- LOG.severe("Asset update status is '" + assetUpdate.getStatus() + "' cannot continue processing");
- assetUpdate.setStatus(AssetUpdate.Status.COMPLETED);
- throw new RuntimeException("Processor " + processor + " error: " + assetUpdate, assetUpdate.getError());
+ LOG.severe("Asset update status is '" + assetState.getProcessingStatus() + "' cannot continue processing");
+ assetState.setProcessingStatus(AssetState.ProcessingStatus.COMPLETED);
+ throw new RuntimeException("Processor " + processor + " error: " + assetState, assetState.getError());
}
}
- assetUpdate.setStatus(AssetUpdate.Status.COMPLETED);
+ assetState.setProcessingStatus(AssetState.ProcessingStatus.COMPLETED);
- publishEvent(assetUpdate);
+ publishEvent(assetState);
} finally {
- LOG.fine("<<< Processing complete: " + assetUpdate);
+ LOG.fine("<<< Processing complete: " + assetState);
}
}
- protected void publishEvent(AssetUpdate assetUpdate) {
+ protected void publishEvent(AssetState assetState) {
eventService.publishEvent(
- new AttributeEvent(assetUpdate.getId(), assetUpdate.getAttributeName(), assetUpdate.getValue())
+ new AttributeEvent(assetState.getId(), assetState.getAttributeName(), assetState.getValue())
);
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
index 86da76ce8..bae6fb9e6 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
@@ -51,7 +51,7 @@ import java.util.logging.Logger;
import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_TOPIC;
import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForEntityType;
-public class AssetStorageService extends RouteBuilder implements ContainerService, Consumer<AssetUpdate> {
+public class AssetStorageService extends RouteBuilder implements ContainerService, Consumer<AssetState> {
private static final Logger LOG = Logger.getLogger(AssetStorageService.class.getName());
protected PersistenceService persistenceService;
@@ -116,12 +116,12 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
}
@Override
- public void accept(AssetUpdate assetUpdate) {
- String assetId = assetUpdate.getId();
- String attributeName = assetUpdate.getAttribute().getName();
- JsonValue value = assetUpdate.getAttribute().getValue();
+ public void accept(AssetState assetState) {
+ String assetId = assetState.getId();
+ String attributeName = assetState.getAttribute().getName();
+ JsonValue value = assetState.getAttribute().getValue();
// Some sanity checking, of course the timestamp should never be -1 if we store updated attribute state
- long timestamp = assetUpdate.getAttribute().getValueTimestamp();
+ long timestamp = assetState.getAttribute().getValueTimestamp();
String valueTimestamp = Long.toString(
timestamp >= 0 ? timestamp : System.currentTimeMillis()
);
diff --git a/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java b/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java
index 48e3b8f0d..cc8c096be 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java
@@ -3,7 +3,7 @@ package org.openremote.manager.server.datapoint;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.container.persistence.PersistenceService;
-import org.openremote.model.asset.AssetUpdate;
+import org.openremote.model.asset.AssetState;
import org.openremote.model.AttributeRef;
import org.openremote.model.datapoint.AssetDatapoint;
@@ -14,7 +14,7 @@ import java.util.function.Consumer;
/**
* Store and retrieve datapoints.
*/
-public class AssetDatapointService implements ContainerService, Consumer<AssetUpdate> {
+public class AssetDatapointService implements ContainerService, Consumer<AssetState> {
private static final Logger LOG = Logger.getLogger(AssetDatapointService.class.getName());
@@ -34,13 +34,13 @@ public class AssetDatapointService implements ContainerService, Consumer<AssetUp
}
@Override
- public void accept(AssetUpdate assetUpdate) {
- if (assetUpdate.getAttribute().isStoreDatapoints()) {
- LOG.finest("Storing asset update data point: " + assetUpdate);
- AssetDatapoint assetDatapoint = new AssetDatapoint(assetUpdate.getAttribute().getStateEvent());
+ public void accept(AssetState assetState) {
+ if (assetState.getAttribute().isStoreDatapoints()) {
+ LOG.finest("Storing data point for: " + assetState);
+ AssetDatapoint assetDatapoint = new AssetDatapoint(assetState.getAttribute().getStateEvent());
persistenceService.doTransaction(entityManager -> entityManager.persist(assetDatapoint));
} else {
- LOG.finest("Ignoring asset update as attribute is not a data point: " + assetUpdate);
+ LOG.finest("Ignoring as attribute is not a data point: " + assetState);
}
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesDeployment.java b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesDeployment.java
index 4b16f6b61..b208a3ff0 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesDeployment.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesDeployment.java
@@ -58,9 +58,9 @@ import org.openremote.model.AttributeEvent;
import org.openremote.model.Consumer;
import org.openremote.model.asset.AbstractAssetUpdate;
import org.openremote.model.asset.AssetQuery;
-import org.openremote.model.asset.AssetUpdate;
+import org.openremote.model.asset.AssetState;
import org.openremote.model.notification.AlertNotification;
-import org.openremote.model.rules.AssetEvent;
+import org.openremote.model.asset.AssetEvent;
import org.openremote.model.rules.Assets;
import org.openremote.model.rules.Users;
@@ -98,7 +98,7 @@ public class RulesDeployment<T extends Ruleset> {
protected Throwable error;
protected boolean running;
protected long currentFactCount;
- final protected Map<AssetUpdate, FactHandle> facts = new HashMap<>();
+ final protected Map<AssetState, FactHandle> assetStates = new HashMap<>();
protected static final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
protected ScheduledFuture startTimer;
@@ -396,8 +396,9 @@ public class RulesDeployment<T extends Ruleset> {
}
// Insert all the facts into the session
- List<AssetUpdate> factEntries = new ArrayList<>(facts.keySet());
- factEntries.forEach(factEntry -> insertFact(factEntry, true));
+ new ArrayList<>(assetStates.keySet()).forEach(
+ factEntry -> insertAssetState(factEntry, true)
+ );
LOG.info("Rule engine started");
knowledgeSession.fireAllRules();
@@ -419,42 +420,42 @@ public class RulesDeployment<T extends Ruleset> {
running = false;
}
- protected synchronized FactHandle insertFact(AssetUpdate assetUpdate, boolean silent) {
+ protected synchronized FactHandle insertAssetState(AssetState assetState, boolean silent) {
return insertIntoSession(
- assetUpdate,
+ assetState,
silent,
- factHandle -> facts.put(assetUpdate, factHandle)
+ factHandle -> assetStates.put(assetState, factHandle)
);
}
- protected synchronized void updateFact(AssetUpdate assetUpdate, boolean silent) {
+ protected synchronized void updateAssetState(AssetState assetState, boolean silent) {
// Check if fact already exists using equals()
- if (!facts.containsKey(assetUpdate)) {
+ if (!assetStates.containsKey(assetState)) {
// Delete any existing fact for this attribute ref
// Put the fact into working memory and store the handle
- retractFact(assetUpdate);
+ retractAssetState(assetState);
if (isRunning()) {
- insertFact(assetUpdate, silent);
+ insertAssetState(assetState, silent);
} else {
- facts.put(assetUpdate, null);
+ assetStates.put(assetState, null);
}
}
}
- protected synchronized void retractFact(AssetUpdate assetUpdate) {
+ protected synchronized void retractAssetState(AssetState assetState) {
// If there already is a fact in working memory for this attribute then delete it
- AssetUpdate update = facts.keySet()
+ AssetState update = assetStates.keySet()
.stream()
- .filter(au -> au.attributeRefsEqual(assetUpdate))
+ .filter(au -> au.attributeRefsEqual(assetState))
.findFirst()
.orElse(null);
- FactHandle factHandle = update != null ? facts.get(update) : null;
+ FactHandle factHandle = update != null ? assetStates.get(update) : null;
if (factHandle != null) {
- facts.remove(update);
+ assetStates.remove(update);
if (isRunning()) {
try {
@@ -468,7 +469,7 @@ public class RulesDeployment<T extends Ruleset> {
}
}
- protected synchronized FactHandle insertEvent(AssetEvent assetEvent, long expirationOffset) {
+ protected synchronized FactHandle insertAssetEvent(AssetEvent assetEvent, long expirationOffset) {
return insertIntoSession(
assetEvent,
false,
@@ -631,8 +632,6 @@ public class RulesDeployment<T extends Ruleset> {
public void storeAndNotify(String userId, AlertNotification alert) {
notificationService.storeAndNotify(userId,alert);
}
-
-
};
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesService.java b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesService.java
index c8538f58c..326d00f5b 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesService.java
@@ -40,7 +40,7 @@ import org.openremote.manager.shared.rules.TenantRuleset;
import org.openremote.manager.shared.security.Tenant;
import org.openremote.model.AbstractValueTimestampHolder;
import org.openremote.model.asset.*;
-import org.openremote.model.rules.AssetEvent;
+import org.openremote.model.asset.AssetEvent;
import org.openremote.model.util.JsonUtil;
import java.util.*;
@@ -54,22 +54,24 @@ import static org.openremote.container.util.MapAccess.getString;
import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForEntityType;
/**
- * Responsible for creating drools knowledge sessions for the rulesets
- * and processing AssetUpdate events; an asset update is processed in the following
- * order: -
+ * Responsible for creating Drools knowledge sessions for the rulesets
+ * and processing {@link AssetState} and {@link AssetEvent} messages.
* <p>
- * Global Rulesets
- * Tenant Rulesets
- * Asset Rulesets (in hierarchical order from oldest ancestor down - ordering of
+ * Each message is processed in the following order:
+ * <ol>
+ * <li>Global Rulesets</li>
+ * <li>Tenant Rulesets</li>
+ * <li>Asset Rulesets (in hierarchical order from oldest ancestor down - ordering of
* asset rulesets with same parent asset are not guaranteed also processing order of rulesets
- * with the same scope is not guaranteed)
+ * with the same scope is not guaranteed)</li>
+ * </ol>
*/
-public class RulesService extends RouteBuilder implements ContainerService, Consumer<AssetUpdate> {
+public class RulesService extends RouteBuilder implements ContainerService, Consumer<AssetState> {
private static final Logger LOG = Logger.getLogger(RulesService.class.getName());
- public static final String RULES_EVENT_EXPIRES = "RULES_EVENT_EXPIRES";
- public static final String RULES_EVENT_EXPIRES_DEFAULT = "1h";
+ public static final String RULE_EVENT_EXPIRES = "RULE_EVENT_EXPIRES";
+ public static final String RULE_EVENT_EXPIRES_DEFAULT = "1h";
protected PersistenceService persistenceService;
protected RulesetStorageService rulesetStorageService;
@@ -82,10 +84,10 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
protected final Map<String, RulesDeployment<AssetRuleset>> assetDeployments = new HashMap<>();
protected String[] activeTenantIds;
- // Keep global list of asset updates that have been pushed to any engines
+ // Keep global list of asset states that have been pushed to any engines
// The objects are already in memory inside the rule engines but keeping them
// here means we can quickly insert facts into newly started engines
- protected List<AssetUpdate> facts = new ArrayList<>();
+ protected List<AssetState> assetStates = new ArrayList<>();
protected String configEventExpires;
@@ -99,7 +101,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
assetProcessingService = container.getService(AssetProcessingService.class);
container.getService(MessageBrokerSetupService.class).getContext().addRoutes(this);
- configEventExpires = getString(container.getConfig(), RULES_EVENT_EXPIRES, RULES_EVENT_EXPIRES_DEFAULT);
+ configEventExpires = getString(container.getConfig(), RULE_EVENT_EXPIRES, RULE_EVENT_EXPIRES_DEFAULT);
}
@Override
@@ -151,7 +153,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
deployAssetRulesets(rulesetStorageService.findEnabledAssetRulesets());
LOG.info("Loading all assets with fact attributes to initialize state of rules engines");
- List<Pair<ServerAsset, List<AssetAttribute>>> assetRuleAttributesList = findRuleFactAttributes(null, null);
+ List<Pair<ServerAsset, List<AssetAttribute>>> assetRuleAttributesList = findRuleStateAttributes(null, null);
// Push each rule attribute as an asset update through the rule engine chain
// that will ensure the insert only happens to the engines in scope
@@ -160,11 +162,11 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
ServerAsset asset = assetRuleAttributes.key;
List<AssetAttribute> ruleAttributes = assetRuleAttributes.value;
ruleAttributes.forEach(ruleAttribute -> {
- AssetUpdate update = new AssetUpdate(asset, ruleAttribute);
+ AssetState assetState = new AssetState(asset, ruleAttribute);
// Set the status to completed already so rules cannot interfere with this initial insert
- update.setStatus(AssetUpdate.Status.COMPLETED);
- LOG.fine("Inserting initial rules engine state: " + update);
- updateFact(update, true);
+ assetState.setProcessingStatus(AssetState.ProcessingStatus.COMPLETED);
+ LOG.fine("Inserting initial rules engine state: " + assetState);
+ updateAssetState(assetState, true);
});
});
}
@@ -188,13 +190,13 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
}
@Override
- public void accept(AssetUpdate assetUpdate) {
- if (assetUpdate.getAttribute().isRulesFact()) {
- updateFact(assetUpdate, false);
- } else if (assetUpdate.getAttribute().isRulesEvent()) {
- process(new AssetEvent(assetUpdate));
+ public void accept(AssetState assetState) {
+ if (assetState.getAttribute().isRuleState()) {
+ updateAssetState(assetState, false);
+ } else if (assetState.getAttribute().isRuleEvent()) {
+ process(new AssetEvent(assetState));
} else {
- LOG.finest("Ignoring update as attribute is not a rules fact or rules event: " + assetUpdate);
+ LOG.finest("Ignoring asset state as attribute is not a rules state or event: " + assetState);
}
}
@@ -240,8 +242,8 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
// We must load the asset from database (only when required), as the
// persistence event might not contain a completely loaded asset
- BiFunction<Asset, AssetAttribute, AssetUpdate> buildUpdateFunction = (loadedAsset, attribute) ->
- new AssetUpdate(loadedAsset,
+ BiFunction<Asset, AssetAttribute, AssetState> buildAssetState = (loadedAsset, attribute) ->
+ new AssetState(loadedAsset,
new AssetAttribute(loadedAsset.getId(),
attribute.getName(),
attribute.getJsonObject()));
@@ -250,12 +252,12 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
switch (persistenceEvent.getCause()) {
case INSERT:
- // New asset has been created so get attributes that have RULES_FACT meta
+ // New asset has been created so get attributes that have RULE_STATE meta
AssetAttributes addedAttributes = new AssetAttributes(asset);
List<AssetAttribute> ruleAttributes = addedAttributes.get()
- .stream()
- .filter(AssetAttribute::isRulesFact)
- .collect(Collectors.toList());
+ .stream()
+ .filter(AssetAttribute::isRuleState)
+ .collect(Collectors.toList());
if (ruleAttributes.size() == 0) {
return;
@@ -266,12 +268,12 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
Asset finalLoadedAsset = loadedAsset;
ruleAttributes.forEach(attribute -> {
- AssetUpdate update = buildUpdateFunction.apply(finalLoadedAsset, attribute);
- // Set the status to completed already so rules cannot interfere with this initial insert
- update.setStatus(AssetUpdate.Status.COMPLETED);
- LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), inserting fact: " + update);
- updateFact(update, true);
- });
+ AssetState assetState = buildAssetState.apply(finalLoadedAsset, attribute);
+ // Set the status to completed already so rules cannot interfere with this initial insert
+ assetState.setProcessingStatus(AssetState.ProcessingStatus.COMPLETED);
+ LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), inserting fact: " + assetState);
+ updateAssetState(assetState, true);
+ });
break;
case UPDATE:
@@ -287,52 +289,52 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
AssetAttributes newAttributes = new AssetAttributes(asset.getId(), (JsonObject) persistenceEvent.getCurrentState()[attributesIndex]);
List<AssetAttribute> oldFactAttributes = oldAttributes.get().stream()
- .filter(AssetAttribute::isRulesFact)
- .collect(Collectors.toList());
+ .filter(AssetAttribute::isRuleState)
+ .collect(Collectors.toList());
List<AssetAttribute> newFactAttributes = newAttributes.get().stream()
- .filter(AssetAttribute::isRulesFact)
- .collect(Collectors.toList());
+ .filter(AssetAttribute::isRuleState)
+ .collect(Collectors.toList());
// Compare attributes by JSON value
// Retract facts for attributes that are in oldFactAttributes but not in newFactAttributes
List<AssetAttribute> processAttributes = oldFactAttributes
+ .stream()
+ .filter(oldFactAttribute -> newFactAttributes
.stream()
- .filter(oldFactAttribute -> newFactAttributes
- .stream()
- .noneMatch(newFactAttribute -> JsonUtil.equals( // Ignore the timestamp in comparison
- oldFactAttribute.getJsonObject(),
- newFactAttribute.getJsonObject(),
- Collections.singletonList(AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME))
- )
+ .noneMatch(newFactAttribute -> JsonUtil.equals( // Ignore the timestamp in comparison
+ oldFactAttribute.getJsonObject(),
+ newFactAttribute.getJsonObject(),
+ Collections.singletonList(AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME))
)
- .collect(Collectors.toList());
+ )
+ .collect(Collectors.toList());
if (processAttributes.size() > 0) {
// Fully load the asset
loadedAsset = assetStorageService.find(asset.getId(), true);
Asset finalLoadedAsset1 = loadedAsset;
processAttributes.forEach(obsoleteFactAttribute -> {
- AssetUpdate update = buildUpdateFunction.apply(finalLoadedAsset1, obsoleteFactAttribute);
+ AssetState update = buildAssetState.apply(finalLoadedAsset1, obsoleteFactAttribute);
LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), retracting fact: " + update);
- retractFact(update);
+ retractAssetState(update);
});
}
// Insert facts for attributes that are in newFactAttributes but not in oldFactAttributes
processAttributes = newFactAttributes
+ .stream()
+ .filter(newFactAttribute -> oldFactAttributes
.stream()
- .filter(newFactAttribute -> oldFactAttributes
- .stream()
- .noneMatch(oldFactAttribute ->
- JsonUtil.equals( // Ignore the timestamp in comparison
- oldFactAttribute.getJsonObject(),
- newFactAttribute.getJsonObject(),
- Collections.singletonList(AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME)
- )
- )
+ .noneMatch(oldFactAttribute ->
+ JsonUtil.equals( // Ignore the timestamp in comparison
+ oldFactAttribute.getJsonObject(),
+ newFactAttribute.getJsonObject(),
+ Collections.singletonList(AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME)
+ )
)
- .collect(Collectors.toList());
+ )
+ .collect(Collectors.toList());
if (processAttributes.size() > 0) {
if (loadedAsset == null) {
@@ -342,11 +344,11 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
Asset finalLoadedAsset2 = loadedAsset;
processAttributes.forEach(newFactAttribute -> {
- AssetUpdate update = buildUpdateFunction.apply(finalLoadedAsset2, newFactAttribute);
+ AssetState assetState = buildAssetState.apply(finalLoadedAsset2, newFactAttribute);
// Set the status to completed already so rules cannot interfere with this initial insert
- update.setStatus(AssetUpdate.Status.COMPLETED);
- LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), inserting fact: " + update);
- updateFact(update, true);
+ assetState.setProcessingStatus(AssetState.ProcessingStatus.COMPLETED);
+ LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), inserting fact: " + assetState);
+ updateAssetState(assetState, true);
});
}
break;
@@ -354,13 +356,13 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
// Retract any facts that were associated with this asset
AssetAttributes removedAttributes = new AssetAttributes(asset);
removedAttributes.get().stream()
- .filter(AssetAttribute::isRulesFact)
+ .filter(AssetAttribute::isRuleState)
.forEach(attribute -> {
- // We can't load the asset again (it was deleted), so don't use buildUpdateFunction() and
+ // We can't load the asset again (it was deleted), so don't use buildAssetState() and
// hope that the path of the event asset has been loaded before deletion
- AssetUpdate update = new AssetUpdate(asset, attribute);
- LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), retracting fact: " + update);
- retractFact(update);
+ AssetState assetState = new AssetState(asset, attribute);
+ LOG.fine("Asset was persisted (" + persistenceEvent.getCause() + "), retracting fact: " + assetState);
+ retractAssetState(assetState);
});
break;
}
@@ -381,7 +383,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
RulesDeployment newEngine = deployGlobalRuleset((GlobalRuleset) ruleset);
if (newEngine != null) {
// Push all existing facts into the engine
- facts.forEach(assetUpdate -> newEngine.updateFact(assetUpdate, true));
+ assetStates.forEach(assetState -> newEngine.updateAssetState(assetState, true));
}
} else if (ruleset instanceof TenantRuleset) {
@@ -389,9 +391,9 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
RulesDeployment newEngine = deployTenantRuleset((TenantRuleset) ruleset);
if (newEngine != null) {
// Push all existing facts for this tenant into the engine
- facts.forEach(assetUpdate -> {
- if (assetUpdate.getRealmId().equals(((TenantRuleset) ruleset).getRealmId())) {
- newEngine.updateFact(assetUpdate, true);
+ assetStates.forEach(assetState -> {
+ if (assetState.getRealmId().equals(((TenantRuleset) ruleset).getRealmId())) {
+ newEngine.updateAssetState(assetState, true);
}
});
}
@@ -403,8 +405,8 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
RulesDeployment newEngine = deployAssetRuleset(assetRuleset);
if (newEngine != null) {
// Push all existing facts for this asset (and it's children into the engine)
- getFactsInScope(((AssetRuleset) ruleset).getAssetId())
- .forEach(assetUpdate -> newEngine.updateFact(assetUpdate, true));
+ getAssetStatesInScope(((AssetRuleset) ruleset).getAssetId())
+ .forEach(assetState -> newEngine.updateAssetState(assetState, true));
}
}
@@ -446,7 +448,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
RulesDeployment<TenantRuleset> deployment = tenantDeployments
.computeIfAbsent(ruleset.getRealmId(), (realmId) -> {
created[0] = true;
- return new RulesDeployment<>(assetStorageService,notificationService, assetProcessingService, TenantRuleset.class, realmId);
+ return new RulesDeployment<>(assetStorageService, notificationService, assetProcessingService, TenantRuleset.class, realmId);
});
deployment.addRuleset(ruleset);
@@ -502,7 +504,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
RulesDeployment<AssetRuleset> deployment = assetDeployments
.computeIfAbsent(ruleset.getAssetId(), (assetId) -> {
created[0] = true;
- return new RulesDeployment<>(assetStorageService,notificationService, assetProcessingService, AssetRuleset.class, assetId);
+ return new RulesDeployment<>(assetStorageService, notificationService, assetProcessingService, AssetRuleset.class, assetId);
});
deployment.addRuleset(ruleset);
@@ -522,7 +524,6 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
}
}
-
protected synchronized void process(AssetEvent assetEvent) {
// TODO: implement rules processing error state handling
@@ -547,79 +548,80 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
String eventExpires = assetEvent.getExpires() != null ? assetEvent.getExpires() : configEventExpires;
long expirationOffset = TimeIntervalParser.parseSingle(eventExpires);
- deployment.insertEvent(assetEvent, expirationOffset);
+ deployment.insertAssetEvent(assetEvent, expirationOffset);
}
}
- protected synchronized void updateFact(AssetUpdate assetUpdate, boolean skipStatusCheck) {
+ protected synchronized void updateAssetState(AssetState assetState, boolean skipStatusCheck) {
// TODO: implement rules processing error state handling
// Get the chain of rule engines that we need to pass through
- List<RulesDeployment> rulesDeployments = getEnginesInScope(assetUpdate.getRealmId(), assetUpdate.getPathFromRoot());
+ List<RulesDeployment> rulesDeployments = getEnginesInScope(assetState.getRealmId(), assetState.getPathFromRoot());
if (rulesDeployments.size() == 0) {
- LOG.fine("Ignoring asset update as there are no matching rules deployments: " + assetUpdate);
+ LOG.fine("Ignoring as there are no matching rules deployments: " + assetState);
}
if (!skipStatusCheck) {
// Check that all engines in the scope are not in ERROR state
if (rulesDeployments.stream().anyMatch(RulesDeployment::isError)) {
- LOG.severe("At least one rule engine is in an error state so cannot process update:" + assetUpdate);
- assetUpdate.setStatus(AssetUpdate.Status.ERROR);
+ LOG.severe("At least one rule engine is in an error state so cannot process:" + assetState);
+ assetState.setProcessingStatus(AssetState.ProcessingStatus.ERROR);
return;
}
}
// Remove any stale fact that has equality with this new one or the attribute ref matches
// (this is what rules deployment does also)
- if (!facts.remove(assetUpdate)) {
- facts.removeIf(storedUpdate -> storedUpdate.attributeRefsEqual(assetUpdate));
+ if (!assetStates.remove(assetState)) {
+ assetStates.removeIf(storedAssetState -> storedAssetState.attributeRefsEqual(assetState));
}
// Insert the new fact
- facts.add(assetUpdate);
+ assetStates.add(assetState);
// Pass through each engine and try and insert the fact
for (RulesDeployment deployment : rulesDeployments) {
// Any exceptions in rule RHS will bubble up and the engine would be marked as in ERROR so future
// updates will be blocked
- deployment.updateFact(assetUpdate, skipStatusCheck);
+ deployment.updateAssetState(assetState, skipStatusCheck);
if (!skipStatusCheck) {
// We have to check status between each engine insert as a rule in the engine could have updated
// the status
- if (assetUpdate.getStatus() != AssetUpdate.Status.CONTINUE) {
- LOG.info("Rules engine has marked update event as '" + assetUpdate.getStatus() + "' so not processing anymore");
- if (assetUpdate.getStatus() == AssetUpdate.Status.RULES_HANDLED) {
- assetUpdate.setStatus(AssetUpdate.Status.CONTINUE);
+ if (assetState.getProcessingStatus() != AssetState.ProcessingStatus.CONTINUE) {
+ LOG.info("Rules engine has marked asset state as '" + assetState.getProcessingStatus() + "' so not processing anymore");
+ if (assetState.getProcessingStatus() == AssetState.ProcessingStatus.RULES_HANDLED) {
+ assetState.setProcessingStatus(AssetState.ProcessingStatus.CONTINUE);
}
break;
}
}
}
}
- protected void retractFact(AssetUpdate assetUpdate) {
+
+ protected void retractAssetState(AssetState assetState) {
// Get the chain of rule engines that we need to pass through
- List<RulesDeployment> rulesDeployments = getEnginesInScope(assetUpdate.getRealmId(), assetUpdate.getPathFromRoot());
+ List<RulesDeployment> rulesDeployments = getEnginesInScope(assetState.getRealmId(), assetState.getPathFromRoot());
- if (!facts.remove(assetUpdate)) {
- facts.removeIf(storedUpdate -> storedUpdate.attributeRefsEqual(assetUpdate));
+ if (!assetStates.remove(assetState)) {
+ assetStates.removeIf(storedAssetState -> storedAssetState.attributeRefsEqual(assetState));
}
if (rulesDeployments.size() == 0) {
- LOG.fine("Ignoring asset update as there are no matching rules deployments: " + assetUpdate);
+ LOG.fine("Ignoring as there are no matching rules deployments: " + assetState);
}
// Pass through each engine and retract this fact
for (RulesDeployment deployment : rulesDeployments) {
- deployment.retractFact(assetUpdate);
+ deployment.retractAssetState(assetState);
}
}
- protected List<AssetUpdate> getFactsInScope(String assetId) {
- return facts
+ protected List<AssetState> getAssetStatesInScope(String assetId) {
+ return assetStates
.stream()
- .filter(assetUpdate -> Arrays.asList(assetUpdate.getPathFromRoot()).contains(assetId))
+ .filter(assetState -> Arrays.asList(assetState.getPathFromRoot()).contains(assetId))
.collect(Collectors.toList());
}
@@ -650,7 +652,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
return rulesDeployments;
}
- protected List<Pair<ServerAsset, List<AssetAttribute>>> findRuleFactAttributes(AssetQuery.TenantPredicate tenantPredicate, AssetQuery.ParentPredicate parentPredicate) {
+ protected List<Pair<ServerAsset, List<AssetAttribute>>> findRuleStateAttributes(AssetQuery.TenantPredicate tenantPredicate, AssetQuery.ParentPredicate parentPredicate) {
List<ServerAsset> assets = assetStorageService.findAll(
new AssetQuery()
.select(new AssetQuery.Select(true))
@@ -658,14 +660,14 @@ public class RulesService extends RouteBuilder implements ContainerService, Cons
.tenant(tenantPredicate)
.attributeMeta(
new AssetQuery.AttributeMetaPredicate(
- AssetMeta.RULES_FACT,
+ AssetMeta.RULE_STATE,
new AssetQuery.BooleanPredicate(true))
));
return assets.stream().map(asset -> {
AssetAttributes attributes = new AssetAttributes(asset);
List<AssetAttribute> ruleAttributes = attributes.get().stream()
- .filter(AssetAttribute::isRulesFact).collect(Collectors.toList());
+ .filter(AssetAttribute::isRuleState).collect(Collectors.toList());
return new Pair<>(asset, ruleAttributes);
}).collect(Collectors.toList());
diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
index aead3d805..34a94eed5 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
@@ -288,9 +288,9 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
).add(
new MetaItem(AssetMeta.DESCRIPTION, Json.create("When triggered, turns all lights in the apartment off"))
).add(
- new MetaItem(AssetMeta.RULES_EVENT, Json.create(true))
+ new MetaItem(AssetMeta.RULE_EVENT, Json.create(true))
).add(
- new MetaItem(AssetMeta.RULES_EVENT_EXPIRES, Json.create("10s"))
+ new MetaItem(AssetMeta.RULE_EVENT_EXPIRES, Json.create("10s"))
)
)
);
@@ -309,7 +309,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
new Meta().add(
new MetaItem(AssetMeta.LABEL, Json.create("Presence Sensor"))
).add(
- new MetaItem(AssetMeta.RULES_EVENT, Json.create(true))
+ new MetaItem(AssetMeta.RULE_EVENT, Json.create(true))
)
),
new AssetAttribute("presenceDetected", AttributeType.BOOLEAN, Json.create(false))
@@ -317,7 +317,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
new Meta().add(
new MetaItem(AssetMeta.LABEL, Json.create("Presence Detected"))
).add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
)
),
new AssetAttribute("lightSwitch", AttributeType.BOOLEAN, Json.create(true))
@@ -325,7 +325,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
new Meta().add(
new MetaItem(AssetMeta.LABEL, Json.create("Light Switch"))
).add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
)
),
new AssetAttribute("windowOpen", AttributeType.BOOLEAN, Json.create(false))
@@ -339,7 +339,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
new Meta().add(
new MetaItem(AssetMeta.LABEL, Json.create("CO2 Level"))
).add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(false))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(false))
)
)
);
@@ -359,7 +359,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
Json.create("Current Temperature"))
)
.add(new MetaItem(
- AssetMeta.RULES_FACT,
+ AssetMeta.RULE_STATE,
Json.create(true)
))
.add(new MetaItem(
@@ -384,7 +384,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
Json.create("Comfort Temperature"))
)
.add(new MetaItem(
- AssetMeta.RULES_FACT,
+ AssetMeta.RULE_STATE,
Json.create(true)
))
.add(new MetaItem(
@@ -420,7 +420,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
).add(
new MetaItem(AssetMeta.DESCRIPTION, Json.create("When triggered, turns all lights in the apartment off"))
).add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
)
)
);
@@ -439,7 +439,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
new Meta().add(
new MetaItem(AssetMeta.LABEL, Json.create("Presence Sensor"))
).add(
- new MetaItem(AssetMeta.RULES_EVENT, Json.create(true))
+ new MetaItem(AssetMeta.RULE_EVENT, Json.create(true))
)
),
new AssetAttribute("presenceDetected", AttributeType.BOOLEAN, Json.create(false))
@@ -447,7 +447,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
new Meta().add(
new MetaItem(AssetMeta.LABEL, Json.create("Presence Detected"))
).add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
)
),
new AssetAttribute("lightSwitch", AttributeType.BOOLEAN, Json.create(true))
@@ -455,7 +455,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
new Meta().add(
new MetaItem(AssetMeta.LABEL, Json.create("Light Switch"))
).add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(false))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(false))
)
),
new AssetAttribute("windowOpen", AttributeType.BOOLEAN, Json.create(false))
@@ -482,7 +482,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
).add(
new MetaItem(AssetMeta.DESCRIPTION, Json.create("When triggered, turns all lights in the apartment off"))
).add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
)
)
);
@@ -501,7 +501,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
new Meta().add(
new MetaItem(AssetMeta.LABEL, Json.create("Presence Sensor"))
).add(
- new MetaItem(AssetMeta.RULES_EVENT, Json.create(true))
+ new MetaItem(AssetMeta.RULE_EVENT, Json.create(true))
)
),
new AssetAttribute("presenceDetected", AttributeType.BOOLEAN, Json.create(false))
@@ -509,7 +509,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
new Meta().add(
new MetaItem(AssetMeta.LABEL, Json.create("Presence Detected"))
).add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(true))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
)
),
new AssetAttribute("lightSwitch", AttributeType.BOOLEAN, Json.create(true))
@@ -517,7 +517,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
new Meta().add(
new MetaItem(AssetMeta.LABEL, Json.create("Light Switch"))
).add(
- new MetaItem(AssetMeta.RULES_FACT, Json.create(false))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(false))
)
),
new AssetAttribute("windowOpen", AttributeType.BOOLEAN, Json.create(false))
diff --git a/manager/server/src/main/resources/demo/rules/DemoApartmentAllLightsOff.drl b/manager/server/src/main/resources/demo/rules/DemoApartmentAllLightsOff.drl
index 1ef695898..6c18efcd4 100644
--- a/manager/server/src/main/resources/demo/rules/DemoApartmentAllLightsOff.drl
+++ b/manager/server/src/main/resources/demo/rules/DemoApartmentAllLightsOff.drl
@@ -2,7 +2,6 @@ package org.openremote.test.rules;
import org.openremote.model.*;
import org.openremote.model.asset.*
-import org.openremote.model.rules.*
import elemental.json.Json;
global java.util.logging.Logger LOG;
diff --git a/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetection.drl b/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetection.drl
index c9be0061e..bc6b5e6e5 100644
--- a/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetection.drl
+++ b/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetection.drl
@@ -2,7 +2,6 @@ package org.openremote.test.rules;
import org.openremote.model.*;
import org.openremote.model.asset.*
-import org.openremote.model.rules.*
import elemental.json.Json;
global java.util.logging.Logger LOG;
@@ -18,7 +17,7 @@ when
count($pir2)
)
// And the presence latch is not set already
- AssetUpdate(id == $pir.getId(), attributeName == "presenceDetected", !value.asBoolean)
+ AssetState(id == $pir.getId(), attributeName == "presenceDetected", !value.asBoolean)
then
LOG.info("### PRESENCE DETECTED IN ROOM: " + $pir);
diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
index ddde69df5..62f952649 100644
--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
@@ -626,7 +626,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
protectedMeta.all().length == 3
protectedMeta.first(AssetMeta.LABEL).getValueAsString() == "Current Temperature"
protectedMeta.first(AssetMeta.READ_ONLY).getValueAsBoolean()
- protectedMeta.first(AssetMeta.RULES_FACT).getValueAsBoolean()
+ protectedMeta.first(AssetMeta.RULE_STATE).getValueAsBoolean()
when: "an asset is retrieved by ID in a foreign realm"
assetResource.get(null, managerDemoSetup.thingId)
diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
index 5f1698f4e..ddebfbf04 100644
--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
@@ -76,14 +76,14 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
//region and: "a mock attribute event consumer"
and: "a mock attribute event consumer"
- List<AssetUpdate> updatesPassedStartOfProcessingChain = []
- List<AssetUpdate> updatesReachedEndOfProcessingChain = []
+ List<AssetState> updatesPassedStartOfProcessingChain = []
+ List<AssetState> updatesReachedEndOfProcessingChain = []
- Consumer<AssetUpdate> mockEndConsumer = { assetUpdate ->
+ Consumer<AssetState> mockEndConsumer = { assetUpdate ->
updatesReachedEndOfProcessingChain.add(assetUpdate)
}
- Consumer<AssetUpdate> mockStartConsumer = { assetUpdate ->
+ Consumer<AssetState> mockStartConsumer = { assetUpdate ->
updatesPassedStartOfProcessingChain.add(assetUpdate)
}
//endregion
@@ -195,7 +195,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
assert sendToActuatorEvents[0].entityId == mockThing.id
assert sendToActuatorEvents[0].attributeName == "light1Toggle"
assert sendToActuatorEvents[0].attributeState.value.asBoolean() == true
- assert updatesPassedStartOfProcessingChain[0].status == AssetUpdate.Status.COMPLETED
+ assert updatesPassedStartOfProcessingChain[0].processingStatus == AssetState.ProcessingStatus.COMPLETED
}
when: "the protocol gets a response from the server"
@@ -211,7 +211,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
assert updatesReachedEndOfProcessingChain[0].attributeName == "light1Toggle"
assert updatesReachedEndOfProcessingChain[0].oldValue.asBoolean() == false
assert updatesReachedEndOfProcessingChain[0].value.asBoolean() == true
- assert updatesReachedEndOfProcessingChain[0].status == AssetUpdate.Status.COMPLETED
+ assert updatesReachedEndOfProcessingChain[0].processingStatus == AssetState.ProcessingStatus.COMPLETED
}
//endregion
@@ -234,7 +234,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
assert updatesPassedStartOfProcessingChain[0].attributeName == "light2Toggle"
assert updatesPassedStartOfProcessingChain[0].error != null
assert updatesPassedStartOfProcessingChain[0].error instanceof RuntimeException
- assert updatesPassedStartOfProcessingChain[0].status == AssetUpdate.Status.COMPLETED
+ assert updatesPassedStartOfProcessingChain[0].processingStatus == AssetState.ProcessingStatus.COMPLETED
}
when: "an attribute event occurs for the plain attribute"
@@ -256,7 +256,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
assert updatesReachedEndOfProcessingChain[0].oldValue.asString() == "demo"
assert updatesReachedEndOfProcessingChain[0].value.asString() == "test"
assert updatesReachedEndOfProcessingChain[0].error == null
- assert updatesReachedEndOfProcessingChain[0].status == AssetUpdate.Status.COMPLETED
+ assert updatesReachedEndOfProcessingChain[0].processingStatus == AssetState.ProcessingStatus.COMPLETED
}
}
}
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentActionsTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentActionsTest.groovy
index 91334daf5..9773b492c 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentActionsTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentActionsTest.groovy
@@ -47,10 +47,10 @@ class ApartmentActionsTest extends Specification implements ManagerContainerTrai
assert customerAEngine.isRunning()
}
- and: "the demo attributes marked with RULES_FACT = true meta should be inserted into the engines"
+ and: "the demo attributes marked with RULE_STATE = true meta should be inserted into the engines"
conditions.eventually {
- assert rulesService.facts.size() == 8
- assert customerAEngine.facts.size() == 8
+ assert rulesService.assetStates.size() == 8
+ assert customerAEngine.assetStates.size() == 8
assert customerAEngine.knowledgeSession.factCount == 8
}
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy
index 02777a17d..c8fb38240 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy
@@ -55,7 +55,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
when: "a new global rule definition is added"
def ruleset = new GlobalRuleset(
"Some more global rules",
- getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetUpdates2.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates2.drl").text
)
rulesetStorageService.merge(ruleset)
@@ -76,7 +76,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
ruleset = new TenantRuleset(
"Some more customerA tenant rules",
keycloakDemoSetup.customerATenant.id,
- getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetUpdates2.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates2.drl").text
)
rulesetStorageService.merge(ruleset)
@@ -98,7 +98,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
ruleset = new TenantRuleset(
"Some more customerB tenant rules",
keycloakDemoSetup.customerBTenant.id,
- getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetUpdates2.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates2.drl").text
)
rulesetStorageService.merge(ruleset)
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy
index 396065e51..568072b0c 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy
@@ -28,13 +28,13 @@ class BasicRulesImport {
Ruleset ruleset = new GlobalRuleset(
"Some global demo rules",
- getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetUpdates.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
rulesetStorageService.merge(ruleset)
ruleset = new GlobalRuleset(
"Other global demo rules with a long name that should fill up space in UI",
- getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetUpdates.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
ruleset.setEnabled(false)
rulesetStorageService.merge(ruleset)
@@ -42,21 +42,21 @@ class BasicRulesImport {
ruleset = new TenantRuleset(
"Some master tenant demo rules",
keycloakDemoSetup.masterTenant.id,
- getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetUpdates.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
rulesetStorageService.merge(ruleset)
ruleset = new TenantRuleset(
"Some customerA tenant demo rules",
keycloakDemoSetup.customerATenant.id,
- getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetUpdates.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
rulesetStorageService.merge(ruleset)
ruleset = new TenantRuleset(
"Some customerB tenant demo rules",
keycloakDemoSetup.customerBTenant.id,
- getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetUpdates.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
ruleset.setEnabled(false)
customerBRulesetId = rulesetStorageService.merge(ruleset).id
@@ -64,14 +64,14 @@ class BasicRulesImport {
ruleset = new AssetRuleset(
"Some apartment 1 demo rules",
managerDemoSetup.apartment1Id,
- getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetUpdates.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
apartment1RulesetId = rulesetStorageService.merge(ruleset).id
ruleset = new AssetRuleset(
"Some apartment 2 demo rules",
managerDemoSetup.apartment2Id,
- getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetUpdates.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
ruleset.setEnabled(false)
rulesetStorageService.merge(ruleset)
@@ -79,7 +79,7 @@ class BasicRulesImport {
ruleset = new AssetRuleset(
"Some apartment 3 demo rules",
managerDemoSetup.apartment3Id,
- getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetUpdates.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
rulesetStorageService.merge(ruleset)
}
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
index 9ec950212..56815e5b2 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
@@ -79,14 +79,14 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
rulesImport.assertEnginesReady(rulesService, keycloakDemoSetup, managerDemoSetup)
}
- and: "the demo attributes marked with RULES_FACT = true meta should be inserted into the engines"
+ and: "the demo attributes marked with RULE_STATE = true meta should be inserted into the engines"
conditions.eventually {
- assert rulesService.facts.size() == 8
- assert rulesImport.globalEngine.facts.size() == 8
- assert rulesImport.masterEngine.facts.size() == 0
- assert rulesImport.customerAEngine.facts.size() == 8
- assert rulesImport.apartment1Engine.facts.size() == 4
- assert rulesImport.apartment3Engine.facts.size() == 2
+ assert rulesService.assetStates.size() == 8
+ assert rulesImport.globalEngine.assetStates.size() == 8
+ assert rulesImport.masterEngine.assetStates.size() == 0
+ assert rulesImport.customerAEngine.assetStates.size() == 8
+ assert rulesImport.apartment1Engine.assetStates.size() == 4
+ assert rulesImport.apartment3Engine.assetStates.size() == 2
}
when: "rule execution loggers are attached to the engines"
@@ -96,7 +96,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
attachRuleExecutionLogger(rulesImport.apartment1Engine, apartment1EngineFiredRules)
attachRuleExecutionLogger(rulesImport.apartment3Engine, apartment3EngineFiredRules)
- and: "an attribute event is pushed into the system for an attribute with RULES_FACT meta set to true"
+ and: "an attribute event is pushed into the system for an attribute with RULE_STATE meta set to true"
def apartment1LivingRoomPresenceDetectedChange = new AttributeEvent(
managerDemoSetup.apartment1LivingroomId, "presenceDetected", Json.create(true)
)
@@ -116,7 +116,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert apartment3EngineFiredRules.size() == 0
}
- when: "an attribute event is pushed into the system for an attribute with RULES_FACT meta set to false"
+ when: "an attribute event is pushed into the system for an attribute with RULE_STATE meta set to false"
resetRuleExecutionLoggers()
def apartment1LivingRoomCO2Change = new AttributeEvent(
managerDemoSetup.apartment1LivingroomId, "co2Level", Json.create(500)
@@ -126,7 +126,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
then: "no rule engines should have fired after a few seconds"
new PollingConditions(initialDelay: 3).eventually assertNoRulesFired
- when: "an attribute event is pushed into the system for an attribute with no RULES_FACT meta"
+ when: "an attribute event is pushed into the system for an attribute with no RULE_STATE meta"
resetRuleExecutionLoggers()
def apartment1LivingRoomWindowOpenChange = new AttributeEvent(
managerDemoSetup.apartment1LivingroomId, "windowOpen", Json.create(true)
@@ -168,7 +168,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
def assetRuleset = new AssetRuleset(
"Some smart home asset rules",
managerDemoSetup.smartHomeId,
- getClass().getResource("/org/openremote/test/rules/BasicSmartHomeMatchAllAssetUpdates.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicSmartHomeMatchAllAssetStates.drl").text
)
rulesetStorageService.merge(assetRuleset)
RulesDeployment smartHomeEngine = null
@@ -178,7 +178,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
smartHomeEngine = rulesService.assetDeployments.get(managerDemoSetup.smartHomeId)
assert smartHomeEngine != null
assert smartHomeEngine.isRunning()
- assert smartHomeEngine.facts.size() == 8
+ assert smartHomeEngine.assetStates.size() == 8
assert smartHomeEngine.allRulesets.length == 1
assert smartHomeEngine.allRulesets[0].enabled
assert smartHomeEngine.allRulesets[0].name == "Some smart home asset rules"
@@ -238,7 +238,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
when: "a RHS filtering test rule definition is loaded into the global rule engine"
assetRuleset = new GlobalRuleset(
"Some global test rules",
- getClass().getResource("/org/openremote/test/rules/BasicSmartHomePreventAssetUpdate.drl").text
+ getClass().getResource("/org/openremote/test/rules/BasicSmartHomePreventAssetState.drl").text
)
rulesetStorageService.merge(assetRuleset)
@@ -247,7 +247,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
rulesImport.globalEngine = rulesService.globalDeployment
assert rulesImport.globalEngine != null
assert rulesImport.globalEngine.isRunning()
- assert rulesImport.globalEngine.facts.size() == 8
+ assert rulesImport.globalEngine.assetStates.size() == 8
assert rulesImport.globalEngine.allRulesets.length == 2
assert rulesImport.globalEngine.allRulesets[1].enabled
assert rulesImport.globalEngine.allRulesets[1].name == "Some global test rules"
@@ -294,7 +294,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert apartment1EngineFiredRules.size() == 0
}
- when: "a Kitchen room asset is inserted into apartment 1 that contains a RULES_FACT = true meta flag"
+ when: "a Kitchen room asset is inserted into apartment 1 that contains a RULE_STATE = true meta flag"
resetRuleExecutionLoggers()
def apartment1 = assetStorageService.find(managerDemoSetup.apartment1Id)
def asset = new ServerAsset(apartment1)
@@ -305,7 +305,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
attributes.put(
new AssetAttribute("testString", AttributeType.STRING, Json.create("test"))
.setMeta(new Meta()
- .add(new MetaItem(AssetMeta.RULES_FACT, Json.create(true)))
+ .add(new MetaItem(AssetMeta.RULE_STATE, Json.create(true)))
)
)
asset.setAttributes(attributes.getJsonObject())
@@ -313,13 +313,13 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
then: "after a few seconds the engines in scope should not have fired any rules but the facts should have been inserted"
conditions.eventually {
- assert rulesService.facts.size() == 9
- assert rulesImport.globalEngine.facts.size() == 9
- assert rulesImport.masterEngine.facts.size() == 0
- assert rulesImport.customerAEngine.facts.size() == 9
- assert smartHomeEngine.facts.size() == 9
- assert rulesImport.apartment1Engine.facts.size() == 5
- assert rulesImport.apartment3Engine.facts.size() == 2
+ assert rulesService.assetStates.size() == 9
+ assert rulesImport.globalEngine.assetStates.size() == 9
+ assert rulesImport.masterEngine.assetStates.size() == 0
+ assert rulesImport.customerAEngine.assetStates.size() == 9
+ assert smartHomeEngine.assetStates.size() == 9
+ assert rulesImport.apartment1Engine.assetStates.size() == 5
+ assert rulesImport.apartment3Engine.assetStates.size() == 2
assert globalEngineFiredRules.size() == 0
assert customerAEngineFiredRules.size() == 0
assert smartHomeEngineFiredRules.size() == 0
@@ -327,14 +327,14 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert apartment3EngineFiredRules.size() == 0
}
- when: "the Kitchen room asset is modified to add a new attribute but RULES_FACT = true meta is not changed"
+ when: "the Kitchen room asset is modified to add a new attribute but RULE_STATE = true meta is not changed"
resetRuleExecutionLoggers()
attributes = new AssetAttributes()
attributes.put(
new AssetAttribute("testString", AttributeType.STRING, Json.create("test"))
.setMeta(
new Meta()
- .add(new MetaItem(AssetMeta.RULES_FACT, Json.create(true)))
+ .add(new MetaItem(AssetMeta.RULE_STATE, Json.create(true)))
),
new AssetAttribute("testInteger", AttributeType.INTEGER, Json.create(0))
)
@@ -343,13 +343,13 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
then: "after a few seconds the fact count shouldn't change and no rules should have fired"
new PollingConditions(initialDelay: 3).eventually {
- assert rulesService.facts.size() == 9
- assert rulesImport.globalEngine.facts.size() == 9
- assert rulesImport.masterEngine.facts.size() == 0
- assert rulesImport.customerAEngine.facts.size() == 9
- assert smartHomeEngine.facts.size() == 9
- assert rulesImport.apartment1Engine.facts.size() == 5
- assert rulesImport.apartment3Engine.facts.size() == 2
+ assert rulesService.assetStates.size() == 9
+ assert rulesImport.globalEngine.assetStates.size() == 9
+ assert rulesImport.masterEngine.assetStates.size() == 0
+ assert rulesImport.customerAEngine.assetStates.size() == 9
+ assert smartHomeEngine.assetStates.size() == 9
+ assert rulesImport.apartment1Engine.assetStates.size() == 5
+ assert rulesImport.apartment3Engine.assetStates.size() == 2
assert globalEngineFiredRules.size() == 0
assert customerAEngineFiredRules.size() == 0
assert smartHomeEngineFiredRules.size() == 0
@@ -357,13 +357,13 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert apartment3EngineFiredRules.size() == 0
}
- when: "the Kitchen room asset is modified to set the RULES_FACT to false"
+ when: "the Kitchen room asset is modified to set the RULE_STATE to false"
attributes = new AssetAttributes()
attributes.put(
new AssetAttribute("testString", AttributeType.STRING, Json.create("test"))
.setMeta(
new Meta()
- .add(new MetaItem(AssetMeta.RULES_FACT, Json.create(false)))
+ .add(new MetaItem(AssetMeta.RULE_STATE, Json.create(false)))
),
new AssetAttribute("testInteger", AttributeType.INTEGER, Json.create(0))
)
@@ -372,13 +372,13 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
then: "the facts should be removed from the rule engines and no rules should have fired"
conditions.eventually {
- assert rulesService.facts.size() == 8
- assert rulesImport.globalEngine.facts.size() == 8
- assert rulesImport.masterEngine.facts.size() == 0
- assert rulesImport.customerAEngine.facts.size() == 8
- assert smartHomeEngine.facts.size() == 8
- assert rulesImport.apartment1Engine.facts.size() == 4
- assert rulesImport.apartment3Engine.facts.size() == 2
+ assert rulesService.assetStates.size() == 8
+ assert rulesImport.globalEngine.assetStates.size() == 8
+ assert rulesImport.masterEngine.assetStates.size() == 0
+ assert rulesImport.customerAEngine.assetStates.size() == 8
+ assert smartHomeEngine.assetStates.size() == 8
+ assert rulesImport.apartment1Engine.assetStates.size() == 4
+ assert rulesImport.apartment3Engine.assetStates.size() == 2
assert globalEngineFiredRules.size() == 0
assert customerAEngineFiredRules.size() == 0
assert smartHomeEngineFiredRules.size() == 0
@@ -386,19 +386,19 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert apartment3EngineFiredRules.size() == 0
}
- when: "the Kitchen room asset is modified to set all attributes to RULES_FACT = true"
+ when: "the Kitchen room asset is modified to set all attributes to RULE_STATE = true"
resetRuleExecutionLoggers()
attributes = new AssetAttributes()
attributes.put(
new AssetAttribute("testString", AttributeType.STRING, Json.create("test"))
.setMeta(
new Meta()
- .add(new MetaItem(AssetMeta.RULES_FACT, Json.create(true)))
+ .add(new MetaItem(AssetMeta.RULE_STATE, Json.create(true)))
),
new AssetAttribute("testInteger", AttributeType.INTEGER, Json.create(0))
.setMeta(
new Meta()
- .add(new MetaItem(AssetMeta.RULES_FACT, Json.create(true)))
+ .add(new MetaItem(AssetMeta.RULE_STATE, Json.create(true)))
)
)
asset.setAttributes(attributes.getJsonObject())
@@ -406,13 +406,13 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
then: "the facts should be added to the rule engines and no rules should have fired"
conditions.eventually {
- assert rulesService.facts.size() == 10
- assert rulesImport.globalEngine.facts.size() == 10
- assert rulesImport.masterEngine.facts.size() == 0
- assert rulesImport.customerAEngine.facts.size() == 10
- assert smartHomeEngine.facts.size() == 10
- assert rulesImport.apartment1Engine.facts.size() == 6
- assert rulesImport.apartment3Engine.facts.size() == 2
+ assert rulesService.assetStates.size() == 10
+ assert rulesImport.globalEngine.assetStates.size() == 10
+ assert rulesImport.masterEngine.assetStates.size() == 0
+ assert rulesImport.customerAEngine.assetStates.size() == 10
+ assert smartHomeEngine.assetStates.size() == 10
+ assert rulesImport.apartment1Engine.assetStates.size() == 6
+ assert rulesImport.apartment3Engine.assetStates.size() == 2
assert globalEngineFiredRules.size() == 0
assert customerAEngineFiredRules.size() == 0
assert smartHomeEngineFiredRules.size() == 0
@@ -426,13 +426,13 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
then: "the facts should be removed from the rule engines and no rules should have fired"
conditions.eventually {
- assert rulesService.facts.size() == 8
- assert rulesImport.globalEngine.facts.size() == 8
- assert rulesImport.masterEngine.facts.size() == 0
- assert rulesImport.customerAEngine.facts.size() == 8
- assert smartHomeEngine.facts.size() == 8
- assert rulesImport.apartment1Engine.facts.size() == 4
- assert rulesImport.apartment3Engine.facts.size() == 2
+ assert rulesService.assetStates.size() == 8
+ assert rulesImport.globalEngine.assetStates.size() == 8
+ assert rulesImport.masterEngine.assetStates.size() == 0
+ assert rulesImport.customerAEngine.assetStates.size() == 8
+ assert smartHomeEngine.assetStates.size() == 8
+ assert rulesImport.apartment1Engine.assetStates.size() == 4
+ assert rulesImport.apartment3Engine.assetStates.size() == 2
assert globalEngineFiredRules.size() == 0
assert customerAEngineFiredRules.size() == 0
assert smartHomeEngineFiredRules.size() == 0
diff --git a/manager/test/src/test/resources/org/openremote/test/rules/BasicMatchAllAssetUpdates.drl b/manager/test/src/test/resources/org/openremote/test/rules/BasicMatchAllAssetStates.drl
similarity index 79%
rename from manager/test/src/test/resources/org/openremote/test/rules/BasicMatchAllAssetUpdates.drl
rename to manager/test/src/test/resources/org/openremote/test/rules/BasicMatchAllAssetStates.drl
index f6d720b8e..d1f80c815 100644
--- a/manager/test/src/test/resources/org/openremote/test/rules/BasicMatchAllAssetUpdates.drl
+++ b/manager/test/src/test/resources/org/openremote/test/rules/BasicMatchAllAssetStates.drl
@@ -7,14 +7,14 @@ global java.util.logging.Logger LOG;
rule "All"
when
- $e: AssetUpdate()
+ $e: AssetState()
then
return;
end
rule "All changed"
when
- $e: AssetUpdate(valueChanged)
+ $e: AssetState(valueChanged)
then
return;
end
\ No newline at end of file
diff --git a/manager/test/src/test/resources/org/openremote/test/rules/BasicMatchAllAssetUpdates2.drl b/manager/test/src/test/resources/org/openremote/test/rules/BasicMatchAllAssetStates2.drl
similarity index 83%
rename from manager/test/src/test/resources/org/openremote/test/rules/BasicMatchAllAssetUpdates2.drl
rename to manager/test/src/test/resources/org/openremote/test/rules/BasicMatchAllAssetStates2.drl
index fce5e1991..a44ba1ef1 100644
--- a/manager/test/src/test/resources/org/openremote/test/rules/BasicMatchAllAssetUpdates2.drl
+++ b/manager/test/src/test/resources/org/openremote/test/rules/BasicMatchAllAssetStates2.drl
@@ -9,14 +9,14 @@ global java.util.logging.Logger LOG;
rule "All 2"
when
- $e: AssetUpdate()
+ $e: AssetState()
then
return;
end
rule "All changed 2"
when
- $e: AssetUpdate(valueChanged)
+ $e: AssetState(valueChanged)
then
return;
end
\ No newline at end of file
diff --git a/manager/test/src/test/resources/org/openremote/test/rules/BasicSmartHomeMatchAllAssetUpdates.drl b/manager/test/src/test/resources/org/openremote/test/rules/BasicSmartHomeMatchAllAssetStates.drl
similarity index 55%
rename from manager/test/src/test/resources/org/openremote/test/rules/BasicSmartHomeMatchAllAssetUpdates.drl
rename to manager/test/src/test/resources/org/openremote/test/rules/BasicSmartHomeMatchAllAssetStates.drl
index 9c43b277c..691cdc382 100644
--- a/manager/test/src/test/resources/org/openremote/test/rules/BasicSmartHomeMatchAllAssetUpdates.drl
+++ b/manager/test/src/test/resources/org/openremote/test/rules/BasicSmartHomeMatchAllAssetStates.drl
@@ -8,84 +8,84 @@ global java.util.logging.Logger LOG;
rule "Living Room All"
when
- $e: AssetUpdate(name == "Livingroom")
+ $e: AssetState(name == "Livingroom")
then
return;
end
rule "Kitchen All"
when
- $e: AssetUpdate(name == "Kitchen")
+ $e: AssetState(name == "Kitchen")
then
return;
end
rule "Kitchen Integer Attributes"
when
- $e: AssetUpdate(name == "Kitchen", attributeType == AttributeType.INTEGER)
+ $e: AssetState(name == "Kitchen", attributeType == AttributeType.INTEGER)
then
return;
end
rule "Living Room Thermostat"
when
- $e: AssetUpdate(name == "Livingroom Thermostat")
+ $e: AssetState(name == "Livingroom Thermostat")
then
return;
end
rule "Living Room Comfort Temperature"
when
- $e: AssetUpdate(name == "Livingroom Thermostat", attributeName == "comfortTemperature")
+ $e: AssetState(name == "Livingroom Thermostat", attributeName == "comfortTemperature")
then
return;
end
rule "Living Room as Parent"
when
- AssetUpdate(parentName == "Livingroom")
+ AssetState(parentName == "Livingroom")
then
return;
end
rule "Boolean Attributes"
when
- AssetUpdate(attributeType == AttributeType.BOOLEAN)
+ AssetState(attributeType == AttributeType.BOOLEAN)
then
return;
end
rule "String Attributes"
when
- AssetUpdate(attributeType == AttributeType.STRING)
+ AssetState(attributeType == AttributeType.STRING)
then
return;
end
rule "JSON Number value types"
when
- AssetUpdate(value.type == JsonType.NUMBER)
+ AssetState(value.type == JsonType.NUMBER)
then
return;
end
rule "Current Asset Update"
when
- AssetUpdate(status != AssetUpdate.Status.COMPLETED)
+ AssetState(processingStatus != AssetState.ProcessingStatus.COMPLETED)
then
return;
end
rule "Parent Type Residence"
when
- AssetUpdate(parentType == AssetType.RESIDENCE)
+ AssetState(parentType == AssetType.RESIDENCE)
then
return;
end
rule "Asset Type Room"
when
- AssetUpdate(type == AssetType.ROOM)
+ AssetState(type == AssetType.ROOM)
then
return;
end
\ No newline at end of file
diff --git a/manager/test/src/test/resources/org/openremote/test/rules/BasicSmartHomePreventAssetUpdate.drl b/manager/test/src/test/resources/org/openremote/test/rules/BasicSmartHomePreventAssetState.drl
similarity index 58%
rename from manager/test/src/test/resources/org/openremote/test/rules/BasicSmartHomePreventAssetUpdate.drl
rename to manager/test/src/test/resources/org/openremote/test/rules/BasicSmartHomePreventAssetState.drl
index d4226be39..bac4ed8b7 100644
--- a/manager/test/src/test/resources/org/openremote/test/rules/BasicSmartHomePreventAssetUpdate.drl
+++ b/manager/test/src/test/resources/org/openremote/test/rules/BasicSmartHomePreventAssetState.drl
@@ -2,13 +2,12 @@ package org.openremote.test.rules;
import org.openremote.model.*;
import org.openremote.model.asset.*;
-import elemental.json.*;
global java.util.logging.Logger LOG;
rule "Prevent Livingroom Thermostat Change"
when
- $e: AssetUpdate(name == "Livingroom Thermostat", !completed)
+ $e: AssetState(name == "Livingroom Thermostat", !completed)
then
- $e.setStatus(AssetUpdate.Status.HANDLED);
+ $e.setProcessingStatus(AssetState.ProcessingStatus.HANDLED);
end
\ No newline at end of file
diff --git a/model/src/main/java/org/openremote/model/asset/AbstractAssetAttribute.java b/model/src/main/java/org/openremote/model/asset/AbstractAssetAttribute.java
index d4735d666..140f1f49f 100644
--- a/model/src/main/java/org/openremote/model/asset/AbstractAssetAttribute.java
+++ b/model/src/main/java/org/openremote/model/asset/AbstractAssetAttribute.java
@@ -98,16 +98,16 @@ public abstract class AbstractAssetAttribute<CHILD extends AbstractAssetAttribut
return hasMetaItem(STORE_DATA_POINTS) && firstMetaItem(STORE_DATA_POINTS).isValueTrue();
}
- public boolean isRulesFact() {
- return hasMetaItem(RULES_FACT) && firstMetaItem(RULES_FACT).isValueTrue();
+ public boolean isRuleState() {
+ return hasMetaItem(RULE_STATE) && firstMetaItem(RULE_STATE).isValueTrue();
}
- public boolean isRulesEvent() {
- return hasMetaItem(RULES_EVENT) && firstMetaItem(RULES_EVENT).isValueTrue();
+ public boolean isRuleEvent() {
+ return hasMetaItem(RULE_EVENT) && firstMetaItem(RULE_EVENT).isValueTrue();
}
- public String getRulesEventExpires() {
- return hasMetaItem(RULES_EVENT_EXPIRES) ? firstMetaItem(RULES_EVENT_EXPIRES).getValueAsString() : null;
+ public String getRuleEventExpires() {
+ return hasMetaItem(RULE_EVENT_EXPIRES) ? firstMetaItem(RULE_EVENT_EXPIRES).getValueAsString() : null;
}
public boolean isAgentLinked() {
diff --git a/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java b/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java
index 82d4e6653..fb0ac90b7 100644
--- a/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java
+++ b/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java
@@ -26,7 +26,8 @@ import org.openremote.model.util.JsonUtil;
import java.util.Date;
/**
- * An asset attribute value change that can be handled by a sequence of processors.
+ * An asset attribute value update, capturing that asset state at a point in time.
+ * <p>
* This class layout is convenient for writing expressions that match getters, while
* carrying as much asset details as needed.
*/
diff --git a/model/src/main/java/org/openremote/model/rules/AssetEvent.java b/model/src/main/java/org/openremote/model/asset/AssetEvent.java
similarity index 89%
rename from model/src/main/java/org/openremote/model/rules/AssetEvent.java
rename to model/src/main/java/org/openremote/model/asset/AssetEvent.java
index 9ec072c5d..71bb06f02 100644
--- a/model/src/main/java/org/openremote/model/rules/AssetEvent.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetEvent.java
@@ -17,10 +17,9 @@
* 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.model.rules;
+package org.openremote.model.asset;
import org.kie.api.definition.type.Role;
-import org.openremote.model.asset.AbstractAssetUpdate;
/**
* An asset attribute value change as a punctual event in rules processing.
@@ -34,6 +33,6 @@ public class AssetEvent extends AbstractAssetUpdate {
}
public String getExpires() {
- return attribute.getRulesEventExpires();
+ return attribute.getRuleEventExpires();
}
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetMeta.java b/model/src/main/java/org/openremote/model/asset/AssetMeta.java
index 359086cce..738556c11 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetMeta.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetMeta.java
@@ -111,25 +111,25 @@ public enum AssetMeta {
/**
* Should attribute writes be processed by the rules engines as facts in knowledge sessions, with a lifecycle
- * that reflects the state of the asset attribute (the {@link AssetUpdate} facts in the rules sessions are kept
+ * that reflects the state of the asset attribute (the {@link AssetState} facts in the rules sessions are kept
* in sync with asset changes).
*/
- RULES_FACT(ASSET_META_NAMESPACE + ":rulesFact", new Access(true, false, true), JsonType.BOOLEAN),
+ RULE_STATE(ASSET_META_NAMESPACE + ":ruleState", new Access(true, false, true), JsonType.BOOLEAN),
/**
* Should attribute writes be processed by the rules engines as events in knowledge sessions with limited
- * lifecycle that reflects how the event is processed (the {@link org.openremote.model.rules.AssetEvent} facts
+ * lifecycle that reflects how the event is processed (the {@link AssetEvent} facts
* in the rules sessions are expired automatically after a certain time and/or if they can no longer be matched
* by time operations).
*/
- RULES_EVENT(ASSET_META_NAMESPACE + ":rulesEvent", new Access(true, false, true), JsonType.BOOLEAN),
+ RULE_EVENT(ASSET_META_NAMESPACE + ":ruleEvent", new Access(true, false, true), JsonType.BOOLEAN),
/**
- * Override rules event expiration, for example "1h30m". Remove {@link org.openremote.model.rules.AssetEvent}
+ * Override rules event expiration, for example "1h30m". Remove {@link AssetEvent}
* facts from the rules sessions if they are older than this value (using event source timestamp, not event
* processing time).
*/
- RULES_EVENT_EXPIRES(ASSET_META_NAMESPACE + ":rulesEventExpires", new Access(true, false, true), JsonType.STRING),
+ RULE_EVENT_EXPIRES(ASSET_META_NAMESPACE + ":ruleEventExpires", new Access(true, false, true), JsonType.STRING),
/**
* Enable flag to be used by asset attributes that could require this functionality (e.g. ProtocolConfiguration)
diff --git a/model/src/main/java/org/openremote/model/asset/AssetUpdate.java b/model/src/main/java/org/openremote/model/asset/AssetState.java
similarity index 65%
rename from model/src/main/java/org/openremote/model/asset/AssetUpdate.java
rename to model/src/main/java/org/openremote/model/asset/AssetState.java
index 149cd8095..ff6a15792 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetUpdate.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetState.java
@@ -22,15 +22,19 @@ package org.openremote.model.asset;
import elemental.json.JsonValue;
/**
- * An asset attribute value change that can be handled by a sequence of processors
- * with status and error handling.
+ * An asset attribute value update, capturing that asset state at a point in time.
+ * <p>
+ * Instances of this class are processed by the system, with a sequence of processors. Each
+ * processor can consume the asset state, and optionally set its status, thus controlling
+ * how the asset state update is ultimately handled (e.g. the rules processor can stop it
+ * from being handled by the database processors).
*/
-public class AssetUpdate extends AbstractAssetUpdate {
+public class AssetState extends AbstractAssetUpdate {
/**
- * Processors of updates can change the status to direct further processing.
+ * Processors of asset state updates can change the status to direct further processing.
*/
- public enum Status {
+ public enum ProcessingStatus {
/**
* Processor is happy for update to continue through the system.
*/
@@ -58,28 +62,31 @@ public class AssetUpdate extends AbstractAssetUpdate {
COMPLETED
}
- protected Status status = Status.CONTINUE;
+ protected ProcessingStatus processingStatus = ProcessingStatus.CONTINUE;
protected Throwable error;
- public AssetUpdate(Asset asset, AbstractAssetAttribute attribute) {
+ public AssetState(Asset asset, AbstractAssetAttribute attribute) {
super(asset, attribute);
}
- public AssetUpdate(Asset asset, AbstractAssetAttribute attribute, JsonValue oldValue, long oldValueTimestamp, boolean northbound) {
+ public AssetState(Asset asset, AbstractAssetAttribute attribute, JsonValue oldValue, long oldValueTimestamp, boolean northbound) {
super(asset, attribute, oldValue, oldValueTimestamp, northbound);
}
- public Status getStatus() {
- return status;
+ public ProcessingStatus getProcessingStatus() {
+ return processingStatus;
}
public Throwable getError() {
return error;
}
+ /**
+ * @return <code>true</code> is this state has completed processing, it's not currently being processed.
+ */
public boolean isCompleted() {
- return getStatus() == Status.COMPLETED;
+ return getProcessingStatus() == ProcessingStatus.COMPLETED;
}
/////////////////////////////////////////////////////////////////
@@ -90,14 +97,14 @@ public class AssetUpdate extends AbstractAssetUpdate {
if (!isCompleted()) {
return attribute;
}
- throw new IllegalStateException("Instance is immutable, status '" + getStatus() + "': " + this);
+ throw new IllegalStateException("Instance is immutable, processing status '" + getProcessingStatus() + "': " + this);
}
public void setValue(JsonValue value) {
if (!isCompleted()) {
attribute.setValue(value);
} else {
- throw new IllegalStateException("Instance is immutable, status '" + getStatus() + "': " + this);
+ throw new IllegalStateException("Instance is immutable, processing status '" + getProcessingStatus() + "': " + this);
}
}
@@ -105,15 +112,15 @@ public class AssetUpdate extends AbstractAssetUpdate {
if (!isCompleted()) {
attribute.setValueUnchecked(value);
} else {
- throw new IllegalStateException("Instance is immutable, status '" + getStatus() + "': " + this);
+ throw new IllegalStateException("Instance is immutable, processing status '" + getProcessingStatus() + "': " + this);
}
}
- public void setStatus(Status status) {
+ public void setProcessingStatus(ProcessingStatus processingStatus) {
if (!isCompleted()) {
- this.status = status;
+ this.processingStatus = processingStatus;
} else {
- throw new IllegalStateException("Instance is immutable, status '" + getStatus() + "': " + this);
+ throw new IllegalStateException("Instance is immutable, processing status '" + getProcessingStatus() + "': " + this);
}
}
@@ -121,7 +128,7 @@ public class AssetUpdate extends AbstractAssetUpdate {
if (!isCompleted()) {
this.error = error;
} else {
- throw new IllegalStateException("Instance is immutable, status '" + getStatus() + "': " + this);
+ throw new IllegalStateException("Instance is immutable, processing status '" + getProcessingStatus() + "': " + this);
}
}
}
diff --git a/model/src/main/java/org/openremote/model/asset/agent/AgentAttribute.java b/model/src/main/java/org/openremote/model/asset/agent/AgentAttribute.java
index 2591eb9bc..1460ec02d 100644
--- a/model/src/main/java/org/openremote/model/asset/agent/AgentAttribute.java
+++ b/model/src/main/java/org/openremote/model/asset/agent/AgentAttribute.java
@@ -24,9 +24,6 @@ import elemental.json.JsonObject;
import elemental.json.JsonValue;
import org.openremote.model.AttributeType;
import org.openremote.model.asset.AbstractAssetAttribute;
-import org.openremote.model.asset.AssetAttribute;
-
-import static org.openremote.model.asset.AssetMeta.RULES_FACT;
public class AgentAttribute<CHILD extends AgentAttribute<CHILD>> extends AbstractAssetAttribute<CHILD> {
diff --git a/model/src/main/java/org/openremote/model/rules/Users.java b/model/src/main/java/org/openremote/model/rules/Users.java
index 55424ec98..1007529e3 100644
--- a/model/src/main/java/org/openremote/model/rules/Users.java
+++ b/model/src/main/java/org/openremote/model/rules/Users.java
@@ -19,9 +19,7 @@
*/
package org.openremote.model.rules;
-import org.openremote.model.AttributeEvent;
import org.openremote.model.Consumer;
-import org.openremote.model.asset.AssetQuery;
import org.openremote.model.notification.AlertNotification;
import org.openremote.model.user.UserQuery;