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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions bin/pubber
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,25 @@ else
for option in $*; do
if [[ $option == *"="* ]]; then
k=$(echo $option | cut -d'=' -f1)
v=$(echo $option | cut -d'=' -f2)
options[$k]=$v
v="\"$(echo $option | cut -d'=' -f2)\""
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
options_json="{${options_json%,}}"

extra_point="${options[extra_point]}"

if [ -n "${options[extra_field]}" ]; then
printf -v extra_field '"extraField": "%s",' "${options[extra_field]}"
fi

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
Expand Down
12 changes: 6 additions & 6 deletions docs/tools/pubber.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ Pubber is run from the CLI within the UDMI directory.
### Options

The following parameters are currently supported from the CLI:
* `extra_field` - adds an extra schema invalidating field to pointset events
* `extraPoint=<name>` - adds an extra point with the given name to the device
which does not exist in device's metadata with a random value (will trigger
validation additional point error)
* `extraField=<name>` - adds an extra schema invalidating field to pointset events
(will trigger validation schema error)
* `extra_point` - adds an extra point to the device which does not exist in
device's metadata (will trigger validation additional point error)

Values can be assigned to the parameters e.g.
`bin/pubber SITE_PATH PROJECT_ID DEVICE_ID SERIAL_NO extra_point=name_of_point`
* `no_hardware` - omits the `system.hardware` field from state messages (will
trigger validation error, missing required field)

More advanced options can be set by by calling pubber directly with the path a
configuration file: `pubber/bin/run path/to/config.json`
Expand Down
6 changes: 4 additions & 2 deletions proxy/pubber.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "1234"
}
}
4 changes: 2 additions & 2 deletions pubber/src/main/java/daq/pubber/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package daq.pubber;


/**
* General bucket of pubber configuration information.
*/
Expand All @@ -15,8 +16,7 @@ public class Configuration {
public String keyFile = "local/rsa_private.pkcs8";
public byte[] keyBytes;
public String algorithm = "RS256";
public Object extraField;
public String serialNo;
public String macAddr;
public String extraPoint;
public ConfigurationOptions options = new ConfigurationOptions();
}
11 changes: 11 additions & 0 deletions pubber/src/main/java/daq/pubber/ConfigurationOptions.java
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;
public String extraPoint;
public String extraField;

}
21 changes: 16 additions & 5 deletions pubber/src/main/java/daq/pubber/Pubber.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
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;
Expand Down Expand Up @@ -146,6 +147,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);
}
Expand Down Expand Up @@ -357,9 +360,8 @@ 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;
Expand All @@ -369,12 +371,21 @@ private void initializeDevice() {
deviceState.system.software = new HashMap<>();
deviceState.system.software.put("firmware", "v1");
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 != null) {
devicePoints.extraField = configuration.options.extraField;
}

if (configuration.options.extraPoint != null) {
addPoint(makePoint(configuration.options.extraPoint,
makePointPointsetModel(true, 50, 50, "Celsius")));
}

if (configuration.options.noHardware != null && configuration.options.noHardware) {
deviceState.system.hardware = null;
}

markStateDirty(0);
}

Expand Down