Send alarm_ack and alarm_clear only by 'Push to Edge' node
This commit is contained in:
		
							parent
							
								
									e20461113f
								
							
						
					
					
						commit
						d9dad36c54
					
				@ -135,6 +135,9 @@ public class EdgeEventSourcingListener {
 | 
				
			|||||||
        if (EntityType.DEVICE.equals(event.getEntityId().getEntityType()) && ActionType.ASSIGNED_TO_TENANT.equals(event.getActionType())) {
 | 
					        if (EntityType.DEVICE.equals(event.getEntityId().getEntityType()) && ActionType.ASSIGNED_TO_TENANT.equals(event.getActionType())) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        if (EntityType.ALARM.equals(event.getEntityId().getEntityType())) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            if (event.getEntityId().getEntityType().equals(EntityType.RULE_CHAIN) && event.getEdgeId() != null && event.getActionType().equals(ActionType.ASSIGNED_TO_EDGE)) {
 | 
					            if (event.getEntityId().getEntityType().equals(EntityType.RULE_CHAIN) && event.getEdgeId() != null && event.getActionType().equals(ActionType.ASSIGNED_TO_EDGE)) {
 | 
				
			||||||
                try {
 | 
					                try {
 | 
				
			||||||
 | 
				
			|||||||
@ -94,44 +94,26 @@ public class AlarmEdgeTest extends AbstractEdgeTest {
 | 
				
			|||||||
        Alarm savedAlarm = doPost("/api/alarm", alarm, Alarm.class);
 | 
					        Alarm savedAlarm = doPost("/api/alarm", alarm, Alarm.class);
 | 
				
			||||||
        edgeImitator.ignoreType(AlarmCommentUpdateMsg.class);
 | 
					        edgeImitator.ignoreType(AlarmCommentUpdateMsg.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // ack alarm
 | 
					        // ack alarm - send only by using push to edge node
 | 
				
			||||||
        edgeImitator.expectMessageAmount(1);
 | 
					        edgeImitator.expectMessageAmount(1);
 | 
				
			||||||
        doPost("/api/alarm/" + savedAlarm.getUuidId() + "/ack");
 | 
					        doPost("/api/alarm/" + savedAlarm.getUuidId() + "/ack");
 | 
				
			||||||
        Assert.assertTrue(edgeImitator.waitForMessages());
 | 
					        Assert.assertFalse(edgeImitator.waitForMessages(5));
 | 
				
			||||||
        AbstractMessage latestMessage = edgeImitator.getLatestMessage();
 | 
					 | 
				
			||||||
        Assert.assertTrue(latestMessage instanceof AlarmUpdateMsg);
 | 
					 | 
				
			||||||
        AlarmUpdateMsg alarmUpdateMsg = (AlarmUpdateMsg) latestMessage;
 | 
					 | 
				
			||||||
        Assert.assertEquals(UpdateMsgType.ALARM_ACK_RPC_MESSAGE, alarmUpdateMsg.getMsgType());
 | 
					 | 
				
			||||||
        Alarm alarmMsg = JacksonUtil.fromString(alarmUpdateMsg.getEntity(), Alarm.class, true);
 | 
					 | 
				
			||||||
        Assert.assertNotNull(alarmMsg);
 | 
					 | 
				
			||||||
        Assert.assertEquals(savedAlarm.getType(), alarmMsg.getType());
 | 
					 | 
				
			||||||
        Assert.assertEquals(savedAlarm.getName(), alarmMsg.getName());
 | 
					 | 
				
			||||||
        Assert.assertEquals(AlarmStatus.ACTIVE_ACK, alarmMsg.getStatus());
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // clear alarm
 | 
					        // clear alarm - send only by using push to edge node
 | 
				
			||||||
        edgeImitator.expectMessageAmount(1);
 | 
					        edgeImitator.expectMessageAmount(1);
 | 
				
			||||||
        doPost("/api/alarm/" + savedAlarm.getUuidId() + "/clear");
 | 
					        doPost("/api/alarm/" + savedAlarm.getUuidId() + "/clear");
 | 
				
			||||||
        Assert.assertTrue(edgeImitator.waitForMessages());
 | 
					        Assert.assertFalse(edgeImitator.waitForMessages(5));
 | 
				
			||||||
        latestMessage = edgeImitator.getLatestMessage();
 | 
					 | 
				
			||||||
        Assert.assertTrue(latestMessage instanceof AlarmUpdateMsg);
 | 
					 | 
				
			||||||
        alarmUpdateMsg = (AlarmUpdateMsg) latestMessage;
 | 
					 | 
				
			||||||
        Assert.assertEquals(UpdateMsgType.ALARM_CLEAR_RPC_MESSAGE, alarmUpdateMsg.getMsgType());
 | 
					 | 
				
			||||||
        alarmMsg = JacksonUtil.fromString(alarmUpdateMsg.getEntity(), Alarm.class, true);
 | 
					 | 
				
			||||||
        Assert.assertNotNull(alarmMsg);
 | 
					 | 
				
			||||||
        Assert.assertEquals(savedAlarm.getType(), alarmMsg.getType());
 | 
					 | 
				
			||||||
        Assert.assertEquals(savedAlarm.getName(), alarmMsg.getName());
 | 
					 | 
				
			||||||
        Assert.assertEquals(AlarmStatus.CLEARED_ACK, alarmMsg.getStatus());
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // delete alarm
 | 
					        // delete alarm
 | 
				
			||||||
        edgeImitator.expectMessageAmount(1);
 | 
					        edgeImitator.expectMessageAmount(1);
 | 
				
			||||||
        doDelete("/api/alarm/" + savedAlarm.getUuidId())
 | 
					        doDelete("/api/alarm/" + savedAlarm.getUuidId())
 | 
				
			||||||
                .andExpect(status().isOk());
 | 
					                .andExpect(status().isOk());
 | 
				
			||||||
        Assert.assertTrue(edgeImitator.waitForMessages());
 | 
					        Assert.assertTrue(edgeImitator.waitForMessages());
 | 
				
			||||||
        latestMessage = edgeImitator.getLatestMessage();
 | 
					        AbstractMessage latestMessage = edgeImitator.getLatestMessage();
 | 
				
			||||||
        Assert.assertTrue(latestMessage instanceof AlarmUpdateMsg);
 | 
					        Assert.assertTrue(latestMessage instanceof AlarmUpdateMsg);
 | 
				
			||||||
        alarmUpdateMsg = (AlarmUpdateMsg) latestMessage;
 | 
					        AlarmUpdateMsg alarmUpdateMsg = (AlarmUpdateMsg) latestMessage;
 | 
				
			||||||
        Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, alarmUpdateMsg.getMsgType());
 | 
					        Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, alarmUpdateMsg.getMsgType());
 | 
				
			||||||
        alarmMsg = JacksonUtil.fromString(alarmUpdateMsg.getEntity(), Alarm.class, true);
 | 
					        Alarm alarmMsg = JacksonUtil.fromString(alarmUpdateMsg.getEntity(), Alarm.class, true);
 | 
				
			||||||
        Assert.assertNotNull(alarmMsg);
 | 
					        Assert.assertNotNull(alarmMsg);
 | 
				
			||||||
        Assert.assertEquals(savedAlarm.getType(), alarmMsg.getType());
 | 
					        Assert.assertEquals(savedAlarm.getType(), alarmMsg.getType());
 | 
				
			||||||
        Assert.assertEquals(savedAlarm.getName(), alarmMsg.getName());
 | 
					        Assert.assertEquals(savedAlarm.getName(), alarmMsg.getName());
 | 
				
			||||||
@ -252,4 +234,5 @@ public class AlarmEdgeTest extends AbstractEdgeTest {
 | 
				
			|||||||
        alarmComment.setCreatedTime(Uuids.unixTimestamp(uuid));
 | 
					        alarmComment.setCreatedTime(Uuids.unixTimestamp(uuid));
 | 
				
			||||||
        return alarmComment;
 | 
					        return alarmComment;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -39,6 +39,8 @@ import java.util.UUID;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import static org.thingsboard.server.common.data.msg.TbMsgType.ACTIVITY_EVENT;
 | 
					import static org.thingsboard.server.common.data.msg.TbMsgType.ACTIVITY_EVENT;
 | 
				
			||||||
import static org.thingsboard.server.common.data.msg.TbMsgType.ALARM;
 | 
					import static org.thingsboard.server.common.data.msg.TbMsgType.ALARM;
 | 
				
			||||||
 | 
					import static org.thingsboard.server.common.data.msg.TbMsgType.ALARM_ACK;
 | 
				
			||||||
 | 
					import static org.thingsboard.server.common.data.msg.TbMsgType.ALARM_CLEAR;
 | 
				
			||||||
import static org.thingsboard.server.common.data.msg.TbMsgType.ATTRIBUTES_DELETED;
 | 
					import static org.thingsboard.server.common.data.msg.TbMsgType.ATTRIBUTES_DELETED;
 | 
				
			||||||
import static org.thingsboard.server.common.data.msg.TbMsgType.ATTRIBUTES_UPDATED;
 | 
					import static org.thingsboard.server.common.data.msg.TbMsgType.ATTRIBUTES_UPDATED;
 | 
				
			||||||
import static org.thingsboard.server.common.data.msg.TbMsgType.CONNECT_EVENT;
 | 
					import static org.thingsboard.server.common.data.msg.TbMsgType.CONNECT_EVENT;
 | 
				
			||||||
@ -81,6 +83,9 @@ public abstract class AbstractTbMsgPushNode<T extends BaseTbMsgPushNodeConfigura
 | 
				
			|||||||
        if (msg.isTypeOf(ALARM)) {
 | 
					        if (msg.isTypeOf(ALARM)) {
 | 
				
			||||||
            EdgeEventActionType actionType = getAlarmActionType(msg);
 | 
					            EdgeEventActionType actionType = getAlarmActionType(msg);
 | 
				
			||||||
            return buildEvent(ctx.getTenantId(), actionType, getUUIDFromMsgData(msg), getAlarmEventType(), null);
 | 
					            return buildEvent(ctx.getTenantId(), actionType, getUUIDFromMsgData(msg), getAlarmEventType(), null);
 | 
				
			||||||
 | 
					        } else if (msg.isTypeOneOf(ALARM_ACK, ALARM_CLEAR)) {
 | 
				
			||||||
 | 
					            EdgeEventActionType actionType = EdgeEventActionType.valueOf(msg.getType());
 | 
				
			||||||
 | 
					            return buildEvent(ctx.getTenantId(), actionType, getUUIDFromMsgData(msg), getAlarmEventType(), null);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            Map<String, String> metadata = msg.getMetaData().getData();
 | 
					            Map<String, String> metadata = msg.getMetaData().getData();
 | 
				
			||||||
            EdgeEventActionType actionType = getEdgeEventActionTypeByMsgType(msg);
 | 
					            EdgeEventActionType actionType = getEdgeEventActionTypeByMsgType(msg);
 | 
				
			||||||
@ -164,8 +169,9 @@ public abstract class AbstractTbMsgPushNode<T extends BaseTbMsgPushNodeConfigura
 | 
				
			|||||||
            actionType = EdgeEventActionType.ATTRIBUTES_DELETED;
 | 
					            actionType = EdgeEventActionType.ATTRIBUTES_DELETED;
 | 
				
			||||||
        } else if (msg.isTypeOneOf(CONNECT_EVENT, DISCONNECT_EVENT, ACTIVITY_EVENT, INACTIVITY_EVENT)) {
 | 
					        } else if (msg.isTypeOneOf(CONNECT_EVENT, DISCONNECT_EVENT, ACTIVITY_EVENT, INACTIVITY_EVENT)) {
 | 
				
			||||||
            String scope = msg.getMetaData().getValue(SCOPE);
 | 
					            String scope = msg.getMetaData().getValue(SCOPE);
 | 
				
			||||||
            actionType = StringUtils.isEmpty(scope) ?
 | 
					            actionType = StringUtils.isEmpty(scope) ? EdgeEventActionType.TIMESERIES_UPDATED : EdgeEventActionType.ATTRIBUTES_UPDATED;
 | 
				
			||||||
                    EdgeEventActionType.TIMESERIES_UPDATED : EdgeEventActionType.ATTRIBUTES_UPDATED;
 | 
					        } else if (msg.isTypeOneOf(ALARM_ACK, ALARM_CLEAR)) {
 | 
				
			||||||
 | 
					            actionType = EdgeEventActionType.valueOf(msg.getType());
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            String type = msg.getType();
 | 
					            String type = msg.getType();
 | 
				
			||||||
            log.warn("Unsupported msg type [{}]", type);
 | 
					            log.warn("Unsupported msg type [{}]", type);
 | 
				
			||||||
@ -176,7 +182,7 @@ public abstract class AbstractTbMsgPushNode<T extends BaseTbMsgPushNodeConfigura
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected boolean isSupportedMsgType(TbMsg msg) {
 | 
					    protected boolean isSupportedMsgType(TbMsg msg) {
 | 
				
			||||||
        return msg.isTypeOneOf(POST_TELEMETRY_REQUEST, POST_ATTRIBUTES_REQUEST, ATTRIBUTES_UPDATED, ATTRIBUTES_DELETED, TIMESERIES_UPDATED,
 | 
					        return msg.isTypeOneOf(POST_TELEMETRY_REQUEST, POST_ATTRIBUTES_REQUEST, ATTRIBUTES_UPDATED, ATTRIBUTES_DELETED, TIMESERIES_UPDATED,
 | 
				
			||||||
                ALARM, CONNECT_EVENT, DISCONNECT_EVENT, ACTIVITY_EVENT, INACTIVITY_EVENT, TO_SERVER_RPC_REQUEST);
 | 
					                ALARM, ALARM_ACK, ALARM_CLEAR, CONNECT_EVENT, DISCONNECT_EVENT, ACTIVITY_EVENT, INACTIVITY_EVENT, TO_SERVER_RPC_REQUEST);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user