Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt committed Aug 7, 2023
1 parent 8e573fe commit 0520c96
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ maven/mavencentral/org.eclipse.edc/dsp-transfer-process/0.2.0, Apache-2.0, appro
maven/mavencentral/org.eclipse.edc/dsp/0.2.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/http-spi/0.2.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/http/0.2.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/iam-mock/0.2.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/jersey-core/0.2.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/jersey-micrometer/0.2.0, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/jersey-providers/0.2.0, Apache-2.0, approved, technology.edc
Expand Down
19 changes: 17 additions & 2 deletions samples/multi-tenancy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
This sample show how to create a custom runtime to run multiple EDC tenants in a single java process.

## How it works

In a Java Runtime, multiple "sub-runtimes" with dedicated classloader can be launched in parallel, giving object-level
separation (an object instantiated by a sub-runtime cannot be accessed by another sub-runtime).

## How to use

The module provides an extension of the `BaseRuntime` class called `MultiTenantRuntime`.
This class can be set in the `build.gradle.kts` as the main class:

```kotlin
application {
mainClass.set("org.eclipse.tractusx.edc.samples.multitenancy.MultiTenantRuntime")
Expand All @@ -18,6 +21,7 @@ application {
This runtime looks for a properties file which path can be specified with the `edc.tenants.path` property.

In this file the tenants are defined through settings, e.g.:

```properties
edc.tenants.tenant1.edc.fs.config=/config/path
edc.tenants.tenant2.edc.fs.config=/config/path
Expand All @@ -28,6 +32,7 @@ Using this file the EDC will run with 3 tenants: `tenant1`, `tenant2` and `tenan
configuration file.
Everything that stays after the tenant name in the setting key will be loaded in the tenant runtime, so *theoretically*
(but not recommended) you could define all the tenants configuration in the tenants properties file:

```properties
edc.tenants.tenant1.web.http.port=18181
edc.tenants.tenant1.any.other.setting=value
Expand All @@ -38,16 +43,19 @@ edc.tenants.tenant3.web.http.port=38181
## Sample

Build:

```shell
./gradlew :samples:multi-tenancy:build
```

Run:

```shell
java -jar -Dedc.tenants.path=samples/multi-tenancy/tenants.properties samples/multi-tenancy/build/libs/multitenant.jar
```

Create a PolicyDefinition on `first` tenant:

```shell
curl -X POST http://localhost:18183/management/v2/policydefinitions \
--header 'Content-Type: application/json' \
Expand All @@ -64,11 +72,14 @@ curl -X POST http://localhost:18183/management/v2/policydefinitions \
'
```

Get `first` tenant assets:
Get `first` tenant policy definitions:

```shell
curl -X POST http://localhost:18183/management/v2/policydefinitions/request
```

Will get a list containing the PolicyDefinition we created:

```json
[
{
Expand All @@ -94,16 +105,20 @@ Will get a list containing the PolicyDefinition we created:
]
```

`second` and `third` tenants will have no assets:
`second` and `third` tenants will have no policy definitions:

```shell
curl -X POST http://localhost:28183/management/v2/policydefinitions/request
```

and

```shell
curl -X POST http://localhost:38183/management/v2/policydefinitions/request
```

will return

```json
[]
```
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ private void bootTenant(Config tenantConfig) {
.map(this::toUrl)
.toArray(URL[]::new);

Thread runtimeThread = null;
try (var classLoader = URLClassLoader.newInstance(classPathEntries, getSystemClassLoader())) {
var runtimeThread = new Thread(() -> {
runtimeThread = new Thread(() -> {
try {
Thread.currentThread().setContextClassLoader(classLoader);
super.boot();
Expand All @@ -68,7 +69,10 @@ private void bootTenant(Config tenantConfig) {

runtimeThread.join(20_000);

} catch (InterruptedException | IOException e) {
} catch (InterruptedException e) {
runtimeThread.interrupt();
throw new EdcException(e);
} catch (IOException e) {
throw new EdcException(e);
} finally {
System.setProperties(baseProperties);
Expand All @@ -94,7 +98,7 @@ private URL toUrl(String entry) {
try {
return new File(entry).toURI().toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
throw new EdcException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - Initial implementation
*
*/

package org.eclipse.tractusx.edc.samples.multitenancy;

import org.eclipse.edc.spi.EdcException;
Expand Down

0 comments on commit 0520c96

Please sign in to comment.