Skip to content

armgit / core

Public Imported from GitHub
0

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

Added AssetDatapointHealthStatusProvider and updated RulesHealthStatusProvider

Rich Turner3afe1d54b193
diff --git a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointHealthStatusProvider.java
new file mode 100644
index 000000000..ecefc6f5b
--- /dev/null
+++ b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointHealthStatusProvider.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.datapoint;
+
+import org.openremote.container.Container;
+import org.openremote.container.ContainerService;
+import org.openremote.model.system.HealthStatusProvider;
+import org.openremote.model.value.ObjectValue;
+import org.openremote.model.value.Value;
+import org.openremote.model.value.Values;
+
+public class AssetDatapointHealthStatusProvider implements HealthStatusProvider, ContainerService {
+
+ public static final String NAME = "datapoints";
+ public static final String VERSION = "1.0";
+ protected AssetDatapointService assetDatapointService;
+
+ @Override
+ public void init(Container container) throws Exception {
+ assetDatapointService = container.getService(AssetDatapointService.class);
+ }
+
+ @Override
+ public void start(Container container) throws Exception {
+
+ }
+
+ @Override
+ public void stop(Container container) throws Exception {
+
+ }
+
+ @Override
+ public String getHealthStatusName() {
+ return NAME;
+ }
+
+ @Override
+ public String getHealthStatusVersion() {
+ return VERSION;
+ }
+
+ @Override
+ public Value getHealthStatus() {
+ ObjectValue value = Values.createObject();
+ value.put("totalDatapoints", assetDatapointService.getDatapointsCount());
+ return value;
+ }
+}
diff --git a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
index f4597ce81..6ec010e25 100644
--- a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
+++ b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
@@ -22,6 +22,7 @@ import org.openremote.model.datapoint.NumberDatapoint;
import org.postgresql.util.PGInterval;
import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -78,15 +79,42 @@ public class AssetDatapointService implements ContainerService, AssetUpdateProce
}
public List<AssetDatapoint> getDatapoints(AttributeRef attributeRef) {
- return persistenceService.doReturningTransaction(entityManager -> entityManager.createQuery(
- "select dp from AssetDatapoint dp " +
- "where dp.entityId = :assetId " +
- "and dp.attributeName = :attributeName " +
- "order by dp.timestamp desc",
- AssetDatapoint.class)
- .setParameter("assetId", attributeRef.getEntityId())
- .setParameter("attributeName", attributeRef.getAttributeName())
- .getResultList());
+ return persistenceService.doReturningTransaction(entityManager ->
+ entityManager.createQuery(
+ "select dp from AssetDatapoint dp " +
+ "where dp.entityId = :assetId " +
+ "and dp.attributeName = :attributeName " +
+ "order by dp.timestamp desc",
+ AssetDatapoint.class)
+ .setParameter("assetId", attributeRef.getEntityId())
+ .setParameter("attributeName", attributeRef.getAttributeName())
+ .getResultList());
+ }
+
+
+ public long getDatapointsCount() {
+ return getDatapointsCount(null);
+ }
+
+ public long getDatapointsCount(AttributeRef attributeRef) {
+ return persistenceService.doReturningTransaction(entityManager -> {
+
+ String queryStr = attributeRef == null ?
+ "select count(dp) from AssetDatapoint dp" :
+ "select count(dp) from AssetDatapoint dp where dp.entityId = :assetId and dp.attributeName = :attributeName";
+
+ TypedQuery<Long> query = entityManager.createQuery(
+ queryStr,
+ Long.class);
+
+ if (attributeRef != null) {
+ query
+ .setParameter("assetId", attributeRef.getEntityId())
+ .setParameter("attributeName", attributeRef.getAttributeName());
+ }
+
+ return query.getSingleResult();
+ });
}
public NumberDatapoint[] aggregateDatapoints(AssetAttribute attribute,
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java
index 985a7cbcd..a7e8ff48e 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java
@@ -121,6 +121,7 @@ public class RulesHealthStatusProvider implements HealthStatusProvider, Containe
int executionErrorDeployments = rulesEngine.getExecutionErrorDeploymentCount();
int compilationErrorDeployments = rulesEngine.getExecutionErrorDeploymentCount();
ObjectValue val = Values.createObject();
+ val.put("isRunning", rulesEngine.isRunning());
val.put("isError", isError);
val.put("totalDeployments", totalDeployments);
val.put("executionErrorDeployments", executionErrorDeployments);
diff --git a/manager/src/main/resources/META-INF/services/org.openremote.model.system.HealthStatusProvider b/manager/src/main/resources/META-INF/services/org.openremote.model.system.HealthStatusProvider
index abd7c1225..a8c513a04 100644
--- a/manager/src/main/resources/META-INF/services/org.openremote.model.system.HealthStatusProvider
+++ b/manager/src/main/resources/META-INF/services/org.openremote.model.system.HealthStatusProvider
@@ -1,4 +1,5 @@
org.openremote.manager.system.JvmHealthStatusProvider
org.openremote.manager.system.SystemHealthStatusProvider
org.openremote.manager.rules.RulesHealthStatusProvider
-org.openremote.manager.agent.AgentHealthStatusProvider
\ No newline at end of file
+org.openremote.manager.agent.AgentHealthStatusProvider
+org.openremote.manager.datapoint.AssetDatapointHealthStatusProvider
\ No newline at end of file