Browse Source

Added edges enabled endpoint. Refactored yml edges config

pull/3693/head
Volodymyr Babak 6 years ago
parent
commit
aabaada198
  1. 4
      application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java
  2. 4
      application/src/main/java/org/thingsboard/server/actors/device/DeviceActorMessageProcessor.java
  3. 12
      application/src/main/java/org/thingsboard/server/controller/BaseController.java
  4. 9
      application/src/main/java/org/thingsboard/server/controller/EdgeController.java
  5. 6
      application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeEventStorageSettings.java
  6. 2
      application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcService.java
  7. 10
      application/src/main/resources/thingsboard.yml
  8. 6
      dao/src/main/java/org/thingsboard/server/dao/edge/EdgeServiceImpl.java

4
application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java

@ -291,9 +291,9 @@ public class ActorSystemContext {
@Getter @Getter
private long statisticsPersistFrequency; private long statisticsPersistFrequency;
@Value("${edges.rpc.enabled}") @Value("${edges.enabled}")
@Getter @Getter
private boolean edgesRpcEnabled; private boolean edgesEnabled;
@Scheduled(fixedDelayString = "${actors.statistics.js_print_interval_ms}") @Scheduled(fixedDelayString = "${actors.statistics.js_print_interval_ms}")
public void printStats() { public void printStats() {

4
application/src/main/java/org/thingsboard/server/actors/device/DeviceActorMessageProcessor.java

@ -130,7 +130,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
this.defaultMetaData = new TbMsgMetaData(); this.defaultMetaData = new TbMsgMetaData();
this.defaultMetaData.putValue("deviceName", deviceName); this.defaultMetaData.putValue("deviceName", deviceName);
this.defaultMetaData.putValue("deviceType", deviceType); this.defaultMetaData.putValue("deviceType", deviceType);
if (systemContext.isEdgesRpcEnabled()) { if (systemContext.isEdgesEnabled()) {
this.edgeId = findRelatedEdgeId(); this.edgeId = findRelatedEdgeId();
} }
return true; return true;
@ -169,7 +169,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
} }
boolean sent; boolean sent;
if (systemContext.isEdgesRpcEnabled() && edgeId != null) { if (systemContext.isEdgesEnabled() && edgeId != null) {
log.debug("[{}][{}] device is related to edge [{}]. Saving RPC request to edge queue", tenantId, deviceId, edgeId.getId()); log.debug("[{}][{}] device is related to edge [{}]. Saving RPC request to edge queue", tenantId, deviceId, edgeId.getId());
saveRpcRequestToEdgeQueue(request, rpcRequest.getRequestId()); saveRpcRequestToEdgeQueue(request, rpcRequest.getRequestId());
sent = true; sent = true;

12
application/src/main/java/org/thingsboard/server/controller/BaseController.java

@ -221,9 +221,9 @@ public abstract class BaseController {
@Getter @Getter
private boolean logControllerErrorStackTrace; private boolean logControllerErrorStackTrace;
@Value("${edges.rpc.enabled}") @Value("${edges.enabled}")
@Getter @Getter
private boolean edgesRpcEnabled; protected boolean edgesEnabled;
@ExceptionHandler(ThingsboardException.class) @ExceptionHandler(ThingsboardException.class)
public void handleThingsboardException(ThingsboardException ex, HttpServletResponse response) { public void handleThingsboardException(ThingsboardException ex, HttpServletResponse response) {
@ -761,7 +761,7 @@ public abstract class BaseController {
} }
protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, CustomerId customerId, EdgeEventActionType action) { protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, CustomerId customerId, EdgeEventActionType action) {
if (!edgesRpcEnabled) { if (!edgesEnabled) {
return; return;
} }
try { try {
@ -772,7 +772,7 @@ public abstract class BaseController {
} }
protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, CustomerId customerId, EdgeEventActionType action) { protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, CustomerId customerId, EdgeEventActionType action) {
if (!edgesRpcEnabled) { if (!edgesEnabled) {
return; return;
} }
EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType()); EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType());
@ -786,7 +786,7 @@ public abstract class BaseController {
} }
protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityRelation relation, EdgeEventActionType action) { protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityRelation relation, EdgeEventActionType action) {
if (!edgesRpcEnabled) { if (!edgesEnabled) {
return; return;
} }
try { try {
@ -804,7 +804,7 @@ public abstract class BaseController {
} }
protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EntityType entityType, EdgeEventActionType action) { protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EntityType entityType, EdgeEventActionType action) {
if (!edgesRpcEnabled) { if (!edgesEnabled) {
return; return;
} }
EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityType); EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityType);

9
application/src/main/java/org/thingsboard/server/controller/EdgeController.java

@ -63,6 +63,13 @@ public class EdgeController extends BaseController {
public static final String EDGE_ID = "edgeId"; public static final String EDGE_ID = "edgeId";
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/edges/enabled", method = RequestMethod.GET)
@ResponseBody
public boolean isEdgesSupportEnabled() {
return edgesEnabled;
}
@PreAuthorize("hasAuthority('TENANT_ADMIN')") @PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/edge/{edgeId}", method = RequestMethod.GET) @RequestMapping(value = "/edge/{edgeId}", method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ -416,7 +423,7 @@ public class EdgeController extends BaseController {
public void syncEdge(@RequestBody EdgeId edgeId) throws ThingsboardException { public void syncEdge(@RequestBody EdgeId edgeId) throws ThingsboardException {
try { try {
edgeId = checkNotNull(edgeId); edgeId = checkNotNull(edgeId);
if (isEdgesRpcEnabled()) { if (isEdgesEnabled()) {
EdgeGrpcSession session = edgeGrpcService.getEdgeGrpcSessionById(edgeId); EdgeGrpcSession session = edgeGrpcService.getEdgeGrpcSessionById(edgeId);
Edge edge = session.getEdge(); Edge edge = session.getEdge();
syncEdgeService.sync(edge); syncEdgeService.sync(edge);

6
application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeEventStorageSettings.java

@ -23,10 +23,10 @@ import org.springframework.stereotype.Component;
@Component @Component
@Data @Data
public class EdgeEventStorageSettings { public class EdgeEventStorageSettings {
@Value("${edges.rpc.storage.max_read_records_count}") @Value("${edges.storage.max_read_records_count}")
private int maxReadRecordsCount; private int maxReadRecordsCount;
@Value("${edges.rpc.storage.no_read_records_sleep}") @Value("${edges.storage.no_read_records_sleep}")
private long noRecordsSleepInterval; private long noRecordsSleepInterval;
@Value("${edges.rpc.storage.sleep_between_batches}") @Value("${edges.storage.sleep_between_batches}")
private long sleepIntervalBetweenBatches; private long sleepIntervalBetweenBatches;
} }

2
application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcService.java

@ -59,7 +59,7 @@ import java.util.concurrent.TimeUnit;
@Service @Service
@Slf4j @Slf4j
@ConditionalOnProperty(prefix = "edges.rpc", value = "enabled", havingValue = "true") @ConditionalOnProperty(prefix = "edges", value = "enabled", havingValue = "true")
@TbCoreComponent @TbCoreComponent
public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase implements EdgeRpcService { public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase implements EdgeRpcService {

10
application/src/main/resources/thingsboard.yml

@ -589,8 +589,8 @@ transport:
# Edges parameters # Edges parameters
edges: edges:
enabled: "${EDGES_ENABLED:false}"
rpc: rpc:
enabled: "${EDGES_RPC_ENABLED:false}"
port: "${EDGES_RPC_PORT:7070}" port: "${EDGES_RPC_PORT:7070}"
client_max_keep_alive_time_sec: "${EDGES_RPC_CLIENT_MAX_KEEP_ALIVE_TIME_SEC:300}" client_max_keep_alive_time_sec: "${EDGES_RPC_CLIENT_MAX_KEEP_ALIVE_TIME_SEC:300}"
ssl: ssl:
@ -598,10 +598,10 @@ edges:
enabled: "${EDGES_RPC_SSL_ENABLED:false}" enabled: "${EDGES_RPC_SSL_ENABLED:false}"
cert: "${EDGES_RPC_SSL_CERT:certChainFile.pem}" cert: "${EDGES_RPC_SSL_CERT:certChainFile.pem}"
private_key: "${EDGES_RPC_SSL_PRIVATE_KEY:privateKeyFile.pem}" private_key: "${EDGES_RPC_SSL_PRIVATE_KEY:privateKeyFile.pem}"
storage: storage:
max_read_records_count: "${EDGES_RPC_STORAGE_MAX_READ_RECORDS_COUNT:50}" max_read_records_count: "${EDGES_STORAGE_MAX_READ_RECORDS_COUNT:50}"
no_read_records_sleep: "${EDGES_RPC_NO_READ_RECORDS_SLEEP:1000}" no_read_records_sleep: "${EDGES_NO_READ_RECORDS_SLEEP:1000}"
sleep_between_batches: "${EDGES_RPC_SLEEP_BETWEEN_BATCHES:1000}" sleep_between_batches: "${EDGES_SLEEP_BETWEEN_BATCHES:1000}"
scheduler_pool_size: "${EDGES_SCHEDULER_POOL_SIZE:4}" scheduler_pool_size: "${EDGES_SCHEDULER_POOL_SIZE:4}"
edge_events_ttl: "${EDGES_EDGE_EVENTS_TTL:0}" edge_events_ttl: "${EDGES_EDGE_EVENTS_TTL:0}"
state: state:

6
dao/src/main/java/org/thingsboard/server/dao/edge/EdgeServiceImpl.java

@ -127,13 +127,13 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
@Autowired @Autowired
private RelationService relationService; private RelationService relationService;
@Value("${edges.rpc.enabled:false}") @Value("${edges.enabled:false}")
private boolean edgesRpcEnabled; private boolean edgesEnabled;
@PostConstruct @PostConstruct
public void init() { public void init() {
super.init(); super.init();
if (edgesRpcEnabled) { if (edgesEnabled) {
initRestTemplate(); initRestTemplate();
} }
} }

Loading…
Cancel
Save