From 3091f88155228e1648b690994c21e8be6dfba701 Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Mon, 6 Aug 2018 17:35:33 +0530 Subject: Provide implementation for activate methods Provide implementation for activate bpmn flow methods. Change-Id: I282d7bc7899f722a6d8e27bb9054bbe5b6d21d44 Issue-ID: SO-689 Signed-off-by: subhash kumar singh --- .../scripts/ActivateSDNCNetworkResource.groovy | 196 +++++++++++++++++++++ .../scripts/CreateSDNCNetworkResource.groovy | 8 +- .../subprocess/ActivateSDNCNetworkResource.bpmn | 33 +++- 3 files changed, 224 insertions(+), 13 deletions(-) diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSDNCNetworkResource.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSDNCNetworkResource.groovy index ef99546214..e034393151 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSDNCNetworkResource.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSDNCNetworkResource.groovy @@ -20,6 +20,12 @@ package org.openecomp.mso.bpmn.infrastructure.scripts +import org.apache.commons.lang3.StringUtils +import org.camunda.bpm.engine.delegate.BpmnError +import org.json.JSONObject +import org.json.XML +import org.onap.so.bpmn.common.recipe.ResourceInput +import org.onap.so.bpmn.common.resource.ResourceRequestBuilder import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.bpmn.core.json.JsonUtils @@ -44,17 +50,207 @@ public class ActivateSDNCNetworkResource extends AbstractServiceTaskProcessor { public void preProcessRequest(DelegateExecution execution) { msoLogger.trace("Started preProcessRequest ") + + try { + //get bpmn inputs from resource request. + String requestId = execution.getVariable("mso-request-id") + String requestAction = execution.getVariable("requestAction") + msoLogger.info("The requestAction is: " + requestAction) + String recipeParamsFromRequest = execution.getVariable("recipeParams") + msoLogger.info("The recipeParams is: " + recipeParamsFromRequest) + String resourceInput = execution.getVariable("resourceInput") + msoLogger.info("The resourceInput is: " + resourceInput) + //Get ResourceInput Object + ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class) + execution.setVariable(Prefix + "resourceInput", resourceInputObj) + + //Deal with recipeParams + String recipeParamsFromWf = execution.getVariable("recipeParamXsd") + String resourceName = resourceInputObj.getResourceInstanceName() + //For sdnc requestAction default is "createNetworkInstance" + String operationType = "Network" + if(!StringUtils.isBlank(recipeParamsFromRequest)){ + //the operationType from worflow(first node) is second priority. + operationType = jsonUtil.getJsonValue(recipeParamsFromRequest, "operationType") + } + if(!StringUtils.isBlank(recipeParamsFromWf)){ + //the operationType from worflow(first node) is highest priority. + operationType = jsonUtil.getJsonValue(recipeParamsFromWf, "operationType") + } + + String sdnc_svcAction = "activate" + operationType = "SOTNConnectivity" + + String sdnc_requestAction = StringUtils.capitalize(sdnc_svcAction) + operationType +"Instance" + execution.setVariable(Prefix + "svcAction", sdnc_svcAction) + execution.setVariable(Prefix + "requestAction", sdnc_requestAction) + execution.setVariable(Prefix + "serviceInstanceId", resourceInputObj.getServiceInstanceId()) + execution.setVariable("mso-request-id", requestId) + execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId()) + } catch (BpmnError e) { + throw e; + } catch (Exception ex){ + msg = "Exception in preProcessRequest " + ex.getMessage() + msoLogger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } } public void prepareUpdateAfterActivateSDNCResource(DelegateExecution execution) { msoLogger.trace("started prepareUpdateAfterActivateSDNCResource ") + + ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput") + String operType = resourceInputObj.getOperationType() + String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid() + String ServiceInstanceId = resourceInputObj.getServiceInstanceId() + String operationId = resourceInputObj.getOperationId() + String progress = "100" + String status = "finished" + String statusDescription = "SDCN resource creation completed" + + execution.getVariable("operationId") + + String body = """ + + + + + ${MsoUtils.xmlEscape(operType)} + ${MsoUtils.xmlEscape(operationId)} + ${MsoUtils.xmlEscape(progress)} + ${MsoUtils.xmlEscape(resourceCustomizationUuid)} + ${MsoUtils.xmlEscape(ServiceInstanceId)} + ${MsoUtils.xmlEscape(status)} + ${MsoUtils.xmlEscape(statusDescription)} + + + """; + + setProgressUpdateVariables(execution, body) + } + + public void prepareSDNCRequest (DelegateExecution execution) { + msoLogger.trace("Started prepareSDNCRequest ") + + try { + // get variables + String sdnc_svcAction = execution.getVariable(Prefix + "svcAction") + String sdnc_requestAction = execution.getVariable(Prefix + "requestAction") + String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback") + String createNetworkInput = execution.getVariable(Prefix + "networkRequest") + + String hdrRequestId = execution.getVariable("mso-request-id") + String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId") + String source = execution.getVariable("source") + String sdnc_service_id = execution.getVariable(Prefix + "sdncServiceId") + ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput") + String serviceType = resourceInputObj.getServiceType() + String serviceModelInvariantUuid = resourceInputObj.getServiceModelInfo().getModelInvariantUuid() + String serviceModelUuid = resourceInputObj.getServiceModelInfo().getModelUuid() + String serviceModelVersion = resourceInputObj.getServiceModelInfo().getModelVersion() + String serviceModelName = resourceInputObj.getServiceModelInfo().getModelName() + String globalCustomerId = resourceInputObj.getGlobalSubscriberId() + String modelInvariantUuid = resourceInputObj.getResourceModelInfo().getModelInvariantUuid(); + String modelCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid() + String modelUuid = resourceInputObj.getResourceModelInfo().getModelUuid() + String modelName = resourceInputObj.getResourceModelInfo().getModelName() + String modelVersion = resourceInputObj.getResourceModelInfo().getModelVersion() + String resourceInputPrameters = resourceInputObj.getResourceParameters() + String networkInputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs") + //here convert json string to xml string + String netowrkInputParameters = XML.toString(new JSONObject(customizeResourceParam(networkInputParametersJson))) + // 1. prepare assign topology via SDNC Adapter SUBFLOW call + String sndcTopologyCreateRequest = + """ + + ${MsoUtils.xmlEscape(hdrRequestId)} + ${MsoUtils.xmlEscape(serviceInstanceId)} + ${MsoUtils.xmlEscape(sdnc_svcAction)} + network-topology-operation + sdncCallback + generic-resource + + + + ${MsoUtils.xmlEscape(hdrRequestId)} + ${MsoUtils.xmlEscape(sdnc_requestAction)} + ${MsoUtils.xmlEscape(source)} + + + + + + ${MsoUtils.xmlEscape(serviceInstanceId)} + ${MsoUtils.xmlEscape(serviceType)} + + ${MsoUtils.xmlEscape(serviceModelInvariantUuid)} + ${MsoUtils.xmlEscape(serviceModelUuid)} + ${MsoUtils.xmlEscape(serviceModelVersion)} + ${MsoUtils.xmlEscape(serviceModelName)} + + ${MsoUtils.xmlEscape(serviceInstanceId)} + ${MsoUtils.xmlEscape(globalCustomerId)} + + + + ${MsoUtils.xmlEscape(modelInvariantUuid)} + ${MsoUtils.xmlEscape(modelCustomizationUuid)} + ${MsoUtils.xmlEscape(modelUuid)} + ${MsoUtils.xmlEscape(modelVersion)} + ${MsoUtils.xmlEscape(modelName)} + + + + ${MsoUtils.xmlEscape(netowrkInputParameters)} + + + """.trim() + + String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest) + msoLogger.debug(sndcTopologyCreateRequesAsString) + execution.setVariable("sdncAdapterWorkflowRequest", sndcTopologyCreateRequesAsString) + msoLogger.debug("sdncAdapterWorkflowRequest - " + "\n" + sndcTopologyCreateRequesAsString) + + } catch (Exception ex) { + String exceptionMessage = " Bpmn error encountered in CreateSDNCCNetworkResource flow. prepareSDNCRequest() - " + ex.getMessage() + msoLogger.debug(exceptionMessage) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) + + } + msoLogger.trace("Exit prepareSDNCRequest ") } public void postCreateSDNCCall(DelegateExecution execution) { msoLogger.trace("started postCreateSDNCCall ") + + String responseCode = execution.getVariable(Prefix + "sdncCreateReturnCode") + String responseObj = execution.getVariable(Prefix + "SuccessIndicator") + + msoLogger.info("response from sdnc, response code :" + responseCode + " response object :" + responseObj) } public void sendSyncResponse(DelegateExecution execution) { msoLogger.trace("started sendSyncResponse ") + + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled) + + try { + String operationStatus = "finished" + // RESTResponse for main flow + String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim() + utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + resourceOperationResp, isDebugEnabled) + sendWorkflowResponse(execution, 202, resourceOperationResp) + execution.setVariable("sentSyncResponse", true) + + } catch (Exception ex) { + String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," ***** Exit sendSyncResopnse *****", isDebugEnabled) } } \ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSDNCNetworkResource.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSDNCNetworkResource.groovy index 1c0975f8c4..cc0f9bb5f4 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSDNCNetworkResource.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSDNCNetworkResource.groovy @@ -109,9 +109,9 @@ public class CreateSDNCNetworkResource extends AbstractServiceTaskProcessor { } } - String customizeResourceParam(String netowrkInputParametersJson) { + String customizeResourceParam(String networkInputParametersJson) { List> paramList = new ArrayList(); - JSONObject jsonObject = new JSONObject(netowrkInputParametersJson); + JSONObject jsonObject = new JSONObject(networkInputParametersJson); Iterator iterator = jsonObject.keys(); while (iterator.hasNext()) { String key = iterator.next(); @@ -159,9 +159,9 @@ public class CreateSDNCNetworkResource extends AbstractServiceTaskProcessor { String modelName = resourceInputObj.getResourceModelInfo().getModelName() String modelVersion = resourceInputObj.getResourceModelInfo().getModelVersion() String resourceInputPrameters = resourceInputObj.getResourceParameters() - String netowrkInputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs") + String networkInputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs") //here convert json string to xml string - String netowrkInputParameters = XML.toString(new JSONObject(customizeResourceParam(netowrkInputParametersJson))) + String netowrkInputParameters = XML.toString(new JSONObject(customizeResourceParam(networkInputParametersJson))) // 1. prepare assign topology via SDNC Adapter SUBFLOW call String sndcTopologyCreateRequest = """ - SequenceFlow_18l3crb + SequenceFlow_0sjrnv5 SequenceFlow_1xk5xed @@ -30,7 +30,7 @@ def dcsi = new ActivateSDNCNetworkResource() dcsi.postCreateSDNCCall(execution) - + SequenceFlow_1c92ks3 SequenceFlow_18l3crb @@ -78,13 +78,21 @@ csi.sendSyncResponse(execution) + + SequenceFlow_18l3crb + SequenceFlow_0sjrnv5 + import org.openecomp.mso.bpmn.infrastructure.scripts.* +def dcsi = new ActivateSDNCNetworkResource() +dcsi.prepareSDNCRequest(execution) + + - + - + @@ -114,14 +122,14 @@ csi.sendSyncResponse(execution) - - + + - + @@ -154,8 +162,15 @@ csi.sendSyncResponse(execution) - - + + + + + + + + + -- cgit 1.2.3-korg