Commit 285a79ab0a64991a830832d60cedf9b8ff161c92
Merge branch '20230509' into 'master_dev'
20230509 See merge request yunteng/thingskit!193
Showing
5 changed files
with
51 additions
and
12 deletions
@@ -30,6 +30,7 @@ import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | @@ -30,6 +30,7 @@ import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | ||
30 | import org.thingsboard.server.dao.yunteng.service.TkDeviceService; | 30 | import org.thingsboard.server.dao.yunteng.service.TkDeviceService; |
31 | import org.thingsboard.server.dao.yunteng.service.TkDeviceTaskCenterService; | 31 | import org.thingsboard.server.dao.yunteng.service.TkDeviceTaskCenterService; |
32 | import org.thingsboard.server.dao.yunteng.service.TkTaskCenterService; | 32 | import org.thingsboard.server.dao.yunteng.service.TkTaskCenterService; |
33 | +import org.thingsboard.server.queue.util.TbCoreComponent; | ||
33 | import org.thingsboard.server.service.rpc.TbCoreDeviceRpcService; | 34 | import org.thingsboard.server.service.rpc.TbCoreDeviceRpcService; |
34 | import org.thingsboard.server.service.security.model.SecurityUser; | 35 | import org.thingsboard.server.service.security.model.SecurityUser; |
35 | import java.time.LocalDateTime; | 36 | import java.time.LocalDateTime; |
@@ -39,6 +40,7 @@ import java.util.*; | @@ -39,6 +40,7 @@ import java.util.*; | ||
39 | @Component("rpcCommandTask") | 40 | @Component("rpcCommandTask") |
40 | @RequiredArgsConstructor | 41 | @RequiredArgsConstructor |
41 | @Slf4j | 42 | @Slf4j |
43 | +@TbCoreComponent | ||
42 | public class RpcCommandTask { | 44 | public class RpcCommandTask { |
43 | @Value("${server.rest.server_side_rpc.default_timeout:10000}") | 45 | @Value("${server.rest.server_side_rpc.default_timeout:10000}") |
44 | protected long defaultTimeout; | 46 | protected long defaultTimeout; |
@@ -124,7 +124,7 @@ public class DeviceDTO extends TenantDTO { | @@ -124,7 +124,7 @@ public class DeviceDTO extends TenantDTO { | ||
124 | private JsonNode customerAdditionalInfo; | 124 | private JsonNode customerAdditionalInfo; |
125 | 125 | ||
126 | public DeviceState getDeviceState() { | 126 | public DeviceState getDeviceState() { |
127 | - if (lastOnlineTime == null) { | 127 | + if (statusTime == null) { |
128 | return DeviceState.INACTIVE; | 128 | return DeviceState.INACTIVE; |
129 | } | 129 | } |
130 | return deviceState; | 130 | return deviceState; |
@@ -297,7 +297,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | @@ -297,7 +297,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | ||
297 | 297 | ||
298 | if (DataConstants.PROVISION.equals(accessToken) || DataConstants.PROVISION.equals(accessToken)) { | 298 | if (DataConstants.PROVISION.equals(accessToken) || DataConstants.PROVISION.equals(accessToken)) { |
299 | deviceSessionCtx.setProvisionOnly(true); | 299 | deviceSessionCtx.setProvisionOnly(true); |
300 | - ctx.writeAndFlush(createTcpConnAckMsg(CONNECTION_ACCEPTED.name())); | 300 | + pushDeviceMsg(ctx,CONNECTION_ACCEPTED.name()); |
301 | } else { | 301 | } else { |
302 | TkScriptInvokeService.authScripts.forEach(id -> { | 302 | TkScriptInvokeService.authScripts.forEach(id -> { |
303 | ListenableFuture item = context.getJsEngine().invokeFunction(id, accessToken); | 303 | ListenableFuture item = context.getJsEngine().invokeFunction(id, accessToken); |
@@ -347,9 +347,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | @@ -347,9 +347,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | ||
347 | } | 347 | } |
348 | 348 | ||
349 | 349 | ||
350 | - private ByteBuf createTcpConnAckMsg(String msg) { | ||
351 | - return Unpooled.copiedBuffer(ByteUtils.getBytes(msg, ByteUtils.UTF_8)); | ||
352 | - } | 350 | + |
353 | 351 | ||
354 | @Override | 352 | @Override |
355 | public void channelReadComplete(ChannelHandlerContext ctx) { | 353 | public void channelReadComplete(ChannelHandlerContext ctx) { |
@@ -450,7 +448,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | @@ -450,7 +448,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | ||
450 | public void onSuccess(Void msg) { | 448 | public void onSuccess(Void msg) { |
451 | SessionMetaData sessionMetaData = transportService.registerAsyncSession(deviceSessionCtx.getSessionInfo(), TcpTransportHandler.this); | 449 | SessionMetaData sessionMetaData = transportService.registerAsyncSession(deviceSessionCtx.getSessionInfo(), TcpTransportHandler.this); |
452 | checkGatewaySession(sessionMetaData); | 450 | checkGatewaySession(sessionMetaData); |
453 | - ctx.writeAndFlush(createTcpConnAckMsg(authEntry.getSuccess())); | 451 | + pushDeviceMsg(ctx,authEntry.getSuccess()); |
454 | deviceSessionCtx.setConnected(true); | 452 | deviceSessionCtx.setConnected(true); |
455 | log.debug("[{}] Client connected!", sessionId); | 453 | log.debug("[{}] Client connected!", sessionId); |
456 | 454 | ||
@@ -474,7 +472,8 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | @@ -474,7 +472,8 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements | ||
474 | private void onValidateFailed(ChannelHandlerContext ctx, MqttConnectReturnCode msg) { | 472 | private void onValidateFailed(ChannelHandlerContext ctx, MqttConnectReturnCode msg) { |
475 | authedCounter.incrementAndGet(); | 473 | authedCounter.incrementAndGet(); |
476 | if (TkScriptInvokeService.authScripts.size() == authedCounter.intValue()) { | 474 | if (TkScriptInvokeService.authScripts.size() == authedCounter.intValue()) { |
477 | - ctx.writeAndFlush(createTcpConnAckMsg(msg.name())); | 475 | + pushDeviceMsg(ctx,msg.name()); |
476 | + | ||
478 | ctx.close(); | 477 | ctx.close(); |
479 | } | 478 | } |
480 | } | 479 | } |
@@ -41,7 +41,7 @@ | @@ -41,7 +41,7 @@ | ||
41 | <pkg.copyInstallScripts>false</pkg.copyInstallScripts> | 41 | <pkg.copyInstallScripts>false</pkg.copyInstallScripts> |
42 | <pkg.win.dist>${project.build.directory}/windows</pkg.win.dist> | 42 | <pkg.win.dist>${project.build.directory}/windows</pkg.win.dist> |
43 | <pkg.implementationTitle>ThingsBoard MQTT Transport Service</pkg.implementationTitle> | 43 | <pkg.implementationTitle>ThingsBoard MQTT Transport Service</pkg.implementationTitle> |
44 | - <pkg.mainClass>org.thingsboard.server.tcp.ThingsboardMqttTransportApplication</pkg.mainClass> | 44 | + <pkg.mainClass>org.thingsboard.server.mqtt.ThingsboardMqttTransportApplication</pkg.mainClass> |
45 | </properties> | 45 | </properties> |
46 | 46 | ||
47 | <dependencies> | 47 | <dependencies> |
@@ -28,9 +28,9 @@ server: | @@ -28,9 +28,9 @@ server: | ||
28 | # Zookeeper connection parameters. Used for service discovery. | 28 | # Zookeeper connection parameters. Used for service discovery. |
29 | zk: | 29 | zk: |
30 | # Enable/disable zookeeper discovery service. | 30 | # Enable/disable zookeeper discovery service. |
31 | - enabled: "${ZOOKEEPER_ENABLED:true}" | 31 | + enabled: "${ZOOKEEPER_ENABLED:false}" |
32 | # Zookeeper connect string | 32 | # Zookeeper connect string |
33 | - url: "${ZOOKEEPER_URL:47.99.141.212:2181}" | 33 | + url: "${ZOOKEEPER_URL:localhost:2181}" |
34 | # Zookeeper retry interval in milliseconds | 34 | # Zookeeper retry interval in milliseconds |
35 | retry_interval_ms: "${ZOOKEEPER_RETRY_INTERVAL_MS:3000}" | 35 | retry_interval_ms: "${ZOOKEEPER_RETRY_INTERVAL_MS:3000}" |
36 | # Zookeeper connection timeout in milliseconds | 36 | # Zookeeper connection timeout in milliseconds |
@@ -68,7 +68,7 @@ redis: | @@ -68,7 +68,7 @@ redis: | ||
68 | # db index | 68 | # db index |
69 | db: "${REDIS_DB:0}" | 69 | db: "${REDIS_DB:0}" |
70 | # db password | 70 | # db password |
71 | - password: "${REDIS_PASSWORD:redis@6379}" | 71 | + password: "${REDIS_PASSWORD:}" |
72 | # pool config | 72 | # pool config |
73 | pool_config: | 73 | pool_config: |
74 | maxTotal: "${REDIS_POOL_CONFIG_MAX_TOTAL:128}" | 74 | maxTotal: "${REDIS_POOL_CONFIG_MAX_TOTAL:128}" |
@@ -83,6 +83,42 @@ redis: | @@ -83,6 +83,42 @@ redis: | ||
83 | numberTestsPerEvictionRun: "${REDIS_POOL_CONFIG_NUMBER_TESTS_PER_EVICTION_RUN:3}" | 83 | numberTestsPerEvictionRun: "${REDIS_POOL_CONFIG_NUMBER_TESTS_PER_EVICTION_RUN:3}" |
84 | blockWhenExhausted: "${REDIS_POOL_CONFIG_BLOCK_WHEN_EXHAUSTED:true}" | 84 | blockWhenExhausted: "${REDIS_POOL_CONFIG_BLOCK_WHEN_EXHAUSTED:true}" |
85 | 85 | ||
86 | +# Actor system parameters | ||
87 | +actors: | ||
88 | + rule: | ||
89 | +# # Specify thread pool size for database request callbacks executor service | ||
90 | +# db_callback_thread_pool_size: "${ACTORS_RULE_DB_CALLBACK_THREAD_POOL_SIZE:50}" | ||
91 | + # Specify thread pool size for javascript executor service | ||
92 | + js_thread_pool_size: "${ACTORS_RULE_JS_THREAD_POOL_SIZE:50}" | ||
93 | +js: | ||
94 | + evaluator: "${JS_EVALUATOR:local}" # local/remote | ||
95 | + # Built-in JVM JavaScript environment properties | ||
96 | + local: | ||
97 | + # Use Sandboxed (secured) JVM JavaScript environment | ||
98 | + use_js_sandbox: "${USE_LOCAL_JS_SANDBOX:true}" | ||
99 | + # Specify thread pool size for JavaScript sandbox resource monitor | ||
100 | + monitor_thread_pool_size: "${LOCAL_JS_SANDBOX_MONITOR_THREAD_POOL_SIZE:4}" | ||
101 | + # Maximum CPU time in milliseconds allowed for script execution | ||
102 | + max_cpu_time: "${LOCAL_JS_SANDBOX_MAX_CPU_TIME:8000}" | ||
103 | + # Maximum allowed JavaScript execution errors before JavaScript will be blacklisted | ||
104 | + max_errors: "${LOCAL_JS_SANDBOX_MAX_ERRORS:3}" | ||
105 | + # JS Eval max request timeout. 0 - no timeout | ||
106 | + max_requests_timeout: "${LOCAL_JS_MAX_REQUEST_TIMEOUT:0}" | ||
107 | + # Maximum time in seconds for black listed function to stay in the list. | ||
108 | + max_black_list_duration_sec: "${LOCAL_JS_SANDBOX_MAX_BLACKLIST_DURATION_SEC:60}" | ||
109 | + stats: | ||
110 | + enabled: "${TB_JS_LOCAL_STATS_ENABLED:false}" | ||
111 | + print_interval_ms: "${TB_JS_LOCAL_STATS_PRINT_INTERVAL_MS:10000}" | ||
112 | + # Remote JavaScript environment properties | ||
113 | + remote: | ||
114 | + # Maximum allowed JavaScript execution errors before JavaScript will be blacklisted | ||
115 | + max_errors: "${REMOTE_JS_SANDBOX_MAX_ERRORS:3}" | ||
116 | + # Maximum time in seconds for black listed function to stay in the list. | ||
117 | + max_black_list_duration_sec: "${REMOTE_JS_SANDBOX_MAX_BLACKLIST_DURATION_SEC:60}" | ||
118 | + stats: | ||
119 | + enabled: "${TB_JS_REMOTE_STATS_ENABLED:false}" | ||
120 | + print_interval_ms: "${TB_JS_REMOTE_STATS_PRINT_INTERVAL_MS:10000}" | ||
121 | + | ||
86 | # TCP_ server parameters | 122 | # TCP_ server parameters |
87 | transport: | 123 | transport: |
88 | tcp: | 124 | tcp: |
@@ -163,7 +199,7 @@ transport: | @@ -163,7 +199,7 @@ transport: | ||
163 | queue: | 199 | queue: |
164 | type: "${TB_QUEUE_TYPE:kafka}" # kafka (Apache Kafka) or aws-sqs (AWS SQS) or pubsub (PubSub) or service-bus (Azure Service Bus) or rabbitmq (RabbitMQ) | 200 | type: "${TB_QUEUE_TYPE:kafka}" # kafka (Apache Kafka) or aws-sqs (AWS SQS) or pubsub (PubSub) or service-bus (Azure Service Bus) or rabbitmq (RabbitMQ) |
165 | kafka: | 201 | kafka: |
166 | - bootstrap.servers: "${TB_KAFKA_SERVERS:47.99.141.212:9092}" | 202 | + bootstrap.servers: "${TB_KAFKA_SERVERS:localhost:9092}" |
167 | acks: "${TB_KAFKA_ACKS:all}" | 203 | acks: "${TB_KAFKA_ACKS:all}" |
168 | retries: "${TB_KAFKA_RETRIES:1}" | 204 | retries: "${TB_KAFKA_RETRIES:1}" |
169 | batch.size: "${TB_KAFKA_BATCH_SIZE:16384}" | 205 | batch.size: "${TB_KAFKA_BATCH_SIZE:16384}" |
@@ -345,3 +381,5 @@ management: | @@ -345,3 +381,5 @@ management: | ||
345 | exposure: | 381 | exposure: |
346 | # Expose metrics endpoint (use value 'prometheus' to enable prometheus metrics). | 382 | # Expose metrics endpoint (use value 'prometheus' to enable prometheus metrics). |
347 | include: '${METRICS_ENDPOINTS_EXPOSE:info}' | 383 | include: '${METRICS_ENDPOINTS_EXPOSE:info}' |
384 | + | ||
385 | + |