Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIFI-11213 Showing version change in older (pre 1.18.0) contained version flows properly #7017

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.nifi.processor.Relationship;
import org.apache.nifi.registry.flow.diff.DifferenceType;
import org.apache.nifi.registry.flow.diff.FlowDifference;
import org.apache.nifi.registry.flow.diff.FlowDifferenceUtil;
import org.apache.nifi.registry.flow.mapping.InstantiatedVersionedComponent;
import org.apache.nifi.registry.flow.mapping.InstantiatedVersionedControllerService;
import org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessor;
Expand Down Expand Up @@ -192,22 +193,13 @@ public static boolean isIgnorableVersionedFlowCoordinateChange(final FlowDiffere
final VersionedFlowCoordinates coordinatesB = versionedProcessGroupB.getVersionedFlowCoordinates();

if (coordinatesA != null && coordinatesB != null) {
String registryUrlA = coordinatesA.getRegistryUrl();
String registryUrlB = coordinatesB.getRegistryUrl();

if (registryUrlA != null && registryUrlB != null && !registryUrlA.equals(registryUrlB)) {
if (registryUrlA.endsWith("/")) {
registryUrlA = registryUrlA.substring(0, registryUrlA.length() - 1);
}

if (registryUrlB.endsWith("/")) {
registryUrlB = registryUrlB.substring(0, registryUrlB.length() - 1);
}

if (registryUrlA.equals(registryUrlB)) {
return true;
}
if (coordinatesA.getStorageLocation() != null || coordinatesB.getStorageLocation() != null) {
return false;
}

return !FlowDifferenceUtil.areRegistryStrictlyEqual(coordinatesA, coordinatesB)
&& FlowDifferenceUtil.areRegistryUrlsEqual(coordinatesA, coordinatesB)
Comment on lines +200 to +201
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this logic is accurate. We're saying here "If the registry URLs are different but logically the same" - and the version is the same. Shouldn't the !FlowDifferenceUtil.areRegistryStrictlyEqual(coordinatesA, coordinatesB) be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first approach and assumption was that, but with that, test TestFlowDifferenceFilter#testFilterIgnorableVersionCoordinateDifferenceWithNonIgnorableDifferencehas broken and after careful check, it turned out this distinction in the original code is deliberate. Our considerations might changed since but removing that would bring in a potential regression

&& coordinatesA.getVersion() == coordinatesB.getVersion();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public String describeDifference(final DifferenceType type, final String flowANa
final VersionedFlowCoordinates coordinatesB = (VersionedFlowCoordinates) valueB;

// If the two vary only by version, then use a more concise message. If anything else is different, then use a fully explanation.
if (Objects.equals(coordinatesA.getRegistryUrl(), coordinatesB.getRegistryUrl()) && Objects.equals(coordinatesA.getBucketId(), coordinatesB.getBucketId())
if (FlowDifferenceUtil.areRegistryUrlsEqual(coordinatesA, coordinatesB) && Objects.equals(coordinatesA.getBucketId(), coordinatesB.getBucketId())
&& Objects.equals(coordinatesA.getFlowId(), coordinatesB.getFlowId()) && coordinatesA.getVersion() != coordinatesB.getVersion()) {

description = String.format("Flow Version changed from %s to %s", coordinatesA.getVersion(), coordinatesB.getVersion());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.VersionedFlowCoordinates;

public final class FlowDifferenceUtil {

private FlowDifferenceUtil() {
// Not to be instantiated
}

public static boolean areRegistryStrictlyEqual(final VersionedFlowCoordinates coordinatesA, final VersionedFlowCoordinates coordinatesB) {
final String registryUrlA = coordinatesA.getRegistryUrl();
final String registryUrlB = coordinatesB.getRegistryUrl();
return registryUrlA != null && registryUrlB != null && registryUrlA.equals(registryUrlB);
}

public static boolean areRegistryUrlsEqual(final VersionedFlowCoordinates coordinatesA, final VersionedFlowCoordinates coordinatesB) {
final String registryUrlA = coordinatesA.getRegistryUrl();
final String registryUrlB = coordinatesB.getRegistryUrl();

if (registryUrlA != null && registryUrlB != null) {
if (registryUrlA.equals(registryUrlB)) {
return true;
}

final String normalizedRegistryUrlA = registryUrlA.endsWith("/") ? registryUrlA.substring(0, registryUrlA.length() - 1) : registryUrlA;
final String normalizedRegistryUrlB = registryUrlB.endsWith("/") ? registryUrlB.substring(0, registryUrlB.length() - 1) : registryUrlB;

return normalizedRegistryUrlA.equals(normalizedRegistryUrlB);
}

return false;
}
}