Giter Club home page Giter Club logo

rule-node-examples's Introduction

rule-node-examples

Examples of custom Rule Nodes for ThingsBoard contribution guide

Unit tests examples for custom rule nodes added as well

To build the project run mvn clean install

To build a custom Docker image run DOCKER_BUILDKIT=0 docker build . -t your_repo/tb-node:3.6.0-custom-1

rule-node-examples's People

Contributors

ashvayka avatar ikulikov avatar kalutkaz avatar shvaykad avatar smatvienko-tb avatar vvlladd28 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rule-node-examples's Issues

Hot reload custom rule node jar

Is it possible to hot reload custom rule node jar in /usr/share/thingsboard/extensions without restarting thingsboard? Thanks.

Recreate PE Scheduler as a custom rule node

Is it possible to recreate PE Scheduler as a custom rule node in CE?

Was thinking something like this as a separate rule chain, disjoint from any other rule chains.
The Scheduler node is a custom rule node
image

Any pointer is appreciated!

Thingsboard custom rule nodes - Defined configuration directive 'myTestNodeConfig' is not available

I created custom RuleNode following https://thingsboard.io/docs/user-guide/contribution/rule-node-development/ When I deploy and run, and when I insert my Custom Rule node it says

Defined configuration directive 'myTestNodeConfig' is not available.

In rule-node-examples project have it defined like this


@RuleNode(
        type = ComponentType.FILTER,
        name = "MyTestNode",
        relationTypes = {"True", "False"},
        configClazz = MyTestNodeConfiguration.class,
        nodeDescription = "Checks the existence of the selected key in the message payload.",
        nodeDetails = "If the selected key  exists - send Message via <b>True</b> chain, otherwise <b>False</b> chain is used.",
        uiResources = {"static/rulenode/custom-nodes-config.js"},
        configDirective = "myTestNodeConfig")
