Skip to content

Commit

Permalink
Console and WebUI now interpret empty directors: as "all", precarious…
Browse files Browse the repository at this point in the history
…ly (#47)
  • Loading branch information
climategadgets committed Sep 13, 2023
1 parent 254cb6d commit ba1143a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 16 deletions.
15 changes: 13 additions & 2 deletions docs/configuration/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
21 changes: 14 additions & 7 deletions docs/configuration/web-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public interface WebUiConfig {
Optional<Integer> port();

@JsonProperty("directors")
Set<String> directors();
Optional<Set<String>> directors();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,16 @@ protected final UnitController getUnitController(String address) {
return result;
}

protected final boolean isConfigured(Set<String> names, Map.Entry<String, ?> d) {
return names.contains(d.getKey());
protected final boolean isConfigured(String source, Set<String> names, Map.Entry<String, ?> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ 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();

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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit ba1143a

Please sign in to comment.