From 2681531aef7ccabcb0b1d76ce9078ba3961bc165 Mon Sep 17 00:00:00 2001 From: casionone Date: Wed, 15 Sep 2021 19:57:17 +0800 Subject: [PATCH] replace jersey with spring web --- .../conf/linkis-cg-linkismanager.properties | 1 + .../linkis/DataWorkCloudApplication.java | 5 ++ .../linkis/server/BDPJettyServerHelper.scala | 24 ++++++ .../wedatasphere/linkis/server/Message.scala | 55 ++++++++---- .../server/conf/ServerConfiguration.scala | 1 + .../manager/am/restful/EMRestfulApi.java | 55 +++++------- .../manager/am/restful/EngineRestfulApi.java | 83 ++++++++----------- 7 files changed, 125 insertions(+), 99 deletions(-) diff --git a/assembly-combined-package/assembly-combined/conf/linkis-cg-linkismanager.properties b/assembly-combined-package/assembly-combined/conf/linkis-cg-linkismanager.properties index a99f065811..738b150696 100644 --- a/assembly-combined-package/assembly-combined/conf/linkis-cg-linkismanager.properties +++ b/assembly-combined-package/assembly-combined/conf/linkis-cg-linkismanager.properties @@ -22,3 +22,4 @@ wds.linkis.server.mybatis.BasePackage=com.webank.wedatasphere.linkis.manager.dao ##Spring spring.server.port=9101 +spring.spring.mvc.servlet.path=/api/rest_s/v1 diff --git a/linkis-commons/linkis-module/src/main/java/com/webank/wedatasphere/linkis/DataWorkCloudApplication.java b/linkis-commons/linkis-module/src/main/java/com/webank/wedatasphere/linkis/DataWorkCloudApplication.java index 28f6877746..e5e102ab5b 100644 --- a/linkis-commons/linkis-module/src/main/java/com/webank/wedatasphere/linkis/DataWorkCloudApplication.java +++ b/linkis-commons/linkis-module/src/main/java/com/webank/wedatasphere/linkis/DataWorkCloudApplication.java @@ -175,8 +175,10 @@ protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { @Bean public WebServerFactoryCustomizer jettyFactoryCustomizer() { return new WebServerFactoryCustomizer() { + @Override public void customize(JettyServletWebServerFactory jettyServletWebServerFactory) { jettyServletWebServerFactory.addServerCustomizers(new JettyServerCustomizer() { + @Override public void customize(Server server) { Handler[] childHandlersByClass = server.getChildHandlersByClass(WebAppContext.class); final WebAppContext webApp = (WebAppContext) childHandlersByClass[0]; @@ -185,6 +187,9 @@ public void customize(Server server) { filterHolder.setInitParameter("forceEncoding", "true"); webApp.addFilter(filterHolder, "/*", EnumSet.allOf(DispatcherType.class)); BDPJettyServerHelper.setupRestApiContextHandler(webApp); + + //set servletHolder for spring restful api + BDPJettyServerHelper.setupSpringRestApiContextHandler(webApp); if(ServerConfiguration.BDP_SERVER_SOCKET_MODE().getValue()) { BDPJettyServerHelper.setupControllerServer(webApp); } diff --git a/linkis-commons/linkis-module/src/main/scala/com/webank/wedatasphere/linkis/server/BDPJettyServerHelper.scala b/linkis-commons/linkis-module/src/main/scala/com/webank/wedatasphere/linkis/server/BDPJettyServerHelper.scala index 6cea9c37a8..12e2c25753 100644 --- a/linkis-commons/linkis-module/src/main/scala/com/webank/wedatasphere/linkis/server/BDPJettyServerHelper.scala +++ b/linkis-commons/linkis-module/src/main/scala/com/webank/wedatasphere/linkis/server/BDPJettyServerHelper.scala @@ -35,6 +35,8 @@ import org.eclipse.jetty.server.session.SessionHandler import org.eclipse.jetty.servlet.{DefaultServlet, FilterHolder, ServletContextHandler, ServletHolder} import org.eclipse.jetty.webapp.WebAppContext import org.glassfish.jersey.servlet.ServletContainer +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext +import org.springframework.web.servlet.DispatcherServlet import scala.collection.mutable @@ -77,6 +79,28 @@ private[linkis] object BDPJettyServerHelper extends Logging { webApp.addFilter(filterHolder, restfulPath, EnumSet.allOf(classOf[DispatcherType])) } + def setupSpringRestApiContextHandler(webApp: ServletContextHandler) { + val context = new AnnotationConfigWebApplicationContext + //val CONFIG_LOCATION = "com.webank.wedatasphere.linkis.manager.am" + val CONFIG_LOCATION = "" + context.setConfigLocation(CONFIG_LOCATION); + val serlvet = new DispatcherServlet(context) + val servletHolder = new ServletHolder(serlvet) + + servletHolder.setName("springrestful") + servletHolder.setForcedPath("springrestful") + + val p = BDP_SERVER_SPRING_RESTFUL_URI.getValue + val restfulPath = if(p.endsWith("/*")) p + else if(p.endsWith("/")) p + "*" + else p + "/*" + + webApp.addServlet(servletHolder, restfulPath) + val filterHolder = new FilterHolder(getSecurityFilter()) + webApp.addFilter(filterHolder, restfulPath, EnumSet.allOf(classOf[DispatcherType])) + webApp.setSessionHandler(new SessionHandler) + + } def setupControllerServer(webApp: ServletContextHandler): ControllerServer = { if(controllerServer != null) return controllerServer synchronized { diff --git a/linkis-commons/linkis-module/src/main/scala/com/webank/wedatasphere/linkis/server/Message.scala b/linkis-commons/linkis-module/src/main/scala/com/webank/wedatasphere/linkis/server/Message.scala index 2da72957b5..4cc79f2933 100644 --- a/linkis-commons/linkis-module/src/main/scala/com/webank/wedatasphere/linkis/server/Message.scala +++ b/linkis-commons/linkis-module/src/main/scala/com/webank/wedatasphere/linkis/server/Message.scala @@ -15,19 +15,22 @@ package com.webank.wedatasphere.linkis.server import java.util +import com.webank.wedatasphere.linkis.server.Message.getCurrentHttpRequest +import javax.servlet.http.HttpServletRequest import javax.ws.rs.Path import javax.ws.rs.core.Response import javax.xml.bind.annotation.XmlRootElement import org.apache.commons.lang.StringUtils import org.apache.commons.lang.exception.ExceptionUtils import org.reflections.ReflectionUtils +import org.springframework.web.context.request.{RequestContextHolder, ServletRequestAttributes} @XmlRootElement(name = "message") class Message(private var method: String, private var status: Int = 0, //-1 no login, 0 success, 1 error, 2 validate failed, 3 auth failed, 4 warning private var message: String, - private var data: util.HashMap[String, Object] = new util.HashMap[String, Object]) { + private var data: util.HashMap[String, Object] = new util.HashMap[String, Object]) { def this() = this(null, 0, null) def << (key: String, value: Any): Message = { data.put(key, value.asInstanceOf[AnyRef]) @@ -57,8 +60,8 @@ class Message(private var method: String, def setData(data: util.HashMap[String, Object]): Unit = this.data = data def getData = data -// def isSuccess = status == 0 -// def isError = status != 0 + // def isSuccess = status == 0 + // def isError = status != 0 override def toString = s"Message($getMethod, $getStatus, $getData)" } @@ -66,17 +69,32 @@ class Message(private var method: String, object Message { def apply(method: String = null, status: Int = 0, message: String = null, data: util.HashMap[String, Object] = new util.HashMap[String, Object]): Message = { - if(StringUtils.isEmpty(method)) { - Thread.currentThread().getStackTrace.find(_.getClassName.toLowerCase.endsWith("restfulapi")).foreach { stack => - val clazz = ReflectionUtils.forName(stack.getClassName) - val path = clazz.getAnnotation(classOf[Path]).value() - clazz.getDeclaredMethods.find(m => m.getName == stack.getMethodName && m.getAnnotation(classOf[Path]) != null) - .foreach { m => - val path1 = m.getAnnotation(classOf[Path]).value() - var method = if(path.startsWith("/")) path else "/" + path - if(method.endsWith("/")) method = method.substring(0, method.length - 1) - method = if(path1.startsWith("/")) "/api" + method + path1 else "/api" + method + "/" + path1 - return new Message(method, status, message, data) + if (StringUtils.isEmpty(method)) { + Thread.currentThread().getStackTrace.find(_.getClassName.toLowerCase.endsWith("restfulapi")).foreach { + stack => { + val clazz = ReflectionUtils.forName(stack.getClassName) + var annotation = clazz.getAnnotation(classOf[Path]) + var path = "" + if (annotation != null) { + path = clazz.getAnnotation(classOf[Path]).value() + clazz.getDeclaredMethods.find(m => m.getName == stack.getMethodName && m.getAnnotation(classOf[Path]) != null) + .foreach { m => + val path1 = m.getAnnotation(classOf[Path]).value() + var method = if (path.startsWith("/")) path else "/" + path + if (method.endsWith("/")) method = method.substring(0, method.length - 1) + method = if (path1.startsWith("/")) "/api" + method + path1 else "/api" + method + "/" + path1 + return new Message(method, status, message, data) + } + } else { + val httpRequest:HttpServletRequest=getCurrentHttpRequest + if(httpRequest!=null){ + val path1=httpRequest.getPathInfo; + var method = if (path.startsWith("/")) path else "/" + path + if (method.endsWith("/")) method = method.substring(0, method.length - 1) + method = if (path1.startsWith("/")) "/api" + method + path1 else "/api" + method + "/" + path1 + return new Message(method, status, message, data) + } + } } } } @@ -106,6 +124,15 @@ object Message { implicit def response(message: Message): String = BDPJettyServerHelper.gson.toJson(message) + def getCurrentHttpRequest: HttpServletRequest = { + val requestAttributes = RequestContextHolder.getRequestAttributes + if (requestAttributes.isInstanceOf[ServletRequestAttributes]) { + val request = requestAttributes.asInstanceOf[ServletRequestAttributes].getRequest + return request + } + null + } + def noLogin(msg: String, t: Throwable): Message = { val message = Message(status = -1) message.setMessage(msg) diff --git a/linkis-commons/linkis-module/src/main/scala/com/webank/wedatasphere/linkis/server/conf/ServerConfiguration.scala b/linkis-commons/linkis-module/src/main/scala/com/webank/wedatasphere/linkis/server/conf/ServerConfiguration.scala index c773dcb4a0..fba8c80847 100644 --- a/linkis-commons/linkis-module/src/main/scala/com/webank/wedatasphere/linkis/server/conf/ServerConfiguration.scala +++ b/linkis-commons/linkis-module/src/main/scala/com/webank/wedatasphere/linkis/server/conf/ServerConfiguration.scala @@ -75,6 +75,7 @@ object ServerConfiguration extends Logging{ val BDP_SERVER_SERVER_CONTEXT_PATH = CommonVars("wds.linkis.server.context.path", "/") val BDP_SERVER_RESTFUL_URI = CommonVars("wds.linkis.server.restful.uri", "/api/rest_j/" + BDP_SERVER_VERSION) + val BDP_SERVER_SPRING_RESTFUL_URI = CommonVars("wds.linkis.server.restful.uri", "/api/rest_s/" + BDP_SERVER_VERSION) val BDP_SERVER_USER_URI = CommonVars("wds.linkis.server.user.restful.uri", "/api/rest_j/" + BDP_SERVER_VERSION + "/user") val BDP_SERVER_RESTFUL_LOGIN_URI = CommonVars("wds.linkis.server.user.restful.login.uri", new File(BDP_SERVER_USER_URI.getValue, "login").getPath) val BDP_SERVER_SECURITY_SSL_URI = CommonVars("wds.linkis.server.user.security.ssl.uri", new File(BDP_SERVER_USER_URI.getValue, "publicKey").getPath) diff --git a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/com/webank/wedatasphere/linkis/manager/am/restful/EMRestfulApi.java b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/com/webank/wedatasphere/linkis/manager/am/restful/EMRestfulApi.java index 7e1c39a7de..60daf173a2 100644 --- a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/com/webank/wedatasphere/linkis/manager/am/restful/EMRestfulApi.java +++ b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/com/webank/wedatasphere/linkis/manager/am/restful/EMRestfulApi.java @@ -18,10 +18,6 @@ package com.webank.wedatasphere.linkis.manager.am.restful; -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.netflix.discovery.converters.Auto; import com.webank.wedatasphere.linkis.common.ServiceInstance; import com.webank.wedatasphere.linkis.manager.am.conf.AMConfiguration; import com.webank.wedatasphere.linkis.manager.am.converter.DefaultMetricsConverter; @@ -35,42 +31,31 @@ import com.webank.wedatasphere.linkis.manager.common.entity.node.EMNode; import com.webank.wedatasphere.linkis.manager.label.builder.factory.LabelBuilderFactory; import com.webank.wedatasphere.linkis.manager.label.builder.factory.LabelBuilderFactoryContext; -import com.webank.wedatasphere.linkis.manager.label.builder.factory.StdLabelBuilderFactory; import com.webank.wedatasphere.linkis.manager.label.entity.Label; import com.webank.wedatasphere.linkis.manager.label.entity.UserModifiable; import com.webank.wedatasphere.linkis.manager.label.exception.LabelErrorException; import com.webank.wedatasphere.linkis.manager.label.service.NodeLabelService; -import com.webank.wedatasphere.linkis.server.BDPJettyServerHelper; import com.webank.wedatasphere.linkis.server.Message; import com.webank.wedatasphere.linkis.server.security.SecurityFilter; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.codehaus.jackson.JsonNode; -import org.json4s.JsonAST; -import org.json4s.JsonUtil; -import org.json4s.jackson.Json; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import scala.util.parsing.json.JSON; -import scala.util.parsing.json.JSONObject; -import scala.util.parsing.json.JSONObject$; +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.RestController; import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.*; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import java.util.*; import java.util.stream.Collectors; -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -@Component -@Path("/linkisManager") +@RequestMapping(path = "/linkisManager", produces = {"application/json"}) +@RestController public class EMRestfulApi { @Autowired @@ -88,12 +73,11 @@ public class EMRestfulApi { //todo add healthInfo - @GET - @Path("/listAllEMs") - public Response listAllEMs(@Context HttpServletRequest req, - @QueryParam("instance") String instance, - @QueryParam("nodeHealthy") String nodeHealthy, - @QueryParam("owner" )String owner) throws AMErrorException { + @RequestMapping(path = "/listAllEMs", method = RequestMethod.GET) + public Message listAllEMs(HttpServletRequest req, + @RequestParam(value = "instance",required = false) String instance, + @RequestParam(value = "nodeHealthy",required = false) String nodeHealthy, + @RequestParam(value = "owner",required = false)String owner) throws AMErrorException { String userName = SecurityFilter.getLoginUsername(req); String[] adminArray = AMConfiguration.GOVERNANCE_STATION_ADMIN().getValue().split(","); if(adminArray != null && !Arrays.asList(adminArray).contains(userName)){ @@ -113,24 +97,23 @@ public Response listAllEMs(@Context HttpServletRequest req, if(CollectionUtils.isNotEmpty(allEMVoFilter3) && !StringUtils.isEmpty(owner)){ allEMVoFilter3 = (ArrayList) allEMVoFilter3.stream().filter(em ->{return em.getOwner().equalsIgnoreCase(owner);}).collect(Collectors.toList()); } - return Message.messageToResponse(Message.ok().data("EMs", allEMVoFilter3)); + return Message.ok().data("EMs", allEMVoFilter3); } - @GET - @Path("/listAllECMHealthyStatus") - public Response listAllNodeHealthyStatus(@Context HttpServletRequest req, @QueryParam("onlyEditable") Boolean onlyEditable){ + @RequestMapping(path = "/listAllECMHealthyStatus", method = RequestMethod.GET) + public Message listAllNodeHealthyStatus( HttpServletRequest req, + @RequestParam(value = "onlyEditable",required = false) Boolean onlyEditable){ NodeHealthy[] nodeHealthy = NodeHealthy.values(); if(onlyEditable){ nodeHealthy = new NodeHealthy[]{NodeHealthy.Healthy, NodeHealthy.UnHealthy, NodeHealthy.WARN, NodeHealthy.StockAvailable, NodeHealthy.StockUnavailable}; } - return Message.messageToResponse(Message.ok().data("nodeHealthy", nodeHealthy)); + return Message.ok().data("nodeHealthy", nodeHealthy); } - @PUT - @Path("/modifyEMInfo") + @RequestMapping(path = "/modifyEMInfo", method = RequestMethod.PUT) @Transactional(rollbackFor = Exception.class) - public Response modifyEMInfo(@Context HttpServletRequest req, JsonNode jsonNode) throws AMErrorException, LabelErrorException { + public Message modifyEMInfo( HttpServletRequest req, JsonNode jsonNode) throws AMErrorException, LabelErrorException { String username = SecurityFilter.getLoginUsername(req); String[] adminArray = AMConfiguration.GOVERNANCE_STATION_ADMIN().getValue().split(","); if(adminArray != null && !Arrays.asList(adminArray).contains(username)){ @@ -176,7 +159,7 @@ public Response modifyEMInfo(@Context HttpServletRequest req, JsonNode jsonNode) nodeLabelService.updateLabelsToNode(serviceInstance, newLabelList); logger.info("success to update label of instance: " + serviceInstance.getInstance()); } - return Message.messageToResponse(Message.ok("修改EM信息成功")); + return Message.ok("修改EM信息成功"); } } diff --git a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/com/webank/wedatasphere/linkis/manager/am/restful/EngineRestfulApi.java b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/com/webank/wedatasphere/linkis/manager/am/restful/EngineRestfulApi.java index 446eabf5fc..f1dfbefd22 100644 --- a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/com/webank/wedatasphere/linkis/manager/am/restful/EngineRestfulApi.java +++ b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/com/webank/wedatasphere/linkis/manager/am/restful/EngineRestfulApi.java @@ -49,16 +49,6 @@ import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; @@ -68,12 +58,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +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.RestController; -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -@Component -@Path("/linkisManager") +@RequestMapping(path = "/linkisManager", produces = {"application/json"}) +@RestController public class EngineRestfulApi { @Autowired @@ -94,9 +85,8 @@ public class EngineRestfulApi { private Logger logger = LoggerFactory.getLogger(EMRestfulApi.class); - @POST - @Path("createEngineConn") - public Response createEngineConn(@Context HttpServletRequest req, JsonNode jsonNode) + @RequestMapping(path = "/createEngineConn", method = RequestMethod.POST) + public Message createEngineConn( HttpServletRequest req, JsonNode jsonNode) throws IOException, InterruptedException { String userName = SecurityFilter.getLoginUsername(req); EngineCreateRequest engineCreateRequest = objectMapper.readValue(jsonNode, EngineCreateRequest.class); @@ -115,62 +105,58 @@ public Response createEngineConn(@Context HttpServletRequest req, JsonNode jsonN } catch (TimeoutException e) { logger.error(String.format("User %s create engineConn timeout.", userName), e); job.cancel(true); - return Message.messageToResponse(Message - .error("Create engineConn timeout, usually caused by the too long initialization of EngineConn(创建引擎超时,通常都是因为初始化引擎时间太长导致).")); + return Message + .error("Create engineConn timeout, usually caused by the too long initialization of EngineConn(创建引擎超时,通常都是因为初始化引擎时间太长导致)."); } catch (ExecutionException e) { logger.error(String.format("User %s create engineConn failed.", userName), e); - return Message.messageToResponse(Message - .error(String.format("Create engineConn failed, caused by %s.", ExceptionUtils.getRootCauseMessage(e)))); + return Message + .error(String.format("Create engineConn failed, caused by %s.", ExceptionUtils.getRootCauseMessage(e))); } logger.info("Finished to create a engineConn for user {}. NodeInfo is {}.", userName, engineNode); //to transform to a map Map retEngineNode = new HashMap<>(); retEngineNode.put("serviceInstance", engineNode.getServiceInstance()); retEngineNode.put("nodeStatus", engineNode.getNodeStatus().toString()); - return Message.messageToResponse(Message.ok("create engineConn succeed.").data("engine", retEngineNode)); + return Message.ok("create engineConn succeed.").data("engine", retEngineNode); } - @POST - @Path("/getEngineConn") - public Response getEngineConn(@Context HttpServletRequest req, JsonNode jsonNode) throws AMErrorException { + @RequestMapping(path = "/getEngineConn", method = RequestMethod.POST) + public Message getEngineConn( HttpServletRequest req, JsonNode jsonNode) throws AMErrorException { String userName = SecurityFilter.getLoginUsername(req); ServiceInstance serviceInstance = getServiceInstance(jsonNode); EngineNode engineNode = engineCreateService.getEngineNode(serviceInstance); if(!userName.equals(engineNode.getOwner()) && !isAdmin(userName)) { - return Message.messageToResponse(Message.error("You have no permission to access EngineConn " + serviceInstance)); + return Message.error("You have no permission to access EngineConn " + serviceInstance); } - return Message.messageToResponse(Message.ok().data("engine", engineNode)); + return Message.ok().data("engine", engineNode); } - @POST - @Path("killEngineConn") - public Response killEngineConn(@Context HttpServletRequest req, JsonNode jsonNode) throws Exception { + @RequestMapping(path = "/killEngineConn", method = RequestMethod.POST) + public Message killEngineConn( HttpServletRequest req, JsonNode jsonNode) throws Exception { String userName = SecurityFilter.getLoginUsername(req); ServiceInstance serviceInstance = getServiceInstance(jsonNode); logger.info("User {} try to kill engineConn {}.", userName, serviceInstance); EngineNode engineNode = engineCreateService.getEngineNode(serviceInstance); if(!userName.equals(engineNode.getOwner()) && !isAdmin(userName)) { - return Message.messageToResponse(Message.error("You have no permission to kill EngineConn " + serviceInstance)); + return Message.error("You have no permission to kill EngineConn " + serviceInstance); } EngineStopRequest stopEngineRequest = new EngineStopRequest(serviceInstance, userName); MessageJob job = messagePublisher.publish(stopEngineRequest); job.get(RMUtils.MANAGER_KILL_ENGINE_EAIT().getValue().toLong(), TimeUnit.MILLISECONDS); logger.info("Finished to kill engineConn {}.", serviceInstance); - return Message.messageToResponse(Message.ok("Kill engineConn succeed.")); + return Message.ok("Kill engineConn succeed."); } - @GET - @Path("/listUserEngines") - public Response listUserEngines(@Context HttpServletRequest req) { + @RequestMapping(path = "/listUserEngines", method = RequestMethod.GET) + public Message listUserEngines( HttpServletRequest req) { String userName = SecurityFilter.getLoginUsername(req); List engineNodes = engineInfoService.listUserEngines(userName); - return Message.messageToResponse(Message.ok().data("engines", engineNodes)); + return Message.ok().data("engines", engineNodes); } - @POST - @Path("/listEMEngines") - public Response listEMEngines(@Context HttpServletRequest req, JsonNode jsonNode) throws IOException, AMErrorException { + @RequestMapping(path = "/listEMEngines", method = RequestMethod.POST) + public Message listEMEngines( HttpServletRequest req, JsonNode jsonNode) throws IOException, AMErrorException { String username = SecurityFilter.getLoginUsername(req); if(!isAdmin(username)){ throw new AMErrorException(210003,"Only admin can search engine information(只有管理员才能查询所有引擎信息)."); @@ -198,12 +184,11 @@ public Response listEMEngines(@Context HttpServletRequest req, JsonNode jsonNode if(CollectionUtils.isNotEmpty(allEMVoFilter4) && engineType != null && !StringUtils.isEmpty(engineType.asText())){ allEMVoFilter4 = (ArrayList) allEMVoFilter4.stream().filter(em ->{return em.getEngineType().equalsIgnoreCase(engineType.asText());}).collect(Collectors.toList()); } - return Message.messageToResponse(Message.ok().data("engines", allEMVoFilter4)); + return Message.ok().data("engines", allEMVoFilter4); } - @PUT - @Path("/modifyEngineInfo") - public Response modifyEngineInfo(@Context HttpServletRequest req, JsonNode jsonNode) throws AMErrorException, LabelErrorException { + @RequestMapping(path = "/modifyEngineInfo", method = RequestMethod.PUT) + public Message modifyEngineInfo( HttpServletRequest req, JsonNode jsonNode) throws AMErrorException, LabelErrorException { String username = SecurityFilter.getLoginUsername(req); if(!isAdmin(username)){ throw new AMErrorException(210003,"Only admin can modify engineConn information(只有管理员才能修改引擎信息)."); @@ -231,14 +216,14 @@ public Response modifyEngineInfo(@Context HttpServletRequest req, JsonNode jsonN nodeLabelService.updateLabelsToNode(serviceInstance, newLabelList); logger.info("success to update label of instance: " + serviceInstance.getInstance()); } - return Message.messageToResponse(Message.ok("success to update engine information(更新引擎信息成功)")); + return Message.ok("success to update engine information(更新引擎信息成功)"); } - @GET - @Path("/listAllNodeHealthyStatus") - public Response listAllNodeHealthyStatus(@Context HttpServletRequest req, @QueryParam("onlyEditable") Boolean onlyEditable){ + @RequestMapping(path = "/listAllNodeHealthyStatus", method = RequestMethod.GET) + public Message listAllNodeHealthyStatus( HttpServletRequest req, + @RequestParam(value = "onlyEditable",required = false) Boolean onlyEditable){ NodeStatus[] nodeStatus = NodeStatus.values(); - return Message.messageToResponse(Message.ok().data("nodeStatus", nodeStatus)); + return Message.ok().data("nodeStatus", nodeStatus); } private boolean isAdmin(String user) {