Question/Problem about KieScanner against a remote BRMS/BPMS server
Environment
- Red Hat Process Automation Manager (RHPAM)
- 6.x
- 7.x
- Red Hat Decision Manager (RHDM)
- 6.x
- 7.x
Issue
- How
KieScannerreplace the previousKnowledgeAgent? - Can
KieScannerfire rules that it wasn't aware of at build time like previousKnowledgeAgentwithchangeset.xml? - Is there a sample project for demonstrate
KieScanneragainst a remoteRHPAM/RHDMserver? - How to configure the rules' client to download / execute rules from remote
Business Centralserver ?
Resolution
KieScanner & KnowledgeAgent
-
The
KieScanneris amaven-orientedreplacement of theKnowledgeAgentpresent inDrools 5, it allows for continuous monitoring of the remotemavenrepository(http://10.10.10.10:8080/business-central/maven2/) to check if a new release of aKie projecthas been installed(Build & Deploy in business-central).KieScannercan fire rules that it wasn't aware of at build time like the previousKnowledgeAgentwithchangeset.xml. -
If a new release is installed or a
-SNAPSHOTversion is updated theKieScannerwill pick up the new updates, put it inKieRepositoryand localmavenrepository. The below code shows how aKieScannercan be registered on aKieContainer:
KieServices kieServices = KieServices.Factory.get();
ReleaseId releaseId = kieServices.newReleaseId( "org.acme", "myartifact", "1.0-SNAPSHOT" );
KieContainer kContainer = kieServices.newKieContainer( releaseId );
KieScanner kScanner = kieServices.newKieScanner( kContainer );
kScanner.start( 10000L );
- If the remote
business-centralserver is unavailable (for example, network outage or scheduled maintenance, etc.), BRMS / BPMS client app. will use the artifact in local maven repository previously downloaded.KieScannerstill runs in background and once remote server is back, it will download the updates on next scanning.
Setting Maven
KieScannerrelies heavily onMaven, which effectively means that it is following all standardmavenconventions. This document: How to access remote BRMSmavenrepository from localmavenproject ? is for how to configure themavensettings.xml, If users wantKieScannerto work correctly they should configuremavenwith the correctupdatePolicy, as following configuration sample:
<profile>
<id>guvnor-m2-repo</id>
<repositories>
<repository>
<id>guvnor-m2-repo</id>
<name>BRMS Repository</name>
<url>http://10.10.10.10:8080/business-central/maven2/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
It sets the updatePolicy as always and enable snapshots and releases, more details about maven configuration please refer to Content from maven.apache.org is not included.maven-settings
Samples
-
Here are few examples which demonstrate this behaviour - they explain how to use
KieScannerin a standalonejava clientagainst projects in thebusiness-central:-
- G(groupId)A(artifactId)V(version)
org:test:1.0-SNAPSHOT
- G(groupId)A(artifactId)V(version)
-
If changes are made to this project in
business-central, and users do not change its version AND build & deploy it, thenKieScannerwill pick up changes.SNAPSHOTactually stands for a time-stamp and every subsequent build will have this time-stamp newer - this tellsmaventhat there is actually a newer version of this project and it will use the version with the newest time-stamp. -
If changes are made to this project, and change the version to
1.0.1-SNAPSHOT, theKieScannerpointed to the1.0-SNAPSHOTwill not pick up changes as this is simply a new, separate release. -
In this conditions, the client sample code like:
-
ReleaseId releaseId = kServices.newReleaseId( "org", "test", "1.0-SNAPSHOT" );
KieContainer kContainer = kServices.newKieContainer( releaseId );
KieScanner kScanner = kServices.newKieScanner( kContainer );
-
- GAV
org:test:1.0
-
if users make changes to this project and change or even do not change the version AND
KieScanneris pointed to theorg:test:1.0the changes will not be picked up byKieScanner. Themavenresolution of a GAV defined like this is simply fixed to a one single artifact. -
if users make changes to this project and increase the version and
KieScannerwill be pointed to theorg:test:LATESTthe changes will be picked up. -
In this conditions, the client sample code like:
- GAV
ReleaseId releaseId = kServices.newReleaseId( "org", "test", "LATEST" );
KieContainer kContainer = kServices.newKieContainer( releaseId );
KieScanner kScanner = kServices.newKieScanner( kContainer );
Similarly should work also other keywords such as RELEASE, which refers to the last non-snapshot release in the repository.
-
Simple
mavenproject is attached which includesKieScannerembedded in the standalonejavaapplication. It runs against simple project in thebusiness-central. It is recommended to play with thegroup/artifact/versionattributes to understandKieScannerbehaviour better. -
In
business-central, the project included only oneDRL rulewith the following content:
rule "hello"
when String()
then
System.out.println("Hello World");
end
The RHS part can be altered before every build & deploy - the output should (not) be changed in the client(depending on the KieScanner configuration).
Diagnostic Steps
- using
Kie-CIto look-upKieModulefrom remoteBusiness Centralconsole as bellow:
@BeforeClass
public void init() {
log.info("--- using kie-ci to load rule package");
String url = "http://localhost:8080/business-central/maven2/";
ReleaseIdImpl releaseId = new ReleaseIdImpl("org.kie.example", "project1","LATEST");
ks = KieServices.Factory.get();
urlResource = ks.getResources().newUrlResource(url);
kc = ks.newKieContainer(releaseId);
kScanner = ks.newKieScanner( kc );
kScanner.start(5000l);
}
...
@Test(singleThreaded=true, invocationCount=100)
public void testStartRuleEngine() {
kScanner.scanNow();
// From the container, a session is created based on
// its definition and configuration in the META-INF/kmodule.xml file
ksession = kc.newKieSession("defaultKieSession"); //defaultKieSession
// fire the engine
ksession.fireAllRules();
ksession.dispose();
log.info(System.currentTimeMillis());
try {
Thread.sleep(5000l);
} catch (InterruptedException e) {
//e.printStackTrace();
}
}
- Now, if just the version is specified for the project in
ReleaseIdImpl(..)it reads and executes the rule from the project inBusiness Central. However, the rule is being updated while this test case is running and it has been attempted to build theBusiness Centralproject , hoping that even if the project version is not being updated, the running test case should pick up the change ifBuild&Deployoperation is performed on the project. But, it doesn't happen.
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
2014-02-03 19:47:56,510 [main] INFO it.com.cdii.rules.ITBlindFireKieCi - --- using kie-ci to load rule package
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Hello, I am always talking from BRMS DRL!!! Darius
2014-02-03 19:48:05,221 [main] INFO it.com.cdii.rules.ITBlindFireKieCi - 1391437085221
Hello, I am always talking from BRMS DRL!!! Darius
2014-02-03 19:48:10,233 [main] INFO it.com.cdii.rules.ITBlindFireKieCi - 1391437090233
Hello, I am always talking from BRMS DRL!!! Darius
2014-02-03 19:48:15,241 [main] INFO it.com.cdii.rules.ITBlindFireKieCi - 1391437095241
Hello, I am always talking from BRMS DRL!!! Darius
2014-02-03 19:48:20,252 [main] INFO it.com.cdii.rules.ITBlindFireKieCi - 1391437100252
Hello, I am always talking from BRMS DRL!!! Darius
2014-02-03 19:48:25,262 [main] INFO it.com.cdii.rules.ITBlindFireKieCi - 1391437105262
Hello, I am always talking from BRMS DRL!!! Darius
2014-02-03 19:48:30,273 [main] INFO it.com.cdii.rules.ITBlindFireKieCi - 1391437110273
...
- As per this chapter Content from docs.jboss.org is not included.1 in community doc, it says: The
KieContainerprovides a runtime to utilize theKieModule, version is built in throughout, viaMaven.Kie-ciwill create a classpath dynamically from all theMavendeclared dependencies for the artefact being loaded. MavenLATEST,SNAPSHOT,RELEASEan version ranges are supported.
So, if users update the ReleaseIdImpl(..) with this value, it is expected that each new revision of the rule which has been kept in Business Central project (where the Group ID, Artifact ID is same but Version ID changes and each time the Build&Deploy is performed) the code should have picked up the latest version of the rule, but it doesn't . Instead the following exception is seen:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
2014-02-03 20:03:17,717 [main] INFO it.com.cdii.rules.ITBlindFireKieCi - --- using kie-ci to load rule package
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Tests run: 504, Failures: 2, Errors: 0, Skipped: 502, Time elapsed: 3.97 sec <<< FAILURE!
Results :
Failed tests: init(it.com.cdii.rules.ITBlindFireKieCi): Cannot find KieModule: org.kie.example:project1:LATEST
init(it.com.cdii.rules.ITBlindFireKieCi): Cannot find KieModule: org.kie.example:project1:LATEST
Tests run: 504, Failures: 2, Errors: 0, Skipped: 502
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.513s
[INFO] Finished at: Mon Feb 03 20:03:20 IST 2014
[INFO] Final Memory: 21M/57M
[INFO] ------------------------------------------------------------------------
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.