* ============LICENSE_END=========================================================\r
*/\r
\r
-package org.openecomp.mso.bpmn.infrastructure.scripts;\r
+package org.openecomp.mso.bpmn.infrastructure.scripts\r
+\r
+import org.json.JSONObject\r
+import org.json.XML;\r
\r
import static org.apache.commons.lang3.StringUtils.*;\r
import groovy.xml.XmlUtil\r
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.ExceptionUtil\r
+import org.openecomp.mso.bpmn.common.recipe.ResourceInput;\r
+import org.openecomp.mso.bpmn.common.resource.ResourceRequestBuilder \r
import org.openecomp.mso.bpmn.core.WorkflowException \r
-import org.openecomp.mso.bpmn.core.json.JsonUtils \r
+import org.openecomp.mso.bpmn.core.json.JsonUtils\r
+import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder\r
import org.openecomp.mso.rest.APIResponse\r
+import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils\r
\r
import java.util.UUID;\r
\r
import org.camunda.bpm.engine.delegate.BpmnError \r
-import org.camunda.bpm.engine.runtime.Execution\r
+import org.camunda.bpm.engine.delegate.DelegateExecution\r
import org.apache.commons.lang3.*\r
import org.apache.commons.codec.binary.Base64;\r
import org.springframework.web.util.UriUtils \r
* This groovy class supports the <class>CreateSDNCCNetworkResource.bpmn</class> process.\r
* flow for SDNC Network Resource Create\r
*/\r
-public class CreateSDNCCNetworkResource extends AbstractServiceTaskProcessor {\r
+public class CreateSDNCNetworkResource extends AbstractServiceTaskProcessor {\r
\r
- String vfcUrl = "/vfc/rest/v1/vfcadapter"\r
- \r
- String host = "http://mso.mso.testlab.openecomp.org:8080"\r
- \r
+ String Prefix="CRESDNCRES_"\r
+ \r
ExceptionUtil exceptionUtil = new ExceptionUtil()\r
\r
JsonUtils jsonUtil = new JsonUtils()\r
+\r
+ SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()\r
+ \r
+ public void preProcessRequest(DelegateExecution execution){\r
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+ utils.log("INFO"," ***** Started preProcessRequest *****", isDebugEnabled)\r
+ try { \r
+ \r
+ //get bpmn inputs from resource request.\r
+ String requestId = execution.getVariable("mso-request-id")\r
+ String requestAction = execution.getVariable("requestAction")\r
+ utils.log("INFO","The requestAction is: " + requestAction, isDebugEnabled)\r
+ String recipeParamsFromRequest = execution.getVariable("recipeParams")\r
+ utils.log("INFO","The recipeParams is: " + recipeParamsFromRequest, isDebugEnabled)\r
+ String resourceInput = execution.getVariable("resourceInput")\r
+ utils.log("INFO","The resourceInput is: " + resourceInput, isDebugEnabled)\r
+ //Get ResourceInput Object\r
+ ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)\r
+ execution.setVariable(Prefix + "resourceInput", resourceInputObj)\r
+ \r
+ //Deal with recipeParams\r
+ String recipeParamsFromWf = execution.getVariable("recipeParamXsd")\r
+ String resourceName = resourceInputObj.getResourceInstanceName() \r
+ //For sdnc requestAction default is "createNetworkInstance"\r
+ String operationType = "Network" \r
+ if(!StringUtils.isBlank(recipeParamsFromRequest)){\r
+ //the operationType from worflow(first node) is second priority.\r
+ operationType = jsonUtil.getJsonValue(recipeParamsFromRequest, "operationType")\r
+ }\r
+ if(!StringUtils.isBlank(recipeParamsFromWf)){\r
+ //the operationType from worflow(first node) is highest priority.\r
+ operationType = jsonUtil.getJsonValue(recipeParamsFromWf, "operationType")\r
+ }\r
+ \r
+ \r
+ //For sdnc, generate svc_action and request_action\r
+ String sdnc_svcAction = "create"\r
+ if(StringUtils.containsIgnoreCase(resourceInputObj.getResourceInstanceName(), "overlay")){\r
+ //This will be resolved in R3.\r
+ sdnc_svcAction ="activate"\r
+ operationType = "NCINetwork" \r
+ }\r
+ if(StringUtils.containsIgnoreCase(resourceInputObj.getResourceInstanceName(), "underlay")){\r
+ //This will be resolved in R3.\r
+ operationType ="Network"\r
+ } \r
+ String sdnc_requestAction = StringUtils.capitalize(sdnc_svcAction) + operationType +"Instance" \r
+ execution.setVariable(Prefix + "svcAction", sdnc_svcAction) \r
+ execution.setVariable(Prefix + "requestAction", sdnc_requestAction)\r
+ execution.setVariable(Prefix + "serviceInstanceId", resourceInputObj.getServiceInstanceId())\r
+ execution.setVariable("mso-request-id", requestId)\r
+ execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId())\r
+ //TODO Here build networkrequest\r
+ \r
+ } catch (BpmnError e) {\r
+ throw e;\r
+ } catch (Exception ex){\r
+ msg = "Exception in preProcessRequest " + ex.getMessage()\r
+ utils.log("DEBUG", msg, isDebugEnabled)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
+ }\r
+ }\r
+\r
+ String customizeResourceParam(String netowrkInputParametersJson) {\r
+ List<Map<String, Object>> paramList = new ArrayList();\r
+ JSONObject jsonObject = new JSONObject(netowrkInputParametersJson);\r
+ Iterator iterator = jsonObject.keys();\r
+ while (iterator.hasNext()) {\r
+ String key = iterator.next();\r
+ HashMap<String, String> hashMap = new HashMap();\r
+ hashMap.put("name", key);\r
+ hashMap.put("value", jsonObject.get(key))\r
+ paramList.add(hashMap)\r
+ }\r
+ Map<String, List<Map<String, Object>>> paramMap = new HashMap();\r
+ paramMap.put("param", paramList);\r
+\r
+ return new JSONObject(paramMap).toString();\r
+ }\r
\r
/**\r
* Pre Process the BPMN Flow Request\r
* generate the nsOperationKey\r
* generate the nsParameters\r
*/\r
- public void preProcessRequest (Execution execution) {\r
- def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
- String msg = ""\r
- utils.log("INFO", " *** preProcessRequest() *** ", isDebugEnabled)\r
- try {\r
- //deal with nsName and Description\r
- String nsServiceName = execution.getVariable("nsServiceName")\r
- String nsServiceDescription = execution.getVariable("nsServiceDescription")\r
- utils.log("INFO", "nsServiceName:" + nsServiceName + " nsServiceDescription:" + nsServiceDescription, isDebugEnabled)\r
- //deal with operation key\r
- String globalSubscriberId = execution.getVariable("globalSubscriberId")\r
- utils.log("INFO", "globalSubscriberId:" + globalSubscriberId, isDebugEnabled)\r
- String serviceType = execution.getVariable("serviceType")\r
- utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)\r
- String serviceId = execution.getVariable("serviceId")\r
- utils.log("INFO", "serviceId:" + serviceId, isDebugEnabled)\r
- String operationId = execution.getVariable("operationId")\r
- utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)\r
- String nodeTemplateUUID = execution.getVariable("resourceUUID")\r
- utils.log("INFO", "nodeTemplateUUID:" + nodeTemplateUUID, isDebugEnabled)\r
- /*\r
- * segmentInformation needed as a object of segment\r
- * {\r
- * "domain":"",\r
- * "nodeTemplateName":"",\r
- * "nodeType":"",\r
- * "nsParameters":{\r
- * //this is the nsParameters sent to VF-C\r
- * }\r
- * }\r
- */\r
- String nsParameters = execution.getVariable("resourceParameters")\r
- utils.log("INFO", "nsParameters:" + nsParameters, isDebugEnabled)\r
- String nsOperationKey = """{\r
- "globalSubscriberId":"${globalSubscriberId}",\r
- "serviceType":"${serviceType}",\r
- "serviceId":"${serviceId}",\r
- "operationId":"${operationId}",\r
- "nodeTemplateUUID":"${nodeTemplateUUID}"\r
- }"""\r
- execution.setVariable("nsOperationKey", nsOperationKey);\r
- execution.setVariable("nsParameters", nsParameters)\r
- \r
-\r
- } catch (BpmnError e) {\r
- throw e;\r
- } catch (Exception ex){\r
- msg = "Exception in preProcessRequest " + ex.getMessage()\r
- utils.log("INFO", msg, isDebugEnabled)\r
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
- }\r
- utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)\r
+ public void prepareSDNCRequest (DelegateExecution execution) {\r
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+ utils.log("INFO"," ***** Started prepareSDNCRequest *****", isDebugEnabled)\r
+\r
+ try {\r
+ // get variables\r
+ String sdnc_svcAction = execution.getVariable(Prefix + "svcAction") \r
+ String sdnc_requestAction = execution.getVariable(Prefix + "requestAction")\r
+ String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")\r
+ String createNetworkInput = execution.getVariable(Prefix + "networkRequest")\r
+\r
+ String hdrRequestId = execution.getVariable("mso-request-id")\r
+ String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")\r
+ String source = execution.getVariable("source")\r
+ String sdnc_service_id = execution.getVariable(Prefix + "sdncServiceId")\r
+ ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")\r
+ String serviceType = resourceInputObj.getServiceType()\r
+ String serviceModelInvariantUuid = resourceInputObj.getServiceModelInfo().getModelInvariantUuid()\r
+ String serviceModelUuid = resourceInputObj.getServiceModelInfo().getModelUuid()\r
+ String serviceModelVersion = resourceInputObj.getServiceModelInfo().getModelVersion()\r
+ String serviceModelName = resourceInputObj.getServiceModelInfo().getModelName()\r
+ String globalCustomerId = resourceInputObj.getGlobalSubscriberId()\r
+ String modelInvariantUuid = resourceInputObj.getResourceModelInfo().getModelInvariantUuid();\r
+ String modelCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()\r
+ String modelUuid = resourceInputObj.getResourceModelInfo().getModelUuid()\r
+ String modelName = resourceInputObj.getResourceModelInfo().getModelName()\r
+ String modelVersion = resourceInputObj.getResourceModelInfo().getModelVersion()\r
+ String resourceInputPrameters = resourceInputObj.getResourceParameters()\r
+ String netowrkInputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs")\r
+ //here convert json string to xml string\r
+ String netowrkInputParameters = XML.toString(new JSONObject(customizeResourceParam(netowrkInputParametersJson)))\r
+ // 1. prepare assign topology via SDNC Adapter SUBFLOW call\r
+ String sndcTopologyCreateRequest =\r
+ """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
+ xmlns:sdncadapter="http://org.openecomp.mso/workflow/sdnc/adapter/schema/v1" \r
+ xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1">\r
+ <sdncadapter:RequestHeader>\r
+ <sdncadapter:RequestId>${hdrRequestId}</sdncadapter:RequestId>\r
+ <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>\r
+ <sdncadapter:SvcAction>${sdnc_svcAction}</sdncadapter:SvcAction>\r
+ <sdncadapter:SvcOperation>network-topology-operation</sdncadapter:SvcOperation>\r
+ <sdncadapter:CallbackUrl>sdncCallback</sdncadapter:CallbackUrl>\r
+ <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>\r
+ </sdncadapter:RequestHeader>\r
+ <sdncadapterworkflow:SDNCRequestData>\r
+ <request-information>\r
+ <request-id>${hdrRequestId}</request-id>\r
+ <request-action>${sdnc_requestAction}</request-action>\r
+ <source>${source}</source>\r
+ <notification-url></notification-url>\r
+ <order-number></order-number>\r
+ <order-version></order-version>\r
+ </request-information>\r
+ <service-information>\r
+ <service-id>${serviceInstanceId}</service-id>\r
+ <subscription-service-type>${serviceType}</subscription-service-type>\r
+ <onap-model-information>\r
+ <model-invariant-uuid>${serviceModelInvariantUuid}</model-invariant-uuid>\r
+ <model-uuid>${serviceModelUuid}</model-uuid>\r
+ <model-version>${serviceModelVersion}</model-version>\r
+ <model-name>${serviceModelName}</model-name>\r
+ </onap-model-information>\r
+ <service-instance-id>${serviceInstanceId}</service-instance-id>\r
+ <global-customer-id>${globalCustomerId}</global-customer-id>\r
+ </service-information>\r
+ <network-information>\r
+ <onap-model-information>\r
+ <model-invariant-uuid>${modelInvariantUuid}</model-invariant-uuid>\r
+ <model-customization-uuid>${modelCustomizationUuid}</model-customization-uuid>\r
+ <model-uuid>${modelUuid}</model-uuid>\r
+ <model-version>${modelVersion}</model-version>\r
+ <model-name>${modelName}</model-name>\r
+ </onap-model-information>\r
+ </network-information>\r
+ <network-request-input>\r
+ <network-input-parameters>${netowrkInputParameters}</network-input-parameters>\r
+ </network-request-input>\r
+ </sdncadapterworkflow:SDNCRequestData>\r
+ </aetgt:SDNCAdapterWorkflowRequest>""".trim()\r
+ \r
+ String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)\r
+ utils.logAudit(sndcTopologyCreateRequesAsString)\r
+ execution.setVariable("sdncAdapterWorkflowRequest", sndcTopologyCreateRequesAsString)\r
+ utils.log("DEBUG","sdncAdapterWorkflowRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)\r
+\r
+ } catch (Exception ex) {\r
+ String exceptionMessage = " Bpmn error encountered in CreateSDNCCNetworkResource flow. prepareSDNCRequest() - " + ex.getMessage()\r
+ utils.log("DEBUG", exceptionMessage, isDebugEnabled)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
+\r
+ }\r
+ utils.log("INFO"," ***** Exit prepareSDNCRequest *****", isDebugEnabled)\r
}\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(Execution execution, String url, String requestBody){\r
- def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
- utils.log("INFO"," ***** Started Execute VFC adapter Post Process *****", isDebugEnabled)\r
- utils.log("INFO","url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled)\r
- APIResponse apiResponse = null\r
- try{\r
- RESTConfig config = new RESTConfig(url);\r
- RESTClient client = new RESTClient(config).addHeader("Content-Type", "application/json").addHeader("Accept","application/json").addHeader("Authorization","Basic QlBFTENsaWVudDpwYXNzd29yZDEk");\r
- apiResponse = client.httpPost(requestBody)\r
- utils.log("INFO","response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString(), isDebugEnabled) \r
- utils.log("INFO","======== Completed Execute VF-C adapter Post Process ======== ", isDebugEnabled)\r
- }catch(Exception e){\r
- 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
+ private void setProgressUpdateVariables(DelegateExecution execution, String body) {\r
+ def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")\r
+ execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
+ execution.setVariable("CVFMI_updateResOperStatusRequest", body)\r
}\r
- \r
- public void postCreateSDNCCall(Execution execution){\r
+\r
+ public void prepareUpdateBeforeCreateSDNCResource(DelegateExecution execution) {\r
+ ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")\r
+ String operType = resourceInputObj.getOperationType()\r
+ String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()\r
+ String ServiceInstanceId = resourceInputObj.getServiceInstanceId()\r
+ String operationId = resourceInputObj.getOperationId()\r
+ String progress = "20"\r
+ String status = "processing"\r
+ String statusDescription = "SDCN resource creation invoked"\r
+\r
+ execution.getVariable("operationId")\r
+\r
+ String body = """\r
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
+ xmlns:ns="http://org.openecomp.mso/requestsdb">\r
+ <soapenv:Header/>\r
+ <soapenv:Body>\r
+ <ns:updateResourceOperationStatus>\r
+ <operType>${operType}</operType>\r
+ <operationId>${operationId}</operationId>\r
+ <progress>${progress}</progress>\r
+ <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>\r
+ <serviceId>${ServiceInstanceId}</serviceId>\r
+ <status>${status}</status>\r
+ <statusDescription>${statusDescription}</statusDescription>\r
+ </ns:updateResourceOperationStatus>\r
+ </soapenv:Body>\r
+ </soapenv:Envelope>""";\r
+\r
+ setProgressUpdateVariables(execution, body)\r
+\r
+ }\r
+\r
+ public void prepareUpdateAfterCreateSDNCResource(execution) {\r
+ ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")\r
+ String operType = resourceInputObj.getOperationType()\r
+ String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()\r
+ String ServiceInstanceId = resourceInputObj.getServiceInstanceId()\r
+ String operationId = resourceInputObj.getOperationId()\r
+ String progress = "100"\r
+ String status = "finished"\r
+ String statusDescription = "SDCN resource creation completed"\r
+\r
+ execution.getVariable("operationId")\r
+\r
+ String body = """\r
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
+ xmlns:ns="http://org.openecomp.mso/requestsdb">\r
+ <soapenv:Header/>\r
+ <soapenv:Body>\r
+ <ns:updateResourceOperationStatus>\r
+ <operType>${operType}</operType>\r
+ <operationId>${operationId}</operationId>\r
+ <progress>${progress}</progress>\r
+ <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>\r
+ <serviceId>${ServiceInstanceId}</serviceId>\r
+ <status>${status}</status>\r
+ <statusDescription>${statusDescription}</statusDescription>\r
+ </ns:updateResourceOperationStatus>\r
+ </soapenv:Body>\r
+ </soapenv:Envelope>""";\r
+\r
+ setProgressUpdateVariables(execution, body)\r
+ }\r
+\r
+ public void postCreateSDNCCall(DelegateExecution execution){\r
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+ utils.log("INFO"," ***** Started prepareSDNCRequest *****", isDebugEnabled)\r
+ String responseCode = execution.getVariable(Prefix + "sdncCreateReturnCode")\r
+ String responseObj = execution.getVariable(Prefix + "SuccessIndicator")\r
\r
+ utils.log("INFO","response from sdnc, response code :" + responseCode + " response object :" + responseObj, isDebugEnabled)\r
+ utils.log("INFO"," ***** Exit prepareSDNCRequest *****", isDebugEnabled)\r
}\r
+ \r
+ public void sendSyncResponse (DelegateExecution execution) {\r
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+ utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)\r
+\r
+ try {\r
+ String operationStatus = "finished"\r
+ // RESTResponse for main flow\r
+ String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()\r
+ utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + resourceOperationResp, isDebugEnabled)\r
+ sendWorkflowResponse(execution, 202, resourceOperationResp)\r
+ execution.setVariable("sentSyncResponse", true)\r
+\r
+ } catch (Exception ex) {\r
+ String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()\r
+ utils.log("DEBUG", msg, isDebugEnabled)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
+ }\r
+ utils.log("DEBUG"," ***** Exit sendSyncResopnse *****", isDebugEnabled)\r
+ }\r
}\r