Commit 2d1f84a703e7e37d2cc89e3eeb0939905e234e84

Authored by Igor Kulikov
Committed by GitHub
2 parents e3fdb70b 289d3b93

Merge pull request #5137 from thingsboard/develop/3.3.1

Develop/3.3.1
@@ -15,8 +15,11 @@ @@ -15,8 +15,11 @@
15 */ 15 */
16 package org.thingsboard.server.controller; 16 package org.thingsboard.server.controller;
17 17
  18 +import com.fasterxml.jackson.databind.JsonNode;
18 import com.google.common.util.concurrent.ListenableFuture; 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import lombok.extern.slf4j.Slf4j;
19 import org.springframework.http.HttpStatus; 21 import org.springframework.http.HttpStatus;
  22 +import org.springframework.http.ResponseEntity;
20 import org.springframework.security.access.prepost.PreAuthorize; 23 import org.springframework.security.access.prepost.PreAuthorize;
21 import org.springframework.web.bind.annotation.PathVariable; 24 import org.springframework.web.bind.annotation.PathVariable;
22 import org.springframework.web.bind.annotation.RequestBody; 25 import org.springframework.web.bind.annotation.RequestBody;
@@ -59,6 +62,7 @@ import java.util.stream.Collectors; @@ -59,6 +62,7 @@ import java.util.stream.Collectors;
59 62
60 @RestController 63 @RestController
61 @TbCoreComponent 64 @TbCoreComponent
  65 +@Slf4j
62 @RequestMapping("/api") 66 @RequestMapping("/api")
63 public class EdgeController extends BaseController { 67 public class EdgeController extends BaseController {
64 68
@@ -544,27 +548,6 @@ public class EdgeController extends BaseController { @@ -544,27 +548,6 @@ public class EdgeController extends BaseController {
544 } 548 }
545 } 549 }
546 550
547 - @RequestMapping(value = "/license/checkInstance", method = RequestMethod.POST)  
548 - @ResponseBody  
549 - public Object checkInstance(@RequestBody Object request) throws ThingsboardException {  
550 - try {  
551 - return edgeService.checkInstance(request);  
552 - } catch (Exception e) {  
553 - throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION);  
554 - }  
555 - }  
556 -  
557 - @RequestMapping(value = "/license/activateInstance", params = {"licenseSecret", "releaseDate"}, method = RequestMethod.POST)  
558 - @ResponseBody  
559 - public Object activateInstance(@RequestParam String licenseSecret,  
560 - @RequestParam String releaseDate) throws ThingsboardException {  
561 - try {  
562 - return edgeService.activateInstance(licenseSecret, releaseDate);  
563 - } catch (Exception e) {  
564 - throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION);  
565 - }  
566 - }  
567 -  
568 @PreAuthorize("hasAuthority('TENANT_ADMIN')") 551 @PreAuthorize("hasAuthority('TENANT_ADMIN')")
569 @RequestMapping(value = "/edge/missingToRelatedRuleChains/{edgeId}", method = RequestMethod.GET) 552 @RequestMapping(value = "/edge/missingToRelatedRuleChains/{edgeId}", method = RequestMethod.GET)
570 @ResponseBody 553 @ResponseBody
@@ -583,4 +566,29 @@ public class EdgeController extends BaseController { @@ -583,4 +566,29 @@ public class EdgeController extends BaseController {
583 private void cleanUpLicenseKey(Edge edge) { 566 private void cleanUpLicenseKey(Edge edge) {
584 edge.setEdgeLicenseKey(null); 567 edge.setEdgeLicenseKey(null);
585 } 568 }
  569 +
  570 + @RequestMapping(value = "/license/checkInstance", method = RequestMethod.POST)
  571 + @ResponseBody
  572 + public ResponseEntity<JsonNode> checkInstance(@RequestBody JsonNode request) throws ThingsboardException {
  573 + log.debug("Checking instance [{}]", request);
  574 + try {
  575 + return edgeService.checkInstance(request);
  576 + } catch (Exception e) {
  577 + log.error("Error occurred: [{}]", e.getMessage(), e);
  578 + throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION);
  579 + }
  580 + }
  581 +
  582 + @RequestMapping(value = "/license/activateInstance", params = {"licenseSecret", "releaseDate"}, method = RequestMethod.POST)
  583 + @ResponseBody
  584 + public ResponseEntity<JsonNode> activateInstance(@RequestParam String licenseSecret,
  585 + @RequestParam String releaseDate) throws ThingsboardException {
  586 + log.debug("Activating instance [{}], [{}]", licenseSecret, releaseDate);
  587 + try {
  588 + return edgeService.activateInstance(licenseSecret, releaseDate);
  589 + } catch (Exception e) {
  590 + log.error("Error occurred: [{}]", e.getMessage(), e);
  591 + throw new ThingsboardException(e, ThingsboardErrorCode.SUBSCRIPTION_VIOLATION);
  592 + }
  593 + }
586 } 594 }
@@ -82,6 +82,11 @@ @@ -82,6 +82,11 @@
82 <scope>provided</scope> 82 <scope>provided</scope>
83 </dependency> 83 </dependency>
84 <dependency> 84 <dependency>
  85 + <groupId>org.springframework</groupId>
  86 + <artifactId>spring-web</artifactId>
  87 + <scope>provided</scope>
  88 + </dependency>
  89 + <dependency>
