Skip to content

Commit 1a006fc

Browse files
authored
Fixed reload not working (#1033)
1 parent 76dbe18 commit 1a006fc

File tree

10 files changed

+63
-109
lines changed

10 files changed

+63
-109
lines changed

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ tasks.register("clean") {
1717
group = "build"
1818
//required since we don't apply the base plugin and otherwise the reports can't be cleaned out
1919
project.delete(files("${project.layout.buildDirectory.get()}"))
20-
dependsOn(gradle.includedBuilds.map { it.task(":clean") })
20+
21+
dependsOn(gradle.includedBuilds.filter { it.name != "hivemq-edge-frontend" }.map { it.task(":$name") })
2122
}
2223

2324
tasks.register("build") {

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/OpcUaClientConnection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private static void awaitOnCounter(final @NotNull AtomicLong requestCounter) {
236236

237237
private @NotNull CompletionStage<OpcUaSubscription> subscribe(final @NotNull OpcUaClient client) {
238238
final OpcUaSubscription subscription = new OpcUaSubscription(client);
239-
subscription.setPublishingInterval((double) config.getOpcuaToMqttConfig().getPublishingInterval());
239+
subscription.setPublishingInterval((double) config.getOpcuaToMqttConfig().publishingInterval());
240240
subscription.setSubscriptionListener(createSubscriptionListener(client));
241241
return subscription.createAsync()
242242
.thenCompose(unit -> addAndSynchronizeMonitoredItems(subscription))
@@ -254,8 +254,8 @@ private static void awaitOnCounter(final @NotNull AtomicLong requestCounter) {
254254
tags.forEach(opcuaTag -> {
255255
final String nodeId = opcuaTag.getDefinition().getNode();
256256
final var monitoredItem = OpcUaMonitoredItem.newDataItem(NodeId.parse(nodeId));
257-
monitoredItem.setQueueSize(uint(config.getOpcuaToMqttConfig().getServerQueueSize()));
258-
monitoredItem.setSamplingInterval(config.getOpcuaToMqttConfig().getPublishingInterval());
257+
monitoredItem.setQueueSize(uint(config.getOpcuaToMqttConfig().serverQueueSize()));
258+
monitoredItem.setSamplingInterval(config.getOpcuaToMqttConfig().publishingInterval());
259259
subscription.addMonitoredItem(monitoredItem);
260260
log.debug("Added monitored item: {}", nodeId);
261261
});

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/client/OpcUaEndpointFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public OpcUaEndpointFilter(
5454
if (policyUri.equals(SecurityPolicy.None.getUri())) {
5555
return true;
5656
}
57-
if (adapterConfig.getTls().isEnabled() &&
58-
adapterConfig.getTls().getKeystore() != null) {
57+
if (adapterConfig.getTls().enabled() &&
58+
adapterConfig.getTls().keystore() != null) {
5959
//if security policy is not 'None', then skip the policy if no keystore is available
6060
return true;
6161
}

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/client/ParsedConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ public record ParsedConfig(boolean tlsEnabled, KeystoreUtil.KeyPairWithChain key
5151
private static final @NotNull Logger log = LoggerFactory.getLogger(ParsedConfig.class);
5252

5353
public static Result<ParsedConfig, String> fromConfig(final OpcUaSpecificAdapterConfig adapterConfig) {
54-
final boolean tlsEnabled = adapterConfig.getTls().isEnabled();
54+
final boolean tlsEnabled = adapterConfig.getTls().enabled();
5555

5656
CertificateValidator certValidator = null;
5757
if (tlsEnabled) {
58-
final var truststore = adapterConfig.getTls().getTruststore();
58+
final var truststore = adapterConfig.getTls().truststore();
5959
final var certOptional = getTrustedCerts(truststore).map(ParsedConfig::createServerCertificateValidator);
6060
if (certOptional.isEmpty()) {
6161
return Failure.of("Failed to create certificate validator, check truststore configuration");
6262
}
6363
certValidator = certOptional.get();
6464
}
6565

66-
final Keystore keystore = adapterConfig.getTls().getKeystore();
66+
final Keystore keystore = adapterConfig.getTls().keystore();
6767
KeystoreUtil.KeyPairWithChain keyPairWithChain = null;
6868
if (keystore != null && !keystore.path().isBlank()) {
6969
final var kpWithChain = getKeyPairWithChain(keystore);

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/config/OpcUaSpecificAdapterConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public OpcUaSpecificAdapterConfig(
8383
this.auth = auth;
8484
this.tls = requireNonNullElse(tls, new Tls(false, null, null));
8585
this.opcuaToMqttConfig =
86-
Objects.requireNonNullElseGet(opcuaToMqttConfig, () -> new OpcUaToMqttConfig(null, null));
86+
Objects.requireNonNullElseGet(opcuaToMqttConfig, () -> new OpcUaToMqttConfig(1, 1000));
8787
this.security = requireNonNullElse(security, new Security(Constants.DEFAULT_SECURITY_POLICY));
8888
}
8989

@@ -118,13 +118,13 @@ public boolean equals(final @Nullable Object o) {
118118
return false;
119119
}
120120
final OpcUaSpecificAdapterConfig that = (OpcUaSpecificAdapterConfig) o;
121-
return getOverrideUri().equals(that.getOverrideUri() &&
121+
return getOverrideUri().equals(that.getOverrideUri()) &&
122122
Objects.equals(id, that.id) &&
123123
Objects.equals(getUri(), that.getUri()) &&
124124
Objects.equals(getAuth(), that.getAuth()) &&
125125
Objects.equals(getTls(), that.getTls()) &&
126126
Objects.equals(getSecurity(), that.getSecurity()) &&
127-
Objects.equals(getOpcuaToMqttConfig(), that.getOpcuaToMqttConfig()));
127+
Objects.equals(getOpcuaToMqttConfig(), that.getOpcuaToMqttConfig());
128128
}
129129

130130
@Override

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/config/Tls.java

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,25 @@
2525

2626
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
2727

28-
public class Tls {
29-
30-
@JsonProperty("enabled")
31-
@ModuleConfigField(title = "Enable TLS", description = "Enables TLS encrypted connection", defaultValue = "false")
32-
private final boolean enabled;
33-
34-
@JsonProperty("keystore")
35-
@JsonInclude(NON_NULL)
36-
@ModuleConfigField(title = "Keystore",
37-
description = "Keystore that contains the client certificate including the chain. Required for X509 authentication.")
38-
private final @Nullable Keystore keystore;
39-
40-
@JsonProperty("truststore")
41-
@JsonInclude(NON_NULL)
42-
@ModuleConfigField(title = "Truststore",
43-
description = "Truststore wich contains the trusted server certificates or trusted intermediates.")
44-
private final @Nullable Truststore truststore;
45-
28+
public record Tls (@JsonProperty("enabled")
29+
@ModuleConfigField(title = "Enable TLS",
30+
description = "Enables TLS encrypted connection",
31+
defaultValue = "false")
32+
boolean enabled,
33+
34+
@JsonProperty("keystore")
35+
@JsonInclude(NON_NULL)
36+
@ModuleConfigField(title = "Keystore",
37+
description = "Keystore that contains the client certificate including the chain. Required for X509 authentication.")
38+
@Nullable Keystore keystore,
39+
40+
@JsonProperty("truststore")
41+
@JsonInclude(NON_NULL)
42+
@ModuleConfigField(title = "truststore",
43+
description = "Truststore that contains certs to be trusted. Required for X509 authentication.")
44+
@Nullable Truststore truststore
45+
) {
4646
@JsonCreator
47-
public Tls(
48-
@JsonProperty("enabled") final @Nullable Boolean enabled,
49-
@JsonProperty("keystore") final @Nullable Keystore keystore,
50-
@JsonProperty("truststore") final @Nullable Truststore truststore) {
51-
this.enabled = Objects.requireNonNullElse(enabled, false);
52-
this.keystore = keystore;
53-
this.truststore = truststore;
54-
}
55-
56-
public boolean isEnabled() {
57-
return enabled;
58-
}
59-
60-
public @Nullable Keystore getKeystore() {
61-
return keystore;
62-
}
63-
64-
public @Nullable Truststore getTruststore() {
65-
return truststore;
47+
public Tls{
6648
}
6749
}

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/config/opcua2mqtt/OpcUaToMqttConfig.java

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,22 @@
2424

2525
import static java.util.Objects.requireNonNullElse;
2626

27-
public class OpcUaToMqttConfig {
28-
29-
@JsonProperty("serverQueueSize")
30-
@ModuleConfigField(title = "OPC UA server queue size",
31-
description = "OPC UA queue size for this subscription on the server",
32-
numberMin = 1,
33-
defaultValue = "1")
34-
private final int serverQueueSize;
35-
36-
37-
@JsonProperty("publishingInterval")
38-
@ModuleConfigField(title = "OPC UA publishing interval [ms]",
39-
description = "OPC UA publishing interval in milliseconds for this subscription on the server",
40-
numberMin = 1,
41-
defaultValue = "1000")
42-
private final int publishingInterval;
27+
public record OpcUaToMqttConfig (@JsonProperty("serverQueueSize")
28+
@ModuleConfigField(title = "OPC UA server queue size",
29+
description = "OPC UA queue size for this subscription on the server",
30+
numberMin = 1,
31+
defaultValue = "1")
32+
int serverQueueSize,
33+
@JsonProperty("publishingInterval")
34+
@ModuleConfigField(title = "OPC UA publishing interval [ms]",
35+
description = "OPC UA publishing interval in milliseconds for this subscription on the server",
36+
numberMin = 1,
37+
defaultValue = "1000")
38+
int publishingInterval
39+
) {
4340

4441
@JsonCreator
45-
public OpcUaToMqttConfig(
46-
@JsonProperty("publishingInterval") final @Nullable Integer publishingInterval,
47-
@JsonProperty("serverQueueSize") final @Nullable Integer serverQueueSize) {
48-
this.publishingInterval = requireNonNullElse(publishingInterval, 1000);
49-
this.serverQueueSize = requireNonNullElse(serverQueueSize, 1);
50-
}
51-
52-
public int getPublishingInterval() {
53-
return publishingInterval;
42+
public OpcUaToMqttConfig{
5443
}
5544

56-
public int getServerQueueSize() {
57-
return serverQueueSize;
58-
}
59-
60-
@Override
61-
public boolean equals(final @Nullable Object o) {
62-
if (o == null || getClass() != o.getClass()) {
63-
return false;
64-
}
65-
final OpcUaToMqttConfig that = (OpcUaToMqttConfig) o;
66-
return getServerQueueSize() == that.getServerQueueSize() &&
67-
getPublishingInterval() == that.getPublishingInterval();
68-
}
69-
70-
@Override
71-
public int hashCode() {
72-
return Objects.hash(getServerQueueSize(), getPublishingInterval());
73-
}
7445
}

modules/hivemq-edge-module-opcua/src/test/java/com/hivemq/edge/adapters/opcua/OpcUaProtocolAdapterAuthTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void whenNoAuthAndNoSubscriptions_thenConnectSuccessfully() {
9595
false,
9696
null,
9797
null,
98-
new OpcUaToMqttConfig(null, null),
98+
new OpcUaToMqttConfig(1, 1000),
9999
null);
100100

101101
when(protocolAdapterInput.getConfig()).thenReturn(config);

modules/hivemq-edge-module-opcua/src/test/java/com/hivemq/edge/adapters/opcua/config/OpcUaProtocolAdapterConfigTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ public void convertConfigObject_fullConfig_valid() throws Exception {
7878
});
7979

8080
assertThat(config.getTls()).satisfies(tls -> {
81-
assertThat(tls.isEnabled()).isTrue();
81+
assertThat(tls.enabled()).isTrue();
8282

83-
assertThat(tls.getKeystore()).isNotNull();
84-
assertThat(tls.getKeystore().path()).isEqualTo("path/to/keystore");
85-
assertThat(tls.getKeystore().password()).isEqualTo("keystore-password");
86-
assertThat(tls.getKeystore().privateKeyPassword()).isEqualTo("private-key-password");
83+
assertThat(tls.keystore()).isNotNull();
84+
assertThat(tls.keystore().path()).isEqualTo("path/to/keystore");
85+
assertThat(tls.keystore().password()).isEqualTo("keystore-password");
86+
assertThat(tls.keystore().privateKeyPassword()).isEqualTo("private-key-password");
8787

88-
assertThat(tls.getTruststore()).isNotNull();
89-
assertThat(tls.getTruststore().path()).isEqualTo("path/to/truststore");
90-
assertThat(tls.getTruststore().password()).isEqualTo("truststore-password");
88+
assertThat(tls.truststore()).isNotNull();
89+
assertThat(tls.truststore().path()).isEqualTo("path/to/truststore");
90+
assertThat(tls.truststore().password()).isEqualTo("truststore-password");
9191
});
9292

9393

@@ -105,8 +105,8 @@ public void convertConfigObject_fullConfig_valid() throws Exception {
105105
});
106106

107107
assertThat(config.getOpcuaToMqttConfig()).satisfies(mapping -> {
108-
assertThat(mapping.getPublishingInterval()).isEqualTo(12);
109-
assertThat(mapping.getServerQueueSize()).isEqualTo(13);
108+
assertThat(mapping.publishingInterval()).isEqualTo(12);
109+
assertThat(mapping.serverQueueSize()).isEqualTo(13);
110110
});
111111

112112
assertThat(protocolAdapterConfig.getSouthboundMappings()).satisfiesExactly(mapping -> {
@@ -135,7 +135,7 @@ public void convertConfigObject_defaults_valid() throws Exception {
135135
assertThat(config.getAuth()).isNull();
136136

137137
assertThat(config.getTls()).satisfies(tls -> {
138-
assertThat(tls.isEnabled()).isFalse();
138+
assertThat(tls.enabled()).isFalse();
139139
});
140140

141141
assertThat(config.getOpcuaToMqttConfig()).isNotNull();
@@ -148,8 +148,8 @@ public void convertConfigObject_defaults_valid() throws Exception {
148148

149149
assertThat(config.getOpcuaToMqttConfig()).isNotNull();
150150
assertThat(config.getOpcuaToMqttConfig()).satisfies(mapping -> {
151-
assertThat(mapping.getPublishingInterval()).isEqualTo(1000);
152-
assertThat(mapping.getServerQueueSize()).isEqualTo(1);
151+
assertThat(mapping.publishingInterval()).isEqualTo(1000);
152+
assertThat(mapping.serverQueueSize()).isEqualTo(1);
153153
});
154154

155155
assertThat(protocolAdapterConfig.getSouthboundMappings()).satisfiesExactly(mapping -> {
@@ -180,7 +180,7 @@ public void unconvertConfigObject_full_valid() {
180180
new Tls(true,
181181
new Keystore("my/keystore/path", "keystore-password", "private-key-password"),
182182
new Truststore("my/truststore/path", "truststore-password")),
183-
new OpcUaToMqttConfig(null, null),
183+
new OpcUaToMqttConfig(1, 1000),
184184
new Security(BASIC128RSA15)
185185
);
186186

@@ -224,7 +224,7 @@ public void unconvertConfigObject_default_valid() {
224224
true,
225225
null,
226226
null,
227-
new OpcUaToMqttConfig(null, null),
227+
new OpcUaToMqttConfig(1, 1000),
228228
null
229229
);
230230

modules/hivemq-edge-module-opcua/src/test/java/com/hivemq/edge/adapters/opcua/northbound/AbstractOpcUaPayloadConverterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected OpcUaProtocolAdapter createAndStartAdapter(final @NotNull String subcr
9797
throws Exception {
9898

9999
final OpcUaToMqttConfig opcuaToMqttConfig =
100-
new OpcUaToMqttConfig(null, null);
100+
new OpcUaToMqttConfig(1, 1000);
101101
final OpcUaSpecificAdapterConfig config = new OpcUaSpecificAdapterConfig(
102102
opcUaServerExtension.getServerUri(),
103103
false,

0 commit comments

Comments
 (0)