|
|
@ -40,6 +40,7 @@ import org.thingsboard.server.common.data.query.EntityKeyType; |
|
|
import org.thingsboard.server.common.data.query.TsValue; |
|
|
import org.thingsboard.server.common.data.query.TsValue; |
|
|
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
|
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
|
import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
|
|
import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
|
|
|
|
|
import org.thingsboard.server.common.stats.EdqsStatsService; |
|
|
import org.thingsboard.server.edqs.data.ApiUsageStateData; |
|
|
import org.thingsboard.server.edqs.data.ApiUsageStateData; |
|
|
import org.thingsboard.server.edqs.data.AssetData; |
|
|
import org.thingsboard.server.edqs.data.AssetData; |
|
|
import org.thingsboard.server.edqs.data.CustomerData; |
|
|
import org.thingsboard.server.edqs.data.CustomerData; |
|
|
@ -54,7 +55,6 @@ import org.thingsboard.server.edqs.query.EdqsQuery; |
|
|
import org.thingsboard.server.edqs.query.SortableEntityData; |
|
|
import org.thingsboard.server.edqs.query.SortableEntityData; |
|
|
import org.thingsboard.server.edqs.query.processor.EntityQueryProcessor; |
|
|
import org.thingsboard.server.edqs.query.processor.EntityQueryProcessor; |
|
|
import org.thingsboard.server.edqs.query.processor.EntityQueryProcessorFactory; |
|
|
import org.thingsboard.server.edqs.query.processor.EntityQueryProcessorFactory; |
|
|
import org.thingsboard.server.edqs.stats.EdqsStatsService; |
|
|
|
|
|
import org.thingsboard.server.edqs.util.RepositoryUtils; |
|
|
import org.thingsboard.server.edqs.util.RepositoryUtils; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
@ -63,7 +63,6 @@ import java.util.Comparator; |
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
import java.util.Optional; |
|
|
|
|
|
import java.util.Set; |
|
|
import java.util.Set; |
|
|
import java.util.TreeSet; |
|
|
import java.util.TreeSet; |
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
@ -94,9 +93,9 @@ public class TenantRepo { |
|
|
private final Lock entityUpdateLock = new ReentrantLock(); |
|
|
private final Lock entityUpdateLock = new ReentrantLock(); |
|
|
|
|
|
|
|
|
private final TenantId tenantId; |
|
|
private final TenantId tenantId; |
|
|
private final Optional<EdqsStatsService> edqsStatsService; |
|
|
private final EdqsStatsService edqsStatsService; |
|
|
|
|
|
|
|
|
public TenantRepo(TenantId tenantId, Optional<EdqsStatsService> edqsStatsService) { |
|
|
public TenantRepo(TenantId tenantId, EdqsStatsService edqsStatsService) { |
|
|
this.tenantId = tenantId; |
|
|
this.tenantId = tenantId; |
|
|
this.edqsStatsService = edqsStatsService; |
|
|
this.edqsStatsService = edqsStatsService; |
|
|
} |
|
|
} |
|
|
@ -144,7 +143,7 @@ public class TenantRepo { |
|
|
EntityData<?> to = getOrCreate(entity.getTo()); |
|
|
EntityData<?> to = getOrCreate(entity.getTo()); |
|
|
boolean added = repo.add(from, to, entity.getType()); |
|
|
boolean added = repo.add(from, to, entity.getType()); |
|
|
if (added) { |
|
|
if (added) { |
|
|
edqsStatsService.ifPresent(statService -> statService.reportEvent(tenantId, ObjectType.RELATION, EdqsEventType.UPDATED)); |
|
|
edqsStatsService.reportAdded(ObjectType.RELATION); |
|
|
} |
|
|
} |
|
|
} else if (RelationTypeGroup.DASHBOARD.equals(entity.getTypeGroup())) { |
|
|
} else if (RelationTypeGroup.DASHBOARD.equals(entity.getTypeGroup())) { |
|
|
if (EntityRelation.CONTAINS_TYPE.equals(entity.getType()) && entity.getFrom().getEntityType() == EntityType.CUSTOMER) { |
|
|
if (EntityRelation.CONTAINS_TYPE.equals(entity.getType()) && entity.getFrom().getEntityType() == EntityType.CUSTOMER) { |
|
|
@ -164,7 +163,7 @@ public class TenantRepo { |
|
|
if (relationsRepo != null) { |
|
|
if (relationsRepo != null) { |
|
|
boolean removed = relationsRepo.remove(entityRelation.getFrom().getId(), entityRelation.getTo().getId(), entityRelation.getType()); |
|
|
boolean removed = relationsRepo.remove(entityRelation.getFrom().getId(), entityRelation.getTo().getId(), entityRelation.getType()); |
|
|
if (removed) { |
|
|
if (removed) { |
|
|
edqsStatsService.ifPresent(statService -> statService.reportEvent(tenantId, ObjectType.RELATION, EdqsEventType.DELETED)); |
|
|
edqsStatsService.reportRemoved(ObjectType.RELATION); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else if (RelationTypeGroup.DASHBOARD.equals(entityRelation.getTypeGroup())) { |
|
|
} else if (RelationTypeGroup.DASHBOARD.equals(entityRelation.getTypeGroup())) { |
|
|
@ -222,7 +221,7 @@ public class TenantRepo { |
|
|
if (removed.getFields() != null) { |
|
|
if (removed.getFields() != null) { |
|
|
getEntitySet(entityType).remove(removed); |
|
|
getEntitySet(entityType).remove(removed); |
|
|
} |
|
|
} |
|
|
edqsStatsService.ifPresent(statService -> statService.reportEvent(tenantId, ObjectType.fromEntityType(entityType), EdqsEventType.DELETED)); |
|
|
edqsStatsService.reportRemoved(entity.type()); |
|
|
|
|
|
|
|
|
UUID customerId = removed.getCustomerId(); |
|
|
UUID customerId = removed.getCustomerId(); |
|
|
if (customerId != null) { |
|
|
if (customerId != null) { |
|
|
@ -243,7 +242,7 @@ public class TenantRepo { |
|
|
Integer keyId = KeyDictionary.get(attributeKv.getKey()); |
|
|
Integer keyId = KeyDictionary.get(attributeKv.getKey()); |
|
|
boolean added = entityData.putAttr(keyId, attributeKv.getScope(), attributeKv.getDataPoint()); |
|
|
boolean added = entityData.putAttr(keyId, attributeKv.getScope(), attributeKv.getDataPoint()); |
|
|
if (added) { |
|
|
if (added) { |
|
|
edqsStatsService.ifPresent(statService -> statService.reportEvent(tenantId, ObjectType.ATTRIBUTE_KV, EdqsEventType.UPDATED)); |
|
|
edqsStatsService.reportAdded(ObjectType.ATTRIBUTE_KV); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -253,7 +252,7 @@ public class TenantRepo { |
|
|
if (entityData != null) { |
|
|
if (entityData != null) { |
|
|
boolean removed = entityData.removeAttr(KeyDictionary.get(attributeKv.getKey()), attributeKv.getScope()); |
|
|
boolean removed = entityData.removeAttr(KeyDictionary.get(attributeKv.getKey()), attributeKv.getScope()); |
|
|
if (removed) { |
|
|
if (removed) { |
|
|
edqsStatsService.ifPresent(statService -> statService.reportEvent(tenantId, ObjectType.ATTRIBUTE_KV, EdqsEventType.DELETED)); |
|
|
edqsStatsService.reportRemoved(ObjectType.ATTRIBUTE_KV); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -264,7 +263,7 @@ public class TenantRepo { |
|
|
Integer keyId = KeyDictionary.get(latestTsKv.getKey()); |
|
|
Integer keyId = KeyDictionary.get(latestTsKv.getKey()); |
|
|
boolean added = entityData.putTs(keyId, latestTsKv.getDataPoint()); |
|
|
boolean added = entityData.putTs(keyId, latestTsKv.getDataPoint()); |
|
|
if (added) { |
|
|
if (added) { |
|
|
edqsStatsService.ifPresent(statService -> statService.reportEvent(tenantId, ObjectType.LATEST_TS_KV, EdqsEventType.UPDATED)); |
|
|
edqsStatsService.reportAdded(ObjectType.LATEST_TS_KV); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -274,7 +273,7 @@ public class TenantRepo { |
|
|
if (entityData != null) { |
|
|
if (entityData != null) { |
|
|
boolean removed = entityData.removeTs(KeyDictionary.get(latestTsKv.getKey())); |
|
|
boolean removed = entityData.removeTs(KeyDictionary.get(latestTsKv.getKey())); |
|
|
if (removed) { |
|
|
if (removed) { |
|
|
edqsStatsService.ifPresent(statService -> statService.reportEvent(tenantId, ObjectType.LATEST_TS_KV, EdqsEventType.DELETED)); |
|
|
edqsStatsService.reportRemoved(ObjectType.LATEST_TS_KV); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -292,7 +291,7 @@ public class TenantRepo { |
|
|
return getEntityMap(entityType).computeIfAbsent(entityId, id -> { |
|
|
return getEntityMap(entityType).computeIfAbsent(entityId, id -> { |
|
|
log.debug("[{}] Adding {} {}", tenantId, entityType, id); |
|
|
log.debug("[{}] Adding {} {}", tenantId, entityType, id); |
|
|
EntityData<?> entityData = constructEntityData(entityType, entityId); |
|
|
EntityData<?> entityData = constructEntityData(entityType, entityId); |
|
|
edqsStatsService.ifPresent(statService -> statService.reportEvent(tenantId, ObjectType.fromEntityType(entityType), EdqsEventType.UPDATED)); |
|
|
edqsStatsService.reportAdded(ObjectType.fromEntityType(entityType)); |
|
|
return entityData; |
|
|
return entityData; |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|