exceptionfactory commented on code in PR #11571:
URL: https://github.com/apache/nifi/pull/11571#discussion_r4041125869


##########
nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/registry/RebaseVersionIT.java:
##########
@@ -396,6 +413,98 @@ public void 
testRebasePreservesLocalModificationsAgainstTargetVersion() throws N
                 "Expected the preserved local change to be reported as a local 
modification after rebase, but none were found");
     }
 
+    @Test
+    public void 
testRebasePreservesLocallyAddedControllerServiceReferencedByProcessor() throws 
NiFiClientException, IOException, InterruptedException {
+        final FlowRegistryClientEntity clientEntity = registerClient();
+        final NiFiClientUtil util = getClientUtil();
+
+        final ProcessGroupEntity originalGroup = 
util.createProcessGroup(ORIGINAL_GROUP_NAME, ROOT_GROUP_ID);
+        final ControllerServiceEntity serviceX = 
util.createControllerService(CONTROLLER_SERVICE_TYPE, originalGroup.getId());
+        final ProcessorEntity fakeProcessor = 
util.createProcessor(PROCESSOR_TYPE, originalGroup.getId());
+        util.updateProcessorProperties(fakeProcessor, 
Map.of(CONTROLLER_SERVICE_PROPERTY, serviceX.getId()));
+        util.createProcessor(GENERATE_FLOW_FILE_TYPE, originalGroup.getId());
+
+        final VersionControlInformationEntity vci = 
util.startVersionControl(originalGroup, clientEntity, TEST_FLOWS_BUCKET,
+                "RebaseLocalAddedControllerServiceProcessorReference");
+        final String flowId = vci.getVersionControlInformation().getFlowId();
+
+        final ProcessGroupEntity secondGroup = 
util.importFlowFromRegistry(ROOT_GROUP_ID, clientEntity.getId(), 
TEST_FLOWS_BUCKET, flowId, "1");
+        final ProcessorEntity upstreamGenerate = 
findProcessorByType(secondGroup.getId(), GENERATE_FLOW_FILE_TYPE);
+        util.updateProcessorProperties(upstreamGenerate, Map.of(TEXT_PROPERTY, 
UPSTREAM_CHANGE));
+        util.saveFlowVersion(secondGroup, clientEntity, 
getVersionControlInformation(secondGroup.getId()));
+
+        final ControllerServiceEntity serviceY = 
util.createControllerService(CONTROLLER_SERVICE_TYPE, originalGroup.getId());
+        util.updateProcessorProperties(fakeProcessor, 
Map.of(CONTROLLER_SERVICE_PROPERTY, serviceY.getId()));
+
+        final RebaseAnalysisEntity analysis = 
util.getRebaseAnalysis(originalGroup.getId(), "2");

Review Comment:
   This `2` value is repeated in a handful of places in this test, so it would 
be helpful to promote as a static variable



##########
nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/main/java/org/apache/nifi/registry/flow/diff/ComponentAddedRebaseHandler.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.registry.flow.diff;
+
+import org.apache.nifi.flow.VersionedComponent;
+import org.apache.nifi.flow.VersionedControllerService;
+import org.apache.nifi.flow.VersionedProcessGroup;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class ComponentAddedRebaseHandler implements RebaseHandler {
+
+    private static final String NULL_COMPONENT_TYPE = "null";
+
+    @Override
+    public DifferenceType getSupportedType() {
+        return DifferenceType.COMPONENT_ADDED;
+    }
+
+    @Override
+    public RebaseAnalysis.ClassifiedDifference classify(final FlowDifference 
localDifference, final Set<FlowDifference> upstreamDifferences,
+                                                        final 
VersionedProcessGroup targetSnapshot) {
+        final VersionedComponent addedComponent = 
localDifference.getComponentB();
+        if (!(addedComponent instanceof VersionedControllerService 
controllerService)) {
+            final String componentType = addedComponent == null ? 
NULL_COMPONENT_TYPE : addedComponent.getClass().getSimpleName();
+            return 
RebaseAnalysis.ClassifiedDifference.unsupported(localDifference, 
RebaseConflictCode.UNSUPPORTED_COMPONENT_TYPE,
+                    "Local component addition type %s is not supported for 
rebase".formatted(componentType));
+        }
+
+        final String parentGroupIdentifier = 
controllerService.getGroupIdentifier();
+        if (parentGroupIdentifier == null) {
+            return 
RebaseAnalysis.ClassifiedDifference.unsupported(localDifference, 
RebaseConflictCode.COMPONENT_NOT_FOUND,
+                    "Controller Service %s does not specify a parent Process 
Group".formatted(controllerService.getIdentifier()));
+        }
+
+        final VersionedProcessGroup parentGroup = 
resolveParentGroup(targetSnapshot, parentGroupIdentifier, upstreamDifferences);
+        if (parentGroup == null) {
+            return 
RebaseAnalysis.ClassifiedDifference.unsupported(localDifference, 
RebaseConflictCode.COMPONENT_NOT_FOUND,
+                    "Parent Process Group %s for Controller Service %s not 
found in target snapshot"
+                            .formatted(parentGroupIdentifier, 
controllerService.getIdentifier()));
+        }
+
+        final VersionedComponent collidingComponent = 
RebaseHandlerUtils.findComponentById(targetSnapshot, 
controllerService.getIdentifier());
+        if (collidingComponent != null) {
+            return 
RebaseAnalysis.ClassifiedDifference.conflicting(localDifference, 
RebaseConflictCode.COMPONENT_IDENTIFIER_COLLISION,
+                    "Target snapshot already contains component %s with 
identifier %s"
+                            
.formatted(collidingComponent.getClass().getSimpleName(), 
controllerService.getIdentifier()));
+        }
+
+        controllerService.setGroupIdentifier(parentGroup.getIdentifier());

Review Comment:
   Is this intentional? It appears to change the value of the provided 
Controller Service, rather than just classifying the changes



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to