Search in sources :

Example 11 with DownlinkMsg

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

the class EntityViewEdgeProcessor method processEntityViewToEdge.

public DownlinkMsg processEntityViewToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    EntityViewId entityViewId = new EntityViewId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
        case ASSIGNED_TO_EDGE:
        case ASSIGNED_TO_CUSTOMER:
        case UNASSIGNED_FROM_CUSTOMER:
            EntityView entityView = entityViewService.findEntityViewById(edgeEvent.getTenantId(), entityViewId);
            if (entityView != null) {
                CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(entityView, edge);
                EntityViewUpdateMsg entityViewUpdateMsg = entityViewMsgConstructor.constructEntityViewUpdatedMsg(msgType, entityView, customerId);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addEntityViewUpdateMsg(entityViewUpdateMsg).build();
            }
            break;
        case DELETED:
        case UNASSIGNED_FROM_EDGE:
            EntityViewUpdateMsg entityViewUpdateMsg = entityViewMsgConstructor.constructEntityViewDeleteMsg(entityViewId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addEntityViewUpdateMsg(entityViewUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) EntityView(org.thingsboard.server.common.data.EntityView) CustomerId(org.thingsboard.server.common.data.id.CustomerId) EntityViewUpdateMsg(org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg)

Example 12 with DownlinkMsg

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

the class RuleChainEdgeProcessor method processRuleChainToEdge.

public DownlinkMsg processRuleChainToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    RuleChainId ruleChainId = new RuleChainId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
        case ASSIGNED_TO_EDGE:
            RuleChain ruleChain = ruleChainService.findRuleChainById(edgeEvent.getTenantId(), ruleChainId);
            if (ruleChain != null) {
                RuleChainUpdateMsg ruleChainUpdateMsg = ruleChainMsgConstructor.constructRuleChainUpdatedMsg(edge.getRootRuleChainId(), msgType, ruleChain);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addRuleChainUpdateMsg(ruleChainUpdateMsg).build();
            }
            break;
        case DELETED:
        case UNASSIGNED_FROM_EDGE:
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addRuleChainUpdateMsg(ruleChainMsgConstructor.constructRuleChainDeleteMsg(ruleChainId)).build();
            break;
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) RuleChainUpdateMsg(org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg)

Example 13 with DownlinkMsg

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

the class UserEdgeProcessor method processUserToEdge.

public DownlinkMsg processUserToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
    UserId userId = new UserId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(edgeEdgeEventActionType) {
        case ADDED:
        case UPDATED:
            User user = userService.findUserById(edgeEvent.getTenantId(), userId);
            if (user != null) {
                CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(user, edge);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addUserUpdateMsg(userMsgConstructor.constructUserUpdatedMsg(msgType, user, customerId)).build();
            }
            break;
        case DELETED:
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addUserUpdateMsg(userMsgConstructor.constructUserDeleteMsg(userId)).build();
            break;
        case CREDENTIALS_UPDATED:
            UserCredentials userCredentialsByUserId = userService.findUserCredentialsByUserId(edge.getTenantId(), userId);
            if (userCredentialsByUserId != null && userCredentialsByUserId.isEnabled()) {
                UserCredentialsUpdateMsg userCredentialsUpdateMsg = userMsgConstructor.constructUserCredentialsUpdatedMsg(userCredentialsByUserId);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addUserCredentialsUpdateMsg(userCredentialsUpdateMsg).build();
            }
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) User(org.thingsboard.server.common.data.User) UserId(org.thingsboard.server.common.data.id.UserId) UserCredentials(org.thingsboard.server.common.data.security.UserCredentials) UserCredentialsUpdateMsg(org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg) CustomerId(org.thingsboard.server.common.data.id.CustomerId)

Example 14 with DownlinkMsg

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

the class EdgeGrpcSession method processEntityMessage.

private DownlinkMsg processEntityMessage(EdgeEvent edgeEvent, EdgeEventActionType action) {
    UpdateMsgType msgType = getResponseMsgType(edgeEvent.getAction());
    log.trace("Executing processEntityMessage, edgeEvent [{}], action [{}], msgType [{}]", edgeEvent, action, msgType);
    switch(edgeEvent.getType()) {
        case DEVICE:
            return ctx.getDeviceProcessor().processDeviceToEdge(edge, edgeEvent, msgType, action);
        case DEVICE_PROFILE:
            return ctx.getDeviceProfileProcessor().processDeviceProfileToEdge(edgeEvent, msgType, action);
        case ASSET:
            return ctx.getAssetProcessor().processAssetToEdge(edge, edgeEvent, msgType, action);
        case ENTITY_VIEW:
            return ctx.getEntityViewProcessor().processEntityViewToEdge(edge, edgeEvent, msgType, action);
        case DASHBOARD:
            return ctx.getDashboardProcessor().processDashboardToEdge(edge, edgeEvent, msgType, action);
        case CUSTOMER:
            return ctx.getCustomerProcessor().processCustomerToEdge(edgeEvent, msgType, action);
        case RULE_CHAIN:
            return ctx.getRuleChainProcessor().processRuleChainToEdge(edge, edgeEvent, msgType, action);
        case RULE_CHAIN_METADATA:
            return ctx.getRuleChainProcessor().processRuleChainMetadataToEdge(edgeEvent, msgType, this.edgeVersion);
        case ALARM:
            return ctx.getAlarmProcessor().processAlarmToEdge(edge, edgeEvent, msgType, action);
        case USER:
            return ctx.getUserProcessor().processUserToEdge(edge, edgeEvent, msgType, action);
        case RELATION:
            return ctx.getRelationProcessor().processRelationToEdge(edgeEvent, msgType);
        case WIDGETS_BUNDLE:
            return ctx.getWidgetBundleProcessor().processWidgetsBundleToEdge(edgeEvent, msgType, action);
        case WIDGET_TYPE:
            return ctx.getWidgetTypeProcessor().processWidgetTypeToEdge(edgeEvent, msgType, action);
        case ADMIN_SETTINGS:
            return ctx.getAdminSettingsProcessor().processAdminSettingsToEdge(edgeEvent);
        default:
            log.warn("Unsupported edge event type [{}]", edgeEvent);
            return null;
    }
}
Also used : UpdateMsgType(org.thingsboard.server.gen.edge.v1.UpdateMsgType)

Example 15 with DownlinkMsg

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

the class EdgeGrpcSession method convertToDownlinkMsg.

private DownlinkMsg convertToDownlinkMsg(EdgeEvent edgeEvent) {
    log.trace("[{}][{}] converting edge event to downlink msg [{}]", edge.getTenantId(), this.sessionId, edgeEvent);
    DownlinkMsg downlinkMsg = null;
    try {
        switch(edgeEvent.getAction()) {
            case UPDATED:
            case ADDED:
            case DELETED:
            case ASSIGNED_TO_EDGE:
            case UNASSIGNED_FROM_EDGE:
            case ALARM_ACK:
            case ALARM_CLEAR:
            case CREDENTIALS_UPDATED:
            case RELATION_ADD_OR_UPDATE:
            case RELATION_DELETED:
            case ASSIGNED_TO_CUSTOMER:
            case UNASSIGNED_FROM_CUSTOMER:
                downlinkMsg = processEntityMessage(edgeEvent, edgeEvent.getAction());
                log.trace("[{}][{}] entity message processed [{}]", edgeEvent.getTenantId(), this.sessionId, downlinkMsg);
                break;
            case ATTRIBUTES_UPDATED:
            case POST_ATTRIBUTES:
            case ATTRIBUTES_DELETED:
            case TIMESERIES_UPDATED:
                downlinkMsg = ctx.getTelemetryProcessor().processTelemetryMessageToEdge(edgeEvent);
                break;
            case CREDENTIALS_REQUEST:
                downlinkMsg = ctx.getEntityProcessor().processCredentialsRequestMessageToEdge(edgeEvent);
                break;
            case ENTITY_MERGE_REQUEST:
                downlinkMsg = ctx.getEntityProcessor().processEntityMergeRequestMessageToEdge(edge, edgeEvent);
                break;
            case RPC_CALL:
                downlinkMsg = ctx.getDeviceProcessor().processRpcCallMsgToEdge(edgeEvent);
                break;
            default:
                log.warn("[{}][{}] Unsupported action type [{}]", edge.getTenantId(), this.sessionId, edgeEvent.getAction());
        }
    } catch (Exception e) {
        log.error("[{}][{}] Exception during converting edge event to downlink msg", edge.getTenantId(), this.sessionId, e);
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg)

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