Question/Problem about KieScanner against a remote BRMS/BPMS server

Solution Verified - Updated

Environment

  • Red Hat Process Automation Manager (RHPAM)
    • 6.x
    • 7.x
  • Red Hat Decision Manager (RHDM)
    • 6.x
    • 7.x

Issue

  • How KieScanner replace the previous KnowledgeAgent?
  • Can KieScanner fire rules that it wasn't aware of at build time like previous KnowledgeAgent with changeset.xml?
  • Is there a sample project for demonstrate KieScanner against a remote RHPAM/RHDM server?
  • How to configure the rules' client to download / execute rules from remote Business Central server ?

Resolution

KieScanner & KnowledgeAgent

  • The KieScanner is a maven-oriented replacement of the KnowledgeAgent present in Drools 5, it allows for continuous monitoring of the remote maven repository(http://10.10.10.10:8080/business-central/maven2/) to check if a new release of a Kie project has been installed(Build & Deploy in business-central). KieScanner can fire rules that it wasn't aware of at build time like the previous KnowledgeAgent with changeset.xml.

  • If a new release is installed or a -SNAPSHOT version is updated the KieScanner will pick up the new updates, put it in KieRepository and local maven repository. The below code shows how a KieScanner can be registered on a KieContainer:

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-central server is unavailable (for example, network outage or scheduled maintenance, etc.), BRMS / BPMS client app. will use the artifact in local maven repository previously downloaded. KieScanner still runs in background and once remote server is back, it will download the updates on next scanning.

Content from blog.athico.com is not included.Developer's blog demonstrates how KieScanner replaces 5.x KnowledgeAgent

Setting Maven

  • KieScanner relies heavily on Maven, which effectively means that it is following all standard maven conventions. This document: How to access remote BRMS maven repository from local maven project ? is for how to configure the maven settings.xml, If users want KieScanner to work correctly they should configure maven with the correct updatePolicy, 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 KieScanner in a standalone java client against projects in the business-central:

      1. G(groupId)A(artifactId)V(version) org:test:1.0-SNAPSHOT
    • If changes are made to this project in business-central, and users do not change its version AND build & deploy it, then KieScanner will pick up changes. SNAPSHOT actually stands for a time-stamp and every subsequent build will have this time-stamp newer - this tells maven that 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, the KieScanner pointed to the 1.0-SNAPSHOT will 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 );
    1. GAV org:test:1.0
    • if users make changes to this project and change or even do not change the version AND KieScanner is pointed to the org:test:1.0 the changes will not be picked up by KieScanner. The maven resolution 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 KieScanner will be pointed to the org:test:LATEST the changes will be picked up.

    • In this conditions, the client sample code like:

		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 maven project is attached which includes KieScanner embedded in the standalone java application. It runs against simple project in the business-central. It is recommended to play with the group / artifact / version attributes to understand KieScanner behaviour better.

  • In business-central, the project included only one DRL rule with 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-CI to look-up KieModule from remote Business Central console 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 in Business Central. However, the rule is being updated while this test case is running and it has been attempted to build the Business Central project , hoping that even if the project version is not being updated, the running test case should pick up the change if Build&Deploy operation 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 KieContainer provides a runtime to utilize the KieModule, version is built in throughout, via Maven. Kie-ci will create a classpath dynamically from all the Maven declared dependencies for the artefact being loaded. Maven LATEST, SNAPSHOT, RELEASE an 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] ------------------------------------------------------------------------
Components
Category

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.