Browse Source

Merge remote-tracking branch 'origin/develop/2.6-edge' into develop/2.6-edge

pull/3693/head
deaflynx 6 years ago
parent
commit
5b340c33f3
  1. 1
      application/src/main/data/upgrade/2.6.0/schema_update.cql
  2. 1
      application/src/main/data/upgrade/2.6.0/schema_update.sql
  3. 8
      application/src/main/java/org/thingsboard/server/controller/AlarmController.java
  4. 8
      application/src/main/java/org/thingsboard/server/controller/AssetController.java
  5. 5
      application/src/main/java/org/thingsboard/server/controller/AuthController.java
  6. 8
      application/src/main/java/org/thingsboard/server/controller/BaseController.java
  7. 4
      application/src/main/java/org/thingsboard/server/controller/CustomerController.java
  8. 8
      application/src/main/java/org/thingsboard/server/controller/DashboardController.java
  9. 10
      application/src/main/java/org/thingsboard/server/controller/DeviceController.java
  10. 8
      application/src/main/java/org/thingsboard/server/controller/EntityViewController.java
  11. 10
      application/src/main/java/org/thingsboard/server/controller/RuleChainController.java
  12. 4
      application/src/main/java/org/thingsboard/server/controller/UserController.java
  13. 5
      application/src/main/java/org/thingsboard/server/controller/WidgetTypeController.java
  14. 5
      application/src/main/java/org/thingsboard/server/controller/WidgetsBundleController.java
  15. 18
      application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java
  16. 5
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/DeviceMsgConstructor.java
  17. 20
      application/src/main/java/org/thingsboard/server/service/edge/rpc/init/DefaultSyncEdgeService.java
  18. 4
      application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/BaseProcessor.java
  19. 99
      application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/DeviceProcessor.java
  20. 19
      application/src/main/java/org/thingsboard/server/service/queue/DefaultTbClusterService.java
  21. 56
      application/src/test/java/org/thingsboard/server/edge/BaseEdgeTest.java
  22. 2
      common/data/src/main/java/org/thingsboard/server/common/data/edge/Edge.java
  23. 2
      common/data/src/main/java/org/thingsboard/server/common/data/edge/EdgeEventActionType.java
  24. 5
      common/edge-api/src/main/proto/edge.proto
  25. 1
      dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java
  26. 6
      dao/src/main/java/org/thingsboard/server/dao/model/nosql/EdgeEntity.java
  27. 6
      dao/src/main/java/org/thingsboard/server/dao/model/sql/EdgeEntity.java
  28. 1
      dao/src/main/resources/cassandra/schema-entities.cql
  29. 1
      dao/src/main/resources/sql/schema-entities-hsql.sql
  30. 1
      dao/src/main/resources/sql/schema-entities.sql
  31. 19
      rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java
  32. 12
      ui/src/app/api/entity.service.js
  33. 14
      ui/src/app/import-export/table-columns-assignment.directive.js
  34. 9
      ui/src/app/locale/locale.constant-en_US.json

1
application/src/main/data/upgrade/2.6.0/schema_update.cql

@ -59,7 +59,6 @@ CREATE TABLE IF NOT EXISTS thingsboard.edge (
secret text, secret text,
edge_license_key text, edge_license_key text,
cloud_endpoint text, cloud_endpoint text,
configuration text,
additional_info text, additional_info text,
PRIMARY KEY (id, tenant_id, customer_id, type) PRIMARY KEY (id, tenant_id, customer_id, type)
); );

1
application/src/main/data/upgrade/2.6.0/schema_update.sql

@ -19,7 +19,6 @@ CREATE TABLE IF NOT EXISTS edge (
additional_info varchar, additional_info varchar,
customer_id varchar(31), customer_id varchar(31),
root_rule_chain_id varchar(31), root_rule_chain_id varchar(31),
configuration varchar(10000000),
type varchar(255), type varchar(255),
name varchar(255), name varchar(255),
label varchar(255), label varchar(255),

8
application/src/main/java/org/thingsboard/server/controller/AlarmController.java

@ -93,7 +93,7 @@ public class AlarmController extends BaseController {
getCurrentUser().getCustomerId(), getCurrentUser().getCustomerId(),
alarm.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); alarm.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
sendNotificationMsgToEdgeService(getTenantId(), savedAlarm.getId(), sendNotificationMsgToEdgeService(getTenantId(), savedAlarm.getId(), EntityType.ALARM,
alarm.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED); alarm.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
return savedAlarm; return savedAlarm;
@ -113,7 +113,7 @@ public class AlarmController extends BaseController {
AlarmId alarmId = new AlarmId(toUUID(strAlarmId)); AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
checkAlarmId(alarmId, Operation.WRITE); checkAlarmId(alarmId, Operation.WRITE);
sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.DELETED); sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.DELETED);
return alarmService.deleteAlarm(getTenantId(), alarmId); return alarmService.deleteAlarm(getTenantId(), alarmId);
} catch (Exception e) { } catch (Exception e) {
@ -135,7 +135,7 @@ public class AlarmController extends BaseController {
alarm.setStatus(alarm.getStatus().isCleared() ? AlarmStatus.CLEARED_ACK : AlarmStatus.ACTIVE_ACK); alarm.setStatus(alarm.getStatus().isCleared() ? AlarmStatus.CLEARED_ACK : AlarmStatus.ACTIVE_ACK);
logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_ACK, null); logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_ACK, null);
sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.ALARM_ACK); sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.ALARM_ACK);
} catch (Exception e) { } catch (Exception e) {
throw handleException(e); throw handleException(e);
} }
@ -155,7 +155,7 @@ public class AlarmController extends BaseController {
alarm.setStatus(alarm.getStatus().isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK); alarm.setStatus(alarm.getStatus().isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK);
logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_CLEAR, null); logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_CLEAR, null);
sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.ALARM_CLEAR); sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.ALARM_CLEAR);
} catch (Exception e) { } catch (Exception e) {
throw handleException(e); throw handleException(e);
} }

8
application/src/main/java/org/thingsboard/server/controller/AssetController.java

@ -92,7 +92,7 @@ public class AssetController extends BaseController {
asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
if (asset.getId() != null) { if (asset.getId() != null) {
sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), EdgeEventActionType.UPDATED); sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.UPDATED);
} }
return savedAsset; return savedAsset;
@ -117,7 +117,7 @@ public class AssetController extends BaseController {
asset.getCustomerId(), asset.getCustomerId(),
ActionType.DELETED, null, strAssetId); ActionType.DELETED, null, strAssetId);
sendNotificationMsgToEdgeService(getTenantId(), assetId, EdgeEventActionType.DELETED); sendNotificationMsgToEdgeService(getTenantId(), assetId, EntityType.ASSET, EdgeEventActionType.DELETED);
} catch (Exception e) { } catch (Exception e) {
logEntityAction(emptyId(EntityType.ASSET), logEntityAction(emptyId(EntityType.ASSET),
null, null,
@ -366,7 +366,7 @@ public class AssetController extends BaseController {
savedAsset.getCustomerId(), savedAsset.getCustomerId(),
ActionType.ASSIGNED_TO_EDGE, null, strAssetId, strEdgeId, edge.getName()); ActionType.ASSIGNED_TO_EDGE, null, strAssetId, strEdgeId, edge.getName());
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE); sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.ASSIGNED_TO_EDGE);
return savedAsset; return savedAsset;
} catch (Exception e) { } catch (Exception e) {
@ -399,7 +399,7 @@ public class AssetController extends BaseController {
asset.getCustomerId(), asset.getCustomerId(),
ActionType.UNASSIGNED_FROM_EDGE, null, strAssetId, strEdgeId, edge.getName()); ActionType.UNASSIGNED_FROM_EDGE, null, strAssetId, strEdgeId, edge.getName());
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE); sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
return savedAsset; return savedAsset;
} catch (Exception e) { } catch (Exception e) {

5
application/src/main/java/org/thingsboard/server/controller/AuthController.java

@ -33,6 +33,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.thingsboard.rule.engine.api.MailService; import org.thingsboard.rule.engine.api.MailService;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.User; import org.thingsboard.server.common.data.User;
import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.audit.ActionType;
import org.thingsboard.server.common.data.edge.EdgeEventActionType; import org.thingsboard.server.common.data.edge.EdgeEventActionType;
@ -127,7 +128,7 @@ public class AuthController extends BaseController {
userCredentials.setPassword(passwordEncoder.encode(newPassword)); userCredentials.setPassword(passwordEncoder.encode(newPassword));
userService.replaceUserCredentials(securityUser.getTenantId(), userCredentials); userService.replaceUserCredentials(securityUser.getTenantId(), userCredentials);
sendNotificationMsgToEdgeService(getTenantId(), userCredentials.getUserId(), EdgeEventActionType.CREDENTIALS_UPDATED); sendNotificationMsgToEdgeService(getTenantId(), userCredentials.getUserId(), EntityType.USER, EdgeEventActionType.CREDENTIALS_UPDATED);
} catch (Exception e) { } catch (Exception e) {
throw handleException(e); throw handleException(e);
@ -237,7 +238,7 @@ public class AuthController extends BaseController {
} }
} }
sendNotificationMsgToEdgeService(user.getTenantId(), user.getId(), EdgeEventActionType.CREDENTIALS_UPDATED); sendNotificationMsgToEdgeService(user.getTenantId(), user.getId(), EntityType.USER, EdgeEventActionType.CREDENTIALS_UPDATED);
JwtToken accessToken = tokenFactory.createAccessJwtToken(securityUser); JwtToken accessToken = tokenFactory.createAccessJwtToken(securityUser);
JwtToken refreshToken = refreshTokenRepository.requestRefreshToken(securityUser); JwtToken refreshToken = refreshTokenRepository.requestRefreshToken(securityUser);

