Skip to content

Commit

Permalink
eclipse-ditto#537 removed all code and configuration for suffixed col…
Browse files Browse the repository at this point in the history
…lections in thins and policies

Signed-off-by: krj1imb <johannes.schneider@bosch-si.com>
  • Loading branch information
krj1imb committed Oct 30, 2019
1 parent b3db20b commit fe436e5
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 951 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@
import org.eclipse.ditto.services.utils.health.status.StatusSupplierActor;
import org.eclipse.ditto.services.utils.metrics.config.MetricsConfig;
import org.eclipse.ditto.services.utils.metrics.prometheus.PrometheusReporterRoute;
import org.eclipse.ditto.services.utils.persistence.mongo.config.DefaultSuffixBuilderConfig;
import org.eclipse.ditto.services.utils.persistence.mongo.config.MongoDbConfig;
import org.eclipse.ditto.services.utils.persistence.mongo.config.SuffixBuilderConfig;
import org.eclipse.ditto.services.utils.persistence.mongo.config.WithMongoDbConfig;
import org.eclipse.ditto.services.utils.persistence.mongo.suffixes.NamespaceSuffixCollectionNames;
import org.eclipse.ditto.signals.commands.messages.MessageCommandSizeValidator;
import org.eclipse.ditto.signals.commands.policies.PolicyCommandSizeValidator;
import org.eclipse.ditto.signals.commands.things.ThingCommandSizeValidator;
Expand Down Expand Up @@ -222,7 +219,6 @@ public ActorSystem start() {
protected ActorSystem doStart() {
logRuntimeParameters();
final Config actorSystemConfig = appendDittoInfo(appendAkkaPersistenceMongoUriToRawConfig());
configureMongoDbSuffixBuilder();
startKamon();
final ActorSystem actorSystem = createActorSystem(actorSystemConfig);
initializeActorSystem(actorSystem);
Expand Down Expand Up @@ -250,13 +246,6 @@ private void logRuntimeParameters() {
logger.info("Available processors: <{}>.", Runtime.getRuntime().availableProcessors());
}

private void configureMongoDbSuffixBuilder() {
if (isServiceWithMongoDbConfig()) {
final SuffixBuilderConfig suffixBuilderConfig = DefaultSuffixBuilderConfig.of(rawConfig);
NamespaceSuffixCollectionNames.setSupportedPrefixes(suffixBuilderConfig.getSupportedPrefixes());
}
}

private void startKamon() {
final Config kamonConfig = ConfigFactory.load("kamon");
Kamon.reconfigure(kamonConfig);
Expand All @@ -278,7 +267,7 @@ private void startPrometheusReporter() {
prometheusReporter = new PrometheusReporter();
Kamon.addReporter(prometheusReporter);
logger.info("Successfully added Prometheus reporter to Kamon.");
} catch (final Throwable ex) {
} catch (final Exception ex) {
logger.error("Error while adding Prometheus reporter to Kamon.", ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private ConnectionPersistenceOperationsActor(final ActorRef pubSubMediator,
*
* @param pubSubMediator Akka pub-sub mediator.
* @param mongoDbConfig the MongoDB configuration settings.
* @param config configuration with info about event journal, snapshot store, suffix-builder and database.
* @param config configuration with info about event journal, snapshot store and database.
* @param persistenceOperationsConfig the persistence operations configuration settings.
* @return a Props object.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private PolicyPersistenceOperationsActor(final ActorRef pubSubMediator,
*
* @param pubSubMediator Akka pub-sub mediator.
* @param mongoDbConfig the MongoDB configuration settings.
* @param config Configuration with info about event journal, snapshot store, suffix-builder and database.
* @param config Configuration with info about event journal, snapshot store and database.
* @param persistenceOperationsConfig the persistence operations configuration settings.
* @return a Props object.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
package org.eclipse.ditto.services.policies.persistence.serializer;

import java.text.MessageFormat;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

Expand All @@ -40,7 +38,6 @@
import akka.actor.ExtendedActorSystem;
import akka.persistence.journal.EventAdapter;
import akka.persistence.journal.EventSeq;
import akka.persistence.journal.Tagged;

public abstract class AbstractPolicyMongoEventAdapter implements EventAdapter {

Expand Down Expand Up @@ -86,21 +83,13 @@ public Object toJournal(final Object event) {
final JsonObject jsonObject =
theEvent.toJson(schemaVersion, IS_REVISION.negate().and(FieldType.regularOrSpecial()));
final DittoBsonJson dittoBsonJson = DittoBsonJson.getInstance();
final Object bson = dittoBsonJson.parse(jsonObject);
final Set<String> readSubjects = calculateReadSubjects(theEvent);
return new Tagged(bson, readSubjects);
return dittoBsonJson.parse(jsonObject);
} else {
throw new IllegalArgumentException(
"Unable to toJournal a non-'PolicyEvent' object! Was: " + event.getClass());
}
}

private static Set<String> calculateReadSubjects(final Event<?> theEvent) {
return theEvent.getDittoHeaders().getReadSubjects().stream()
.map(rs -> "rs:" + rs)
.collect(Collectors.toSet());
}

@Override
public EventSeq fromJournal(final Object event, final String manifest) {
if (event instanceof BsonValue) {
Expand Down
12 changes: 0 additions & 12 deletions services/policies/starter/src/main/resources/policies.conf
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,6 @@ policy-snaps-persistence-dispatcher {

akka.contrib.persistence.mongodb.mongo {

suffix-builder {
separator = "@"
separator = ${?MONGO_COLLECTION_NAME_SUFFIX_SEPARATOR}
// set class="" to disable suffixing
class = "org.eclipse.ditto.services.utils.persistence.mongo.suffixes.NamespaceSuffixCollectionNames"
class = ${?MONGO_COLLECTION_NAME_SUFFIX_CLASS}
supported-prefixes = ["policy"]
}

suffix-drop-empty-collections = true
suffix-drop-empty-collections = ${?MONGO_COLLECTION_SUFFIX_DROP_EMPTY_COLLECTIONS}

collection-cache {
journal {
class = "org.eclipse.ditto.services.utils.persistence.mongo.DittoMongoCollectionCache"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,12 @@ public final class PolicyPersistenceOperationsActorIT extends MongoEventSourceIT

@Test
public void purgeNamespaceWithoutSuffix() {
assertPurgeNamespaceWithoutSuffix();
assertPurgeNamespace();
}

@Test
public void purgeNamespaceWithSuffix() {
assertPurgeNamespaceWithSuffix();
}

@Test
public void purgeEntitiesWithNamespaceWithoutSuffix() {
assertPurgeEntitiesWithNamespaceWithoutSuffix();
}

@Test
public void purgeEntitiesWithNamespaceWithSuffix() {
assertPurgeEntitiesWithNamespaceWithSuffix();
public void purgeEntitiesWithNamespace() {
assertPurgeEntitiesWithNamespace();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private ThingPersistenceOperationsActor(final ActorRef pubSubMediator,
*
* @param pubSubMediator Akka pub-sub mediator.
* @param mongoDbConfig the MongoDB configuration settings.
* @param config Configuration with info about event journal, snapshot store, suffix-builder and database.
* @param config Configuration with info about event journal, snapshot store and database.
* @param persistenceOperationsConfig the persistence operations config.
* @return a Props object.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -59,7 +57,6 @@
import akka.actor.ExtendedActorSystem;
import akka.persistence.journal.EventAdapter;
import akka.persistence.journal.EventSeq;
import akka.persistence.journal.Tagged;

/**
* EventAdapter for {@link Event}s persisted into akka-persistence event-journal. Converts Event to MongoDB
Expand Down Expand Up @@ -148,20 +145,12 @@ public Object toJournal(final Object event) {
// remove the policy entries from thing event payload
.remove(POLICY_IN_THING_EVENT_PAYLOAD);
final DittoBsonJson dittoBsonJson = DittoBsonJson.getInstance();
final Object bson = dittoBsonJson.parse(jsonObject);
final Set<String> readSubjects = calculateReadSubjects(theEvent);
return new Tagged(bson, readSubjects);
return dittoBsonJson.parse(jsonObject);
} else {
throw new IllegalArgumentException("Unable to toJournal a non-'Event' object! Was: " + event.getClass());
}
}

private Set<String> calculateReadSubjects(final Event<?> theEvent) {
return theEvent.getDittoHeaders().getReadSubjects().stream()
.map(rs -> "rs:" + rs)
.collect(Collectors.toSet());
}

@Override
public EventSeq fromJournal(final Object event, final String manifest) {
if (event instanceof BsonValue) {
Expand Down
12 changes: 0 additions & 12 deletions services/things/starter/src/main/resources/things.conf
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,6 @@ thing-snaps-persistence-dispatcher {

akka.contrib.persistence.mongodb.mongo {

suffix-builder {
separator = "@"
separator = ${?MONGO_COLLECTION_NAME_SUFFIX_SEPARATOR}
// set class = "" to disable suffixing
class = "org.eclipse.ditto.services.utils.persistence.mongo.suffixes.NamespaceSuffixCollectionNames"
class = ${?MONGO_COLLECTION_NAME_SUFFIX_CLASS}
supported-prefixes = ["thing"]
}

suffix-drop-empty-collections = true
suffix-drop-empty-collections = ${?MONGO_COLLECTION_SUFFIX_DROP_EMPTY_COLLECTIONS}

collection-cache {
journal {
class = "org.eclipse.ditto.services.utils.persistence.mongo.DittoMongoCollectionCache"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.eclipse.ditto.model.base.entity.id.EntityId;
import org.eclipse.ditto.model.base.headers.DittoHeaders;
import org.eclipse.ditto.model.policies.PolicyId;
import org.eclipse.ditto.model.things.Thing;
import org.eclipse.ditto.model.things.ThingId;
import org.eclipse.ditto.services.utils.persistence.mongo.ops.eventsource.MongoEventSourceITAssertions;
Expand Down Expand Up @@ -41,13 +42,8 @@
public final class ThingPersistenceOperationsActorIT extends MongoEventSourceITAssertions<ThingId> {

@Test
public void purgeNamespaceWithoutSuffix() {
assertPurgeNamespaceWithoutSuffix();
}

@Test
public void purgeNamespaceWithSuffix() {
assertPurgeNamespaceWithSuffix();
public void purgeNamespace() {
assertPurgeNamespace();
}

@Override
Expand All @@ -67,8 +63,10 @@ protected ThingId toEntityId(final EntityId entityId) {

@Override
protected Object getCreateEntityCommand(final ThingId id) {
return CreateThing.of(Thing.newBuilder().setId(id).setPolicyId(id.toString()).build(), null,
DittoHeaders.empty());
return CreateThing.of(Thing.newBuilder()
.setId(id)
.setPolicyId(PolicyId.of(id))
.build(), null, DittoHeaders.empty());
}

@Override
Expand Down

This file was deleted.

0 comments on commit fe436e5

Please sign in to comment.