Merge pull request #11139 from AndriiLandiak/feature/edge-proxy-rpc
[Edge] Proxy for grpc client
This commit is contained in:
commit
f5a85cafe8
@ -270,14 +270,16 @@ public class TenantActor extends RuleChainManagerActor {
|
||||
initRuleChains();
|
||||
}
|
||||
}
|
||||
if (msg.getEntityId().getEntityType() == EntityType.EDGE) {
|
||||
if (msg.getEntityId().getEntityType() == EntityType.EDGE && isCore) {
|
||||
EdgeId edgeId = new EdgeId(msg.getEntityId().getId());
|
||||
EdgeRpcService edgeRpcService = systemContext.getEdgeRpcService();
|
||||
if (msg.getEvent() == ComponentLifecycleEvent.DELETED) {
|
||||
edgeRpcService.deleteEdge(tenantId, edgeId);
|
||||
} else if (msg.getEvent() == ComponentLifecycleEvent.UPDATED) {
|
||||
Edge edge = systemContext.getEdgeService().findEdgeById(tenantId, edgeId);
|
||||
edgeRpcService.updateEdge(tenantId, edge);
|
||||
if (edgeRpcService != null) {
|
||||
if (msg.getEvent() == ComponentLifecycleEvent.DELETED) {
|
||||
edgeRpcService.deleteEdge(tenantId, edgeId);
|
||||
} else if (msg.getEvent() == ComponentLifecycleEvent.UPDATED) {
|
||||
Edge edge = systemContext.getEdgeService().findEdgeById(tenantId, edgeId);
|
||||
edgeRpcService.updateEdge(tenantId, edge);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (msg.getEntityId().getEntityType() == EntityType.DEVICE && ComponentLifecycleEvent.DELETED == msg.getEvent() && isMyPartition(msg.getEntityId())) {
|
||||
|
||||
@ -18,24 +18,20 @@ package org.thingsboard.server.controller;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
import org.thingsboard.rule.engine.flow.TbRuleChainInputNode;
|
||||
@ -114,8 +110,7 @@ public class EdgeController extends BaseController {
|
||||
@ApiOperation(value = "Is edges support enabled (isEdgesSupportEnabled)",
|
||||
notes = "Returns 'true' if edges support enabled on server, 'false' - otherwise.")
|
||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@RequestMapping(value = "/edges/enabled", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/edges/enabled")
|
||||
public boolean isEdgesSupportEnabled() {
|
||||
return edgesEnabled;
|
||||
}
|
||||
@ -123,8 +118,7 @@ public class EdgeController extends BaseController {
|
||||
@ApiOperation(value = "Get Edge (getEdgeById)",
|
||||
notes = "Get the Edge object based on the provided Edge Id. " + EDGE_SECURITY_CHECK + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@RequestMapping(value = "/edge/{edgeId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/edge/{edgeId}")
|
||||
public Edge getEdgeById(@Parameter(description = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||
@PathVariable(EDGE_ID) String strEdgeId) throws ThingsboardException {
|
||||
checkParameter(EDGE_ID, strEdgeId);
|
||||
@ -135,8 +129,7 @@ public class EdgeController extends BaseController {
|
||||
@ApiOperation(value = "Get Edge Info (getEdgeInfoById)",
|
||||
notes = "Get the Edge Info object based on the provided Edge Id. " + EDGE_SECURITY_CHECK + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@RequestMapping(value = "/edge/info/{edgeId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/edge/info/{edgeId}")
|
||||
public EdgeInfo getEdgeInfoById(@Parameter(description = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||
@PathVariable(EDGE_ID) String strEdgeId) throws ThingsboardException {
|
||||
checkParameter(EDGE_ID, strEdgeId);
|
||||
@ -153,8 +146,7 @@ public class EdgeController extends BaseController {
|
||||
"Remove 'id', 'tenantId' and optionally 'customerId' from the request body example (below) to create new Edge entity. " +
|
||||
TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/edge", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/edge")
|
||||
public Edge saveEdge(@Parameter(description = "A JSON value representing the edge.", required = true)
|
||||
@RequestBody Edge edge) throws Exception {
|
||||
TenantId tenantId = getTenantId();
|
||||
@ -179,8 +171,7 @@ public class EdgeController extends BaseController {
|
||||
@ApiOperation(value = "Delete edge (deleteEdge)",
|
||||
notes = "Deletes the edge. Referencing non-existing edge Id will cause an error." + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/edge/{edgeId}", method = RequestMethod.DELETE)
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@DeleteMapping(value = "/edge/{edgeId}")
|
||||
public void deleteEdge(@Parameter(description = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||
@PathVariable(EDGE_ID) String strEdgeId) throws ThingsboardException {
|
||||
checkParameter(EDGE_ID, strEdgeId);
|
||||
@ -193,8 +184,7 @@ public class EdgeController extends BaseController {
|
||||
notes = "Returns a page of edges owned by tenant. " +
|
||||
PAGE_DATA_PARAMETERS + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/edges", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/edges", params = {"pageSize", "page"})
|
||||
public PageData<Edge> getEdges(@Parameter(description = PAGE_SIZE_DESCRIPTION, required = true)
|
||||
@RequestParam int pageSize,
|
||||
@Parameter(description = PAGE_NUMBER_DESCRIPTION, required = true)
|
||||
@ -213,8 +203,7 @@ public class EdgeController extends BaseController {
|
||||
@ApiOperation(value = "Assign edge to customer (assignEdgeToCustomer)",
|
||||
notes = "Creates assignment of the edge to customer. Customer will be able to query edge afterwards." + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/customer/{customerId}/edge/{edgeId}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/customer/{customerId}/edge/{edgeId}")
|
||||
public Edge assignEdgeToCustomer(@Parameter(description = CUSTOMER_ID_PARAM_DESCRIPTION, required = true)
|
||||
@PathVariable("customerId") String strCustomerId,
|
||||
@Parameter(description = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||
@ -231,8 +220,7 @@ public class EdgeController extends BaseController {
|
||||
@ApiOperation(value = "Unassign edge from customer (unassignEdgeFromCustomer)",
|
||||
notes = "Clears assignment of the edge to customer. Customer will not be able to query edge afterwards." + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/customer/edge/{edgeId}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
@DeleteMapping(value = "/customer/edge/{edgeId}")
|
||||
public Edge unassignEdgeFromCustomer(@Parameter(description = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||
@PathVariable(EDGE_ID) String strEdgeId) throws ThingsboardException {
|
||||
checkParameter(EDGE_ID, strEdgeId);
|
||||
@ -251,8 +239,7 @@ public class EdgeController extends BaseController {
|
||||
"This is useful to create dashboards that you plan to share/embed on a publicly available website. " +
|
||||
"However, users that are logged-in and belong to different tenant will not be able to access the edge." + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/customer/public/edge/{edgeId}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/customer/public/edge/{edgeId}")
|
||||
public Edge assignEdgeToPublicCustomer(@Parameter(description = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||
@PathVariable(EDGE_ID) String strEdgeId) throws ThingsboardException {
|
||||
checkParameter(EDGE_ID, strEdgeId);
|
||||
@ -265,8 +252,7 @@ public class EdgeController extends BaseController {
|
||||
notes = "Returns a page of edges owned by tenant. " +
|
||||
PAGE_DATA_PARAMETERS + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/tenant/edges", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/tenant/edges", params = {"pageSize", "page"})
|
||||
public PageData<Edge> getTenantEdges(
|
||||
@Parameter(description = PAGE_SIZE_DESCRIPTION, required = true)
|
||||
@RequestParam int pageSize,
|
||||
@ -293,8 +279,7 @@ public class EdgeController extends BaseController {
|
||||
notes = "Returns a page of edges info objects owned by tenant. " +
|
||||
PAGE_DATA_PARAMETERS + EDGE_INFO_DESCRIPTION + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/tenant/edgeInfos", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/tenant/edgeInfos", params = {"pageSize", "page"})
|
||||
public PageData<EdgeInfo> getTenantEdgeInfos(
|
||||
@Parameter(description = PAGE_SIZE_DESCRIPTION, required = true)
|
||||
@RequestParam int pageSize,
|
||||
@ -321,8 +306,7 @@ public class EdgeController extends BaseController {
|
||||
notes = "Requested edge must be owned by tenant or customer that the user belongs to. " +
|
||||
"Edge name is an unique property of edge. So it can be used to identify the edge." + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/tenant/edges", params = {"edgeName"}, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/tenant/edges", params = {"edgeName"})
|
||||
public Edge getTenantEdge(@Parameter(description = "Unique name of the edge", required = true)
|
||||
@RequestParam String edgeName) throws ThingsboardException {
|
||||
TenantId tenantId = getCurrentUser().getTenantId();
|
||||
@ -333,8 +317,7 @@ public class EdgeController extends BaseController {
|
||||
notes = "Change root rule chain of the edge to the new provided rule chain. \n" +
|
||||
"This operation will send a notification to update root rule chain on remote edge service." + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/edge/{edgeId}/{ruleChainId}/root", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/edge/{edgeId}/{ruleChainId}/root")
|
||||
public Edge setEdgeRootRuleChain(@Parameter(description = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||
@PathVariable(EDGE_ID) String strEdgeId,
|
||||
@Parameter(description = RULE_CHAIN_ID_PARAM_DESCRIPTION, required = true)
|
||||
@ -353,8 +336,7 @@ public class EdgeController extends BaseController {
|
||||
notes = "Returns a page of edges objects assigned to customer. " +
|
||||
PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@RequestMapping(value = "/customer/{customerId}/edges", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/customer/{customerId}/edges", params = {"pageSize", "page"})
|
||||
public PageData<Edge> getCustomerEdges(
|
||||
@Parameter(description = CUSTOMER_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable("customerId") String strCustomerId,
|
||||
@ -389,8 +371,7 @@ public class EdgeController extends BaseController {
|
||||
notes = "Returns a page of edges info objects assigned to customer. " +
|
||||
PAGE_DATA_PARAMETERS + EDGE_INFO_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@RequestMapping(value = "/customer/{customerId}/edgeInfos", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/customer/{customerId}/edgeInfos", params = {"pageSize", "page"})
|
||||
public PageData<EdgeInfo> getCustomerEdgeInfos(
|
||||
@Parameter(description = CUSTOMER_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable("customerId") String strCustomerId,
|
||||
@ -424,8 +405,7 @@ public class EdgeController extends BaseController {
|
||||
@ApiOperation(value = "Get Edges By Ids (getEdgesByIds)",
|
||||
notes = "Requested edges must be owned by tenant or assigned to customer which user is performing the request." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@RequestMapping(value = "/edges", params = {"edgeIds"}, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/edges", params = {"edgeIds"})
|
||||
public List<Edge> getEdgesByIds(
|
||||
@Parameter(description = "A list of edges ids, separated by comma ','", array = @ArraySchema(schema = @Schema(type = "string")), required = true)
|
||||
@RequestParam("edgeIds") String[] strEdgeIds) throws ThingsboardException, ExecutionException, InterruptedException {
|
||||
@ -452,8 +432,7 @@ public class EdgeController extends BaseController {
|
||||
"The entity id, relation type, edge types, depth of the search, and other query parameters defined using complex 'EdgeSearchQuery' object. " +
|
||||
"See 'Model' tab of the Parameters for more info." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@RequestMapping(value = "/edges", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/edges")
|
||||
public List<Edge> findByQuery(@RequestBody EdgeSearchQuery query) throws ThingsboardException, ExecutionException, InterruptedException {
|
||||
checkNotNull(query);
|
||||
checkNotNull(query.getParameters());
|
||||
@ -477,8 +456,7 @@ public class EdgeController extends BaseController {
|
||||
notes = "Returns a set of unique edge types based on edges that are either owned by the tenant or assigned to the customer which user is performing the request."
|
||||
+ TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@RequestMapping(value = "/edge/types", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/edge/types")
|
||||
public List<EntitySubtype> getEdgeTypes() throws ThingsboardException, ExecutionException, InterruptedException {
|
||||
SecurityUser user = getCurrentUser();
|
||||
TenantId tenantId = user.getTenantId();
|
||||
@ -490,7 +468,7 @@ public class EdgeController extends BaseController {
|
||||
notes = "Starts synchronization process between edge and cloud. \n" +
|
||||
"All entities that are assigned to particular edge are going to be send to remote edge service." + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/edge/sync/{edgeId}", method = RequestMethod.POST)
|
||||
@PostMapping(value = "/edge/sync/{edgeId}")
|
||||
public DeferredResult<ResponseEntity> syncEdge(@Parameter(description = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||
@PathVariable("edgeId") String strEdgeId) throws ThingsboardException {
|
||||
checkParameter("edgeId", strEdgeId);
|
||||
@ -519,8 +497,7 @@ public class EdgeController extends BaseController {
|
||||
@ApiOperation(value = "Find missing rule chains (findMissingToRelatedRuleChains)",
|
||||
notes = "Returns list of rule chains ids that are not assigned to particular edge, but these rule chains are present in the already assigned rule chains to edge." + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/edge/missingToRelatedRuleChains/{edgeId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/edge/missingToRelatedRuleChains/{edgeId}")
|
||||
public String findMissingToRelatedRuleChains(@Parameter(description = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||
@PathVariable("edgeId") String strEdgeId) throws ThingsboardException {
|
||||
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
|
||||
@ -547,8 +524,7 @@ public class EdgeController extends BaseController {
|
||||
@ApiOperation(value = "Get Edge Install Instructions (getEdgeInstallInstructions)",
|
||||
notes = "Get an install instructions for provided edge id." + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/edge/instructions/install/{edgeId}/{method}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/edge/instructions/install/{edgeId}/{method}")
|
||||
public EdgeInstructions getEdgeInstallInstructions(
|
||||
@Parameter(description = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||
@PathVariable("edgeId") String strEdgeId,
|
||||
@ -568,8 +544,7 @@ public class EdgeController extends BaseController {
|
||||
@ApiOperation(value = "Get Edge Upgrade Instructions (getEdgeUpgradeInstructions)",
|
||||
notes = "Get an upgrade instructions for provided edge version." + TENANT_AUTHORITY_PARAGRAPH)
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/edge/instructions/upgrade/{edgeVersion}/{method}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/edge/instructions/upgrade/{edgeVersion}/{method}")
|
||||
public EdgeInstructions getEdgeUpgradeInstructions(
|
||||
@Parameter(description = "Edge version", required = true)
|
||||
@PathVariable("edgeVersion") String edgeVersion,
|
||||
@ -585,8 +560,7 @@ public class EdgeController extends BaseController {
|
||||
@ApiOperation(value = "Is edge upgrade enabled (isEdgeUpgradeAvailable)",
|
||||
notes = "Returns 'true' if upgrade available for connected edge, 'false' - otherwise.")
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/edge/{edgeId}/upgrade/available", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/edge/{edgeId}/upgrade/available")
|
||||
public boolean isEdgeUpgradeAvailable(
|
||||
@Parameter(description = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||
@PathVariable("edgeId") String strEdgeId) throws Exception {
|
||||
@ -599,4 +573,5 @@ public class EdgeController extends BaseController {
|
||||
throw new ThingsboardException("Edges support disabled", ThingsboardErrorCode.GENERAL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -16,18 +16,14 @@
|
||||
package org.thingsboard.server.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.thingsboard.server.common.data.edge.EdgeEvent;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
@ -62,8 +58,7 @@ public class EdgeEventController extends BaseController {
|
||||
notes = "Returns a page of edge events for the requested edge. " +
|
||||
PAGE_DATA_PARAMETERS)
|
||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||
@RequestMapping(value = "/edge/{edgeId}/events", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/edge/{edgeId}/events")
|
||||
public PageData<EdgeEvent> getEdgeEvents(
|
||||
@Parameter(description = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||
@PathVariable(EDGE_ID) String strEdgeId,
|
||||
@ -88,4 +83,5 @@ public class EdgeEventController extends BaseController {
|
||||
TimePageLink pageLink = createTimePageLink(pageSize, page, textSearch, sortProperty, sortOrder, startTime, endTime);
|
||||
return checkNotNull(edgeEventService.findEdgeEvents(tenantId, edgeId, 0L, null, pageLink));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.thingsboard.server.service.edge.instructions;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.AttributeScope;
|
||||
@ -164,4 +162,5 @@ public class DefaultEdgeUpgradeInstructionsService extends BaseEdgeInstallUpgrad
|
||||
protected String getBaseDirName() {
|
||||
return UPGRADE_DIR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -15,14 +15,14 @@
|
||||
*/
|
||||
package org.thingsboard.server.service.edge.instructions;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.thingsboard.server.common.data.edge.Edge;
|
||||
import org.thingsboard.server.common.data.edge.EdgeInstructions;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
public interface EdgeInstallInstructionsService {
|
||||
|
||||
EdgeInstructions getInstallInstructions(Edge edge, String installationMethod, HttpServletRequest request);
|
||||
|
||||
void setAppVersion(String version);
|
||||
|
||||
}
|
||||
|
||||
@ -21,6 +21,9 @@ import com.google.common.util.concurrent.Futures;
|
||||
import io.grpc.Server;
|
||||
import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import jakarta.annotation.Nullable;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -55,9 +58,6 @@ import org.thingsboard.server.service.edge.EdgeContextComponent;
|
||||
import org.thingsboard.server.service.state.DefaultDeviceStateService;
|
||||
import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService;
|
||||
|
||||
import jakarta.annotation.Nullable;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
|
||||
@ -23,12 +23,12 @@ import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.server.common.adaptor.JsonConverter;
|
||||
import org.thingsboard.server.common.data.DataConstants;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.adaptor.JsonConverter;
|
||||
import org.thingsboard.server.gen.edge.v1.AttributeDeleteMsg;
|
||||
import org.thingsboard.server.gen.edge.v1.EntityDataProto;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
@ -106,4 +106,5 @@ public class EntityDataMsgConstructor {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,7 +19,6 @@ import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.Tenant;
|
||||
import org.thingsboard.server.common.data.TenantProfile;
|
||||
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration;
|
||||
import org.thingsboard.server.gen.edge.v1.EdgeVersion;
|
||||
import org.thingsboard.server.gen.edge.v1.TenantProfileUpdateMsg;
|
||||
import org.thingsboard.server.gen.edge.v1.TenantUpdateMsg;
|
||||
@ -37,22 +36,6 @@ public class TenantMsgConstructorV2 implements TenantMsgConstructor {
|
||||
|
||||
@Override
|
||||
public TenantProfileUpdateMsg constructTenantProfileUpdateMsg(UpdateMsgType msgType, TenantProfile tenantProfile, EdgeVersion edgeVersion) {
|
||||
tenantProfile = JacksonUtil.clone(tenantProfile);
|
||||
// clear all config
|
||||
var configuration = tenantProfile.getDefaultProfileConfiguration();
|
||||
configuration.setRpcTtlDays(0);
|
||||
configuration.setMaxJSExecutions(0);
|
||||
configuration.setMaxREExecutions(0);
|
||||
configuration.setMaxDPStorageDays(0);
|
||||
configuration.setMaxTbelExecutions(0);
|
||||
configuration.setQueueStatsTtlDays(0);
|
||||
configuration.setMaxTransportMessages(0);
|
||||
configuration.setDefaultStorageTtlDays(0);
|
||||
configuration.setMaxTransportDataPoints(0);
|
||||
configuration.setRuleEngineExceptionsTtlDays(0);
|
||||
configuration.setMaxRuleNodeExecutionsPerMessage(0);
|
||||
tenantProfile.getProfileData().setConfiguration(configuration);
|
||||
|
||||
return TenantProfileUpdateMsg.newBuilder().setMsgType(msgType).setEntity(JacksonUtil.toString(tenantProfile)).build();
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.edge.EdgeEvent;
|
||||
import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceCredentialsUpdateMsg;
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg;
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg;
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg;
|
||||
import org.thingsboard.server.gen.edge.v1.DownlinkMsg;
|
||||
@ -37,4 +36,5 @@ public interface DeviceProcessor extends EdgeProcessor {
|
||||
DownlinkMsg convertDeviceEventToDownlink(EdgeEvent edgeEvent, EdgeId edgeId, EdgeVersion edgeVersion);
|
||||
|
||||
ListenableFuture<Void> processDeviceRpcCallFromEdge(TenantId tenantId, Edge edge, DeviceRpcCallMsg deviceRpcCallMsg);
|
||||
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.thingsboard.edge.rpc;
|
||||
|
||||
import io.grpc.HttpConnectProxiedSocketAddress;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts;
|
||||
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
|
||||
@ -43,6 +44,7 @@ import org.thingsboard.server.gen.edge.v1.UplinkMsg;
|
||||
import org.thingsboard.server.gen.edge.v1.UplinkResponseMsg;
|
||||
|
||||
import javax.net.ssl.SSLException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Consumer;
|
||||
@ -67,6 +69,16 @@ public class EdgeGrpcClient implements EdgeRpcClient {
|
||||
private String certResource;
|
||||
@Value("${cloud.rpc.max_inbound_message_size:4194304}")
|
||||
private int maxInboundMessageSize;
|
||||
@Value("${cloud.rpc.proxy.enabled}")
|
||||
private boolean proxyEnabled;
|
||||
@Value("${cloud.rpc.proxy.host:}")
|
||||
private String proxyHost;
|
||||
@Value("${cloud.rpc.proxy.port:0}")
|
||||
private int proxyPort;
|
||||
@Value("${cloud.rpc.proxy.username:}")
|
||||
private String proxyUsername;
|
||||
@Value("${cloud.rpc.proxy.password:}")
|
||||
private String proxyPassword;
|
||||
@Getter
|
||||
private int serverMaxInboundMessageSize;
|
||||
|
||||
@ -88,6 +100,7 @@ public class EdgeGrpcClient implements EdgeRpcClient {
|
||||
.keepAliveTime(keepAliveTimeSec, TimeUnit.SECONDS)
|
||||
.keepAliveTimeout(keepAliveTimeoutSec, TimeUnit.SECONDS)
|
||||
.keepAliveWithoutCalls(true);
|
||||
|
||||
if (sslEnabled) {
|
||||
try {
|
||||
SslContextBuilder sslContextBuilder = GrpcSslContexts.forClient();
|
||||
@ -102,6 +115,18 @@ public class EdgeGrpcClient implements EdgeRpcClient {
|
||||
} else {
|
||||
builder.usePlaintext();
|
||||
}
|
||||
|
||||
if (proxyEnabled && StringUtils.isNotEmpty(proxyHost) && proxyPort > 0) {
|
||||
InetSocketAddress proxyAddress = new InetSocketAddress(proxyHost, proxyPort);
|
||||
InetSocketAddress targetAddress = new InetSocketAddress(rpcHost, rpcPort);
|
||||
builder.proxyDetector(socketAddress -> HttpConnectProxiedSocketAddress.newBuilder()
|
||||
.setTargetAddress(targetAddress)
|
||||
.setProxyAddress(proxyAddress)
|
||||
.setUsername(proxyUsername)
|
||||
.setPassword(proxyPassword)
|
||||
.build());
|
||||
}
|
||||
|
||||
channel = builder.build();
|
||||
EdgeRpcServiceGrpc.EdgeRpcServiceStub stub = EdgeRpcServiceGrpc.newStub(channel);
|
||||
log.info("[{}] Sending a connect request to the TB!", edgeKey);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user