85 <groupId>com.datastax.oss</groupId> 90 <groupId>com.datastax.oss</groupId>
86 <artifactId>java-driver-core</artifactId> 91 <artifactId>java-driver-core</artifactId>
87 <scope>provided</scope> 92 <scope>provided</scope>
@@ -15,16 +15,16 @@ @@ -15,16 +15,16 @@
15 */ 15 */
16 package org.thingsboard.server.dao.edge; 16 package org.thingsboard.server.dao.edge;
17 17
  18 +import com.fasterxml.jackson.databind.JsonNode;
18 import com.google.common.util.concurrent.ListenableFuture; 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import org.springframework.http.ResponseEntity;
19 import org.thingsboard.server.common.data.EntitySubtype; 21 import org.thingsboard.server.common.data.EntitySubtype;
20 import org.thingsboard.server.common.data.edge.Edge; 22 import org.thingsboard.server.common.data.edge.Edge;
21 import org.thingsboard.server.common.data.edge.EdgeInfo; 23 import org.thingsboard.server.common.data.edge.EdgeInfo;
22 import org.thingsboard.server.common.data.edge.EdgeSearchQuery; 24 import org.thingsboard.server.common.data.edge.EdgeSearchQuery;
23 import org.thingsboard.server.common.data.id.CustomerId; 25 import org.thingsboard.server.common.data.id.CustomerId;
24 -import org.thingsboard.server.common.data.id.DashboardId;  
25 import org.thingsboard.server.common.data.id.EdgeId; 26 import org.thingsboard.server.common.data.id.EdgeId;
26 import org.thingsboard.server.common.data.id.EntityId; 27 import org.thingsboard.server.common.data.id.EntityId;
27 -import org.thingsboard.server.common.data.id.RuleChainId;  
28 import org.thingsboard.server.common.data.id.TenantId; 28 import org.thingsboard.server.common.data.id.TenantId;
29 import org.thingsboard.server.common.data.page.PageData; 29 import org.thingsboard.server.common.data.page.PageData;
30 import org.thingsboard.server.common.data.page.PageLink; 30 import org.thingsboard.server.common.data.page.PageLink;
@@ -86,9 +86,9 @@ public interface EdgeService { @@ -86,9 +86,9 @@ public interface EdgeService {
86 86
87 PageData<EdgeId> findRelatedEdgeIdsByEntityId(TenantId tenantId, EntityId entityId, PageLink pageLink); 87 PageData<EdgeId> findRelatedEdgeIdsByEntityId(TenantId tenantId, EntityId entityId, PageLink pageLink);
88 88
89 - Object checkInstance(Object request); 89 + ResponseEntity<JsonNode> checkInstance(JsonNode request);
90 90
91 - Object activateInstance(String licenseSecret, String releaseDate); 91 + ResponseEntity<JsonNode> activateInstance(String licenseSecret, String releaseDate);
92 92
93 String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId); 93 String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId);
94 } 94 }
@@ -92,7 +92,7 @@ public class EdgeGrpcClient implements EdgeRpcClient { @@ -92,7 +92,7 @@ public class EdgeGrpcClient implements EdgeRpcClient {
92 channel = builder.build(); 92 channel = builder.build();
93 EdgeRpcServiceGrpc.EdgeRpcServiceStub stub = EdgeRpcServiceGrpc.newStub(channel); 93 EdgeRpcServiceGrpc.EdgeRpcServiceStub stub = EdgeRpcServiceGrpc.newStub(channel);
94 log.info("[{}] Sending a connect request to the TB!", edgeKey); 94 log.info("[{}] Sending a connect request to the TB!", edgeKey);
95 - this.inputStream = stub.handleMsgs(initOutputStream(edgeKey, onUplinkResponse, onEdgeUpdate, onDownlink, onError)); 95 + this.inputStream = stub.withCompression("gzip").handleMsgs(initOutputStream(edgeKey, onUplinkResponse, onEdgeUpdate, onDownlink, onError));
96 this.inputStream.onNext(RequestMsg.newBuilder() 96 this.inputStream.onNext(RequestMsg.newBuilder()
97 .setMsgType(RequestMsgType.CONNECT_RPC_MESSAGE) 97 .setMsgType(RequestMsgType.CONNECT_RPC_MESSAGE)
98 .setConnectRequestMsg(ConnectRequestMsg.newBuilder().setEdgeRoutingKey(edgeKey).setEdgeSecret(edgeSecret).build()) 98 .setConnectRequestMsg(ConnectRequestMsg.newBuilder().setEdgeRoutingKey(edgeKey).setEdgeSecret(edgeSecret).build())
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.edge; 16 package org.thingsboard.server.dao.edge;
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.ArrayNode; 20 import com.fasterxml.jackson.databind.node.ArrayNode;
20 import com.fasterxml.jackson.databind.node.ObjectNode; 21 import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -34,6 +35,7 @@ import org.springframework.cache.Cache; @@ -34,6 +35,7 @@ import org.springframework.cache.Cache;
34 import org.springframework.cache.CacheManager; 35 import org.springframework.cache.CacheManager;
35 import org.springframework.cache.annotation.CacheEvict; 36 import org.springframework.cache.annotation.CacheEvict;
36 import org.springframework.cache.annotation.Cacheable; 37 import org.springframework.cache.annotation.Cacheable;
  38 +import org.springframework.http.ResponseEntity;
37 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; 39 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
38 import org.springframework.http.client.SimpleClientHttpRequestFactory; 40 import org.springframework.http.client.SimpleClientHttpRequestFactory;
39 import org.springframework.stereotype.Service; 41 import org.springframework.stereotype.Service;
@@ -543,16 +545,16 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic @@ -543,16 +545,16 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
543 } 545 }
544 546
545 @Override 547 @Override
546 - public Object checkInstance(Object request) {  
547 - return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/checkInstance", request, Object.class, new Object[0]); 548 + public ResponseEntity<JsonNode> checkInstance(JsonNode request) {
  549 + return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/checkInstance", request, JsonNode.class);
548 } 550 }
549 551
550 @Override 552 @Override
551 - public Object activateInstance(String edgeLicenseSecret, String releaseDate) { 553 + public ResponseEntity<JsonNode> activateInstance(String edgeLicenseSecret, String releaseDate) {
552 Map<String, String> params = new HashMap<>(); 554 Map<String, String> params = new HashMap<>();
553 params.put("licenseSecret", edgeLicenseSecret); 555 params.put("licenseSecret", edgeLicenseSecret);
554 params.put("releaseDate", releaseDate); 556 params.put("releaseDate", releaseDate);
555 - return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/activateInstance?licenseSecret={licenseSecret}&releaseDate={releaseDate}", (Object) null, Object.class, params); 557 + return this.restTemplate.postForEntity(EDGE_LICENSE_SERVER_ENDPOINT + "/api/license/activateInstance?licenseSecret={licenseSecret}&releaseDate={releaseDate}", null, JsonNode.class, params);
556 } 558 }
557 559
558 @Override 560 @Override
@@ -29,14 +29,14 @@ @@ -29,14 +29,14 @@
29 <tb-time-unit-select [labelText]="'device-profile.edrx-cycle'" 29 <tb-time-unit-select [labelText]="'device-profile.edrx-cycle'"
30 [requiredText]="'device-profile.edrx-cycle-required'" 30 [requiredText]="'device-profile.edrx-cycle-required'"
31 [patternText]="'device-profile.edrx-cycle-pattern'" 31 [patternText]="'device-profile.edrx-cycle-pattern'"
32 - [minTime]="20480" 32 + [minTime]="5120"
33 [minText]="'device-profile.edrx-cycle-min'" 33 [minText]="'device-profile.edrx-cycle-min'"
34 formControlName="edrxCycle"> 34 formControlName="edrxCycle">
35 </tb-time-unit-select> 35 </tb-time-unit-select>
36 <tb-time-unit-select [labelText]="'device-profile.paging-transmission-window'" 36 <tb-time-unit-select [labelText]="'device-profile.paging-transmission-window'"
37 [requiredText]="'device-profile.paging-transmission-window-required'" 37 [requiredText]="'device-profile.paging-transmission-window-required'"
38 [patternText]="'device-profile.paging-transmission-window-pattern'" 38 [patternText]="'device-profile.paging-transmission-window-pattern'"
39 - [minTime]="2000" 39 + [minTime]="1280"
40 [minText]="'device-profile.paging-transmission-window-min'" 40 [minText]="'device-profile.paging-transmission-window-min'"
41 formControlName="pagingTransmissionWindow"> 41 formControlName="pagingTransmissionWindow">
42 </tb-time-unit-select> 42 </tb-time-unit-select>
@@ -45,7 +45,7 @@ @@ -45,7 +45,7 @@
45 [labelText]="'device-profile.psm-activity-timer'" 45 [labelText]="'device-profile.psm-activity-timer'"
46 [requiredText]="'device-profile.psm-activity-timer-required'" 46 [requiredText]="'device-profile.psm-activity-timer-required'"
47 [patternText]="'device-profile.psm-activity-timer-pattern'" 47 [patternText]="'device-profile.psm-activity-timer-pattern'"
48 - [minTime]="2000" 48 + [minTime]="1280"
49 [minText]="'device-profile.psm-activity-timer-min'" 49 [minText]="'device-profile.psm-activity-timer-min'"
50 formControlName="psmActivityTimer"> 50 formControlName="psmActivityTimer">
51 </tb-time-unit-select> 51 </tb-time-unit-select>