8
application/src/main/java/org/thingsboard/server/controller/BaseController.java

@ -799,15 +799,15 @@ public abstract class BaseController {
} }
} }
protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, EdgeEventActionType action) { protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, EntityType entityType, EdgeEventActionType action) {
sendNotificationMsgToEdgeService(tenantId, null, entityId, action); sendNotificationMsgToEdgeService(tenantId, null, entityId, entityType, action);
} }
protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EdgeEventActionType action) { protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EntityType entityType, EdgeEventActionType action) {
if (!edgesRpcEnabled) { if (!edgesRpcEnabled) {
return; return;
} }
EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType()); EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityType);
if (type != null) { if (type != null) {
sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, type, action); sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, type, action);
} }

4
application/src/main/java/org/thingsboard/server/controller/CustomerController.java

@ -110,7 +110,7 @@ public class CustomerController extends BaseController {
customer.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); customer.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
if (customer.getId() != null) { if (customer.getId() != null) {
sendNotificationMsgToEdgeService(savedCustomer.getTenantId(), savedCustomer.getId(), EdgeEventActionType.UPDATED); sendNotificationMsgToEdgeService(savedCustomer.getTenantId(), savedCustomer.getId(), EntityType.CUSTOMER, EdgeEventActionType.UPDATED);
} }
return savedCustomer; return savedCustomer;
@ -137,7 +137,7 @@ public class CustomerController extends BaseController {
customer.getId(), customer.getId(),
ActionType.DELETED, null, strCustomerId); ActionType.DELETED, null, strCustomerId);
sendNotificationMsgToEdgeService(getTenantId(), customerId, EdgeEventActionType.DELETED); sendNotificationMsgToEdgeService(getTenantId(), customerId, EntityType.CUSTOMER, EdgeEventActionType.DELETED);
} catch (Exception e) { } catch (Exception e) {
logEntityAction(emptyId(EntityType.CUSTOMER), logEntityAction(emptyId(EntityType.CUSTOMER),

8
application/src/main/java/org/thingsboard/server/controller/DashboardController.java

@ -117,7 +117,7 @@ public class DashboardController extends BaseController {
dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
if (dashboard.getId() != null) { if (dashboard.getId() != null) {
sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), EdgeEventActionType.UPDATED); sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.UPDATED);
} }
return savedDashboard; return savedDashboard;
@ -143,7 +143,7 @@ public class DashboardController extends BaseController {
null, null,
ActionType.DELETED, null, strDashboardId); ActionType.DELETED, null, strDashboardId);
sendNotificationMsgToEdgeService(getTenantId(), dashboardId, EdgeEventActionType.DELETED); sendNotificationMsgToEdgeService(getTenantId(), dashboardId, EntityType.DASHBOARD, EdgeEventActionType.DELETED);
} catch (Exception e) { } catch (Exception e) {
logEntityAction(emptyId(EntityType.DASHBOARD), logEntityAction(emptyId(EntityType.DASHBOARD),
@ -505,7 +505,7 @@ public class DashboardController extends BaseController {
null, null,
ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName()); ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName());
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE); sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.ASSIGNED_TO_EDGE);
return savedDashboard; return savedDashboard;
} catch (Exception e) { } catch (Exception e) {
@ -537,7 +537,7 @@ public class DashboardController extends BaseController {
null, null,
ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, strEdgeId, edge.getName()); ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, strEdgeId, edge.getName());
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE); sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
return savedDashboard; return savedDashboard;
} catch (Exception e) { } catch (Exception e) {

10
application/src/main/java/org/thingsboard/server/controller/DeviceController.java

@ -114,7 +114,7 @@ public class DeviceController extends BaseController {
savedDevice.getId(), savedDevice.getName(), savedDevice.getType()), null); savedDevice.getId(), savedDevice.getName(), savedDevice.getType()), null);
if (device.getId() != null) { if (device.getId() != null) {
sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(), EdgeEventActionType.UPDATED); sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.UPDATED);
} }
logEntityAction(savedDevice.getId(), savedDevice, logEntityAction(savedDevice.getId(), savedDevice,
@ -148,7 +148,7 @@ public class DeviceController extends BaseController {
device.getCustomerId(), device.getCustomerId(),
ActionType.DELETED, null, strDeviceId); ActionType.DELETED, null, strDeviceId);
sendNotificationMsgToEdgeService(getTenantId(), deviceId, EdgeEventActionType.DELETED); sendNotificationMsgToEdgeService(getTenantId(), deviceId, EntityType.DEVICE, EdgeEventActionType.DELETED);
deviceStateService.onDeviceDeleted(device); deviceStateService.onDeviceDeleted(device);
} catch (Exception e) { } catch (Exception e) {
@ -279,7 +279,7 @@ public class DeviceController extends BaseController {
tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(getCurrentUser().getTenantId(), deviceCredentials.getDeviceId()), null); tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(getCurrentUser().getTenantId(), deviceCredentials.getDeviceId()), null);
sendNotificationMsgToEdgeService(getTenantId(), device.getId(), EdgeEventActionType.CREDENTIALS_UPDATED); sendNotificationMsgToEdgeService(getTenantId(), device.getId(), EntityType.DEVICE, EdgeEventActionType.CREDENTIALS_UPDATED);
logEntityAction(device.getId(), device, logEntityAction(device.getId(), device,
device.getCustomerId(), device.getCustomerId(),
@ -583,7 +583,7 @@ public class DeviceController extends BaseController {
savedDevice.getCustomerId(), savedDevice.getCustomerId(),
ActionType.ASSIGNED_TO_EDGE, null, strDeviceId, strEdgeId, edge.getName()); ActionType.ASSIGNED_TO_EDGE, null, strDeviceId, strEdgeId, edge.getName());
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE); sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.ASSIGNED_TO_EDGE);
return savedDevice; return savedDevice;
} catch (Exception e) { } catch (Exception e) {
@ -617,7 +617,7 @@ public class DeviceController extends BaseController {
device.getCustomerId(), device.getCustomerId(),
ActionType.UNASSIGNED_FROM_EDGE, null, strDeviceId, strEdgeId, edge.getName()); ActionType.UNASSIGNED_FROM_EDGE, null, strDeviceId, strEdgeId, edge.getName());
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE); sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
return savedDevice; return savedDevice;
} catch (Exception e) { } catch (Exception e) {

8
application/src/main/java/org/thingsboard/server/controller/EntityViewController.java

@ -119,7 +119,7 @@ public class EntityViewController extends BaseController {
entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
if (entityView.getId() != null) { if (entityView.getId() != null) {
sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), EdgeEventActionType.UPDATED); sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.UPDATED);
} }
return savedEntityView; return savedEntityView;
@ -192,7 +192,7 @@ public class EntityViewController extends BaseController {
logEntityAction(entityViewId, entityView, entityView.getCustomerId(), logEntityAction(entityViewId, entityView, entityView.getCustomerId(),
ActionType.DELETED, null, strEntityViewId); ActionType.DELETED, null, strEntityViewId);
sendNotificationMsgToEdgeService(getTenantId(), entityViewId, EdgeEventActionType.DELETED); sendNotificationMsgToEdgeService(getTenantId(), entityViewId, EntityType.ENTITY_VIEW, EdgeEventActionType.DELETED);
} catch (Exception e) { } catch (Exception e) {
logEntityAction(emptyId(EntityType.ENTITY_VIEW), logEntityAction(emptyId(EntityType.ENTITY_VIEW),
null, null,
@ -405,7 +405,7 @@ public class EntityViewController extends BaseController {
savedEntityView.getCustomerId(), savedEntityView.getCustomerId(),
ActionType.ASSIGNED_TO_EDGE, null, strEntityViewId, strEdgeId, edge.getName()); ActionType.ASSIGNED_TO_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE); sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.ASSIGNED_TO_EDGE);
return savedEntityView; return savedEntityView;
} catch (Exception e) { } catch (Exception e) {
@ -435,7 +435,7 @@ public class EntityViewController extends BaseController {
entityView.getCustomerId(), entityView.getCustomerId(),
ActionType.UNASSIGNED_FROM_EDGE, null, strEntityViewId, strEdgeId, edge.getName()); ActionType.UNASSIGNED_FROM_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE); sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
return savedEntityView; return savedEntityView;
} catch (Exception e) { } catch (Exception e) {

10
application/src/main/java/org/thingsboard/server/controller/RuleChainController.java

@ -146,7 +146,7 @@ public class RuleChainController extends BaseController {
if (RuleChainType.EDGE.equals(savedRuleChain.getType())) { if (RuleChainType.EDGE.equals(savedRuleChain.getType())) {
if (!created) { if (!created) {
sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), savedRuleChain.getId(), EdgeEventActionType.UPDATED); sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UPDATED);
} }
} }
@ -226,7 +226,7 @@ public class RuleChainController extends BaseController {
if (RuleChainType.EDGE.equals(ruleChain.getType())) { if (RuleChainType.EDGE.equals(ruleChain.getType())) {
sendNotificationMsgToEdgeService(ruleChain.getTenantId(), sendNotificationMsgToEdgeService(ruleChain.getTenantId(),
ruleChain.getId(), EdgeEventActionType.UPDATED); ruleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UPDATED);
} }
return savedRuleChainMetaData; return savedRuleChainMetaData;
@ -290,7 +290,7 @@ public class RuleChainController extends BaseController {
ActionType.DELETED, null, strRuleChainId); ActionType.DELETED, null, strRuleChainId);
if (RuleChainType.EDGE.equals(ruleChain.getType())) { if (RuleChainType.EDGE.equals(ruleChain.getType())) {
sendNotificationMsgToEdgeService(ruleChain.getTenantId(), ruleChain.getId(), EdgeEventActionType.DELETED); sendNotificationMsgToEdgeService(ruleChain.getTenantId(), ruleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.DELETED);
} }
} catch (Exception e) { } catch (Exception e) {
@ -422,7 +422,7 @@ public class RuleChainController extends BaseController {
null, null,
ActionType.ASSIGNED_TO_EDGE, null, strRuleChainId, strEdgeId, edge.getName()); ActionType.ASSIGNED_TO_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE); sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.ASSIGNED_TO_EDGE);
return savedRuleChain; return savedRuleChain;
} catch (Exception e) { } catch (Exception e) {
@ -454,7 +454,7 @@ public class RuleChainController extends BaseController {
null, null,
ActionType.UNASSIGNED_FROM_EDGE, null, strRuleChainId, strEdgeId, edge.getName()); ActionType.UNASSIGNED_FROM_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE); sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UNASSIGNED_FROM_EDGE);
return savedRuleChain; return savedRuleChain;
} catch (Exception e) { } catch (Exception e) {

4
application/src/main/java/org/thingsboard/server/controller/UserController.java

@ -166,7 +166,7 @@ public class UserController extends BaseController {
savedUser.getCustomerId(), savedUser.getCustomerId(),
user.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); user.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
sendNotificationMsgToEdgeService(getTenantId(), savedUser.getId(), sendNotificationMsgToEdgeService(getTenantId(), savedUser.getId(), EntityType.USER,
user.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED); user.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
return savedUser; return savedUser;
@ -244,7 +244,7 @@ public class UserController extends BaseController {
user.getCustomerId(), user.getCustomerId(),
ActionType.DELETED, null, strUserId); ActionType.DELETED, null, strUserId);
sendNotificationMsgToEdgeService(getTenantId(), user.getId(), EdgeEventActionType.DELETED); sendNotificationMsgToEdgeService(getTenantId(), user.getId(), EntityType.USER, EdgeEventActionType.DELETED);
} catch (Exception e) { } catch (Exception e) {
logEntityAction(emptyId(EntityType.USER), logEntityAction(emptyId(EntityType.USER),

5
application/src/main/java/org/thingsboard/server/controller/WidgetTypeController.java

@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.audit.ActionType;
import org.thingsboard.server.common.data.edge.EdgeEventActionType; import org.thingsboard.server.common.data.edge.EdgeEventActionType;
import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.common.data.exception.ThingsboardException;
@ -73,7 +74,7 @@ public class WidgetTypeController extends BaseController {
checkEntity(widgetType.getId(), widgetType, Resource.WIDGET_TYPE); checkEntity(widgetType.getId(), widgetType, Resource.WIDGET_TYPE);
WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType); WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
sendNotificationMsgToEdgeService(getTenantId(), savedWidgetType.getId(), sendNotificationMsgToEdgeService(getTenantId(), savedWidgetType.getId(), EntityType.WIDGET_TYPE,
widgetType.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED); widgetType.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
return checkNotNull(savedWidgetType); return checkNotNull(savedWidgetType);
@ -92,7 +93,7 @@ public class WidgetTypeController extends BaseController {
checkWidgetTypeId(widgetTypeId, Operation.DELETE); checkWidgetTypeId(widgetTypeId, Operation.DELETE);
widgetTypeService.deleteWidgetType(getCurrentUser().getTenantId(), widgetTypeId); widgetTypeService.deleteWidgetType(getCurrentUser().getTenantId(), widgetTypeId);
sendNotificationMsgToEdgeService(getTenantId(), widgetTypeId, EdgeEventActionType.DELETED); sendNotificationMsgToEdgeService(getTenantId(), widgetTypeId, EntityType.WIDGET_TYPE, EdgeEventActionType.DELETED);
} catch (Exception e) { } catch (Exception e) {
throw handleException(e); throw handleException(e);

5
application/src/main/java/org/thingsboard/server/controller/WidgetsBundleController.java

@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.audit.ActionType;
import org.thingsboard.server.common.data.edge.EdgeEventActionType; import org.thingsboard.server.common.data.edge.EdgeEventActionType;
import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.common.data.exception.ThingsboardException;
@ -72,7 +73,7 @@ public class WidgetsBundleController extends BaseController {
checkEntity(widgetsBundle.getId(), widgetsBundle, Resource.WIDGETS_BUNDLE); checkEntity(widgetsBundle.getId(), widgetsBundle, Resource.WIDGETS_BUNDLE);
WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle); WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(), sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(), EntityType.WIDGETS_BUNDLE,
widgetsBundle.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED); widgetsBundle.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
return checkNotNull(savedWidgetsBundle); return checkNotNull(savedWidgetsBundle);
@ -91,7 +92,7 @@ public class WidgetsBundleController extends BaseController {
checkWidgetsBundleId(widgetsBundleId, Operation.DELETE); checkWidgetsBundleId(widgetsBundleId, Operation.DELETE);
widgetsBundleService.deleteWidgetsBundle(getTenantId(), widgetsBundleId); widgetsBundleService.deleteWidgetsBundle(getTenantId(), widgetsBundleId);
sendNotificationMsgToEdgeService(getTenantId(), widgetsBundleId, EdgeEventActionType.DELETED); sendNotificationMsgToEdgeService(getTenantId(), widgetsBundleId, EntityType.WIDGETS_BUNDLE, EdgeEventActionType.DELETED);
} catch (Exception e) { } catch (Exception e) {
throw handleException(e); throw handleException(e);

18
application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java

@ -17,6 +17,7 @@ package org.thingsboard.server.service.edge.rpc;
import com.datastax.driver.core.utils.UUIDs; import com.datastax.driver.core.utils.UUIDs;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -335,8 +336,8 @@ public final class EdgeGrpcSession implements Closeable {
case CREDENTIALS_REQUEST: case CREDENTIALS_REQUEST:
downlinkMsg = processCredentialsRequestMessage(edgeEvent); downlinkMsg = processCredentialsRequestMessage(edgeEvent);
break; break;
case ENTITY_EXISTS_REQUEST: case ENTITY_MERGE_REQUEST:
downlinkMsg = processEntityExistsRequestMessage(edgeEvent); downlinkMsg = processEntityMergeRequestMessage(edgeEvent);
break; break;
case RPC_CALL: case RPC_CALL:
downlinkMsg = processRpcCallMsg(edgeEvent); downlinkMsg = processRpcCallMsg(edgeEvent);
@ -352,13 +353,18 @@ public final class EdgeGrpcSession implements Closeable {
return result; return result;
} }
private DownlinkMsg processEntityExistsRequestMessage(EdgeEvent edgeEvent) { private DownlinkMsg processEntityMergeRequestMessage(EdgeEvent edgeEvent) {
DownlinkMsg downlinkMsg = null; DownlinkMsg downlinkMsg = null;
if (EdgeEventType.DEVICE.equals(edgeEvent.getType())) { if (EdgeEventType.DEVICE.equals(edgeEvent.getType())) {
DeviceId deviceId = new DeviceId(edgeEvent.getEntityId()); DeviceId deviceId = new DeviceId(edgeEvent.getEntityId());
Device device = ctx.getDeviceService().findDeviceById(edge.getTenantId(), deviceId); Device device = ctx.getDeviceService().findDeviceById(edge.getTenantId(), deviceId);
CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(device); CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(device);
DeviceUpdateMsg d = ctx.getDeviceMsgConstructor().constructDeviceUpdatedMsg(UpdateMsgType.DEVICE_CONFLICT_RPC_MESSAGE, device, customerId); String conflictName = null;
if(edgeEvent.getBody() != null) {
conflictName = edgeEvent.getBody().get("conflictName").asText();
}
DeviceUpdateMsg d = ctx.getDeviceMsgConstructor()
.constructDeviceUpdatedMsg(UpdateMsgType.ENTITY_MERGE_RPC_MESSAGE, device, customerId, conflictName);
downlinkMsg = DownlinkMsg.newBuilder() downlinkMsg = DownlinkMsg.newBuilder()
.addAllDeviceUpdateMsg(Collections.singletonList(d)) .addAllDeviceUpdateMsg(Collections.singletonList(d))
.build(); .build();
@ -497,7 +503,7 @@ public final class EdgeGrpcSession implements Closeable {
if (device != null) { if (device != null) {
CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(device); CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(device);
DeviceUpdateMsg deviceUpdateMsg = DeviceUpdateMsg deviceUpdateMsg =
ctx.getDeviceMsgConstructor().constructDeviceUpdatedMsg(msgType, device, customerId); ctx.getDeviceMsgConstructor().constructDeviceUpdatedMsg(msgType, device, customerId, null);
downlinkMsg = DownlinkMsg.newBuilder() downlinkMsg = DownlinkMsg.newBuilder()
.addAllDeviceUpdateMsg(Collections.singletonList(deviceUpdateMsg)) .addAllDeviceUpdateMsg(Collections.singletonList(deviceUpdateMsg))
.build(); .build();
@ -969,7 +975,7 @@ public final class EdgeGrpcSession implements Closeable {
.setSecret(edge.getSecret()) .setSecret(edge.getSecret())
.setEdgeLicenseKey(edge.getEdgeLicenseKey()) .setEdgeLicenseKey(edge.getEdgeLicenseKey())
.setCloudEndpoint(edge.getCloudEndpoint()) .setCloudEndpoint(edge.getCloudEndpoint())
.setConfiguration(JacksonUtil.toString(edge.getConfiguration())) .setAdditionalInfo(JacksonUtil.toString(edge.getAdditionalInfo()))
.setCloudType("CE"); .setCloudType("CE");
if (edge.getCustomerId() != null) { if (edge.getCustomerId() != null) {
builder.setCustomerIdMSB(edge.getCustomerId().getId().getMostSignificantBits()) builder.setCustomerIdMSB(edge.getCustomerId().getId().getMostSignificantBits())

5
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/DeviceMsgConstructor.java

@ -38,7 +38,7 @@ public class DeviceMsgConstructor {
protected static final ObjectMapper mapper = new ObjectMapper(); protected static final ObjectMapper mapper = new ObjectMapper();
public DeviceUpdateMsg constructDeviceUpdatedMsg(UpdateMsgType msgType, Device device, CustomerId customerId) { public DeviceUpdateMsg constructDeviceUpdatedMsg(UpdateMsgType msgType, Device device, CustomerId customerId, String conflictName) {
DeviceUpdateMsg.Builder builder = DeviceUpdateMsg.newBuilder() DeviceUpdateMsg.Builder builder = DeviceUpdateMsg.newBuilder()
.setMsgType(msgType) .setMsgType(msgType)
.setIdMSB(device.getId().getId().getMostSignificantBits()) .setIdMSB(device.getId().getId().getMostSignificantBits())
@ -55,6 +55,9 @@ public class DeviceMsgConstructor {
if (device.getAdditionalInfo() != null) { if (device.getAdditionalInfo() != null) {
builder.setAdditionalInfo(JacksonUtil.toString(device.getAdditionalInfo())); builder.setAdditionalInfo(JacksonUtil.toString(device.getAdditionalInfo()));
} }
if (conflictName != null) {
builder.setConflictName(conflictName);
}
return builder.build(); return builder.build();
} }

20
application/src/main/java/org/thingsboard/server/service/edge/rpc/init/DefaultSyncEdgeService.java

@ -311,11 +311,11 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
do { do {
pageData = userService.findTenantAdmins(edge.getTenantId(), pageLink); pageData = userService.findTenantAdmins(edge.getTenantId(), pageLink);
pushUsersToEdge(pageData, edge); pushUsersToEdge(pageData, edge);
syncCustomerUsers(edge);
if (pageData != null && pageData.hasNext()) { if (pageData != null && pageData.hasNext()) {
pageLink = pageData.getNextPageLink(); pageLink = pageData.getNextPageLink();
} }
} while (pageData != null && pageData.hasNext()); } while (pageData != null && pageData.hasNext());
syncCustomerUsers(edge);
} catch (Exception e) { } catch (Exception e) {
log.error("Exception during loading edge user(s) on sync!", e); log.error("Exception during loading edge user(s) on sync!", e);
} }
@ -336,6 +336,15 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
} }
} }
private void pushUsersToEdge(TextPageData<User> pageData, Edge edge) {
if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
log.trace("[{}] [{}] user(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size());
for (User user : pageData.getData()) {
saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.USER, EdgeEventActionType.ADDED, user.getId(), null);
}
}
}
private void syncWidgetsBundleAndWidgetTypes(Edge edge) { private void syncWidgetsBundleAndWidgetTypes(Edge edge) {
log.trace("[{}] syncWidgetsBundleAndWidgetTypes [{}]", edge.getTenantId(), edge.getName()); log.trace("[{}] syncWidgetsBundleAndWidgetTypes [{}]", edge.getTenantId(), edge.getName());
List<WidgetsBundle> widgetsBundlesToPush = new ArrayList<>(); List<WidgetsBundle> widgetsBundlesToPush = new ArrayList<>();
@ -423,15 +432,6 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
return tenantMailSettings; return tenantMailSettings;
} }
private void pushUsersToEdge(TextPageData<User> pageData, Edge edge) {
if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
log.trace("[{}] [{}] user(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size());
for (User user : pageData.getData()) {
saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.USER, EdgeEventActionType.ADDED, user.getId(), null);
}
}
}
@Override @Override
public ListenableFuture<Void> processRuleChainMetadataRequestMsg(Edge edge, RuleChainMetadataRequestMsg ruleChainMetadataRequestMsg) { public ListenableFuture<Void> processRuleChainMetadataRequestMsg(Edge edge, RuleChainMetadataRequestMsg ruleChainMetadataRequestMsg) {
log.trace("[{}] processRuleChainMetadataRequestMsg [{}][{}]", edge.getTenantId(), edge.getName(), ruleChainMetadataRequestMsg); log.trace("[{}] processRuleChainMetadataRequestMsg [{}][{}]", edge.getTenantId(), edge.getName(), ruleChainMetadataRequestMsg);

4
application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/BaseProcessor.java

@ -37,6 +37,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.dao.device.DeviceCredentialsService; import org.thingsboard.server.dao.device.DeviceCredentialsService;
import org.thingsboard.server.dao.device.DeviceService; import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.edge.EdgeEventService; import org.thingsboard.server.dao.edge.EdgeEventService;
import org.thingsboard.server.dao.edge.EdgeService;
import org.thingsboard.server.dao.entityview.EntityViewService; import org.thingsboard.server.dao.entityview.EntityViewService;
import org.thingsboard.server.dao.relation.RelationService; import org.thingsboard.server.dao.relation.RelationService;
import org.thingsboard.server.dao.user.UserService; import org.thingsboard.server.dao.user.UserService;
@ -64,6 +65,9 @@ public abstract class BaseProcessor {
@Autowired @Autowired
protected EntityViewService entityViewService; protected EntityViewService entityViewService;
@Autowired
protected EdgeService edgeService;
@Autowired @Autowired
protected CustomerService customerService; protected CustomerService customerService;

99
application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/DeviceProcessor.java

@ -17,12 +17,15 @@ package org.thingsboard.server.service.edge.rpc.processor;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture; import com.google.common.util.concurrent.SettableFuture;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.thingsboard.rule.engine.api.RpcError; import org.thingsboard.rule.engine.api.RpcError;
import org.thingsboard.server.common.data.DataConstants; import org.thingsboard.server.common.data.DataConstants;
@ -52,6 +55,7 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; import org.thingsboard.server.service.rpc.FromDeviceRpcResponse;
import org.thingsboard.server.service.rpc.FromDeviceRpcResponseActorMsg; import org.thingsboard.server.service.rpc.FromDeviceRpcResponseActorMsg;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -64,36 +68,62 @@ public class DeviceProcessor extends BaseProcessor {
public ListenableFuture<Void> onDeviceUpdate(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg) { public ListenableFuture<Void> onDeviceUpdate(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg) {
log.trace("[{}] onDeviceUpdate [{}] from edge [{}]", tenantId, deviceUpdateMsg, edge.getName()); log.trace("[{}] onDeviceUpdate [{}] from edge [{}]", tenantId, deviceUpdateMsg, edge.getName());
DeviceId edgeDeviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB()));
switch (deviceUpdateMsg.getMsgType()) { switch (deviceUpdateMsg.getMsgType()) {
case ENTITY_CREATED_RPC_MESSAGE: case ENTITY_CREATED_RPC_MESSAGE:
String deviceName = deviceUpdateMsg.getName(); String deviceName = deviceUpdateMsg.getName();
Device device = deviceService.findDeviceByTenantIdAndName(tenantId, deviceName); Device device = deviceService.findDeviceByTenantIdAndName(tenantId, deviceName);
if (device != null) { if (device != null) {
log.info("[{}] Device with name '{}' already exists on the cloud. Updating id of device entity on the edge", tenantId, deviceName); ListenableFuture<List<EdgeId>> future = edgeService.findRelatedEdgeIdsByEntityId(tenantId, device.getId());
if (!device.getId().equals(edgeDeviceId)) { SettableFuture<Void> futureToSet = SettableFuture.create();
saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.ENTITY_EXISTS_REQUEST, device.getId(), null); Futures.addCallback(future, new FutureCallback<List<EdgeId>>() {
} @Override
public void onSuccess(@Nullable List<EdgeId> edgeIds) {
boolean update = false;
if (edgeIds != null && !edgeIds.isEmpty()) {
if (edgeIds.contains(edge.getId())) {
update = true;
}
}
Device device;
if (update) {
log.info("[{}] Device with name '{}' already exists on the cloud, and related to this edge [{}]. " +
"deviceUpdateMsg [{}], Updating device", tenantId, deviceName, edge.getId(), deviceUpdateMsg);
updateDevice(tenantId, edge, deviceUpdateMsg);
} else {
log.info("[{}] Device with name '{}' already exists on the cloud, but not related to this edge [{}]. deviceUpdateMsg [{}]." +
"Creating a new device with random prefix and relate to this edge", tenantId, deviceName, edge.getId(), deviceUpdateMsg);
String newDeviceName = deviceUpdateMsg.getName() + "_" + RandomStringUtils.randomAlphabetic(15);
device = createDevice(tenantId, edge, deviceUpdateMsg, newDeviceName);
ObjectNode body = mapper.createObjectNode();
body.put("conflictName", deviceName);
saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.ENTITY_MERGE_REQUEST, device.getId(), body);
deviceService.assignDeviceToEdge(edge.getTenantId(), device.getId(), edge.getId());
}
futureToSet.set(null);
}
@Override
public void onFailure(Throwable t) {
log.error("[{}] Failed to get related edge ids by device id [{}], edge [{}]", tenantId, deviceUpdateMsg, edge.getId(), t);
futureToSet.setException(t);
}
}, dbCallbackExecutorService);
return futureToSet;
} else { } else {
Device deviceById = deviceService.findDeviceById(edge.getTenantId(), edgeDeviceId); log.info("[{}] Creating new device and replacing device entity on the edge [{}]", tenantId, deviceUpdateMsg);
if (deviceById != null) { device = createDevice(tenantId, edge, deviceUpdateMsg, deviceUpdateMsg.getName());
log.info("[{}] Device ID [{}] already used by other device on the cloud. Creating new device and replacing device entity on the edge", tenantId, edgeDeviceId.getId()); saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.ENTITY_MERGE_REQUEST, device.getId(), null);
device = createDevice(tenantId, edge, deviceUpdateMsg); deviceService.assignDeviceToEdge(edge.getTenantId(), device.getId(), edge.getId());
saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.ENTITY_EXISTS_REQUEST, device.getId(), null);
} else {
device = createDevice(tenantId, edge, deviceUpdateMsg);
}
} }
// TODO: voba - assign device only in case device is not assigned yet. Missing functionality to check this relation prior assignment
deviceService.assignDeviceToEdge(edge.getTenantId(), device.getId(), edge.getId());
break; break;
case ENTITY_UPDATED_RPC_MESSAGE: case ENTITY_UPDATED_RPC_MESSAGE:
updateDevice(tenantId, edge, deviceUpdateMsg); updateDevice(tenantId, edge, deviceUpdateMsg);
break; break;
case ENTITY_DELETED_RPC_MESSAGE: case ENTITY_DELETED_RPC_MESSAGE:
Device deviceToDelete = deviceService.findDeviceById(tenantId, edgeDeviceId); DeviceId deviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB()));
Device deviceToDelete = deviceService.findDeviceById(tenantId, deviceId);
if (deviceToDelete != null) { if (deviceToDelete != null) {
deviceService.unassignDeviceFromEdge(tenantId, edgeDeviceId, edge.getId()); deviceService.unassignDeviceFromEdge(tenantId, deviceId, edge.getId());
} }
break; break;
case UNRECOGNIZED: case UNRECOGNIZED:
@ -103,7 +133,6 @@ public class DeviceProcessor extends BaseProcessor {
return Futures.immediateFuture(null); return Futures.immediateFuture(null);
} }
public ListenableFuture<Void> onDeviceCredentialsUpdate(TenantId tenantId, DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg) { public ListenableFuture<Void> onDeviceCredentialsUpdate(TenantId tenantId, DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg) {
log.debug("Executing onDeviceCredentialsUpdate, deviceCredentialsUpdateMsg [{}]", deviceCredentialsUpdateMsg); log.debug("Executing onDeviceCredentialsUpdate, deviceCredentialsUpdateMsg [{}]", deviceCredentialsUpdateMsg);
DeviceId deviceId = new DeviceId(new UUID(deviceCredentialsUpdateMsg.getDeviceIdMSB(), deviceCredentialsUpdateMsg.getDeviceIdLSB())); DeviceId deviceId = new DeviceId(new UUID(deviceCredentialsUpdateMsg.getDeviceIdMSB(), deviceCredentialsUpdateMsg.getDeviceIdLSB()));
@ -131,36 +160,34 @@ public class DeviceProcessor extends BaseProcessor {
private void updateDevice(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg) { private void updateDevice(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg) {
DeviceId deviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB())); DeviceId deviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB()));
Device device = deviceService.findDeviceById(tenantId, deviceId); Device device = deviceService.findDeviceById(tenantId, deviceId);
device.setName(deviceUpdateMsg.getName()); if (device != null) {
device.setType(deviceUpdateMsg.getType()); device.setName(deviceUpdateMsg.getName());
device.setLabel(deviceUpdateMsg.getLabel()); device.setType(deviceUpdateMsg.getType());
device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo())); device.setLabel(deviceUpdateMsg.getLabel());
deviceService.saveDevice(device); device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo()));
deviceService.saveDevice(device);
saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_REQUEST, deviceId, null); saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_REQUEST, deviceId, null);
} else {
log.warn("[{}] can't find device [{}], edge [{}]", tenantId, deviceUpdateMsg, edge.getId());
}
} }
private Device createDevice(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg) { private Device createDevice(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg, String deviceName) {
Device device; Device device;
try { try {
deviceCreationLock.lock(); deviceCreationLock.lock();
log.debug("[{}] Creating device entity [{}] from edge [{}]", tenantId, deviceUpdateMsg, edge.getName()); log.debug("[{}] Creating device entity [{}] from edge [{}]", tenantId, deviceUpdateMsg, edge.getName());
DeviceId deviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB()));
device = new Device(); device = new Device();
device.setTenantId(edge.getTenantId()); device.setTenantId(edge.getTenantId());
device.setCustomerId(edge.getCustomerId()); device.setCustomerId(edge.getCustomerId());
device.setId(deviceId); device.setName(deviceName);
device.setName(deviceUpdateMsg.getName());
device.setType(deviceUpdateMsg.getType()); device.setType(deviceUpdateMsg.getType());
device.setLabel(deviceUpdateMsg.getLabel()); device.setLabel(deviceUpdateMsg.getLabel());
device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo())); device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo()));
device = deviceService.saveDevice(device); device = deviceService.saveDevice(device);
createDeviceCredentials(device);
createRelationFromEdge(tenantId, edge.getId(), device.getId()); createRelationFromEdge(tenantId, edge.getId(), device.getId());
deviceStateService.onDeviceAdded(device); deviceStateService.onDeviceAdded(device);
pushDeviceCreatedEventToRuleEngine(tenantId, edge, device); pushDeviceCreatedEventToRuleEngine(tenantId, edge, device);
saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_REQUEST, deviceId, null);
} finally { } finally {
deviceCreationLock.unlock(); deviceCreationLock.unlock();
} }
@ -176,14 +203,6 @@ public class DeviceProcessor extends BaseProcessor {
relationService.saveRelation(tenantId, relation); relationService.saveRelation(tenantId, relation);
} }
private void createDeviceCredentials(Device device) {
DeviceCredentials deviceCredentials = new DeviceCredentials();
deviceCredentials.setDeviceId(device.getId());
deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN);
deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20));
deviceCredentialsService.createDeviceCredentials(device.getTenantId(), deviceCredentials);
}
private void pushDeviceCreatedEventToRuleEngine(TenantId tenantId, Edge edge, Device device) { private void pushDeviceCreatedEventToRuleEngine(TenantId tenantId, Edge edge, Device device) {
try { try {
DeviceId deviceId = device.getId(); DeviceId deviceId = device.getId();

19
application/src/main/java/org/thingsboard/server/service/queue/DefaultTbClusterService.java

@ -184,12 +184,9 @@ public class DefaultTbClusterService implements TbClusterService {
byte[] msgBytes = encodingService.encode(msg); byte[] msgBytes = encodingService.encode(msg);
TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> toRuleEngineProducer = producerProvider.getRuleEngineNotificationsMsgProducer(); TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> toRuleEngineProducer = producerProvider.getRuleEngineNotificationsMsgProducer();
Set<String> tbRuleEngineServices = new HashSet<>(partitionService.getAllServiceIds(ServiceType.TB_RULE_ENGINE)); Set<String> tbRuleEngineServices = new HashSet<>(partitionService.getAllServiceIds(ServiceType.TB_RULE_ENGINE));
boolean toCore = msg.getEntityId().getEntityType().equals(EntityType.TENANT) ||
msg.getEntityId().getEntityType().equals(EntityType.EDGE);
boolean toRuleEngine = !msg.getEntityId().getEntityType().equals(EntityType.EDGE); if (msg.getEntityId().getEntityType().equals(EntityType.TENANT) ||
msg.getEntityId().getEntityType().equals(EntityType.EDGE)) {
if (toCore) {
TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> toCoreNfProducer = producerProvider.getTbCoreNotificationsMsgProducer(); TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> toCoreNfProducer = producerProvider.getTbCoreNotificationsMsgProducer();
Set<String> tbCoreServices = partitionService.getAllServiceIds(ServiceType.TB_CORE); Set<String> tbCoreServices = partitionService.getAllServiceIds(ServiceType.TB_CORE);
for (String serviceId : tbCoreServices) { for (String serviceId : tbCoreServices) {
@ -201,13 +198,11 @@ public class DefaultTbClusterService implements TbClusterService {
// No need to push notifications twice // No need to push notifications twice
tbRuleEngineServices.removeAll(tbCoreServices); tbRuleEngineServices.removeAll(tbCoreServices);
} }
if (toRuleEngine) { for (String serviceId : tbRuleEngineServices) {
for (String serviceId : tbRuleEngineServices) { TopicPartitionInfo tpi = partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceId);
TopicPartitionInfo tpi = partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceId); ToRuleEngineNotificationMsg toRuleEngineMsg = ToRuleEngineNotificationMsg.newBuilder().setComponentLifecycleMsg(ByteString.copyFrom(msgBytes)).build();
ToRuleEngineNotificationMsg toRuleEngineMsg = ToRuleEngineNotificationMsg.newBuilder().setComponentLifecycleMsg(ByteString.copyFrom(msgBytes)).build(); toRuleEngineProducer.send(tpi, new TbProtoQueueMsg<>(msg.getEntityId().getId(), toRuleEngineMsg), null);
toRuleEngineProducer.send(tpi, new TbProtoQueueMsg<>(msg.getEntityId().getId(), toRuleEngineMsg), null); toRuleEngineNfs.incrementAndGet();
toRuleEngineNfs.incrementAndGet();
}
} }
} }

56
application/src/test/java/org/thingsboard/server/edge/BaseEdgeTest.java

@ -26,6 +26,7 @@ import com.google.protobuf.AbstractMessage;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.MessageLite; import com.google.protobuf.MessageLite;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.RandomStringUtils;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -48,6 +49,7 @@ import org.thingsboard.server.common.data.edge.Edge;
import org.thingsboard.server.common.data.edge.EdgeEvent; import org.thingsboard.server.common.data.edge.EdgeEvent;
import org.thingsboard.server.common.data.edge.EdgeEventActionType; import org.thingsboard.server.common.data.edge.EdgeEventActionType;
import org.thingsboard.server.common.data.edge.EdgeEventType; import org.thingsboard.server.common.data.edge.EdgeEventType;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.EdgeId; import org.thingsboard.server.common.data.id.EdgeId;
import org.thingsboard.server.common.data.id.EntityId; import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.EntityIdFactory; import org.thingsboard.server.common.data.id.EntityIdFactory;
@ -964,6 +966,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
private void testSendMessagesToCloud() throws Exception { private void testSendMessagesToCloud() throws Exception {
log.info("Sending messages to cloud"); log.info("Sending messages to cloud");
sendDevice(); sendDevice();
sendDeviceWithNameThatAlreadyExistsOnCloud();
sendRelationRequest(); sendRelationRequest();
sendAlarm(); sendAlarm();
sendTelemetry(); sendTelemetry();
@ -992,17 +995,66 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
uplinkMsgBuilder.addDeviceUpdateMsg(deviceUpdateMsgBuilder.build()); uplinkMsgBuilder.addDeviceUpdateMsg(deviceUpdateMsgBuilder.build());
edgeImitator.expectResponsesAmount(1); edgeImitator.expectResponsesAmount(1);
edgeImitator.expectMessageAmount(1);
testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder); testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build()); edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
edgeImitator.waitForResponses(); edgeImitator.waitForResponses();
edgeImitator.waitForMessages();
AbstractMessage latestMessage = edgeImitator.getLatestMessage();
Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg);
DeviceUpdateMsg latestDeviceUpdateMsg = (DeviceUpdateMsg) latestMessage;
Assert.assertEquals("Edge Device 2", latestDeviceUpdateMsg.getName());
UUID newDeviceId = new UUID(latestDeviceUpdateMsg.getIdMSB(), latestDeviceUpdateMsg.getIdLSB());
Device device = doGet("/api/device/" + uuid.toString(), Device.class); Device device = doGet("/api/device/" + newDeviceId, Device.class);
Assert.assertNotNull(device); Assert.assertNotNull(device);
Assert.assertEquals("Edge Device 2", device.getName()); Assert.assertEquals("Edge Device 2", device.getName());
} }
private void sendDeviceWithNameThatAlreadyExistsOnCloud() throws Exception {
String deviceOnCloudName = RandomStringUtils.randomAlphanumeric(15);
Device deviceOnCloud = saveDevice(deviceOnCloudName);
UUID uuid = UUIDs.timeBased();
UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
DeviceUpdateMsg.Builder deviceUpdateMsgBuilder = DeviceUpdateMsg.newBuilder();
deviceUpdateMsgBuilder.setIdMSB(uuid.getMostSignificantBits());
deviceUpdateMsgBuilder.setIdLSB(uuid.getLeastSignificantBits());
deviceUpdateMsgBuilder.setName(deviceOnCloudName);
deviceUpdateMsgBuilder.setType("test");
deviceUpdateMsgBuilder.setMsgType(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE);
testAutoGeneratedCodeByProtobuf(deviceUpdateMsgBuilder);
uplinkMsgBuilder.addDeviceUpdateMsg(deviceUpdateMsgBuilder.build());
edgeImitator.expectResponsesAmount(1);
edgeImitator.expectMessageAmount(1);
testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
edgeImitator.waitForResponses();
edgeImitator.waitForMessages();
AbstractMessage latestMessage = edgeImitator.getLatestMessage();
Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg);
DeviceUpdateMsg latestDeviceUpdateMsg = (DeviceUpdateMsg) latestMessage;
Assert.assertNotEquals(deviceOnCloudName, latestDeviceUpdateMsg.getName());
Assert.assertEquals(deviceOnCloudName, latestDeviceUpdateMsg.getConflictName());
UUID newDeviceId = new UUID(latestDeviceUpdateMsg.getIdMSB(), latestDeviceUpdateMsg.getIdLSB());
Assert.assertNotEquals(deviceOnCloud.getId().getId(), newDeviceId);
Device device = doGet("/api/device/" + newDeviceId, Device.class);
Assert.assertNotNull(device);
Assert.assertNotEquals(deviceOnCloudName, device.getName());
}
private void sendRelationRequest() throws Exception { private void sendRelationRequest() throws Exception {
Device device = findDeviceByName("Edge Device 1"); Device device = findDeviceByName("Edge Device 1");
Asset asset = findAssetByName("Edge Asset 1"); Asset asset = findAssetByName("Edge Asset 1");

2
common/data/src/main/java/org/thingsboard/server/common/data/edge/Edge.java

@ -47,7 +47,6 @@ public class Edge extends SearchTextBasedWithAdditionalInfo<EdgeId> implements H
private String secret; private String secret;
private String edgeLicenseKey; private String edgeLicenseKey;
private String cloudEndpoint; private String cloudEndpoint;
private transient JsonNode configuration;
public Edge() { public Edge() {
super(); super();
@ -68,7 +67,6 @@ public class Edge extends SearchTextBasedWithAdditionalInfo<EdgeId> implements H
this.secret = edge.getSecret(); this.secret = edge.getSecret();
this.edgeLicenseKey = edge.getEdgeLicenseKey(); this.edgeLicenseKey = edge.getEdgeLicenseKey();
this.cloudEndpoint = edge.getCloudEndpoint(); this.cloudEndpoint = edge.getCloudEndpoint();
this.configuration = edge.getConfiguration();
} }
@Override @Override

2
common/data/src/main/java/org/thingsboard/server/common/data/edge/EdgeEventActionType.java

@ -34,5 +34,5 @@ public enum EdgeEventActionType {
ASSIGNED_TO_EDGE, ASSIGNED_TO_EDGE,
UNASSIGNED_FROM_EDGE, UNASSIGNED_FROM_EDGE,
CREDENTIALS_REQUEST, CREDENTIALS_REQUEST,
ENTITY_EXISTS_REQUEST ENTITY_MERGE_REQUEST
} }

5
common/edge-api/src/main/proto/edge.proto

@ -87,7 +87,7 @@ message EdgeConfiguration {
string secret = 10; string secret = 10;
string edgeLicenseKey = 11; string edgeLicenseKey = 11;
string cloudEndpoint = 12; string cloudEndpoint = 12;
string configuration = 13; string additionalInfo = 13;
string cloudType = 14; string cloudType = 14;
} }
@ -97,7 +97,7 @@ enum UpdateMsgType {
ENTITY_DELETED_RPC_MESSAGE = 2; ENTITY_DELETED_RPC_MESSAGE = 2;
ALARM_ACK_RPC_MESSAGE = 3; ALARM_ACK_RPC_MESSAGE = 3;
ALARM_CLEAR_RPC_MESSAGE = 4; ALARM_CLEAR_RPC_MESSAGE = 4;
DEVICE_CONFLICT_RPC_MESSAGE = 5; ENTITY_MERGE_RPC_MESSAGE = 5;
} }
message EntityDataProto { message EntityDataProto {
@ -182,6 +182,7 @@ message DeviceUpdateMsg {
string type = 7; string type = 7;
string label = 8; string label = 8;
string additionalInfo = 9; string additionalInfo = 9;
string conflictName = 10;
} }
message DeviceCredentialsUpdateMsg { message DeviceCredentialsUpdateMsg {

1
dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java

@ -366,7 +366,6 @@ public class ModelConstants {
public static final String EDGE_NAME_PROPERTY = "name"; public static final String EDGE_NAME_PROPERTY = "name";
public static final String EDGE_LABEL_PROPERTY = "label"; public static final String EDGE_LABEL_PROPERTY = "label";
public static final String EDGE_TYPE_PROPERTY = "type"; public static final String EDGE_TYPE_PROPERTY = "type";
public static final String EDGE_CONFIGURATION_PROPERTY = "configuration";
public static final String EDGE_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; public static final String EDGE_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY;
public static final String EDGE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "edge_by_tenant_and_search_text"; public static final String EDGE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "edge_by_tenant_and_search_text";
public static final String EDGE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "edge_by_tenant_by_type_and_search_text"; public static final String EDGE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "edge_by_tenant_by_type_and_search_text";

6
dao/src/main/java/org/thingsboard/server/dao/model/nosql/EdgeEntity.java

@ -34,7 +34,6 @@ import java.util.UUID;
import static org.thingsboard.server.dao.model.ModelConstants.EDGE_ADDITIONAL_INFO_PROPERTY; import static org.thingsboard.server.dao.model.ModelConstants.EDGE_ADDITIONAL_INFO_PROPERTY;
import static org.thingsboard.server.dao.model.ModelConstants.EDGE_CLOUD_ENDPOINT_KEY_PROPERTY; import static org.thingsboard.server.dao.model.ModelConstants.EDGE_CLOUD_ENDPOINT_KEY_PROPERTY;
import static org.thingsboard.server.dao.model.ModelConstants.EDGE_COLUMN_FAMILY_NAME; import static org.thingsboard.server.dao.model.ModelConstants.EDGE_COLUMN_FAMILY_NAME;
import static org.thingsboard.server.dao.model.ModelConstants.EDGE_CONFIGURATION_PROPERTY;
import static org.thingsboard.server.dao.model.ModelConstants.EDGE_CUSTOMER_ID_PROPERTY; import static org.thingsboard.server.dao.model.ModelConstants.EDGE_CUSTOMER_ID_PROPERTY;
import static org.thingsboard.server.dao.model.ModelConstants.EDGE_LABEL_PROPERTY; import static org.thingsboard.server.dao.model.ModelConstants.EDGE_LABEL_PROPERTY;
import static org.thingsboard.server.dao.model.ModelConstants.EDGE_LICENSE_KEY_PROPERTY; import static org.thingsboard.server.dao.model.ModelConstants.EDGE_LICENSE_KEY_PROPERTY;
@ -91,9 +90,6 @@ public class EdgeEntity implements SearchTextEntity<Edge> {
@Column(name = EDGE_SECRET_PROPERTY) @Column(name = EDGE_SECRET_PROPERTY)
private String secret; private String secret;
@Column(name = EDGE_CONFIGURATION_PROPERTY, codec = JsonCodec.class)
private JsonNode configuration;
@Column(name = EDGE_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) @Column(name = EDGE_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class)
private JsonNode additionalInfo; private JsonNode additionalInfo;
@ -131,7 +127,6 @@ public class EdgeEntity implements SearchTextEntity<Edge> {
this.secret = edge.getSecret(); this.secret = edge.getSecret();
this.edgeLicenseKey = edge.getEdgeLicenseKey(); this.edgeLicenseKey = edge.getEdgeLicenseKey();
this.cloudEndpoint = edge.getCloudEndpoint(); this.cloudEndpoint = edge.getCloudEndpoint();
this.configuration = edge.getConfiguration();
this.additionalInfo = edge.getAdditionalInfo(); this.additionalInfo = edge.getAdditionalInfo();
} }
@ -160,7 +155,6 @@ public class EdgeEntity implements SearchTextEntity<Edge> {
edge.setSecret(secret); edge.setSecret(secret);
edge.setEdgeLicenseKey(edgeLicenseKey); edge.setEdgeLicenseKey(edgeLicenseKey);
edge.setCloudEndpoint(cloudEndpoint); edge.setCloudEndpoint(cloudEndpoint);
edge.setConfiguration(configuration);
edge.setAdditionalInfo(additionalInfo); edge.setAdditionalInfo(additionalInfo);
return edge; return edge;
} }

6
dao/src/main/java/org/thingsboard/server/dao/model/sql/EdgeEntity.java

@ -89,10 +89,6 @@ public class EdgeEntity extends BaseSqlEntity<Edge> implements SearchTextEntity<
@Column(name = EDGE_CLOUD_ENDPOINT_KEY_PROPERTY) @Column(name = EDGE_CLOUD_ENDPOINT_KEY_PROPERTY)
private String cloudEndpoint; private String cloudEndpoint;
@Type(type = "json")
@Column(name = ModelConstants.EDGE_CONFIGURATION_PROPERTY)
private JsonNode configuration;
@Type(type = "json") @Type(type = "json")
@Column(name = ModelConstants.EDGE_ADDITIONAL_INFO_PROPERTY) @Column(name = ModelConstants.EDGE_ADDITIONAL_INFO_PROPERTY)
private JsonNode additionalInfo; private JsonNode additionalInfo;
@ -121,7 +117,6 @@ public class EdgeEntity extends BaseSqlEntity<Edge> implements SearchTextEntity<
this.secret = edge.getSecret(); this.secret = edge.getSecret();
this.edgeLicenseKey = edge.getEdgeLicenseKey(); this.edgeLicenseKey = edge.getEdgeLicenseKey();
this.cloudEndpoint = edge.getCloudEndpoint(); this.cloudEndpoint = edge.getCloudEndpoint();
this.configuration = edge.getConfiguration();
this.additionalInfo = edge.getAdditionalInfo(); this.additionalInfo = edge.getAdditionalInfo();
} }
@ -159,7 +154,6 @@ public class EdgeEntity extends BaseSqlEntity<Edge> implements SearchTextEntity<
edge.setSecret(secret); edge.setSecret(secret);
edge.setEdgeLicenseKey(edgeLicenseKey); edge.setEdgeLicenseKey(edgeLicenseKey);
edge.setCloudEndpoint(cloudEndpoint); edge.setCloudEndpoint(cloudEndpoint);
edge.setConfiguration(configuration);
edge.setAdditionalInfo(additionalInfo); edge.setAdditionalInfo(additionalInfo);
return edge; return edge;
} }

