To build and test the components as well as building the modelserver as standalone JAR execute the following maven goal in the root directory:
mvn clean install
To run the example modelserver within an IDE, run the main method of ExampleServerLauncher.java as a Java Application, located in the module com.eclipsesource.modelserver.example
.
To run the model server standalone JAR, run this command in your terminal:
cd examples/com.eclipsesource.modelserver.example/target/
java -jar com.eclipsesource.modelserver.example-X.X.X-SNAPSHOT-standalone.jar
usage: java -jar com.eclipsesource.modelserver.example-X.X.X-SNAPSHOT-standalone.jar
[-e] [-h] [-p <arg>] [-r <arg>]
options:
-e,--errorsOnly Only log errors
-h,--help Display usage information about ModelServer
-p,--port <arg> Set server port, otherwise default port 8081 is used
-r,--root <arg> Set workspace root
If the modelserver is up and running, you can access the modelserver API via http://localhost:8081/api/v1/*
.
The following table shows the current HTTP endpoints:
Category | Description | HTTP method | Path | Input |
---|---|---|---|---|
Models | Get all available models in the workspace | GET | /models |
- |
Get model | GET | /models |
query parameter: [?modeluri=...[&format=...]] |
|
Create new model | POST | /models |
query parameter: ?modeluri=...[&format=...] application/json |
|
Update model | PATCH | /models |
query parameter: ?modeluri=...[&format=...] application/json |
|
Delete model | DELETE | /models |
query parameter: ?modeluri=... |
|
Save | GET | /save |
query parameter: ?modeluri=... |
|
Execute commands | GET | /edit |
query parameter: ?modeluri=... |
|
Get all available model URIs in the workspace | GET | /modeluris |
- | |
JSON schema | Get JSON schema of a model | GET | /schema |
query parameter: ?modeluri=... |
Server actions | Ping server | GET | /api/v1/server/ping |
- |
Update server configuration | PUT | /api/v1/server/configure |
application/json |
The query parameter ?modeluri=
accepts files in the loaded workspace as well as absolute file paths.
Subscriptions are implemented via websockets ws://localhost:8081/api/v1/*
.
The following table shows the current WS endpoints:
Description | Path | Input | Returns |
---|---|---|---|
Subscribe to model changes | /subscribe |
query parameter: ?modeluri=...[&format=...] |
sessionId |
The modelserver project features a Java-based client API that eases integration with the model server. The interface declaration looks as follows
public interface ModelServerClientApiV1 {
CompletableFuture<Response<String>> get(String modelUri);
CompletableFuture<Response<A>> get(String modelUri, String format);
CompletableFuture<Response<List<String>>> getAll();
CompletableFuture<Response<Boolean>> delete(String modelUri);
CompletableFuture<Response<String>> update(String modelUri, String updatedModel);
CompletableFuture<Response<A>> update(String modelUri, A updatedModel, String format);
CompletableFuture<Response<Boolean>> save(String modelUri);
CompletableFuture<Response<String>> getSchema(String modelUri);
CompletableFuture<Response<Boolean>> configure(ServerConfiguration configuration);
CompletableFuture<Response<Boolean>> ping();
CompletableFuture<Response<Boolean>> edit(String modelUri, CCommand command, String format);
void subscribe(String modelUri, SubscriptionListener subscriptionListener, String format);
boolean unsubscribe(String modelUri);
EditingContext edit();
boolean close(EditingContext editingContext);
}
// You can customize the underlying okhttp instance by passing it in as a 1st parameter
ModelServerClient client = new ModelServerClient("http://localhost:8081/api/v1/");
// perform simple GET
client.get("SuperBrewer3000.json")
.thenAccept(response -> System.out.println(response.body()));
// perform same GET, but expect XMI format
client.get("SuperBrewer3000.json&format=xmi")
.thenAccept(response -> System.out.println(response.body()));
// perform POST
client.update("SuperBrewer3000.json", "{ \"data\": <payload> }")
.thenAccept(response -> System.out.println(response.body()));
// perform POST with XMI format
client.update("SuperBrewer3000.json&format=xmi", client.encode(brewingUnit, "xmi"))
.thenAccept(response -> {
client.get("SuperBrewer3000.json&format=xmi").thenAccept(resp -> {
System.out.println(client.decode(resp.body(), "xmi"));
});
});
}
If you want to be notified about any changes happening on a certain model,
you can subscribe with a SubscriptionListener
.
ModelServerClient client = new ModelServerClient("http://localhost:8081/api/v1/");
String subscriptionId = "SuperBrewer3000.json&format=xmi";
client.subscribe(subscriptionId, new SubscriptionListener() {
@Override
public void onOpen(Response<String> response) {
System.out.println("connected: " + response.getMessage());
}
@Override
public void onMessage(String response) {
System.out.println("message received: " + response);
}
@Override
public void onClosing(int code, @NotNull String reason) {
System.out.println("Closing");
}
@Override
public void onFailure(Throwable t) {
System.out.println("Failed: ");
t.printStackTrace();
}
@Override
public void onClosed(int code, @NotNull String reason) {
System.out.println("Connected closed");
}
@Override
public void onFailure(Throwable t, Response<String> response) {
System.out.println("Failed: " + response);
}
});
client.unsubscribe(subscriptionId);
Latest Code Coverage report can be found here: com.eclipsesource.modelserver.codecoverage/jacoco/index.html
The code coverage report is generated with JaCoCo and is integrated in the Maven build. In the package com.eclispesource.modelserver.codecoverage
all code coverages are aggregated into one report.
For now, only the main overall result per module is uploaded to the repository here. When executing the Maven build executed locally, the detailled results are computed and can be investigated in more detail.