Commit d9023482d906df834a6133aea0dd304f1433269c

Authored by Igor Kulikov
1 parent ae4a7134

TB-73: Make Rule plugin and action optional. Fix rule deletion.

@@ -72,16 +72,19 @@ public abstract class RuleManager { @@ -72,16 +72,19 @@ public abstract class RuleManager {
72 } 72 }
73 73
74 public Optional<ActorRef> update(ActorContext context, RuleId ruleId, ComponentLifecycleEvent event) { 74 public Optional<ActorRef> update(ActorContext context, RuleId ruleId, ComponentLifecycleEvent event) {
75 - RuleMetaData rule = null; 75 + RuleMetaData rule;
76 if (event != ComponentLifecycleEvent.DELETED) { 76 if (event != ComponentLifecycleEvent.DELETED) {
77 rule = systemContext.getRuleService().findRuleById(ruleId); 77 rule = systemContext.getRuleService().findRuleById(ruleId);
78 - }  
79 - if (rule == null) { 78 + } else {
80 rule = ruleMap.keySet().stream() 79 rule = ruleMap.keySet().stream()
81 .filter(r -> r.getId().equals(ruleId)) 80 .filter(r -> r.getId().equals(ruleId))
82 .peek(r -> r.setState(ComponentLifecycleState.SUSPENDED)) 81 .peek(r -> r.setState(ComponentLifecycleState.SUSPENDED))
83 .findFirst() 82 .findFirst()
84 .orElse(null); 83 .orElse(null);
  84 + if (rule != null) {
  85 + ruleMap.remove(rule);
  86 + ruleActors.remove(ruleId);
  87 + }
85 } 88 }
86 if (rule != null) { 89 if (rule != null) {
87 RuleActorMetaData actorMd = ruleMap.get(rule); 90 RuleActorMetaData actorMd = ruleMap.get(rule);
@@ -176,7 +176,7 @@ actors: @@ -176,7 +176,7 @@ actors:
176 statistics: 176 statistics:
177 # Enable/disable actor statistics 177 # Enable/disable actor statistics
178 enabled: "${ACTORS_STATISTICS_ENABLED:true}" 178 enabled: "${ACTORS_STATISTICS_ENABLED:true}"
179 - persist_frequency: "${ACTORS_STATISTICS_PERSIST_FREQUENCY:60000}" 179 + persist_frequency: "${ACTORS_STATISTICS_PERSIST_FREQUENCY:3600000}"
180 180
181 # Cache parameters 181 # Cache parameters
182 cache: 182 cache:
@@ -17,6 +17,7 @@ package org.thingsboard.server.common.data.rule; @@ -17,6 +17,7 @@ package org.thingsboard.server.common.data.rule;
17 17
18 import com.fasterxml.jackson.databind.JsonNode; 18 import com.fasterxml.jackson.databind.JsonNode;
19 import lombok.Data; 19 import lombok.Data;
  20 +import lombok.EqualsAndHashCode;
20 import org.thingsboard.server.common.data.HasName; 21 import org.thingsboard.server.common.data.HasName;
21 import org.thingsboard.server.common.data.SearchTextBased; 22 import org.thingsboard.server.common.data.SearchTextBased;
22 import org.thingsboard.server.common.data.id.RuleId; 23 import org.thingsboard.server.common.data.id.RuleId;
@@ -24,6 +25,7 @@ import org.thingsboard.server.common.data.id.TenantId; @@ -24,6 +25,7 @@ import org.thingsboard.server.common.data.id.TenantId;
24 import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; 25 import org.thingsboard.server.common.data.plugin.ComponentLifecycleState;
25 26
26 @Data 27 @Data
  28 +@EqualsAndHashCode(callSuper = true)
27 public class RuleMetaData extends SearchTextBased<RuleId> implements HasName { 29 public class RuleMetaData extends SearchTextBased<RuleId> implements HasName {
28 30
29 private static final long serialVersionUID = -5656679015122935465L; 31 private static final long serialVersionUID = -5656679015122935465L;
@@ -165,11 +165,11 @@ @@ -165,11 +165,11 @@
165 <fieldset ng-disabled="loading || !isEdit || isReadOnly"> 165 <fieldset ng-disabled="loading || !isEdit || isReadOnly">
166 <md-input-container ng-if="!isEdit || isReadOnly" flex class="md-block"> 166 <md-input-container ng-if="!isEdit || isReadOnly" flex class="md-block">
167 <label translate>plugin.plugin</label> 167 <label translate>plugin.plugin</label>
168 - <input required name="name" ng-model="plugin.name"> 168 + <input name="name" ng-model="plugin.name">
169 </md-input-container> 169 </md-input-container>
170 <tb-plugin-select ng-show="isEdit && !isReadOnly" flex 170 <tb-plugin-select ng-show="isEdit && !isReadOnly" flex
171 ng-model="plugin" 171 ng-model="plugin"
172 - tb-required="true" 172 + tb-required="false"
173 the-form="theForm" 173 the-form="theForm"
174 plugins-scope="action"> 174 plugins-scope="action">
175 </tb-plugin-select> 175 </tb-plugin-select>
@@ -85,10 +85,11 @@ export default function RuleDirective($compile, $templateCache, $mdDialog, $docu @@ -85,10 +85,11 @@ export default function RuleDirective($compile, $templateCache, $mdDialog, $docu
85 if (scope.rule) { 85 if (scope.rule) {
86 var valid = scope.rule.filters && scope.rule.filters.length > 0; 86 var valid = scope.rule.filters && scope.rule.filters.length > 0;
87 scope.theForm.$setValidity('filters', valid); 87 scope.theForm.$setValidity('filters', valid);
88 - valid = angular.isDefined(scope.rule.pluginToken) && scope.rule.pluginToken != null;  
89 - scope.theForm.$setValidity('plugin', valid);  
90 - valid = angular.isDefined(scope.rule.action) && scope.rule.action != null;  
91 - scope.theForm.$setValidity('action', valid); 88 + var processorDefined = angular.isDefined(scope.rule.processor) && scope.rule.processor != null;
  89 + var pluginDefined = angular.isDefined(scope.rule.pluginToken) && scope.rule.pluginToken != null;
  90 + var pluginActionDefined = angular.isDefined(scope.rule.action) && scope.rule.action != null;
  91 + valid = processorDefined && !pluginDefined || (pluginDefined && pluginActionDefined);
  92 + scope.theForm.$setValidity('processorOrPlugin', valid);
92 } 93 }
93 }; 94 };
94 95
@@ -160,6 +161,7 @@ export default function RuleDirective($compile, $templateCache, $mdDialog, $docu @@ -160,6 +161,7 @@ export default function RuleDirective($compile, $templateCache, $mdDialog, $docu
160 scope.$watch('rule.processor', function(newVal, prevVal) { 161 scope.$watch('rule.processor', function(newVal, prevVal) {
161 if (scope.rule && scope.isEdit && !angular.equals(newVal, prevVal)) { 162 if (scope.rule && scope.isEdit && !angular.equals(newVal, prevVal)) {
162 scope.theForm.$setDirty(); 163 scope.theForm.$setDirty();
  164 + scope.updateValidity();
163 } 165 }
164 }, true); 166 }, true);
165 167