aboutsummaryrefslogtreecommitdiffstats
path: root/servicegateway
diff options
context:
space:
mode:
authorLuji <lu.ji3@zte.com.cn>2016-09-19 16:46:29 +0000
committerGerrit Code Review <gerrit@open-o.org>2016-09-19 16:46:29 +0000
commit8db529e4bc5575bc2d04d19312766e7cb1dfe850 (patch)
tree6cf7c90b6b11839f0ac327cc211395ebac716b1e /servicegateway
parent59f5934e6b3c8f239746d843bdafc36c0384650c (diff)
parent2e0d5b25d06415247a2446ba85a212db473a9bb0 (diff)
Merge "add servicegateway implementation for deleteService"
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;
+ }
}
}