Improvements to the TbMsg to support CustomerId
This commit is contained in:
parent
3db3385571
commit
0ff4e6ac0d
@ -926,7 +926,7 @@ public abstract class BaseController {
|
|||||||
tenantId = ((HasTenantId) entity).getTenantId();
|
tenantId = ((HasTenantId) entity).getTenantId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tbClusterService.pushMsgToRuleEngine(tenantId, customerId, entityId, tbMsg, null);
|
tbClusterService.pushMsgToRuleEngine(tenantId, entityId, tbMsg, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("[{}] Failed to push entity action to rule engine: {}", entityId, actionType, e);
|
log.warn("[{}] Failed to push entity action to rule engine: {}", entityId, actionType, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -645,8 +645,8 @@ public class DeviceController extends BaseController {
|
|||||||
private void pushAssignedFromNotification(Tenant currentTenant, TenantId newTenantId, Device assignedDevice) {
|
private void pushAssignedFromNotification(Tenant currentTenant, TenantId newTenantId, Device assignedDevice) {
|
||||||
String data = entityToStr(assignedDevice);
|
String data = entityToStr(assignedDevice);
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
TbMsg tbMsg = TbMsg.newMsg(DataConstants.ENTITY_ASSIGNED_FROM_TENANT, assignedDevice.getId(), getMetaDataForAssignedFrom(currentTenant), TbMsgDataType.JSON, data);
|
TbMsg tbMsg = TbMsg.newMsg(DataConstants.ENTITY_ASSIGNED_FROM_TENANT, assignedDevice.getId(), assignedDevice.getCustomerId(), getMetaDataForAssignedFrom(currentTenant), TbMsgDataType.JSON, data);
|
||||||
tbClusterService.pushMsgToRuleEngine(newTenantId, assignedDevice.getCustomerId(), assignedDevice.getId(), tbMsg, null);
|
tbClusterService.pushMsgToRuleEngine(newTenantId, assignedDevice.getId(), tbMsg, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -231,9 +231,9 @@ public class DeviceProcessor extends BaseProcessor {
|
|||||||
try {
|
try {
|
||||||
DeviceId deviceId = device.getId();
|
DeviceId deviceId = device.getId();
|
||||||
ObjectNode entityNode = mapper.valueToTree(device);
|
ObjectNode entityNode = mapper.valueToTree(device);
|
||||||
TbMsg tbMsg = TbMsg.newMsg(DataConstants.ENTITY_CREATED, deviceId,
|
TbMsg tbMsg = TbMsg.newMsg(DataConstants.ENTITY_CREATED, deviceId, device.getCustomerId(),
|
||||||
getActionTbMsgMetaData(edge, device.getCustomerId()), TbMsgDataType.JSON, mapper.writeValueAsString(entityNode));
|
getActionTbMsgMetaData(edge, device.getCustomerId()), TbMsgDataType.JSON, mapper.writeValueAsString(entityNode));
|
||||||
tbClusterService.pushMsgToRuleEngine(tenantId, device.getCustomerId(), deviceId, tbMsg, new TbQueueCallback() {
|
tbClusterService.pushMsgToRuleEngine(tenantId, deviceId, tbMsg, new TbQueueCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(TbQueueMsgMetadata metadata) {
|
public void onSuccess(TbQueueMsgMetadata metadata) {
|
||||||
log.debug("Successfully send ENTITY_CREATED EVENT to rule engine [{}]", device);
|
log.debug("Successfully send ENTITY_CREATED EVENT to rule engine [{}]", device);
|
||||||
|
|||||||
@ -156,8 +156,8 @@ public class TelemetryProcessor extends BaseProcessor {
|
|||||||
Pair<String, RuleChainId> defaultQueueAndRuleChain = getDefaultQueueNameAndRuleChainId(tenantId, entityId);
|
Pair<String, RuleChainId> defaultQueueAndRuleChain = getDefaultQueueNameAndRuleChainId(tenantId, entityId);
|
||||||
String queueName = defaultQueueAndRuleChain.getKey();
|
String queueName = defaultQueueAndRuleChain.getKey();
|
||||||
RuleChainId ruleChainId = defaultQueueAndRuleChain.getValue();
|
RuleChainId ruleChainId = defaultQueueAndRuleChain.getValue();
|
||||||
TbMsg tbMsg = TbMsg.newMsg(queueName, SessionMsgType.POST_TELEMETRY_REQUEST.name(), entityId, metaData, gson.toJson(json), ruleChainId, null);
|
TbMsg tbMsg = TbMsg.newMsg(queueName, SessionMsgType.POST_TELEMETRY_REQUEST.name(), entityId, customerId, metaData, gson.toJson(json), ruleChainId, null);
|
||||||
tbClusterService.pushMsgToRuleEngine(tenantId, customerId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() {
|
tbClusterService.pushMsgToRuleEngine(tenantId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(TbQueueMsgMetadata metadata) {
|
public void onSuccess(TbQueueMsgMetadata metadata) {
|
||||||
futureToSet.set(null);
|
futureToSet.set(null);
|
||||||
@ -179,8 +179,8 @@ public class TelemetryProcessor extends BaseProcessor {
|
|||||||
Pair<String, RuleChainId> defaultQueueAndRuleChain = getDefaultQueueNameAndRuleChainId(tenantId, entityId);
|
Pair<String, RuleChainId> defaultQueueAndRuleChain = getDefaultQueueNameAndRuleChainId(tenantId, entityId);
|
||||||
String queueName = defaultQueueAndRuleChain.getKey();
|
String queueName = defaultQueueAndRuleChain.getKey();
|
||||||
RuleChainId ruleChainId = defaultQueueAndRuleChain.getValue();
|
RuleChainId ruleChainId = defaultQueueAndRuleChain.getValue();
|
||||||
TbMsg tbMsg = TbMsg.newMsg(queueName, SessionMsgType.POST_ATTRIBUTES_REQUEST.name(), entityId, metaData, gson.toJson(json), ruleChainId, null);
|
TbMsg tbMsg = TbMsg.newMsg(queueName, SessionMsgType.POST_ATTRIBUTES_REQUEST.name(), entityId, customerId, metaData, gson.toJson(json), ruleChainId, null);
|
||||||
tbClusterService.pushMsgToRuleEngine(tenantId, customerId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() {
|
tbClusterService.pushMsgToRuleEngine(tenantId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(TbQueueMsgMetadata metadata) {
|
public void onSuccess(TbQueueMsgMetadata metadata) {
|
||||||
futureToSet.set(null);
|
futureToSet.set(null);
|
||||||
@ -206,8 +206,8 @@ public class TelemetryProcessor extends BaseProcessor {
|
|||||||
Pair<String, RuleChainId> defaultQueueAndRuleChain = getDefaultQueueNameAndRuleChainId(tenantId, entityId);
|
Pair<String, RuleChainId> defaultQueueAndRuleChain = getDefaultQueueNameAndRuleChainId(tenantId, entityId);
|
||||||
String queueName = defaultQueueAndRuleChain.getKey();
|
String queueName = defaultQueueAndRuleChain.getKey();
|
||||||
RuleChainId ruleChainId = defaultQueueAndRuleChain.getValue();
|
RuleChainId ruleChainId = defaultQueueAndRuleChain.getValue();
|
||||||
TbMsg tbMsg = TbMsg.newMsg(queueName, DataConstants.ATTRIBUTES_UPDATED, entityId, metaData, gson.toJson(json), ruleChainId, null);
|
TbMsg tbMsg = TbMsg.newMsg(queueName, DataConstants.ATTRIBUTES_UPDATED, entityId, customerId, metaData, gson.toJson(json), ruleChainId, null);
|
||||||
tbClusterService.pushMsgToRuleEngine(tenantId, customerId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() {
|
tbClusterService.pushMsgToRuleEngine(tenantId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(TbQueueMsgMetadata metadata) {
|
public void onSuccess(TbQueueMsgMetadata metadata) {
|
||||||
futureToSet.set(null);
|
futureToSet.set(null);
|
||||||
|
|||||||
@ -134,12 +134,7 @@ public class DefaultTbClusterService implements TbClusterService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pushMsgToRuleEngine(TenantId tenantId, EntityId entityId, TbMsg msg, TbQueueCallback callback) {
|
public void pushMsgToRuleEngine(TenantId tenantId, EntityId entityId, TbMsg tbMsg, TbQueueCallback callback) {
|
||||||
pushMsgToRuleEngine(tenantId, null, entityId, msg, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pushMsgToRuleEngine(TenantId tenantId, CustomerId customerId, EntityId entityId, TbMsg tbMsg, TbQueueCallback callback) {
|
|
||||||
if (tenantId.isNullUid()) {
|
if (tenantId.isNullUid()) {
|
||||||
if (entityId.getEntityType().equals(EntityType.TENANT)) {
|
if (entityId.getEntityType().equals(EntityType.TENANT)) {
|
||||||
tenantId = new TenantId(entityId.getId());
|
tenantId = new TenantId(entityId.getId());
|
||||||
@ -154,7 +149,6 @@ public class DefaultTbClusterService implements TbClusterService {
|
|||||||
tbMsg = transformMsg(tbMsg, deviceProfileCache.get(tenantId, new DeviceProfileId(entityId.getId())));
|
tbMsg = transformMsg(tbMsg, deviceProfileCache.get(tenantId, new DeviceProfileId(entityId.getId())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tbMsg.setCustomerId(customerId);
|
|
||||||
TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_RULE_ENGINE, tbMsg.getQueueName(), tenantId, entityId);
|
TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_RULE_ENGINE, tbMsg.getQueueName(), tenantId, entityId);
|
||||||
log.trace("PUSHING msg: {} to:{}", tbMsg, tpi);
|
log.trace("PUSHING msg: {} to:{}", tbMsg, tpi);
|
||||||
ToRuleEngineMsg msg = ToRuleEngineMsg.newBuilder()
|
ToRuleEngineMsg msg = ToRuleEngineMsg.newBuilder()
|
||||||
|
|||||||
@ -51,8 +51,6 @@ public interface TbClusterService {
|
|||||||
|
|
||||||
void pushMsgToRuleEngine(TenantId tenantId, EntityId entityId, TbMsg msg, TbQueueCallback callback);
|
void pushMsgToRuleEngine(TenantId tenantId, EntityId entityId, TbMsg msg, TbQueueCallback callback);
|
||||||
|
|
||||||
void pushMsgToRuleEngine(TenantId tenantId, CustomerId customerId, EntityId entityId, TbMsg msg, TbQueueCallback callback);
|
|
||||||
|
|
||||||
void pushNotificationToRuleEngine(String targetServiceId, FromDeviceRpcResponse response, TbQueueCallback callback);
|
void pushNotificationToRuleEngine(String targetServiceId, FromDeviceRpcResponse response, TbQueueCallback callback);
|
||||||
|
|
||||||
void pushNotificationToTransport(String targetServiceId, ToTransportMsg response, TbQueueCallback callback);
|
void pushNotificationToTransport(String targetServiceId, ToTransportMsg response, TbQueueCallback callback);
|
||||||
|
|||||||
@ -168,8 +168,8 @@ public class DefaultTbCoreDeviceRpcService implements TbCoreDeviceRpcService {
|
|||||||
entityNode.put("params", msg.getBody().getParams());
|
entityNode.put("params", msg.getBody().getParams());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TbMsg tbMsg = TbMsg.newMsg(DataConstants.RPC_CALL_FROM_SERVER_TO_DEVICE, msg.getDeviceId(), metaData, TbMsgDataType.JSON, json.writeValueAsString(entityNode));
|
TbMsg tbMsg = TbMsg.newMsg(DataConstants.RPC_CALL_FROM_SERVER_TO_DEVICE, msg.getDeviceId(), currentUser.getCustomerId(), metaData, TbMsgDataType.JSON, json.writeValueAsString(entityNode));
|
||||||
clusterService.pushMsgToRuleEngine(msg.getTenantId(), currentUser.getCustomerId(), msg.getDeviceId(), tbMsg, null);
|
clusterService.pushMsgToRuleEngine(msg.getTenantId(), msg.getDeviceId(), tbMsg, null);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -508,8 +508,8 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit
|
|||||||
if(!persistToTelemetry){
|
if(!persistToTelemetry){
|
||||||
md.putValue(DataConstants.SCOPE, SERVER_SCOPE);
|
md.putValue(DataConstants.SCOPE, SERVER_SCOPE);
|
||||||
}
|
}
|
||||||
TbMsg tbMsg = TbMsg.newMsg(msgType, stateData.getDeviceId(), md, TbMsgDataType.JSON, data);
|
TbMsg tbMsg = TbMsg.newMsg(msgType, stateData.getDeviceId(), stateData.getCustomerId(), md, TbMsgDataType.JSON, data);
|
||||||
clusterService.pushMsgToRuleEngine(stateData.getTenantId(), stateData.getCustomerId(), stateData.getDeviceId(), tbMsg, null);
|
clusterService.pushMsgToRuleEngine(stateData.getTenantId(), stateData.getDeviceId(), tbMsg, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("[{}] Failed to push inactivity alarm: {}", stateData.getDeviceId(), state, e);
|
log.warn("[{}] Failed to push inactivity alarm: {}", stateData.getDeviceId(), state, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -273,8 +273,8 @@ public class DefaultTransportApiService implements TransportApiService {
|
|||||||
|
|
||||||
DeviceId deviceId = device.getId();
|
DeviceId deviceId = device.getId();
|
||||||
ObjectNode entityNode = mapper.valueToTree(device);
|
ObjectNode entityNode = mapper.valueToTree(device);
|
||||||
TbMsg tbMsg = TbMsg.newMsg(DataConstants.ENTITY_CREATED, deviceId, metaData, TbMsgDataType.JSON, mapper.writeValueAsString(entityNode));
|
TbMsg tbMsg = TbMsg.newMsg(DataConstants.ENTITY_CREATED, deviceId, customerId, metaData, TbMsgDataType.JSON, mapper.writeValueAsString(entityNode));
|
||||||
tbClusterService.pushMsgToRuleEngine(tenantId, customerId, deviceId, tbMsg, null);
|
tbClusterService.pushMsgToRuleEngine(tenantId, deviceId, tbMsg, null);
|
||||||
}
|
}
|
||||||
GetOrCreateDeviceFromGatewayResponseMsg.Builder builder = GetOrCreateDeviceFromGatewayResponseMsg.newBuilder()
|
GetOrCreateDeviceFromGatewayResponseMsg.Builder builder = GetOrCreateDeviceFromGatewayResponseMsg.newBuilder()
|
||||||
.setDeviceInfo(getDeviceInfoProto(device));
|
.setDeviceInfo(getDeviceInfoProto(device));
|
||||||
|
|||||||
@ -48,7 +48,7 @@ public final class TbMsg implements Serializable {
|
|||||||
private final long ts;
|
private final long ts;
|
||||||
private final String type;
|
private final String type;
|
||||||
private final EntityId originator;
|
private final EntityId originator;
|
||||||
private CustomerId customerId;
|
private final CustomerId customerId;
|
||||||
private final TbMsgMetaData metaData;
|
private final TbMsgMetaData metaData;
|
||||||
private final TbMsgDataType dataType;
|
private final TbMsgDataType dataType;
|
||||||
private final String data;
|
private final String data;
|
||||||
@ -57,6 +57,7 @@ public final class TbMsg implements Serializable {
|
|||||||
@Getter(value = AccessLevel.NONE)
|
@Getter(value = AccessLevel.NONE)
|
||||||
private final AtomicInteger ruleNodeExecCounter;
|
private final AtomicInteger ruleNodeExecCounter;
|
||||||
|
|
||||||
|
|
||||||
public int getAndIncrementRuleNodeCounter() {
|
public int getAndIncrementRuleNodeCounter() {
|
||||||
return ruleNodeExecCounter.getAndIncrement();
|
return ruleNodeExecCounter.getAndIncrement();
|
||||||
}
|
}
|
||||||
@ -66,60 +67,74 @@ public final class TbMsg implements Serializable {
|
|||||||
transient private final TbMsgCallback callback;
|
transient private final TbMsgCallback callback;
|
||||||
|
|
||||||
public static TbMsg newMsg(String queueName, String type, EntityId originator, TbMsgMetaData metaData, String data, RuleChainId ruleChainId, RuleNodeId ruleNodeId) {
|
public static TbMsg newMsg(String queueName, String type, EntityId originator, TbMsgMetaData metaData, String data, RuleChainId ruleChainId, RuleNodeId ruleNodeId) {
|
||||||
return new TbMsg(queueName, UUID.randomUUID(), System.currentTimeMillis(), type, originator,
|
return new TbMsg(queueName, UUID.randomUUID(), System.currentTimeMillis(), type, originator, null,
|
||||||
|
metaData.copy(), TbMsgDataType.JSON, data, ruleChainId, ruleNodeId, 0, TbMsgCallback.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TbMsg newMsg(String queueName, String type, EntityId originator, CustomerId customerId, TbMsgMetaData metaData, String data, RuleChainId ruleChainId, RuleNodeId ruleNodeId) {
|
||||||
|
return new TbMsg(queueName, UUID.randomUUID(), System.currentTimeMillis(), type, originator, customerId,
|
||||||
metaData.copy(), TbMsgDataType.JSON, data, ruleChainId, ruleNodeId, 0, TbMsgCallback.EMPTY);
|
metaData.copy(), TbMsgDataType.JSON, data, ruleChainId, ruleNodeId, 0, TbMsgCallback.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, String data) {
|
public static TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, String data) {
|
||||||
return new TbMsg(ServiceQueue.MAIN, UUID.randomUUID(), System.currentTimeMillis(), type, originator, metaData.copy(), TbMsgDataType.JSON, data, null, null, 0, TbMsgCallback.EMPTY);
|
return new TbMsg(ServiceQueue.MAIN, UUID.randomUUID(), System.currentTimeMillis(), type, originator, null, metaData.copy(), TbMsgDataType.JSON, data, null, null, 0, TbMsgCallback.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REALLY NEW MSG
|
// REALLY NEW MSG
|
||||||
|
|
||||||
public static TbMsg newMsg(String queueName, String type, EntityId originator, TbMsgMetaData metaData, String data) {
|
public static TbMsg newMsg(String queueName, String type, EntityId originator, TbMsgMetaData metaData, String data) {
|
||||||
return new TbMsg(queueName, UUID.randomUUID(), System.currentTimeMillis(), type, originator, metaData.copy(), TbMsgDataType.JSON, data, null, null, 0, TbMsgCallback.EMPTY);
|
return new TbMsg(queueName, UUID.randomUUID(), System.currentTimeMillis(), type, originator, null, metaData.copy(), TbMsgDataType.JSON, data, null, null, 0, TbMsgCallback.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TbMsg newMsg(String type, EntityId originator, CustomerId customerId, TbMsgMetaData metaData, TbMsgDataType dataType, String data) {
|
||||||
|
return new TbMsg(ServiceQueue.MAIN, UUID.randomUUID(), System.currentTimeMillis(), type, originator, customerId, metaData.copy(), dataType, data, null, null, 0, TbMsgCallback.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data) {
|
public static TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data) {
|
||||||
return new TbMsg(ServiceQueue.MAIN, UUID.randomUUID(), System.currentTimeMillis(), type, originator, metaData.copy(), dataType, data, null, null, 0, TbMsgCallback.EMPTY);
|
return new TbMsg(ServiceQueue.MAIN, UUID.randomUUID(), System.currentTimeMillis(), type, originator, null, metaData.copy(), dataType, data, null, null, 0, TbMsgCallback.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For Tests only
|
// For Tests only
|
||||||
|
|
||||||
public static TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data, RuleChainId ruleChainId, RuleNodeId ruleNodeId) {
|
public static TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data, RuleChainId ruleChainId, RuleNodeId ruleNodeId) {
|
||||||
return new TbMsg(ServiceQueue.MAIN, UUID.randomUUID(), System.currentTimeMillis(), type, originator, metaData.copy(), dataType, data, ruleChainId, ruleNodeId, 0, TbMsgCallback.EMPTY);
|
return new TbMsg(ServiceQueue.MAIN, UUID.randomUUID(), System.currentTimeMillis(), type, originator, null, metaData.copy(), dataType, data, ruleChainId, ruleNodeId, 0, TbMsgCallback.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, String data, TbMsgCallback callback) {
|
public static TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, String data, TbMsgCallback callback) {
|
||||||
return new TbMsg(ServiceQueue.MAIN, UUID.randomUUID(), System.currentTimeMillis(), type, originator, metaData.copy(), TbMsgDataType.JSON, data, null, null, 0, callback);
|
return new TbMsg(ServiceQueue.MAIN, UUID.randomUUID(), System.currentTimeMillis(), type, originator, null, metaData.copy(), TbMsgDataType.JSON, data, null, null, 0, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TbMsg transformMsg(TbMsg tbMsg, String type, EntityId originator, TbMsgMetaData metaData, String data) {
|
public static TbMsg transformMsg(TbMsg tbMsg, String type, EntityId originator, TbMsgMetaData metaData, String data) {
|
||||||
return new TbMsg(tbMsg.getQueueName(), tbMsg.getId(), tbMsg.getTs(), type, originator, metaData.copy(), tbMsg.getDataType(),
|
return new TbMsg(tbMsg.queueName, tbMsg.id, tbMsg.ts, type, originator, tbMsg.customerId, metaData.copy(), tbMsg.dataType,
|
||||||
data, tbMsg.getRuleChainId(), tbMsg.getRuleNodeId(), tbMsg.ruleNodeExecCounter.get(), tbMsg.getCallback());
|
data, tbMsg.ruleChainId, tbMsg.ruleNodeId, tbMsg.ruleNodeExecCounter.get(), tbMsg.callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TbMsg transformMsg(TbMsg tbMsg, CustomerId customerId) {
|
||||||
|
return new TbMsg(tbMsg.queueName, tbMsg.id, tbMsg.ts, tbMsg.type, tbMsg.originator, customerId, tbMsg.metaData, tbMsg.dataType,
|
||||||
|
tbMsg.data, tbMsg.ruleChainId, tbMsg.ruleNodeId, tbMsg.ruleNodeExecCounter.get(), tbMsg.getCallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TbMsg transformMsg(TbMsg tbMsg, RuleChainId ruleChainId) {
|
public static TbMsg transformMsg(TbMsg tbMsg, RuleChainId ruleChainId) {
|
||||||
return new TbMsg(tbMsg.queueName, tbMsg.id, tbMsg.ts, tbMsg.type, tbMsg.originator, tbMsg.metaData, tbMsg.dataType,
|
return new TbMsg(tbMsg.queueName, tbMsg.id, tbMsg.ts, tbMsg.type, tbMsg.originator, tbMsg.customerId, tbMsg.metaData, tbMsg.dataType,
|
||||||
tbMsg.data, ruleChainId, null, tbMsg.ruleNodeExecCounter.get(), tbMsg.getCallback());
|
tbMsg.data, ruleChainId, null, tbMsg.ruleNodeExecCounter.get(), tbMsg.getCallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TbMsg transformMsg(TbMsg tbMsg, String queueName) {
|
public static TbMsg transformMsg(TbMsg tbMsg, String queueName) {
|
||||||
return new TbMsg(queueName, tbMsg.id, tbMsg.ts, tbMsg.type, tbMsg.originator, tbMsg.metaData, tbMsg.dataType,
|
return new TbMsg(queueName, tbMsg.id, tbMsg.ts, tbMsg.type, tbMsg.originator, tbMsg.customerId, tbMsg.metaData, tbMsg.dataType,
|
||||||
tbMsg.data, tbMsg.getRuleChainId(), null, tbMsg.ruleNodeExecCounter.get(), tbMsg.getCallback());
|
tbMsg.data, tbMsg.getRuleChainId(), null, tbMsg.ruleNodeExecCounter.get(), tbMsg.getCallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TbMsg transformMsg(TbMsg tbMsg, RuleChainId ruleChainId, String queueName) {
|
public static TbMsg transformMsg(TbMsg tbMsg, RuleChainId ruleChainId, String queueName) {
|
||||||
return new TbMsg(queueName, tbMsg.id, tbMsg.ts, tbMsg.type, tbMsg.originator, tbMsg.metaData, tbMsg.dataType,
|
return new TbMsg(queueName, tbMsg.id, tbMsg.ts, tbMsg.type, tbMsg.originator, tbMsg.customerId, tbMsg.metaData, tbMsg.dataType,
|
||||||
tbMsg.data, ruleChainId, null, tbMsg.ruleNodeExecCounter.get(), tbMsg.getCallback());
|
tbMsg.data, ruleChainId, null, tbMsg.ruleNodeExecCounter.get(), tbMsg.getCallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TbMsg newMsg(TbMsg tbMsg, RuleChainId ruleChainId, RuleNodeId ruleNodeId) {
|
public static TbMsg newMsg(TbMsg tbMsg, RuleChainId ruleChainId, RuleNodeId ruleNodeId) {
|
||||||
return new TbMsg(tbMsg.getQueueName(), UUID.randomUUID(), tbMsg.getTs(), tbMsg.getType(), tbMsg.getOriginator(), tbMsg.getMetaData().copy(),
|
return new TbMsg(tbMsg.getQueueName(), UUID.randomUUID(), tbMsg.getTs(), tbMsg.getType(), tbMsg.getOriginator(), tbMsg.customerId, tbMsg.getMetaData().copy(),
|
||||||
tbMsg.getDataType(), tbMsg.getData(), ruleChainId, ruleNodeId, tbMsg.ruleNodeExecCounter.get(), TbMsgCallback.EMPTY);
|
tbMsg.getDataType(), tbMsg.getData(), ruleChainId, ruleNodeId, tbMsg.ruleNodeExecCounter.get(), TbMsgCallback.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TbMsg(String queueName, UUID id, long ts, String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data,
|
private TbMsg(String queueName, UUID id, long ts, String type, EntityId originator, CustomerId customerId, TbMsgMetaData metaData, TbMsgDataType dataType, String data,
|
||||||
RuleChainId ruleChainId, RuleNodeId ruleNodeId, int ruleNodeExecCounter, TbMsgCallback callback) {
|
RuleChainId ruleChainId, RuleNodeId ruleNodeId, int ruleNodeExecCounter, TbMsgCallback callback) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.queueName = queueName != null ? queueName : ServiceQueue.MAIN;
|
this.queueName = queueName != null ? queueName : ServiceQueue.MAIN;
|
||||||
@ -130,6 +145,7 @@ public final class TbMsg implements Serializable {
|
|||||||
}
|
}
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.originator = originator;
|
this.originator = originator;
|
||||||
|
this.customerId = (customerId == null || customerId.isNullUid()) ? null : customerId;
|
||||||
this.metaData = metaData;
|
this.metaData = metaData;
|
||||||
this.dataType = dataType;
|
this.dataType = dataType;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
@ -156,6 +172,11 @@ public final class TbMsg implements Serializable {
|
|||||||
builder.setEntityIdMSB(msg.getOriginator().getId().getMostSignificantBits());
|
builder.setEntityIdMSB(msg.getOriginator().getId().getMostSignificantBits());
|
||||||
builder.setEntityIdLSB(msg.getOriginator().getId().getLeastSignificantBits());
|
builder.setEntityIdLSB(msg.getOriginator().getId().getLeastSignificantBits());
|
||||||
|
|
||||||
|
if (msg.getCustomerId() != null) {
|
||||||
|
builder.setCustomerIdMSB(msg.getCustomerId().getId().getMostSignificantBits());
|
||||||
|
builder.setCustomerIdLSB(msg.getCustomerId().getId().getLeastSignificantBits());
|
||||||
|
}
|
||||||
|
|
||||||
if (msg.getRuleChainId() != null) {
|
if (msg.getRuleChainId() != null) {
|
||||||
builder.setRuleChainIdMSB(msg.getRuleChainId().getId().getMostSignificantBits());
|
builder.setRuleChainIdMSB(msg.getRuleChainId().getId().getMostSignificantBits());
|
||||||
builder.setRuleChainIdLSB(msg.getRuleChainId().getId().getLeastSignificantBits());
|
builder.setRuleChainIdLSB(msg.getRuleChainId().getId().getLeastSignificantBits());
|
||||||
@ -181,16 +202,21 @@ public final class TbMsg implements Serializable {
|
|||||||
MsgProtos.TbMsgProto proto = MsgProtos.TbMsgProto.parseFrom(data);
|
MsgProtos.TbMsgProto proto = MsgProtos.TbMsgProto.parseFrom(data);
|
||||||
TbMsgMetaData metaData = new TbMsgMetaData(proto.getMetaData().getDataMap());
|
TbMsgMetaData metaData = new TbMsgMetaData(proto.getMetaData().getDataMap());
|
||||||
EntityId entityId = EntityIdFactory.getByTypeAndUuid(proto.getEntityType(), new UUID(proto.getEntityIdMSB(), proto.getEntityIdLSB()));
|
EntityId entityId = EntityIdFactory.getByTypeAndUuid(proto.getEntityType(), new UUID(proto.getEntityIdMSB(), proto.getEntityIdLSB()));
|
||||||
|
CustomerId customerId = null;
|
||||||
RuleChainId ruleChainId = null;
|
RuleChainId ruleChainId = null;
|
||||||
RuleNodeId ruleNodeId = null;
|
RuleNodeId ruleNodeId = null;
|
||||||
|
if (proto.getCustomerIdMSB() != 0L && proto.getCustomerIdLSB() != 0L) {
|
||||||
|
customerId = new CustomerId(new UUID(proto.getCustomerIdMSB(), proto.getCustomerIdLSB()));
|
||||||
|
}
|
||||||
if (proto.getRuleChainIdMSB() != 0L && proto.getRuleChainIdLSB() != 0L) {
|
if (proto.getRuleChainIdMSB() != 0L && proto.getRuleChainIdLSB() != 0L) {
|
||||||
ruleChainId = new RuleChainId(new UUID(proto.getRuleChainIdMSB(), proto.getRuleChainIdLSB()));
|
ruleChainId = new RuleChainId(new UUID(proto.getRuleChainIdMSB(), proto.getRuleChainIdLSB()));
|
||||||
}
|
}
|
||||||
if (proto.getRuleNodeIdMSB() != 0L && proto.getRuleNodeIdLSB() != 0L) {
|
if (proto.getRuleNodeIdMSB() != 0L && proto.getRuleNodeIdLSB() != 0L) {
|
||||||
ruleNodeId = new RuleNodeId(new UUID(proto.getRuleNodeIdMSB(), proto.getRuleNodeIdLSB()));
|
ruleNodeId = new RuleNodeId(new UUID(proto.getRuleNodeIdMSB(), proto.getRuleNodeIdLSB()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TbMsgDataType dataType = TbMsgDataType.values()[proto.getDataType()];
|
TbMsgDataType dataType = TbMsgDataType.values()[proto.getDataType()];
|
||||||
return new TbMsg(queueName, UUID.fromString(proto.getId()), proto.getTs(), proto.getType(), entityId, metaData, dataType, proto.getData(), ruleChainId, ruleNodeId, proto.getRuleNodeExecCounter(), callback);
|
return new TbMsg(queueName, UUID.fromString(proto.getId()), proto.getTs(), proto.getType(), entityId, customerId, metaData, dataType, proto.getData(), ruleChainId, ruleNodeId, proto.getRuleNodeExecCounter(), callback);
|
||||||
} catch (InvalidProtocolBufferException e) {
|
} catch (InvalidProtocolBufferException e) {
|
||||||
throw new IllegalStateException("Could not parse protobuf for TbMsg", e);
|
throw new IllegalStateException("Could not parse protobuf for TbMsg", e);
|
||||||
}
|
}
|
||||||
@ -201,11 +227,11 @@ public final class TbMsg implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TbMsg copyWithRuleChainId(RuleChainId ruleChainId, UUID msgId) {
|
public TbMsg copyWithRuleChainId(RuleChainId ruleChainId, UUID msgId) {
|
||||||
return new TbMsg(this.queueName, msgId, this.ts, this.type, this.originator, this.metaData, this.dataType, this.data, ruleChainId, null, this.ruleNodeExecCounter.get(), callback);
|
return new TbMsg(this.queueName, msgId, this.ts, this.type, this.originator, this.customerId, this.metaData, this.dataType, this.data, ruleChainId, null, this.ruleNodeExecCounter.get(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TbMsg copyWithRuleNodeId(RuleChainId ruleChainId, RuleNodeId ruleNodeId, UUID msgId) {
|
public TbMsg copyWithRuleNodeId(RuleChainId ruleChainId, RuleNodeId ruleNodeId, UUID msgId) {
|
||||||
return new TbMsg(this.queueName, msgId, this.ts, this.type, this.originator, this.metaData, this.dataType, this.data, ruleChainId, ruleNodeId, this.ruleNodeExecCounter.get(), callback);
|
return new TbMsg(this.queueName, msgId, this.ts, this.type, this.originator, this.customerId, this.metaData, this.dataType, this.data, ruleChainId, ruleNodeId, this.ruleNodeExecCounter.get(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TbMsgCallback getCallback() {
|
public TbMsgCallback getCallback() {
|
||||||
|
|||||||
@ -46,4 +46,7 @@ message TbMsgProto {
|
|||||||
|
|
||||||
int64 ts = 15;
|
int64 ts = 15;
|
||||||
int32 ruleNodeExecCounter = 16;
|
int32 ruleNodeExecCounter = 16;
|
||||||
|
|
||||||
|
int64 customerIdMSB = 17;
|
||||||
|
int64 customerIdLSB = 18;
|
||||||
}
|
}
|
||||||
@ -409,15 +409,15 @@ public class DefaultTransportService implements TransportService {
|
|||||||
reportActivityInternal(sessionInfo);
|
reportActivityInternal(sessionInfo);
|
||||||
TenantId tenantId = getTenantId(sessionInfo);
|
TenantId tenantId = getTenantId(sessionInfo);
|
||||||
DeviceId deviceId = new DeviceId(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
|
DeviceId deviceId = new DeviceId(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
|
||||||
MsgPackCallback packCallback = new MsgPackCallback(msg.getTsKvListCount(), new ApiStatsProxyCallback<>(tenantId, getCustomerId(sessionInfo), dataPoints, callback));
|
CustomerId customerId = getCustomerId(sessionInfo);
|
||||||
|
MsgPackCallback packCallback = new MsgPackCallback(msg.getTsKvListCount(), new ApiStatsProxyCallback<>(tenantId, customerId, dataPoints, callback));
|
||||||
for (TransportProtos.TsKvListProto tsKv : msg.getTsKvListList()) {
|
for (TransportProtos.TsKvListProto tsKv : msg.getTsKvListList()) {
|
||||||
TbMsgMetaData metaData = new TbMsgMetaData();
|
TbMsgMetaData metaData = new TbMsgMetaData();
|
||||||
metaData.putValue("deviceName", sessionInfo.getDeviceName());
|
metaData.putValue("deviceName", sessionInfo.getDeviceName());
|
||||||
metaData.putValue("deviceType", sessionInfo.getDeviceType());
|
metaData.putValue("deviceType", sessionInfo.getDeviceType());
|
||||||
metaData.putValue("ts", tsKv.getTs() + "");
|
metaData.putValue("ts", tsKv.getTs() + "");
|
||||||
JsonObject json = JsonUtils.getJsonObject(tsKv.getKvList());
|
JsonObject json = JsonUtils.getJsonObject(tsKv.getKvList());
|
||||||
sendToRuleEngine(tenantId, deviceId, sessionInfo, json, metaData, SessionMsgType.POST_TELEMETRY_REQUEST, packCallback);
|
sendToRuleEngine(tenantId, deviceId, customerId, sessionInfo, json, metaData, SessionMsgType.POST_TELEMETRY_REQUEST, packCallback);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -433,8 +433,9 @@ public class DefaultTransportService implements TransportService {
|
|||||||
metaData.putValue("deviceName", sessionInfo.getDeviceName());
|
metaData.putValue("deviceName", sessionInfo.getDeviceName());
|
||||||
metaData.putValue("deviceType", sessionInfo.getDeviceType());
|
metaData.putValue("deviceType", sessionInfo.getDeviceType());
|
||||||
metaData.putValue("notifyDevice", "false");
|
metaData.putValue("notifyDevice", "false");
|
||||||
sendToRuleEngine(tenantId, deviceId, sessionInfo, json, metaData, SessionMsgType.POST_ATTRIBUTES_REQUEST,
|
CustomerId customerId = getCustomerId(sessionInfo);
|
||||||
new TransportTbQueueCallback(new ApiStatsProxyCallback<>(tenantId, getCustomerId(sessionInfo), msg.getKvList().size(), callback)));
|
sendToRuleEngine(tenantId, deviceId, customerId, sessionInfo, json, metaData, SessionMsgType.POST_ATTRIBUTES_REQUEST,
|
||||||
|
new TransportTbQueueCallback(new ApiStatsProxyCallback<>(tenantId, customerId, msg.getKvList().size(), callback)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,7 +516,7 @@ public class DefaultTransportService implements TransportService {
|
|||||||
metaData.putValue("requestId", Integer.toString(msg.getRequestId()));
|
metaData.putValue("requestId", Integer.toString(msg.getRequestId()));
|
||||||
metaData.putValue("serviceId", serviceInfoProvider.getServiceId());
|
metaData.putValue("serviceId", serviceInfoProvider.getServiceId());
|
||||||
metaData.putValue("sessionId", sessionId.toString());
|
metaData.putValue("sessionId", sessionId.toString());
|
||||||
sendToRuleEngine(tenantId, deviceId, sessionInfo, json, metaData,
|
sendToRuleEngine(tenantId, deviceId, getCustomerId(sessionInfo), sessionInfo, json, metaData,
|
||||||
SessionMsgType.TO_SERVER_RPC_REQUEST, new TransportTbQueueCallback(callback));
|
SessionMsgType.TO_SERVER_RPC_REQUEST, new TransportTbQueueCallback(callback));
|
||||||
String requestId = sessionId + "-" + msg.getRequestId();
|
String requestId = sessionId + "-" + msg.getRequestId();
|
||||||
toServerRpcPendingMap.put(requestId, new RpcRequestMetadata(sessionId, msg.getRequestId()));
|
toServerRpcPendingMap.put(requestId, new RpcRequestMetadata(sessionId, msg.getRequestId()));
|
||||||
@ -848,7 +849,7 @@ public class DefaultTransportService implements TransportService {
|
|||||||
ruleEngineMsgProducer.send(tpi, new TbProtoQueueMsg<>(tbMsg.getId(), msg), wrappedCallback);
|
ruleEngineMsgProducer.send(tpi, new TbProtoQueueMsg<>(tbMsg.getId(), msg), wrappedCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendToRuleEngine(TenantId tenantId, DeviceId deviceId, TransportProtos.SessionInfoProto sessionInfo, JsonObject json,
|
private void sendToRuleEngine(TenantId tenantId, DeviceId deviceId, CustomerId customerId, TransportProtos.SessionInfoProto sessionInfo, JsonObject json,
|
||||||
TbMsgMetaData metaData, SessionMsgType sessionMsgType, TbQueueCallback callback) {
|
TbMsgMetaData metaData, SessionMsgType sessionMsgType, TbQueueCallback callback) {
|
||||||
DeviceProfileId deviceProfileId = new DeviceProfileId(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
|
DeviceProfileId deviceProfileId = new DeviceProfileId(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
|
||||||
DeviceProfile deviceProfile = deviceProfileCache.get(deviceProfileId);
|
DeviceProfile deviceProfile = deviceProfileCache.get(deviceProfileId);
|
||||||
@ -865,7 +866,7 @@ public class DefaultTransportService implements TransportService {
|
|||||||
queueName = defaultQueueName != null ? defaultQueueName : ServiceQueue.MAIN;
|
queueName = defaultQueueName != null ? defaultQueueName : ServiceQueue.MAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
TbMsg tbMsg = TbMsg.newMsg(queueName, sessionMsgType.name(), deviceId, metaData, gson.toJson(json), ruleChainId, null);
|
TbMsg tbMsg = TbMsg.newMsg(queueName, sessionMsgType.name(), deviceId, customerId, metaData, gson.toJson(json), ruleChainId, null);
|
||||||
sendToRuleEngine(tenantId, tbMsg, callback);
|
sendToRuleEngine(tenantId, tbMsg, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user