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
\r
import java.util.UUID;\r
*/\r
public class CreateSDNCCNetworkResource 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
+ 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("requestId")\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: " + recipeParams, isDebugEnabled)\r
+ String resourceInput = execution.getVariable("requestInput")\r
+ utils.log("INFO","The resourceInput is: " + resourceInput, isDebugEnabled)\r
+ //Get ResourceInput Object\r
+ ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, resourceInputObj)\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
+ \r
/**\r
* Pre Process the BPMN Flow Request\r
* Inclouds:\r
* generate the nsOperationKey\r
* generate the nsParameters\r
*/\r
- public void preProcessRequest (DelegateExecution 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
+ 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 serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")\r
+ \r
+ // 1. prepare assign topology via SDNC Adapter SUBFLOW call\r
+ String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, sdnc_svcAction, sdnc_requestAction, null, null, null)\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
+ String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)\r
+ utils.logAudit(sndcTopologyCreateRequesAsString)\r
+ execution.setVariable(Prefix + "createSDNCRequest", sndcTopologyCreateRequesAsString)\r
+ utils.log("DEBUG", Prefix + "createSDNCRequest - " + "\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(DelegateExecution 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
- }\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
<bpmn:startEvent id="createNS_StartEvent" name="createNS_StartEvent">
<bpmn:outgoing>SequenceFlow_1qo2pln</bpmn:outgoing>
</bpmn:startEvent>
- <bpmn:sequenceFlow id="SequenceFlow_1qo2pln" sourceRef="createNS_StartEvent" targetRef="PreprocessIncomingRequest_task" />
+ <bpmn:sequenceFlow id="SequenceFlow_1qo2pln" sourceRef="createNS_StartEvent" targetRef="Task_1dlrfiw" />
<bpmn:sequenceFlow id="SequenceFlow_0khtova" sourceRef="PreprocessIncomingRequest_task" targetRef="CallActivity_1600xlj" />
- <bpmn:scriptTask id="PreprocessIncomingRequest_task" name="Preprocess Incoming Request" scriptFormat="groovy">
- <bpmn:incoming>SequenceFlow_1qo2pln</bpmn:incoming>
+ <bpmn:scriptTask id="PreprocessIncomingRequest_task" name="prepare SDNC Request" scriptFormat="groovy">
+ <bpmn:incoming>SequenceFlow_18l3crb</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_0khtova</bpmn:outgoing>
<bpmn:script><![CDATA[import org.openecomp.mso.bpmn.infrastructure.scripts.*
def dcsi = new CreateSDNCNetworkResource()
-dcsi.preProcessRequest(execution)]]></bpmn:script>
+dcsi.prepareSDNCRequest(execution)]]></bpmn:script>
</bpmn:scriptTask>
<bpmn:endEvent id="EndEvent_1x6k78c" name="create SDNC call end">
<bpmn:incoming>SequenceFlow_0ow44q0</bpmn:incoming>
</bpmn:endEvent>
<bpmn:callActivity id="CallActivity_1600xlj" name="Call SDNC RSRC Create Adapter V1 " calledElement="sdncAdapter">
<bpmn:extensionElements>
- <camunda:in source="CRENWKI_activateSDNCRequest" target="sdncAdapterWorkflowRequest" />
+ <camunda:in source="CRESDNCRES_activateSDNCRequest" target="sdncAdapterWorkflowRequest" />
<camunda:in source="mso-request-id" target="mso-request-id" />
<camunda:in source="mso-service-instance-id" target="mso-service-instance-id" />
<camunda:out source="sdncAdapterResponse" target="CRENWKI_activateSDNCResponse" />
- <camunda:out source="SDNCA_ResponseCode" target="CRENWKI_sdncActivateReturnCode" />
- <camunda:out source="SDNCA_SuccessIndicator" target="SDNCA_SuccessIndicator" />
+ <camunda:out source="SDNCA_ResponseCode" target="CRESDNCRES_sdncCreateReturnCode" />
+ <camunda:out source="SDNCA_SuccessIndicator" target="CRESDNCRES_SuccessIndicator" />
<camunda:out source="WorkflowException" target="WorkflowException" />
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_0khtova</bpmn:incoming>
def dcsi = new CreateSDNCNetworkResource()
dcsi.postCreateSDNCCall(execution)]]></bpmn:script>
</bpmn:scriptTask>
+ <bpmn:sequenceFlow id="SequenceFlow_0w2es8j" sourceRef="Task_1dlrfiw" targetRef="Task_13sx2bp" />
+ <bpmn:sequenceFlow id="SequenceFlow_18l3crb" sourceRef="Task_13sx2bp" targetRef="PreprocessIncomingRequest_task" />
+ <bpmn:scriptTask id="Task_1dlrfiw" name="Set the Recipe DesignTimeParam" scriptFormat="groovy">
+ <bpmn:incoming>SequenceFlow_1qo2pln</bpmn:incoming>
+ <bpmn:outgoing>SequenceFlow_0w2es8j</bpmn:outgoing>
+ <bpmn:script><![CDATA[String recipeParamXsdDemo="""{"operationType":"GRE"}"""
+String recipeParamXsd=""
+execution.setVariable("recipeParamXsd", recipeParamXsd)]]></bpmn:script>
+ </bpmn:scriptTask>
+ <bpmn:scriptTask id="Task_13sx2bp" name="Pre Process Request" scriptFormat="groovy">
+ <bpmn:incoming>SequenceFlow_0w2es8j</bpmn:incoming>
+ <bpmn:outgoing>SequenceFlow_18l3crb</bpmn:outgoing>
+ <bpmn:script><![CDATA[import org.openecomp.mso.bpmn.infrastructure.scripts.*
+def dcsi = new CreateSDNCNetworkResource()
+dcsi.preProcessRequest(execution)]]></bpmn:script>
+ </bpmn:scriptTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="CreateSDNCNetworkResource">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="createNS_StartEvent">
- <dc:Bounds x="175" y="111" width="36" height="36" />
+ <dc:Bounds x="80" y="111" width="36" height="36" />
<bpmndi:BPMNLabel>
- <dc:Bounds x="152" y="147" width="83" height="24" />
+ <dc:Bounds x="57" y="147" width="83" height="24" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1qo2pln_di" bpmnElement="SequenceFlow_1qo2pln">
- <di:waypoint xsi:type="dc:Point" x="211" y="129" />
- <di:waypoint xsi:type="dc:Point" x="251" y="129" />
- <di:waypoint xsi:type="dc:Point" x="251" y="129" />
- <di:waypoint xsi:type="dc:Point" x="293" y="129" />
+ <di:waypoint xsi:type="dc:Point" x="116" y="129" />
+ <di:waypoint xsi:type="dc:Point" x="185" y="129" />
<bpmndi:BPMNLabel>
- <dc:Bounds x="266" y="123" width="0" height="12" />
+ <dc:Bounds x="105.5" y="108" width="90" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_0khtova_di" bpmnElement="SequenceFlow_0khtova">
- <di:waypoint xsi:type="dc:Point" x="393" y="129" />
- <di:waypoint xsi:type="dc:Point" x="544" y="129" />
+ <di:waypoint xsi:type="dc:Point" x="677" y="129" />
+ <di:waypoint xsi:type="dc:Point" x="739" y="129" />
<bpmndi:BPMNLabel>
- <dc:Bounds x="423.5" y="108" width="90" height="12" />
+ <dc:Bounds x="663" y="108" width="90" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="ScriptTask_03j6ogo_di" bpmnElement="PreprocessIncomingRequest_task">
- <dc:Bounds x="293" y="89" width="100" height="80" />
+ <dc:Bounds x="577" y="89" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_15pcuuc_di" bpmnElement="EndEvent_1x6k78c">
- <dc:Bounds x="951" y="111" width="36" height="36" />
+ <dc:Bounds x="1079" y="111" width="36" height="36" />
<bpmndi:BPMNLabel>
- <dc:Bounds x="912" y="153" width="85" height="24" />
+ <dc:Bounds x="1040" y="153" width="85" height="24" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="CallActivity_1600xlj_di" bpmnElement="CallActivity_1600xlj">
- <dc:Bounds x="544" y="89" width="100" height="80" />
+ <dc:Bounds x="739" y="89" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1xk5xed_di" bpmnElement="SequenceFlow_1xk5xed">
- <di:waypoint xsi:type="dc:Point" x="644" y="129" />
- <di:waypoint xsi:type="dc:Point" x="800" y="129" />
+ <di:waypoint xsi:type="dc:Point" x="839" y="129" />
+ <di:waypoint xsi:type="dc:Point" x="902" y="129" />
<bpmndi:BPMNLabel>
- <dc:Bounds x="677" y="108" width="90" height="12" />
+ <dc:Bounds x="825.5" y="108" width="90" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_0ow44q0_di" bpmnElement="SequenceFlow_0ow44q0">
- <di:waypoint xsi:type="dc:Point" x="900" y="129" />
- <di:waypoint xsi:type="dc:Point" x="951" y="129" />
+ <di:waypoint xsi:type="dc:Point" x="1002" y="129" />
+ <di:waypoint xsi:type="dc:Point" x="1079" y="129" />
<bpmndi:BPMNLabel>
- <dc:Bounds x="880.5" y="108" width="90" height="12" />
+ <dc:Bounds x="995.5" y="108" width="90" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="ScriptTask_0gyej62_di" bpmnElement="Task_023hred">
- <dc:Bounds x="800" y="89" width="100" height="80" />
+ <dc:Bounds x="902" y="89" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNEdge id="SequenceFlow_0w2es8j_di" bpmnElement="SequenceFlow_0w2es8j">
+ <di:waypoint xsi:type="dc:Point" x="285" y="129" />
+ <di:waypoint xsi:type="dc:Point" x="385" y="129" />
+ <bpmndi:BPMNLabel>
+ <dc:Bounds x="335" y="108" width="0" height="12" />
+ </bpmndi:BPMNLabel>
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="SequenceFlow_18l3crb_di" bpmnElement="SequenceFlow_18l3crb">
+ <di:waypoint xsi:type="dc:Point" x="485" y="129" />
+ <di:waypoint xsi:type="dc:Point" x="577" y="129" />
+ <bpmndi:BPMNLabel>
+ <dc:Bounds x="531" y="108" width="0" height="12" />
+ </bpmndi:BPMNLabel>
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNShape id="ScriptTask_0lc6l7a_di" bpmnElement="Task_1dlrfiw">
+ <dc:Bounds x="185" y="89" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="ScriptTask_14l9mlv_di" bpmnElement="Task_13sx2bp">
+ <dc:Bounds x="385" y="89" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>