Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 1062547 - KieScanner doesn't work with non-timestamped snapshot artifacts
Summary: KieScanner doesn't work with non-timestamped snapshot artifacts
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss BRMS Platform 6
Classification: Retired
Component: BRE
Version: 6.0.0
Hardware: Unspecified
OS: Unspecified
urgent
urgent
Target Milestone: CR1
: 6.0.1
Assignee: Mario Fusco
QA Contact: Marek Winkler
URL:
Whiteboard:
Depends On:
Blocks: 1091524
TreeView+ depends on / blocked
 
Reported: 2014-02-07 09:04 UTC by Mario Fusco
Modified: 2014-08-06 19:57 UTC (History)
11 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-08-06 19:57:36 UTC
Type: Bug


Attachments (Terms of Use)
Maven project with part of the reproducer (deleted)
2014-02-19 18:03 UTC, Marek Winkler
no flags Details
Maven project with reproducer updated to ER2 (deleted)
2014-03-11 09:54 UTC, Marek Winkler
no flags Details

Description Mario Fusco 2014-02-07 09:04:00 UTC
Description of problem:

KieScanner is not able to recognize that a non-timestamped snapshot artifact on the maven repository is newer than the one currently installed and then never upgrades it.

How reproducible:

1. Create a KieContainer on a snapshot kproject
2. Register a KieScanner on that KieContainer
3. Modify the kproject (without changing the version) and install the new version on the local maven repository (using a remote repository maven always creates a timestamped snapshot)
4. Run the KieScanner
5. Verify that the KieContainer is still running with the old kproject even if it should have been updated with the new one

Comment 1 Mario Fusco 2014-02-07 09:10:18 UTC
Fixed by https://github.com/droolsjbpm/drools/commit/c3094c217

Comment 2 Marek Winkler 2014-02-19 18:00:14 UTC
It seems that the original problem has been fixed, however when KieScanner picks up a new version of a -SNAPSHOT kjar, it throws NPE (see console output below).

You can reproduce the problem by the following steps:

1. create a KieModule in business-central with GAV org.redhat:myProject:1.0-SNAPSHOT containing a simple DRL:

rule "test_rule"
when
  String(this == "test")
then
  System.out.println("DRL 1.3");
end

2. build and deploy the artifact in business-central,
3. run the following command 

 mvn clean install exec:java -Dexec.mainClass=com.sample.ProcessMain -s settings.xml

from the attached maven project,

4. change the DRL to output for instance "DRL 1.4",
5. do build and deploy in the business-central.

The NPE is thrown as shown in the console output:

[com.sample.ProcessMain.main()] INFO org.drools.compiler.kie.builder.impl.KieRepositoryImpl - KieModule was added:ZipKieModule[ ReleaseId=org.redhat:myProject:1.0-SNAPSHOTfile=/home/mwinkler/.m2/repository/org/redhat/myProject/1.0-SNAPSHOT/myProject-1.0-SNAPSHOT.jar]
DRL 1.3
DRL 1.3
[com.sample.ProcessMain.main()] INFO org.drools.compiler.kie.builder.impl.KieRepositoryImpl - KieModule was added:ZipKieModule[ ReleaseId=org.redhat:myProject:1.0-SNAPSHOTfile=/home/mwinkler/.m2/repository/org/redhat/myProject/1.0-SNAPSHOT/myProject-1.0-SNAPSHOT.jar]
[WARNING] 
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
	at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NullPointerException
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.updateResourcesIncrementally(KieContainerImpl.java:256)
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.update(KieContainerImpl.java:161)
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.updateDependencyToVersion(KieContainerImpl.java:109)
	at org.kie.scanner.KieRepositoryScannerImpl.updateKieModule(KieRepositoryScannerImpl.java:213)
	at org.kie.scanner.KieRepositoryScannerImpl.scanNow(KieRepositoryScannerImpl.java:202)
	at com.sample.ProcessMain.main(ProcessMain.java:47)
	... 6 more

