Validation of TsKvQuery
This commit is contained in:
parent
02be0edf93
commit
df27d7acc8
@ -83,6 +83,7 @@ dashboard:
|
|||||||
max_datapoints_limit: "${DASHBOARD_MAX_DATAPOINTS_LIMIT:50000}"
|
max_datapoints_limit: "${DASHBOARD_MAX_DATAPOINTS_LIMIT:50000}"
|
||||||
|
|
||||||
database:
|
database:
|
||||||
|
ts_max_intervals: "${DATABASE_TS_MAX_INTERVALS:700}" # mas number of DB queries generated by single API call to fetch telemetry records
|
||||||
entities:
|
entities:
|
||||||
type: "${DATABASE_ENTITIES_TYPE:sql}" # cassandra OR sql
|
type: "${DATABASE_ENTITIES_TYPE:sql}" # cassandra OR sql
|
||||||
ts:
|
ts:
|
||||||
|
|||||||
@ -20,11 +20,13 @@ import com.google.common.util.concurrent.Futures;
|
|||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
import org.thingsboard.server.common.data.EntityView;
|
import org.thingsboard.server.common.data.EntityView;
|
||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
import org.thingsboard.server.common.data.id.EntityViewId;
|
import org.thingsboard.server.common.data.id.EntityViewId;
|
||||||
|
import org.thingsboard.server.common.data.kv.Aggregation;
|
||||||
import org.thingsboard.server.common.data.kv.BaseReadTsKvQuery;
|
import org.thingsboard.server.common.data.kv.BaseReadTsKvQuery;
|
||||||
import org.thingsboard.server.common.data.kv.DeleteTsKvQuery;
|
import org.thingsboard.server.common.data.kv.DeleteTsKvQuery;
|
||||||
import org.thingsboard.server.common.data.kv.ReadTsKvQuery;
|
import org.thingsboard.server.common.data.kv.ReadTsKvQuery;
|
||||||
@ -47,8 +49,11 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class BaseTimeseriesService implements TimeseriesService {
|
public class BaseTimeseriesService implements TimeseriesService {
|
||||||
|
|
||||||
public static final int INSERTS_PER_ENTRY = 3;
|
private static final int INSERTS_PER_ENTRY = 3;
|
||||||
public static final int DELETES_PER_ENTRY = INSERTS_PER_ENTRY;
|
private static final int DELETES_PER_ENTRY = INSERTS_PER_ENTRY;
|
||||||
|
|
||||||
|
@Value("${database.ts_max_intervals}")
|
||||||
|
private long maxTsIntervals;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TimeseriesDao timeseriesDao;
|
private TimeseriesDao timeseriesDao;
|
||||||
@ -59,7 +64,7 @@ public class BaseTimeseriesService implements TimeseriesService {
|
|||||||
@Override
|
@Override
|
||||||
public ListenableFuture<List<TsKvEntry>> findAll(EntityId entityId, List<ReadTsKvQuery> queries) {
|
public ListenableFuture<List<TsKvEntry>> findAll(EntityId entityId, List<ReadTsKvQuery> queries) {
|
||||||
validate(entityId);
|
validate(entityId);
|
||||||
queries.forEach(BaseTimeseriesService::validate);
|
queries.forEach(this::validate);
|
||||||
if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) {
|
if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) {
|
||||||
EntityView entityView = entityViewService.findEntityViewById((EntityViewId) entityId);
|
EntityView entityView = entityViewService.findEntityViewById((EntityViewId) entityId);
|
||||||
List<ReadTsKvQuery> filteredQueries =
|
List<ReadTsKvQuery> filteredQueries =
|
||||||
@ -189,7 +194,7 @@ public class BaseTimeseriesService implements TimeseriesService {
|
|||||||
Validator.validateEntityId(entityId, "Incorrect entityId " + entityId);
|
Validator.validateEntityId(entityId, "Incorrect entityId " + entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validate(ReadTsKvQuery query) {
|
private void validate(ReadTsKvQuery query) {
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
throw new IncorrectParameterException("ReadTsKvQuery can't be null");
|
throw new IncorrectParameterException("ReadTsKvQuery can't be null");
|
||||||
} else if (isBlank(query.getKey())) {
|
} else if (isBlank(query.getKey())) {
|
||||||
@ -197,6 +202,14 @@ public class BaseTimeseriesService implements TimeseriesService {
|
|||||||
} else if (query.getAggregation() == null) {
|
} else if (query.getAggregation() == null) {
|
||||||
throw new IncorrectParameterException("Incorrect ReadTsKvQuery. Aggregation can't be empty");
|
throw new IncorrectParameterException("Incorrect ReadTsKvQuery. Aggregation can't be empty");
|
||||||
}
|
}
|
||||||
|
if(!Aggregation.NONE.equals(query.getAggregation())) {
|
||||||
|
long step = Math.max(query.getInterval(), 1000);
|
||||||
|
long intervalCounts = (query.getEndTs() - query.getStartTs()) / step;
|
||||||
|
if (intervalCounts > maxTsIntervals || intervalCounts < 0) {
|
||||||
|
throw new IncorrectParameterException("Incorrect TsKvQuery. Number of intervals is to high - " + intervalCounts + ". " +
|
||||||
|
"Please increase 'interval' parameter for your query or reduce the time range of the query.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validate(DeleteTsKvQuery query) {
|
private static void validate(DeleteTsKvQuery query) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user