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

This commit is contained in:
Igor Kulikov 2017-07-24 16:24:32 +03:00
parent ae4a71346f
commit d9023482d9
5 changed files with 17 additions and 10 deletions

View File

@ -72,16 +72,19 @@ public abstract class RuleManager {
}
public Optional<ActorRef> update(ActorContext context, RuleId ruleId, ComponentLifecycleEvent event) {
RuleMetaData rule = null;
RuleMetaData rule;
if (event != ComponentLifecycleEvent.DELETED) {
rule = systemContext.getRuleService().findRuleById(ruleId);
}
if (rule == null) {
} else {
rule = ruleMap.keySet().stream()
.filter(r -> r.getId().equals(ruleId))
.peek(r -> r.setState(ComponentLifecycleState.SUSPENDED))
.findFirst()
.orElse(null);
if (rule != null) {
ruleMap.remove(rule);
ruleActors.remove(ruleId);
}
}
if (rule != null) {
RuleActorMetaData actorMd = ruleMap.get(rule);

View File

@ -176,7 +176,7 @@ actors:
statistics:
# Enable/disable actor statistics
enabled: "${ACTORS_STATISTICS_ENABLED:true}"
persist_frequency: "${ACTORS_STATISTICS_PERSIST_FREQUENCY:60000}"
persist_frequency: "${ACTORS_STATISTICS_PERSIST_FREQUENCY:3600000}"
# Cache parameters
cache:

View File

@ -17,6 +17,7 @@ package org.thingsboard.server.common.data.rule;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.HasName;
import org.thingsboard.server.common.data.SearchTextBased;
import org.thingsboard.server.common.data.id.RuleId;
@ -24,6 +25,7 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.plugin.ComponentLifecycleState;
@Data
@EqualsAndHashCode(callSuper = true)
public class RuleMetaData extends SearchTextBased<RuleId> implements HasName {
private static final long serialVersionUID = -5656679015122935465L;

View File

@ -165,11 +165,11 @@
<fieldset ng-disabled="loading || !isEdit || isReadOnly">
<md-input-container ng-if="!isEdit || isReadOnly" flex class="md-block">
<label translate>plugin.plugin</label>
<input required name="name" ng-model="plugin.name">
<input name="name" ng-model="plugin.name">
</md-input-container>
<tb-plugin-select ng-show="isEdit && !isReadOnly" flex
ng-model="plugin"
tb-required="true"
tb-required="false"
the-form="theForm"
plugins-scope="action">
</tb-plugin-select>

View File

@ -85,10 +85,11 @@ export default function RuleDirective($compile, $templateCache, $mdDialog, $docu
if (scope.rule) {
var valid = scope.rule.filters && scope.rule.filters.length > 0;
scope.theForm.$setValidity('filters', valid);
valid = angular.isDefined(scope.rule.pluginToken) && scope.rule.pluginToken != null;
scope.theForm.$setValidity('plugin', valid);
valid = angular.isDefined(scope.rule.action) && scope.rule.action != null;
scope.theForm.$setValidity('action', valid);
var processorDefined = angular.isDefined(scope.rule.processor) && scope.rule.processor != null;
var pluginDefined = angular.isDefined(scope.rule.pluginToken) && scope.rule.pluginToken != null;
var pluginActionDefined = angular.isDefined(scope.rule.action) && scope.rule.action != null;
valid = processorDefined && !pluginDefined || (pluginDefined && pluginActionDefined);
scope.theForm.$setValidity('processorOrPlugin', valid);
}
};
@ -160,6 +161,7 @@ export default function RuleDirective($compile, $templateCache, $mdDialog, $docu
scope.$watch('rule.processor', function(newVal, prevVal) {
if (scope.rule && scope.isEdit && !angular.equals(newVal, prevVal)) {
scope.theForm.$setDirty();
scope.updateValidity();
}
}, true);