add servicegateway implementation for deleteService
authorLuji7 <lu.ji3@zte.com.cn>
Mon, 19 Sep 2016 16:36:31 +0000 (00:36 +0800)
committerLuji7 <lu.ji3@zte.com.cn>
Mon, 19 Sep 2016 16:36:31 +0000 (00:36 +0800)
Change-Id: I9dd276ccdf1f645c7e62d08eeafc81c751b2f03f
Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/constant/Constant.java
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java

index 2e35b5a..3a26a60 100644 (file)
@@ -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.
index 492d75f..ff33751 100644 (file)
@@ -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();
     }
 }
index 7016252..07442bb 100644 (file)
@@ -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;
+        }
     }
 
 }