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

ASF GitHub Bot commented on MINIFI-415:
---------------------------------------

GitHub user apiri opened a pull request:

    https://github.com/apache/nifi-minifi/pull/108

    MINIFI-415 Adjusting logging when a bundle is automatically selected

    MINIFI-415 Adjusting logging when a bundle is automatically selected for a 
component when multiple options are available.
    
    Thank you for submitting a contribution to Apache NiFi - MiNiFi.
    
    In order to streamline the review of the contribution we ask you
    to ensure the following steps have been taken:
    
    ### For all changes:
    - [ ] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [ ] Does your PR title start with MINIFI-XXXX where XXXX is the JIRA 
number you are trying to resolve? Pay particular attention to the hyphen "-" 
character.
    
    - [ ] Has your PR been rebased against the latest commit within the target 
branch (typically master)?
    
    - [ ] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [ ] Have you ensured that the full suite of tests is executed via mvn 
-Pcontrib-check clean install at the root nifi-minifi folder?
    - [ ] Have you written or updated unit tests to verify your changes?
    - [ ] If adding new dependencies to the code, are these dependencies 
licensed in a way that is compatible for inclusion under [ASF 
2.0](http://www.apache.org/legal/resolved.html#category-a)? 
    - [ ] If applicable, have you updated the LICENSE file, including the main 
LICENSE file under minifi-assembly?
    - [ ] If applicable, have you updated the NOTICE file, including the main 
NOTICE file found under minifi-assembly?
    
    ### For documentation related changes:
    - [ ] Have you ensured that format looks appropriate for the output in 
which it is rendered?
    
    ### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build 
issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/apiri/nifi-minifi MINIFI-415

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi-minifi/pull/108.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #108
    
----
commit 3797f8c1c09e331b544fb85d7cc0cc5668cf13b4
Author: Aldrin Piri <aldrin@...>
Date:   2018-01-11T18:56:54Z

    MINIFI-415 Adjusting logging when a bundle is automatically selected for a 
component when multiple options are available.

----


> 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
>            Assignee: Aldrin Piri
>            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)

Reply via email to