Search in sources :

Example 1 with DeleteTsKvQuery

use of org.thingsboard.server.common.data.kv.DeleteTsKvQuery in project thingsboard by thingsboard.

the class TelemetryController method deleteTimeseries.

private DeferredResult<ResponseEntity> deleteTimeseries(EntityId entityIdStr, String keysStr, boolean deleteAllDataForKeys, Long startTs, Long endTs, boolean rewriteLatestIfDeleted) throws ThingsboardException {
    List<String> keys = toKeysList(keysStr);
    if (keys.isEmpty()) {
        return getImmediateDeferredResult("Empty keys: " + keysStr, HttpStatus.BAD_REQUEST);
    }
    SecurityUser user = getCurrentUser();
    long deleteFromTs;
    long deleteToTs;
    if (deleteAllDataForKeys) {
        deleteFromTs = 0L;
        deleteToTs = System.currentTimeMillis();
    } else {
        if (startTs == null || endTs == null) {
            return getImmediateDeferredResult("When deleteAllDataForKeys is false, start and end timestamp values shouldn't be empty", HttpStatus.BAD_REQUEST);
        } else {
            deleteFromTs = startTs;
            deleteToTs = endTs;
        }
    }
    return accessValidator.validateEntityAndCallback(user, Operation.WRITE_TELEMETRY, entityIdStr, (result, tenantId, entityId) -> {
        List<DeleteTsKvQuery> deleteTsKvQueries = new ArrayList<>();
        for (String key : keys) {
            deleteTsKvQueries.add(new BaseDeleteTsKvQuery(key, deleteFromTs, deleteToTs, rewriteLatestIfDeleted));
        }
        tsSubService.deleteTimeseriesAndNotify(tenantId, entityId, keys, deleteTsKvQueries, new FutureCallback<>() {

            @Override
            public void onSuccess(@Nullable Void tmp) {
                logTimeseriesDeleted(user, entityId, keys, deleteFromTs, deleteToTs, null);
                result.setResult(new ResponseEntity<>(HttpStatus.OK));
            }

            @Override
            public void onFailure(Throwable t) {
                logTimeseriesDeleted(user, entityId, keys, deleteFromTs, deleteToTs, t);
                result.setResult(new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR));
            }
        });
    });
}
Also used : BaseDeleteTsKvQuery(org.thingsboard.server.common.data.kv.BaseDeleteTsKvQuery) DeleteTsKvQuery(org.thingsboard.server.common.data.kv.DeleteTsKvQuery) BaseDeleteTsKvQuery(org.thingsboard.server.common.data.kv.BaseDeleteTsKvQuery) ArrayList(java.util.ArrayList) ResponseEntity(org.springframework.http.ResponseEntity) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser)

Example 2 with DeleteTsKvQuery

use of org.thingsboard.server.common.data.kv.DeleteTsKvQuery in project thingsboard by thingsboard.

the class BaseTimeseriesService method removeLatest.

@Override
public ListenableFuture<List<TsKvLatestRemovingResult>> removeLatest(TenantId tenantId, EntityId entityId, Collection<String> keys) {
    validate(entityId);
    List<ListenableFuture<TsKvLatestRemovingResult>> futures = Lists.newArrayListWithExpectedSize(keys.size());
    for (String key : keys) {
        DeleteTsKvQuery query = new BaseDeleteTsKvQuery(key, 0, System.currentTimeMillis(), false);
        futures.add(timeseriesLatestDao.removeLatest(tenantId, entityId, query));
    }
    return Futures.allAsList(futures);
}
Also used : BaseDeleteTsKvQuery(org.thingsboard.server.common.data.kv.BaseDeleteTsKvQuery) DeleteTsKvQuery(org.thingsboard.server.common.data.kv.DeleteTsKvQuery) BaseDeleteTsKvQuery(org.thingsboard.server.common.data.kv.BaseDeleteTsKvQuery) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 3 with DeleteTsKvQuery

use of org.thingsboard.server.common.data.kv.DeleteTsKvQuery in project thingsboard by thingsboard.

the class BaseTimeseriesService method remove.

@Override
public ListenableFuture<List<TsKvLatestRemovingResult>> remove(TenantId tenantId, EntityId entityId, List<DeleteTsKvQuery> deleteTsKvQueries) {
    validate(entityId);
    deleteTsKvQueries.forEach(BaseTimeseriesService::validate);
    List<ListenableFuture<TsKvLatestRemovingResult>> futures = Lists.newArrayListWithExpectedSize(deleteTsKvQueries.size() * DELETES_PER_ENTRY);
    for (DeleteTsKvQuery tsKvQuery : deleteTsKvQueries) {
        deleteAndRegisterFutures(tenantId, futures, entityId, tsKvQuery);
    }
    return Futures.allAsList(futures);
}
Also used : BaseDeleteTsKvQuery(org.thingsboard.server.common.data.kv.BaseDeleteTsKvQuery) DeleteTsKvQuery(org.thingsboard.server.common.data.kv.DeleteTsKvQuery) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Aggregations

BaseDeleteTsKvQuery (org.thingsboard.server.common.data.kv.BaseDeleteTsKvQuery)3 DeleteTsKvQuery (org.thingsboard.server.common.data.kv.DeleteTsKvQuery)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ArrayList (java.util.ArrayList)1 ResponseEntity (org.springframework.http.ResponseEntity)1 SecurityUser (org.thingsboard.server.service.security.model.SecurityUser)1