Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 21. OptaWeb Vehicle Routing development guide
This section describes how to configure and run the back-end and front-end modules in development mode.
21.1. OptaWeb Vehicle Routing project structure Link kopierenLink in die Zwischenablage kopiert!
The OptaWeb Vehicle Routing project is a multi-module Maven project.
Figure 21.1. Module dependency tree diagram
The back-end and front-end modules are at the bottom of the module tree. These modules contain the application source code.
The standalone module is an assembly module that combines the back end and front end into a single executable JAR file.
The distribution module represents the final assembly step. It takes the standalone application and the documentation and wraps them in an archive that is easy to distribute.
The back end and front end are separate projects that you can build and deploy separately. In fact, they are written in completely different languages and built with different tools. Both projects have tools that provide a modern developer experience with fast turn-around between code changes and the running application.
The next sections describe how to run both back-end and front-end projects in development mode.
21.2. The OptaWeb Vehicle Routing back-end module Link kopierenLink in die Zwischenablage kopiert!
The back-end module contains a server-side application that uses Red Hat Build of OptaPlanner to optimize vehicle routes. Optimization is a CPU-intensive computation that must avoid any I/O operations in order to perform to its full potential. Because one of the chief objectives is to minimize travel cost, either time or distance, OptaWeb Vehicle Routing keeps the travel cost information in RAM memory. While solving, OptaPlanner needs to know the travel cost between every pair of locations entered by the user. This information is stored in a structure called the distance matrix.
When you enter a new location, OptaWeb Vehicle Routing calculates the travel cost between the new location and every other location that has been entered so far, and stores the travel cost in the distance matrix. The travel cost calculation is performed by the GraphHopper routing engine.
The back-end module implements the following additional functionality:
- Persistence
- WebSocket connection for the front end
- Data set loading, export, and import
To learn more about the back-end code architecture, see Chapter 22, OptaWeb Vehicle Routing back-end architecture.
The next sections describe how to configure and run the back end in development mode.
21.2.1. Running the OptaWeb Vehicle Routing back-end module Link kopierenLink in die Zwischenablage kopiert!
You can run the back-end module in Quarkus development mode.
Prerequisites
- OptaWeb Vehicle Routing has been configured as described in Chapter 18, Configure and run OptaWeb Vehicle Routing manually.
Procedure
-
Change directory to
rhbop-8.33.0-kogito-and-optaplanner-quickstarts/optaweb-8.33.0.Final-redhat-00004/optaweb-vehicle-routing/optaweb-vehicle-routing-backend. To run the back end in development mode, enter the following command:
mvn compile quarkus:dev
mvn compile quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow
21.2.2. Running the OptaWeb Vehicle Routing back-end module from IntelliJ IDEA Ultimate Link kopierenLink in die Zwischenablage kopiert!
You can use IntelliJ IDEA Ulitmate to run the OptaWeb Vehicle Routing back-end module to make it easier to develop your project. IntelliJ IDEA Ultimate includes a Quarkus plug-in that automatically creates run configurations for modules that use the Quarkus framework.
Procedure
Use the optaweb-vehicle-routing-backend run configuration to run the back end.
Additional resources
For more information, see Run the Quarkus application.
21.2.3. Quarkus development mode Link kopierenLink in die Zwischenablage kopiert!
In development mode, if there are changes to the back-end source code or configuration and you refresh the browser tab where the front end runs, the back-end automatically restarts.
Learn more about Quarkus development mode.
21.2.4. Changing OptaWeb Vehicle Routing back-end module system property values Link kopierenLink in die Zwischenablage kopiert!
You can temporarily or permanently override the default system property values of the OptaWeb Vehicle Routing back-end module.
The OptaWeb Vehicle Routing back-end module system properties are stored in the /src/main/resources/application.properties file. This file is under version control. Use it to permanently store default configuration property values and to define Quarkus profiles.
Prerequisites
- The OptaWeb Vehicle Routing starter application has been downloaded and extracted. For information, see Chapter 16, Download and build the OptaWeb Vehicle Routing deployment files.
Procedure
To temporarily override a default system property value, include the
-D<PROPERTY>=<VALUE>argument when you run themvnorjavacommand, where<PROPERTY>is the name of the property that you want to change and<VALUE>is the value that you want to temporarily assign to that property. The following example shows how to temporarily change the value of thequarkus.http.portsystem property to8181when you use Maven to compile a Quarkus project indevmode:mvn compile quarkus:dev -Dquarkus.http.port=8181
mvn compile quarkus:dev -Dquarkus.http.port=8181Copy to Clipboard Copied! Toggle word wrap Toggle overflow This temporarily changes the value of the property stored in the
/src/main/resources/application.propertiesfile.To change a configuration value permanently, for example to store a configuration that is specific to your development environment, copy the contents of the
env-examplefile to theoptaweb-vehicle-routing-backend/.envfile.This file is excluded from version control and therefore it does not exist when you clone the repository. You can make changes in the
.envfile without affecting the Git working tree.
Additional resources
For a complete list of OptaWeb Vehicle Routing configuration properties, see Chapter 23, OptaWeb Vehicle Routing back-end configuration properties.
21.2.5. OptaWeb Vehicle Routing backend logging Link kopierenLink in die Zwischenablage kopiert!
OptaWeb Vehicle Routing uses the SLF4J API and Logback as the logging framework. For more information, see Quarkus - Configuring Logging.
21.3. Working with the OptaWeb Vehicle Routing front-end module Link kopierenLink in die Zwischenablage kopiert!
The front-end project was bootstrapped with Create React App. Create React App provides a number of scripts and dependencies that help with development and with building the application for production.
Prerequisites
- The OptaWeb Vehicle Routing starter application has been downloaded and extracted. For information, see Chapter 16, Download and build the OptaWeb Vehicle Routing deployment files.
Procedure
On Fedora, enter the following command to set up the development environment:
sudo dnf install npm
sudo dnf install npmCopy to Clipboard Copied! Toggle word wrap Toggle overflow See Downloading and installing Node.js and npm for more information about installing npm.
-
Change directory to
rhbop-8.33.0-kogito-and-optaplanner-quickstarts/optaweb-8.33.0.Final-redhat-00004/optaweb-vehicle-routing/optaweb-vehicle-routing-frontend. Install
npmdependencies:npm install
npm installCopy to Clipboard Copied! Toggle word wrap Toggle overflow Unlike Maven, the
npmpackage manager installs dependencies innode_modulesunder the project directory and does that only when you executenpm install. Whenever the dependencies listed inpackage.jsonchange, for example when you pull changes to the master branch, you must executenpm installbefore you run the development server.Enter the following command to run the development server:
npm start
npm startCopy to Clipboard Copied! Toggle word wrap Toggle overflow If it does not open automatically, open
http://localhost:3000/in a web browser.By default, the
npm startcommand attempts to open this URL in your default browser.NoteIf you do not want the
npm startcommand to open a new browser tab each time you run it, export theBROWSER=noneenvironment variable. You can use.env.localfile to make this preference permanent. To do that, enter the following command:echo BROWSER=none >> .env.local
echo BROWSER=none >> .env.localCopy to Clipboard Copied! Toggle word wrap Toggle overflow The browser refreshes the page whenever you make changes in the front-end source code. The development server process running in the terminal picks up the changes as well and prints compilation and lint errors to the console.
Enter the following command to run tests:
npm test
npm testCopy to Clipboard Copied! Toggle word wrap Toggle overflow Change the value of the
REACT_APP_BACKEND_URLenvironment variable to specify the location of the back-end project to be used bynpmwhen you executenpm startornpm run build, for example:REACT_APP_BACKEND_URL=http://10.0.0.123:8081
REACT_APP_BACKEND_URL=http://10.0.0.123:8081Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteEnvironment variables are hard coded inside the JavaScript bundle during the
npmbuild process, so you must specify the back-end location before you build and deploy the front end.To learn more about the React environment variables, see Adding Custom Environment Variables.
To build the front end, enter one of the following commands:
./mvnw install
./mvnw installCopy to Clipboard Copied! Toggle word wrap Toggle overflow mvn install
mvn installCopy to Clipboard Copied! Toggle word wrap Toggle overflow