Browse Source

Clean up tenant service

pull/10201/head
ViacheslavKlimov 3 years ago
parent
commit
886c448d61
  1. 18
      application/src/main/java/org/thingsboard/server/service/housekeeper/DefaultHousekeeperService.java
  2. 10
      application/src/main/java/org/thingsboard/server/service/housekeeper/HousekeeperReprocessingService.java
  3. 8
      application/src/main/java/org/thingsboard/server/service/housekeeper/stats/HousekeeperStatsService.java
  4. 2
      application/src/main/java/org/thingsboard/server/service/notification/rule/trigger/RuleEngineComponentLifecycleEventTriggerProcessor.java
  5. 3
      common/data/src/main/java/org/thingsboard/server/common/data/EntityType.java
  6. 6
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java
  7. 8
      dao/src/main/java/org/thingsboard/server/dao/housekeeper/CleanUpService.java
  8. 3
      dao/src/main/java/org/thingsboard/server/dao/housekeeper/data/AlarmsUnassignHousekeeperTask.java
  9. 3
      dao/src/main/java/org/thingsboard/server/dao/housekeeper/data/EntitiesDeletionHousekeeperTask.java
  10. 1
      dao/src/main/java/org/thingsboard/server/dao/service/validator/AssetProfileDataValidator.java
  11. 2
      dao/src/main/java/org/thingsboard/server/dao/service/validator/DashboardDataValidator.java
  12. 2
      dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceDataValidator.java
  13. 1
      dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java
  14. 1
      dao/src/main/java/org/thingsboard/server/dao/service/validator/ResourceDataValidator.java
  15. 1
      dao/src/main/java/org/thingsboard/server/dao/service/validator/RuleChainDataValidator.java
  16. 39
      dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsServiceImpl.java
  17. 113
      dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java
  18. 2
      dao/src/main/java/org/thingsboard/server/dao/usagerecord/ApiUsageStateServiceImpl.java

18
application/src/main/java/org/thingsboard/server/service/housekeeper/DefaultHousekeeperService.java

