Merge pull request #9204 from ShvaykaD/bugfix/get-attributes-nodes-upgrade
Fix for get attributes nodes upgrade when fetchToData is null
This commit is contained in:
commit
96893f5c36
@ -227,25 +227,25 @@ public class DefaultDataUpdateService implements DataUpdateService {
|
||||
@Override
|
||||
public void upgradeRuleNodes() {
|
||||
try {
|
||||
log.info("Lookup rule nodes to upgrade ...");
|
||||
log.info("Starting rule nodes upgrade ...");
|
||||
var nodeClassToVersionMap = componentDiscoveryService.getVersionedNodes();
|
||||
log.info("Found {} versioned nodes to check for upgrade!", nodeClassToVersionMap.size());
|
||||
log.debug("Found {} versioned nodes to check for upgrade!", nodeClassToVersionMap.size());
|
||||
nodeClassToVersionMap.forEach(clazz -> {
|
||||
var ruleNodeType = clazz.getClassName();
|
||||
var ruleNodeTypeForLogs = clazz.getSimpleName();
|
||||
var toVersion = clazz.getCurrentVersion();
|
||||
log.info("Going to check for nodes with type: {} to upgrade to version: {}.", ruleNodeTypeForLogs, toVersion);
|
||||
log.debug("Going to check for nodes with type: {} to upgrade to version: {}.", ruleNodeTypeForLogs, toVersion);
|
||||
var ruleNodesToUpdate = new PageDataIterable<>(
|
||||
pageLink -> ruleChainService.findAllRuleNodesByTypeAndVersionLessThan(ruleNodeType, toVersion, pageLink), 1024
|
||||
);
|
||||
if (Iterables.isEmpty(ruleNodesToUpdate)) {
|
||||
log.info("There are no active nodes with type: {}, or all nodes with this type already set to latest version!", ruleNodeTypeForLogs);
|
||||
log.debug("There are no active nodes with type: {}, or all nodes with this type already set to latest version!", ruleNodeTypeForLogs);
|
||||
} else {
|
||||
for (var ruleNode : ruleNodesToUpdate) {
|
||||
var ruleNodeId = ruleNode.getId();
|
||||
var oldConfiguration = ruleNode.getConfiguration();
|
||||
int fromVersion = ruleNode.getConfigurationVersion();
|
||||
log.info("Going to upgrade rule node with id: {} type: {} fromVersion: {} toVersion: {}",
|
||||
log.debug("Going to upgrade rule node with id: {} type: {} fromVersion: {} toVersion: {}",
|
||||
ruleNodeId, ruleNodeTypeForLogs, fromVersion, toVersion);
|
||||
try {
|
||||
var tbVersionedNode = (TbVersionedNode) clazz.getClazz().getDeclaredConstructor().newInstance();
|
||||
@ -255,7 +255,7 @@ public class DefaultDataUpdateService implements DataUpdateService {
|
||||
}
|
||||
ruleNode.setConfigurationVersion(toVersion);
|
||||
ruleChainService.saveRuleNode(TenantId.SYS_TENANT_ID, ruleNode);
|
||||
log.info("Successfully upgrade rule node with id: {} type: {} fromVersion: {} toVersion: {}",
|
||||
log.debug("Successfully upgrade rule node with id: {} type: {} fromVersion: {} toVersion: {}",
|
||||
ruleNodeId, ruleNodeTypeForLogs, fromVersion, toVersion);
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to upgrade rule node with id: {} type: {} fromVersion: {} toVersion: {} due to: ",
|
||||
|
||||
@ -88,6 +88,11 @@ public abstract class TbAbstractGetAttributesNode<C extends TbGetAttributesNodeC
|
||||
newConfigObjectNode.put(FETCH_TO_PROPERTY_NAME, TbMsgSource.METADATA.name());
|
||||
return new TbPair<>(true, newConfigObjectNode);
|
||||
}
|
||||
if (newConfigObjectNode.get(oldProperty).isNull()) {
|
||||
newConfigObjectNode.remove(oldProperty);
|
||||
newConfigObjectNode.put(FETCH_TO_PROPERTY_NAME, TbMsgSource.METADATA.name());
|
||||
return new TbPair<>(true, newConfigObjectNode);
|
||||
}
|
||||
return upgradeConfigurationToUseFetchTo(oldProperty, ifTrue, ifFalse, newConfigObjectNode);
|
||||
}
|
||||
|
||||
|
||||
@ -285,6 +285,23 @@ public class TbGetAttributesNodeTest {
|
||||
Assertions.assertEquals(defaultConfig, JacksonUtil.treeToValue(upgrade.getSecond(), defaultConfig.getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenOldConfigWithNullFetchToDataProperty_whenUpgrade_thenShouldReturnTrueResultWithNewConfig() throws Exception {
|
||||
var defaultConfig = new TbGetAttributesNodeConfiguration().defaultConfiguration();
|
||||
var node = new TbGetAttributesNode();
|
||||
String oldConfig = "{\"fetchToData\":null," +
|
||||
"\"clientAttributeNames\":[]," +
|
||||
"\"sharedAttributeNames\":[]," +
|
||||
"\"serverAttributeNames\":[]," +
|
||||
"\"latestTsKeyNames\":[]," +
|
||||
"\"tellFailureIfAbsent\":true," +
|
||||
"\"getLatestValueWithTs\":false}";
|
||||
JsonNode configJson = JacksonUtil.toJsonNode(oldConfig);
|
||||
TbPair<Boolean, JsonNode> upgrade = node.upgrade(0, configJson);
|
||||
Assertions.assertTrue(upgrade.getFirst());
|
||||
Assertions.assertEquals(defaultConfig, JacksonUtil.treeToValue(upgrade.getSecond(), defaultConfig.getClass()));
|
||||
}
|
||||
|
||||
private TbMsg checkMsg(boolean checkSuccess) {
|
||||
var msgCaptor = ArgumentCaptor.forClass(TbMsg.class);
|
||||
if (checkSuccess) {
|
||||
|
||||
@ -60,4 +60,23 @@ public class TbGetDeviceAttrNodeTest {
|
||||
Assertions.assertEquals(defaultConfig, JacksonUtil.treeToValue(upgrade.getSecond(), defaultConfig.getClass()));
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
public void givenOldConfigWithNullFetchToDataProperty_whenUpgrade_thenShouldReturnTrueResultWithNewConfig() throws Exception {
|
||||
var defaultConfig = new TbGetDeviceAttrNodeConfiguration().defaultConfiguration();
|
||||
var node = new TbGetDeviceAttrNode();
|
||||
String oldConfig = "{\"fetchToData\":null," +
|
||||
"\"clientAttributeNames\":[]," +
|
||||
"\"sharedAttributeNames\":[]," +
|
||||
"\"serverAttributeNames\":[]," +
|
||||
"\"latestTsKeyNames\":[]," +
|
||||
"\"tellFailureIfAbsent\":true," +
|
||||
"\"getLatestValueWithTs\":false," +
|
||||
"\"deviceRelationsQuery\":{\"direction\":\"FROM\",\"maxLevel\":1,\"relationType\":\"Contains\",\"deviceTypes\":[\"default\"]," +
|
||||
"\"fetchLastLevelOnly\":false}}";
|
||||
JsonNode configJson = JacksonUtil.toJsonNode(oldConfig);
|
||||
TbPair<Boolean, JsonNode> upgrade = node.upgrade(0, configJson);
|
||||
Assertions.assertTrue(upgrade.getFirst());
|
||||
Assertions.assertEquals(defaultConfig, JacksonUtil.treeToValue(upgrade.getSecond(), defaultConfig.getClass()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user