Comment 3 Marek Winkler 2014-02-19 18:03:17 UTC
Created attachment 865174 [details]
Maven project with part of the reproducer

Comment 4 Marek Winkler 2014-02-19 18:08:49 UTC
I just realized that I should have configured KIE-CI to use the custom settings.xml. Please substitute the maven command in the previous comment with

mvn clean install exec:java -Dexec.mainClass=com.sample.ProcessMain -Dkie.maven.settings.custom=settings.xml -s settings.xml

Anyway, this time there is no NPE, but the KieModule does not get updated:

[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ jbpm-example ---
 wagon http use multi threaded http connection manager maxPerRoute 20, max total 40
[com.sample.ProcessMain.main()] INFO org.drools.compiler.kie.builder.impl.KieRepositoryImpl - KieModule was added:ZipKieModule[ ReleaseId=org.redhat:myProject:1.0-SNAPSHOTfile=/home/mwinkler/work/temp/anton/reproducer/client/kie-scanner-example/repo/org/redhat/myProject/1.0-SNAPSHOT/myProject-1.0-SNAPSHOT.jar]
[com.sample.ProcessMain.main()] INFO org.drools.compiler.kie.builder.impl.KieRepositoryImpl - KieModule was added:ZipKieModule[ ReleaseId=org.redhat:myProject:1.0-SNAPSHOTfile=/home/mwinkler/work/temp/anton/reproducer/client/kie-scanner-example/repo/org/redhat/myProject/1.0-SNAPSHOT/myProject-1.0-SNAPSHOT.jar]
[com.sample.ProcessMain.main()] INFO org.kie.api.builder.KieScanner - The following artifacts have been updated: {org.redhat:myProject:1.0-SNAPSHOT=org.redhat:myProject:jar:1.0-20140219.175734-9}
DRL 1.3
DRL 1.3
....

(The text does not change after rebuilding the changed rule in business-central.)

Comment 5 Marek Winkler 2014-02-19 18:11:05 UTC
Please do not forget to update the settings.xml in the reproducer to your valid business-central credentials.

Comment 6 Mario Fusco 2014-02-21 09:58:26 UTC
I cannot reproduce this problem. I suspect that this is caused by the fact that you already have a 1.0 version of the kproject in your maven repository and then you downgraded it to 1.0-SNAPSHOT. In this case the 1.0 version is always considered to be newer than the snapshot one and then the KieScanner never updates it. Can you please try with a 2.0-SNAPSHOT version, for example, or even better using a completely different artifact name?

Comment 7 Marek Winkler 2014-02-21 11:00:51 UTC
I can still reproduce the problem with a completely different GAV (com.redhat.qa.brms:myKieScannerTest2:1.0.0-SNAPSHOT). 

I also tried erasing the local maven repo used by the kie-scanner-example app but it did not help, the behaviour is still the same.

When I tried updating the KieModule using maven only (no business-central), the KieScanner works fine. Probably a problem with some metadata in the maven repo published by business-central?

Comment 8 Mario Fusco 2014-02-21 11:21:53 UTC
Apparently the problem is in the business-central now. Reassigning to Michael to further investigate this.

Comment 9 Marek Winkler 2014-02-21 12:33:30 UTC
It seems that the problem is not related to -SNAPSHOT versions - I tried this version range [2.0.0,3.0.0), LATEST, and RELEASE and when I created 2.0.1 version, it is also not picked up by the kie-scanner.

Comment 10 manstis 2014-02-25 14:28:45 UTC
For SNAPSHOTs, this relates to the repository update policy.

If I add the following to settings.xml and use a -SNAPSHOT the updates work OK:

  <profiles>
    <profile>
      <id>guvnor-m2-repo-profile</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>guvnor-m2-repo</id>
          <name>guvnor-m2-repo</name>
          <url>http://localhost:8888/maven2</url>
          <!-- Set update policy to *always* otherwise it defaults to *daily* -->
          <snapshots>
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

Non-SNAPSHOTs are a little more complicated.

Since the assumption is non-SNAPSHOTs don't change having KieScanner check for updates to non-SNAPSHOT JARs is meaningless (in principle). However if we are to cater for scenarios where users of the API want to monitor for changes to non-SNAPSHOTs a change to KieRepositoryScannerImpl.setKieContainer() is needed. This, currently only records artifacts to check for updates against if their version is SNAPSHOT (or RELEASE or a ranged release).

IDK if we want to cater for this (erroneous) user scenario?

Reassigning to Mario for changes, if any.

Comment 11 manstis 2014-02-25 14:33:05 UTC
Discussed with Mario and we're confident this is working.

We'd prefer to leave the update policy in settings.xml; as hard-coding this into KieScanner breaks maven compliance - for people expecting "everything maven" to work how "everything else maven" works.

The same is said for static versions: once a JAR is published with a static version it should *not* change. Ever. Imagine the world we'd have if fixed versions of JARs in Nexus or Maven Central changed...

Comment 12 Marek Winkler 2014-02-25 15:47:48 UTC
Configuring updatePolicy in settings.xml sounds good. We should just document this.

Regarding non-SNAPSHOTs, I am not sure if we are talking about the same use-case. I did not mean changing contents of the same non-SNAPSHOT version, which is really against Maven practices, but publishing a new version of the artifact. For instance:

1. build and deploy a kjar with GAV org.redhat:myProject:1.0.0.

2. start a client application running KieScanner which monitors KieContainer created for ReleaseId org.redhat:myProject:LATEST

3. build and deploy a new version of the artifact under org.redhat:myProject:1.0.1

Currently, KieScanner does not pick up the new version of the artifact.

What do you think?

Comment 13 Marek Winkler 2014-02-25 16:16:05 UTC
I have configured the <updatePolicy>always</updatePolicy> in settings.xml and the new version of a SNAPSHOT artifact is still not picked up by the KieScanner.

According to info from Michael, I will wait for ER2 build for verification of SNAPSHOTs.

Comment 14 Marek Winkler 2014-03-03 13:10:06 UTC
I am sorry but KieScanner still does not see changes made to a SNAPSHOT project built by business-central, even when I have configured the updatePolicy to always.

Please try to reproduce this with product build.

Comment 16 manstis 2014-03-03 14:38:03 UTC
OK, double checked with master codebase and -SNAPSHOT KJAR continues to work as required (when the update policy is set to ALWAYS). I'll check with the ER2 from the link in Comment #15 next....

Comment 22 Marek Winkler 2014-03-03 18:29:56 UTC
I tried experimenting with modification of ~/.m2/settings.xml and I have found that:

1. creating a KieModule in business central which contains a rule without a package declared, and then running the reproducer using the same local maven repo as business-central does, causes this NPE:

Caused by: java.lang.NullPointerException
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.updateResourcesIncrementally(KieContainerImpl.java:256)
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.update(KieContainerImpl.java:161)
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.updateDependencyToVersion(KieContainerImpl.java:109)
	at org.kie.scanner.KieRepositoryScannerImpl.updateKieModule(KieRepositoryScannerImpl.java:213)
	at org.kie.scanner.KieRepositoryScannerImpl.scanNow(KieRepositoryScannerImpl.java:202)
	at com.sample.ProcessMain.main(ProcessMain.java:47)

2. if I update the rule to declare a package, then I observe the same behaviour as Mike did (KieScanner picks the changes and works as expected). 

However, when I change the configuration to make BC use a different local maven repo than the reproducer project does, KieScanner does not react to any changes.

Looking at the log, it seems that there is a difference in the version reported by KieScanner:

I have the following line (when using different local maven repos for BC and KieScanner reproducer): The following artifacts have been updated: {org.kie.example:project2:1.0.0-SNAPSHOT=org.kie.example:project2:jar:1.0.0-20140303.172130-3}

while Michael (and me using the same local repo for BC and reproducer) has [main] INFO org.kie.api.builder.KieScanner - The following artifacts have been updated: {org.kie.example:project1:1.0.0-SNAPSHOT=org.kie.example:project1:jar:1.0.0-SNAPSHOT}

We discussed this with Mario and Geoffrey and it seems that in the latter case the artifact seems to be treated like downloaded from a local Maven repo, not a remote, as would be expected.

Comment 23 Mario Fusco 2014-03-04 09:02:08 UTC
NPE fixed by https://github.com/droolsjbpm/drools/commit/39e13f6b0

Comment 24 Marek Winkler 2014-03-04 09:48:03 UTC
Another couple of observations:

1. it does not matter for me, if I use -Dkie.maven.settings.custom=settings.xml or default ~/.m2/settings.xml - the difference is caused by using the same/different maven local repo by business-central and KieScanner

2. KieScanner is able to pick up changes in non-SNAPSHOT artifacts when I change them using CLI (mvn install), but fails to pick up the changes if they are done by business-central. It seems related to the problem with SNAPSHOTs.

Comment 25 Mario Fusco 2014-03-04 13:41:58 UTC
KieScanner updates when using different local repo fixed by https://github.com/droolsjbpm/drools/commit/769c57516

Comment 26 Kris Verlaenen 2014-03-04 13:53:52 UTC
Please note there are TWO (!) commits related to this fix (comment 23 and 25).

Comment 27 Edson Tirelli 2014-03-04 17:23:35 UTC
This was cherry-picked into the 6.0.1.ER2 tag:

https://github.com/jboss-integration/drools/commit/012d316

https://github.com/jboss-integration/drools/commit/f82d6f2

Comment 28 Marek Winkler 2014-03-11 09:53:13 UTC
Unfortunately the fix still does not work for me with BRMS 6.0.1 ER2.

Here are the detailed steps I use to reproduce the issue:

-- prepare project in business-central:

1. Start BRMS business-central which is using a local maven repository REPO_1.
  -- for instance, I use default ~/.m2/settings.xml which uses ~/.m2/repository as the repository location

2. Create a new project with GAV org.kie.examples:kieScannerTest:1.0.0-SNAPSHOT

3. Create the following rule in this project (it can be in default package):

rule "test rule"
when
  String()
then
  System.out.println("Version 1.0");
end

4. Save the rule, Build and Deploy the project

--- run the reproducer with KieScanner:

5. extract the attached reproducer (labelled as 'for ER2'), and update extracted settings.xml with your business-central user credentials
  -- please note this settings.xml needs to declare a different local maven repository than REPO_1, for instance, the reproducer uses <localRepository>repo</localRepository>

6. run mvn clean install exec:java -Dexec.mainClass=com.sample.ProcessMain -Dkie.maven.settings.custom=settings.xml -s settings.xml

7. wait until the reproducer starts printing the rule output (each 10 seconds)

--- modify the rule in the business-central:

8. using business-central, modify the rule to print "Version 1.1", save the DRL, build and deploy the project

9. watch the reproducer continuing to print "Version 1.0"

Comment 29 Marek Winkler 2014-03-11 09:54:32 UTC
Created attachment 873032 [details]
Maven project with reproducer updated to ER2

Comment 31 Mario Fusco 2014-03-12 17:35:11 UTC
Fixed by https://github.com/droolsjbpm/drools/commit/09ed95450

Comment 33 Michael 2014-03-17 16:27:47 UTC
Ticket cherry-picked into 6.0.1.CR1. 
Commits: 1031440d91a1ea338cd9ec44ed860216b60a0596
         98314148327c8b6001c7b5a595ab35086d8ebc13
         771467f445c9469d5a5d1f70e4cd9aa58931f951

Comment 34 Marek Winkler 2014-03-24 09:57:07 UTC
Verified that the KieScanner in 6.0.1 CR1 picks up changes from business-central when using both SNAPSHOT artifacts and non-SNAPSHOT artifacts combined with setting artifact version to LATEST. 

Verified for both BRMS and BPMS business-central.


Note You need to log in before you can comment on or make changes to this bug.