From 22b44b9884ca367050e96045e2dcd9675cb605cd Mon Sep 17 00:00:00 2001 From: c00149107 Date: Fri, 22 Sep 2017 10:31:09 +0800 Subject: Add generic post function Add generic post function and correct the api define Change-Id: I11c2a10f4aad00f389b68cf7b9c42dab4441027c Issue-ID:SO-57 Signed-off-by: c00149107 --- .../mso-vfc-adapter/WebContent/WEB-INF/web.xml | 2 +- .../openecomp/mso/adapters/vfc/VfcAdapterRest.java | 2 +- .../DoCreateVFCNetworkServiceInstance.groovy | 43 ++++++++++++++++++---- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml b/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml index 5bf8864351..160dfb81bf 100644 --- a/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml +++ b/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml @@ -38,7 +38,7 @@ Resteasy - /rest/* + /vfcadapter/* diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java index f4c295337a..684933f3a9 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java @@ -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); diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVFCNetworkServiceInstance.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVFCNetworkServiceInstance.groovy index 4a7f4745bc..43a2731eb6 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVFCNetworkServiceInstance.groovy +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVFCNetworkServiceInstance.groovy @@ -25,7 +25,6 @@ import groovy.xml.XmlUtil import groovy.json.* import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil -import org.openecomp.mso.bpmn.common.scripts.VidUtils import org.openecomp.mso.bpmn.core.WorkflowException import org.openecomp.mso.bpmn.core.json.JsonUtils import org.openecomp.mso.rest.APIResponse @@ -36,7 +35,10 @@ import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.runtime.Execution import org.apache.commons.lang3.* import org.apache.commons.codec.binary.Base64; -import org.springframework.web.util.UriUtils +import org.springframework.web.util.UriUtils +import org.openecomp.mso.rest.RESTClient +import org.openecomp.mso.rest.RESTConfig +import org.openecomp.mso.rest.APIResponse; /** * This groovy class supports the CreateGenericE2EServiceInstance.bpmn process. @@ -44,18 +46,21 @@ import org.springframework.web.util.UriUtils */ public class CreateGenericE2EServiceInstance extends AbstractServiceTaskProcessor { + String createUrl = "/vfc/vfcadapters/v1/ns" + + String instantiateUrl = "/vfcvfcadatpers/v1/ns/{nsInstanceId}/instantiate" + + String queryJobUrl = "/vfc/vfcadatpers/v1/jobs/{jobId}" + ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() - VidUtils vidUtils = new VidUtils() - /** * Pre Process the BPMN Flow Request * Inclouds: - * Deal with the parameters - * generate the service instance id - * generate the operation id + * generate the nsOperationKey + * generate the nsParameters */ public void preProcessRequest (Execution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") @@ -101,8 +106,8 @@ public class CreateGenericE2EServiceInstance extends AbstractServiceTaskProcesso utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled) } - public void createNetworkService(Execution execution) { + } public void instantiateNetworkService(Execution execution) { @@ -116,4 +121,26 @@ public class CreateGenericE2EServiceInstance extends AbstractServiceTaskProcesso public void finishNSCreate(Execution execution) { } + + /** + * post request + * url: the url of the request + * requestBody: the body of the request + */ + private APIResponse postRequest(String url, String requestBody){ + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + taskProcessor.logDebug( " ======== Started Execute VFC adapter Post Process ======== ", isDebugEnabled) + taskProcessor.logDebug( "url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled) + APIResponse apiResponse = null + try{ + RESTConfig config = new RESTConfig(url); + RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/json"); + apiResponse = client.httpPost(requestBody) + taskProcessor.logDebug( "======== Completed Execute VF-C adapter Post Process ======== ", isDebugEnabled) + }catch(Exception e){ + taskProcessor.utils.log("ERROR", "Exception occured while executing AAI Post Call. Exception is: \n" + e, isDebugEnabled) + throw new BpmnError("MSOWorkflowException") + } + return apiResponse + } } -- cgit 1.2.3-korg