fixed test script
This commit is contained in:
parent
baf0e948db
commit
a0331655d1
@ -132,6 +132,7 @@ import org.thingsboard.server.service.state.DeviceStateService;
|
|||||||
import org.thingsboard.server.service.telemetry.AlarmSubscriptionService;
|
import org.thingsboard.server.service.telemetry.AlarmSubscriptionService;
|
||||||
import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService;
|
import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService;
|
||||||
import org.thingsboard.server.service.transport.TbCoreToTransportService;
|
import org.thingsboard.server.service.transport.TbCoreToTransportService;
|
||||||
|
import org.thingsboard.server.utils.DebugModeRateLimitsConfig;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
@ -453,10 +454,15 @@ public class ActorSystemContext {
|
|||||||
private ApiLimitService apiLimitService;
|
private ApiLimitService apiLimitService;
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@Autowired()
|
@Autowired(required = false)
|
||||||
@Getter
|
@Getter
|
||||||
private RateLimitService rateLimitService;
|
private RateLimitService rateLimitService;
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
@Autowired(required = false)
|
||||||
|
@Getter
|
||||||
|
private DebugModeRateLimitsConfig debugModeRateLimitsConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The following Service will be null if we operate in tb-core mode
|
* The following Service will be null if we operate in tb-core mode
|
||||||
*/
|
*/
|
||||||
@ -614,22 +620,6 @@ public class ActorSystemContext {
|
|||||||
@Getter
|
@Getter
|
||||||
private long sessionReportTimeout;
|
private long sessionReportTimeout;
|
||||||
|
|
||||||
@Value("${actors.rule.chain.debug_mode_rate_limits_per_tenant.enabled:true}")
|
|
||||||
@Getter
|
|
||||||
private boolean debugPerTenantEnabled;
|
|
||||||
|
|
||||||
@Value("${actors.rule.chain.debug_mode_rate_limits_per_tenant.configuration:50000:3600}")
|
|
||||||
@Getter
|
|
||||||
private String debugPerTenantLimitsConfiguration;
|
|
||||||
|
|
||||||
@Value("${actors.calculated_fields.debug_mode_rate_limits_per_tenant.enabled:true}")
|
|
||||||
@Getter
|
|
||||||
private boolean calculatedFieldsDebugPerTenantEnabled;
|
|
||||||
|
|
||||||
@Value("${actors.calculated_fields.debug_mode_rate_limits_per_tenant.configuration:50000:3600}")
|
|
||||||
@Getter
|
|
||||||
private String calculatedFieldsDebugPerTenantLimitsConfiguration;
|
|
||||||
|
|
||||||
@Value("${actors.rpc.submit_strategy:BURST}")
|
@Value("${actors.rpc.submit_strategy:BURST}")
|
||||||
@Getter
|
@Getter
|
||||||
private String rpcSubmitStrategy;
|
private String rpcSubmitStrategy;
|
||||||
@ -783,9 +773,9 @@ public class ActorSystemContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkLimits(TenantId tenantId, TbMsg tbMsg, Throwable error) {
|
private boolean checkLimits(TenantId tenantId, TbMsg tbMsg, Throwable error) {
|
||||||
if (debugPerTenantEnabled) {
|
if (debugModeRateLimitsConfig.isRuleChainDebugPerTenantLimitsEnabled()) {
|
||||||
DebugTbRateLimits debugTbRateLimits = debugPerTenantLimits.computeIfAbsent(tenantId, id ->
|
DebugTbRateLimits debugTbRateLimits = debugPerTenantLimits.computeIfAbsent(tenantId, id ->
|
||||||
new DebugTbRateLimits(new TbRateLimits(debugPerTenantLimitsConfiguration), false));
|
new DebugTbRateLimits(new TbRateLimits(debugModeRateLimitsConfig.getRuleChainDebugPerTenantLimitsConfiguration()), false));
|
||||||
|
|
||||||
if (!debugTbRateLimits.getTbRateLimits().tryConsume()) {
|
if (!debugTbRateLimits.getTbRateLimits().tryConsume()) {
|
||||||
if (!debugTbRateLimits.isRuleChainEventSaved()) {
|
if (!debugTbRateLimits.isRuleChainEventSaved()) {
|
||||||
@ -852,8 +842,8 @@ public class ActorSystemContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkLimits(TenantId tenantId) {
|
private boolean checkLimits(TenantId tenantId) {
|
||||||
if (calculatedFieldsDebugPerTenantEnabled &&
|
if (debugModeRateLimitsConfig.isCalculatedFieldDebugPerTenantLimitsEnabled() &&
|
||||||
!rateLimitService.checkRateLimit(LimitedApi.CALCULATED_FIELD_DEBUG_EVENTS, (Object) tenantId, calculatedFieldsDebugPerTenantLimitsConfiguration)) {
|
!rateLimitService.checkRateLimit(LimitedApi.CALCULATED_FIELD_DEBUG_EVENTS, (Object) tenantId, debugModeRateLimitsConfig.getCalculatedFieldDebugPerTenantLimitsConfiguration())) {
|
||||||
log.trace("[{}] Calculated field debug event limits exceeded!", tenantId);
|
log.trace("[{}] Calculated field debug event limits exceeded!", tenantId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.thingsboard.common.util.JacksonUtil;
|
import org.thingsboard.common.util.JacksonUtil;
|
||||||
|
import org.thingsboard.script.api.tbel.TbelCfArg;
|
||||||
import org.thingsboard.script.api.tbel.TbelInvokeService;
|
import org.thingsboard.script.api.tbel.TbelInvokeService;
|
||||||
import org.thingsboard.server.common.data.cf.CalculatedField;
|
import org.thingsboard.server.common.data.cf.CalculatedField;
|
||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
@ -84,9 +85,15 @@ public class CalculatedFieldController extends BaseController {
|
|||||||
private static final String TEST_SCRIPT_EXPRESSION = "Execute the Script expression and return the result. The format of request: \n\n"
|
private static final String TEST_SCRIPT_EXPRESSION = "Execute the Script expression and return the result. The format of request: \n\n"
|
||||||
+ MARKDOWN_CODE_BLOCK_START
|
+ MARKDOWN_CODE_BLOCK_START
|
||||||
+ "{\n" +
|
+ "{\n" +
|
||||||
" \"expression\": \"var temp = 0; foreach(element: temperature.values) {temp += element.value;} var avgTemperature = temp / temperature.values.size(); var adjustedTemperature = avgTemperature + 0.1 * humidity.value; return {\"adjustedTemperature\": adjustedTemperature};\",\n" +
|
" \"expression\": \"var temp = 0; foreach(element: temperature.values) {temp += element.value;} var avgTemperature = temp / temperature.values.size(); var adjustedTemperature = avgTemperature + 0.1 * humidity.value; return {\\\"adjustedTemperature\\\": adjustedTemperature};\",\n" +
|
||||||
" \"arguments\": {\n" +
|
" \"arguments\": {\n" +
|
||||||
" \"temperature\": {\n" +
|
" \"temperature\": {\n" +
|
||||||
|
" \"type\": \"TS_ROLLING\",\n" +
|
||||||
|
" \"timeWindow\": {\n" +
|
||||||
|
" \"startTs\": 1739775630002,\n" +
|
||||||
|
" \"endTs\": 65432211,\n" +
|
||||||
|
" \"limit\": 5\n" +
|
||||||
|
" },\n" +
|
||||||
" \"values\": [\n" +
|
" \"values\": [\n" +
|
||||||
" { \"ts\": 1739775639851, \"value\": 23 },\n" +
|
" { \"ts\": 1739775639851, \"value\": 23 },\n" +
|
||||||
" { \"ts\": 1739775664561, \"value\": 43 },\n" +
|
" { \"ts\": 1739775664561, \"value\": 43 },\n" +
|
||||||
@ -95,7 +102,7 @@ public class CalculatedFieldController extends BaseController {
|
|||||||
" { \"ts\": 1739776228452, \"value\": 22 }\n" +
|
" { \"ts\": 1739776228452, \"value\": 22 }\n" +
|
||||||
" ]\n" +
|
" ]\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
" \"humidity\": { \"ts\": 1739776478057, \"value\": 23 }\n" +
|
" \"humidity\": { \"type\": \"SINGLE_VALUE\", \"ts\": 1739776478057, \"value\": 23 }\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
"}"
|
"}"
|
||||||
+ MARKDOWN_CODE_BLOCK_END
|
+ MARKDOWN_CODE_BLOCK_END
|
||||||
@ -176,8 +183,8 @@ public class CalculatedFieldController extends BaseController {
|
|||||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "Test calculated field TBEL expression.")
|
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "Test calculated field TBEL expression.")
|
||||||
@RequestBody JsonNode inputParams) {
|
@RequestBody JsonNode inputParams) {
|
||||||
String expression = inputParams.get("expression").asText();
|
String expression = inputParams.get("expression").asText();
|
||||||
Map<String, Object> arguments = Objects.requireNonNullElse(
|
Map<String, TbelCfArg> arguments = Objects.requireNonNullElse(
|
||||||
JacksonUtil.convertValue(inputParams.get("arguments"), new TypeReference<Map<String, Object>>() {
|
JacksonUtil.convertValue(inputParams.get("arguments"), new TypeReference<Map<String, TbelCfArg>>() {
|
||||||
}),
|
}),
|
||||||
Collections.emptyMap()
|
Collections.emptyMap()
|
||||||
);
|
);
|
||||||
|
|||||||
@ -46,6 +46,7 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
|
|||||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||||
import org.thingsboard.server.service.security.model.UserPrincipal;
|
import org.thingsboard.server.service.security.model.UserPrincipal;
|
||||||
import org.thingsboard.server.service.sync.vc.EntitiesVersionControlService;
|
import org.thingsboard.server.service.sync.vc.EntitiesVersionControlService;
|
||||||
|
import org.thingsboard.server.utils.DebugModeRateLimitsConfig;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -74,18 +75,6 @@ public class SystemInfoController extends BaseController {
|
|||||||
@Value("${debug.settings.default_duration:15}")
|
@Value("${debug.settings.default_duration:15}")
|
||||||
private int defaultDebugDurationMinutes;
|
private int defaultDebugDurationMinutes;
|
||||||
|
|
||||||
@Value("${actors.rule.chain.debug_mode_rate_limits_per_tenant.enabled:true}")
|
|
||||||
private boolean ruleChainDebugPerTenantLimitsEnabled;
|
|
||||||
|
|
||||||
@Value("${actors.rule.chain.debug_mode_rate_limits_per_tenant.configuration:50000:3600}")
|
|
||||||
private String ruleChainDebugPerTenantLimitsConfiguration;
|
|
||||||
|
|
||||||
@Value("${actors.calculated_fields.debug_mode_rate_limits_per_tenant.enabled:true}")
|
|
||||||
private boolean calculatedFieldDebugPerTenantLimitsEnabled;
|
|
||||||
|
|
||||||
@Value("${actors.calculated_fields.debug_mode_rate_limits_per_tenant.configuration:50000:3600}")
|
|
||||||
private String calculatedFieldDebugPerTenantLimitsConfiguration;
|
|
||||||
|
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private BuildProperties buildProperties;
|
private BuildProperties buildProperties;
|
||||||
|
|
||||||
@ -95,6 +84,9 @@ public class SystemInfoController extends BaseController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private QrCodeSettingService qrCodeSettingService;
|
private QrCodeSettingService qrCodeSettingService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DebugModeRateLimitsConfig debugModeRateLimitsConfig;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
JsonNode info = buildInfoObject();
|
JsonNode info = buildInfoObject();
|
||||||
@ -158,11 +150,11 @@ public class SystemInfoController extends BaseController {
|
|||||||
DefaultTenantProfileConfiguration tenantProfileConfiguration = tenantProfileCache.get(tenantId).getDefaultProfileConfiguration();
|
DefaultTenantProfileConfiguration tenantProfileConfiguration = tenantProfileCache.get(tenantId).getDefaultProfileConfiguration();
|
||||||
systemParams.setMaxResourceSize(tenantProfileConfiguration.getMaxResourceSize());
|
systemParams.setMaxResourceSize(tenantProfileConfiguration.getMaxResourceSize());
|
||||||
systemParams.setMaxDebugModeDurationMinutes(DebugModeUtil.getMaxDebugAllDuration(tenantProfileConfiguration.getMaxDebugModeDurationMinutes(), defaultDebugDurationMinutes));
|
systemParams.setMaxDebugModeDurationMinutes(DebugModeUtil.getMaxDebugAllDuration(tenantProfileConfiguration.getMaxDebugModeDurationMinutes(), defaultDebugDurationMinutes));
|
||||||
if (ruleChainDebugPerTenantLimitsEnabled) {
|
if (debugModeRateLimitsConfig.isRuleChainDebugPerTenantLimitsEnabled()) {
|
||||||
systemParams.setRuleChainDebugPerTenantLimitsConfiguration(ruleChainDebugPerTenantLimitsConfiguration);
|
systemParams.setRuleChainDebugPerTenantLimitsConfiguration(debugModeRateLimitsConfig.getRuleChainDebugPerTenantLimitsConfiguration());
|
||||||
}
|
}
|
||||||
if (calculatedFieldDebugPerTenantLimitsEnabled) {
|
if (debugModeRateLimitsConfig.isCalculatedFieldDebugPerTenantLimitsEnabled()) {
|
||||||
systemParams.setCalculatedFieldDebugPerTenantLimitsConfiguration(calculatedFieldDebugPerTenantLimitsConfiguration);
|
systemParams.setCalculatedFieldDebugPerTenantLimitsConfiguration(debugModeRateLimitsConfig.getCalculatedFieldDebugPerTenantLimitsConfiguration());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
systemParams.setMobileQrEnabled(Optional.ofNullable(qrCodeSettingService.findQrCodeSettings(TenantId.SYS_TENANT_ID))
|
systemParams.setMobileQrEnabled(Optional.ofNullable(qrCodeSettingService.findQrCodeSettings(TenantId.SYS_TENANT_ID))
|
||||||
|
|||||||
@ -82,8 +82,7 @@ public class TsRollingArgumentEntry implements ArgumentEntry {
|
|||||||
for (var e : tsRecords.entrySet()) {
|
for (var e : tsRecords.entrySet()) {
|
||||||
values.add(new TbelCfTsDoubleVal(e.getKey(), e.getValue()));
|
values.add(new TbelCfTsDoubleVal(e.getKey(), e.getValue()));
|
||||||
}
|
}
|
||||||
long ts = System.currentTimeMillis();
|
return new TbelCfTsRollingArg(limit, timeWindow, values);
|
||||||
return new TbelCfTsRollingArg(ts - timeWindow, ts, values);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2024 The Thingsboard Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.thingsboard.server.utils;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Data
|
||||||
|
public class DebugModeRateLimitsConfig {
|
||||||
|
|
||||||
|
@Value("${actors.rule.chain.debug_mode_rate_limits_per_tenant.enabled:true}")
|
||||||
|
private boolean ruleChainDebugPerTenantLimitsEnabled;
|
||||||
|
@Value("${actors.rule.chain.debug_mode_rate_limits_per_tenant.configuration:50000:3600}")
|
||||||
|
private String ruleChainDebugPerTenantLimitsConfiguration;
|
||||||
|
|
||||||
|
@Value("${actors.calculated_fields.debug_mode_rate_limits_per_tenant.enabled:true}")
|
||||||
|
private boolean calculatedFieldDebugPerTenantLimitsEnabled;
|
||||||
|
@Value("${actors.calculated_fields.debug_mode_rate_limits_per_tenant.configuration:50000:3600}")
|
||||||
|
private String calculatedFieldDebugPerTenantLimitsConfiguration;
|
||||||
|
|
||||||
|
}
|
||||||
@ -136,6 +136,7 @@ public class DefaultTbelInvokeService extends AbstractScriptInvokeService implem
|
|||||||
parserConfig.registerDataType("TbelCfSingleValueArg", TbelCfSingleValueArg.class, TbelCfSingleValueArg::memorySize);
|
parserConfig.registerDataType("TbelCfSingleValueArg", TbelCfSingleValueArg.class, TbelCfSingleValueArg::memorySize);
|
||||||
parserConfig.registerDataType("TbelCfTsRollingArg", TbelCfTsRollingArg.class, TbelCfTsRollingArg::memorySize);
|
parserConfig.registerDataType("TbelCfTsRollingArg", TbelCfTsRollingArg.class, TbelCfTsRollingArg::memorySize);
|
||||||
parserConfig.registerDataType("TbelCfTsDoubleVal", TbelCfTsDoubleVal.class, TbelCfTsDoubleVal::memorySize);
|
parserConfig.registerDataType("TbelCfTsDoubleVal", TbelCfTsDoubleVal.class, TbelCfTsDoubleVal::memorySize);
|
||||||
|
parserConfig.registerDataType("TbTimeWindow", TbTimeWindow.class, TbTimeWindow::memorySize);
|
||||||
TbUtils.register(parserConfig);
|
TbUtils.register(parserConfig);
|
||||||
executor = MoreExecutors.listeningDecorator(ThingsBoardExecutors.newWorkStealingPool(threadPoolSize, "tbel-executor"));
|
executor = MoreExecutors.listeningDecorator(ThingsBoardExecutors.newWorkStealingPool(threadPoolSize, "tbel-executor"));
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2024 The Thingsboard Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.thingsboard.script.api.tbel;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class TbTimeWindow implements TbelCfObject {
|
||||||
|
|
||||||
|
public static final long OBJ_SIZE = 32L;
|
||||||
|
|
||||||
|
private long startTs;
|
||||||
|
private long endTs;
|
||||||
|
private int limit;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long memorySize() {
|
||||||
|
return OBJ_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -15,6 +15,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.script.api.tbel;
|
package org.thingsboard.script.api.tbel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
|
|
||||||
|
@JsonTypeInfo(
|
||||||
|
use = JsonTypeInfo.Id.NAME,
|
||||||
|
include = JsonTypeInfo.As.PROPERTY,
|
||||||
|
property = "type"
|
||||||
|
)
|
||||||
|
@JsonSubTypes({
|
||||||
|
@JsonSubTypes.Type(value = TbelCfSingleValueArg.class, name = "SINGLE_VALUE"),
|
||||||
|
@JsonSubTypes.Type(value = TbelCfTsRollingArg.class, name = "TS_ROLLING")
|
||||||
|
})
|
||||||
public interface TbelCfArg extends TbelCfObject {
|
public interface TbelCfArg extends TbelCfObject {
|
||||||
|
|
||||||
|
String getType();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.script.api.tbel;
|
package org.thingsboard.script.api.tbel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ -23,9 +25,23 @@ public class TbelCfSingleValueArg implements TbelCfArg {
|
|||||||
private final long ts;
|
private final long ts;
|
||||||
private final Object value;
|
private final Object value;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public TbelCfSingleValueArg(
|
||||||
|
@JsonProperty("ts") long ts,
|
||||||
|
@JsonProperty("value") Object value
|
||||||
|
) {
|
||||||
|
this.ts = ts;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long memorySize() {
|
public long memorySize() {
|
||||||
return 8L; // TODO;
|
return 8L; // TODO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "SINGLE_VALUE";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.script.api.tbel;
|
package org.thingsboard.script.api.tbel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -28,15 +30,22 @@ import static org.thingsboard.script.api.tbel.TbelCfTsDoubleVal.OBJ_SIZE;
|
|||||||
public class TbelCfTsRollingArg implements TbelCfArg, Iterable<TbelCfTsDoubleVal> {
|
public class TbelCfTsRollingArg implements TbelCfArg, Iterable<TbelCfTsDoubleVal> {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final long startTs;
|
private final TbTimeWindow timeWindow;
|
||||||
@Getter
|
|
||||||
private final long endTs;
|
|
||||||
@Getter
|
@Getter
|
||||||
private final List<TbelCfTsDoubleVal> values;
|
private final List<TbelCfTsDoubleVal> values;
|
||||||
|
|
||||||
public TbelCfTsRollingArg(long startTs, long endTs, List<TbelCfTsDoubleVal> values) {
|
@JsonCreator
|
||||||
this.startTs = startTs;
|
public TbelCfTsRollingArg(
|
||||||
this.endTs = endTs;
|
@JsonProperty("timeWindow") TbTimeWindow timeWindow,
|
||||||
|
@JsonProperty("values") List<TbelCfTsDoubleVal> values
|
||||||
|
) {
|
||||||
|
this.timeWindow = timeWindow;
|
||||||
|
this.values = Collections.unmodifiableList(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TbelCfTsRollingArg(int limit, long timeWindow, List<TbelCfTsDoubleVal> values) {
|
||||||
|
long ts = System.currentTimeMillis();
|
||||||
|
this.timeWindow = new TbTimeWindow(ts - timeWindow, ts, limit);
|
||||||
this.values = Collections.unmodifiableList(values);
|
this.values = Collections.unmodifiableList(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,4 +85,9 @@ public class TbelCfTsRollingArg implements TbelCfArg, Iterable<TbelCfTsDoubleVal
|
|||||||
values.forEach(action);
|
values.forEach(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "TS_ROLLING";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user