1
dao/src/main/resources/cassandra/schema-entities.cql

@ -739,7 +739,6 @@ CREATE TABLE IF NOT EXISTS thingsboard.edge (
secret text, secret text,
edge_license_key text, edge_license_key text,
cloud_endpoint text, cloud_endpoint text,
configuration text,
additional_info text, additional_info text,
PRIMARY KEY (id, tenant_id, customer_id, type) PRIMARY KEY (id, tenant_id, customer_id, type)
); );

1
dao/src/main/resources/sql/schema-entities-hsql.sql

@ -259,7 +259,6 @@ CREATE TABLE IF NOT EXISTS edge (
additional_info varchar, additional_info varchar,
customer_id varchar(31), customer_id varchar(31),
root_rule_chain_id varchar(31), root_rule_chain_id varchar(31),
configuration varchar(10000000),
type varchar(255), type varchar(255),
name varchar(255), name varchar(255),
label varchar(255), label varchar(255),

1
dao/src/main/resources/sql/schema-entities.sql

@ -259,7 +259,6 @@ CREATE TABLE IF NOT EXISTS edge (
additional_info varchar, additional_info varchar,
customer_id varchar(31), customer_id varchar(31),
root_rule_chain_id varchar(31), root_rule_chain_id varchar(31),
configuration varchar(10000000),
type varchar(255), type varchar(255),
name varchar(255), name varchar(255),
label varchar(255), label varchar(255),

19
rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java

@ -87,6 +87,7 @@ import org.thingsboard.server.common.data.relation.EntityRelationsQuery;
import org.thingsboard.server.common.data.relation.RelationTypeGroup; import org.thingsboard.server.common.data.relation.RelationTypeGroup;
import org.thingsboard.server.common.data.rule.RuleChain; import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.common.data.rule.RuleChainMetaData; import org.thingsboard.server.common.data.rule.RuleChainMetaData;
import org.thingsboard.server.common.data.rule.RuleChainType;
import org.thingsboard.server.common.data.security.DeviceCredentials; import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.common.data.security.DeviceCredentialsType; import org.thingsboard.server.common.data.security.DeviceCredentialsType;
import org.thingsboard.server.common.data.security.model.SecuritySettings; import org.thingsboard.server.common.data.security.model.SecuritySettings;
@ -97,6 +98,7 @@ import org.thingsboard.server.common.data.widget.WidgetsBundle;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -626,22 +628,31 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
} }
public List<ComponentDescriptor> getComponentDescriptorsByType(ComponentType componentType) { public List<ComponentDescriptor> getComponentDescriptorsByType(ComponentType componentType) {
return getComponentDescriptorsByType(componentType, RuleChainType.CORE);
}
public List<ComponentDescriptor> getComponentDescriptorsByType(ComponentType componentType, RuleChainType ruleChainType) {
return restTemplate.exchange( return restTemplate.exchange(
baseURL + "/api/components?componentType={componentType}", baseURL + "/api/components/" + componentType.name() + "/?ruleChainType={ruleChainType}",
HttpMethod.GET, HttpEntity.EMPTY, HttpMethod.GET, HttpEntity.EMPTY,
new ParameterizedTypeReference<List<ComponentDescriptor>>() { new ParameterizedTypeReference<List<ComponentDescriptor>>() {
}, },
componentType).getBody(); ruleChainType).getBody();
} }
public List<ComponentDescriptor> getComponentDescriptorsByTypes(List<ComponentType> componentTypes) { public List<ComponentDescriptor> getComponentDescriptorsByTypes(List<ComponentType> componentTypes) {
return getComponentDescriptorsByTypes(componentTypes, RuleChainType.CORE);
}
public List<ComponentDescriptor> getComponentDescriptorsByTypes(List<ComponentType> componentTypes, RuleChainType ruleChainType) {
return restTemplate.exchange( return restTemplate.exchange(
baseURL + "/api/components?componentTypes={componentTypes}", baseURL + "/api/components?componentTypes={componentTypes}&ruleChainType={ruleChainType}",
HttpMethod.GET, HttpMethod.GET,
HttpEntity.EMPTY, HttpEntity.EMPTY,
new ParameterizedTypeReference<List<ComponentDescriptor>>() { new ParameterizedTypeReference<List<ComponentDescriptor>>() {
}, },
listEnumToString(componentTypes)) listEnumToString(componentTypes),
ruleChainType)
.getBody(); .getBody();
} }

12
ui/src/app/api/entity.service.js

@ -1278,10 +1278,14 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
} }
if (entityType === types.entityType.edge) { if (entityType === types.entityType.edge) {
newEntity.edgeLicenseKey = entityParameters.edgeLicenseKey; Object.assign(newEntity,
newEntity.cloudEndpoint = entityParameters.cloudEndpoint; {
newEntity.routingKey = entityParameters.routingKey; edgeLicenseKey: entityParameters.edgeLicenseKey,
newEntity.secret = entityParameters.secret; cloudEndpoint: entityParameters.cloudEndpoint,
routingKey: entityParameters.routingKey,
secret: entityParameters.secret
}
);
} }
let saveEntityPromise = getEntitySavePromise(entityType, newEntity, config); let saveEntityPromise = getEntitySavePromise(entityType, newEntity, config);

14
ui/src/app/import-export/table-columns-assignment.directive.js

@ -133,15 +133,19 @@ function TableColumnsAssignmentController($scope, types, $timeout) {
vm.columnTypes.name.disable = isSelectName; vm.columnTypes.name.disable = isSelectName;
vm.columnTypes.type.disable = isSelectType; vm.columnTypes.type.disable = isSelectType;
vm.columnTypes.label.disable = isSelectLabel; vm.columnTypes.label.disable = isSelectLabel;
vm.columnTypes.gateway.disable = isSelectGateway; if (angular.isDefined(vm.columnTypes.gateway)) {
vm.columnTypes.gateway.disable = isSelectGateway;
}
vm.columnTypes.description.disable = isSelectDescription; vm.columnTypes.description.disable = isSelectDescription;
if (angular.isDefined(vm.columnTypes.accessToken)) { if (angular.isDefined(vm.columnTypes.accessToken)) {
vm.columnTypes.accessToken.disable = isSelectCredentials; vm.columnTypes.accessToken.disable = isSelectCredentials;
} }
vm.columnTypes.edgeLicenseKey.disable = isSelectEdgeLicenseKey; if (vm.entityType === types.entityType.edge) {
vm.columnTypes.cloudEndpoint.disable = isSelectCloudEndpoint; vm.columnTypes.edgeLicenseKey.disable = isSelectEdgeLicenseKey;
vm.columnTypes.routingKey.disable = isSelectRoutingKey; vm.columnTypes.cloudEndpoint.disable = isSelectCloudEndpoint;
vm.columnTypes.secret.disable = isSelectSecret; vm.columnTypes.routingKey.disable = isSelectRoutingKey;
vm.columnTypes.secret.disable = isSelectSecret;
}
}); });
} }
}, true); }, true);

