Skip to content

Commit 5abcf4d

Browse files
committed
Final refactor
Signed-off-by: Aleksandar Stanchev <aleksandar.stanchev@bosch.com>
1 parent ec82e0c commit 5abcf4d

File tree

14 files changed

+608
-658
lines changed

14 files changed

+608
-658
lines changed

connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/ConnectivityRootActor.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.apache.pekko.cluster.sharding.ClusterSharding;
2323
import org.apache.pekko.cluster.sharding.ClusterShardingSettings;
2424
import org.apache.pekko.event.DiagnosticLoggingAdapter;
25+
import org.apache.pekko.cluster.singleton.ClusterSingletonProxy;
26+
import org.apache.pekko.cluster.singleton.ClusterSingletonProxySettings;
2527
import org.apache.pekko.japi.pf.DeciderBuilder;
2628
import org.eclipse.ditto.base.service.RootChildActorStarter;
2729
import org.eclipse.ditto.base.service.actors.DittoRootActor;
@@ -117,8 +119,7 @@ private ConnectivityRootActor(final ConnectivityConfig connectivityConfig,
117119
ConnectionPersistenceOperationsActor.props(pubSubMediator, connectivityConfig.getMongoDbConfig(),
118120
config, connectivityConfig.getPersistenceOperationsConfig()));
119121

120-
startChildActor(EncryptionMigrationActor.ACTOR_NAME,
121-
EncryptionMigrationActor.props(connectivityConfig));
122+
startEncryptionMigrationSingleton(actorSystem, connectivityConfig);
122123

123124
RootChildActorStarter.get(actorSystem, ScopedConfig.dittoExtension(config)).execute(getContext());
124125

@@ -154,6 +155,20 @@ protected PartialFunction<Throwable, SupervisorStrategy.Directive> getSupervisio
154155
}).build().orElse(super.getSupervisionDecider());
155156
}
156157

158+
private void startEncryptionMigrationSingleton(final ActorSystem actorSystem,
159+
final ConnectivityConfig connectivityConfig) {
160+
161+
final String managerName = EncryptionMigrationActor.ACTOR_NAME + "Singleton";
162+
final ActorRef singletonManager = startClusterSingletonActor(
163+
EncryptionMigrationActor.props(connectivityConfig), managerName);
164+
165+
final ClusterSingletonProxySettings proxySettings =
166+
ClusterSingletonProxySettings.create(actorSystem).withRole(CLUSTER_ROLE);
167+
final Props proxyProps = ClusterSingletonProxy.props(
168+
singletonManager.path().toStringWithoutAddress(), proxySettings);
169+
getContext().actorOf(proxyProps, EncryptionMigrationActor.ACTOR_NAME);
170+
}
171+
157172
private ActorRef startClusterSingletonActor(final Props props, final String name) {
158173
return ClusterUtil.startSingleton(getContext(), CLUSTER_ROLE, name, props);
159174
}

connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/config/DefaultFieldsEncryptionConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ private void validateConfiguration() {
5959
"Missing 'symmetrical-key'. It is mandatory when encryption is enabled for connections!");
6060
}
6161

62+
if (migrationBatchSize <= 0) {
63+
throw new DittoConfigError(
64+
"'migration.batch-size' must be greater than 0, was: " + migrationBatchSize);
65+
}
66+
if (migrationMaxDocumentsPerMinute < 0) {
67+
throw new DittoConfigError(
68+
"'migration.max-documents-per-minute' must be >= 0, was: " + migrationMaxDocumentsPerMinute);
69+
}
70+
6271
// If both keys are set, they must be different
6372
if (hasSymmetricalKey && hasOldKey && symmetricalKey.equals(oldSymmetricalKey)) {
6473
throw new DittoConfigError(

connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/config/FieldsEncryptionConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ enum ConfigValue implements KnownConfigValue {
128128
* This throttles the migration stream to avoid overwhelming the database.
129129
* 0 means no throttling.
130130
*/
131-
MIGRATION_MAX_DOCUMENTS_PER_MINUTE("migration.max-documents-per-minute", 100);
131+
MIGRATION_MAX_DOCUMENTS_PER_MINUTE("migration.max-documents-per-minute", 200);
132132

133133
private final String configPath;
134134
private final Object defaultValue;

connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/persistence/EncryptionMigrationActor.java

Lines changed: 325 additions & 532 deletions
Large diffs are not rendered by default.

connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/persistence/JsonFieldsEncryptor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private static JsonObject createPatch(final JsonPointer pointer, final String ol
157157

158158
private static String decryptValue(final String value, final String symmetricKey) {
159159
if (value.startsWith(ENCRYPTED_PREFIX)) {
160-
final String striped = value.replace(ENCRYPTED_PREFIX, "");
160+
final String striped = value.substring(ENCRYPTED_PREFIX.length());
161161
try {
162162
return EncryptorAesGcm.decryptWithPrefixIV(striped, symmetricKey);
163163
} catch (final Exception e) {
@@ -177,7 +177,7 @@ private static String decryptValueWithFallback(final String value, final String
177177
return value;
178178
}
179179

180-
final String stripped = value.replace(ENCRYPTED_PREFIX, "");
180+
final String stripped = value.substring(ENCRYPTED_PREFIX.length());
181181

182182
// Try current key first
183183
try {
@@ -189,6 +189,7 @@ private static String decryptValueWithFallback(final String value, final String
189189
try {
190190
return EncryptorAesGcm.decryptWithPrefixIV(stripped, oldSymmetricKey.get());
191191
} catch (final Exception oldKeyException) {
192+
oldKeyException.addSuppressed(currentKeyException);
192193
throw ConnectionConfigurationInvalidException.newBuilder(
193194
"Decryption of connection field failed with both current and old keys. " +
194195
"Verify that the configured encryption keys match the keys used to encrypt the data.")

connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/persistence/MigrateConnectionEncryption.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2026 Contributors to the Eclipse Foundation
33
*
44
* See the NOTICE file(s) distributed with this work for additional
55
* information regarding copyright ownership.

connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/persistence/MigrateConnectionEncryptionAbort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2026 Contributors to the Eclipse Foundation
33
*
44
* See the NOTICE file(s) distributed with this work for additional
55
* information regarding copyright ownership.

connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/persistence/MigrateConnectionEncryptionAbortResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2026 Contributors to the Eclipse Foundation
33
*
44
* See the NOTICE file(s) distributed with this work for additional
55
* information regarding copyright ownership.

connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/persistence/MigrateConnectionEncryptionResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2026 Contributors to the Eclipse Foundation
33
*
44
* See the NOTICE file(s) distributed with this work for additional
55
* information regarding copyright ownership.

connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/persistence/MigrateConnectionEncryptionStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2026 Contributors to the Eclipse Foundation
33
*
44
* See the NOTICE file(s) distributed with this work for additional
55
* information regarding copyright ownership.

0 commit comments

Comments
 (0)