-
Notifications
You must be signed in to change notification settings - Fork 44
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
Changes from 14 commits
c248416
0ab1555
ebaf1a7
b771921
929e285
fc3bb3f
d16175b
d91f9bb
6cb12c6
8b88953
0da054b
de43900
691911a
900d940
237ec8a
a882177
ef8fbfa
7df2aa0
d0aded8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
v="\"$v\"" | ||
fi | ||
else | ||
options[$option]=$option | ||
k=$option | ||
v=true | ||
grafnu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fi | ||
printf -v options_json '%s"%s":%s,' "$options_json" "$k" "$v" | ||
done | ||
|
||
extra_point="${options[extra_point]}" | ||
|
||
if [ -n "${options[extra_field]}" ]; then | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. last character, changed to remove trailing comma |
||
cloud_region=`jq -r .cloud_region $site_path/cloud_iot_config.json` | ||
|
||
cat <<EOF > /tmp/pubber_config.json | ||
{ | ||
$extra_field | ||
"extraPoint": "$extra_point", | ||
"projectId": "$project_id", | ||
"sitePath": "$site_path", | ||
"cloudRegion": "$cloud_region", | ||
"deviceId": "$device_id", | ||
"serialNo": "$serial" | ||
"serialNo": "$serial_no", | ||
"options": $options_json | ||
} | ||
EOF | ||
$ROOT_DIR/pubber/bin/run /tmp/pubber_config.json | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,13 @@ | |
"projectId": "bos-udmi-hub", | ||
"cloudRegion": "us-central1", | ||
"registryId": "ZZ-TRI-FECTA", | ||
"extraField": 1234, | ||
"serialNo": "test_aux-16132", | ||
"macAddr": "3c5ab41e8f0a", | ||
"keyFile": "./udmi_site_model/devices/GAT-123/ec_private.pkcs8", | ||
"algorithm": "ES256", | ||
"gatewayId": "GAT-123", | ||
"deviceId": "SNS-4" | ||
"deviceId": "SNS-4", | ||
"options": { | ||
"extraField": true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't extraField be a string, not boolean? |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package daq.pubber; | ||
|
||
/** | ||
* Pubber configuration options which change default behavior. | ||
*/ | ||
public class ConfigurationOptions { | ||
public Boolean noHardware = false; | ||
public Boolean extraPoint = false; | ||
public Boolean extraField = false; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ | |
import static java.util.stream.Collectors.toMap; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.MapperFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; | ||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat; | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableMap; | ||
|
@@ -75,6 +77,7 @@ public class Pubber { | |
private static final String UDMI_VERSION = "1.3.14"; | ||
private static final Logger LOG = LoggerFactory.getLogger(Pubber.class); | ||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() | ||
.disable(MapperFeature.ALLOW_COERCION_OF_SCALARS) | ||
.enable(SerializationFeature.INDENT_OUTPUT) | ||
.setDateFormat(new ISO8601DateFormat()) | ||
.setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
|
@@ -146,6 +149,8 @@ public Pubber(String configPath) { | |
File configFile = new File(configPath); | ||
try { | ||
configuration = OBJECT_MAPPER.readValue(configFile, Configuration.class); | ||
} catch (UnrecognizedPropertyException e) { | ||
throw new RuntimeException("Invalid arguments or options: " + e.getMessage()); | ||
} catch (Exception e) { | ||
throw new RuntimeException("While reading config " + configFile.getAbsolutePath(), e); | ||
} | ||
|
@@ -357,24 +362,32 @@ private void initializeDevice() { | |
pullDeviceMessage(); | ||
} | ||
|
||
info(String.format("Starting pubber %s, serial %s, mac %s, extra %s, gateway %s", | ||
info(String.format("Starting pubber %s, serial %s, mac %, gateway %s", | ||
configuration.deviceId, configuration.serialNo, configuration.macAddr, | ||
configuration.extraField, | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. tws? |
||
deviceState.system.last_config = new Date(0); | ||
devicePoints.extraField = configuration.extraField; | ||
|
||
if (configuration.extraPoint != null && !configuration.extraPoint.isEmpty()) { | ||
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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. extra field value now taken from string |
||
} | ||
|
||
if (configuration.options.extraPoint) { | ||
addPoint(makePoint("extra_point", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. extra point value now taken from string |
||
makePointPointsetModel(true, 50, 50, "Celsius"))); | ||
} | ||
|
||
if (configuration.options.noHardware) { | ||
deviceState.system.hardware = null; | ||
} | ||
|
||
markStateDirty(0); | ||
} | ||
|
||
|
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