9
ui/src/app/locale/locale.constant-en_US.json

@ -848,7 +848,8 @@
"status": "Received by edge", "status": "Received by edge",
"deployed": "Deployed", "deployed": "Deployed",
"pending": "Pending", "pending": "Pending",
"unassign-edges-action-title": "Unassign { count, plural, 1 {1 edge} other {# edges} } from customer" "unassign-edges-action-title": "Unassign { count, plural, 1 {1 edge} other {# edges} } from customer",
"enter-edge-type": "Enter edge type"
}, },
"error": { "error": {
"unable-to-connect": "Unable to connect to the server! Please check your internet connection.", "unable-to-connect": "Unable to connect to the server! Please check your internet connection.",
@ -1405,9 +1406,9 @@
"access-token": "Access token", "access-token": "Access token",
"isgateway": "Is Gateway", "isgateway": "Is Gateway",
"description": "Description", "description": "Description",
"edgeLicenseKey": "Edge license key", "edgeLicenseKey": "License Key",
"cloudEndpoint": "Cloud endpoint", "cloudEndpoint": "Cloud Endpoint",
"routingKey": "Edge routing key", "routingKey": "Edge key",
"secret": "Edge secret" "secret": "Edge secret"
}, },
"stepper-text":{ "stepper-text":{

Loading…
Cancel
Save