com.nepxion.discovery.plugin.admincenter.endpoint.RouterEndpoint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of discovery-plugin-admin-center-starter Show documentation
Show all versions of discovery-plugin-admin-center-starter Show documentation
Nepxion Discovery is a solution for Spring Cloud with blue green, gray, weight, limitation, circuit breaker, degrade, isolation, monitor, tracing, dye, failover, async agent
The newest version!
package com.nepxion.discovery.plugin.admincenter.endpoint;
/**
* Title: Nepxion Discovery
* Description: Nepxion Discovery
* Copyright: Copyright (c) 2017-2050
* Company: Nepxion
* @author Haojun Ren
* @version 1.0
*/
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.nepxion.discovery.common.entity.RouterEntity;
import com.nepxion.discovery.common.util.ResponseUtil;
import com.nepxion.discovery.plugin.admincenter.resource.RouterResource;
@RestController
@RequestMapping(path = "/router")
public class RouterEndpoint {
@Autowired
private RouterResource routerResource;
@RequestMapping(path = "/info", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity> info() {
return doInfo();
}
@RequestMapping(path = "/route/{routeServiceId}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity> route(@PathVariable(value = "routeServiceId") String routeServiceId) {
return doNativeRoute(routeServiceId);
}
@RequestMapping(path = "/route/{routeServiceId}/{routeProtocol}/{routeHost}/{routePort}/{routeContextPath}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity> route(@PathVariable(value = "routeServiceId") String routeServiceId, @PathVariable(value = "routeProtocol") String routeProtocol, @PathVariable(value = "routeHost") String routeHost, @PathVariable(value = "routePort") int routePort, @PathVariable(value = "routeContextPath") String routeContextPath) {
return doRemoteRoute(routeServiceId, routeProtocol, routeHost, routePort, routeContextPath);
}
@RequestMapping(path = "/routes", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity> routes(@RequestBody String routeServiceIds) {
return doRoutes(routeServiceIds);
}
private ResponseEntity> doInfo() {
try {
RouterEntity routerEntity = routerResource.getRouterEntity();
return ResponseUtil.getSuccessResponse(routerEntity);
} catch (Exception e) {
return ResponseUtil.getFailureResponse(e);
}
}
private ResponseEntity> doNativeRoute(String routeServiceId) {
try {
List routerEntityList = routerResource.getRouterEntityList(routeServiceId);
return ResponseUtil.getSuccessResponse(routerEntityList);
} catch (Exception e) {
return ResponseUtil.getFailureResponse(e);
}
}
private ResponseEntity> doRemoteRoute(String routeServiceId, String routeProtocol, String routeHost, int routePort, String routeContextPath) {
try {
List routerEntityList = routerResource.getRouterEntityList(routeServiceId, routeProtocol, routeHost, routePort, routeContextPath);
return ResponseUtil.getSuccessResponse(routerEntityList);
} catch (Exception e) {
return ResponseUtil.getFailureResponse(e);
}
}
private ResponseEntity> doRoutes(String routeServiceIds) {
try {
RouterEntity routerEntity = routerResource.routeTree(routeServiceIds);
return ResponseUtil.getSuccessResponse(routerEntity);
} catch (Exception e) {
return ResponseUtil.getFailureResponse(e);
}
}
}