-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into timestamp
- Loading branch information
Showing
5 changed files
with
116 additions
and
11 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
common/src/main/java/com/google/daq/mqtt/util/ContextWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.google.daq.mqtt.util; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
import java.util.function.Supplier; | ||
|
||
public class ContextWrapper { | ||
|
||
private static final ThreadLocal<List<String>> contexts = ThreadLocal.withInitial(ArrayList::new); | ||
|
||
public static <T> T runInContext(String context, Supplier<T> supplier) { | ||
contexts.get().add(context); | ||
try { | ||
return supplier.get(); | ||
} catch (Exception e) { | ||
throw wrapExceptionWithContext(e, true); | ||
} finally { | ||
contexts.get().remove(contexts.get().size() - 1); | ||
} | ||
} | ||
|
||
public static void runInContext(String context, Runnable action) { | ||
runInContext(context, () -> { | ||
action.run(); | ||
return null; | ||
}); | ||
} | ||
|
||
public static String getCurrentContext() { | ||
List<String> contextList = contexts.get(); | ||
return String.join(" -> ", contextList); | ||
} | ||
|
||
public static RuntimeException wrapExceptionWithContext(Exception e, boolean includeOnlyLatest) { | ||
List<String> contextStrings = contexts.get(); | ||
if (contextStrings.size() == 0) { | ||
return new RuntimeException(e); | ||
} | ||
|
||
RuntimeException wrappedException = new RuntimeException( | ||
contextStrings.get(contextStrings.size() - 1), e); | ||
if (!includeOnlyLatest) { | ||
for (int i = contextStrings.size() - 2; i >= 0; i--) { | ||
String context = contextStrings.get(i); | ||
wrappedException = new RuntimeException(context, wrappedException); | ||
} | ||
} | ||
return wrappedException; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
Exceptions for AHU-22 | ||
While converting device config | ||
While converting point filter_differential_pressure_sensor | ||
protocol ref FAXLE12.present_value does not match expression bacnet://[1-9][0-9]*/([A-Z]{2,4}):([1-9][0-9]*)(#[_a-z]+)? | ||
While converting device config | ||
While converting point filter_alarm_pressure_status | ||
protocol ref MCN8.present_value does not match expression bacnet://[1-9][0-9]*/([A-Z]{2,4}):([1-9][0-9]*)(#[_a-z]+)? | ||
While converting device config | ||
While converting point filter_differential_pressure | ||
protocol ref AI2.differential does not match expression bacnet://[1-9][0-9]*/([A-Z]{2,4}):([1-9][0-9]*)(#[_a-z]+)? |
36 changes: 36 additions & 0 deletions
36
tests/sites/missing/devices/AHU-22/expected/generated_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"timestamp": "2020-05-01T13:39:07Z", | ||
"version": "1.5.2", | ||
"system": { | ||
"min_loglevel": 300, | ||
"metrics_rate_sec": 10, | ||
"operation": { } | ||
}, | ||
"gateway": { | ||
"target": { | ||
"addr": "0x65", | ||
"family": "bacnet" | ||
} | ||
}, | ||
"localnet": { | ||
"families": { | ||
"bacnet": { } | ||
} | ||
}, | ||
"pointset": { | ||
"points": { | ||
"filter_alarm_pressure_status": { | ||
"ref": "MCN8.present_value", | ||
"units": "No-units" | ||
}, | ||
"filter_differential_pressure": { | ||
"ref": "AI2.differential", | ||
"units": "Bars" | ||
}, | ||
"filter_differential_pressure_sensor": { | ||
"ref": "FAXLE12.present_value", | ||
"units": "Degrees-Celsius" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters