use of org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg in project thingsboard by thingsboard.
the class DeviceMsgConstructor method constructDeviceRpcCallMsg.
public DeviceRpcCallMsg constructDeviceRpcCallMsg(UUID deviceId, JsonNode body) {
int requestId = body.get("requestId").asInt();
boolean oneway = body.get("oneway").asBoolean();
UUID requestUUID = UUID.fromString(body.get("requestUUID").asText());
long expirationTime = body.get("expirationTime").asLong();
String method = body.get("method").asText();
String params = body.get("params").asText();
RpcRequestMsg.Builder requestBuilder = RpcRequestMsg.newBuilder();
requestBuilder.setMethod(method);
requestBuilder.setParams(params);
DeviceRpcCallMsg.Builder builder = DeviceRpcCallMsg.newBuilder().setDeviceIdMSB(deviceId.getMostSignificantBits()).setDeviceIdLSB(deviceId.getLeastSignificantBits()).setRequestUuidMSB(requestUUID.getMostSignificantBits()).setRequestUuidLSB(requestUUID.getLeastSignificantBits()).setRequestId(requestId).setExpirationTime(expirationTime).setOneway(oneway).setRequestMsg(requestBuilder.build());
return builder.build();
}
use of org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg in project thingsboard by thingsboard.
the class DeviceEdgeProcessor method processRpcCallMsgToEdge.
public DownlinkMsg processRpcCallMsgToEdge(EdgeEvent edgeEvent) {
log.trace("Executing processRpcCall, edgeEvent [{}]", edgeEvent);
DeviceRpcCallMsg deviceRpcCallMsg = deviceMsgConstructor.constructDeviceRpcCallMsg(edgeEvent.getEntityId(), edgeEvent.getBody());
return DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceRpcCallMsg(deviceRpcCallMsg).build();
}
use of org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg in project thingsboard by thingsboard.
the class BaseEdgeTest method testRpcCall.
@Test
public void testRpcCall() throws Exception {
Device device = findDeviceByName("Edge Device 1");
ObjectNode body = mapper.createObjectNode();
body.put("requestId", new Random().nextInt());
body.put("requestUUID", Uuids.timeBased().toString());
body.put("oneway", false);
body.put("expirationTime", System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10));
body.put("method", "test_method");
body.put("params", "{\"param1\":\"value1\"}");
EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.RPC_CALL, device.getId().getId(), EdgeEventType.DEVICE, body);
edgeImitator.expectMessageAmount(1);
edgeEventService.save(edgeEvent);
clusterService.onEdgeEventUpdate(tenantId, edge.getId());
Assert.assertTrue(edgeImitator.waitForMessages());
AbstractMessage latestMessage = edgeImitator.getLatestMessage();
Assert.assertTrue(latestMessage instanceof DeviceRpcCallMsg);
DeviceRpcCallMsg latestDeviceRpcCallMsg = (DeviceRpcCallMsg) latestMessage;
Assert.assertEquals("test_method", latestDeviceRpcCallMsg.getRequestMsg().getMethod());
}
Aggregations