Git Product home page Git Product logo

mod-camunda's Introduction

mod-camunda

Copyright (C) 2018-2022 The Open Library Foundation

This software is distributed under the terms of the Apache License, Version 2.0. See the file "LICENSE" for more information.

Table of Contents

  1. Docker deployment
    1. Publish docker image
  2. Camunda Module Dependencies
  3. Workflow Project Structure
  4. App Deployment
  5. Camunda APIs
  6. ActiveMQ Message Broker
  7. FOLIO Integration
  8. Additional Information
  9. Issue Tracker

Docker deployment

cd ..
git clone https://github.com/TAMULib/mod-workflow.git
cd mod-workflow
mvn clean install

cd mod-camunda
docker build -t folio/mod-camunda .
docker run -d -p 9000:9000 folio/mod-camunda

Publish docker image

docker login [docker repo]
docker build -t [docker repo]/folio/mod-camunda:[version] .
docker push [docker repo]/folio/mod-camunda:[version]

Camunda Module Dependencies

This module extends spring-module-core and brings in Camunda BPM to enable workflow capabilities. Camunda is an open-source BPM platform that is embedded in this module via the following dependencies.

# --- VERSIONS ---
<camunda.version>7.9.0</camunda.version>
<camunda.spring.boot.version>3.0.0</camunda.spring.boot.version>

# --- DEPENDENCY MANAGEMENT ---
<dependency>
  <!-- Import dependency management from Camunda -->
  <groupId>org.camunda.bpm</groupId>
  <artifactId>camunda-bom</artifactId>
  <version>${camunda.version}</version>
  <scope>import</scope>
  <type>pom</type>
</dependency>

# --- DEPENDENCIES ---
<dependency>
  <groupId>org.camunda.bpm.springboot</groupId>
  <artifactId>camunda-bpm-spring-boot-starter</artifactId>
  <version>${camunda.spring.boot.version}</version>
</dependency>

<dependency>
  <groupId>org.camunda.bpm.springboot</groupId>
  <artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
  <version>${camunda.spring.boot.version}</version>
</dependency>

<dependency>
  <groupId>org.camunda.bpm.springboot</groupId>
  <artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
  <version>${camunda.spring.boot.version}</version>
</dependency>

Workflow Project Structure

Business Process Models and Decision Models are built using the Camunda Modeler which impelements BPMN 2.0 and DMN 1.1 specifications.

  • .bpmn files are stored in /src/main/java/resources/workflows
  • .dmn files are stored in /src/main/java/resources/decisions

Any Java code that is executed in the context of a process is usually written in a Java Delegate. These classes are stored in /src/main/java/org/folio/rest/delegate/

Deploy and run the application

  1. Run the application mvn clean spring-boot:run
    1. Note there is a hard dependency on ActiveMQ. If running without ActiveMQ, be sure to comment out activemq.broker-url: tcp://localhost:61616 in the application.yml
  2. Deploy all the processes by running scripts/deploy.sh file
  3. Navigate to Camunda Portal localhost:9000/app/welcome/default/#/welcome
  4. Log in as admin username: admin, password: admin

Camunda APIs

ActiveMQ Message Broker

We are using ActiveMQ to consume messages. Currently we are only consuming, not producing messages. This is a hard dependency when running the application, so if you want to run the application without a message broker, comment out activemq.broker-url: tcp://localhost:61616 in the application.yml

FOLIO Integration

For detailed information to bring up a FOLIO instance refer to https://github.com/folio-org/folio-ansible.

The following requires Vagrant 1.9.6 or above.

vagrant up
# wait

When finished Okapi will be running with mod-workflow and mod-camunda deployed under the diku tenant. mod-camunda will have its port forwarded for access to the Camunda webapps. FOLIO UI will be accessible at http://localhost:3000; username: diku_admin, password: admin.

Okapi is being built and redeployed from within this vagrant. Eventually this will not need to happen. If a specific branch of either mod-camunda or mod-workflow is desired to be deployed, modify the Vagrantfile git checkout main to the desired branch and restart vagrant. vagrant destroy, vagrant up

Development

In order to facilitate development on mod-camunda in the context of Okapi, there is a sync directory from the host machine to the guest machine. The host directory is at .vagrant/sync and it will contain okapi, mod-camunda, and mod-workflow. The development and git branch management can be done on the host machine. The guest directory is at /sync. The redeployment of a module must be done from the guest machine.

