100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
RulesService minor update
Rich Turnercc850a2a2d7c
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.javaindex 830eafc34..82dff68c3 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@@ -46,6 +46,10 @@ import java.util.stream.IntStream;* asset definitions with same parent asset are not guaranteed also processing of definitions* with the same scope is not guaranteed)*/+// TODO: Listen to changes in tenant enabled status and start/stop engines accordingly+// TODO: Listen to asset changes and start/stop engines accordingly+// TODO: Listen to rule definition changes and update engines accordingly+// TODO: When restarting rules engine should we wait for executing rules to finish?public class RulesService implements ContainerService, Consumer<AssetUpdate> {private static final Logger LOG = Logger.getLogger(RulesService.class.getName());protected PersistenceService persistenceService;@@ -55,6 +59,7 @@ public class RulesService implements ContainerService, Consumer<AssetUpdate> {protected RulesDeployment<GlobalRulesDefinition> globalDeployment;protected final Map<String, RulesDeployment<TenantRulesDefinition>> tenantDeployments = new HashMap<>();protected final Map<String, RulesDeployment<AssetRulesDefinition>> assetDeployments = new HashMap<>();+ protected String[] activeTenantNames;@Overridepublic void init(Container container) throws Exception {@@ -153,6 +158,10 @@ public class RulesService implements ContainerService, Consumer<AssetUpdate> {processAssetUpdate(assetUpdate);}+ public void processTenantChange() {++ }+// protected boolean addResource(Resource resource, KieServices kieServices, KieFileSystem kfs) {// String sourcePath = resource.getSourcePath();// if (sourcePath == null) {@@ -267,23 +276,14 @@ public class RulesService implements ContainerService, Consumer<AssetUpdate> {}// Add asset engines- List<RulesDeployment> matchedAssetDeployments = new ArrayList<>();- RulesDeployment assetDeployment = assetDeployments.get(asset.getId());- if (assetDeployment != null) {- matchedAssetDeployments.add(assetDeployment);- }-- // TODO: Check if this is the correct procedure- for (String assetPathElement : asset.getReversePath()) {- RulesDeployment parentDeployment = assetDeployments.get(assetPathElement);- if (parentDeployment != null) {- matchedAssetDeployments.add(parentDeployment);+ // Iterate through asset hierarchy using asset IDs from getPath+ for (String assetId : asset.getPath()) {+ RulesDeployment assetDeployment = assetDeployments.get(assetId);+ if (assetDeployment != null) {+ rulesDeployments.add(assetDeployment);}}- Collections.reverse(matchedAssetDeployments);- rulesDeployments.addAll(matchedAssetDeployments);-// Pass through each engine if an engine is in error state then log and skip itfor (RulesDeployment deployment : rulesDeployments) {synchronized (deployment) {