-
Notifications
You must be signed in to change notification settings - Fork 786
Conversation
66ca3ba
to
44d52cd
Compare
c52073b
to
9b841e5
Compare
fca6078
to
db4c2ca
Compare
@htreu The PR is ready for review |
db4c2ca
to
4705710
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @davidgraeff, I gave this a first round. Looks good from what I can say. Please find some comments inline.
import org.junit.Test; | ||
|
||
/** | ||
* Tests cases for {@link HexUtils}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually for the MqttWillAndTestamentBuilder
public void invalidHex() { | ||
final String hexTest = "a2a1a0ll"; | ||
byte[] test = HexUtils.fromHex(hexTest); | ||
assertThat(hexTest, is(HexUtils.toHexString(test))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this will fail in line 56, so the assertion is obsolete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, makes sense this way: First an ascii hex is decoded to bytes and then those bytes are encoded to ascii hex again and compared.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In line 53 (@Test(expected = IllegalArgumentException.class)
) you expect the code to throw the IAE which is done by the code in line 56. So I guess line 57 is never reached.
The following test case will run happily:
@Test(expected = IllegalArgumentException.class)
public void invalidHex() {
final String hexTest = "a2a1a0ll";
HexUtils.fromHex(hexTest);
assertThat(true, is(false)); // should fail here if the line is reached.
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. fixed
* | ||
* @author David Graeff - Initial contribution | ||
*/ | ||
public class NetworkDiscoveryTests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually the MqttServiceDiscoveryServiceTest
?
import org.mockito.MockitoAnnotations; | ||
|
||
/** | ||
* Tests cases for {@link HexUtils}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for MqttServiceDiscoveryService
?
import org.mockito.stubbing.Answer; | ||
|
||
/** | ||
* Tests cases for {@link HexUtils}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for NetworkDiscoveryService
?
@@ -0,0 +1,131 @@ | |||
package org.eclipse.smarthome.binding.mqttbroker.internal.ssl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
license header missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -0,0 +1,6 @@ | |||
package org.eclipse.smarthome.binding.mqttbroker.internal.ssl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
license header missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -0,0 +1,9 @@ | |||
package org.eclipse.smarthome.binding.mqttbroker.internal.ssl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
license header missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
package org.eclipse.smarthome.binding.mqttbroker.internal.ssl; | ||
|
||
public interface PinnedCallback { | ||
void pinnedLearnedHash(Pin pin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add some javadoc (all methods).
@@ -0,0 +1,39 @@ | |||
package org.eclipse.smarthome.binding.mqttbroker.internal.ssl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
license header missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
50b18f5
to
4a12e3d
Compare
4a12e3d
to
d74a140
Compare
@@ -0,0 +1 @@ | |||
OSGI-INF/*.xml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please create the folder OSGI-INF
and place the .gitignore
with content *.xml
inside. right now the folder is marked as new for git after checkout and build.
d74a140
to
364bf2d
Compare
@htreu Changes incorporated |
@davidgraeff looks good so far, please take another look at this comment #3839 (comment). Thanks. |
2d83fa3
to
1bcef6c
Compare
1bcef6c
to
427d668
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems my comments has been incorporated.
So, okay from my side.
Thanks @davidgraeff for your whole MQTT work.
@davidgraeff do you want to wait for #5364 or adopt the timeout with another PR? |
It is not possible to test broker handlers without a timeout. I will never get a thing online/offline status update. Therefore I'll reckon waiting is the better option. |
b481a71
to
d984635
Compare
Travis complains, I guess we already know this one:
|
Some more Travis goodness:
|
@htreu Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally (w/o actual broker), works nicely with the MQTT connections from the managed service.
Thanks for the awesome work @davidgraeff!
@kaikreuzer let me know if you want to have another look and change your review status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I still do have a few comments, please see below.
xmlns:binding="http://eclipse.org/smarthome/schemas/binding/v1.0.0" | ||
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/binding/v1.0.0 http://eclipse.org/smarthome/schemas/binding-1.0.0.xsd"> | ||
|
||
<name>MQTT Broker connections</name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file describes the whole "mqtt" binding - not just the parts of this bundle.
So the name should imho be "MQTT Binding".
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/binding/v1.0.0 http://eclipse.org/smarthome/schemas/binding-1.0.0.xsd"> | ||
|
||
<name>MQTT Broker connections</name> | ||
<description>Add/remove MQTT broker connections and manage system-wide configured connections</description> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also update to be applicable for the binding in general.
@@ -0,0 +1,7 @@ | |||
binding.mqtt.name = MQTT Broker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dito
@@ -0,0 +1,7 @@ | |||
binding.mqtt.name = MQTT Broker | |||
binding.mqtt.description = Konfiguriere MQTT Broker Verbindungen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dito
<context>network-address</context> | ||
</parameter> | ||
|
||
<parameter name="secure" type="text" required="true"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please apply the formatter
* | ||
* @author David Graeff - Initial contribution | ||
*/ | ||
@Component(immediate = true, service = DiscoveryService.class, configurationPid = "org.eclipse.smarthome.NetworkDiscoveryService") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> pid discovery.networkmqttbroker
lock.tryLock(TIMEOUT_IN_MS, TimeUnit.MILLISECONDS); | ||
|
||
if (testConnection.connectionState() == MqttConnectionState.CONNECTED) { | ||
logger.trace("Found service device at {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to fully parameterised logging: {}:{}
.
|
||
ThingUID thingUID = MqttThingID.getThingUID(testConnection.getHost(), testConnection.getPort()); | ||
thingDiscovered(DiscoveryResultBuilder.create(thingUID).withTTL(120).withProperties(properties) | ||
.withLabel("Mqtt Broker (" + testConnection.getHost() + ")").build()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> "MQTT Broker" and declare "host" as representation property
try { | ||
scanTarget(c); | ||
} catch (ConfigurationException | MqttException | InterruptedException e) { | ||
logger.trace("Scan of {} failed", c.getHost() + ":" + String.valueOf(c.getPort())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to fully parameterised logging
|
||
for (MqttBrokerConnection c : o) { | ||
scheduler.execute(() -> { | ||
Thread.currentThread().setName("Discovery thread " + c.getHost() + ":" + String.valueOf(c.getPort())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not change the thread names - they are from a re-used pool and they are already named by the framework.
Comments are addressed. If the readme is meant to describe all features of the other MQTT bundles, it still needs some editing though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update - looks good to me, just a few small issues left to fix; I'll quickly create a commit to fix them myself, so that @htreu can create the CQ for this PR.
f the readme is meant to describe all features of the other MQTT bundles, it still needs some editing though.
No, I think it is just fine as it is, thanks!
<parameter name="port" type="integer"> | ||
<label>Broker Port</label> | ||
<description>The port is optional, if none is provided, the typical ports 1883 and 8883 (SSL) are used.</description> | ||
<context>network-address</context> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the port must not have context network-address
.
@@ -1,7 +1,7 @@ | |||
Manifest-Version: 1.0 | |||
Automatic-Module-Name: org.eclipse.smarthome.binding.mqtt | |||
Bundle-ManifestVersion: 2 | |||
Bundle-Name: MQTT Broker Connections | |||
Bundle-Name: MQTT Binging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
|
||
Map<String, Object> properties = new HashMap<>(); | ||
properties.put("host", testConnection.getHost()); | ||
properties.put("port", testConnection.getPort()); | ||
|
||
ThingUID thingUID = MqttThingID.getThingUID(testConnection.getHost(), testConnection.getPort()); | ||
thingDiscovered(DiscoveryResultBuilder.create(thingUID).withTTL(120).withProperties(properties) | ||
.withLabel("Mqtt Broker (" + testConnection.getHost() + ")").build()); | ||
.withRepresentationProperty(testConnection.getHost()).withLabel("MQTT Broker").build()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the representation property must be the key, not the value!
Unfortunately we have to tranquillise Travis one more time:
|
509ab06
to
0313e15
Compare
This is the main mqtt binding. At the moment it is possible to configure brokers in a textual way. Without intensively watching the log file, there is no way to tell if the provided configuration is correct and if the connection to the broker have been established, neither via the GUI (PaperUI) nor machine readable (REST interface). This binding makes the configuration of brokers more intuitive and let the user add broker connections as things. The connections are synced to the io.transport.mqtt MqttService and are therefore available for all other bindings to use. Features include: * 2 different Bridges: SystemBrokerConnection, BrokerConnection * Rich status feedback for textual configured brokers. No longer skimming through log files if a connection doesn't work. * Auto discovery of brokers (Enumeration of MqttService shared broker connections, best effort subnet and localhost scan on standard Mqtt ports) * Configurable reconnect time (this is not possible via textual configuration yet) * Certificate and public key pinning for ssl connections to brokers * Extensive tests for all handlers, the discovery services and the SSLContextProvider. Signed-off-by: David Graeff <david.graeff@web.de>
0313e15
to
3f904c1
Compare
FTR: CQ16168 created. |
FTR: CQ16168 approved. |
This is the main mqtt binding. At the moment it is possible to configure brokers in a textual way. Without intensively watching the log file, there is no way to tell if the provided configuration is correct and if the connection to the broker have been established, neither via the GUI (PaperUI) nor machine readable (REST interface). This binding makes the configuration of brokers more intuitive and let the user add broker connections as things. The connections are synced to the io.transport.mqtt MqttService and are therefore available for all other bindings to use. Features include: * 2 different Bridges: SystemBrokerConnection, BrokerConnection * Rich status feedback for textual configured brokers. No longer skimming through log files if a connection doesn't work. * Auto discovery of brokers (Enumeration of MqttService shared broker connections, best effort subnet and localhost scan on standard Mqtt ports) * Configurable reconnect time (this is not possible via textual configuration yet) * Certificate and public key pinning for ssl connections to brokers * Extensive tests for all handlers, the discovery services and the SSLContextProvider. Signed-off-by: David Graeff <david.graeff@web.de>
Abstract
At the moment it is possible to configure brokers in a textual way. Without intensively watching the log file, there is no way to tell if the provided configuration is correct and if the connection to the broker have been established, neither via the GUI (PaperUI) nor machine readable (REST interface).
This binding makes the configuration of brokers more intuitive and let the user add broker connections as things. The connections are synced to the
io.transport.mqtt.MqttService
and are therefore available for all other bindings to use.Features include:
Discussion
Points that need to be discussed might be:
I'm happy to hear some feedback.
Cheers,
David