|
|
|
@ -15,15 +15,12 @@ |
|
|
|
*/ |
|
|
|
package org.thingsboard.server.service.edge.rpc.processor.entityview; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
import com.google.common.util.concurrent.Futures; |
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.data.util.Pair; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.common.data.DataConstants; |
|
|
|
import org.thingsboard.server.common.data.EdgeUtils; |
|
|
|
import org.thingsboard.server.common.data.EntityView; |
|
|
|
import org.thingsboard.server.common.data.edge.Edge; |
|
|
|
@ -34,14 +31,11 @@ import org.thingsboard.server.common.data.id.CustomerId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityViewId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.msg.TbMsgType; |
|
|
|
import org.thingsboard.server.common.msg.TbMsg; |
|
|
|
import org.thingsboard.server.common.msg.TbMsgDataType; |
|
|
|
import org.thingsboard.server.common.msg.TbMsgMetaData; |
|
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
import org.thingsboard.server.gen.edge.v1.DownlinkMsg; |
|
|
|
import org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg; |
|
|
|
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
|
|
import org.thingsboard.server.queue.TbQueueCallback; |
|
|
|
import org.thingsboard.server.queue.TbQueueMsgMetadata; |
|
|
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
|
|
|
|
|
|
import java.util.UUID; |
|
|
|
@ -90,7 +84,7 @@ public class EntityViewEdgeProcessor extends BaseEntityViewProcessor { |
|
|
|
Boolean created = resultPair.getFirst(); |
|
|
|
if (created) { |
|
|
|
createRelationFromEdge(tenantId, edge.getId(), entityViewId); |
|
|
|
pushAssetCreatedEventToRuleEngine(tenantId, edge, entityViewId); |
|
|
|
pushEntityViewCreatedEventToRuleEngine(tenantId, edge, entityViewId); |
|
|
|
entityViewService.assignEntityViewToEdge(tenantId, entityViewId, edge.getId()); |
|
|
|
} |
|
|
|
Boolean assetNameUpdated = resultPair.getSecond(); |
|
|
|
@ -99,25 +93,14 @@ public class EntityViewEdgeProcessor extends BaseEntityViewProcessor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void pushAssetCreatedEventToRuleEngine(TenantId tenantId, Edge edge, EntityViewId entityViewId) { |
|
|
|
private void pushEntityViewCreatedEventToRuleEngine(TenantId tenantId, Edge edge, EntityViewId entityViewId) { |
|
|
|
try { |
|
|
|
EntityView entityView = entityViewService.findEntityViewById(tenantId, entityViewId); |
|
|
|
ObjectNode entityNode = JacksonUtil.OBJECT_MAPPER.valueToTree(entityView); |
|
|
|
TbMsg tbMsg = TbMsg.newMsg(TbMsgType.ENTITY_CREATED, entityViewId, entityView.getCustomerId(), |
|
|
|
getActionTbMsgMetaData(edge, entityView.getCustomerId()), TbMsgDataType.JSON, JacksonUtil.OBJECT_MAPPER.writeValueAsString(entityNode)); |
|
|
|
tbClusterService.pushMsgToRuleEngine(tenantId, entityViewId, tbMsg, new TbQueueCallback() { |
|
|
|
@Override |
|
|
|
public void onSuccess(TbQueueMsgMetadata metadata) { |
|
|
|
log.debug("[{}] Successfully send ENTITY_CREATED EVENT to rule engine [{}]", tenantId, entityView); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Throwable t) { |
|
|
|
log.warn("[{}] Failed to send ENTITY_CREATED EVENT to rule engine [{}]", tenantId, entityView, t); |
|
|
|
} |
|
|
|
}); |
|
|
|
} catch (JsonProcessingException | IllegalArgumentException e) { |
|
|
|
log.warn("[{}][{}] Failed to push entity view action to rule engine: {}", tenantId, entityViewId, DataConstants.ENTITY_CREATED, e); |
|
|
|
String entityViewAsString = JacksonUtil.toString(entityView); |
|
|
|
TbMsgMetaData msgMetaData = getEdgeActionTbMsgMetaData(edge, entityView.getCustomerId()); |
|
|
|
pushEntityCreatedEventToRuleEngine(tenantId, entityViewId, entityView.getCustomerId(), entityViewAsString, msgMetaData); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("[{}][{}] Failed to push entity view action to rule engine: {}", tenantId, entityViewId, TbMsgType.ENTITY_CREATED.name(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|