use of org.openremote.model.asset.agent.ConnectionStatus in project openremote by openremote.
the class HttpClientProtocol method updateConnectionStatus.
protected void updateConnectionStatus(HttpClientRequest request, AttributeRef protocolConfigurationRef, int responseCode) {
Response.Status status = Response.Status.fromStatusCode(responseCode);
ConnectionStatus connectionStatus = ConnectionStatus.CONNECTED;
if (status == null) {
connectionStatus = ConnectionStatus.UNKNOWN;
} else {
switch(status.getFamily()) {
case INFORMATIONAL:
connectionStatus = ConnectionStatus.ERROR;
break;
case SUCCESSFUL:
connectionStatus = ConnectionStatus.CONNECTED;
break;
case REDIRECTION:
connectionStatus = ConnectionStatus.ERROR;
break;
case CLIENT_ERROR:
if (responseCode == 401 || responseCode == 402 || responseCode == 403) {
connectionStatus = ConnectionStatus.ERROR_AUTHENTICATION;
} else {
connectionStatus = ConnectionStatus.ERROR_CONFIGURATION;
}
break;
case SERVER_ERROR:
connectionStatus = ConnectionStatus.ERROR;
break;
case OTHER:
break;
}
}
LOG.fine("Updating connection status based on polling response code: URI=" + request + ", ResponseCode=" + responseCode + ", Status=" + connectionStatus);
updateStatus(protocolConfigurationRef, connectionStatus);
}
use of org.openremote.model.asset.agent.ConnectionStatus in project openremote by openremote.
the class BluetoothMeshProtocol method doStart.
// Implements AbstractProtocol ------------------------------------------------------------------
@Override
protected synchronized void doStart(Container container) throws Exception {
LOG.info("Starting Bluetooth Mesh protocol.");
String meshNetKeyParam = agent.getNetworkKey().orElseThrow(() -> {
String msg = "No Bluetooth Mesh network key provided for protocol: " + this;
LOG.warning(msg);
return new IllegalArgumentException(msg);
});
Integer netKeyIndex = extractIndex(meshNetKeyParam, DEFAULT_NETWORK_KEY_INDEX);
String netKeyAsString = extractKey(meshNetKeyParam);
if (netKeyIndex == null || netKeyAsString == null) {
String msg = "Format of network key '" + meshNetKeyParam + "' is invalid for protocol: " + this;
LOG.warning(msg);
throw new IllegalArgumentException(msg);
}
NetworkKey networkKey = new NetworkKey(netKeyIndex, MeshParserUtils.toByteArray(netKeyAsString));
String meshAppKeyParam = agent.getApplicationKey().orElseThrow(() -> {
String msg = "No Bluetooth Mesh application key provided for protocol: " + this;
LOG.warning(msg);
return new IllegalArgumentException(msg);
});
Integer appKeyIndex = extractIndex(meshAppKeyParam, DEFAULT_APPLICATION_KEY_INDEX);
String appKeyAsString = extractKey(meshAppKeyParam);
if (appKeyIndex == null || appKeyAsString == null) {
String msg = "Format of application key '" + meshAppKeyParam + "' is invalid for protocol: " + this;
LOG.warning(msg);
throw new IllegalArgumentException(msg);
}
ApplicationKey applicationKey = new ApplicationKey(appKeyIndex, MeshParserUtils.toByteArray(appKeyAsString));
String proxyAddress = agent.getProxyAddress().orElse(null);
proxyAddress = proxyAddress != null ? proxyAddress.trim() : null;
if (proxyAddress != null && !proxyAddress.matches(REGEXP_PROXY_ADDRESS)) {
String msg = "Format of proxy address '" + proxyAddress + "' is invalid for protocol: " + this;
LOG.warning(msg);
throw new IllegalArgumentException(msg);
}
String sourceAddressParam = agent.getSourceAddress().orElseThrow(() -> {
String msg = "No Bluetooth Mesh unicast source address provided for protocol: " + this;
LOG.warning(msg);
return new IllegalArgumentException(msg);
});
final Integer sourceAddress = toIntegerAddress(sourceAddressParam, null);
if (sourceAddress == null) {
String msg = "Format of Bluetooth Mesh unicast source address '" + sourceAddressParam + "' is invalid for protocol: " + this;
throw new IllegalArgumentException(msg);
}
int sequenceNumberParam = agent.getSequenceNumber().orElse(DEFAULT_SEQUENCE_NUMBER);
final int mtuParam = agent.getMtu().orElse(DEFAULT_MTU);
Map<Integer, ApplicationKey> applicationKeyMap = new HashMap<>();
applicationKeyMap.put(appKeyIndex, applicationKey);
final ScheduledExecutorService finalExecutorService = executorService;
Consumer<ConnectionStatus> statusConsumer = new Consumer<ConnectionStatus>() {
@Override
public void accept(ConnectionStatus connectionStatus) {
setConnectionStatus(connectionStatus);
if (connectionStatus == ConnectionStatus.CONNECTED) {
finalExecutorService.execute(() -> updateAllAttributes());
}
}
};
BluetoothMeshProtocol.sequenceNumberManager.load();
Integer oldSequenceNumber = BluetoothMeshProtocol.sequenceNumberManager.getSequenceNumber(networkKey, sourceAddress);
if (oldSequenceNumber == null) {
oldSequenceNumber = sequenceNumberParam;
BluetoothMeshProtocol.sequenceNumberManager.save(networkKey, sourceAddress, oldSequenceNumber);
}
BluetoothMeshProtocol.initMainThread(executorService);
meshNetwork = new BluetoothMeshNetwork(BluetoothMeshProtocol.bluetoothCentral, BluetoothMeshProtocol.sequenceNumberManager, BluetoothMeshProtocol.mainThread, proxyAddress, sourceAddress, networkKey, applicationKeyMap, mtuParam, oldSequenceNumber, executorService, statusConsumer);
BluetoothMeshProtocol.addNetwork(meshNetwork);
BluetoothMeshProtocol.mainThread.enqueue(() -> meshNetwork.start());
}
use of org.openremote.model.asset.agent.ConnectionStatus in project openremote by openremote.
the class AbstractVelbusProtocol method doLinkAttribute.
@Override
protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {
Pair<VelbusNetwork, Consumer<ConnectionStatus>> velbusNetworkConsumerPair = networkConfigurationMap.get(protocolConfiguration.getReferenceOrThrow());
if (velbusNetworkConsumerPair == null) {
LOG.info("Protocol Configuration doesn't have a valid VelbusNetwork so cannot link");
return;
}
VelbusNetwork velbusNetwork = velbusNetworkConsumerPair.key;
// Get the device that this attribute is linked to
int deviceAddress = getVelbusDeviceAddress(attribute);
// Get the property that this attribute is linked to
String property = getVelbusDevicePropertyLink(attribute);
AttributeRef attributeRef = attribute.getReferenceOrThrow();
ValueType valueType = attribute.getType().orElse(AttributeType.STRING).getValueType();
LOG.fine("Linking attribute to device '" + deviceAddress + "' and property '" + property + "': " + attributeRef);
Consumer<DevicePropertyValue> propertyValueConsumer = propertyValue -> updateLinkedAttribute(new AttributeState(attributeRef, propertyValue != null ? propertyValue.toValue(valueType) : null));
attributePropertyValueConsumers.put(attributeRef, propertyValueConsumer);
velbusNetwork.addPropertyValueConsumer(deviceAddress, property, propertyValueConsumer);
}
use of org.openremote.model.asset.agent.ConnectionStatus in project openremote by openremote.
the class AgentHealthStatusProvider method getHealthStatus.
@Override
public Object getHealthStatus() {
AtomicInteger connectedCount = new AtomicInteger(0);
AtomicInteger disabledCount = new AtomicInteger(0);
AtomicInteger errorCount = new AtomicInteger(0);
AtomicInteger otherCount = new AtomicInteger(0);
ObjectNode objectValue = ValueUtil.JSON.createObjectNode();
objectValue.put("agents", agentService.getAgents().size());
objectValue.put("protocols", agentService.protocolInstanceMap.size());
for (Agent<?, ?, ?> agent : agentService.getAgents().values()) {
ConnectionStatus status = agent.getAgentStatus().orElse(null);
if (status != null) {
switch(status) {
case DISCONNECTED:
case CONNECTING:
case DISCONNECTING:
case WAITING:
otherCount.incrementAndGet();
break;
case CONNECTED:
connectedCount.incrementAndGet();
break;
case DISABLED:
disabledCount.incrementAndGet();
break;
case ERROR:
errorCount.incrementAndGet();
break;
}
} else {
otherCount.incrementAndGet();
}
ObjectNode agentValue = ValueUtil.JSON.createObjectNode();
agentValue.put("name", agent.getName());
agentValue.put("status", status != null ? status.name() : "null");
agentValue.put("type", agent.getType());
objectValue.set(agent.getId(), agentValue);
}
objectValue.put("totalAgents", agentService.agentMap.size());
objectValue.put("connectedAgents", connectedCount.get());
objectValue.put("errorAgents", errorCount.get());
objectValue.put("disabledAgents", disabledCount.get());
objectValue.put("otherAgents", otherCount.get());
return objectValue;
}
Aggregations