Fixes for telemetry service subscription
This commit is contained in:
		
							parent
							
								
									63395fc8e5
								
							
						
					
					
						commit
						0b379d6b6a
					
				@ -105,6 +105,9 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private ClusterRpcService rpcService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private EntityViewService entityViewService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    @Lazy
 | 
			
		||||
    private DeviceStateService stateService;
 | 
			
		||||
@ -137,6 +140,10 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void addLocalWsSubscription(String sessionId, EntityId entityId, SubscriptionState sub) {
 | 
			
		||||
        if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) {
 | 
			
		||||
            EntityView entityView = entityViewService.findEntityViewById(new EntityViewId(entityId.getId()));
 | 
			
		||||
            entityId = entityView.getEntityId();
 | 
			
		||||
        }
 | 
			
		||||
        Optional<ServerAddress> server = routingService.resolveById(entityId);
 | 
			
		||||
        Subscription subscription;
 | 
			
		||||
        if (server.isPresent()) {
 | 
			
		||||
 | 
			
		||||
@ -39,8 +39,8 @@ public class EntityView extends SearchTextBasedWithAdditionalInfo<EntityViewId>
 | 
			
		||||
    private CustomerId customerId;
 | 
			
		||||
    private String name;
 | 
			
		||||
    private TelemetryEntityView keys;
 | 
			
		||||
    private long startTs;
 | 
			
		||||
    private long endTs;
 | 
			
		||||
    private long startTimeMs;
 | 
			
		||||
    private long endTimeMs;
 | 
			
		||||
 | 
			
		||||
    public EntityView() {
 | 
			
		||||
        super();
 | 
			
		||||
 | 
			
		||||
@ -15,30 +15,21 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.dao.entityview;
 | 
			
		||||
 | 
			
		||||
import com.google.common.base.Function;
 | 
			
		||||
import com.google.common.util.concurrent.FutureCallback;
 | 
			
		||||
import com.google.common.util.concurrent.Futures;
 | 
			
		||||
import com.google.common.util.concurrent.ListenableFuture;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.apache.commons.lang3.StringUtils;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.cache.Cache;
 | 
			
		||||
import org.springframework.cache.CacheManager;
 | 
			
		||||
import org.springframework.cache.annotation.CacheEvict;
 | 
			
		||||
import org.springframework.cache.annotation.CachePut;
 | 
			
		||||
import org.springframework.cache.annotation.Cacheable;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.common.data.Customer;
 | 
			
		||||
import org.thingsboard.server.common.data.DataConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.Device;
 | 
			
		||||
import org.thingsboard.server.common.data.EntitySubtype;
 | 
			
		||||
import org.thingsboard.server.common.data.EntityType;
 | 
			
		||||
import org.thingsboard.server.common.data.EntityView;
 | 
			
		||||
import org.thingsboard.server.common.data.Tenant;
 | 
			
		||||
import org.thingsboard.server.common.data.device.DeviceSearchQuery;
 | 
			
		||||
import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery;
 | 
			
		||||
import org.thingsboard.server.common.data.id.CustomerId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.DeviceId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.EntityId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.EntityViewId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
@ -58,13 +49,9 @@ import org.thingsboard.server.dao.tenant.TenantDao;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.Comparator;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
import static org.thingsboard.server.common.data.CacheConstants.DEVICE_CACHE;
 | 
			
		||||
import static org.thingsboard.server.common.data.CacheConstants.ENTITY_VIEW_CACHE;
 | 
			
		||||
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
 | 
			
		||||
import static org.thingsboard.server.dao.service.Validator.validateId;
 | 
			
		||||
import static org.thingsboard.server.dao.service.Validator.validatePageLink;
 | 
			
		||||
@ -135,17 +122,17 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
 | 
			
		||||
                        List<AttributeKvEntry> filteredAttributes =
 | 
			
		||||
                                attributeKvEntries.stream()
 | 
			
		||||
                                        .filter(attributeKvEntry -> {
 | 
			
		||||
                                            if (entityView.getStartTs() == 0 && entityView.getEndTs() == 0) {
 | 
			
		||||
                                            if (entityView.getStartTimeMs() == 0 && entityView.getEndTimeMs() == 0) {
 | 
			
		||||
                                                return true;
 | 
			
		||||
                                            }
 | 
			
		||||
                                            if (entityView.getEndTs() == 0 && entityView.getStartTs() < attributeKvEntry.getLastUpdateTs()) {
 | 
			
		||||
                                            if (entityView.getEndTimeMs() == 0 && entityView.getStartTimeMs() < attributeKvEntry.getLastUpdateTs()) {
 | 
			
		||||
                                                return true;
 | 
			
		||||
                                            }
 | 
			
		||||
                                            if (entityView.getStartTs() == 0 && entityView.getEndTs() > attributeKvEntry.getLastUpdateTs()) {
 | 
			
		||||
                                            if (entityView.getStartTimeMs() == 0 && entityView.getEndTimeMs() > attributeKvEntry.getLastUpdateTs()) {
 | 
			
		||||
                                                return true;
 | 
			
		||||
                                            }
 | 
			
		||||
                                            return entityView.getStartTs() < attributeKvEntry.getLastUpdateTs()
 | 
			
		||||
                                                    && entityView.getEndTs() > attributeKvEntry.getLastUpdateTs();
 | 
			
		||||
                                            return entityView.getStartTimeMs() < attributeKvEntry.getLastUpdateTs()
 | 
			
		||||
                                                    && entityView.getEndTimeMs() > attributeKvEntry.getLastUpdateTs();
 | 
			
		||||
                                        }).collect(Collectors.toList());
 | 
			
		||||
                        attributesService.save(entityView.getId(), scope, filteredAttributes);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
@ -114,8 +114,8 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> {
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
        this.startTs = entityView.getStartTs();
 | 
			
		||||
        this.endTs = entityView.getEndTs();
 | 
			
		||||
        this.startTs = entityView.getStartTimeMs();
 | 
			
		||||
        this.endTs = entityView.getEndTimeMs();
 | 
			
		||||
        this.searchText = entityView.getSearchText();
 | 
			
		||||
        this.additionalInfo = entityView.getAdditionalInfo();
 | 
			
		||||
    }
 | 
			
		||||
@ -144,8 +144,8 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> {
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
        entityView.setStartTs(startTs);
 | 
			
		||||
        entityView.setEndTs(endTs);
 | 
			
		||||
        entityView.setStartTimeMs(startTs);
 | 
			
		||||
        entityView.setEndTimeMs(endTs);
 | 
			
		||||
        entityView.setAdditionalInfo(additionalInfo);
 | 
			
		||||
        return entityView;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -105,8 +105,8 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
        this.startTs = entityView.getStartTs() != 0L ? entityView.getStartTs() : 0L;
 | 
			
		||||
        this.endTs = entityView.getEndTs() != 0L ? entityView.getEndTs() : 0L;
 | 
			
		||||
        this.startTs = entityView.getStartTimeMs();
 | 
			
		||||
        this.endTs = entityView.getEndTimeMs();
 | 
			
		||||
        this.searchText = entityView.getSearchText();
 | 
			
		||||
        this.additionalInfo = entityView.getAdditionalInfo();
 | 
			
		||||
    }
 | 
			
		||||
@ -141,8 +141,8 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
        entityView.setStartTs(startTs);
 | 
			
		||||
        entityView.setEndTs(endTs);
 | 
			
		||||
        entityView.setStartTimeMs(startTs);
 | 
			
		||||
        entityView.setEndTimeMs(endTs);
 | 
			
		||||
        entityView.setAdditionalInfo(additionalInfo);
 | 
			
		||||
        return entityView;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -84,7 +84,7 @@ public class BaseTimeseriesService implements TimeseriesService {
 | 
			
		||||
            }
 | 
			
		||||
            List<ReadTsKvQuery> queries =
 | 
			
		||||
                    filteredKeys.stream()
 | 
			
		||||
                            .map(key -> new BaseReadTsKvQuery(key, entityView.getStartTs(), entityView.getEndTs(), 1, "ASC"))
 | 
			
		||||
                            .map(key -> new BaseReadTsKvQuery(key, entityView.getStartTimeMs(), entityView.getEndTimeMs(), 1, "ASC"))
 | 
			
		||||
                            .collect(Collectors.toList());
 | 
			
		||||
 | 
			
		||||
            return timeseriesDao.findAllAsync(entityView.getEntityId(), updateQueriesForEntityView(entityView, queries));
 | 
			
		||||
@ -133,8 +133,8 @@ public class BaseTimeseriesService implements TimeseriesService {
 | 
			
		||||
 | 
			
		||||
    private List<ReadTsKvQuery> updateQueriesForEntityView(EntityView entityView, List<ReadTsKvQuery> queries) {
 | 
			
		||||
        return queries.stream().map(query -> {
 | 
			
		||||
            long startTs = entityView.getStartTs() == 0 ? query.getStartTs() : entityView.getStartTs();
 | 
			
		||||
            long endTs = entityView.getEndTs() == 0 ? query.getEndTs() : entityView.getEndTs();
 | 
			
		||||
            long startTs = entityView.getStartTimeMs() == 0 ? query.getStartTs() : entityView.getStartTimeMs();
 | 
			
		||||
            long endTs = entityView.getEndTimeMs() == 0 ? query.getEndTs() : entityView.getEndTimeMs();
 | 
			
		||||
 | 
			
		||||
            return startTs <= query.getStartTs() && endTs >= query.getEndTs() ? query :
 | 
			
		||||
                    new BaseReadTsKvQuery(query.getKey(), startTs, endTs, query.getInterval(), query.getLimit(), query.getAggregation());
 | 
			
		||||
 | 
			
		||||
@ -95,23 +95,25 @@
 | 
			
		||||
                      md-separator-keys="separatorKeys">
 | 
			
		||||
            </md-chips>
 | 
			
		||||
        </section>
 | 
			
		||||
        <section layout="row" layout-align="start start">
 | 
			
		||||
            <mdp-date-picker ng-model="startTs"
 | 
			
		||||
                             mdp-max-date="maxStartTs"
 | 
			
		||||
                             mdp-placeholder="{{ 'entity-view.start-ts' | translate }}"></mdp-date-picker>
 | 
			
		||||
            <mdp-time-picker ng-model="startTs"
 | 
			
		||||
                             mdp-max-date="maxStartTs"
 | 
			
		||||
                             mdp-placeholder="{{ 'entity-view.start-ts' | translate }}"
 | 
			
		||||
                             mdp-auto-switch="true"></mdp-time-picker>
 | 
			
		||||
        </section>
 | 
			
		||||
        <section layout="row" layout-align="start start">
 | 
			
		||||
            <mdp-date-picker ng-model="endTs"
 | 
			
		||||
                             mdp-min-date="minEndTs"
 | 
			
		||||
                             mdp-placeholder="{{ 'entity-view.end-ts' | translate }}"></mdp-date-picker>
 | 
			
		||||
            <mdp-time-picker ng-model="endTs"
 | 
			
		||||
                             mdp-min-date="minEndTs"
 | 
			
		||||
                             mdp-placeholder="{{ 'entity-view.end-ts' | translate }}"
 | 
			
		||||
                             mdp-auto-switch="true"></mdp-time-picker>
 | 
			
		||||
        <section layout="column">
 | 
			
		||||
            <section layout="row" layout-align="start start">
 | 
			
		||||
                <mdp-date-picker ng-model="startTimeMs"
 | 
			
		||||
                                 mdp-max-date="maxStartTimeTs"
 | 
			
		||||
                                 mdp-placeholder="{{ 'entity-view.start-ts' | translate }}"></mdp-date-picker>
 | 
			
		||||
                <mdp-time-picker ng-model="startTimeMs"
 | 
			
		||||
                                 mdp-max-date="maxStartTimeTs"
 | 
			
		||||
                                 mdp-placeholder="{{ 'entity-view.start-ts' | translate }}"
 | 
			
		||||
                                 mdp-auto-switch="true"></mdp-time-picker>
 | 
			
		||||
            </section>
 | 
			
		||||
            <section layout="row" layout-align="start start">
 | 
			
		||||
                <mdp-date-picker ng-model="endTimeMs"
 | 
			
		||||
                                 mdp-min-date="minEndTimeTs"
 | 
			
		||||
                                 mdp-placeholder="{{ 'entity-view.end-ts' | translate }}"></mdp-date-picker>
 | 
			
		||||
                <mdp-time-picker ng-model="endTimeMs"
 | 
			
		||||
                                 mdp-min-date="minEndTimeTs"
 | 
			
		||||
                                 mdp-placeholder="{{ 'entity-view.end-ts' | translate }}"
 | 
			
		||||
                                 mdp-auto-switch="true"></mdp-time-picker>
 | 
			
		||||
            </section>
 | 
			
		||||
        </section>
 | 
			
		||||
	</fieldset>
 | 
			
		||||
</md-content>
 | 
			
		||||
 | 
			
		||||
@ -51,8 +51,12 @@ export default function EntityViewDirective($compile, $templateCache, $filter, t
 | 
			
		||||
                    scope.isPublic = false;
 | 
			
		||||
                    scope.assignedCustomer = null;
 | 
			
		||||
                }
 | 
			
		||||
                scope.startTs = new Date(scope.entityView.startTs);
 | 
			
		||||
                scope.endTs = new Date(scope.entityView.endTs);
 | 
			
		||||
                if (scope.entityView.startTimeMs > 0) {
 | 
			
		||||
                    scope.startTimeMs = new Date(scope.entityView.startTimeMs);
 | 
			
		||||
                }
 | 
			
		||||
                if (scope.entityView.endTimeTs > 0) {
 | 
			
		||||
                    scope.endTimeTs = new Date(scope.entityView.endTimeTs);
 | 
			
		||||
                }
 | 
			
		||||
                if (!scope.entityView.keys) {
 | 
			
		||||
                    scope.entityView.keys = {};
 | 
			
		||||
                    scope.entityView.keys.timeseries = [];
 | 
			
		||||
@ -65,32 +69,32 @@ export default function EntityViewDirective($compile, $templateCache, $filter, t
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        scope.$watch('startTs', function (newDate) {
 | 
			
		||||
        scope.$watch('startTimeMs', function (newDate) {
 | 
			
		||||
            if (newDate) {
 | 
			
		||||
                if (newDate.getTime() > scope.maxStartTs) {
 | 
			
		||||
                    scope.startTs = angular.copy(scope.maxStartTs);
 | 
			
		||||
                if (newDate.getTime() > scope.maxStartTimeMs) {
 | 
			
		||||
                    scope.startTimeMs = angular.copy(scope.maxStartTimeMs);
 | 
			
		||||
                }
 | 
			
		||||
                updateMinMaxDates();
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        scope.$watch('endTs', function (newDate) {
 | 
			
		||||
        scope.$watch('endTimeTs', function (newDate) {
 | 
			
		||||
            if (newDate) {
 | 
			
		||||
                if (newDate.getTime() < scope.minEndTs) {
 | 
			
		||||
                    scope.endTs = angular.copy(scope.minEndTs);
 | 
			
		||||
                if (newDate.getTime() < scope.minEndTimeTs) {
 | 
			
		||||
                    scope.endTimeTs = angular.copy(scope.minEndTimeTs);
 | 
			
		||||
                }
 | 
			
		||||
                updateMinMaxDates();
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        function updateMinMaxDates() {
 | 
			
		||||
            if (scope.endTs) {
 | 
			
		||||
                scope.maxStartTs = angular.copy(new Date(scope.endTs.getTime()));
 | 
			
		||||
                scope.entityView.endTs = scope.endTs.getTime();
 | 
			
		||||
            if (scope.endTimeTs) {
 | 
			
		||||
                scope.maxStartTimeMs = angular.copy(new Date(scope.endTimeTs.getTime()));
 | 
			
		||||
                scope.entityView.endTimeTs = scope.endTimeTs.getTime();
 | 
			
		||||
            }
 | 
			
		||||
            if (scope.startTs) {
 | 
			
		||||
                scope.minEndTs = angular.copy(new Date(scope.startTs.getTime()));
 | 
			
		||||
                scope.entityView.startTs = scope.startTs.getTime();
 | 
			
		||||
            if (scope.startTimeMs) {
 | 
			
		||||
                scope.minEndTimeTs = angular.copy(new Date(scope.startTimeMs.getTime()));
 | 
			
		||||
                scope.entityView.startTimeMs = scope.startTimeMs.getTime();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -827,8 +827,9 @@
 | 
			
		||||
        "unable-entity-view-device-alias-text": "Device alias '{{entityViewAlias}}' can't be deleted as it used by the following widget(s):<br/>{{widgetsList}}",
 | 
			
		||||
        "select-entity-view": "Select entity view",
 | 
			
		||||
        "make-public": "Make entity view public",
 | 
			
		||||
        "start-ts": "Start ts",
 | 
			
		||||
        "end-ts": "End ts",
 | 
			
		||||
        "start-ts": "Start time",
 | 
			
		||||
        "end-ts": "End time",
 | 
			
		||||
        "date-limits": "Date limits",
 | 
			
		||||
        "client-attributes": "Client attributes",
 | 
			
		||||
        "shared-attributes": "Shared attributes",
 | 
			
		||||
        "server-attributes": "Server attributes",
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user