From a343bb4d455b9fcd708d5d00d7bd7e5fd2362f31 Mon Sep 17 00:00:00 2001 From: Daniel Krueger Date: Tue, 17 Dec 2024 08:50:54 +0100 Subject: [PATCH 1/7] 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(), From 6bea7c95a6ccd73d05f1641ea4c6f0cf41c68b5a Mon Sep 17 00:00:00 2001 From: Daniel Krueger Date: Tue, 17 Dec 2024 09:11:09 +0100 Subject: [PATCH 2/7] add version field to config.xsd --- hivemq-edge/src/main/resources/config.xsd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hivemq-edge/src/main/resources/config.xsd b/hivemq-edge/src/main/resources/config.xsd index 14bdbf6819..9ac8f6fe2c 100644 --- a/hivemq-edge/src/main/resources/config.xsd +++ b/hivemq-edge/src/main/resources/config.xsd @@ -23,6 +23,7 @@ + @@ -861,7 +862,7 @@ From b69e15bd1e07b1c4c0ae0db62da2d7bc852733ab Mon Sep 17 00:00:00 2001 From: Daniel Krueger Date: Tue, 17 Dec 2024 09:21:35 +0100 Subject: [PATCH 3/7] update test-config.xml --- hivemq-edge/src/test/resources/test-config.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/hivemq-edge/src/test/resources/test-config.xml b/hivemq-edge/src/test/resources/test-config.xml index 9b625bdd1f..50807ec110 100644 --- a/hivemq-edge/src/test/resources/test-config.xml +++ b/hivemq-edge/src/test/resources/test-config.xml @@ -1,5 +1,6 @@ + 1 1883 From fda5f584732b710a66eaa46ba5d7b5ac8cf82c64 Mon Sep 17 00:00:00 2001 From: Daniel Krueger Date: Thu, 19 Dec 2024 13:31:56 +0100 Subject: [PATCH 4/7] add config version to all adapters --- .../impl/ProtocolAdaptersResourceImpl.java | 1 + .../entity/adapter/ProtocolAdapterEntity.java | 20 +++++++++++++++---- .../migration/ConfigurationMigrator.java | 4 +++- .../SimulationProtocolAdapterInformation.java | 9 ++++++++- .../protocols/ProtocolAdapterConfig.java | 7 +++++++ .../ProtocolAdapterConfigConverter.java | 4 +++- .../protocols/ProtocolAdapterManager.java | 8 +++++++- .../protocols/ProtocolAdapterManagerTest.java | 5 +++++ .../EipProtocolAdapterInformation.java | 6 ++++++ .../file/FileProtocolAdapterInformation.java | 10 +++++++++- .../http/HttpProtocolAdapterInformation.java | 8 +++++++- .../ModbusProtocolAdapterInformation.java | 6 ++++++ .../OpcUaProtocolAdapterInformation.java | 9 ++++++++- .../ads/ADSProtocolAdapterInformation.java | 11 ++++++++-- .../siemens/S7ProtocolAdapterInformation.java | 8 +++++++- 15 files changed, 102 insertions(+), 14 deletions(-) diff --git a/hivemq-edge/src/main/java/com/hivemq/api/resources/impl/ProtocolAdaptersResourceImpl.java b/hivemq-edge/src/main/java/com/hivemq/api/resources/impl/ProtocolAdaptersResourceImpl.java index 9bf2c37b2d..747d15f4a8 100644 --- a/hivemq-edge/src/main/java/com/hivemq/api/resources/impl/ProtocolAdaptersResourceImpl.java +++ b/hivemq-edge/src/main/java/com/hivemq/api/resources/impl/ProtocolAdaptersResourceImpl.java @@ -696,6 +696,7 @@ protected void validateAdapterSchema( protocolAdapterManager.addAdapter(new ProtocolAdapterConfig(adapterId, adapterType, + protocolAdapterInformation.get().getCurrentConfigVersion(), protocolSpecificAdapterConfig, southboundMappings, northboundMappings, diff --git a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java index 6a25e0dcb4..8dd941682b 100644 --- a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java +++ b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java @@ -18,8 +18,9 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.hivemq.configuration.reader.ArbitraryValuesMapAdapter; -import org.jetbrains.annotations.NotNull; import com.hivemq.protocols.ProtocolAdapterConfig; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.xml.bind.ValidationEvent; import javax.xml.bind.annotation.XmlElement; @@ -41,6 +42,9 @@ public class ProtocolAdapterEntity { @XmlElement(name = "protocolId", required = true) private @NotNull String protocolId; + @XmlElement(name = "protocolId") + private @NotNull Integer configVersion; + @XmlElement(name = "config") @XmlJavaTypeAdapter(ArbitraryValuesMapAdapter.class) private @NotNull Map config = new HashMap<>(); @@ -65,12 +69,15 @@ public ProtocolAdapterEntity() { public ProtocolAdapterEntity( final @NotNull String adapterId, final @NotNull String protocolId, + final @Nullable Integer configVersion, final @NotNull Map config, final @NotNull List northboundMappingEntities, final @NotNull List southboundMappingEntities, final @NotNull List tags) { this.adapterId = adapterId; this.config = config; + // if no config version is present, we assume it is the oldest possible version + this.configVersion = configVersion != null ? configVersion : 1; this.northboundMappingEntities = northboundMappingEntities; this.protocolId = protocolId; this.tags = tags; @@ -101,6 +108,10 @@ public ProtocolAdapterEntity( return adapterId; } + public @NotNull Integer getConfigVersion() { + return configVersion; + } + public void validate(final @NotNull List validationEvents) { if (adapterId == null || adapterId.isEmpty()) { validationEvents.add(new ValidationEventImpl(ValidationEvent.FATAL_ERROR, "adapterId is missing", null)); @@ -130,16 +141,17 @@ public void validate(final @NotNull List validationEvents) { .collect(Collectors.toList()); final List tagEntities = protocolAdapterConfig.getTags() - .stream().map(tag -> TagEntity.fromAdapterTag(tag, objectMapper)) + .stream() + .map(tag -> TagEntity.fromAdapterTag(tag, objectMapper)) .collect(Collectors.toList()); final Map configAsMaps = objectMapper.convertValue(protocolAdapterConfig.getAdapterConfig(), new TypeReference<>() { }); - return new ProtocolAdapterEntity( - protocolAdapterConfig.getAdapterId(), + return new ProtocolAdapterEntity(protocolAdapterConfig.getAdapterId(), protocolAdapterConfig.getProtocolId(), + protocolAdapterConfig.getConfigVersion(), configAsMaps, northboundMappings, southboundMappings, diff --git a/hivemq-edge/src/main/java/com/hivemq/configuration/migration/ConfigurationMigrator.java b/hivemq-edge/src/main/java/com/hivemq/configuration/migration/ConfigurationMigrator.java index c627fdc2a5..082d1a031f 100644 --- a/hivemq-edge/src/main/java/com/hivemq/configuration/migration/ConfigurationMigrator.java +++ b/hivemq-edge/src/main/java/com/hivemq/configuration/migration/ConfigurationMigrator.java @@ -89,7 +89,8 @@ public ConfigurationMigrator( @VisibleForTesting public ConfigurationMigrator( - final @NotNull ConfigurationFile configurationFile, final @NotNull ModuleLoader moduleLoader) { + final @NotNull ConfigurationFile configurationFile, + final @NotNull ModuleLoader moduleLoader) { this.moduleLoader = moduleLoader; moduleLoader.loadModules(); this.configurationFile = configurationFile; @@ -188,6 +189,7 @@ public Optional migrateIfNeeded(final Map() { }), northboundMappingEntities, diff --git a/hivemq-edge/src/main/java/com/hivemq/edge/modules/adapters/simulation/SimulationProtocolAdapterInformation.java b/hivemq-edge/src/main/java/com/hivemq/edge/modules/adapters/simulation/SimulationProtocolAdapterInformation.java index d4a21f7ac8..4c4f8fe7ae 100644 --- a/hivemq-edge/src/main/java/com/hivemq/edge/modules/adapters/simulation/SimulationProtocolAdapterInformation.java +++ b/hivemq-edge/src/main/java/com/hivemq/edge/modules/adapters/simulation/SimulationProtocolAdapterInformation.java @@ -36,9 +36,11 @@ public class SimulationProtocolAdapterInformation implements ProtocolAdapterInformation { + public static final ProtocolAdapterInformation INSTANCE = new SimulationProtocolAdapterInformation(); + private static final Logger log = LoggerFactory.getLogger(SimulationProtocolAdapterInformation.class); - public static final ProtocolAdapterInformation INSTANCE = new SimulationProtocolAdapterInformation(); + public static final int CURRENT_CONFIG_VERSION = 1; private SimulationProtocolAdapterInformation() { } @@ -114,6 +116,11 @@ public ProtocolAdapterCategory getCategory() { } } + @Override + public int getCurrentConfigVersion() { + return CURRENT_CONFIG_VERSION; + } + @Override public @NotNull Class tagConfigurationClass() { diff --git a/hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterConfig.java b/hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterConfig.java index 90d59be3de..361bd1634b 100644 --- a/hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterConfig.java +++ b/hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterConfig.java @@ -32,18 +32,21 @@ public class ProtocolAdapterConfig { private final @NotNull List tags; private final @NotNull String adapterId; private final @NotNull String protocolId; + private final int configVersion; private final @NotNull List southboundMappings; private final @NotNull List northboundMappings; public ProtocolAdapterConfig( final @NotNull String adapterId, final @NotNull String protocolId, + final int configVersion, final @NotNull ProtocolSpecificAdapterConfig protocolSpecificConfig, final @NotNull List southboundMappings, final @NotNull List northboundMappings, final @NotNull List tags) { this.adapterId = adapterId; this.protocolId = protocolId; + this.configVersion = configVersion; this.southboundMappings = southboundMappings; this.northboundMappings = northboundMappings; this.adapterConfig = protocolSpecificConfig; @@ -90,4 +93,8 @@ public ProtocolAdapterConfig( public @NotNull List getToEdgeMappings() { return southboundMappings; } + + public int getConfigVersion() { + return configVersion; + } } diff --git a/hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterConfigConverter.java b/hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterConfigConverter.java index f1ae32b99d..aff646c60b 100644 --- a/hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterConfigConverter.java +++ b/hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterConfigConverter.java @@ -77,7 +77,9 @@ public ProtocolAdapterConfigConverter( return new ProtocolAdapterConfig(protocolAdapterEntity.getAdapterId(), protocolAdapterEntity.getProtocolId(), - protocolSpecificAdapterConfig, southboundMappingList, + protocolAdapterEntity.getConfigVersion(), + protocolSpecificAdapterConfig, + southboundMappingList, northboundMappingList, tags); } diff --git a/hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterManager.java b/hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterManager.java index 001ed39168..706e1be6d2 100644 --- a/hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterManager.java +++ b/hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterManager.java @@ -421,7 +421,8 @@ protected void handleStartupError( Preconditions.checkNotNull(adapterId); Preconditions.checkNotNull(config); - if (getAdapterTypeById(adapterType).isEmpty()) { + final Optional adapterInformationOptional = getAdapterTypeById(adapterType); + if (adapterInformationOptional.isEmpty()) { throw new IllegalArgumentException("invalid adapter type '" + adapterType + "'"); } if (getAdapterById(adapterId).isPresent()) { @@ -436,6 +437,7 @@ protected void handleStartupError( final ProtocolAdapterConfig protocolAdapterConfig = new ProtocolAdapterConfig( adapterId, adapterType, + adapterInformationOptional.get().getCurrentConfigVersion(), protocolSpecificAdapterConfig, List.of(), List.of(), @@ -498,6 +500,7 @@ public boolean updateAdapterConfig( final ProtocolAdapterConfig protocolAdapterConfig = new ProtocolAdapterConfig(adapterId, adapterType, + oldInstance.getAdapterInformation().getCurrentConfigVersion(), protocolSpecificAdapterConfig, oldInstance.getToEdgeMappings(), oldInstance.getFromEdgeMappings(), @@ -516,6 +519,7 @@ public boolean updateAdapterTags(final @NotNull String adapterId, final @NotNull final String protocolId = oldInstance.getAdapterInformation().getProtocolId(); final ProtocolAdapterConfig protocolAdapterConfig = new ProtocolAdapterConfig(oldInstance.getId(), protocolId, + oldInstance.getAdapterInformation().getCurrentConfigVersion(), oldInstance.getConfigObject(), oldInstance.getToEdgeMappings(), oldInstance.getFromEdgeMappings(), @@ -533,6 +537,7 @@ public boolean updateAdapterFromMappings(final @NotNull String adapterId, final final String protocolId = oldInstance.getAdapterInformation().getProtocolId(); final ProtocolAdapterConfig protocolAdapterConfig = new ProtocolAdapterConfig(oldInstance.getId(), protocolId, + oldInstance.getAdapterInformation().getCurrentConfigVersion(), oldInstance.getConfigObject(), oldInstance.getToEdgeMappings(), northboundMappings, oldInstance.getTags()); @@ -556,6 +561,7 @@ public boolean updateAdapterToMappings(final @NotNull String adapterId, final @N final String protocolId = oldInstance.getAdapterInformation().getProtocolId(); final ProtocolAdapterConfig protocolAdapterConfig = new ProtocolAdapterConfig(oldInstance.getId(), protocolId, + oldInstance.getAdapterInformation().getCurrentConfigVersion(), oldInstance.getConfigObject(), southboundMappings, oldInstance.getFromEdgeMappings(), oldInstance.getTags()); diff --git a/hivemq-edge/src/test/java/com/hivemq/protocols/ProtocolAdapterManagerTest.java b/hivemq-edge/src/test/java/com/hivemq/protocols/ProtocolAdapterManagerTest.java index a83fd41a41..d9b86256be 100644 --- a/hivemq-edge/src/test/java/com/hivemq/protocols/ProtocolAdapterManagerTest.java +++ b/hivemq-edge/src/test/java/com/hivemq/protocols/ProtocolAdapterManagerTest.java @@ -338,6 +338,11 @@ static class TestWritingProtocolAdapterInformation implements ProtocolAdapterInf public @org.jetbrains.annotations.NotNull Class configurationClassNorthAndSouthbound() { return null; } + + @Override + public int getCurrentConfigVersion() { + return 1; + } } static class TestWritingAdapter implements WritingProtocolAdapter { diff --git a/modules/hivemq-edge-module-etherip/src/main/java/com/hivemq/edge/adapters/etherip/EipProtocolAdapterInformation.java b/modules/hivemq-edge-module-etherip/src/main/java/com/hivemq/edge/adapters/etherip/EipProtocolAdapterInformation.java index 91c1e3e55a..2024b16c78 100644 --- a/modules/hivemq-edge-module-etherip/src/main/java/com/hivemq/edge/adapters/etherip/EipProtocolAdapterInformation.java +++ b/modules/hivemq-edge-module-etherip/src/main/java/com/hivemq/edge/adapters/etherip/EipProtocolAdapterInformation.java @@ -40,6 +40,7 @@ public class EipProtocolAdapterInformation implements ProtocolAdapterInformation public static final @NotNull ProtocolAdapterInformation INSTANCE = new EipProtocolAdapterInformation(); private static final @NotNull Logger log = LoggerFactory.getLogger(EipProtocolAdapterInformation.class); public static final String PROTOCOL_ID = "eip"; + private static final int CURRENT_CONFIG_VERSION = 1; private EipProtocolAdapterInformation() { } @@ -137,4 +138,9 @@ public List getTags() { public @NotNull Class configurationClassNorthAndSouthbound() { return EipSpecificAdapterConfig.class; } + + @Override + public int getCurrentConfigVersion() { + return CURRENT_CONFIG_VERSION; + } } diff --git a/modules/hivemq-edge-module-file/src/main/java/com/hivemq/edge/adapters/file/FileProtocolAdapterInformation.java b/modules/hivemq-edge-module-file/src/main/java/com/hivemq/edge/adapters/file/FileProtocolAdapterInformation.java index 504297cb2a..431c92e5e6 100644 --- a/modules/hivemq-edge-module-file/src/main/java/com/hivemq/edge/adapters/file/FileProtocolAdapterInformation.java +++ b/modules/hivemq-edge-module-file/src/main/java/com/hivemq/edge/adapters/file/FileProtocolAdapterInformation.java @@ -38,9 +38,12 @@ public class FileProtocolAdapterInformation implements ProtocolAdapterInformation { public static final @NotNull ProtocolAdapterInformation INSTANCE = new FileProtocolAdapterInformation(); - private static final @NotNull Logger LOG = LoggerFactory.getLogger(FileProtocolAdapterInformation.class); public static final String PROTOCOL_ID = "file"; + private static final @NotNull Logger LOG = LoggerFactory.getLogger(FileProtocolAdapterInformation.class); + private static final int CURRENT_CONFIG_VERSION = 1; + + protected FileProtocolAdapterInformation() { } @@ -135,4 +138,9 @@ public List getTags() { public @NotNull Class configurationClassNorthAndSouthbound() { return FileSpecificAdapterConfig.class; } + + @Override + public int getCurrentConfigVersion() { + return CURRENT_CONFIG_VERSION; + } } diff --git a/modules/hivemq-edge-module-http/src/main/java/com/hivemq/edge/adapters/http/HttpProtocolAdapterInformation.java b/modules/hivemq-edge-module-http/src/main/java/com/hivemq/edge/adapters/http/HttpProtocolAdapterInformation.java index 17427012ef..2bd594563b 100644 --- a/modules/hivemq-edge-module-http/src/main/java/com/hivemq/edge/adapters/http/HttpProtocolAdapterInformation.java +++ b/modules/hivemq-edge-module-http/src/main/java/com/hivemq/edge/adapters/http/HttpProtocolAdapterInformation.java @@ -39,10 +39,11 @@ */ public class HttpProtocolAdapterInformation implements ProtocolAdapterInformation { - private static final @NotNull Logger log = LoggerFactory.getLogger(HttpProtocolAdapterInformation.class); public static final ProtocolAdapterInformation INSTANCE = new HttpProtocolAdapterInformation(); public static final String PROTOCOL_ID = "http"; + private static final @NotNull Logger log = LoggerFactory.getLogger(HttpProtocolAdapterInformation.class); + private static final int CURRENT_CONFIG_VERSION = 1; protected HttpProtocolAdapterInformation() { } @@ -132,4 +133,9 @@ public List getTags() { public @NotNull Class configurationClassNorthAndSouthbound() { return HttpSpecificAdapterConfig.class; } + + @Override + public int getCurrentConfigVersion() { + return CURRENT_CONFIG_VERSION; + } } diff --git a/modules/hivemq-edge-module-modbus/src/main/java/com/hivemq/edge/adapters/modbus/ModbusProtocolAdapterInformation.java b/modules/hivemq-edge-module-modbus/src/main/java/com/hivemq/edge/adapters/modbus/ModbusProtocolAdapterInformation.java index 347e53d400..5543d9ac1f 100644 --- a/modules/hivemq-edge-module-modbus/src/main/java/com/hivemq/edge/adapters/modbus/ModbusProtocolAdapterInformation.java +++ b/modules/hivemq-edge-module-modbus/src/main/java/com/hivemq/edge/adapters/modbus/ModbusProtocolAdapterInformation.java @@ -37,6 +37,7 @@ public class ModbusProtocolAdapterInformation implements ProtocolAdapterInformat public static final ProtocolAdapterInformation INSTANCE = new ModbusProtocolAdapterInformation(); private static final @NotNull Logger log = LoggerFactory.getLogger(ModbusProtocolAdapterInformation.class); public static final @NotNull String PROTOCOL_ID = "modbus"; + private static final int CURRENT_CONFIG_VERSION = 1; protected ModbusProtocolAdapterInformation() { } @@ -107,6 +108,11 @@ public List getTags() { } } + @Override + public int getCurrentConfigVersion() { + return CURRENT_CONFIG_VERSION; + } + @Override public @NotNull Class tagConfigurationClass() { return ModbusTag.class; diff --git a/modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/OpcUaProtocolAdapterInformation.java b/modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/OpcUaProtocolAdapterInformation.java index 4460ad8c9c..3e0986c8e1 100644 --- a/modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/OpcUaProtocolAdapterInformation.java +++ b/modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/OpcUaProtocolAdapterInformation.java @@ -38,9 +38,11 @@ public class OpcUaProtocolAdapterInformation implements ProtocolAdapterInformation{ public static final ProtocolAdapterInformation INSTANCE = new OpcUaProtocolAdapterInformation(); - private static final @NotNull Logger log = LoggerFactory.getLogger(OpcUaProtocolAdapterInformation.class); public static final String PROTOCOL_ID = "opcua"; + private static final @NotNull Logger log = LoggerFactory.getLogger(OpcUaProtocolAdapterInformation.class); + private static final int CURRENT_CONFIG_VERSION = 1; + private OpcUaProtocolAdapterInformation() { } @@ -136,4 +138,9 @@ private OpcUaProtocolAdapterInformation() { public @NotNull Class configurationClassNorthAndSouthbound() { return BidirectionalOpcUaSpecificAdapterConfig.class; } + + @Override + public int getCurrentConfigVersion() { + return CURRENT_CONFIG_VERSION; + } } diff --git a/modules/hivemq-edge-module-plc4x/src/main/java/com/hivemq/edge/adapters/plc4x/types/ads/ADSProtocolAdapterInformation.java b/modules/hivemq-edge-module-plc4x/src/main/java/com/hivemq/edge/adapters/plc4x/types/ads/ADSProtocolAdapterInformation.java index b3f645d3ea..15b3e35ccd 100644 --- a/modules/hivemq-edge-module-plc4x/src/main/java/com/hivemq/edge/adapters/plc4x/types/ads/ADSProtocolAdapterInformation.java +++ b/modules/hivemq-edge-module-plc4x/src/main/java/com/hivemq/edge/adapters/plc4x/types/ads/ADSProtocolAdapterInformation.java @@ -37,11 +37,13 @@ /** * @author HiveMQ Adapter Generator */ -public class ADSProtocolAdapterInformation - implements ProtocolAdapterInformation { +public class ADSProtocolAdapterInformation implements ProtocolAdapterInformation { public static final ProtocolAdapterInformation INSTANCE = new ADSProtocolAdapterInformation(); + private static final @NotNull Logger log = LoggerFactory.getLogger(ADSProtocolAdapterInformation.class); + private static final int CURRENT_CONFIG_VERSION = 1; + protected ADSProtocolAdapterInformation() { } @@ -134,4 +136,9 @@ public List getTags() { public @NotNull Class configurationClassNorthAndSouthbound() { return ADSSpecificAdapterConfig.class; } + + @Override + public int getCurrentConfigVersion() { + return CURRENT_CONFIG_VERSION; + } } diff --git a/modules/hivemq-edge-module-plc4x/src/main/java/com/hivemq/edge/adapters/plc4x/types/siemens/S7ProtocolAdapterInformation.java b/modules/hivemq-edge-module-plc4x/src/main/java/com/hivemq/edge/adapters/plc4x/types/siemens/S7ProtocolAdapterInformation.java index c5c87c5b25..ed5c858ab9 100644 --- a/modules/hivemq-edge-module-plc4x/src/main/java/com/hivemq/edge/adapters/plc4x/types/siemens/S7ProtocolAdapterInformation.java +++ b/modules/hivemq-edge-module-plc4x/src/main/java/com/hivemq/edge/adapters/plc4x/types/siemens/S7ProtocolAdapterInformation.java @@ -40,9 +40,10 @@ public class S7ProtocolAdapterInformation implements ProtocolAdapterInformation { public static final ProtocolAdapterInformation INSTANCE = new S7ProtocolAdapterInformation(); - private static final @NotNull Logger log = LoggerFactory.getLogger(S7ProtocolAdapterInformation.class); public static final String PROTOCOL_ID = "s7"; + private static final @NotNull Logger log = LoggerFactory.getLogger(S7ProtocolAdapterInformation.class); + private static final int CURRENT_CONFIG_VERSION = 1; protected S7ProtocolAdapterInformation() { } @@ -135,4 +136,9 @@ public List getTags() { public @NotNull Class configurationClassNorthAndSouthbound() { return S7SpecificAdapterConfig.class; } + + @Override + public int getCurrentConfigVersion() { + return CURRENT_CONFIG_VERSION; + } } From 2566028065ff649c4b87d786950a2507f82e5c6c Mon Sep 17 00:00:00 2001 From: Daniel Krueger Date: Thu, 19 Dec 2024 13:43:13 +0100 Subject: [PATCH 5/7] fix nullability --- .../entity/adapter/ProtocolAdapterEntity.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java index 8dd941682b..42955ecbc6 100644 --- a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java +++ b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java @@ -43,7 +43,7 @@ public class ProtocolAdapterEntity { private @NotNull String protocolId; @XmlElement(name = "protocolId") - private @NotNull Integer configVersion; + private @Nullable Integer configVersion; @XmlElement(name = "config") @XmlJavaTypeAdapter(ArbitraryValuesMapAdapter.class) @@ -77,7 +77,7 @@ public ProtocolAdapterEntity( this.adapterId = adapterId; this.config = config; // if no config version is present, we assume it is the oldest possible version - this.configVersion = configVersion != null ? configVersion : 1; + this.configVersion = configVersion; this.northboundMappingEntities = northboundMappingEntities; this.protocolId = protocolId; this.tags = tags; @@ -109,7 +109,11 @@ public ProtocolAdapterEntity( } public @NotNull Integer getConfigVersion() { - return configVersion; + if (configVersion == null) { + return 1; + } else { + return configVersion; + } } public void validate(final @NotNull List validationEvents) { From 929bdfe9fb219ea02c0c826758c3edfedc7c032e Mon Sep 17 00:00:00 2001 From: Daniel Krueger Date: Thu, 19 Dec 2024 14:02:15 +0100 Subject: [PATCH 6/7] simplify --- .../entity/adapter/ProtocolAdapterEntity.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java index 42955ecbc6..010cc15ce2 100644 --- a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java +++ b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; @SuppressWarnings({"FieldMayBeFinal", "unused"}) @@ -109,11 +110,7 @@ public ProtocolAdapterEntity( } public @NotNull Integer getConfigVersion() { - if (configVersion == null) { - return 1; - } else { - return configVersion; - } + return Objects.requireNonNullElse(configVersion, 1); } public void validate(final @NotNull List validationEvents) { From a3ef45d082e740b7026598568781c9bb54d1dc60 Mon Sep 17 00:00:00 2001 From: Daniel Krueger Date: Thu, 19 Dec 2024 16:11:05 +0100 Subject: [PATCH 7/7] fix key --- .../configuration/entity/adapter/ProtocolAdapterEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java index 010cc15ce2..59dace2ec4 100644 --- a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java +++ b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/ProtocolAdapterEntity.java @@ -43,7 +43,7 @@ public class ProtocolAdapterEntity { @XmlElement(name = "protocolId", required = true) private @NotNull String protocolId; - @XmlElement(name = "protocolId") + @XmlElement(name = "configVersion") private @Nullable Integer configVersion; @XmlElement(name = "config")