public class MyTestNode implements TbNode {

In rule-node-examples-ui project have it defined like below

import CheckKeyConfigDirective from './check-key-config.directive';
export default angular.module('thingsboard.ruleChain.config.filter', [])
.directive('myTestNodeConfig', CheckKeyConfigDirective)
    .name;

unable to import org.thingsboard.server.service.security.model.SecurityUser

Here is what I see in IntelliJ:
image

As an alternate path forward, I tried adding this into pom.xml and loading Maven changes but it errors out because it isn't valid either

<dependency>
    <groupId>org.thingsboard.service</groupId>
    <artifactId>security</artifactId>
    <scope>provided</scope>
    <version>${thingsboard.version}</version>
</dependency>

I looked around at https://repo.thingsboard.io/artifactory/libs-release-public/org/thingsboard/ to see if I could find something that might work for me but never figured it out myself.


I am trying to use `entityGroupService.findGroupEntities()` which requires `MergedUserPermissions` as a parameter. `org.thingsboard.server.controller.EntityGroupController.getEntities()` seems to be able to get them from a `SecurityUser` but I can't seem to get that far. My proof-of-concept code so far is:
    @Override
    public void onMsg(TbContext ctx, TbMsg msg) {
        var tenantId = ctx.getTenantId();
        var customerId = msg.getCustomerId();
        var userId = new UserId(UUID.fromString(msg.getMetaData().getValue("userId")));
        var permissions = new SecurityUser(userId).getUserPermissions();
        var entityGroupId = new EntityGroupId(UUID.fromString("Cleaner-Inspectors-User-Group")); // todo real UUID
        var pageLink = new PageLink(100);
        var entityGroupService = ctx.getPeContext().getEntityGroupService();
        var pageData = entityGroupService.findGroupEntities(tenantId, customerId, permissions, entityGroupId, pageLink);

Is there perhaps an alternate / easier way to generate a MergedUserPermissions since unlike the web API the rule engine should always have permission to do the query?

Is there an easy way to get MergedUserPermissions for my tenantId "Tenant Admin" for example?

error in custom node example compilation

Hi,

I have managed to run maven install for version 3.2.0PE following the instructions in https://thingsboard.io/docs/user-guide/contribution/rule-node-development/#step-1-download-and-build-sample-project

BUT code there is compilation issue in all 3 rule nodes related to configuration setKey()/ getKey() functions.
e.g. filter node
https://github.com/thingsboard/rule-node-examples/blob/master/src/main/java/org/thingsboard/rule/engine/node/filter/TbKeyFilterNode.java#L53

The method getKey() is undefined for the type TbKeyFilterNodeConfiguration

https://github.com/thingsboard/rule-node-examples/blob/master/src/main/java/org/thingsboard/rule/engine/node/filter/TbKeyFilterNodeConfiguration.java#L29

The method setKey(null) is undefined for the type TbKeyFilterNodeConfiguration

Am I missing something?

Thanks in advance for your responce

Is there any option to hot reload custom rule nodes (cluster deployment) to be applied?

Hi @smatvienko-tb,

Could you please check this question?

It's similar to one that was previously submitted, but in this case I'm using Thingsboard deployed in cluster with docker-compose setup.

I'm wondering if there's any possibility to reload JUST some of the microservices in order to apply changes. In that case, which ones (from docker-compose ps -a output attached in the related issue link) should I restart?

Also I've noticed that I could check that the custom nodes appears (restarting all the services), BUT another colleague tried to login and use them and he can't see the custom nodes. I've just uploaded the custom node *.jar files to one of the services (tb-core1 and /usr/share/thingsboard/extensions location).

I'm wondering if it can be the reason why my colleague does not see it?
Does each tb-core replicated service need to contain the custom nodes files? In this case, is there any possibility to configure that all of them share the same volume where the custom nodes could be located making them available for the replicas?

Hope you can help me to address above questions.

Many thanks in advance and don't hesitate to ask me if you need more details ;)

Is it needed to update thingsboard.version parameter in POM file every TB upgrade?

I had developed a few custom nodes that were working version 3.3.4

Now, I've updated Thingsboard platform to the latest version 3.5.0, but everytime I try to use a custom node, I receive errors (in method OnStart) when I try to use any of them.

I'm using Thingsboard version deployed as a cluster (with docker-compose) with a shared volume pointing to /usr/share/thingsboard/extensions (for tb-core1 & tb-core2) containing the custom nodes *.jar files.

java.lang.ClassNotFoundException: com.grupotsk.iot.rule.engine.node.external.MQTTPublisherNode
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
	at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:315)
	at org.thingsboard.server.actors.ruleChain.RuleNodeActorMessageProcessor.initComponent(RuleNodeActorMessageProcessor.java:171)
	at org.thingsboard.server.actors.ruleChain.RuleNodeActorMessageProcessor.start(RuleNodeActorMessageProcessor.java:64)
	at org.thingsboard.server.actors.service.ComponentActor.initProcessor(ComponentActor.java:63)
	at org.thingsboard.server.actors.service.ComponentActor.init(ComponentActor.java:57)
	at org.thingsboard.server.actors.TbActorMailbox.tryInit(TbActorMailbox.java:65)
	at org.thingsboard.server.actors.TbActorMailbox.lambda$tryInit$1(TbActorMailbox.java:82)
	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

I'm wondering if it is mandatory to update thingsboard.version parameter in POM file and recompile custom nodes code everytime the platform is upgraded? are not backward compatible with major versions? What can be the error if not?

Thank in advance!

Thingsboard custom rule nodes - Failed to load configuration ui resources

I created a custom RuleNode following https://thingsboard.io/docs/user-guide/contribution/rule-node-development/
customizing also the component ui starting from rule-node-examples-ui-ngx project.
When I deploy and run Thingsboard, the custom RuleNode is visible, but not the form. The error says: "Failed to load configuration ui resources"

In rule-node-examples project I defined directive like this:
configDirective = "tbExternalNodeCustomRestApiCallConfig"

In rule-node-examples-ui-ngx project I defined component selector in component ts file like this:
selector: 'tb-external-node-custom-rest-api-call-config'

Is it necessary to define directive in other places or something similar?

mvn install failed

When run mvn clean install, it failed with message:
Failed to execute goal on project rule-engine: Could not resolve dependencies for project com.custom-nodes.tb:rule-engine:jar:1.0.0: The following artifacts could not be resolved: org.thingsboard.common:data:jar:2.1.1-SNAPSHOT, org.thingsboard.common:message:jar:2.1.1-SNAPSHOT, org.thingsboard:dao:jar:2.1.1-SNAPSHOT, org.thingsboard.rule-engine:rule-engine-api:jar:2.1.1-SNAPSHOT: Could not find artifact org.thingsboard.common:data:jar:2.1.1-SNAPSHOT -> [Help 1]

Have tried to change tb.version to 2.3.0, problem not resolved.

getPeContext() doesn't seem available

I need org.thingsboard.server.dao.group.EntityGroupService for a node I am trying to write and discovered that it is oddly missing from TbContext which has the others services.

Trying to just bring it into my class like:

    protected EntityGroupService getEntityGroupService()

is also a problem because the compiler thinks group.EntityGroupService doesn't exist when I import org.thingsboard.server.dao.group.EntityGroupService;

Thinking it could be a PE only thing I set my pom.xml to have
<thingsboard.version>3.4.0PE</thingsboard.version> and did a
mvn clean install again but that didn't help.

Any ideas how I can get EntityGroupService or if it could be added into TbContext for a future release?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.