From c248416dbc465ea4e6b16f4bd673140ab68eda78 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Wed, 25 May 2022 10:41:18 +0100 Subject: [PATCH 01/17] add no_hardware to pubber opts --- bin/pubber | 4 +++- pubber/src/main/java/daq/pubber/Configuration.java | 1 + pubber/src/main/java/daq/pubber/Pubber.java | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/pubber b/bin/pubber index c7ce71253..ccdbc7379 100755 --- a/bin/pubber +++ b/bin/pubber @@ -38,7 +38,8 @@ else done extra_point="${options[extra_point]}" - + no_hardware="${options[no_hardware]}" + if [ -n "${options[extra_field]}" ]; then printf -v extra_field '"extraField": "%s",' "${options[extra_field]}" fi @@ -49,6 +50,7 @@ else { $extra_field "extraPoint": "$extra_point", + "noHardware": "$no_hardware", "projectId": "$project_id", "sitePath": "$site_path", "cloudRegion": "$cloud_region", diff --git a/pubber/src/main/java/daq/pubber/Configuration.java b/pubber/src/main/java/daq/pubber/Configuration.java index 62d9aa77f..fcb5b0ac1 100644 --- a/pubber/src/main/java/daq/pubber/Configuration.java +++ b/pubber/src/main/java/daq/pubber/Configuration.java @@ -19,4 +19,5 @@ public class Configuration { public String serialNo; public String macAddr; public String extraPoint; + public String noHardware; } diff --git a/pubber/src/main/java/daq/pubber/Pubber.java b/pubber/src/main/java/daq/pubber/Pubber.java index d4008e220..c8b11b112 100644 --- a/pubber/src/main/java/daq/pubber/Pubber.java +++ b/pubber/src/main/java/daq/pubber/Pubber.java @@ -363,6 +363,11 @@ private void initializeDevice() { addPoint(makePoint(configuration.extraPoint, makePointPointsetModel(true, 50, 50, "Celsius"))); } + + if (configuration.noHardware != null && !configuration.noHardware.isEmpty()) { + deviceState.system.hardware = null; + } + markStateDirty(0); } From 0ab15556b9865ac83f774e25e21f77d4704e6abb Mon Sep 17 00:00:00 2001 From: Noureddine Date: Wed, 25 May 2022 10:45:49 +0100 Subject: [PATCH 02/17] docs --- docs/tools/pubber.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/tools/pubber.md b/docs/tools/pubber.md index 4716a8acb..c4608ea63 100644 --- a/docs/tools/pubber.md +++ b/docs/tools/pubber.md @@ -29,6 +29,8 @@ The following parameters are currently supported from the CLI: (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) +* `no_hardware` - omits the `system.hardware` field from state messages (will + trigger validation error, missing required field) Values can be assigned to the parameters e.g. `bin/pubber SITE_PATH PROJECT_ID DEVICE_ID SERIAL_NO extra_point=name_of_point` From ebaf1a7d7d4074bd9831b51f0a9f8c4bcfb8f7a3 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Wed, 25 May 2022 20:39:51 +0100 Subject: [PATCH 03/17] dynamic options object --- bin/pubber | 19 ++++++------------- .../main/java/daq/pubber/Configuration.java | 6 +++--- pubber/src/main/java/daq/pubber/Pubber.java | 16 +++++++++------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/bin/pubber b/bin/pubber index ccdbc7379..2628f3b6a 100755 --- a/bin/pubber +++ b/bin/pubber @@ -31,31 +31,24 @@ else if [[ $option == *"="* ]]; then k=$(echo $option | cut -d'=' -f1) v=$(echo $option | cut -d'=' -f2) - options[$k]=$v else - options[$option]=$option + k=$option + v=$option fi + printf -v options_json '%s"%s":"%s",' "$options_json" "$k" "$v" done - extra_point="${options[extra_point]}" - no_hardware="${options[no_hardware]}" - - if [ -n "${options[extra_field]}" ]; then - printf -v extra_field '"extraField": "%s",' "${options[extra_field]}" - fi - + options_json="{${options_json%?}}" cloud_region=`jq -r .cloud_region $site_path/cloud_iot_config.json` cat < /tmp/pubber_config.json { - $extra_field - "extraPoint": "$extra_point", - "noHardware": "$no_hardware", "projectId": "$project_id", "sitePath": "$site_path", "cloudRegion": "$cloud_region", "deviceId": "$device_id", - "serialNo": "$serial" + "serialNo": "$serial", + "options": $options_json } EOF $ROOT_DIR/pubber/bin/run /tmp/pubber_config.json diff --git a/pubber/src/main/java/daq/pubber/Configuration.java b/pubber/src/main/java/daq/pubber/Configuration.java index fcb5b0ac1..89dbeb866 100644 --- a/pubber/src/main/java/daq/pubber/Configuration.java +++ b/pubber/src/main/java/daq/pubber/Configuration.java @@ -1,5 +1,7 @@ package daq.pubber; +import java.util.HashMap; + /** * General bucket of pubber configuration information. */ @@ -15,9 +17,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 String noHardware; + public HashMap options = new HashMap<>(); } diff --git a/pubber/src/main/java/daq/pubber/Pubber.java b/pubber/src/main/java/daq/pubber/Pubber.java index c8b11b112..457c06828 100644 --- a/pubber/src/main/java/daq/pubber/Pubber.java +++ b/pubber/src/main/java/daq/pubber/Pubber.java @@ -346,10 +346,10 @@ 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, options %s", configuration.deviceId, configuration.serialNo, configuration.macAddr, - configuration.extraField, - configuration.gatewayId)); + configuration.gatewayId, + configuration.options.keySet())); deviceState.system.operational = true; deviceState.system.serial_no = configuration.serialNo; @@ -357,14 +357,16 @@ private void initializeDevice() { deviceState.system.hardware.model = "pubber"; deviceState.system.software = new HashMap<>(); deviceState.system.software.put("firmware", "v1"); - devicePoints.extraField = configuration.extraField; + + // Pubber runtime options + devicePoints.extraField = configuration.options.get("extra_field"); - if (configuration.extraPoint != null && !configuration.extraPoint.isEmpty()) { - addPoint(makePoint(configuration.extraPoint, + if (configuration.options.get("extra_point") != null) { + addPoint(makePoint(configuration.options.get("extra_point"), makePointPointsetModel(true, 50, 50, "Celsius"))); } - if (configuration.noHardware != null && !configuration.noHardware.isEmpty()) { + if (configuration.options.get("no_hardware") != null) { deviceState.system.hardware = null; } From b771921a0c74ab37ad9a2cc6adc10b55ef9afe9f Mon Sep 17 00:00:00 2001 From: Noureddine Date: Thu, 26 May 2022 14:53:33 +0100 Subject: [PATCH 04/17] update pubber.json --- proxy/pubber.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/proxy/pubber.json b/proxy/pubber.json index dc99d8ca8..8223887a1 100644 --- a/proxy/pubber.json +++ b/proxy/pubber.json @@ -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": { + "extra_field": 1234 + } } From 929e285504b5b388126a42b44ba01bab35c85758 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Mon, 6 Jun 2022 16:22:04 +0100 Subject: [PATCH 05/17] use options object --- bin/pubber | 12 ++----- proxy/pubber.json | 2 +- .../main/java/daq/pubber/Configuration.java | 3 +- .../java/daq/pubber/ConfigurationOptions.java | 31 +++++++++++++++++++ pubber/src/main/java/daq/pubber/Pubber.java | 17 ++++++---- 5 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 pubber/src/main/java/daq/pubber/ConfigurationOptions.java diff --git a/bin/pubber b/bin/pubber index 2628f3b6a..9d3c4dcbe 100755 --- a/bin/pubber +++ b/bin/pubber @@ -26,16 +26,8 @@ echo Running tools version `(cd $ROOT_DIR; git describe)` if (($# == 0)); then $ROOT_DIR/pubber/bin/run $project_id $site_path $device_id $serial_no else - declare -A options for option in $*; do - if [[ $option == *"="* ]]; then - k=$(echo $option | cut -d'=' -f1) - v=$(echo $option | cut -d'=' -f2) - else - k=$option - v=$option - fi - printf -v options_json '%s"%s":"%s",' "$options_json" "$k" "$v" + printf -v options_json '%s"%s":%s,' "$options_json" "$option" "true" done options_json="{${options_json%?}}" @@ -47,7 +39,7 @@ else "sitePath": "$site_path", "cloudRegion": "$cloud_region", "deviceId": "$device_id", - "serialNo": "$serial", + "serialNo": "$serial_no", "options": $options_json } EOF diff --git a/proxy/pubber.json b/proxy/pubber.json index 8223887a1..24c1139a5 100644 --- a/proxy/pubber.json +++ b/proxy/pubber.json @@ -9,6 +9,6 @@ "gatewayId": "GAT-123", "deviceId": "SNS-4", "options": { - "extra_field": 1234 + "extraField": true } } diff --git a/pubber/src/main/java/daq/pubber/Configuration.java b/pubber/src/main/java/daq/pubber/Configuration.java index 89dbeb866..223280094 100644 --- a/pubber/src/main/java/daq/pubber/Configuration.java +++ b/pubber/src/main/java/daq/pubber/Configuration.java @@ -1,6 +1,5 @@ package daq.pubber; -import java.util.HashMap; /** * General bucket of pubber configuration information. @@ -19,5 +18,5 @@ public class Configuration { public String algorithm = "RS256"; public String serialNo; public String macAddr; - public HashMap options = new HashMap<>(); + public ConfigurationOptions options = new ConfigurationOptions(); } diff --git a/pubber/src/main/java/daq/pubber/ConfigurationOptions.java b/pubber/src/main/java/daq/pubber/ConfigurationOptions.java new file mode 100644 index 000000000..6ecbfe615 --- /dev/null +++ b/pubber/src/main/java/daq/pubber/ConfigurationOptions.java @@ -0,0 +1,31 @@ +package daq.pubber; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +/** + * Pubber configuration options which change default behaviour + */ +public class ConfigurationOptions { + public Boolean noHardware = false; + public Boolean extraPoint = false; + public Boolean extraField = false; + + + public String toString() { + String options = ""; + Field[] fields = ConfigurationOptions.class.getDeclaredFields(); + + for (Field field : fields) { + try { + if ((Boolean) field.get(this)) { + options = options + " " + field.getName(); + } + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + return options; + } +} diff --git a/pubber/src/main/java/daq/pubber/Pubber.java b/pubber/src/main/java/daq/pubber/Pubber.java index 457c06828..43c326614 100644 --- a/pubber/src/main/java/daq/pubber/Pubber.java +++ b/pubber/src/main/java/daq/pubber/Pubber.java @@ -3,6 +3,7 @@ import static java.util.stream.Collectors.toMap; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.util.ISO8601DateFormat; @@ -145,6 +146,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 Pubber arguments or options provided: " + e.getMessage()); } catch (Exception e) { throw new RuntimeException("While reading config " + configFile.getAbsolutePath(), e); } @@ -346,10 +349,10 @@ private void initializeDevice() { pullDeviceMessage(); } - info(String.format("Starting pubber %s, serial %s, mac %, gateway %s, options %s", + info(String.format("Starting pubber %s, serial %s, mac %, gateway %s, options:%s", configuration.deviceId, configuration.serialNo, configuration.macAddr, configuration.gatewayId, - configuration.options.keySet())); + configuration.options)); deviceState.system.operational = true; deviceState.system.serial_no = configuration.serialNo; @@ -359,14 +362,16 @@ private void initializeDevice() { deviceState.system.software.put("firmware", "v1"); // Pubber runtime options - devicePoints.extraField = configuration.options.get("extra_field"); + if (configuration.options.extraField) { + devicePoints.extraField = "extra_field"; + } - if (configuration.options.get("extra_point") != null) { - addPoint(makePoint(configuration.options.get("extra_point"), + if (configuration.options.extraPoint) { + addPoint(makePoint("extra_point", makePointPointsetModel(true, 50, 50, "Celsius"))); } - if (configuration.options.get("no_hardware") != null) { + if (configuration.options.noHardware != null) { deviceState.system.hardware = null; } From fc3bb3f7d51de2122a045c8f17470d8aedba42e6 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Tue, 7 Jun 2022 10:48:40 +0100 Subject: [PATCH 06/17] pubber assignable options --- bin/pubber | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/pubber b/bin/pubber index 9d3c4dcbe..84a5d9ad1 100755 --- a/bin/pubber +++ b/bin/pubber @@ -26,10 +26,17 @@ echo Running tools version `(cd $ROOT_DIR; git describe)` if (($# == 0)); then $ROOT_DIR/pubber/bin/run $project_id $site_path $device_id $serial_no else + declare -A options for option in $*; do - printf -v options_json '%s"%s":%s,' "$options_json" "$option" "true" + if [[ $option == *"="* ]]; then + k=$(echo $option | cut -d'=' -f1) + v=$(echo $option | cut -d'=' -f2) + else + k=$option + v=true + fi + printf -v options_json '%s"%s":%s,' "$options_json" "$k" "$v" done - options_json="{${options_json%?}}" cloud_region=`jq -r .cloud_region $site_path/cloud_iot_config.json` From d16175b80161f36c1a58f14a351e16372925c810 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Tue, 7 Jun 2022 10:57:01 +0100 Subject: [PATCH 07/17] handle and enforce types --- bin/pubber | 3 +++ pubber/src/main/java/daq/pubber/Pubber.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/bin/pubber b/bin/pubber index 84a5d9ad1..2893e37af 100755 --- a/bin/pubber +++ b/bin/pubber @@ -31,6 +31,9 @@ else if [[ $option == *"="* ]]; then k=$(echo $option | cut -d'=' -f1) v=$(echo $option | cut -d'=' -f2) + if ! [[ $v =~ ^[0-9]+([.][0-9]+)?$ ]]; then + v="\"$v\"" + fi else k=$option v=true diff --git a/pubber/src/main/java/daq/pubber/Pubber.java b/pubber/src/main/java/daq/pubber/Pubber.java index 43c326614..f30eca40d 100644 --- a/pubber/src/main/java/daq/pubber/Pubber.java +++ b/pubber/src/main/java/daq/pubber/Pubber.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.util.ISO8601DateFormat; import com.google.common.base.Preconditions; @@ -75,6 +76,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); From d91f9bb469a6a08eee2bcc9b9de92fe19538aa73 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Tue, 7 Jun 2022 11:30:37 +0100 Subject: [PATCH 08/17] fix noHardware logic --- pubber/src/main/java/daq/pubber/Pubber.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubber/src/main/java/daq/pubber/Pubber.java b/pubber/src/main/java/daq/pubber/Pubber.java index f30eca40d..bea51ba8e 100644 --- a/pubber/src/main/java/daq/pubber/Pubber.java +++ b/pubber/src/main/java/daq/pubber/Pubber.java @@ -373,7 +373,7 @@ private void initializeDevice() { makePointPointsetModel(true, 50, 50, "Celsius"))); } - if (configuration.options.noHardware != null) { + if (!configuration.options.noHardware) { deviceState.system.hardware = null; } From 6cb12c660d32eca27f2de368559b5f9daa33f63f Mon Sep 17 00:00:00 2001 From: Noureddine Date: Tue, 7 Jun 2022 11:32:28 +0100 Subject: [PATCH 09/17] fix noHardware logic --- pubber/src/main/java/daq/pubber/Pubber.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubber/src/main/java/daq/pubber/Pubber.java b/pubber/src/main/java/daq/pubber/Pubber.java index bea51ba8e..868c0bb2a 100644 --- a/pubber/src/main/java/daq/pubber/Pubber.java +++ b/pubber/src/main/java/daq/pubber/Pubber.java @@ -373,7 +373,7 @@ private void initializeDevice() { makePointPointsetModel(true, 50, 50, "Celsius"))); } - if (!configuration.options.noHardware) { + if (configuration.options.noHardware) { deviceState.system.hardware = null; } From 0da054bafe0b1c7ea77b0b4ae38fa03434c9d843 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Tue, 7 Jun 2022 11:48:36 +0100 Subject: [PATCH 10/17] fix style errors and remove tostring --- .../java/daq/pubber/ConfigurationOptions.java | 18 +----------------- pubber/src/main/java/daq/pubber/Pubber.java | 9 ++++----- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/pubber/src/main/java/daq/pubber/ConfigurationOptions.java b/pubber/src/main/java/daq/pubber/ConfigurationOptions.java index 6ecbfe615..a1b1aaf5c 100644 --- a/pubber/src/main/java/daq/pubber/ConfigurationOptions.java +++ b/pubber/src/main/java/daq/pubber/ConfigurationOptions.java @@ -5,27 +5,11 @@ import java.lang.reflect.Method; /** - * Pubber configuration options which change default behaviour + * Pubber configuration options which change default behavior. */ public class ConfigurationOptions { public Boolean noHardware = false; public Boolean extraPoint = false; public Boolean extraField = false; - - public String toString() { - String options = ""; - Field[] fields = ConfigurationOptions.class.getDeclaredFields(); - - for (Field field : fields) { - try { - if ((Boolean) field.get(this)) { - options = options + " " + field.getName(); - } - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - return options; - } } diff --git a/pubber/src/main/java/daq/pubber/Pubber.java b/pubber/src/main/java/daq/pubber/Pubber.java index 868c0bb2a..188d0c6ef 100644 --- a/pubber/src/main/java/daq/pubber/Pubber.java +++ b/pubber/src/main/java/daq/pubber/Pubber.java @@ -3,10 +3,10 @@ import static java.util.stream.Collectors.toMap; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.MapperFeature; 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; @@ -149,7 +149,7 @@ public Pubber(String configPath) { try { configuration = OBJECT_MAPPER.readValue(configFile, Configuration.class); } catch (UnrecognizedPropertyException e) { - throw new RuntimeException("Invalid Pubber arguments or options provided: " + e.getMessage()); + throw new RuntimeException("Invalid arguments or options: " + e.getMessage()); } catch (Exception e) { throw new RuntimeException("While reading config " + configFile.getAbsolutePath(), e); } @@ -351,10 +351,9 @@ private void initializeDevice() { pullDeviceMessage(); } - info(String.format("Starting pubber %s, serial %s, mac %, gateway %s, options:%s", + info(String.format("Starting pubber %s, serial %s, mac %, gateway %s", configuration.deviceId, configuration.serialNo, configuration.macAddr, - configuration.gatewayId, - configuration.options)); + configuration.gatewayId)); deviceState.system.operational = true; deviceState.system.serial_no = configuration.serialNo; From 691911a9fb62827ea6c80aefd80c9ecd9a352b88 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Tue, 7 Jun 2022 11:52:01 +0100 Subject: [PATCH 11/17] fix style --- pubber/src/main/java/daq/pubber/Pubber.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubber/src/main/java/daq/pubber/Pubber.java b/pubber/src/main/java/daq/pubber/Pubber.java index a934c7f18..197853940 100644 --- a/pubber/src/main/java/daq/pubber/Pubber.java +++ b/pubber/src/main/java/daq/pubber/Pubber.java @@ -3,8 +3,8 @@ import static java.util.stream.Collectors.toMap; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.ObjectMapper; 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; @@ -376,7 +376,7 @@ private void initializeDevice() { // Pubber runtime options if (configuration.options.extraField) { - devicePoints.extraField = "extra_field"; + devicePoints.extraField = "extra_field"; } if (configuration.options.extraPoint) { From 900d94054036f11184d19c6e88cd0ff5c1535345 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Tue, 7 Jun 2022 14:45:39 +0100 Subject: [PATCH 12/17] remove unused imports --- pubber/src/main/java/daq/pubber/ConfigurationOptions.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pubber/src/main/java/daq/pubber/ConfigurationOptions.java b/pubber/src/main/java/daq/pubber/ConfigurationOptions.java index a1b1aaf5c..7532d9bd6 100644 --- a/pubber/src/main/java/daq/pubber/ConfigurationOptions.java +++ b/pubber/src/main/java/daq/pubber/ConfigurationOptions.java @@ -1,9 +1,5 @@ package daq.pubber; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - /** * Pubber configuration options which change default behavior. */ From 237ec8aa1fdc186186c2f8584ade24cf0582f84c Mon Sep 17 00:00:00 2001 From: Noureddine Date: Wed, 8 Jun 2022 20:52:16 +0100 Subject: [PATCH 13/17] comments .. type and explicit string manip --- bin/pubber | 8 +++----- .../src/main/java/daq/pubber/ConfigurationOptions.java | 4 ++-- pubber/src/main/java/daq/pubber/Pubber.java | 10 ++++------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/bin/pubber b/bin/pubber index 2893e37af..39eaf7443 100755 --- a/bin/pubber +++ b/bin/pubber @@ -30,17 +30,15 @@ else for option in $*; do if [[ $option == *"="* ]]; then k=$(echo $option | cut -d'=' -f1) - v=$(echo $option | cut -d'=' -f2) - if ! [[ $v =~ ^[0-9]+([.][0-9]+)?$ ]]; then - v="\"$v\"" - fi + v="\"$(echo $option | cut -d'=' -f2)\"" else k=$option v=true fi printf -v options_json '%s"%s":%s,' "$options_json" "$k" "$v" done - options_json="{${options_json%?}}" + options_json="{${options_json%,}}" + cloud_region=`jq -r .cloud_region $site_path/cloud_iot_config.json` cat < /tmp/pubber_config.json diff --git a/pubber/src/main/java/daq/pubber/ConfigurationOptions.java b/pubber/src/main/java/daq/pubber/ConfigurationOptions.java index 7532d9bd6..c3db6317a 100644 --- a/pubber/src/main/java/daq/pubber/ConfigurationOptions.java +++ b/pubber/src/main/java/daq/pubber/ConfigurationOptions.java @@ -5,7 +5,7 @@ */ public class ConfigurationOptions { public Boolean noHardware = false; - public Boolean extraPoint = false; - public Boolean extraField = false; + public String extraPoint = ""; + public String extraField = ""; } diff --git a/pubber/src/main/java/daq/pubber/Pubber.java b/pubber/src/main/java/daq/pubber/Pubber.java index 197853940..20e9cc03f 100644 --- a/pubber/src/main/java/daq/pubber/Pubber.java +++ b/pubber/src/main/java/daq/pubber/Pubber.java @@ -3,7 +3,6 @@ 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; @@ -77,7 +76,6 @@ 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); @@ -375,12 +373,12 @@ private void initializeDevice() { deviceState.system.last_config = new Date(0); // Pubber runtime options - if (configuration.options.extraField) { - devicePoints.extraField = "extra_field"; + if (!configuration.options.extraField.isEmpty()) { + devicePoints.extraField = configuration.options.extraField; } - if (configuration.options.extraPoint) { - addPoint(makePoint("extra_point", + if (!configuration.options.extraPoint.isEmpty()) { + addPoint(makePoint(configuration.options.extraPoint, makePointPointsetModel(true, 50, 50, "Celsius"))); } From a882177e20239c7d38a9d469163cc2f7195e2517 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Thu, 9 Jun 2022 09:47:02 +0100 Subject: [PATCH 14/17] remove extra white space --- pubber/src/main/java/daq/pubber/Pubber.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubber/src/main/java/daq/pubber/Pubber.java b/pubber/src/main/java/daq/pubber/Pubber.java index 20e9cc03f..9d4e0be1e 100644 --- a/pubber/src/main/java/daq/pubber/Pubber.java +++ b/pubber/src/main/java/daq/pubber/Pubber.java @@ -369,7 +369,7 @@ private void initializeDevice() { 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"); deviceState.system.last_config = new Date(0); // Pubber runtime options From ef8fbfaec9971f184ba97fa88a8d8c3535bd6060 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Thu, 9 Jun 2022 19:32:14 +0100 Subject: [PATCH 15/17] no empty check --- pubber/src/main/java/daq/pubber/ConfigurationOptions.java | 4 ++-- pubber/src/main/java/daq/pubber/Pubber.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pubber/src/main/java/daq/pubber/ConfigurationOptions.java b/pubber/src/main/java/daq/pubber/ConfigurationOptions.java index c3db6317a..3bef9ed24 100644 --- a/pubber/src/main/java/daq/pubber/ConfigurationOptions.java +++ b/pubber/src/main/java/daq/pubber/ConfigurationOptions.java @@ -5,7 +5,7 @@ */ public class ConfigurationOptions { public Boolean noHardware = false; - public String extraPoint = ""; - public String extraField = ""; + public String extraPoint; + public String extraField; } diff --git a/pubber/src/main/java/daq/pubber/Pubber.java b/pubber/src/main/java/daq/pubber/Pubber.java index 9d4e0be1e..5c05554b9 100644 --- a/pubber/src/main/java/daq/pubber/Pubber.java +++ b/pubber/src/main/java/daq/pubber/Pubber.java @@ -373,16 +373,16 @@ private void initializeDevice() { deviceState.system.last_config = new Date(0); // Pubber runtime options - if (!configuration.options.extraField.isEmpty()) { + if (configuration.options.extraField != null) { devicePoints.extraField = configuration.options.extraField; } - if (!configuration.options.extraPoint.isEmpty()) { + if (configuration.options.extraPoint != null) { addPoint(makePoint(configuration.options.extraPoint, makePointPointsetModel(true, 50, 50, "Celsius"))); } - if (configuration.options.noHardware) { + if (!configuration.options.noHardware) { deviceState.system.hardware = null; } From 7df2aa0a5d323118982243141333eaa2be3f6ba3 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Fri, 10 Jun 2022 09:10:30 +0100 Subject: [PATCH 16/17] comments + docs --- docs/tools/pubber.md | 13 ++++++------- proxy/pubber.json | 2 +- .../main/java/daq/pubber/ConfigurationOptions.java | 2 +- pubber/src/main/java/daq/pubber/Pubber.java | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/tools/pubber.md b/docs/tools/pubber.md index c4608ea63..e9f43829e 100644 --- a/docs/tools/pubber.md +++ b/docs/tools/pubber.md @@ -25,16 +25,15 @@ 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 - (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) +* `extraPoint=` - 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) +* `missingPoint=` - removes the point with the given name (if exists) from + the device's active pointset at initialization (will trigger validation + missing point) * `no_hardware` - omits the `system.hardware` field from state messages (will trigger validation error, missing required field) -Values can be assigned to the parameters e.g. -`bin/pubber SITE_PATH PROJECT_ID DEVICE_ID SERIAL_NO extra_point=name_of_point` - More advanced options can be set by by calling pubber directly with the path a configuration file: `pubber/bin/run path/to/config.json` diff --git a/proxy/pubber.json b/proxy/pubber.json index 24c1139a5..be0532143 100644 --- a/proxy/pubber.json +++ b/proxy/pubber.json @@ -9,6 +9,6 @@ "gatewayId": "GAT-123", "deviceId": "SNS-4", "options": { - "extraField": true + "extraField": "1234" } } diff --git a/pubber/src/main/java/daq/pubber/ConfigurationOptions.java b/pubber/src/main/java/daq/pubber/ConfigurationOptions.java index 3bef9ed24..822f8f15f 100644 --- a/pubber/src/main/java/daq/pubber/ConfigurationOptions.java +++ b/pubber/src/main/java/daq/pubber/ConfigurationOptions.java @@ -4,7 +4,7 @@ * Pubber configuration options which change default behavior. */ public class ConfigurationOptions { - public Boolean noHardware = false; + public Boolean noHardware; public String extraPoint; public String extraField; diff --git a/pubber/src/main/java/daq/pubber/Pubber.java b/pubber/src/main/java/daq/pubber/Pubber.java index 5c05554b9..99bef948a 100644 --- a/pubber/src/main/java/daq/pubber/Pubber.java +++ b/pubber/src/main/java/daq/pubber/Pubber.java @@ -382,7 +382,7 @@ private void initializeDevice() { makePointPointsetModel(true, 50, 50, "Celsius"))); } - if (!configuration.options.noHardware) { + if (configuration.options.noHardware != null && configuration.options.noHardware) { deviceState.system.hardware = null; } From d0aded87518f18e5a1148871fd8a4c5a10f32c92 Mon Sep 17 00:00:00 2001 From: Noureddine Date: Fri, 10 Jun 2022 12:20:51 +0100 Subject: [PATCH 17/17] correct documentation --- docs/tools/pubber.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/tools/pubber.md b/docs/tools/pubber.md index e9f43829e..8669c76db 100644 --- a/docs/tools/pubber.md +++ b/docs/tools/pubber.md @@ -28,9 +28,8 @@ The following parameters are currently supported from the CLI: * `extraPoint=` - 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) -* `missingPoint=` - removes the point with the given name (if exists) from - the device's active pointset at initialization (will trigger validation - missing point) +* `extraField=` - adds an extra schema invalidating field to pointset events + (will trigger validation schema error) * `no_hardware` - omits the `system.hardware` field from state messages (will trigger validation error, missing required field)