Push credentials updates to edge

This commit is contained in:
Volodymyr Babak 2020-04-27 13:53:51 +03:00
parent 2f85f7037a
commit 24f2ea502c
4 changed files with 22 additions and 3 deletions

View File

@ -565,6 +565,7 @@ public abstract class BaseController {
}
if (e == null) {
pushEntityActionToRuleEngine(entityId, entity, user, customerId, actionType, additionalInfo);
// TODO: voba - refactor to push events to edge queue directly, instead of the rule engine flow
}
auditLogService.logEntityAction(user.getTenantId(), customerId, user.getId(), user.getName(), entityId, entity, actionType, e, additionalInfo);
}
@ -611,6 +612,10 @@ public abstract class BaseController {
case UNASSIGNED_FROM_EDGE:
msgType = DataConstants.ENTITY_UNASSIGNED_FROM_EDGE;
break;
case CREDENTIALS_UPDATED:
//TODO: voba - this is not efficient way to do this. Refactor on later stages
msgType = DataConstants.ENTITY_UPDATED;
break;
}
if (!StringUtils.isEmpty(msgType)) {
try {

View File

@ -16,8 +16,11 @@
package org.thingsboard.server.service.edge.rpc.constructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.dao.device.DeviceCredentialsService;
import org.thingsboard.server.gen.edge.DeviceUpdateMsg;
import org.thingsboard.server.gen.edge.UpdateMsgType;
@ -25,11 +28,21 @@ import org.thingsboard.server.gen.edge.UpdateMsgType;
@Slf4j
public class DeviceUpdateMsgConstructor {
@Autowired
private DeviceCredentialsService deviceCredentialsService;
public DeviceUpdateMsg constructDeviceUpdatedMsg(UpdateMsgType msgType, Device device) {
DeviceCredentials deviceCredentials
= deviceCredentialsService.findDeviceCredentialsByDeviceId(device.getTenantId(), device.getId());
DeviceUpdateMsg.Builder builder = DeviceUpdateMsg.newBuilder()
.setMsgType(msgType)
.setName(device.getName())
.setType(device.getType());
.setType(device.getType())
.setCredentialsType(deviceCredentials.getCredentialsType().name())
.setCredentialsId(deviceCredentials.getCredentialsId());
if (deviceCredentials.getCredentialsValue() != null) {
builder.setCredentialsValue(deviceCredentials.getCredentialsValue());
}
return builder.build();
}
}

View File

@ -15,12 +15,10 @@
*/
package org.thingsboard.server.dao.edge;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.ListenableFuture;
import org.thingsboard.server.common.data.EntitySubtype;
import org.thingsboard.server.common.data.Event;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.edge.Edge;
import org.thingsboard.server.common.data.edge.EdgeSearchQuery;
import org.thingsboard.server.common.data.id.CustomerId;

View File

@ -160,6 +160,9 @@ message DeviceUpdateMsg {
UpdateMsgType msgType = 1;
string name = 2;
string type = 3;
string credentialsType = 4;
string credentialsId = 5;
string credentialsValue = 6;
}
message AssetUpdateMsg {