...
|
...
|
@@ -20,11 +20,13 @@ import com.google.common.util.concurrent.Futures; |
20
|
20
|
import com.google.common.util.concurrent.ListenableFuture;
|
21
|
21
|
import lombok.extern.slf4j.Slf4j;
|
22
|
22
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
23
|
+import org.springframework.beans.factory.annotation.Value;
|
23
|
24
|
import org.springframework.stereotype.Service;
|
24
|
25
|
import org.thingsboard.server.common.data.EntityType;
|
25
|
26
|
import org.thingsboard.server.common.data.EntityView;
|
26
|
27
|
import org.thingsboard.server.common.data.id.EntityId;
|
27
|
28
|
import org.thingsboard.server.common.data.id.EntityViewId;
|
|
29
|
+import org.thingsboard.server.common.data.kv.Aggregation;
|
28
|
30
|
import org.thingsboard.server.common.data.kv.BaseReadTsKvQuery;
|
29
|
31
|
import org.thingsboard.server.common.data.kv.DeleteTsKvQuery;
|
30
|
32
|
import org.thingsboard.server.common.data.kv.ReadTsKvQuery;
|
...
|
...
|
@@ -47,8 +49,11 @@ import static org.apache.commons.lang3.StringUtils.isBlank; |
47
|
49
|
@Slf4j
|
48
|
50
|
public class BaseTimeseriesService implements TimeseriesService {
|
49
|
51
|
|
50
|
|
- public static final int INSERTS_PER_ENTRY = 3;
|
51
|
|
- public static final int DELETES_PER_ENTRY = INSERTS_PER_ENTRY;
|
|
52
|
+ private static final int INSERTS_PER_ENTRY = 3;
|
|
53
|
+ private static final int DELETES_PER_ENTRY = INSERTS_PER_ENTRY;
|
|
54
|
+
|
|
55
|
+ @Value("${database.ts_max_intervals}")
|
|
56
|
+ private long maxTsIntervals;
|
52
|
57
|
|
53
|
58
|
@Autowired
|
54
|
59
|
private TimeseriesDao timeseriesDao;
|
...
|
...
|
@@ -59,7 +64,7 @@ public class BaseTimeseriesService implements TimeseriesService { |
59
|
64
|
@Override
|
60
|
65
|
public ListenableFuture<List<TsKvEntry>> findAll(EntityId entityId, List<ReadTsKvQuery> queries) {
|
61
|
66
|
validate(entityId);
|
62
|
|
- queries.forEach(BaseTimeseriesService::validate);
|
|
67
|
+ queries.forEach(this::validate);
|
63
|
68
|
if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) {
|
64
|
69
|
EntityView entityView = entityViewService.findEntityViewById((EntityViewId) entityId);
|
65
|
70
|
List<ReadTsKvQuery> filteredQueries =
|
...
|
...
|
@@ -189,7 +194,7 @@ public class BaseTimeseriesService implements TimeseriesService { |
189
|
194
|
Validator.validateEntityId(entityId, "Incorrect entityId " + entityId);
|
190
|
195
|
}
|
191
|
196
|
|
192
|
|
- private static void validate(ReadTsKvQuery query) {
|
|
197
|
+ private void validate(ReadTsKvQuery query) {
|
193
|
198
|
if (query == null) {
|
194
|
199
|
throw new IncorrectParameterException("ReadTsKvQuery can't be null");
|
195
|
200
|
} else if (isBlank(query.getKey())) {
|
...
|
...
|
@@ -197,6 +202,14 @@ public class BaseTimeseriesService implements TimeseriesService { |
197
|
202
|
} else if (query.getAggregation() == null) {
|
198
|
203
|
throw new IncorrectParameterException("Incorrect ReadTsKvQuery. Aggregation can't be empty");
|
199
|
204
|
}
|
|
205
|
+ if(!Aggregation.NONE.equals(query.getAggregation())) {
|
|
206
|
+ long step = Math.max(query.getInterval(), 1000);
|
|
207
|
+ long intervalCounts = (query.getEndTs() - query.getStartTs()) / step;
|
|
208
|
+ if (intervalCounts > maxTsIntervals || intervalCounts < 0) {
|
|
209
|
+ throw new IncorrectParameterException("Incorrect TsKvQuery. Number of intervals is to high - " + intervalCounts + ". " +
|
|
210
|
+ "Please increase 'interval' parameter for your query or reduce the time range of the query.");
|
|
211
|
+ }
|
|
212
|
+ }
|
200
|
213
|
}
|
201
|
214
|
|
202
|
215
|
private static void validate(DeleteTsKvQuery query) {
|
...
|
...
|
|