Search in sources :

Example 16 with DeviceProfileAlarm

use of org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm in project thingsboard by thingsboard.

the class TbDeviceProfileNodeTest method testConstantKeyFilterSimple.

@Test
public void testConstantKeyFilterSimple() throws Exception {
    init();
    DeviceProfile deviceProfile = new DeviceProfile();
    deviceProfile.setId(deviceProfileId);
    DeviceProfileData deviceProfileData = new DeviceProfileData();
    Device device = new Device();
    device.setId(deviceId);
    device.setCustomerId(customerId);
    AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey(EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "alarmEnabled");
    AttributeKvEntity attributeKvEntity = new AttributeKvEntity();
    attributeKvEntity.setId(compositeKey);
    attributeKvEntity.setBooleanValue(Boolean.TRUE);
    attributeKvEntity.setLastUpdateTs(System.currentTimeMillis());
    AttributeKvEntry entry = attributeKvEntity.toData();
    ListenableFuture<List<AttributeKvEntry>> attrListListenableFuture = Futures.immediateFuture(Collections.singletonList(entry));
    AlarmConditionFilter alarmEnabledFilter = new AlarmConditionFilter();
    alarmEnabledFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.CONSTANT, "alarmEnabled"));
    alarmEnabledFilter.setValue(Boolean.TRUE);
    alarmEnabledFilter.setValueType(EntityKeyValueType.BOOLEAN);
    BooleanFilterPredicate alarmEnabledPredicate = new BooleanFilterPredicate();
    alarmEnabledPredicate.setOperation(BooleanFilterPredicate.BooleanOperation.EQUAL);
    alarmEnabledPredicate.setValue(new FilterPredicateValue<>(Boolean.FALSE, null, new DynamicValue<>(DynamicValueSourceType.CURRENT_DEVICE, "alarmEnabled")));
    alarmEnabledFilter.setPredicate(alarmEnabledPredicate);
    AlarmConditionFilter temperatureFilter = new AlarmConditionFilter();
    temperatureFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.TIME_SERIES, "temperature"));
    temperatureFilter.setValueType(EntityKeyValueType.NUMERIC);
    NumericFilterPredicate temperaturePredicate = new NumericFilterPredicate();
    temperaturePredicate.setOperation(NumericFilterPredicate.NumericOperation.GREATER);
    temperaturePredicate.setValue(new FilterPredicateValue<>(20.0, null, null));
    temperatureFilter.setPredicate(temperaturePredicate);
    AlarmCondition alarmCondition = new AlarmCondition();
    alarmCondition.setCondition(Arrays.asList(alarmEnabledFilter, temperatureFilter));
    AlarmRule alarmRule = new AlarmRule();
    alarmRule.setCondition(alarmCondition);
    DeviceProfileAlarm dpa = new DeviceProfileAlarm();
    dpa.setId("alarmEnabledAlarmID");
    dpa.setAlarmType("alarmEnabledAlarm");
    dpa.setCreateRules(new TreeMap<>(Collections.singletonMap(AlarmSeverity.CRITICAL, alarmRule)));
    deviceProfileData.setAlarms(Collections.singletonList(dpa));
    deviceProfile.setProfileData(deviceProfileData);
    Mockito.when(cache.get(tenantId, deviceId)).thenReturn(deviceProfile);
    Mockito.when(timeseriesService.findLatest(tenantId, deviceId, Collections.singleton("temperature"))).thenReturn(Futures.immediateFuture(Collections.emptyList()));
    Mockito.when(alarmService.findLatestByOriginatorAndType(tenantId, deviceId, "alarmEnabledAlarm")).thenReturn(Futures.immediateFuture(null));
    Mockito.when(alarmService.createOrUpdateAlarm(Mockito.any())).thenAnswer(AdditionalAnswers.returnsFirstArg());
    Mockito.when(ctx.getAttributesService()).thenReturn(attributesService);
    Mockito.when(attributesService.find(eq(tenantId), eq(deviceId), Mockito.anyString(), Mockito.anySet())).thenReturn(attrListListenableFuture);
    TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), "");
    Mockito.when(ctx.newMsg(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn(theMsg);
    ObjectNode data = mapper.createObjectNode();
    data.put("temperature", 21);
    TbMsg msg = TbMsg.newMsg(SessionMsgType.POST_TELEMETRY_REQUEST.name(), deviceId, new TbMsgMetaData(), TbMsgDataType.JSON, mapper.writeValueAsString(data), null, null);
    node.onMsg(ctx, msg);
    verify(ctx).tellSuccess(msg);
    verify(ctx).enqueueForTellNext(theMsg, "Alarm Created");
    verify(ctx, Mockito.never()).tellFailure(Mockito.any(), Mockito.any());
}
Also used : BooleanFilterPredicate(org.thingsboard.server.common.data.query.BooleanFilterPredicate) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AttributeKvEntity(org.thingsboard.server.dao.model.sql.AttributeKvEntity) NumericFilterPredicate(org.thingsboard.server.common.data.query.NumericFilterPredicate) Device(org.thingsboard.server.common.data.Device) AlarmRule(org.thingsboard.server.common.data.device.profile.AlarmRule) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) AlarmConditionFilter(org.thingsboard.server.common.data.device.profile.AlarmConditionFilter) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) AlarmCondition(org.thingsboard.server.common.data.device.profile.AlarmCondition) DeviceProfileAlarm(org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm) List(java.util.List) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) AlarmConditionFilterKey(org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey) AttributeKvCompositeKey(org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey) DynamicValue(org.thingsboard.server.common.data.query.DynamicValue) TbMsg(org.thingsboard.server.common.msg.TbMsg) Test(org.junit.Test)

Example 17 with DeviceProfileAlarm

use of org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm in project thingsboard by thingsboard.

the class TbDeviceProfileNodeTest method testInheritTenantAttributeForDuration.

@Test
public void testInheritTenantAttributeForDuration() throws Exception {
    init();
    DeviceProfile deviceProfile = new DeviceProfile();
    deviceProfile.setId(deviceProfileId);
    DeviceProfileData deviceProfileData = new DeviceProfileData();
    Device device = new Device();
    device.setId(deviceId);
    device.setCustomerId(customerId);
    AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey(EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "greaterAttribute");
    AttributeKvEntity attributeKvEntity = new AttributeKvEntity();
    attributeKvEntity.setId(compositeKey);
    attributeKvEntity.setLongValue(30L);
    attributeKvEntity.setLastUpdateTs(0L);
    AttributeKvCompositeKey alarmDelayCompositeKey = new AttributeKvCompositeKey(EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "alarm_delay");
    AttributeKvEntity alarmDelayAttributeKvEntity = new AttributeKvEntity();
    alarmDelayAttributeKvEntity.setId(alarmDelayCompositeKey);
    long alarmDelayInSeconds = 5L;
    alarmDelayAttributeKvEntity.setLongValue(alarmDelayInSeconds);
    alarmDelayAttributeKvEntity.setLastUpdateTs(0L);
    AttributeKvEntry entry = attributeKvEntity.toData();
    AttributeKvEntry alarmDelayAttributeKvEntry = alarmDelayAttributeKvEntity.toData();
    ListenableFuture<Optional<AttributeKvEntry>> optionalDurationAttribute = Futures.immediateFuture(Optional.of(alarmDelayAttributeKvEntry));
    ListenableFuture<List<AttributeKvEntry>> listNoDurationAttribute = Futures.immediateFuture(Collections.singletonList(entry));
    ListenableFuture<Optional<AttributeKvEntry>> emptyOptional = Futures.immediateFuture(Optional.empty());
    AlarmConditionFilter highTempFilter = new AlarmConditionFilter();
    highTempFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.TIME_SERIES, "temperature"));
    highTempFilter.setValueType(EntityKeyValueType.NUMERIC);
    NumericFilterPredicate highTemperaturePredicate = new NumericFilterPredicate();
    highTemperaturePredicate.setOperation(NumericFilterPredicate.NumericOperation.GREATER);
    highTemperaturePredicate.setValue(new FilterPredicateValue<>(0.0, null, new DynamicValue<>(DynamicValueSourceType.CURRENT_DEVICE, "greaterAttribute", false)));
    highTempFilter.setPredicate(highTemperaturePredicate);
    AlarmCondition alarmCondition = new AlarmCondition();
    alarmCondition.setCondition(Collections.singletonList(highTempFilter));
    FilterPredicateValue<Long> filterPredicateValue = new FilterPredicateValue<>(10L, null, new DynamicValue<>(DynamicValueSourceType.CURRENT_DEVICE, "alarm_delay", true));
    DurationAlarmConditionSpec durationSpec = new DurationAlarmConditionSpec();
    durationSpec.setUnit(TimeUnit.SECONDS);
    durationSpec.setPredicate(filterPredicateValue);
    alarmCondition.setSpec(durationSpec);
    AlarmRule alarmRule = new AlarmRule();
    alarmRule.setCondition(alarmCondition);
    DeviceProfileAlarm dpa = new DeviceProfileAlarm();
    dpa.setId("highTemperatureAlarmID");
    dpa.setAlarmType("highTemperatureAlarm");
    dpa.setCreateRules(new TreeMap<>(Collections.singletonMap(AlarmSeverity.CRITICAL, alarmRule)));
    deviceProfileData.setAlarms(Collections.singletonList(dpa));
    deviceProfile.setProfileData(deviceProfileData);
    Mockito.when(cache.get(tenantId, deviceId)).thenReturn(deviceProfile);
    Mockito.when(timeseriesService.findLatest(tenantId, deviceId, Collections.singleton("temperature"))).thenReturn(Futures.immediateFuture(Collections.emptyList()));
    Mockito.when(alarmService.findLatestByOriginatorAndType(tenantId, deviceId, "highTemperatureAlarm")).thenReturn(Futures.immediateFuture(null));
    Mockito.when(alarmService.createOrUpdateAlarm(Mockito.any())).thenAnswer(AdditionalAnswers.returnsFirstArg());
    Mockito.when(ctx.getAttributesService()).thenReturn(attributesService);
    Mockito.when(attributesService.find(eq(tenantId), eq(tenantId), Mockito.anyString(), Mockito.anyString())).thenReturn(optionalDurationAttribute);
    Mockito.when(ctx.getDeviceService().findDeviceById(tenantId, deviceId)).thenReturn(device);
    Mockito.when(attributesService.find(eq(tenantId), eq(customerId), eq(DataConstants.SERVER_SCOPE), Mockito.anyString())).thenReturn(emptyOptional);
    Mockito.when(attributesService.find(eq(tenantId), eq(deviceId), Mockito.anyString(), Mockito.anySet())).thenReturn(listNoDurationAttribute);
    TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), "");
    Mockito.when(ctx.newMsg(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn(theMsg);
    ObjectNode data = mapper.createObjectNode();
    data.put("temperature", 150);
    TbMsg msg = TbMsg.newMsg(SessionMsgType.POST_TELEMETRY_REQUEST.name(), deviceId, new TbMsgMetaData(), TbMsgDataType.JSON, mapper.writeValueAsString(data), null, null);
    node.onMsg(ctx, msg);
    verify(ctx).tellSuccess(msg);
    int halfOfAlarmDelay = new BigDecimal(alarmDelayInSeconds).multiply(BigDecimal.valueOf(1000)).divide(BigDecimal.valueOf(2), 3, RoundingMode.HALF_EVEN).intValueExact();
    Thread.sleep(halfOfAlarmDelay);
    verify(ctx, Mockito.never()).tellNext(theMsg, "Alarm Created");
    Thread.sleep(halfOfAlarmDelay);
    TbMsg msg2 = TbMsg.newMsg(SessionMsgType.POST_TELEMETRY_REQUEST.name(), deviceId, new TbMsgMetaData(), TbMsgDataType.JSON, mapper.writeValueAsString(data), null, null);
    node.onMsg(ctx, msg2);
    verify(ctx).tellSuccess(msg2);
    verify(ctx).enqueueForTellNext(theMsg, "Alarm Created");
    verify(ctx, Mockito.never()).tellFailure(Mockito.any(), Mockito.any());
}
Also used : AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) AttributeKvEntity(org.thingsboard.server.dao.model.sql.AttributeKvEntity) AlarmRule(org.thingsboard.server.common.data.device.profile.AlarmRule) FilterPredicateValue(org.thingsboard.server.common.data.query.FilterPredicateValue) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) List(java.util.List) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) AlarmConditionFilterKey(org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey) AttributeKvCompositeKey(org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey) TbMsg(org.thingsboard.server.common.msg.TbMsg) Optional(java.util.Optional) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NumericFilterPredicate(org.thingsboard.server.common.data.query.NumericFilterPredicate) Device(org.thingsboard.server.common.data.Device) AlarmConditionFilter(org.thingsboard.server.common.data.device.profile.AlarmConditionFilter) BigDecimal(java.math.BigDecimal) AlarmCondition(org.thingsboard.server.common.data.device.profile.AlarmCondition) DurationAlarmConditionSpec(org.thingsboard.server.common.data.device.profile.DurationAlarmConditionSpec) DeviceProfileAlarm(org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm) DynamicValue(org.thingsboard.server.common.data.query.DynamicValue) Test(org.junit.Test)

Example 18 with DeviceProfileAlarm

use of org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm in project thingsboard by thingsboard.

the class DeviceState method processAttributes.

private boolean processAttributes(TbContext ctx, TbMsg msg, String scope) throws ExecutionException, InterruptedException {
    boolean stateChanged = false;
    Set<AttributeKvEntry> attributes = JsonConverter.convertToAttributes(new JsonParser().parse(msg.getData()));
    if (!attributes.isEmpty()) {
        SnapshotUpdate update = merge(latestValues, attributes, scope);
        for (DeviceProfileAlarm alarm : deviceProfile.getAlarmSettings()) {
            AlarmState alarmState = alarmStates.computeIfAbsent(alarm.getId(), a -> new AlarmState(this.deviceProfile, deviceId, alarm, getOrInitPersistedAlarmState(alarm), dynamicPredicateValueCtx));
            stateChanged |= alarmState.process(ctx, msg, latestValues, update);
        }
    }
    ctx.tellSuccess(msg);
    return stateChanged;
}
Also used : AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) PersistedAlarmState(org.thingsboard.rule.engine.profile.state.PersistedAlarmState) DeviceProfileAlarm(org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm) JsonParser(com.google.gson.JsonParser)

Example 19 with DeviceProfileAlarm

use of org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm in project thingsboard by thingsboard.

