Skip to content
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

Merged
merged 19 commits into from
Jun 13, 2022
Merged

Conversation

noursaidi
Copy link
Collaborator

Add pubber runtime option to omit hardware field to trigger validation error (missing required field)

@noursaidi noursaidi requested a review from grafnu May 25, 2022 09:46
Copy link
Collaborator

@grafnu grafnu left a 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.

@noursaidi
Copy link
Collaborator Author

@grafnu PTAL - the options are now an object in the configuration file

bin/pubber Outdated
else
options[$option]=$option
k=$option
v=$option
Copy link
Collaborator

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...

Copy link
Collaborator Author

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<>();
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

@noursaidi noursaidi requested a review from grafnu June 7, 2022 11:40
@noursaidi
Copy link
Collaborator Author

@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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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";
Copy link
Collaborator

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",
Copy link
Collaborator

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

Copy link
Collaborator Author

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";
Copy link
Collaborator

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!

Copy link
Collaborator Author

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 Show resolved Hide resolved
bin/pubber Outdated
printf -v extra_field '"extraField": "%s",' "${options[extra_field]}"
fi

options_json="{${options_json%?}}"
Copy link
Collaborator

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?)

Copy link
Collaborator Author

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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tws?

"deviceId": "SNS-4"
"deviceId": "SNS-4",
"options": {
"extraField": true
Copy link
Collaborator

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 = "";
Copy link
Collaborator

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).

Copy link
Collaborator Author

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()) {
Copy link
Collaborator

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()) {
Copy link
Collaborator

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)

@grafnu
Copy link
Collaborator

grafnu commented Jun 9, 2022 via email

@noursaidi noursaidi requested a review from grafnu June 10, 2022 11:43
Copy link
Collaborator

@grafnu grafnu left a 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!

@noursaidi noursaidi merged commit e215679 into faucetsdn:master Jun 13, 2022
@noursaidi noursaidi deleted the pubberhardware branch September 20, 2022 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants