Search in sources :

Example 1 with ServiceType

use of org.thingsboard.server.common.msg.queue.ServiceType in project thingsboard by thingsboard.

the class TenantActor method doProcess.

@Override
protected boolean doProcess(TbActorMsg msg) {
    if (cantFindTenant) {
        log.info("[{}] Processing missing Tenant msg: {}", tenantId, msg);
        if (msg.getMsgType().equals(MsgType.QUEUE_TO_RULE_ENGINE_MSG)) {
            QueueToRuleEngineMsg queueMsg = (QueueToRuleEngineMsg) msg;
            queueMsg.getMsg().getCallback().onSuccess();
        } else if (msg.getMsgType().equals(MsgType.TRANSPORT_TO_DEVICE_ACTOR_MSG)) {
            TransportToDeviceActorMsgWrapper transportMsg = (TransportToDeviceActorMsgWrapper) msg;
            transportMsg.getCallback().onSuccess();
        }
        return true;
    }
    switch(msg.getMsgType()) {
        case PARTITION_CHANGE_MSG:
            PartitionChangeMsg partitionChangeMsg = (PartitionChangeMsg) msg;
            ServiceType serviceType = partitionChangeMsg.getServiceQueueKey().getServiceType();
            if (ServiceType.TB_RULE_ENGINE.equals(serviceType)) {
                // To Rule Chain Actors
                broadcast(msg);
            } else if (ServiceType.TB_CORE.equals(serviceType)) {
                List<TbActorId> deviceActorIds = ctx.filterChildren(new TbEntityTypeActorIdPredicate(EntityType.DEVICE) {

                    @Override
                    protected boolean testEntityId(EntityId entityId) {
                        return super.testEntityId(entityId) && !isMyPartition(entityId);
                    }
                });
                deviceActorIds.forEach(id -> ctx.stop(id));
            }
            break;
        case COMPONENT_LIFE_CYCLE_MSG:
            onComponentLifecycleMsg((ComponentLifecycleMsg) msg);
            break;
        case QUEUE_TO_RULE_ENGINE_MSG:
            onQueueToRuleEngineMsg((QueueToRuleEngineMsg) msg);
            break;
        case TRANSPORT_TO_DEVICE_ACTOR_MSG:
            onToDeviceActorMsg((DeviceAwareMsg) msg, false);
            break;
        case DEVICE_ATTRIBUTES_UPDATE_TO_DEVICE_ACTOR_MSG:
        case DEVICE_CREDENTIALS_UPDATE_TO_DEVICE_ACTOR_MSG:
        case DEVICE_NAME_OR_TYPE_UPDATE_TO_DEVICE_ACTOR_MSG:
        case DEVICE_EDGE_UPDATE_TO_DEVICE_ACTOR_MSG:
        case DEVICE_RPC_REQUEST_TO_DEVICE_ACTOR_MSG:
        case DEVICE_RPC_RESPONSE_TO_DEVICE_ACTOR_MSG:
        case SERVER_RPC_RESPONSE_TO_DEVICE_ACTOR_MSG:
        case REMOVE_RPC_TO_DEVICE_ACTOR_MSG:
            onToDeviceActorMsg((DeviceAwareMsg) msg, true);
            break;
        case SESSION_TIMEOUT_MSG:
            ctx.broadcastToChildrenByType(msg, EntityType.DEVICE);
            break;
        case RULE_CHAIN_INPUT_MSG:
        case RULE_CHAIN_OUTPUT_MSG:
        case RULE_CHAIN_TO_RULE_CHAIN_MSG:
            onRuleChainMsg((RuleChainAwareMsg) msg);
            break;
        case EDGE_EVENT_UPDATE_TO_EDGE_SESSION_MSG:
            onToEdgeSessionMsg((EdgeEventUpdateMsg) msg);
            break;
        default:
            return false;
    }
    return true;
}
Also used : EntityId(org.thingsboard.server.common.data.id.EntityId) TransportToDeviceActorMsgWrapper(org.thingsboard.server.service.transport.msg.TransportToDeviceActorMsgWrapper) Edge(org.thingsboard.server.common.data.edge.Edge) TbMsg(org.thingsboard.server.common.msg.TbMsg) RuleChainManagerActor(org.thingsboard.server.actors.ruleChain.RuleChainManagerActor) EdgeEventUpdateMsg(org.thingsboard.server.common.msg.edge.EdgeEventUpdateMsg) Tenant(org.thingsboard.server.common.data.Tenant) TenantId(org.thingsboard.server.common.data.id.TenantId) DeviceActorCreator(org.thingsboard.server.actors.device.DeviceActorCreator) DefaultActorService(org.thingsboard.server.actors.service.DefaultActorService) TbActorId(org.thingsboard.server.actors.TbActorId) TbActorNotRegisteredException(org.thingsboard.server.actors.TbActorNotRegisteredException) MsgType(org.thingsboard.server.common.msg.MsgType) TenantProfile(org.thingsboard.server.common.data.TenantProfile) ActorSystemContext(org.thingsboard.server.actors.ActorSystemContext) ServiceType(org.thingsboard.server.common.msg.queue.ServiceType) QueueToRuleEngineMsg(org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg) EntityId(org.thingsboard.server.common.data.id.EntityId) TbEntityTypeActorIdPredicate(org.thingsboard.server.actors.TbEntityTypeActorIdPredicate) EntityType(org.thingsboard.server.common.data.EntityType) DeviceAwareMsg(org.thingsboard.server.common.msg.aware.DeviceAwareMsg) EdgeId(org.thingsboard.server.common.data.id.EdgeId) TbEntityActorId(org.thingsboard.server.actors.TbEntityActorId) DeviceId(org.thingsboard.server.common.data.id.DeviceId) ComponentLifecycleMsg(org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg) RuleChainType(org.thingsboard.server.common.data.rule.RuleChainType) TbActorCtx(org.thingsboard.server.actors.TbActorCtx) ComponentLifecycleEvent(org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent) ApiUsageState(org.thingsboard.server.common.data.ApiUsageState) PartitionChangeMsg(org.thingsboard.server.common.msg.queue.PartitionChangeMsg) EdgeRpcService(org.thingsboard.server.service.edge.rpc.EdgeRpcService) RuleEngineException(org.thingsboard.server.common.msg.queue.RuleEngineException) Slf4j(lombok.extern.slf4j.Slf4j) TbActorException(org.thingsboard.server.actors.TbActorException) List(java.util.List) TbActorMsg(org.thingsboard.server.common.msg.TbActorMsg) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) Optional(java.util.Optional) ContextBasedCreator(org.thingsboard.server.actors.service.ContextBasedCreator) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) RuleChainAwareMsg(org.thingsboard.server.common.msg.aware.RuleChainAwareMsg) TbActor(org.thingsboard.server.actors.TbActor) TbActorRef(org.thingsboard.server.actors.TbActorRef) QueueToRuleEngineMsg(org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg) ServiceType(org.thingsboard.server.common.msg.queue.ServiceType) PartitionChangeMsg(org.thingsboard.server.common.msg.queue.PartitionChangeMsg) List(java.util.List) TransportToDeviceActorMsgWrapper(org.thingsboard.server.service.transport.msg.TransportToDeviceActorMsgWrapper) TbEntityTypeActorIdPredicate(org.thingsboard.server.actors.TbEntityTypeActorIdPredicate)

