package com.myspace.demorule;
import com.myspace.demorule.Sale;
rule "DiscountForCarSale"
when
thisSale : Sale (quantity >= 5 , item == "Car");
then
thisSale.setDiscount(10);
end;
rule "DiscountForBikeSale"
when
thisSale : Sale (quantity >= 10 , item == "Bike");
then
thisSale.setDiscount(15);
end;
Make sure to validate by clicking on validate button
Build & Install
Deploy
Deployment added
Kie Server logs
2021-05-13 06:26:51.835 INFO 9516 --- [0.1-8090-exec-6] o.d.c.kie.builder.impl.KieContainerImpl : End creation of KieBase: defaultKieBase
2021-05-13 06:26:51.836 INFO 9516 --- [0.1-8090-exec-6] o.k.s.s.jbpm.JbpmKieServerExtension : Container drools-demo-kjar_1.0.0-SNAPSHOT does not include processes, jBPM KIE Server extension skipped
2021-05-13 06:26:51.837 INFO 9516 --- [0.1-8090-exec-6] o.k.server.services.impl.KieServerImpl : Container drools-demo-kjar_1.0.0-SNAPSHOT (for release id com.github.mnadeem:drools-demo-kjar:1.0.0-SNAPSHOT) successfully started
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.4.RELEASE)
2021-05-11 05:16:27.421 INFO 6868 --- [ main] c.g.m.kie.BootJbpmKieServerApplication : Starting BootJbpmKieServerApplication on DESKTOP-9AES3TT with PID 6868 (E:\eWorkspaces\drools\boot-jbpm-kie-server\target\classes started by reach in E:\eWorkspaces\drools\boot-jbpm-kie-server)
2021-05-11 05:16:27.424 INFO 6868 --- [ main] c.g.m.kie.BootJbpmKieServerApplication : No active profile set, falling back to default profiles: default
2021-05-11 05:16:28.872 INFO 6868 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8090 (http)
2021-05-11 05:16:28.887 INFO 6868 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-05-11 05:16:28.887 INFO 6868 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
2021-05-11 05:16:29.073 INFO 6868 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-05-11 05:16:29.073 INFO 6868 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1607 ms
2021-05-11 05:16:29.422 WARN 6868 --- [ main] com.arjuna.ats.common : ARJUNA048002: Could not find configuration file, URL was: null
2021-05-11 05:16:29.509 INFO 6868 --- [ main] o.d.p.api.TransactionManagerFactory : Using org.kie.spring.persistence.KieSpringTransactionManagerFactory@559d19c
2021-05-11 05:16:29.535 INFO 6868 --- [ main] com.arjuna.ats.jbossatx : ARJUNA032010: JBossTS Recovery Service (tag: 92f28891fd5f29d0381da214d4f3a2917f46e301) - JBoss Inc.
2021-05-11 05:16:29.577 INFO 6868 --- [ main] com.arjuna.ats.jbossatx : ARJUNA032013: Starting transaction recovery manager
2021-05-11 05:16:29.742 INFO 6868 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: org.jbpm.domain]
2021-05-11 05:16:29.821 INFO 6868 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.21.Final
2021-05-11 05:16:30.019 INFO 6868 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2021-05-11 05:16:31.011 INFO 6868 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2021-05-11 05:16:31.501 INFO 6868 --- [ main] org.hibernate.orm.beans : HHH10005002: No explicit CDI BeanManager reference was passed to Hibernate, but CDI is available on the Hibernate ClassLoader.
2021-05-11 05:16:31.615 INFO 6868 --- [d Entry Monitor] com.arjuna.ats.arjuna : ARJUNA012332: Failed to establish connection to server
2021-05-11 05:16:32.262 INFO 6868 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform]
2021-05-11 05:16:32.787 WARN 6868 --- [ main] o.h.dialect.function.TemplateRenderer : HHH000174: Function template anticipated 4 arguments, but 1 arguments encountered
2021-05-11 05:16:32.787 WARN 6868 --- [ main] o.h.dialect.function.TemplateRenderer : HHH000174: Function template anticipated 4 arguments, but 1 arguments encountered
2021-05-11 05:16:32.838 INFO 6868 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'org.jbpm.domain'
2021-05-11 05:16:32.881 WARN 6868 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-05-11 05:16:33.163 INFO 6868 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@4690cb47, org.springframework.security.web.context.SecurityContextPersistenceFilter@5e91b051, org.springframework.security.web.header.HeaderWriterFilter@751636da, org.springframework.security.web.authentication.logout.LogoutFilter@16908f89, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@55fbebba, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@77376e83, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@1b204439, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@77d80294, org.springframework.security.web.session.SessionManagementFilter@3d5a6849, org.springframework.security.web.access.ExceptionTranslationFilter@28068327, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@16c9ec5b]
2021-05-11 05:16:33.253 INFO 6868 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-05-11 05:16:33.692 INFO 6868 --- [ main] o.k.i.pmml.PMMLImplementationsUtil : Using NEW implementation
2021-05-11 05:16:33.692 INFO 6868 --- [ main] o.k.i.pmml.PMMLImplementationsUtil : Using NEW implementation
2021-05-11 05:16:33.877 INFO 6868 --- [ main] com.arjuna.ats.arjuna : ARJUNA012170: TransactionStatusManager started on port 58892 and host 127.0.0.1 with service com.arjuna.ats.arjuna.recovery.ActionStatusService
2021-05-11 05:16:34.265 INFO 6868 --- [ main] o.k.s.s.a.KieServerAutoConfiguration : KieServer (id boot-kie-server (name KIE Server SpringBoot)) started initialization process
2021-05-11 05:16:34.482 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : Starting server in 'DEVELOPMENT' mode.
2021-05-11 05:16:34.485 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : Selected startup strategy ControllerBasedStartupStrategy - deploys kie containers given by controller ignoring locally defined
2021-05-11 05:16:34.486 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : Configured 'KieServerStateFileRepository' server state repository
2021-05-11 05:16:34.515 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : Server Default Extension has been successfully registered as server extension
2021-05-11 05:16:34.516 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : Drools KIE Server extension has been successfully registered as server extension
2021-05-11 05:16:34.535 INFO 6868 --- [ main] o.k.s.api.marshalling.MarshallerFactory : Marshaller extensions init
2021-05-11 05:16:34.546 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : jBPM KIE Server extension has been successfully registered as server extension
2021-05-11 05:16:34.548 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : Case-Mgmt KIE Server extension has been successfully registered as server extension
2021-05-11 05:16:34.655 INFO 6868 --- [ main] o.k.s.s.j.u.f.r.BootstrapFormRenderer : Boostrap Form renderer templates loaded successfully.
2021-05-11 05:16:34.660 INFO 6868 --- [ main] o.k.s.s.j.u.f.r.PatternflyFormRenderer : patternfly Form renderer templates loaded successfully.
2021-05-11 05:16:34.666 INFO 6868 --- [ main] o.k.s.s.j.u.f.r.PatternflyFormRenderer : workbench Form renderer templates loaded successfully.
2021-05-11 05:16:34.667 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : jBPM-UI KIE Server extension has been successfully registered as server extension
2021-05-11 05:16:34.670 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : DMN KIE Server extension has been successfully registered as server extension
2021-05-11 05:16:34.672 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : Scenario Simulation KIE Server extension has been successfully registered as server extension
2021-05-11 05:16:34.674 INFO 6868 --- [ main] o.k.s.s.impl.policy.PolicyManager : Registered KeepLatestContainerOnlyPolicy{interval=0 ms} policy under name KeepLatestOnly
2021-05-11 05:16:34.674 INFO 6868 --- [ main] o.k.s.s.impl.policy.PolicyManager : Policy manager started successfully, activated policies are []
2021-05-11 05:16:34.678 INFO 6868 --- [ main] o.k.s.services.impl.ContainerManager : About to install containers on kie server
KieServer{id='boot-kie-server'name='KIE Server SpringBoot'version='7.53.0.Final'location='http://localhost:8090/rest/server'}:
KieContainerResource [containerId=my-deploy, releaseId=com.github.mnadeem:drools-discount-kjar:0.0.1-SNAPSHOT, resolvedReleaseId=null, status=STARTED]
KieContainerResource [containerId=testFirstContainer, releaseId=com.github.mnadeem:drools-discount-kjar:0.0.1-SNAPSHOT, resolvedReleaseId=null, status=STARTED]
2021-05-11 05:16:35.839 INFO 6868 --- [ main] o.d.c.k.b.i.InternalKieModuleProvider : Creating KieModule for artifact com.github.mnadeem:drools-discount-kjar:0.0.1-SNAPSHOT
2021-05-11 05:16:35.847 INFO 6868 --- [ main] o.d.m.CanonicalKieModuleProvider : No executable model found for artifact com.github.mnadeem:drools-discount-kjar:0.0.1-SNAPSHOT. Falling back to resources parsing.
2021-05-11 05:16:35.956 INFO 6868 --- [ main] o.d.c.kie.builder.impl.KieContainerImpl : Start creation of KieBase: defaultKieBase
2021-05-11 05:16:36.644 INFO 6868 --- [ main] o.d.c.kie.builder.impl.KieContainerImpl : End creation of KieBase: defaultKieBase
2021-05-11 05:16:36.645 INFO 6868 --- [ main] o.k.s.s.jbpm.JbpmKieServerExtension : Container my-deploy does not include processes, jBPM KIE Server extension skipped
2021-05-11 05:16:36.646 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : Container my-deploy (for release id com.github.mnadeem:drools-discount-kjar:0.0.1-SNAPSHOT) successfully started
2021-05-11 05:16:36.656 WARN 6868 --- [ main] o.k.s.s.i.c.DefaultRestControllerImpl : No controllers found to update to new status org.kie.server.api.model.KieServerStateInfo@6983436f
2021-05-11 05:16:36.732 INFO 6868 --- [ main] o.d.c.k.b.i.InternalKieModuleProvider : Creating KieModule for artifact com.github.mnadeem:drools-discount-kjar:0.0.1-SNAPSHOT
2021-05-11 05:16:36.732 INFO 6868 --- [ main] o.d.m.CanonicalKieModuleProvider : No executable model found for artifact com.github.mnadeem:drools-discount-kjar:0.0.1-SNAPSHOT. Falling back to resources parsing.
2021-05-11 05:16:36.793 INFO 6868 --- [ main] o.d.c.kie.builder.impl.KieContainerImpl : Start creation of KieBase: defaultKieBase
2021-05-11 05:16:36.849 INFO 6868 --- [ main] o.d.c.kie.builder.impl.KieContainerImpl : End creation of KieBase: defaultKieBase
2021-05-11 05:16:36.849 INFO 6868 --- [ main] o.k.s.s.jbpm.JbpmKieServerExtension : Container testFirstContainer does not include processes, jBPM KIE Server extension skipped
2021-05-11 05:16:36.907 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : Container testFirstContainer (for release id com.github.mnadeem:drools-discount-kjar:0.0.1-SNAPSHOT) successfully started
2021-05-11 05:16:36.909 WARN 6868 --- [ main] o.k.s.s.i.c.DefaultRestControllerImpl : No controllers found to update to new status org.kie.server.api.model.KieServerStateInfo@16ee0c8f
2021-05-11 05:16:36.912 INFO 6868 --- [ main] o.k.server.services.impl.KieServerImpl : KieServer boot-kie-server is ready to receive requests
2021-05-11 05:16:36.950 INFO 6868 --- [ main] o.k.s.s.a.KieServerAutoConfiguration : KieServer (id boot-kie-server) started successfully
2021-05-11 05:16:37.164 INFO 6868 --- [ main] org.apache.cxf.endpoint.ServerImpl : Setting the server's publish address to be /
2021-05-11 05:16:37.330 INFO 6868 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8090 (http) with context path ''
2021-05-11 05:16:37.339 INFO 6868 --- [ main] c.g.m.kie.BootJbpmKieServerApplication : Started BootJbpmKieServerApplication in 10.235 seconds (JVM running for 10.785)
There are couple of options to define the scope of the resources and configurations that will be included in an instance of KieContainer.
Based of KieFileSystem, we have seen this approach earlier.
Based on classpath : will look at all the business assets in the application classpath and allow us to load them in different instances of the rule engine.
Based on Maven dependency resolution techniques (KIE-CI) : Will delegate the responsibility of finding out the predefined artifacts and their transitive dependencies into Maven to find out all the resources that need to be included.
package com.github.mnadeem.discount.model;
public class Sale {
private int quantity;
private String item;
private int discount;
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getItem() {
return item;
}
public void setItem(String item) {
this.item = item;
}
public int getDiscount() {
return discount;
}
public void setDiscount(int discount) {
this.discount = discount;
}
}
When we create a new KieContainer based on the classpath, all the available jars will be scanned.
Drools will scan all the jars in the classpath looking for the kmodule.xml file in the META-INF/ directory. When found, this file will load the provided configurations to make them available to use in our applications.
In essence all the KieModules that are found in the classpath of the application will be loaded in the KieContainer.
Loading Rules Using Maven Artifacts (KIE-CI)
In Cases where we don’t want to load all the KieModules that are found in the classpath, will go ahead with this approach.
In this case we don’t add any KieModule dependency in the pom.xml file, instead we add the following dependency.
The above dependency will enable Drools to use the Maven mechanism to resolve the artifacts that are outside the application classpath. Here is how we can create a container in this approach.
Notice that in this approach, instead of adding the dependency to our project we are letting the KieContainer resolve an artifact that we are providing based on GAV.
The Drools API allows us to not only use this ReleaseId specific version of the KieModule, but also upgrade it to a newer version, should it be necessary, through the updateToVersion() method. This method will recreate the KieContainer to become an access point to the KieBases and KieSessions of a newer version of the KieModule.
The KieScanner component in Drools is nothing but a wrapper around a KieContainer that can be configured to automatically detect changes in the resources that the container depends on.
KieServices ks = KieServices.Factory.get();
KieContainer kieContainer = ks.newKieContainer(ks.newReleaseId("group.test","artifact-test", "1.0"));
KieScanner scanner = ks.newKieScanner(kieContainer);
//Manually run a check for new versions
scanner.scanNow();
//Configure the scanner to check for new versions every 10 seconds
scanner.start(10_000);
jBPM business process management. Adds jBPM capabilities to your application. It provides the jBPM /RHPAM-embedded runtime and services to run the process execution engine within your application.
Fully featured KIE Server (Drools, jBPM, Optaplanner) : Adds KIE Server capabilities to your application. This allows you to run the KIE Server services and RESTful APIs within your application. This starter provides all the business automation features that Process Automation Manager has to offer. This includes process and case execution (jBPM ), (business) rules and DMN (Decision Model & Notation) execution (Drools ), and business resource optimization (OptaPlanner ).
Rules and Decisions, Process and Cases KIE Server (Drools, DMN, jBPM, Case mgmt) : Same as kie-server-spring-boot-starter, but has only rules and process and case execution (jBPM) capabilities.
Planning KIE Server (Optaplanner) : Same as the kie-server-spring-boot-starter, but has only business resource optimization (OptaPlanner ) capabilities.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.4.RELEASE)
2021-05-09 22:02:43.526 INFO 14324 --- [ main] c.g.m.kie.BootJbpmKieServerApplication : Starting BootJbpmKieServerApplication on DESKTOP-9AES3TT with PID 14324 (E:\eWorkspaces\drools\boot-jbpm-kie-server\target\classes started by reach in E:\eWorkspaces\drools\boot-jbpm-kie-server)
2021-05-09 22:02:43.529 INFO 14324 --- [ main] c.g.m.kie.BootJbpmKieServerApplication : No active profile set, falling back to default profiles: default
2021-05-09 22:02:44.877 INFO 14324 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8090 (http)
2021-05-09 22:02:44.887 INFO 14324 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-05-09 22:02:44.887 INFO 14324 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
2021-05-09 22:02:45.072 INFO 14324 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-05-09 22:02:45.072 INFO 14324 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1504 ms
2021-05-09 22:02:45.347 WARN 14324 --- [ main] com.arjuna.ats.common : ARJUNA048002: Could not find configuration file, URL was: null
2021-05-09 22:02:45.390 INFO 14324 --- [ main] o.d.p.api.TransactionManagerFactory : Using org.kie.spring.persistence.KieSpringTransactionManagerFactory@20b54cfe
2021-05-09 22:02:45.409 INFO 14324 --- [ main] com.arjuna.ats.jbossatx : ARJUNA032010: JBossTS Recovery Service (tag: 92f28891fd5f29d0381da214d4f3a2917f46e301) - JBoss Inc.
2021-05-09 22:02:45.438 INFO 14324 --- [ main] com.arjuna.ats.jbossatx : ARJUNA032013: Starting transaction recovery manager
2021-05-09 22:02:45.555 INFO 14324 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: org.jbpm.domain]
2021-05-09 22:02:45.614 INFO 14324 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.21.Final
2021-05-09 22:02:45.751 INFO 14324 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2021-05-09 22:02:46.651 INFO 14324 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2021-05-09 22:02:47.127 INFO 14324 --- [ main] org.hibernate.orm.beans : HHH10005002: No explicit CDI BeanManager reference was passed to Hibernate, but CDI is available on the Hibernate ClassLoader.
2021-05-09 22:02:47.473 INFO 14324 --- [d Entry Monitor] com.arjuna.ats.arjuna : ARJUNA012332: Failed to establish connection to server
2021-05-09 22:02:47.809 INFO 14324 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform]
2021-05-09 22:02:48.353 WARN 14324 --- [ main] o.h.dialect.function.TemplateRenderer : HHH000174: Function template anticipated 4 arguments, but 1 arguments encountered
2021-05-09 22:02:48.354 WARN 14324 --- [ main] o.h.dialect.function.TemplateRenderer : HHH000174: Function template anticipated 4 arguments, but 1 arguments encountered
2021-05-09 22:02:48.405 INFO 14324 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'org.jbpm.domain'
2021-05-09 22:02:48.465 WARN 14324 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-05-09 22:02:48.770 INFO 14324 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@4c2b8df7, org.springframework.security.web.context.SecurityContextPersistenceFilter@1bd97254, org.springframework.security.web.header.HeaderWriterFilter@5e91b051, org.springframework.security.web.authentication.logout.LogoutFilter@20e7ea20, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@4f5080ea, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@32b19d03, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@364c4ba9, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@7734ddb8, org.springframework.security.web.session.SessionManagementFilter@46199519, org.springframework.security.web.access.ExceptionTranslationFilter@3d5a6849, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@e00f822]
2021-05-09 22:02:48.860 INFO 14324 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-05-09 22:02:49.210 INFO 14324 --- [ main] o.k.i.pmml.PMMLImplementationsUtil : Using NEW implementation
2021-05-09 22:02:49.210 INFO 14324 --- [ main] o.k.i.pmml.PMMLImplementationsUtil : Using NEW implementation
2021-05-09 22:02:49.338 INFO 14324 --- [ main] com.arjuna.ats.arjuna : ARJUNA012170: TransactionStatusManager started on port 50890 and host 127.0.0.1 with service com.arjuna.ats.arjuna.recovery.ActionStatusService
2021-05-09 22:02:49.641 INFO 14324 --- [ main] o.k.s.s.a.KieServerAutoConfiguration : KieServer (id boot-kie-server (name KIE Server SpringBoot)) started initialization process
2021-05-09 22:02:49.770 INFO 14324 --- [ main] o.k.server.services.impl.KieServerImpl : Starting server in 'DEVELOPMENT' mode.
2021-05-09 22:02:49.773 INFO 14324 --- [ main] o.k.server.services.impl.KieServerImpl : Selected startup strategy ControllerBasedStartupStrategy - deploys kie containers given by controller ignoring locally defined
2021-05-09 22:02:49.774 INFO 14324 --- [ main] o.k.server.services.impl.KieServerImpl : Configured 'KieServerStateFileRepository' server state repository
2021-05-09 22:02:49.800 INFO 14324 --- [ main] o.k.server.services.impl.KieServerImpl : Server Default Extension has been successfully registered as server extension
2021-05-09 22:02:49.802 INFO 14324 --- [ main] o.k.server.services.impl.KieServerImpl : Drools KIE Server extension has been successfully registered as server extension
2021-05-09 22:02:49.819 INFO 14324 --- [ main] o.k.s.api.marshalling.MarshallerFactory : Marshaller extensions init
2021-05-09 22:02:49.830 INFO 14324 --- [ main] o.k.server.services.impl.KieServerImpl : jBPM KIE Server extension has been successfully registered as server extension
2021-05-09 22:02:49.832 INFO 14324 --- [ main] o.k.server.services.impl.KieServerImpl : Case-Mgmt KIE Server extension has been successfully registered as server extension
2021-05-09 22:02:49.920 INFO 14324 --- [ main] o.k.s.s.j.u.f.r.BootstrapFormRenderer : Boostrap Form renderer templates loaded successfully.
2021-05-09 22:02:49.924 INFO 14324 --- [ main] o.k.s.s.j.u.f.r.PatternflyFormRenderer : patternfly Form renderer templates loaded successfully.
2021-05-09 22:02:49.927 INFO 14324 --- [ main] o.k.s.s.j.u.f.r.PatternflyFormRenderer : workbench Form renderer templates loaded successfully.
2021-05-09 22:02:49.928 INFO 14324 --- [ main] o.k.server.services.impl.KieServerImpl : jBPM-UI KIE Server extension has been successfully registered as server extension
2021-05-09 22:02:49.929 INFO 14324 --- [ main] o.k.server.services.impl.KieServerImpl : DMN KIE Server extension has been successfully registered as server extension
2021-05-09 22:02:49.931 INFO 14324 --- [ main] o.k.server.services.impl.KieServerImpl : Scenario Simulation KIE Server extension has been successfully registered as server extension
2021-05-09 22:02:49.933 INFO 14324 --- [ main] o.k.s.s.impl.policy.PolicyManager : Registered KeepLatestContainerOnlyPolicy{interval=0 ms} policy under name KeepLatestOnly
2021-05-09 22:02:49.933 INFO 14324 --- [ main] o.k.s.s.impl.policy.PolicyManager : Policy manager started successfully, activated policies are []
2021-05-09 22:02:49.936 INFO 14324 --- [ main] o.k.s.services.impl.ContainerManager : About to install containers on kie server
KieServer{id='boot-kie-server'name='KIE Server SpringBoot'version='7.53.0.Final'location='http://localhost:8090/rest/server'}:
2021-05-09 22:02:49.941 INFO 14324 --- [ main] o.k.server.services.impl.KieServerImpl : KieServer boot-kie-server is ready to receive requests
2021-05-09 22:02:49.971 INFO 14324 --- [ main] o.k.s.s.a.KieServerAutoConfiguration : KieServer (id boot-kie-server) started successfully
2021-05-09 22:02:50.145 INFO 14324 --- [ main] org.apache.cxf.endpoint.ServerImpl : Setting the server's publish address to be /
2021-05-09 22:02:50.253 INFO 14324 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8090 (http) with context path ''
2021-05-09 22:02:50.262 INFO 14324 --- [ main] c.g.m.kie.BootJbpmKieServerApplication : Started BootJbpmKieServerApplication in 7.039 seconds (JVM running for 7.575)
package com.github.mnadeem.discount.model;
public class Sale {
private int quantity;
private String item;
private int discount;
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getItem() {
return item;
}
public void setItem(String item) {
this.item = item;
}
public int getDiscount() {
return discount;
}
public void setDiscount(int discount) {
this.discount = discount;
}
}
import org.kie.server.api.marshalling.MarshallingFormat;
import org.kie.server.api.model.KieContainerResource;
import org.kie.server.api.model.KieContainerStatus;
import org.kie.server.api.model.ReleaseId;
import org.kie.server.api.model.ServiceResponse;
import org.kie.server.client.KieServicesClient;
import org.kie.server.client.KieServicesConfiguration;
import org.kie.server.client.KieServicesFactory;
private static final String CONTAINER_ID = "my-deploy";
private static final String USER = "kieserver";
private static final String PASSWORD = "kieserver1!";
private static final String URL = "http://localhost:8090/rest/server";
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(URL, USER, PASSWORD, 60000);
config.setMarshallingFormat(MarshallingFormat.JSON);
KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
KieContainerResource kContainer = new KieContainerResource();
kContainer.setContainerId(CONTAINER_ID);
kContainer.setReleaseId(new ReleaseId("com.github.mnadeem", "drools-discount-kjar", "0.0.1-SNAPSHOT"));
ServiceResponse<KieContainerResource> resp = client.createContainer(CONTAINER_ID, kContainer);
KieContainerStatus status = resp.getResult().getStatus();
if (!KieContainerStatus.STARTED.equals(status)) {
throw new IllegalStateException();
}
2021-05-11 01:08:20.956 INFO 2648 --- [0.1-8090-exec-4] o.k.s.s.jbpm.JbpmKieServerExtension : Container my-deploy does not include processes, jBPM KIE Server extension skipped
2021-05-11 01:08:20.956 INFO 2648 --- [0.1-8090-exec-4] o.k.server.services.impl.KieServerImpl : Container my-deploy (for release id com.github.mnadeem:drools-discount-kjar:0.0.1-SNAPSHOT) successfully started
2021-05-11 01:08:20.958 WARN 2648 --- [0.1-8090-exec-4] o.k.s.s.i.c.DefaultRestControllerImpl : No controllers found to update to new status org.kie.server.api.model.KieServerStateInfo@6e6283d9
2021-05-13 04:34:37.167 INFO 7132 --- [ main] o.k.s.s.a.KieServerAutoConfiguration : KieServer (id boot-kie-server (name KIE Server SpringBoot)) started initialization process
2021-05-13 04:34:37.350 INFO 7132 --- [ main] o.k.server.services.impl.KieServerImpl : Starting server in 'DEVELOPMENT' mode.
2021-05-13 04:34:37.353 INFO 7132 --- [ main] o.k.server.services.impl.KieServerImpl : Selected startup strategy ControllerBasedStartupStrategy - deploys kie containers given by controller ignoring locally defined
2021-05-13 04:34:37.354 INFO 7132 --- [ main] o.k.server.services.impl.KieServerImpl : Configured 'KieServerStateFileRepository' server state repository
2021-05-13 04:34:37.362 INFO 7132 --- [ main] o.k.s.s.impl.storage.KieServerState : Added default controller located at http://localhost:8080/business-central/rest/controller
2021-05-13 04:34:37.373 INFO 7132 --- [ main] o.k.s.s.impl.storage.KieServerState : Added default controller located at http://localhost:8080/business-central/rest/controller
2021-05-13 04:34:37.380 INFO 7132 --- [ main] o.k.server.services.impl.KieServerImpl : Server Default Extension has been successfully registered as server extension
2021-05-13 04:34:37.381 INFO 7132 --- [ main] o.k.server.services.impl.KieServerImpl : Drools KIE Server extension has been successfully registered as server extension
2021-05-13 04:34:37.398 INFO 7132 --- [ main] o.k.s.api.marshalling.MarshallerFactory : Marshaller extensions init
2021-05-13 04:34:37.409 INFO 7132 --- [ main] o.k.server.services.impl.KieServerImpl : jBPM KIE Server extension has been successfully registered as server extension
2021-05-13 04:34:37.410 INFO 7132 --- [ main] o.k.server.services.impl.KieServerImpl : Case-Mgmt KIE Server extension has been successfully registered as server extension
2021-05-13 04:34:37.517 INFO 7132 --- [ main] o.k.s.s.j.u.f.r.BootstrapFormRenderer : Boostrap Form renderer templates loaded successfully.
2021-05-13 04:34:37.521 INFO 7132 --- [ main] o.k.s.s.j.u.f.r.PatternflyFormRenderer : patternfly Form renderer templates loaded successfully.
2021-05-13 04:34:37.524 INFO 7132 --- [ main] o.k.s.s.j.u.f.r.PatternflyFormRenderer : workbench Form renderer templates loaded successfully.
2021-05-13 04:34:37.525 INFO 7132 --- [ main] o.k.server.services.impl.KieServerImpl : jBPM-UI KIE Server extension has been successfully registered as server extension
2021-05-13 04:34:37.527 INFO 7132 --- [ main] o.k.server.services.impl.KieServerImpl : DMN KIE Server extension has been successfully registered as server extension
2021-05-13 04:34:37.529 INFO 7132 --- [ main] o.k.server.services.impl.KieServerImpl : Scenario Simulation KIE Server extension has been successfully registered as server extension
2021-05-13 04:34:37.532 INFO 7132 --- [ main] o.k.s.s.impl.policy.PolicyManager : Registered KeepLatestContainerOnlyPolicy{interval=0 ms} policy under name KeepLatestOnly
2021-05-13 04:34:37.532 INFO 7132 --- [ main] o.k.s.s.impl.policy.PolicyManager : Policy manager started successfully, activated policies are []
2021-05-13 04:34:37.535 WARN 7132 --- [ main] o.kie.server.common.KeyStoreHelperUtil : Unable to load key store. Using password from configuration
2021-05-13 04:34:38.409 INFO 7132 --- [ main] o.k.s.services.impl.ContainerManager : About to install containers on kie server
KieServer{id='boot-kie-server'name='KIE Server SpringBoot'version='7.53.0.Final'location='http://localhost:8090/rest/server'}:
2021-05-13 04:34:38.416 INFO 7132 --- [ main] o.k.server.services.impl.KieServerImpl : KieServer boot-kie-server is ready to receive requests
2021-05-13 04:34:38.456 INFO 7132 --- [ main] o.k.s.s.a.KieServerAutoConfiguration : KieServer (id boot-kie-server) started successfully
2021-05-13 04:34:38.671 INFO 7132 --- [ main] org.apache.cxf.endpoint.ServerImpl : Setting the server's publish address to be /
2021-05-13 04:34:38.835 INFO 7132 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8090 (http) with context path ''
2021-05-13 04:34:38.844 INFO 7132 --- [ main] c.g.m.kie.BootJbpmKieServerApplication : Started BootJbpmKieServerApplication in 8.409 seconds (JVM running for 8.929)
2021-05-13 04:34:39.160 INFO 7132 --- [0.1-8090-exec-1] o.k.s.a.m.xstream.XStreamMarshaller : XStreamMarshallerExtension implementation found: org.kie.server.services.jbpm.xstream.HibernateXStreamMarshallerExtension
2021-05-13 04:34:39.251 INFO 7132 --- [0.1-8090-exec-1] o.j.k.s.i.q.p.PersistDataSetListener : Data set jbpmExecutionErrorList updated in db storage
2021-05-13 04:34:39.252 INFO 7132 --- [0.1-8090-exec-1] o.j.k.s.impl.query.QueryServiceImpl : Registered jbpmExecutionErrorList query successfully
2021-05-13 04:34:39.349 INFO 7132 --- [0.1-8090-exec-2] o.j.k.s.i.q.p.PersistDataSetListener : Data set jbpmHumanTasks updated in db storage
2021-05-13 04:34:39.350 INFO 7132 --- [0.1-8090-exec-2] o.j.k.s.impl.query.QueryServiceImpl : Registered jbpmHumanTasks query successfully
2021-05-13 04:34:39.420 INFO 7132 --- [0.1-8090-exec-3] o.j.k.s.i.q.p.PersistDataSetListener : Data set jbpmHumanTasksWithAdmin updated in db storage
2021-05-13 04:34:39.422 INFO 7132 --- [0.1-8090-exec-3] o.j.k.s.impl.query.QueryServiceImpl : Registered jbpmHumanTasksWithAdmin query successfully
2021-05-13 04:34:39.496 INFO 7132 --- [0.1-8090-exec-4] o.j.k.s.i.q.p.PersistDataSetListener : Data set processesMonitoring updated in db storage
2021-05-13 04:34:39.496 INFO 7132 --- [0.1-8090-exec-4] o.j.k.s.impl.query.QueryServiceImpl : Registered processesMonitoring query successfully
2021-05-13 04:34:39.567 INFO 7132 --- [0.1-8090-exec-5] o.j.k.s.i.q.p.PersistDataSetListener : Data set jbpmRequestList updated in db storage
2021-05-13 04:34:39.567 INFO 7132 --- [0.1-8090-exec-5] o.j.k.s.impl.query.QueryServiceImpl : Registered jbpmRequestList query successfully
2021-05-13 04:34:39.636 INFO 7132 --- [0.1-8090-exec-6] o.j.k.s.i.q.p.PersistDataSetListener : Data set tasksMonitoring updated in db storage
2021-05-13 04:34:39.638 INFO 7132 --- [0.1-8090-exec-6] o.j.k.s.impl.query.QueryServiceImpl : Registered tasksMonitoring query successfully
2021-05-13 04:34:39.708 INFO 7132 --- [0.1-8090-exec-7] o.j.k.s.i.q.p.PersistDataSetListener : Data set jbpmHumanTasksWithUser updated in db storage
2021-05-13 04:34:39.708 INFO 7132 --- [0.1-8090-exec-7] o.j.k.s.impl.query.QueryServiceImpl : Registered jbpmHumanTasksWithUser query successfully
2021-05-13 04:34:39.780 INFO 7132 --- [0.1-8090-exec-8] o.j.k.s.i.q.p.PersistDataSetListener : Data set jbpmProcessInstancesWithVariables updated in db storage
2021-05-13 04:34:39.780 INFO 7132 --- [0.1-8090-exec-8] o.j.k.s.impl.query.QueryServiceImpl : Registered jbpmProcessInstancesWithVariables query successfully
2021-05-13 04:34:39.849 INFO 7132 --- [0.1-8090-exec-9] o.j.k.s.i.q.p.PersistDataSetListener : Data set jbpmProcessInstances updated in db storage
2021-05-13 04:34:39.850 INFO 7132 --- [0.1-8090-exec-9] o.j.k.s.impl.query.QueryServiceImpl : Registered jbpmProcessInstances query successfully
2021-05-13 04:34:39.919 INFO 7132 --- [.1-8090-exec-10] o.j.k.s.i.q.p.PersistDataSetListener : Data set jbpmHumanTasksWithVariables updated in db storage
2021-05-13 04:34:39.919 INFO 7132 --- [.1-8090-exec-10] o.j.k.s.impl.query.QueryServiceImpl : Registered jbpmHumanTasksWithVariables query successfully
2021-05-13 04:34:39.988 INFO 7132 --- [0.1-8090-exec-1] o.j.k.s.i.q.p.PersistDataSetListener : Data set jbpmProcessInstanceLogs updated in db storage
2021-05-13 04:34:39.988 INFO 7132 --- [0.1-8090-exec-1] o.j.k.s.impl.query.QueryServiceImpl : Registered jbpmProcessInstanceLogs query successfully
Contains, org.kie:kie-api, org.drools:drools-compiler, jbpm and spring related dependencies
org.kie:kie-api
Contains all the public interfaces exposed by the KIE Platform, which is composed by Drools, jBPM, and OptaPlanner
org.drools:drools-compiler
Contains the algorithm to translate the rules written in different resources (text files, spreadsheets, your own types, and so on) to executable rules. This artifact is required only because we are compiling our rules in the project. It is possible to separate the rules compilation from the rules execution to remove this dependency from our project; however, for the sake of simplicity, we are going to compile our rules in the same project.
public class Sale {
private int quantity;
private String item;
private int discount;
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getItem() {
return item;
}
public void setItem(String item) {
this.item = item;
}
public int getDiscount() {
return discount;
}
public void setDiscount(int discount) {
this.discount = discount;
}
}
discount.drl
package rules;
import com.github.mnadeem.discount.model.Sale;
rule "DiscountForCarSale"
when
thisSale : Sale (quantity >= 5 , item == "Car");
then
thisSale.setDiscount(10);
end;
rule "DiscountForBikeSale"
when
thisSale : Sale (quantity >= 10 , item == "Bike");
then
thisSale.setDiscount(15);
end;
DiscountService
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.stereotype.Service;
import com.github.mnadeem.discount.model.Sale;
@Service
public class DiscountService {
private final KieContainer kieContainer;
public DiscountService(KieContainer kieContainer) {
this.kieContainer = kieContainer;
}
public void applyDiscount(Sale sale) {
KieSession kieSession = kieContainer.newKieSession();
kieSession.insert(sale);
kieSession.fireAllRules();
kieSession.dispose();
}
}
DiscountController
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.github.mnadeem.discount.model.Sale;
@RestController
public class DiscountController {
private DiscountService discountService;
public DiscountController(DiscountService service) {
this.discountService = service;
}
@PostMapping("/discount")
private Sale getDiscountPercent(@RequestBody Sale sale) {
this.discountService.applyDiscount(sale);
return sale;
}
}
Start the Application
2021-05-09 00:19:41.127 INFO 624 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-05-09 00:19:41.288 INFO 624 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-05-09 00:19:41.298 INFO 624 --- [ main] c.g.m.BootDroolsEmbeddedApplication : Started BootDroolsEmbeddedApplication in 2.14 seconds (JVM running for 2.486)
2021-05-09 00:19:42.753 INFO 624 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-05-09 00:19:42.753 INFO 624 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-05-09 00:19:42.754 INFO 624 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2021-05-09 00:19:42.816 INFO 624 --- [nio-8080-exec-1] o.d.c.kie.builder.impl.KieContainerImpl : Start creation of KieBase: defaultKieBase
2021-05-09 00:19:42.870 INFO 624 --- [nio-8080-exec-1] o.d.c.kie.builder.impl.KieContainerImpl : End creation of KieBase: defaultKieBase
Execute Rule
localhost:8080/discount
{
"quantity": 11,
"item": "Car"
}
Junit Test Cases
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.github.mnadeem.discount.DiscountService;
import com.github.mnadeem.discount.model.Sale;
@SpringBootTest
class BootDroolsEmbeddedApplicationTests {
@Autowired
private DiscountService discountService;
@Test
void discountOnCarWithQuantityMoreThan5ShouldBe10() {
Sale sale = new Sale();
sale.setItem("Car");
sale.setQuantity(11);
discountService.applyDiscount(sale);
assertEquals(10, sale.getDiscount());
}
@Test
void discountOnBikeWithQuantityMoreThan10ShouldBe15() {
Sale sale = new Sale();
sale.setItem("Bike");
sale.setQuantity(11);
discountService.applyDiscount(sale);
assertEquals(15, sale.getDiscount());
}
}
KIE Components
Kie = Knowledge is Everything
Component
Notes
KieServices
KieServices class that gives us access to all these other concepts by providing a registry of services where we can find helpers for different purposes. Using the KieServices, we can access a number of factories, services, and utility methods used along with Rule Engine instances.
KieServices ks = KieServices.Factory.get();
KieContainer
defines the scope of the rules that will be used to create new instances of the Rule Engine. A KieContainer can host a KieModule and its dependencies.
Internally, the KieContainer has references to all the business assets (rules, processes, spreadsheets, PMML documents, and so on) that will be loaded when we create new Rule Engine instances.
KieModule
In Drools 6, everything is created around KieModules. Each KieModule contains business assets (business rules, business processes, decision tables, and so on) related to a certain area or domain.
A KieModule is a standard Java-Maven project containing the rules, business process and other assets among its resources. A special file called kmodule.xml (in the METAINF/ directory) that defines the internal configuration about how to group and consume these particular assets must also be present in it.
KieBase
A KieBase represents a compiled version of a set of assets
KieSession
A KieSession represents an instance of the rule engine containing the rules in the KieBase. For this reason, it makes sense to have multiple sessions defined with different configurations for the same KieBase.
KieBase and KieSession, we can define the granularity of how the rules will need to be loaded.
KIE Server
The KIE Server is a standalone execution server for rules.
KIE Server is a modular, standalone server component that can be used to instantiate and execute rules and processes. It exposes this functionality via REST, JMS and Java interfaces to client application. It also provides seamless integration with the Business Central.
The main purpose of the Kie Server is to be a runtime environment for Kie components.
Each instance of the Kie Server can create and use many Kie Containers, and its functionality can be extended through the use of something called Kie Server Extensions.
Also, the Kie Server allows us to provide Kie Server Controllers. These are endpoints which will expose Kie Server functionalities. In a sense, they will be the front-end of our Kie Server.
A platforms that allow business experts to access rule writing in a more user-friendly way. These platforms are a composition of user-friendly editors, with versioning and publishing capabilities, called Business Rule Management Systems (BRMS)
The Drools workbench (Business Central) is built with the UberFire framework and uses the Guvnor plugin. Drools provides an additional rich set of plugins for rule authoring metaphors.
Kie Workbench is a web environment where we can create and test all sorts of Kie assets, such as rules, processes, and data models. It is a very useful tool to include business people with little technical knowledge of the specifics of implementation into the development cycle, because it provides a user-friendly environment for rule writing.
KIE Projects
Other Options
KieModule In Classpath
External Repository
Drools getting our rules from an external repository
Alternatively, we can directly build our Kie Container objects based on a specific version of our code. If done this way, we can use a KieScanner to let our runtime know it should monitor the repository for possible future changes, so that the runtime can change versions without even having to restart: