Showing
11 changed files
with
13 additions
and
402 deletions
... | ... | @@ -36,7 +36,6 @@ import org.springframework.data.redis.core.RedisTemplate; |
36 | 36 | import org.springframework.scheduling.annotation.Scheduled; |
37 | 37 | import org.springframework.stereotype.Component; |
38 | 38 | import org.thingsboard.rule.engine.api.MailService; |
39 | -import org.thingsboard.rule.engine.api.RuleChainTransactionService; | |
40 | 39 | import org.thingsboard.server.actors.service.ActorService; |
41 | 40 | import org.thingsboard.server.actors.tenant.DebugTbRateLimits; |
42 | 41 | import org.thingsboard.server.common.data.DataConstants; |
... | ... | @@ -67,7 +66,6 @@ import org.thingsboard.server.dao.timeseries.TimeseriesService; |
67 | 66 | import org.thingsboard.server.dao.user.UserService; |
68 | 67 | import org.thingsboard.server.queue.discovery.PartitionService; |
69 | 68 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
70 | -import org.thingsboard.server.queue.provider.TbQueueProducerProvider; | |
71 | 69 | import org.thingsboard.server.service.component.ComponentDiscoveryService; |
72 | 70 | import org.thingsboard.server.service.encoding.DataDecodingEncodingService; |
73 | 71 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
... | ... | @@ -246,10 +244,6 @@ public class ActorSystemContext { |
246 | 244 | @Getter |
247 | 245 | private TbCoreDeviceRpcService tbCoreDeviceRpcService; |
248 | 246 | |
249 | - @Autowired(required = false) | |
250 | - @Getter | |
251 | - private RuleChainTransactionService ruleChainTransactionService; | |
252 | - | |
253 | 247 | @Value("${actors.session.max_concurrent_sessions_per_device:1}") |
254 | 248 | @Getter |
255 | 249 | private long maxConcurrentSessionsPerDevice; | ... | ... |
... | ... | @@ -24,7 +24,6 @@ import lombok.extern.slf4j.Slf4j; |
24 | 24 | import org.springframework.data.redis.core.RedisTemplate; |
25 | 25 | import org.thingsboard.common.util.ListeningExecutor; |
26 | 26 | import org.thingsboard.rule.engine.api.MailService; |
27 | -import org.thingsboard.rule.engine.api.RuleChainTransactionService; | |
28 | 27 | import org.thingsboard.rule.engine.api.RuleEngineRpcService; |
29 | 28 | import org.thingsboard.rule.engine.api.RuleEngineTelemetryService; |
30 | 29 | import org.thingsboard.rule.engine.api.ScriptEngine; |
... | ... | @@ -379,11 +378,6 @@ class DefaultTbContext implements TbContext { |
379 | 378 | } |
380 | 379 | |
381 | 380 | @Override |
382 | - public RuleChainTransactionService getRuleChainTransactionService() { | |
383 | - return mainCtx.getRuleChainTransactionService(); | |
384 | - } | |
385 | - | |
386 | - @Override | |
387 | 381 | public EventLoopGroup getSharedEventLoop() { |
388 | 382 | return mainCtx.getSharedEventLoopGroupService().getSharedEventLoopGroup(); |
389 | 383 | } | ... | ... |
application/src/main/java/org/thingsboard/server/service/transaction/BaseRuleChainTransactionService.java
deleted
100644 → 0
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.service.transaction; | |
17 | - | |
18 | -import lombok.extern.slf4j.Slf4j; | |
19 | -import org.springframework.beans.factory.annotation.Value; | |
20 | -import org.springframework.stereotype.Service; | |
21 | -import org.thingsboard.common.util.ThingsBoardThreadFactory; | |
22 | -import org.thingsboard.rule.engine.api.RuleChainTransactionService; | |
23 | -import org.thingsboard.server.common.data.id.EntityId; | |
24 | -import org.thingsboard.server.common.msg.TbMsg; | |
25 | -import org.thingsboard.server.queue.util.TbRuleEngineComponent; | |
26 | -import org.thingsboard.server.service.executors.DbCallbackExecutorService; | |
27 | - | |
28 | -import javax.annotation.PostConstruct; | |
29 | -import javax.annotation.PreDestroy; | |
30 | -import java.util.Queue; | |
31 | -import java.util.concurrent.BlockingQueue; | |
32 | -import java.util.concurrent.Callable; | |
33 | -import java.util.concurrent.ConcurrentHashMap; | |
34 | -import java.util.concurrent.ConcurrentLinkedQueue; | |
35 | -import java.util.concurrent.ConcurrentMap; | |
36 | -import java.util.concurrent.ExecutorService; | |
37 | -import java.util.concurrent.Executors; | |
38 | -import java.util.concurrent.LinkedBlockingQueue; | |
39 | -import java.util.concurrent.TimeUnit; | |
40 | -import java.util.concurrent.locks.Lock; | |
41 | -import java.util.concurrent.locks.ReentrantLock; | |
42 | -import java.util.function.Consumer; | |
43 | - | |
44 | -@Service | |
45 | -@TbRuleEngineComponent | |
46 | -@Slf4j | |
47 | -public class BaseRuleChainTransactionService implements RuleChainTransactionService { | |
48 | - | |
49 | - private final DbCallbackExecutorService callbackExecutor; | |
50 | - | |
51 | - @Value("${actors.rule.transaction.queue_size}") | |
52 | - private int finalQueueSize; | |
53 | - @Value("${actors.rule.transaction.duration}") | |
54 | - private long duration; | |
55 | - | |
56 | - private final Lock transactionLock = new ReentrantLock(); | |
57 | - private final ConcurrentMap<EntityId, BlockingQueue<TbTransactionTask>> transactionMap = new ConcurrentHashMap<>(); | |
58 | - private final Queue<TbTransactionTask> timeoutQueue = new ConcurrentLinkedQueue<>(); | |
59 | - | |
60 | - private ExecutorService timeoutExecutor; | |
61 | - | |
62 | - public BaseRuleChainTransactionService(DbCallbackExecutorService callbackExecutor) { | |
63 | - this.callbackExecutor = callbackExecutor; | |
64 | - } | |
65 | - | |
66 | - @PostConstruct | |
67 | - public void init() { | |
68 | - timeoutExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("rule-chain-transaction")); | |
69 | - executeOnTimeout(); | |
70 | - } | |
71 | - | |
72 | - @PreDestroy | |
73 | - public void destroy() { | |
74 | - if (timeoutExecutor != null) { | |
75 | - timeoutExecutor.shutdownNow(); | |
76 | - } | |
77 | - } | |
78 | - | |
79 | - @Override | |
80 | - public void beginTransaction(TbMsg msg, Consumer<TbMsg> onStart, Consumer<TbMsg> onEnd, Consumer<Throwable> onFailure) { | |
81 | - transactionLock.lock(); | |
82 | - try { | |
83 | - BlockingQueue<TbTransactionTask> queue = transactionMap.computeIfAbsent(msg.getTransactionData().getOriginatorId(), id -> | |
84 | - new LinkedBlockingQueue<>(finalQueueSize)); | |
85 | - | |
86 | - TbTransactionTask transactionTask = new TbTransactionTask(msg, onStart, onEnd, onFailure, System.currentTimeMillis() + duration); | |
87 | - int queueSize = queue.size(); | |
88 | - if (queueSize >= finalQueueSize) { | |
89 | - log.trace("Queue has no space: {}", transactionTask); | |
90 | - executeOnFailure(transactionTask.getOnFailure(), "Queue has no space!"); | |
91 | - } else { | |
92 | - addMsgToQueues(queue, transactionTask); | |
93 | - if (queueSize == 0) { | |
94 | - executeOnSuccess(transactionTask.getOnStart(), transactionTask.getMsg()); | |
95 | - } else { | |
96 | - log.trace("Msg [{}][{}] is waiting to start transaction!", msg.getId(), msg.getType()); | |
97 | - } | |
98 | - } | |
99 | - } finally { | |
100 | - transactionLock.unlock(); | |
101 | - } | |
102 | - } | |
103 | - | |
104 | - @Override | |
105 | - public void endTransaction(TbMsg msg, Consumer<TbMsg> onSuccess, Consumer<Throwable> onFailure) { | |
106 | - //TODO 2.5 | |
107 | -// Optional<ServerAddress> address = routingService.resolveById(msg.getTransactionData().getOriginatorId()); | |
108 | -// if (address.isPresent()) { | |
109 | -// sendTransactionEventToRemoteServer(msg, address.get()); | |
110 | -// executeOnSuccess(onSuccess, msg); | |
111 | -// } else { | |
112 | - endLocalTransaction(msg, onSuccess, onFailure); | |
113 | -// } | |
114 | - } | |
115 | - | |
116 | - private void addMsgToQueues(BlockingQueue<TbTransactionTask> queue, TbTransactionTask transactionTask) { | |
117 | - queue.offer(transactionTask); | |
118 | - timeoutQueue.offer(transactionTask); | |
119 | - log.trace("Added msg to queue, size: [{}]", queue.size()); | |
120 | - } | |
121 | - | |
122 | - private void endLocalTransaction(TbMsg msg, Consumer<TbMsg> onSuccess, Consumer<Throwable> onFailure) { | |
123 | - transactionLock.lock(); | |
124 | - try { | |
125 | - BlockingQueue<TbTransactionTask> queue = transactionMap.computeIfAbsent(msg.getTransactionData().getOriginatorId(), id -> | |
126 | - new LinkedBlockingQueue<>(finalQueueSize)); | |
127 | - | |
128 | - TbTransactionTask currentTransactionTask = queue.peek(); | |
129 | - if (currentTransactionTask != null) { | |
130 | - if (currentTransactionTask.getMsg().getTransactionData().getTransactionId().equals(msg.getTransactionData().getTransactionId())) { | |
131 | - currentTransactionTask.setCompleted(true); | |
132 | - queue.poll(); | |
133 | - log.trace("Removed msg from queue, size [{}]", queue.size()); | |
134 | - | |
135 | - executeOnSuccess(currentTransactionTask.getOnEnd(), currentTransactionTask.getMsg()); | |
136 | - executeOnSuccess(onSuccess, msg); | |
137 | - | |
138 | - TbTransactionTask nextTransactionTask = queue.peek(); | |
139 | - if (nextTransactionTask != null) { | |
140 | - executeOnSuccess(nextTransactionTask.getOnStart(), nextTransactionTask.getMsg()); | |
141 | - } | |
142 | - } else { | |
143 | - log.trace("Task has expired!"); | |
144 | - executeOnFailure(onFailure, "Task has expired!"); | |
145 | - } | |
146 | - } else { | |
147 | - log.trace("Queue is empty, previous task has expired!"); | |
148 | - executeOnFailure(onFailure, "Queue is empty, previous task has expired!"); | |
149 | - } | |
150 | - } finally { | |
151 | - transactionLock.unlock(); | |
152 | - } | |
153 | - } | |
154 | - | |
155 | - private void executeOnTimeout() { | |
156 | - timeoutExecutor.submit(() -> { | |
157 | - while (true) { | |
158 | - TbTransactionTask transactionTask = timeoutQueue.peek(); | |
159 | - if (transactionTask != null) { | |
160 | - long sleepDuration = 0L; | |
161 | - transactionLock.lock(); | |
162 | - try { | |
163 | - if (transactionTask.isCompleted()) { | |
164 | - timeoutQueue.poll(); | |
165 | - } else { | |
166 | - long expIn = transactionTask.getExpirationTime() - System.currentTimeMillis(); | |
167 | - if (expIn < 0) { | |
168 | - log.trace("Task has expired! Deleting it...[{}][{}]", transactionTask.getMsg().getId(), transactionTask.getMsg().getType()); | |
169 | - timeoutQueue.poll(); | |
170 | - executeOnFailure(transactionTask.getOnFailure(), "Task has expired!"); | |
171 | - | |
172 | - BlockingQueue<TbTransactionTask> queue = transactionMap.get(transactionTask.getMsg().getTransactionData().getOriginatorId()); | |
173 | - if (queue != null) { | |
174 | - queue.poll(); | |
175 | - TbTransactionTask nextTransactionTask = queue.peek(); | |
176 | - if (nextTransactionTask != null) { | |
177 | - executeOnSuccess(nextTransactionTask.getOnStart(), nextTransactionTask.getMsg()); | |
178 | - } | |
179 | - } | |
180 | - } else { | |
181 | - sleepDuration = Math.min(expIn, duration); | |
182 | - } | |
183 | - } | |
184 | - } finally { | |
185 | - transactionLock.unlock(); | |
186 | - } | |
187 | - if (sleepDuration > 0L) { | |
188 | - try { | |
189 | - log.trace("Task has not expired! Continue executing...[{}][{}]", transactionTask.getMsg().getId(), transactionTask.getMsg().getType()); | |
190 | - TimeUnit.MILLISECONDS.sleep(sleepDuration); | |
191 | - } catch (InterruptedException e) { | |
192 | - throw new IllegalStateException("Thread interrupted", e); | |
193 | - } | |
194 | - } | |
195 | - } else { | |
196 | - try { | |
197 | - log.trace("Queue is empty, waiting for tasks!"); | |
198 | - TimeUnit.SECONDS.sleep(1); | |
199 | - } catch (InterruptedException e) { | |
200 | - throw new IllegalStateException("Thread interrupted", e); | |
201 | - } | |
202 | - } | |
203 | - } | |
204 | - }); | |
205 | - } | |
206 | - | |
207 | - private void executeOnFailure(Consumer<Throwable> onFailure, String exception) { | |
208 | - executeCallback(() -> { | |
209 | - onFailure.accept(new RuntimeException(exception)); | |
210 | - return null; | |
211 | - }); | |
212 | - } | |
213 | - | |
214 | - private void executeOnSuccess(Consumer<TbMsg> onSuccess, TbMsg tbMsg) { | |
215 | - executeCallback(() -> { | |
216 | - onSuccess.accept(tbMsg); | |
217 | - return null; | |
218 | - }); | |
219 | - } | |
220 | - | |
221 | - private void executeCallback(Callable<Void> task) { | |
222 | - callbackExecutor.executeAsync(task); | |
223 | - } | |
224 | - | |
225 | -} |
application/src/main/java/org/thingsboard/server/service/transaction/TbTransactionTask.java
deleted
100644 → 0
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.service.transaction; | |
17 | - | |
18 | -import lombok.AllArgsConstructor; | |
19 | -import lombok.Data; | |
20 | -import org.thingsboard.server.common.msg.TbMsg; | |
21 | - | |
22 | -import java.util.function.Consumer; | |
23 | - | |
24 | -@Data | |
25 | -@AllArgsConstructor | |
26 | -public final class TbTransactionTask { | |
27 | - | |
28 | - private final TbMsg msg; | |
29 | - private final Consumer<TbMsg> onStart; | |
30 | - private final Consumer<TbMsg> onEnd; | |
31 | - private final Consumer<Throwable> onFailure; | |
32 | - private final long expirationTime; | |
33 | - | |
34 | - private boolean isCompleted; | |
35 | - | |
36 | - public TbTransactionTask(TbMsg msg, Consumer<TbMsg> onStart, Consumer<TbMsg> onEnd, Consumer<Throwable> onFailure, long expirationTime) { | |
37 | - this.msg = msg; | |
38 | - this.onStart = onStart; | |
39 | - this.onEnd = onEnd; | |
40 | - this.onFailure = onFailure; | |
41 | - this.expirationTime = expirationTime; | |
42 | - this.isCompleted = false; | |
43 | - } | |
44 | -} |
... | ... | @@ -44,7 +44,6 @@ public final class TbMsg implements Serializable { |
44 | 44 | private final TbMsgMetaData metaData; |
45 | 45 | private final TbMsgDataType dataType; |
46 | 46 | private final String data; |
47 | - private final TbMsgTransactionData transactionData; | |
48 | 47 | private final RuleChainId ruleChainId; |
49 | 48 | private final RuleNodeId ruleNodeId; |
50 | 49 | //This field is not serialized because we use queues and there is no need to do it |
... | ... | @@ -68,27 +67,22 @@ public final class TbMsg implements Serializable { |
68 | 67 | |
69 | 68 | public static TbMsg transformMsg(TbMsg origMsg, String type, EntityId originator, TbMsgMetaData metaData, String data) { |
70 | 69 | return new TbMsg(origMsg.getId(), type, originator, metaData.copy(), origMsg.getDataType(), |
71 | - data, origMsg.getTransactionData(), origMsg.getRuleChainId(), origMsg.getRuleNodeId(), origMsg.getCallback()); | |
70 | + data, origMsg.getRuleChainId(), origMsg.getRuleNodeId(), origMsg.getCallback()); | |
72 | 71 | } |
73 | 72 | |
74 | 73 | public static TbMsg newMsg(TbMsg tbMsg, RuleChainId ruleChainId, RuleNodeId ruleNodeId) { |
75 | - return new TbMsg(UUID.randomUUID(), tbMsg.getType(), tbMsg.getOriginator(), tbMsg.getMetaData().copy(), tbMsg.getDataType(), tbMsg.getData(), ruleChainId, ruleNodeId, TbMsgCallback.EMPTY); | |
74 | + return new TbMsg(UUID.randomUUID(), tbMsg.getType(), tbMsg.getOriginator(), tbMsg.getMetaData().copy(), | |
75 | + tbMsg.getDataType(), tbMsg.getData(), ruleChainId, ruleNodeId, TbMsgCallback.EMPTY); | |
76 | 76 | } |
77 | 77 | |
78 | 78 | private TbMsg(UUID id, String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data, |
79 | 79 | RuleChainId ruleChainId, RuleNodeId ruleNodeId, TbMsgCallback callback) { |
80 | - this(id, type, originator, metaData, dataType, data, new TbMsgTransactionData(id, originator), ruleChainId, ruleNodeId, callback); | |
81 | - } | |
82 | - | |
83 | - private TbMsg(UUID id, String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data, | |
84 | - TbMsgTransactionData transactionData, RuleChainId ruleChainId, RuleNodeId ruleNodeId, TbMsgCallback callback) { | |
85 | 80 | this.id = id; |
86 | 81 | this.type = type; |
87 | 82 | this.originator = originator; |
88 | 83 | this.metaData = metaData; |
89 | 84 | this.dataType = dataType; |
90 | 85 | this.data = data; |
91 | - this.transactionData = transactionData; | |
92 | 86 | this.ruleChainId = ruleChainId; |
93 | 87 | this.ruleNodeId = ruleNodeId; |
94 | 88 | if (callback != null) { |
... | ... | @@ -125,15 +119,6 @@ public final class TbMsg implements Serializable { |
125 | 119 | builder.setMetaData(MsgProtos.TbMsgMetaDataProto.newBuilder().putAllData(msg.getMetaData().getData()).build()); |
126 | 120 | } |
127 | 121 | |
128 | - TbMsgTransactionData transactionData = msg.getTransactionData(); | |
129 | - if (transactionData != null) { | |
130 | - MsgProtos.TbMsgTransactionDataProto.Builder transactionBuilder = MsgProtos.TbMsgTransactionDataProto.newBuilder(); | |
131 | - transactionBuilder.setId(transactionData.getTransactionId().toString()); | |
132 | - transactionBuilder.setEntityType(transactionData.getOriginatorId().getEntityType().name()); | |
133 | - transactionBuilder.setEntityIdMSB(transactionData.getOriginatorId().getId().getMostSignificantBits()); | |
134 | - transactionBuilder.setEntityIdLSB(transactionData.getOriginatorId().getId().getLeastSignificantBits()); | |
135 | - builder.setTransactionData(transactionBuilder.build()); | |
136 | - } | |
137 | 122 | |
138 | 123 | builder.setDataType(msg.getDataType().ordinal()); |
139 | 124 | builder.setData(msg.getData()); |
... | ... | @@ -144,9 +129,6 @@ public final class TbMsg implements Serializable { |
144 | 129 | try { |
145 | 130 | MsgProtos.TbMsgProto proto = MsgProtos.TbMsgProto.parseFrom(data); |
146 | 131 | TbMsgMetaData metaData = new TbMsgMetaData(proto.getMetaData().getDataMap()); |
147 | - EntityId transactionEntityId = EntityIdFactory.getByTypeAndUuid(proto.getTransactionData().getEntityType(), | |
148 | - new UUID(proto.getTransactionData().getEntityIdMSB(), proto.getTransactionData().getEntityIdLSB())); | |
149 | - TbMsgTransactionData transactionData = new TbMsgTransactionData(UUID.fromString(proto.getTransactionData().getId()), transactionEntityId); | |
150 | 132 | EntityId entityId = EntityIdFactory.getByTypeAndUuid(proto.getEntityType(), new UUID(proto.getEntityIdMSB(), proto.getEntityIdLSB())); |
151 | 133 | RuleChainId ruleChainId = null; |
152 | 134 | RuleNodeId ruleNodeId = null; |
... | ... | @@ -157,17 +139,17 @@ public final class TbMsg implements Serializable { |
157 | 139 | ruleNodeId = new RuleNodeId(new UUID(proto.getRuleNodeIdMSB(), proto.getRuleNodeIdLSB())); |
158 | 140 | } |
159 | 141 | TbMsgDataType dataType = TbMsgDataType.values()[proto.getDataType()]; |
160 | - return new TbMsg(UUID.fromString(proto.getId()), proto.getType(), entityId, metaData, dataType, proto.getData(), transactionData, ruleChainId, ruleNodeId, callback); | |
142 | + return new TbMsg(UUID.fromString(proto.getId()), proto.getType(), entityId, metaData, dataType, proto.getData(), ruleChainId, ruleNodeId, callback); | |
161 | 143 | } catch (InvalidProtocolBufferException e) { |
162 | 144 | throw new IllegalStateException("Could not parse protobuf for TbMsg", e); |
163 | 145 | } |
164 | 146 | } |
165 | 147 | |
166 | 148 | public TbMsg copyWithRuleChainId(RuleChainId ruleChainId) { |
167 | - return new TbMsg(this.id, this.type, this.originator, this.metaData, this.dataType, this.data, this.transactionData, ruleChainId, null, callback); | |
149 | + return new TbMsg(this.id, this.type, this.originator, this.metaData, this.dataType, this.data, ruleChainId, null, callback); | |
168 | 150 | } |
169 | 151 | |
170 | 152 | public TbMsg copyWithRuleNodeId(RuleChainId ruleChainId, RuleNodeId ruleNodeId) { |
171 | - return new TbMsg(this.id, this.type, this.originator, this.metaData, this.dataType, this.data, this.transactionData, ruleChainId, ruleNodeId, callback); | |
153 | + return new TbMsg(this.id, this.type, this.originator, this.metaData, this.dataType, this.data, ruleChainId, ruleNodeId, callback); | |
172 | 154 | } |
173 | 155 | } | ... | ... |
common/message/src/main/java/org/thingsboard/server/common/msg/TbMsgTransactionData.java
deleted
100644 → 0
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; | |
17 | - | |
18 | -import lombok.Data; | |
19 | -import org.thingsboard.server.common.data.id.EntityId; | |
20 | - | |
21 | -import java.io.Serializable; | |
22 | -import java.util.UUID; | |
23 | - | |
24 | -@Data | |
25 | -public final class TbMsgTransactionData implements Serializable { | |
26 | - | |
27 | - private final UUID transactionId; | |
28 | - private final EntityId originatorId; | |
29 | - | |
30 | -} |
... | ... | @@ -23,13 +23,6 @@ message TbMsgMetaDataProto { |
23 | 23 | map<string, string> data = 1; |
24 | 24 | } |
25 | 25 | |
26 | -message TbMsgTransactionDataProto { | |
27 | - string id = 1; | |
28 | - string entityType = 2; | |
29 | - int64 entityIdMSB = 3; | |
30 | - int64 entityIdLSB = 4; | |
31 | -} | |
32 | - | |
33 | 26 | message TbMsgProto { |
34 | 27 | string id = 1; |
35 | 28 | string type = 2; |
... | ... | @@ -46,7 +39,7 @@ message TbMsgProto { |
46 | 39 | |
47 | 40 | TbMsgMetaDataProto metaData = 11; |
48 | 41 | |
49 | - TbMsgTransactionDataProto transactionData = 12; | |
42 | + //Transaction Data (12) was removed in 2.5 | |
50 | 43 | |
51 | 44 | int32 dataType = 13; |
52 | 45 | string data = 14; | ... | ... |
rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/RuleChainTransactionService.java
deleted
100644 → 0
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.rule.engine.api; | |
17 | - | |
18 | -import org.thingsboard.server.common.msg.TbMsg; | |
19 | - | |
20 | -import java.util.function.Consumer; | |
21 | - | |
22 | -public interface RuleChainTransactionService { | |
23 | - | |
24 | - void beginTransaction(TbMsg msg, Consumer<TbMsg> onStart, Consumer<TbMsg> onEnd, Consumer<Throwable> onFailure); | |
25 | - | |
26 | - void endTransaction(TbMsg msg, Consumer<TbMsg> onSuccess, Consumer<Throwable> onFailure); | |
27 | - | |
28 | -} |
... | ... | @@ -25,10 +25,6 @@ import org.thingsboard.rule.engine.api.TbNodeException; |
25 | 25 | import org.thingsboard.rule.engine.api.util.TbNodeUtils; |
26 | 26 | import org.thingsboard.server.common.data.plugin.ComponentType; |
27 | 27 | import org.thingsboard.server.common.msg.TbMsg; |
28 | -import org.thingsboard.server.common.msg.TbMsgDataType; | |
29 | -import org.thingsboard.server.common.msg.TbMsgTransactionData; | |
30 | - | |
31 | -import java.util.concurrent.ExecutionException; | |
32 | 28 | |
33 | 29 | import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; |
34 | 30 | |
... | ... | @@ -43,31 +39,17 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; |
43 | 39 | "Size of the queue per originator and timeout values are configurable on a system level", |
44 | 40 | uiResources = {"static/rulenode/rulenode-core-config.js"}, |
45 | 41 | configDirective = "tbNodeEmptyConfig") |
42 | +@Deprecated | |
46 | 43 | public class TbSynchronizationBeginNode implements TbNode { |
47 | 44 | |
48 | - private EmptyNodeConfiguration config; | |
49 | - | |
50 | 45 | @Override |
51 | 46 | public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { |
52 | - this.config = TbNodeUtils.convert(configuration, EmptyNodeConfiguration.class); | |
53 | 47 | } |
54 | 48 | |
55 | 49 | @Override |
56 | 50 | public void onMsg(TbContext ctx, TbMsg msg) { |
57 | - log.trace("Msg enters transaction - [{}][{}]", msg.getId(), msg.getType()); | |
58 | - | |
59 | - TbMsgTransactionData transactionData = new TbMsgTransactionData(msg.getId(), msg.getOriginator()); | |
60 | - //TODO 2.5: Callback? | |
61 | - TbMsg tbMsg = TbMsg.transformMsg(msg, msg.getType(), msg.getOriginator(), msg.getMetaData(), msg.getData()); | |
62 | - | |
63 | - ctx.getRuleChainTransactionService().beginTransaction(tbMsg, startMsg -> { | |
64 | - log.trace("Transaction starting...[{}][{}]", startMsg.getId(), startMsg.getType()); | |
65 | - ctx.tellNext(startMsg, SUCCESS); | |
66 | - }, endMsg -> log.trace("Transaction ended successfully...[{}][{}]", endMsg.getId(), endMsg.getType()), | |
67 | - throwable -> { | |
68 | - log.trace("Transaction failed! [{}][{}]", tbMsg.getId(), tbMsg.getType(), throwable); | |
69 | - ctx.tellFailure(tbMsg, throwable); | |
70 | - }); | |
51 | + log.warn("Synchronization Start/End nodes are deprecated since TB 2.5. Use queue with submit strategy SEQUENTIAL_WITHIN_ORIGINATOR instead."); | |
52 | + ctx.tellSuccess(msg); | |
71 | 53 | } |
72 | 54 | |
73 | 55 | @Override | ... | ... |
... | ... | @@ -40,25 +40,20 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; |
40 | 40 | uiResources = {"static/rulenode/rulenode-core-config.js"}, |
41 | 41 | configDirective = ("tbNodeEmptyConfig") |
42 | 42 | ) |
43 | +@Deprecated | |
43 | 44 | public class TbSynchronizationEndNode implements TbNode { |
44 | 45 | |
45 | - private EmptyNodeConfiguration config; | |
46 | - | |
47 | 46 | @Override |
48 | 47 | public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { |
49 | - this.config = TbNodeUtils.convert(configuration, EmptyNodeConfiguration.class); | |
50 | 48 | } |
51 | 49 | |
52 | 50 | @Override |
53 | 51 | public void onMsg(TbContext ctx, TbMsg msg) { |
54 | - ctx.getRuleChainTransactionService().endTransaction(msg, | |
55 | - successMsg -> ctx.tellNext(successMsg, SUCCESS), | |
56 | - throwable -> ctx.tellFailure(msg, throwable)); | |
57 | - log.trace("Msg left transaction - [{}][{}]", msg.getId(), msg.getType()); | |
52 | + log.warn("Synchronization Start/End nodes are deprecated since TB 2.5. Use queue with submit strategy SEQUENTIAL_WITHIN_ORIGINATOR instead."); | |
53 | + ctx.tellSuccess(msg); | |
58 | 54 | } |
59 | 55 | |
60 | 56 | @Override |
61 | 57 | public void destroy() { |
62 | - | |
63 | 58 | } |
64 | 59 | } | ... | ... |