-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add no_hardware to pubber options #340
Conversation
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'm not convinced this is the right way for us to add lots of configuration options to pubber. I'd like to understand the motivating use case a bit more. Ideally, more of this would be encapsulated in the metadata setup rather than as line-items in a script. But, that would explicitly depend on the use-cases that are being explored. Basically, this won't scale well, so we should have an understanding of the potential complexity (how many options?) this is intended to serve. Maybe we can briefly talk about it in our meeting today.
@grafnu PTAL - the options are now an object in the configuration file |
bin/pubber
Outdated
else | ||
options[$option]=$option | ||
k=$option | ||
v=$option |
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'm wondering if this should be a boolean. Ideally we can be more semantic about this, and having it as a boolean would allow us to make sure people are using options correctly...
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.
Agree, turned it into a boolean with correct type assignment for checking
public String serialNo; | ||
public String macAddr; | ||
public String extraPoint; | ||
public HashMap<String, String> options = new HashMap<>(); |
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 would make this an explicit Options object. The reason is once you go to a general map here you lose the ability to have any checking on the contents and types. Ideally, this structure would be specified as a protobuf or json schema itself, so we get the auto-documenting process with that. It also makes the code simpler since it's not a lot of key-lookups-in-maps and makes the code itself more stable through any changes.
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.
Turned options into an options object
@grafnu PTAL if the changes now address the comments |
bin/pubber
Outdated
@@ -31,29 +31,26 @@ else | |||
if [[ $option == *"="* ]]; then | |||
k=$(echo $option | cut -d'=' -f1) | |||
v=$(echo $option | cut -d'=' -f2) | |||
options[$k]=$v | |||
if ! [[ $v =~ ^[0-9]+([.][0-9]+)?$ ]]; then |
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 wouldn't go about it this way, since although it seems "simple" it's actually somewhat of a minefield because, say, what if you want a string that looks like a number? Better to be just simpler (all options are strings) and then deal with the conversion later, if/when necessary.
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.
Removed so options are either boolean true or string value
addPoint(makePoint(configuration.extraPoint, | ||
// Pubber runtime options | ||
if (configuration.options.extraField) { | ||
devicePoints.extraField = "extra_field"; |
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.
see, now if this were still a string then you have your extra field value!
} | ||
|
||
if (configuration.options.extraPoint) { | ||
addPoint(makePoint("extra_point", |
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.
ditto -- extra_point here would be useful
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.
extra point value now taken from string
addPoint(makePoint(configuration.extraPoint, | ||
// Pubber runtime options | ||
if (configuration.options.extraField) { | ||
devicePoints.extraField = "extra_field"; |
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.
see, now if this were still a string then you have your extra field value!
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.
extra field value now taken from string
bin/pubber
Outdated
printf -v extra_field '"extraField": "%s",' "${options[extra_field]}" | ||
fi | ||
|
||
options_json="{${options_json%?}}" |
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.
what's the ? for? If it's a wildcard, can you be explicit about what it's removing (trailing comma, right?)
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.
last character, changed to remove trailing comma
configuration.gatewayId)); | ||
|
||
deviceState.system.operational = true; | ||
deviceState.system.serial_no = configuration.serialNo; | ||
deviceState.system.hardware.make = "BOS"; | ||
deviceState.system.hardware.model = "pubber"; | ||
deviceState.system.software = new HashMap<>(); | ||
deviceState.system.software.put("firmware", "v1"); | ||
deviceState.system.software.put("firmware", "v1"); |
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.
tws?
proxy/pubber.json
Outdated
"deviceId": "SNS-4" | ||
"deviceId": "SNS-4", | ||
"options": { | ||
"extraField": 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.
shouldn't extraField be a string, not boolean?
*/ | ||
public class ConfigurationOptions { | ||
public Boolean noHardware = false; | ||
public String extraPoint = ""; |
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.
don't assign an empty string to undefined values -- there's a semantic difference between them -- so these should all default to null (no assignment).
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.
@grafnu thanks! should that extend to noHardware too which I've assigned a default value? Then the check is != null && !configuration.optionsnoHardware
?
if (configuration.extraPoint != null && !configuration.extraPoint.isEmpty()) { | ||
addPoint(makePoint(configuration.extraPoint, | ||
// Pubber runtime options | ||
if (!configuration.options.extraField.isEmpty()) { |
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.
should be "extraField != null" -- if somebody really wants to specify an empty extra field then they should be able to.
devicePoints.extraField = configuration.options.extraField; | ||
} | ||
|
||
if (!configuration.options.extraPoint.isEmpty()) { |
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.
semantically this should be != null, and then something else would throw an error saying "can't define an empty point name" (or just ignore that case because it's all for error checking anyway)
Correct... generally avoid a default unless it's really really
useful/necessary.
…On Thu, Jun 9, 2022 at 12:06 PM Noureddine ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In pubber/src/main/java/daq/pubber/ConfigurationOptions.java
<#340 (comment)>:
> @@ -0,0 +1,11 @@
+package daq.pubber;
+
+/**
+ * Pubber configuration options which change default behavior.
+ */
+public class ConfigurationOptions {
+ public Boolean noHardware = false;
+ public String extraPoint = "";
@grafnu <https://github.com/grafnu> thanks! should that extend to
noHardware too which I've assigned a default value? Then the check is !=
null && !configuration.optionsnoHardware?
—
Reply to this email directly, view it on GitHub
<#340 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIEPD3VME6N3TLDL3OOSXLVOI6EXANCNFSM5W4QTQJA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
97afa88
to
7df2aa0
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.
Brilliant. Thanks for working through all the iterations with me!
Add pubber runtime option to omit
hardware
field to trigger validation error (missing required field)