Search in sources :

Example 6 with BaseAttributeKvEntry

use of org.thingsboard.server.common.data.kv.BaseAttributeKvEntry in project thingsboard by thingsboard.

the class DeviceAttributesFilterTest method basicClientAttributesStressTest.

@Test(timeout = 30000)
public void basicClientAttributesStressTest() {
    DeviceAttributesFilter filter = new DeviceAttributesFilter();
    filter.init(wrap("doubleValue == 1.0 && booleanValue == false"));
    List<AttributeKvEntry> clientAttributes = new ArrayList<>();
    clientAttributes.add(new BaseAttributeKvEntry(new DoubleDataEntry("doubleValue", 1.0), 42));
    clientAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", false), 42));
    DeviceAttributes attributes = new DeviceAttributes(clientAttributes, new ArrayList<>(), new ArrayList<>());
    Mockito.when(ruleCtx.getDeviceMetaData()).thenReturn(new DeviceMetaData(new DeviceId(UUID.randomUUID()), "A", "A", attributes));
    for (int i = 0; i < 10000; i++) {
        Assert.assertTrue(filter.filter(ruleCtx, null));
    }
    filter.stop();
}
Also used : BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) DoubleDataEntry(org.thingsboard.server.common.data.kv.DoubleDataEntry) BooleanDataEntry(org.thingsboard.server.common.data.kv.BooleanDataEntry) DeviceId(org.thingsboard.server.common.data.id.DeviceId) ArrayList(java.util.ArrayList) DeviceAttributes(org.thingsboard.server.extensions.api.device.DeviceAttributes) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) DeviceMetaData(org.thingsboard.server.extensions.api.device.DeviceMetaData) Test(org.junit.Test)

Example 7 with BaseAttributeKvEntry

use of org.thingsboard.server.common.data.kv.BaseAttributeKvEntry in project thingsboard by thingsboard.

the class CassandraBaseAttributesDao method convertResultToAttributesKvEntry.

private AttributeKvEntry convertResultToAttributesKvEntry(String key, Row row) {
    AttributeKvEntry attributeEntry = null;
    if (row != null) {
        long lastUpdateTs = row.get(LAST_UPDATE_TS_COLUMN, Long.class);
        attributeEntry = new BaseAttributeKvEntry(CassandraBaseTimeseriesDao.toKvEntry(row, key), lastUpdateTs);
    }
    return attributeEntry;
}
Also used : BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)

Example 8 with BaseAttributeKvEntry

use of org.thingsboard.server.common.data.kv.BaseAttributeKvEntry in project thingsboard by thingsboard.

the class BaseAttributesServiceTest method saveAndFetch.

@Test
public void saveAndFetch() throws Exception {
    DeviceId deviceId = new DeviceId(UUIDs.timeBased());
    KvEntry attrValue = new StringDataEntry("attribute1", "value1");
    AttributeKvEntry attr = new BaseAttributeKvEntry(attrValue, 42L);
    attributesService.save(deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attr)).get();
    Optional<AttributeKvEntry> saved = attributesService.find(deviceId, DataConstants.CLIENT_SCOPE, attr.getKey()).get();
    Assert.assertTrue(saved.isPresent());
    Assert.assertEquals(attr, saved.get());
}
Also used : BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) DeviceId(org.thingsboard.server.common.data.id.DeviceId) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) Test(org.junit.Test) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest)

Example 9 with BaseAttributeKvEntry

use of org.thingsboard.server.common.data.kv.BaseAttributeKvEntry in project thingsboard by thingsboard.

the class BaseAttributesServiceTest method saveMultipleTypeAndFetch.

@Test
public void saveMultipleTypeAndFetch() throws Exception {
    DeviceId deviceId = new DeviceId(UUIDs.timeBased());
    KvEntry attrOldValue = new StringDataEntry("attribute1", "value1");
    AttributeKvEntry attrOld = new BaseAttributeKvEntry(attrOldValue, 42L);
    attributesService.save(deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attrOld)).get();
    Optional<AttributeKvEntry> saved = attributesService.find(deviceId, DataConstants.CLIENT_SCOPE, attrOld.getKey()).get();
    Assert.assertTrue(saved.isPresent());
    Assert.assertEquals(attrOld, saved.get());
    KvEntry attrNewValue = new StringDataEntry("attribute1", "value2");
    AttributeKvEntry attrNew = new BaseAttributeKvEntry(attrNewValue, 73L);
    attributesService.save(deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attrNew)).get();
    saved = attributesService.find(deviceId, DataConstants.CLIENT_SCOPE, attrOld.getKey()).get();
    Assert.assertEquals(attrNew, saved.get());
}
Also used : BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) DeviceId(org.thingsboard.server.common.data.id.DeviceId) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) Test(org.junit.Test) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest)

Example 10 with BaseAttributeKvEntry

use of org.thingsboard.server.common.data.kv.BaseAttributeKvEntry in project thingsboard by thingsboard.

the class GatewaySessionCtx method onDeviceAttributes.

public void onDeviceAttributes(MqttPublishMessage mqttMsg) throws AdaptorException {
    JsonElement json = validateJsonPayload(gatewaySessionId, mqttMsg.payload());
    int requestId = mqttMsg.variableHeader().messageId();
    if (json.isJsonObject()) {
        JsonObject jsonObj = json.getAsJsonObject();
        for (Map.Entry<String, JsonElement> deviceEntry : jsonObj.entrySet()) {
            String deviceName = checkDeviceConnected(deviceEntry.getKey());
            if (!deviceEntry.getValue().isJsonObject()) {
                throw new JsonSyntaxException(CAN_T_PARSE_VALUE + json);
            }
            long ts = System.currentTimeMillis();
            BasicUpdateAttributesRequest request = new BasicUpdateAttributesRequest(requestId);
            JsonObject deviceData = deviceEntry.getValue().getAsJsonObject();
            request.add(JsonConverter.parseValues(deviceData).stream().map(kv -> new BaseAttributeKvEntry(kv, ts)).collect(Collectors.toList()));
            GatewayDeviceSessionCtx deviceSessionCtx = devices.get(deviceName);
            processor.process(new BasicToDeviceActorSessionMsg(deviceSessionCtx.getDevice(), new BasicAdaptorToSessionActorMsg(deviceSessionCtx, request)));
        }
    } else {
        throw new JsonSyntaxException(CAN_T_PARSE_VALUE + json);
    }
}
Also used : JsonObject(com.google.gson.JsonObject) BasicAdaptorToSessionActorMsg(org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) BasicToDeviceActorSessionMsg(org.thingsboard.server.common.msg.session.BasicToDeviceActorSessionMsg) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)

Aggregations

BaseAttributeKvEntry (org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)10 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)9 Test (org.junit.Test)8 DeviceId (org.thingsboard.server.common.data.id.DeviceId)8 ArrayList (java.util.ArrayList)5 BooleanDataEntry (org.thingsboard.server.common.data.kv.BooleanDataEntry)5 DeviceAttributes (org.thingsboard.server.extensions.api.device.DeviceAttributes)5 DeviceMetaData (org.thingsboard.server.extensions.api.device.DeviceMetaData)5 DoubleDataEntry (org.thingsboard.server.common.data.kv.DoubleDataEntry)4 KvEntry (org.thingsboard.server.common.data.kv.KvEntry)3 StringDataEntry (org.thingsboard.server.common.data.kv.StringDataEntry)3 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)3 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 BasicAdaptorToSessionActorMsg (org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg)1 BasicToDeviceActorSessionMsg (org.thingsboard.server.common.msg.session.BasicToDeviceActorSessionMsg)1