Browse Source

Fix entity update events order

pull/11112/head
ViacheslavKlimov 2 years ago
parent
commit
ea3b5c80f3
  1. 10
      application/src/test/java/org/thingsboard/server/transport/lwm2m/ota/sql/OtaLwM2MIntegrationTest.java
  2. 2
      dao/src/main/java/org/thingsboard/server/dao/customer/CustomerServiceImpl.java
  3. 4
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java
  4. 2
      dao/src/main/java/org/thingsboard/server/dao/edge/EdgeServiceImpl.java

10
application/src/test/java/org/thingsboard/server/transport/lwm2m/ota/sql/OtaLwM2MIntegrationTest.java

@ -59,7 +59,7 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
createDeviceProfile(transportConfiguration); createDeviceProfile(transportConfiguration);
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_WITHOUT_FW_INFO)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_WITHOUT_FW_INFO));
final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO); final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO);
createNewClient(SECURITY_NO_SEC, null, false, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO); createNewClient(SECURITY_NO_SEC, null, false, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO);
awaitObserveReadAll(0, device.getId().getId().toString()); awaitObserveReadAll(0, device.getId().getId().toString());
device.setFirmwareId(createFirmware().getId()); device.setFirmwareId(createFirmware().getId());
@ -145,12 +145,14 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
return tsKvEntries; return tsKvEntries;
} }
private boolean predicateForStatuses (List<TsKvEntry> ts) { private boolean predicateForStatuses(List<TsKvEntry> ts) {
List<OtaPackageUpdateStatus> statuses = ts.stream().sorted(Comparator List<OtaPackageUpdateStatus> statuses = ts.stream()
.comparingLong(TsKvEntry::getTs)).map(KvEntry::getValueAsString) .sorted(Comparator.comparingLong(TsKvEntry::getTs))
.map(KvEntry::getValueAsString)
.map(OtaPackageUpdateStatus::valueOf) .map(OtaPackageUpdateStatus::valueOf)
.collect(Collectors.toList()); .collect(Collectors.toList());
log.warn("{}", statuses); log.warn("{}", statuses);
return statuses.containsAll(expectedStatuses); return statuses.containsAll(expectedStatuses);
} }
} }

2
dao/src/main/java/org/thingsboard/server/dao/customer/CustomerServiceImpl.java

@ -201,9 +201,9 @@ public class CustomerServiceImpl extends AbstractCachedEntityService<CustomerCac
userService.deleteCustomerUsers(customer.getTenantId(), customerId); userService.deleteCustomerUsers(customer.getTenantId(), customerId);
apiUsageStateService.deleteApiUsageStateByEntityId(customerId); apiUsageStateService.deleteApiUsageStateByEntityId(customerId);
customerDao.removeById(tenantId, customerId.getId()); customerDao.removeById(tenantId, customerId.getId());
publishEvictEvent(new CustomerCacheEvictEvent(customer.getTenantId(), customer.getTitle(), null));
countService.publishCountEntityEvictEvent(tenantId, EntityType.CUSTOMER); countService.publishCountEntityEvictEvent(tenantId, EntityType.CUSTOMER);
eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(tenantId).entityId(customerId).build()); eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(tenantId).entityId(customerId).build());
publishEvictEvent(new CustomerCacheEvictEvent(customer.getTenantId(), customer.getTitle(), null));
} }
@Override @Override

4
dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

@ -236,13 +236,13 @@ public class DeviceServiceImpl extends CachedVersionedEntityService<DeviceCacheK
device.setType(deviceProfile.getName()); device.setType(deviceProfile.getName());
device.setDeviceData(syncDeviceData(deviceProfile, device.getDeviceData())); device.setDeviceData(syncDeviceData(deviceProfile, device.getDeviceData()));
Device savedDevice = deviceDao.saveAndFlush(device.getTenantId(), device); Device savedDevice = deviceDao.saveAndFlush(device.getTenantId(), device);
deviceCacheEvictEvent.setSavedDevice(savedDevice);
publishEvictEvent(deviceCacheEvictEvent);
if (device.getId() == null) { if (device.getId() == null) {
countService.publishCountEntityEvictEvent(savedDevice.getTenantId(), EntityType.DEVICE); countService.publishCountEntityEvictEvent(savedDevice.getTenantId(), EntityType.DEVICE);
} }
eventPublisher.publishEvent(SaveEntityEvent.builder().tenantId(savedDevice.getTenantId()).entityId(savedDevice.getId()) eventPublisher.publishEvent(SaveEntityEvent.builder().tenantId(savedDevice.getTenantId()).entityId(savedDevice.getId())
.entity(savedDevice).oldEntity(oldDevice).created(device.getId() == null).build()); .entity(savedDevice).oldEntity(oldDevice).created(device.getId() == null).build());
deviceCacheEvictEvent.setSavedDevice(savedDevice);
publishEvictEvent(deviceCacheEvictEvent);
return savedDevice; return savedDevice;
} catch (Exception t) { } catch (Exception t) {
handleEvictEvent(deviceCacheEvictEvent); handleEvictEvent(deviceCacheEvictEvent);

2
dao/src/main/java/org/thingsboard/server/dao/edge/EdgeServiceImpl.java

@ -246,8 +246,8 @@ public class EdgeServiceImpl extends AbstractCachedEntityService<EdgeCacheKey, E
} }
edgeDao.removeById(tenantId, edgeId.getId()); edgeDao.removeById(tenantId, edgeId.getId());
eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(tenantId).entityId(edgeId).build());
publishEvictEvent(new EdgeCacheEvictEvent(edge.getTenantId(), edge.getName(), null)); publishEvictEvent(new EdgeCacheEvictEvent(edge.getTenantId(), edge.getName(), null));
eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(tenantId).entityId(edgeId).build());
} }
@Override @Override

Loading…
Cancel
Save