Skip to content

Commit f778214

Browse files
committed
NIFI-16310 Assign migration-created service IDs after migration
Assign versioned IDs to Controller Services created by property migration once all migrations have run, so that the result does not depend on migration order and reflects each service's own migration. A reference to another Controller Service contributes that service's versioned ID. Services with inline sensitive values, unresolvable or external references, or duplicate IDs stay unversioned as before. Missing services are recorded per group and removed after migration unless still referenced.
1 parent b7ac623 commit f778214

13 files changed

Lines changed: 1014 additions & 732 deletions

File tree

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

Lines changed: 212 additions & 146 deletions
Large diffs are not rendered by default.

‎nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/migration/StandardControllerServiceFactory.java‎

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.apache.nifi.migration;
1919

20-
import jakarta.annotation.Nullable;
2120
import org.apache.nifi.bundle.Bundle;
2221
import org.apache.nifi.bundle.BundleCoordinate;
2322
import org.apache.nifi.components.validation.ValidationStatus;
@@ -34,12 +33,13 @@
3433
import org.slf4j.LoggerFactory;
3534

3635
import java.nio.charset.StandardCharsets;
36+
import java.util.ArrayList;
37+
import java.util.Collection;
3738
import java.util.Collections;
3839
import java.util.HashMap;
3940
import java.util.List;
4041
import java.util.Map;
4142
import java.util.Optional;
42-
import java.util.Set;
4343
import java.util.SortedMap;
4444
import java.util.TreeMap;
4545
import java.util.UUID;
@@ -59,20 +59,24 @@ public class StandardControllerServiceFactory implements ControllerServiceFactor
5959
private final FlowManager flowManager;
6060
private final ControllerServiceProvider serviceProvider;
6161
private final ComponentNode creator;
62-
private final @Nullable String owningGroupIdentity;
62+
private final Collection<ControllerServiceNode> createdServices;
6363

6464
public StandardControllerServiceFactory(final ExtensionManager extensionManager, final FlowManager flowManager, final ControllerServiceProvider serviceProvider,
6565
final ComponentNode creator) {
66-
this(extensionManager, flowManager, serviceProvider, creator, null);
66+
this(extensionManager, flowManager, serviceProvider, creator, new ArrayList<>());
6767
}
6868

69+
/**
70+
* @param createdServices receives every Controller Service this factory creates, including those created by the migration of
71+
* another created service.
72+
*/
6973
public StandardControllerServiceFactory(final ExtensionManager extensionManager, final FlowManager flowManager, final ControllerServiceProvider serviceProvider,
70-
final ComponentNode creator, final @Nullable String owningGroupIdentity) {
74+
final ComponentNode creator, final Collection<ControllerServiceNode> createdServices) {
7175
this.extensionManager = extensionManager;
7276
this.flowManager = flowManager;
7377
this.serviceProvider = serviceProvider;
7478
this.creator = creator;
75-
this.owningGroupIdentity = owningGroupIdentity;
79+
this.createdServices = createdServices;
7680
}
7781

7882
@Override
@@ -101,6 +105,7 @@ public ControllerServiceCreationDetails getCreationDetails(final String implemen
101105
public ControllerServiceNode create(final ControllerServiceCreationDetails creationDetails) {
102106
final ControllerServiceNode serviceNode = flowManager.createControllerService(creationDetails.type(), creationDetails.serviceIdentifier(), creationDetails.serviceBundleCoordinate(),
103107
Collections.emptySet(), true, true, null);
108+
createdServices.add(serviceNode);
104109

105110
final Optional<ProcessGroup> group = creator.getParentProcessGroup();
106111
if (group.isPresent()) {
@@ -113,20 +118,7 @@ public ControllerServiceNode create(final ControllerServiceCreationDetails creat
113118

114119
serviceNode.setProperties(creationDetails.serviceProperties());
115120

116-
final String versionedId = generateVersionedId(creationDetails, serviceNode);
117-
if (versionedId != null) {
118-
final Set<ControllerServiceNode> groupControllerServices = group.map(processGroup -> processGroup.getControllerServices(false)).orElse(Collections.emptySet());
119-
final boolean occupied = groupControllerServices.stream()
120-
.map(ControllerServiceNode::getVersionedComponentId)
121-
.flatMap(Optional::stream)
122-
.anyMatch(versionedId::equals);
123-
124-
if (!occupied) {
125-
serviceNode.setVersionedComponentId(versionedId);
126-
}
127-
}
128-
129-
final ControllerServiceFactory serviceFactory = new StandardControllerServiceFactory(extensionManager, flowManager, serviceProvider, serviceNode, owningGroupIdentity);
121+
final ControllerServiceFactory serviceFactory = new StandardControllerServiceFactory(extensionManager, flowManager, serviceProvider, serviceNode, createdServices);
130122
serviceNode.migrateConfiguration(creationDetails.serviceProperties(), serviceFactory);
131123

132124
// Mark the service as migration-created so that flow-difference filtering can distinguish it from a
@@ -145,22 +137,6 @@ public ControllerServiceNode create(final ControllerServiceCreationDetails creat
145137
return serviceNode;
146138
}
147139

148-
private @Nullable String generateVersionedId(final ControllerServiceCreationDetails creationDetails, final ControllerServiceNode serviceNode) {
149-
if (owningGroupIdentity == null) {
150-
return null;
151-
}
152-
153-
final Map<String, String> sortedProperties = new TreeMap<>();
154-
for (final Map.Entry<String, String> property : creationDetails.serviceProperties().entrySet()) {
155-
if (!serviceNode.getPropertyDescriptor(property.getKey()).isSensitive()) {
156-
sortedProperties.put(property.getKey(), property.getValue());
157-
}
158-
}
159-
160-
final String componentDescription = owningGroupIdentity + creationDetails.type() + sortedProperties;
161-
return UUID.nameUUIDFromBytes(componentDescription.getBytes(StandardCharsets.UTF_8)).toString();
162-
}
163-
164140
private boolean isEnable() {
165141
// Do not enable any Controller Services if it's added to a stateless group. Let the stateless group handle
166142
// the lifecycle of Controller Services on its own.

0 commit comments

Comments
 (0)