@ -30,10 +30,10 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.transaction.event.TransactionalEventListener ;
import org.thingsboard.common.util.JacksonUtil ;
import org.thingsboard.server.common.data.DataConstants ;
import org.thingsboard.server.common.data.EntitySubtype ;
import org.thingsboard.server.common.data.EntityType ;
import org.thingsboard.server.common.data.StringUtils ;
import org.thingsboard.server.common.data.Tenant ;
import org.thingsboard.server.common.data.User ;
import org.thingsboard.server.common.data.audit.ActionType ;
import org.thingsboard.server.common.data.edge.Edge ;
@ -48,14 +48,15 @@ import org.thingsboard.server.common.data.id.RuleChainId;
import org.thingsboard.server.common.data.id.TenantId ;
import org.thingsboard.server.common.data.id.TenantProfileId ;
import org.thingsboard.server.common.data.id.UserId ;
import org.thingsboard.server.common.data.kv.KvEntry ;
import org.thingsboard.server.common.data.page.PageData ;
import org.thingsboard.server.common.data.page.PageDataIterable ;
import org.thingsboard.server.common.data.page.PageDataIterableByTenantIdEntityId ;
import org.thingsboard.server.common.data.page.PageLink ;
import org.thingsboard.server.common.data.relation.EntityRelation ;
import org.thingsboard.server.common.data.relation.EntitySearchDirection ;
import org.thingsboard.server.common.data.rule.RuleChain ;
import org.thingsboard.server.common.data.rule.RuleNode ;
import org.thingsboard.server.dao.attributes.AttributesService ;
import org.thingsboard.server.dao.entity.AbstractCachedEntityService ;
import org.thingsboard.server.dao.eventsourcing.ActionEntityEvent ;
import org.thingsboard.server.dao.exception.DataValidationException ;
@ -64,7 +65,7 @@ import org.thingsboard.server.dao.rule.RuleChainService;
import org.thingsboard.server.dao.service.DataValidator ;
import org.thingsboard.server.dao.service.PaginatedRemover ;
import org.thingsboard.server.dao.service.Validator ;
import org.thingsboard.server.dao.tenant.Tenant Service ;
import org.thingsboard.server.dao.timeseries.Timeseries Service ;
import org.thingsboard.server.dao.user.UserService ;
import javax.annotation.Nullable ;
@ -105,7 +106,10 @@ public class EdgeServiceImpl extends AbstractCachedEntityService<EdgeCacheKey, E
private RelationService relationService ;
@Autowired
private TenantService tenantService ;
private TimeseriesService timeseriesService ;
@Autowired
private AttributesService attributesService ;
@Autowired
private DataValidator < Edge > edgeValidator ;
@ -113,6 +117,8 @@ public class EdgeServiceImpl extends AbstractCachedEntityService<EdgeCacheKey, E
@Value ( "${edges.enabled}" )
@Getter
private boolean edgesEnabled ;
@Value ( "${edges.state.persistToTelemetry:false}" )
private boolean persistToTelemetry ;
@TransactionalEventListener ( classes = EdgeCacheEvictEvent . class )
@Override
@ -530,6 +536,18 @@ public class EdgeServiceImpl extends AbstractCachedEntityService<EdgeCacheKey, E
return result . toString ( ) ;
}
@Override
public ListenableFuture < Boolean > isEdgeActiveAsync ( TenantId tenantId , EdgeId edgeId , String key ) {
ListenableFuture < ? extends Optional < ? extends KvEntry > > futureKvEntry ;
if ( persistToTelemetry ) {
futureKvEntry = timeseriesService . findLatest ( tenantId , edgeId , key ) ;
} else {
futureKvEntry = attributesService . find ( tenantId , edgeId , DataConstants . SERVER_SCOPE , key ) ;
}
return Futures . transformAsync ( futureKvEntry , kvEntryOpt - >
Futures . immediateFuture ( kvEntryOpt . flatMap ( KvEntry : : getBooleanValue ) . orElse ( false ) ) , MoreExecutors . directExecutor ( ) ) ;
}
private List < RuleChain > findEdgeRuleChains ( TenantId tenantId , EdgeId edgeId ) {
List < RuleChain > result = new ArrayList < > ( ) ;
PageLink pageLink = new PageLink ( DEFAULT_PAGE_SIZE ) ;