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