Showing
100 changed files
with
389 additions
and
2770 deletions
Too many changes to show.
To preserve performance only 100 of 539 files are displayed.
@@ -23,7 +23,6 @@ | @@ -23,7 +23,6 @@ | ||
23 | <version>2.0.0-SNAPSHOT</version> | 23 | <version>2.0.0-SNAPSHOT</version> |
24 | <artifactId>thingsboard</artifactId> | 24 | <artifactId>thingsboard</artifactId> |
25 | </parent> | 25 | </parent> |
26 | - <groupId>org.thingsboard</groupId> | ||
27 | <artifactId>application</artifactId> | 26 | <artifactId>application</artifactId> |
28 | <packaging>jar</packaging> | 27 | <packaging>jar</packaging> |
29 | 28 | ||
@@ -50,10 +49,6 @@ | @@ -50,10 +49,6 @@ | ||
50 | <classifier>linux-x86_64</classifier> | 49 | <classifier>linux-x86_64</classifier> |
51 | </dependency> | 50 | </dependency> |
52 | <dependency> | 51 | <dependency> |
53 | - <groupId>org.thingsboard</groupId> | ||
54 | - <artifactId>extensions-api</artifactId> | ||
55 | - </dependency> | ||
56 | - <dependency> | ||
57 | <groupId>org.thingsboard.rule-engine</groupId> | 52 | <groupId>org.thingsboard.rule-engine</groupId> |
58 | <artifactId>rule-engine-api</artifactId> | 53 | <artifactId>rule-engine-api</artifactId> |
59 | </dependency> | 54 | </dependency> |
@@ -62,10 +57,6 @@ | @@ -62,10 +57,6 @@ | ||
62 | <artifactId>rule-engine-components</artifactId> | 57 | <artifactId>rule-engine-components</artifactId> |
63 | </dependency> | 58 | </dependency> |
64 | <dependency> | 59 | <dependency> |
65 | - <groupId>org.thingsboard</groupId> | ||
66 | - <artifactId>extensions-core</artifactId> | ||
67 | - </dependency> | ||
68 | - <dependency> | ||
69 | <groupId>org.thingsboard.common</groupId> | 60 | <groupId>org.thingsboard.common</groupId> |
70 | <artifactId>transport</artifactId> | 61 | <artifactId>transport</artifactId> |
71 | </dependency> | 62 | </dependency> |
@@ -472,48 +463,6 @@ | @@ -472,48 +463,6 @@ | ||
472 | <artifactId>maven-dependency-plugin</artifactId> | 463 | <artifactId>maven-dependency-plugin</artifactId> |
473 | <executions> | 464 | <executions> |
474 | <execution> | 465 | <execution> |
475 | - <id>copy-extensions</id> | ||
476 | - <phase>package</phase> | ||
477 | - <goals> | ||
478 | - <goal>copy</goal> | ||
479 | - </goals> | ||
480 | - <configuration> | ||
481 | - <outputDirectory>${project.build.directory}/extensions</outputDirectory> | ||
482 | - <artifactItems> | ||
483 | - <artifactItem> | ||
484 | - <groupId>org.thingsboard.extensions</groupId> | ||
485 | - <artifactId>extension-rabbitmq</artifactId> | ||
486 | - <classifier>extension</classifier> | ||
487 | - </artifactItem> | ||
488 | - <artifactItem> | ||
489 | - <groupId>org.thingsboard.extensions</groupId> | ||
490 | - <artifactId>extension-rest-api-call</artifactId> | ||
491 | - <classifier>extension</classifier> | ||
492 | - </artifactItem> | ||
493 | - <artifactItem> | ||
494 | - <groupId>org.thingsboard.extensions</groupId> | ||
495 | - <artifactId>extension-kafka</artifactId> | ||
496 | - <classifier>extension</classifier> | ||
497 | - </artifactItem> | ||
498 | - <artifactItem> | ||
499 | - <groupId>org.thingsboard.extensions</groupId> | ||
500 | - <artifactId>extension-mqtt</artifactId> | ||
501 | - <classifier>extension</classifier> | ||
502 | - </artifactItem> | ||
503 | - <artifactItem> | ||
504 | - <groupId>org.thingsboard.extensions</groupId> | ||
505 | - <artifactId>extension-sqs</artifactId> | ||
506 | - <classifier>extension</classifier> | ||
507 | - </artifactItem> | ||
508 | - <artifactItem> | ||
509 | - <groupId>org.thingsboard.extensions</groupId> | ||
510 | - <artifactId>extension-sns</artifactId> | ||
511 | - <classifier>extension</classifier> | ||
512 | - </artifactItem> | ||
513 | - </artifactItems> | ||
514 | - </configuration> | ||
515 | - </execution> | ||
516 | - <execution> | ||
517 | <id>copy-winsw-service</id> | 466 | <id>copy-winsw-service</id> |
518 | <phase>package</phase> | 467 | <phase>package</phase> |
519 | <goals> | 468 | <goals> |
@@ -94,3 +94,10 @@ CREATE TABLE IF NOT EXISTS thingsboard.rule_node ( | @@ -94,3 +94,10 @@ CREATE TABLE IF NOT EXISTS thingsboard.rule_node ( | ||
94 | PRIMARY KEY (id) | 94 | PRIMARY KEY (id) |
95 | ); | 95 | ); |
96 | 96 | ||
97 | +DROP MATERIALIZED VIEW IF EXISTS rule_by_plugin_token; | ||
98 | +DROP MATERIALIZED VIEW IF EXISTS rule_by_tenant_and_search_text; | ||
99 | +DROP MATERIALIZED VIEW IF EXISTS plugin_by_api_token; | ||
100 | +DROP MATERIALIZED VIEW IF EXISTS plugin_by_tenant_and_search_text; | ||
101 | + | ||
102 | +DROP TABLE IF EXISTS rule; | ||
103 | +DROP TABLE IF EXISTS plugin; |
@@ -35,4 +35,7 @@ CREATE TABLE IF NOT EXISTS rule_node ( | @@ -35,4 +35,7 @@ CREATE TABLE IF NOT EXISTS rule_node ( | ||
35 | name varchar(255), | 35 | name varchar(255), |
36 | debug_mode boolean, | 36 | debug_mode boolean, |
37 | search_text varchar(255) | 37 | search_text varchar(255) |
38 | -); | ||
38 | +); | ||
39 | + | ||
40 | +DROP TABLE rule; | ||
41 | +DROP TABLE plugin; |
@@ -29,7 +29,6 @@ import lombok.extern.slf4j.Slf4j; | @@ -29,7 +29,6 @@ import lombok.extern.slf4j.Slf4j; | ||
29 | import org.springframework.beans.factory.annotation.Autowired; | 29 | import org.springframework.beans.factory.annotation.Autowired; |
30 | import org.springframework.beans.factory.annotation.Value; | 30 | import org.springframework.beans.factory.annotation.Value; |
31 | import org.springframework.stereotype.Component; | 31 | import org.springframework.stereotype.Component; |
32 | -import org.thingsboard.rule.engine.api.ListeningExecutor; | ||
33 | import org.thingsboard.rule.engine.api.MailService; | 32 | import org.thingsboard.rule.engine.api.MailService; |
34 | import org.thingsboard.server.actors.service.ActorService; | 33 | import org.thingsboard.server.actors.service.ActorService; |
35 | import org.thingsboard.server.common.data.DataConstants; | 34 | import org.thingsboard.server.common.data.DataConstants; |
@@ -40,7 +39,6 @@ import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | @@ -40,7 +39,6 @@ import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | ||
40 | import org.thingsboard.server.common.msg.TbMsg; | 39 | import org.thingsboard.server.common.msg.TbMsg; |
41 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 40 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
42 | import org.thingsboard.server.common.transport.auth.DeviceAuthService; | 41 | import org.thingsboard.server.common.transport.auth.DeviceAuthService; |
43 | -import org.thingsboard.server.controller.plugin.PluginWebSocketMsgEndpoint; | ||
44 | import org.thingsboard.server.dao.alarm.AlarmService; | 42 | import org.thingsboard.server.dao.alarm.AlarmService; |
45 | import org.thingsboard.server.dao.asset.AssetService; | 43 | import org.thingsboard.server.dao.asset.AssetService; |
46 | import org.thingsboard.server.dao.attributes.AttributesService; | 44 | import org.thingsboard.server.dao.attributes.AttributesService; |
@@ -48,11 +46,8 @@ import org.thingsboard.server.dao.audit.AuditLogService; | @@ -48,11 +46,8 @@ import org.thingsboard.server.dao.audit.AuditLogService; | ||
48 | import org.thingsboard.server.dao.customer.CustomerService; | 46 | import org.thingsboard.server.dao.customer.CustomerService; |
49 | import org.thingsboard.server.dao.device.DeviceService; | 47 | import org.thingsboard.server.dao.device.DeviceService; |
50 | import org.thingsboard.server.dao.event.EventService; | 48 | import org.thingsboard.server.dao.event.EventService; |
51 | -import org.thingsboard.server.dao.plugin.PluginService; | ||
52 | -import org.thingsboard.server.dao.queue.MsgQueue; | ||
53 | import org.thingsboard.server.dao.relation.RelationService; | 49 | import org.thingsboard.server.dao.relation.RelationService; |
54 | import org.thingsboard.server.dao.rule.RuleChainService; | 50 | import org.thingsboard.server.dao.rule.RuleChainService; |
55 | -import org.thingsboard.server.dao.rule.RuleService; | ||
56 | import org.thingsboard.server.dao.tenant.TenantService; | 51 | import org.thingsboard.server.dao.tenant.TenantService; |
57 | import org.thingsboard.server.dao.timeseries.TimeseriesService; | 52 | import org.thingsboard.server.dao.timeseries.TimeseriesService; |
58 | import org.thingsboard.server.dao.user.UserService; | 53 | import org.thingsboard.server.dao.user.UserService; |
@@ -133,18 +128,10 @@ public class ActorSystemContext { | @@ -133,18 +128,10 @@ public class ActorSystemContext { | ||
133 | 128 | ||
134 | @Autowired | 129 | @Autowired |
135 | @Getter | 130 | @Getter |
136 | - private RuleService ruleService; | ||
137 | - | ||
138 | - @Autowired | ||
139 | - @Getter | ||
140 | private RuleChainService ruleChainService; | 131 | private RuleChainService ruleChainService; |
141 | 132 | ||
142 | @Autowired | 133 | @Autowired |
143 | @Getter | 134 | @Getter |
144 | - private PluginService pluginService; | ||
145 | - | ||
146 | - @Autowired | ||
147 | - @Getter | ||
148 | private TimeseriesService tsService; | 135 | private TimeseriesService tsService; |
149 | 136 | ||
150 | @Autowired | 137 | @Autowired |
@@ -177,11 +164,6 @@ public class ActorSystemContext { | @@ -177,11 +164,6 @@ public class ActorSystemContext { | ||
177 | 164 | ||
178 | @Autowired | 165 | @Autowired |
179 | @Getter | 166 | @Getter |
180 | - @Setter | ||
181 | - private PluginWebSocketMsgEndpoint wsMsgEndpoint; | ||
182 | - | ||
183 | - @Autowired | ||
184 | - @Getter | ||
185 | private JsExecutorService jsExecutor; | 167 | private JsExecutorService jsExecutor; |
186 | 168 | ||
187 | @Autowired | 169 | @Autowired |
@@ -15,24 +15,26 @@ | @@ -15,24 +15,26 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.actors.app; | 16 | package org.thingsboard.server.actors.app; |
17 | 17 | ||
18 | -import akka.actor.*; | 18 | +import akka.actor.ActorRef; |
19 | +import akka.actor.LocalActorRef; | ||
20 | +import akka.actor.OneForOneStrategy; | ||
21 | +import akka.actor.Props; | ||
22 | +import akka.actor.SupervisorStrategy; | ||
19 | import akka.actor.SupervisorStrategy.Directive; | 23 | import akka.actor.SupervisorStrategy.Directive; |
24 | +import akka.actor.Terminated; | ||
20 | import akka.event.Logging; | 25 | import akka.event.Logging; |
21 | import akka.event.LoggingAdapter; | 26 | import akka.event.LoggingAdapter; |
22 | import akka.japi.Function; | 27 | import akka.japi.Function; |
23 | import org.thingsboard.server.actors.ActorSystemContext; | 28 | import org.thingsboard.server.actors.ActorSystemContext; |
24 | -import org.thingsboard.server.actors.plugin.PluginTerminationMsg; | ||
25 | import org.thingsboard.server.actors.ruleChain.RuleChainManagerActor; | 29 | import org.thingsboard.server.actors.ruleChain.RuleChainManagerActor; |
26 | import org.thingsboard.server.actors.service.ContextBasedCreator; | 30 | import org.thingsboard.server.actors.service.ContextBasedCreator; |
27 | import org.thingsboard.server.actors.service.DefaultActorService; | 31 | import org.thingsboard.server.actors.service.DefaultActorService; |
28 | -import org.thingsboard.server.actors.shared.plugin.SystemPluginManager; | ||
29 | import org.thingsboard.server.actors.shared.rulechain.SystemRuleChainManager; | 32 | import org.thingsboard.server.actors.shared.rulechain.SystemRuleChainManager; |
30 | import org.thingsboard.server.actors.tenant.TenantActor; | 33 | import org.thingsboard.server.actors.tenant.TenantActor; |
31 | import org.thingsboard.server.common.data.Tenant; | 34 | import org.thingsboard.server.common.data.Tenant; |
32 | import org.thingsboard.server.common.data.id.TenantId; | 35 | import org.thingsboard.server.common.data.id.TenantId; |
33 | import org.thingsboard.server.common.data.page.PageDataIterable; | 36 | import org.thingsboard.server.common.data.page.PageDataIterable; |
34 | import org.thingsboard.server.common.msg.TbActorMsg; | 37 | import org.thingsboard.server.common.msg.TbActorMsg; |
35 | -import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; | ||
36 | import org.thingsboard.server.common.msg.aware.TenantAwareMsg; | 38 | import org.thingsboard.server.common.msg.aware.TenantAwareMsg; |
37 | import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; | 39 | import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; |
38 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 40 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
@@ -41,8 +43,6 @@ import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; | @@ -41,8 +43,6 @@ import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; | ||
41 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; | 43 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; |
42 | import org.thingsboard.server.dao.model.ModelConstants; | 44 | import org.thingsboard.server.dao.model.ModelConstants; |
43 | import org.thingsboard.server.dao.tenant.TenantService; | 45 | import org.thingsboard.server.dao.tenant.TenantService; |
44 | -import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | ||
45 | -import org.thingsboard.server.extensions.api.plugins.msg.ToPluginActorMsg; | ||
46 | import scala.concurrent.duration.Duration; | 46 | import scala.concurrent.duration.Duration; |
47 | 47 | ||
48 | import java.util.HashMap; | 48 | import java.util.HashMap; |
@@ -58,7 +58,7 @@ public class AppActor extends RuleChainManagerActor { | @@ -58,7 +58,7 @@ public class AppActor extends RuleChainManagerActor { | ||
58 | private final Map<TenantId, ActorRef> tenantActors; | 58 | private final Map<TenantId, ActorRef> tenantActors; |
59 | 59 | ||
60 | private AppActor(ActorSystemContext systemContext) { | 60 | private AppActor(ActorSystemContext systemContext) { |
61 | - super(systemContext, new SystemRuleChainManager(systemContext), new SystemPluginManager(systemContext)); | 61 | + super(systemContext, new SystemRuleChainManager(systemContext)); |
62 | this.tenantService = systemContext.getTenantService(); | 62 | this.tenantService = systemContext.getTenantService(); |
63 | this.tenantActors = new HashMap<>(); | 63 | this.tenantActors = new HashMap<>(); |
64 | } | 64 | } |
@@ -17,6 +17,8 @@ package org.thingsboard.server.actors.device; | @@ -17,6 +17,8 @@ package org.thingsboard.server.actors.device; | ||
17 | 17 | ||
18 | import akka.event.Logging; | 18 | import akka.event.Logging; |
19 | import akka.event.LoggingAdapter; | 19 | import akka.event.LoggingAdapter; |
20 | +import org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg; | ||
21 | +import org.thingsboard.rule.engine.api.msg.DeviceNameOrTypeUpdateMsg; | ||
20 | import org.thingsboard.server.actors.ActorSystemContext; | 22 | import org.thingsboard.server.actors.ActorSystemContext; |
21 | import org.thingsboard.server.actors.service.ContextAwareActor; | 23 | import org.thingsboard.server.actors.service.ContextAwareActor; |
22 | import org.thingsboard.server.actors.service.ContextBasedCreator; | 24 | import org.thingsboard.server.actors.service.ContextBasedCreator; |
@@ -28,8 +30,6 @@ import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; | @@ -28,8 +30,6 @@ import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; | ||
28 | import org.thingsboard.server.common.msg.timeout.DeviceActorClientSideRpcTimeoutMsg; | 30 | import org.thingsboard.server.common.msg.timeout.DeviceActorClientSideRpcTimeoutMsg; |
29 | import org.thingsboard.server.common.msg.timeout.DeviceActorQueueTimeoutMsg; | 31 | import org.thingsboard.server.common.msg.timeout.DeviceActorQueueTimeoutMsg; |
30 | import org.thingsboard.server.common.msg.timeout.DeviceActorServerSideRpcTimeoutMsg; | 32 | import org.thingsboard.server.common.msg.timeout.DeviceActorServerSideRpcTimeoutMsg; |
31 | -import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; | ||
32 | -import org.thingsboard.server.extensions.api.device.DeviceNameOrTypeUpdateMsg; | ||
33 | import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg; | 33 | import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg; |
34 | import org.thingsboard.server.service.rpc.ToServerRpcResponseActorMsg; | 34 | import org.thingsboard.server.service.rpc.ToServerRpcResponseActorMsg; |
35 | 35 |
@@ -25,6 +25,9 @@ import com.google.common.util.concurrent.ListenableFuture; | @@ -25,6 +25,9 @@ import com.google.common.util.concurrent.ListenableFuture; | ||
25 | import com.google.gson.Gson; | 25 | import com.google.gson.Gson; |
26 | import com.google.gson.JsonObject; | 26 | import com.google.gson.JsonObject; |
27 | import com.google.gson.JsonParser; | 27 | import com.google.gson.JsonParser; |
28 | +import org.thingsboard.rule.engine.api.RpcError; | ||
29 | +import org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg; | ||
30 | +import org.thingsboard.rule.engine.api.msg.DeviceNameOrTypeUpdateMsg; | ||
28 | import org.thingsboard.server.actors.ActorSystemContext; | 31 | import org.thingsboard.server.actors.ActorSystemContext; |
29 | import org.thingsboard.server.actors.shared.AbstractContextAwareMsgProcessor; | 32 | import org.thingsboard.server.actors.shared.AbstractContextAwareMsgProcessor; |
30 | import org.thingsboard.server.common.data.DataConstants; | 33 | import org.thingsboard.server.common.data.DataConstants; |
@@ -41,12 +44,13 @@ import org.thingsboard.server.common.msg.TbMsgDataType; | @@ -41,12 +44,13 @@ import org.thingsboard.server.common.msg.TbMsgDataType; | ||
41 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 44 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
42 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | 45 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
43 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 46 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
47 | +import org.thingsboard.server.common.msg.core.ActorSystemToDeviceSessionActorMsg; | ||
44 | import org.thingsboard.server.common.msg.core.AttributesUpdateNotification; | 48 | import org.thingsboard.server.common.msg.core.AttributesUpdateNotification; |
45 | import org.thingsboard.server.common.msg.core.AttributesUpdateRequest; | 49 | import org.thingsboard.server.common.msg.core.AttributesUpdateRequest; |
50 | +import org.thingsboard.server.common.msg.core.BasicActorSystemToDeviceSessionActorMsg; | ||
46 | import org.thingsboard.server.common.msg.core.BasicCommandAckResponse; | 51 | import org.thingsboard.server.common.msg.core.BasicCommandAckResponse; |
47 | import org.thingsboard.server.common.msg.core.BasicGetAttributesResponse; | 52 | import org.thingsboard.server.common.msg.core.BasicGetAttributesResponse; |
48 | import org.thingsboard.server.common.msg.core.BasicStatusCodeResponse; | 53 | import org.thingsboard.server.common.msg.core.BasicStatusCodeResponse; |
49 | -import org.thingsboard.server.common.msg.core.BasicActorSystemToDeviceSessionActorMsg; | ||
50 | import org.thingsboard.server.common.msg.core.GetAttributesRequest; | 54 | import org.thingsboard.server.common.msg.core.GetAttributesRequest; |
51 | import org.thingsboard.server.common.msg.core.RuleEngineError; | 55 | import org.thingsboard.server.common.msg.core.RuleEngineError; |
52 | import org.thingsboard.server.common.msg.core.RuleEngineErrorMsg; | 56 | import org.thingsboard.server.common.msg.core.RuleEngineErrorMsg; |
@@ -56,7 +60,6 @@ import org.thingsboard.server.common.msg.core.SessionOpenMsg; | @@ -56,7 +60,6 @@ import org.thingsboard.server.common.msg.core.SessionOpenMsg; | ||
56 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; | 60 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; |
57 | import org.thingsboard.server.common.msg.core.ToDeviceRpcRequestMsg; | 61 | import org.thingsboard.server.common.msg.core.ToDeviceRpcRequestMsg; |
58 | import org.thingsboard.server.common.msg.core.ToDeviceRpcResponseMsg; | 62 | import org.thingsboard.server.common.msg.core.ToDeviceRpcResponseMsg; |
59 | -import org.thingsboard.server.common.msg.core.ActorSystemToDeviceSessionActorMsg; | ||
60 | import org.thingsboard.server.common.msg.core.ToServerRpcRequestMsg; | 63 | import org.thingsboard.server.common.msg.core.ToServerRpcRequestMsg; |
61 | import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; | 64 | import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
62 | import org.thingsboard.server.common.msg.kv.BasicAttributeKVMsg; | 65 | import org.thingsboard.server.common.msg.kv.BasicAttributeKVMsg; |
@@ -68,10 +71,7 @@ import org.thingsboard.server.common.msg.session.ToDeviceMsg; | @@ -68,10 +71,7 @@ import org.thingsboard.server.common.msg.session.ToDeviceMsg; | ||
68 | import org.thingsboard.server.common.msg.timeout.DeviceActorClientSideRpcTimeoutMsg; | 71 | import org.thingsboard.server.common.msg.timeout.DeviceActorClientSideRpcTimeoutMsg; |
69 | import org.thingsboard.server.common.msg.timeout.DeviceActorQueueTimeoutMsg; | 72 | import org.thingsboard.server.common.msg.timeout.DeviceActorQueueTimeoutMsg; |
70 | import org.thingsboard.server.common.msg.timeout.DeviceActorServerSideRpcTimeoutMsg; | 73 | import org.thingsboard.server.common.msg.timeout.DeviceActorServerSideRpcTimeoutMsg; |
71 | -import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; | ||
72 | -import org.thingsboard.server.extensions.api.device.DeviceNameOrTypeUpdateMsg; | ||
73 | -import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; | ||
74 | -import org.thingsboard.server.extensions.api.plugins.msg.RpcError; | 74 | +import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; |
75 | import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg; | 75 | import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg; |
76 | import org.thingsboard.server.service.rpc.ToServerRpcResponseActorMsg; | 76 | import org.thingsboard.server.service.rpc.ToServerRpcResponseActorMsg; |
77 | 77 |
@@ -17,7 +17,6 @@ package org.thingsboard.server.actors.device; | @@ -17,7 +17,6 @@ package org.thingsboard.server.actors.device; | ||
17 | 17 | ||
18 | import akka.actor.ActorRef; | 18 | import akka.actor.ActorRef; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | -import org.thingsboard.server.common.data.id.TenantId; | ||
21 | import org.thingsboard.server.common.msg.MsgType; | 20 | import org.thingsboard.server.common.msg.MsgType; |
22 | import org.thingsboard.server.common.msg.TbActorMsg; | 21 | import org.thingsboard.server.common.msg.TbActorMsg; |
23 | import org.thingsboard.server.common.msg.TbMsg; | 22 | import org.thingsboard.server.common.msg.TbMsg; |
@@ -16,7 +16,6 @@ | @@ -16,7 +16,6 @@ | ||
16 | package org.thingsboard.server.actors.device; | 16 | package org.thingsboard.server.actors.device; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | -import org.thingsboard.server.common.data.id.SessionId; | ||
20 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 19 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
21 | import org.thingsboard.server.common.msg.session.SessionType; | 20 | import org.thingsboard.server.common.msg.session.SessionType; |
22 | 21 |
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.actors.plugin; | ||
17 | - | ||
18 | -import akka.actor.ActorContext; | ||
19 | -import akka.actor.ActorRef; | ||
20 | -import org.thingsboard.server.actors.ActorSystemContext; | ||
21 | -import org.thingsboard.server.actors.service.ComponentActor; | ||
22 | -import org.thingsboard.server.actors.service.ContextBasedCreator; | ||
23 | -import org.thingsboard.server.actors.stats.StatsPersistTick; | ||
24 | -import org.thingsboard.server.common.data.id.PluginId; | ||
25 | -import org.thingsboard.server.common.data.id.TenantId; | ||
26 | -import org.thingsboard.server.common.msg.TbActorMsg; | ||
27 | -import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | ||
28 | -import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; | ||
29 | -import org.thingsboard.server.common.msg.timeout.TimeoutMsg; | ||
30 | -import org.thingsboard.server.extensions.api.plugins.msg.ToPluginRpcResponseDeviceMsg; | ||
31 | -import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; | ||
32 | -import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; | ||
33 | -import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; | ||
34 | -import org.thingsboard.server.extensions.api.rules.RuleException; | ||
35 | - | ||
36 | -public class PluginActor extends ComponentActor<PluginId, PluginActorMessageProcessor> { | ||
37 | - | ||
38 | - private PluginActor(ActorSystemContext systemContext, TenantId tenantId, PluginId pluginId) { | ||
39 | - super(systemContext, tenantId, pluginId); | ||
40 | - setProcessor(new PluginActorMessageProcessor(tenantId, pluginId, systemContext, | ||
41 | - logger, context().parent(), context().self())); | ||
42 | - } | ||
43 | - | ||
44 | - @Override | ||
45 | - protected boolean process(TbActorMsg msg) { | ||
46 | - //TODO Move everything here, to work with TbActorMsg | ||
47 | - return false; | ||
48 | - } | ||
49 | - | ||
50 | - @Override | ||
51 | - public void onReceive(Object msg) throws Exception { | ||
52 | - if (msg instanceof PluginWebsocketMsg) { | ||
53 | - onWebsocketMsg((PluginWebsocketMsg<?>) msg); | ||
54 | - } else if (msg instanceof PluginRestMsg) { | ||
55 | - onRestMsg((PluginRestMsg) msg); | ||
56 | - } else if (msg instanceof PluginCallbackMessage) { | ||
57 | - onPluginCallback((PluginCallbackMessage) msg); | ||
58 | - } else if (msg instanceof RuleToPluginMsgWrapper) { | ||
59 | - onRuleToPluginMsg((RuleToPluginMsgWrapper) msg); | ||
60 | - } else if (msg instanceof PluginRpcMsg) { | ||
61 | - onRpcMsg((PluginRpcMsg) msg); | ||
62 | - } else if (msg instanceof ClusterEventMsg) { | ||
63 | - onClusterEventMsg((ClusterEventMsg) msg); | ||
64 | - } else if (msg instanceof ComponentLifecycleMsg) { | ||
65 | - onComponentLifecycleMsg((ComponentLifecycleMsg) msg); | ||
66 | - } else if (msg instanceof ToPluginRpcResponseDeviceMsg) { | ||
67 | - onRpcResponse((ToPluginRpcResponseDeviceMsg) msg); | ||
68 | - } else if (msg instanceof PluginTerminationMsg) { | ||
69 | - logger.info("[{}][{}] Going to terminate plugin actor.", tenantId, id); | ||
70 | - context().parent().tell(msg, ActorRef.noSender()); | ||
71 | - context().stop(self()); | ||
72 | - } else if (msg instanceof TimeoutMsg) { | ||
73 | - onTimeoutMsg(context(), (TimeoutMsg) msg); | ||
74 | - } else if (msg instanceof StatsPersistTick) { | ||
75 | - onStatsPersistTick(id); | ||
76 | - } else { | ||
77 | - logger.debug("[{}][{}] Unknown msg type.", tenantId, id, msg.getClass().getName()); | ||
78 | - } | ||
79 | - } | ||
80 | - | ||
81 | - private void onPluginCallback(PluginCallbackMessage msg) { | ||
82 | - try { | ||
83 | - processor.onPluginCallbackMsg(msg); | ||
84 | - } catch (Exception e) { | ||
85 | - logAndPersist("onPluginCallbackMsg", e); | ||
86 | - } | ||
87 | - } | ||
88 | - | ||
89 | - private void onTimeoutMsg(ActorContext context, TimeoutMsg msg) { | ||
90 | - processor.onTimeoutMsg(context, msg); | ||
91 | - } | ||
92 | - | ||
93 | - private void onRpcResponse(ToPluginRpcResponseDeviceMsg msg) { | ||
94 | - processor.onDeviceRpcMsg(msg.getResponse()); | ||
95 | - } | ||
96 | - | ||
97 | - private void onRuleToPluginMsg(RuleToPluginMsgWrapper msg) throws RuleException { | ||
98 | - logger.debug("[{}] Going to process rule msg: {}", id, msg.getMsg()); | ||
99 | - try { | ||
100 | - processor.onRuleToPluginMsg(msg); | ||
101 | - increaseMessagesProcessedCount(); | ||
102 | - } catch (Exception e) { | ||
103 | - logAndPersist("onRuleMsg", e); | ||
104 | - } | ||
105 | - } | ||
106 | - | ||
107 | - private void onWebsocketMsg(PluginWebsocketMsg<?> msg) { | ||
108 | - logger.debug("[{}] Going to process web socket msg: {}", id, msg); | ||
109 | - try { | ||
110 | - processor.onWebsocketMsg(msg); | ||
111 | - increaseMessagesProcessedCount(); | ||
112 | - } catch (Exception e) { | ||
113 | - logAndPersist("onWebsocketMsg", e); | ||
114 | - } | ||
115 | - } | ||
116 | - | ||
117 | - private void onRestMsg(PluginRestMsg msg) { | ||
118 | - logger.debug("[{}] Going to process rest msg: {}", id, msg); | ||
119 | - try { | ||
120 | - processor.onRestMsg(msg); | ||
121 | - increaseMessagesProcessedCount(); | ||
122 | - } catch (Exception e) { | ||
123 | - logAndPersist("onRestMsg", e); | ||
124 | - } | ||
125 | - } | ||
126 | - | ||
127 | - private void onRpcMsg(PluginRpcMsg msg) { | ||
128 | - try { | ||
129 | - logger.debug("[{}] Going to process rpc msg: {}", id, msg); | ||
130 | - processor.onRpcMsg(msg); | ||
131 | - } catch (Exception e) { | ||
132 | - logAndPersist("onRpcMsg", e); | ||
133 | - } | ||
134 | - } | ||
135 | - | ||
136 | - public static class ActorCreator extends ContextBasedCreator<PluginActor> { | ||
137 | - private static final long serialVersionUID = 1L; | ||
138 | - | ||
139 | - private final TenantId tenantId; | ||
140 | - private final PluginId pluginId; | ||
141 | - | ||
142 | - public ActorCreator(ActorSystemContext context, TenantId tenantId, PluginId pluginId) { | ||
143 | - super(context); | ||
144 | - this.tenantId = tenantId; | ||
145 | - this.pluginId = pluginId; | ||
146 | - } | ||
147 | - | ||
148 | - @Override | ||
149 | - public PluginActor create() throws Exception { | ||
150 | - return new PluginActor(context, tenantId, pluginId); | ||
151 | - } | ||
152 | - } | ||
153 | - | ||
154 | - @Override | ||
155 | - protected long getErrorPersistFrequency() { | ||
156 | - return 0; | ||
157 | -// return systemContext.getPluginErrorPersistFrequency(); | ||
158 | - } | ||
159 | -} |
application/src/main/java/org/thingsboard/server/actors/plugin/PluginActorMessageProcessor.java
deleted
100644 → 0
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.actors.plugin; | ||
17 | - | ||
18 | -import akka.actor.ActorContext; | ||
19 | -import akka.actor.ActorRef; | ||
20 | -import akka.event.LoggingAdapter; | ||
21 | -import com.fasterxml.jackson.core.JsonProcessingException; | ||
22 | -import org.thingsboard.server.actors.ActorSystemContext; | ||
23 | -import org.thingsboard.server.actors.shared.ComponentMsgProcessor; | ||
24 | -import org.thingsboard.server.common.data.id.PluginId; | ||
25 | -import org.thingsboard.server.common.data.id.TenantId; | ||
26 | -import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; | ||
27 | -import org.thingsboard.server.common.data.plugin.ComponentType; | ||
28 | -import org.thingsboard.server.common.data.plugin.PluginMetaData; | ||
29 | -import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | ||
30 | -import org.thingsboard.server.common.msg.cluster.ServerAddress; | ||
31 | -import org.thingsboard.server.common.msg.core.BasicStatusCodeResponse; | ||
32 | -import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | ||
33 | -import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
34 | -import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
35 | -import org.thingsboard.server.extensions.api.plugins.Plugin; | ||
36 | -import org.thingsboard.server.extensions.api.plugins.PluginInitializationException; | ||
37 | -import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; | ||
38 | -import org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg; | ||
39 | -import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | ||
40 | -import org.thingsboard.server.common.msg.timeout.TimeoutMsg; | ||
41 | -import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; | ||
42 | -import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; | ||
43 | -import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; | ||
44 | -import org.thingsboard.server.extensions.api.rules.RuleException; | ||
45 | - | ||
46 | -/** | ||
47 | - * @author Andrew Shvayka | ||
48 | - */ | ||
49 | -public class PluginActorMessageProcessor extends ComponentMsgProcessor<PluginId> { | ||
50 | - | ||
51 | - private final SharedPluginProcessingContext pluginCtx; | ||
52 | - private final PluginProcessingContext trustedCtx; | ||
53 | - private PluginMetaData pluginMd; | ||
54 | - private Plugin pluginImpl; | ||
55 | - private ComponentLifecycleState state; | ||
56 | - | ||
57 | - | ||
58 | - protected PluginActorMessageProcessor(TenantId tenantId, PluginId pluginId, ActorSystemContext systemContext | ||
59 | - , LoggingAdapter logger, ActorRef parent, ActorRef self) { | ||
60 | - super(systemContext, logger, tenantId, pluginId); | ||
61 | - this.pluginCtx = new SharedPluginProcessingContext(systemContext, tenantId, pluginId, parent, self); | ||
62 | - this.trustedCtx = new PluginProcessingContext(pluginCtx, null); | ||
63 | - } | ||
64 | - | ||
65 | - @Override | ||
66 | - public void start(ActorContext context) throws Exception { | ||
67 | - logger.info("[{}] Going to start plugin actor.", entityId); | ||
68 | - pluginMd = systemContext.getPluginService().findPluginById(entityId); | ||
69 | - if (pluginMd == null) { | ||
70 | - throw new PluginInitializationException("Plugin not found!"); | ||
71 | - } | ||
72 | - if (pluginMd.getConfiguration() == null) { | ||
73 | - throw new PluginInitializationException("Plugin metadata is empty!"); | ||
74 | - } | ||
75 | - state = pluginMd.getState(); | ||
76 | - if (state == ComponentLifecycleState.ACTIVE) { | ||
77 | - logger.info("[{}] Plugin is active. Going to initialize plugin.", entityId); | ||
78 | - initComponent(); | ||
79 | - } else { | ||
80 | - logger.info("[{}] Plugin is suspended. Skipping plugin initialization.", entityId); | ||
81 | - } | ||
82 | - } | ||
83 | - | ||
84 | - @Override | ||
85 | - public void stop(ActorContext context) throws Exception { | ||
86 | - onStop(); | ||
87 | - } | ||
88 | - | ||
89 | - private void initComponent() { | ||
90 | - try { | ||
91 | - pluginImpl = initComponent(pluginMd.getClazz(), ComponentType.PLUGIN, mapper.writeValueAsString(pluginMd.getConfiguration())); | ||
92 | - } catch (InstantiationException e) { | ||
93 | - throw new PluginInitializationException("No default constructor for plugin implementation!", e); | ||
94 | - } catch (IllegalAccessException e) { | ||
95 | - throw new PluginInitializationException("Illegal Access Exception during plugin initialization!", e); | ||
96 | - } catch (ClassNotFoundException e) { | ||
97 | - throw new PluginInitializationException("Plugin Class not found!", e); | ||
98 | - } catch (JsonProcessingException e) { | ||
99 | - throw new PluginInitializationException("Plugin Configuration is invalid!", e); | ||
100 | - } catch (Exception e) { | ||
101 | - throw new PluginInitializationException(e.getMessage(), e); | ||
102 | - } | ||
103 | - } | ||
104 | - | ||
105 | - public void onRuleToPluginMsg(RuleToPluginMsgWrapper msg) throws RuleException { | ||
106 | - if (state == ComponentLifecycleState.ACTIVE) { | ||
107 | - try { | ||
108 | - pluginImpl.process(trustedCtx, msg.getRuleTenantId(), msg.getRuleId(), msg.getMsg()); | ||
109 | - } catch (Exception ex) { | ||
110 | - logger.debug("[{}] Failed to process RuleToPlugin msg: [{}] [{}]", tenantId, msg.getMsg(), ex); | ||
111 | - RuleToPluginMsg ruleMsg = msg.getMsg(); | ||
112 | - SessionMsgType responceMsgType = SessionMsgType.RULE_ENGINE_ERROR; | ||
113 | - Integer requestId = 0; | ||
114 | - if (ruleMsg.getPayload() instanceof FromDeviceRequestMsg) { | ||
115 | - requestId = ((FromDeviceRequestMsg) ruleMsg.getPayload()).getRequestId(); | ||
116 | - } | ||
117 | - trustedCtx.reply( | ||
118 | - new ResponsePluginToRuleMsg(ruleMsg.getUid(), tenantId, msg.getRuleId(), | ||
119 | - BasicStatusCodeResponse.onError(responceMsgType, requestId, ex))); | ||
120 | - } | ||
121 | - } else { | ||
122 | - //TODO: reply with plugin suspended message | ||
123 | - } | ||
124 | - } | ||
125 | - | ||
126 | - public void onWebsocketMsg(PluginWebsocketMsg<?> msg) { | ||
127 | - if (state == ComponentLifecycleState.ACTIVE) { | ||
128 | - pluginImpl.process(new PluginProcessingContext(pluginCtx, msg.getSecurityCtx()), msg); | ||
129 | - } else { | ||
130 | - //TODO: reply with plugin suspended message | ||
131 | - } | ||
132 | - } | ||
133 | - | ||
134 | - public void onRestMsg(PluginRestMsg msg) { | ||
135 | - if (state == ComponentLifecycleState.ACTIVE) { | ||
136 | - pluginImpl.process(new PluginProcessingContext(pluginCtx, msg.getSecurityCtx()), msg); | ||
137 | - } | ||
138 | - } | ||
139 | - | ||
140 | - public void onRpcMsg(PluginRpcMsg msg) { | ||
141 | - if (state == ComponentLifecycleState.ACTIVE) { | ||
142 | - pluginImpl.process(trustedCtx, msg.getRpcMsg()); | ||
143 | - } else { | ||
144 | - //TODO: reply with plugin suspended message | ||
145 | - } | ||
146 | - } | ||
147 | - | ||
148 | - public void onPluginCallbackMsg(PluginCallbackMessage msg) { | ||
149 | - if (state == ComponentLifecycleState.ACTIVE) { | ||
150 | - if (msg.isSuccess()) { | ||
151 | - msg.getCallback().onSuccess(trustedCtx, msg.getV()); | ||
152 | - } else { | ||
153 | - msg.getCallback().onFailure(trustedCtx, msg.getE()); | ||
154 | - } | ||
155 | - } else { | ||
156 | - //TODO: reply with plugin suspended message | ||
157 | - } | ||
158 | - } | ||
159 | - | ||
160 | - | ||
161 | - public void onTimeoutMsg(ActorContext context, TimeoutMsg<?> msg) { | ||
162 | - if (state == ComponentLifecycleState.ACTIVE) { | ||
163 | - pluginImpl.process(trustedCtx, msg); | ||
164 | - } | ||
165 | - } | ||
166 | - | ||
167 | - | ||
168 | - public void onDeviceRpcMsg(FromDeviceRpcResponse response) { | ||
169 | - if (state == ComponentLifecycleState.ACTIVE) { | ||
170 | - pluginImpl.process(trustedCtx, response); | ||
171 | - } | ||
172 | - } | ||
173 | - | ||
174 | - @Override | ||
175 | - public void onClusterEventMsg(ClusterEventMsg msg) { | ||
176 | - if (state == ComponentLifecycleState.ACTIVE) { | ||
177 | - ServerAddress address = msg.getServerAddress(); | ||
178 | - if (msg.isAdded()) { | ||
179 | - logger.debug("[{}] Going to process server add msg: {}", entityId, address); | ||
180 | - pluginImpl.onServerAdded(trustedCtx, address); | ||
181 | - } else { | ||
182 | - logger.debug("[{}] Going to process server remove msg: {}", entityId, address); | ||
183 | - pluginImpl.onServerRemoved(trustedCtx, address); | ||
184 | - } | ||
185 | - } | ||
186 | - } | ||
187 | - | ||
188 | - @Override | ||
189 | - public void onCreated(ActorContext context) { | ||
190 | - logger.info("[{}] Going to process onCreated plugin.", entityId); | ||
191 | - } | ||
192 | - | ||
193 | - @Override | ||
194 | - public void onUpdate(ActorContext context) throws Exception { | ||
195 | - PluginMetaData oldPluginMd = pluginMd; | ||
196 | - pluginMd = systemContext.getPluginService().findPluginById(entityId); | ||
197 | - boolean requiresRestart = false; | ||
198 | - logger.info("[{}] Plugin configuration was updated from {} to {}.", entityId, oldPluginMd, pluginMd); | ||
199 | - if (!oldPluginMd.getClazz().equals(pluginMd.getClazz())) { | ||
200 | - logger.info("[{}] Plugin requires restart due to clazz change from {} to {}.", | ||
201 | - entityId, oldPluginMd.getClazz(), pluginMd.getClazz()); | ||
202 | - requiresRestart = true; | ||
203 | - } else if (!oldPluginMd.getConfiguration().equals(pluginMd.getConfiguration())) { | ||
204 | - logger.info("[{}] Plugin requires restart due to configuration change from {} to {}.", | ||
205 | - entityId, oldPluginMd.getConfiguration(), pluginMd.getConfiguration()); | ||
206 | - requiresRestart = true; | ||
207 | - } | ||
208 | - if (requiresRestart) { | ||
209 | - this.state = ComponentLifecycleState.SUSPENDED; | ||
210 | - if (pluginImpl != null) { | ||
211 | - pluginImpl.stop(trustedCtx); | ||
212 | - } | ||
213 | - start(context); | ||
214 | - } | ||
215 | - } | ||
216 | - | ||
217 | - @Override | ||
218 | - public void onStop(ActorContext context) { | ||
219 | - onStop(); | ||
220 | -// scheduleMsgWithDelay(context, new PluginTerminationMsg(entityId), systemContext.getPluginActorTerminationDelay()); | ||
221 | - } | ||
222 | - | ||
223 | - private void onStop() { | ||
224 | - logger.info("[{}] Going to process onStop plugin.", entityId); | ||
225 | - this.state = ComponentLifecycleState.SUSPENDED; | ||
226 | - if (pluginImpl != null) { | ||
227 | - pluginImpl.stop(trustedCtx); | ||
228 | - } | ||
229 | - } | ||
230 | - | ||
231 | - @Override | ||
232 | - public void onActivate(ActorContext context) throws Exception { | ||
233 | - logger.info("[{}] Going to process onActivate plugin.", entityId); | ||
234 | - this.state = ComponentLifecycleState.ACTIVE; | ||
235 | - if (pluginImpl != null) { | ||
236 | - pluginImpl.resume(trustedCtx); | ||
237 | - logger.info("[{}] Plugin resumed.", entityId); | ||
238 | - } else { | ||
239 | - start(context); | ||
240 | - } | ||
241 | - } | ||
242 | - | ||
243 | - @Override | ||
244 | - public void onSuspend(ActorContext context) { | ||
245 | - logger.info("[{}] Going to process onSuspend plugin.", entityId); | ||
246 | - this.state = ComponentLifecycleState.SUSPENDED; | ||
247 | - if (pluginImpl != null) { | ||
248 | - pluginImpl.suspend(trustedCtx); | ||
249 | - } | ||
250 | - } | ||
251 | - | ||
252 | -} |
application/src/main/java/org/thingsboard/server/actors/plugin/PluginCallbackMessage.java
deleted
100644 → 0
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.actors.plugin; | ||
17 | - | ||
18 | -import lombok.Data; | ||
19 | -import lombok.Getter; | ||
20 | -import lombok.ToString; | ||
21 | -import org.thingsboard.server.extensions.api.plugins.PluginCallback; | ||
22 | - | ||
23 | -import java.util.Optional; | ||
24 | - | ||
25 | -/** | ||
26 | - * @author Andrew Shvayka | ||
27 | - */ | ||
28 | -@ToString | ||
29 | -public final class PluginCallbackMessage<V> { | ||
30 | - @Getter | ||
31 | - private final PluginCallback<V> callback; | ||
32 | - @Getter | ||
33 | - private final boolean success; | ||
34 | - @Getter | ||
35 | - private final V v; | ||
36 | - @Getter | ||
37 | - private final Exception e; | ||
38 | - | ||
39 | - public static <V> PluginCallbackMessage<V> onSuccess(PluginCallback<V> callback, V data) { | ||
40 | - return new PluginCallbackMessage<V>(true, callback, data, null); | ||
41 | - } | ||
42 | - | ||
43 | - public static <V> PluginCallbackMessage<V> onError(PluginCallback<V> callback, Exception e) { | ||
44 | - return new PluginCallbackMessage<V>(false, callback, null, e); | ||
45 | - } | ||
46 | - | ||
47 | - private PluginCallbackMessage(boolean success, PluginCallback<V> callback, V v, Exception e) { | ||
48 | - this.success = success; | ||
49 | - this.callback = callback; | ||
50 | - this.v = v; | ||
51 | - this.e = e; | ||
52 | - } | ||
53 | -} |
application/src/main/java/org/thingsboard/server/actors/plugin/PluginProcessingContext.java
deleted
100644 → 0
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.actors.plugin; | ||
17 | - | ||
18 | -import akka.actor.ActorRef; | ||
19 | -import com.google.common.base.Function; | ||
20 | -import com.google.common.util.concurrent.FutureCallback; | ||
21 | -import com.google.common.util.concurrent.Futures; | ||
22 | -import com.google.common.util.concurrent.ListenableFuture; | ||
23 | -import lombok.extern.slf4j.Slf4j; | ||
24 | -import org.thingsboard.server.common.data.Customer; | ||
25 | -import org.thingsboard.server.common.data.Device; | ||
26 | -import org.thingsboard.server.common.data.EntityType; | ||
27 | -import org.thingsboard.server.common.data.Tenant; | ||
28 | -import org.thingsboard.server.common.data.asset.Asset; | ||
29 | -import org.thingsboard.server.common.data.audit.ActionType; | ||
30 | -import org.thingsboard.server.common.data.id.*; | ||
31 | -import org.thingsboard.server.common.data.kv.AttributeKey; | ||
32 | -import org.thingsboard.server.common.data.kv.AttributeKvEntry; | ||
33 | -import org.thingsboard.server.common.data.kv.TsKvEntry; | ||
34 | -import org.thingsboard.server.common.data.kv.TsKvQuery; | ||
35 | -import org.thingsboard.server.common.data.page.TextPageLink; | ||
36 | -import org.thingsboard.server.common.data.plugin.PluginMetaData; | ||
37 | -import org.thingsboard.server.common.data.relation.EntityRelation; | ||
38 | -import org.thingsboard.server.common.data.relation.RelationTypeGroup; | ||
39 | -import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | ||
40 | -import org.thingsboard.server.common.data.rule.RuleChain; | ||
41 | -import org.thingsboard.server.common.data.rule.RuleMetaData; | ||
42 | -import org.thingsboard.server.common.msg.cluster.ServerAddress; | ||
43 | -import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | ||
44 | -import org.thingsboard.server.common.msg.timeout.TimeoutMsg; | ||
45 | -import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; | ||
46 | -import org.thingsboard.server.extensions.api.plugins.PluginApiCallSecurityContext; | ||
47 | -import org.thingsboard.server.extensions.api.plugins.PluginCallback; | ||
48 | -import org.thingsboard.server.extensions.api.plugins.PluginContext; | ||
49 | -import org.thingsboard.server.extensions.api.plugins.msg.*; | ||
50 | -import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; | ||
51 | -import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg; | ||
52 | -import org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef; | ||
53 | -import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; | ||
54 | - | ||
55 | -import javax.annotation.Nullable; | ||
56 | -import java.io.IOException; | ||
57 | -import java.util.*; | ||
58 | -import java.util.concurrent.Executor; | ||
59 | -import java.util.concurrent.Executors; | ||
60 | -import java.util.stream.Collectors; | ||
61 | - | ||
62 | -@Slf4j | ||
63 | -public final class PluginProcessingContext implements PluginContext { | ||
64 | - | ||
65 | - private static final Executor executor = Executors.newSingleThreadExecutor(); | ||
66 | - public static final String CUSTOMER_USER_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION = "Customer user is not allowed to perform this operation!"; | ||
67 | - public static final String SYSTEM_ADMINISTRATOR_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION = "System administrator is not allowed to perform this operation!"; | ||
68 | - public static final String DEVICE_WITH_REQUESTED_ID_NOT_FOUND = "Device with requested id wasn't found!"; | ||
69 | - | ||
70 | - private final SharedPluginProcessingContext pluginCtx; | ||
71 | - private final Optional<PluginApiCallSecurityContext> securityCtx; | ||
72 | - | ||
73 | - public PluginProcessingContext(SharedPluginProcessingContext pluginCtx, PluginApiCallSecurityContext securityCtx) { | ||
74 | - super(); | ||
75 | - this.pluginCtx = pluginCtx; | ||
76 | - this.securityCtx = Optional.ofNullable(securityCtx); | ||
77 | - } | ||
78 | - | ||
79 | - public void persistError(String method, Exception e) { | ||
80 | - pluginCtx.persistError(method, e); | ||
81 | - } | ||
82 | - | ||
83 | - @Override | ||
84 | - public void sendPluginRpcMsg(RpcMsg msg) { | ||
85 | - //ToDO is this a cluster messsage? | ||
86 | -// this.pluginCtx.rpcService.tell(new PluginRpcMsg(pluginCtx.tenantId, pluginCtx.pluginId, msg)); | ||
87 | - } | ||
88 | - | ||
89 | - @Override | ||
90 | - public void send(PluginWebsocketMsg<?> wsMsg) throws IOException { | ||
91 | - pluginCtx.msgEndpoint.send(wsMsg); | ||
92 | - } | ||
93 | - | ||
94 | - @Override | ||
95 | - public void close(PluginWebsocketSessionRef sessionRef) throws IOException { | ||
96 | - pluginCtx.msgEndpoint.close(sessionRef); | ||
97 | - } | ||
98 | - | ||
99 | - @Override | ||
100 | - public void saveAttributes(final TenantId tenantId, final EntityId entityId, final String scope, final List<AttributeKvEntry> attributes, final PluginCallback<Void> callback) { | ||
101 | - validate(entityId, new ValidationCallback(callback, ctx -> { | ||
102 | - ListenableFuture<List<Void>> futures = pluginCtx.attributesService.save(entityId, scope, attributes); | ||
103 | - Futures.addCallback(futures, getListCallback(callback, v -> { | ||
104 | - if (entityId.getEntityType() == EntityType.DEVICE) { | ||
105 | - onDeviceAttributesChanged(tenantId, new DeviceId(entityId.getId()), scope, attributes); | ||
106 | - } | ||
107 | - return null; | ||
108 | - }), executor); | ||
109 | - })); | ||
110 | - } | ||
111 | - | ||
112 | - @Override | ||
113 | - public void removeAttributes(final TenantId tenantId, final EntityId entityId, final String scope, final List<String> keys, final PluginCallback<Void> callback) { | ||
114 | - validate(entityId, new ValidationCallback(callback, ctx -> { | ||
115 | - ListenableFuture<List<Void>> futures = pluginCtx.attributesService.removeAll(entityId, scope, keys); | ||
116 | - Futures.addCallback(futures, getCallback(callback, v -> null), executor); | ||
117 | - if (entityId.getEntityType() == EntityType.DEVICE) { | ||
118 | - onDeviceAttributesDeleted(tenantId, new DeviceId(entityId.getId()), keys.stream().map(key -> new AttributeKey(scope, key)).collect(Collectors.toSet())); | ||
119 | - } | ||
120 | - })); | ||
121 | - } | ||
122 | - | ||
123 | - @Override | ||
124 | - public void loadAttribute(EntityId entityId, String attributeType, String attributeKey, final PluginCallback<Optional<AttributeKvEntry>> callback) { | ||
125 | - validate(entityId, new ValidationCallback(callback, ctx -> { | ||
126 | - ListenableFuture<Optional<AttributeKvEntry>> future = pluginCtx.attributesService.find(entityId, attributeType, attributeKey); | ||
127 | - Futures.addCallback(future, getCallback(callback, v -> v), executor); | ||
128 | - })); | ||
129 | - } | ||
130 | - | ||
131 | - @Override | ||
132 | - public void loadAttributes(EntityId entityId, String attributeType, Collection<String> attributeKeys, final PluginCallback<List<AttributeKvEntry>> callback) { | ||
133 | - validate(entityId, new ValidationCallback(callback, ctx -> { | ||
134 | - ListenableFuture<List<AttributeKvEntry>> future = pluginCtx.attributesService.find(entityId, attributeType, attributeKeys); | ||
135 | - Futures.addCallback(future, getCallback(callback, v -> v), executor); | ||
136 | - })); | ||
137 | - } | ||
138 | - | ||
139 | - @Override | ||
140 | - public void loadAttributes(EntityId entityId, String attributeType, PluginCallback<List<AttributeKvEntry>> callback) { | ||
141 | - validate(entityId, new ValidationCallback(callback, ctx -> { | ||
142 | - ListenableFuture<List<AttributeKvEntry>> future = pluginCtx.attributesService.findAll(entityId, attributeType); | ||
143 | - Futures.addCallback(future, getCallback(callback, v -> v), executor); | ||
144 | - })); | ||
145 | - } | ||
146 | - | ||
147 | - @Override | ||
148 | - public void loadAttributes(final EntityId entityId, final Collection<String> attributeTypes, final PluginCallback<List<AttributeKvEntry>> callback) { | ||
149 | - validate(entityId, new ValidationCallback(callback, ctx -> { | ||
150 | - List<ListenableFuture<List<AttributeKvEntry>>> futures = new ArrayList<>(); | ||
151 | - attributeTypes.forEach(attributeType -> futures.add(pluginCtx.attributesService.findAll(entityId, attributeType))); | ||
152 | - convertFuturesAndAddCallback(callback, futures); | ||
153 | - })); | ||
154 | - } | ||
155 | - | ||
156 | - @Override | ||
157 | - public void loadAttributes(final EntityId entityId, final Collection<String> attributeTypes, final Collection<String> attributeKeys, final PluginCallback<List<AttributeKvEntry>> callback) { | ||
158 | - validate(entityId, new ValidationCallback(callback, ctx -> { | ||
159 | - List<ListenableFuture<List<AttributeKvEntry>>> futures = new ArrayList<>(); | ||
160 | - attributeTypes.forEach(attributeType -> futures.add(pluginCtx.attributesService.find(entityId, attributeType, attributeKeys))); | ||
161 | - convertFuturesAndAddCallback(callback, futures); | ||
162 | - })); | ||
163 | - } | ||
164 | - | ||
165 | - @Override | ||
166 | - public void saveTsData(final EntityId entityId, final TsKvEntry entry, final PluginCallback<Void> callback) { | ||
167 | - validate(entityId, new ValidationCallback(callback, ctx -> { | ||
168 | - ListenableFuture<List<Void>> rsListFuture = pluginCtx.tsService.save(entityId, entry); | ||
169 | - Futures.addCallback(rsListFuture, getListCallback(callback, v -> null), executor); | ||
170 | - })); | ||
171 | - } | ||
172 | - | ||
173 | - @Override | ||
174 | - public void saveTsData(final EntityId entityId, final List<TsKvEntry> entries, final PluginCallback<Void> callback) { | ||
175 | - saveTsData(entityId, entries, 0L, callback); | ||
176 | - } | ||
177 | - | ||
178 | - @Override | ||
179 | - public void saveTsData(final EntityId entityId, final List<TsKvEntry> entries, long ttl, final PluginCallback<Void> callback) { | ||
180 | - validate(entityId, new ValidationCallback(callback, ctx -> { | ||
181 | - ListenableFuture<List<Void>> rsListFuture = pluginCtx.tsService.save(entityId, entries, ttl); | ||
182 | - Futures.addCallback(rsListFuture, getListCallback(callback, v -> null), executor); | ||
183 | - })); | ||
184 | - } | ||
185 | - | ||
186 | - | ||
187 | - @Override | ||
188 | - public void loadTimeseries(final EntityId entityId, final List<TsKvQuery> queries, final PluginCallback<List<TsKvEntry>> callback) { | ||
189 | - validate(entityId, new ValidationCallback(callback, ctx -> { | ||
190 | - ListenableFuture<List<TsKvEntry>> future = pluginCtx.tsService.findAll(entityId, queries); | ||
191 | - Futures.addCallback(future, getCallback(callback, v -> v), executor); | ||
192 | - })); | ||
193 | - } | ||
194 | - | ||
195 | - @Override | ||
196 | - public void loadLatestTimeseries(final EntityId entityId, final PluginCallback<List<TsKvEntry>> callback) { | ||
197 | - validate(entityId, new ValidationCallback(callback, ctx -> { | ||
198 | - ListenableFuture<List<TsKvEntry>> future = pluginCtx.tsService.findAllLatest(entityId); | ||
199 | - Futures.addCallback(future, getCallback(callback, v -> v), executor); | ||
200 | - })); | ||
201 | - } | ||
202 | - | ||
203 | - @Override | ||
204 | - public void logAttributesUpdated(PluginApiCallSecurityContext ctx, EntityId entityId, String attributeType, | ||
205 | - List<AttributeKvEntry> attributes, Exception e) { | ||
206 | - pluginCtx.auditLogService.logEntityAction( | ||
207 | - ctx.getTenantId(), | ||
208 | - ctx.getCustomerId(), | ||
209 | - ctx.getUserId(), | ||
210 | - ctx.getUserName(), | ||
211 | - (UUIDBased & EntityId)entityId, | ||
212 | - null, | ||
213 | - ActionType.ATTRIBUTES_UPDATED, | ||
214 | - e, | ||
215 | - attributeType, | ||
216 | - attributes); | ||
217 | - } | ||
218 | - | ||
219 | - @Override | ||
220 | - public void logAttributesDeleted(PluginApiCallSecurityContext ctx, EntityId entityId, String attributeType, List<String> keys, Exception e) { | ||
221 | - pluginCtx.auditLogService.logEntityAction( | ||
222 | - ctx.getTenantId(), | ||
223 | - ctx.getCustomerId(), | ||
224 | - ctx.getUserId(), | ||
225 | - ctx.getUserName(), | ||
226 | - (UUIDBased & EntityId)entityId, | ||
227 | - null, | ||
228 | - ActionType.ATTRIBUTES_DELETED, | ||
229 | - e, | ||
230 | - attributeType, | ||
231 | - keys); | ||
232 | - } | ||
233 | - | ||
234 | - @Override | ||
235 | - public void logAttributesRead(PluginApiCallSecurityContext ctx, EntityId entityId, String attributeType, List<String> keys, Exception e) { | ||
236 | - pluginCtx.auditLogService.logEntityAction( | ||
237 | - ctx.getTenantId(), | ||
238 | - ctx.getCustomerId(), | ||
239 | - ctx.getUserId(), | ||
240 | - ctx.getUserName(), | ||
241 | - (UUIDBased & EntityId)entityId, | ||
242 | - null, | ||
243 | - ActionType.ATTRIBUTES_READ, | ||
244 | - e, | ||
245 | - attributeType, | ||
246 | - keys); | ||
247 | - } | ||
248 | - | ||
249 | - @Override | ||
250 | - public void loadLatestTimeseries(final EntityId entityId, final Collection<String> keys, final PluginCallback<List<TsKvEntry>> callback) { | ||
251 | - validate(entityId, new ValidationCallback(callback, ctx -> { | ||
252 | - ListenableFuture<List<TsKvEntry>> rsListFuture = pluginCtx.tsService.findLatest(entityId, keys); | ||
253 | - Futures.addCallback(rsListFuture, getCallback(callback, v -> v), executor); | ||
254 | - })); | ||
255 | - } | ||
256 | - | ||
257 | - @Override | ||
258 | - public void reply(PluginToRuleMsg<?> msg) { | ||
259 | - pluginCtx.parentActor.tell(msg, ActorRef.noSender()); | ||
260 | - } | ||
261 | - | ||
262 | - @Override | ||
263 | - public PluginId getPluginId() { | ||
264 | - return pluginCtx.pluginId; | ||
265 | - } | ||
266 | - | ||
267 | - @Override | ||
268 | - public Optional<PluginApiCallSecurityContext> getSecurityCtx() { | ||
269 | - return securityCtx; | ||
270 | - } | ||
271 | - | ||
272 | - private void onDeviceAttributesDeleted(TenantId tenantId, DeviceId deviceId, Set<AttributeKey> keys) { | ||
273 | - pluginCtx.toDeviceActor(DeviceAttributesEventNotificationMsg.onDelete(tenantId, deviceId, keys)); | ||
274 | - } | ||
275 | - | ||
276 | - private void onDeviceAttributesChanged(TenantId tenantId, DeviceId deviceId, String scope, List<AttributeKvEntry> values) { | ||
277 | - pluginCtx.toDeviceActor(DeviceAttributesEventNotificationMsg.onUpdate(tenantId, deviceId, scope, values)); | ||
278 | - } | ||
279 | - | ||
280 | - private <T, R> FutureCallback<List<T>> getListCallback(final PluginCallback<R> callback, Function<List<T>, R> transformer) { | ||
281 | - return new FutureCallback<List<T>>() { | ||
282 | - @Override | ||
283 | - public void onSuccess(@Nullable List<T> result) { | ||
284 | - pluginCtx.self().tell(PluginCallbackMessage.onSuccess(callback, transformer.apply(result)), ActorRef.noSender()); | ||
285 | - } | ||
286 | - | ||
287 | - @Override | ||
288 | - public void onFailure(Throwable t) { | ||
289 | - if (t instanceof Exception) { | ||
290 | - pluginCtx.self().tell(PluginCallbackMessage.onError(callback, (Exception) t), ActorRef.noSender()); | ||
291 | - } else { | ||
292 | - log.error("Critical error: {}", t.getMessage(), t); | ||
293 | - } | ||
294 | - } | ||
295 | - }; | ||
296 | - } | ||
297 | - | ||
298 | - private <T, R> FutureCallback<R> getCallback(final PluginCallback<T> callback, Function<R, T> transformer) { | ||
299 | - return new FutureCallback<R>() { | ||
300 | - @Override | ||
301 | - public void onSuccess(@Nullable R result) { | ||
302 | - try { | ||
303 | - pluginCtx.self().tell(PluginCallbackMessage.onSuccess(callback, transformer.apply(result)), ActorRef.noSender()); | ||
304 | - } catch (Exception e) { | ||
305 | - pluginCtx.self().tell(PluginCallbackMessage.onError(callback, e), ActorRef.noSender()); | ||
306 | - } | ||
307 | - } | ||
308 | - | ||
309 | - @Override | ||
310 | - public void onFailure(Throwable t) { | ||
311 | - if (t instanceof Exception) { | ||
312 | - pluginCtx.self().tell(PluginCallbackMessage.onError(callback, (Exception) t), ActorRef.noSender()); | ||
313 | - } else { | ||
314 | - log.error("Critical error: {}", t.getMessage(), t); | ||
315 | - } | ||
316 | - } | ||
317 | - }; | ||
318 | - } | ||
319 | - | ||
320 | - @Override | ||
321 | - public void checkAccess(DeviceId deviceId, PluginCallback<Void> callback) { | ||
322 | - validate(deviceId, new ValidationCallback(callback, ctx -> callback.onSuccess(ctx, null))); | ||
323 | - } | ||
324 | - | ||
325 | - private void validate(EntityId entityId, ValidationCallback callback) { | ||
326 | - if (securityCtx.isPresent()) { | ||
327 | - final PluginApiCallSecurityContext ctx = securityCtx.get(); | ||
328 | - switch (entityId.getEntityType()) { | ||
329 | - case DEVICE: | ||
330 | - validateDevice(ctx, entityId, callback); | ||
331 | - return; | ||
332 | - case ASSET: | ||
333 | - validateAsset(ctx, entityId, callback); | ||
334 | - return; | ||
335 | - case RULE: | ||
336 | - validateRule(ctx, entityId, callback); | ||
337 | - return; | ||
338 | - case RULE_CHAIN: | ||
339 | - validateRuleChain(ctx, entityId, callback); | ||
340 | - return; | ||
341 | - case PLUGIN: | ||
342 | - validatePlugin(ctx, entityId, callback); | ||
343 | - return; | ||
344 | - case CUSTOMER: | ||
345 | - validateCustomer(ctx, entityId, callback); | ||
346 | - return; | ||
347 | - case TENANT: | ||
348 | - validateTenant(ctx, entityId, callback); | ||
349 | - return; | ||
350 | - default: | ||
351 | - //TODO: add support of other entities | ||
352 | - throw new IllegalStateException("Not Implemented!"); | ||
353 | - } | ||
354 | - } else { | ||
355 | - callback.onSuccess(this, ValidationResult.ok(null)); | ||
356 | - } | ||
357 | - } | ||
358 | - | ||
359 | - private void validateDevice(final PluginApiCallSecurityContext ctx, EntityId entityId, ValidationCallback callback) { | ||
360 | - if (ctx.isSystemAdmin()) { | ||
361 | - callback.onSuccess(this, ValidationResult.accessDenied(SYSTEM_ADMINISTRATOR_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); | ||
362 | - } else { | ||
363 | - ListenableFuture<Device> deviceFuture = pluginCtx.deviceService.findDeviceByIdAsync(new DeviceId(entityId.getId())); | ||
364 | - Futures.addCallback(deviceFuture, getCallback(callback, device -> { | ||
365 | - if (device == null) { | ||
366 | - return ValidationResult.entityNotFound(DEVICE_WITH_REQUESTED_ID_NOT_FOUND); | ||
367 | - } else { | ||
368 | - if (!device.getTenantId().equals(ctx.getTenantId())) { | ||
369 | - return ValidationResult.accessDenied("Device doesn't belong to the current Tenant!"); | ||
370 | - } else if (ctx.isCustomerUser() && !device.getCustomerId().equals(ctx.getCustomerId())) { | ||
371 | - return ValidationResult.accessDenied("Device doesn't belong to the current Customer!"); | ||
372 | - } else { | ||
373 | - return ValidationResult.ok(null); | ||
374 | - } | ||
375 | - } | ||
376 | - })); | ||
377 | - } | ||
378 | - } | ||
379 | - | ||
380 | - private void validateAsset(final PluginApiCallSecurityContext ctx, EntityId entityId, ValidationCallback callback) { | ||
381 | - if (ctx.isSystemAdmin()) { | ||
382 | - callback.onSuccess(this, ValidationResult.accessDenied(SYSTEM_ADMINISTRATOR_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); | ||
383 | - } else { | ||
384 | - ListenableFuture<Asset> assetFuture = pluginCtx.assetService.findAssetByIdAsync(new AssetId(entityId.getId())); | ||
385 | - Futures.addCallback(assetFuture, getCallback(callback, asset -> { | ||
386 | - if (asset == null) { | ||
387 | - return ValidationResult.entityNotFound("Asset with requested id wasn't found!"); | ||
388 | - } else { | ||
389 | - if (!asset.getTenantId().equals(ctx.getTenantId())) { | ||
390 | - return ValidationResult.accessDenied("Asset doesn't belong to the current Tenant!"); | ||
391 | - } else if (ctx.isCustomerUser() && !asset.getCustomerId().equals(ctx.getCustomerId())) { | ||
392 | - return ValidationResult.accessDenied("Asset doesn't belong to the current Customer!"); | ||
393 | - } else { | ||
394 | - return ValidationResult.ok(null); | ||
395 | - } | ||
396 | - } | ||
397 | - })); | ||
398 | - } | ||
399 | - } | ||
400 | - | ||
401 | - private void validateRule(final PluginApiCallSecurityContext ctx, EntityId entityId, ValidationCallback callback) { | ||
402 | - if (ctx.isCustomerUser()) { | ||
403 | - callback.onSuccess(this, ValidationResult.accessDenied(CUSTOMER_USER_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); | ||
404 | - } else { | ||
405 | - ListenableFuture<RuleMetaData> ruleFuture = pluginCtx.ruleService.findRuleByIdAsync(new RuleId(entityId.getId())); | ||
406 | - Futures.addCallback(ruleFuture, getCallback(callback, rule -> { | ||
407 | - if (rule == null) { | ||
408 | - return ValidationResult.entityNotFound("Rule with requested id wasn't found!"); | ||
409 | - } else { | ||
410 | - if (ctx.isTenantAdmin() && !rule.getTenantId().equals(ctx.getTenantId())) { | ||
411 | - return ValidationResult.accessDenied("Rule doesn't belong to the current Tenant!"); | ||
412 | - } else if (ctx.isSystemAdmin() && !rule.getTenantId().isNullUid()) { | ||
413 | - return ValidationResult.accessDenied("Rule is not in system scope!"); | ||
414 | - } else { | ||
415 | - return ValidationResult.ok(null); | ||
416 | - } | ||
417 | - } | ||
418 | - })); | ||
419 | - } | ||
420 | - } | ||
421 | - | ||
422 | - private void validateRuleChain(final PluginApiCallSecurityContext ctx, EntityId entityId, ValidationCallback callback) { | ||
423 | - if (ctx.isCustomerUser()) { | ||
424 | - callback.onSuccess(this, ValidationResult.accessDenied(CUSTOMER_USER_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); | ||
425 | - } else { | ||
426 | - ListenableFuture<RuleChain> ruleChainFuture = pluginCtx.ruleChainService.findRuleChainByIdAsync(new RuleChainId(entityId.getId())); | ||
427 | - Futures.addCallback(ruleChainFuture, getCallback(callback, ruleChain -> { | ||
428 | - if (ruleChain == null) { | ||
429 | - return ValidationResult.entityNotFound("Rule chain with requested id wasn't found!"); | ||
430 | - } else { | ||
431 | - if (ctx.isTenantAdmin() && !ruleChain.getTenantId().equals(ctx.getTenantId())) { | ||
432 | - return ValidationResult.accessDenied("Rule chain doesn't belong to the current Tenant!"); | ||
433 | - } else if (ctx.isSystemAdmin() && !ruleChain.getTenantId().isNullUid()) { | ||
434 | - return ValidationResult.accessDenied("Rule chain is not in system scope!"); | ||
435 | - } else { | ||
436 | - return ValidationResult.ok(null); | ||
437 | - } | ||
438 | - } | ||
439 | - })); | ||
440 | - } | ||
441 | - } | ||
442 | - | ||
443 | - | ||
444 | - private void validatePlugin(final PluginApiCallSecurityContext ctx, EntityId entityId, ValidationCallback callback) { | ||
445 | - if (ctx.isCustomerUser()) { | ||
446 | - callback.onSuccess(this, ValidationResult.accessDenied(CUSTOMER_USER_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); | ||
447 | - } else { | ||
448 | - ListenableFuture<PluginMetaData> pluginFuture = pluginCtx.pluginService.findPluginByIdAsync(new PluginId(entityId.getId())); | ||
449 | - Futures.addCallback(pluginFuture, getCallback(callback, plugin -> { | ||
450 | - if (plugin == null) { | ||
451 | - return ValidationResult.entityNotFound("Plugin with requested id wasn't found!"); | ||
452 | - } else { | ||
453 | - if (ctx.isTenantAdmin() && !plugin.getTenantId().equals(ctx.getTenantId())) { | ||
454 | - return ValidationResult.accessDenied("Plugin doesn't belong to the current Tenant!"); | ||
455 | - } else if (ctx.isSystemAdmin() && !plugin.getTenantId().isNullUid()) { | ||
456 | - return ValidationResult.accessDenied("Plugin is not in system scope!"); | ||
457 | - } else { | ||
458 | - return ValidationResult.ok(null); | ||
459 | - } | ||
460 | - } | ||
461 | - })); | ||
462 | - } | ||
463 | - } | ||
464 | - | ||
465 | - private void validateCustomer(final PluginApiCallSecurityContext ctx, EntityId entityId, ValidationCallback callback) { | ||
466 | - if (ctx.isSystemAdmin()) { | ||
467 | - callback.onSuccess(this, ValidationResult.accessDenied(SYSTEM_ADMINISTRATOR_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); | ||
468 | - } else { | ||
469 | - ListenableFuture<Customer> customerFuture = pluginCtx.customerService.findCustomerByIdAsync(new CustomerId(entityId.getId())); | ||
470 | - Futures.addCallback(customerFuture, getCallback(callback, customer -> { | ||
471 | - if (customer == null) { | ||
472 | - return ValidationResult.entityNotFound("Customer with requested id wasn't found!"); | ||
473 | - } else { | ||
474 | - if (!customer.getTenantId().equals(ctx.getTenantId())) { | ||
475 | - return ValidationResult.accessDenied("Customer doesn't belong to the current Tenant!"); | ||
476 | - } else if (ctx.isCustomerUser() && !customer.getId().equals(ctx.getCustomerId())) { | ||
477 | - return ValidationResult.accessDenied("Customer doesn't relate to the currently authorized customer user!"); | ||
478 | - } else { | ||
479 | - return ValidationResult.ok(null); | ||
480 | - } | ||
481 | - } | ||
482 | - })); | ||
483 | - } | ||
484 | - } | ||
485 | - | ||
486 | - private void validateTenant(final PluginApiCallSecurityContext ctx, EntityId entityId, ValidationCallback callback) { | ||
487 | - if (ctx.isCustomerUser()) { | ||
488 | - callback.onSuccess(this, ValidationResult.accessDenied(CUSTOMER_USER_IS_NOT_ALLOWED_TO_PERFORM_THIS_OPERATION)); | ||
489 | - } else if (ctx.isSystemAdmin()) { | ||
490 | - callback.onSuccess(this, ValidationResult.ok(null)); | ||
491 | - } else { | ||
492 | - ListenableFuture<Tenant> tenantFuture = pluginCtx.tenantService.findTenantByIdAsync(new TenantId(entityId.getId())); | ||
493 | - Futures.addCallback(tenantFuture, getCallback(callback, tenant -> { | ||
494 | - if (tenant == null) { | ||
495 | - return ValidationResult.entityNotFound("Tenant with requested id wasn't found!"); | ||
496 | - } else if (!tenant.getId().equals(ctx.getTenantId())) { | ||
497 | - return ValidationResult.accessDenied("Tenant doesn't relate to the currently authorized user!"); | ||
498 | - } else { | ||
499 | - return ValidationResult.ok(null); | ||
500 | - } | ||
501 | - })); | ||
502 | - } | ||
503 | - } | ||
504 | - | ||
505 | - @Override | ||
506 | - public ListenableFuture<List<EntityRelation>> findByFromAndType(EntityId from, String relationType) { | ||
507 | - return this.pluginCtx.relationService.findByFromAndTypeAsync(from, relationType, RelationTypeGroup.COMMON); | ||
508 | - } | ||
509 | - | ||
510 | - @Override | ||
511 | - public ListenableFuture<List<EntityRelation>> findByToAndType(EntityId from, String relationType) { | ||
512 | - return this.pluginCtx.relationService.findByToAndTypeAsync(from, relationType, RelationTypeGroup.COMMON); | ||
513 | - } | ||
514 | - | ||
515 | - @Override | ||
516 | - public Optional<ServerAddress> resolve(EntityId entityId) { | ||
517 | - return pluginCtx.routingService.resolveById(entityId); | ||
518 | - } | ||
519 | - | ||
520 | - @Override | ||
521 | - public void getDevice(DeviceId deviceId, PluginCallback<Device> callback) { | ||
522 | - ListenableFuture<Device> deviceFuture = pluginCtx.deviceService.findDeviceByIdAsync(deviceId); | ||
523 | - Futures.addCallback(deviceFuture, getCallback(callback, v -> v)); | ||
524 | - } | ||
525 | - | ||
526 | - @Override | ||
527 | - public void getCustomerDevices(TenantId tenantId, CustomerId customerId, int limit, PluginCallback<List<Device>> callback) { | ||
528 | - //TODO: add caching here with async api. | ||
529 | - List<Device> devices = pluginCtx.deviceService.findDevicesByTenantIdAndCustomerId(tenantId, customerId, new TextPageLink(limit)).getData(); | ||
530 | - pluginCtx.self().tell(PluginCallbackMessage.onSuccess(callback, devices), ActorRef.noSender()); | ||
531 | - } | ||
532 | - | ||
533 | - @Override | ||
534 | - public void sendRpcRequest(ToDeviceRpcRequest msg) { | ||
535 | - pluginCtx.sendRpcRequest(msg); | ||
536 | - } | ||
537 | - | ||
538 | - @Override | ||
539 | - public void logRpcRequest(PluginApiCallSecurityContext ctx, DeviceId deviceId, ToDeviceRpcRequestBody body, boolean oneWay, Optional<RpcError> rpcError, Exception e) { | ||
540 | - String rpcErrorStr = ""; | ||
541 | - if (rpcError.isPresent()) { | ||
542 | - rpcErrorStr = "RPC Error: " + rpcError.get().name(); | ||
543 | - } | ||
544 | - String method = body.getMethod(); | ||
545 | - String params = body.getParams(); | ||
546 | - pluginCtx.auditLogService.logEntityAction( | ||
547 | - ctx.getTenantId(), | ||
548 | - ctx.getCustomerId(), | ||
549 | - ctx.getUserId(), | ||
550 | - ctx.getUserName(), | ||
551 | - deviceId, | ||
552 | - null, | ||
553 | - ActionType.RPC_CALL, | ||
554 | - e, | ||
555 | - rpcErrorStr, | ||
556 | - new Boolean(oneWay), | ||
557 | - method, | ||
558 | - params); | ||
559 | - } | ||
560 | - | ||
561 | - @Override | ||
562 | - public void scheduleTimeoutMsg(TimeoutMsg msg) { | ||
563 | - pluginCtx.scheduleTimeoutMsg(msg); | ||
564 | - } | ||
565 | - | ||
566 | - | ||
567 | - private void convertFuturesAndAddCallback(PluginCallback<List<AttributeKvEntry>> callback, List<ListenableFuture<List<AttributeKvEntry>>> futures) { | ||
568 | - ListenableFuture<List<AttributeKvEntry>> future = Futures.transform(Futures.successfulAsList(futures), | ||
569 | - (Function<? super List<List<AttributeKvEntry>>, ? extends List<AttributeKvEntry>>) input -> { | ||
570 | - List<AttributeKvEntry> result = new ArrayList<>(); | ||
571 | - input.forEach(r -> result.addAll(r)); | ||
572 | - return result; | ||
573 | - }, executor); | ||
574 | - Futures.addCallback(future, getCallback(callback, v -> v), executor); | ||
575 | - } | ||
576 | -} |
application/src/main/java/org/thingsboard/server/actors/plugin/PluginTerminationMsg.java
deleted
100644 → 0
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.actors.plugin; | ||
17 | - | ||
18 | -import org.thingsboard.server.actors.shared.ActorTerminationMsg; | ||
19 | -import org.thingsboard.server.common.data.id.PluginId; | ||
20 | -import org.thingsboard.server.common.data.id.SessionId; | ||
21 | - | ||
22 | -/** | ||
23 | - * @author Andrew Shvayka | ||
24 | - */ | ||
25 | -public class PluginTerminationMsg extends ActorTerminationMsg<PluginId> { | ||
26 | - | ||
27 | - public PluginTerminationMsg(PluginId id) { | ||
28 | - super(id); | ||
29 | - } | ||
30 | -} |
application/src/main/java/org/thingsboard/server/actors/plugin/RuleToPluginMsgWrapper.java
deleted
100644 → 0
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.actors.plugin; | ||
17 | - | ||
18 | -import org.thingsboard.server.common.data.id.PluginId; | ||
19 | -import org.thingsboard.server.common.data.id.RuleId; | ||
20 | -import org.thingsboard.server.common.data.id.TenantId; | ||
21 | -import org.thingsboard.server.common.msg.aware.RuleAwareMsg; | ||
22 | -import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | ||
23 | -import org.thingsboard.server.extensions.api.plugins.msg.ToPluginActorMsg; | ||
24 | - | ||
25 | -public class RuleToPluginMsgWrapper implements ToPluginActorMsg, RuleAwareMsg { | ||
26 | - | ||
27 | - private final TenantId pluginTenantId; | ||
28 | - private final PluginId pluginId; | ||
29 | - private final TenantId ruleTenantId; | ||
30 | - private final RuleId ruleId; | ||
31 | - private final RuleToPluginMsg<?> msg; | ||
32 | - | ||
33 | - public RuleToPluginMsgWrapper(TenantId pluginTenantId, PluginId pluginId, TenantId ruleTenantId, RuleId ruleId, RuleToPluginMsg<?> msg) { | ||
34 | - super(); | ||
35 | - this.pluginTenantId = pluginTenantId; | ||
36 | - this.pluginId = pluginId; | ||
37 | - this.ruleTenantId = ruleTenantId; | ||
38 | - this.ruleId = ruleId; | ||
39 | - this.msg = msg; | ||
40 | - } | ||
41 | - | ||
42 | - @Override | ||
43 | - public TenantId getPluginTenantId() { | ||
44 | - return pluginTenantId; | ||
45 | - } | ||
46 | - | ||
47 | - @Override | ||
48 | - public PluginId getPluginId() { | ||
49 | - return pluginId; | ||
50 | - } | ||
51 | - | ||
52 | - public TenantId getRuleTenantId() { | ||
53 | - return ruleTenantId; | ||
54 | - } | ||
55 | - | ||
56 | - @Override | ||
57 | - public RuleId getRuleId() { | ||
58 | - return ruleId; | ||
59 | - } | ||
60 | - | ||
61 | - | ||
62 | - public RuleToPluginMsg getMsg() { | ||
63 | - return msg; | ||
64 | - } | ||
65 | - | ||
66 | -} |
application/src/main/java/org/thingsboard/server/actors/plugin/SharedPluginProcessingContext.java
deleted
100644 → 0
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.actors.plugin; | ||
17 | - | ||
18 | -import akka.actor.ActorRef; | ||
19 | -import lombok.extern.slf4j.Slf4j; | ||
20 | -import org.thingsboard.server.actors.ActorSystemContext; | ||
21 | -import org.thingsboard.server.common.data.id.DeviceId; | ||
22 | -import org.thingsboard.server.common.data.id.PluginId; | ||
23 | -import org.thingsboard.server.common.data.id.TenantId; | ||
24 | -import org.thingsboard.server.common.msg.TbActorMsg; | ||
25 | -import org.thingsboard.server.common.msg.cluster.ServerAddress; | ||
26 | -import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | ||
27 | -import org.thingsboard.server.common.msg.timeout.TimeoutMsg; | ||
28 | -import org.thingsboard.server.controller.plugin.PluginWebSocketMsgEndpoint; | ||
29 | -import org.thingsboard.server.dao.asset.AssetService; | ||
30 | -import org.thingsboard.server.dao.attributes.AttributesService; | ||
31 | -import org.thingsboard.server.dao.audit.AuditLogService; | ||
32 | -import org.thingsboard.server.dao.customer.CustomerService; | ||
33 | -import org.thingsboard.server.dao.device.DeviceService; | ||
34 | -import org.thingsboard.server.dao.plugin.PluginService; | ||
35 | -import org.thingsboard.server.dao.relation.RelationService; | ||
36 | -import org.thingsboard.server.dao.rule.RuleChainService; | ||
37 | -import org.thingsboard.server.dao.rule.RuleService; | ||
38 | -import org.thingsboard.server.dao.tenant.TenantService; | ||
39 | -import org.thingsboard.server.dao.timeseries.TimeseriesService; | ||
40 | -import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; | ||
41 | -import org.thingsboard.server.service.cluster.routing.ClusterRoutingService; | ||
42 | -import org.thingsboard.server.service.cluster.rpc.ClusterRpcService; | ||
43 | -import scala.concurrent.duration.Duration; | ||
44 | - | ||
45 | -import java.util.Optional; | ||
46 | -import java.util.concurrent.TimeUnit; | ||
47 | -import java.util.function.BiConsumer; | ||
48 | - | ||
49 | -@Slf4j | ||
50 | -public final class SharedPluginProcessingContext { | ||
51 | - final ActorRef parentActor; | ||
52 | - final ActorRef currentActor; | ||
53 | - final ActorSystemContext systemContext; | ||
54 | - final PluginWebSocketMsgEndpoint msgEndpoint; | ||
55 | - final AssetService assetService; | ||
56 | - final DeviceService deviceService; | ||
57 | - final RuleService ruleService; | ||
58 | - final RuleChainService ruleChainService; | ||
59 | - final PluginService pluginService; | ||
60 | - final CustomerService customerService; | ||
61 | - final TenantService tenantService; | ||
62 | - final TimeseriesService tsService; | ||
63 | - final AttributesService attributesService; | ||
64 | - final ClusterRpcService rpcService; | ||
65 | - final ClusterRoutingService routingService; | ||
66 | - final RelationService relationService; | ||
67 | - final AuditLogService auditLogService; | ||
68 | - final PluginId pluginId; | ||
69 | - final TenantId tenantId; | ||
70 | - | ||
71 | - public SharedPluginProcessingContext(ActorSystemContext sysContext, TenantId tenantId, PluginId pluginId, | ||
72 | - ActorRef parentActor, ActorRef self) { | ||
73 | - super(); | ||
74 | - this.tenantId = tenantId; | ||
75 | - this.pluginId = pluginId; | ||
76 | - this.parentActor = parentActor; | ||
77 | - this.currentActor = self; | ||
78 | - this.systemContext = sysContext; | ||
79 | - this.msgEndpoint = sysContext.getWsMsgEndpoint(); | ||
80 | - this.tsService = sysContext.getTsService(); | ||
81 | - this.attributesService = sysContext.getAttributesService(); | ||
82 | - this.assetService = sysContext.getAssetService(); | ||
83 | - this.deviceService = sysContext.getDeviceService(); | ||
84 | - this.rpcService = sysContext.getRpcService(); | ||
85 | - this.routingService = sysContext.getRoutingService(); | ||
86 | - this.ruleService = sysContext.getRuleService(); | ||
87 | - this.ruleChainService = sysContext.getRuleChainService(); | ||
88 | - this.pluginService = sysContext.getPluginService(); | ||
89 | - this.customerService = sysContext.getCustomerService(); | ||
90 | - this.tenantService = sysContext.getTenantService(); | ||
91 | - this.relationService = sysContext.getRelationService(); | ||
92 | - this.auditLogService = sysContext.getAuditLogService(); | ||
93 | - } | ||
94 | - | ||
95 | - public PluginId getPluginId() { | ||
96 | - return pluginId; | ||
97 | - } | ||
98 | - | ||
99 | - public TenantId getPluginTenantId() { | ||
100 | - return tenantId; | ||
101 | - } | ||
102 | - | ||
103 | - public void toDeviceActor(DeviceAttributesEventNotificationMsg msg) { | ||
104 | - forward(msg.getDeviceId(), msg); | ||
105 | - } | ||
106 | - | ||
107 | - public void sendRpcRequest(ToDeviceRpcRequest msg) { | ||
108 | - log.trace("[{}] Forwarding msg {} to device actor!", pluginId, msg); | ||
109 | -// ToDeviceRpcRequestPluginMsg rpcMsg = new ToDeviceRpcRequestPluginMsg(pluginId, tenantId, msg); | ||
110 | -// forward(msg.getDeviceId(), rpcMsg, rpcService::tell); | ||
111 | - } | ||
112 | - | ||
113 | - private <T extends TbActorMsg> void forward(DeviceId deviceId, T msg) { | ||
114 | - Optional<ServerAddress> instance = routingService.resolveById(deviceId); | ||
115 | - if (instance.isPresent()) { | ||
116 | - log.trace("[{}] Forwarding msg {} to remote device actor!", pluginId, msg); | ||
117 | - rpcService.tell(systemContext.getEncodingService().convertToProtoDataMessage(instance.get(), msg)); | ||
118 | - } else { | ||
119 | - log.trace("[{}] Forwarding msg {} to local device actor!", pluginId, msg); | ||
120 | - parentActor.tell(msg, ActorRef.noSender()); | ||
121 | - } | ||
122 | - } | ||
123 | - | ||
124 | - public void scheduleTimeoutMsg(TimeoutMsg msg) { | ||
125 | - log.debug("Scheduling msg {} with delay {} ms", msg, msg.getTimeout()); | ||
126 | - systemContext.getScheduler().scheduleOnce( | ||
127 | - Duration.create(msg.getTimeout(), TimeUnit.MILLISECONDS), | ||
128 | - currentActor, | ||
129 | - msg, | ||
130 | - systemContext.getActorSystem().dispatcher(), | ||
131 | - ActorRef.noSender()); | ||
132 | - | ||
133 | - } | ||
134 | - | ||
135 | - public void persistError(String method, Exception e) { | ||
136 | - systemContext.persistError(tenantId, pluginId, method, e); | ||
137 | - } | ||
138 | - | ||
139 | - public ActorRef self() { | ||
140 | - return currentActor; | ||
141 | - } | ||
142 | -} |
application/src/main/java/org/thingsboard/server/actors/plugin/TimeoutScheduler.java
deleted
100644 → 0
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.actors.plugin; | ||
17 | - | ||
18 | -import akka.actor.ActorRef; | ||
19 | - | ||
20 | -/** | ||
21 | - * @author Andrew Shvayka | ||
22 | - */ | ||
23 | -public interface TimeoutScheduler { | ||
24 | - | ||
25 | - void scheduleMsgWithDelay(Object msg, long delayInMs); | ||
26 | - | ||
27 | -} |
application/src/main/java/org/thingsboard/server/actors/plugin/ValidationCallback.java
deleted
100644 → 0
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.actors.plugin; | ||
17 | - | ||
18 | -import java.util.function.Consumer; | ||
19 | -import org.thingsboard.server.extensions.api.exception.AccessDeniedException; | ||
20 | -import org.thingsboard.server.extensions.api.exception.EntityNotFoundException; | ||
21 | -import org.thingsboard.server.extensions.api.exception.InternalErrorException; | ||
22 | -import org.thingsboard.server.extensions.api.exception.UnauthorizedException; | ||
23 | -import org.thingsboard.server.extensions.api.plugins.PluginCallback; | ||
24 | -import org.thingsboard.server.extensions.api.plugins.PluginContext; | ||
25 | - | ||
26 | -/** | ||
27 | - * Created by ashvayka on 21.02.17. | ||
28 | - */ | ||
29 | -public class ValidationCallback implements PluginCallback<ValidationResult> { | ||
30 | - | ||
31 | - private final PluginCallback<?> callback; | ||
32 | - private final Consumer<PluginContext> action; | ||
33 | - | ||
34 | - public ValidationCallback(PluginCallback<?> callback, Consumer<PluginContext> action) { | ||
35 | - this.callback = callback; | ||
36 | - this.action = action; | ||
37 | - } | ||
38 | - | ||
39 | - @Override | ||
40 | - public void onSuccess(PluginContext ctx, ValidationResult result) { | ||
41 | - ValidationResultCode resultCode = result.getResultCode(); | ||
42 | - if (resultCode == ValidationResultCode.OK) { | ||
43 | - action.accept(ctx); | ||
44 | - } else { | ||
45 | - Exception e; | ||
46 | - switch (resultCode) { | ||
47 | - case ENTITY_NOT_FOUND: | ||
48 | - e = new EntityNotFoundException(result.getMessage()); | ||
49 | - break; | ||
50 | - case UNAUTHORIZED: | ||
51 | - e = new UnauthorizedException(result.getMessage()); | ||
52 | - break; | ||
53 | - case ACCESS_DENIED: | ||
54 | - e = new AccessDeniedException(result.getMessage()); | ||
55 | - break; | ||
56 | - case INTERNAL_ERROR: | ||
57 | - e = new InternalErrorException(result.getMessage()); | ||
58 | - break; | ||
59 | - default: | ||
60 | - e = new UnauthorizedException("Permission denied."); | ||
61 | - break; | ||
62 | - } | ||
63 | - onFailure(ctx, e); | ||
64 | - } | ||
65 | - } | ||
66 | - | ||
67 | - @Override | ||
68 | - public void onFailure(PluginContext ctx, Exception e) { | ||
69 | - callback.onFailure(ctx, e); | ||
70 | - } | ||
71 | -} |
@@ -29,7 +29,11 @@ import org.thingsboard.server.common.msg.cluster.ServerAddress; | @@ -29,7 +29,11 @@ import org.thingsboard.server.common.msg.cluster.ServerAddress; | ||
29 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; | 29 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; |
30 | import org.thingsboard.server.service.cluster.discovery.ServerInstance; | 30 | import org.thingsboard.server.service.cluster.discovery.ServerInstance; |
31 | 31 | ||
32 | -import java.util.*; | 32 | +import java.util.HashMap; |
33 | +import java.util.LinkedList; | ||
34 | +import java.util.Map; | ||
35 | +import java.util.Queue; | ||
36 | +import java.util.UUID; | ||
33 | 37 | ||
34 | /** | 38 | /** |
35 | * @author Andrew Shvayka | 39 | * @author Andrew Shvayka |
@@ -16,7 +16,6 @@ | @@ -16,7 +16,6 @@ | ||
16 | package org.thingsboard.server.actors.rpc; | 16 | package org.thingsboard.server.actors.rpc; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | -import org.thingsboard.server.common.msg.cluster.ServerAddress; | ||
20 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; | 19 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; |
21 | 20 | ||
22 | /** | 21 | /** |
@@ -17,8 +17,14 @@ package org.thingsboard.server.actors.ruleChain; | @@ -17,8 +17,14 @@ package org.thingsboard.server.actors.ruleChain; | ||
17 | 17 | ||
18 | import akka.actor.ActorRef; | 18 | import akka.actor.ActorRef; |
19 | import com.datastax.driver.core.utils.UUIDs; | 19 | import com.datastax.driver.core.utils.UUIDs; |
20 | -import com.google.common.base.Function; | ||
21 | -import org.thingsboard.rule.engine.api.*; | 20 | +import org.thingsboard.rule.engine.api.ListeningExecutor; |
21 | +import org.thingsboard.rule.engine.api.MailService; | ||
22 | +import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcRequest; | ||
23 | +import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcResponse; | ||
24 | +import org.thingsboard.rule.engine.api.RuleEngineRpcService; | ||
25 | +import org.thingsboard.rule.engine.api.RuleEngineTelemetryService; | ||
26 | +import org.thingsboard.rule.engine.api.ScriptEngine; | ||
27 | +import org.thingsboard.rule.engine.api.TbContext; | ||
22 | import org.thingsboard.server.actors.ActorSystemContext; | 28 | import org.thingsboard.server.actors.ActorSystemContext; |
23 | import org.thingsboard.server.common.data.id.DeviceId; | 29 | import org.thingsboard.server.common.data.id.DeviceId; |
24 | import org.thingsboard.server.common.data.id.EntityId; | 30 | import org.thingsboard.server.common.data.id.EntityId; |
@@ -28,14 +34,12 @@ import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | @@ -28,14 +34,12 @@ import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | ||
28 | import org.thingsboard.server.common.data.rule.RuleNode; | 34 | import org.thingsboard.server.common.data.rule.RuleNode; |
29 | import org.thingsboard.server.common.msg.TbMsg; | 35 | import org.thingsboard.server.common.msg.TbMsg; |
30 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 36 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
31 | -import org.thingsboard.server.common.msg.cluster.ServerAddress; | ||
32 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 37 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
33 | import org.thingsboard.server.dao.alarm.AlarmService; | 38 | import org.thingsboard.server.dao.alarm.AlarmService; |
34 | import org.thingsboard.server.dao.asset.AssetService; | 39 | import org.thingsboard.server.dao.asset.AssetService; |
35 | import org.thingsboard.server.dao.attributes.AttributesService; | 40 | import org.thingsboard.server.dao.attributes.AttributesService; |
36 | import org.thingsboard.server.dao.customer.CustomerService; | 41 | import org.thingsboard.server.dao.customer.CustomerService; |
37 | import org.thingsboard.server.dao.device.DeviceService; | 42 | import org.thingsboard.server.dao.device.DeviceService; |
38 | -import org.thingsboard.server.dao.plugin.PluginService; | ||
39 | import org.thingsboard.server.dao.relation.RelationService; | 43 | import org.thingsboard.server.dao.relation.RelationService; |
40 | import org.thingsboard.server.dao.rule.RuleChainService; | 44 | import org.thingsboard.server.dao.rule.RuleChainService; |
41 | import org.thingsboard.server.dao.timeseries.TimeseriesService; | 45 | import org.thingsboard.server.dao.timeseries.TimeseriesService; |
@@ -44,7 +48,6 @@ import org.thingsboard.server.service.script.NashornJsEngine; | @@ -44,7 +48,6 @@ import org.thingsboard.server.service.script.NashornJsEngine; | ||
44 | import scala.concurrent.duration.Duration; | 48 | import scala.concurrent.duration.Duration; |
45 | 49 | ||
46 | import java.util.Collections; | 50 | import java.util.Collections; |
47 | -import java.util.List; | ||
48 | import java.util.Set; | 51 | import java.util.Set; |
49 | import java.util.concurrent.TimeUnit; | 52 | import java.util.concurrent.TimeUnit; |
50 | import java.util.function.Consumer; | 53 | import java.util.function.Consumer; |
@@ -168,11 +171,6 @@ class DefaultTbContext implements TbContext { | @@ -168,11 +171,6 @@ class DefaultTbContext implements TbContext { | ||
168 | } | 171 | } |
169 | 172 | ||
170 | @Override | 173 | @Override |
171 | - public PluginService getPluginService() { | ||
172 | - return mainCtx.getPluginService(); | ||
173 | - } | ||
174 | - | ||
175 | - @Override | ||
176 | public AssetService getAssetService() { | 174 | public AssetService getAssetService() { |
177 | return mainCtx.getAssetService(); | 175 | return mainCtx.getAssetService(); |
178 | } | 176 | } |
@@ -18,10 +18,8 @@ package org.thingsboard.server.actors.ruleChain; | @@ -18,10 +18,8 @@ package org.thingsboard.server.actors.ruleChain; | ||
18 | import akka.actor.ActorRef; | 18 | import akka.actor.ActorRef; |
19 | import org.thingsboard.server.actors.ActorSystemContext; | 19 | import org.thingsboard.server.actors.ActorSystemContext; |
20 | import org.thingsboard.server.actors.service.ContextAwareActor; | 20 | import org.thingsboard.server.actors.service.ContextAwareActor; |
21 | -import org.thingsboard.server.actors.shared.plugin.PluginManager; | ||
22 | import org.thingsboard.server.actors.shared.rulechain.RuleChainManager; | 21 | import org.thingsboard.server.actors.shared.rulechain.RuleChainManager; |
23 | import org.thingsboard.server.common.data.id.EntityId; | 22 | import org.thingsboard.server.common.data.id.EntityId; |
24 | -import org.thingsboard.server.common.data.id.PluginId; | ||
25 | import org.thingsboard.server.common.data.id.RuleChainId; | 23 | import org.thingsboard.server.common.data.id.RuleChainId; |
26 | import org.thingsboard.server.dao.rule.RuleChainService; | 24 | import org.thingsboard.server.dao.rule.RuleChainService; |
27 | 25 | ||
@@ -33,7 +31,7 @@ public abstract class RuleChainManagerActor extends ContextAwareActor { | @@ -33,7 +31,7 @@ public abstract class RuleChainManagerActor extends ContextAwareActor { | ||
33 | protected final RuleChainManager ruleChainManager; | 31 | protected final RuleChainManager ruleChainManager; |
34 | protected final RuleChainService ruleChainService; | 32 | protected final RuleChainService ruleChainService; |
35 | 33 | ||
36 | - public RuleChainManagerActor(ActorSystemContext systemContext, RuleChainManager ruleChainManager, PluginManager pluginManager) { | 34 | + public RuleChainManagerActor(ActorSystemContext systemContext, RuleChainManager ruleChainManager) { |
37 | super(systemContext); | 35 | super(systemContext); |
38 | this.ruleChainManager = ruleChainManager; | 36 | this.ruleChainManager = ruleChainManager; |
39 | this.ruleChainService = systemContext.getRuleChainService(); | 37 | this.ruleChainService = systemContext.getRuleChainService(); |
@@ -16,7 +16,6 @@ | @@ -16,7 +16,6 @@ | ||
16 | package org.thingsboard.server.actors.ruleChain; | 16 | package org.thingsboard.server.actors.ruleChain; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | -import org.thingsboard.rule.engine.api.TbContext; | ||
20 | import org.thingsboard.server.common.data.id.RuleChainId; | 19 | import org.thingsboard.server.common.data.id.RuleChainId; |
21 | import org.thingsboard.server.common.msg.MsgType; | 20 | import org.thingsboard.server.common.msg.MsgType; |
22 | import org.thingsboard.server.common.msg.TbActorMsg; | 21 | import org.thingsboard.server.common.msg.TbActorMsg; |
application/src/main/java/org/thingsboard/server/actors/ruleChain/RuleNodeActorMessageProcessor.java
@@ -21,7 +21,6 @@ import akka.event.LoggingAdapter; | @@ -21,7 +21,6 @@ import akka.event.LoggingAdapter; | ||
21 | import org.thingsboard.rule.engine.api.TbContext; | 21 | import org.thingsboard.rule.engine.api.TbContext; |
22 | import org.thingsboard.rule.engine.api.TbNode; | 22 | import org.thingsboard.rule.engine.api.TbNode; |
23 | import org.thingsboard.rule.engine.api.TbNodeConfiguration; | 23 | import org.thingsboard.rule.engine.api.TbNodeConfiguration; |
24 | -import org.thingsboard.rule.engine.api.TbNodeException; | ||
25 | import org.thingsboard.server.actors.ActorSystemContext; | 24 | import org.thingsboard.server.actors.ActorSystemContext; |
26 | import org.thingsboard.server.actors.shared.ComponentMsgProcessor; | 25 | import org.thingsboard.server.actors.shared.ComponentMsgProcessor; |
27 | import org.thingsboard.server.common.data.id.RuleChainId; | 26 | import org.thingsboard.server.common.data.id.RuleChainId; |
@@ -32,8 +31,6 @@ import org.thingsboard.server.common.data.rule.RuleNode; | @@ -32,8 +31,6 @@ import org.thingsboard.server.common.data.rule.RuleNode; | ||
32 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | 31 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
33 | import org.thingsboard.server.dao.rule.RuleChainService; | 32 | import org.thingsboard.server.dao.rule.RuleChainService; |
34 | 33 | ||
35 | -import java.util.concurrent.ExecutionException; | ||
36 | - | ||
37 | /** | 34 | /** |
38 | * @author Andrew Shvayka | 35 | * @author Andrew Shvayka |
39 | */ | 36 | */ |
@@ -16,7 +16,6 @@ | @@ -16,7 +16,6 @@ | ||
16 | package org.thingsboard.server.actors.ruleChain; | 16 | package org.thingsboard.server.actors.ruleChain; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | -import org.thingsboard.server.common.data.id.RuleNodeId; | ||
20 | import org.thingsboard.server.common.msg.MsgType; | 19 | import org.thingsboard.server.common.msg.MsgType; |
21 | import org.thingsboard.server.common.msg.TbActorMsg; | 20 | import org.thingsboard.server.common.msg.TbActorMsg; |
22 | import org.thingsboard.server.common.msg.TbMsg; | 21 | import org.thingsboard.server.common.msg.TbMsg; |
@@ -15,16 +15,17 @@ | @@ -15,16 +15,17 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.actors.service; | 16 | package org.thingsboard.server.actors.service; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.data.id.*; | 18 | +import org.thingsboard.server.common.data.id.DeviceId; |
19 | +import org.thingsboard.server.common.data.id.EntityId; | ||
20 | +import org.thingsboard.server.common.data.id.TenantId; | ||
19 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | 21 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
20 | -import org.thingsboard.server.common.msg.TbMsg; | ||
21 | import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; | 22 | import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; |
22 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; | 23 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; |
23 | import org.thingsboard.server.common.transport.SessionMsgProcessor; | 24 | import org.thingsboard.server.common.transport.SessionMsgProcessor; |
24 | import org.thingsboard.server.service.cluster.discovery.DiscoveryServiceListener; | 25 | import org.thingsboard.server.service.cluster.discovery.DiscoveryServiceListener; |
25 | import org.thingsboard.server.service.cluster.rpc.RpcMsgListener; | 26 | import org.thingsboard.server.service.cluster.rpc.RpcMsgListener; |
26 | 27 | ||
27 | -public interface ActorService extends SessionMsgProcessor, WebSocketMsgProcessor, RestMsgProcessor, RpcMsgListener, DiscoveryServiceListener { | 28 | +public interface ActorService extends SessionMsgProcessor, RpcMsgListener, DiscoveryServiceListener { |
28 | 29 | ||
29 | void onEntityStateChange(TenantId tenantId, EntityId entityId, ComponentLifecycleEvent state); | 30 | void onEntityStateChange(TenantId tenantId, EntityId entityId, ComponentLifecycleEvent state); |
30 | 31 |
@@ -15,9 +15,8 @@ | @@ -15,9 +15,8 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.actors.service; | 16 | package org.thingsboard.server.actors.service; |
17 | 17 | ||
18 | -import org.thingsboard.server.actors.ActorSystemContext; | ||
19 | - | ||
20 | import akka.japi.Creator; | 18 | import akka.japi.Creator; |
19 | +import org.thingsboard.server.actors.ActorSystemContext; | ||
21 | 20 | ||
22 | public abstract class ContextBasedCreator<T> implements Creator<T> { | 21 | public abstract class ContextBasedCreator<T> implements Creator<T> { |
23 | 22 |
@@ -23,6 +23,8 @@ import com.google.protobuf.ByteString; | @@ -23,6 +23,8 @@ import com.google.protobuf.ByteString; | ||
23 | import lombok.extern.slf4j.Slf4j; | 23 | import lombok.extern.slf4j.Slf4j; |
24 | import org.springframework.beans.factory.annotation.Autowired; | 24 | import org.springframework.beans.factory.annotation.Autowired; |
25 | import org.springframework.stereotype.Service; | 25 | import org.springframework.stereotype.Service; |
26 | +import org.thingsboard.rule.engine.api.msg.DeviceCredentialsUpdateNotificationMsg; | ||
27 | +import org.thingsboard.rule.engine.api.msg.DeviceNameOrTypeUpdateMsg; | ||
26 | import org.thingsboard.server.actors.ActorSystemContext; | 28 | import org.thingsboard.server.actors.ActorSystemContext; |
27 | import org.thingsboard.server.actors.app.AppActor; | 29 | import org.thingsboard.server.actors.app.AppActor; |
28 | import org.thingsboard.server.actors.rpc.RpcBroadcastMsg; | 30 | import org.thingsboard.server.actors.rpc.RpcBroadcastMsg; |
@@ -30,7 +32,9 @@ import org.thingsboard.server.actors.rpc.RpcManagerActor; | @@ -30,7 +32,9 @@ import org.thingsboard.server.actors.rpc.RpcManagerActor; | ||
30 | import org.thingsboard.server.actors.rpc.RpcSessionCreateRequestMsg; | 32 | import org.thingsboard.server.actors.rpc.RpcSessionCreateRequestMsg; |
31 | import org.thingsboard.server.actors.session.SessionManagerActor; | 33 | import org.thingsboard.server.actors.session.SessionManagerActor; |
32 | import org.thingsboard.server.actors.stats.StatsActor; | 34 | import org.thingsboard.server.actors.stats.StatsActor; |
33 | -import org.thingsboard.server.common.data.id.*; | 35 | +import org.thingsboard.server.common.data.id.DeviceId; |
36 | +import org.thingsboard.server.common.data.id.EntityId; | ||
37 | +import org.thingsboard.server.common.data.id.TenantId; | ||
34 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | 38 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
35 | import org.thingsboard.server.common.msg.TbActorMsg; | 39 | import org.thingsboard.server.common.msg.TbActorMsg; |
36 | import org.thingsboard.server.common.msg.aware.SessionAwareMsg; | 40 | import org.thingsboard.server.common.msg.aware.SessionAwareMsg; |
@@ -38,12 +42,8 @@ import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | @@ -38,12 +42,8 @@ import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | ||
38 | import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; | 42 | import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; |
39 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 43 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
40 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; | 44 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; |
41 | -import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; | ||
42 | -import org.thingsboard.server.extensions.api.device.DeviceNameOrTypeUpdateMsg; | ||
43 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; | 45 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; |
44 | -import org.thingsboard.server.extensions.api.device.DeviceCredentialsUpdateNotificationMsg; | ||
45 | -import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; | ||
46 | -import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; | 46 | +import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; |
47 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; | 47 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; |
48 | import org.thingsboard.server.service.cluster.discovery.DiscoveryService; | 48 | import org.thingsboard.server.service.cluster.discovery.DiscoveryService; |
49 | import org.thingsboard.server.service.cluster.discovery.ServerInstance; | 49 | import org.thingsboard.server.service.cluster.discovery.ServerInstance; |
@@ -91,7 +91,7 @@ public class DefaultActorService implements ActorService { | @@ -91,7 +91,7 @@ public class DefaultActorService implements ActorService { | ||
91 | 91 | ||
92 | @PostConstruct | 92 | @PostConstruct |
93 | public void initActorSystem() { | 93 | public void initActorSystem() { |
94 | - log.info("Initializing Actor system. {}", actorContext.getRuleService()); | 94 | + log.info("Initializing Actor system. {}", actorContext.getRuleChainService()); |
95 | actorContext.setActorService(this); | 95 | actorContext.setActorService(this); |
96 | system = ActorSystem.create(ACTOR_SYSTEM_NAME, actorContext.getConfig()); | 96 | system = ActorSystem.create(ACTOR_SYSTEM_NAME, actorContext.getConfig()); |
97 | actorContext.setActorSystem(system); | 97 | actorContext.setActorSystem(system); |
@@ -138,19 +138,6 @@ public class DefaultActorService implements ActorService { | @@ -138,19 +138,6 @@ public class DefaultActorService implements ActorService { | ||
138 | } | 138 | } |
139 | 139 | ||
140 | @Override | 140 | @Override |
141 | - public void process(PluginWebsocketMsg<?> msg) { | ||
142 | - log.debug("Processing websocket msg: {}", msg); | ||
143 | - appActor.tell(msg, ActorRef.noSender()); | ||
144 | - } | ||
145 | - | ||
146 | - @Override | ||
147 | - public void process(PluginRestMsg msg) { | ||
148 | - log.debug("Processing rest msg: {}", msg); | ||
149 | - appActor.tell(msg, ActorRef.noSender()); | ||
150 | - } | ||
151 | - | ||
152 | - | ||
153 | - @Override | ||
154 | public void onServerAdded(ServerInstance server) { | 141 | public void onServerAdded(ServerInstance server) { |
155 | log.trace("Processing onServerAdded msg: {}", server); | 142 | log.trace("Processing onServerAdded msg: {}", server); |
156 | broadcast(new ClusterEventMsg(server.getServerAddress(), true)); | 143 | broadcast(new ClusterEventMsg(server.getServerAddress(), true)); |
@@ -263,4 +250,5 @@ public class DefaultActorService implements ActorService { | @@ -263,4 +250,5 @@ public class DefaultActorService implements ActorService { | ||
263 | public void onBroadcastMsg(RpcBroadcastMsg msg) { | 250 | public void onBroadcastMsg(RpcBroadcastMsg msg) { |
264 | rpcManagerActor.tell(msg, ActorRef.noSender()); | 251 | rpcManagerActor.tell(msg, ActorRef.noSender()); |
265 | } | 252 | } |
253 | + | ||
266 | } | 254 | } |
application/src/main/java/org/thingsboard/server/actors/service/RestMsgProcessor.java
deleted
100644 → 0
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.actors.service; | ||
17 | - | ||
18 | -import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; | ||
19 | - | ||
20 | -public interface RestMsgProcessor { | ||
21 | - | ||
22 | - void process(PluginRestMsg msg); | ||
23 | - | ||
24 | -} |
application/src/main/java/org/thingsboard/server/actors/service/WebSocketMsgProcessor.java
deleted
100644 → 0
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.actors.service; | ||
17 | - | ||
18 | -import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; | ||
19 | - | ||
20 | -public interface WebSocketMsgProcessor { | ||
21 | - | ||
22 | - void process(PluginWebsocketMsg<?> msg); | ||
23 | - | ||
24 | -} |
@@ -15,18 +15,26 @@ | @@ -15,18 +15,26 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.actors.session; | 16 | package org.thingsboard.server.actors.session; |
17 | 17 | ||
18 | +import akka.actor.ActorContext; | ||
19 | +import akka.event.LoggingAdapter; | ||
18 | import org.thingsboard.server.actors.ActorSystemContext; | 20 | import org.thingsboard.server.actors.ActorSystemContext; |
19 | import org.thingsboard.server.actors.shared.SessionTimeoutMsg; | 21 | import org.thingsboard.server.actors.shared.SessionTimeoutMsg; |
20 | import org.thingsboard.server.common.data.id.SessionId; | 22 | import org.thingsboard.server.common.data.id.SessionId; |
21 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | 23 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
22 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 24 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
23 | -import org.thingsboard.server.common.msg.core.*; | 25 | +import org.thingsboard.server.common.msg.core.AttributesSubscribeMsg; |
26 | +import org.thingsboard.server.common.msg.core.ResponseMsg; | ||
27 | +import org.thingsboard.server.common.msg.core.RpcSubscribeMsg; | ||
24 | import org.thingsboard.server.common.msg.core.SessionCloseMsg; | 28 | import org.thingsboard.server.common.msg.core.SessionCloseMsg; |
29 | +import org.thingsboard.server.common.msg.core.SessionOpenMsg; | ||
25 | import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; | 30 | import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
26 | -import org.thingsboard.server.common.msg.session.*; | ||
27 | - | ||
28 | -import akka.actor.ActorContext; | ||
29 | -import akka.event.LoggingAdapter; | 31 | +import org.thingsboard.server.common.msg.session.BasicSessionActorToAdaptorMsg; |
32 | +import org.thingsboard.server.common.msg.session.FromDeviceMsg; | ||
33 | +import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | ||
34 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
35 | +import org.thingsboard.server.common.msg.session.SessionType; | ||
36 | +import org.thingsboard.server.common.msg.session.ToDeviceMsg; | ||
37 | +import org.thingsboard.server.common.msg.session.TransportToDeviceSessionActorMsg; | ||
30 | import org.thingsboard.server.common.msg.session.ex.SessionException; | 38 | import org.thingsboard.server.common.msg.session.ex.SessionException; |
31 | 39 | ||
32 | import java.util.HashMap; | 40 | import java.util.HashMap; |
@@ -15,6 +15,9 @@ | @@ -15,6 +15,9 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.actors.session; | 16 | package org.thingsboard.server.actors.session; |
17 | 17 | ||
18 | +import akka.actor.ActorContext; | ||
19 | +import akka.actor.ActorRef; | ||
20 | +import akka.event.LoggingAdapter; | ||
18 | import org.thingsboard.server.actors.ActorSystemContext; | 21 | import org.thingsboard.server.actors.ActorSystemContext; |
19 | import org.thingsboard.server.actors.shared.AbstractContextAwareMsgProcessor; | 22 | import org.thingsboard.server.actors.shared.AbstractContextAwareMsgProcessor; |
20 | import org.thingsboard.server.actors.shared.SessionTimeoutMsg; | 23 | import org.thingsboard.server.actors.shared.SessionTimeoutMsg; |
@@ -25,13 +28,15 @@ import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; | @@ -25,13 +28,15 @@ import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; | ||
25 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 28 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
26 | import org.thingsboard.server.common.msg.device.BasicDeviceToDeviceActorMsg; | 29 | import org.thingsboard.server.common.msg.device.BasicDeviceToDeviceActorMsg; |
27 | import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; | 30 | import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
28 | -import org.thingsboard.server.common.msg.session.*; | 31 | +import org.thingsboard.server.common.msg.session.AdaptorToSessionActorMsg; |
32 | +import org.thingsboard.server.common.msg.session.FromDeviceMsg; | ||
33 | +import org.thingsboard.server.common.msg.session.SessionContext; | ||
34 | +import org.thingsboard.server.common.msg.session.SessionCtrlMsg; | ||
35 | +import org.thingsboard.server.common.msg.session.SessionType; | ||
36 | +import org.thingsboard.server.common.msg.session.ToDeviceMsg; | ||
37 | +import org.thingsboard.server.common.msg.session.TransportToDeviceSessionActorMsg; | ||
29 | import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg; | 38 | import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg; |
30 | 39 | ||
31 | -import akka.actor.ActorContext; | ||
32 | -import akka.actor.ActorRef; | ||
33 | -import akka.event.LoggingAdapter; | ||
34 | - | ||
35 | import java.util.Optional; | 40 | import java.util.Optional; |
36 | 41 | ||
37 | abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgProcessor { | 42 | abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgProcessor { |
@@ -17,6 +17,8 @@ package org.thingsboard.server.actors.session; | @@ -17,6 +17,8 @@ package org.thingsboard.server.actors.session; | ||
17 | 17 | ||
18 | import akka.actor.OneForOneStrategy; | 18 | import akka.actor.OneForOneStrategy; |
19 | import akka.actor.SupervisorStrategy; | 19 | import akka.actor.SupervisorStrategy; |
20 | +import akka.event.Logging; | ||
21 | +import akka.event.LoggingAdapter; | ||
20 | import org.thingsboard.server.actors.ActorSystemContext; | 22 | import org.thingsboard.server.actors.ActorSystemContext; |
21 | import org.thingsboard.server.actors.service.ContextAwareActor; | 23 | import org.thingsboard.server.actors.service.ContextAwareActor; |
22 | import org.thingsboard.server.actors.service.ContextBasedCreator; | 24 | import org.thingsboard.server.actors.service.ContextBasedCreator; |
@@ -25,14 +27,11 @@ import org.thingsboard.server.common.data.id.SessionId; | @@ -25,14 +27,11 @@ import org.thingsboard.server.common.data.id.SessionId; | ||
25 | import org.thingsboard.server.common.msg.TbActorMsg; | 27 | import org.thingsboard.server.common.msg.TbActorMsg; |
26 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | 28 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
27 | import org.thingsboard.server.common.msg.core.ActorSystemToDeviceSessionActorMsg; | 29 | import org.thingsboard.server.common.msg.core.ActorSystemToDeviceSessionActorMsg; |
28 | -import org.thingsboard.server.common.msg.session.TransportToDeviceSessionActorMsg; | ||
29 | import org.thingsboard.server.common.msg.session.SessionCtrlMsg; | 30 | import org.thingsboard.server.common.msg.session.SessionCtrlMsg; |
30 | import org.thingsboard.server.common.msg.session.SessionMsg; | 31 | import org.thingsboard.server.common.msg.session.SessionMsg; |
31 | import org.thingsboard.server.common.msg.session.SessionType; | 32 | import org.thingsboard.server.common.msg.session.SessionType; |
33 | +import org.thingsboard.server.common.msg.session.TransportToDeviceSessionActorMsg; | ||
32 | import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg; | 34 | import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg; |
33 | - | ||
34 | -import akka.event.Logging; | ||
35 | -import akka.event.LoggingAdapter; | ||
36 | import scala.concurrent.duration.Duration; | 35 | import scala.concurrent.duration.Duration; |
37 | 36 | ||
38 | public class SessionActor extends ContextAwareActor { | 37 | public class SessionActor extends ContextAwareActor { |
@@ -15,10 +15,13 @@ | @@ -15,10 +15,13 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.actors.session; | 16 | package org.thingsboard.server.actors.session; |
17 | 17 | ||
18 | -import java.util.HashMap; | ||
19 | -import java.util.Map; | ||
20 | - | ||
21 | -import akka.actor.*; | 18 | +import akka.actor.ActorRef; |
19 | +import akka.actor.InvalidActorNameException; | ||
20 | +import akka.actor.LocalActorRef; | ||
21 | +import akka.actor.Props; | ||
22 | +import akka.actor.Terminated; | ||
23 | +import akka.event.Logging; | ||
24 | +import akka.event.LoggingAdapter; | ||
22 | import org.thingsboard.server.actors.ActorSystemContext; | 25 | import org.thingsboard.server.actors.ActorSystemContext; |
23 | import org.thingsboard.server.actors.service.ContextAwareActor; | 26 | import org.thingsboard.server.actors.service.ContextAwareActor; |
24 | import org.thingsboard.server.actors.service.ContextBasedCreator; | 27 | import org.thingsboard.server.actors.service.ContextBasedCreator; |
@@ -27,14 +30,13 @@ import org.thingsboard.server.actors.shared.SessionTimeoutMsg; | @@ -27,14 +30,13 @@ import org.thingsboard.server.actors.shared.SessionTimeoutMsg; | ||
27 | import org.thingsboard.server.common.data.id.SessionId; | 30 | import org.thingsboard.server.common.data.id.SessionId; |
28 | import org.thingsboard.server.common.msg.TbActorMsg; | 31 | import org.thingsboard.server.common.msg.TbActorMsg; |
29 | import org.thingsboard.server.common.msg.aware.SessionAwareMsg; | 32 | import org.thingsboard.server.common.msg.aware.SessionAwareMsg; |
30 | - | ||
31 | -import akka.event.Logging; | ||
32 | -import akka.event.LoggingAdapter; | ||
33 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | 33 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
34 | -import org.thingsboard.server.common.msg.core.SessionCloseMsg; | ||
35 | import org.thingsboard.server.common.msg.core.ActorSystemToDeviceSessionActorMsg; | 34 | import org.thingsboard.server.common.msg.core.ActorSystemToDeviceSessionActorMsg; |
35 | +import org.thingsboard.server.common.msg.core.SessionCloseMsg; | ||
36 | import org.thingsboard.server.common.msg.session.SessionCtrlMsg; | 36 | import org.thingsboard.server.common.msg.session.SessionCtrlMsg; |
37 | -import org.thingsboard.server.common.msg.session.TransportToDeviceSessionActorMsg; | 37 | + |
38 | +import java.util.HashMap; | ||
39 | +import java.util.Map; | ||
38 | 40 | ||
39 | public class SessionManagerActor extends ContextAwareActor { | 41 | public class SessionManagerActor extends ContextAwareActor { |
40 | 42 |
@@ -15,20 +15,22 @@ | @@ -15,20 +15,22 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.actors.session; | 16 | package org.thingsboard.server.actors.session; |
17 | 17 | ||
18 | +import akka.actor.ActorContext; | ||
19 | +import akka.event.LoggingAdapter; | ||
18 | import org.thingsboard.server.actors.ActorSystemContext; | 20 | import org.thingsboard.server.actors.ActorSystemContext; |
19 | import org.thingsboard.server.actors.shared.SessionTimeoutMsg; | 21 | import org.thingsboard.server.actors.shared.SessionTimeoutMsg; |
20 | import org.thingsboard.server.common.data.id.SessionId; | 22 | import org.thingsboard.server.common.data.id.SessionId; |
21 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | 23 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
22 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 24 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
23 | import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; | 25 | import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
24 | -import org.thingsboard.server.common.msg.session.*; | 26 | +import org.thingsboard.server.common.msg.session.BasicSessionActorToAdaptorMsg; |
27 | +import org.thingsboard.server.common.msg.session.SessionContext; | ||
28 | +import org.thingsboard.server.common.msg.session.SessionType; | ||
29 | +import org.thingsboard.server.common.msg.session.ToDeviceMsg; | ||
25 | import org.thingsboard.server.common.msg.session.TransportToDeviceSessionActorMsg; | 30 | import org.thingsboard.server.common.msg.session.TransportToDeviceSessionActorMsg; |
26 | import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg; | 31 | import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg; |
27 | import org.thingsboard.server.common.msg.session.ex.SessionException; | 32 | import org.thingsboard.server.common.msg.session.ex.SessionException; |
28 | 33 | ||
29 | -import akka.actor.ActorContext; | ||
30 | -import akka.event.LoggingAdapter; | ||
31 | - | ||
32 | import java.util.Optional; | 34 | import java.util.Optional; |
33 | 35 | ||
34 | class SyncMsgProcessor extends AbstractSessionActorMsgProcessor { | 36 | class SyncMsgProcessor extends AbstractSessionActorMsgProcessor { |
application/src/main/java/org/thingsboard/server/actors/shared/AbstractContextAwareMsgProcessor.java
@@ -19,18 +19,13 @@ import akka.actor.ActorContext; | @@ -19,18 +19,13 @@ import akka.actor.ActorContext; | ||
19 | import akka.actor.ActorRef; | 19 | import akka.actor.ActorRef; |
20 | import akka.actor.Scheduler; | 20 | import akka.actor.Scheduler; |
21 | import akka.event.LoggingAdapter; | 21 | import akka.event.LoggingAdapter; |
22 | -import com.fasterxml.jackson.databind.JsonNode; | ||
23 | import com.fasterxml.jackson.databind.ObjectMapper; | 22 | import com.fasterxml.jackson.databind.ObjectMapper; |
24 | import lombok.AllArgsConstructor; | 23 | import lombok.AllArgsConstructor; |
25 | import lombok.Data; | 24 | import lombok.Data; |
26 | import org.thingsboard.server.actors.ActorSystemContext; | 25 | import org.thingsboard.server.actors.ActorSystemContext; |
27 | -import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | ||
28 | -import org.thingsboard.server.common.data.plugin.ComponentType; | ||
29 | -import org.thingsboard.server.extensions.api.component.*; | ||
30 | import scala.concurrent.ExecutionContextExecutor; | 26 | import scala.concurrent.ExecutionContextExecutor; |
31 | import scala.concurrent.duration.Duration; | 27 | import scala.concurrent.duration.Duration; |
32 | 28 | ||
33 | -import java.io.IOException; | ||
34 | import java.util.concurrent.TimeUnit; | 29 | import java.util.concurrent.TimeUnit; |
35 | 30 | ||
36 | public abstract class AbstractContextAwareMsgProcessor { | 31 | public abstract class AbstractContextAwareMsgProcessor { |
@@ -76,50 +71,6 @@ public abstract class AbstractContextAwareMsgProcessor { | @@ -76,50 +71,6 @@ public abstract class AbstractContextAwareMsgProcessor { | ||
76 | getScheduler().scheduleOnce(Duration.create(delayInMs, TimeUnit.MILLISECONDS), target, msg, getSystemDispatcher(), null); | 71 | getScheduler().scheduleOnce(Duration.create(delayInMs, TimeUnit.MILLISECONDS), target, msg, getSystemDispatcher(), null); |
77 | } | 72 | } |
78 | 73 | ||
79 | - protected <T extends ConfigurableComponent> T initComponent(JsonNode componentNode) throws Exception { | ||
80 | - ComponentConfiguration configuration = new ComponentConfiguration( | ||
81 | - componentNode.get("clazz").asText(), | ||
82 | - componentNode.get("name").asText(), | ||
83 | - mapper.writeValueAsString(componentNode.get("configuration")) | ||
84 | - ); | ||
85 | - logger.info("Initializing [{}][{}] component", configuration.getName(), configuration.getClazz()); | ||
86 | - ComponentDescriptor componentDescriptor = systemContext.getComponentService().getComponent(configuration.getClazz()) | ||
87 | - .orElseThrow(() -> new InstantiationException("Component Not found!")); | ||
88 | - return initComponent(componentDescriptor, configuration); | ||
89 | - } | ||
90 | - | ||
91 | - protected <T extends ConfigurableComponent> T initComponent(ComponentDescriptor componentDefinition, ComponentConfiguration configuration) | ||
92 | - throws Exception { | ||
93 | - return initComponent(componentDefinition.getClazz(), componentDefinition.getType(), configuration.getConfiguration()); | ||
94 | - } | ||
95 | - | ||
96 | - protected <T extends ConfigurableComponent> T initComponent(String clazz, ComponentType type, String configuration) | ||
97 | - throws Exception { | ||
98 | - Class<?> componentClazz = Class.forName(clazz); | ||
99 | - T component = (T) (componentClazz.newInstance()); | ||
100 | - Class<?> configurationClazz; | ||
101 | - switch (type) { | ||
102 | - case FILTER: | ||
103 | - configurationClazz = ((Filter) componentClazz.getAnnotation(Filter.class)).configuration(); | ||
104 | - break; | ||
105 | - case ACTION: | ||
106 | - configurationClazz = ((Action) componentClazz.getAnnotation(Action.class)).configuration(); | ||
107 | - break; | ||
108 | - case PLUGIN: | ||
109 | - configurationClazz = ((Plugin) componentClazz.getAnnotation(Plugin.class)).configuration(); | ||
110 | - break; | ||
111 | - default: | ||
112 | - throw new IllegalStateException("Component with type: " + type + " is not supported!"); | ||
113 | - } | ||
114 | - component.init(decode(configuration, configurationClazz)); | ||
115 | - return component; | ||
116 | - } | ||
117 | - | ||
118 | - public <C> C decode(String configuration, Class<C> configurationClazz) throws IOException, RuntimeException { | ||
119 | - logger.info("Initializing using configuration: {}", configuration); | ||
120 | - return mapper.readValue(configuration, configurationClazz); | ||
121 | - } | ||
122 | - | ||
123 | @Data | 74 | @Data |
124 | @AllArgsConstructor | 75 | @AllArgsConstructor |
125 | private static class ComponentConfiguration { | 76 | private static class ComponentConfiguration { |
@@ -26,7 +26,6 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -26,7 +26,6 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
26 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; | 26 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; |
27 | import org.thingsboard.server.common.msg.TbMsg; | 27 | import org.thingsboard.server.common.msg.TbMsg; |
28 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | 28 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
29 | -import org.thingsboard.server.dao.queue.MsgQueue; | ||
30 | import org.thingsboard.server.service.queue.MsgQueueService; | 29 | import org.thingsboard.server.service.queue.MsgQueueService; |
31 | 30 | ||
32 | import javax.annotation.Nullable; | 31 | import javax.annotation.Nullable; |
@@ -24,12 +24,10 @@ import lombok.extern.slf4j.Slf4j; | @@ -24,12 +24,10 @@ import lombok.extern.slf4j.Slf4j; | ||
24 | import org.thingsboard.server.actors.ActorSystemContext; | 24 | import org.thingsboard.server.actors.ActorSystemContext; |
25 | import org.thingsboard.server.actors.service.ContextAwareActor; | 25 | import org.thingsboard.server.actors.service.ContextAwareActor; |
26 | import org.thingsboard.server.common.data.SearchTextBased; | 26 | import org.thingsboard.server.common.data.SearchTextBased; |
27 | -import org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo; | ||
28 | import org.thingsboard.server.common.data.id.EntityId; | 27 | import org.thingsboard.server.common.data.id.EntityId; |
29 | import org.thingsboard.server.common.data.id.TenantId; | 28 | import org.thingsboard.server.common.data.id.TenantId; |
30 | import org.thingsboard.server.common.data.id.UUIDBased; | 29 | import org.thingsboard.server.common.data.id.UUIDBased; |
31 | import org.thingsboard.server.common.data.page.PageDataIterable; | 30 | import org.thingsboard.server.common.data.page.PageDataIterable; |
32 | -import org.thingsboard.server.common.data.plugin.PluginMetaData; | ||
33 | 31 | ||
34 | import java.util.HashMap; | 32 | import java.util.HashMap; |
35 | import java.util.Map; | 33 | import java.util.Map; |
application/src/main/java/org/thingsboard/server/actors/shared/plugin/PluginManager.java
deleted
100644 → 0
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.actors.shared.plugin; | ||
17 | - | ||
18 | -import akka.japi.Creator; | ||
19 | -import lombok.extern.slf4j.Slf4j; | ||
20 | -import org.thingsboard.server.actors.ActorSystemContext; | ||
21 | -import org.thingsboard.server.actors.plugin.PluginActor; | ||
22 | -import org.thingsboard.server.actors.shared.EntityActorsManager; | ||
23 | -import org.thingsboard.server.common.data.id.PluginId; | ||
24 | -import org.thingsboard.server.common.data.plugin.PluginMetaData; | ||
25 | -import org.thingsboard.server.dao.plugin.PluginService; | ||
26 | - | ||
27 | -@Slf4j | ||
28 | -public abstract class PluginManager extends EntityActorsManager<PluginId, PluginActor, PluginMetaData> { | ||
29 | - | ||
30 | - protected final PluginService pluginService; | ||
31 | - | ||
32 | - public PluginManager(ActorSystemContext systemContext) { | ||
33 | - super(systemContext); | ||
34 | - this.pluginService = systemContext.getPluginService(); | ||
35 | - } | ||
36 | - | ||
37 | - @Override | ||
38 | - public Creator<PluginActor> creator(PluginId entityId){ | ||
39 | - return new PluginActor.ActorCreator(systemContext, getTenantId(), entityId); | ||
40 | - } | ||
41 | - | ||
42 | -} |
application/src/main/java/org/thingsboard/server/actors/shared/plugin/SystemPluginManager.java
deleted
100644 → 0
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.actors.shared.plugin; | ||
17 | - | ||
18 | -import org.thingsboard.server.actors.ActorSystemContext; | ||
19 | -import org.thingsboard.server.actors.service.DefaultActorService; | ||
20 | -import org.thingsboard.server.common.data.id.TenantId; | ||
21 | -import org.thingsboard.server.common.data.page.PageDataIterable.FetchFunction; | ||
22 | -import org.thingsboard.server.common.data.plugin.PluginMetaData; | ||
23 | -import org.thingsboard.server.dao.plugin.BasePluginService; | ||
24 | - | ||
25 | -public class SystemPluginManager extends PluginManager { | ||
26 | - | ||
27 | - public SystemPluginManager(ActorSystemContext systemContext) { | ||
28 | - super(systemContext); | ||
29 | - } | ||
30 | - | ||
31 | - @Override | ||
32 | - protected FetchFunction<PluginMetaData> getFetchEntitiesFunction() { | ||
33 | - return pluginService::findSystemPlugins; | ||
34 | - } | ||
35 | - | ||
36 | - @Override | ||
37 | - protected TenantId getTenantId() { | ||
38 | - return BasePluginService.SYSTEM_TENANT; | ||
39 | - } | ||
40 | - | ||
41 | - @Override | ||
42 | - protected String getDispatcherName() { | ||
43 | - return DefaultActorService.SYSTEM_PLUGIN_DISPATCHER_NAME; | ||
44 | - } | ||
45 | -} |
application/src/main/java/org/thingsboard/server/actors/shared/plugin/TenantPluginManager.java
deleted
100644 → 0
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.actors.shared.plugin; | ||
17 | - | ||
18 | -import akka.actor.ActorContext; | ||
19 | -import org.thingsboard.server.actors.ActorSystemContext; | ||
20 | -import org.thingsboard.server.actors.service.DefaultActorService; | ||
21 | -import org.thingsboard.server.common.data.id.TenantId; | ||
22 | -import org.thingsboard.server.common.data.page.PageDataIterable; | ||
23 | -import org.thingsboard.server.common.data.page.PageDataIterable.FetchFunction; | ||
24 | -import org.thingsboard.server.common.data.plugin.PluginMetaData; | ||
25 | - | ||
26 | -public class TenantPluginManager extends PluginManager { | ||
27 | - | ||
28 | - private final TenantId tenantId; | ||
29 | - | ||
30 | - public TenantPluginManager(ActorSystemContext systemContext, TenantId tenantId) { | ||
31 | - super(systemContext); | ||
32 | - this.tenantId = tenantId; | ||
33 | - } | ||
34 | - | ||
35 | - @Override | ||
36 | - public void init(ActorContext context) { | ||
37 | - if (systemContext.isTenantComponentsInitEnabled()) { | ||
38 | - super.init(context); | ||
39 | - } | ||
40 | - } | ||
41 | - | ||
42 | - @Override | ||
43 | - protected FetchFunction<PluginMetaData> getFetchEntitiesFunction() { | ||
44 | - return link -> pluginService.findTenantPlugins(tenantId, link); | ||
45 | - } | ||
46 | - | ||
47 | - @Override | ||
48 | - protected TenantId getTenantId() { | ||
49 | - return tenantId; | ||
50 | - } | ||
51 | - | ||
52 | - @Override | ||
53 | - protected String getDispatcherName() { | ||
54 | - return DefaultActorService.TENANT_PLUGIN_DISPATCHER_NAME; | ||
55 | - } | ||
56 | - | ||
57 | -} |
application/src/main/java/org/thingsboard/server/actors/shared/rulechain/SystemRuleChainManager.java
@@ -17,14 +17,11 @@ package org.thingsboard.server.actors.shared.rulechain; | @@ -17,14 +17,11 @@ package org.thingsboard.server.actors.shared.rulechain; | ||
17 | 17 | ||
18 | import org.thingsboard.server.actors.ActorSystemContext; | 18 | import org.thingsboard.server.actors.ActorSystemContext; |
19 | import org.thingsboard.server.actors.service.DefaultActorService; | 19 | import org.thingsboard.server.actors.service.DefaultActorService; |
20 | -import org.thingsboard.server.actors.shared.plugin.PluginManager; | ||
21 | import org.thingsboard.server.common.data.id.TenantId; | 20 | import org.thingsboard.server.common.data.id.TenantId; |
22 | import org.thingsboard.server.common.data.page.PageDataIterable.FetchFunction; | 21 | import org.thingsboard.server.common.data.page.PageDataIterable.FetchFunction; |
23 | import org.thingsboard.server.common.data.page.TextPageData; | 22 | import org.thingsboard.server.common.data.page.TextPageData; |
24 | -import org.thingsboard.server.common.data.page.TextPageLink; | ||
25 | -import org.thingsboard.server.common.data.plugin.PluginMetaData; | ||
26 | import org.thingsboard.server.common.data.rule.RuleChain; | 23 | import org.thingsboard.server.common.data.rule.RuleChain; |
27 | -import org.thingsboard.server.dao.plugin.BasePluginService; | 24 | +import org.thingsboard.server.dao.model.ModelConstants; |
28 | 25 | ||
29 | import java.util.Collections; | 26 | import java.util.Collections; |
30 | 27 | ||
@@ -41,7 +38,7 @@ public class SystemRuleChainManager extends RuleChainManager { | @@ -41,7 +38,7 @@ public class SystemRuleChainManager extends RuleChainManager { | ||
41 | 38 | ||
42 | @Override | 39 | @Override |
43 | protected TenantId getTenantId() { | 40 | protected TenantId getTenantId() { |
44 | - return BasePluginService.SYSTEM_TENANT; | 41 | + return ModelConstants.SYSTEM_TENANT; |
45 | } | 42 | } |
46 | 43 | ||
47 | @Override | 44 | @Override |
@@ -23,12 +23,10 @@ import akka.japi.Function; | @@ -23,12 +23,10 @@ import akka.japi.Function; | ||
23 | import org.thingsboard.server.actors.ActorSystemContext; | 23 | import org.thingsboard.server.actors.ActorSystemContext; |
24 | import org.thingsboard.server.actors.device.DeviceActor; | 24 | import org.thingsboard.server.actors.device.DeviceActor; |
25 | import org.thingsboard.server.actors.device.DeviceActorToRuleEngineMsg; | 25 | import org.thingsboard.server.actors.device.DeviceActorToRuleEngineMsg; |
26 | -import org.thingsboard.server.actors.plugin.PluginTerminationMsg; | ||
27 | import org.thingsboard.server.actors.ruleChain.RuleChainManagerActor; | 26 | import org.thingsboard.server.actors.ruleChain.RuleChainManagerActor; |
28 | import org.thingsboard.server.actors.ruleChain.RuleChainToRuleChainMsg; | 27 | import org.thingsboard.server.actors.ruleChain.RuleChainToRuleChainMsg; |
29 | import org.thingsboard.server.actors.service.ContextBasedCreator; | 28 | import org.thingsboard.server.actors.service.ContextBasedCreator; |
30 | import org.thingsboard.server.actors.service.DefaultActorService; | 29 | import org.thingsboard.server.actors.service.DefaultActorService; |
31 | -import org.thingsboard.server.actors.shared.plugin.TenantPluginManager; | ||
32 | import org.thingsboard.server.actors.shared.rulechain.TenantRuleChainManager; | 30 | import org.thingsboard.server.actors.shared.rulechain.TenantRuleChainManager; |
33 | import org.thingsboard.server.common.data.EntityType; | 31 | import org.thingsboard.server.common.data.EntityType; |
34 | import org.thingsboard.server.common.data.id.DeviceId; | 32 | import org.thingsboard.server.common.data.id.DeviceId; |
@@ -37,11 +35,8 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -37,11 +35,8 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
37 | import org.thingsboard.server.common.data.rule.RuleChain; | 35 | import org.thingsboard.server.common.data.rule.RuleChain; |
38 | import org.thingsboard.server.common.msg.TbActorMsg; | 36 | import org.thingsboard.server.common.msg.TbActorMsg; |
39 | import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; | 37 | import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; |
40 | -import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; | ||
41 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; | 38 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; |
42 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; | 39 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; |
43 | -import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | ||
44 | -import org.thingsboard.server.extensions.api.plugins.msg.ToPluginActorMsg; | ||
45 | import scala.concurrent.duration.Duration; | 40 | import scala.concurrent.duration.Duration; |
46 | 41 | ||
47 | import java.util.HashMap; | 42 | import java.util.HashMap; |
@@ -53,7 +48,7 @@ public class TenantActor extends RuleChainManagerActor { | @@ -53,7 +48,7 @@ public class TenantActor extends RuleChainManagerActor { | ||
53 | private final Map<DeviceId, ActorRef> deviceActors; | 48 | private final Map<DeviceId, ActorRef> deviceActors; |
54 | 49 | ||
55 | private TenantActor(ActorSystemContext systemContext, TenantId tenantId) { | 50 | private TenantActor(ActorSystemContext systemContext, TenantId tenantId) { |
56 | - super(systemContext, new TenantRuleChainManager(systemContext, tenantId), new TenantPluginManager(systemContext, tenantId)); | 51 | + super(systemContext, new TenantRuleChainManager(systemContext, tenantId)); |
57 | this.tenantId = tenantId; | 52 | this.tenantId = tenantId; |
58 | this.deviceActors = new HashMap<>(); | 53 | this.deviceActors = new HashMap<>(); |
59 | } | 54 | } |
@@ -17,8 +17,6 @@ package org.thingsboard.server.config; | @@ -17,8 +17,6 @@ package org.thingsboard.server.config; | ||
17 | 17 | ||
18 | import org.springframework.boot.context.properties.ConfigurationProperties; | 18 | import org.springframework.boot.context.properties.ConfigurationProperties; |
19 | import org.springframework.context.annotation.Configuration; | 19 | import org.springframework.context.annotation.Configuration; |
20 | -import org.thingsboard.server.common.data.EntityType; | ||
21 | -import org.thingsboard.server.common.data.audit.ActionType; | ||
22 | 20 | ||
23 | import java.util.HashMap; | 21 | import java.util.HashMap; |
24 | import java.util.Map; | 22 | import java.util.Map; |
@@ -24,7 +24,11 @@ import org.springframework.context.annotation.Configuration; | @@ -24,7 +24,11 @@ import org.springframework.context.annotation.Configuration; | ||
24 | import org.thingsboard.server.common.data.security.Authority; | 24 | import org.thingsboard.server.common.data.security.Authority; |
25 | import springfox.documentation.builders.ApiInfoBuilder; | 25 | import springfox.documentation.builders.ApiInfoBuilder; |
26 | import springfox.documentation.schema.AlternateTypeRule; | 26 | import springfox.documentation.schema.AlternateTypeRule; |
27 | -import springfox.documentation.service.*; | 27 | +import springfox.documentation.service.ApiInfo; |
28 | +import springfox.documentation.service.ApiKey; | ||
29 | +import springfox.documentation.service.AuthorizationScope; | ||
30 | +import springfox.documentation.service.Contact; | ||
31 | +import springfox.documentation.service.SecurityReference; | ||
28 | import springfox.documentation.spi.DocumentationType; | 32 | import springfox.documentation.spi.DocumentationType; |
29 | import springfox.documentation.spi.service.contexts.SecurityContext; | 33 | import springfox.documentation.spi.service.contexts.SecurityContext; |
30 | import springfox.documentation.spring.web.plugins.Docket; | 34 | import springfox.documentation.spring.web.plugins.Docket; |
@@ -40,10 +40,14 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | @@ -40,10 +40,14 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
40 | import org.springframework.web.filter.CorsFilter; | 40 | import org.springframework.web.filter.CorsFilter; |
41 | import org.thingsboard.server.dao.audit.AuditLogLevelFilter; | 41 | import org.thingsboard.server.dao.audit.AuditLogLevelFilter; |
42 | import org.thingsboard.server.exception.ThingsboardErrorResponseHandler; | 42 | import org.thingsboard.server.exception.ThingsboardErrorResponseHandler; |
43 | +import org.thingsboard.server.service.security.auth.jwt.JwtAuthenticationProvider; | ||
44 | +import org.thingsboard.server.service.security.auth.jwt.JwtTokenAuthenticationProcessingFilter; | ||
45 | +import org.thingsboard.server.service.security.auth.jwt.RefreshTokenAuthenticationProvider; | ||
46 | +import org.thingsboard.server.service.security.auth.jwt.RefreshTokenProcessingFilter; | ||
47 | +import org.thingsboard.server.service.security.auth.jwt.SkipPathRequestMatcher; | ||
48 | +import org.thingsboard.server.service.security.auth.jwt.extractor.TokenExtractor; | ||
43 | import org.thingsboard.server.service.security.auth.rest.RestAuthenticationProvider; | 49 | import org.thingsboard.server.service.security.auth.rest.RestAuthenticationProvider; |
44 | import org.thingsboard.server.service.security.auth.rest.RestLoginProcessingFilter; | 50 | import org.thingsboard.server.service.security.auth.rest.RestLoginProcessingFilter; |
45 | -import org.thingsboard.server.service.security.auth.jwt.*; | ||
46 | -import org.thingsboard.server.service.security.auth.jwt.extractor.TokenExtractor; | ||
47 | import org.thingsboard.server.service.security.auth.rest.RestPublicLoginProcessingFilter; | 51 | import org.thingsboard.server.service.security.auth.rest.RestPublicLoginProcessingFilter; |
48 | 52 | ||
49 | import java.util.ArrayList; | 53 | import java.util.ArrayList; |
@@ -15,12 +15,6 @@ | @@ -15,12 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.config; | 16 | package org.thingsboard.server.config; |
17 | 17 | ||
18 | -import java.util.Map; | ||
19 | - | ||
20 | -import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
21 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
22 | -import org.thingsboard.server.controller.plugin.TbWebSocketHandler; | ||
23 | -import org.thingsboard.server.service.security.model.SecurityUser; | ||
24 | import org.springframework.context.annotation.Bean; | 18 | import org.springframework.context.annotation.Bean; |
25 | import org.springframework.context.annotation.Configuration; | 19 | import org.springframework.context.annotation.Configuration; |
26 | import org.springframework.http.HttpStatus; | 20 | import org.springframework.http.HttpStatus; |
@@ -35,6 +29,12 @@ import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry | @@ -35,6 +29,12 @@ import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry | ||
35 | import org.springframework.web.socket.server.HandshakeInterceptor; | 29 | import org.springframework.web.socket.server.HandshakeInterceptor; |
36 | import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean; | 30 | import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean; |
37 | import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor; | 31 | import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor; |
32 | +import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
33 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
34 | +import org.thingsboard.server.controller.plugin.TbWebSocketHandler; | ||
35 | +import org.thingsboard.server.service.security.model.SecurityUser; | ||
36 | + | ||
37 | +import java.util.Map; | ||
38 | 38 | ||
39 | @Configuration | 39 | @Configuration |
40 | @EnableWebSocket | 40 | @EnableWebSocket |
@@ -17,11 +17,16 @@ package org.thingsboard.server.controller; | @@ -17,11 +17,16 @@ package org.thingsboard.server.controller; | ||
17 | 17 | ||
18 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
19 | import org.springframework.security.access.prepost.PreAuthorize; | 19 | import org.springframework.security.access.prepost.PreAuthorize; |
20 | -import org.springframework.web.bind.annotation.*; | 20 | +import org.springframework.web.bind.annotation.PathVariable; |
21 | +import org.springframework.web.bind.annotation.RequestBody; | ||
22 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
23 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
24 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
25 | +import org.springframework.web.bind.annotation.RestController; | ||
26 | +import org.thingsboard.rule.engine.api.MailService; | ||
21 | import org.thingsboard.server.common.data.AdminSettings; | 27 | import org.thingsboard.server.common.data.AdminSettings; |
22 | -import org.thingsboard.server.dao.settings.AdminSettingsService; | ||
23 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 28 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
24 | -import org.thingsboard.rule.engine.api.MailService; | 29 | +import org.thingsboard.server.dao.settings.AdminSettingsService; |
25 | import org.thingsboard.server.service.update.UpdateService; | 30 | import org.thingsboard.server.service.update.UpdateService; |
26 | import org.thingsboard.server.service.update.model.UpdateMessage; | 31 | import org.thingsboard.server.service.update.model.UpdateMessage; |
27 | 32 |
@@ -18,13 +18,27 @@ package org.thingsboard.server.controller; | @@ -18,13 +18,27 @@ package org.thingsboard.server.controller; | ||
18 | import org.apache.commons.lang3.StringUtils; | 18 | import org.apache.commons.lang3.StringUtils; |
19 | import org.springframework.http.HttpStatus; | 19 | import org.springframework.http.HttpStatus; |
20 | import org.springframework.security.access.prepost.PreAuthorize; | 20 | import org.springframework.security.access.prepost.PreAuthorize; |
21 | -import org.springframework.web.bind.annotation.*; | ||
22 | -import org.thingsboard.server.common.data.alarm.*; | ||
23 | -import org.thingsboard.server.common.data.id.*; | ||
24 | -import org.thingsboard.server.common.data.page.TimePageData; | ||
25 | -import org.thingsboard.server.common.data.page.TimePageLink; | 21 | +import org.springframework.web.bind.annotation.PathVariable; |
22 | +import org.springframework.web.bind.annotation.RequestBody; | ||
23 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
24 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
25 | +import org.springframework.web.bind.annotation.RequestParam; | ||
26 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
27 | +import org.springframework.web.bind.annotation.ResponseStatus; | ||
28 | +import org.springframework.web.bind.annotation.RestController; | ||
29 | +import org.thingsboard.server.common.data.alarm.Alarm; | ||
30 | +import org.thingsboard.server.common.data.alarm.AlarmId; | ||
31 | +import org.thingsboard.server.common.data.alarm.AlarmInfo; | ||
32 | +import org.thingsboard.server.common.data.alarm.AlarmQuery; | ||
33 | +import org.thingsboard.server.common.data.alarm.AlarmSearchStatus; | ||
34 | +import org.thingsboard.server.common.data.alarm.AlarmSeverity; | ||
35 | +import org.thingsboard.server.common.data.alarm.AlarmStatus; | ||
26 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | 36 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
27 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 37 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
38 | +import org.thingsboard.server.common.data.id.EntityId; | ||
39 | +import org.thingsboard.server.common.data.id.EntityIdFactory; | ||
40 | +import org.thingsboard.server.common.data.page.TimePageData; | ||
41 | +import org.thingsboard.server.common.data.page.TimePageLink; | ||
28 | 42 | ||
29 | @RestController | 43 | @RestController |
30 | @RequestMapping("/api") | 44 | @RequestMapping("/api") |
@@ -18,23 +18,30 @@ package org.thingsboard.server.controller; | @@ -18,23 +18,30 @@ package org.thingsboard.server.controller; | ||
18 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | import org.springframework.http.HttpStatus; | 19 | import org.springframework.http.HttpStatus; |
20 | import org.springframework.security.access.prepost.PreAuthorize; | 20 | import org.springframework.security.access.prepost.PreAuthorize; |
21 | -import org.springframework.web.bind.annotation.*; | 21 | +import org.springframework.web.bind.annotation.PathVariable; |
22 | +import org.springframework.web.bind.annotation.RequestBody; | ||
23 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
24 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
25 | +import org.springframework.web.bind.annotation.RequestParam; | ||
26 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
27 | +import org.springframework.web.bind.annotation.ResponseStatus; | ||
28 | +import org.springframework.web.bind.annotation.RestController; | ||
22 | import org.thingsboard.server.common.data.Customer; | 29 | import org.thingsboard.server.common.data.Customer; |
23 | import org.thingsboard.server.common.data.EntitySubtype; | 30 | import org.thingsboard.server.common.data.EntitySubtype; |
24 | import org.thingsboard.server.common.data.EntityType; | 31 | import org.thingsboard.server.common.data.EntityType; |
25 | import org.thingsboard.server.common.data.asset.Asset; | 32 | import org.thingsboard.server.common.data.asset.Asset; |
33 | +import org.thingsboard.server.common.data.asset.AssetSearchQuery; | ||
26 | import org.thingsboard.server.common.data.audit.ActionType; | 34 | import org.thingsboard.server.common.data.audit.ActionType; |
35 | +import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
36 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
27 | import org.thingsboard.server.common.data.id.AssetId; | 37 | import org.thingsboard.server.common.data.id.AssetId; |
28 | import org.thingsboard.server.common.data.id.CustomerId; | 38 | import org.thingsboard.server.common.data.id.CustomerId; |
29 | import org.thingsboard.server.common.data.id.TenantId; | 39 | import org.thingsboard.server.common.data.id.TenantId; |
30 | import org.thingsboard.server.common.data.page.TextPageData; | 40 | import org.thingsboard.server.common.data.page.TextPageData; |
31 | import org.thingsboard.server.common.data.page.TextPageLink; | 41 | import org.thingsboard.server.common.data.page.TextPageLink; |
32 | -import org.thingsboard.server.common.data.asset.AssetSearchQuery; | ||
33 | import org.thingsboard.server.common.data.security.Authority; | 42 | import org.thingsboard.server.common.data.security.Authority; |
34 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 43 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
35 | import org.thingsboard.server.dao.model.ModelConstants; | 44 | import org.thingsboard.server.dao.model.ModelConstants; |
36 | -import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
37 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
38 | import org.thingsboard.server.service.security.model.SecurityUser; | 45 | import org.thingsboard.server.service.security.model.SecurityUser; |
39 | 46 | ||
40 | import java.util.ArrayList; | 47 | import java.util.ArrayList; |
@@ -16,15 +16,20 @@ | @@ -16,15 +16,20 @@ | ||
16 | package org.thingsboard.server.controller; | 16 | package org.thingsboard.server.controller; |
17 | 17 | ||
18 | import org.springframework.security.access.prepost.PreAuthorize; | 18 | import org.springframework.security.access.prepost.PreAuthorize; |
19 | -import org.springframework.web.bind.annotation.*; | 19 | +import org.springframework.web.bind.annotation.PathVariable; |
20 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
21 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
22 | +import org.springframework.web.bind.annotation.RequestParam; | ||
23 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
24 | +import org.springframework.web.bind.annotation.RestController; | ||
20 | import org.thingsboard.server.common.data.audit.AuditLog; | 25 | import org.thingsboard.server.common.data.audit.AuditLog; |
26 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
21 | import org.thingsboard.server.common.data.id.CustomerId; | 27 | import org.thingsboard.server.common.data.id.CustomerId; |
22 | import org.thingsboard.server.common.data.id.EntityIdFactory; | 28 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
23 | import org.thingsboard.server.common.data.id.TenantId; | 29 | import org.thingsboard.server.common.data.id.TenantId; |
24 | import org.thingsboard.server.common.data.id.UserId; | 30 | import org.thingsboard.server.common.data.id.UserId; |
25 | import org.thingsboard.server.common.data.page.TimePageData; | 31 | import org.thingsboard.server.common.data.page.TimePageData; |
26 | import org.thingsboard.server.common.data.page.TimePageLink; | 32 | import org.thingsboard.server.common.data.page.TimePageLink; |
27 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
28 | 33 | ||
29 | import java.util.UUID; | 34 | import java.util.UUID; |
30 | 35 |
@@ -25,12 +25,18 @@ import org.springframework.http.HttpStatus; | @@ -25,12 +25,18 @@ import org.springframework.http.HttpStatus; | ||
25 | import org.springframework.http.ResponseEntity; | 25 | import org.springframework.http.ResponseEntity; |
26 | import org.springframework.security.access.prepost.PreAuthorize; | 26 | import org.springframework.security.access.prepost.PreAuthorize; |
27 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | 27 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
28 | -import org.springframework.web.bind.annotation.*; | 28 | +import org.springframework.web.bind.annotation.RequestBody; |
29 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
30 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
31 | +import org.springframework.web.bind.annotation.RequestParam; | ||
32 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
33 | +import org.springframework.web.bind.annotation.ResponseStatus; | ||
34 | +import org.springframework.web.bind.annotation.RestController; | ||
35 | +import org.thingsboard.rule.engine.api.MailService; | ||
29 | import org.thingsboard.server.common.data.User; | 36 | import org.thingsboard.server.common.data.User; |
30 | -import org.thingsboard.server.common.data.security.UserCredentials; | ||
31 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | 37 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
32 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 38 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
33 | -import org.thingsboard.rule.engine.api.MailService; | 39 | +import org.thingsboard.server.common.data.security.UserCredentials; |
34 | import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository; | 40 | import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository; |
35 | import org.thingsboard.server.service.security.model.SecurityUser; | 41 | import org.thingsboard.server.service.security.model.SecurityUser; |
36 | import org.thingsboard.server.service.security.model.UserPrincipal; | 42 | import org.thingsboard.server.service.security.model.UserPrincipal; |
@@ -22,20 +22,38 @@ import org.springframework.security.core.Authentication; | @@ -22,20 +22,38 @@ import org.springframework.security.core.Authentication; | ||
22 | import org.springframework.security.core.context.SecurityContextHolder; | 22 | import org.springframework.security.core.context.SecurityContextHolder; |
23 | import org.springframework.web.bind.annotation.ExceptionHandler; | 23 | import org.springframework.web.bind.annotation.ExceptionHandler; |
24 | import org.thingsboard.server.actors.service.ActorService; | 24 | import org.thingsboard.server.actors.service.ActorService; |
25 | -import org.thingsboard.server.common.data.*; | 25 | +import org.thingsboard.server.common.data.BaseData; |
26 | +import org.thingsboard.server.common.data.Customer; | ||
27 | +import org.thingsboard.server.common.data.Dashboard; | ||
28 | +import org.thingsboard.server.common.data.DashboardInfo; | ||
29 | +import org.thingsboard.server.common.data.Device; | ||
30 | +import org.thingsboard.server.common.data.EntityType; | ||
31 | +import org.thingsboard.server.common.data.HasName; | ||
32 | +import org.thingsboard.server.common.data.User; | ||
26 | import org.thingsboard.server.common.data.alarm.Alarm; | 33 | import org.thingsboard.server.common.data.alarm.Alarm; |
27 | import org.thingsboard.server.common.data.alarm.AlarmId; | 34 | import org.thingsboard.server.common.data.alarm.AlarmId; |
28 | import org.thingsboard.server.common.data.alarm.AlarmInfo; | 35 | import org.thingsboard.server.common.data.alarm.AlarmInfo; |
29 | import org.thingsboard.server.common.data.asset.Asset; | 36 | import org.thingsboard.server.common.data.asset.Asset; |
30 | import org.thingsboard.server.common.data.audit.ActionType; | 37 | import org.thingsboard.server.common.data.audit.ActionType; |
31 | -import org.thingsboard.server.common.data.id.*; | 38 | +import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
39 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
40 | +import org.thingsboard.server.common.data.id.AssetId; | ||
41 | +import org.thingsboard.server.common.data.id.CustomerId; | ||
42 | +import org.thingsboard.server.common.data.id.DashboardId; | ||
43 | +import org.thingsboard.server.common.data.id.DeviceId; | ||
44 | +import org.thingsboard.server.common.data.id.EntityId; | ||
45 | +import org.thingsboard.server.common.data.id.EntityIdFactory; | ||
46 | +import org.thingsboard.server.common.data.id.RuleChainId; | ||
47 | +import org.thingsboard.server.common.data.id.TenantId; | ||
48 | +import org.thingsboard.server.common.data.id.UUIDBased; | ||
49 | +import org.thingsboard.server.common.data.id.UserId; | ||
50 | +import org.thingsboard.server.common.data.id.WidgetTypeId; | ||
51 | +import org.thingsboard.server.common.data.id.WidgetsBundleId; | ||
32 | import org.thingsboard.server.common.data.page.TextPageLink; | 52 | import org.thingsboard.server.common.data.page.TextPageLink; |
33 | import org.thingsboard.server.common.data.page.TimePageLink; | 53 | import org.thingsboard.server.common.data.page.TimePageLink; |
34 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | 54 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; |
35 | import org.thingsboard.server.common.data.plugin.ComponentType; | 55 | import org.thingsboard.server.common.data.plugin.ComponentType; |
36 | -import org.thingsboard.server.common.data.plugin.PluginMetaData; | ||
37 | import org.thingsboard.server.common.data.rule.RuleChain; | 56 | import org.thingsboard.server.common.data.rule.RuleChain; |
38 | -import org.thingsboard.server.common.data.rule.RuleMetaData; | ||
39 | import org.thingsboard.server.common.data.security.Authority; | 57 | import org.thingsboard.server.common.data.security.Authority; |
40 | import org.thingsboard.server.common.data.widget.WidgetType; | 58 | import org.thingsboard.server.common.data.widget.WidgetType; |
41 | import org.thingsboard.server.common.data.widget.WidgetsBundle; | 59 | import org.thingsboard.server.common.data.widget.WidgetsBundle; |
@@ -49,17 +67,13 @@ import org.thingsboard.server.dao.device.DeviceService; | @@ -49,17 +67,13 @@ import org.thingsboard.server.dao.device.DeviceService; | ||
49 | import org.thingsboard.server.dao.exception.DataValidationException; | 67 | import org.thingsboard.server.dao.exception.DataValidationException; |
50 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 68 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
51 | import org.thingsboard.server.dao.model.ModelConstants; | 69 | import org.thingsboard.server.dao.model.ModelConstants; |
52 | -import org.thingsboard.server.dao.plugin.PluginService; | ||
53 | import org.thingsboard.server.dao.relation.RelationService; | 70 | import org.thingsboard.server.dao.relation.RelationService; |
54 | import org.thingsboard.server.dao.rule.RuleChainService; | 71 | import org.thingsboard.server.dao.rule.RuleChainService; |
55 | -import org.thingsboard.server.dao.rule.RuleService; | ||
56 | import org.thingsboard.server.dao.tenant.TenantService; | 72 | import org.thingsboard.server.dao.tenant.TenantService; |
57 | import org.thingsboard.server.dao.user.UserService; | 73 | import org.thingsboard.server.dao.user.UserService; |
58 | import org.thingsboard.server.dao.widget.WidgetTypeService; | 74 | import org.thingsboard.server.dao.widget.WidgetTypeService; |
59 | import org.thingsboard.server.dao.widget.WidgetsBundleService; | 75 | import org.thingsboard.server.dao.widget.WidgetsBundleService; |
60 | -import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
61 | import org.thingsboard.server.exception.ThingsboardErrorResponseHandler; | 76 | import org.thingsboard.server.exception.ThingsboardErrorResponseHandler; |
62 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
63 | import org.thingsboard.server.service.component.ComponentDiscoveryService; | 77 | import org.thingsboard.server.service.component.ComponentDiscoveryService; |
64 | import org.thingsboard.server.service.security.model.SecurityUser; | 78 | import org.thingsboard.server.service.security.model.SecurityUser; |
65 | import org.thingsboard.server.service.state.DeviceStateService; | 79 | import org.thingsboard.server.service.state.DeviceStateService; |
@@ -117,12 +131,6 @@ public abstract class BaseController { | @@ -117,12 +131,6 @@ public abstract class BaseController { | ||
117 | protected ComponentDiscoveryService componentDescriptorService; | 131 | protected ComponentDiscoveryService componentDescriptorService; |
118 | 132 | ||
119 | @Autowired | 133 | @Autowired |
120 | - protected RuleService ruleService; | ||
121 | - | ||
122 | - @Autowired | ||
123 | - protected PluginService pluginService; | ||
124 | - | ||
125 | - @Autowired | ||
126 | protected RuleChainService ruleChainService; | 134 | protected RuleChainService ruleChainService; |
127 | 135 | ||
128 | @Autowired | 136 | @Autowired |
@@ -299,12 +307,6 @@ public abstract class BaseController { | @@ -299,12 +307,6 @@ public abstract class BaseController { | ||
299 | case TENANT: | 307 | case TENANT: |
300 | checkTenantId(new TenantId(entityId.getId())); | 308 | checkTenantId(new TenantId(entityId.getId())); |
301 | return; | 309 | return; |
302 | - case PLUGIN: | ||
303 | - checkPlugin(new PluginId(entityId.getId())); | ||
304 | - return; | ||
305 | - case RULE: | ||
306 | - checkRule(new RuleId(entityId.getId())); | ||
307 | - return; | ||
308 | case RULE_CHAIN: | 310 | case RULE_CHAIN: |
309 | checkRuleChain(new RuleChainId(entityId.getId())); | 311 | checkRuleChain(new RuleChainId(entityId.getId())); |
310 | return; | 312 | return; |
@@ -494,60 +496,6 @@ public abstract class BaseController { | @@ -494,60 +496,6 @@ public abstract class BaseController { | ||
494 | } | 496 | } |
495 | } | 497 | } |
496 | 498 | ||
497 | - List<ComponentDescriptor> checkPluginActionsByPluginClazz(String pluginClazz) throws ThingsboardException { | ||
498 | - try { | ||
499 | - checkComponentDescriptorByClazz(pluginClazz); | ||
500 | - log.debug("[{}] Lookup plugin actions", pluginClazz); | ||
501 | - return componentDescriptorService.getPluginActions(pluginClazz); | ||
502 | - } catch (Exception e) { | ||
503 | - throw handleException(e, false); | ||
504 | - } | ||
505 | - } | ||
506 | - | ||
507 | - protected PluginMetaData checkPlugin(PluginMetaData plugin) throws ThingsboardException { | ||
508 | - checkNotNull(plugin); | ||
509 | - SecurityUser authUser = getCurrentUser(); | ||
510 | - TenantId tenantId = plugin.getTenantId(); | ||
511 | - validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | ||
512 | - if (authUser.getAuthority() != Authority.SYS_ADMIN) { | ||
513 | - if (authUser.getTenantId() == null || | ||
514 | - !tenantId.getId().equals(ModelConstants.NULL_UUID) && !authUser.getTenantId().equals(tenantId)) { | ||
515 | - throw new ThingsboardException(YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION, | ||
516 | - ThingsboardErrorCode.PERMISSION_DENIED); | ||
517 | - | ||
518 | - } else if (tenantId.getId().equals(ModelConstants.NULL_UUID)) { | ||
519 | - plugin.setConfiguration(null); | ||
520 | - } | ||
521 | - } | ||
522 | - return plugin; | ||
523 | - } | ||
524 | - | ||
525 | - protected PluginMetaData checkPlugin(PluginId pluginId) throws ThingsboardException { | ||
526 | - checkNotNull(pluginId); | ||
527 | - return checkPlugin(pluginService.findPluginById(pluginId)); | ||
528 | - } | ||
529 | - | ||
530 | - protected RuleMetaData checkRule(RuleId ruleId) throws ThingsboardException { | ||
531 | - checkNotNull(ruleId); | ||
532 | - return checkRule(ruleService.findRuleById(ruleId)); | ||
533 | - } | ||
534 | - | ||
535 | - protected RuleMetaData checkRule(RuleMetaData rule) throws ThingsboardException { | ||
536 | - checkNotNull(rule); | ||
537 | - SecurityUser authUser = getCurrentUser(); | ||
538 | - TenantId tenantId = rule.getTenantId(); | ||
539 | - validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | ||
540 | - if (authUser.getAuthority() != Authority.SYS_ADMIN) { | ||
541 | - if (authUser.getTenantId() == null || | ||
542 | - !tenantId.getId().equals(ModelConstants.NULL_UUID) && !authUser.getTenantId().equals(tenantId)) { | ||
543 | - throw new ThingsboardException(YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION, | ||
544 | - ThingsboardErrorCode.PERMISSION_DENIED); | ||
545 | - | ||
546 | - } | ||
547 | - } | ||
548 | - return rule; | ||
549 | - } | ||
550 | - | ||
551 | protected RuleChain checkRuleChain(RuleChainId ruleChainId) throws ThingsboardException { | 499 | protected RuleChain checkRuleChain(RuleChainId ruleChainId) throws ThingsboardException { |
552 | checkNotNull(ruleChainId); | 500 | checkNotNull(ruleChainId); |
553 | return checkRuleChain(ruleChainService.findRuleChainById(ruleChainId)); | 501 | return checkRuleChain(ruleChainService.findRuleChainById(ruleChainId)); |
@@ -16,10 +16,15 @@ | @@ -16,10 +16,15 @@ | ||
16 | package org.thingsboard.server.controller; | 16 | package org.thingsboard.server.controller; |
17 | 17 | ||
18 | import org.springframework.security.access.prepost.PreAuthorize; | 18 | import org.springframework.security.access.prepost.PreAuthorize; |
19 | -import org.springframework.web.bind.annotation.*; | 19 | +import org.springframework.web.bind.annotation.PathVariable; |
20 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
21 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
22 | +import org.springframework.web.bind.annotation.RequestParam; | ||
23 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
24 | +import org.springframework.web.bind.annotation.RestController; | ||
25 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
20 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | 26 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; |
21 | import org.thingsboard.server.common.data.plugin.ComponentType; | 27 | import org.thingsboard.server.common.data.plugin.ComponentType; |
22 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
23 | 28 | ||
24 | import java.util.HashSet; | 29 | import java.util.HashSet; |
25 | import java.util.List; | 30 | import java.util.List; |
@@ -69,16 +74,4 @@ public class ComponentDescriptorController extends BaseController { | @@ -69,16 +74,4 @@ public class ComponentDescriptorController extends BaseController { | ||
69 | } | 74 | } |
70 | } | 75 | } |
71 | 76 | ||
72 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')") | ||
73 | - @RequestMapping(value = "/components/actions/{pluginClazz:.+}", method = RequestMethod.GET) | ||
74 | - @ResponseBody | ||
75 | - public List<ComponentDescriptor> getPluginActionsByPluginClazz(@PathVariable("pluginClazz") String pluginClazz) throws ThingsboardException { | ||
76 | - checkParameter("pluginClazz", pluginClazz); | ||
77 | - try { | ||
78 | - return checkPluginActionsByPluginClazz(pluginClazz); | ||
79 | - } catch (Exception e) { | ||
80 | - throw handleException(e); | ||
81 | - } | ||
82 | - } | ||
83 | - | ||
84 | } | 77 | } |
@@ -20,15 +20,22 @@ import com.fasterxml.jackson.databind.ObjectMapper; | @@ -20,15 +20,22 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ||
20 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | import org.springframework.http.HttpStatus; | 21 | import org.springframework.http.HttpStatus; |
22 | import org.springframework.security.access.prepost.PreAuthorize; | 22 | import org.springframework.security.access.prepost.PreAuthorize; |
23 | -import org.springframework.web.bind.annotation.*; | 23 | +import org.springframework.web.bind.annotation.PathVariable; |
24 | +import org.springframework.web.bind.annotation.RequestBody; | ||
25 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
26 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
27 | +import org.springframework.web.bind.annotation.RequestParam; | ||
28 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
29 | +import org.springframework.web.bind.annotation.ResponseStatus; | ||
30 | +import org.springframework.web.bind.annotation.RestController; | ||
24 | import org.thingsboard.server.common.data.Customer; | 31 | import org.thingsboard.server.common.data.Customer; |
25 | import org.thingsboard.server.common.data.EntityType; | 32 | import org.thingsboard.server.common.data.EntityType; |
26 | import org.thingsboard.server.common.data.audit.ActionType; | 33 | import org.thingsboard.server.common.data.audit.ActionType; |
34 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
27 | import org.thingsboard.server.common.data.id.CustomerId; | 35 | import org.thingsboard.server.common.data.id.CustomerId; |
28 | import org.thingsboard.server.common.data.id.TenantId; | 36 | import org.thingsboard.server.common.data.id.TenantId; |
29 | import org.thingsboard.server.common.data.page.TextPageData; | 37 | import org.thingsboard.server.common.data.page.TextPageData; |
30 | import org.thingsboard.server.common.data.page.TextPageLink; | 38 | import org.thingsboard.server.common.data.page.TextPageLink; |
31 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
32 | 39 | ||
33 | @RestController | 40 | @RestController |
34 | @RequestMapping("/api") | 41 | @RequestMapping("/api") |
@@ -17,9 +17,21 @@ package org.thingsboard.server.controller; | @@ -17,9 +17,21 @@ package org.thingsboard.server.controller; | ||
17 | 17 | ||
18 | import org.springframework.http.HttpStatus; | 18 | import org.springframework.http.HttpStatus; |
19 | import org.springframework.security.access.prepost.PreAuthorize; | 19 | import org.springframework.security.access.prepost.PreAuthorize; |
20 | -import org.springframework.web.bind.annotation.*; | ||
21 | -import org.thingsboard.server.common.data.*; | 20 | +import org.springframework.web.bind.annotation.PathVariable; |
21 | +import org.springframework.web.bind.annotation.RequestBody; | ||
22 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
23 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
24 | +import org.springframework.web.bind.annotation.RequestParam; | ||
25 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
26 | +import org.springframework.web.bind.annotation.ResponseStatus; | ||
27 | +import org.springframework.web.bind.annotation.RestController; | ||
28 | +import org.thingsboard.server.common.data.Customer; | ||
29 | +import org.thingsboard.server.common.data.Dashboard; | ||
30 | +import org.thingsboard.server.common.data.DashboardInfo; | ||
31 | +import org.thingsboard.server.common.data.EntityType; | ||
32 | +import org.thingsboard.server.common.data.ShortCustomerInfo; | ||
22 | import org.thingsboard.server.common.data.audit.ActionType; | 33 | import org.thingsboard.server.common.data.audit.ActionType; |
34 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
23 | import org.thingsboard.server.common.data.id.CustomerId; | 35 | import org.thingsboard.server.common.data.id.CustomerId; |
24 | import org.thingsboard.server.common.data.id.DashboardId; | 36 | import org.thingsboard.server.common.data.id.DashboardId; |
25 | import org.thingsboard.server.common.data.id.TenantId; | 37 | import org.thingsboard.server.common.data.id.TenantId; |
@@ -27,7 +39,6 @@ import org.thingsboard.server.common.data.page.TextPageData; | @@ -27,7 +39,6 @@ import org.thingsboard.server.common.data.page.TextPageData; | ||
27 | import org.thingsboard.server.common.data.page.TextPageLink; | 39 | import org.thingsboard.server.common.data.page.TextPageLink; |
28 | import org.thingsboard.server.common.data.page.TimePageData; | 40 | import org.thingsboard.server.common.data.page.TimePageData; |
29 | import org.thingsboard.server.common.data.page.TimePageLink; | 41 | import org.thingsboard.server.common.data.page.TimePageLink; |
30 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
31 | 42 | ||
32 | import java.util.HashSet; | 43 | import java.util.HashSet; |
33 | import java.util.Set; | 44 | import java.util.Set; |
@@ -18,13 +18,22 @@ package org.thingsboard.server.controller; | @@ -18,13 +18,22 @@ package org.thingsboard.server.controller; | ||
18 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | import org.springframework.http.HttpStatus; | 19 | import org.springframework.http.HttpStatus; |
20 | import org.springframework.security.access.prepost.PreAuthorize; | 20 | import org.springframework.security.access.prepost.PreAuthorize; |
21 | -import org.springframework.web.bind.annotation.*; | 21 | +import org.springframework.web.bind.annotation.PathVariable; |
22 | +import org.springframework.web.bind.annotation.RequestBody; | ||
23 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
24 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
25 | +import org.springframework.web.bind.annotation.RequestParam; | ||
26 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
27 | +import org.springframework.web.bind.annotation.ResponseStatus; | ||
28 | +import org.springframework.web.bind.annotation.RestController; | ||
22 | import org.thingsboard.server.common.data.Customer; | 29 | import org.thingsboard.server.common.data.Customer; |
23 | import org.thingsboard.server.common.data.Device; | 30 | import org.thingsboard.server.common.data.Device; |
24 | import org.thingsboard.server.common.data.EntitySubtype; | 31 | import org.thingsboard.server.common.data.EntitySubtype; |
25 | import org.thingsboard.server.common.data.EntityType; | 32 | import org.thingsboard.server.common.data.EntityType; |
26 | import org.thingsboard.server.common.data.audit.ActionType; | 33 | import org.thingsboard.server.common.data.audit.ActionType; |
27 | import org.thingsboard.server.common.data.device.DeviceSearchQuery; | 34 | import org.thingsboard.server.common.data.device.DeviceSearchQuery; |
35 | +import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
36 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
28 | import org.thingsboard.server.common.data.id.CustomerId; | 37 | import org.thingsboard.server.common.data.id.CustomerId; |
29 | import org.thingsboard.server.common.data.id.DeviceId; | 38 | import org.thingsboard.server.common.data.id.DeviceId; |
30 | import org.thingsboard.server.common.data.id.TenantId; | 39 | import org.thingsboard.server.common.data.id.TenantId; |
@@ -34,8 +43,6 @@ import org.thingsboard.server.common.data.security.Authority; | @@ -34,8 +43,6 @@ import org.thingsboard.server.common.data.security.Authority; | ||
34 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 43 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
35 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 44 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
36 | import org.thingsboard.server.dao.model.ModelConstants; | 45 | import org.thingsboard.server.dao.model.ModelConstants; |
37 | -import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
38 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
39 | import org.thingsboard.server.service.security.model.SecurityUser; | 46 | import org.thingsboard.server.service.security.model.SecurityUser; |
40 | 47 | ||
41 | import java.util.ArrayList; | 48 | import java.util.ArrayList; |
@@ -17,15 +17,21 @@ package org.thingsboard.server.controller; | @@ -17,15 +17,21 @@ package org.thingsboard.server.controller; | ||
17 | 17 | ||
18 | import org.springframework.http.HttpStatus; | 18 | import org.springframework.http.HttpStatus; |
19 | import org.springframework.security.access.prepost.PreAuthorize; | 19 | import org.springframework.security.access.prepost.PreAuthorize; |
20 | -import org.springframework.web.bind.annotation.*; | 20 | +import org.springframework.web.bind.annotation.RequestBody; |
21 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
22 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
23 | +import org.springframework.web.bind.annotation.RequestParam; | ||
24 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
25 | +import org.springframework.web.bind.annotation.ResponseStatus; | ||
26 | +import org.springframework.web.bind.annotation.RestController; | ||
27 | +import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
28 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
21 | import org.thingsboard.server.common.data.id.EntityId; | 29 | import org.thingsboard.server.common.data.id.EntityId; |
22 | import org.thingsboard.server.common.data.id.EntityIdFactory; | 30 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
23 | import org.thingsboard.server.common.data.relation.EntityRelation; | 31 | import org.thingsboard.server.common.data.relation.EntityRelation; |
24 | import org.thingsboard.server.common.data.relation.EntityRelationInfo; | 32 | import org.thingsboard.server.common.data.relation.EntityRelationInfo; |
25 | -import org.thingsboard.server.common.data.relation.RelationTypeGroup; | ||
26 | import org.thingsboard.server.common.data.relation.EntityRelationsQuery; | 33 | import org.thingsboard.server.common.data.relation.EntityRelationsQuery; |
27 | -import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
28 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | 34 | +import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
29 | 35 | ||
30 | import java.util.List; | 36 | import java.util.List; |
31 | 37 |
@@ -17,15 +17,21 @@ package org.thingsboard.server.controller; | @@ -17,15 +17,21 @@ package org.thingsboard.server.controller; | ||
17 | 17 | ||
18 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
19 | import org.springframework.security.access.prepost.PreAuthorize; | 19 | import org.springframework.security.access.prepost.PreAuthorize; |
20 | -import org.springframework.web.bind.annotation.*; | 20 | +import org.springframework.web.bind.annotation.PathVariable; |
21 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
22 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
23 | +import org.springframework.web.bind.annotation.RequestParam; | ||
24 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
25 | +import org.springframework.web.bind.annotation.RestController; | ||
21 | import org.thingsboard.server.common.data.Event; | 26 | import org.thingsboard.server.common.data.Event; |
22 | -import org.thingsboard.server.common.data.id.*; | 27 | +import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
28 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
29 | +import org.thingsboard.server.common.data.id.EntityIdFactory; | ||
30 | +import org.thingsboard.server.common.data.id.TenantId; | ||
23 | import org.thingsboard.server.common.data.page.TimePageData; | 31 | import org.thingsboard.server.common.data.page.TimePageData; |
24 | import org.thingsboard.server.common.data.page.TimePageLink; | 32 | import org.thingsboard.server.common.data.page.TimePageLink; |
25 | import org.thingsboard.server.dao.event.EventService; | 33 | import org.thingsboard.server.dao.event.EventService; |
26 | import org.thingsboard.server.dao.model.ModelConstants; | 34 | import org.thingsboard.server.dao.model.ModelConstants; |
27 | -import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
28 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
29 | 35 | ||
30 | @RestController | 36 | @RestController |
31 | @RequestMapping("/api") | 37 | @RequestMapping("/api") |
application/src/main/java/org/thingsboard/server/controller/PluginController.java
deleted
100644 → 0
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.controller; | ||
17 | - | ||
18 | -import org.springframework.http.HttpStatus; | ||
19 | -import org.springframework.security.access.prepost.PreAuthorize; | ||
20 | -import org.springframework.web.bind.annotation.*; | ||
21 | -import org.thingsboard.server.common.data.EntityType; | ||
22 | -import org.thingsboard.server.common.data.audit.ActionType; | ||
23 | -import org.thingsboard.server.common.data.id.PluginId; | ||
24 | -import org.thingsboard.server.common.data.id.TenantId; | ||
25 | -import org.thingsboard.server.common.data.page.TextPageData; | ||
26 | -import org.thingsboard.server.common.data.page.TextPageLink; | ||
27 | -import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | ||
28 | -import org.thingsboard.server.common.data.plugin.PluginMetaData; | ||
29 | -import org.thingsboard.server.common.data.security.Authority; | ||
30 | -import org.thingsboard.server.dao.model.ModelConstants; | ||
31 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
32 | - | ||
33 | -import java.util.List; | ||
34 | - | ||
35 | -@RestController | ||
36 | -@RequestMapping("/api") | ||
37 | -public class PluginController extends BaseController { | ||
38 | - | ||
39 | - public static final String PLUGIN_ID = "pluginId"; | ||
40 | - | ||
41 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
42 | - @RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.GET) | ||
43 | - @ResponseBody | ||
44 | - public PluginMetaData getPluginById(@PathVariable(PLUGIN_ID) String strPluginId) throws ThingsboardException { | ||
45 | - checkParameter(PLUGIN_ID, strPluginId); | ||
46 | - try { | ||
47 | - PluginId pluginId = new PluginId(toUUID(strPluginId)); | ||
48 | - return checkPlugin(pluginService.findPluginById(pluginId)); | ||
49 | - } catch (Exception e) { | ||
50 | - throw handleException(e); | ||
51 | - } | ||
52 | - } | ||
53 | - | ||
54 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
55 | - @RequestMapping(value = "/plugin/token/{pluginToken}", method = RequestMethod.GET) | ||
56 | - @ResponseBody | ||
57 | - public PluginMetaData getPluginByToken(@PathVariable("pluginToken") String pluginToken) throws ThingsboardException { | ||
58 | - checkParameter("pluginToken", pluginToken); | ||
59 | - try { | ||
60 | - return checkPlugin(pluginService.findPluginByApiToken(pluginToken)); | ||
61 | - } catch (Exception e) { | ||
62 | - throw handleException(e); | ||
63 | - } | ||
64 | - } | ||
65 | - | ||
66 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
67 | - @RequestMapping(value = "/plugin", method = RequestMethod.POST) | ||
68 | - @ResponseBody | ||
69 | - public PluginMetaData savePlugin(@RequestBody PluginMetaData source) throws ThingsboardException { | ||
70 | - try { | ||
71 | - boolean created = source.getId() == null; | ||
72 | - source.setTenantId(getCurrentUser().getTenantId()); | ||
73 | - PluginMetaData plugin = checkNotNull(pluginService.savePlugin(source)); | ||
74 | - actorService.onEntityStateChange(plugin.getTenantId(), plugin.getId(), | ||
75 | - created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | ||
76 | - | ||
77 | - logEntityAction(plugin.getId(), plugin, | ||
78 | - null, | ||
79 | - created ? ActionType.ADDED : ActionType.UPDATED, null); | ||
80 | - | ||
81 | - return plugin; | ||
82 | - } catch (Exception e) { | ||
83 | - | ||
84 | - logEntityAction(emptyId(EntityType.PLUGIN), source, | ||
85 | - null, source.getId() == null ? ActionType.ADDED : ActionType.UPDATED, e); | ||
86 | - | ||
87 | - throw handleException(e); | ||
88 | - } | ||
89 | - } | ||
90 | - | ||
91 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
92 | - @RequestMapping(value = "/plugin/{pluginId}/activate", method = RequestMethod.POST) | ||
93 | - @ResponseStatus(value = HttpStatus.OK) | ||
94 | - public void activatePluginById(@PathVariable(PLUGIN_ID) String strPluginId) throws ThingsboardException { | ||
95 | - checkParameter(PLUGIN_ID, strPluginId); | ||
96 | - try { | ||
97 | - PluginId pluginId = new PluginId(toUUID(strPluginId)); | ||
98 | - PluginMetaData plugin = checkPlugin(pluginService.findPluginById(pluginId)); | ||
99 | - pluginService.activatePluginById(pluginId); | ||
100 | - actorService.onEntityStateChange(plugin.getTenantId(), plugin.getId(), ComponentLifecycleEvent.ACTIVATED); | ||
101 | - | ||
102 | - logEntityAction(plugin.getId(), plugin, | ||
103 | - null, | ||
104 | - ActionType.ACTIVATED, null, strPluginId); | ||
105 | - | ||
106 | - } catch (Exception e) { | ||
107 | - | ||
108 | - logEntityAction(emptyId(EntityType.PLUGIN), | ||
109 | - null, | ||
110 | - null, | ||
111 | - ActionType.ACTIVATED, e, strPluginId); | ||
112 | - | ||
113 | - throw handleException(e); | ||
114 | - } | ||
115 | - } | ||
116 | - | ||
117 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
118 | - @RequestMapping(value = "/plugin/{pluginId}/suspend", method = RequestMethod.POST) | ||
119 | - @ResponseStatus(value = HttpStatus.OK) | ||
120 | - public void suspendPluginById(@PathVariable(PLUGIN_ID) String strPluginId) throws ThingsboardException { | ||
121 | - checkParameter(PLUGIN_ID, strPluginId); | ||
122 | - try { | ||
123 | - PluginId pluginId = new PluginId(toUUID(strPluginId)); | ||
124 | - PluginMetaData plugin = checkPlugin(pluginService.findPluginById(pluginId)); | ||
125 | - pluginService.suspendPluginById(pluginId); | ||
126 | - actorService.onEntityStateChange(plugin.getTenantId(), plugin.getId(), ComponentLifecycleEvent.SUSPENDED); | ||
127 | - | ||
128 | - logEntityAction(plugin.getId(), plugin, | ||
129 | - null, | ||
130 | - ActionType.SUSPENDED, null, strPluginId); | ||
131 | - | ||
132 | - } catch (Exception e) { | ||
133 | - | ||
134 | - logEntityAction(emptyId(EntityType.PLUGIN), | ||
135 | - null, | ||
136 | - null, | ||
137 | - ActionType.SUSPENDED, e, strPluginId); | ||
138 | - | ||
139 | - throw handleException(e); | ||
140 | - } | ||
141 | - } | ||
142 | - | ||
143 | - @PreAuthorize("hasAuthority('SYS_ADMIN')") | ||
144 | - @RequestMapping(value = "/plugin/system", params = {"limit"}, method = RequestMethod.GET) | ||
145 | - @ResponseBody | ||
146 | - public TextPageData<PluginMetaData> getSystemPlugins( | ||
147 | - @RequestParam int limit, | ||
148 | - @RequestParam(required = false) String textSearch, | ||
149 | - @RequestParam(required = false) String idOffset, | ||
150 | - @RequestParam(required = false) String textOffset) throws ThingsboardException { | ||
151 | - try { | ||
152 | - TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset); | ||
153 | - return checkNotNull(pluginService.findSystemPlugins(pageLink)); | ||
154 | - } catch (Exception e) { | ||
155 | - throw handleException(e); | ||
156 | - } | ||
157 | - } | ||
158 | - | ||
159 | - @PreAuthorize("hasAuthority('SYS_ADMIN')") | ||
160 | - @RequestMapping(value = "/plugin/tenant/{tenantId}", params = {"limit"}, method = RequestMethod.GET) | ||
161 | - @ResponseBody | ||
162 | - public TextPageData<PluginMetaData> getTenantPlugins( | ||
163 | - @PathVariable("tenantId") String strTenantId, | ||
164 | - @RequestParam int limit, | ||
165 | - @RequestParam(required = false) String textSearch, | ||
166 | - @RequestParam(required = false) String idOffset, | ||
167 | - @RequestParam(required = false) String textOffset) throws ThingsboardException { | ||
168 | - checkParameter("tenantId", strTenantId); | ||
169 | - try { | ||
170 | - TenantId tenantId = new TenantId(toUUID(strTenantId)); | ||
171 | - TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset); | ||
172 | - return checkNotNull(pluginService.findTenantPlugins(tenantId, pageLink)); | ||
173 | - } catch (Exception e) { | ||
174 | - throw handleException(e); | ||
175 | - } | ||
176 | - } | ||
177 | - | ||
178 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
179 | - @RequestMapping(value = "/plugins", method = RequestMethod.GET) | ||
180 | - @ResponseBody | ||
181 | - public List<PluginMetaData> getPlugins() throws ThingsboardException { | ||
182 | - try { | ||
183 | - if (getCurrentUser().getAuthority() == Authority.SYS_ADMIN) { | ||
184 | - return checkNotNull(pluginService.findSystemPlugins()); | ||
185 | - } else { | ||
186 | - TenantId tenantId = getCurrentUser().getTenantId(); | ||
187 | - List<PluginMetaData> plugins = checkNotNull(pluginService.findAllTenantPluginsByTenantId(tenantId)); | ||
188 | - plugins.stream() | ||
189 | - .filter(plugin -> plugin.getTenantId().getId().equals(ModelConstants.NULL_UUID)) | ||
190 | - .forEach(plugin -> plugin.setConfiguration(null)); | ||
191 | - return plugins; | ||
192 | - } | ||
193 | - } catch (Exception e) { | ||
194 | - throw handleException(e); | ||
195 | - } | ||
196 | - } | ||
197 | - | ||
198 | - @PreAuthorize("hasAuthority('TENANT_ADMIN')") | ||
199 | - @RequestMapping(value = "/plugin", params = {"limit"}, method = RequestMethod.GET) | ||
200 | - @ResponseBody | ||
201 | - public TextPageData<PluginMetaData> getTenantPlugins( | ||
202 | - @RequestParam int limit, | ||
203 | - @RequestParam(required = false) String textSearch, | ||
204 | - @RequestParam(required = false) String idOffset, | ||
205 | - @RequestParam(required = false) String textOffset) throws ThingsboardException { | ||
206 | - try { | ||
207 | - TenantId tenantId = getCurrentUser().getTenantId(); | ||
208 | - TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset); | ||
209 | - return checkNotNull(pluginService.findTenantPlugins(tenantId, pageLink)); | ||
210 | - } catch (Exception e) { | ||
211 | - throw handleException(e); | ||
212 | - } | ||
213 | - } | ||
214 | - | ||
215 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
216 | - @RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.DELETE) | ||
217 | - @ResponseStatus(value = HttpStatus.OK) | ||
218 | - public void deletePlugin(@PathVariable(PLUGIN_ID) String strPluginId) throws ThingsboardException { | ||
219 | - checkParameter(PLUGIN_ID, strPluginId); | ||
220 | - try { | ||
221 | - PluginId pluginId = new PluginId(toUUID(strPluginId)); | ||
222 | - PluginMetaData plugin = checkPlugin(pluginService.findPluginById(pluginId)); | ||
223 | - pluginService.deletePluginById(pluginId); | ||
224 | - actorService.onEntityStateChange(plugin.getTenantId(), plugin.getId(), ComponentLifecycleEvent.DELETED); | ||
225 | - | ||
226 | - logEntityAction(pluginId, plugin, | ||
227 | - null, | ||
228 | - ActionType.DELETED, null, strPluginId); | ||
229 | - | ||
230 | - } catch (Exception e) { | ||
231 | - logEntityAction(emptyId(EntityType.PLUGIN), | ||
232 | - null, | ||
233 | - null, | ||
234 | - ActionType.DELETED, e, strPluginId); | ||
235 | - throw handleException(e); | ||
236 | - } | ||
237 | - } | ||
238 | - | ||
239 | - | ||
240 | -} |
@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestMethod; | @@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestMethod; | ||
31 | import org.springframework.web.bind.annotation.ResponseBody; | 31 | import org.springframework.web.bind.annotation.ResponseBody; |
32 | import org.springframework.web.bind.annotation.RestController; | 32 | import org.springframework.web.bind.annotation.RestController; |
33 | import org.springframework.web.context.request.async.DeferredResult; | 33 | import org.springframework.web.context.request.async.DeferredResult; |
34 | +import org.thingsboard.rule.engine.api.RpcError; | ||
34 | import org.thingsboard.server.common.data.audit.ActionType; | 35 | import org.thingsboard.server.common.data.audit.ActionType; |
35 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | 36 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
36 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 37 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
@@ -41,14 +42,12 @@ import org.thingsboard.server.common.data.id.UUIDBased; | @@ -41,14 +42,12 @@ import org.thingsboard.server.common.data.id.UUIDBased; | ||
41 | import org.thingsboard.server.common.data.rpc.RpcRequest; | 42 | import org.thingsboard.server.common.data.rpc.RpcRequest; |
42 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | 43 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; |
43 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 44 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
44 | -import org.thingsboard.server.extensions.api.exception.ToErrorResponseEntity; | ||
45 | -import org.thingsboard.server.extensions.api.plugins.PluginConstants; | ||
46 | -import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; | ||
47 | -import org.thingsboard.server.extensions.api.plugins.msg.RpcError; | ||
48 | import org.thingsboard.server.service.rpc.DeviceRpcService; | 45 | import org.thingsboard.server.service.rpc.DeviceRpcService; |
46 | +import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; | ||
49 | import org.thingsboard.server.service.rpc.LocalRequestMetaData; | 47 | import org.thingsboard.server.service.rpc.LocalRequestMetaData; |
50 | import org.thingsboard.server.service.security.AccessValidator; | 48 | import org.thingsboard.server.service.security.AccessValidator; |
51 | import org.thingsboard.server.service.security.model.SecurityUser; | 49 | import org.thingsboard.server.service.security.model.SecurityUser; |
50 | +import org.thingsboard.server.service.telemetry.exception.ToErrorResponseEntity; | ||
52 | 51 | ||
53 | import javax.annotation.Nullable; | 52 | import javax.annotation.Nullable; |
54 | import javax.annotation.PostConstruct; | 53 | import javax.annotation.PostConstruct; |
@@ -58,13 +57,12 @@ import java.util.Optional; | @@ -58,13 +57,12 @@ import java.util.Optional; | ||
58 | import java.util.UUID; | 57 | import java.util.UUID; |
59 | import java.util.concurrent.ExecutorService; | 58 | import java.util.concurrent.ExecutorService; |
60 | import java.util.concurrent.Executors; | 59 | import java.util.concurrent.Executors; |
61 | -import java.util.function.Consumer; | ||
62 | 60 | ||
63 | /** | 61 | /** |
64 | * Created by ashvayka on 22.03.18. | 62 | * Created by ashvayka on 22.03.18. |
65 | */ | 63 | */ |
66 | @RestController | 64 | @RestController |
67 | -@RequestMapping(PluginConstants.RPC_URL_PREFIX) | 65 | +@RequestMapping(TbUrlConstants.RPC_URL_PREFIX) |
68 | @Slf4j | 66 | @Slf4j |
69 | public class RpcController extends BaseController { | 67 | public class RpcController extends BaseController { |
70 | 68 | ||
@@ -130,13 +128,7 @@ public class RpcController extends BaseController { | @@ -130,13 +128,7 @@ public class RpcController extends BaseController { | ||
130 | timeout, | 128 | timeout, |
131 | body | 129 | body |
132 | ); | 130 | ); |
133 | - deviceRpcService.process(rpcRequest, new Consumer<FromDeviceRpcResponse>(){ | ||
134 | - | ||
135 | - @Override | ||
136 | - public void accept(FromDeviceRpcResponse fromDeviceRpcResponse) { | ||
137 | - reply(new LocalRequestMetaData(rpcRequest, currentUser, result), fromDeviceRpcResponse); | ||
138 | - } | ||
139 | - }); | 131 | + deviceRpcService.process(rpcRequest, fromDeviceRpcResponse -> reply(new LocalRequestMetaData(rpcRequest, currentUser, result), fromDeviceRpcResponse)); |
140 | } | 132 | } |
141 | 133 | ||
142 | @Override | 134 | @Override |
@@ -25,12 +25,20 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -25,12 +25,20 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
25 | import org.springframework.http.HttpStatus; | 25 | import org.springframework.http.HttpStatus; |
26 | import org.springframework.security.access.prepost.PreAuthorize; | 26 | import org.springframework.security.access.prepost.PreAuthorize; |
27 | import org.springframework.util.StringUtils; | 27 | import org.springframework.util.StringUtils; |
28 | -import org.springframework.web.bind.annotation.*; | 28 | +import org.springframework.web.bind.annotation.PathVariable; |
29 | +import org.springframework.web.bind.annotation.RequestBody; | ||
30 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
31 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
32 | +import org.springframework.web.bind.annotation.RequestParam; | ||
33 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
34 | +import org.springframework.web.bind.annotation.ResponseStatus; | ||
35 | +import org.springframework.web.bind.annotation.RestController; | ||
29 | import org.thingsboard.rule.engine.api.ScriptEngine; | 36 | import org.thingsboard.rule.engine.api.ScriptEngine; |
30 | import org.thingsboard.server.common.data.DataConstants; | 37 | import org.thingsboard.server.common.data.DataConstants; |
31 | import org.thingsboard.server.common.data.EntityType; | 38 | import org.thingsboard.server.common.data.EntityType; |
32 | import org.thingsboard.server.common.data.Event; | 39 | import org.thingsboard.server.common.data.Event; |
33 | import org.thingsboard.server.common.data.audit.ActionType; | 40 | import org.thingsboard.server.common.data.audit.ActionType; |
41 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
34 | import org.thingsboard.server.common.data.id.RuleChainId; | 42 | import org.thingsboard.server.common.data.id.RuleChainId; |
35 | import org.thingsboard.server.common.data.id.RuleNodeId; | 43 | import org.thingsboard.server.common.data.id.RuleNodeId; |
36 | import org.thingsboard.server.common.data.id.TenantId; | 44 | import org.thingsboard.server.common.data.id.TenantId; |
@@ -39,12 +47,9 @@ import org.thingsboard.server.common.data.page.TextPageLink; | @@ -39,12 +47,9 @@ import org.thingsboard.server.common.data.page.TextPageLink; | ||
39 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | 47 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
40 | import org.thingsboard.server.common.data.rule.RuleChain; | 48 | import org.thingsboard.server.common.data.rule.RuleChain; |
41 | import org.thingsboard.server.common.data.rule.RuleChainMetaData; | 49 | import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
42 | -import org.thingsboard.server.common.data.security.Authority; | ||
43 | import org.thingsboard.server.common.msg.TbMsg; | 50 | import org.thingsboard.server.common.msg.TbMsg; |
44 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 51 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
45 | import org.thingsboard.server.dao.event.EventService; | 52 | import org.thingsboard.server.dao.event.EventService; |
46 | -import org.thingsboard.server.dao.model.ModelConstants; | ||
47 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
48 | import org.thingsboard.server.service.script.NashornJsEngine; | 53 | import org.thingsboard.server.service.script.NashornJsEngine; |
49 | 54 | ||
50 | import java.util.List; | 55 | import java.util.List; |
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.controller; | ||
17 | - | ||
18 | -import org.springframework.http.HttpStatus; | ||
19 | -import org.springframework.security.access.prepost.PreAuthorize; | ||
20 | -import org.springframework.web.bind.annotation.*; | ||
21 | -import org.thingsboard.server.common.data.EntityType; | ||
22 | -import org.thingsboard.server.common.data.audit.ActionType; | ||
23 | -import org.thingsboard.server.common.data.id.RuleId; | ||
24 | -import org.thingsboard.server.common.data.id.TenantId; | ||
25 | -import org.thingsboard.server.common.data.page.TextPageData; | ||
26 | -import org.thingsboard.server.common.data.page.TextPageLink; | ||
27 | -import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | ||
28 | -import org.thingsboard.server.common.data.plugin.PluginMetaData; | ||
29 | -import org.thingsboard.server.common.data.rule.RuleMetaData; | ||
30 | -import org.thingsboard.server.common.data.security.Authority; | ||
31 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
32 | - | ||
33 | -import java.util.List; | ||
34 | - | ||
35 | -@RestController | ||
36 | -@RequestMapping("/api") | ||
37 | -public class RuleController extends BaseController { | ||
38 | - | ||
39 | - public static final String RULE_ID = "ruleId"; | ||
40 | - | ||
41 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
42 | - @RequestMapping(value = "/rule/{ruleId}", method = RequestMethod.GET) | ||
43 | - @ResponseBody | ||
44 | - public RuleMetaData getRuleById(@PathVariable(RULE_ID) String strRuleId) throws ThingsboardException { | ||
45 | - checkParameter(RULE_ID, strRuleId); | ||
46 | - try { | ||
47 | - RuleId ruleId = new RuleId(toUUID(strRuleId)); | ||
48 | - return checkRule(ruleService.findRuleById(ruleId)); | ||
49 | - } catch (Exception e) { | ||
50 | - throw handleException(e); | ||
51 | - } | ||
52 | - } | ||
53 | - | ||
54 | - | ||
55 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
56 | - @RequestMapping(value = "/rule/token/{pluginToken}", method = RequestMethod.GET) | ||
57 | - @ResponseBody | ||
58 | - public List<RuleMetaData> getRulesByPluginToken(@PathVariable("pluginToken") String pluginToken) throws ThingsboardException { | ||
59 | - checkParameter("pluginToken", pluginToken); | ||
60 | - try { | ||
61 | - PluginMetaData plugin = checkPlugin(pluginService.findPluginByApiToken(pluginToken)); | ||
62 | - return ruleService.findPluginRules(plugin.getApiToken()); | ||
63 | - } catch (Exception e) { | ||
64 | - throw handleException(e); | ||
65 | - } | ||
66 | - } | ||
67 | - | ||
68 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
69 | - @RequestMapping(value = "/rule", method = RequestMethod.POST) | ||
70 | - @ResponseBody | ||
71 | - public RuleMetaData saveRule(@RequestBody RuleMetaData source) throws ThingsboardException { | ||
72 | - try { | ||
73 | - boolean created = source.getId() == null; | ||
74 | - source.setTenantId(getCurrentUser().getTenantId()); | ||
75 | - RuleMetaData rule = checkNotNull(ruleService.saveRule(source)); | ||
76 | - actorService.onEntityStateChange(rule.getTenantId(), rule.getId(), | ||
77 | - created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | ||
78 | - | ||
79 | - logEntityAction(rule.getId(), rule, | ||
80 | - null, | ||
81 | - created ? ActionType.ADDED : ActionType.UPDATED, null); | ||
82 | - | ||
83 | - return rule; | ||
84 | - } catch (Exception e) { | ||
85 | - | ||
86 | - logEntityAction(emptyId(EntityType.RULE), source, | ||
87 | - null, source.getId() == null ? ActionType.ADDED : ActionType.UPDATED, e); | ||
88 | - | ||
89 | - throw handleException(e); | ||
90 | - } | ||
91 | - } | ||
92 | - | ||
93 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
94 | - @RequestMapping(value = "/rule/{ruleId}/activate", method = RequestMethod.POST) | ||
95 | - @ResponseStatus(value = HttpStatus.OK) | ||
96 | - public void activateRuleById(@PathVariable(RULE_ID) String strRuleId) throws ThingsboardException { | ||
97 | - checkParameter(RULE_ID, strRuleId); | ||
98 | - try { | ||
99 | - RuleId ruleId = new RuleId(toUUID(strRuleId)); | ||
100 | - RuleMetaData rule = checkRule(ruleService.findRuleById(ruleId)); | ||
101 | - ruleService.activateRuleById(ruleId); | ||
102 | - actorService.onEntityStateChange(rule.getTenantId(), rule.getId(), ComponentLifecycleEvent.ACTIVATED); | ||
103 | - | ||
104 | - logEntityAction(rule.getId(), rule, | ||
105 | - null, | ||
106 | - ActionType.ACTIVATED, null, strRuleId); | ||
107 | - | ||
108 | - } catch (Exception e) { | ||
109 | - | ||
110 | - logEntityAction(emptyId(EntityType.RULE), | ||
111 | - null, | ||
112 | - null, | ||
113 | - ActionType.ACTIVATED, e, strRuleId); | ||
114 | - | ||
115 | - throw handleException(e); | ||
116 | - } | ||
117 | - } | ||
118 | - | ||
119 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
120 | - @RequestMapping(value = "/rule/{ruleId}/suspend", method = RequestMethod.POST) | ||
121 | - @ResponseStatus(value = HttpStatus.OK) | ||
122 | - public void suspendRuleById(@PathVariable(RULE_ID) String strRuleId) throws ThingsboardException { | ||
123 | - checkParameter(RULE_ID, strRuleId); | ||
124 | - try { | ||
125 | - RuleId ruleId = new RuleId(toUUID(strRuleId)); | ||
126 | - RuleMetaData rule = checkRule(ruleService.findRuleById(ruleId)); | ||
127 | - ruleService.suspendRuleById(ruleId); | ||
128 | - actorService.onEntityStateChange(rule.getTenantId(), rule.getId(), ComponentLifecycleEvent.SUSPENDED); | ||
129 | - | ||
130 | - logEntityAction(rule.getId(), rule, | ||
131 | - null, | ||
132 | - ActionType.SUSPENDED, null, strRuleId); | ||
133 | - | ||
134 | - } catch (Exception e) { | ||
135 | - | ||
136 | - logEntityAction(emptyId(EntityType.RULE), | ||
137 | - null, | ||
138 | - null, | ||
139 | - ActionType.SUSPENDED, e, strRuleId); | ||
140 | - | ||
141 | - throw handleException(e); | ||
142 | - } | ||
143 | - } | ||
144 | - | ||
145 | - @PreAuthorize("hasAuthority('SYS_ADMIN')") | ||
146 | - @RequestMapping(value = "/rule/system", params = {"limit"}, method = RequestMethod.GET) | ||
147 | - @ResponseBody | ||
148 | - public TextPageData<RuleMetaData> getSystemRules( | ||
149 | - @RequestParam int limit, | ||
150 | - @RequestParam(required = false) String textSearch, | ||
151 | - @RequestParam(required = false) String idOffset, | ||
152 | - @RequestParam(required = false) String textOffset) throws ThingsboardException { | ||
153 | - try { | ||
154 | - TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset); | ||
155 | - return checkNotNull(ruleService.findSystemRules(pageLink)); | ||
156 | - } catch (Exception e) { | ||
157 | - throw handleException(e); | ||
158 | - } | ||
159 | - } | ||
160 | - | ||
161 | - @PreAuthorize("hasAuthority('SYS_ADMIN')") | ||
162 | - @RequestMapping(value = "/rule/tenant/{tenantId}", params = {"limit"}, method = RequestMethod.GET) | ||
163 | - @ResponseBody | ||
164 | - public TextPageData<RuleMetaData> getTenantRules( | ||
165 | - @PathVariable("tenantId") String strTenantId, | ||
166 | - @RequestParam int limit, | ||
167 | - @RequestParam(required = false) String textSearch, | ||
168 | - @RequestParam(required = false) String idOffset, | ||
169 | - @RequestParam(required = false) String textOffset) throws ThingsboardException { | ||
170 | - checkParameter("tenantId", strTenantId); | ||
171 | - try { | ||
172 | - TenantId tenantId = new TenantId(toUUID(strTenantId)); | ||
173 | - TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset); | ||
174 | - return checkNotNull(ruleService.findTenantRules(tenantId, pageLink)); | ||
175 | - } catch (Exception e) { | ||
176 | - throw handleException(e); | ||
177 | - } | ||
178 | - } | ||
179 | - | ||
180 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
181 | - @RequestMapping(value = "/rules", method = RequestMethod.GET) | ||
182 | - @ResponseBody | ||
183 | - public List<RuleMetaData> getRules() throws ThingsboardException { | ||
184 | - try { | ||
185 | - if (getCurrentUser().getAuthority() == Authority.SYS_ADMIN) { | ||
186 | - return checkNotNull(ruleService.findSystemRules()); | ||
187 | - } else { | ||
188 | - TenantId tenantId = getCurrentUser().getTenantId(); | ||
189 | - return checkNotNull(ruleService.findAllTenantRulesByTenantId(tenantId)); | ||
190 | - } | ||
191 | - } catch (Exception e) { | ||
192 | - throw handleException(e); | ||
193 | - } | ||
194 | - } | ||
195 | - | ||
196 | - @PreAuthorize("hasAuthority('TENANT_ADMIN')") | ||
197 | - @RequestMapping(value = "/rule", params = {"limit"}, method = RequestMethod.GET) | ||
198 | - @ResponseBody | ||
199 | - public TextPageData<RuleMetaData> getTenantRules( | ||
200 | - @RequestParam int limit, | ||
201 | - @RequestParam(required = false) String textSearch, | ||
202 | - @RequestParam(required = false) String idOffset, | ||
203 | - @RequestParam(required = false) String textOffset) throws ThingsboardException { | ||
204 | - try { | ||
205 | - TenantId tenantId = getCurrentUser().getTenantId(); | ||
206 | - TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset); | ||
207 | - return checkNotNull(ruleService.findTenantRules(tenantId, pageLink)); | ||
208 | - } catch (Exception e) { | ||
209 | - throw handleException(e); | ||
210 | - } | ||
211 | - } | ||
212 | - | ||
213 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | ||
214 | - @RequestMapping(value = "/rule/{ruleId}", method = RequestMethod.DELETE) | ||
215 | - @ResponseStatus(value = HttpStatus.OK) | ||
216 | - public void deleteRule(@PathVariable(RULE_ID) String strRuleId) throws ThingsboardException { | ||
217 | - checkParameter(RULE_ID, strRuleId); | ||
218 | - try { | ||
219 | - RuleId ruleId = new RuleId(toUUID(strRuleId)); | ||
220 | - RuleMetaData rule = checkRule(ruleService.findRuleById(ruleId)); | ||
221 | - ruleService.deleteRuleById(ruleId); | ||
222 | - actorService.onEntityStateChange(rule.getTenantId(), rule.getId(), ComponentLifecycleEvent.DELETED); | ||
223 | - | ||
224 | - logEntityAction(ruleId, rule, | ||
225 | - null, | ||
226 | - ActionType.DELETED, null, strRuleId); | ||
227 | - | ||
228 | - } catch (Exception e) { | ||
229 | - | ||
230 | - logEntityAction(emptyId(EntityType.RULE), | ||
231 | - null, | ||
232 | - null, | ||
233 | - ActionType.DELETED, e, strRuleId); | ||
234 | - | ||
235 | - throw handleException(e); | ||
236 | - } | ||
237 | - } | ||
238 | - | ||
239 | -} |
application/src/main/java/org/thingsboard/server/controller/TbUrlConstants.java
renamed from
extensions-api/src/main/java/org/thingsboard/server/extensions/api/plugins/PluginConstants.java
@@ -13,13 +13,12 @@ | @@ -13,13 +13,12 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.extensions.api.plugins; | 16 | +package org.thingsboard.server.controller; |
17 | 17 | ||
18 | /** | 18 | /** |
19 | - * @author Andrew Shvayka | 19 | + * Created by ashvayka on 17.05.18. |
20 | */ | 20 | */ |
21 | -public class PluginConstants { | 21 | +public class TbUrlConstants { |
22 | public static final String TELEMETRY_URL_PREFIX = "/api/plugins/telemetry"; | 22 | public static final String TELEMETRY_URL_PREFIX = "/api/plugins/telemetry"; |
23 | public static final String RPC_URL_PREFIX = "/api/plugins/rpc"; | 23 | public static final String RPC_URL_PREFIX = "/api/plugins/rpc"; |
24 | - public static final String PLUGIN_URL_PREFIX = "/api/plugins"; | ||
25 | } | 24 | } |
@@ -39,6 +39,7 @@ import org.springframework.web.context.request.async.DeferredResult; | @@ -39,6 +39,7 @@ import org.springframework.web.context.request.async.DeferredResult; | ||
39 | import org.thingsboard.server.common.data.DataConstants; | 39 | import org.thingsboard.server.common.data.DataConstants; |
40 | import org.thingsboard.server.common.data.EntityType; | 40 | import org.thingsboard.server.common.data.EntityType; |
41 | import org.thingsboard.server.common.data.audit.ActionType; | 41 | import org.thingsboard.server.common.data.audit.ActionType; |
42 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
42 | import org.thingsboard.server.common.data.id.EntityId; | 43 | import org.thingsboard.server.common.data.id.EntityId; |
43 | import org.thingsboard.server.common.data.id.EntityIdFactory; | 44 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
44 | import org.thingsboard.server.common.data.id.UUIDBased; | 45 | import org.thingsboard.server.common.data.id.UUIDBased; |
@@ -58,15 +59,13 @@ import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; | @@ -58,15 +59,13 @@ import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; | ||
58 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; | 59 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; |
59 | import org.thingsboard.server.dao.attributes.AttributesService; | 60 | import org.thingsboard.server.dao.attributes.AttributesService; |
60 | import org.thingsboard.server.dao.timeseries.TimeseriesService; | 61 | import org.thingsboard.server.dao.timeseries.TimeseriesService; |
61 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
62 | -import org.thingsboard.server.extensions.api.exception.InvalidParametersException; | ||
63 | -import org.thingsboard.server.extensions.api.exception.UncheckedApiException; | ||
64 | -import org.thingsboard.server.extensions.api.plugins.PluginConstants; | ||
65 | -import org.thingsboard.server.extensions.core.plugin.telemetry.AttributeData; | ||
66 | -import org.thingsboard.server.extensions.core.plugin.telemetry.TsData; | ||
67 | import org.thingsboard.server.service.security.AccessValidator; | 62 | import org.thingsboard.server.service.security.AccessValidator; |
68 | import org.thingsboard.server.service.security.model.SecurityUser; | 63 | import org.thingsboard.server.service.security.model.SecurityUser; |
64 | +import org.thingsboard.server.service.telemetry.AttributeData; | ||
69 | import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; | 65 | import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; |
66 | +import org.thingsboard.server.service.telemetry.TsData; | ||
67 | +import org.thingsboard.server.service.telemetry.exception.InvalidParametersException; | ||
68 | +import org.thingsboard.server.service.telemetry.exception.UncheckedApiException; | ||
70 | 69 | ||
71 | import javax.annotation.Nullable; | 70 | import javax.annotation.Nullable; |
72 | import javax.annotation.PostConstruct; | 71 | import javax.annotation.PostConstruct; |
@@ -84,7 +83,7 @@ import java.util.stream.Collectors; | @@ -84,7 +83,7 @@ import java.util.stream.Collectors; | ||
84 | * Created by ashvayka on 22.03.18. | 83 | * Created by ashvayka on 22.03.18. |
85 | */ | 84 | */ |
86 | @RestController | 85 | @RestController |
87 | -@RequestMapping(PluginConstants.TELEMETRY_URL_PREFIX) | 86 | +@RequestMapping(TbUrlConstants.TELEMETRY_URL_PREFIX) |
88 | @Slf4j | 87 | @Slf4j |
89 | public class TelemetryController extends BaseController { | 88 | public class TelemetryController extends BaseController { |
90 | 89 |
@@ -18,10 +18,20 @@ package org.thingsboard.server.controller; | @@ -18,10 +18,20 @@ package org.thingsboard.server.controller; | ||
18 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
19 | import org.springframework.http.HttpStatus; | 19 | import org.springframework.http.HttpStatus; |
20 | import org.springframework.security.access.prepost.PreAuthorize; | 20 | import org.springframework.security.access.prepost.PreAuthorize; |
21 | -import org.springframework.web.bind.annotation.*; | 21 | +import org.springframework.web.bind.annotation.PathVariable; |
22 | +import org.springframework.web.bind.annotation.RequestBody; | ||
23 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
24 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
25 | +import org.springframework.web.bind.annotation.RequestParam; | ||
26 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
27 | +import org.springframework.web.bind.annotation.ResponseStatus; | ||
28 | +import org.springframework.web.bind.annotation.RestController; | ||
29 | +import org.thingsboard.rule.engine.api.MailService; | ||
22 | import org.thingsboard.server.common.data.EntityType; | 30 | import org.thingsboard.server.common.data.EntityType; |
23 | import org.thingsboard.server.common.data.User; | 31 | import org.thingsboard.server.common.data.User; |
24 | import org.thingsboard.server.common.data.audit.ActionType; | 32 | import org.thingsboard.server.common.data.audit.ActionType; |
33 | +import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
34 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
25 | import org.thingsboard.server.common.data.id.CustomerId; | 35 | import org.thingsboard.server.common.data.id.CustomerId; |
26 | import org.thingsboard.server.common.data.id.TenantId; | 36 | import org.thingsboard.server.common.data.id.TenantId; |
27 | import org.thingsboard.server.common.data.id.UserId; | 37 | import org.thingsboard.server.common.data.id.UserId; |
@@ -29,9 +39,6 @@ import org.thingsboard.server.common.data.page.TextPageData; | @@ -29,9 +39,6 @@ import org.thingsboard.server.common.data.page.TextPageData; | ||
29 | import org.thingsboard.server.common.data.page.TextPageLink; | 39 | import org.thingsboard.server.common.data.page.TextPageLink; |
30 | import org.thingsboard.server.common.data.security.Authority; | 40 | import org.thingsboard.server.common.data.security.Authority; |
31 | import org.thingsboard.server.common.data.security.UserCredentials; | 41 | import org.thingsboard.server.common.data.security.UserCredentials; |
32 | -import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | ||
33 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
34 | -import org.thingsboard.rule.engine.api.MailService; | ||
35 | import org.thingsboard.server.service.security.model.SecurityUser; | 42 | import org.thingsboard.server.service.security.model.SecurityUser; |
36 | 43 | ||
37 | import javax.servlet.http.HttpServletRequest; | 44 | import javax.servlet.http.HttpServletRequest; |
@@ -17,13 +17,20 @@ package org.thingsboard.server.controller; | @@ -17,13 +17,20 @@ package org.thingsboard.server.controller; | ||
17 | 17 | ||
18 | import org.springframework.http.HttpStatus; | 18 | import org.springframework.http.HttpStatus; |
19 | import org.springframework.security.access.prepost.PreAuthorize; | 19 | import org.springframework.security.access.prepost.PreAuthorize; |
20 | -import org.springframework.web.bind.annotation.*; | 20 | +import org.springframework.web.bind.annotation.PathVariable; |
21 | +import org.springframework.web.bind.annotation.RequestBody; | ||
22 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
23 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
24 | +import org.springframework.web.bind.annotation.RequestParam; | ||
25 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
26 | +import org.springframework.web.bind.annotation.ResponseStatus; | ||
27 | +import org.springframework.web.bind.annotation.RestController; | ||
28 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
21 | import org.thingsboard.server.common.data.id.TenantId; | 29 | import org.thingsboard.server.common.data.id.TenantId; |
22 | import org.thingsboard.server.common.data.id.WidgetTypeId; | 30 | import org.thingsboard.server.common.data.id.WidgetTypeId; |
23 | import org.thingsboard.server.common.data.security.Authority; | 31 | import org.thingsboard.server.common.data.security.Authority; |
24 | import org.thingsboard.server.common.data.widget.WidgetType; | 32 | import org.thingsboard.server.common.data.widget.WidgetType; |
25 | import org.thingsboard.server.dao.model.ModelConstants; | 33 | import org.thingsboard.server.dao.model.ModelConstants; |
26 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
27 | 34 | ||
28 | import java.util.List; | 35 | import java.util.List; |
29 | 36 |
@@ -17,7 +17,15 @@ package org.thingsboard.server.controller; | @@ -17,7 +17,15 @@ package org.thingsboard.server.controller; | ||
17 | 17 | ||
18 | import org.springframework.http.HttpStatus; | 18 | import org.springframework.http.HttpStatus; |
19 | import org.springframework.security.access.prepost.PreAuthorize; | 19 | import org.springframework.security.access.prepost.PreAuthorize; |
20 | -import org.springframework.web.bind.annotation.*; | 20 | +import org.springframework.web.bind.annotation.PathVariable; |
21 | +import org.springframework.web.bind.annotation.RequestBody; | ||
22 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
23 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
24 | +import org.springframework.web.bind.annotation.RequestParam; | ||
25 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
26 | +import org.springframework.web.bind.annotation.ResponseStatus; | ||
27 | +import org.springframework.web.bind.annotation.RestController; | ||
28 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
21 | import org.thingsboard.server.common.data.id.TenantId; | 29 | import org.thingsboard.server.common.data.id.TenantId; |
22 | import org.thingsboard.server.common.data.id.WidgetsBundleId; | 30 | import org.thingsboard.server.common.data.id.WidgetsBundleId; |
23 | import org.thingsboard.server.common.data.page.TextPageData; | 31 | import org.thingsboard.server.common.data.page.TextPageData; |
@@ -25,7 +33,6 @@ import org.thingsboard.server.common.data.page.TextPageLink; | @@ -25,7 +33,6 @@ import org.thingsboard.server.common.data.page.TextPageLink; | ||
25 | import org.thingsboard.server.common.data.security.Authority; | 33 | import org.thingsboard.server.common.data.security.Authority; |
26 | import org.thingsboard.server.common.data.widget.WidgetsBundle; | 34 | import org.thingsboard.server.common.data.widget.WidgetsBundle; |
27 | import org.thingsboard.server.dao.model.ModelConstants; | 35 | import org.thingsboard.server.dao.model.ModelConstants; |
28 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
29 | 36 | ||
30 | import java.util.List; | 37 | import java.util.List; |
31 | 38 |
application/src/main/java/org/thingsboard/server/controller/plugin/PluginApiController.java
deleted
100644 → 0
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.controller.plugin; | ||
17 | - | ||
18 | - | ||
19 | -import lombok.extern.slf4j.Slf4j; | ||
20 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
21 | -import org.springframework.web.bind.annotation.RestController; | ||
22 | -import org.thingsboard.server.controller.BaseController; | ||
23 | -import org.thingsboard.server.extensions.api.plugins.PluginConstants; | ||
24 | - | ||
25 | -@RestController | ||
26 | -@RequestMapping(PluginConstants.PLUGIN_URL_PREFIX) | ||
27 | -@Slf4j | ||
28 | -public class PluginApiController extends BaseController { | ||
29 | - | ||
30 | -// @SuppressWarnings("rawtypes") | ||
31 | -// @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") | ||
32 | -// @RequestMapping(value = "/{pluginToken}/**") | ||
33 | -// @ResponseStatus(value = HttpStatus.OK) | ||
34 | -// public DeferredResult<ResponseEntity> processRequest( | ||
35 | -// @PathVariable("pluginToken") String pluginToken, | ||
36 | -// RequestEntity<byte[]> requestEntity, | ||
37 | -// HttpServletRequest request) | ||
38 | -// throws ThingsboardException { | ||
39 | -// log.debug("[{}] Going to process requst uri: {}", pluginToken, requestEntity.getUrl()); | ||
40 | -// DeferredResult<ResponseEntity> result = new DeferredResult<ResponseEntity>(); | ||
41 | -// PluginMetaData pluginMd = pluginService.findPluginByApiToken(pluginToken); | ||
42 | -// if (pluginMd == null) { | ||
43 | -// result.setErrorResult(new PluginNotFoundException("Plugin with token: " + pluginToken + " not found!")); | ||
44 | -// } else { | ||
45 | -// TenantId tenantId = getCurrentUser().getTenantId(); | ||
46 | -// CustomerId customerId = getCurrentUser().getCustomerId(); | ||
47 | -// if (validatePluginAccess(pluginMd, tenantId, customerId)) { | ||
48 | -// if(tenantId != null && ModelConstants.NULL_UUID.equals(tenantId.getId())){ | ||
49 | -// tenantId = null; | ||
50 | -// } | ||
51 | -// UserId userId = getCurrentUser().getId(); | ||
52 | -// String userName = getCurrentUser().getName(); | ||
53 | -// PluginApiCallSecurityContext securityCtx = new PluginApiCallSecurityContext(pluginMd.getTenantId(), pluginMd.getId(), | ||
54 | -// tenantId, customerId, userId, userName); | ||
55 | -// actorService.process(new BasicPluginRestMsg(securityCtx, new RestRequest(requestEntity, request), result)); | ||
56 | -// } else { | ||
57 | -// result.setResult(new ResponseEntity<>(HttpStatus.FORBIDDEN)); | ||
58 | -// } | ||
59 | -// | ||
60 | -// } | ||
61 | -// return result; | ||
62 | -// } | ||
63 | -// | ||
64 | -// public static boolean validatePluginAccess(PluginMetaData pluginMd, TenantId tenantId, CustomerId customerId) { | ||
65 | -// boolean systemAdministrator = tenantId == null || ModelConstants.NULL_UUID.equals(tenantId.getId()); | ||
66 | -// boolean tenantAdministrator = !systemAdministrator && (customerId == null || ModelConstants.NULL_UUID.equals(customerId.getId())); | ||
67 | -// boolean systemPlugin = ModelConstants.NULL_UUID.equals(pluginMd.getTenantId().getId()); | ||
68 | -// | ||
69 | -// boolean validUser = false; | ||
70 | -// if (systemPlugin) { | ||
71 | -// if (pluginMd.isPublicAccess() || systemAdministrator) { | ||
72 | -// // All users can access public system plugins. Only system | ||
73 | -// // users can access private system plugins | ||
74 | -// validUser = true; | ||
75 | -// } | ||
76 | -// } else { | ||
77 | -// if ((pluginMd.isPublicAccess() || tenantAdministrator) && tenantId != null && tenantId.equals(pluginMd.getTenantId())) { | ||
78 | -// // All tenant users can access public tenant plugins. Only tenant | ||
79 | -// // administrator can access private tenant plugins | ||
80 | -// validUser = true; | ||
81 | -// } | ||
82 | -// } | ||
83 | -// return validUser; | ||
84 | -// } | ||
85 | -} |
application/src/main/java/org/thingsboard/server/controller/plugin/PluginNotFoundException.java
deleted
100644 → 0
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.controller.plugin; | ||
17 | - | ||
18 | -import org.springframework.http.HttpStatus; | ||
19 | -import org.springframework.web.bind.annotation.ResponseStatus; | ||
20 | - | ||
21 | -@ResponseStatus(HttpStatus.NOT_FOUND) | ||
22 | -public class PluginNotFoundException extends RuntimeException { | ||
23 | - | ||
24 | - private static final long serialVersionUID = 1L; | ||
25 | - | ||
26 | - public PluginNotFoundException(String message){ | ||
27 | - super(message); | ||
28 | - } | ||
29 | - | ||
30 | -} |
application/src/main/java/org/thingsboard/server/controller/plugin/PluginWebSocketMsgEndpoint.java
deleted
100644 → 0
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.controller.plugin; | ||
17 | - | ||
18 | -import java.io.IOException; | ||
19 | - | ||
20 | -import org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef; | ||
21 | -import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; | ||
22 | - | ||
23 | -public interface PluginWebSocketMsgEndpoint { | ||
24 | - | ||
25 | - void send(PluginWebsocketMsg<?> wsMsg) throws IOException; | ||
26 | - | ||
27 | - void close(PluginWebsocketSessionRef sessionRef) throws IOException; | ||
28 | -} |
@@ -25,11 +25,8 @@ import org.springframework.web.socket.TextMessage; | @@ -25,11 +25,8 @@ import org.springframework.web.socket.TextMessage; | ||
25 | import org.springframework.web.socket.WebSocketSession; | 25 | import org.springframework.web.socket.WebSocketSession; |
26 | import org.springframework.web.socket.handler.TextWebSocketHandler; | 26 | import org.springframework.web.socket.handler.TextWebSocketHandler; |
27 | import org.thingsboard.server.config.WebSocketConfiguration; | 27 | import org.thingsboard.server.config.WebSocketConfiguration; |
28 | -import org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef; | ||
29 | -import org.thingsboard.server.extensions.api.plugins.ws.SessionEvent; | ||
30 | -import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; | ||
31 | -import org.thingsboard.server.extensions.api.plugins.ws.msg.TextPluginWebSocketMsg; | ||
32 | import org.thingsboard.server.service.security.model.SecurityUser; | 28 | import org.thingsboard.server.service.security.model.SecurityUser; |
29 | +import org.thingsboard.server.service.telemetry.SessionEvent; | ||
33 | import org.thingsboard.server.service.telemetry.TelemetryWebSocketMsgEndpoint; | 30 | import org.thingsboard.server.service.telemetry.TelemetryWebSocketMsgEndpoint; |
34 | import org.thingsboard.server.service.telemetry.TelemetryWebSocketService; | 31 | import org.thingsboard.server.service.telemetry.TelemetryWebSocketService; |
35 | import org.thingsboard.server.service.telemetry.TelemetryWebSocketSessionRef; | 32 | import org.thingsboard.server.service.telemetry.TelemetryWebSocketSessionRef; |
@@ -43,7 +40,7 @@ import java.util.concurrent.ConcurrentMap; | @@ -43,7 +40,7 @@ import java.util.concurrent.ConcurrentMap; | ||
43 | 40 | ||
44 | @Service | 41 | @Service |
45 | @Slf4j | 42 | @Slf4j |
46 | -public class TbWebSocketHandler extends TextWebSocketHandler implements PluginWebSocketMsgEndpoint, TelemetryWebSocketMsgEndpoint { | 43 | +public class TbWebSocketHandler extends TextWebSocketHandler implements TelemetryWebSocketMsgEndpoint { |
47 | 44 | ||
48 | private static final ConcurrentMap<String, SessionMetaData> internalSessionMap = new ConcurrentHashMap<>(); | 45 | private static final ConcurrentMap<String, SessionMetaData> internalSessionMap = new ConcurrentHashMap<>(); |
49 | private static final ConcurrentMap<String, String> externalSessionMap = new ConcurrentHashMap<>(); | 46 | private static final ConcurrentMap<String, String> externalSessionMap = new ConcurrentHashMap<>(); |
@@ -183,43 +180,4 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements PluginWe | @@ -183,43 +180,4 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements PluginWe | ||
183 | } | 180 | } |
184 | } | 181 | } |
185 | 182 | ||
186 | - //TODO: remove | ||
187 | - @Override | ||
188 | - public void send(PluginWebsocketMsg<?> wsMsg) throws IOException { | ||
189 | - PluginWebsocketSessionRef sessionRef = wsMsg.getSessionRef(); | ||
190 | - String externalId = sessionRef.getSessionId(); | ||
191 | - log.debug("[{}] Processing {}", externalId, wsMsg); | ||
192 | - String internalId = externalSessionMap.get(externalId); | ||
193 | - if (internalId != null) { | ||
194 | - SessionMetaData sessionMd = internalSessionMap.get(internalId); | ||
195 | - if (sessionMd != null) { | ||
196 | - if (wsMsg instanceof TextPluginWebSocketMsg) { | ||
197 | - String payload = ((TextPluginWebSocketMsg) wsMsg).getPayload(); | ||
198 | - sessionMd.session.sendMessage(new TextMessage(payload)); | ||
199 | - } | ||
200 | - } else { | ||
201 | - log.warn("[{}][{}] Failed to find session by internal id", externalId, internalId); | ||
202 | - } | ||
203 | - } else { | ||
204 | - log.warn("[{}] Failed to find session by external id", externalId); | ||
205 | - } | ||
206 | - } | ||
207 | - | ||
208 | - //TODO: remove | ||
209 | - @Override | ||
210 | - public void close(PluginWebsocketSessionRef sessionRef) throws IOException { | ||
211 | - String externalId = sessionRef.getSessionId(); | ||
212 | - log.debug("[{}] Processing close request", externalId); | ||
213 | - String internalId = externalSessionMap.get(externalId); | ||
214 | - if (internalId != null) { | ||
215 | - SessionMetaData sessionMd = internalSessionMap.get(internalId); | ||
216 | - if (sessionMd != null) { | ||
217 | - sessionMd.session.close(CloseStatus.NORMAL); | ||
218 | - } else { | ||
219 | - log.warn("[{}][{}] Failed to find session by internal id", externalId, internalId); | ||
220 | - } | ||
221 | - } else { | ||
222 | - log.warn("[{}] Failed to find session by external id", externalId); | ||
223 | - } | ||
224 | - } | ||
225 | } | 183 | } |
@@ -23,9 +23,10 @@ import org.springframework.context.ApplicationContext; | @@ -23,9 +23,10 @@ import org.springframework.context.ApplicationContext; | ||
23 | import org.springframework.context.annotation.Profile; | 23 | import org.springframework.context.annotation.Profile; |
24 | import org.springframework.stereotype.Service; | 24 | import org.springframework.stereotype.Service; |
25 | import org.thingsboard.server.service.component.ComponentDiscoveryService; | 25 | import org.thingsboard.server.service.component.ComponentDiscoveryService; |
26 | -import org.thingsboard.server.service.install.*; | ||
27 | - | ||
28 | -import java.nio.file.Paths; | 26 | +import org.thingsboard.server.service.install.DataUpdateService; |
27 | +import org.thingsboard.server.service.install.DatabaseSchemaService; | ||
28 | +import org.thingsboard.server.service.install.DatabaseUpgradeService; | ||
29 | +import org.thingsboard.server.service.install.SystemDataLoaderService; | ||
29 | 30 | ||
30 | @Service | 31 | @Service |
31 | @Profile("install") | 32 | @Profile("install") |
@@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
21 | import org.springframework.context.annotation.DependsOn; | 21 | import org.springframework.context.annotation.DependsOn; |
22 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
23 | -import org.thingsboard.server.service.environment.EnvironmentLogService; | ||
24 | 23 | ||
25 | import javax.annotation.PostConstruct; | 24 | import javax.annotation.PostConstruct; |
26 | import java.util.Collections; | 25 | import java.util.Collections; |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.cluster.discovery; | 16 | package org.thingsboard.server.service.cluster.discovery; |
17 | 17 | ||
18 | -import lombok.AccessLevel; | ||
19 | import lombok.EqualsAndHashCode; | 18 | import lombok.EqualsAndHashCode; |
20 | import lombok.Getter; | 19 | import lombok.Getter; |
21 | import lombok.ToString; | 20 | import lombok.ToString; |
@@ -16,9 +16,7 @@ | @@ -16,9 +16,7 @@ | ||
16 | package org.thingsboard.server.service.cluster.routing; | 16 | package org.thingsboard.server.service.cluster.routing; |
17 | 17 | ||
18 | import org.thingsboard.server.common.data.id.EntityId; | 18 | import org.thingsboard.server.common.data.id.EntityId; |
19 | -import org.thingsboard.server.common.data.id.UUIDBased; | ||
20 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 19 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
21 | -import org.thingsboard.server.service.cluster.discovery.ServerInstance; | ||
22 | 20 | ||
23 | import java.util.Optional; | 21 | import java.util.Optional; |
24 | import java.util.UUID; | 22 | import java.util.UUID; |
@@ -23,7 +23,6 @@ import org.springframework.beans.factory.annotation.Value; | @@ -23,7 +23,6 @@ import org.springframework.beans.factory.annotation.Value; | ||
23 | import org.springframework.stereotype.Service; | 23 | import org.springframework.stereotype.Service; |
24 | import org.springframework.util.Assert; | 24 | import org.springframework.util.Assert; |
25 | import org.thingsboard.server.common.data.id.EntityId; | 25 | import org.thingsboard.server.common.data.id.EntityId; |
26 | -import org.thingsboard.server.common.data.id.UUIDBased; | ||
27 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 26 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
28 | import org.thingsboard.server.service.cluster.discovery.DiscoveryService; | 27 | import org.thingsboard.server.service.cluster.discovery.DiscoveryService; |
29 | import org.thingsboard.server.service.cluster.discovery.DiscoveryServiceListener; | 28 | import org.thingsboard.server.service.cluster.discovery.DiscoveryServiceListener; |
@@ -26,9 +26,7 @@ import org.thingsboard.server.actors.rpc.RpcBroadcastMsg; | @@ -26,9 +26,7 @@ import org.thingsboard.server.actors.rpc.RpcBroadcastMsg; | ||
26 | import org.thingsboard.server.actors.rpc.RpcSessionCreateRequestMsg; | 26 | import org.thingsboard.server.actors.rpc.RpcSessionCreateRequestMsg; |
27 | import org.thingsboard.server.common.msg.TbActorMsg; | 27 | import org.thingsboard.server.common.msg.TbActorMsg; |
28 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 28 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
29 | - | ||
30 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; | 29 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; |
31 | - | ||
32 | import org.thingsboard.server.gen.cluster.ClusterRpcServiceGrpc; | 30 | import org.thingsboard.server.gen.cluster.ClusterRpcServiceGrpc; |
33 | import org.thingsboard.server.service.cluster.discovery.ServerInstance; | 31 | import org.thingsboard.server.service.cluster.discovery.ServerInstance; |
34 | import org.thingsboard.server.service.cluster.discovery.ServerInstanceService; | 32 | import org.thingsboard.server.service.cluster.discovery.ServerInstanceService; |
@@ -15,11 +15,9 @@ | @@ -15,11 +15,9 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.component; | 16 | package org.thingsboard.server.service.component; |
17 | 17 | ||
18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
18 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
19 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
20 | -import com.fasterxml.jackson.databind.JsonNode; | ||
21 | -import com.google.common.base.Charsets; | ||
22 | -import com.google.common.io.Resources; | ||
23 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
24 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
25 | import org.springframework.beans.factory.annotation.Value; | 23 | import org.springframework.beans.factory.annotation.Value; |
@@ -28,17 +26,24 @@ import org.springframework.context.annotation.ClassPathScanningCandidateComponen | @@ -28,17 +26,24 @@ import org.springframework.context.annotation.ClassPathScanningCandidateComponen | ||
28 | import org.springframework.core.env.Environment; | 26 | import org.springframework.core.env.Environment; |
29 | import org.springframework.core.type.filter.AnnotationTypeFilter; | 27 | import org.springframework.core.type.filter.AnnotationTypeFilter; |
30 | import org.springframework.stereotype.Service; | 28 | import org.springframework.stereotype.Service; |
31 | -import org.thingsboard.rule.engine.api.*; | 29 | +import org.thingsboard.rule.engine.api.NodeConfiguration; |
30 | +import org.thingsboard.rule.engine.api.NodeDefinition; | ||
31 | +import org.thingsboard.rule.engine.api.RuleNode; | ||
32 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; | 32 | import org.thingsboard.server.common.data.plugin.ComponentDescriptor; |
33 | import org.thingsboard.server.common.data.plugin.ComponentType; | 33 | import org.thingsboard.server.common.data.plugin.ComponentType; |
34 | import org.thingsboard.server.dao.component.ComponentDescriptorService; | 34 | import org.thingsboard.server.dao.component.ComponentDescriptorService; |
35 | -import org.thingsboard.server.extensions.api.component.*; | ||
36 | 35 | ||
37 | import javax.annotation.PostConstruct; | 36 | import javax.annotation.PostConstruct; |
38 | -import java.io.IOException; | ||
39 | import java.lang.annotation.Annotation; | 37 | import java.lang.annotation.Annotation; |
40 | -import java.util.*; | ||
41 | -import java.util.stream.Collectors; | 38 | +import java.util.ArrayList; |
39 | +import java.util.Collection; | ||
40 | +import java.util.Collections; | ||
41 | +import java.util.HashMap; | ||
42 | +import java.util.HashSet; | ||
43 | +import java.util.List; | ||
44 | +import java.util.Map; | ||
45 | +import java.util.Optional; | ||
46 | +import java.util.Set; | ||
42 | 47 | ||
43 | @Service | 48 | @Service |
44 | @Slf4j | 49 | @Slf4j |
@@ -112,7 +117,6 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe | @@ -112,7 +117,6 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe | ||
112 | try { | 117 | try { |
113 | scannedComponent.setType(type); | 118 | scannedComponent.setType(type); |
114 | Class<?> clazz = Class.forName(clazzName); | 119 | Class<?> clazz = Class.forName(clazzName); |
115 | - String descriptorResourceName; | ||
116 | switch (type) { | 120 | switch (type) { |
117 | case ENRICHMENT: | 121 | case ENRICHMENT: |
118 | case FILTER: | 122 | case FILTER: |
@@ -128,34 +132,6 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe | @@ -128,34 +132,6 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe | ||
128 | configurationDescriptor.set("nodeDefinition", node); | 132 | configurationDescriptor.set("nodeDefinition", node); |
129 | scannedComponent.setConfigurationDescriptor(configurationDescriptor); | 133 | scannedComponent.setConfigurationDescriptor(configurationDescriptor); |
130 | break; | 134 | break; |
131 | - case OLD_ACTION: | ||
132 | - Action oldActionAnnotation = clazz.getAnnotation(Action.class); | ||
133 | - scannedComponent.setName(oldActionAnnotation.name()); | ||
134 | - scannedComponent.setScope(oldActionAnnotation.scope()); | ||
135 | - descriptorResourceName = oldActionAnnotation.descriptor(); | ||
136 | - scannedComponent.setConfigurationDescriptor(mapper.readTree( | ||
137 | - Resources.toString(Resources.getResource(descriptorResourceName), Charsets.UTF_8))); | ||
138 | - break; | ||
139 | - case PLUGIN: | ||
140 | - Plugin pluginAnnotation = clazz.getAnnotation(Plugin.class); | ||
141 | - scannedComponent.setName(pluginAnnotation.name()); | ||
142 | - scannedComponent.setScope(pluginAnnotation.scope()); | ||
143 | - descriptorResourceName = pluginAnnotation.descriptor(); | ||
144 | - for (Class<?> actionClazz : pluginAnnotation.actions()) { | ||
145 | - ComponentDescriptor actionComponent = getComponent(actionClazz.getName()) | ||
146 | - .orElseThrow(() -> { | ||
147 | - log.error("Can't initialize plugin {}, due to missing action {}!", def.getBeanClassName(), actionClazz.getName()); | ||
148 | - return new ClassNotFoundException("Action: " + actionClazz.getName() + "is missing!"); | ||
149 | - }); | ||
150 | - if (actionComponent.getType() != ComponentType.OLD_ACTION) { | ||
151 | - log.error("Plugin {} action {} has wrong component type!", def.getBeanClassName(), actionClazz.getName(), actionComponent.getType()); | ||
152 | - throw new RuntimeException("Plugin " + def.getBeanClassName() + "action " + actionClazz.getName() + " has wrong component type!"); | ||
153 | - } | ||
154 | - } | ||
155 | - scannedComponent.setActions(Arrays.stream(pluginAnnotation.actions()).map(Class::getName).collect(Collectors.joining(","))); | ||
156 | - scannedComponent.setConfigurationDescriptor(mapper.readTree( | ||
157 | - Resources.toString(Resources.getResource(descriptorResourceName), Charsets.UTF_8))); | ||
158 | - break; | ||
159 | default: | 135 | default: |
160 | throw new RuntimeException(type + " is not supported yet!"); | 136 | throw new RuntimeException(type + " is not supported yet!"); |
161 | } | 137 | } |
@@ -212,13 +188,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe | @@ -212,13 +188,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe | ||
212 | 188 | ||
213 | @Override | 189 | @Override |
214 | public void discoverComponents() { | 190 | public void discoverComponents() { |
215 | - | ||
216 | registerRuleNodeComponents(); | 191 | registerRuleNodeComponents(); |
217 | - | ||
218 | - registerComponents(ComponentType.OLD_ACTION, Action.class); | ||
219 | - | ||
220 | - registerComponents(ComponentType.PLUGIN, Plugin.class); | ||
221 | - | ||
222 | log.info("Found following definitions: {}", components.values()); | 192 | log.info("Found following definitions: {}", components.values()); |
223 | } | 193 | } |
224 | 194 | ||
@@ -244,22 +214,4 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe | @@ -244,22 +214,4 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe | ||
244 | public Optional<ComponentDescriptor> getComponent(String clazz) { | 214 | public Optional<ComponentDescriptor> getComponent(String clazz) { |
245 | return Optional.ofNullable(components.get(clazz)); | 215 | return Optional.ofNullable(components.get(clazz)); |
246 | } | 216 | } |
247 | - | ||
248 | - @Override | ||
249 | - public List<ComponentDescriptor> getPluginActions(String pluginClazz) { | ||
250 | - Optional<ComponentDescriptor> pluginOpt = getComponent(pluginClazz); | ||
251 | - if (pluginOpt.isPresent()) { | ||
252 | - ComponentDescriptor plugin = pluginOpt.get(); | ||
253 | - if (ComponentType.PLUGIN != plugin.getType()) { | ||
254 | - throw new IllegalArgumentException(pluginClazz + " is not a plugin!"); | ||
255 | - } | ||
256 | - List<ComponentDescriptor> result = new ArrayList<>(); | ||
257 | - for (String action : plugin.getActions().split(",")) { | ||
258 | - getComponent(action).ifPresent(result::add); | ||
259 | - } | ||
260 | - return result; | ||
261 | - } else { | ||
262 | - throw new IllegalArgumentException(pluginClazz + " is not a component!"); | ||
263 | - } | ||
264 | - } | ||
265 | } | 217 | } |
@@ -35,6 +35,4 @@ public interface ComponentDiscoveryService { | @@ -35,6 +35,4 @@ public interface ComponentDiscoveryService { | ||
35 | 35 | ||
36 | Optional<ComponentDescriptor> getComponent(String clazz); | 36 | Optional<ComponentDescriptor> getComponent(String clazz); |
37 | 37 | ||
38 | - List<ComponentDescriptor> getPluginActions(String pluginClazz); | ||
39 | - | ||
40 | } | 38 | } |
application/src/main/java/org/thingsboard/server/service/install/CassandraDatabaseSchemaService.java
@@ -17,7 +17,6 @@ package org.thingsboard.server.service.install; | @@ -17,7 +17,6 @@ package org.thingsboard.server.service.install; | ||
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
20 | -import org.springframework.beans.factory.annotation.Value; | ||
21 | import org.springframework.context.annotation.Profile; | 20 | import org.springframework.context.annotation.Profile; |
22 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
23 | import org.thingsboard.server.dao.cassandra.CassandraInstallCluster; | 22 | import org.thingsboard.server.dao.cassandra.CassandraInstallCluster; |
@@ -18,7 +18,6 @@ package org.thingsboard.server.service.install; | @@ -18,7 +18,6 @@ package org.thingsboard.server.service.install; | ||
18 | import com.datastax.driver.core.KeyspaceMetadata; | 18 | import com.datastax.driver.core.KeyspaceMetadata; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
20 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
21 | -import org.springframework.beans.factory.annotation.Value; | ||
22 | import org.springframework.context.annotation.Profile; | 21 | import org.springframework.context.annotation.Profile; |
23 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
24 | import org.thingsboard.server.dao.cassandra.CassandraCluster; | 23 | import org.thingsboard.server.dao.cassandra.CassandraCluster; |
@@ -33,7 +32,17 @@ import java.nio.file.Path; | @@ -33,7 +32,17 @@ import java.nio.file.Path; | ||
33 | import java.nio.file.Paths; | 32 | import java.nio.file.Paths; |
34 | import java.util.List; | 33 | import java.util.List; |
35 | 34 | ||
36 | -import static org.thingsboard.server.service.install.DatabaseHelper.*; | 35 | +import static org.thingsboard.server.service.install.DatabaseHelper.ADDITIONAL_INFO; |
36 | +import static org.thingsboard.server.service.install.DatabaseHelper.ASSET; | ||
37 | +import static org.thingsboard.server.service.install.DatabaseHelper.ASSIGNED_CUSTOMERS; | ||
38 | +import static org.thingsboard.server.service.install.DatabaseHelper.CONFIGURATION; | ||
39 | +import static org.thingsboard.server.service.install.DatabaseHelper.CUSTOMER_ID; | ||
40 | +import static org.thingsboard.server.service.install.DatabaseHelper.DASHBOARD; | ||
41 | +import static org.thingsboard.server.service.install.DatabaseHelper.DEVICE; | ||
42 | +import static org.thingsboard.server.service.install.DatabaseHelper.ID; | ||
43 | +import static org.thingsboard.server.service.install.DatabaseHelper.SEARCH_TEXT; | ||
44 | +import static org.thingsboard.server.service.install.DatabaseHelper.TENANT_ID; | ||
45 | +import static org.thingsboard.server.service.install.DatabaseHelper.TITLE; | ||
37 | 46 | ||
38 | @Service | 47 | @Service |
39 | @NoSqlDao | 48 | @NoSqlDao |
@@ -30,7 +30,11 @@ import org.thingsboard.server.dao.dashboard.DashboardService; | @@ -30,7 +30,11 @@ import org.thingsboard.server.dao.dashboard.DashboardService; | ||
30 | import java.io.IOException; | 30 | import java.io.IOException; |
31 | import java.nio.file.Files; | 31 | import java.nio.file.Files; |
32 | import java.nio.file.Path; | 32 | import java.nio.file.Path; |
33 | -import java.util.*; | 33 | +import java.util.ArrayList; |
34 | +import java.util.HashSet; | ||
35 | +import java.util.List; | ||
36 | +import java.util.Set; | ||
37 | +import java.util.UUID; | ||
34 | 38 | ||
35 | /** | 39 | /** |
36 | * Created by igor on 2/27/18. | 40 | * Created by igor on 2/27/18. |
application/src/main/java/org/thingsboard/server/service/install/DefaultSystemDataLoaderService.java
@@ -15,46 +15,34 @@ | @@ -15,46 +15,34 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.install; | 16 | package org.thingsboard.server.service.install; |
17 | 17 | ||
18 | -import com.fasterxml.jackson.databind.JsonNode; | ||
19 | import com.fasterxml.jackson.databind.ObjectMapper; | 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
20 | import com.fasterxml.jackson.databind.node.ObjectNode; | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
22 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
23 | -import org.springframework.beans.factory.annotation.Value; | ||
24 | import org.springframework.context.annotation.Bean; | 22 | import org.springframework.context.annotation.Bean; |
25 | import org.springframework.context.annotation.Profile; | 23 | import org.springframework.context.annotation.Profile; |
26 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | 24 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
27 | import org.springframework.stereotype.Service; | 25 | import org.springframework.stereotype.Service; |
28 | -import org.thingsboard.server.common.data.*; | 26 | +import org.thingsboard.server.common.data.AdminSettings; |
27 | +import org.thingsboard.server.common.data.Customer; | ||
28 | +import org.thingsboard.server.common.data.Device; | ||
29 | +import org.thingsboard.server.common.data.Tenant; | ||
30 | +import org.thingsboard.server.common.data.User; | ||
29 | import org.thingsboard.server.common.data.id.CustomerId; | 31 | import org.thingsboard.server.common.data.id.CustomerId; |
30 | import org.thingsboard.server.common.data.id.TenantId; | 32 | import org.thingsboard.server.common.data.id.TenantId; |
31 | -import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; | ||
32 | -import org.thingsboard.server.common.data.plugin.PluginMetaData; | ||
33 | -import org.thingsboard.server.common.data.rule.RuleMetaData; | ||
34 | import org.thingsboard.server.common.data.security.Authority; | 33 | import org.thingsboard.server.common.data.security.Authority; |
35 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 34 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
36 | import org.thingsboard.server.common.data.security.UserCredentials; | 35 | import org.thingsboard.server.common.data.security.UserCredentials; |
37 | -import org.thingsboard.server.common.data.widget.WidgetType; | ||
38 | import org.thingsboard.server.common.data.widget.WidgetsBundle; | 36 | import org.thingsboard.server.common.data.widget.WidgetsBundle; |
39 | import org.thingsboard.server.dao.customer.CustomerService; | 37 | import org.thingsboard.server.dao.customer.CustomerService; |
40 | -import org.thingsboard.server.dao.dashboard.DashboardService; | ||
41 | import org.thingsboard.server.dao.device.DeviceCredentialsService; | 38 | import org.thingsboard.server.dao.device.DeviceCredentialsService; |
42 | import org.thingsboard.server.dao.device.DeviceService; | 39 | import org.thingsboard.server.dao.device.DeviceService; |
43 | import org.thingsboard.server.dao.model.ModelConstants; | 40 | import org.thingsboard.server.dao.model.ModelConstants; |
44 | -import org.thingsboard.server.dao.plugin.PluginService; | ||
45 | -import org.thingsboard.server.dao.rule.RuleService; | ||
46 | import org.thingsboard.server.dao.settings.AdminSettingsService; | 41 | import org.thingsboard.server.dao.settings.AdminSettingsService; |
47 | import org.thingsboard.server.dao.tenant.TenantService; | 42 | import org.thingsboard.server.dao.tenant.TenantService; |
48 | import org.thingsboard.server.dao.user.UserService; | 43 | import org.thingsboard.server.dao.user.UserService; |
49 | -import org.thingsboard.server.dao.widget.WidgetTypeService; | ||
50 | import org.thingsboard.server.dao.widget.WidgetsBundleService; | 44 | import org.thingsboard.server.dao.widget.WidgetsBundleService; |
51 | 45 | ||
52 | -import java.io.IOException; | ||
53 | -import java.nio.file.DirectoryStream; | ||
54 | -import java.nio.file.Files; | ||
55 | -import java.nio.file.Path; | ||
56 | -import java.nio.file.Paths; | ||
57 | - | ||
58 | @Service | 46 | @Service |
59 | @Profile("install") | 47 | @Profile("install") |
60 | @Slf4j | 48 | @Slf4j |
@@ -16,7 +16,6 @@ | @@ -16,7 +16,6 @@ | ||
16 | package org.thingsboard.server.service.install; | 16 | package org.thingsboard.server.service.install; |
17 | 17 | ||
18 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
19 | -import lombok.Getter; | ||
20 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
21 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
22 | import org.springframework.beans.factory.annotation.Value; | 21 | import org.springframework.beans.factory.annotation.Value; |
@@ -28,7 +28,6 @@ import java.nio.file.Path; | @@ -28,7 +28,6 @@ import java.nio.file.Path; | ||
28 | import java.nio.file.Paths; | 28 | import java.nio.file.Paths; |
29 | import java.sql.Connection; | 29 | import java.sql.Connection; |
30 | import java.sql.DriverManager; | 30 | import java.sql.DriverManager; |
31 | -import java.sql.PreparedStatement; | ||
32 | 31 | ||
33 | @Service | 32 | @Service |
34 | @Profile("install") | 33 | @Profile("install") |
@@ -22,7 +22,6 @@ import org.springframework.context.annotation.Profile; | @@ -22,7 +22,6 @@ import org.springframework.context.annotation.Profile; | ||
22 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
23 | import org.thingsboard.server.dao.dashboard.DashboardService; | 23 | import org.thingsboard.server.dao.dashboard.DashboardService; |
24 | import org.thingsboard.server.dao.util.SqlDao; | 24 | import org.thingsboard.server.dao.util.SqlDao; |
25 | -import org.thingsboard.server.service.install.cql.CassandraDbHelper; | ||
26 | import org.thingsboard.server.service.install.sql.SqlDbHelper; | 25 | import org.thingsboard.server.service.install.sql.SqlDbHelper; |
27 | 26 | ||
28 | import java.nio.charset.Charset; | 27 | import java.nio.charset.Charset; |
@@ -30,11 +29,16 @@ import java.nio.file.Files; | @@ -30,11 +29,16 @@ import java.nio.file.Files; | ||
30 | import java.nio.file.Path; | 29 | import java.nio.file.Path; |
31 | import java.nio.file.Paths; | 30 | import java.nio.file.Paths; |
32 | import java.sql.Connection; | 31 | import java.sql.Connection; |
33 | -import java.sql.DatabaseMetaData; | ||
34 | import java.sql.DriverManager; | 32 | import java.sql.DriverManager; |
35 | 33 | ||
36 | -import static org.thingsboard.server.service.install.DatabaseHelper.*; | 34 | +import static org.thingsboard.server.service.install.DatabaseHelper.ASSIGNED_CUSTOMERS; |
37 | import static org.thingsboard.server.service.install.DatabaseHelper.CONFIGURATION; | 35 | import static org.thingsboard.server.service.install.DatabaseHelper.CONFIGURATION; |
36 | +import static org.thingsboard.server.service.install.DatabaseHelper.CUSTOMER_ID; | ||
37 | +import static org.thingsboard.server.service.install.DatabaseHelper.DASHBOARD; | ||
38 | +import static org.thingsboard.server.service.install.DatabaseHelper.ID; | ||
39 | +import static org.thingsboard.server.service.install.DatabaseHelper.SEARCH_TEXT; | ||
40 | +import static org.thingsboard.server.service.install.DatabaseHelper.TENANT_ID; | ||
41 | +import static org.thingsboard.server.service.install.DatabaseHelper.TITLE; | ||
38 | 42 | ||
39 | @Service | 43 | @Service |
40 | @Profile("install") | 44 | @Profile("install") |
@@ -15,7 +15,16 @@ | @@ -15,7 +15,16 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.install.cql; | 16 | package org.thingsboard.server.service.install.cql; |
17 | 17 | ||
18 | -import com.datastax.driver.core.*; | 18 | +import com.datastax.driver.core.BoundStatement; |
19 | +import com.datastax.driver.core.DataType; | ||
20 | +import com.datastax.driver.core.KeyspaceMetadata; | ||
21 | +import com.datastax.driver.core.PreparedStatement; | ||
22 | +import com.datastax.driver.core.ResultSet; | ||
23 | +import com.datastax.driver.core.Row; | ||
24 | +import com.datastax.driver.core.Session; | ||
25 | +import com.datastax.driver.core.SimpleStatement; | ||
26 | +import com.datastax.driver.core.Statement; | ||
27 | +import com.datastax.driver.core.TableMetadata; | ||
19 | import org.apache.commons.csv.CSVFormat; | 28 | import org.apache.commons.csv.CSVFormat; |
20 | import org.apache.commons.csv.CSVParser; | 29 | import org.apache.commons.csv.CSVParser; |
21 | import org.apache.commons.csv.CSVPrinter; | 30 | import org.apache.commons.csv.CSVPrinter; |
@@ -25,7 +34,11 @@ import java.io.IOException; | @@ -25,7 +34,11 @@ import java.io.IOException; | ||
25 | import java.nio.file.Files; | 34 | import java.nio.file.Files; |
26 | import java.nio.file.Path; | 35 | import java.nio.file.Path; |
27 | import java.nio.file.StandardCopyOption; | 36 | import java.nio.file.StandardCopyOption; |
28 | -import java.util.*; | 37 | +import java.util.ArrayList; |
38 | +import java.util.Date; | ||
39 | +import java.util.Iterator; | ||
40 | +import java.util.List; | ||
41 | +import java.util.UUID; | ||
29 | 42 | ||
30 | import static org.thingsboard.server.service.install.DatabaseHelper.CSV_DUMP_FORMAT; | 43 | import static org.thingsboard.server.service.install.DatabaseHelper.CSV_DUMP_FORMAT; |
31 | 44 |
@@ -23,7 +23,12 @@ import org.apache.commons.csv.CSVRecord; | @@ -23,7 +23,12 @@ import org.apache.commons.csv.CSVRecord; | ||
23 | 23 | ||
24 | import java.nio.file.Files; | 24 | import java.nio.file.Files; |
25 | import java.nio.file.Path; | 25 | import java.nio.file.Path; |
26 | -import java.sql.*; | 26 | +import java.sql.Connection; |
27 | +import java.sql.PreparedStatement; | ||
28 | +import java.sql.ResultSet; | ||
29 | +import java.sql.ResultSetMetaData; | ||
30 | +import java.sql.SQLException; | ||
31 | +import java.sql.Statement; | ||
27 | import java.util.ArrayList; | 32 | import java.util.ArrayList; |
28 | import java.util.HashMap; | 33 | import java.util.HashMap; |
29 | import java.util.List; | 34 | import java.util.List; |
@@ -15,47 +15,30 @@ | @@ -15,47 +15,30 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.rpc; | 16 | package org.thingsboard.server.service.rpc; |
17 | 17 | ||
18 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
19 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
20 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
21 | -import org.springframework.http.HttpStatus; | ||
22 | -import org.springframework.http.ResponseEntity; | ||
23 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
24 | -import org.springframework.util.StringUtils; | ||
25 | -import org.springframework.web.context.request.async.DeferredResult; | 21 | +import org.thingsboard.rule.engine.api.RpcError; |
22 | +import org.thingsboard.rule.engine.api.msg.ToDeviceActorNotificationMsg; | ||
26 | import org.thingsboard.server.actors.service.ActorService; | 23 | import org.thingsboard.server.actors.service.ActorService; |
27 | -import org.thingsboard.server.common.data.audit.ActionType; | ||
28 | import org.thingsboard.server.common.data.id.DeviceId; | 24 | import org.thingsboard.server.common.data.id.DeviceId; |
29 | -import org.thingsboard.server.common.data.id.EntityId; | ||
30 | import org.thingsboard.server.common.data.id.TenantId; | 25 | import org.thingsboard.server.common.data.id.TenantId; |
31 | -import org.thingsboard.server.common.data.id.UUIDBased; | ||
32 | -import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | ||
33 | -import org.thingsboard.server.common.msg.TbActorMsg; | ||
34 | import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; | 26 | import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; |
35 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 27 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
36 | import org.thingsboard.server.common.msg.core.ToServerRpcResponseMsg; | 28 | import org.thingsboard.server.common.msg.core.ToServerRpcResponseMsg; |
37 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 29 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
38 | -import org.thingsboard.server.controller.BaseController; | ||
39 | import org.thingsboard.server.dao.audit.AuditLogService; | 30 | import org.thingsboard.server.dao.audit.AuditLogService; |
40 | -import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | ||
41 | -import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; | ||
42 | -import org.thingsboard.server.extensions.api.plugins.msg.RpcError; | ||
43 | -import org.thingsboard.server.gen.cluster.ClusterAPIProtos; | ||
44 | import org.thingsboard.server.service.cluster.routing.ClusterRoutingService; | 31 | import org.thingsboard.server.service.cluster.routing.ClusterRoutingService; |
45 | import org.thingsboard.server.service.cluster.rpc.ClusterRpcService; | 32 | import org.thingsboard.server.service.cluster.rpc.ClusterRpcService; |
46 | -import org.thingsboard.server.service.security.model.SecurityUser; | ||
47 | 33 | ||
48 | import javax.annotation.PostConstruct; | 34 | import javax.annotation.PostConstruct; |
49 | import javax.annotation.PreDestroy; | 35 | import javax.annotation.PreDestroy; |
50 | -import java.io.IOException; | ||
51 | -import java.util.Optional; | ||
52 | import java.util.UUID; | 36 | import java.util.UUID; |
53 | import java.util.concurrent.ConcurrentHashMap; | 37 | import java.util.concurrent.ConcurrentHashMap; |
54 | import java.util.concurrent.ConcurrentMap; | 38 | import java.util.concurrent.ConcurrentMap; |
55 | import java.util.concurrent.Executors; | 39 | import java.util.concurrent.Executors; |
56 | import java.util.concurrent.ScheduledExecutorService; | 40 | import java.util.concurrent.ScheduledExecutorService; |
57 | import java.util.concurrent.TimeUnit; | 41 | import java.util.concurrent.TimeUnit; |
58 | -import java.util.function.BiConsumer; | ||
59 | import java.util.function.Consumer; | 42 | import java.util.function.Consumer; |
60 | 43 | ||
61 | /** | 44 | /** |
@@ -19,7 +19,6 @@ import org.thingsboard.server.common.data.id.DeviceId; | @@ -19,7 +19,6 @@ import org.thingsboard.server.common.data.id.DeviceId; | ||
19 | import org.thingsboard.server.common.data.id.TenantId; | 19 | import org.thingsboard.server.common.data.id.TenantId; |
20 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 20 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
21 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 21 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
22 | -import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; | ||
23 | 22 | ||
24 | import java.util.function.Consumer; | 23 | import java.util.function.Consumer; |
25 | 24 |
application/src/main/java/org/thingsboard/server/service/rpc/FromDeviceRpcResponse.java
renamed from
extensions-api/src/main/java/org/thingsboard/server/extensions/api/plugins/msg/FromDeviceRpcResponse.java
@@ -13,11 +13,12 @@ | @@ -13,11 +13,12 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.extensions.api.plugins.msg; | 16 | +package org.thingsboard.server.service.rpc; |
17 | 17 | ||
18 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | import lombok.RequiredArgsConstructor; | 19 | import lombok.RequiredArgsConstructor; |
20 | import lombok.ToString; | 20 | import lombok.ToString; |
21 | +import org.thingsboard.rule.engine.api.RpcError; | ||
21 | 22 | ||
22 | import java.util.Optional; | 23 | import java.util.Optional; |
23 | import java.util.UUID; | 24 | import java.util.UUID; |
@@ -18,12 +18,12 @@ package org.thingsboard.server.service.rpc; | @@ -18,12 +18,12 @@ package org.thingsboard.server.service.rpc; | ||
18 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | import lombok.RequiredArgsConstructor; | 19 | import lombok.RequiredArgsConstructor; |
20 | import lombok.ToString; | 20 | import lombok.ToString; |
21 | +import org.thingsboard.rule.engine.api.msg.ToDeviceActorNotificationMsg; | ||
21 | import org.thingsboard.server.common.data.id.DeviceId; | 22 | import org.thingsboard.server.common.data.id.DeviceId; |
22 | import org.thingsboard.server.common.data.id.TenantId; | 23 | import org.thingsboard.server.common.data.id.TenantId; |
23 | import org.thingsboard.server.common.msg.MsgType; | 24 | import org.thingsboard.server.common.msg.MsgType; |
24 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 25 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
25 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 26 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
26 | -import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | ||
27 | 27 | ||
28 | import java.util.Optional; | 28 | import java.util.Optional; |
29 | 29 |
@@ -18,12 +18,12 @@ package org.thingsboard.server.service.rpc; | @@ -18,12 +18,12 @@ package org.thingsboard.server.service.rpc; | ||
18 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | import lombok.RequiredArgsConstructor; | 19 | import lombok.RequiredArgsConstructor; |
20 | import lombok.ToString; | 20 | import lombok.ToString; |
21 | +import org.thingsboard.rule.engine.api.msg.ToDeviceActorNotificationMsg; | ||
21 | import org.thingsboard.server.common.data.id.DeviceId; | 22 | import org.thingsboard.server.common.data.id.DeviceId; |
22 | import org.thingsboard.server.common.data.id.TenantId; | 23 | import org.thingsboard.server.common.data.id.TenantId; |
23 | import org.thingsboard.server.common.msg.MsgType; | 24 | import org.thingsboard.server.common.msg.MsgType; |
24 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 25 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
25 | import org.thingsboard.server.common.msg.core.ToServerRpcResponseMsg; | 26 | import org.thingsboard.server.common.msg.core.ToServerRpcResponseMsg; |
26 | -import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | ||
27 | 27 | ||
28 | import java.util.Optional; | 28 | import java.util.Optional; |
29 | 29 |
@@ -24,12 +24,11 @@ import org.springframework.http.HttpStatus; | @@ -24,12 +24,11 @@ import org.springframework.http.HttpStatus; | ||
24 | import org.springframework.http.ResponseEntity; | 24 | import org.springframework.http.ResponseEntity; |
25 | import org.springframework.stereotype.Component; | 25 | import org.springframework.stereotype.Component; |
26 | import org.springframework.web.context.request.async.DeferredResult; | 26 | import org.springframework.web.context.request.async.DeferredResult; |
27 | -import org.thingsboard.server.actors.plugin.ValidationResult; | ||
28 | -import org.thingsboard.server.common.data.BaseData; | ||
29 | import org.thingsboard.server.common.data.Customer; | 27 | import org.thingsboard.server.common.data.Customer; |
30 | import org.thingsboard.server.common.data.Device; | 28 | import org.thingsboard.server.common.data.Device; |
31 | import org.thingsboard.server.common.data.Tenant; | 29 | import org.thingsboard.server.common.data.Tenant; |
32 | import org.thingsboard.server.common.data.asset.Asset; | 30 | import org.thingsboard.server.common.data.asset.Asset; |
31 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
33 | import org.thingsboard.server.common.data.id.AssetId; | 32 | import org.thingsboard.server.common.data.id.AssetId; |
34 | import org.thingsboard.server.common.data.id.CustomerId; | 33 | import org.thingsboard.server.common.data.id.CustomerId; |
35 | import org.thingsboard.server.common.data.id.DeviceId; | 34 | import org.thingsboard.server.common.data.id.DeviceId; |
@@ -48,9 +47,8 @@ import org.thingsboard.server.dao.device.DeviceService; | @@ -48,9 +47,8 @@ import org.thingsboard.server.dao.device.DeviceService; | ||
48 | import org.thingsboard.server.dao.rule.RuleChainService; | 47 | import org.thingsboard.server.dao.rule.RuleChainService; |
49 | import org.thingsboard.server.dao.tenant.TenantService; | 48 | import org.thingsboard.server.dao.tenant.TenantService; |
50 | import org.thingsboard.server.dao.user.UserService; | 49 | import org.thingsboard.server.dao.user.UserService; |
51 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
52 | -import org.thingsboard.server.extensions.api.exception.ToErrorResponseEntity; | ||
53 | import org.thingsboard.server.service.security.model.SecurityUser; | 50 | import org.thingsboard.server.service.security.model.SecurityUser; |
51 | +import org.thingsboard.server.service.telemetry.exception.ToErrorResponseEntity; | ||
54 | 52 | ||
55 | import javax.annotation.Nullable; | 53 | import javax.annotation.Nullable; |
56 | import javax.annotation.PostConstruct; | 54 | import javax.annotation.PostConstruct; |
@@ -16,12 +16,10 @@ | @@ -16,12 +16,10 @@ | ||
16 | package org.thingsboard.server.service.security; | 16 | package org.thingsboard.server.service.security; |
17 | 17 | ||
18 | import com.google.common.util.concurrent.FutureCallback; | 18 | import com.google.common.util.concurrent.FutureCallback; |
19 | -import org.thingsboard.server.actors.plugin.ValidationResult; | ||
20 | -import org.thingsboard.server.actors.plugin.ValidationResultCode; | ||
21 | -import org.thingsboard.server.extensions.api.exception.AccessDeniedException; | ||
22 | -import org.thingsboard.server.extensions.api.exception.EntityNotFoundException; | ||
23 | -import org.thingsboard.server.extensions.api.exception.InternalErrorException; | ||
24 | -import org.thingsboard.server.extensions.api.exception.UnauthorizedException; | 19 | +import org.thingsboard.server.service.telemetry.exception.AccessDeniedException; |
20 | +import org.thingsboard.server.service.telemetry.exception.EntityNotFoundException; | ||
21 | +import org.thingsboard.server.service.telemetry.exception.InternalErrorException; | ||
22 | +import org.thingsboard.server.service.telemetry.exception.UnauthorizedException; | ||
25 | 23 | ||
26 | /** | 24 | /** |
27 | * Created by ashvayka on 31.03.18. | 25 | * Created by ashvayka on 31.03.18. |
application/src/main/java/org/thingsboard/server/service/security/ValidationResult.java
renamed from
application/src/main/java/org/thingsboard/server/actors/plugin/ValidationResult.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.actors.plugin; | 16 | +package org.thingsboard.server.service.security; |
17 | 17 | ||
18 | import lombok.AllArgsConstructor; | 18 | import lombok.AllArgsConstructor; |
19 | import lombok.Data; | 19 | import lombok.Data; |
application/src/main/java/org/thingsboard/server/service/security/ValidationResultCode.java
renamed from
application/src/main/java/org/thingsboard/server/actors/plugin/ValidationResultCode.java
@@ -13,8 +13,11 @@ | @@ -13,8 +13,11 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.actors.plugin; | 16 | +package org.thingsboard.server.service.security; |
17 | 17 | ||
18 | +/** | ||
19 | + * Created by ashvayka on 17.05.18. | ||
20 | + */ | ||
18 | public enum ValidationResultCode { | 21 | public enum ValidationResultCode { |
19 | OK, | 22 | OK, |
20 | UNAUTHORIZED, | 23 | UNAUTHORIZED, |
@@ -15,24 +15,16 @@ | @@ -15,24 +15,16 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.security.auth.jwt; | 16 | package org.thingsboard.server.service.security.auth.jwt; |
17 | 17 | ||
18 | -import io.jsonwebtoken.Claims; | ||
19 | -import io.jsonwebtoken.Jws; | ||
20 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
21 | import org.springframework.security.authentication.AuthenticationProvider; | 19 | import org.springframework.security.authentication.AuthenticationProvider; |
22 | import org.springframework.security.core.Authentication; | 20 | import org.springframework.security.core.Authentication; |
23 | import org.springframework.security.core.AuthenticationException; | 21 | import org.springframework.security.core.AuthenticationException; |
24 | -import org.springframework.security.core.GrantedAuthority; | ||
25 | -import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
26 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
27 | -import org.thingsboard.server.config.JwtSettings; | ||
28 | import org.thingsboard.server.service.security.auth.JwtAuthenticationToken; | 23 | import org.thingsboard.server.service.security.auth.JwtAuthenticationToken; |
29 | import org.thingsboard.server.service.security.model.SecurityUser; | 24 | import org.thingsboard.server.service.security.model.SecurityUser; |
30 | import org.thingsboard.server.service.security.model.token.JwtTokenFactory; | 25 | import org.thingsboard.server.service.security.model.token.JwtTokenFactory; |
31 | import org.thingsboard.server.service.security.model.token.RawAccessJwtToken; | 26 | import org.thingsboard.server.service.security.model.token.RawAccessJwtToken; |
32 | 27 | ||
33 | -import java.util.List; | ||
34 | -import java.util.stream.Collectors; | ||
35 | - | ||
36 | @Component | 28 | @Component |
37 | @SuppressWarnings("unchecked") | 29 | @SuppressWarnings("unchecked") |
38 | public class JwtAuthenticationProvider implements AuthenticationProvider { | 30 | public class JwtAuthenticationProvider implements AuthenticationProvider { |
@@ -23,7 +23,6 @@ import org.springframework.security.core.context.SecurityContextHolder; | @@ -23,7 +23,6 @@ import org.springframework.security.core.context.SecurityContextHolder; | ||
23 | import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; | 23 | import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; |
24 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; | 24 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; |
25 | import org.springframework.security.web.util.matcher.RequestMatcher; | 25 | import org.springframework.security.web.util.matcher.RequestMatcher; |
26 | -import org.thingsboard.server.config.ThingsboardSecurityConfiguration; | ||
27 | import org.thingsboard.server.service.security.auth.JwtAuthenticationToken; | 26 | import org.thingsboard.server.service.security.auth.JwtAuthenticationToken; |
28 | import org.thingsboard.server.service.security.auth.jwt.extractor.TokenExtractor; | 27 | import org.thingsboard.server.service.security.auth.jwt.extractor.TokenExtractor; |
29 | import org.thingsboard.server.service.security.model.token.RawAccessJwtToken; | 28 | import org.thingsboard.server.service.security.model.token.RawAccessJwtToken; |