Example 2 with ServiceType

use of org.thingsboard.server.common.msg.queue.ServiceType in project thingsboard by thingsboard.

the class HashPartitionService method getServiceKeyListMap.

private Map<ServiceQueueKey, List<ServiceInfo>> getServiceKeyListMap(List<ServiceInfo> services) {
    final Map<ServiceQueueKey, List<ServiceInfo>> currentMap = new HashMap<>();
    services.forEach(serviceInfo -> {
        for (String serviceTypeStr : serviceInfo.getServiceTypesList()) {
            ServiceType serviceType = ServiceType.valueOf(serviceTypeStr.toUpperCase());
            if (ServiceType.TB_RULE_ENGINE.equals(serviceType)) {
                for (TransportProtos.QueueInfo queue : serviceInfo.getRuleEngineQueuesList()) {
                    ServiceQueueKey serviceQueueKey = new ServiceQueueKey(new ServiceQueue(serviceType, queue.getName()), getSystemOrIsolatedTenantId(serviceInfo));
                    currentMap.computeIfAbsent(serviceQueueKey, key -> new ArrayList<>()).add(serviceInfo);
                }
            } else {
                ServiceQueueKey serviceQueueKey = new ServiceQueueKey(new ServiceQueue(serviceType), getSystemOrIsolatedTenantId(serviceInfo));
                currentMap.computeIfAbsent(serviceQueueKey, key -> new ArrayList<>()).add(serviceInfo);
            }
        }
    });
    return currentMap;
}
Also used : ServiceQueue(org.thingsboard.server.common.msg.queue.ServiceQueue) ClusterTopologyChangeEvent(org.thingsboard.server.queue.discovery.event.ClusterTopologyChangeEvent) Hashing(com.google.common.hash.Hashing) HashMap(java.util.HashMap) QueueService(org.thingsboard.server.queue.QueueService) TenantId(org.thingsboard.server.common.data.id.TenantId) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) ServiceType(org.thingsboard.server.common.msg.queue.ServiceType) Service(org.springframework.stereotype.Service) ServiceQueueKey(org.thingsboard.server.common.msg.queue.ServiceQueueKey) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) EntityId(org.thingsboard.server.common.data.id.EntityId) Hasher(com.google.common.hash.Hasher) TbQueueRuleEngineSettings(org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings) ServiceInfo(org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo) ServiceListChangedEvent(org.thingsboard.server.queue.discovery.event.ServiceListChangedEvent) PartitionChangeEvent(org.thingsboard.server.queue.discovery.event.PartitionChangeEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) ServiceQueue(org.thingsboard.server.common.msg.queue.ServiceQueue) List(java.util.List) PostConstruct(javax.annotation.PostConstruct) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) HashFunction(com.google.common.hash.HashFunction) Comparator(java.util.Comparator) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) TopicPartitionInfo(org.thingsboard.server.common.msg.queue.TopicPartitionInfo) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ServiceType(org.thingsboard.server.common.msg.queue.ServiceType) ServiceQueueKey(org.thingsboard.server.common.msg.queue.ServiceQueueKey) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos)

