diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java index cc9bc5b5c5..2fe35cc3c9 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java @@ -674,9 +674,9 @@ public final class EdgeGrpcSession implements Closeable { result.add(ctx.getDeviceProcessor().processDeviceCredentialsMsg(edge.getTenantId(), deviceCredentialsUpdateMsg)); } } - if (uplinkMsg.getDeviceProfileUpdateMsgCount() > 0) { - for (DeviceProfileUpdateMsg deviceProfileUpdateMsg : uplinkMsg.getDeviceProfileUpdateMsgList()) { - result.add(ctx.getDeviceProfileProcessor().processDeviceProfileMsgFromEdge(edge.getTenantId(), edge, deviceProfileUpdateMsg)); + if (uplinkMsg.getAssetProfileUpdateMsgCount() > 0) { + for (AssetProfileUpdateMsg assetProfileUpdateMsg : uplinkMsg.getAssetProfileUpdateMsgList()) { + result.add(ctx.getAssetProfileProcessor().processAssetProfileMsgFromEdge(edge.getTenantId(), edge, assetProfileUpdateMsg)); } } if (uplinkMsg.getAssetUpdateMsgCount() > 0) { @@ -684,16 +684,16 @@ public final class EdgeGrpcSession implements Closeable { result.add(ctx.getAssetProcessor().processAssetMsgFromEdge(edge.getTenantId(), edge, assetUpdateMsg)); } } - if (uplinkMsg.getAssetProfileUpdateMsgCount() > 0) { - for (AssetProfileUpdateMsg assetProfileUpdateMsg : uplinkMsg.getAssetProfileUpdateMsgList()) { - result.add(ctx.getAssetProfileProcessor().processAssetProfileMsgFromEdge(edge.getTenantId(), edge, assetProfileUpdateMsg)); - } - } if (uplinkMsg.getAlarmUpdateMsgCount() > 0) { for (AlarmUpdateMsg alarmUpdateMsg : uplinkMsg.getAlarmUpdateMsgList()) { result.add(ctx.getAlarmProcessor().processAlarmMsg(edge.getTenantId(), alarmUpdateMsg)); } } + if (uplinkMsg.getDeviceProfileUpdateMsgCount() > 0) { + for (DeviceProfileUpdateMsg deviceProfileUpdateMsg : uplinkMsg.getDeviceProfileUpdateMsgList()) { + result.add(ctx.getDeviceProfileProcessor().processDeviceProfileMsgFromEdge(edge.getTenantId(), edge, deviceProfileUpdateMsg)); + } + } if (uplinkMsg.getRelationUpdateMsgCount() > 0) { for (RelationUpdateMsg relationUpdateMsg : uplinkMsg.getRelationUpdateMsgList()) { result.add(ctx.getRelationProcessor().processRelationMsg(edge.getTenantId(), relationUpdateMsg)); diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/BaseEdgeProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/BaseEdgeProcessor.java index ee7542f22c..ea2236374e 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/BaseEdgeProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/BaseEdgeProcessor.java @@ -114,11 +114,7 @@ import java.util.concurrent.locks.ReentrantLock; public abstract class BaseEdgeProcessor { protected static final Lock deviceCreationLock = new ReentrantLock(); - protected static final Lock deviceProfileCreationLock = new ReentrantLock(); protected static final Lock assetCreationLock = new ReentrantLock(); - protected static final Lock assetProfileCreationLock = new ReentrantLock(); - protected static final Lock dashboardCreationLock = new ReentrantLock(); - protected static final Lock entityViewCreationLock = new ReentrantLock(); protected static final int DEFAULT_PAGE_SIZE = 100; diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/asset/AssetEdgeProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/asset/AssetEdgeProcessor.java index 0c25e6b5ca..3e61a538c5 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/asset/AssetEdgeProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/asset/AssetEdgeProcessor.java @@ -115,7 +115,7 @@ public class AssetEdgeProcessor extends BaseAssetProcessor { @Override public void onFailure(Throwable t) { - log.debug("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", asset, t); + log.warn("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", asset, t); } }); } catch (JsonProcessingException | IllegalArgumentException e) { diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/asset/AssetProfileEdgeProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/asset/AssetProfileEdgeProcessor.java index 5d14b17f1a..3cae9c5123 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/asset/AssetProfileEdgeProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/asset/AssetProfileEdgeProcessor.java @@ -64,12 +64,8 @@ public class AssetProfileEdgeProcessor extends BaseAssetProfileProcessor { return handleUnsupportedMsgType(assetProfileUpdateMsg.getMsgType()); } } catch (DataValidationException e) { - if (e.getMessage().contains("limit reached")) { - log.warn("[{}] Number of allowed asset profile violated {}", tenantId, assetProfileUpdateMsg, e); - return Futures.immediateFuture(null); - } else { - return Futures.immediateFailedFuture(e); - } + log.warn("Failed to process AssetProfileUpdateMsg from Edge [{}]", assetProfileUpdateMsg, e); + return Futures.immediateFailedFuture(e); } finally { edgeSynchronizationManager.getSync().remove(); } @@ -97,7 +93,7 @@ public class AssetProfileEdgeProcessor extends BaseAssetProfileProcessor { @Override public void onFailure(Throwable t) { - log.debug("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", assetProfile, t); + log.warn("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", assetProfile, t); } }); } catch (JsonProcessingException | IllegalArgumentException e) { diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/asset/BaseAssetProfileProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/asset/BaseAssetProfileProcessor.java index 3f3eab383d..4fe778402f 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/asset/BaseAssetProfileProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/asset/BaseAssetProfileProcessor.java @@ -33,7 +33,7 @@ public class BaseAssetProfileProcessor extends BaseEdgeProcessor { protected boolean saveOrUpdateAssetProfile(TenantId tenantId, AssetProfileId assetProfileId, AssetProfileUpdateMsg assetProfileUpdateMsg) { boolean created = false; - assetProfileCreationLock.lock(); + assetCreationLock.lock(); try { AssetProfile assetProfile = assetProfileService.findAssetProfileById(tenantId, assetProfileId); String assetProfileName = assetProfileUpdateMsg.getName(); @@ -62,7 +62,7 @@ public class BaseAssetProfileProcessor extends BaseEdgeProcessor { } assetProfileService.saveAssetProfile(assetProfile, false); } finally { - assetProfileCreationLock.unlock(); + assetCreationLock.unlock(); } return created; } diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/dashboard/BaseDashboardProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/dashboard/BaseDashboardProcessor.java index 063d405a84..b055c03cf7 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/dashboard/BaseDashboardProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/dashboard/BaseDashboardProcessor.java @@ -34,39 +34,35 @@ public abstract class BaseDashboardProcessor extends BaseEdgeProcessor { protected boolean saveOrUpdateDashboard(TenantId tenantId, DashboardId dashboardId, DashboardUpdateMsg dashboardUpdateMsg, CustomerId customerId) { boolean created = false; - dashboardCreationLock.lock(); - try { - Dashboard dashboard = dashboardService.findDashboardById(tenantId, dashboardId); - if (dashboard == null) { - created = true; - dashboard = new Dashboard(); - dashboard.setTenantId(tenantId); - dashboard.setCreatedTime(Uuids.unixTimestamp(dashboardId.getId())); - } - dashboard.setTitle(dashboardUpdateMsg.getTitle()); - dashboard.setConfiguration(JacksonUtil.toJsonNode(dashboardUpdateMsg.getConfiguration())); - Set assignedCustomers = null; - if (dashboardUpdateMsg.hasAssignedCustomers()) { - assignedCustomers = JacksonUtil.fromString(dashboardUpdateMsg.getAssignedCustomers(), new TypeReference<>() {}); - dashboard.setAssignedCustomers(assignedCustomers); - } + Dashboard dashboard = dashboardService.findDashboardById(tenantId, dashboardId); + if (dashboard == null) { + created = true; + dashboard = new Dashboard(); + dashboard.setTenantId(tenantId); + dashboard.setCreatedTime(Uuids.unixTimestamp(dashboardId.getId())); + } + dashboard.setTitle(dashboardUpdateMsg.getTitle()); + dashboard.setConfiguration(JacksonUtil.toJsonNode(dashboardUpdateMsg.getConfiguration())); + Set assignedCustomers = null; + if (dashboardUpdateMsg.hasAssignedCustomers()) { + assignedCustomers = JacksonUtil.fromString(dashboardUpdateMsg.getAssignedCustomers(), new TypeReference<>() { + }); + dashboard.setAssignedCustomers(assignedCustomers); + } - dashboardValidator.validate(dashboard, Dashboard::getTenantId); - if (created) { - dashboard.setId(dashboardId); - } - Dashboard savedDashboard = dashboardService.saveDashboard(dashboard, false); - if (assignedCustomers != null && !assignedCustomers.isEmpty()) { - for (ShortCustomerInfo assignedCustomer : assignedCustomers) { - if (assignedCustomer.getCustomerId().equals(customerId)) { - dashboardService.assignDashboardToCustomer(tenantId, dashboardId, assignedCustomer.getCustomerId()); - } + dashboardValidator.validate(dashboard, Dashboard::getTenantId); + if (created) { + dashboard.setId(dashboardId); + } + Dashboard savedDashboard = dashboardService.saveDashboard(dashboard, false); + if (assignedCustomers != null && !assignedCustomers.isEmpty()) { + for (ShortCustomerInfo assignedCustomer : assignedCustomers) { + if (assignedCustomer.getCustomerId().equals(customerId)) { + dashboardService.assignDashboardToCustomer(tenantId, dashboardId, assignedCustomer.getCustomerId()); } - } else { - unassignCustomersFromDashboard(tenantId, savedDashboard); } - } finally { - dashboardCreationLock.unlock(); + } else { + unassignCustomersFromDashboard(tenantId, savedDashboard); } return created; } diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/dashboard/DashboardEdgeProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/dashboard/DashboardEdgeProcessor.java index a31356c636..59f12ec64b 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/dashboard/DashboardEdgeProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/dashboard/DashboardEdgeProcessor.java @@ -105,7 +105,7 @@ public class DashboardEdgeProcessor extends BaseDashboardProcessor { @Override public void onFailure(Throwable t) { - log.debug("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", dashboard, t); + log.warn("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", dashboard, t); } }); } catch (JsonProcessingException | IllegalArgumentException e) { diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/BaseDeviceProfileProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/BaseDeviceProfileProcessor.java index 9914e0f50d..662a497528 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/BaseDeviceProfileProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/BaseDeviceProfileProcessor.java @@ -45,7 +45,7 @@ public class BaseDeviceProfileProcessor extends BaseEdgeProcessor { protected boolean saveOrUpdateDeviceProfile(TenantId tenantId, DeviceProfileId deviceProfileId, DeviceProfileUpdateMsg deviceProfileUpdateMsg) { boolean created = false; - deviceProfileCreationLock.lock(); + deviceCreationLock.lock(); try { DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(tenantId, deviceProfileId); if (deviceProfile == null) { @@ -95,7 +95,7 @@ public class BaseDeviceProfileProcessor extends BaseEdgeProcessor { } deviceProfileService.saveDeviceProfile(deviceProfile, false); } finally { - deviceProfileCreationLock.unlock(); + deviceCreationLock.unlock(); } return created; } diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/DeviceEdgeProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/DeviceEdgeProcessor.java index a034369e06..dfa5705840 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/DeviceEdgeProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/DeviceEdgeProcessor.java @@ -124,7 +124,7 @@ public class DeviceEdgeProcessor extends BaseDeviceProcessor { @Override public void onFailure(Throwable t) { - log.debug("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", device, t); + log.warn("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", device, t); } }); } catch (JsonProcessingException | IllegalArgumentException e) { diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/DeviceProfileEdgeProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/DeviceProfileEdgeProcessor.java index e063da0b73..edaffd6f74 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/DeviceProfileEdgeProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/DeviceProfileEdgeProcessor.java @@ -65,12 +65,8 @@ public class DeviceProfileEdgeProcessor extends BaseDeviceProfileProcessor { return handleUnsupportedMsgType(deviceProfileUpdateMsg.getMsgType()); } } catch (DataValidationException e) { - if (e.getMessage().contains("limit reached")) { - log.warn("[{}] Number of allowed device profile violated {}", tenantId, deviceProfileUpdateMsg, e); - return Futures.immediateFuture(null); - } else { - return Futures.immediateFailedFuture(e); - } + log.warn("Failed to process DeviceProfileUpdateMsg from Edge [{}]", deviceProfileUpdateMsg, e); + return Futures.immediateFailedFuture(e); } finally { edgeSynchronizationManager.getSync().remove(); } @@ -98,7 +94,7 @@ public class DeviceProfileEdgeProcessor extends BaseDeviceProfileProcessor { @Override public void onFailure(Throwable t) { - log.debug("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", deviceProfile, t); + log.warn("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", deviceProfile, t); } }); } catch (JsonProcessingException | IllegalArgumentException e) { diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/entityview/BaseEntityViewProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/entityview/BaseEntityViewProcessor.java index 70237c67b9..509b2e5196 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/entityview/BaseEntityViewProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/entityview/BaseEntityViewProcessor.java @@ -38,44 +38,39 @@ public abstract class BaseEntityViewProcessor extends BaseEdgeProcessor { protected Pair saveOrUpdateEntityView(TenantId tenantId, EntityViewId entityViewId, EntityViewUpdateMsg entityViewUpdateMsg, CustomerId customerId) { boolean created = false; boolean entityViewNameUpdated = false; - entityViewCreationLock.lock(); - try { - EntityView entityView = entityViewService.findEntityViewById(tenantId, entityViewId); - String entityViewName = entityViewUpdateMsg.getName(); - if (entityView == null) { - created = true; - entityView = new EntityView(); - entityView.setTenantId(tenantId); - entityView.setCreatedTime(Uuids.unixTimestamp(entityViewId.getId())); - } - EntityView entityViewByName = entityViewService.findEntityViewByTenantIdAndName(tenantId, entityViewName); - if (entityViewByName != null && !entityViewByName.getId().equals(entityViewId)) { - entityViewName = entityViewName + "_" + StringUtils.randomAlphanumeric(15); - log.warn("Entity view with name {} already exists. Renaming entity view name to {}", - entityViewUpdateMsg.getName(), entityViewName); - entityViewNameUpdated = true; - } - entityView.setName(entityViewName); - entityView.setType(entityViewUpdateMsg.getType()); - entityView.setCustomerId(customerId); - entityView.setAdditionalInfo(entityViewUpdateMsg.hasAdditionalInfo() ? - JacksonUtil.toJsonNode(entityViewUpdateMsg.getAdditionalInfo()) : null); - - UUID entityIdUUID = safeGetUUID(entityViewUpdateMsg.getEntityIdMSB(), entityViewUpdateMsg.getEntityIdLSB()); - if (EdgeEntityType.DEVICE.equals(entityViewUpdateMsg.getEntityType())) { - entityView.setEntityId(entityIdUUID != null ? new DeviceId(entityIdUUID) : null); - } else if (EdgeEntityType.ASSET.equals(entityViewUpdateMsg.getEntityType())) { - entityView.setEntityId(entityIdUUID != null ? new AssetId(entityIdUUID) : null); - } - - entityViewValidator.validate(entityView, EntityView::getTenantId); - if (created) { - entityView.setId(entityViewId); - } - entityViewService.saveEntityView(entityView, false); - } finally { - entityViewCreationLock.unlock(); + EntityView entityView = entityViewService.findEntityViewById(tenantId, entityViewId); + String entityViewName = entityViewUpdateMsg.getName(); + if (entityView == null) { + created = true; + entityView = new EntityView(); + entityView.setTenantId(tenantId); + entityView.setCreatedTime(Uuids.unixTimestamp(entityViewId.getId())); } + EntityView entityViewByName = entityViewService.findEntityViewByTenantIdAndName(tenantId, entityViewName); + if (entityViewByName != null && !entityViewByName.getId().equals(entityViewId)) { + entityViewName = entityViewName + "_" + StringUtils.randomAlphanumeric(15); + log.warn("Entity view with name {} already exists. Renaming entity view name to {}", + entityViewUpdateMsg.getName(), entityViewName); + entityViewNameUpdated = true; + } + entityView.setName(entityViewName); + entityView.setType(entityViewUpdateMsg.getType()); + entityView.setCustomerId(customerId); + entityView.setAdditionalInfo(entityViewUpdateMsg.hasAdditionalInfo() ? + JacksonUtil.toJsonNode(entityViewUpdateMsg.getAdditionalInfo()) : null); + + UUID entityIdUUID = safeGetUUID(entityViewUpdateMsg.getEntityIdMSB(), entityViewUpdateMsg.getEntityIdLSB()); + if (EdgeEntityType.DEVICE.equals(entityViewUpdateMsg.getEntityType())) { + entityView.setEntityId(entityIdUUID != null ? new DeviceId(entityIdUUID) : null); + } else if (EdgeEntityType.ASSET.equals(entityViewUpdateMsg.getEntityType())) { + entityView.setEntityId(entityIdUUID != null ? new AssetId(entityIdUUID) : null); + } + + entityViewValidator.validate(entityView, EntityView::getTenantId); + if (created) { + entityView.setId(entityViewId); + } + entityViewService.saveEntityView(entityView, false); return Pair.of(created, entityViewNameUpdated); } } diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/entityview/EntityViewEdgeProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/entityview/EntityViewEdgeProcessor.java index 0353df8086..e78b6b4ff5 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/entityview/EntityViewEdgeProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/entityview/EntityViewEdgeProcessor.java @@ -113,7 +113,7 @@ public class EntityViewEdgeProcessor extends BaseEntityViewProcessor { @Override public void onFailure(Throwable t) { - log.debug("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", entityView, t); + log.warn("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", entityView, t); } }); } catch (JsonProcessingException | IllegalArgumentException e) {