vagrant ssh
sudo su
cd /sync
# kill mod-camunda running on port 9000
kill $(lsof -t -i :9000)
cd mod-camunda
mvn clean install
nohup java -jar target/mod-camunda-1.1.0.jar &

Login

curl -v -H "Content-Type: application/json" -H "X-Okapi-Tenant: diku" http://localhost:9130/authn/login -d '{"username": "diku_admin", "password": "admin"}'

The response headers of interest are X-Okapi-Token and refreshToken.

Refresh Token

curl -v -H "X-Okapi-Tenant: diku" -H "Content-Type: application/json" http://localhost:9130/refresh -d '{"refreshToken": "`[refresh token goes here]`"}'

The body of this response will contain the new X-Okapi-Token.

Workflow Module Triggers

The Trigger entity from mod-workflow is used to select which request-response events from Okapi are to be published to the event.queue that mod-camunda can subscribe to. In order to create the Triggers we have to provide the correct permissions to the diku_admin. The vagrant will create an example trigger for when a user is created.

Permissions

In order to call mod-camunda and mod-workflow through the Okapi gateway a user will need the appropriate permissions. In order to accommodate this the Vagrantfile runs a shell script in which updates permissions for diku_admin. Providing him with all permissions to all interfaces of mod-camunda and mod-workflow.

Cleanup

When finished it will be desired to cleanup as the FOLIO vagrant uses a lot of resources.

vagrant destroy
rm -rf .vagrant/sync

Removing the synced directory, .vagrant/sync, on the host will remove any changes during development that have not been pushed.

Additional information

Issue tracker

See project FOLIO at the FOLIO issue tracker.

mod-camunda's People

Contributors

wwelling avatar kaladay avatar jeremythuff avatar rladdusaw avatar jeremy-bp3 avatar jsavell avatar dcrossleyau avatar julianladisch avatar rmathew1011 avatar dependabot[bot] avatar jmicah avatar cappadona avatar jcreel avatar

Watchers

James Cloos avatar  avatar

mod-camunda's Issues

The StreamingResponseDelegate (formerly the TestStreamDelegate) should support multiple streams.

In its current implementation the StreamingResponseDelegate (refactored from TestStreamDelegate) utilizes the StreamService to register its stream.

The StreamService can only store and provide access to one Flux stream at a time. The StreamService should change to support a map of Flux streams. The StreamingResponseDelegate should supply a unique key (or one could be generated by the service itself) and that key should be placed on the execution context to be used in retrieving that flux stream in subsequent delegates.

The map solution used should support concurrent access.

We will need a strategy in place for cleaning a flux from the map when its stream is complete.

Email Java Delegate

Spend a few minutes researching existing functionality in Camunda.

Otherwise, create Java delegate that is provided email configuration, to, cc, bcc, from, subject, body template.

Mod Camunda should provide multiple extractor delegates

Given the completion of this issue in Mod Workflow and this local issue:

Mod Camunda should provide an abstract extractor delegate.

Mod Camunda should provide specific extensions of the abstract extractor delegate for extraction strategies corresponding to the values of the MergeStrategy enum in Mod Workflow.

The enumeration of MergeStrategy mergeStrategy found on any incoming Workflow Task of type ExtractorTask should be used to implicate a specific extensions of the abstract extractor delegate when creating the BPMN representation of that workflow.

Use milliseconds instead of seconds for flux element delay

It would be better appreciated to have finer-grained control over how long the delay is.

For modules, like external reference resolver, higher speeds may be potentially supported and a smaller delay would be preferred, especially for large data sets.
(example: 1 million records at 1 second delay vs 1 million records at 400ms delay.)

This would require either changing duration to milliseconds OR allow custom parsing such that "ms" (or something similar) is added to inform the parser to use milliseconds.

The former would require updating all appropriate tasks in fm-workflow.
The latter would require updating only what needs to use milliseconds, but at the cost of adding more processing logic to determine when to use seconds or milliseconds.

fm-workflows will need to be updated based on the decision made here.

Mod-workflow may also need to be changed, and also ensure that the data type is consistent between camunda and workflow (e.g. long vs int).

Mod Camunda should provide a start workflow interface

Mod Camunda's module descriptor should be modified to include an endpoint for the manual start of a workflow, designated by the workflows process identifier.

It should also provide a controller implementation of for this endpoint which will start the designated workflow.

