From 5b70f275529dc33fb3cd01d046b5fd21cd4b66da Mon Sep 17 00:00:00 2001 From: Luji7 Date: Fri, 21 Oct 2016 14:13:44 +0800 Subject: GSO-26 Modify the response structure for deleting service to be consistent with the api. Change-Id: Ic6a4fa300e914be8bb6016e5022d548940fed29e Signed-off-by: Luji7 --- .../roa/impl/ServiceGatewayRoaModuleImpl.java | 14 ++------------ .../servicegateway/service/impl/ServiceGatewayImpl.java | 13 ++++++++++++- .../gui/servicegateway/service/inf/IServiceGateway.java | 4 +++- 3 files changed, 17 insertions(+), 14 deletions(-) (limited to 'servicegateway/service/src') diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java index 7d2e0721..cca5f604 100644 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java +++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java @@ -101,7 +101,6 @@ public class ServiceGatewayRoaModuleImpl implements IServiceGatewayRoaModule { */ @Override public Response deleteService(String serviceId, HttpServletRequest servletReq) { - Map operateStatus = null; Map result = null; try { // 1. Check validation @@ -109,20 +108,11 @@ public class ServiceGatewayRoaModuleImpl implements IServiceGatewayRoaModule { ValidateUtil.assertStringNotNull(reqContent); // 2. Delete service - serviceGateway.deleteService(serviceId, servletReq); + result = serviceGateway.deleteService(serviceId, servletReq); } catch(ServiceException exception) { LOGGER.error("Fail to delete service instance."); - operateStatus = ResponseUtils.setOperateStatus(Constant.RESPONSE_STATUS_FAIL, exception, - String.valueOf(exception.getHttpCode())); - result = ResponseUtils.setResult(serviceId, operateStatus); - - return Response.accepted().entity(result).build(); + return Response.serverError().build(); } - - operateStatus = ResponseUtils.setOperateStatus(Constant.RESPONSE_STATUS_SUCCESS, null, - String.valueOf(HttpCode.RESPOND_OK)); - result = ResponseUtils.setResult(serviceId, operateStatus); - return Response.accepted().entity(result).build(); } diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java index 3ff4f89b..bc716d5e 100644 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java +++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java @@ -16,6 +16,7 @@ package org.openo.gso.gui.servicegateway.service.impl; +import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -130,7 +131,7 @@ public class ServiceGatewayImpl implements IServiceGateway { * @since GSO 0.5 */ @Override - public void deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException { + public Map deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException { if(httpRequest == null) { LOGGER.error("ServiceGatewayImpl.deleteService httpRequest is null"); @@ -153,16 +154,26 @@ public class ServiceGatewayImpl implements IServiceGateway { // call the restful try { RestfulResponse restfulRsp = null; + Map result = new HashMap(); if(Constant.SERVICE_DELETE_OPERATION.equalsIgnoreCase(operation)) { restfulRsp = RestfulFactory.getRestInstance("http").delete(gatewayUri, getRestfulParameters(JsonUtil.marshal(requestBody))); + result.put(Constant.RESPONSE_STATUS, "success"); + result.put(Constant.RESPONSE_STATUS_DESCRIPTION, "It is deleting."); + result.put(Constant.RESPONSE_ERRORCODE, "202"); } else { restfulRsp = RestfulFactory.getRestInstance("http").post(gatewayUri, getRestfulParameters(JsonUtil.marshal(requestBody))); + if (null != restfulRsp) { + String jobId = restfulRsp.getRespHeaderStr(Constant.JOB_ID); + result.put(Constant.JOB_ID, jobId); + } } if (null != restfulRsp) { LOGGER.info("restful call result:", restfulRsp.getStatus()); + LOGGER.info("restful call content:", restfulRsp.getResponseContent()); } + return result; } catch(ServiceException e) { LOGGER.error("service gateway delete restful call result:", e); throw e; diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java index 9e18cb13..cba925c6 100644 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java +++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java @@ -21,6 +21,8 @@ import javax.servlet.http.HttpServletRequest; import org.openo.baseservice.remoteservice.exception.ServiceException; +import java.util.Map; + /** * Interface to operate service.
*

@@ -50,6 +52,6 @@ public interface IServiceGateway { * @throws ServiceException operate DB or parameter is wrong. * @since GSO 0.5 */ - void deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException; + Map deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException; } -- cgit 1.2.3-korg