77 changed files with 1385 additions and 349 deletions
@ -0,0 +1,37 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.actors.ruleChain; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import org.thingsboard.server.common.data.id.RuleNodeId; |
||||
|
import org.thingsboard.server.common.msg.MsgType; |
||||
|
import org.thingsboard.server.common.msg.TbActorMsg; |
||||
|
import org.thingsboard.server.common.msg.TbMsg; |
||||
|
|
||||
|
/** |
||||
|
* Created by ashvayka on 19.03.18. |
||||
|
*/ |
||||
|
@Data |
||||
|
final class RuleNodeToSelfMsg implements TbActorMsg { |
||||
|
|
||||
|
private final TbMsg msg; |
||||
|
|
||||
|
@Override |
||||
|
public MsgType getMsgType() { |
||||
|
return MsgType.RULE_TO_SELF_MSG; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.dao.exception; |
||||
|
|
||||
|
public class BufferLimitException extends RuntimeException { |
||||
|
|
||||
|
private static final long serialVersionUID = 4513762009041887588L; |
||||
|
|
||||
|
public BufferLimitException() { |
||||
|
super("Rate Limit Buffer is full"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,83 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.rule.engine.debug; |
||||
|
|
||||
|
import com.datastax.driver.core.utils.UUIDs; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.thingsboard.rule.engine.TbNodeUtils; |
||||
|
import org.thingsboard.rule.engine.api.ListeningExecutor; |
||||
|
import org.thingsboard.rule.engine.api.RuleNode; |
||||
|
import org.thingsboard.rule.engine.api.TbContext; |
||||
|
import org.thingsboard.rule.engine.api.TbNode; |
||||
|
import org.thingsboard.rule.engine.api.TbNodeConfiguration; |
||||
|
import org.thingsboard.rule.engine.api.TbNodeException; |
||||
|
import org.thingsboard.rule.engine.filter.TbJsFilterNodeConfiguration; |
||||
|
import org.thingsboard.rule.engine.js.NashornJsEngine; |
||||
|
import org.thingsboard.server.common.data.plugin.ComponentType; |
||||
|
import org.thingsboard.server.common.msg.TbMsg; |
||||
|
import org.thingsboard.server.common.msg.TbMsgMetaData; |
||||
|
|
||||
|
import javax.script.Bindings; |
||||
|
|
||||
|
import java.nio.charset.StandardCharsets; |
||||
|
import java.util.concurrent.TimeUnit; |
||||
|
|
||||
|
import static org.thingsboard.rule.engine.DonAsynchron.withCallback; |
||||
|
|
||||
|
@Slf4j |
||||
|
@RuleNode( |
||||
|
type = ComponentType.ACTION, |
||||
|
name = "generator", |
||||
|
configClazz = TbMsgGeneratorNodeConfiguration.class, |
||||
|
nodeDescription = "Periodically generates messages", |
||||
|
nodeDetails = "Generates messages with configurable period. ", |
||||
|
inEnabled = false |
||||
|
) |
||||
|
|
||||
|
public class TbMsgGeneratorNode implements TbNode { |
||||
|
|
||||
|
public static final String TB_MSG_GENERATOR_NODE_MSG = "TbMsgGeneratorNodeMsg"; |
||||
|
|
||||
|
private TbMsgGeneratorNodeConfiguration config; |
||||
|
private long delay; |
||||
|
|
||||
|
@Override |
||||
|
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { |
||||
|
this.config = TbNodeUtils.convert(configuration, TbMsgGeneratorNodeConfiguration.class); |
||||
|
this.delay = TimeUnit.SECONDS.toMillis(config.getPeriodInSeconds()); |
||||
|
ctx.tellSelf(newTickMsg(ctx), delay); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onMsg(TbContext ctx, TbMsg msg) { |
||||
|
if (msg.getType().equals(TB_MSG_GENERATOR_NODE_MSG)) { |
||||
|
TbMsgMetaData metaData = new TbMsgMetaData(); |
||||
|
if (config.getMsgMetaData() != null) { |
||||
|
config.getMsgMetaData().forEach(metaData::putValue); |
||||
|
} |
||||
|
ctx.tellNext(new TbMsg(UUIDs.timeBased(), config.getMsgType(), ctx.getSelfId(), metaData, config.getMsgBody().getBytes(StandardCharsets.UTF_8))); |
||||
|
ctx.tellSelf(newTickMsg(ctx), delay); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private TbMsg newTickMsg(TbContext ctx) { |
||||
|
return new TbMsg(UUIDs.timeBased(), TB_MSG_GENERATOR_NODE_MSG, ctx.getSelfId(), new TbMsgMetaData(), new byte[]{}); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void destroy() { |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.rule.engine.debug; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import org.thingsboard.rule.engine.api.NodeConfiguration; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Data |
||||
|
public class TbMsgGeneratorNodeConfiguration implements NodeConfiguration<TbMsgGeneratorNodeConfiguration> { |
||||
|
|
||||
|
private int msgCount; |
||||
|
private int periodInSeconds; |
||||
|
private String msgType; |
||||
|
private String msgBody; |
||||
|
private Map<String, String> msgMetaData; |
||||
|
|
||||
|
@Override |
||||
|
public TbMsgGeneratorNodeConfiguration defaultConfiguration() { |
||||
|
TbMsgGeneratorNodeConfiguration configuration = new TbMsgGeneratorNodeConfiguration(); |
||||
|
configuration.setMsgCount(0); |
||||
|
configuration.setPeriodInSeconds(1); |
||||
|
configuration.setMsgType("DebugMsg"); |
||||
|
configuration.setMsgBody("{}"); |
||||
|
return configuration; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,2 @@ |
|||||
|
.tb-message-type-autocomplete .tb-not-found{display:block;line-height:1.5;height:48px}.tb-message-type-autocomplete .tb-not-found .tb-no-entries{line-height:48px}.tb-message-type-autocomplete li{height:auto!important;white-space:normal!important} |
||||
|
/*# sourceMappingURL=rulenode-core-config.css.map*/ |
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,27 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2018 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<div hide-xs hide-sm translate class="tb-cell" flex="30">event.event-time</div> |
||||
|
<div translate class="tb-cell" flex="20">event.server</div> |
||||
|
<div translate class="tb-cell" flex="20">event.type</div> |
||||
|
<div translate class="tb-cell" flex="20">event.entity</div> |
||||
|
<div translate class="tb-cell" flex="20">event.message-id</div> |
||||
|
<div translate class="tb-cell" flex="20">event.message-type</div> |
||||
|
<div translate class="tb-cell" flex="20">event.data-type</div> |
||||
|
<div translate class="tb-cell" flex="20">event.data</div> |
||||
|
<div translate class="tb-cell" flex="20">event.metadata</div> |
||||
|
<div translate class="tb-cell" flex="20">event.error</div> |
||||
@ -0,0 +1,63 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2018 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
<div hide-xs hide-sm class="tb-cell" flex="30">{{event.createdTime | date : 'yyyy-MM-dd HH:mm:ss'}}</div> |
||||
|
<div class="tb-cell" flex="20">{{event.body.server}}</div> |
||||
|
<div class="tb-cell" flex="20">{{event.body.type}}</div> |
||||
|
<div class="tb-cell" flex="20">{{event.body.entityName}}</div> |
||||
|
<div class="tb-cell" flex="20">{{event.body.msgId}}</div> |
||||
|
<div class="tb-cell" flex="20">{{event.body.msgType}}</div> |
||||
|
<div class="tb-cell" flex="20">{{event.body.dataType}}</div> |
||||
|
<div class="tb-cell" flex="20"> |
||||
|
<md-button ng-if="event.body.data" class="md-icon-button md-primary" |
||||
|
ng-click="showContent($event, event.body.data, 'event.data', event.body.dataType)" |
||||
|
aria-label="{{ 'action.view' | translate }}"> |
||||
|
<md-tooltip md-direction="top"> |
||||
|
{{ 'action.view' | translate }} |
||||
|
</md-tooltip> |
||||
|
<md-icon aria-label="{{ 'action.view' | translate }}" |
||||
|
class="material-icons"> |
||||
|
more_horiz |
||||
|
</md-icon> |
||||
|
</md-button> |
||||
|
</div> |
||||
|
<div class="tb-cell" flex="20"> |
||||
|
<md-button ng-if="event.body.metadata" class="md-icon-button md-primary" |
||||
|
ng-click="showContent($event, event.body.metadata, 'event.metadata', 'JSON')" |
||||
|
aria-label="{{ 'action.view' | translate }}"> |
||||
|
<md-tooltip md-direction="top"> |
||||
|
{{ 'action.view' | translate }} |
||||
|
</md-tooltip> |
||||
|
<md-icon aria-label="{{ 'action.view' | translate }}" |
||||
|
class="material-icons"> |
||||
|
more_horiz |
||||
|
</md-icon> |
||||
|
</md-button> |
||||
|
</div> |
||||
|
<div class="tb-cell" flex="20"> |
||||
|
<md-button ng-if="event.body.error" class="md-icon-button md-primary" |
||||
|
ng-click="showContent($event, event.body.error, 'event.error')" |
||||
|
aria-label="{{ 'action.view' | translate }}"> |
||||
|
<md-tooltip md-direction="top"> |
||||
|
{{ 'action.view' | translate }} |
||||
|
</md-tooltip> |
||||
|
<md-icon aria-label="{{ 'action.view' | translate }}" |
||||
|
class="material-icons"> |
||||
|
more_horiz |
||||
|
</md-icon> |
||||
|
</md-button> |
||||
|
</div> |
||||
@ -0,0 +1,78 @@ |
|||||
|
/* |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
|
||||
|
/* eslint-disable import/no-unresolved, import/default */ |
||||
|
|
||||
|
import ruleNodeConfigTemplate from './rulenode-config.tpl.html'; |
||||
|
|
||||
|
/* eslint-enable import/no-unresolved, import/default */ |
||||
|
|
||||
|
/*@ngInject*/ |
||||
|
export default function RuleNodeConfigDirective($compile, $templateCache, $injector, $translate) { |
||||
|
|
||||
|
var linker = function (scope, element, attrs, ngModelCtrl) { |
||||
|
var template = $templateCache.get(ruleNodeConfigTemplate); |
||||
|
element.html(template); |
||||
|
|
||||
|
scope.$watch('configuration', function (newVal, prevVal) { |
||||
|
if (!angular.equals(newVal, prevVal)) { |
||||
|
ngModelCtrl.$setViewValue(scope.configuration); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
ngModelCtrl.$render = function () { |
||||
|
scope.configuration = ngModelCtrl.$viewValue; |
||||
|
}; |
||||
|
|
||||
|
scope.useDefinedDirective = function() { |
||||
|
return scope.nodeDefinition && |
||||
|
scope.nodeDefinition.configDirective && !scope.definedDirectiveError; |
||||
|
}; |
||||
|
|
||||
|
scope.$watch('nodeDefinition', () => { |
||||
|
if (scope.nodeDefinition) { |
||||
|
validateDefinedDirective(); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
function validateDefinedDirective() { |
||||
|
if (scope.nodeDefinition.uiResourceLoadError && scope.nodeDefinition.uiResourceLoadError.length) { |
||||
|
scope.definedDirectiveError = scope.nodeDefinition.uiResourceLoadError; |
||||
|
} else { |
||||
|
var definedDirective = scope.nodeDefinition.configDirective; |
||||
|
if (definedDirective && definedDirective.length) { |
||||
|
if (!$injector.has(definedDirective + 'Directive')) { |
||||
|
scope.definedDirectiveError = $translate.instant('rulenode.directive-is-not-loaded', {directiveName: definedDirective}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$compile(element.contents())(scope); |
||||
|
}; |
||||
|
|
||||
|
return { |
||||
|
restrict: "E", |
||||
|
require: "^ngModel", |
||||
|
scope: { |
||||
|
nodeDefinition:'=', |
||||
|
required:'=ngRequired', |
||||
|
readonly:'=ngReadonly' |
||||
|
}, |
||||
|
link: linker |
||||
|
}; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2018 The Thingsboard Authors |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
--> |
||||
|
|
||||
|
<tb-rule-node-defined-config ng-if="useDefinedDirective()" |
||||
|
ng-model="configuration" |
||||
|
rule-node-directive="{{nodeDefinition.configDirective}}" |
||||
|
ng-required="required" |
||||
|
ng-readonly="readonly"> |
||||
|
</tb-rule-node-defined-config> |
||||
|
<div class="tb-rulenode-directive-error" ng-if="definedDirectiveError">{{definedDirectiveError}}</div> |
||||
|
<tb-json-object-edit ng-if="!useDefinedDirective()" |
||||
|
class="tb-rule-node-configuration-json" |
||||
|
ng-model="configuration" |
||||
|
label="{{ 'rulenode.configuration' | translate }}" |
||||
|
ng-required="required" |
||||
|
fill-height="true"> |
||||
|
</tb-json-object-edit> |
||||
@ -0,0 +1,67 @@ |
|||||
|
/* |
||||
|
* Copyright © 2016-2018 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
|
||||
|
const SNAKE_CASE_REGEXP = /[A-Z]/g; |
||||
|
|
||||
|
/*@ngInject*/ |
||||
|
export default function RuleNodeDefinedConfigDirective($compile) { |
||||
|
|
||||
|
var linker = function (scope, element, attrs, ngModelCtrl) { |
||||
|
|
||||
|
attrs.$observe('ruleNodeDirective', function() { |
||||
|
loadTemplate(); |
||||
|
}); |
||||
|
|
||||
|
scope.$watch('configuration', function (newVal, prevVal) { |
||||
|
if (!angular.equals(newVal, prevVal)) { |
||||
|
ngModelCtrl.$setViewValue(scope.configuration); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
ngModelCtrl.$render = function () { |
||||
|
scope.configuration = ngModelCtrl.$viewValue; |
||||
|
}; |
||||
|
|
||||
|
function loadTemplate() { |
||||
|
if (scope.ruleNodeConfigScope) { |
||||
|
scope.ruleNodeConfigScope.$destroy(); |
||||
|
} |
||||
|
var directive = snake_case(attrs.ruleNodeDirective, '-'); |
||||
|
var template = `<${directive} ng-model="configuration" ng-required="required" ng-readonly="readonly"></${directive}>`; |
||||
|
element.html(template); |
||||
|
scope.ruleNodeConfigScope = scope.$new(); |
||||
|
$compile(element.contents())(scope.ruleNodeConfigScope); |
||||
|
} |
||||
|
|
||||
|
function snake_case(name, separator) { |
||||
|
separator = separator || '_'; |
||||
|
return name.replace(SNAKE_CASE_REGEXP, function(letter, pos) { |
||||
|
return (pos ? separator : '') + letter.toLowerCase(); |
||||
|
}); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
return { |
||||
|
restrict: "E", |
||||
|
require: "^ngModel", |
||||
|
scope: { |
||||
|
required:'=ngRequired', |
||||
|
readonly:'=ngReadonly' |
||||
|
}, |
||||
|
link: linker |
||||
|
}; |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue