SlideShare a Scribd company logo
Turning Maven into a High scalable,
resource efficient,
cloud ready microservice
Oracle Code One 24 Oct 2018
Alex Porcelli
Business Automation Architect
Max Dessì
Senior Software Engineer
Speakers
Massimiliano Dessì has more than 18
years of experience in programming.
Co-founder of Java User Group Sardegna,
Manager of Google Developer Group
Sardegna,
Author of Spring 2.5 AOP (Packt)
He works as a Senior Software Engineer
for Red Hat in the BSIG
(Business Systems and Intelligence
Group) , on KIE projects (Knowledge Is
Everything),
he lives in Cagliari, Sardinia, Europe.
Alex Porcelli is Principal Software
Engineer at JBoss by Red Hat, proud
member of the architecture group behind
the Drools, jBPM and Business Central
platform, and co-founder of AppFormer.
Professional developer since 1996, has
been working exclusively on Open Source
projects for almost a decade. Since joined
Red Hat he has been focusing on web
enabled of the Drools&jBPM platforms
redefining all web tooling. Porcelli is also a
frequent speaker in tech events like QCon,
JavaOne, CodeOne, Red Hat Summit and
DevNation.
QUICK INTRO TO BUSINESS CENTRAL
● KJAR
○ What is a KJAR
● Maven based packaging model
○ kie-maven-plugin
○ kie-takari-plugin
4
BUSINESS CENTRAL
ALL ABOUT BUSINESS PROCESS AND RULES
<groupId>com.example</groupId>
<artifactId>user-project</artifactId>
<packaging>kjar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>7.10.0.Final</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
5
● Multiple Personas
● Design
○ Practitioners & Devs
○ Modeling tools
○ Hides Tech details (ie. POM)
○ Git backed storage
○ Editors need access to project
classloader for autocomplete
■ A build is needed on every
user I/O action
BUSINESS CENTRAL
ALL ABOUT BUSINESS PROCESS AND RULES
6
BUSINESS CENTRAL
DESIGN ENVIRONMENT
BUSINESS CENTRAL REQUIREMENTS
The GOOD
● Builds Incrementally
● Multi-thread support
● Uses POM.xml as input
● Just works
○ In production for ~6y
8
CURRENT IN-HOUSE BUILD SYSTEM
The BAD
● Stateful
● Hard to scale out
● Hard to work on CI/CD
● Don’t respect Maven semantics
○ Problems from customers
(RFE)
9
REQUEST:
REPLACE CURRENT BUILD WITH MAVEN
REQUIREMENTS GATHERING
10
11
INCREMENTAL COMPILATION
REQUIREMENT
Business Central user shouldn’t have to wait for a full compilation if the user has just
changed a POJO or a Business Rule.
Most of Business Central rich editors provide some level of autocomplete that is based on
the project content (Rules, Processes, POJOs, Configs, etc.).
On every user I/O action, it needs trigger an incremental build.
12
RESPECT/PRESERVE USER’S POM
Business Central users shouldn’t require to change their POM’s if they already work outside
Business central.
The system should be able to adapt on the fly User’s POM in order to make changed needed
that result in a incremental build.
REQUIREMENT
13
LOW LATENCY AND MEMORY FOOTPRINT
REQUIREMENT
Business Central is a web based tool, that has to support multiple concurrent users.
Maven is designed as stateless, however its bootstrap is quite heavy (multiple containers
have to be initialized, like plexus/sisu/guice).
Business Central has different interactions that relies on the build system: Incremental for
every user I/O operation, JUnit/Rules/Process execution, Packaging and Deployment.
Every use case, requires some configuration/tweak of Maven execution.
14
ADJUSTABLE FOR DIFFERENT USE CASES
REQUIREMENT
Business Central should enable multiple users interact with projects, including collaboration
in the same project.
Everyone that had to check a Maven output log of a build with a “-T 2” knows that logs are
not isolated per thread.
Maven Embedder can’t even execute correctly more than 4 threads at same time
(parameter parser get lost).
15
MULTI-THREAD
REQUIREMENT
Business Central users may work in the same project in a isolated way (forked).
Avoid users step on other toes when consuming and producing artifacts (KJARs).
16
MULTI-USER/MULTI-M2REPO
REQUIREMENT
The build system should be consumed by Business Central “as a Service” and should be
developed as a cloud native component.
Builds could be executed co-located (within Business Central, suitable for incremental
compilation) or executed remotely.
It’s expect that on heavy load the build system be auto-scaled by cloud infrastructure.
17
µService/Cloud Native
REQUIREMENT
Business Central should be able to keep working even if a malicious code is executed by a
Business Rule or Process (ie. System.exit).
For efficient user interaction incremental compilation should be, as much as possible, be
executed in the same JVM. However it’s necessary some isolation of JUnit/Rules/Process
execution to avoid shut down the Application Server using System.exit.
18
In & Off-Process
REQUIREMENT
The kie-maven-plugin and kie-takari-plugin create some in-memory objects that are super
heavy to create (basically all metadata information for all rules and process in a
pre-compiled way).
Original Maven API basically returns only two values: FAIL or SUCCESS.
19
RETURN RICH DATA STRUCTURES
REQUIREMENT
Compile, Packaging, JUnit Runs… or any Maven execution can take some time (like
download the internet!), and we should not block Caller to wait for the completion of those
heavy tasks.
Useful also for remote execution.
20
ASYNC API
REQUIREMENT
21
DETAILED REQUIREMENT LIST
The devil is in the details
● Incremental compilation
● Respect/Preserve User’s POM
● Low latency and memory footprint
● Adjustable for Different Use Cases
○ Compilation, JUnit Run, etc
● Multi-thread
● Multi-user
○ Multi M2 repos
● µService/Cloud Native
○ Local and Remote executions
● Embedded & Off-process mode
● Return rich data structures
○ Beyond Fail/Success
○ Collect data from PlugIn’s
● Async API
MAVEN AS A SERVICE
FEATURES
23
THE SOLUTION
Provide an “enhanced compiler” with request-response behavior as
simple as possible in its use and configuration and rich in terms of
objects in the response compared to “plain” Maven
24
● Maven repo per request
● Project Path
● Maven CLI arguments
● Settings file
● Unique Compilation ID
REQUEST
interface CompilationRequest {
AFCliRequest getKieCliRequest();
WorkspaceCompilationInfo getInfo();
String getMavenRepo();
String[] getOriginalArgs();
Map<String, Object> getMap();
String getRequestUUID();
Boolean skipAutoSourceUpdate();
Boolean skipProjectDependenciesCreationList();
Boolean getRestoreOverride();
}
25
● Result of the build
● In Memory Log
● Dependency List
● Target folder content
RESPONSE
interface CompilationResponse {
Boolean isSuccessful();
List<String> getMavenOutput();
Optional<Path> getWorkingDir();
List<String> getDependencies();
List<URI> getDependenciesAsURI();
List<URL> getDependenciesAsURL();
List<String> getTargetContent();
List<URI> getTargetContentAsURI();
List<URL> getTargetContentAsURL();
}
26
● Drools live objects extracted from
the Maven plugin
● Drools live objects generated on the
fly (no .class file)
● Classloaders contents
KIE RESPONSE EXTENSION
interface KieCompilationResponse
extends CompilationResponse {
Optional<KieModuleMetaInfo> getKieModuleMetaInfo();
Optional<KieModule> getKieModule();
Map<String, byte[]> getProjectClassLoaderStore();
Set<String> getEventTypeClasses();
}
We add objects to the Maven result (a
simple int) and we use a pipeline of
decorators to add behaviours before and
after compilation
27
COMPILER
interface AFCompiler<T extends CompilationResponse> {
T compile(final CompilationRequest req);
T compile(final CompilationRequest req,
final Map<Path, InputStream> override);
Boolean cleanInternalCache();
}
PIPELINE: CHAIN OF DECORATORS
● Static factory for common use cases
● Configurable per object
● Possible to provide your own
decorator
28
MAVEN API VERY RESTRICT
The first problem is how to open the
“sealed” Maven API, we change the use of
Plexus/Sisu we can reuse the same IoC
container per project saving a huge
amount of time, because the major part of
the time in a Maven startup is the creation
of this container
29
CLASSLOADERS
30
Maven use classworlds to manage the various classloaders used for its tasks
● System Classloader
● Core Classloader
● Plugin Classloaders
● Custom Classloaders
https://maven.apache.org/guides/mini/guide-maven-classloading.html
CLASSLOADERS
31
If we want read an object inside the plugin
and export it to the client code we have to
cross the barriers of those classloaders.
● ReusableAFMavenCli
● BuildMojo
● BaseMavenCompiler
IN MEMORY PLUGINS
32
A cool side effects when you cross the
barriers of the classloaders is the option to
turn the plugins impl from FS to in
memory.
INCREMENTAL COMPILER
33
To spent less time in front of a Maven build
we change on the fly the pom to add the
Takari compiler in every module of the
project tied with the compiler
POM PROCESSOR
34
The Compiler is aware
of the plugins in the POM
It changes on the fly
the Pom turning off the Default Compiler
and adds Takari and the Kie Plugin
ASYNC API
35
interface AFCompilerService {
CompletableFuture<KieCompilationResponse> build(Path projectPath, String mavenRepo);
CompletableFuture<KieCompilationResponse> build(Path projectPath, String mavenRepo,
Map<Path, InputStream> override);
CompletableFuture<KieCompilationResponse> build(Path projectPath, String mavenRepo,
Boolean skipPrjDependenciesCreationList);
CompletableFuture<KieCompilationResponse> buildAndInstall(Path projectPath, String mavenRepo);
CompletableFuture<KieCompilationResponse> buildAndInstall(Path projectPath, String mavenRepo,
Boolean skipPrjDependenciesCreationList);
CompletableFuture<KieCompilationResponse> buildSpecialized(Path projectPath, String mavenRepo, String[] args);
CompletableFuture<KieCompilationResponse> buildSpecialized(Path projectPath,
String mavenRepo,
String[] args,
Boolean skipPrjDependenciesCreationList);
}
COMPILER SERVICE
36
We could use the compiler core
to enable a compiler service
enabling local Maven executors
or remote Maven executors
on other nodes/pods/containers/VMs
COMPILER SERVICE
37
We could demand a build to a remote
node/pod/container/vm
and reads a remote File System
because
the core compiler
can use use a
JGITCompilerBeforeDecorator
LOCAL/REMOTE EXECUTORS
38
The compiler service need to know if the
current “machine” owns enough resources
to run a local executors or if is better to
ask to a remote executor to satisfy the
build.
To invoke a remote executors It needs to
know the address to reach the chosen
instance.
REST ENDPOINT
39
@Path("/build/maven/")
@RequestScoped
public class MavenRestHandler extends Application {
@POST
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public void postAsync(@Suspended AsyncResponse ar,
@HeaderParam("project") String projectRepo,
@HeaderParam("mavenrepo") String mavenRepo) throws Exception {
CompletableFuture<KieCompilationResponse> response = compilerService.build(projectRepo, mavenRepo);
response.whenCompleteAsync((kieCompilationResponse, throwable) -> {
if (throwable != null) {
logger.error(throwable.getMessage());
ar.resume(Response.serverError().build());
} else {
byte[] bytes = RestUtils.serialize(new DefaultHttpCompilationResponse(kieCompilationResponse));
ar.resume(Response.ok(bytes).build());
}
});
}
}
Resources
40
https://github.com/desmax74 https://github.com/porcelli
https://twitter.com/desmax74 https://twitter.com/porcelli
https://pt.slideshare.net/alexandre_porcelli/https://www.slideshare.net/desmax74
THANK YOU
plus.google.com/+RedHat
linkedin.com/company/red-hat
youtube.com/user/RedHatVideos
facebook.com/redhatinc
twitter.com/RedHat

More Related Content

ODP
GlassFish v3 - Architecture
PDF
Glassfish An Introduction
PPTX
Micronaut: A new way to build microservices
PDF
JPQL/ JPA Activity 1
 
PDF
Project Fuji/OpenESB Aquarium Paris
PDF
Domino OSGi Development
PPTX
Ausoug glassfish perth
PPTX
BP207 - Meet the Java Application Server You Already Own – IBM Domino
GlassFish v3 - Architecture
Glassfish An Introduction
Micronaut: A new way to build microservices
JPQL/ JPA Activity 1
 
Project Fuji/OpenESB Aquarium Paris
Domino OSGi Development
Ausoug glassfish perth
BP207 - Meet the Java Application Server You Already Own – IBM Domino

What's hot (20)

PDF
GlassFish v3 Prelude Aquarium Paris
PDF
GlassFish Server 3.1: Deploying your Java EE 6 Applications
PDF
OSGi and Java EE in GlassFish - Tech Days 2010 India
PDF
Mavenizing your Liferay project
PPTX
Cloud Foundry a Developer's Perspective
PPTX
An XPager's Guide to Process Server-Side Jobs on Domino
PPTX
GlassFish in Production Environments
PDF
Peering Inside the Black Box: A Case for Observability
ODP
Java 9 modularity
PDF
Nuxeo WebEngine and GlassFish v3
PPTX
Modular Java
PPT
Developing modular Java applications
PPTX
Java modularization
PDF
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
PDF
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...
PDF
Serverless Java Challenges & Triumphs
PPTX
Java Modularity with OSGi
PPTX
Migrating From Applets to Java Desktop Apps in JavaFX
PDF
Deployment Best Practices on WebLogic Server (DOAG IMC Summit 2013)
PDF
JavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap – Duško Vukmanović
GlassFish v3 Prelude Aquarium Paris
GlassFish Server 3.1: Deploying your Java EE 6 Applications
OSGi and Java EE in GlassFish - Tech Days 2010 India
Mavenizing your Liferay project
Cloud Foundry a Developer's Perspective
An XPager's Guide to Process Server-Side Jobs on Domino
GlassFish in Production Environments
Peering Inside the Black Box: A Case for Observability
Java 9 modularity
Nuxeo WebEngine and GlassFish v3
Modular Java
Developing modular Java applications
Java modularization
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...
Serverless Java Challenges & Triumphs
Java Modularity with OSGi
Migrating From Applets to Java Desktop Apps in JavaFX
Deployment Best Practices on WebLogic Server (DOAG IMC Summit 2013)
JavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap – Duško Vukmanović
Ad

Similar to Code One 2018 maven (20)

PDF
MuleSoft Surat Virtual Meetup#15 - Caching Scope, Caching Strategy and Jenkin...
PDF
Agile integration: Decomposing the monolith
PDF
MuleSoft Surat Virtual Meetup#35 - Setting up MuleSoft Runtime and Anypoint C...
PPTX
How to build a Oracle cloud adapter SOA, Integration & API's
PPTX
How to build a cloud adapter
PDF
Apache Mesos Overview and Integration
PPTX
MuleSoft Meetup Adelaide 7th April 2021
PPT
Java Development on Bluemix
PDF
OSDC 2018 | Three years running containers with Kubernetes in Production by T...
PPTX
Anypoint Tools and MuleSoft Automation (DRAFT).pptx
PPTX
MuleSoft Meetup #9 - Anypoint Tools and MuleSoft Automation (FINAL).pptx
PDF
API Microservices with Node.js and Docker
PPTX
Nyc mule soft_meetup_13_march_2021
PDF
Operator Framework Overview
PDF
Containerize, PaaS, or Go Serverless!?
PDF
Pivotal Cloud Foundry 2.6: A First Look
PPTX
Meet Magento Spain 2019 - Our Experience with Magento Cloud
PDF
MuleSoft Surat Virtual Meetup#16 - Anypoint Deployment Option, API and Operat...
DOCX
198970820 p-oooooooooo
PDF
OSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius Schumacher
MuleSoft Surat Virtual Meetup#15 - Caching Scope, Caching Strategy and Jenkin...
Agile integration: Decomposing the monolith
MuleSoft Surat Virtual Meetup#35 - Setting up MuleSoft Runtime and Anypoint C...
How to build a Oracle cloud adapter SOA, Integration & API's
How to build a cloud adapter
Apache Mesos Overview and Integration
MuleSoft Meetup Adelaide 7th April 2021
Java Development on Bluemix
OSDC 2018 | Three years running containers with Kubernetes in Production by T...
Anypoint Tools and MuleSoft Automation (DRAFT).pptx
MuleSoft Meetup #9 - Anypoint Tools and MuleSoft Automation (FINAL).pptx
API Microservices with Node.js and Docker
Nyc mule soft_meetup_13_march_2021
Operator Framework Overview
Containerize, PaaS, or Go Serverless!?
Pivotal Cloud Foundry 2.6: A First Look
Meet Magento Spain 2019 - Our Experience with Magento Cloud
MuleSoft Surat Virtual Meetup#16 - Anypoint Deployment Option, API and Operat...
198970820 p-oooooooooo
OSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius Schumacher
Ad

More from Massimiliano Dessì (20)

PDF
When Old Meets New: Turning Maven into a High Scalable, Resource Efficient, C...
PDF
Hacking Maven Linux day 2017
PDF
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
PDF
Dessi docker kubernetes paas cloud
PDF
Docker dDessi november 2015
PDF
Docker linuxday 2015
PDF
Openshift linuxday 2014
PDF
Web Marketing Training 2014 Community Online
PDF
Vert.X like Node.js but polyglot and reactive on JVM
PDF
Reactive applications Linux Day 2013
PDF
Scala Italy 2013 extended Scalatra vs Spring MVC
PDF
Codemotion 2013 scalatra_play_spray
ODP
Why we cannot ignore functional programming
PDF
Scala linux day 2012
PDF
Three languages in thirty minutes
PDF
MongoDB dessi-codemotion
PDF
MongoDB Webtech conference 2010
PDF
PDF
Spring Roo Internals Javaday IV
PDF
Spring Roo JaxItalia09
When Old Meets New: Turning Maven into a High Scalable, Resource Efficient, C...
Hacking Maven Linux day 2017
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
Dessi docker kubernetes paas cloud
Docker dDessi november 2015
Docker linuxday 2015
Openshift linuxday 2014
Web Marketing Training 2014 Community Online
Vert.X like Node.js but polyglot and reactive on JVM
Reactive applications Linux Day 2013
Scala Italy 2013 extended Scalatra vs Spring MVC
Codemotion 2013 scalatra_play_spray
Why we cannot ignore functional programming
Scala linux day 2012
Three languages in thirty minutes
MongoDB dessi-codemotion
MongoDB Webtech conference 2010
Spring Roo Internals Javaday IV
Spring Roo JaxItalia09

Recently uploaded (20)

PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
System and Network Administraation Chapter 3
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
top salesforce developer skills in 2025.pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Digital Strategies for Manufacturing Companies
PPTX
history of c programming in notes for students .pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
AI in Product Development-omnex systems
PPTX
Essential Infomation Tech presentation.pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Nekopoi APK 2025 free lastest update
Odoo POS Development Services by CandidRoot Solutions
How to Choose the Right IT Partner for Your Business in Malaysia
System and Network Administraation Chapter 3
Design an Analysis of Algorithms I-SECS-1021-03
top salesforce developer skills in 2025.pdf
ai tools demonstartion for schools and inter college
Softaken Excel to vCard Converter Software.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
Digital Strategies for Manufacturing Companies
history of c programming in notes for students .pptx
Design an Analysis of Algorithms II-SECS-1021-03
AI in Product Development-omnex systems
Essential Infomation Tech presentation.pptx
How Creative Agencies Leverage Project Management Software.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Adobe Illustrator 28.6 Crack My Vision of Vector Design
How to Migrate SBCGlobal Email to Yahoo Easily
Understanding Forklifts - TECH EHS Solution
Nekopoi APK 2025 free lastest update

Code One 2018 maven

  • 1. Turning Maven into a High scalable, resource efficient, cloud ready microservice Oracle Code One 24 Oct 2018 Alex Porcelli Business Automation Architect Max Dessì Senior Software Engineer
  • 2. Speakers Massimiliano Dessì has more than 18 years of experience in programming. Co-founder of Java User Group Sardegna, Manager of Google Developer Group Sardegna, Author of Spring 2.5 AOP (Packt) He works as a Senior Software Engineer for Red Hat in the BSIG (Business Systems and Intelligence Group) , on KIE projects (Knowledge Is Everything), he lives in Cagliari, Sardinia, Europe. Alex Porcelli is Principal Software Engineer at JBoss by Red Hat, proud member of the architecture group behind the Drools, jBPM and Business Central platform, and co-founder of AppFormer. Professional developer since 1996, has been working exclusively on Open Source projects for almost a decade. Since joined Red Hat he has been focusing on web enabled of the Drools&jBPM platforms redefining all web tooling. Porcelli is also a frequent speaker in tech events like QCon, JavaOne, CodeOne, Red Hat Summit and DevNation.
  • 3. QUICK INTRO TO BUSINESS CENTRAL
  • 4. ● KJAR ○ What is a KJAR ● Maven based packaging model ○ kie-maven-plugin ○ kie-takari-plugin 4 BUSINESS CENTRAL ALL ABOUT BUSINESS PROCESS AND RULES <groupId>com.example</groupId> <artifactId>user-project</artifactId> <packaging>kjar</packaging> <build> <plugins> <plugin> <groupId>org.kie</groupId> <artifactId>kie-maven-plugin</artifactId> <version>7.10.0.Final</version> <extensions>true</extensions> </plugin> </plugins> </build>
  • 5. 5 ● Multiple Personas ● Design ○ Practitioners & Devs ○ Modeling tools ○ Hides Tech details (ie. POM) ○ Git backed storage ○ Editors need access to project classloader for autocomplete ■ A build is needed on every user I/O action BUSINESS CENTRAL ALL ABOUT BUSINESS PROCESS AND RULES
  • 8. The GOOD ● Builds Incrementally ● Multi-thread support ● Uses POM.xml as input ● Just works ○ In production for ~6y 8 CURRENT IN-HOUSE BUILD SYSTEM The BAD ● Stateful ● Hard to scale out ● Hard to work on CI/CD ● Don’t respect Maven semantics ○ Problems from customers (RFE)
  • 11. 11 INCREMENTAL COMPILATION REQUIREMENT Business Central user shouldn’t have to wait for a full compilation if the user has just changed a POJO or a Business Rule. Most of Business Central rich editors provide some level of autocomplete that is based on the project content (Rules, Processes, POJOs, Configs, etc.). On every user I/O action, it needs trigger an incremental build.
  • 12. 12 RESPECT/PRESERVE USER’S POM Business Central users shouldn’t require to change their POM’s if they already work outside Business central. The system should be able to adapt on the fly User’s POM in order to make changed needed that result in a incremental build. REQUIREMENT
  • 13. 13 LOW LATENCY AND MEMORY FOOTPRINT REQUIREMENT Business Central is a web based tool, that has to support multiple concurrent users. Maven is designed as stateless, however its bootstrap is quite heavy (multiple containers have to be initialized, like plexus/sisu/guice).
  • 14. Business Central has different interactions that relies on the build system: Incremental for every user I/O operation, JUnit/Rules/Process execution, Packaging and Deployment. Every use case, requires some configuration/tweak of Maven execution. 14 ADJUSTABLE FOR DIFFERENT USE CASES REQUIREMENT
  • 15. Business Central should enable multiple users interact with projects, including collaboration in the same project. Everyone that had to check a Maven output log of a build with a “-T 2” knows that logs are not isolated per thread. Maven Embedder can’t even execute correctly more than 4 threads at same time (parameter parser get lost). 15 MULTI-THREAD REQUIREMENT
  • 16. Business Central users may work in the same project in a isolated way (forked). Avoid users step on other toes when consuming and producing artifacts (KJARs). 16 MULTI-USER/MULTI-M2REPO REQUIREMENT
  • 17. The build system should be consumed by Business Central “as a Service” and should be developed as a cloud native component. Builds could be executed co-located (within Business Central, suitable for incremental compilation) or executed remotely. It’s expect that on heavy load the build system be auto-scaled by cloud infrastructure. 17 µService/Cloud Native REQUIREMENT
  • 18. Business Central should be able to keep working even if a malicious code is executed by a Business Rule or Process (ie. System.exit). For efficient user interaction incremental compilation should be, as much as possible, be executed in the same JVM. However it’s necessary some isolation of JUnit/Rules/Process execution to avoid shut down the Application Server using System.exit. 18 In & Off-Process REQUIREMENT
  • 19. The kie-maven-plugin and kie-takari-plugin create some in-memory objects that are super heavy to create (basically all metadata information for all rules and process in a pre-compiled way). Original Maven API basically returns only two values: FAIL or SUCCESS. 19 RETURN RICH DATA STRUCTURES REQUIREMENT
  • 20. Compile, Packaging, JUnit Runs… or any Maven execution can take some time (like download the internet!), and we should not block Caller to wait for the completion of those heavy tasks. Useful also for remote execution. 20 ASYNC API REQUIREMENT
  • 21. 21 DETAILED REQUIREMENT LIST The devil is in the details ● Incremental compilation ● Respect/Preserve User’s POM ● Low latency and memory footprint ● Adjustable for Different Use Cases ○ Compilation, JUnit Run, etc ● Multi-thread ● Multi-user ○ Multi M2 repos ● µService/Cloud Native ○ Local and Remote executions ● Embedded & Off-process mode ● Return rich data structures ○ Beyond Fail/Success ○ Collect data from PlugIn’s ● Async API
  • 22. MAVEN AS A SERVICE FEATURES
  • 23. 23 THE SOLUTION Provide an “enhanced compiler” with request-response behavior as simple as possible in its use and configuration and rich in terms of objects in the response compared to “plain” Maven
  • 24. 24 ● Maven repo per request ● Project Path ● Maven CLI arguments ● Settings file ● Unique Compilation ID REQUEST interface CompilationRequest { AFCliRequest getKieCliRequest(); WorkspaceCompilationInfo getInfo(); String getMavenRepo(); String[] getOriginalArgs(); Map<String, Object> getMap(); String getRequestUUID(); Boolean skipAutoSourceUpdate(); Boolean skipProjectDependenciesCreationList(); Boolean getRestoreOverride(); }
  • 25. 25 ● Result of the build ● In Memory Log ● Dependency List ● Target folder content RESPONSE interface CompilationResponse { Boolean isSuccessful(); List<String> getMavenOutput(); Optional<Path> getWorkingDir(); List<String> getDependencies(); List<URI> getDependenciesAsURI(); List<URL> getDependenciesAsURL(); List<String> getTargetContent(); List<URI> getTargetContentAsURI(); List<URL> getTargetContentAsURL(); }
  • 26. 26 ● Drools live objects extracted from the Maven plugin ● Drools live objects generated on the fly (no .class file) ● Classloaders contents KIE RESPONSE EXTENSION interface KieCompilationResponse extends CompilationResponse { Optional<KieModuleMetaInfo> getKieModuleMetaInfo(); Optional<KieModule> getKieModule(); Map<String, byte[]> getProjectClassLoaderStore(); Set<String> getEventTypeClasses(); }
  • 27. We add objects to the Maven result (a simple int) and we use a pipeline of decorators to add behaviours before and after compilation 27 COMPILER interface AFCompiler<T extends CompilationResponse> { T compile(final CompilationRequest req); T compile(final CompilationRequest req, final Map<Path, InputStream> override); Boolean cleanInternalCache(); }
  • 28. PIPELINE: CHAIN OF DECORATORS ● Static factory for common use cases ● Configurable per object ● Possible to provide your own decorator 28
  • 29. MAVEN API VERY RESTRICT The first problem is how to open the “sealed” Maven API, we change the use of Plexus/Sisu we can reuse the same IoC container per project saving a huge amount of time, because the major part of the time in a Maven startup is the creation of this container 29
  • 30. CLASSLOADERS 30 Maven use classworlds to manage the various classloaders used for its tasks ● System Classloader ● Core Classloader ● Plugin Classloaders ● Custom Classloaders https://maven.apache.org/guides/mini/guide-maven-classloading.html
  • 31. CLASSLOADERS 31 If we want read an object inside the plugin and export it to the client code we have to cross the barriers of those classloaders. ● ReusableAFMavenCli ● BuildMojo ● BaseMavenCompiler
  • 32. IN MEMORY PLUGINS 32 A cool side effects when you cross the barriers of the classloaders is the option to turn the plugins impl from FS to in memory.
  • 33. INCREMENTAL COMPILER 33 To spent less time in front of a Maven build we change on the fly the pom to add the Takari compiler in every module of the project tied with the compiler
  • 34. POM PROCESSOR 34 The Compiler is aware of the plugins in the POM It changes on the fly the Pom turning off the Default Compiler and adds Takari and the Kie Plugin
  • 35. ASYNC API 35 interface AFCompilerService { CompletableFuture<KieCompilationResponse> build(Path projectPath, String mavenRepo); CompletableFuture<KieCompilationResponse> build(Path projectPath, String mavenRepo, Map<Path, InputStream> override); CompletableFuture<KieCompilationResponse> build(Path projectPath, String mavenRepo, Boolean skipPrjDependenciesCreationList); CompletableFuture<KieCompilationResponse> buildAndInstall(Path projectPath, String mavenRepo); CompletableFuture<KieCompilationResponse> buildAndInstall(Path projectPath, String mavenRepo, Boolean skipPrjDependenciesCreationList); CompletableFuture<KieCompilationResponse> buildSpecialized(Path projectPath, String mavenRepo, String[] args); CompletableFuture<KieCompilationResponse> buildSpecialized(Path projectPath, String mavenRepo, String[] args, Boolean skipPrjDependenciesCreationList); }
  • 36. COMPILER SERVICE 36 We could use the compiler core to enable a compiler service enabling local Maven executors or remote Maven executors on other nodes/pods/containers/VMs
  • 37. COMPILER SERVICE 37 We could demand a build to a remote node/pod/container/vm and reads a remote File System because the core compiler can use use a JGITCompilerBeforeDecorator
  • 38. LOCAL/REMOTE EXECUTORS 38 The compiler service need to know if the current “machine” owns enough resources to run a local executors or if is better to ask to a remote executor to satisfy the build. To invoke a remote executors It needs to know the address to reach the chosen instance.
  • 39. REST ENDPOINT 39 @Path("/build/maven/") @RequestScoped public class MavenRestHandler extends Application { @POST @Produces(MediaType.APPLICATION_OCTET_STREAM) public void postAsync(@Suspended AsyncResponse ar, @HeaderParam("project") String projectRepo, @HeaderParam("mavenrepo") String mavenRepo) throws Exception { CompletableFuture<KieCompilationResponse> response = compilerService.build(projectRepo, mavenRepo); response.whenCompleteAsync((kieCompilationResponse, throwable) -> { if (throwable != null) { logger.error(throwable.getMessage()); ar.resume(Response.serverError().build()); } else { byte[] bytes = RestUtils.serialize(new DefaultHttpCompilationResponse(kieCompilationResponse)); ar.resume(Response.ok(bytes).build()); } }); } }