Skip to content

Commit 72575be

Browse files
Feature/27476 rework tags (#618)
* Starting tags rework * Everything is building again * eip-tests working * file adapter tests working * http adapter working * modbus adapter working * opcua adapter working * plc4x adapter working * Move it * All tests are working * eip working with new persistence * Reworked tag config structure * Remaining tests fixed * Getting rid of the explicit persistence and moving it into the adaptermanager * Fixing compile issues * Added logs * Applying debugging results * A last typing change * Reverting the last typing change because of generics-shenanigans * npe ... * Fixed a broken config mapping * Fixed a mapping problem * Prevent empty rewrite * protecting underlying map * Removed FIXME * Post rebase cleanup * Review comments * Review comments * add license headers * Cleaning up mess caused by rebase ... * update OpenAPI --------- Co-authored-by: Daniel Krueger <[email protected]>
1 parent 1626be9 commit 72575be

File tree

157 files changed

+4133
-3925
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+4133
-3925
lines changed

ext/hivemq-edge-openapi-2024.8-SNAPSHOT.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4702,7 +4702,11 @@ components:
47024702
type: string
47034703
description: The protocol id of the protocol for which this tag was created.
47044704
tagDefinition:
4705-
$ref: '#/components/schemas/JsonNode'
4705+
type: object
4706+
additionalProperties:
4707+
type: object
4708+
description: A user created description for this tag.
4709+
description: A user created description for this tag.
47064710
tagName:
47074711
type: string
47084712
description: The name of the tag that identifies it within this edge instance.

hivemq-edge/src/distribution/conf/examples/configuration/adapters/config-sample-s7.xml

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,42 @@
2626
</mqtt-listeners>
2727
<protocol-adapters>
2828
<s7>
29-
<id>my-s7-id</id>
30-
<host>172.16.10.51</host>
31-
<port>102</port>
32-
<controllerType>S7_1500</controllerType>
33-
<remoteRack>0</remoteRack>
34-
<remoteRack2>0</remoteRack2>
35-
<remoteSlot>0</remoteSlot>
36-
<remoteSlot2>0</remoteSlot2>
37-
<remoteTsap>0</remoteTsap>
38-
<s7ToMqtt>
39-
<maxPollingErrorsBeforeRemoval>10</maxPollingErrorsBeforeRemoval>
40-
<pollingIntervalMillis>1000</pollingIntervalMillis>
41-
<publishChangedDataOnly>true</publishChangedDataOnly>
42-
<s7ToMqttMappings>
43-
<s7ToMqttMapping>
44-
<mqttTopic>my/topic</mqttTopic>
45-
<mqttQos>1</mqttQos>
46-
<includeTagNames>false</includeTagNames>
47-
<includeTimestamp>true</includeTimestamp>
48-
<messageHandlingOptions>MQTTMessagePerTag</messageHandlingOptions>
49-
<tagName>my-tag-name-1</tagName>
50-
<tagDefinition>tag1</tagDefinition>
51-
<dataType>BOOL</dataType>
52-
</s7ToMqttMapping>
53-
</s7ToMqttMappings>
54-
</s7ToMqtt>
29+
<config>
30+
<id>my-s7-id</id>
31+
<host>172.16.10.51</host>
32+
<port>102</port>
33+
<controllerType>S7_1500</controllerType>
34+
<remoteRack>0</remoteRack>
35+
<remoteRack2>0</remoteRack2>
36+
<remoteSlot>0</remoteSlot>
37+
<remoteSlot2>0</remoteSlot2>
38+
<remoteTsap>0</remoteTsap>
39+
<s7ToMqtt>
40+
<maxPollingErrorsBeforeRemoval>10</maxPollingErrorsBeforeRemoval>
41+
<pollingIntervalMillis>1000</pollingIntervalMillis>
42+
<publishChangedDataOnly>true</publishChangedDataOnly>
43+
<s7ToMqttMappings>
44+
<s7ToMqttMapping>
45+
<mqttTopic>my/topic</mqttTopic>
46+
<mqttQos>1</mqttQos>
47+
<includeTagNames>false</includeTagNames>
48+
<includeTimestamp>true</includeTimestamp>
49+
<messageHandlingOptions>MQTTMessagePerTag</messageHandlingOptions>
50+
<tagName>my-tag-name-1</tagName>
51+
<dataType>BOOL</dataType>
52+
</s7ToMqttMapping>
53+
</s7ToMqttMappings>
54+
</s7ToMqtt>
55+
</config>
56+
<tags>
57+
<tag>
58+
<name>my-tag-name-1</name>
59+
<description></description>
60+
<definition>
61+
<tagAddress>tag1</tagAddress>
62+
</definition>
63+
</tag>
64+
</tags>
5565
</s7>
5666
</protocol-adapters>
5767
</hivemq>

hivemq-edge/src/distribution/conf/tag.xml

Lines changed: 0 additions & 32 deletions
This file was deleted.

hivemq-edge/src/distribution/conf/tag.xsd

Lines changed: 0 additions & 52 deletions
This file was deleted.

hivemq-edge/src/main/java/com/hivemq/api/model/tags/DomainTagModel.java

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@
2323
import com.hivemq.persistence.domain.DomainTag;
2424
import io.swagger.v3.oas.annotations.media.Schema;
2525

26+
import java.util.Map;
27+
import java.util.Objects;
28+
2629
@Schema(name = "DomainTag")
2730
public class DomainTagModel {
2831

29-
@JsonProperty("tagDefinition")
30-
@Schema(description = "The address for the data point on the device.")
31-
private final @NotNull JsonNode tagDefinition;
32-
3332
@JsonProperty("tagName")
3433
@Schema(description = "The name of the tag that identifies it within this edge instance.")
3534
private final @NotNull String tag;
@@ -42,26 +41,26 @@ public class DomainTagModel {
4241
@Schema(description = "A user created description for this tag.")
4342
private final @NotNull String description;
4443

44+
@JsonProperty("tagDefinition")
45+
@Schema(description = "A user created description for this tag.")
46+
private final @NotNull Map<String, Object> definition;
47+
4548
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
4649
public DomainTagModel(
47-
@JsonProperty("tagDefinition") final @NotNull JsonNode tagDefinition,
4850
@JsonProperty("tagName") final @NotNull String tag,
4951
@JsonProperty("protocolId") final @NotNull String protocolId,
50-
@JsonProperty("description") final @NotNull String description) {
51-
this.tagDefinition = tagDefinition;
52+
@JsonProperty("description") final @NotNull String description,
53+
@JsonProperty("tagDefinition") final @NotNull Map<String, Object> definition) {
5254
this.tag = tag;
5355
this.protocolId = protocolId;
5456
this.description = description;
57+
this.definition = definition;
5558
}
5659

5760
public @NotNull String getTag() {
5861
return tag;
5962
}
6063

61-
public @NotNull JsonNode getTagDefinition() {
62-
return tagDefinition;
63-
}
64-
6564
public @NotNull String getDescription() {
6665
return description;
6766
}
@@ -70,46 +69,45 @@ public DomainTagModel(
7069
return protocolId;
7170
}
7271

73-
public static @NotNull DomainTagModel fromDomainTag(final @NotNull DomainTag domainTag) {
74-
return new DomainTagModel(domainTag.getTagDefinition(),
75-
domainTag.getTagName(),
76-
"someProtocolId",
77-
"someDescription");
78-
}
79-
80-
@Override
81-
public boolean equals(final @Nullable Object o) {
82-
if (this == o) return true;
83-
if (o == null || getClass() != o.getClass()) return false;
84-
85-
final DomainTagModel that = (DomainTagModel) o;
86-
return tagDefinition.equals(that.tagDefinition) &&
87-
tag.equals(that.tag) &&
88-
protocolId.equals(that.protocolId) &&
89-
description.equals(that.description);
72+
public @NotNull Map<String, Object> getDefinition() {
73+
return definition;
9074
}
9175

92-
@Override
93-
public int hashCode() {
94-
int result = tagDefinition.hashCode();
95-
result = 31 * result + tag.hashCode();
96-
result = 31 * result + protocolId.hashCode();
97-
result = 31 * result + description.hashCode();
98-
return result;
76+
public static @NotNull DomainTagModel fromDomainTag(final @NotNull DomainTag domainTag) {
77+
return new DomainTagModel(
78+
domainTag.getTagName(),
79+
domainTag.getProtocolId(),
80+
domainTag.getDescription(),
81+
domainTag.getDefinition());
9982
}
10083

10184
@Override
102-
public @NotNull String toString() {
85+
public String toString() {
10386
return "DomainTagModel{" +
104-
"description='" +
105-
description +
106-
'\'' + ", tagAddress=" + tagDefinition +
107-
", tag='" +
87+
"tag='" +
10888
tag +
10989
'\'' +
11090
", protocolId='" +
11191
protocolId +
11292
'\'' +
93+
", description='" +
94+
description +
95+
'\'' +
11396
'}';
11497
}
98+
99+
@Override
100+
public boolean equals(final Object o) {
101+
if (this == o) return true;
102+
if (o == null || getClass() != o.getClass()) return false;
103+
final DomainTagModel that = (DomainTagModel) o;
104+
return Objects.equals(tag, that.tag) &&
105+
Objects.equals(protocolId, that.protocolId) &&
106+
Objects.equals(description, that.description);
107+
}
108+
109+
@Override
110+
public int hashCode() {
111+
return Objects.hash(tag, protocolId, description);
112+
}
115113
}

hivemq-edge/src/main/java/com/hivemq/api/resources/impl/ProtocolAdapterApiUtils.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.google.common.base.Preconditions;
2424
import com.hivemq.adapter.sdk.api.ProtocolAdapterCapability;
2525
import com.hivemq.adapter.sdk.api.ProtocolAdapterInformation;
26-
import com.hivemq.adapter.sdk.api.factories.ProtocolAdapterFactory;
2726
import com.hivemq.api.model.adapters.ProtocolAdapter;
2827
import com.hivemq.api.model.adapters.ProtocolAdapterCategory;
2928
import com.hivemq.api.model.components.Module;
@@ -86,17 +85,15 @@ public static ProtocolAdapter convertInstalledAdapterType(
8685
// so we should trust but validate and at least log.
8786
LOG.warn("Logo url for adapter '{}' was null. ", info.getDisplayName());
8887
}
89-
final ProtocolAdapterFactory<?> protocolAdapterFactory =
90-
adapterManager.getProtocolAdapterFactory(info.getProtocolId());
91-
if (protocolAdapterFactory == null) {
88+
if (!adapterManager.protocolAdapterFactoryExists(info.getProtocolId())) {
9289
// this can only happen if the adapter somehow got removed from the manager concurrently, which is not possible right now
93-
LOG.warn("Factory for adapter '{}' was not found while conversion of adapter to information for REST API.",
90+
LOG.error("Factory for adapter '{}' was not found while conversion of adapter to information for REST API.",
9491
info.getDisplayName());
9592
return null;
9693
}
9794

9895
final ProtocolAdapterSchemaManager protocolAdapterSchemaManager =
99-
new ProtocolAdapterSchemaManager(objectMapper, protocolAdapterFactory.getConfigClass());
96+
new ProtocolAdapterSchemaManager(objectMapper, adapterManager.writingEnabled() ? info.configurationClassWriting() : info.configurationClassReading());
10097

10198

10299
final String rawVersion = info.getVersion();

0 commit comments

Comments
 (0)