Skip to content

armgit / core

Public Imported from GitHub
0

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

Protocol DeploymentStatus replaced with generic ConnectionStatus

Rich Turnerd262ff7e0822
diff --git a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
index abfc9de1e..439b4fc77 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
@@ -47,7 +47,7 @@ public abstract class AbstractProtocol implements Protocol {
private static final Logger LOG = Logger.getLogger(AbstractProtocol.class.getName());
protected final Map<AttributeRef, AssetAttribute> linkedAttributes = new HashMap<>();
- protected final Map<AttributeRef, Triplet<AssetAttribute, Consumer<DeploymentStatus>, DeploymentStatus>> linkedProtocolConfigurations = new HashMap<>();
+ protected final Map<AttributeRef, Triplet<AssetAttribute, Consumer<ConnectionStatus>, ConnectionStatus>> linkedProtocolConfigurations = new HashMap<>();
protected MessageBrokerContext messageBrokerContext;
protected ProducerTemplate producerTemplate;
protected TimerService timerService;
@@ -106,12 +106,12 @@ public abstract class AbstractProtocol implements Protocol {
@Override
- public void linkProtocolConfiguration(AssetAttribute protocolConfiguration, Consumer<DeploymentStatus> deploymentStatusConsumer) {
+ public void linkProtocolConfiguration(AssetAttribute protocolConfiguration, Consumer<ConnectionStatus> statusConsumer) {
synchronized (linkedProtocolConfigurations) {
LOG.finer("Linking protocol configuration to protocol '" + getProtocolName() + "': " + protocolConfiguration);
linkedProtocolConfigurations.put(
protocolConfiguration.getReferenceOrThrow(),
- new Triplet<>(protocolConfiguration, deploymentStatusConsumer, DeploymentStatus.LINKING)
+ new Triplet<>(protocolConfiguration, statusConsumer, ConnectionStatus.CONNECTING)
);
doLinkProtocolConfiguration(protocolConfiguration);
}
@@ -167,7 +167,7 @@ public abstract class AbstractProtocol implements Protocol {
protected AssetAttribute getLinkedProtocolConfiguration(AttributeRef protocolConfigurationRef) {
synchronized (linkedProtocolConfigurations) {
- Triplet<AssetAttribute, Consumer<DeploymentStatus>, DeploymentStatus> assetAttributeConsumerInfo = linkedProtocolConfigurations.get(protocolConfigurationRef);
+ Triplet<AssetAttribute, Consumer<ConnectionStatus>, ConnectionStatus> assetAttributeConsumerInfo = linkedProtocolConfigurations.get(protocolConfigurationRef);
// Don't bother with null check if someone calls here with an attribute not linked to this protocol
// then they're doing something wrong so fail hard and fast
return assetAttributeConsumerInfo.getValue1();
@@ -239,14 +239,14 @@ public abstract class AbstractProtocol implements Protocol {
}
/**
- * Update the deployment status of a protocol configuration by its attribute ref
+ * Update the runtime status of a protocol configuration by its attribute ref
*/
- protected void updateDeploymentStatus(AttributeRef protocolRef, DeploymentStatus deploymentStatus) {
+ protected void updateStatus(AttributeRef protocolRef, ConnectionStatus connectionStatus) {
synchronized (linkedProtocolConfigurations) {
linkedProtocolConfigurations.computeIfPresent(protocolRef,
(ref, pair) -> {
- pair.getValue2().accept(deploymentStatus);
- pair.value3 = deploymentStatus;
+ pair.getValue2().accept(connectionStatus);
+ pair.value3 = connectionStatus;
return pair;
}
);
@@ -254,11 +254,11 @@ public abstract class AbstractProtocol implements Protocol {
}
/**
- * Gets the current deployment status of a protocol configuration.
+ * Gets the current runtime status of a protocol configuration.
*/
- protected DeploymentStatus getDeploymentStatus(AssetAttribute protocolConfiguration) {
+ protected ConnectionStatus getStatus(AssetAttribute protocolConfiguration) {
synchronized (linkedProtocolConfigurations) {
- Triplet<AssetAttribute, Consumer<DeploymentStatus>, DeploymentStatus> assetAttributeConsumerInfo = linkedProtocolConfigurations.get(protocolConfiguration.getReferenceOrThrow());
+ Triplet<AssetAttribute, Consumer<ConnectionStatus>, ConnectionStatus> assetAttributeConsumerInfo = linkedProtocolConfigurations.get(protocolConfiguration.getReferenceOrThrow());
return assetAttributeConsumerInfo.getValue3();
}
}
diff --git a/agent/src/main/java/org/openremote/agent/protocol/Protocol.java b/agent/src/main/java/org/openremote/agent/protocol/Protocol.java
index b136b04e3..ae1517458 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/Protocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/Protocol.java
@@ -31,7 +31,6 @@ import org.openremote.model.attribute.MetaItem;
import org.openremote.model.value.ValueType;
import java.util.Collection;
-import java.util.List;
import java.util.function.Consumer;
/**
@@ -45,13 +44,13 @@ import java.util.function.Consumer;
* attribute must conform to {@link ProtocolConfiguration}.
* <p>
* When a protocol configuration is loaded/created for a protocol then the
- * {@link #linkProtocolConfiguration(AssetAttribute, Consumer)} method will be called.
- * The protocol should check the {@link AssetAttribute#isEnabled()} status of the protocol
+ * {@link #linkProtocolConfiguration} method will be called.
+ * The protocol should check the {@link AssetAttribute#isEnabled} status of the protocol
* configuration to determine whether or not the logical instance should be running or stopped.
* <p>
* The protocol is responsible for calling the provided consumer whenever the status of the
* logical instance changes (e.g. if the configuration is not valid then the protocol should
- * call the consumer with a value of {@link DeploymentStatus#ERROR} and it should provide
+ * call the consumer with a value of {@link ConnectionStatus#ERROR} and it should provide
* sensible logging to allow fault finding).
* <h3>Connecting attributes to actuators and sensors</h3>
* {@link AssetAttribute}s of {@link Asset}s can be linked to a protocol configuration
@@ -59,7 +58,7 @@ import java.util.function.Consumer;
* Besides the {@link AssetMeta#AGENT_LINK}, other protocol-specific meta items may also be
* required when an asset attribute is linked to a protocol configuration instance.
* Attributes linked to a protocol configuration instance will get passed to the protocol via
- * a call to {@link #linkAttributes(Collection, AssetAttribute)}.
+ * a call to {@link #linkAttributes}.
* <p>
* The protocol handles read and write of linked attributes:
* <p>
@@ -86,89 +85,42 @@ import java.util.function.Consumer;
* <p>
* Protocol configuration (logical instance) is created/loaded:
* <ol>
- * <li>{@link #linkProtocolConfiguration(AssetAttribute, Consumer)}</li>
- * <li>{@link #linkAttributes(Collection, AssetAttribute)}</li>
+ * <li>{@link #linkProtocolConfiguration}</li>
+ * <li>{@link #linkAttributes}</li>
* </ol>
* <p>
* Protocol configuration (logical instance) is modified:
* <ol>
- * <li>{@link #unlinkAttributes(Collection, AssetAttribute)}</li>
- * <li>{@link #unlinkProtocolConfiguration(AssetAttribute)}</li>
- * <li>{@link #linkProtocolConfiguration(AssetAttribute, Consumer)}</li>
- * <li>{@link #linkAttributes(Collection, AssetAttribute)}</li>
+ * <li>{@link #unlinkAttributes}</li>
+ * <li>{@link #unlinkProtocolConfiguration)}</li>
+ * <li>{@link #linkProtocolConfiguration}</li>
+ * <li>{@link #linkAttributes}</li>
* </ol>
* <p>
* Protocol configuration (logical instance) is removed:
* <ol>
- * <li>{@link #unlinkAttributes(Collection, AssetAttribute)}</li>
- * <li>{@link #unlinkProtocolConfiguration(AssetAttribute)}</li>
+ * <li>{@link #unlinkAttributes}</li>
+ * <li>{@link #unlinkProtocolConfiguration}</li>
* </ol>
* <p>
* Attribute linked to protocol configuration is created/loaded:
* <ol>
- * <li>{@link #linkAttributes(Collection, AssetAttribute)}</li>
+ * <li>{@link #linkAttributes}</li>
* </ol>
* <p>
* Attribute linked to protocol configuration is modified:
* <ol>
- * <li>{@link #unlinkAttributes(Collection, AssetAttribute)}</li>
- * <li>{@link #linkAttributes(Collection, AssetAttribute)}</li>
+ * <li>{@link #unlinkAttributes}</li>
+ * <li>{@link #linkAttributes}</li>
* </ol>
* <p>
* Attribute link to protocol configuration is removed:
* <ol>
- * <li>{@link #unlinkAttributes(Collection, AssetAttribute)}</li>
+ * <li>{@link #unlinkAttributes}</li>
* </ol>
*/
public interface Protocol extends ContainerService {
- /**
- * Indicates the deployment status of a protocol configuration (i.e. protocol instance).
- */
- enum DeploymentStatus {
-
- /**
- * Protocol configuration has not yet been linked (i.e. {@link #linkProtocolConfiguration}
- * hasn't yet been called for the configuration).
- */
- UNLINKED,
-
- /**
- * Protocol configuration is being linked to the protocol.
- */
- LINKING,
-
- /**
- * Protocol configuration is being unlinked from the protocol.
- */
- UNLINKING,
-
- /**
- * Protocol configuration has been linked, is valid and it is enabled.
- */
- LINKED_ENABLED,
-
- /**
- * Protocol configuration has been linked, it is valid but it is not enabled (i.e. it has a
- * {@link org.openremote.model.asset.AssetMeta#ENABLED} {@link MetaItem}
- * with a value of <code>false</code>).
- */
- LINKED_DISABLED,
-
- /**
- * Protocol configuration is not valid or some internal protocol error occurred that prevents
- * this configuration from running (the protocol should provide sensible logging to allow fault
- * finding).
- */
- ERROR,
-
- /**
- * Protocol is performing an operation that means the status cannot be exactly determined at this
- * time (e.g. the protocol is trying to re-establish a connection to a remote server).
- */
- UPDATING
- }
-
String ACTUATOR_TOPIC_TARGET_PROTOCOL = "Protocol";
String SENSOR_QUEUE_SOURCE_PROTOCOL = "Protocol";
@@ -186,7 +138,7 @@ public interface Protocol extends ContainerService {
* Links attributes to their protocolConfiguration; the protocolConfiguration would have
* been linked before this call. If an attribute is not valid for this protocol or the protocol
* Configuration then it is up to the protocol whether to put the entire protocolConfiguration
- * into an {@link DeploymentStatus#ERROR} state or to continue running (appropriate logging should
+ * into an {@link ConnectionStatus#ERROR} state or to continue running (appropriate logging should
* always be used).
* <p>
* Attributes are linked to a protocol configuration via an {@link AssetMeta#AGENT_LINK} meta item.
@@ -200,10 +152,10 @@ public interface Protocol extends ContainerService {
void unlinkAttributes(Collection<AssetAttribute> attributes, AssetAttribute protocolConfiguration) throws Exception;
/**
- * Links the protocol configuration to the protocol; the protocol is responsible for calling the deploymentStatusConsumer
- * to indicate the state of the protocol configuration.
+ * Links the protocol configuration to the protocol; the protocol is responsible for calling the statusConsumer
+ * to indicate the runtime state of the protocol configuration.
*/
- void linkProtocolConfiguration(AssetAttribute protocolConfiguration, Consumer<DeploymentStatus> deploymentStatusConsumer);
+ void linkProtocolConfiguration(AssetAttribute protocolConfiguration, Consumer<ConnectionStatus> statusConsumer);
/**
* Un-links the protocol configuration from the protocol; called whenever a protocolConfiguration is modified
diff --git a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java
index 366f03159..ef03b12a5 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java
@@ -20,6 +20,7 @@
package org.openremote.agent.protocol.macro;
import org.openremote.agent.protocol.AbstractProtocol;
+import org.openremote.agent.protocol.ConnectionStatus;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.attribute.*;
import org.openremote.model.util.Pair;
@@ -157,13 +158,13 @@ public class MacroProtocol extends AbstractProtocol {
// Check macro configuration is valid
if (!isValidMacroConfiguration(protocolConfiguration)) {
LOG.fine("Macro configuration is not valid: " + protocolConfiguration);
- updateDeploymentStatus(macroRef, DeploymentStatus.ERROR);
+ updateStatus(macroRef, ConnectionStatus.ERROR);
// Put an empty list of actions against this macro
macroMap.put(macroRef, new Pair<>(isEnabled, Collections.emptyList()));
} else {
// Store the macro actions for later execution requests
macroMap.put(macroRef, new Pair<>(isEnabled, MacroConfiguration.getMacroActions(protocolConfiguration)));
- updateDeploymentStatus(macroRef, isEnabled ? DeploymentStatus.LINKED_ENABLED : DeploymentStatus.LINKED_DISABLED);
+ updateStatus(macroRef, isEnabled ? ConnectionStatus.CONNECTED : ConnectionStatus.DISABLED);
}
}
}
diff --git a/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java
index 2861da15f..04d6189c9 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/simulator/SimulatorProtocol.java
@@ -20,6 +20,7 @@
package org.openremote.agent.protocol.simulator;
import org.openremote.agent.protocol.AbstractProtocol;
+import org.openremote.agent.protocol.ConnectionStatus;
import org.openremote.agent.protocol.simulator.element.*;
import org.openremote.model.AbstractValueHolder;
import org.openremote.model.asset.AssetAttribute;
@@ -150,7 +151,7 @@ public class SimulatorProtocol extends AbstractProtocol {
.flatMap(AbstractValueHolder::getValueAsInteger)
.orElse(DEFAULT_WRITE_DELAY);
- updateDeploymentStatus(protocolRef, protocolConfiguration.isEnabled() ? DeploymentStatus.LINKED_ENABLED : DeploymentStatus.LINKED_DISABLED);
+ updateStatus(protocolRef, protocolConfiguration.isEnabled() ? ConnectionStatus.CONNECTED : ConnectionStatus.DISABLED);
return new Instance(mode, writeDelay, protocolConfiguration.isEnabled());
}
);
diff --git a/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java
index e83789499..12d5f7fd7 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java
@@ -20,6 +20,7 @@
package org.openremote.agent.protocol.timer;
import org.openremote.agent.protocol.AbstractProtocol;
+import org.openremote.agent.protocol.ConnectionStatus;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.AssetMeta;
import org.openremote.model.attribute.AttributeEvent;
@@ -79,7 +80,7 @@ public class TimerProtocol extends AbstractProtocol {
// Verify that this is a valid Timer Configuration
if (!isValidTimerConfiguration(protocolConfiguration)) {
LOG.warning("Timer Configuration is not valid so it will be ignored: " + protocolRef);
- updateDeploymentStatus(protocolRef, DeploymentStatus.ERROR);
+ updateStatus(protocolRef, ConnectionStatus.ERROR);
return;
}
@@ -90,7 +91,7 @@ public class TimerProtocol extends AbstractProtocol {
if (expressionParser == null || !expressionParser.isValid()) {
LOG.warning("Timer cron expression is missing or invalid");
- updateDeploymentStatus(protocolRef, DeploymentStatus.ERROR);
+ updateStatus(protocolRef, ConnectionStatus.ERROR);
return;
}
@@ -145,7 +146,7 @@ public class TimerProtocol extends AbstractProtocol {
// check event value is a boolean
boolean enabled = Values.getBoolean(event.getValue()
.orElse(null))
- .orElseThrow(() -> new IllegalStateException("Writing to protocol configuration ENABLED property requires a boolean value"));
+ .orElseThrow(() -> new IllegalStateException("Writing to protocol configuration CONNECTED property requires a boolean value"));
if (enabled == protocolConfiguration.isEnabled()) {
LOG.finer("Protocol configuration enabled status is already: " + enabled);
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 0b72ec3cc..3a8202574 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
@@ -20,6 +20,7 @@
package org.openremote.manager.server.agent;
import org.apache.camel.builder.RouteBuilder;
+import org.openremote.agent.protocol.ConnectionStatus;
import org.openremote.agent.protocol.Protocol;
import org.openremote.agent.protocol.ProtocolAssetService;
import org.openremote.container.Container;
@@ -49,7 +50,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.openremote.agent.protocol.Protocol.ACTUATOR_TOPIC;
-import static org.openremote.agent.protocol.Protocol.DeploymentStatus.*;
+import static org.openremote.agent.protocol.ConnectionStatus.*;
import static org.openremote.agent.protocol.Protocol.SENSOR_QUEUE;
import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_TOPIC;
import static org.openremote.manager.server.asset.AssetProcessingService.ASSET_QUEUE;
@@ -76,7 +77,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
protected AssetStorageService assetStorageService;
protected AssetDatapointService assetDatapointService;
protected MessageBrokerService messageBrokerService;
- protected final Map<AttributeRef, Pair<AssetAttribute, Protocol.DeploymentStatus>> protocolConfigurations = new HashMap<>();
+ protected final Map<AttributeRef, Pair<AssetAttribute, ConnectionStatus>> protocolConfigurations = new HashMap<>();
protected final Map<String, Protocol> protocols = new HashMap<>();
@Override
@@ -379,17 +380,17 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
synchronized (protocolConfigurations) {
// Create a consumer callback for deployment status updates
- Consumer<Protocol.DeploymentStatus> deploymentStatusConsumer = status ->
+ Consumer<ConnectionStatus> deploymentStatusConsumer = status ->
publishProtocolDeploymentStatus(protocolAttributeRef, status);
// Store the info
protocolConfigurations.put(
protocolAttributeRef,
- new Pair<>(protocolConfiguration, LINKING)
+ new Pair<>(protocolConfiguration, CONNECTING)
);
// Set status to linking
- publishProtocolDeploymentStatus(protocolAttributeRef, LINKING);
+ publishProtocolDeploymentStatus(protocolAttributeRef, CONNECTING);
// Link the protocol configuration to the protocol
try {
@@ -465,24 +466,24 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
LOG.log(Level.SEVERE, "Protocol threw an exception during protocol configuration unlinking", e);
}
- // Set status to error
- publishProtocolDeploymentStatus(protocolAttributeRef, UNLINKED);
+ // Set status to disconnected
+ publishProtocolDeploymentStatus(protocolAttributeRef, DISCONNECTED);
protocolConfigurations.remove(protocolAttributeRef);
}
}
// TODO: Implement mechanism for publishing/subscribing to protocolconfiguration deployment status
- protected void publishProtocolDeploymentStatus(AttributeRef protocolRef, Protocol.DeploymentStatus status) {
- LOG.fine("Protocol status updated to '" + status + "': " + protocolRef);
+ protected void publishProtocolDeploymentStatus(AttributeRef protocolRef, ConnectionStatus connectionStatus) {
+ LOG.fine("Protocol status updated to '" + connectionStatus + "': " + protocolRef);
synchronized (protocolConfigurations) {
- Pair<AssetAttribute, Protocol.DeploymentStatus> protocolDeploymentInfo = protocolConfigurations.get(protocolRef);
+ Pair<AssetAttribute, ConnectionStatus> protocolDeploymentInfo = protocolConfigurations.get(protocolRef);
if (protocolDeploymentInfo != null) {
- protocolDeploymentInfo.value = status;
+ protocolDeploymentInfo.value = connectionStatus;
}
}
}
- public Protocol.DeploymentStatus getProtocolDeploymentStatus(AttributeRef protocolRef) {
+ public ConnectionStatus getProtocolDeploymentStatus(AttributeRef protocolRef) {
synchronized (protocolConfigurations) {
return Optional.ofNullable(protocolConfigurations.get(protocolRef))
.map(pair -> pair.value)
@@ -614,7 +615,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
public Optional<AssetAttribute> getProtocolConfiguration(AttributeRef protocolRef) {
synchronized (protocolConfigurations) {
- Pair<AssetAttribute, Protocol.DeploymentStatus> deploymentStatusPair = protocolConfigurations.get(protocolRef);
+ Pair<AssetAttribute, ConnectionStatus> deploymentStatusPair = protocolConfigurations.get(protocolRef);
return deploymentStatusPair == null ? Optional.empty() : Optional.of(deploymentStatusPair.key);
}
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/event/ClientEventService.java b/manager/server/src/main/java/org/openremote/manager/server/event/ClientEventService.java
index 44234648e..0f29b475d 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/event/ClientEventService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/event/ClientEventService.java
@@ -104,6 +104,8 @@ public class ClientEventService implements ContainerService {
protected MessageBrokerService messageBrokerService;
protected EventSubscriptions eventSubscriptions;
+ protected boolean stopped;
+
@Override
public void init(Container container) throws Exception {
messageBrokerService = container.getService(MessageBrokerService.class);
@@ -184,11 +186,12 @@ public class ClientEventService implements ContainerService {
@Override
public void start(Container container) {
+ stopped = false;
}
@Override
public void stop(Container container) {
-
+ stopped = true;
}
public void addSubscriptionAuthorizer(EventSubscriptionAuthorizer authorizer) {
@@ -196,6 +199,11 @@ public class ClientEventService implements ContainerService {
}
public void publishEvent(SharedEvent event) {
+ // Only publish if service is not stopped
+ if (stopped) {
+ return;
+ }
+
if (messageBrokerService != null && messageBrokerService.getProducerTemplate() != null) {
// Don't log that we are publishing a syslog event,
if (!(event instanceof SyslogEvent)) {
diff --git a/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy b/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
index 6db8ff0b9..0a1f2aab2 100644
--- a/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
@@ -20,7 +20,7 @@
package org.openremote.test.protocol
import org.openremote.agent.protocol.AbstractProtocol
-import org.openremote.agent.protocol.Protocol
+import org.openremote.agent.protocol.ConnectionStatus
import org.openremote.manager.server.agent.AgentService
import org.openremote.manager.server.asset.AssetProcessingService
import org.openremote.manager.server.asset.AssetStorageService
@@ -41,7 +41,7 @@ import spock.util.concurrent.PollingConditions
*/
class BasicProtocolTest extends Specification implements ManagerContainerTrait {
- def "Check processing of asset updates"() {
+ def "Check abstract protocol linking/un-linking"() {
given: "expected conditions"
def conditions = new PollingConditions(timeout: 10, delay: 1)
@@ -78,13 +78,13 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
protocolMethodCalls.add("LINK_PROTOCOL")
protocolLinkedConfigurations.add(protocolConfiguration)
if (!protocolConfiguration.getMetaItem("MOCK_REQUIRED_META").isPresent()) {
- updateDeploymentStatus(protocolConfiguration.getReferenceOrThrow(), Protocol.DeploymentStatus.ERROR)
+ updateStatus(protocolConfiguration.getReferenceOrThrow(), ConnectionStatus.ERROR)
} else if(protocolConfiguration.getMetaItem("MOCK_THROW_EXCEPTION").isPresent()) {
throw new IllegalStateException("Exception occurred whilst linking the protocol configuration")
} else if (protocolConfiguration.isEnabled()) {
- updateDeploymentStatus(protocolConfiguration.getReferenceOrThrow(), Protocol.DeploymentStatus.LINKED_ENABLED)
+ updateStatus(protocolConfiguration.getReferenceOrThrow(), ConnectionStatus.CONNECTED)
} else {
- updateDeploymentStatus(protocolConfiguration.getReferenceOrThrow(), Protocol.DeploymentStatus.LINKED_DISABLED)
+ updateStatus(protocolConfiguration.getReferenceOrThrow(), ConnectionStatus.DISABLED)
}
}
@@ -104,8 +104,8 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
}
protocolLinkedAttributes[protocolConfiguration.getName().orElse("")] << attribute
- def deploymentStatus = getDeploymentStatus(protocolConfiguration);
- if (deploymentStatus == Protocol.DeploymentStatus.LINKED_ENABLED) {
+ def deploymentStatus = getStatus(protocolConfiguration);
+ if (deploymentStatus == ConnectionStatus.CONNECTED) {
String attributeName = attribute.getName().orElse("");
if (attributeName.startsWith("lightToggle")) {
// Set all lights to on
@@ -181,10 +181,10 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {
assert config2 != null
assert config3 != null
assert config4 != null
- assert agentService.getProtocolDeploymentStatus(config1.getReferenceOrThrow()) == Protocol.DeploymentStatus.LINKED_ENABLED
- assert agentService.getProtocolDeploymentStatus(config2.getReferenceOrThrow()) == Protocol.DeploymentStatus.ERROR
- assert agentService.getProtocolDeploymentStatus(config3.getReferenceOrThrow()) == Protocol.DeploymentStatus.ERROR
- assert agentService.getProtocolDeploymentStatus(config4.getReferenceOrThrow()) == Protocol.DeploymentStatus.LINKED_DISABLED
+ assert agentService.getProtocolDeploymentStatus(config1.getReferenceOrThrow()) == ConnectionStatus.CONNECTED
+ assert agentService.getProtocolDeploymentStatus(config2.getReferenceOrThrow()) == ConnectionStatus.ERROR
+ assert agentService.getProtocolDeploymentStatus(config3.getReferenceOrThrow()) == ConnectionStatus.ERROR
+ assert agentService.getProtocolDeploymentStatus(config4.getReferenceOrThrow()) == ConnectionStatus.DISABLED
}
when: "a mock thing asset is created that links to the mock protocol configurations"