Add generic post function 13/14413/1
authorc00149107 <chenchuanyu@huawei.com>
Fri, 22 Sep 2017 02:31:09 +0000 (10:31 +0800)
committerc00149107 <chenchuanyu@huawei.com>
Fri, 22 Sep 2017 02:32:11 +0000 (10:32 +0800)
Add generic post function and correct the api define

Change-Id: I11c2a10f4aad00f389b68cf7b9c42dab4441027c
Issue-ID:SO-57
Signed-off-by: c00149107 <chenchuanyu@huawei.com>
adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml
adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java
bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVFCNetworkServiceInstance.groovy

index 5bf8864..160dfb8 100644 (file)
@@ -38,7 +38,7 @@
   </servlet>
   <servlet-mapping>
     <servlet-name>Resteasy</servlet-name>
-    <url-pattern>/rest/*</url-pattern>
+    <url-pattern>/vfcadapter/*</url-pattern>
   </servlet-mapping>
     <security-constraint>
         <web-resource-collection>
index f4c2953..684933f 100644 (file)
@@ -49,7 +49,7 @@ import org.openecomp.mso.logger.MsoLogger;
  * @author
  * @version ONAP Amsterdam Release 2017-08-28
  */
-@Path("/v1/vfcdrivers")
+@Path("/vfcadapter/v1")
 public class VfcAdapterRest {
 
     private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
index 4a7f474..43a2731 100644 (file)
@@ -25,7 +25,6 @@ import groovy.xml.XmlUtil
 import groovy.json.*\r
 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor \r
 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil \r
-import org.openecomp.mso.bpmn.common.scripts.VidUtils \r
 import org.openecomp.mso.bpmn.core.WorkflowException \r
 import org.openecomp.mso.bpmn.core.json.JsonUtils \r
 import org.openecomp.mso.rest.APIResponse\r
@@ -36,7 +35,10 @@ import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.runtime.Execution\r
 import org.apache.commons.lang3.*\r
 import org.apache.commons.codec.binary.Base64;\r
-import org.springframework.web.util.UriUtils\r
+import org.springframework.web.util.UriUtils \r
+import org.openecomp.mso.rest.RESTClient \r
+import org.openecomp.mso.rest.RESTConfig\r
+import org.openecomp.mso.rest.APIResponse;\r
 \r
 /**\r
  * This groovy class supports the <class>CreateGenericE2EServiceInstance.bpmn</class> process.\r
@@ -44,18 +46,21 @@ import org.springframework.web.util.UriUtils
  */\r
 public class CreateGenericE2EServiceInstance extends AbstractServiceTaskProcessor {\r
 \r
+    String createUrl = "/vfc/vfcadapters/v1/ns"\r
+            \r
+    String instantiateUrl = "/vfcvfcadatpers/v1/ns/{nsInstanceId}/instantiate"\r
+    \r
+    String queryJobUrl = "/vfc/vfcadatpers/v1/jobs/{jobId}"\r
+    \r
     ExceptionUtil exceptionUtil = new ExceptionUtil()\r
 \r
     JsonUtils jsonUtil = new JsonUtils()\r
 \r
-    VidUtils vidUtils = new VidUtils()\r
-\r
     /**\r
      * Pre Process the BPMN Flow Request\r
      * Inclouds:\r
-     * Deal with the parameters\r
-     * generate the service instance id\r
-     * generate the operation id\r
+     * generate the nsOperationKey\r
+     * generate the nsParameters\r
      */\r
     public void preProcessRequest (Execution execution) {\r
           def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
@@ -101,8 +106,8 @@ public class CreateGenericE2EServiceInstance extends AbstractServiceTaskProcesso
        utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)\r
        }\r
 \r
-\r
     public void createNetworkService(Execution execution) {\r
+\r
     }\r
 \r
     public void instantiateNetworkService(Execution execution) {\r
@@ -116,4 +121,26 @@ public class CreateGenericE2EServiceInstance extends AbstractServiceTaskProcesso
 \r
     public void finishNSCreate(Execution execution) {\r
     }\r
+\r
+    /**\r
+     * post request\r
+     * url: the url of the request\r
+     * requestBody: the body of the request\r
+     */\r
+    private APIResponse postRequest(String url, String requestBody){\r
+        def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+        taskProcessor.logDebug( " ======== Started Execute VFC adapter Post Process ======== ", isDebugEnabled)\r
+        taskProcessor.logDebug( "url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled)\r
+        APIResponse apiResponse = null\r
+        try{\r
+            RESTConfig config = new RESTConfig(url);\r
+            RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/json");\r
+            apiResponse = client.httpPost(requestBody)\r
+            taskProcessor.logDebug( "======== Completed Execute VF-C adapter Post Process ======== ", isDebugEnabled)\r
+        }catch(Exception e){\r
+            taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Post Call. Exception is: \n" + e, isDebugEnabled)\r
+            throw new BpmnError("MSOWorkflowException")\r
+        }\r
+        return apiResponse\r
+    }\r
 }\r