|
|
|
@ -18,7 +18,9 @@ package org.thingsboard.server.service.script; |
|
|
|
import com.google.common.util.concurrent.Futures; |
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
|
import com.google.common.util.concurrent.MoreExecutors; |
|
|
|
import lombok.Getter; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.thingsboard.common.util.ThingsBoardThreadFactory; |
|
|
|
import org.thingsboard.server.common.data.ApiUsageRecordKey; |
|
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
|
@ -47,6 +49,16 @@ public abstract class AbstractJsInvokeService implements JsInvokeService { |
|
|
|
protected Map<UUID, String> scriptIdToNameMap = new ConcurrentHashMap<>(); |
|
|
|
protected Map<UUID, DisableListInfo> disabledFunctions = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
@Getter |
|
|
|
@Value("${js.max_total_args_size:100000}") |
|
|
|
private long maxTotalArgsSize; |
|
|
|
@Getter |
|
|
|
@Value("${js.max_result_size:300000}") |
|
|
|
private long maxResultSize; |
|
|
|
@Getter |
|
|
|
@Value("${js.max_script_body_size:50000}") |
|
|
|
private long maxScriptBodySize; |
|
|
|
|
|
|
|
protected AbstractJsInvokeService(TbApiUsageStateService apiUsageStateService, TbApiUsageClient apiUsageClient) { |
|
|
|
this.apiUsageStateService = apiUsageStateService; |
|
|
|
this.apiUsageClient = apiUsageClient; |
|
|
|
@ -134,12 +146,6 @@ public abstract class AbstractJsInvokeService implements JsInvokeService { |
|
|
|
|
|
|
|
protected abstract long getMaxBlacklistDuration(); |
|
|
|
|
|
|
|
protected abstract long getMaxTotalArgsSize(); |
|
|
|
|
|
|
|
protected abstract long getMaxResultSize(); |
|
|
|
|
|
|
|
protected abstract long getMaxScriptBodySize(); |
|
|
|
|
|
|
|
protected void onScriptExecutionError(UUID scriptId, Throwable t, String scriptBody) { |
|
|
|
DisableListInfo disableListInfo = disabledFunctions.computeIfAbsent(scriptId, key -> new DisableListInfo()); |
|
|
|
log.warn("Script has exception and will increment counter {} on disabledFunctions for id {}, exception {}, cause {}, scriptBody {}", |
|
|
|
|