Este contenido no está disponible en el idioma seleccionado.
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 Copiar enlaceEnlace copiado en el portapapeles!
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 Copiar enlaceEnlace copiado en el portapapeles!
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 Copiar enlaceEnlace copiado en el portapapeles!
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:dev
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
21.2.2. Running the OptaWeb Vehicle Routing back-end module from IntelliJ IDEA Ultimate Copiar enlaceEnlace copiado en el portapapeles!
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 Copiar enlaceEnlace copiado en el portapapeles!
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 Copiar enlaceEnlace copiado en el portapapeles!
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 themvn
orjava
command, 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.port
system property to8181
when you use Maven to compile a Quarkus project indev
mode:mvn compile quarkus:dev -Dquarkus.http.port=8181
mvn compile quarkus:dev -Dquarkus.http.port=8181
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This temporarily changes the value of the property stored in the
/src/main/resources/application.properties
file.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-example
file to theoptaweb-vehicle-routing-backend/.env
file.This file is excluded from version control and therefore it does not exist when you clone the repository. You can make changes in the
.env
file 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 Copiar enlaceEnlace copiado en el portapapeles!
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 Copiar enlaceEnlace copiado en el portapapeles!
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 npm
Copy 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
npm
dependencies:npm install
npm install
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Unlike Maven, the
npm
package manager installs dependencies innode_modules
under the project directory and does that only when you executenpm install
. Whenever the dependencies listed inpackage.json
change, for example when you pull changes to the master branch, you must executenpm install
before you run the development server.Enter the following command to run the development server:
npm start
npm start
Copy 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 start
command attempts to open this URL in your default browser.NoteIf you do not want the
npm start
command to open a new browser tab each time you run it, export theBROWSER=none
environment variable. You can use.env.local
file to make this preference permanent. To do that, enter the following command:echo BROWSER=none >> .env.local
echo BROWSER=none >> .env.local
Copy 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 test
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the value of the
REACT_APP_BACKEND_URL
environment variable to specify the location of the back-end project to be used bynpm
when you executenpm start
ornpm run build
, for example:REACT_APP_BACKEND_URL=http://10.0.0.123:8081
REACT_APP_BACKEND_URL=http://10.0.0.123:8081
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteEnvironment variables are hard coded inside the JavaScript bundle during the
npm
build 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 install
Copy to Clipboard Copied! Toggle word wrap Toggle overflow mvn install
mvn install
Copy to Clipboard Copied! Toggle word wrap Toggle overflow