Skip to content

armgit / core

Public Imported from GitHub
0

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

AgentService update to reload agent on attribute event for agent attributes, also fix some broken tests (Fixes #336)

Rich Turnerc8d29f506a39
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 b694ffb57..66cf99835 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
@@ -452,15 +452,18 @@ public abstract class AbstractNettyIoClient<T, U extends SocketAddress> implemen
protected void onConnectionStatusChanged(ConnectionStatus connectionStatus) {
this.connectionStatus = connectionStatus;
- 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);
- }
- }));
+ executorService.submit(() -> {
+ synchronized (connectionStatusConsumers) {
+ connectionStatusConsumers.forEach(
+ consumer -> {
+ try {
+ consumer.accept(connectionStatus);
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "Connection status change handler threw an exception: " + getClientUri(), e);
+ }
+ });
+ }
+ });
}
protected void setPermanentError(String message) {
diff --git a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroAgent.java b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroAgent.java
index 318686f16..07b4da389 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroAgent.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroAgent.java
@@ -105,4 +105,9 @@ public class MacroAgent extends Agent<MacroAgent, MacroProtocol, MacroAgent.Macr
public Optional<AttributeExecuteStatus> getMacroStatus() {
return getAttributes().getValue(MACRO_STATUS);
}
+
+ @Override
+ public boolean isConfigurationAttribute(String attributeName) {
+ return !attributeName.equals(MACRO_STATUS.getName()) && super.isConfigurationAttribute(attributeName);
+ }
}
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 3e1f28703..44e480bac 100644
--- a/manager/src/main/java/org/openremote/manager/agent/AgentService.java
+++ b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
@@ -52,7 +52,6 @@ import org.openremote.model.query.filter.PathPredicate;
import org.openremote.model.query.filter.StringPredicate;
import org.openremote.model.util.Pair;
import org.openremote.model.util.TextUtil;
-import org.openremote.model.value.MetaItemType;
import javax.persistence.EntityManager;
import java.util.*;
@@ -69,15 +68,15 @@ import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;
import static org.openremote.container.concurrent.GlobalLock.withLock;
import static org.openremote.container.concurrent.GlobalLock.withLockReturning;
-import static org.openremote.container.persistence.PersistenceEvent.*;
+import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_TOPIC;
+import static org.openremote.container.persistence.PersistenceEvent.isPersistenceEventForEntityType;
import static org.openremote.manager.asset.AssetProcessingService.ASSET_QUEUE;
import static org.openremote.manager.gateway.GatewayService.isNotForGateway;
import static org.openremote.model.asset.agent.Protocol.ACTUATOR_TOPIC;
import static org.openremote.model.asset.agent.Protocol.SENSOR_QUEUE;
import static org.openremote.model.attribute.Attribute.getAddedOrModifiedAttributes;
import static org.openremote.model.attribute.AttributeEvent.HEADER_SOURCE;
-import static org.openremote.model.attribute.AttributeEvent.Source.GATEWAY;
-import static org.openremote.model.attribute.AttributeEvent.Source.SENSOR;
+import static org.openremote.model.attribute.AttributeEvent.Source.*;
import static org.openremote.model.value.MetaItemType.AGENT_LINK;
/**
@@ -157,7 +156,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
@Override
public void stop(Container container) throws Exception {
- agentMap.values().forEach(this::stopAgent);
+ agentMap.values().stream().map(Agent::getId).forEach(this::stopAgent);
agentMap.clear();
protocolInstanceMap.clear();
}
@@ -274,42 +273,33 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
break;
case UPDATE:
- Agent<?, ?, ?> oldAgent = getAgents().get(persistenceEvent.getEntity().getId());
-
- // Old agent can be null if an update happens straight after the creation
- if (oldAgent == null || !removeAgent(oldAgent)) {
- return;
- }
-
- stopAgent(oldAgent);
- addReplaceAgent(agent);
-
- if (agent.isDisabled().orElse(false)) {
- LOG.info("Agent is disabled so not starting: " + agent);
- assetProcessingService.sendAttributeEvent(new AttributeEvent(agent.getId(), Agent.STATUS.getName(), ConnectionStatus.DISABLED));
- } else {
- startAgent(agent);
- }
+ onAgentUpdated(agent);
break;
case DELETE:
- if (!removeAgent(agent)) {
+ if (!removeAgent(agent.getId())) {
return;
}
// Unlink any attributes that have an agent link to this agent
- stopAgent(agent);
+ stopAgent(agent.getId());
break;
}
}
- protected void onAgentUpdated(Agent<?,?,?> agent, AttributeEvent attributeEvent) {
- if (Agent.DISABLED.getName().equals(attributeEvent.getAttributeName()) && !agent.isDisabled().orElse(false).equals(attributeEvent.getValue().orElse(false))) {
- LOG.fine("Agent disabled status has been updated: agent=" + agent.getId() + ", event=" + attributeEvent);
+ protected void onAgentUpdated(Agent<?,?,?> agent) {
- // Disabled status has changed
- stopAgent(agent);
- if (!attributeEvent.<Boolean>getValue().orElse(false)) {
- startAgent(agent);
- }
+ // Old agent can be null if an update happens straight after the creation
+ if (!removeAgent(agent.getId())) {
+ return;
+ }
+
+ stopAgent(agent.getId());
+ addReplaceAgent(agent);
+
+ if (agent.isDisabled().orElse(false)) {
+ LOG.info("Agent is disabled so not starting: " + agent);
+ assetProcessingService.sendAttributeEvent(new AttributeEvent(agent.getId(), Agent.STATUS.getName(), ConnectionStatus.DISABLED));
+ } else {
+ startAgent(agent);
}
}
@@ -354,7 +344,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
getGroupedAgentLinkAttributes(
obsoleteOrModified.stream(),
attribute -> true
- ).forEach((agent, attributes) -> unlinkAttributes(agent, asset.getId(), attributes));
+ ).forEach((agent, attributes) -> unlinkAttributes(agent.getId(), asset.getId(), attributes));
// Link new or modified attributes
getGroupedAgentLinkAttributes(
@@ -368,7 +358,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
// Unlink any AGENT_LINK attributes from the referenced protocol
getGroupedAgentLinkAttributes(asset.getAttributes().stream(), attribute -> true)
- .forEach((agent, attributes) -> unlinkAttributes(agent, asset.getId(), attributes));
+ .forEach((agent, attributes) -> unlinkAttributes(agent.getId(), asset.getId(), attributes));
break;
}
}
@@ -448,9 +438,9 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
});
}
- protected void stopAgent(Agent<?,?,?> agent) {
+ protected void stopAgent(String agentId) {
withLock(getClass().getSimpleName() + "::stopAgent", () -> {
- Protocol<?> protocol = protocolInstanceMap.get(agent.getId());
+ Protocol<?> protocol = protocolInstanceMap.get(agentId);
if (protocol == null) {
return;
@@ -460,7 +450,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
Collectors.groupingBy(entry -> entry.getKey().getId(), mapping(Map.Entry::getValue, toList()))
);
- groupedAttributes.forEach((assetId, linkedAttributes) -> unlinkAttributes(agent, assetId, linkedAttributes));
+ groupedAttributes.forEach((assetId, linkedAttributes) -> unlinkAttributes(agentId, assetId, linkedAttributes));
// Stop the protocol instance
try {
@@ -470,8 +460,8 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
}
// Remove child asset subscriptions for this agent
- childAssetSubscriptions.remove(agent.getId());
- protocolInstanceMap.remove(agent.getId());
+ childAssetSubscriptions.remove(agentId);
+ protocolInstanceMap.remove(agentId);
});
}
@@ -499,9 +489,9 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
});
}
- protected void unlinkAttributes(Agent<?,?,?> agent, String assetId, List<Attribute<?>> attributes) {
+ protected void unlinkAttributes(String agentId, String assetId, List<Attribute<?>> attributes) {
withLock(getClass().getSimpleName() + "::unlinkAttributes", () -> {
- Protocol<?> protocol = getProtocolInstance(agent.getId());
+ Protocol<?> protocol = getProtocolInstance(agentId);
if (protocol == null) {
return;
@@ -530,6 +520,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
* processing of this event by the processing chain. The protocol should raise sensor updates as
* required (i.e. the protocol is responsible for synchronising state with the database).
*/
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Override
public boolean processAssetUpdate(EntityManager entityManager,
Asset<?> asset,
@@ -543,11 +534,23 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
AttributeEvent attributeEvent = new AttributeEvent(new AttributeState(asset.getId(), attribute), attribute.getTimestamp().orElseGet(timerService::getCurrentTimeMillis));
if (asset instanceof Agent) {
- LOG.fine("Attribute write for agent attribute: agent=" + asset.getId() + ", attribute=" + attribute.getName());
- onAgentUpdated(getAgents().get(asset.getId()), attributeEvent);
- // Update in memory agent
- Optional.ofNullable(getAgent(asset.getId())).ifPresent(agent -> agent.addOrReplaceAttributes(attribute));
+ // This is how we update the agent when an attribute event occurs on an agent's attribute by a client, this
+ // is not ideal as value is not committed to the DB and could in theory be consumed by another processor
+ // but we need to know the source which isn't available from the client event service.
+ // TODO: Expose event source to client event subscriptions
+ Agent<?, ?, ?> agent = getAgent(attributeEvent.getAssetId());
+
+ if (agent != null) {
+
+ // Update in memory agent
+ agent.addOrReplaceAttributes(attribute);
+
+ if (source == CLIENT && agent.isConfigurationAttribute(attribute.getName())) {
+ LOG.fine("Agent attribute event occurred from a client for an agent config attribute so updating: agent=" + agent.getId() + ", event=" + attributeEvent);
+ onAgentUpdated(agent);
+ }
+ }
// Don't consume the event as we want the agent attribute to be updated in the DB
return false;
@@ -610,8 +613,8 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
}
@SuppressWarnings("ConstantConditions")
- protected boolean removeAgent(Agent<?, ?, ?> agent) {
- return withLockReturning(getClass().getSimpleName() + "::removeAgent", () -> getAgents().remove(agent.getId()) != null);
+ protected boolean removeAgent(String agentId) {
+ return withLockReturning(getClass().getSimpleName() + "::removeAgent", () -> getAgents().remove(agentId) != null);
}
public Agent<?, ?, ?> getAgent(String agentId) {
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 875276df6..bfa92c6ee 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
@@ -492,7 +492,6 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
if (!complete) {
LOG.fine("No processor consumed the update completely, storing: " + attributeStr);
storeAttributeValue(em, asset, attribute);
- em.flush(); // Make sure constraint violations are immediately visible
}
LOG.fine("<<< Processing complete: " + attributeStr);
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
index 1c3548e13..974a87f1b 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
@@ -1176,15 +1176,15 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
new AssetEvent(AssetEvent.Cause.CREATE, loadedAsset, null)
);
- // Raise attribute event for each attribute
- asset.getAttributes().forEach(newAttribute ->
- clientEventService.publishEvent(
- new AttributeEvent(asset.getId(),
- newAttribute.getName(),
- newAttribute.getValue().orElse(null),
- newAttribute.getTimestamp().orElse(timerService.getCurrentTimeMillis()))
- .setParentId(asset.getParentId()).setRealm(asset.getRealm())
- ));
+// // Raise attribute event for each attribute
+// asset.getAttributes().forEach(newAttribute ->
+// clientEventService.publishEvent(
+// new AttributeEvent(asset.getId(),
+// newAttribute.getName(),
+// newAttribute.getValue().orElse(null),
+// newAttribute.getTimestamp().orElse(timerService.getCurrentTimeMillis()))
+// .setParentId(asset.getParentId()).setRealm(asset.getRealm())
+// ));
break;
case UPDATE:
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesService.java b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
index 651d16583..fc3d2fd25 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesService.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
@@ -403,7 +403,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
// Check if enabled status has changed
boolean wasEnabled = Arrays.stream(tenants).anyMatch(t -> tenant.getRealm().equals(t.getRealm()) && tenant.getId().equals(t.getId()));
boolean isEnabled = tenant.getEnabled() && cause != PersistenceEvent.Cause.DELETE;
- tenants = identityService.getIdentityProvider().getTenants();
+ tenants = Arrays.stream(identityService.getIdentityProvider().getTenants()).filter(Tenant::getEnabled).toArray(Tenant[]::new);
if (wasEnabled == isEnabled) {
// Nothing to do here
diff --git a/model/src/main/java/org/openremote/model/asset/Asset.java b/model/src/main/java/org/openremote/model/asset/Asset.java
index b304f5d08..0abbea087 100644
--- a/model/src/main/java/org/openremote/model/asset/Asset.java
+++ b/model/src/main/java/org/openremote/model/asset/Asset.java
@@ -22,6 +22,7 @@ package org.openremote.model.asset;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver;
import org.hibernate.annotations.Check;
+import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Formula;
import org.openremote.model.Constants;
import org.openremote.model.IdentifiableEntity;
@@ -243,6 +244,7 @@ import static org.openremote.model.Constants.PERSISTENCE_UNIQUE_ID_GENERATOR;
@JsonTypeInfo(include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type", visible = true, use = JsonTypeInfo.Id.CUSTOM, defaultImpl = UnknownAsset.class)
@JsonTypeIdResolver(AssetTypeIdResolver.class)
@AssetValid(groups = Asset.AssetSave.class)
+@DynamicUpdate
@SuppressWarnings("unchecked")
public abstract class Asset<T extends Asset<?>> implements IdentifiableEntity<T> {
diff --git a/model/src/main/java/org/openremote/model/asset/agent/Agent.java b/model/src/main/java/org/openremote/model/asset/agent/Agent.java
index bdd4d80d5..6b80a212d 100644
--- a/model/src/main/java/org/openremote/model/asset/agent/Agent.java
+++ b/model/src/main/java/org/openremote/model/asset/agent/Agent.java
@@ -20,23 +20,26 @@
package org.openremote.model.asset.agent;
import org.openremote.model.asset.Asset;
+import org.openremote.model.asset.impl.UnknownAsset;
import org.openremote.model.attribute.Attribute;
import org.openremote.model.attribute.MetaItem;
import org.openremote.model.auth.OAuthGrant;
import org.openremote.model.auth.UsernamePassword;
+import org.openremote.model.util.AssetModelUtil;
import org.openremote.model.value.AttributeDescriptor;
import org.openremote.model.value.MetaItemType;
import org.openremote.model.value.ValueType;
+import java.util.Arrays;
import java.util.Optional;
import static org.openremote.model.value.MetaItemType.AGENT_LINK;
/**
- * An agent is a special sub type of {@link Asset} that is associated with a {@link Protocol} and is responsible
- * for providing an instance of the associated {@link Protocol} when requested via {@link #getProtocolInstance}.
+ * An agent is a special sub type of {@link Asset} that is associated with a {@link Protocol} and is responsible for
+ * providing an instance of the associated {@link Protocol} when requested via {@link #getProtocolInstance}.
*/
-@SuppressWarnings( "unchecked" )
+@SuppressWarnings("unchecked")
public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V extends AgentLink<?>> extends Asset<T> {
public static final AttributeDescriptor<Boolean> DISABLED = new AttributeDescriptor<>("agentDisabled", ValueType.BOOLEAN);
@@ -77,8 +80,8 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
public static final AttributeDescriptor<String[]> MESSAGE_DELIMITERS = new AttributeDescriptor<>("messageDelimiters", ValueType.TEXT.asArray()).withOptional(true);
/**
- * For protocols that use {@link #MESSAGE_DELIMITERS}, this indicates whether or not the matched delimiter
- * should be stripped from the message.
+ * For protocols that use {@link #MESSAGE_DELIMITERS}, this indicates whether or not the matched delimiter should be
+ * stripped from the message.
*/
public static final AttributeDescriptor<Boolean> MESSAGE_STRIP_DELIMITER = new AttributeDescriptor<>("messageStripDelimiter", ValueType.BOOLEAN).withOptional(true);
@@ -127,7 +130,8 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
*/
public static final AttributeDescriptor<Integer> POLLING_MILLIS = new AttributeDescriptor<>("pollingMillis", ValueType.POSITIVE_INTEGER).withOptional(true);
- protected Agent() {}
+ protected Agent() {
+ }
protected Agent(String name) {
super(name);
@@ -154,7 +158,7 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
@SuppressWarnings("unchecked")
public T setDisabled(boolean disabled) {
getAttributes().addOrReplace(new Attribute<>(DISABLED, disabled));
- return (T)this;
+ return (T) this;
}
public Optional<ConnectionStatus> getAgentStatus() {
@@ -168,7 +172,7 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
@SuppressWarnings("unchecked")
public T setOAuthGrant(OAuthGrant value) {
getAttributes().getOrCreate(OAUTH_GRANT).setValue(value);
- return (T)this;
+ return (T) this;
}
public Optional<UsernamePassword> getUsernamePassword() {
@@ -178,7 +182,7 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
@SuppressWarnings("unchecked")
public T setUsernamePassword(UsernamePassword value) {
getAttributes().getOrCreate(USERNAME_AND_PASSWORD).setValue(value);
- return (T)this;
+ return (T) this;
}
public Optional<String> getHost() {
@@ -188,7 +192,7 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
@SuppressWarnings("unchecked")
public T setHost(String value) {
getAttributes().getOrCreate(HOST).setValue(value);
- return (T)this;
+ return (T) this;
}
public Optional<Integer> getPort() {
@@ -198,7 +202,7 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
@SuppressWarnings("unchecked")
public T setPort(Integer value) {
getAttributes().getOrCreate(PORT).setValue(value);
- return (T)this;
+ return (T) this;
}
public Optional<Integer> getBindPort() {
@@ -208,7 +212,7 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
@SuppressWarnings("unchecked")
public T setBindPort(Integer value) {
getAttributes().getOrCreate(BIND_PORT).setValue(value);
- return (T)this;
+ return (T) this;
}
public Optional<String> getBindHost() {
@@ -218,7 +222,7 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
@SuppressWarnings("unchecked")
public T setBindHost(String value) {
getAttributes().getOrCreate(BIND_HOST).setValue(value);
- return (T)this;
+ return (T) this;
}
public Optional<String> getSerialPort() {
@@ -228,7 +232,7 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
@SuppressWarnings("unchecked")
public T setSerialPort(String value) {
getAttributes().getOrCreate(SERIAL_PORT).setValue(value);
- return (T)this;
+ return (T) this;
}
public Optional<Integer> getSerialBaudrate() {
@@ -238,10 +242,32 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
@SuppressWarnings("unchecked")
public T setSerialBaudrate(Integer value) {
getAttributes().getOrCreate(SERIAL_BAUDRATE).setValue(value);
- return (T)this;
+ return (T) this;
}
public Optional<Integer> getPollingMillis() {
return getAttributes().getValue(POLLING_MILLIS);
}
+
+ /**
+ * Indicates if the specified attribute name is a configuration attribute and therefore if an {@link
+ * org.openremote.model.attribute.AttributeEvent} is detected for this attribute the agent should be stopped and
+ * restarted. The default behaviour is any attribute that has an {@link AttributeDescriptor} defined on the {@link
+ * Agent} class or one of its' subclasses is considered to be a configuration attribute for the agent; excluding
+ * {@link Agent#STATUS}. Agent's can override this behaviour as required.
+ */
+ public boolean isConfigurationAttribute(String attributeName) {
+
+ // This is an event for an agent so is it for an attribute that has a descriptor which is defined in an agent class
+ // and it's not the status attribute (or we'll end up in a loop)
+ return !attributeName.equals(Agent.STATUS.getName())
+ && AssetModelUtil.getAssetInfo(getType())
+ .map(info ->
+ Arrays.stream(info.getAttributeDescriptors())
+ .anyMatch(ad -> ad.getName().equals(attributeName)))
+ .orElse(false)
+ && AssetModelUtil.getAssetInfo(UnknownAsset.class)
+ .map(typeInfo -> Arrays.stream(typeInfo.getAttributeDescriptors()).noneMatch(ad -> ad.getName().equals(attributeName)))
+ .orElse(false);
+ }
}
diff --git a/test/src/main/groovy/org/openremote/test/ContainerTrait.groovy b/test/src/main/groovy/org/openremote/test/ContainerTrait.groovy
index 93ae25e4c..270e086eb 100644
--- a/test/src/main/groovy/org/openremote/test/ContainerTrait.groovy
+++ b/test/src/main/groovy/org/openremote/test/ContainerTrait.groovy
@@ -270,31 +270,40 @@ trait ContainerTrait {
def agentService = container.hasService(AgentService.class) ? container.getService(AgentService.class) : null
def rulesService = container.hasService(RulesService.class) ? container.getService(RulesService.class) : null
def assetProcessingService = container.hasService(AssetProcessingService.class) ? container.getService(AssetProcessingService.class) : null
+ int i=0
if (agentService != null) {
println("Waiting for agents to be deployed")
- while (TestFixture.assets.stream().filter { it instanceof Agent }.any { !agentService.agentMap.containsKey(it.id) }) {
+ i=0
+ while (i < 100 && TestFixture.assets.stream().filter { it instanceof Agent }.any { !agentService.agentMap.containsKey(it.id) }) {
Thread.sleep(100)
+ i++
}
println("Agents are deployed")
}
if (rulesService != null) {
println("Waiting for global rulesets to be deployed")
- while (TestFixture.globalRulesets.stream().filter { it.enabled }.any { rulesService.globalEngine == null || !rulesService.globalEngine.deployments.containsKey(it.id) }) {
+ i=0
+ while (i < 100 && TestFixture.globalRulesets.stream().filter { it.enabled }.any { rulesService.globalEngine == null || !rulesService.globalEngine.deployments.containsKey(it.id) }) {
Thread.sleep(100)
+ i++
}
println("Global rulesets are deployed")
println("Waiting for tenant rulesets to be deployed")
- while (TestFixture.tenantRulesets.stream().filter { it.enabled }.any { !rulesService.tenantEngines.containsKey(it.realm) || !rulesService.tenantEngines.get(it.realm).deployments.containsKey(it.id) }) {
+ i=0
+ while (i < 100 && TestFixture.tenantRulesets.stream().filter { it.enabled }.any { !rulesService.tenantEngines.containsKey(it.realm) || !rulesService.tenantEngines.get(it.realm).deployments.containsKey(it.id) }) {
Thread.sleep(100)
+ i++
}
println("Tenant rulesets are deployed")
println("Waiting for asset rulesets to be deployed")
- while (TestFixture.assetRulesets.stream().filter { it.enabled }.any { !rulesService.assetEngines.containsKey(it.assetId) || !rulesService.assetEngines.get(it.assetId).deployments.containsKey(it.id) }) {
+ i=0
+ while (i < 100 && TestFixture.assetRulesets.stream().filter { it.enabled }.any { !rulesService.assetEngines.containsKey(it.assetId) || !rulesService.assetEngines.get(it.assetId).deployments.containsKey(it.id) }) {
Thread.sleep(100)
+ i++
}
println("Asset rulesets are deployed")
}
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
index 52e95fc55..d075e6023 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
@@ -106,7 +106,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets.size() == 6
assets.get(0).id == managerTestSetup.apartment1Id
assets.get(1).id == managerTestSetup.apartment1LivingroomId
- assets.get(1).getAttributes().size() == 12
+ assets.get(1).getAttributes().size() == 14
assets.get(1).getAttribute("motionSensor").isPresent()
!assets.get(1).getAttribute("currentTemperature").get().getValue().isPresent()
!assets.get(1).getAttribute("currentTemperature").get().meta.isEmpty()
diff --git a/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy b/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy
index ff2292f3c..02b50fe62 100644
--- a/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy
@@ -62,7 +62,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
def "Gateway asset provisioning and local manager logic test"() {
given: "the container environment is started"
- def conditions = new PollingConditions(timeout: 10, delay: 0.2)
+ def conditions = new PollingConditions(timeout: 15, delay: 0.2)
def container = startContainer(defaultConfig(), defaultServices())
def assetProcessingService = container.getService(AssetProcessingService.class)
def executorService = container.getExecutorService()
@@ -408,7 +408,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
assert localBuilding1Room5Asset.getType() == RoomAsset.DESCRIPTOR.getName()
assert localBuilding1Room5Asset.getRealm() == managerTestSetup.realmBuildingTenant
assert localBuilding1Room5Asset.getParentId() == mapAssetId(gateway.id, assetIds[0], false)
- assert localBuilding1Room5Asset.getAttributes().size() == 4
+ assert localBuilding1Room5Asset.getAttributes().size() == 6
}
when: "an asset is modified on the gateway and the local manager is notified"
@@ -432,7 +432,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
assert localBuilding1Room5Asset.getType() == RoomAsset.DESCRIPTOR.getName()
assert localBuilding1Room5Asset.getRealm() == managerTestSetup.realmBuildingTenant
assert localBuilding1Room5Asset.getParentId() == mapAssetId(gateway.id, assetIds[0], false)
- assert localBuilding1Room5Asset.getAttributes().size() == 5
+ assert localBuilding1Room5Asset.getAttributes().size() == 7
assert localBuilding1Room5Asset.getAttribute("co2Level", Integer.class).flatMap{it.getValue()}.orElse(0i) == 500i
}
@@ -494,7 +494,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
assert localBuilding1Room5Asset.getType() == RoomAsset.DESCRIPTOR.getName()
assert localBuilding1Room5Asset.getRealm() == managerTestSetup.realmBuildingTenant
assert localBuilding1Room5Asset.getParentId() == mapAssetId(gateway.id, assetIds[0], false)
- assert localBuilding1Room5Asset.getAttributes().size() == 4
+ assert localBuilding1Room5Asset.getAttributes().size() == 6
assert localBuilding1Room5Asset.version == version
when: "the client received messages are cleared"
diff --git a/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy
index 853031146..578b2c67b 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy
@@ -90,7 +90,7 @@ class KNXProtocolTest extends Specification implements ManagerContainerTrait {
when: "KNX agents are created"
- def knxAgent1 = new KNXAgent("KNX Agent 2")
+ def knxAgent1 = new KNXAgent("KNX Agent 1")
.setHost("127.0.0.1")
.setBindHost("127.0.0.1")
.setRealm(Constants.MASTER_REALM)