the class DeviceState method updateProfile.

public void updateProfile(TbContext ctx, DeviceProfile deviceProfile) throws ExecutionException, InterruptedException {
    Set<AlarmConditionFilterKey> oldKeys = Set.copyOf(this.deviceProfile.getEntityKeys());
    this.deviceProfile.updateDeviceProfile(deviceProfile);
    if (latestValues != null) {
        Set<AlarmConditionFilterKey> keysToFetch = new HashSet<>(this.deviceProfile.getEntityKeys());
        keysToFetch.removeAll(oldKeys);
        if (!keysToFetch.isEmpty()) {
            addEntityKeysToSnapshot(ctx, deviceId, keysToFetch, latestValues);
        }
    }
    Set<String> newAlarmStateIds = this.deviceProfile.getAlarmSettings().stream().map(DeviceProfileAlarm::getId).collect(Collectors.toSet());
    alarmStates.keySet().removeIf(id -> !newAlarmStateIds.contains(id));
    for (DeviceProfileAlarm alarm : this.deviceProfile.getAlarmSettings()) {
        if (alarmStates.containsKey(alarm.getId())) {
            alarmStates.get(alarm.getId()).updateState(alarm, getOrInitPersistedAlarmState(alarm));
        } else {
            alarmStates.putIfAbsent(alarm.getId(), new AlarmState(this.deviceProfile, deviceId, alarm, getOrInitPersistedAlarmState(alarm), dynamicPredicateValueCtx));
        }
    }
}
Also used : PersistedAlarmState(org.thingsboard.rule.engine.profile.state.PersistedAlarmState) DeviceProfileAlarm(org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm) AlarmConditionFilterKey(org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey) HashSet(java.util.HashSet)

Example 20 with DeviceProfileAlarm

use of org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm in project thingsboard by thingsboard.

