TbVersionedNode removed in favour of RuleNode.version() annotation
This commit is contained in:
parent
09fcc18b5e
commit
6e3f1995bf
@ -30,13 +30,12 @@ import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.rule.engine.api.NodeConfiguration;
|
||||
import org.thingsboard.rule.engine.api.NodeDefinition;
|
||||
import org.thingsboard.rule.engine.api.RuleNode;
|
||||
import org.thingsboard.server.common.data.msg.TbMsgType;
|
||||
import org.thingsboard.server.common.data.msg.TbNodeConnectionType;
|
||||
import org.thingsboard.rule.engine.api.TbVersionedNode;
|
||||
import org.thingsboard.rule.engine.filter.TbMsgTypeSwitchNode;
|
||||
import org.thingsboard.rule.engine.filter.TbOriginatorTypeSwitchNode;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.msg.TbMsgType;
|
||||
import org.thingsboard.server.common.data.msg.TbNodeConnectionType;
|
||||
import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
|
||||
import org.thingsboard.server.common.data.plugin.ComponentType;
|
||||
import org.thingsboard.server.common.data.rule.RuleChainType;
|
||||
@ -89,15 +88,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe
|
||||
try {
|
||||
var clazz = Class.forName(clazzName);
|
||||
RuleNode annotation = clazz.getAnnotation(RuleNode.class);
|
||||
boolean versioned = false;
|
||||
if (annotation.version() > 0) { // No need to process nodes that has version = 0;
|
||||
if (TbVersionedNode.class.isAssignableFrom(clazz)) {
|
||||
versioned = true;
|
||||
} else {
|
||||
log.error("RuleNode [{}] has version {} but does not implement TbVersionedNode interface! Any update procedures for this rule node will be skipped!", clazzName, annotation.version());
|
||||
}
|
||||
}
|
||||
ruleNodeClasses.put(clazzName, new RuleNodeClassInfo(clazz, annotation, versioned));
|
||||
ruleNodeClasses.put(clazzName, new RuleNodeClassInfo(clazz, annotation));
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to create instance of rule node type: {} due to: ", clazzName, e);
|
||||
}
|
||||
@ -194,7 +185,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe
|
||||
scannedComponent.setType(type);
|
||||
Class<?> clazz = def.getClazz();
|
||||
RuleNode ruleNodeAnnotation = clazz.getAnnotation(RuleNode.class);
|
||||
scannedComponent.setConfigurationVersion(def.isVersioned() ? def.getCurrentVersion() : 0);
|
||||
scannedComponent.setConfigurationVersion(def.getCurrentVersion());
|
||||
scannedComponent.setName(ruleNodeAnnotation.name());
|
||||
scannedComponent.setScope(ruleNodeAnnotation.scope());
|
||||
scannedComponent.setClusteringMode(ruleNodeAnnotation.clusteringMode());
|
||||
|
||||
@ -23,7 +23,6 @@ public class RuleNodeClassInfo {
|
||||
|
||||
private final Class<?> clazz;
|
||||
private final RuleNode annotation;
|
||||
private final boolean versioned;
|
||||
|
||||
public String getClassName(){
|
||||
return clazz.getName();
|
||||
@ -37,4 +36,8 @@ public class RuleNodeClassInfo {
|
||||
return annotation.version();
|
||||
}
|
||||
|
||||
public boolean isVersioned() {
|
||||
return annotation.version() > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.rule.engine.api.TbVersionedNode;
|
||||
import org.thingsboard.rule.engine.api.TbNode;
|
||||
import org.thingsboard.rule.engine.flow.TbRuleChainInputNode;
|
||||
import org.thingsboard.rule.engine.flow.TbRuleChainInputNodeConfiguration;
|
||||
import org.thingsboard.rule.engine.profile.TbDeviceProfileNode;
|
||||
@ -88,9 +88,7 @@ import org.thingsboard.server.service.install.SystemDataLoaderService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Function;
|
||||
@ -248,7 +246,7 @@ public class DefaultDataUpdateService implements DataUpdateService {
|
||||
log.debug("Going to upgrade rule node with id: {} type: {} fromVersion: {} toVersion: {}",
|
||||
ruleNodeId, ruleNodeTypeForLogs, fromVersion, toVersion);
|
||||
try {
|
||||
var tbVersionedNode = (TbVersionedNode) clazz.getClazz().getDeclaredConstructor().newInstance();
|
||||
var tbVersionedNode = (TbNode) clazz.getClazz().getDeclaredConstructor().newInstance();
|
||||
TbPair<Boolean, JsonNode> upgradeRuleNodeConfigurationResult = tbVersionedNode.upgrade(fromVersion, oldConfiguration);
|
||||
if (upgradeRuleNodeConfigurationResult.getFirst()) {
|
||||
ruleNode.setConfiguration(upgradeRuleNodeConfigurationResult.getSecond());
|
||||
|
||||
@ -20,8 +20,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.rule.engine.api.TbNode;
|
||||
import org.thingsboard.rule.engine.api.TbNodeException;
|
||||
import org.thingsboard.rule.engine.api.TbVersionedNode;
|
||||
import org.thingsboard.rule.engine.flow.TbRuleChainInputNode;
|
||||
import org.thingsboard.rule.engine.flow.TbRuleChainInputNodeConfiguration;
|
||||
import org.thingsboard.rule.engine.flow.TbRuleChainOutputNode;
|
||||
@ -402,7 +402,7 @@ public class DefaultTbRuleChainService extends AbstractTbEntityService implement
|
||||
var ruleNodeClass = componentDiscoveryService.getRuleNodeInfo(ruleNodeType)
|
||||
.orElseThrow(() -> new RuntimeException("Rule node " + ruleNodeType + " is not supported!"));
|
||||
if (ruleNodeClass.isVersioned()) {
|
||||
TbVersionedNode tbVersionedNode = (TbVersionedNode) ruleNodeClass.getClazz().getDeclaredConstructor().newInstance();
|
||||
TbNode tbVersionedNode = (TbNode) ruleNodeClass.getClazz().getDeclaredConstructor().newInstance();
|
||||
int fromVersion = node.getConfigurationVersion();
|
||||
int toVersion = ruleNodeClass.getCurrentVersion();
|
||||
if (fromVersion < toVersion) {
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.thingsboard.server.common.data.util.TbPair;
|
||||
import org.thingsboard.server.common.msg.TbMsg;
|
||||
import org.thingsboard.server.common.msg.queue.PartitionChangeMsg;
|
||||
|
||||
@ -35,4 +37,18 @@ public interface TbNode {
|
||||
default void onPartitionChangeMsg(TbContext ctx, PartitionChangeMsg msg) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrades the configuration from a specific version to the current version specified in the
|
||||
* {@link RuleNode} annotation for the instance of {@link TbNode}.
|
||||
*
|
||||
* @param fromVersion The version from which the configuration needs to be upgraded.
|
||||
* @param oldConfiguration The old configuration to be upgraded.
|
||||
* @return A pair consisting of a Boolean flag indicating the success of the upgrade
|
||||
* and a JsonNode representing the upgraded configuration.
|
||||
* @throws TbNodeException If an error occurs during the upgrade process.
|
||||
*/
|
||||
default TbPair<Boolean, JsonNode> upgrade(int fromVersion, JsonNode oldConfiguration) throws TbNodeException {
|
||||
return new TbPair<>(false, oldConfiguration);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 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.api;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.thingsboard.server.common.data.util.TbPair;
|
||||
|
||||
public interface TbVersionedNode extends TbNode {
|
||||
|
||||
/**
|
||||
* Upgrades the configuration from a specific version to the current version specified in the
|
||||
* {@link RuleNode} annotation for the instance of {@link TbVersionedNode}.
|
||||
*
|
||||
* @param fromVersion The version from which the configuration needs to be upgraded.
|
||||
* @param oldConfiguration The old configuration to be upgraded.
|
||||
* @return A pair consisting of a Boolean flag indicating the success of the upgrade
|
||||
* and a JsonNode representing the upgraded configuration.
|
||||
* @throws TbNodeException If an error occurs during the upgrade process.
|
||||
*/
|
||||
TbPair<Boolean, JsonNode> upgrade(int fromVersion, JsonNode oldConfiguration) throws TbNodeException;
|
||||
|
||||
}
|
||||
@ -22,9 +22,9 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.api.TbVersionedNode;
|
||||
import org.thingsboard.rule.engine.api.util.TbNodeUtils;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
@ -58,7 +58,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback;
|
||||
"Output connections: <code>True</code>, <code>False</code>, <code>Failure</code>",
|
||||
uiResources = {"static/rulenode/rulenode-core-config.js"},
|
||||
configDirective = "tbFilterNodeCheckRelationConfig")
|
||||
public class TbCheckRelationNode implements TbVersionedNode {
|
||||
public class TbCheckRelationNode implements TbNode {
|
||||
|
||||
private static final String DIRECTION_PROPERTY_NAME = "direction";
|
||||
|
||||
|
||||
@ -22,9 +22,9 @@ import com.google.common.util.concurrent.Futures;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
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.api.TbVersionedNode;
|
||||
import org.thingsboard.rule.engine.util.TbMsgSource;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.kv.KvEntry;
|
||||
@ -35,7 +35,7 @@ import org.thingsboard.server.common.msg.TbMsgMetaData;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
@Slf4j
|
||||
public abstract class TbAbstractNodeWithFetchTo<C extends TbAbstractFetchToNodeConfiguration> implements TbVersionedNode {
|
||||
public abstract class TbAbstractNodeWithFetchTo<C extends TbAbstractFetchToNodeConfiguration> implements TbNode {
|
||||
|
||||
protected final static String FETCH_TO_PROPERTY_NAME = "fetchTo";
|
||||
|
||||
|
||||
@ -24,9 +24,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.thingsboard.common.util.DonAsynchron;
|
||||
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.api.TbVersionedNode;
|
||||
import org.thingsboard.rule.engine.api.util.TbNodeUtils;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
|
||||
@ -43,9 +43,7 @@ import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.thingsboard.server.common.data.DataConstants.CLIENT_SCOPE;
|
||||
import static org.thingsboard.server.common.data.DataConstants.NOTIFY_DEVICE_METADATA_KEY;
|
||||
import static org.thingsboard.server.common.data.DataConstants.SCOPE;
|
||||
import static org.thingsboard.server.common.data.DataConstants.*;
|
||||
import static org.thingsboard.server.common.data.msg.TbMsgType.POST_ATTRIBUTES_REQUEST;
|
||||
|
||||
@Slf4j
|
||||
@ -64,7 +62,7 @@ import static org.thingsboard.server.common.data.msg.TbMsgType.POST_ATTRIBUTES_R
|
||||
configDirective = "tbActionNodeAttributesConfig",
|
||||
icon = "file_upload"
|
||||
)
|
||||
public class TbMsgAttributesNode implements TbVersionedNode {
|
||||
public class TbMsgAttributesNode implements TbNode {
|
||||
|
||||
static final String UPDATE_ATTRIBUTES_ONLY_ON_VALUE_CHANGE_KEY = "updateAttributesOnlyOnValueChange";
|
||||
private TbMsgAttributesNodeConfiguration config;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user