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

System feature configuration #1115

Merged
merged 31 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
30d5ba2
Update config
dmdashenkov Jul 15, 2019
5f379e4
Fix alignment
dmdashenkov Jul 15, 2019
51d3847
Declare empty (NOP) implementations of storages
dmdashenkov Jul 15, 2019
6488aed
Delete empty implementations of storages
dmdashenkov Jul 15, 2019
02c75fa
Define system-aware storage factory
dmdashenkov Jul 15, 2019
d194cf3
Wrap storage factory into SystemAware impl
dmdashenkov Jul 15, 2019
4ac26d1
Configure system context features per BC
dmdashenkov Jul 15, 2019
cf71f69
Clean up
dmdashenkov Jul 15, 2019
a0f6de1
Fix CLI warnings
dmdashenkov Jul 15, 2019
d0e1cc7
Configure system context according to the required features
dmdashenkov Jul 15, 2019
4497347
Merge branch 'master' into system-storage
dmdashenkov Jul 16, 2019
22e4f47
Add a configuration to store system events
dmdashenkov Jul 16, 2019
3cac64d
Add tests for SystemFeatures
dmdashenkov Jul 16, 2019
1189513
Move `EmptyEventStore` to subpackage
dmdashenkov Jul 16, 2019
87f2562
Add tests for `EmptyEventStore`
dmdashenkov Jul 16, 2019
e9f6587
Add tests for `SystemAwareStorageFactory`
dmdashenkov Jul 16, 2019
75a29f8
Document SystemFeatures
dmdashenkov Jul 16, 2019
c1f2877
Move `SystemFeatures` into the system package
dmdashenkov Jul 16, 2019
5a1a0e5
Document new API of BoundedContextBuilder
dmdashenkov Jul 16, 2019
9629920
Document new API
dmdashenkov Jul 16, 2019
a3b590b
Document test utils
dmdashenkov Jul 16, 2019
82675bc
Add another test for SystemAwareStorageFactory
dmdashenkov Jul 16, 2019
47ddf00
Add tests for configuration of the system BC
dmdashenkov Jul 16, 2019
ee180fc
Merge branch 'master' into system-storage
dmdashenkov Jul 18, 2019
3a82c15
Rephrase doc
dmdashenkov Jul 18, 2019
2fc7934
Consistent class name spelling
dmdashenkov Jul 18, 2019
70294fa
Yet better doc for SystemFeatures
dmdashenkov Jul 18, 2019
8e55707
Update Gradle to 5.5.1
dmdashenkov Jul 18, 2019
9e58d21
Merge branch 'master' into system-storage
dmdashenkov Jul 18, 2019
571b9a1
Add equals/hashCode for SystemFeatures
dmdashenkov Jul 18, 2019
f6750db
Document `ContextSpec.storesEvents`
dmdashenkov Jul 18, 2019
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
2 changes: 1 addition & 1 deletion config
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 8 additions & 8 deletions license-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Jul 16 22:35:29 EEST 2019** 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 **Thu Jul 18 12:11:28 EEST 2019** 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).



Expand Down Expand Up @@ -873,7 +873,7 @@ This report was generated on **Tue Jul 16 22:35:29 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Jul 16 22:35:36 EEST 2019** 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 **Thu Jul 18 12:11:28 EEST 2019** 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).



Expand Down Expand Up @@ -1439,7 +1439,7 @@ This report was generated on **Tue Jul 16 22:35:36 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Jul 16 22:35:45 EEST 2019** 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 **Thu Jul 18 12:11:29 EEST 2019** 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).



Expand Down Expand Up @@ -2167,7 +2167,7 @@ This report was generated on **Tue Jul 16 22:35:45 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Jul 16 22:35:57 EEST 2019** 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 **Thu Jul 18 12:11:29 EEST 2019** 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).



Expand Down Expand Up @@ -2745,7 +2745,7 @@ This report was generated on **Tue Jul 16 22:35:57 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Jul 16 22:36:06 EEST 2019** 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 **Thu Jul 18 12:11:30 EEST 2019** 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).



Expand Down Expand Up @@ -3279,7 +3279,7 @@ This report was generated on **Tue Jul 16 22:36:06 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Jul 16 22:36:18 EEST 2019** 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 **Thu Jul 18 12:11:30 EEST 2019** 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).



Expand Down Expand Up @@ -3821,7 +3821,7 @@ This report was generated on **Tue Jul 16 22:36:18 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Jul 16 22:36:28 EEST 2019** 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 **Thu Jul 18 12:11:31 EEST 2019** 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).