the class TbDeviceProfileNodeTest method testInheritTenantAttributeForRepeating.

@Test
public void testInheritTenantAttributeForRepeating() throws Exception {
    init();
    DeviceProfile deviceProfile = new DeviceProfile();
    deviceProfile.setId(deviceProfileId);
    DeviceProfileData deviceProfileData = new DeviceProfileData();
    AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey(EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "greaterAttribute");
    Device device = new Device();
    device.setId(deviceId);
    device.setCustomerId(customerId);
    AttributeKvEntity attributeKvEntity = new AttributeKvEntity();
    attributeKvEntity.setId(compositeKey);
    attributeKvEntity.setLongValue(30L);
    attributeKvEntity.setLastUpdateTs(0L);
    AttributeKvCompositeKey alarmDelayCompositeKey = new AttributeKvCompositeKey(EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "alarm_delay");
    AttributeKvEntity alarmDelayAttributeKvEntity = new AttributeKvEntity();
    alarmDelayAttributeKvEntity.setId(alarmDelayCompositeKey);
    long repeatingCondition = 2;
    alarmDelayAttributeKvEntity.setLongValue(repeatingCondition);
    alarmDelayAttributeKvEntity.setLastUpdateTs(0L);
    AttributeKvEntry entry = attributeKvEntity.toData();
    AttributeKvEntry alarmDelayAttributeKvEntry = alarmDelayAttributeKvEntity.toData();
    ListenableFuture<Optional<AttributeKvEntry>> optionalDurationAttribute = Futures.immediateFuture(Optional.of(alarmDelayAttributeKvEntry));
    ListenableFuture<List<AttributeKvEntry>> listNoDurationAttribute = Futures.immediateFuture(Collections.singletonList(entry));
    ListenableFuture<Optional<AttributeKvEntry>> emptyOptional = Futures.immediateFuture(Optional.empty());
    AlarmConditionFilter highTempFilter = new AlarmConditionFilter();
    highTempFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.TIME_SERIES, "temperature"));
    highTempFilter.setValueType(EntityKeyValueType.NUMERIC);
    NumericFilterPredicate highTemperaturePredicate = new NumericFilterPredicate();
    highTemperaturePredicate.setOperation(NumericFilterPredicate.NumericOperation.GREATER);
    highTemperaturePredicate.setValue(new FilterPredicateValue<>(0.0, null, new DynamicValue<>(DynamicValueSourceType.CURRENT_DEVICE, "greaterAttribute", false)));
    highTempFilter.setPredicate(highTemperaturePredicate);
    AlarmCondition alarmCondition = new AlarmCondition();
    alarmCondition.setCondition(Collections.singletonList(highTempFilter));
    FilterPredicateValue<Integer> filterPredicateValue = new FilterPredicateValue<>(10, null, new DynamicValue<>(DynamicValueSourceType.CURRENT_DEVICE, "alarm_delay", true));
    RepeatingAlarmConditionSpec repeatingSpec = new RepeatingAlarmConditionSpec();
    repeatingSpec.setPredicate(filterPredicateValue);
    alarmCondition.setSpec(repeatingSpec);
    AlarmRule alarmRule = new AlarmRule();
    alarmRule.setCondition(alarmCondition);
    DeviceProfileAlarm dpa = new DeviceProfileAlarm();
    dpa.setId("highTemperatureAlarmID");
    dpa.setAlarmType("highTemperatureAlarm");
    dpa.setCreateRules(new TreeMap<>(Collections.singletonMap(AlarmSeverity.CRITICAL, alarmRule)));
    deviceProfileData.setAlarms(Collections.singletonList(dpa));
    deviceProfile.setProfileData(deviceProfileData);
    Mockito.when(cache.get(tenantId, deviceId)).thenReturn(deviceProfile);
    Mockito.when(timeseriesService.findLatest(tenantId, deviceId, Collections.singleton("temperature"))).thenReturn(Futures.immediateFuture(Collections.emptyList()));
    Mockito.when(alarmService.findLatestByOriginatorAndType(tenantId, deviceId, "highTemperatureAlarm")).thenReturn(Futures.immediateFuture(null));
    Mockito.when(alarmService.createOrUpdateAlarm(Mockito.any())).thenAnswer(AdditionalAnswers.returnsFirstArg());
    Mockito.when(ctx.getAttributesService()).thenReturn(attributesService);
    Mockito.when(attributesService.find(eq(tenantId), eq(tenantId), Mockito.anyString(), Mockito.anyString())).thenReturn(optionalDurationAttribute);
    Mockito.when(ctx.getDeviceService().findDeviceById(tenantId, deviceId)).thenReturn(device);
    Mockito.when(attributesService.find(eq(tenantId), eq(customerId), eq(DataConstants.SERVER_SCOPE), Mockito.anyString())).thenReturn(emptyOptional);
    Mockito.when(attributesService.find(eq(tenantId), eq(deviceId), Mockito.anyString(), Mockito.anySet())).thenReturn(listNoDurationAttribute);
    TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), "");
    Mockito.when(ctx.newMsg(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn(theMsg);
    ObjectNode data = mapper.createObjectNode();
    data.put("temperature", 150);
    TbMsg msg = TbMsg.newMsg(SessionMsgType.POST_TELEMETRY_REQUEST.name(), deviceId, new TbMsgMetaData(), TbMsgDataType.JSON, mapper.writeValueAsString(data), null, null);
    node.onMsg(ctx, msg);
    verify(ctx).tellSuccess(msg);
    verify(ctx, Mockito.never()).tellNext(theMsg, "Alarm Created");
    data.put("temperature", 151);
    TbMsg msg2 = TbMsg.newMsg(SessionMsgType.POST_TELEMETRY_REQUEST.name(), deviceId, new TbMsgMetaData(), TbMsgDataType.JSON, mapper.writeValueAsString(data), null, null);
    node.onMsg(ctx, msg2);
    verify(ctx).tellSuccess(msg2);
    verify(ctx).enqueueForTellNext(theMsg, "Alarm Created");
    verify(ctx, Mockito.never()).tellFailure(Mockito.any(), Mockito.any());
}
Also used : AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) AttributeKvEntity(org.thingsboard.server.dao.model.sql.AttributeKvEntity) AlarmRule(org.thingsboard.server.common.data.device.profile.AlarmRule) FilterPredicateValue(org.thingsboard.server.common.data.query.FilterPredicateValue) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) List(java.util.List) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) AlarmConditionFilterKey(org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey) AttributeKvCompositeKey(org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey) TbMsg(org.thingsboard.server.common.msg.TbMsg) Optional(java.util.Optional) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NumericFilterPredicate(org.thingsboard.server.common.data.query.NumericFilterPredicate) Device(org.thingsboard.server.common.data.Device) AlarmConditionFilter(org.thingsboard.server.common.data.device.profile.AlarmConditionFilter) AlarmCondition(org.thingsboard.server.common.data.device.profile.AlarmCondition) DeviceProfileAlarm(org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm) RepeatingAlarmConditionSpec(org.thingsboard.server.common.data.device.profile.RepeatingAlarmConditionSpec) DynamicValue(org.thingsboard.server.common.data.query.DynamicValue) Test(org.junit.Test)

Aggregations

DeviceProfileAlarm (org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm)25 AlarmConditionFilterKey (org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)18 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)17 AlarmRule (org.thingsboard.server.common.data.device.profile.AlarmRule)17 AlarmCondition (org.thingsboard.server.common.data.device.profile.AlarmCondition)16 AlarmConditionFilter (org.thingsboard.server.common.data.device.profile.AlarmConditionFilter)16 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)16 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)16 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)15 List (java.util.List)15 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)15 TbMsg (org.thingsboard.server.common.msg.TbMsg)15 TbMsgMetaData (org.thingsboard.server.common.msg.TbMsgMetaData)15 Test (org.junit.Test)14 DynamicValue (org.thingsboard.server.common.data.query.DynamicValue)14 AttributeKvCompositeKey (org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey)13 AttributeKvEntity (org.thingsboard.server.dao.model.sql.AttributeKvEntity)13 Device (org.thingsboard.server.common.data.Device)9 Optional (java.util.Optional)7 PersistedAlarmState (org.thingsboard.rule.engine.profile.state.PersistedAlarmState)7