Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Enabling of Knowledge Layer #50

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
db8e01a
Add basis directory structure with readme files
chrizmc May 23, 2024
64e06ec
add basic setup of informationlayer containing basic dbrouter and rea…
chrizmc May 29, 2024
5ee12fd
add files
claireqiu May 31, 2024
75c0eb3
Fixed readme format of config.js
sschleemilch Jun 6, 2024
a77d8a3
Renamed knowledge-connector -> connector
sschleemilch Jun 6, 2024
327db86
Removed dead README link
sschleemilch Jun 6, 2024
69da82d
Fixed README formatting and fixed typos
sschleemilch Jun 6, 2024
9bb7dc4
Updated docs, added config.js
sschleemilch Jun 6, 2024
e0d7aa6
Added handlers layer
sschleemilch Jun 6, 2024
9722e2b
Hint for hard coded realmdb and js formatting
sschleemilch Jun 6, 2024
dbbed43
Fixed require path for new structure
sschleemilch Jun 6, 2024
f98ef6f
Added missing dot in readme
chrizmc Jun 18, 2024
0da163a
Fixed wrong readme link
chrizmc Jun 18, 2024
0c83de4
add basic router parts
chrizmc Jul 8, 2024
3e36432
Add environment variable functionallity and update README files.
chrizmc Jul 9, 2024
72ab98b
Update link URL and create a IoTDB connection using the IoTDB Handler
chrizmc Jul 24, 2024
c075e51
Update the authentification configuration for the IoTDB handler
chrizmc Jul 31, 2024
684f3f9
Add validator for message format and IoTDB message processing
chrizmc Aug 7, 2024
62e8402
Extend supported data points in RealmDB Handler
sschleemilch Aug 9, 2024
cd597d1
Support for UseCase endpoits in IoTDB Handler
sschleemilch Aug 9, 2024
5f142ab
Add write support to realmdb
sschleemilch Aug 13, 2024
56a1109
Extracted common methods
sschleemilch Aug 21, 2024
6d28e89
Support dots separation for endpoint naming in realm db
aw-muc Aug 22, 2024
deff29c
• Import supported endpoints for IoTDB and RealmDB from YAML/JSON fil…
aw-muc Aug 27, 2024
c8ef06d
Dockerize informations-layer
aw-muc Sep 6, 2024
7f1ae37
Fixed doc typos
sschleemilch Sep 6, 2024
838af3f
Remove unnecessary config files and add it as gitignore.
aw-muc Sep 13, 2024
dfb873f
Data transmission via websocket client in knowledge layer:
aw-muc Sep 16, 2024
28ec28b
Documentation for new data source within information layer
aw-muc Sep 16, 2024
b84a37e
Handle and send error message within information layer for websocket …
aw-muc Sep 16, 2024
8614c90
Vehicle data point knowledge layer configuration
sschleemilch Sep 26, 2024
e68d6bb
CMake windows support
sschleemilch Sep 27, 2024
bbe803f
Add --help CLI feature to display configured and default parameters
chrizmc Oct 9, 2024
9559d7f
Use configuration file to organize the use case model directory
chrizmc Oct 9, 2024
ffce704
Configure RDFox environment
chrizmc Oct 9, 2024
24b871e
Develop RDFox adapter for rest api integration
Oct 17, 2024
1bcadd7
Refactored information-layer Docs (#36)
sschleemilch Oct 21, 2024
7ae2fb4
- Migrate JS to TypeScript
aw-muc Oct 21, 2024
c936c4b
add hello world kl usecase readme
chrizmc Oct 21, 2024
cd64ada
IMplementation of Thrift to access IoTDB without TypeScript; JavaScri…
aw-muc Oct 23, 2024
7465d61
Switched README graph to mermaid
sschleemilch Oct 30, 2024
c078a05
Subscription functionality for IoTDB data layer
aw-muc Nov 4, 2024
21236aa
Locate another transformation function in transformations.ts, too
chrizmc Nov 13, 2024
9693e64
Add instruction how to build and run tests
chrizmc Nov 13, 2024
d9da312
change _ to . notation in readme
chrizmc Nov 14, 2024
c76f57a
Transform Json data into RDF triples using SHACL shapes and SPARQ…
Nov 26, 2024
21e519b
Add subscription status message after subscribe/unsubscribe when usin…
chrizmc Dec 2, 2024
43a1758
Add session management to Information Layer
chrizmc Dec 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions cdsp/information-layer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
This directory contains files related to the [Information Layer](https://en.wikipedia.org/wiki/DIKW_pyramid) of the Central Data Service Playground.

# Information Layer Playground components
- [Database-Handlers](./handlers)
- [Database-Router](./router)

# Setting up a CDSP Information Layer
Setting up an information layer in the CDSP involves running a [Database-Router](./router), which is technically a configurable Websocket server that enables northbound connections for WebSocket clients, such as a [Knowledge Layer Connector](../knowledge-layer/README.md), to read, subscribe, and write data. The WebSocket server is connected to a database, which can be selected before starting the web server. Southbound feeders write data to the database in a predefined semantic format, such as [VSS](https://github.com/COVESA/vehicle_signal_specification).

## Installation of Database-Handler

Please follow installation instructions of the chosen [handler](./handlers/).

## Installation of Database-Router
See [hier](./router/README.md#Install) how to install the Database-Router.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'hier' should be 'here'?


# Running "Hello World" example

The Hello World example in our case is quite simple. We feed an updated value for the `CurrentLocation_Longitude` into the database and we check afterwards in the logs if the DB-router creates a Websocket update message for it.

## Choose and prepare your Database

### Realm
- Ensure that in your [ATLAS cloud](https://cloud.mongodb.com/) app there is a vehicle *document* with an `VehicleIdentification_VIN: SMT905JN26J262542` in a collection named *`Vehicles`*.
- Ensure that this document as well contains VSS data. Here you can see the supported data in a vehicle document within the *Vehicles* should look like in ATLAS:

```
_id: "<SOME_ID>" (string)
VehicleIdentification_VIN: "<SOME_VIN>" (string)
CurrentLocation_Latitude: <SOME_LATITUDE_VALUE> (Int64)
CurrentLocation_Longitude: <SOME_LONGITUDE_VALUE> (Int64)
```

### IoTDB
- Ensure to start and run Docker containers defined in a [Docker Compose file](/docker/).
- Ensure that in the IoTDB CLI there is a `root.Vehicles` *database* like this:

```
IoTDB> show databases;
+-------------+----+-----------------------+---------------------+---------------------+
| Database| TTL|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|
+-------------+----+-----------------------+---------------------+---------------------+
|root.Vehicles|null| 1| 1| 604800000|
+-------------+----+-----------------------+---------------------+---------------------+
Total line number = 1
It costs 0.004s
```

- Create two *timeseries* with the `root.Vehicles.VehicleIdentification_VIN` and some VSS data. Here you can see an example how the vehicle document within the *Vehicles* should look like in IoTDB CLI:

```
IoTDB> show timeseries;
+---------------------------------------+-----+-------------+--------+--------+-----------+----+----------+--------+------------------+--------+
| Timeseries|Alias| Database|DataType|Encoding|Compression|Tags|Attributes|Deadband|DeadbandParameters|ViewType|
+---------------------------------------+-----+-------------+--------+--------+-----------+----+----------+--------+------------------+--------+
|root.Vehicles.VehicleIdentification_VIN| null|root.Vehicles| TEXT| PLAIN| LZ4|null| null| null| null| BASE|
| root.Vehicles.CurrentLocation_Latitude| null|root.Vehicles| DOUBLE| RLE| LZ4|null| null| null| null| BASE|
|root.Vehicles.CurrentLocation_Longitude| null|root.Vehicles| DOUBLE| RLE| LZ4|null| null| null| null| BASE|
+---------------------------------------+-----+-------------+--------+--------+-----------+----+----------+--------+------------------+--------+
```

## Start the Database Router

See [here](./router/README.md#Run) how to start the database router.

## Look out for the Websocket Server message in the console
If you the handler is running and you are subscribed to that element, when you change the value of `CurrentLocation_Longitude` in ATLAS cloud (let's say `-157845.68200000003`), you should immediately see this line in console:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'If you the handler'?


```
{
type: 'update',
tree: 'VSS',
id: '<your_VIN>',
dateTime: '<actual_data_time>',
uuid: '<your_uuid>',
node: { name: 'CurrentLocation_Longitude', value: `-157845.68200000003` }
}
```

# Connect your own Websocket Client
Connect your own websocket client by connecting to `ws://localhost:8080`

The examples use the VIN (Vehicle Identification Number) as object identifier.

### Reading data

To read data, send a message with the type of request and VIN as object ID:

* Example for one Node:
```json
{
"type": "read",
"tree": "VSS",
"id": "<some_VIN>",
"uuid": "<random_string>",
"node": {
"name": "<some_endpoint>"
}
}
```
* Example for multiple Nodes:
```json
{
"type": "read",
"tree": "VSS",
"id": "<some_VIN>",
"uuid": "<random-string>",
"nodes": [
{
"name": "<some_endpoint>"
},
{
"name": "<other_endpoint>"
}
]
}
```

### Writing data

To write data, send a message with the type of request and VIN as object ID (at this moment only with IoTDB available):

* Example for one Node:
```json
{
"type": "write",
"tree": "VSS",
"id": "<some_VIN>",
"uuid": "<random_string>",
"node": {
"name": "<some_endpoint>",
"value": "<some_value>"
}
}
```
* Example for multiple Nodes:
```json
{
"type": "write",
"tree": "VSS",
"id": "<some_VIN>",
"uuid": "<random-string>",
"nodes": [
{
"name": "<some_endpoint>",
"value": "<some_value>"
},
{
"name": "<other_endpoint>",
"value": "<other_value>"
}
]
}
```
### Subscribing to changes

To subscribe to changes in a specific object, send a message with the type of request and VIN as object ID (at this moment only with RealmDB available):

```json
{
"type": "subscribe",
"tree": "VSS",
"id": "<some_VIN>",
"uuid": "<your_uuid>",
}
```

4 changes: 4 additions & 0 deletions cdsp/information-layer/handlers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Handlers

- [IotDB](./iotdb)
- [RealmDB](./realmdb)
35 changes: 35 additions & 0 deletions cdsp/information-layer/handlers/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Handler {
authenticateAndConnect(sendMessageToClients) {
throw new Error("Method 'authenticateAndConnect' must be implemented.");
}

handleMessage(message, ws) {
switch (message.type) {
case "read":
this.read(message, ws);
break;
case "write":
this.write(message, ws);
break;
case "subscribe":
this.subscribe(message, ws);
break;
default:
ws.send(JSON.stringify({ error: "Unknown message type" }));
}
}

read(message, ws) {
throw new Error("Read method not implemented, yet!");
}

write(message, ws) {
throw new Error("Write method not implemented, yet!");
}

subscribe(message, ws) {
throw new Error("Subscribe method not implemented, yet!");
}
}

module.exports = Handler;
9 changes: 9 additions & 0 deletions cdsp/information-layer/handlers/iotdb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Node.js
node_modules/
package-lock.json

# Credentials Config File
config.js

# MAC
**/.DS_Store
39 changes: 39 additions & 0 deletions cdsp/information-layer/handlers/iotdb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
This directory contains the IoTDB Handler as a Node.js application. As [Apache IoTDB](https://iotdb.apache.org/) is a time-series database, the IoTDB Handler connects to an existing IoTDB instance using the Thrift protocol. The handler utilizes the [IoTDB Thrift API](https://github.com/apache/thrift) to communicate with the database and perform operations. Configuration details, such as the IoTDB host, port, user credentials, and time zone, are specified in the handler's configuration file. The IoTDB Handler is designed to manage sessions, execute queries, and interact with the IoTDB instance efficiently during runtime.

# Features

- **Authentication**: Authenticates with IoTDB using the IoTDB host, port, user credentials, and time zone.
- **Error Handling**: Logs and handles errors during database operations and synchronization.

# Installation

Execute within `iotdb` directory

```bash
npm install
```

# Configure IoTDB

Before the Database-Router can start the IoTDB Handler without any errors you need to start and run Docker containers defined in a [Docker Compose file](/docker/).

## Configure of a IoTDB Handler

Create `config/config.js` with the following format, replacing the app id and the api key with yours.

```js
module.exports = {
iotdbHost: "your-iotdb-host", // Default "localhost"
iotdbPort: 6667, // Set this to the appropriate IotDB Port
iotdbUser: "your-iotdb-user", // Default "root"
iotdbPassword: "your-iotdb-password", // Default "root"
timeZoneId: Intl.DateTimeFormat().resolvedOptions().timeZone, // Set this to the appropriate time zone
fetchSize: 10000, // number of rows that will be fetched from the database at a time when executing a query
};
```

> **_IMPORTANT:_** Do not commit this file to github!

## Starting the IoTDB handler

You do not need to start IotDB Handler manually. It is started by the DB-Router like described [here](../../router/README.md#Run).
11 changes: 11 additions & 0 deletions cdsp/information-layer/handlers/iotdb/config/Database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Contains the definition of the database name and its identifier endpoint for each catalog.
*/
const Database = Object.freeze({
VSS: {
database_name: "root.Vehicles", // name of the configured IoTDB for the VSS Database
endpoint_id: "VehicleIdentification_VIN", // endpoint used as element ID
},
});

module.exports = Database;
12 changes: 12 additions & 0 deletions cdsp/information-layer/handlers/iotdb/config/MeasurementsType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const JSDataType = require("../utils/IoTDBConstants");

/*
* Define the supported endpoints and the corresponding data types.
*/
const MeasurementType = Object.freeze({
VehicleIdentification_VIN: JSDataType.TEXT,
CurrentLocation_Latitude: JSDataType.DOUBLE,
CurrentLocation_Longitude: JSDataType.DOUBLE,
});

module.exports = MeasurementType;
Loading
Loading