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

[1.x] Import events from 3rd-party with respect for tenancy #1503

Merged
merged 4 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 16 additions & 16 deletions license-report.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# Dependencies of `io.spine:spine-client:1.9.0-SNAPSHOT.8`
# Dependencies of `io.spine:spine-client:1.9.0-SNAPSHOT.9`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -399,12 +399,12 @@
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Feb 03 15:42:45 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Tue Feb 07 12:37:58 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-core:1.9.0-SNAPSHOT.8`
# Dependencies of `io.spine:spine-core:1.9.0-SNAPSHOT.9`

## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
Expand Down Expand Up @@ -763,12 +763,12 @@ This report was generated on **Fri Feb 03 15:42:45 WET 2023** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Feb 03 15:42:45 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Tue Feb 07 12:37:58 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.tools:spine-model-assembler:1.9.0-SNAPSHOT.8`
# Dependencies of `io.spine.tools:spine-model-assembler:1.9.0-SNAPSHOT.9`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -1162,12 +1162,12 @@ This report was generated on **Fri Feb 03 15:42:45 WET 2023** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Feb 03 15:42:46 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Tue Feb 07 12:37:59 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.tools:spine-model-verifier:1.9.0-SNAPSHOT.8`
# Dependencies of `io.spine.tools:spine-model-verifier:1.9.0-SNAPSHOT.9`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -1627,12 +1627,12 @@ This report was generated on **Fri Feb 03 15:42:46 WET 2023** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Feb 03 15:42:46 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Tue Feb 07 12:38:00 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-server:1.9.0-SNAPSHOT.8`
# Dependencies of `io.spine:spine-server:1.9.0-SNAPSHOT.9`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -2039,12 +2039,12 @@ This report was generated on **Fri Feb 03 15:42:46 WET 2023** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Feb 03 15:42:47 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Tue Feb 07 12:38:00 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-testutil-client:1.9.0-SNAPSHOT.8`
# Dependencies of `io.spine:spine-testutil-client:1.9.0-SNAPSHOT.9`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -2493,12 +2493,12 @@ This report was generated on **Fri Feb 03 15:42:47 WET 2023** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Feb 03 15:42:50 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Tue Feb 07 12:38:03 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-testutil-core:1.9.0-SNAPSHOT.8`
# Dependencies of `io.spine:spine-testutil-core:1.9.0-SNAPSHOT.9`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -2947,12 +2947,12 @@ This report was generated on **Fri Feb 03 15:42:50 WET 2023** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Feb 03 15:42:52 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Tue Feb 07 12:38:05 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-testutil-server:1.9.0-SNAPSHOT.8`
# Dependencies of `io.spine:spine-testutil-server:1.9.0-SNAPSHOT.9`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -3445,4 +3445,4 @@ This report was generated on **Fri Feb 03 15:42:52 WET 2023** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Feb 03 15:42:56 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Tue Feb 07 12:38:09 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject.

<groupId>io.spine</groupId>
<artifactId>spine-core-java</artifactId>
<version>1.9.0-SNAPSHOT.8</version>
<version>1.9.0-SNAPSHOT.9</version>

<inceptionYear>2015</inceptionYear>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.spine.server.ContextAware;
import io.spine.server.ServerEnvironment;
import io.spine.server.event.EventDispatcher;
import io.spine.server.tenant.TenantAwareRunner;
import io.spine.server.transport.ChannelId;
import io.spine.server.transport.Publisher;
import io.spine.server.transport.PublisherHub;
Expand Down Expand Up @@ -245,7 +246,8 @@ void dispatchLocally(Event event) {
* Dispatches the given event via the local {@code EventBus} and observes the acknowledgement.
*/
void dispatchLocally(Event event, StreamObserver<Ack> ackObserver) {
bus.dispatch(event, ackObserver);
TenantAwareRunner.with(event.tenant())
.run(() -> bus.dispatch(event, ackObserver));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* @implSpec Note that a {@code ThirdPartyContext} sends a request for external messages to
* other contexts. The {@code ThirdPartyContext} never consumes external messages itself,
* but requires the other Bounded Contexts to send their requests, so that the publishing
* channels are open. Depending of the implementation of
* channels are open. Depending on the implementation of
* {@link io.spine.server.transport.TransportFactory transport}, creating
* a {@code ThirdPartyContext} may be an expensive operation. Thus, it is recommended that
* the instances of this class are reused and {@linkplain #close() closed} when they are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ void prepareContext() {
@AfterEach
void closeContext() throws Exception {
context.close();
ServerEnvironment
.instance()
.reset();
resetServerEnvironment();
}

@Test
Expand Down Expand Up @@ -213,11 +211,16 @@ void domesticSubscriber() {
@Test
@DisplayName("in a multitenant environment")
void multitenant() {
/* Getting rid of the class-level repositories and bounded contexts. */
resetServerEnvironment();

DocumentRepository documentRepository = new DocumentRepository();
BoundedContextBuilder
BoundedContext boundedContext = BoundedContextBuilder
.assumingTests(true)
.add(documentRepository)
.build();
assertThat(boundedContext.isMultitenant())
.isTrue();
UserId johnDoe = userId();
TenantId acmeCorp = TenantId
.newBuilder()
Expand Down Expand Up @@ -248,6 +251,12 @@ void multitenant() {
assertThat(cyberdyneDailyReport).isEmpty();
}

private static void resetServerEnvironment() {
ServerEnvironment
.instance()
.reset();
}

private static void postForSingleTenant(UserId actor, EventMessage event) {
try (ThirdPartyContext uploads = ThirdPartyContext.singleTenant("Imports")) {
uploads.emittedEvent(event, actor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
import io.spine.server.integration.PaperDocumentScanned;
import io.spine.server.route.EventRouting;

import java.util.Optional;
import java.util.Set;

import static io.spine.server.route.EventRoute.withId;

public class DocumentRepository extends AggregateRepository<DocumentId, DocumentAggregate> {
public final class DocumentRepository extends AggregateRepository<DocumentId, DocumentAggregate> {

@Override
protected void setupImportRouting(EventRouting<DocumentId> routing) {
Expand All @@ -45,7 +48,31 @@ protected void setupImportRouting(EventRouting<DocumentId> routing) {
@Override
protected void setupEventRouting(EventRouting<DocumentId> routing) {
super.setupEventRouting(routing);
routing.route(OpenOfficeDocumentUploaded.class,
(message, context) -> withId(message.getId()));
routing.route(OpenOfficeDocumentUploaded.class, (message, context) -> route(message));
}

/**
* Routes an external event to the instances of {@link DocumentAggregate}.
*
* <p>This method includes an explicit call to repository's {@code find(..)} method.
* This is done to ensure that even in multi-tenant environment such a call
* is available, meaning that the {@code TenantId} is present in scope
* of runtime execution context.
*
* <p>Corresponding tests are available
* in {@link io.spine.server.integration.IntegrationBrokerTest IntegrationBrokerTest}.
*
* @param event
* event to route
* @return set of identifiers
*/
private Set<DocumentId> route(OpenOfficeDocumentUploaded event) {
DocumentId id = event.getId();
Optional<DocumentAggregate> aggregate = find(id);
if (!aggregate.isPresent()) {
_debug().log("`Document` aggregate is not found by ID `%s`. " +
"Creating a new instance.", id);
}
return withId(id);
}
}
2 changes: 1 addition & 1 deletion version.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/**
* Version of this library.
*/
val coreJava = "1.9.0-SNAPSHOT.8"
val coreJava = "1.9.0-SNAPSHOT.9"

/**
* Versions of the Spine libraries that `core-java` depends on.
Expand Down