** This may already exist **

Mod Camunda should provide an activate/deactivate interface

Mod Camunda should expose an API for activating workflows.

Mod Camunda should have its module descriptor modified to provide an interface for workflow-engine/workflow/activate and workflow-engine/workflow/deactivate, with all relevant permissions.

Both endpoints should accept a JSON representation of a workflow as defined by Mod Workflow. We should explore making mod-workflow a dependency of mod camunda, so that the workflow model defined in mod workflow can be available in mod camunda for deserialization.

The implementation of the activation and deactivation should be a recapitulation of the logic found in ModCamundaService and BpmnModelFactory of Mod Workflow.

Analogous service ought to be created in Mod Camunda to handle the activation.

StreamCreateForEach (formerly TestCreateForEachDelegate) should allow restriction of creation by multiple properties.

Currently the StreamCreateForEach delegate (refactored from TestCreateForEachDelegate) allows for the optional property String uniqueBy. When not null this property is used to query the target location to see if any entities are already with the same key value pair as the current potential entity being created.

It might be the case that the potential entity being created is needed to be unique by multiple keys. To support this potential use case the property uniqueBy ought to be changed to be a String[] and the query generated from it should check for an existing entity which matches on each key value pair.

The delegates package should be decluttered

Currently there are quite a few delegates in place from previous proof of concept work on workflows. These delegates should be deprecated and refactored into a separate package, such as delegate.examples or delegates.poc.

Only those delegates needed to perform the migration workflows should reside at the top level of the delegate package.

Any documentation references to these classes will need to reflect this refactor.

Mod-Camunda should have a StreamConsumer Delegate

This delegate should utilize the stream service to obtain the primary stream and subscribe to. Th BPMN model factory should ensure that this delegate is always called from a service task at the end of the workflow, if any task on that workflow return true from isStreaming

File I/O Read Delegate

We need a delegate to read from a path and read JSON files into a workflow. Should have a few properties; path to request JSON files and delay to provide ability to throttle.

The StreamAccumulationDelegate (formerly TestAccumulationDelegate) should have its request functionality moved into a new PoolRequestDelegate

Currently the StreamAccumulationDelegate (refactored from the TestAccumulationDelegate) both accumulates a stream into a list, and then makes a creation request for each object within the list.

This is poor separation of concerns. Instead the StreamAccumulationDelegate should only collect a stream into a list of size n, and then pass that list forward in the workflow. The request functionality that currently exists should be implemented in a PoolRequestDelegate.

Enhancing Extractor Delegate Should Enhance All Matches

Enhancing Extractor Delegate should continue to enhance all matches until no match is found. This should include respecting a boolean for isMultiple, placing enhanced properties within an object and placing that object in an array. The enhancement delegate will need to name the key of the destination array based on the mapAs value.

The BPMN model factory will need to be updated to respect the isMultiple and mapAs properties on the enhancement task.

The Streaming Process Delegate should support multiple scripting languages

Currently full support of multiple scripting languages has not been full implemented.

The ScriptEngineService utilizes a script template written in javascript. This should have a map of templates for all supported languages and should select the correct template based on the scriptType value.

The script utils have only been expressed in javascript. This file should be refactored to be src/main/resources/scripts/utils.js. Then analogous implementations should be created in each of the supported scripting languages. The script utility resources should be loaded from these files using the scriptType as an extension.

finally, the implementation of each utility function should be in Java, and each script utility should expose a call to the Java method as a native function call. Here is an example of calling java from javascript in the javax scripting engine.

Mod Camunda should provide a PoolRequestDelegate

A new PoolRequestDelegate should be created and placed at the top level of the delegate package. It should receive a list of objects and properties Expression concurentRequest
and Expression requestEndpoint, where concurentRequest should be parsable into an integer representing the desired number of concurrent request and requestEndpoint is a string representing the url to which the request should be made.

The delegate should pop n number of objects from the incoming array of objects, and for each make a request to the endpoint designated by requestEndpoint. wThe body of each request is a JSON representation of the object.

This delegate should continue to pop object from the incoming array and make requests from those object, while ensuring that the total number of pending requests never accedes concurentRequest. As each pending request resolves, a new request should be made until all objects in the incoming array have been exhausted.

File I/O Write Delegate

We need a delegate to write batch requests as JSON to a provided path. Introduce two properties, one for the path to write and another for the directory to hold the JSON files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.