pvillard31 commented on code in PR #11571: URL: https://github.com/apache/nifi/pull/11571#discussion_r4057049475
########## 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: This was intentional to translate the locally mapped parent identifier to the corresponding target Process Group identifier before `apply()`, but I agree that `classify()` should not mutate the supplied Controller Service. I will move that translation to the apply phase. -- 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]
