From ba1143a3852673461472aa92fc269dfc26a950e8 Mon Sep 17 00:00:00 2001 From: Vadim Tkachenko Date: Wed, 13 Sep 2023 02:36:52 -0700 Subject: [PATCH] Console and WebUI now interpret empty directors: as "all", precariously (#47) --- docs/configuration/console.md | 15 +++++++++++-- docs/configuration/web-ui.md | 21 ++++++++++++------- .../config/quarkus/model/WebUiConfig.java | 2 +- .../runtime/mapper/InterfaceRecordMapper.java | 2 +- .../config/ConfigurationContextAware.java | 13 ++++++++++-- .../model/ConsoleConfigurationParser.java | 4 ++-- .../model/WebUiConfigurationParser.java | 2 +- 7 files changed, 43 insertions(+), 16 deletions(-) diff --git a/docs/configuration/console.md b/docs/configuration/console.md index 4344c880c..59a7d43b5 100644 --- a/docs/configuration/console.md +++ b/docs/configuration/console.md @@ -17,8 +17,19 @@ Best explained by example: - ambient-patio-temperature ``` -* `directors`: Set of references to [directors](./directors.md). -* `sensors`: Set of references to [sensors](./sensors-and-switches.md). +### `directors` +Set of references to [directors](./directors.md). If you skip it HCC will assume you want all the directors. + +> **NOTE**: Be careful with an empty set. All configuration readers may skip a bare `console:` or `console.directors:` as absent. +> Both "include all" and "missing" will be logged at `WARNING` level, verify if what you think you configured is what HCC thinks it is. + +### `sensors` +Set of references to [sensors](./sensors-and-switches.md). + +> **NOTE**: Be careful with an empty set. Quarkus will not ignore it, but Spring will include all, and you likely have A LOT of sensors in the system, and it's unlikely that you want all of them on the console. +> Be sure to examine the boot log to verify how exactly the configuration was interpreted. + +### Implied Configuration In addition to entities above, contains the [instrument cluster](../instrument-cluster/index.md), collected implicitly from all essential system components. diff --git a/docs/configuration/web-ui.md b/docs/configuration/web-ui.md index 7b349618d..0a1455ace 100644 --- a/docs/configuration/web-ui.md +++ b/docs/configuration/web-ui.md @@ -12,15 +12,22 @@ Best explained by example: - house-unit1 - house-unit2 - server-room - sensors: - - ambient-courtyard-temperature - - air-ambient-northeast - - ambient-patio-temperature ``` -* `port`: Port to listen on. Defaults to 3939. -* `directors`: Set of references to [directors](./directors.md). -* `sensors`: Set of references to [sensors](./sensors-and-switches.md). +### port +Port to listen on. Defaults to 3939. + +### directors +Set of references to [directors](./directors.md). If you skip it HCC will assume you want all the directors. + +> **NOTE**: Be careful with an empty set. All configuration readers may skip a bare `web-ui:` or `webui.directors:` as absent. +> Both "include all" and "missing" will be logged at `WARNING` level, verify if what you think you configured is what HCC thinks it is. +> It is best to include at least one non-empty keyword (in this case, `port`). + +### sensors +Unlike the [console](./console.md#sensors), WebUI takes all the configured [sensors](./sensors-and-switches.md) as a part of the implied configuration. + +### Implied Configuration In addition to entities above, contains the [instrument cluster](../instrument-cluster/index.md), collected implicitly from all essential system components. diff --git a/dz3r-app-quarkus/src/main/java/net/sf/dz3r/runtime/config/quarkus/model/WebUiConfig.java b/dz3r-app-quarkus/src/main/java/net/sf/dz3r/runtime/config/quarkus/model/WebUiConfig.java index 9745db744..b372a88a8 100644 --- a/dz3r-app-quarkus/src/main/java/net/sf/dz3r/runtime/config/quarkus/model/WebUiConfig.java +++ b/dz3r-app-quarkus/src/main/java/net/sf/dz3r/runtime/config/quarkus/model/WebUiConfig.java @@ -11,5 +11,5 @@ public interface WebUiConfig { Optional port(); @JsonProperty("directors") - Set directors(); + Optional> directors(); } diff --git a/dz3r-app-quarkus/src/main/java/net/sf/dz3r/runtime/mapper/InterfaceRecordMapper.java b/dz3r-app-quarkus/src/main/java/net/sf/dz3r/runtime/mapper/InterfaceRecordMapper.java index 08f5d352e..bb0a33fdd 100644 --- a/dz3r-app-quarkus/src/main/java/net/sf/dz3r/runtime/mapper/InterfaceRecordMapper.java +++ b/dz3r-app-quarkus/src/main/java/net/sf/dz3r/runtime/mapper/InterfaceRecordMapper.java @@ -218,7 +218,7 @@ public interface InterfaceRecordMapper { @Mapping(expression = "java(source.mode())", target = "mode") net.sf.dz3r.runtime.config.model.UnitDirectorConfig director(UnitDirectorConfig source); @Mapping(expression = "java(source.port().orElse(null))", target = "port") - @Mapping(expression = "java(source.directors())", target = "directors") + @Mapping(expression = "java(source.directors().orElse(null))", target = "directors") net.sf.dz3r.runtime.config.model.WebUiConfig webUi(WebUiConfig source); @Mapping(expression = "java(source.units().orElse(null))", target = "units") diff --git a/dz3r-bootstrap/src/main/java/net/sf/dz3r/runtime/config/ConfigurationContextAware.java b/dz3r-bootstrap/src/main/java/net/sf/dz3r/runtime/config/ConfigurationContextAware.java index fc2f4ee80..06db04f02 100644 --- a/dz3r-bootstrap/src/main/java/net/sf/dz3r/runtime/config/ConfigurationContextAware.java +++ b/dz3r-bootstrap/src/main/java/net/sf/dz3r/runtime/config/ConfigurationContextAware.java @@ -123,7 +123,16 @@ protected final UnitController getUnitController(String address) { return result; } - protected final boolean isConfigured(Set names, Map.Entry d) { - return names.contains(d.getKey()); + protected final boolean isConfigured(String source, Set names, Map.Entry configured) { + + if (names == null || names.isEmpty()) { + logger.warn("{} is missing, assuming all configured, returning: {}", + source, + Optional.ofNullable(configured).map(Map.Entry::getKey).orElse(null)); + + return true; + } + + return names.contains(configured.getKey()); } } diff --git a/dz3r-bootstrap/src/main/java/net/sf/dz3r/runtime/config/model/ConsoleConfigurationParser.java b/dz3r-bootstrap/src/main/java/net/sf/dz3r/runtime/config/model/ConsoleConfigurationParser.java index 23ed5cfad..e448c3385 100644 --- a/dz3r-bootstrap/src/main/java/net/sf/dz3r/runtime/config/model/ConsoleConfigurationParser.java +++ b/dz3r-bootstrap/src/main/java/net/sf/dz3r/runtime/config/model/ConsoleConfigurationParser.java @@ -29,7 +29,7 @@ public ReactiveConsole parse(String instance, ConsoleConfig cf) { var directors = context .directors .getFlux() - .filter(d -> isConfigured(cf.directors(), d)) + .filter(d -> isConfigured("console.directors", cf.directors(), d)) .map(Map.Entry::getValue) .collect(Collectors.toSet()) .block(); @@ -37,7 +37,7 @@ public ReactiveConsole parse(String instance, ConsoleConfig cf) { var sensors = context .sensors .getFlux() - .filter(s -> isConfigured(cf.sensors(), s)) + .filter(s -> isConfigured("console.sensors", cf.sensors(), s)) .collectMap(Map.Entry::getKey, Map.Entry::getValue) .block(); diff --git a/dz3r-bootstrap/src/main/java/net/sf/dz3r/runtime/config/model/WebUiConfigurationParser.java b/dz3r-bootstrap/src/main/java/net/sf/dz3r/runtime/config/model/WebUiConfigurationParser.java index 3c4a3ce0e..43253af12 100644 --- a/dz3r-bootstrap/src/main/java/net/sf/dz3r/runtime/config/model/WebUiConfigurationParser.java +++ b/dz3r-bootstrap/src/main/java/net/sf/dz3r/runtime/config/model/WebUiConfigurationParser.java @@ -26,7 +26,7 @@ public WebUI parse(WebUiConfig cf) { var directors = context .directors .getFlux() - .filter(d -> isConfigured(cf.directors(), d)) + .filter(d -> isConfigured("web-ui.directors", cf.directors(), d)) .map(Map.Entry::getValue) .map(Object.class::cast) .collect(Collectors.toSet())