Showing
4 changed files
with
84 additions
and
30 deletions
@@ -143,28 +143,29 @@ public class ZkDiscoveryService implements DiscoveryService, PathChildrenCacheLi | @@ -143,28 +143,29 @@ public class ZkDiscoveryService implements DiscoveryService, PathChildrenCacheLi | ||
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | - private boolean reconnectInProgress = false; | ||
147 | - | ||
148 | - private synchronized ConnectionStateListener checkReconnect(ServerInstance self) { | 146 | + private ConnectionStateListener checkReconnect(ServerInstance self) { |
149 | return (client, newState) -> { | 147 | return (client, newState) -> { |
150 | log.info("[{}:{}] ZK state changed: {}", self.getHost(), self.getPort(), newState); | 148 | log.info("[{}:{}] ZK state changed: {}", self.getHost(), self.getPort(), newState); |
151 | if (newState == ConnectionState.LOST) { | 149 | if (newState == ConnectionState.LOST) { |
152 | - if (!reconnectInProgress) { | ||
153 | - reconnectInProgress = true; | ||
154 | - reconnect(); | ||
155 | - } | 150 | + reconnect(); |
156 | } | 151 | } |
157 | }; | 152 | }; |
158 | } | 153 | } |
159 | 154 | ||
160 | - private void reconnect() { | ||
161 | - try { | ||
162 | - client.blockUntilConnected(); | ||
163 | - } catch (InterruptedException e) { | ||
164 | - log.error("Failed to reconnect to ZK: {}", e.getMessage(), e); | 155 | + private boolean reconnectInProgress = false; |
156 | + | ||
157 | + private synchronized void reconnect() { | ||
158 | + if (!reconnectInProgress) { | ||
159 | + reconnectInProgress = true; | ||
160 | + try { | ||
161 | + client.blockUntilConnected(); | ||
162 | + publishCurrentServer(); | ||
163 | + } catch (InterruptedException e) { | ||
164 | + log.error("Failed to reconnect to ZK: {}", e.getMessage(), e); | ||
165 | + } finally { | ||
166 | + reconnectInProgress = false; | ||
167 | + } | ||
165 | } | 168 | } |
166 | - publishCurrentServer(); | ||
167 | - reconnectInProgress = false; | ||
168 | } | 169 | } |
169 | 170 | ||
170 | @Override | 171 | @Override |
@@ -18,22 +18,24 @@ package org.thingsboard.server.service.script; | @@ -18,22 +18,24 @@ package org.thingsboard.server.service.script; | ||
18 | 18 | ||
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
20 | import org.springframework.beans.factory.annotation.Value; | 20 | import org.springframework.beans.factory.annotation.Value; |
21 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
21 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
22 | 23 | ||
23 | @Slf4j | 24 | @Slf4j |
25 | +@ConditionalOnProperty(prefix = "js", value = "evaluator", havingValue = "local", matchIfMissing = true) | ||
24 | @Service | 26 | @Service |
25 | public class NashornJsInvokeService extends AbstractNashornJsInvokeService { | 27 | public class NashornJsInvokeService extends AbstractNashornJsInvokeService { |
26 | 28 | ||
27 | - @Value("${actors.rule.js_sandbox.use_js_sandbox}") | 29 | + @Value("${js.local.use_js_sandbox}") |
28 | private boolean useJsSandbox; | 30 | private boolean useJsSandbox; |
29 | 31 | ||
30 | - @Value("${actors.rule.js_sandbox.monitor_thread_pool_size}") | 32 | + @Value("${js.local.js_sandbox.monitor_thread_pool_size}") |
31 | private int monitorThreadPoolSize; | 33 | private int monitorThreadPoolSize; |
32 | 34 | ||
33 | - @Value("${actors.rule.js_sandbox.max_cpu_time}") | 35 | + @Value("${js.local.js_sandbox.max_cpu_time}") |
34 | private long maxCpuTime; | 36 | private long maxCpuTime; |
35 | 37 | ||
36 | - @Value("${actors.rule.js_sandbox.max_errors}") | 38 | + @Value("${js.local.js_sandbox.max_errors}") |
37 | private int maxErrors; | 39 | private int maxErrors; |
38 | 40 | ||
39 | @Override | 41 | @Override |
application/src/main/java/org/thingsboard/server/service/script/RemoteJsInvokeService.java
0 → 100644
1 | +/** | ||
2 | + * Copyright © 2016-2018 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.service.script; | ||
17 | + | ||
18 | +import com.google.common.util.concurrent.ListenableFuture; | ||
19 | +import lombok.extern.slf4j.Slf4j; | ||
20 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
21 | +import org.springframework.stereotype.Service; | ||
22 | +import org.thingsboard.server.common.data.id.EntityId; | ||
23 | + | ||
24 | +import java.util.UUID; | ||
25 | + | ||
26 | +@Slf4j | ||
27 | +@ConditionalOnProperty(prefix = "js", value = "evaluator", havingValue = "local", matchIfMissing = true) | ||
28 | +@Service | ||
29 | +public class RemoteJsInvokeService implements JsInvokeService { | ||
30 | + | ||
31 | + @Override | ||
32 | + public ListenableFuture<UUID> eval(JsScriptType scriptType, String scriptBody, String... argNames) { | ||
33 | + return null; | ||
34 | + } | ||
35 | + | ||
36 | + @Override | ||
37 | + public ListenableFuture<Object> invokeFunction(UUID scriptId, EntityId entityId, Object... args) { | ||
38 | + return null; | ||
39 | + } | ||
40 | + | ||
41 | + @Override | ||
42 | + public ListenableFuture<Void> release(UUID scriptId, EntityId entityId) { | ||
43 | + return null; | ||
44 | + } | ||
45 | + | ||
46 | +} |
@@ -246,15 +246,6 @@ actors: | @@ -246,15 +246,6 @@ actors: | ||
246 | allow_system_mail_service: "${ACTORS_RULE_ALLOW_SYSTEM_MAIL_SERVICE:true}" | 246 | allow_system_mail_service: "${ACTORS_RULE_ALLOW_SYSTEM_MAIL_SERVICE:true}" |
247 | # Specify thread pool size for external call service | 247 | # Specify thread pool size for external call service |
248 | external_call_thread_pool_size: "${ACTORS_RULE_EXTERNAL_CALL_THREAD_POOL_SIZE:10}" | 248 | external_call_thread_pool_size: "${ACTORS_RULE_EXTERNAL_CALL_THREAD_POOL_SIZE:10}" |
249 | - js_sandbox: | ||
250 | - # Use Sandboxed (secured) JavaScript environment | ||
251 | - use_js_sandbox: "${ACTORS_RULE_JS_SANDBOX_USE_JS_SANDBOX:true}" | ||
252 | - # Specify thread pool size for JavaScript sandbox resource monitor | ||
253 | - monitor_thread_pool_size: "${ACTORS_RULE_JS_SANDBOX_MONITOR_THREAD_POOL_SIZE:4}" | ||
254 | - # Maximum CPU time in milliseconds allowed for script execution | ||
255 | - max_cpu_time: "${ACTORS_RULE_JS_SANDBOX_MAX_CPU_TIME:100}" | ||
256 | - # Maximum allowed JavaScript execution errors before JavaScript will be blacklisted | ||
257 | - max_errors: "${ACTORS_RULE_JS_SANDBOX_MAX_ERRORS:3}" | ||
258 | chain: | 249 | chain: |
259 | # Errors for particular actor are persisted once per specified amount of milliseconds | 250 | # Errors for particular actor are persisted once per specified amount of milliseconds |
260 | error_persist_frequency: "${ACTORS_RULE_CHAIN_ERROR_FREQUENCY:3000}" | 251 | error_persist_frequency: "${ACTORS_RULE_CHAIN_ERROR_FREQUENCY:3000}" |
@@ -413,6 +404,20 @@ audit_log: | @@ -413,6 +404,20 @@ audit_log: | ||
413 | state: | 404 | state: |
414 | defaultInactivityTimeoutInSec: 10 | 405 | defaultInactivityTimeoutInSec: 10 |
415 | defaultStateCheckIntervalInSec: 10 | 406 | defaultStateCheckIntervalInSec: 10 |
416 | -# TODO in v2.1 | ||
417 | -# defaultStatePersistenceIntervalInSec: 60 | ||
418 | -# defaultStatePersistencePack: 100 | ||
407 | + | ||
408 | +js: | ||
409 | + evaluator: "${JS_EVALUATOR:external}" # local/external | ||
410 | + # Built-in JVM JavaScript environment properties | ||
411 | + local: | ||
412 | + # Use Sandboxed (secured) JVM JavaScript environment | ||
413 | + use_js_sandbox: "${USE_LOCAL_JS_SANDBOX:true}" | ||
414 | + # Specify thread pool size for JavaScript sandbox resource monitor | ||
415 | + monitor_thread_pool_size: "${LOCAL_JS_SANDBOX_MONITOR_THREAD_POOL_SIZE:4}" | ||
416 | + # Maximum CPU time in milliseconds allowed for script execution | ||
417 | + max_cpu_time: "${LOCAL_JS_SANDBOX_MAX_CPU_TIME:100}" | ||
418 | + # Maximum allowed JavaScript execution errors before JavaScript will be blacklisted | ||
419 | + max_errors: "${LOCAL_JS_SANDBOX_MAX_ERRORS:3}" | ||
420 | + # Remote JavaScript environment properties | ||
421 | + remote: | ||
422 | + # Use Sandboxed (secured) JVM JavaScript environment | ||
423 | + use_js_sandbox: "${USE_REMOTE_JS_SANDBOX:true}" |