diff options
author | Luji7 <lu.ji3@zte.com.cn> | 2016-10-21 14:13:44 +0800 |
---|---|---|
committer | Luji7 <lu.ji3@zte.com.cn> | 2016-10-21 14:13:44 +0800 |
commit | 5b70f275529dc33fb3cd01d046b5fd21cd4b66da (patch) | |
tree | 214c46e1feba7e409fb53fc168889673b063a3bc /servicegateway/service | |
parent | 9a7b8cfb0e8182d0d69d73ee40c0116042bc2e5e (diff) |
GSO-26 Modify the response structure for deleting service to be consistent with the api.
Change-Id: Ic6a4fa300e914be8bb6016e5022d548940fed29e
Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
Diffstat (limited to 'servicegateway/service')
3 files changed, 17 insertions, 14 deletions
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<String, Object> operateStatus = null; Map<String, Object> 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<String, Object> 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<String, Object> result = new HashMap<String, Object>(); 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.<br/> * <p> @@ -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<String, Object> deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException; } |