From fa64519b7ae1b9fae846d367532b66713e7e88f7 Mon Sep 17 00:00:00 2001 From: Daniel Krueger Date: Tue, 17 Dec 2024 08:50:54 +0100 Subject: [PATCH] add version to config --- .../entity/HiveMQConfigEntity.java | 22 ++++++++++++++++--- .../migration/LegacyHiveMQConfigEntity.java | 5 ++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/HiveMQConfigEntity.java b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/HiveMQConfigEntity.java index 693817c13c..827f27a965 100644 --- a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/HiveMQConfigEntity.java +++ b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/HiveMQConfigEntity.java @@ -34,6 +34,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** * @author Dominik Obermaier @@ -44,6 +45,11 @@ @SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"}) public class HiveMQConfigEntity { + public static final int CURRENT_CONFIG_VERSION = 1; + + @XmlElement(name = "config-version", defaultValue = "" + CURRENT_CONFIG_VERSION) + private int version = CURRENT_CONFIG_VERSION; + @XmlElementWrapper(name = "mqtt-listeners", required = true) @XmlElementRef(required = false) private @NotNull List mqttListeners = new ArrayList<>(); @@ -95,11 +101,12 @@ public class HiveMQConfigEntity { private final @NotNull InternalConfigEntity internal = new InternalConfigEntity(); // no-arg constructor as JaxB does need one - public HiveMQConfigEntity(){ + public HiveMQConfigEntity() { } public HiveMQConfigEntity( + final @NotNull Integer version, final @NotNull AdminApiEntity api, final @NotNull DynamicConfigEntity gateway, final @NotNull Map moduleConfigs, @@ -114,6 +121,7 @@ public HiveMQConfigEntity( final @NotNull SecurityConfigEntity security, final @NotNull UnsConfigEntity uns, final @NotNull UsageTrackingConfigEntity usageTracking) { + this.version = Objects.requireNonNullElse(version, CURRENT_CONFIG_VERSION); this.api = api; this.gateway = gateway; this.moduleConfigs = moduleConfigs; @@ -174,9 +182,13 @@ public HiveMQConfigEntity( return moduleConfigs; } - public @NotNull UnsConfigEntity getUns() { return uns; } + public @NotNull UnsConfigEntity getUns() { + return uns; + } - public @NotNull DynamicConfigEntity getGatewayConfig() { return gateway;} + public @NotNull DynamicConfigEntity getGatewayConfig() { + return gateway; + } public @NotNull UsageTrackingConfigEntity getUsageTracking() { return usageTracking; @@ -185,4 +197,8 @@ public HiveMQConfigEntity( public @NotNull InternalConfigEntity getInternal() { return internal; } + + public int getVersion() { + return version; + } } diff --git a/hivemq-edge/src/main/java/com/hivemq/configuration/migration/LegacyHiveMQConfigEntity.java b/hivemq-edge/src/main/java/com/hivemq/configuration/migration/LegacyHiveMQConfigEntity.java index a2292d5942..fa5a9ea28f 100644 --- a/hivemq-edge/src/main/java/com/hivemq/configuration/migration/LegacyHiveMQConfigEntity.java +++ b/hivemq-edge/src/main/java/com/hivemq/configuration/migration/LegacyHiveMQConfigEntity.java @@ -44,6 +44,8 @@ import java.util.List; import java.util.Map; +import static com.hivemq.configuration.entity.HiveMQConfigEntity.CURRENT_CONFIG_VERSION; + /** * @author Dominik Obermaier * @author Lukas brandl @@ -165,7 +167,8 @@ public class LegacyHiveMQConfigEntity { final @NotNull HiveMQConfigEntity to( final @NotNull List adapterEntities) { - return new HiveMQConfigEntity(this.getApiConfig(), + return new HiveMQConfigEntity(CURRENT_CONFIG_VERSION, + this.getApiConfig(), this.getGatewayConfig(), this.getModuleConfigs(), this.getMqttConfig(),