Example 3 with ServiceType

use of org.thingsboard.server.common.msg.queue.ServiceType in project thingsboard by thingsboard.

the class HashPartitionService method addNode.

private void addNode(Map<ServiceQueueKey, List<ServiceInfo>> queueServiceList, ServiceInfo instance) {
    TenantId tenantId = getSystemOrIsolatedTenantId(instance);
    for (String serviceTypeStr : instance.getServiceTypesList()) {
        ServiceType serviceType = ServiceType.valueOf(serviceTypeStr.toUpperCase());
        if (ServiceType.TB_RULE_ENGINE.equals(serviceType)) {
            for (TransportProtos.QueueInfo queue : instance.getRuleEngineQueuesList()) {
                ServiceQueueKey serviceQueueKey = new ServiceQueueKey(new ServiceQueue(serviceType, queue.getName()), tenantId);
                partitionSizes.put(new ServiceQueue(ServiceType.TB_RULE_ENGINE, queue.getName()), queue.getPartitions());
                partitionTopics.put(new ServiceQueue(ServiceType.TB_RULE_ENGINE, queue.getName()), queue.getTopic());
                queueServiceList.computeIfAbsent(serviceQueueKey, key -> new ArrayList<>()).add(instance);
            }
        } else {
            ServiceQueueKey serviceQueueKey = new ServiceQueueKey(new ServiceQueue(serviceType), tenantId);
            queueServiceList.computeIfAbsent(serviceQueueKey, key -> new ArrayList<>()).add(instance);
        }
    }
    for (String transportType : instance.getTransportsList()) {
        tbTransportServicesByType.computeIfAbsent(transportType, t -> new ArrayList<>()).add(instance);
    }
}
Also used : ServiceQueue(org.thingsboard.server.common.msg.queue.ServiceQueue) ClusterTopologyChangeEvent(org.thingsboard.server.queue.discovery.event.ClusterTopologyChangeEvent) Hashing(com.google.common.hash.Hashing) HashMap(java.util.HashMap) QueueService(org.thingsboard.server.queue.QueueService) TenantId(org.thingsboard.server.common.data.id.TenantId) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) ServiceType(org.thingsboard.server.common.msg.queue.ServiceType) Service(org.springframework.stereotype.Service) ServiceQueueKey(org.thingsboard.server.common.msg.queue.ServiceQueueKey) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) EntityId(org.thingsboard.server.common.data.id.EntityId) Hasher(com.google.common.hash.Hasher) TbQueueRuleEngineSettings(org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings) ServiceInfo(org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo) ServiceListChangedEvent(org.thingsboard.server.queue.discovery.event.ServiceListChangedEvent) PartitionChangeEvent(org.thingsboard.server.queue.discovery.event.PartitionChangeEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) ServiceQueue(org.thingsboard.server.common.msg.queue.ServiceQueue) List(java.util.List) PostConstruct(javax.annotation.PostConstruct) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) HashFunction(com.google.common.hash.HashFunction) Comparator(java.util.Comparator) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) TopicPartitionInfo(org.thingsboard.server.common.msg.queue.TopicPartitionInfo) TenantId(org.thingsboard.server.common.data.id.TenantId) ServiceType(org.thingsboard.server.common.msg.queue.ServiceType) ServiceQueueKey(org.thingsboard.server.common.msg.queue.ServiceQueueKey) ArrayList(java.util.ArrayList) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos)

Example 4 with ServiceType

use of org.thingsboard.server.common.msg.queue.ServiceType in project thingsboard by thingsboard.

the class DefaultTbServiceInfoProvider method init.

@PostConstruct
public void init() {
    if (StringUtils.isEmpty(serviceId)) {
        try {
            serviceId = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            serviceId = org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(10);
        }
    }
    log.info("Current Service ID: {}", serviceId);
    if (serviceType.equalsIgnoreCase("monolith")) {
        serviceTypes = Collections.unmodifiableList(Arrays.asList(ServiceType.values()));
    } else {
        serviceTypes = Collections.singletonList(ServiceType.of(serviceType));
    }
    ServiceInfo.Builder builder = ServiceInfo.newBuilder().setServiceId(serviceId).addAllServiceTypes(serviceTypes.stream().map(ServiceType::name).collect(Collectors.toList()));
    UUID tenantId;
    if (!StringUtils.isEmpty(tenantIdStr)) {
        tenantId = UUID.fromString(tenantIdStr);
        isolatedTenant = TenantId.fromUUID(tenantId);
    } else {
        tenantId = TenantId.NULL_UUID;
    }
    builder.setTenantIdMSB(tenantId.getMostSignificantBits());
    builder.setTenantIdLSB(tenantId.getLeastSignificantBits());
    if (serviceTypes.contains(ServiceType.TB_RULE_ENGINE) && ruleEngineSettings != null) {
        for (TbRuleEngineQueueConfiguration queue : ruleEngineSettings.getQueues()) {
            TransportProtos.QueueInfo queueInfo = TransportProtos.QueueInfo.newBuilder().setName(queue.getName()).setTopic(queue.getTopic()).setPartitions(queue.getPartitions()).build();
            builder.addRuleEngineQueues(queueInfo);
        }
    }
    serviceInfo = builder.build();
}
Also used : ServiceInfo(org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo) UnknownHostException(java.net.UnknownHostException) ServiceType(org.thingsboard.server.common.msg.queue.ServiceType) TbRuleEngineQueueConfiguration(org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) UUID(java.util.UUID) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ServiceType (org.thingsboard.server.common.msg.queue.ServiceType)4 List (java.util.List)3 UUID (java.util.UUID)3 PostConstruct (javax.annotation.PostConstruct)3 Slf4j (lombok.extern.slf4j.Slf4j)3 EntityId (org.thingsboard.server.common.data.id.EntityId)3 TenantId (org.thingsboard.server.common.data.id.TenantId)3 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)3 ServiceInfo (org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo)3 HashFunction (com.google.common.hash.HashFunction)2 Hasher (com.google.common.hash.Hasher)2 Hashing (com.google.common.hash.Hashing)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2