Search in sources :

Example 6 with DownlinkMsg

use of org.thingsboard.server.gen.edge.v1.DownlinkMsg in project thingsboard by thingsboard.

the class CustomerEdgeProcessor method processCustomerToEdge.

public DownlinkMsg processCustomerToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    CustomerId customerId = new CustomerId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
            Customer customer = customerService.findCustomerById(edgeEvent.getTenantId(), customerId);
            if (customer != null) {
                CustomerUpdateMsg customerUpdateMsg = customerMsgConstructor.constructCustomerUpdatedMsg(msgType, customer);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addCustomerUpdateMsg(customerUpdateMsg).build();
            }
            break;
        case DELETED:
            CustomerUpdateMsg customerUpdateMsg = customerMsgConstructor.constructCustomerDeleteMsg(customerId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addCustomerUpdateMsg(customerUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) Customer(org.thingsboard.server.common.data.Customer) CustomerId(org.thingsboard.server.common.data.id.CustomerId) CustomerUpdateMsg(org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg)

Example 7 with DownlinkMsg

use of org.thingsboard.server.gen.edge.v1.DownlinkMsg 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();
}
Also used : DeviceRpcCallMsg(org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg)

Example 8 with DownlinkMsg

use of org.thingsboard.server.gen.edge.v1.DownlinkMsg in project thingsboard by thingsboard.

the class RuleChainEdgeProcessor method processRuleChainMetadataToEdge.

public DownlinkMsg processRuleChainMetadataToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeVersion edgeVersion) {
    RuleChainId ruleChainId = new RuleChainId(edgeEvent.getEntityId());
    RuleChain ruleChain = ruleChainService.findRuleChainById(edgeEvent.getTenantId(), ruleChainId);
    DownlinkMsg downlinkMsg = null;
    if (ruleChain != null) {
        RuleChainMetaData ruleChainMetaData = ruleChainService.loadRuleChainMetaData(edgeEvent.getTenantId(), ruleChainId);
        RuleChainMetadataUpdateMsg ruleChainMetadataUpdateMsg = ruleChainMsgConstructor.constructRuleChainMetadataUpdatedMsg(msgType, ruleChainMetaData, edgeVersion);
        if (ruleChainMetadataUpdateMsg != null) {
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addRuleChainMetadataUpdateMsg(ruleChainMetadataUpdateMsg).build();
        }
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) RuleChainMetadataUpdateMsg(org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) RuleChainMetaData(org.thingsboard.server.common.data.rule.RuleChainMetaData) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId)

Example 9 with DownlinkMsg

use of org.thingsboard.server.gen.edge.v1.DownlinkMsg in project thingsboard by thingsboard.

the class AlarmEdgeProcessor method processAlarmToEdge.

public DownlinkMsg processAlarmToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    AlarmId alarmId = new AlarmId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
        case ALARM_ACK:
        case ALARM_CLEAR:
            try {
                Alarm alarm = alarmService.findAlarmByIdAsync(edgeEvent.getTenantId(), alarmId).get();
                if (alarm != null) {
                    downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addAlarmUpdateMsg(alarmMsgConstructor.constructAlarmUpdatedMsg(edge.getTenantId(), msgType, alarm)).build();
                }
            } catch (Exception e) {
                log.error("Can't process alarm msg [{}] [{}]", edgeEvent, msgType, e);
            }
            break;
        case DELETED:
            Alarm alarm = mapper.convertValue(edgeEvent.getBody(), Alarm.class);
            AlarmUpdateMsg alarmUpdateMsg = alarmMsgConstructor.constructAlarmUpdatedMsg(edge.getTenantId(), msgType, alarm);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addAlarmUpdateMsg(alarmUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : AlarmId(org.thingsboard.server.common.data.id.AlarmId) AlarmUpdateMsg(org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg) DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) Alarm(org.thingsboard.server.common.data.alarm.Alarm) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 10 with DownlinkMsg

use of org.thingsboard.server.gen.edge.v1.DownlinkMsg in project thingsboard by thingsboard.

the class DeviceEdgeProcessor method processDeviceToEdge.

public DownlinkMsg processDeviceToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
    DeviceId deviceId = new DeviceId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(edgeEdgeEventActionType) {
        case ADDED:
        case UPDATED:
        case ASSIGNED_TO_EDGE:
        case ASSIGNED_TO_CUSTOMER:
        case UNASSIGNED_FROM_CUSTOMER:
            Device device = deviceService.findDeviceById(edgeEvent.getTenantId(), deviceId);
            if (device != null) {
                CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(device, edge);
                DeviceUpdateMsg deviceUpdateMsg = deviceMsgConstructor.constructDeviceUpdatedMsg(msgType, device, customerId, null);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceUpdateMsg(deviceUpdateMsg).build();
            }
            break;
        case DELETED:
        case UNASSIGNED_FROM_EDGE:
            DeviceUpdateMsg deviceUpdateMsg = deviceMsgConstructor.constructDeviceDeleteMsg(deviceId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceUpdateMsg(deviceUpdateMsg).build();
            break;
        case CREDENTIALS_UPDATED:
            DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(edge.getTenantId(), deviceId);
            if (deviceCredentials != null) {
                DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg = deviceMsgConstructor.constructDeviceCredentialsUpdatedMsg(deviceCredentials);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceCredentialsUpdateMsg(deviceCredentialsUpdateMsg).build();
            }
            break;
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Device(org.thingsboard.server.common.data.Device) DeviceUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg) CustomerId(org.thingsboard.server.common.data.id.CustomerId) DeviceCredentialsUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceCredentialsUpdateMsg) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials)

Aggregations

DownlinkMsg (org.thingsboard.server.gen.edge.v1.DownlinkMsg)16 CustomerId (org.thingsboard.server.common.data.id.CustomerId)7 DeviceId (org.thingsboard.server.common.data.id.DeviceId)3 Device (org.thingsboard.server.common.data.Device)2 RuleChainId (org.thingsboard.server.common.data.id.RuleChainId)2 RuleChain (org.thingsboard.server.common.data.rule.RuleChain)2 DeviceUpdateMsg (org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 NettyChannelBuilder (io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder)1 SslContextBuilder (io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder)1 StreamObserver (io.grpc.stub.StreamObserver)1 UUID (java.util.UUID)1 SSLException (javax.net.ssl.SSLException)1 EdgeConnectionException (org.thingsboard.edge.exception.EdgeConnectionException)1 AdminSettings (org.thingsboard.server.common.data.AdminSettings)1 Customer (org.thingsboard.server.common.data.Customer)1 Dashboard (org.thingsboard.server.common.data.Dashboard)1 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)1 EntityView (org.thingsboard.server.common.data.EntityView)1 User (org.thingsboard.server.common.data.User)1