Commit 7394d173 authored by Evgeny Kusmenko's avatar Evgeny Kusmenko
Browse files

Merge branch 'docker' into 'master'

Better support for Mac/Linux users

See merge request !2
parents d6fddae6 a8959c93
Pipeline #89765 passed with stages
in 2 minutes and 5 seconds
......@@ -25,11 +25,26 @@ __NOTE:__ _MontiSim_ is the directory, in which MontiSim-belonging projects shou
To run the server one can has to run the corresponding script file from the __scripts__ directory in _RMIModelServer_ project.
* For Windows the `run.bat` file has to be executed
* For Linux the `run.sh` file has to be exeuted __*(irrelevant, due to dependency on Windows platform)__
By default, the RMI server will start with port 10101, you can change this if you need to. For example if you want to start multiple RMI server on different ports.
## External models
* For Windows users, edit the variable PORT and DLL in `run.bat` before you execute it.
* For Linux users, edit the variable DLL in `run.sh`, then execute the script with:
```
$ ./run.sh [port]
```
for example, to start RMI server with default port(10101):
```
$ ./run.sh
```
to start it with custom port:
```
$ ./run.sh 5000
```
## External models
### Windows
To use an external vehicle model, one has to clone the corresponding repository. For the _Autopilot emam_ vehicle model, located in [Autopilot emam repository](https://github.com/MontiSim/EMAM-showcase), the following commands have to be executed:
cd MontiSim
......@@ -42,6 +57,44 @@ To use an external vehicle model, one has to clone the corresponding repository.
The last command `main.bat` will compile the model and run it in a server container to test it.
__NOTE:__ Autopilot EMAM model works only in _Windows 64 bit_ environment.
### Linux
First you need to edit the JAVA_HOME variable in scripts/linux/variables.sh
Then generate the cpp code:
```$xslt
$ ./generate.sh
```
Then compile the AutopilotAdapter.dll:
```$xslt
$ ./compile.sh
```
The scripts in `script` directory are already adjusted to use _Autopilot_ model. If a new model has to be integrated to the RMI Model server, an implementation of _VehicleModel_ has to be created and adjusted with the _ModelManager_. Additionally, all dependencies of the new model have to be declared in the _library_ or _class-path_ of the RMI Model server.
## Docker
Here is another possibility to run the RMI server without compiling the AutopilotAdapter.dll yourself.
First we build the docker image with
```
$ ./docker/build.sh
```
This script only does 2 things:
1. Copy the latest rmi-model-server build into ./docker/ in order to prepare the build.
2. Then use ./docker/Dockerfile to build the rmi-model-server docker image.
If there is a new version of rmi-model-server, the `RMI_VERSION` in the Dockerfile needs to be updated accordingly.
If you need to update the `AutopilotAdapter.dll`, it has to be recompiled under a linux 64-bit environment by using scripts in `scripts/linux` of repo `EMAM-showcase`.
After the docker image is built. Run following command to start the RMI server with port 10101:
```
$ docker run --name=rmi-server -p 10101:10101 --rm rmi-server
```
Or, for example with port 5000:
```
$ docker run --name=rmi-server -p 5000:10101 --rm rmi-server
```
#
#
# ******************************************************************************
# MontiCAR Modeling Family, www.se-rwth.de
# Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
# All rights reserved.
#
# This project is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this project. If not, see <http://www.gnu.org/licenses/>.
# *******************************************************************************
#
FROM openjdk:8
ENV RMI_VERSION=1.0.1-SNAPSHOT
ENV RMI_JAR=rmi-model-server-${RMI_VERSION}.jar
WORKDIR /app
COPY AutopilotAdapter.dll /usr/lib/
COPY AutopilotAdapter.dll ./
COPY rmi-model-server-$RMI_VERSION.jar ./rmi-model-server.jar
CMD exec java -cp rmi-model-server.jar -Djava.rmi.server.codebase=file:rmi-model-server.jar -Djava.rmi.server.hostname=rmi-server rwth.rmi.model.server.RMIServer 10101 /usr/lib/AutopilotAdapter.dll
#!/bin/bash
#
#
# ******************************************************************************
# MontiCAR Modeling Family, www.se-rwth.de
# Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
# All rights reserved.
#
# This project is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this project. If not, see <http://www.gnu.org/licenses/>.
# *******************************************************************************
#
rm rmi-model-server-*.jar
cp ../target/rmi-model-server-*.jar ./
docker build -t rmi-server .
......@@ -26,13 +26,12 @@
<groupId>montisim</groupId>
<artifactId>rmi-model-server</artifactId>
<version>${global.version}</version>
<version>1.0.1-SNAPSHO</version>
<packaging>jar</packaging>
<name>rmi-model-server</name>
<properties>
<global.version>1.0.1-SNAPSHOT</global.version>
<!-- .. SE-Libraries .................................................. -->
<monticore.version>4.5.4.08.11.2017</monticore.version>
<se-commons.version>1.7.7</se-commons.version>
......
......@@ -28,5 +28,11 @@ set ARMADILLO_HOME=%AUTOPILOT_HOME%\armadillo-8.400.0
set AUTOPILOT_DLL_DIR=%AUTOPILOT_HOME%\dll
set PATH=%AUTOPILOT_DLL_DIR%;%JAVA_HOME%\bin;%MINGW_HOME%\bin;%ARMADILLO_HOME%\examples\lib_win64;%PATH%
java "-Djava.library.path=%PATH%" "-Djava.rmi.server.codebase=file:..\target\rmi-model-server-1.0.1.jar" "-Djava.rmi.server.hostname=127.0.0.1" -cp ..\target\rmi-model-server-1.0.1.jar rwth.rmi.model.server.RMIServer
@REM Please replace this with the actual ABSOLUTE PATH to AutopilotAdapter.dll on your machine
set DLL=/ABSOLUTE/PATH/TO/AutopilotAdapter.dll
@REM Change the port if you need to
set PORT=10101
java "-Djava.library.path=%PATH%" "-Djava.rmi.server.codebase=file:..\target\rmi-model-server-1.0.1.jar" "-Djava.rmi.server.hostname=127.0.0.1" -cp ..\target\rmi-model-server-1.0.1.jar rwth.rmi.model.server.RMIServer %PORT% %DLL%
pause
......@@ -20,4 +20,16 @@
#
#run rmi server and registry
java -cp ../target/rmi-model-server-1.0.0.jar -Djava.rmi.server.codebase=file:../target/rmi-model-server-1.0.1.jar -Djava.rmi.server.hostname=127.0.0.1 rwth.rmi.model.server.RMIServer
if [ -z "$1" ]; then
PORT=10101
else
PORT="$1"
fi
# Please replace this with the actual ABSOLUTE PATH to AutopilotAdapter.dll on your machine
DLL=/ABSOLUTE/PATH/TO/AutopilotAdapter.dll
java -cp ../target/rmi-model-server-1.0.1-SNAPSHOT.jar\
-Djava.rmi.server.codebase=file:../target/rmi-model-server-1.0.1-SNAPSHOT.jar\
-Djava.rmi.server.hostname=127.0.0.1 rwth.rmi.model.server.RMIServer\
$PORT $DLL
......@@ -36,15 +36,16 @@ public class ModelManager implements RMIManager {
private int lastModelId = 0;
private Map<Integer, VehicleModel> models;
//Served models
private VehicleModel[] supportedModels = new VehicleModel[] {
new AutopilotAdapter()
};
public ModelManager() {
private VehicleModel[] supportedModels;
public ModelManager(String libraryPath) {
super();
this.models = new HashMap<Integer, VehicleModel>();
this.supportedModels = new VehicleModel[] {
new AutopilotAdapter(libraryPath)
};
}
@Override
......
......@@ -20,6 +20,10 @@
*/
package rwth.rmi.model.server;
import java.io.File;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
......@@ -27,22 +31,70 @@ import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class RMIServer {
public final static String MODEL_MANAGER = "ModelManager";
private final static int INIT_PORT = 10101;
public final static String MODEL_MANAGER = "ModelManager";
public static void main(String[] args) {
ModelManager manager = new ModelManager();
try {
Registry registry = LocateRegistry.createRegistry(INIT_PORT);
System.out.println("RMIRegistry serving on port: " + INIT_PORT);
//bind the ModelManager to a stub, representing the remote object
registry.bind(MODEL_MANAGER, UnicastRemoteObject.exportObject(manager, 0));
System.out.println("RMIManager listening");
} catch (RemoteException | AlreadyBoundException e) {
e.printStackTrace();
}
if (args.length < 2){
System.out.println("Please assign a port that the RMI server need to bind, also the path to AutopilotAdapter.dll");
return;
}
if (!isPortAvailable(args[0])){
System.out.printf("Port %s is currently unavailable, please use another port.\n", args[0]);
return;
}
File autopilotAdapterDLL = new File(args[1]);
if (!autopilotAdapterDLL.exists()){
System.out.printf("AutopilotAdapter: %s not exist\n", autopilotAdapterDLL);
return;
}
ModelManager manager = new ModelManager(args[1]);
try {
int port = Integer.valueOf(args[0]);
Registry registry = LocateRegistry.createRegistry(port);
System.out.println("RMIRegistry serving on port: " + port);
//bind the ModelManager to a stub, representing the remote object
registry.bind(MODEL_MANAGER, UnicastRemoteObject.exportObject(manager, 0));
System.out.println("RMIManager listening");
} catch (RemoteException | AlreadyBoundException e) {
e.printStackTrace();
}
}
public static boolean isPortAvailable(String portString) {
int port;
try {
port = Integer.valueOf(portString);
} catch (NumberFormatException e) {
System.out.printf("Port %s is illegel, please check your input.", portString);
throw e;
}
ServerSocket ss = null;
DatagramSocket ds = null;
try {
ss = new ServerSocket(port);
ss.setReuseAddress(true);
ds = new DatagramSocket(port);
ds.setReuseAddress(true);
return true;
} catch (IOException e) {
} finally {
if (ds != null) {
ds.close();
}
if (ss != null) {
try {
ss.close();
} catch (IOException e) {
}
}
}
return false;
}
}
......@@ -32,14 +32,10 @@ import rwth.rmi.model.server.interfaces.VehicleModel;
*/
public class AutopilotAdapter implements VehicleModel {
static {
// make sure the corresponding DLL is on the classpath
// when the java app with simulation is started
System.loadLibrary("AutopilotAdapter");
}
public AutopilotAdapter() {
public AutopilotAdapter(String libraryPath) {
super();
// Load AutopilotAdapter.dll from libraryPath
System.load(libraryPath);
initialize();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment