summaryrefslogtreecommitdiffstats
path: root/servicegateway
diff options
context:
space:
mode:
authorLuji7 <lu.ji3@zte.com.cn>2016-09-20 00:36:31 +0800
committerLuji7 <lu.ji3@zte.com.cn>2016-09-20 00:36:31 +0800
commit2e0d5b25d06415247a2446ba85a212db473a9bb0 (patch)
treeef298f43761a303d6619bf1371347b4e0760902d /servicegateway
parent422bd743ef87e7c159ad1c5d76c467fab79b1032 (diff)
add servicegateway implementation for deleteService
Change-Id: I9dd276ccdf1f645c7e62d08eeafc81c751b2f03f Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
Diffstat (limited to 'servicegateway')
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java9
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java23
-rw-r--r--servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java37
3 files changed, 68 insertions, 1 deletions
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<String, Object> operateStatus = null;
+ Map<String, Object> 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<String, Object> requestBody = JsonUtil.unMarshal(reqContent, Map.class);
+ Map<String, Object> service = (Map<String, Object>)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;
+ }
}
}