此内容没有您所选择的语言版本。
Running and modifying the employee roster starter application for Red Hat Business Optimizer using an IDE
Abstract
Preface 复制链接链接已复制到粘贴板!
As a business rules developer, you can use an IDE to build, run, and modify the employee-rostering starter application that uses the Red Hat Business Optimizer functionality.
Prerequisites
- You use an integrated development environment, such as Eclipse (including Red Hat CodeReady Studio) or IntelliJ IDEA.
- You have an understanding of the Java language.
The employee rostering starter application assigns employees to shifts on various positions in an organization. For example, you can use the application to distribute shifts in a hospital between nurses, guard duty shifts across a number of locations, or shifts on an assembly line between workers.
Optimal employee rostering must take a number of variables into account. For example, different skills can be required for shifts in different positions. Also, some employees might be unavailable for some time slots or might prefer a particular time slot. Moreover, an employee can have a contract that limits the number of hours that the employee can work in a single time period.
The Red Hat Business Optimizer rules for this starter application use both hard and soft constraints. During an optimization, the planning engine may not violate hard constraints, for example, if an employee is unavailable (out sick), or that an employee cannot work two spots in a single shift. The planning engine tries to adhere to soft constraints, such as an employee’s preference to not work a specific shift, but can violate them if the optimal solution requires it.
You can build the employee rostering starter application from the source code and run it using a JBoss EAP or WildFly application server.
You can use the command line to build the application, then install it into a stand-alone server.
Alternatively, you can use your IDE, for example, Eclipse (including Red Hat CodeReady Studio), to build and run the application.
You can also deploy and run the pre-built WAR file that is supplied with the source code.
For information about using the application, see Deploying and using the employee roster starter application for Red Hat Business Optimizer on Red Hat OpenShift Container Platform.
2.1. Preparing deployment files 复制链接链接已复制到粘贴板!
You must download and prepare the deployment files before building and deploying the application.
Procedure
-
Download the
rhdm-7.5.1-reference-implementation.zipfile from the Software Downloads page for Red Hat Decision Manager 7.5. - Unzip the downloaded archive.
Unzip the
rhdm-7.5-employee-rostering.zipfile that is extracted from the reference implementation archive.The
employee-rostering-distribution-7.26.0.Final-redhat-00005folder is created. This folder is the base folder in subsequent parts of this document.NoteFile and folder names might have higher version numbers than specifically noted in this document.
You can use the command line to build the employee rostering starter application and run it.
If you use this procedure, the data is stored in memory and is lost when the server is stopped. To build and run the application with a database server for persistent storage, see Section 2.3, “Building and running the employee rostering starter application with persistent data storage from the command line”.
Prerequisites
- You prepared the deployment files as described in Section 2.1, “Preparing deployment files”.
- A Java Development Kit is installed.
- Maven is installed.
- The host has access to the Internet. The build process uses the Internet for downloading Maven packages from external repositories.
Procedure
-
In a terminal window, change to the
sourcesdirectory. Enter the following command:
mvn clean install
mvn clean installCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Wait for the build process to complete.
Use one of the following methods to run the application:
Run the WildFly server deployed as part of the build process:
-
In the
local/appserver/wildfly-14.0.1-final/standalone/deploymentssubdirectory, create theoptaweb-employee-rostering-webapp-<version>.war.dodeployfile. The<version>must be the same as in the existingoptaweb-employee-rostering-webapp-<version>.warsymlink in the same directory. -
In the
local/appserver/wildfly-14.0.1-final/binsubdirectory, enter the./standalone.shcommand.
-
In the
-
Deploy the
optaweb-employee-rostering-webapp/target/optaweb-employee-rostering-*.warfile into an existing WildFly or JBoss EAP server and start the application server. Use the following commands to run a server using Maven:
mvn -N wildfly:start wildfly:deploy mvn gwt:codeserver
mvn -N wildfly:start wildfly:deploy mvn gwt:codeserverCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you use Maven to start the server, the UI uses the gwt codeserver and monitors the gwtui source. In this case, if you change gwtui code, the codeserver picks the changes up automatically; there is no need to rebuild the application for gwtui code changes.
Later, to stop this server, use the command:
mvn -N wildfly:shutdown
mvn -N wildfly:shutdownCopy to Clipboard Copied! Toggle word wrap Toggle overflow
- To access the application, enter http://localhost:8080/gwtui/gwtui.html in a web browser.
If you use the command line to build the employee rostering starter application and run it, you can provide a database server for persistent data storage.
Prerequisites
- You prepared the deployment files as described in Section 2.1, “Preparing deployment files”.
- A Java Development Kit is installed.
- Maven is installed.
- The host has access to the Internet. The build process uses the Internet for downloading Maven packages from external repositories.
- You have a deployed WildFly or Red Hat JBoss EAP application server and a deployed MySQL or PostrgeSQL database server.
- You have set up a JDBC data source in the application server for the database server.
Procedure
-
In a terminal window, change to the
sourcesdirectory. Enter the following command:
mvn clean install -Dproductized -Dorg.optaweb.employeerostering.persistence.datasource=<dsname> -Dorg.optaweb.employeerostering.persistence.dialect=<dialect>
mvn clean install -Dproductized -Dorg.optaweb.employeerostering.persistence.datasource=<dsname> -Dorg.optaweb.employeerostering.persistence.dialect=<dialect>Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the preceding command, replace the following values:
- <dsname> with the name of the data source in the application server.
<dialect> with one of the following strings, depending on the type of database server:
-
For MySQL,
org.hibernate.dialect.MySQL5Dialect -
For PostgreSQL,
org.hibernate.dialect.PostgreSQLDialect
-
For MySQL,
- Wait for the build process to complete.
-
Deploy the
optaweb-employee-rostering-webapp/target/optaweb-employee-rostering-7.26.0.Final-redhat-00005.wardirectory into the application server and start the application server. - To access the application, enter http://localhost:8080/gwtui/gwtui.html in a web browser.
You can use Eclipse, including Red Hat CodeReady Studio, to build the employee rostering starter application and run it.
Prerequisites
- You prepared the deployment files as described in Section 2.1, “Preparing deployment files”.
- Eclipse is installed.
- The host has access to the Internet. The build process uses the Internet for downloading Maven packages from external repositories.
- Google Chrome is installed in order to run the application with the suggested configuration.
You can modify the configuration to use another web browser.
Procedure
- Start Eclipse.
- From the main menu, select File > Import….
- Select the Maven > Existing Maven projects wizard.
- For the root directory, select the root directory of the application source.
- Click Finish.
Optionally, to avoid seeing many errors in Eclipse:
-
In the root directory of the application source, enter the
mvn clean installcommand and wait for the build to finish. -
In the Eclipse navigation tree, right-click
employee-rostering-sharedand select Build Path > Configure Build Path…. - Click the Source tab, then click Add Folder….
-
Select the
employee-rostering-shared/target/generated-sourcesfolder and click OK.
-
In the root directory of the application source, enter the
- From the main menu, select Run > External Tools > External Tools Configurations….
Under Program, create the following launch configurations:
Open OptaWeb Employee Rostering in Chrome:
-
Name:
Open OptaWeb Employee Rostering in Chrome -
Location:
/usr/bin/google-chrome -
Working Directory:
${workspace_loc:/employee-rostering} Arguments:
--incognito http://localhost:8080/gwtui/gwtui.htmlNoteYou can change the name, location. and arguments to use another browser instead of Chrome.
-
Name:
Kill Code Server:
-
Name:
Kill Code Server -
Location:
/usr/sbin/fuser -
Working Directory:
${workspace_loc:/employee-rostering} -
Arguments:
fuser -k 9876/tcp
-
Name:
- From the main menu, select Run > Run Configurations….
Under Maven Build, create the following launch configurations:
OptaWeb Employee Rostering Build:
-
Name:
OptaWeb Employee Rostering Build -
Base directory:
${workspace_loc:/employee-rostering} -
Goals:
clean install -
Parameter:
gwt:skipCompilationValue:true
-
Name:
OptaWeb Employee Rostering Start Code Server:
-
Name:
OptaWeb Employee Rostering Start Code Server -
Base directory:
${workspace_loc:/employee-rostering} -
Goals:
gwt:codeserver -
Parameter:
gwt:skipCompilationValue:true
-
Name:
OptaWeb Employee Rostering Start Webserver:
-
Name:
OptaWeb Employee Rostering Start Webserver -
Base directory:
${workspace_loc:/employee-rostering} -
Goals:
wildfly:start wildfly:deploy -
Parameter:
gwt:skipCompilationValue:true
-
Name:
OptaWeb Employee Rostering Stop Webserver:
-
Name:
OptaWeb Employee Rostering Stop Webserver -
Base directory:
${workspace_loc:/employee-rostering} -
Goals:
wildfly:shutdown -
Parameter:
gwt:skipCompilationValue:true
-
Name:
Under Launch Group, create a launch group named
OptaWeb Employee Rostering Run. Add the following launches to it:-
Program::Kill Code ServerLaunch mode: inherit Post launch action: Wait until terminated -
Maven Build::OptaWeb Employee Rostering Stop WebserverLaunch mode: inherit Post launch action: Wait until terminated -
Maven Build::OptaWeb Employee Rostering BuildLaunch mode: inherit Post launch action: Wait until terminated -
Maven Build::OptaWeb Employee Rostering Start WebserverLaunch mode: inherit Post launch action: none -
Maven Build::OptaWeb Employee Rostering Start Code serverLaunch mode: inherit Post launch action: Wait for console output (regexp):The code server is ready at -
Program::Open OptaWeb Employee Rostering in ChromeLaunch mode: inherit Post launch action: none
-
To build, run, and immediately acccess the application, run the
OptaWeb Employee Rostering Runlaunch group. You can then change the application and rerun the launch group to test your changes.NoteWhen you use this method to run the application, the UI uses the gwt codeserver and monitors the gwtui source. If you change gwtui code, the codeserver picks the changes up automatically; there is no need to rebuild the application for gwtui code changes.
2.5. Running the supplied pre-built WAR file 复制链接链接已复制到粘贴板!
To access the Employee Rostering starter application, you can deploy and run the pre-built employee-rostering-webapp-7.26.0.Final-redhat-00005.war file that is supplied with Red Hat Decision Manager.
Prerequisites
- You prepared the deployment files as described in Section 2.1, “Preparing deployment files”.
- A Java Development Kit is installed.
- You have a deployed WildFly or Red Hat JBoss EAP application server.
Procedure
In your WildFly or Red Hat JBoss EAP application server, enable property replacement. For more information about enabling and disabling property replacement in Red Hat JBoss EAP, see Property Replacement in the Red Hat JBoss Enterprise Application Platform 7.2 Configuration Guide.
- Start the application server in standalone mode.
Start the management CLI by entering the following command:
EAP_HOME/bin/jboss-cli.sh --connect
EAP_HOME/bin/jboss-cli.sh --connectCopy to Clipboard Copied! Toggle word wrap Toggle overflow In the management CLI enter the following command:
/subsystem=ee:write-attribute(name="spec-descriptor-property-replacement",value=true)
/subsystem=ee:write-attribute(name="spec-descriptor-property-replacement",value=true)Copy to Clipboard Copied! Toggle word wrap Toggle overflow
- Stop the application server.
-
Deploy the
binaries/employee-rostering-webapp-7.26.0.Final-redhat-00005.wardirectory into the application server and start the application server. - To access the application, enter http://localhost:8080/gwtui/gwtui.html in a web browser.
The employee rostering starter application consists of the following principal components:
- The server that implements the rostering logic using Red Hat Business Optimizer and provides a REST API.
-
The client that implements a user interface using the
gwtlibrary and calls the server using the REST API.
While some code is shared between the client and the server, you can build and use these components independently. In particular, you can implement a different user interface and use the REST API to call the server.
In addition to the two main components, the employee rostering template contains a generator of random source data (useful for demonstration and testing purposes) and a benchmarking application.
Modules and key classes
The Java source code of the employee rostering template contains several Maven modules. Each of these modules includes a separate Maven project file (pom.xml), but they are intended for building in a common project.
The modules contain a number of files, including Java classes. This document lists all the modules, as well as the classes and other files that contain the key information for the employee rostering calculations.
-
employee-rostering-benchmarkmodule: Contains an additional application that generates random data and benchmarks the solution. -
employee-rostering-distributionmodule: Contains readme files. -
employee-rostering-docsmodule: Contains documentation files. -
employee-rostering-gwtuimodule: Contains the client application with the user interface, developed using thegwttoolkit. employee-rostering-servermodule: Contains the server application that uses Red Hat Business Optimizer to perform the rostering calculation.-
src/main/resources/org/optaweb/employeerostering/server/solver/employeeRosteringScoreRules.drlfile: Contains the rules for the Red Hat Business Optimizer calculation. These rules are written in the Drools rules language. You can modify the rules to change the logic for employee rostering. -
src/main/java/org.optaweb.employeerostering.server.roster/rosterGenerator.javaclass: generates random input data for demonstration and testing purposes. If you change the requires input data, change the generator accordingly.
-
employee-rostering-sharedmodule: Contains the data structures shared between the server and client applications. In particular, undersrc/main/java/org/optaweb/employeerostering/shared/*, this module includes the Java classes that define the input data for the rostering calculations, including the following classes:-
employee/EmployeeAvailability.javadefines availability information for an employee. For every time slot, an employee can be unavailable, available, or it can be a preferred timeslot for the employee. -
employee/Employee.javadefines an employee. An employee has a name, a list of skills, and works under a contract. Skills are represented byEmployeeSkillProficiencyobjects. -
roster/Roster.javadefines the calculated rostering information. -
shift/Shift.javadefines a shift to which an employee can be assigned. A shift is defined by a time slot and a spot. For example, in a diner there could be a shift in theKitchenspot for theFebruary 20 8AM-4PMtime slot. Multiple shifts can be defined for a given spot and time slot; in this case, multiple employees are required for this spot and time slot. -
skill/Skill.javadefines a skill that an employee can have. -
spot/Spot.javadefines a spot where employees can be placed. For example, in a dinerKitchencan be a spot. -
contract/Contract.javadefines a contract that sets the limits of work time for an employee in various time periods. tenant/Tenant.javadefines a tenant. Each tenant represents an independent set of data; any change in the data for one tenant does not affect any other tenants.The
employee-rostering-sharedmodule also includes other shared artifacts:-
*View.javaclasses define value sets that are calculated from other information; the client application can read these values through the REST API, but not write them. -
*RestService.javainterfaces define the REST API. Both the server and the client application separately define implementations of these interfaces.
-
-
employee-rostering-shared-gwtmodule: Contains some of the classes required for the GWT client application. -
employee-rostering-webappmodule: Contains the HTML and other files necessary for building the entire application (client and server).
To modify the employee rostering starter application to suit your needs, you must change the rules that govern the optimization process. You must also ensure that the data structures include the required data and provide the required calculations for the rules. If the required data is not present in the user interface, you must also modify the user interface.
The following procedure outlines the general approach to modifying the employee rostering starter application.
Prerequisites
- You have a build environment that successfully builds the application.
- You can read and modify Java code.
Procedure
Plan the required changes. Answer the following questions:
- What are the additional scenarios that must be avoided? These scenarios are hard constraints.
- What are the additional scenarios that the optimizer must try to avoid when possible? These scenarios are soft constraints.
- What data is required to calculate if each scenario is happening in a potential solution?
- Which of the data can be derived from the information that the user enters in the existing version?
- Which of the data can be hardcoded?
- Which of the data must be entered by the user and is not entered in the current version?
- If any required data can be calculated from the current data or can be hardcoded, add the calculations or hardcoding to existing view or utility classes. If the data must be calculated on the server side, add REST API endpoints to read it.
-
If any required data must be entered by the user, add the data to the classes representing the data entities (for example, the
Employeeclass), add REST API endpoints to read and write the data, and modify the user interface to enter the data. When all the data is available, modify the rules. For most modifications, you must add a new rule. The rules are located in the
src/main/resources/org/optaweb/employeerostering/server/solver/employeeRosteringScoreRules.drlfile of theemployee-rostering-servermodule.Use the Drools language for the rules. For reference information about the Drools rule language, see Rule Language Reference. Classes defined in the
optaweb-employee-rostering-sharedandoptaweb-employee-rostering-servermodules are available to the decision engine.- After modifying the application, build and run it.
Appendix A. Versioning information 复制链接链接已复制到粘贴板!
Documentation last updated on Thursday, October 31, 2019.