Expand Down Expand Up @@ -4463,4 +4463,4 @@ This report was generated on **Tue Jul 16 22:36:28 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Jul 16 22:36:40 EEST 2019** 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 **Thu Jul 18 12:11:31 EEST 2019** 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).
44 changes: 37 additions & 7 deletions server/src/main/java/io/spine/server/BoundedContextBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.spine.annotation.Internal;
import io.spine.core.BoundedContextName;
import io.spine.core.BoundedContextNames;
import io.spine.logging.Logging;
import io.spine.server.aggregate.AggregateRootDirectory;
import io.spine.server.aggregate.InMemoryRootDirectory;
Expand All @@ -48,6 +47,7 @@
import io.spine.system.server.NoOpSystemClient;
import io.spine.system.server.SystemClient;
import io.spine.system.server.SystemContext;
import io.spine.system.server.SystemFeatures;
import io.spine.system.server.SystemReadSide;
import io.spine.system.server.SystemWriteSide;

Expand Down Expand Up @@ -91,10 +91,13 @@ public final class BoundedContextBuilder implements Logging {

private final IntegrationBus.Builder integrationBus = IntegrationBus.newBuilder();

private final SystemFeatures systemFeatures;

private Stand.Builder stand;
private Supplier<AggregateRootDirectory> rootDirectory;
private TenantIndex tenantIndex;


/** Repositories to be registered with the Bounded Context being built after its creation. */
private final Collection<Repository<?, ?>> repositories = new ArrayList<>();

Expand All @@ -107,7 +110,20 @@ public final class BoundedContextBuilder implements Logging {
* @see BoundedContext#multitenant
*/
BoundedContextBuilder(ContextSpec spec) {
this(spec, SystemFeatures.defaults());
}

/**
* Prevents direct instantiation.
*
* @param spec
* the context spec for the built context
* @see BoundedContext#singleTenant
* @see BoundedContext#multitenant
*/
private BoundedContextBuilder(ContextSpec spec, SystemFeatures systemFeatures) {
this.spec = checkNotNull(spec);
this.systemFeatures = checkNotNull(systemFeatures);
}

/**
Expand Down Expand Up @@ -476,6 +492,17 @@ AggregateRootDirectory aggregateRootDirectory() {
return this;
}

/**
* Obtains the system context feature configuration.
*
* <p>Users may enable or disable some features of the system context.
*
* @see SystemFeatures
*/
public SystemFeatures systemFeatures() {
return systemFeatures;
}

/**
* Creates a new instance of {@code BoundedContext} with the set configurations.
*
Expand Down Expand Up @@ -553,18 +580,21 @@ private BoundedContext buildDomain(SystemContext system) {
}

private SystemContext buildSystem() {
String name = BoundedContextNames.system(spec.name()).getValue();
boolean multitenant = isMultitenant();
BoundedContextBuilder system = multitenant
? BoundedContext.multitenant(name)
: BoundedContext.singleTenant(name);
BoundedContextBuilder system = new BoundedContextBuilder(systemSpec(), systemFeatures);
Optional<? extends TenantIndex> tenantIndex = tenantIndex();
tenantIndex.ifPresent(system::setTenantIndex);

SystemContext result =
system.buildPartial(SystemContext::newInstance, NoOpSystemClient.INSTANCE);
return result;
}

private ContextSpec systemSpec() {
ContextSpec systemSpec = this.spec.toSystem();
if (!systemFeatures.includePersistentEvents()) {
systemSpec = systemSpec.notStoringEvents();
}
return systemSpec;
}

private <B extends BoundedContext>
B buildPartial(Function<BoundedContextBuilder, B> instanceFactory, SystemClient client) {
Expand Down
36 changes: 31 additions & 5 deletions server/src/main/java/io/spine/server/ContextSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import io.spine.annotation.Internal;
import io.spine.annotation.SPI;
import io.spine.core.BoundedContextName;
import io.spine.core.BoundedContextNames;

import static com.google.common.base.Preconditions.checkNotNull;
import static io.spine.core.BoundedContextNames.newName;
Expand All @@ -38,32 +40,34 @@ public final class ContextSpec {

private final BoundedContextName name;
private final boolean multitenant;
private final boolean storeEvents;

private ContextSpec(BoundedContextName name, boolean multitenant) {
private ContextSpec(BoundedContextName name, boolean multitenant, boolean storeEvents) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The storeEvents parameter looks weird and not native for a regular BoundedContext. What a context does not store events? It can be equally named isSystem... :) This looks like the idea of context hierarchy and its properties leaked into here.

this.name = checkNotNull(name);
this.multitenant = multitenant;
this.storeEvents = storeEvents;
}

/**
* Creates a spec of a single tenant context with the given name.
*/
@VisibleForTesting
public static ContextSpec singleTenant(String name) {
return create(name, false);
return createDomain(name, false);
}

/**
* Creates a spec of a multitenant context with the given name.
*/
@VisibleForTesting
public static ContextSpec multitenant(String name) {
return create(name, true);
return createDomain(name, true);
}

private static ContextSpec create(String name, boolean multitenant) {
private static ContextSpec createDomain(String name, boolean multitenant) {
checkNotNull(name);
BoundedContextName contextName = newName(name);
return new ContextSpec(contextName, multitenant);
return new ContextSpec(contextName, multitenant, true);
}

/**
Expand All @@ -80,6 +84,28 @@ public boolean isMultitenant() {
return multitenant;
}

/**
* Checks if the specified context stores its event log.
*
* <p>All domain-specific contexts store their events. A System context may be configured
* to store or not to store its events.
*
* @return {@code true} if the context persists its event log, {@code false otherwise}
*/
@Internal
public boolean storesEvents() {
return storeEvents;
}

ContextSpec toSystem() {
BoundedContextName systemName = BoundedContextNames.system(name);
return new ContextSpec(systemName, multitenant, storeEvents);
}

ContextSpec notStoringEvents() {
return new ContextSpec(name, multitenant, false);
}

/**
* Returns a single-tenant version of this instance, if it is multitenant, or
* this instance if it is single-tenant.
Expand Down
8 changes: 5 additions & 3 deletions server/src/main/java/io/spine/server/ServerEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.emptyToNull;
import static io.spine.server.storage.system.SystemAwareStorageFactory.wrap;

/**
* The server conditions and configuration under which the application operates.
Expand Down Expand Up @@ -243,7 +244,7 @@ public void configureStorage(StorageFactory productionStorageFactory) {
"%s cannot be used for production storage.",
InMemoryStorageFactory.class.getName()
);
this.productionStorageFactory = productionStorageFactory;
this.productionStorageFactory = wrap(productionStorageFactory);
}

/**
Expand All @@ -252,7 +253,8 @@ public void configureStorage(StorageFactory productionStorageFactory) {
* @see #configureStorage(StorageFactory)
*/
public void configureStorageForTests(StorageFactory factory) {
this.storageFactoryForTests = checkNotNull(factory);
checkNotNull(factory);
this.storageFactoryForTests = wrap(factory);
}

/**
Expand Down Expand Up @@ -280,7 +282,7 @@ public Optional<TracerFactory> tracing() {
public StorageFactory storageFactory() {
if (environment().isTests()) {
if (storageFactoryForTests == null) {
this.storageFactoryForTests = InMemoryStorageFactory.newInstance();
configureStorageForTests(InMemoryStorageFactory.newInstance());
}
return storageFactoryForTests;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ private static AggregateEventRecord toStorageRecord(Snapshot snapshot) {
* the read request
* @return new iterator instance
*/
protected abstract Iterator<AggregateEventRecord> historyBackward(
AggregateReadRequest<I> request);
protected abstract Iterator<AggregateEventRecord>
historyBackward(AggregateReadRequest<I> request);

/**
* Truncates the storage, dropping all records which occur before the Nth snapshot for each
Expand Down
3 changes: 2 additions & 1 deletion server/src/main/java/io/spine/server/bus/Bus.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,12 @@ public FilterChain<E> get() {
private FilterChain<E> buildChain() {
Collection<BusFilter<E>> tail = filterChainTail();
tail.forEach(chainBuilder::append);

BusFilter<E> deadMsgFilter = new DeadMessageFilter<>(deadMessageHandler(), registry());
BusFilter<E> validatingFilter = new ValidatingFilter<>(validator());

chainBuilder.prepend(deadMsgFilter);
chainBuilder.prepend(validatingFilter);

Collection<BusFilter<E>> head = filterChainHead();
head.forEach(chainBuilder::prepend);

Expand Down
19 changes: 0 additions & 19 deletions server/src/main/java/io/spine/server/event/EventBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,23 +385,4 @@ public UnsupportedEventException handle(EventEnvelope event) {
return exception;
}
}

/**
* Ensures that the passed object has a valid reference to {@code EventBus}.
*
* @param holder
* the object which holds the reference
* @param value
* the value of the reference to check
* @return the passed value, if it's not null
* @throws NullPointerException
* if the passed value is null
*/
public static EventBus checkAssigned(Object holder, @Nullable EventBus value) {
return checkNotNull(
value,
"`%s` does not have `EventBus` assigned.",
holder
);
}
}
Loading