Commit aabaada1980b95e0592fa9ffd809f1ac64314284

Authored by Volodymyr Babak
1 parent 966f149c

Added edges enabled endpoint. Refactored yml edges config

@@ -291,9 +291,9 @@ public class ActorSystemContext { @@ -291,9 +291,9 @@ public class ActorSystemContext {
291 @Getter 291 @Getter
292 private long statisticsPersistFrequency; 292 private long statisticsPersistFrequency;
293 293
294 - @Value("${edges.rpc.enabled}") 294 + @Value("${edges.enabled}")
295 @Getter 295 @Getter
296 - private boolean edgesRpcEnabled; 296 + private boolean edgesEnabled;
297 297
298 @Scheduled(fixedDelayString = "${actors.statistics.js_print_interval_ms}") 298 @Scheduled(fixedDelayString = "${actors.statistics.js_print_interval_ms}")
299 public void printStats() { 299 public void printStats() {
@@ -130,7 +130,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { @@ -130,7 +130,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
130 this.defaultMetaData = new TbMsgMetaData(); 130 this.defaultMetaData = new TbMsgMetaData();
131 this.defaultMetaData.putValue("deviceName", deviceName); 131 this.defaultMetaData.putValue("deviceName", deviceName);
132 this.defaultMetaData.putValue("deviceType", deviceType); 132 this.defaultMetaData.putValue("deviceType", deviceType);
133 - if (systemContext.isEdgesRpcEnabled()) { 133 + if (systemContext.isEdgesEnabled()) {
134 this.edgeId = findRelatedEdgeId(); 134 this.edgeId = findRelatedEdgeId();
135 } 135 }
136 return true; 136 return true;
@@ -169,7 +169,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { @@ -169,7 +169,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
169 } 169 }
170 170
171 boolean sent; 171 boolean sent;
172 - if (systemContext.isEdgesRpcEnabled() && edgeId != null) { 172 + if (systemContext.isEdgesEnabled() && edgeId != null) {
173 log.debug("[{}][{}] device is related to edge [{}]. Saving RPC request to edge queue", tenantId, deviceId, edgeId.getId()); 173 log.debug("[{}][{}] device is related to edge [{}]. Saving RPC request to edge queue", tenantId, deviceId, edgeId.getId());
174 saveRpcRequestToEdgeQueue(request, rpcRequest.getRequestId()); 174 saveRpcRequestToEdgeQueue(request, rpcRequest.getRequestId());
175 sent = true; 175 sent = true;
@@ -221,9 +221,9 @@ public abstract class BaseController { @@ -221,9 +221,9 @@ public abstract class BaseController {
221 @Getter 221 @Getter
222 private boolean logControllerErrorStackTrace; 222 private boolean logControllerErrorStackTrace;
223 223
224 - @Value("${edges.rpc.enabled}") 224 + @Value("${edges.enabled}")
225 @Getter 225 @Getter
226 - private boolean edgesRpcEnabled; 226 + protected boolean edgesEnabled;
227 227
228 @ExceptionHandler(ThingsboardException.class) 228 @ExceptionHandler(ThingsboardException.class)
229 public void handleThingsboardException(ThingsboardException ex, HttpServletResponse response) { 229 public void handleThingsboardException(ThingsboardException ex, HttpServletResponse response) {
@@ -761,7 +761,7 @@ public abstract class BaseController { @@ -761,7 +761,7 @@ public abstract class BaseController {
761 } 761 }
762 762
763 protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, CustomerId customerId, EdgeEventActionType action) { 763 protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, CustomerId customerId, EdgeEventActionType action) {
764 - if (!edgesRpcEnabled) { 764 + if (!edgesEnabled) {
765 return; 765 return;
766 } 766 }
767 try { 767 try {
@@ -772,7 +772,7 @@ public abstract class BaseController { @@ -772,7 +772,7 @@ public abstract class BaseController {
772 } 772 }
773 773
774 protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, CustomerId customerId, EdgeEventActionType action) { 774 protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, CustomerId customerId, EdgeEventActionType action) {
775 - if (!edgesRpcEnabled) { 775 + if (!edgesEnabled) {
776 return; 776 return;
777 } 777 }
778 EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType()); 778 EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType());
@@ -786,7 +786,7 @@ public abstract class BaseController { @@ -786,7 +786,7 @@ public abstract class BaseController {
786 } 786 }
787 787
788 protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityRelation relation, EdgeEventActionType action) { 788 protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityRelation relation, EdgeEventActionType action) {
789 - if (!edgesRpcEnabled) { 789 + if (!edgesEnabled) {
790 return; 790 return;
791 } 791 }
792 try { 792 try {
@@ -804,7 +804,7 @@ public abstract class BaseController { @@ -804,7 +804,7 @@ public abstract class BaseController {
804 } 804 }
805 805
806 protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EntityType entityType, EdgeEventActionType action) { 806 protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EntityType entityType, EdgeEventActionType action) {
807 - if (!edgesRpcEnabled) { 807 + if (!edgesEnabled) {
808 return; 808 return;
809 } 809 }
810 EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityType); 810 EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityType);
@@ -63,6 +63,13 @@ public class EdgeController extends BaseController { @@ -63,6 +63,13 @@ public class EdgeController extends BaseController {
63 63
64 public static final String EDGE_ID = "edgeId"; 64 public static final String EDGE_ID = "edgeId";
65 65
  66 + @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
  67 + @RequestMapping(value = "/edges/enabled", method = RequestMethod.GET)
  68 + @ResponseBody
  69 + public boolean isEdgesSupportEnabled() {
  70 + return edgesEnabled;
  71 + }
  72 +
66 @PreAuthorize("hasAuthority('TENANT_ADMIN')") 73 @PreAuthorize("hasAuthority('TENANT_ADMIN')")
67 @RequestMapping(value = "/edge/{edgeId}", method = RequestMethod.GET) 74 @RequestMapping(value = "/edge/{edgeId}", method = RequestMethod.GET)
68 @ResponseBody 75 @ResponseBody
@@ -416,7 +423,7 @@ public class EdgeController extends BaseController { @@ -416,7 +423,7 @@ public class EdgeController extends BaseController {
416 public void syncEdge(@RequestBody EdgeId edgeId) throws ThingsboardException { 423 public void syncEdge(@RequestBody EdgeId edgeId) throws ThingsboardException {
417 try { 424 try {
418 edgeId = checkNotNull(edgeId); 425 edgeId = checkNotNull(edgeId);
419 - if (isEdgesRpcEnabled()) { 426 + if (isEdgesEnabled()) {
420 EdgeGrpcSession session = edgeGrpcService.getEdgeGrpcSessionById(edgeId); 427 EdgeGrpcSession session = edgeGrpcService.getEdgeGrpcSessionById(edgeId);
421 Edge edge = session.getEdge(); 428 Edge edge = session.getEdge();
422 syncEdgeService.sync(edge); 429 syncEdgeService.sync(edge);
@@ -23,10 +23,10 @@ import org.springframework.stereotype.Component; @@ -23,10 +23,10 @@ import org.springframework.stereotype.Component;
23 @Component 23 @Component
24 @Data 24 @Data
25 public class EdgeEventStorageSettings { 25 public class EdgeEventStorageSettings {
26 - @Value("${edges.rpc.storage.max_read_records_count}") 26 + @Value("${edges.storage.max_read_records_count}")
27 private int maxReadRecordsCount; 27 private int maxReadRecordsCount;
28 - @Value("${edges.rpc.storage.no_read_records_sleep}") 28 + @Value("${edges.storage.no_read_records_sleep}")
29 private long noRecordsSleepInterval; 29 private long noRecordsSleepInterval;
30 - @Value("${edges.rpc.storage.sleep_between_batches}") 30 + @Value("${edges.storage.sleep_between_batches}")
31 private long sleepIntervalBetweenBatches; 31 private long sleepIntervalBetweenBatches;
32 } 32 }
@@ -59,7 +59,7 @@ import java.util.concurrent.TimeUnit; @@ -59,7 +59,7 @@ import java.util.concurrent.TimeUnit;
59 59
60 @Service 60 @Service
61 @Slf4j 61 @Slf4j
62 -@ConditionalOnProperty(prefix = "edges.rpc", value = "enabled", havingValue = "true") 62 +@ConditionalOnProperty(prefix = "edges", value = "enabled", havingValue = "true")
63 @TbCoreComponent 63 @TbCoreComponent
64 public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase implements EdgeRpcService { 64 public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase implements EdgeRpcService {
65 65
@@ -589,8 +589,8 @@ transport: @@ -589,8 +589,8 @@ transport:
589 589
590 # Edges parameters 590 # Edges parameters
591 edges: 591 edges:
  592 + enabled: "${EDGES_ENABLED:false}"
592 rpc: 593 rpc:
593 - enabled: "${EDGES_RPC_ENABLED:false}"  
594 port: "${EDGES_RPC_PORT:7070}" 594 port: "${EDGES_RPC_PORT:7070}"
595 client_max_keep_alive_time_sec: "${EDGES_RPC_CLIENT_MAX_KEEP_ALIVE_TIME_SEC:300}" 595 client_max_keep_alive_time_sec: "${EDGES_RPC_CLIENT_MAX_KEEP_ALIVE_TIME_SEC:300}"
596 ssl: 596 ssl:
@@ -598,10 +598,10 @@ edges: @@ -598,10 +598,10 @@ edges:
598 enabled: "${EDGES_RPC_SSL_ENABLED:false}" 598 enabled: "${EDGES_RPC_SSL_ENABLED:false}"
599 cert: "${EDGES_RPC_SSL_CERT:certChainFile.pem}" 599 cert: "${EDGES_RPC_SSL_CERT:certChainFile.pem}"
600 private_key: "${EDGES_RPC_SSL_PRIVATE_KEY:privateKeyFile.pem}" 600 private_key: "${EDGES_RPC_SSL_PRIVATE_KEY:privateKeyFile.pem}"
601 - storage:  
602 - max_read_records_count: "${EDGES_RPC_STORAGE_MAX_READ_RECORDS_COUNT:50}"  
603 - no_read_records_sleep: "${EDGES_RPC_NO_READ_RECORDS_SLEEP:1000}"  
604 - sleep_between_batches: "${EDGES_RPC_SLEEP_BETWEEN_BATCHES:1000}" 601 + storage:
  602 + max_read_records_count: "${EDGES_STORAGE_MAX_READ_RECORDS_COUNT:50}"
  603 + no_read_records_sleep: "${EDGES_NO_READ_RECORDS_SLEEP:1000}"
  604 + sleep_between_batches: "${EDGES_SLEEP_BETWEEN_BATCHES:1000}"
605 scheduler_pool_size: "${EDGES_SCHEDULER_POOL_SIZE:4}" 605 scheduler_pool_size: "${EDGES_SCHEDULER_POOL_SIZE:4}"
606 edge_events_ttl: "${EDGES_EDGE_EVENTS_TTL:0}" 606 edge_events_ttl: "${EDGES_EDGE_EVENTS_TTL:0}"
607 state: 607 state:
@@ -127,13 +127,13 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic @@ -127,13 +127,13 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
127 @Autowired 127 @Autowired
128 private RelationService relationService; 128 private RelationService relationService;
129 129
130 - @Value("${edges.rpc.enabled:false}")  
131 - private boolean edgesRpcEnabled; 130 + @Value("${edges.enabled:false}")
  131 + private boolean edgesEnabled;
132 132
133 @PostConstruct 133 @PostConstruct
134 public void init() { 134 public void init() {
135 super.init(); 135 super.init();
136 - if (edgesRpcEnabled) { 136 + if (edgesEnabled) {
137 initRestTemplate(); 137 initRestTemplate();
138 } 138 }
139 } 139 }