Commit 2ca577e9c5f6b669d18689cbaf8a66f37152c98d
Merge branch 'master' of github.com:thingsboard/thingsboard
Showing
8 changed files
with
85 additions
and
3 deletions
@@ -161,7 +161,7 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh | @@ -161,7 +161,7 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh | ||
161 | private TbActorRef createRuleNodeActor(TbActorCtx ctx, RuleNode ruleNode) { | 161 | private TbActorRef createRuleNodeActor(TbActorCtx ctx, RuleNode ruleNode) { |
162 | return ctx.getOrCreateChildActor(new TbEntityActorId(ruleNode.getId()), | 162 | return ctx.getOrCreateChildActor(new TbEntityActorId(ruleNode.getId()), |
163 | () -> DefaultActorService.RULE_DISPATCHER_NAME, | 163 | () -> DefaultActorService.RULE_DISPATCHER_NAME, |
164 | - () -> new RuleNodeActor.ActorCreator(systemContext, tenantId, entityId, ruleNode.getName(), ruleNode.getId())); | 164 | + () -> new RuleNodeActor.ActorCreator(systemContext, tenantId, entityId, ruleChainName, ruleNode.getId())); |
165 | } | 165 | } |
166 | 166 | ||
167 | private void initRoutes(RuleChain ruleChain, List<RuleNode> ruleNodeList) { | 167 | private void initRoutes(RuleChain ruleChain, List<RuleNode> ruleNodeList) { |
application/src/main/java/org/thingsboard/server/actors/ruleChain/RuleNodeActorMessageProcessor.java
@@ -27,6 +27,7 @@ import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; | @@ -27,6 +27,7 @@ import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; | ||
27 | import org.thingsboard.server.common.data.rule.RuleNode; | 27 | import org.thingsboard.server.common.data.rule.RuleNode; |
28 | import org.thingsboard.server.common.msg.queue.PartitionChangeMsg; | 28 | import org.thingsboard.server.common.msg.queue.PartitionChangeMsg; |
29 | import org.thingsboard.server.common.msg.queue.RuleNodeException; | 29 | import org.thingsboard.server.common.msg.queue.RuleNodeException; |
30 | +import org.thingsboard.server.common.msg.queue.RuleNodeInfo; | ||
30 | 31 | ||
31 | /** | 32 | /** |
32 | * @author Andrew Shvayka | 33 | * @author Andrew Shvayka |
@@ -38,6 +39,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod | @@ -38,6 +39,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod | ||
38 | private RuleNode ruleNode; | 39 | private RuleNode ruleNode; |
39 | private TbNode tbNode; | 40 | private TbNode tbNode; |
40 | private DefaultTbContext defaultCtx; | 41 | private DefaultTbContext defaultCtx; |
42 | + private RuleNodeInfo info; | ||
41 | 43 | ||
42 | RuleNodeActorMessageProcessor(TenantId tenantId, String ruleChainName, RuleNodeId ruleNodeId, ActorSystemContext systemContext | 44 | RuleNodeActorMessageProcessor(TenantId tenantId, String ruleChainName, RuleNodeId ruleNodeId, ActorSystemContext systemContext |
43 | , TbActorRef parent, TbActorRef self) { | 45 | , TbActorRef parent, TbActorRef self) { |
@@ -46,6 +48,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod | @@ -46,6 +48,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod | ||
46 | this.self = self; | 48 | this.self = self; |
47 | this.ruleNode = systemContext.getRuleChainService().findRuleNodeById(tenantId, entityId); | 49 | this.ruleNode = systemContext.getRuleChainService().findRuleNodeById(tenantId, entityId); |
48 | this.defaultCtx = new DefaultTbContext(systemContext, new RuleNodeCtx(tenantId, parent, self, ruleNode)); | 50 | this.defaultCtx = new DefaultTbContext(systemContext, new RuleNodeCtx(tenantId, parent, self, ruleNode)); |
51 | + this.info = new RuleNodeInfo(ruleNodeId, ruleChainName, ruleNode != null ? ruleNode.getName() : "Unknown"); | ||
49 | } | 52 | } |
50 | 53 | ||
51 | @Override | 54 | @Override |
@@ -99,6 +102,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod | @@ -99,6 +102,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod | ||
99 | } | 102 | } |
100 | 103 | ||
101 | void onRuleChainToRuleNodeMsg(RuleChainToRuleNodeMsg msg) throws Exception { | 104 | void onRuleChainToRuleNodeMsg(RuleChainToRuleNodeMsg msg) throws Exception { |
105 | + msg.getMsg().getCallback().visit(info); | ||
102 | checkActive(msg.getMsg()); | 106 | checkActive(msg.getMsg()); |
103 | if (ruleNode.isDebugMode()) { | 107 | if (ruleNode.isDebugMode()) { |
104 | systemContext.persistDebugInput(tenantId, entityId, msg.getMsg(), msg.getFromRelationType()); | 108 | systemContext.persistDebugInput(tenantId, entityId, msg.getMsg(), msg.getFromRelationType()); |
@@ -22,11 +22,13 @@ import org.springframework.scheduling.annotation.Scheduled; | @@ -22,11 +22,13 @@ import org.springframework.scheduling.annotation.Scheduled; | ||
22 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
23 | import org.thingsboard.rule.engine.api.RpcError; | 23 | import org.thingsboard.rule.engine.api.RpcError; |
24 | import org.thingsboard.server.actors.ActorSystemContext; | 24 | import org.thingsboard.server.actors.ActorSystemContext; |
25 | +import org.thingsboard.server.common.data.id.RuleNodeId; | ||
25 | import org.thingsboard.server.common.data.id.TenantId; | 26 | import org.thingsboard.server.common.data.id.TenantId; |
26 | import org.thingsboard.server.common.msg.TbActorMsg; | 27 | import org.thingsboard.server.common.msg.TbActorMsg; |
27 | import org.thingsboard.server.common.msg.TbMsg; | 28 | import org.thingsboard.server.common.msg.TbMsg; |
28 | import org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg; | 29 | import org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg; |
29 | import org.thingsboard.server.common.msg.queue.RuleEngineException; | 30 | import org.thingsboard.server.common.msg.queue.RuleEngineException; |
31 | +import org.thingsboard.server.common.msg.queue.RuleNodeInfo; | ||
30 | import org.thingsboard.server.common.msg.queue.ServiceQueue; | 32 | import org.thingsboard.server.common.msg.queue.ServiceQueue; |
31 | import org.thingsboard.server.common.msg.queue.ServiceType; | 33 | import org.thingsboard.server.common.msg.queue.ServiceType; |
32 | import org.thingsboard.server.common.msg.queue.TbCallback; | 34 | import org.thingsboard.server.common.msg.queue.TbCallback; |
@@ -59,6 +61,7 @@ import javax.annotation.PreDestroy; | @@ -59,6 +61,7 @@ import javax.annotation.PreDestroy; | ||
59 | import java.util.Collections; | 61 | import java.util.Collections; |
60 | import java.util.HashSet; | 62 | import java.util.HashSet; |
61 | import java.util.List; | 63 | import java.util.List; |
64 | +import java.util.Map; | ||
62 | import java.util.Optional; | 65 | import java.util.Optional; |
63 | import java.util.Set; | 66 | import java.util.Set; |
64 | import java.util.UUID; | 67 | import java.util.UUID; |
@@ -185,6 +188,12 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | @@ -185,6 +188,12 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | ||
185 | } | 188 | } |
186 | 189 | ||
187 | TbRuleEngineProcessingResult result = new TbRuleEngineProcessingResult(configuration.getName(), timeout, ctx); | 190 | TbRuleEngineProcessingResult result = new TbRuleEngineProcessingResult(configuration.getName(), timeout, ctx); |
191 | + if (timeout) { | ||
192 | + printFirstOrAll(configuration, ctx, ctx.getPendingMap(), "Timeout"); | ||
193 | + } | ||
194 | + if (!ctx.getFailedMap().isEmpty()) { | ||
195 | + printFirstOrAll(configuration, ctx, ctx.getFailedMap(), "Failed"); | ||
196 | + } | ||
188 | TbRuleEngineProcessingDecision decision = ackStrategy.analyze(result); | 197 | TbRuleEngineProcessingDecision decision = ackStrategy.analyze(result); |
189 | if (statsEnabled) { | 198 | if (statsEnabled) { |
190 | stats.log(result, decision.isCommit()); | 199 | stats.log(result, decision.isCommit()); |
@@ -212,6 +221,22 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | @@ -212,6 +221,22 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | ||
212 | }); | 221 | }); |
213 | } | 222 | } |
214 | 223 | ||
224 | + private void printFirstOrAll(TbRuleEngineQueueConfiguration configuration, TbMsgPackProcessingContext ctx, Map<UUID, TbProtoQueueMsg<ToRuleEngineMsg>> map, String prefix) { | ||
225 | + boolean printAll = log.isTraceEnabled(); | ||
226 | + log.info("{} to process [{}] messages", prefix, map.size()); | ||
227 | + for (Map.Entry<UUID, TbProtoQueueMsg<ToRuleEngineMsg>> pending : map.entrySet()) { | ||
228 | + ToRuleEngineMsg tmp = pending.getValue().getValue(); | ||
229 | + TbMsg tmpMsg = TbMsg.fromBytes(configuration.getName(), tmp.getTbMsg().toByteArray(), TbMsgCallback.EMPTY); | ||
230 | + RuleNodeInfo ruleNodeInfo = ctx.getLastVisitedRuleNode(pending.getKey()); | ||
231 | + if (printAll) { | ||
232 | + log.trace("[{}] {} to process message: {}, Last Rule Node: {}", new TenantId(new UUID(tmp.getTenantIdMSB(), tmp.getTenantIdLSB())), prefix, tmpMsg, ruleNodeInfo); | ||
233 | + } else { | ||
234 | + log.info("[{}] {} to process message: {}, Last Rule Node: {}", new TenantId(new UUID(tmp.getTenantIdMSB(), tmp.getTenantIdLSB())), prefix, tmpMsg, ruleNodeInfo); | ||
235 | + break; | ||
236 | + } | ||
237 | + } | ||
238 | + } | ||
239 | + | ||
215 | @Override | 240 | @Override |
216 | protected ServiceType getServiceType() { | 241 | protected ServiceType getServiceType() { |
217 | return ServiceType.TB_RULE_ENGINE; | 242 | return ServiceType.TB_RULE_ENGINE; |
@@ -16,8 +16,10 @@ | @@ -16,8 +16,10 @@ | ||
16 | package org.thingsboard.server.service.queue; | 16 | package org.thingsboard.server.service.queue; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | +import org.thingsboard.server.common.data.id.RuleNodeId; | ||
19 | import org.thingsboard.server.common.data.id.TenantId; | 20 | import org.thingsboard.server.common.data.id.TenantId; |
20 | import org.thingsboard.server.common.msg.queue.RuleEngineException; | 21 | import org.thingsboard.server.common.msg.queue.RuleEngineException; |
22 | +import org.thingsboard.server.common.msg.queue.RuleNodeInfo; | ||
21 | import org.thingsboard.server.common.msg.queue.TbMsgCallback; | 23 | import org.thingsboard.server.common.msg.queue.TbMsgCallback; |
22 | 24 | ||
23 | import java.util.UUID; | 25 | import java.util.UUID; |
@@ -45,4 +47,10 @@ public class TbMsgPackCallback implements TbMsgCallback { | @@ -45,4 +47,10 @@ public class TbMsgPackCallback implements TbMsgCallback { | ||
45 | log.trace("[{}] ON FAILURE", id, e); | 47 | log.trace("[{}] ON FAILURE", id, e); |
46 | ctx.onFailure(tenantId, id, e); | 48 | ctx.onFailure(tenantId, id, e); |
47 | } | 49 | } |
50 | + | ||
51 | + @Override | ||
52 | + public void visit(RuleNodeInfo ruleNodeInfo) { | ||
53 | + log.trace("[{}] ON PROCESS: {}", id, ruleNodeInfo); | ||
54 | + ctx.visit(id, ruleNodeInfo); | ||
55 | + } | ||
48 | } | 56 | } |
@@ -16,8 +16,10 @@ | @@ -16,8 +16,10 @@ | ||
16 | package org.thingsboard.server.service.queue; | 16 | package org.thingsboard.server.service.queue; |
17 | 17 | ||
18 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | +import org.thingsboard.server.common.data.id.RuleNodeId; | ||
19 | import org.thingsboard.server.common.data.id.TenantId; | 20 | import org.thingsboard.server.common.data.id.TenantId; |
20 | import org.thingsboard.server.common.msg.queue.RuleEngineException; | 21 | import org.thingsboard.server.common.msg.queue.RuleEngineException; |
22 | +import org.thingsboard.server.common.msg.queue.RuleNodeInfo; | ||
21 | import org.thingsboard.server.gen.transport.TransportProtos; | 23 | import org.thingsboard.server.gen.transport.TransportProtos; |
22 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 24 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
23 | import org.thingsboard.server.service.queue.processing.TbRuleEngineSubmitStrategy; | 25 | import org.thingsboard.server.service.queue.processing.TbRuleEngineSubmitStrategy; |
@@ -32,7 +34,6 @@ import java.util.concurrent.atomic.AtomicInteger; | @@ -32,7 +34,6 @@ import java.util.concurrent.atomic.AtomicInteger; | ||
32 | public class TbMsgPackProcessingContext { | 34 | public class TbMsgPackProcessingContext { |
33 | 35 | ||
34 | private final TbRuleEngineSubmitStrategy submitStrategy; | 36 | private final TbRuleEngineSubmitStrategy submitStrategy; |
35 | - | ||
36 | private final AtomicInteger pendingCount; | 37 | private final AtomicInteger pendingCount; |
37 | private final CountDownLatch processingTimeoutLatch = new CountDownLatch(1); | 38 | private final CountDownLatch processingTimeoutLatch = new CountDownLatch(1); |
38 | @Getter | 39 | @Getter |
@@ -44,6 +45,8 @@ public class TbMsgPackProcessingContext { | @@ -44,6 +45,8 @@ public class TbMsgPackProcessingContext { | ||
44 | @Getter | 45 | @Getter |
45 | private final ConcurrentMap<TenantId, RuleEngineException> exceptionsMap = new ConcurrentHashMap<>(); | 46 | private final ConcurrentMap<TenantId, RuleEngineException> exceptionsMap = new ConcurrentHashMap<>(); |
46 | 47 | ||
48 | + private final ConcurrentMap<UUID, RuleNodeInfo> lastRuleNodeMap = new ConcurrentHashMap<>(); | ||
49 | + | ||
47 | public TbMsgPackProcessingContext(TbRuleEngineSubmitStrategy submitStrategy) { | 50 | public TbMsgPackProcessingContext(TbRuleEngineSubmitStrategy submitStrategy) { |
48 | this.submitStrategy = submitStrategy; | 51 | this.submitStrategy = submitStrategy; |
49 | this.pendingMap = submitStrategy.getPendingMap(); | 52 | this.pendingMap = submitStrategy.getPendingMap(); |
@@ -81,4 +84,13 @@ public class TbMsgPackProcessingContext { | @@ -81,4 +84,13 @@ public class TbMsgPackProcessingContext { | ||
81 | processingTimeoutLatch.countDown(); | 84 | processingTimeoutLatch.countDown(); |
82 | } | 85 | } |
83 | } | 86 | } |
87 | + | ||
88 | + public void visit(UUID id, RuleNodeInfo ruleNodeInfo) { | ||
89 | + lastRuleNodeMap.put(id, ruleNodeInfo); | ||
90 | + } | ||
91 | + | ||
92 | + public RuleNodeInfo getLastVisitedRuleNode(UUID id) { | ||
93 | + return lastRuleNodeMap.get(id); | ||
94 | + } | ||
95 | + | ||
84 | } | 96 | } |
@@ -106,7 +106,6 @@ public final class TbMsg implements Serializable { | @@ -106,7 +106,6 @@ public final class TbMsg implements Serializable { | ||
106 | if (callback != null) { | 106 | if (callback != null) { |
107 | this.callback = callback; | 107 | this.callback = callback; |
108 | } else { | 108 | } else { |
109 | - log.warn("[{}] Created message with empty callback: {}", originator, type); | ||
110 | this.callback = TbMsgCallback.EMPTY; | 109 | this.callback = TbMsgCallback.EMPTY; |
111 | } | 110 | } |
112 | } | 111 | } |
1 | +/** | ||
2 | + * Copyright © 2016-2020 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.common.msg.queue; | ||
17 | + | ||
18 | +import org.thingsboard.server.common.data.id.RuleNodeId; | ||
19 | + | ||
20 | +public class RuleNodeInfo { | ||
21 | + private final String label; | ||
22 | + | ||
23 | + public RuleNodeInfo(RuleNodeId id, String ruleChainName, String ruleNodeName) { | ||
24 | + this.label = "[RuleChain: " + ruleChainName + "|RuleNode: " + ruleNodeName + "(" + id + ")]"; | ||
25 | + } | ||
26 | + | ||
27 | + @Override | ||
28 | + public String toString() { | ||
29 | + return label; | ||
30 | + } | ||
31 | +} |