nifi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aldrin Piri (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (MINIFI-415) Bundle version number should not be compared as a simple String
Date Wed, 13 Dec 2017 03:46:02 GMT

    [ https://issues.apache.org/jira/browse/MINIFI-415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16288673#comment-16288673
] 

Aldrin Piri commented on MINIFI-415:
------------------------------------

Yeah, there was certainly some uncertainty when implementing, but looking at the majority
use case, the current implementation made the most sense and this sorted comparison was a
best effort should the minority case arise.  While I agree the snippet shown is problematic
I am not sure how often it would arise in practice.  Typically from what I have seen from
users is that they use the base package and then add a NAR with some components.  To add that
many versions of associated NARs seems a bit counter intuitive to the aims of MiNiFi.  Additionally,
where feasible there is also a matching up of dependency NARs with the extension NARs.  While
I do like the idea of some stronger guarantees than "stringly typing" our versions, this is
effectively how it is handled in NiFi as well, but as mentioned, the user is presented with
a UI to make such selections. While the proposed breakdown of versions could be helpful, I
have also seen users generate versions that would cause this to also break.

Potentially we avoid making an auto-determination and cause an exception case to be evaluated
in such a state?  This removes any uncertainty and has the user take specific action for those
scenarios that would be out of the expected conventions.

Anyway, let me know your thoughts and would be interested to see if we can come up with a
solution that is more fitting.   

> Bundle version number should not be compared as a simple String
> ---------------------------------------------------------------
>
>                 Key: MINIFI-415
>                 URL: https://issues.apache.org/jira/browse/MINIFI-415
>             Project: Apache NiFi MiNiFi
>          Issue Type: Bug
>          Components: Agent Configuration/Installation
>    Affects Versions: 0.3.0
>            Reporter: Koji Kawamura
>            Priority: Minor
>
> MINIFI-408 added support for picking the latest bundle version automatically if there
are multiple versions for the same Nar. However, it compares version as simple Strings and
may not be able to pick the latest one semantically.
> https://github.com/apache/nifi-minifi/pull/99/files#diff-c7d8398db8540d6e85f1a9207438ebddR138
> Following code shows the problematic inputs and possible solution. Current implementation
picks "1.0.9", and using Version class, it can pick "1.0.12".
> {code}
> class Test {
>     public static void main(String[] args) throws Exception {
>         Set<String> componentToEnrichBundleVersions = new HashSet<>();
>         componentToEnrichBundleVersions.add("1.0.0");
>         componentToEnrichBundleVersions.add("1.0.5");
>         componentToEnrichBundleVersions.add("1.0.9");
>         componentToEnrichBundleVersions.add("1.0.11-SNAPSHOT");
>         componentToEnrichBundleVersions.add("1.0.12");
>         // Current implementation
>         final String bundleVersion = componentToEnrichBundleVersions.stream().sorted()
>                 .reduce((version, otherVersion) -> otherVersion).orElse(null);
>         // Suggestion
>         final Version latestVersion = componentToEnrichBundleVersions.stream().map(Version::fromString).sorted()
>                 .reduce((version, otherVersion) -> otherVersion).orElse(null);
>         System.out.println(bundleVersion);
>         System.out.println(latestVersion.toVersionString());
>     }
> }
> class Version implements Comparable<Version> {
>     private static Pattern P = Pattern.compile("^([\\d]+)\\.([\\d]+)\\.([\\d]+)([^\\d]*)$");
>     final int major;
>     final int minor;
>     final int patch;
>     final String opt;
>     public static Version fromString(String s) {
>         final Matcher matcher = P.matcher(s);
>         if (matcher.matches()) {
>             return new Version(
>                     Integer.parseInt(matcher.group(1)),
>                     Integer.parseInt(matcher.group(2)),
>                     Integer.parseInt(matcher.group(3)),
>                     matcher.group(4));
>         }
>         throw new IllegalArgumentException("Unknown version pattern " + s);
>     }
>     private Version(int major, int minor, int patch, String opt) {
>         this.major = major;
>         this.minor = minor;
>         this.patch = patch;
>         this.opt = opt;
>     }
>     @Override
>     public int compareTo(@NotNull Version o) {
>         final int ma = new Integer(major).compareTo(o.major);
>         if (ma != 0) {
>             return ma;
>         }
>         final int mi = new Integer(minor).compareTo(o.minor);
>         if (mi != 0) {
>             return mi;
>         }
>         final int pa = new Integer(patch).compareTo(o.patch);
>         if (pa != 0) {
>             return pa;
>         }
>         final String o1 = opt != null ? opt : "";
>         final String o2 = o.opt != null ? o.opt : "";
>         final int op = o1.compareTo(o2);
>         return op;
>     }
>     public String toVersionString() {
>         return String.format("%d.%d.%d%s", major, minor, patch, opt);
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message