Skip to content

Commit e067a76

Browse files
committed
NIFI-14944 - Fix flow upgrade when CS reference goes from external to scoped controller service
1 parent 9ccef4c commit e067a76

File tree

4 files changed

+1373
-24
lines changed

4 files changed

+1373
-24
lines changed

nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,35 +1616,38 @@ private Map<String, String> populatePropertiesMap(final ComponentNode componentN
16161616

16171617
final String value;
16181618
if (descriptor != null && referencesService && (proposedProperties.get(propertyName) != null)) {
1619-
// Need to determine if the component's property descriptor for this service is already set to an id
1620-
// of an existing service that is outside the current processor group, and if it is we want to leave
1621-
// the property set to that value
1622-
String existingExternalServiceId = null;
1623-
final String componentDescriptorValue = componentNode.getEffectivePropertyValue(descriptor);
1624-
if (componentDescriptorValue != null) {
1625-
final ProcessGroup parentGroup = topLevelGroup.getParent();
1626-
if (parentGroup != null) {
1627-
final ControllerServiceNode serviceNode = parentGroup.findControllerService(componentDescriptorValue, false, true);
1628-
if (serviceNode != null) {
1629-
existingExternalServiceId = componentDescriptorValue;
1630-
}
1631-
}
1632-
}
1633-
1634-
// If the component's property descriptor is not already set to an id of an existing external service,
1635-
// then we need to take the Versioned Component ID and resolve this to the instance ID of the service
1636-
if (existingExternalServiceId == null) {
1637-
final String serviceVersionedComponentId = proposedProperties.get(propertyName);
1638-
String instanceId = getServiceInstanceId(serviceVersionedComponentId, group);
1639-
value = (instanceId == null) ? serviceVersionedComponentId : instanceId;
1619+
// Prefer mapping the proposed Versioned Component ID to an in-scope service instance ID
1620+
final String serviceVersionedComponentId = proposedProperties.get(propertyName);
1621+
final String inScopeInstanceId = getServiceInstanceId(serviceVersionedComponentId, group);
16401622

1641-
// Find the same property descriptor in the component's CreatedExtension and replace it with the
1642-
// instance ID of the service
1623+
if (inScopeInstanceId != null) {
1624+
value = inScopeInstanceId;
1625+
// Update captured created/modified extension properties with resolved instance id
16431626
createdAndModifiedExtensions.stream().filter(ce -> ce.extension.equals(componentNode)).forEach(createdOrModifiedExtension -> {
16441627
createdOrModifiedExtension.propertyValues.replace(propertyName, value);
16451628
});
16461629
} else {
1647-
value = existingExternalServiceId;
1630+
// No in-scope mapping: if the current value references an external service in a parent group, retain it
1631+
String existingExternalServiceId = null;
1632+
final String componentDescriptorValue = componentNode.getEffectivePropertyValue(descriptor);
1633+
if (componentDescriptorValue != null) {
1634+
final ProcessGroup parentGroup = topLevelGroup.getParent();
1635+
if (parentGroup != null) {
1636+
final ControllerServiceNode serviceNode = parentGroup.findControllerService(componentDescriptorValue, false, true);
1637+
if (serviceNode != null) {
1638+
existingExternalServiceId = componentDescriptorValue;
1639+
}
1640+
}
1641+
}
1642+
1643+
value = (existingExternalServiceId != null) ? existingExternalServiceId : serviceVersionedComponentId;
1644+
if (existingExternalServiceId == null) {
1645+
// When falling back to proposed versioned id, reflect that in created/modified extension
1646+
final String finalValue = value;
1647+
createdAndModifiedExtensions.stream().filter(ce -> ce.extension.equals(componentNode)).forEach(createdOrModifiedExtension -> {
1648+
createdOrModifiedExtension.propertyValues.replace(propertyName, finalValue);
1649+
});
1650+
}
16481651
}
16491652
} else {
16501653
value = proposedProperties.get(propertyName);

0 commit comments

Comments
 (0)