[rrd4j] Avoid IAE thrown if e.g. invalid start/end time given (#14238)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
80094b5e9d
commit
a78db1feb2
@ -280,7 +280,10 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long start = 0L;
|
long start = 0L;
|
||||||
long end = filter.getEndDate() == null ? System.currentTimeMillis() / 1000
|
// set end to {@link Instant#MAX} instead of current timestamp to enable requesting future time ranges including
|
||||||
|
// boundary values via REST API
|
||||||
|
// see discussion in https://github.com/openhab/openhab-addons/pull/14238
|
||||||
|
long end = filter.getEndDate() == null ? Instant.MAX.getEpochSecond()
|
||||||
: filter.getEndDate().toInstant().getEpochSecond();
|
: filter.getEndDate().toInstant().getEpochSecond();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -308,13 +311,21 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
|
|||||||
start = end;
|
start = end;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException("rrd4j does not allow querys without a begin date, "
|
throw new UnsupportedOperationException(
|
||||||
+ "unless order is descending and a single value is requested");
|
"rrd4j does not allow querys without a begin date, unless order is descending and a single value is requested");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
start = filter.getBeginDate().toInstant().getEpochSecond();
|
start = filter.getBeginDate().toInstant().getEpochSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// do not call method {@link RrdDb#createFetchRequest(ConsolFun, long, long, long)} if start > end to avoid
|
||||||
|
// an IAE to be thrown
|
||||||
|
if (start > end) {
|
||||||
|
logger.warn("Could not query rrd4j database for item '{}': start ({}) > end ({})", itemName, start,
|
||||||
|
end);
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
FetchRequest request = db.createFetchRequest(getConsolidationFunction(db), start, end, 1);
|
FetchRequest request = db.createFetchRequest(getConsolidationFunction(db), start, end, 1);
|
||||||
FetchData result = request.fetchData();
|
FetchData result = request.fetchData();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user