Merge branch 'master' into edqs
This commit is contained in:
		
						commit
						9bbcef515d
					
				@ -644,6 +644,10 @@ public class ActorSystemContext {
 | 
			
		||||
    @Getter
 | 
			
		||||
    private String deviceStateNodeRateLimitConfig;
 | 
			
		||||
 | 
			
		||||
    @Value("${actors.calculated_fields.calculation_timeout:5}")
 | 
			
		||||
    @Getter
 | 
			
		||||
    private long cfCalculationResultTimeout;
 | 
			
		||||
 | 
			
		||||
    @Getter
 | 
			
		||||
    @Setter
 | 
			
		||||
    private TbActorSystem actorSystem;
 | 
			
		||||
 | 
			
		||||
@ -274,32 +274,30 @@ public class CalculatedFieldEntityMessageProcessor extends AbstractContextAwareM
 | 
			
		||||
 | 
			
		||||
    private void processStateIfReady(CalculatedFieldCtx ctx, List<CalculatedFieldId> cfIdList, CalculatedFieldState state, UUID tbMsgId, TbMsgType tbMsgType, TbCallback callback) throws CalculatedFieldException {
 | 
			
		||||
        CalculatedFieldEntityCtxId ctxId = new CalculatedFieldEntityCtxId(tenantId, ctx.getCfId(), entityId);
 | 
			
		||||
        boolean stateSizeOk;
 | 
			
		||||
        if (ctx.isInitialized() && state.isReady()) {
 | 
			
		||||
            try {
 | 
			
		||||
                CalculatedFieldResult calculationResult = state.performCalculation(ctx).get(5, TimeUnit.SECONDS);
 | 
			
		||||
        boolean stateSizeChecked = false;
 | 
			
		||||
        try {
 | 
			
		||||
            if (ctx.isInitialized() && state.isReady()) {
 | 
			
		||||
                CalculatedFieldResult calculationResult = state.performCalculation(ctx).get(systemContext.getCfCalculationResultTimeout(), TimeUnit.SECONDS);
 | 
			
		||||
                state.checkStateSize(ctxId, ctx.getMaxStateSize());
 | 
			
		||||
                stateSizeOk = state.isSizeOk();
 | 
			
		||||
                if (stateSizeOk) {
 | 
			
		||||
                stateSizeChecked = true;
 | 
			
		||||
                if (state.isSizeOk()) {
 | 
			
		||||
                    cfService.pushMsgToRuleEngine(tenantId, entityId, calculationResult, cfIdList, callback);
 | 
			
		||||
                    if (DebugModeUtil.isDebugAllAvailable(ctx.getCalculatedField())) {
 | 
			
		||||
                        systemContext.persistCalculatedFieldDebugEvent(tenantId, ctx.getCfId(), entityId, state.getArguments(), tbMsgId, tbMsgType, JacksonUtil.writeValueAsString(calculationResult.getResult()), null);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                throw CalculatedFieldException.builder().ctx(ctx).eventEntity(entityId).msgId(tbMsgId).msgType(tbMsgType).arguments(state.getArguments()).cause(e).build();
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            state.checkStateSize(ctxId, ctx.getMaxStateSize());
 | 
			
		||||
            stateSizeOk = state.isSizeOk();
 | 
			
		||||
            if (stateSizeOk) {
 | 
			
		||||
                callback.onSuccess(); // State was updated but no calculation performed;
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw CalculatedFieldException.builder().ctx(ctx).eventEntity(entityId).msgId(tbMsgId).msgType(tbMsgType).arguments(state.getArguments()).cause(e).build();
 | 
			
		||||
        } finally {
 | 
			
		||||
            if (!stateSizeChecked) {
 | 
			
		||||
                state.checkStateSize(ctxId, ctx.getMaxStateSize());
 | 
			
		||||
            }
 | 
			
		||||
            if (state.isSizeOk()) {
 | 
			
		||||
                cfStateService.persistState(ctxId, state, callback);
 | 
			
		||||
            } else {
 | 
			
		||||
                removeStateAndRaiseSizeException(ctxId, CalculatedFieldException.builder().ctx(ctx).eventEntity(entityId).errorMessage(ctx.getSizeExceedsLimitMessage()).build(), callback);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (stateSizeOk) {
 | 
			
		||||
            cfStateService.persistState(ctxId, state, callback);
 | 
			
		||||
        } else {
 | 
			
		||||
            removeStateAndRaiseSizeException(ctxId, CalculatedFieldException.builder().ctx(ctx).eventEntity(entityId).errorMessage(ctx.getSizeExceedsLimitMessage()).build(), callback);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -100,10 +100,6 @@ public class SingleValueArgumentEntry implements ArgumentEntry {
 | 
			
		||||
            if (newVersion == null || this.version == null || newVersion > this.version) {
 | 
			
		||||
                this.ts = singleValueEntry.getTs();
 | 
			
		||||
                this.version = newVersion;
 | 
			
		||||
                BasicKvEntry newValue = singleValueEntry.getKvEntryValue();
 | 
			
		||||
                if (this.kvEntryValue != null && this.kvEntryValue.getValue().equals(newValue.getValue())) {
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
                this.kvEntryValue = singleValueEntry.getKvEntryValue();
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@ -436,7 +436,9 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc
 | 
			
		||||
                ctx.sendWsMsg(update);
 | 
			
		||||
            } else {
 | 
			
		||||
                ctx.doFetchAlarmCount();
 | 
			
		||||
                ctx.createAlarmSubscriptions();
 | 
			
		||||
                if (entitiesIds != null) {
 | 
			
		||||
                    ctx.createAlarmSubscriptions();
 | 
			
		||||
                }
 | 
			
		||||
                TbAlarmCountSubCtx finalCtx = ctx;
 | 
			
		||||
                ScheduledFuture<?> task = scheduler.scheduleWithFixedDelay(
 | 
			
		||||
                        () -> refreshDynamicQuery(finalCtx),
 | 
			
		||||
 | 
			
		||||
@ -512,6 +512,8 @@ actors:
 | 
			
		||||
      enabled: "${ACTORS_CALCULATED_FIELD_DEBUG_MODE_RATE_LIMITS_PER_TENANT_ENABLED:true}"
 | 
			
		||||
      # The value of DEBUG mode rate limit. By default, no more than 50 thousand events per hour
 | 
			
		||||
      configuration: "${ACTORS_CALCULATED_FIELD_DEBUG_MODE_RATE_LIMITS_PER_TENANT_CONFIGURATION:50000:3600}"
 | 
			
		||||
    # Time in seconds to receive calculation result.
 | 
			
		||||
    calculation_timeout: "${ACTORS_CALCULATION_TIMEOUT_SEC:5}"
 | 
			
		||||
 | 
			
		||||
debug:
 | 
			
		||||
  settings:
 | 
			
		||||
 | 
			
		||||
@ -83,7 +83,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
 | 
			
		||||
@Slf4j
 | 
			
		||||
@DaoSqlTest
 | 
			
		||||
@TestPropertySource(properties = {
 | 
			
		||||
        "server.ws.alarms_per_alarm_status_subscription_cache_size=5"
 | 
			
		||||
        "server.ws.alarms_per_alarm_status_subscription_cache_size=5",
 | 
			
		||||
        "server.ws.dynamic_page_link.refresh_interval=15"
 | 
			
		||||
})
 | 
			
		||||
public class WebsocketApiTest extends AbstractControllerTest {
 | 
			
		||||
    @Autowired
 | 
			
		||||
 | 
			
		||||
@ -71,6 +71,6 @@ public class SingleValueArgumentEntryTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testUpdateEntryWhenValueWasNotChanged() {
 | 
			
		||||
        assertThat(entry.updateEntry(new SingleValueArgumentEntry(ts + 18, new LongDataEntry("key", 11L), 237L))).isFalse();
 | 
			
		||||
        assertThat(entry.updateEntry(new SingleValueArgumentEntry(ts + 18, new LongDataEntry("key", 11L), 364L))).isTrue();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user