@ -97,12 +97,12 @@ public class DefaultHousekeeperService implements HousekeeperService {
for (TbProtoQueueMsg<ToHousekeeperServiceMsg> msg : msgs) {
log.trace("Processing task: {}", msg);
try {
processTask(msg);
processTask(msg.getValue());
} catch (InterruptedException e) {
return;
} catch (Throwable e) {
log.error("Unexpected error during message processing [{}]", msg, e);
reprocessingService.submitForReprocessing(msg, e);
reprocessingService.submitForReprocessing(msg.getValue(), e);
}
}
consumer.commit();
@ -122,8 +122,7 @@ public class DefaultHousekeeperService implements HousekeeperService {
}
@SuppressWarnings("unchecked")
protected <T extends HousekeeperTask> void processTask(TbProtoQueueMsg<ToHousekeeperServiceMsg> queueMsg) throws Exception {
ToHousekeeperServiceMsg msg = queueMsg.getValue();
protected <T extends HousekeeperTask> void processTask(ToHousekeeperServiceMsg msg) throws Exception {
HousekeeperTask task = JacksonUtil.fromString(msg.getTask().getValue(), HousekeeperTask.class);
HousekeeperTaskProcessor<T> taskProcessor = (HousekeeperTaskProcessor<T>) taskProcessors.get(task.getTaskType());
if (taskProcessor == null) {
@ -131,8 +130,9 @@ public class DefaultHousekeeperService implements HousekeeperService {
}
if (log.isDebugEnabled()) {
log.debug("[{}][{}][{}] {} task {}", task.getTenantId(), task.getEntityId().getEntityType(), task.getEntityId(),
msg.getTask().getErrorsCount() == 0 ? "Processing" : "Reprocessing", task.getTaskType());
log.debug("[{}] {} task {}", task.getTenantId(),
msg.getTask().getErrorsCount() == 0 ? "Processing" : "Reprocessing",
msg.getTask().getValue());
}
try {
Future<Object> future = executor.submit(() -> {
@ -140,7 +140,7 @@ public class DefaultHousekeeperService implements HousekeeperService {
return null;
});
future.get(taskProcessingTimeout, TimeUnit.MILLISECONDS);
statsService.reportProcessed(task, msg);
statsService.reportProcessed(task.getTaskType(), msg);
} catch (InterruptedException e) {
throw e;
} catch (Throwable e) {
@ -153,8 +153,8 @@ public class DefaultHousekeeperService implements HousekeeperService {
log.error("[{}][{}][{}] {} task processing failed, submitting for reprocessing (attempt {}): {}",
task.getTenantId(), task.getEntityId().getEntityType(), task.getEntityId(),
task.getTaskType(), msg.getTask().getAttempt(), task, error);
reprocessingService.submitForReprocessing(queueMsg, error);
statsService.reportFailure(task, msg);
reprocessingService.submitForReprocessing(msg, error);
statsService.reportFailure(task.getTaskType(), msg);
}
}

10
application/src/main/java/org/thingsboard/server/service/housekeeper/HousekeeperReprocessingService.java

@ -38,6 +38,7 @@ import javax.annotation.PreDestroy;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@ -107,12 +108,12 @@ public class HousekeeperReprocessingService {
for (TbProtoQueueMsg<ToHousekeeperServiceMsg> msg : msgs) {
log.trace("Reprocessing task: {}", msg);
try {
housekeeperService.processTask(msg);
housekeeperService.processTask(msg.getValue());
} catch (InterruptedException e) {
return;
} catch (Throwable e) {
log.error("Unexpected error during message reprocessing [{}]", msg, e);
submitForReprocessing(msg, e);
submitForReprocessing(msg.getValue(), e);
// fixme: msgs are duplicated
}
}
@ -134,8 +135,7 @@ public class HousekeeperReprocessingService {
}
// todo: dead letter queue if attempts count exceeds the configured maximum
public void submitForReprocessing(TbProtoQueueMsg<ToHousekeeperServiceMsg> queueMsg, Throwable error) {
ToHousekeeperServiceMsg msg = queueMsg.getValue();
public void submitForReprocessing(ToHousekeeperServiceMsg msg, Throwable error) {
HousekeeperTaskProto task = msg.getTask();
int attempt = task.getAttempt() + 1;
@ -152,7 +152,7 @@ public class HousekeeperReprocessingService {
log.trace("Submitting for reprocessing: {}", msg);
var producer = producerProvider.getHousekeeperReprocessingMsgProducer();
TopicPartitionInfo tpi = TopicPartitionInfo.builder().topic(producer.getDefaultTopic()).build();
producer.send(tpi, new TbProtoQueueMsg<>(queueMsg.getKey(), msg), null);
producer.send(tpi, new TbProtoQueueMsg<>(UUID.randomUUID(), msg), null); // reprocessing topic has single partition, so we don't care about the msg key
}
@PreDestroy

8
application/src/main/java/org/thingsboard/server/service/housekeeper/stats/HousekeeperStatsService.java

@ -67,8 +67,8 @@ public class HousekeeperStatsService {
}
}
public void reportProcessed(HousekeeperTask task, ToHousekeeperServiceMsg msg) {
HousekeeperStats stats = this.stats.get(task.getTaskType());
public void reportProcessed(HousekeeperTaskType taskType, ToHousekeeperServiceMsg msg) {
HousekeeperStats stats = this.stats.get(taskType);
if (msg.getTask().getErrorsCount() == 0) {
stats.getProcessedCounter().increment();
} else {
@ -76,8 +76,8 @@ public class HousekeeperStatsService {
}
}
public void reportFailure(HousekeeperTask task, ToHousekeeperServiceMsg msg) {
HousekeeperStats stats = this.stats.get(task.getTaskType());
public void reportFailure(HousekeeperTaskType taskType, ToHousekeeperServiceMsg msg) {
HousekeeperStats stats = this.stats.get(taskType);
if (msg.getTask().getErrorsCount() == 0) {
stats.getFailedProcessingCounter().increment();
} else {

2
application/src/main/java/org/thingsboard/server/service/notification/rule/trigger/RuleEngineComponentLifecycleEventTriggerProcessor.java

@ -47,7 +47,7 @@ public class RuleEngineComponentLifecycleEventTriggerProcessor implements Notifi
return false;
}
}
if (!partitionService.resolve(ServiceType.TB_RULE_ENGINE, trigger.getTenantId(), trigger.getComponentId()).isMyPartition()) {
if (!partitionService.isMyPartition(ServiceType.TB_RULE_ENGINE, trigger.getTenantId(), trigger.getComponentId())) {
return false;
}

3
common/data/src/main/java/org/thingsboard/server/common/data/EntityType.java

@ -58,8 +58,7 @@ public enum EntityType {
NOTIFICATION_TEMPLATE (30),
NOTIFICATION_REQUEST (31),
NOTIFICATION (32),
NOTIFICATION_RULE (33),
ADMIN_SETTINGS(34);
NOTIFICATION_RULE (33);
@Getter
private final int protoNumber; // Corresponds to EntityTypeProto

6
dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java

@ -18,7 +18,6 @@ package org.thingsboard.server.dao.device;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionalEventListener;
@ -47,7 +46,6 @@ import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
import org.thingsboard.server.dao.eventsourcing.DeleteEntityEvent;
import org.thingsboard.server.dao.eventsourcing.SaveEntityEvent;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.queue.QueueService;
import org.thingsboard.server.dao.resource.ImageService;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.PaginatedRemover;
@ -91,10 +89,6 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device
@Autowired
private DataValidator<DeviceProfile> deviceProfileValidator;
@Lazy
@Autowired
private QueueService queueService;
@Autowired
private ImageService imageService;

8
dao/src/main/java/org/thingsboard/server/dao/housekeeper/CleanUpService.java

@ -37,13 +37,11 @@ public class CleanUpService {
private final HousekeeperService housekeeperService;
private final RelationService relationService;
@TransactionalEventListener(fallbackExecution = true) // todo: consider moving this to HousekeeperService
@TransactionalEventListener(fallbackExecution = true)
public void handleEntityDeletionEvent(DeleteEntityEvent<?> event) {
TenantId tenantId = event.getTenantId();
EntityId entityId = event.getEntityId();
log.trace("[{}] DeleteEntityEvent handler: {}", tenantId, event);
log.info("[{}][{}][{}] Handling DeleteEntityEvent", tenantId, entityId.getEntityType(), entityId.getId());
log.trace("[{}] Handling entity deletion event: {}", tenantId, event);
cleanUpRelatedData(tenantId, entityId);
if (entityId.getEntityType() == EntityType.USER) {
housekeeperService.submitTask(HousekeeperTask.unassignAlarms((User) event.getEntity()));
@ -60,7 +58,7 @@ public class CleanUpService {
}
public void removeTenantEntities(TenantId tenantId, EntityType... entityTypes) {
UUID tasksKey = UUID.randomUUID(); // so that all tasks are processed synchronously from one partition
UUID tasksKey = UUID.randomUUID(); // so that all tasks are pushed to single partition to be processed synchronously
for (EntityType entityType : entityTypes) {
housekeeperService.submitTask(tasksKey, HousekeeperTask.deleteEntities(tenantId, entityType));
}

3
dao/src/main/java/org/thingsboard/server/dao/housekeeper/data/AlarmsUnassignHousekeeperTask.java

@ -15,12 +15,15 @@
*/
package org.thingsboard.server.dao.housekeeper.data;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.thingsboard.server.common.data.User;
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AlarmsUnassignHousekeeperTask extends HousekeeperTask {
private String userTitle;

3
dao/src/main/java/org/thingsboard/server/dao/housekeeper/data/EntitiesDeletionHousekeeperTask.java

@ -15,13 +15,16 @@
*/
package org.thingsboard.server.dao.housekeeper.data;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.TenantId;
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class EntitiesDeletionHousekeeperTask extends HousekeeperTask {
private EntityType entityType;

1
dao/src/main/java/org/thingsboard/server/dao/service/validator/AssetProfileDataValidator.java

@ -42,6 +42,7 @@ public class AssetProfileDataValidator extends DataValidator<AssetProfile> {
@Lazy
private AssetProfileService assetProfileService;
@Autowired
@Lazy
private TenantService tenantService;
@Lazy
@Autowired

2
dao/src/main/java/org/thingsboard/server/dao/service/validator/DashboardDataValidator.java

@ -16,6 +16,7 @@
package org.thingsboard.server.dao.service.validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.EntityType;
@ -28,6 +29,7 @@ import org.thingsboard.server.dao.tenant.TenantService;
public class DashboardDataValidator extends DataValidator<Dashboard> {
@Autowired
@Lazy
private TenantService tenantService;
@Override

2
dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceDataValidator.java

@ -16,6 +16,7 @@
package org.thingsboard.server.dao.service.validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Device;
@ -39,6 +40,7 @@ public class DeviceDataValidator extends AbstractHasOtaPackageValidator<Device>
private DeviceDao deviceDao;
@Autowired
@Lazy
private TenantService tenantService;
@Autowired

1
dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java

@ -86,6 +86,7 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator<D
@Autowired
private DeviceDao deviceDao;
@Autowired
@Lazy
private TenantService tenantService;
@Lazy
@Autowired

1
dao/src/main/java/org/thingsboard/server/dao/service/validator/ResourceDataValidator.java

@ -49,6 +49,7 @@ public class ResourceDataValidator extends DataValidator<TbResource> {
private WidgetTypeDao widgetTypeDao;
@Autowired
@Lazy
private TenantService tenantService;
@Autowired

1
dao/src/main/java/org/thingsboard/server/dao/service/validator/RuleChainDataValidator.java

@ -53,6 +53,7 @@ public class RuleChainDataValidator extends DataValidator<RuleChain> {
private RuleChainService ruleChainService;
@Autowired
@Lazy
private TenantService tenantService;
@Override

39
dao/src/main/java/org/thingsboard/server/dao/settings/AdminSettingsServiceImpl.java

@ -21,21 +21,15 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.AdminSettings;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.AdminSettingsId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.HasId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.entity.EntityDaoService;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.Validator;
import java.util.Optional;
@Service
@Slf4j
public class AdminSettingsServiceImpl implements AdminSettingsService, EntityDaoService {
public class AdminSettingsServiceImpl implements AdminSettingsService {
@Autowired
private AdminSettingsDao adminSettingsDao;
@ -46,7 +40,7 @@ public class AdminSettingsServiceImpl implements AdminSettingsService, EntityDao
public AdminSettings findAdminSettingsById(TenantId tenantId, AdminSettingsId adminSettingsId) {
log.trace("Executing findAdminSettingsById [{}]", adminSettingsId);
Validator.validateId(adminSettingsId, "Incorrect adminSettingsId " + adminSettingsId);
return adminSettingsDao.findById(tenantId, adminSettingsId.getId());
return adminSettingsDao.findById(tenantId, adminSettingsId.getId());
}
@Override
@ -65,15 +59,15 @@ public class AdminSettingsServiceImpl implements AdminSettingsService, EntityDao
public AdminSettings saveAdminSettings(TenantId tenantId, AdminSettings adminSettings) {
log.trace("Executing saveAdminSettings [{}]", adminSettings);
adminSettingsValidator.validate(adminSettings, data -> tenantId);
if (adminSettings.getKey().equals("mail")){
if (adminSettings.getKey().equals("mail")) {
AdminSettings mailSettings = findAdminSettingsByKey(tenantId, "mail");
if (mailSettings != null) {
JsonNode newJsonValue = adminSettings.getJsonValue();
JsonNode oldJsonValue = mailSettings.getJsonValue();
if (!newJsonValue.has("password") && oldJsonValue.has("password")){
((ObjectNode) newJsonValue).put("password", oldJsonValue.get("password").asText());
if (!newJsonValue.has("password") && oldJsonValue.has("password")) {
((ObjectNode) newJsonValue).put("password", oldJsonValue.get("password").asText());
}
if (!newJsonValue.has("refreshToken") && oldJsonValue.has("refreshToken")){
if (!newJsonValue.has("refreshToken") && oldJsonValue.has("refreshToken")) {
((ObjectNode) newJsonValue).put("refreshToken", oldJsonValue.get("refreshToken").asText());
}
dropTokenIfProviderInfoChanged(newJsonValue, oldJsonValue);
@ -98,12 +92,12 @@ public class AdminSettingsServiceImpl implements AdminSettingsService, EntityDao
}
private void dropTokenIfProviderInfoChanged(JsonNode newJsonValue, JsonNode oldJsonValue) {
if (newJsonValue.has("enableOauth2") && newJsonValue.get("enableOauth2").asBoolean()){
if (newJsonValue.has("enableOauth2") && newJsonValue.get("enableOauth2").asBoolean()) {
if (!newJsonValue.get("providerId").equals(oldJsonValue.get("providerId")) ||
!newJsonValue.get("clientId").equals(oldJsonValue.get("clientId")) ||
!newJsonValue.get("clientSecret").equals(oldJsonValue.get("clientSecret")) ||
!newJsonValue.get("redirectUri").equals(oldJsonValue.get("redirectUri")) ||
(newJsonValue.has("providerTenantId") && !newJsonValue.get("providerTenantId").equals(oldJsonValue.get("providerTenantId")))){
(newJsonValue.has("providerTenantId") && !newJsonValue.get("providerTenantId").equals(oldJsonValue.get("providerTenantId")))) {
((ObjectNode) newJsonValue).put("tokenGenerated", false);
((ObjectNode) newJsonValue).remove("refreshToken");
((ObjectNode) newJsonValue).remove("refreshTokenExpires");
@ -111,19 +105,4 @@ public class AdminSettingsServiceImpl implements AdminSettingsService, EntityDao
}
}
@Override
public void deleteByTenantId(TenantId tenantId) {
deleteAdminSettingsByTenantId(tenantId);
}
@Override
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
return Optional.empty();
}
@Override
public EntityType getEntityType() {
return EntityType.ADMIN_SETTINGS;
}
}

113
dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java

@ -16,9 +16,8 @@
package org.thingsboard.server.dao.tenant;
import com.google.common.util.concurrent.ListenableFuture;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionalEventListener;
@ -34,32 +33,17 @@ import org.thingsboard.server.common.data.id.TenantProfileId;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.dao.asset.AssetProfileService;
import org.thingsboard.server.dao.asset.AssetService;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.dao.device.DeviceProfileService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
import org.thingsboard.server.dao.eventsourcing.DeleteEntityEvent;
import org.thingsboard.server.dao.eventsourcing.SaveEntityEvent;
import org.thingsboard.server.dao.notification.NotificationRequestService;
import org.thingsboard.server.dao.notification.NotificationRuleService;
import org.thingsboard.server.dao.notification.NotificationSettingsService;
import org.thingsboard.server.dao.notification.NotificationTargetService;
import org.thingsboard.server.dao.notification.NotificationTemplateService;
import org.thingsboard.server.dao.ota.OtaPackageService;
import org.thingsboard.server.dao.queue.QueueService;
import org.thingsboard.server.dao.resource.ResourceService;
import org.thingsboard.server.dao.rpc.RpcService;
import org.thingsboard.server.dao.rule.RuleChainService;
import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.PaginatedRemover;
import org.thingsboard.server.dao.service.Validator;
import org.thingsboard.server.dao.settings.AdminSettingsService;
import org.thingsboard.server.dao.usagerecord.ApiUsageStateService;
import org.thingsboard.server.dao.user.UserService;
import org.thingsboard.server.dao.widget.WidgetTypeService;
import org.thingsboard.server.dao.widget.WidgetsBundleService;
import java.util.List;
import java.util.Optional;
@ -68,89 +52,22 @@ import static org.thingsboard.server.dao.service.Validator.validateId;
@Service("TenantDaoService")
@Slf4j
@RequiredArgsConstructor
public class TenantServiceImpl extends AbstractCachedEntityService<TenantId, Tenant, TenantEvictEvent> implements TenantService {
private static final String DEFAULT_TENANT_REGION = "Global";
public static final String INCORRECT_TENANT_ID = "Incorrect tenantId ";
@Autowired
private TenantDao tenantDao;
@Autowired
private TenantProfileService tenantProfileService;
@Autowired
@Lazy
private UserService userService;
@Autowired
private CustomerService customerService;
@Autowired
private AssetService assetService;
@Autowired
private AssetProfileService assetProfileService;
@Autowired
private DeviceService deviceService;
@Autowired
private DeviceProfileService deviceProfileService;
@Lazy
@Autowired
private ApiUsageStateService apiUsageStateService;
@Autowired
private WidgetsBundleService widgetsBundleService;
@Autowired
private WidgetTypeService widgetTypeService;
@Autowired
private DashboardService dashboardService;
@Autowired
private RuleChainService ruleChainService;
@Autowired
private ResourceService resourceService;
@Autowired
@Lazy
private OtaPackageService otaPackageService;
@Autowired
private RpcService rpcService;
@Autowired
private DataValidator<Tenant> tenantValidator;
@Lazy
@Autowired
private QueueService queueService;
@Autowired
private AdminSettingsService adminSettingsService;
@Autowired
private NotificationSettingsService notificationSettingsService;
@Autowired
private NotificationRequestService notificationRequestService;
@Autowired
private NotificationRuleService notificationRuleService;
@Autowired
private NotificationTemplateService notificationTemplateService;
@Autowired
private NotificationTargetService notificationTargetService;
@Autowired
protected TbTransactionalCache<TenantId, Boolean> existsTenantCache;
private final TenantDao tenantDao;
private final TenantProfileService tenantProfileService;
private final UserService userService;
private final AssetProfileService assetProfileService;
private final DeviceProfileService deviceProfileService;
private final ApiUsageStateService apiUsageStateService;
private final AdminSettingsService adminSettingsService;
private final NotificationSettingsService notificationSettingsService;
private final DataValidator<Tenant> tenantValidator;
private final TbTransactionalCache<TenantId, Boolean> existsTenantCache;
@TransactionalEventListener(classes = TenantEvictEvent.class)
@Override
@ -218,16 +135,18 @@ public class TenantServiceImpl extends AbstractCachedEntityService<TenantId, Ten
Validator.validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
userService.deleteByTenantId(tenantId);
adminSettingsService.deleteAdminSettingsByTenantId(tenantId);
notificationSettingsService.deleteNotificationSettings(tenantId);
tenantDao.removeById(tenantId, tenantId.getId());
notificationSettingsService.deleteNotificationSettings(tenantId); // fixme: maybe remove ADMIN_SETTINGS entity type, just delete here or in the CleanUpService
// fixme: we should publish to housekeeper when a transaction is committed (or better after msg was broadcasted): move this to cleanup-service
cleanUpService.removeTenantEntities(tenantId, // don't forget to implement deleteByTenantId from EntityDaoService when adding entity type to this list
EntityType.ENTITY_VIEW, EntityType.WIDGETS_BUNDLE, EntityType.WIDGET_TYPE,
EntityType.ASSET, EntityType.ASSET_PROFILE, EntityType.DEVICE, EntityType.DEVICE_PROFILE,
EntityType.DASHBOARD, EntityType.CUSTOMER, EntityType.EDGE, EntityType.RULE_CHAIN,
EntityType.API_USAGE_STATE, EntityType.TB_RESOURCE, EntityType.OTA_PACKAGE, EntityType.RPC,
EntityType.QUEUE, EntityType.NOTIFICATION_REQUEST, EntityType.NOTIFICATION_RULE,
EntityType.NOTIFICATION_TEMPLATE, EntityType.NOTIFICATION_TARGET, EntityType.ADMIN_SETTINGS
EntityType.NOTIFICATION_TEMPLATE, EntityType.NOTIFICATION_TARGET
);
publishEvictEvent(new TenantEvictEvent(tenantId, true));

2
dao/src/main/java/org/thingsboard/server/dao/usagerecord/ApiUsageStateServiceImpl.java

@ -59,7 +59,7 @@ public class ApiUsageStateServiceImpl extends AbstractEntityService implements A
private final DataValidator<ApiUsageState> apiUsageStateValidator;
public ApiUsageStateServiceImpl(ApiUsageStateDao apiUsageStateDao, TenantProfileDao tenantProfileDao,
TenantService tenantService, @Lazy TimeseriesService tsService,
@Lazy TenantService tenantService, @Lazy TimeseriesService tsService,
DataValidator<ApiUsageState> apiUsageStateValidator) {
this.apiUsageStateDao = apiUsageStateDao;
this.tenantProfileDao = tenantProfileDao;

Loading…
Cancel
Save