From 2e0d5b25d06415247a2446ba85a212db473a9bb0 Mon Sep 17 00:00:00 2001 From: Luji7 Date: Tue, 20 Sep 2016 00:36:31 +0800 Subject: add servicegateway implementation for deleteService Change-Id: I9dd276ccdf1f645c7e62d08eeafc81c751b2f03f Signed-off-by: Luji7 --- .../gso/gui/servicegateway/constant/Constant.java | 9 ++++++ .../roa/impl/ServiceGatewayRoaModuleImpl.java | 23 +++++++++++++- .../service/impl/ServiceGatewayImpl.java | 37 ++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) (limited to 'servicegateway') diff --git a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java index 2e35b5a8..3a26a606 100644 --- a/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java +++ b/servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java @@ -46,6 +46,15 @@ public class Constant { */ public static final String SERVICE_GATEWAY_URI = "gatewayUri"; + /** + * Service operation. + */ + public static final String SERVICE_OPERATION = "operation"; + + /** + * Service delete operation. + */ + public static final String SERVICE_DELETE_OPERATION = "delete"; /** * Create workflow name. 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 492d75fe..ff337512 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 @@ -100,7 +100,28 @@ public class ServiceGatewayRoaModuleImpl implements IServiceGatewayRoaModule { */ @Override public Response deleteService(String serviceId, HttpServletRequest servletReq) { + Map operateStatus = null; + Map result = null; + try { + // 1. Check validation + String reqContent = RestUtils.getRequestBody(servletReq); + ValidateUtil.assertStringNotNull(reqContent); + + // 2. Delete service + 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 null; + return Response.accepted().entity(result).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 70162529..07442bb3 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 @@ -25,6 +25,7 @@ import org.openo.baseservice.remoteservice.exception.ServiceException; import org.openo.baseservice.roa.util.restclient.RestfulFactory; import org.openo.baseservice.roa.util.restclient.RestfulParametes; import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.baseservice.util.RestUtils; import org.openo.gso.gui.servicegateway.constant.Constant; import org.openo.gso.gui.servicegateway.service.inf.IServiceGateway; import org.openo.gso.gui.servicegateway.util.json.JsonUtil; @@ -127,7 +128,43 @@ public class ServiceGatewayImpl implements IServiceGateway { */ @Override public void deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException { + // Parse request + String reqContent = RestUtils.getRequestBody(httpRequest); + Map requestBody = JsonUtil.unMarshal(reqContent, Map.class); + Map service = (Map)requestBody.get(Constant.SERVICE_INDENTIFY); + if(null == service) + { + service = requestBody; + } + ValidateUtil.assertObjectNotNull(requestBody); + + // Validate data + String gatewayUri = (String)service.get(Constant.SERVICE_GATEWAY_URI); + ValidateUtil.assertStringNotNull(gatewayUri); + service.remove(Constant.SERVICE_GATEWAY_URI); + String operation = (String) service.get(Constant.SERVICE_OPERATION); + ValidateUtil.assertStringNotNull(operation); + service.remove(Constant.SERVICE_OPERATION); + + // call the restful + String id = null; + try { + RestfulResponse restfulRsp = null; + if(Constant.SERVICE_DELETE_OPERATION.equalsIgnoreCase(operation)) { + restfulRsp = RestfulFactory.getRestInstance("http").delete(gatewayUri, + getRestfulParameters(JsonUtil.marshal(requestBody))); + } else { + restfulRsp = RestfulFactory.getRestInstance("http").post(gatewayUri, + getRestfulParameters(JsonUtil.marshal(requestBody))); + } + if (null != restfulRsp) { + LOGGER.info("restful call result:", restfulRsp.getStatus()); + } + } catch(ServiceException e) { + LOGGER.error("service gateway delete restful call result:", e); + throw e; + } } } -- cgit 1.2.3-korg