Fix for #5931 and merge the PR #5915

This commit is contained in:
Andrii Shvaika 2022-01-20 12:53:24 +02:00
parent 1104c4e8f6
commit 8b0a1f5538
4 changed files with 13 additions and 6 deletions

View File

@ -96,8 +96,7 @@ public class DefaultRuleEngineStatisticsService implements RuleEngineStatisticsS
}
});
ruleEngineStats.getTenantExceptions().forEach((tenantId, e) -> {
TsKvEntry tsKv = new BasicTsKvEntry(e.getTs(), new JsonDataEntry("ruleEngineException",
JacksonUtil.toString(JacksonUtil.newObjectNode().put("message", e.getMessage()))));
TsKvEntry tsKv = new BasicTsKvEntry(e.getTs(), new JsonDataEntry("ruleEngineException", e.toJsonString()));
try {
tsService.saveAndNotifyInternal(tenantId, getServiceAssetId(tenantId, queueName), Collections.singletonList(tsKv), CALLBACK);
} catch (DataValidationException e2) {

View File

@ -25,11 +25,19 @@ public class RuleEngineException extends Exception {
protected static final ObjectMapper mapper = new ObjectMapper();
@Getter
private final long ts;
private long ts;
public RuleEngineException(String message) {
super(message != null ? message : "Unknown");
this.ts = System.currentTimeMillis();
ts = System.currentTimeMillis();
}
public String toJsonString() {
try {
return mapper.writeValueAsString(mapper.createObjectNode().put("message", getMessage()));
} catch (JsonProcessingException e) {
log.warn("Failed to serialize exception ", e);
throw new RuntimeException(e);
}
}
}

View File

@ -265,7 +265,7 @@ class AlarmRuleState {
var longValue = getLongValue(keyValue);
if (longValue == null) {
String sourceAttribute = dynamicValue.getSourceAttribute();
throw new NumericParseException(String.format("could not parse attribute [%s: %s] from source!", sourceAttribute, getStrValue(keyValue)));
throw new NumericParseException(String.format("Could not convert attribute '%s' with value '%s' to numeric value!", sourceAttribute, getStrValue(keyValue)));
}
return longValue;
}

View File

@ -51,7 +51,7 @@ import java.util.function.BiFunction;
@Slf4j
class AlarmState {
public static final String ERROR_MSG = "Failed to process alarm state for Device [%s]: %s";
public static final String ERROR_MSG = "Failed to process alarm rule for Device [%s]: %s";
private final ProfileState deviceProfile;
private final EntityId originator;
private DeviceProfileAlarm alarmDefinition;