diff --git a/application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java b/application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java index 2920fa400a..e2a6f452c5 100644 --- a/application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java +++ b/application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java @@ -577,9 +577,9 @@ public class ActorSystemContext { @Getter private boolean externalNodeForceAck; - @Value("${actors.rule.node.max_debug_mode_duration:60}") + @Value("${debug_mode.max_duration:60}") @Getter - private int maxRuleNodeDebugModeDurationMinutes; + private int maxDebugModeDurationMinutes; @Value("${state.rule.node.deviceState.rateLimit:1:1,30:60,60:3600}") @Getter diff --git a/application/src/main/java/org/thingsboard/server/actors/ruleChain/DefaultTbContext.java b/application/src/main/java/org/thingsboard/server/actors/ruleChain/DefaultTbContext.java index 000c260769..27c6dd19b7 100644 --- a/application/src/main/java/org/thingsboard/server/actors/ruleChain/DefaultTbContext.java +++ b/application/src/main/java/org/thingsboard/server/actors/ruleChain/DefaultTbContext.java @@ -64,7 +64,7 @@ import org.thingsboard.server.common.data.msg.TbNodeConnectionType; import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.rule.RuleNode; -import org.thingsboard.server.common.data.rule.RuleNodeDebugUtil; +import org.thingsboard.common.util.DebugModeUtil; import org.thingsboard.server.common.data.rule.RuleNodeState; import org.thingsboard.server.common.data.script.ScriptLanguage; import org.thingsboard.server.common.msg.TbActorMsg; @@ -1002,9 +1002,9 @@ public class DefaultTbContext implements TbContext { private void persistDebugOutput(TbMsg msg, Set relationTypes, Throwable error, String failureMessage) { RuleNode ruleNode = nodeCtx.getSelf(); - if (RuleNodeDebugUtil.isDebugAllAvailable(ruleNode)) { + if (DebugModeUtil.isDebugAllAvailable(ruleNode)) { relationTypes.forEach(relationType -> mainCtx.persistDebugOutput(getTenantId(), ruleNode.getId(), msg, relationType, error, failureMessage)); - } else if (RuleNodeDebugUtil.isDebugFailuresAvailable(ruleNode, relationTypes)) { + } else if (DebugModeUtil.isDebugFailuresAvailable(ruleNode, relationTypes)) { mainCtx.persistDebugOutput(getTenantId(), ruleNode.getId(), msg, TbNodeConnectionType.FAILURE, error, failureMessage); } } diff --git a/application/src/main/java/org/thingsboard/server/actors/ruleChain/RuleChainActorMessageProcessor.java b/application/src/main/java/org/thingsboard/server/actors/ruleChain/RuleChainActorMessageProcessor.java index 636ea3fd07..460da228c3 100644 --- a/application/src/main/java/org/thingsboard/server/actors/ruleChain/RuleChainActorMessageProcessor.java +++ b/application/src/main/java/org/thingsboard/server/actors/ruleChain/RuleChainActorMessageProcessor.java @@ -35,7 +35,7 @@ import org.thingsboard.server.common.data.relation.EntityRelation; import org.thingsboard.server.common.data.rule.RuleChain; import org.thingsboard.server.common.data.rule.RuleChainType; import org.thingsboard.server.common.data.rule.RuleNode; -import org.thingsboard.server.common.data.rule.RuleNodeDebugUtil; +import org.thingsboard.common.util.DebugModeUtil; import org.thingsboard.server.common.msg.TbMsg; import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; import org.thingsboard.server.common.msg.plugin.RuleNodeUpdatedMsg; @@ -256,7 +256,7 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor implements HasName { +public class RuleNode extends BaseDataWithAdditionalInfo implements HasName, HasDebugMode { private static final long serialVersionUID = -5656679015121235465L; diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleNodeDebugUtil.java b/common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleNodeDebugUtil.java deleted file mode 100644 index c6a3b495c8..0000000000 --- a/common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleNodeDebugUtil.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright © 2016-2024 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.common.data.rule; - -import org.thingsboard.server.common.data.msg.TbNodeConnectionType; - -import java.util.Set; - -public final class RuleNodeDebugUtil { - private RuleNodeDebugUtil() {} - - public static boolean isDebugAllAvailable(RuleNode ruleNode) { - return ruleNode.getDebugAllUntil() > System.currentTimeMillis(); - } - - public static boolean isDebugAvailable(RuleNode ruleNode, String nodeConnection) { - return isDebugAllAvailable(ruleNode) || ruleNode.isDebugFailures() && TbNodeConnectionType.FAILURE.equals(nodeConnection); - } - - public static boolean isDebugFailuresAvailable(RuleNode ruleNode, Set nodeConnections) { - return isDebugFailuresAvailable(ruleNode) && nodeConnections.contains(TbNodeConnectionType.FAILURE); - } - - public static boolean isDebugFailuresAvailable(RuleNode ruleNode, String nodeConnection) { - return isDebugFailuresAvailable(ruleNode) && TbNodeConnectionType.FAILURE.equals(nodeConnection); - } - - public static boolean isDebugFailuresAvailable(RuleNode ruleNode) { - return ruleNode.isDebugFailures() || isDebugAllAvailable(ruleNode); - } - -} diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/tenant/profile/DefaultTenantProfileConfiguration.java b/common/data/src/main/java/org/thingsboard/server/common/data/tenant/profile/DefaultTenantProfileConfiguration.java index 1b36578a77..540dafdd4a 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/tenant/profile/DefaultTenantProfileConfiguration.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/tenant/profile/DefaultTenantProfileConfiguration.java @@ -95,7 +95,7 @@ public class DefaultTenantProfileConfiguration implements TenantProfileConfigura @Schema(example = "50") private int maxRuleNodeExecutionsPerMessage; @Schema(example = "15") - private int maxRuleNodeDebugDurationMinutes; + private int maxDebugDurationMinutes; @Schema(example = "0") private long maxEmails; @Schema(example = "true") @@ -204,10 +204,10 @@ public class DefaultTenantProfileConfiguration implements TenantProfileConfigura } @Override - public int getMaxRuleNodeDebugModeDurationMinutes(int systemMaxRuleNodeDebugModeDurationMinutes) { - if (maxRuleNodeDebugDurationMinutes > 0) { - return Math.min(systemMaxRuleNodeDebugModeDurationMinutes, maxRuleNodeDebugDurationMinutes); + public int getMaxDebugModeDurationMinutes(int systemMaxDebugModeDurationMinutes) { + if (maxDebugDurationMinutes > 0) { + return Math.min(systemMaxDebugModeDurationMinutes, maxDebugDurationMinutes); } - return systemMaxRuleNodeDebugModeDurationMinutes; + return systemMaxDebugModeDurationMinutes; } } diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/tenant/profile/TenantProfileConfiguration.java b/common/data/src/main/java/org/thingsboard/server/common/data/tenant/profile/TenantProfileConfiguration.java index af36a15c4f..12d66e5178 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/tenant/profile/TenantProfileConfiguration.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/tenant/profile/TenantProfileConfiguration.java @@ -52,6 +52,6 @@ public interface TenantProfileConfiguration extends Serializable { int getMaxRuleNodeExecsPerMessage(); @JsonIgnore - int getMaxRuleNodeDebugModeDurationMinutes(int systemMaxRuleNodeDebugModeDurationMinutes); + int getMaxDebugModeDurationMinutes(int systemMaxDebugModeDurationMinutes); } diff --git a/common/util/src/main/java/org/thingsboard/common/util/DebugModeUtil.java b/common/util/src/main/java/org/thingsboard/common/util/DebugModeUtil.java new file mode 100644 index 0000000000..0f4213f989 --- /dev/null +++ b/common/util/src/main/java/org/thingsboard/common/util/DebugModeUtil.java @@ -0,0 +1,43 @@ +/** + * Copyright © 2016-2024 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.common.util; + +import org.thingsboard.server.common.data.HasDebugMode; +import org.thingsboard.server.common.data.msg.TbNodeConnectionType; + +import java.util.Set; + +public final class DebugModeUtil { + private DebugModeUtil() { + } + + public static boolean isDebugAllAvailable(HasDebugMode debugMode) { + return debugMode.getDebugAllUntil() > System.currentTimeMillis(); + } + + public static boolean isDebugAvailable(HasDebugMode debugMode, String nodeConnection) { + return isDebugAllAvailable(debugMode) || debugMode.isDebugFailures() && TbNodeConnectionType.FAILURE.equals(nodeConnection); + } + + public static boolean isDebugFailuresAvailable(HasDebugMode debugMode, Set nodeConnections) { + return isDebugFailuresAvailable(debugMode) && nodeConnections.contains(TbNodeConnectionType.FAILURE); + } + + private static boolean isDebugFailuresAvailable(HasDebugMode debugMode) { + return debugMode.isDebugFailures() || isDebugAllAvailable(debugMode); + } + +} diff --git a/dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java b/dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java index 52f28db5db..046a5532c4 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java +++ b/dao/src/main/java/org/thingsboard/server/dao/rule/BaseRuleChainService.java @@ -68,7 +68,6 @@ import org.thingsboard.server.dao.service.PaginatedRemover; import org.thingsboard.server.dao.service.Validator; import org.thingsboard.server.dao.service.validator.RuleChainDataValidator; import org.thingsboard.server.dao.tenant.TbTenantProfileCache; -import org.thingsboard.server.dao.util.TimeUtils; import java.util.ArrayList; import java.util.Collection; @@ -118,8 +117,8 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @Lazy private TbTenantProfileCache tbTenantProfileCache; - @Value("${actors.rule.node.max_debug_mode_duration:60}") - private int maxRuleNodeDebugModeDurationMinutes; + @Value("${debug_mode.max_duration:60}") + private int maxDebugModeDurationMinutes; @Override @Transactional @@ -231,7 +230,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC node.setRuleChainId(ruleChainId); node = ruleNodeUpdater.apply(node); - int debugDuration = tbTenantProfileCache.get(tenantId).getDefaultProfileConfiguration().getMaxRuleNodeDebugModeDurationMinutes(maxRuleNodeDebugModeDurationMinutes); + int debugDuration = tbTenantProfileCache.get(tenantId).getDefaultProfileConfiguration().getMaxDebugModeDurationMinutes(maxDebugModeDurationMinutes); long debugUntil = now + TimeUnit.MINUTES.toMillis(debugDuration); if (node.isDebugAll()) {