Commit e58d5b2d8a7e3760525ce5c9a0f497b299a9625d
1 parent
6b546a45
removed rpc status sent, added idx_rpc_tenant_id_device_id
Showing
16 changed files
with
147 additions
and
62 deletions
... | ... | @@ -174,20 +174,15 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { |
174 | 174 | |
175 | 175 | long timeout = request.getExpirationTime() - System.currentTimeMillis(); |
176 | 176 | boolean persisted = request.isPersisted(); |
177 | + | |
177 | 178 | if (timeout <= 0) { |
178 | 179 | log.debug("[{}][{}] Ignoring message due to exp time reached, {}", deviceId, request.getId(), request.getExpirationTime()); |
179 | - | |
180 | 180 | if (persisted) { |
181 | - Rpc rpc = new Rpc(new RpcId(request.getId())); | |
182 | - rpc.setCreatedTime(System.currentTimeMillis()); | |
183 | - rpc.setTenantId(tenantId); | |
184 | - rpc.setDeviceId(deviceId); | |
185 | - rpc.setExpirationTime(request.getExpirationTime()); | |
186 | - rpc.setRequest(JacksonUtil.valueToTree(request)); | |
187 | - rpc.setStatus(RpcStatus.TIMEOUT); | |
188 | - systemContext.getTbRpcService().save(tenantId, rpc); | |
181 | + createRpc(request, RpcStatus.TIMEOUT); | |
189 | 182 | } |
190 | 183 | return; |
184 | + } else if (persisted) { | |
185 | + createRpc(request, RpcStatus.QUEUED); | |
191 | 186 | } |
192 | 187 | |
193 | 188 | boolean sent; |
... | ... | @@ -204,24 +199,14 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { |
204 | 199 | syncSessionSet.add(key); |
205 | 200 | } |
206 | 201 | }); |
207 | - log.trace("46) Rpc syncSessionSet [{}] subscription after sent [{}]",syncSessionSet, rpcSubscriptions); | |
202 | + log.trace("46) Rpc syncSessionSet [{}] subscription after sent [{}]", syncSessionSet, rpcSubscriptions); | |
208 | 203 | syncSessionSet.forEach(rpcSubscriptions::remove); |
209 | 204 | } |
210 | 205 | |
211 | - if (persisted) { | |
212 | - Rpc rpc = new Rpc(new RpcId(request.getId())); | |
213 | - rpc.setCreatedTime(System.currentTimeMillis()); | |
214 | - rpc.setTenantId(tenantId); | |
215 | - rpc.setDeviceId(deviceId); | |
216 | - rpc.setExpirationTime(request.getExpirationTime()); | |
217 | - rpc.setRequest(JacksonUtil.valueToTree(request)); | |
218 | - rpc.setStatus(sent ? RpcStatus.SENT : RpcStatus.QUEUED); | |
219 | - systemContext.getTbRpcService().save(tenantId, rpc); | |
220 | - if (!(sent || request.isOneway())) { | |
221 | - ObjectNode response = JacksonUtil.newObjectNode(); | |
222 | - response.put("rpcId", request.getId().toString()); | |
223 | - systemContext.getTbCoreDeviceRpcService().processRpcResponseFromDeviceActor(new FromDeviceRpcResponse(msg.getMsg().getId(), JacksonUtil.toString(response), null)); | |
224 | - } | |
206 | + if (persisted && !(sent || request.isOneway())) { | |
207 | + ObjectNode response = JacksonUtil.newObjectNode(); | |
208 | + response.put("rpcId", request.getId().toString()); | |
209 | + systemContext.getTbCoreDeviceRpcService().processRpcResponseFromDeviceActor(new FromDeviceRpcResponse(msg.getMsg().getId(), JacksonUtil.toString(response), null)); | |
225 | 210 | } |
226 | 211 | |
227 | 212 | if (request.isOneway() && sent) { |
... | ... | @@ -237,6 +222,18 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { |
237 | 222 | } |
238 | 223 | } |
239 | 224 | |
225 | + private Rpc createRpc(ToDeviceRpcRequest request, RpcStatus status) { | |
226 | + Rpc rpc = new Rpc(new RpcId(request.getId())); | |
227 | + rpc.setCreatedTime(System.currentTimeMillis()); | |
228 | + rpc.setTenantId(tenantId); | |
229 | + rpc.setDeviceId(deviceId); | |
230 | + rpc.setExpirationTime(request.getExpirationTime()); | |
231 | + rpc.setRequest(JacksonUtil.valueToTree(request)); | |
232 | + rpc.setStatus(status); | |
233 | + systemContext.getTbRpcService().save(tenantId, rpc); | |
234 | + return systemContext.getTbRpcService().save(tenantId, rpc); | |
235 | + } | |
236 | + | |
240 | 237 | private ToDeviceRpcRequestMsg creteToDeviceRpcRequestMsg(ToDeviceRpcRequest request) { |
241 | 238 | ToDeviceRpcRequestBody body = request.getBody(); |
242 | 239 | return ToDeviceRpcRequestMsg.newBuilder() |
... | ... | @@ -318,9 +315,6 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { |
318 | 315 | .setPersisted(request.isPersisted()) |
319 | 316 | .build(); |
320 | 317 | |
321 | - if (request.isPersisted()) { | |
322 | - systemContext.getTbRpcService().save(tenantId, new RpcId(request.getId()), RpcStatus.SENT, null); | |
323 | - } | |
324 | 318 | sendToTransport(rpcRequest, sessionId, nodeId); |
325 | 319 | }; |
326 | 320 | } |
... | ... | @@ -821,10 +815,10 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { |
821 | 815 | |
822 | 816 | void init(TbActorCtx ctx) { |
823 | 817 | schedulePeriodicMsgWithDelay(ctx, SessionTimeoutCheckMsg.instance(), systemContext.getSessionReportTimeout(), systemContext.getSessionReportTimeout()); |
824 | - PageLink pageLink = new PageLink(10); | |
818 | + PageLink pageLink = new PageLink(1024); | |
825 | 819 | PageData<Rpc> pageData; |
826 | 820 | do { |
827 | - pageData = systemContext.getTbRpcService().findAllByDeviceIdAndStatus(deviceId, RpcStatus.QUEUED, pageLink); | |
821 | + pageData = systemContext.getTbRpcService().findAllByDeviceIdAndStatus(tenantId, deviceId, RpcStatus.QUEUED, pageLink); | |
828 | 822 | pageData.getData().forEach(rpc -> { |
829 | 823 | ToDeviceRpcRequest msg = JacksonUtil.convertValue(rpc.getRequest(), ToDeviceRpcRequest.class); |
830 | 824 | long timeout = rpc.getExpirationTime() - System.currentTimeMillis(); | ... | ... |
... | ... | @@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.PathVariable; |
29 | 29 | import org.springframework.web.bind.annotation.RequestBody; |
30 | 30 | import org.springframework.web.bind.annotation.RequestMapping; |
31 | 31 | import org.springframework.web.bind.annotation.RequestMethod; |
32 | +import org.springframework.web.bind.annotation.RequestParam; | |
32 | 33 | import org.springframework.web.bind.annotation.ResponseBody; |
33 | 34 | import org.springframework.web.bind.annotation.RestController; |
34 | 35 | import org.springframework.web.context.request.async.DeferredResult; |
... | ... | @@ -41,7 +42,10 @@ import org.thingsboard.server.common.data.id.EntityId; |
41 | 42 | import org.thingsboard.server.common.data.id.RpcId; |
42 | 43 | import org.thingsboard.server.common.data.id.TenantId; |
43 | 44 | import org.thingsboard.server.common.data.id.UUIDBased; |
45 | +import org.thingsboard.server.common.data.page.PageData; | |
46 | +import org.thingsboard.server.common.data.page.PageLink; | |
44 | 47 | import org.thingsboard.server.common.data.rpc.Rpc; |
48 | +import org.thingsboard.server.common.data.rpc.RpcStatus; | |
45 | 49 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; |
46 | 50 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
47 | 51 | import org.thingsboard.server.queue.util.TbCoreComponent; |
... | ... | @@ -95,7 +99,7 @@ public class RpcController extends BaseController { |
95 | 99 | return handleDeviceRPCRequest(false, new DeviceId(UUID.fromString(deviceIdStr)), requestBody); |
96 | 100 | } |
97 | 101 | |
98 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") | |
102 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | |
99 | 103 | @RequestMapping(value = "/persisted/{rpcId}", method = RequestMethod.GET) |
100 | 104 | @ResponseBody |
101 | 105 | public Rpc getPersistedRpc(@PathVariable("rpcId") String strRpc) throws ThingsboardException { |
... | ... | @@ -108,6 +112,39 @@ public class RpcController extends BaseController { |
108 | 112 | } |
109 | 113 | } |
110 | 114 | |
115 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | |
116 | + @RequestMapping(value = "/persisted/{deviceId}", method = RequestMethod.GET) | |
117 | + @ResponseBody | |
118 | + public PageData<Rpc> getPersistedRpcByDevice(@PathVariable("deviceId") String strDeviceId, | |
119 | + @RequestParam int pageSize, | |
120 | + @RequestParam int page, | |
121 | + @RequestParam RpcStatus rpcStatus, | |
122 | + @RequestParam(required = false) String textSearch, | |
123 | + @RequestParam(required = false) String sortProperty, | |
124 | + @RequestParam(required = false) String sortOrder) throws ThingsboardException { | |
125 | + checkParameter("DeviceId", strDeviceId); | |
126 | + try { | |
127 | + TenantId tenantId = getCurrentUser().getTenantId(); | |
128 | + PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); | |
129 | + DeviceId deviceId = new DeviceId(UUID.fromString(strDeviceId)); | |
130 | + return checkNotNull(rpcService.findAllByDeviceIdAndStatus(tenantId, deviceId, rpcStatus, pageLink)); | |
131 | + } catch (Exception e) { | |
132 | + throw handleException(e); | |
133 | + } | |
134 | + } | |
135 | + | |
136 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") | |
137 | + @RequestMapping(value = "/persisted/{rpcId}", method = RequestMethod.DELETE) | |
138 | + @ResponseBody | |
139 | + public void deleteResource(@PathVariable("rpcId") String strRpc) throws ThingsboardException { | |
140 | + checkParameter("RpcId", strRpc); | |
141 | + try { | |
142 | + rpcService.deleteRpc(getTenantId(), new RpcId(UUID.fromString(strRpc))); | |
143 | + } catch (Exception e) { | |
144 | + throw handleException(e); | |
145 | + } | |
146 | + } | |
147 | + | |
111 | 148 | private DeferredResult<ResponseEntity> handleDeviceRPCRequest(boolean oneWay, DeviceId deviceId, String requestBody) throws ThingsboardException { |
112 | 149 | try { |
113 | 150 | JsonNode rpcRequestBody = jsonMapper.readTree(requestBody); | ... | ... |
... | ... | @@ -54,7 +54,7 @@ public class RuleEngineEntityActionService { |
54 | 54 | |
55 | 55 | private static final ObjectMapper json = new ObjectMapper(); |
56 | 56 | |
57 | - public void pushEntityActionToRuleEngine(EntityId entityId, Object entity, TenantId tenantId, CustomerId customerId, | |
57 | + public void pushEntityActionToRuleEngine(EntityId entityId, HasName entity, TenantId tenantId, CustomerId customerId, | |
58 | 58 | ActionType actionType, User user, Object... additionalInfo) { |
59 | 59 | String msgType = null; |
60 | 60 | switch (actionType) { | ... | ... |
... | ... | @@ -41,9 +41,10 @@ public class TbRpcService { |
41 | 41 | private final RpcService rpcService; |
42 | 42 | private final TbClusterService tbClusterService; |
43 | 43 | |
44 | - public void save(TenantId tenantId, Rpc rpc) { | |
45 | - Rpc saved = rpcService.save(tenantId, rpc); | |
44 | + public Rpc save(TenantId tenantId, Rpc rpc) { | |
45 | + Rpc saved = rpcService.save(rpc); | |
46 | 46 | pushRpcMsgToRuleEngine(tenantId, saved); |
47 | + return saved; | |
47 | 48 | } |
48 | 49 | |
49 | 50 | public void save(TenantId tenantId, RpcId rpcId, RpcStatus newStatus, JsonNode response) { |
... | ... | @@ -53,7 +54,7 @@ public class TbRpcService { |
53 | 54 | if (response != null) { |
54 | 55 | foundRpc.setResponse(response); |
55 | 56 | } |
56 | - Rpc saved = rpcService.save(tenantId, foundRpc); | |
57 | + Rpc saved = rpcService.save(foundRpc); | |
57 | 58 | pushRpcMsgToRuleEngine(tenantId, saved); |
58 | 59 | } else { |
59 | 60 | log.warn("[{}] Failed to update RPC status because RPC was already deleted", rpcId); |
... | ... | @@ -69,8 +70,8 @@ public class TbRpcService { |
69 | 70 | return rpcService.findById(tenantId, rpcId); |
70 | 71 | } |
71 | 72 | |
72 | - public PageData<Rpc> findAllByDeviceIdAndStatus(DeviceId deviceId, RpcStatus rpcStatus, PageLink pageLink) { | |
73 | - return rpcService.findAllByDeviceIdAndStatus(deviceId, rpcStatus, pageLink); | |
73 | + public PageData<Rpc> findAllByDeviceIdAndStatus(TenantId tenantId, DeviceId deviceId, RpcStatus rpcStatus, PageLink pageLink) { | |
74 | + return rpcService.findAllByDeviceIdAndStatus(tenantId, deviceId, rpcStatus, pageLink); | |
74 | 75 | } |
75 | 76 | |
76 | 77 | } | ... | ... |
... | ... | @@ -25,13 +25,15 @@ import org.thingsboard.server.common.data.rpc.Rpc; |
25 | 25 | import org.thingsboard.server.common.data.rpc.RpcStatus; |
26 | 26 | |
27 | 27 | public interface RpcService { |
28 | - Rpc save(TenantId tenantId, Rpc rpc); | |
28 | + Rpc save(Rpc rpc); | |
29 | 29 | |
30 | - void remove(TenantId tenantId, RpcId id); | |
30 | + void deleteRpc(TenantId tenantId, RpcId id); | |
31 | + | |
32 | + void deleteAllRpcByTenantId(TenantId tenantId); | |
31 | 33 | |
32 | 34 | Rpc findById(TenantId tenantId, RpcId id); |
33 | 35 | |
34 | 36 | ListenableFuture<Rpc> findRpcByIdAsync(TenantId tenantId, RpcId id); |
35 | 37 | |
36 | - PageData<Rpc> findAllByDeviceIdAndStatus(DeviceId deviceId, RpcStatus rpcStatus, PageLink pageLink); | |
38 | + PageData<Rpc> findAllByDeviceIdAndStatus(TenantId tenantId, DeviceId deviceId, RpcStatus rpcStatus, PageLink pageLink); | |
37 | 39 | } | ... | ... |
... | ... | @@ -77,7 +77,6 @@ public class DataConstants { |
77 | 77 | public static final String RPC_CALL_FROM_SERVER_TO_DEVICE = "RPC_CALL_FROM_SERVER_TO_DEVICE"; |
78 | 78 | |
79 | 79 | public static final String RPC_QUEUED = "RPC_QUEUED"; |
80 | - public static final String RPC_SENT = "RPC_SENT"; | |
81 | 80 | public static final String RPC_DELIVERED = "RPC_DELIVERED"; |
82 | 81 | public static final String RPC_SUCCESSFUL = "RPC_SUCCESSFUL"; |
83 | 82 | public static final String RPC_TIMEOUT = "RPC_TIMEOUT"; | ... | ... |
... | ... | @@ -26,35 +26,75 @@ import org.thingsboard.server.common.data.page.PageData; |
26 | 26 | import org.thingsboard.server.common.data.page.PageLink; |
27 | 27 | import org.thingsboard.server.common.data.rpc.Rpc; |
28 | 28 | import org.thingsboard.server.common.data.rpc.RpcStatus; |
29 | +import org.thingsboard.server.dao.service.PaginatedRemover; | |
30 | + | |
31 | +import static org.thingsboard.server.dao.service.Validator.validateId; | |
32 | +import static org.thingsboard.server.dao.service.Validator.validatePageLink; | |
29 | 33 | |
30 | 34 | @Service |
31 | 35 | @Slf4j |
32 | 36 | @RequiredArgsConstructor |
33 | 37 | public class BaseRpcService implements RpcService { |
38 | + public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; | |
39 | + public static final String INCORRECT_RPC_ID = "Incorrect rpcId "; | |
40 | + | |
34 | 41 | private final RpcDao rpcDao; |
35 | 42 | |
36 | 43 | @Override |
37 | - public Rpc save(TenantId tenantId, Rpc rpc) { | |
38 | - return rpcDao.save(tenantId, rpc); | |
44 | + public Rpc save(Rpc rpc) { | |
45 | + log.trace("Executing save, [{}]", rpc); | |
46 | + return rpcDao.save(rpc.getTenantId(), rpc); | |
39 | 47 | } |
40 | 48 | |
41 | 49 | @Override |
42 | - public void remove(TenantId tenantId, RpcId id) { | |
43 | - rpcDao.removeById(tenantId, id.getId()); | |
50 | + public void deleteRpc(TenantId tenantId, RpcId rpcId) { | |
51 | + log.trace("Executing deleteRpc, tenantId [{}], rpcId [{}]", tenantId, rpcId); | |
52 | + validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | |
53 | + validateId(rpcId, INCORRECT_RPC_ID + rpcId); | |
54 | + rpcDao.removeById(tenantId, rpcId.getId()); | |
44 | 55 | } |
45 | 56 | |
46 | 57 | @Override |
47 | - public Rpc findById(TenantId tenantId, RpcId id) { | |
48 | - return rpcDao.findById(tenantId, id.getId()); | |
58 | + public void deleteAllRpcByTenantId(TenantId tenantId) { | |
59 | + log.trace("Executing deleteAllRpcByTenantId, tenantId [{}]", tenantId); | |
60 | + validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | |
61 | + tenantRpcRemover.removeEntities(tenantId, tenantId); | |
49 | 62 | } |
50 | 63 | |
51 | 64 | @Override |
52 | - public ListenableFuture<Rpc> findRpcByIdAsync(TenantId tenantId, RpcId id) { | |
53 | - return rpcDao.findByIdAsync(tenantId, id.getId()); | |
65 | + public Rpc findById(TenantId tenantId, RpcId rpcId) { | |
66 | + log.trace("Executing findById, tenantId [{}], rpcId [{}]", tenantId, rpcId); | |
67 | + validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | |
68 | + validateId(rpcId, INCORRECT_RPC_ID + rpcId); | |
69 | + return rpcDao.findById(tenantId, rpcId.getId()); | |
54 | 70 | } |
55 | 71 | |
56 | 72 | @Override |
57 | - public PageData<Rpc> findAllByDeviceIdAndStatus(DeviceId deviceId, RpcStatus rpcStatus, PageLink pageLink) { | |
58 | - return rpcDao.findAllByDeviceId(deviceId, rpcStatus, pageLink); | |
73 | + public ListenableFuture<Rpc> findRpcByIdAsync(TenantId tenantId, RpcId rpcId) { | |
74 | + log.trace("Executing findRpcByIdAsync, tenantId [{}], rpcId: [{}]", tenantId, rpcId); | |
75 | + validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | |
76 | + validateId(rpcId, INCORRECT_RPC_ID + rpcId); | |
77 | + return rpcDao.findByIdAsync(tenantId, rpcId.getId()); | |
59 | 78 | } |
79 | + | |
80 | + @Override | |
81 | + public PageData<Rpc> findAllByDeviceIdAndStatus(TenantId tenantId, DeviceId deviceId, RpcStatus rpcStatus, PageLink pageLink) { | |
82 | + log.trace("Executing findAllByDeviceIdAndStatus, tenantId [{}], deviceId [{}], rpcStatus [{}], pageLink [{}]", tenantId, deviceId, rpcStatus, pageLink); | |
83 | + validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | |
84 | + validatePageLink(pageLink); | |
85 | + return rpcDao.findAllByDeviceId(tenantId, deviceId, rpcStatus, pageLink); | |
86 | + } | |
87 | + | |
88 | + private PaginatedRemover<TenantId, Rpc> tenantRpcRemover = | |
89 | + new PaginatedRemover<>() { | |
90 | + @Override | |
91 | + protected PageData<Rpc> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) { | |
92 | + return rpcDao.findAllRpcByTenantId(id, pageLink); | |
93 | + } | |
94 | + | |
95 | + @Override | |
96 | + protected void removeEntity(TenantId tenantId, Rpc entity) { | |
97 | + deleteRpc(tenantId, entity.getId()); | |
98 | + } | |
99 | + }; | |
60 | 100 | } | ... | ... |
... | ... | @@ -24,7 +24,9 @@ import org.thingsboard.server.common.data.rpc.RpcStatus; |
24 | 24 | import org.thingsboard.server.dao.Dao; |
25 | 25 | |
26 | 26 | public interface RpcDao extends Dao<Rpc> { |
27 | - PageData<Rpc> findAllByDeviceId(DeviceId deviceId, RpcStatus rpcStatus, PageLink pageLink); | |
27 | + PageData<Rpc> findAllByDeviceId(TenantId tenantId, DeviceId deviceId, RpcStatus rpcStatus, PageLink pageLink); | |
28 | + | |
29 | + PageData<Rpc> findAllRpcByTenantId(TenantId tenantId, PageLink pageLink); | |
28 | 30 | |
29 | 31 | Long deleteOutdatedRpcByTenantId(TenantId tenantId, Long expirationTime); |
30 | 32 | } | ... | ... |
... | ... | @@ -49,10 +49,14 @@ public class JpaRpcDao extends JpaAbstractDao<RpcEntity, Rpc> implements RpcDao |
49 | 49 | return rpcRepository; |
50 | 50 | } |
51 | 51 | |
52 | + @Override | |
53 | + public PageData<Rpc> findAllByDeviceId(TenantId tenantId, DeviceId deviceId, RpcStatus rpcStatus, PageLink pageLink) { | |
54 | + return DaoUtil.toPageData(rpcRepository.findAllByTenantIdAndDeviceIdAndStatus(tenantId.getId(), deviceId.getId(), rpcStatus, DaoUtil.toPageable(pageLink))); | |
55 | + } | |
52 | 56 | |
53 | 57 | @Override |
54 | - public PageData<Rpc> findAllByDeviceId(DeviceId deviceId, RpcStatus rpcStatus, PageLink pageLink) { | |
55 | - return DaoUtil.toPageData(rpcRepository.findAllByDeviceIdAndStatus(deviceId.getId(), rpcStatus, DaoUtil.toPageable(pageLink))); | |
58 | + public PageData<Rpc> findAllRpcByTenantId(TenantId tenantId, PageLink pageLink) { | |
59 | + return DaoUtil.toPageData(rpcRepository.findAllByTenantId(tenantId.getId(), DaoUtil.toPageable(pageLink))); | |
56 | 60 | } |
57 | 61 | |
58 | 62 | @Override | ... | ... |
... | ... | @@ -26,7 +26,9 @@ import org.thingsboard.server.dao.model.sql.RpcEntity; |
26 | 26 | import java.util.UUID; |
27 | 27 | |
28 | 28 | public interface RpcRepository extends CrudRepository<RpcEntity, UUID> { |
29 | - Page<RpcEntity> findAllByDeviceIdAndStatus(UUID deviceId, RpcStatus status, Pageable pageable); | |
29 | + Page<RpcEntity> findAllByTenantIdAndDeviceIdAndStatus(UUID tenantId, UUID deviceId, RpcStatus status, Pageable pageable); | |
30 | + | |
31 | + Page<RpcEntity> findAllByTenantId(UUID tenantId, Pageable pageable); | |
30 | 32 | |
31 | 33 | @Query(value = "WITH deleted AS (DELETE FROM rpc WHERE (tenant_id = :tenantId AND created_time < :expirationTime) IS TRUE RETURNING *) SELECT count(*) FROM deleted", |
32 | 34 | nativeQuery = true) | ... | ... |
... | ... | @@ -37,6 +37,7 @@ import org.thingsboard.server.dao.entityview.EntityViewService; |
37 | 37 | import org.thingsboard.server.dao.exception.DataValidationException; |
38 | 38 | import org.thingsboard.server.dao.ota.OtaPackageService; |
39 | 39 | import org.thingsboard.server.dao.resource.ResourceService; |
40 | +import org.thingsboard.server.dao.rpc.RpcService; | |
40 | 41 | import org.thingsboard.server.dao.rule.RuleChainService; |
41 | 42 | import org.thingsboard.server.dao.service.DataValidator; |
42 | 43 | import org.thingsboard.server.dao.service.PaginatedRemover; |
... | ... | @@ -96,6 +97,9 @@ public class TenantServiceImpl extends AbstractEntityService implements TenantSe |
96 | 97 | @Autowired |
97 | 98 | private OtaPackageService otaPackageService; |
98 | 99 | |
100 | + @Autowired | |
101 | + private RpcService rpcService; | |
102 | + | |
99 | 103 | @Override |
100 | 104 | public Tenant findTenantById(TenantId tenantId) { |
101 | 105 | log.trace("Executing findTenantById [{}]", tenantId); |
... | ... | @@ -151,6 +155,7 @@ public class TenantServiceImpl extends AbstractEntityService implements TenantSe |
151 | 155 | apiUsageStateService.deleteApiUsageStateByTenantId(tenantId); |
152 | 156 | resourceService.deleteResourcesByTenantId(tenantId); |
153 | 157 | otaPackageService.deleteOtaPackagesByTenantId(tenantId); |
158 | + rpcService.deleteAllRpcByTenantId(tenantId); | |
154 | 159 | tenantDao.removeById(tenantId, tenantId.getId()); |
155 | 160 | deleteEntityRelations(tenantId, tenantId); |
156 | 161 | } | ... | ... |
... | ... | @@ -46,3 +46,4 @@ CREATE INDEX IF NOT EXISTS idx_attribute_kv_by_key_and_last_update_ts ON attribu |
46 | 46 | |
47 | 47 | CREATE INDEX IF NOT EXISTS idx_audit_log_tenant_id_and_created_time ON audit_log(tenant_id, created_time); |
48 | 48 | |
49 | +CREATE INDEX IF NOT EXISTS idx_rpc_tenant_id_device_id ON rpc(tenant_id, device_id); | ... | ... |
... | ... | @@ -33,7 +33,7 @@ import org.thingsboard.server.common.msg.session.SessionMsgType; |
33 | 33 | type = ComponentType.FILTER, |
34 | 34 | name = "message type switch", |
35 | 35 | configClazz = EmptyNodeConfiguration.class, |
36 | - relationTypes = {"Post attributes", "Post telemetry", "RPC Request from Device", "RPC Request to Device", "RPC Queued", "RPC Sent", "RPC Delivered", "RPC Successful", "RPC Timeout", "RPC Failed", | |
36 | + relationTypes = {"Post attributes", "Post telemetry", "RPC Request from Device", "RPC Request to Device", "RPC Queued", "RPC Delivered", "RPC Successful", "RPC Timeout", "RPC Failed", | |
37 | 37 | "Activity Event", "Inactivity Event", "Connect Event", "Disconnect Event", "Entity Created", "Entity Updated", "Entity Deleted", "Entity Assigned", |
38 | 38 | "Entity Unassigned", "Attributes Updated", "Attributes Deleted", "Alarm Acknowledged", "Alarm Cleared", "Other", "Entity Assigned From Tenant", "Entity Assigned To Tenant", |
39 | 39 | "Timeseries Updated", "Timeseries Deleted"}, |
... | ... | @@ -97,8 +97,6 @@ public class TbMsgTypeSwitchNode implements TbNode { |
97 | 97 | relationType = "Timeseries Deleted"; |
98 | 98 | } else if (msg.getType().equals(DataConstants.RPC_QUEUED)) { |
99 | 99 | relationType = "RPC Queued"; |
100 | - } else if (msg.getType().equals(DataConstants.RPC_SENT)) { | |
101 | - relationType = "RPC Sent"; | |
102 | 100 | } else if (msg.getType().equals(DataConstants.RPC_DELIVERED)) { |
103 | 101 | relationType = "RPC Delivered"; |
104 | 102 | } else if (msg.getType().equals(DataConstants.RPC_SUCCESSFUL)) { | ... | ... |
... | ... | @@ -354,9 +354,8 @@ export enum MessageType { |
354 | 354 | TIMESERIES_UPDATED = 'TIMESERIES_UPDATED', |
355 | 355 | TIMESERIES_DELETED = 'TIMESERIES_DELETED', |
356 | 356 | RPC_QUEUED = 'RPC_QUEUED', |
357 | - RPC_SENT = 'RPC_SENT', | |
358 | - RPC_DELIVERED = 'RPC_SENT', | |
359 | - RPC_SUCCESSFUL = 'RPC_DELIVERED', | |
357 | + RPC_DELIVERED = 'RPC_DELIVERED', | |
358 | + RPC_SUCCESSFUL = 'RPC_SUCCESSFUL', | |
360 | 359 | RPC_TIMEOUT = 'RPC_TIMEOUT', |
361 | 360 | RPC_FAILED = 'RPC_FAILED' |
362 | 361 | } |
... | ... | @@ -381,7 +380,6 @@ export const messageTypeNames = new Map<MessageType, string>( |
381 | 380 | [MessageType.TIMESERIES_UPDATED, 'Timeseries Updated'], |
382 | 381 | [MessageType.TIMESERIES_DELETED, 'Timeseries Deleted'], |
383 | 382 | [MessageType.RPC_QUEUED, 'RPC Queued'], |
384 | - [MessageType.RPC_SENT, 'RPC Sent'], | |
385 | 383 | [MessageType.RPC_DELIVERED, 'RPC Delivered'], |
386 | 384 | [MessageType.RPC_SUCCESSFUL, 'RPC Successful'], |
387 | 385 | [MessageType.RPC_TIMEOUT, 'RPC Timeout'], | ... | ... |