Skip to content

Commit

Permalink
refactor(EntityOperationHandler): fix PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasBousselin committed May 24, 2024
1 parent 7d3bf2e commit 9886433
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 57 deletions.
133 changes: 85 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,74 +15,105 @@
[![CodeQL](https://github.com/stellio-hub/stellio-context-broker/actions/workflows/codeql.yml/badge.svg)](https://github.com/stellio-hub/stellio-context-broker/actions/workflows/codeql.yml)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/4527/badge)](https://bestpractices.coreinfrastructure.org/projects/4527)

Stellio is an NGSI-LD compliant context broker developed by EGM. NGSI-LD is an Open API and Datamodel specification for
context management [published by ETSI](https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.08.01_60/gs_CIM009v010801p.pdf)).

Stellio is a [FIWARE](https://www.fiware.org/) Generic Enabler. Therefore, it can be integrated as part of any platform “Powered by FIWARE”.
FIWARE is a curated framework of open source platform components which can be assembled together with other third-party
platform components to accelerate the development of Smart Solutions. For more information check the FIWARE Catalogue entry for
[Core Context](https://github.com/Fiware/catalogue/tree/master/core). The roadmap of this FIWARE GE is described [here](https://github.com/stellio-hub/stellio-context-broker/projects/1).

You can find more info at the [FIWARE developers](https://developers.fiware.org/) website and the [FIWARE](https://fiware.org/) website.
The complete list of FIWARE GEs and Incubated FIWARE GEs can be found in the [FIWARE Catalogue](https://catalogue.fiware.org/).
Stellio is an NGSI-LD compliant context broker developed by EGM. NGSI-LD is an Open API and Datamodel specification for
context
management [published by ETSI](https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.08.01_60/gs_CIM009v010801p.pdf)).

Stellio is a [FIWARE](https://www.fiware.org/) Generic Enabler. Therefore, it can be integrated as part of any platform
“Powered by FIWARE”.
FIWARE is a curated framework of open source platform components which can be assembled together with other third-party
platform components to accelerate the development of Smart Solutions. For more information check the FIWARE Catalogue
entry for
[Core Context](https://github.com/Fiware/catalogue/tree/master/core). The roadmap of this FIWARE GE is
described [here](https://github.com/stellio-hub/stellio-context-broker/projects/1).

You can find more info at the [FIWARE developers](https://developers.fiware.org/) website and
the [FIWARE](https://fiware.org/) website.
The complete list of FIWARE GEs and Incubated FIWARE GEs can be found in
the [FIWARE Catalogue](https://catalogue.fiware.org/).

**NGSI-LD Context Broker Feature Comparison**

The NGSI-LD Specification is regularly updated and published by ETSI. The latest specification is [version 1.8.1](https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.08.01_60/gs_CIM009v010801p.pdf) which was published in April 2024.
The NGSI-LD Specification is regularly updated and published by ETSI. The latest specification
is [version 1.8.1](https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.08.01_60/gs_CIM009v010801p.pdf) which was
published in April 2024.

- An Excel file detailing the current compatibility of the development version of the Stellio Context Broker against the features of the 1.8.1 specification can be downloaded [here](https://docs.google.com/spreadsheets/d/e/2PACX-1vRxOjsDf3lqhwuypJ---pZN2OlqFRl0jyoTV0ewQ1WFnpe7xQary3uxRjunbgJkwQ/pub?output=xlsx)
- An Excel file detailing the current compatibility of the development version of the Stellio Context Broker against the
features of the 1.8.1 specification can be
downloaded [here](https://docs.google.com/spreadsheets/d/e/2PACX-1vRxOjsDf3lqhwuypJ---pZN2OlqFRl0jyoTV0ewQ1WFnpe7xQary3uxRjunbgJkwQ/pub?output=xlsx)

| :books: [Documentation](https://stellio.rtfd.io/) | :whale: [Docker Hub](https://hub.docker.com/orgs/stellio/repositories) | :dart: [Roadmap](./docs/roadmap.md) |
|---------------------------------------------------|------------------------------------------------------------------------|-------------------------------------|

## Overview

Stellio is composed of 2 business services:
* Search service is in charge of managing the information context and handling the temporal (and geospatial) queries, it is backed by a [TimescaleDB](https://www.timescale.com/) database
* Subscription service is in charge of managing subscriptions and subsequent notifications, it is backed by a [TimescaleDB](https://www.timescale.com/) database

* Search service is in charge of managing the information context and handling the temporal (and geospatial) queries, it
is backed by a [TimescaleDB](https://www.timescale.com/) database
* Subscription service is in charge of managing subscriptions and subsequent notifications, it is backed by
a [TimescaleDB](https://www.timescale.com/) database

It is completed with:

* An API Gateway module that dispatches requests to downstream services
* A [Kafka](https://kafka.apache.org/) streaming engine that decouples communication inside the broker (and allows plugging other services seamlessly)
* A [Kafka](https://kafka.apache.org/) streaming engine that decouples communication inside the broker (and allows
plugging other services seamlessly)

The services are based on the [Spring Boot](https://spring.io/projects/spring-boot) framework, developed in [Kotlin](https://kotlinlang.org),
The services are based on the [Spring Boot](https://spring.io/projects/spring-boot) framework, developed
in [Kotlin](https://kotlinlang.org),
and built with [Gradle](https://gradle.org).

## Quick start

A quick way to start using Stellio is to use the provided `docker-compose.yml` file in the root directory (feel free to change
A quick way to start using Stellio is to use the provided `docker-compose.yml` file in the root directory (feel free to
change
the default passwords defined in the `.env` file):

```shell script
docker-compose up -d && docker-compose logs -f
```

It will start all the services composing the Stellio context broker platform and expose them on the following ports:

* API Gateway: 8080
* Search service: 8083
* Subscription service: 8084

Please note that the environment and scripts are validated on Ubuntu and macOS. Some errors may occur on other platforms.
Please note that the environment and scripts are validated on Ubuntu and macOS. Some errors may occur on other
platforms.

We also provide a configuration to deploy Stellio in a k8s cluster. For more information, please look in the [stellio-k8s project](https://github.com/stellio-hub/stellio-k8s)
We also provide a configuration to deploy Stellio in a k8s cluster. For more information, please look in
the [stellio-k8s project](https://github.com/stellio-hub/stellio-k8s)

#### TROUBLESHOOTING

If Kafka container crash when starting, you may need to change "config/kafka/update_run.sh" line separator from CRLF to
LF

## Docker images tagging

Starting from version 2.0.0, a new scheme is used for tagging of Docker images:

* Releases are tagged with the version number, e.g., `stellio/stellio-search-service:2.0.0`
* `latest` tag is no longer used for releases as it can be dangerous (for instance, triggering an unwanted major upgrade)
* On each commit on the `develop` branch, an image with the `latest-dev` tag is produced, e.g., `stellio/stellio-search-service:latest-dev`
* `latest` tag is no longer used for releases as it can be dangerous (for instance, triggering an unwanted major
upgrade)
* On each commit on the `develop` branch, an image with the `latest-dev` tag is produced,
e.g., `stellio/stellio-search-service:latest-dev`

The version number is obtained during the build process by using the `version` information in the `build.gradle.kts` file.
The version number is obtained during the build process by using the `version` information in the `build.gradle.kts`
file.

## Development

### Developing on a service

Requirements:

* Java 21 (we recommend using [sdkman!](https://sdkman.io/) to install and manage versions of the JDK)

To develop on a specific service, you can use the provided `docker-compose.yml` file inside each service's directory, for instance:
To develop on a specific service, you can use the provided `docker-compose.yml` file inside each service's directory,
for instance:

```shell script
cd search-service
Expand All @@ -97,11 +128,12 @@ Then, from the root directory, launch the service:

### Running the tests

Each service has a suite of unit and integration tests. You can run them without manually launching any external component, thanks
Each service has a suite of unit and integration tests. You can run them without manually launching any external
component, thanks
to Spring Boot embedded test support and to the great [TestContainers](https://www.testcontainers.org/) library.

For instance, you can launch the test suite for entity service with the following command:

```shell script
./gradlew search-service:test
```
Expand Down Expand Up @@ -135,14 +167,15 @@ Code formatting and standard code quality checks are performed by [Detekt](https

Detekt checks are automatically performed as part of the build and fail the build if any error is encountered.

* You may consider using a plugin like [Save Actions](https://plugins.jetbrains.com/plugin/7642-save-actions)
that applies changed code refactoring and optimized imports on a save.
* You may consider using a plugin like [Save Actions](https://plugins.jetbrains.com/plugin/7642-save-actions)
that applies changed code refactoring and optimized imports on a save.

* You can enable Detekt support with the [Detekt plugin](https://github.com/detekt/detekt-intellij-plugin).

### Working locally with Docker images

To work locally with a Docker image of a service without publishing it to Docker Hub, you can follow the below instructions:
To work locally with a Docker image of a service without publishing it to Docker Hub, you can follow the below
instructions:

* Build a tar image:

Expand All @@ -164,7 +197,7 @@ docker run stellio/stellio-search-service:latest

## Releasing a new version

* Merge develop into master
* Merge develop into master

```
git checkout master
Expand All @@ -184,50 +217,54 @@ git commit -am "chore: upgrade version to x.y.z"
git push origin master
```

The CI will then create and publish Docker images tagged with the published version number in https://hub.docker.com/u/stellio.
The CI will then create and publish Docker images tagged with the published version number
in https://hub.docker.com/u/stellio.

* On GitHub, check and publish the release notes in https://github.com/stellio-hub/stellio-context-broker/releases

## Usage

To start using Stellio, you can follow the [API quick start](https://github.com/stellio-hub/stellio-docs/blob/master/docs/quick_start_guide.md).
To start using Stellio, you can follow
the [API quick start](https://github.com/stellio-hub/stellio-docs/blob/master/docs/quick_start_guide.md).

## Minimal hardware requirements needed to run Stellio

The recommended system requirements may vary depending on factors such as the scale of deployment, usage patterns, and specific use cases. That said, here are the general guidelines for the minimum computer requirements:
The recommended system requirements may vary depending on factors such as the scale of deployment, usage patterns, and
specific use cases. That said, here are the general guidelines for the minimum computer requirements:

* Processor: Dual-core processor or higher
* RAM: 4GB or higher (1.8GB is needed to just run it)
* Storage: At least 4GB of free disk space (3.8GB is needed to just run it)
* Operating System: Linux (recommended), macOS (also recommended), or Windows

Please note that these requirements may vary based on factors such as the size of your dataset, the number of concurrent users, and the overall complexity of your use case.
Please note that these requirements may vary based on factors such as the size of your dataset, the number of concurrent
users, and the overall complexity of your use case.

## Further resources

For more detailed explanations on NGSI-LD or FIWARE:

- [NGSI-LD v1.8.1 Specification](https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.08.01_60/gs_CIM009v010801p.pdf)
- [NGSI-LD Primer](https://www.etsi.org/deliver/etsi_gr/CIM/001_099/008/01.01.01_60/gr_CIM008v010101p.pdf)
- [NGSI-LD Tutorials](https://ngsi-ld-tutorials.readthedocs.io/en/latest/)
- [FIWARE Training](https://fiware-academy.readthedocs.io/en/latest/integrated-courses/fiware-training/index.html)
- [NGSI-LD v1.8.1 Specification](https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.08.01_60/gs_CIM009v010801p.pdf)
- [NGSI-LD Primer](https://www.etsi.org/deliver/etsi_gr/CIM/001_099/008/01.01.01_60/gr_CIM008v010101p.pdf)
- [NGSI-LD Tutorials](https://ngsi-ld-tutorials.readthedocs.io/en/latest/)
- [FIWARE Training](https://fiware-academy.readthedocs.io/en/latest/integrated-courses/fiware-training/index.html)

## License

Stellio is licensed under [APL-2.0](https://spdx.org/licenses/Apache-2.0.html).

It mainly makes use of the following libraries and frameworks (dependencies of dependencies have been omitted):

| Library / Framework | Licence |
|---------------------|--------------|
| Spring | APL v2 |
| Titanium JSON-LD | APL v2 |
| Reactor | APL v2 |
| Jackson | APL v2 |
| JUnit | EPL v2 |
| Mockk | APL v2 |
| JsonPath | APL v2 |
| WireMock | APL v2 |
| Testcontainers | MIT |
| Library / Framework | Licence |
|---------------------|----------|
| Spring | APL v2 |
| Titanium JSON-LD | APL v2 |
| Reactor | APL v2 |
| Jackson | APL v2 |
| JUnit | EPL v2 |
| Mockk | APL v2 |
| JsonPath | APL v2 |
| WireMock | APL v2 |
| Testcontainers | MIT |

© 2020 - 2024 EGM
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ class EntityOperationService(
): Either<BatchEntityError, BatchEntitySuccess> =
kotlin.runCatching {
either {
val processedEntity = processor(entity, disallowOverwrite, sub).bind()
if (processedEntity.notUpdated.isEmpty())
processedEntity.right().bind()
val result = processor(entity, disallowOverwrite, sub).bind()
if (result.notUpdated.isEmpty())
result.right().bind()
else
BadRequestDataException(
ArrayList(processedEntity.notUpdated.map { it.attributeName + " : " + it.reason })
ArrayList(result.notUpdated.map { it.attributeName + " : " + it.reason })
.joinToString()
).left().bind<UpdateResult>()
}.map {
Expand All @@ -212,13 +212,12 @@ class EntityOperationService(
): Either<APIException, UpdateResult> = either {
val (jsonLdEntity, ngsiLdEntity) = entity
temporalEntityAttributeService.deleteTemporalAttributesOfEntity(ngsiLdEntity.id).bind()
val result = entityPayloadService.appendAttributes(
entityPayloadService.appendAttributes(
ngsiLdEntity.id,
jsonLdEntity.getModifiableMembers(),
disallowOverwrite,
sub
).bind()
return@either result
}

suspend fun updateEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class EntityOperationServiceTests {
}

@Test
fun `filterExistingEntitiesAsIds should split entities per existence`() = runTest {
fun `splitEntitiesByExistence should split entities per existence`() = runTest {
coEvery {
entityPayloadService.filterExistingEntitiesAsIds(listOf(firstEntityURI, secondEntityURI))
} returns listOf(firstEntityURI)
Expand All @@ -87,7 +87,7 @@ class EntityOperationServiceTests {
}

@Test
fun `filterExistingEntitiesAsIds should split entities per existence with ids`() = runTest {
fun `splitEntitiesByExistence should split entities per existence with ids`() = runTest {
coEvery {
entityPayloadService.filterExistingEntitiesAsIds(listOf(firstEntityURI, secondEntityURI))
} returns listOf(firstEntityURI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ class EntityOperationHandlerTests {

@Test
fun `merge batch entity should return a 400 if JSON-LD payload is not correct`() {
shouldReturn400WithBadPayload("update")
shouldReturn400WithBadPayload("merge")
}

@Test
Expand Down

0 comments on commit 9886433

Please sign in to comment.