diff options
Diffstat (limited to 'bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp')
8 files changed, 3887 insertions, 0 deletions
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/CreateVcpeResCustService.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/CreateVcpeResCustService.groovy new file mode 100644 index 0000000000..3b24ebf544 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/CreateVcpeResCustService.groovy @@ -0,0 +1,883 @@ +/*
+ * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
+ */
+package org.openecomp.mso.bpmn.vcpe.scripts;
+
+import groovy.xml.XmlUtil
+import groovy.json.*
+
+import org.openecomp.mso.bpmn.core.json.JsonUtils
+import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
+import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
+import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
+import org.openecomp.mso.bpmn.common.scripts.VidUtils
+import org.openecomp.mso.bpmn.core.RollbackData
+import org.openecomp.mso.bpmn.core.WorkflowException
+import org.openecomp.mso.bpmn.core.domain.*
+
+import java.util.UUID;
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.runtime.Execution
+import org.json.JSONObject;
+import org.json.JSONArray;
+import org.apache.commons.lang3.*
+import org.apache.commons.codec.binary.Base64;
+import org.springframework.web.util.UriUtils;
+
+/**
+ * This groovy class supports the <class>CreateVcpeResCustService.bpmn</class> process.
+ *
+ * @author ek1439
+ *
+ */
+public class CreateVcpeResCustService extends AbstractServiceTaskProcessor {
+
+ String Prefix="CVRCS_"
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+ VidUtils vidUtils = new VidUtils()
+ CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
+
+ /**
+ * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
+ * @param execution
+ */
+ public InitializeProcessVariables(Execution execution){
+ /* Initialize all the process variables in this block */
+
+ execution.setVariable("createVcpeServiceRequest", "")
+ execution.setVariable("globalSubscriberId", "")
+ execution.setVariable("serviceInstanceName", "")
+ execution.setVariable("msoRequestId", "")
+ execution.setVariable("CVRCS_NetworksCreatedCount", 0)
+ execution.setVariable("CVRCS_VnfsCreatedCount", 0)
+ execution.setVariable("productFamilyId", "")
+ execution.setVariable("brgWanMacAddress", "")
+
+ //TODO
+ execution.setVariable("sdncVersion", "1707")
+ }
+
+ // **************************************************
+ // Pre or Prepare Request Section
+ // **************************************************
+ /**
+ * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
+ * @param execution
+ */
+ public void preProcessRequest (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ execution.setVariable("prefix",Prefix)
+
+ utils.log("DEBUG", " ***** Inside preProcessRequest CreateVcpeResCustService Request ***** ", isDebugEnabled)
+
+ try {
+ // initialize flow variables
+ InitializeProcessVariables(execution)
+
+ // check for incoming json message/input
+ String createVcpeServiceRequest = execution.getVariable("bpmnRequest")
+ utils.logAudit(createVcpeServiceRequest)
+ execution.setVariable("createVcpeServiceRequest", createVcpeServiceRequest);
+ println 'createVcpeServiceRequest - ' + createVcpeServiceRequest
+
+ // extract requestId
+ String requestId = execution.getVariable("mso-request-id")
+ execution.setVariable("msoRequestId", requestId)
+
+ String serviceInstanceId = execution.getVariable("serviceInstanceId")
+
+ if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
+ serviceInstanceId = UUID.randomUUID().toString()
+ utils.log("DEBUG", " Generated new Service Instance: " + serviceInstanceId , isDebugEnabled)
+ } else {
+ utils.log("DEBUG", "Using provided Service Instance ID: " + serviceInstanceId , isDebugEnabled)
+ }
+
+ serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
+ execution.setVariable("serviceInstanceId", serviceInstanceId)
+
+ String requestAction = execution.getVariable("requestAction")
+ execution.setVariable("requestAction", requestAction)
+
+ setBasicDBAuthHeader(execution, isDebugEnabled)
+
+ String source = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.source")
+ if ((source == null) || (source.isEmpty())) {
+ execution.setVariable("source", "VID")
+ } else {
+ execution.setVariable("source", source)
+ }
+
+ // extract globalSubscriberId
+ String globalSubscriberId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo.globalSubscriberId")
+
+ // verify element global-customer-id is sent from JSON input, throw exception if missing
+ if ((globalSubscriberId == null) || (globalSubscriberId.isEmpty())) {
+ String dataErrorMessage = " Element 'globalSubscriberId' is missing. "
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
+
+ } else {
+ execution.setVariable("globalSubscriberId", globalSubscriberId)
+ execution.setVariable("globalCustomerId", globalSubscriberId)
+ }
+
+ // extract subscriptionServiceType
+ String subscriptionServiceType = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters.subscriptionServiceType")
+ execution.setVariable("subscriptionServiceType", subscriptionServiceType)
+ utils.log("DEBUG", "Incoming subscriptionServiceType is: " + subscriptionServiceType, isDebugEnabled)
+
+ String suppressRollback = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.suppressRollback")
+ execution.setVariable("disableRollback", suppressRollback)
+ utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)
+
+ String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
+ execution.setVariable("productFamilyId", productFamilyId)
+ utils.log("DEBUG", "Incoming productFamilyId is: " + productFamilyId, isDebugEnabled)
+
+ String subscriberInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo")
+ execution.setVariable("subscriberInfo", subscriberInfo)
+ utils.log("DEBUG", "Incoming subscriberInfo is: " + subscriberInfo, isDebugEnabled)
+
+ /* + * Extracting User Parameters from incoming Request and converting into a Map + */ + def jsonSlurper = new JsonSlurper() + def jsonOutput = new JsonOutput() + + Map reqMap = jsonSlurper.parseText(createVcpeServiceRequest) + + //InputParams + def userParams = reqMap.requestDetails?.requestParameters?.userParams + + Map<String, String> inputMap = [:] + if (userParams) { + userParams.each { + name, value -> inputMap.put(name, value) + if (name.equals("BRG_WAN_MAC_Address")) + execution.setVariable("brgWanMacAddress", value)
+ } + } + + utils.log("DEBUG", "User Input Parameters map: " + userParams.toString(), isDebugEnabled) + execution.setVariable("serviceInputParams", inputMap) + + utils.log("DEBUG", "Incoming brgWanMacAddress is: " + execution.getVariable('brgWanMacAddress'), isDebugEnabled)
+
+ //For Completion Handler & Fallout Handler
+ String requestInfo =
+ """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
+ <request-id>${requestId}</request-id>
+ <action>CREATE</action>
+ <source>${source}</source>
+ </request-info>"""
+
+ execution.setVariable("CVRCS_requestInfo", requestInfo)
+
+ utils.log("DEBUG", " ***** Completed preProcessRequest CreateVcpeResCustService Request ***** ", isDebugEnabled)
+
+ } catch (BpmnError e) {
+ throw e;
+
+ } catch (Exception ex){
+ String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ public void sendSyncResponse (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ utils.log("DEBUG", " ***** Inside sendSyncResponse of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+ try {
+ String serviceInstanceId = execution.getVariable("serviceInstanceId")
+ String requestId = execution.getVariable("mso-request-id")
+
+ // RESTResponse (for API Handler (APIH) Reply Task)
+ String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
+
+ utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
+ sendWorkflowResponse(execution, 202, syncResponse)
+
+ } catch (Exception ex) {
+ String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ // *******************************
+ //
+ // *******************************
+ public void prepareDecomposeService(Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside prepareDecomposeService of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+ String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
+
+ //serviceModelInfo JSON string will be used as-is for DoCreateServiceInstance BB
+ String serviceModelInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.modelInfo")
+ execution.setVariable("serviceModelInfo", serviceModelInfo)
+
+ utils.log("DEBUG", " ***** Completed prepareDecomposeService of CreateVcpeResCustService ***** ", isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ // *******************************
+ //
+ // *******************************
+ public void prepareCreateServiceInstance(Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside prepareCreateServiceInstance of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+ /*
+ * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
+ * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+ * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
+ *
+ */
+ String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
+// String serviceInputParams = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters")
+// execution.setVariable("serviceInputParams", serviceInputParams)
+
+ + String serviceInstanceName = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.instanceName")
+ execution.setVariable("serviceInstanceName", serviceInstanceName)
+
+ ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+ execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonString())
+
+ utils.log("DEBUG", " ***** Completed prepareCreateServiceInstance of CreateVcpeResCustService ***** ", isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ public void postProcessServiceInstanceCreate (Execution execution){
+ def method = getClass().getSimpleName() + '.postProcessServiceInstanceCreate(' +'execution=' + execution.getId() +')'
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
+ logDebug('Entered ' + method, isDebugLogEnabled)
+
+ String source = execution.getVariable("source")
+ String requestId = execution.getVariable("mso-request-id")
+ String serviceInstanceId = execution.getVariable("serviceInstanceId")
+ String serviceInstanceName = execution.getVariable("serviceInstanceName")
+
+ try {
+
+ String payload = """
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
+ <soapenv:Header/>
+ <soapenv:Body>
+ <req:updateInfraRequest>
+ <requestId>${requestId}</requestId>
+ <lastModifiedBy>BPEL</lastModifiedBy>
+ <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
+ <serviceInstanceName>${serviceInstanceName}</serviceInstanceName>
+ </req:updateInfraRequest>
+ </soapenv:Body>
+ </soapenv:Envelope>
+ """
+ execution.setVariable("CVRCS_setUpdateDbInstancePayload", payload)
+ utils.logAudit("CVRCS_setUpdateDbInstancePayload: " + payload)
+ logDebug('Exited ' + method, isDebugLogEnabled)
+
+ } catch (BpmnError e) {
+ throw e;
+ } catch (Exception e) {
+ logError('Caught exception in ' + method, e)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
+ }
+ }
+
+
+ public void processDecomposition (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ utils.log("DEBUG", " ***** Inside getDataFromDecomposition() of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+ try {
+
+ ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+ List<NetworkResource> networkList = serviceDecomposition.getServiceNetworks()
+
+
+ execution.setVariable("networkList", networkList)
+ execution.setVariable("networkListString", networkList.toString())
+
+ utils.log("DEBUG", "networkList: "+ networkList, isDebugEnabled)
+
+ if (networkList != null && networkList.size() > 0) {
+ execution.setVariable("CVRCS_NetworksCount", networkList.size())
+ utils.log("DEBUG", "networks to create: "+ networkList.size(), isDebugEnabled)
+ } else {
+ execution.setVariable("CVRCS_NetworksCount", 0)
+ utils.log("DEBUG", "no networks to create based upon serviceDecomposition content", isDebugEnabled)
+ }
+
+ // VNFs
+ List<VnfResource> vnfList = serviceDecomposition.getServiceVnfs()
+ execution.setVariable("vnfList", vnfList)
+ execution.setVariable("vnfListString", vnfList.toString())
+
+ String vnfModelInfoString = ""
+ if (vnfList != null && vnfList.size() > 0) {
+ execution.setVariable("CVRCS_VNFsCount", vnfList.size())
+ utils.log("DEBUG", "vnfs to create: "+ vnfList.size(), isDebugEnabled)
+ ModelInfo vnfModelInfo = vnfList[0].getModelInfo()
+
+ vnfModelInfoString = vnfModelInfo.toString()
+ String vnfModelInfoWithRoot = vnfModelInfo.toString()
+ vnfModelInfoString = jsonUtil.getJsonValue(vnfModelInfoWithRoot, "modelInfo")
+ } else {
+ execution.setVariable("CVRCS_VNFsCount", 0)
+ utils.log("DEBUG", "no vnfs to create based upon serviceDecomposition content", isDebugEnabled)
+ }
+
+ execution.setVariable("vnfModelInfo", vnfModelInfoString)
+ execution.setVariable("vnfModelInfoString", vnfModelInfoString)
+ utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
+
+ utils.log("DEBUG", " ***** Completed getDataFromDecomposition() of CreateVcpeResCustService ***** ", isDebugEnabled)
+ } catch (Exception ex) {
+ sendSyncError(execution)
+ String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. getDataFromDecomposition() - " + ex.getMessage()
+ utils.log("DEBUG", exceptionMessage, isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ // *******************************
+ // Generate Network request Section
+ // *******************************
+ public void prepareNetworkCreate (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside preparenNetworkCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+
+ String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
+
+ List<NetworkResource> networkList = execution.getVariable("networkList")
+ utils.log("DEBUG", "networkList: "+ networkList, isDebugEnabled)
+
+ Integer networksCreatedCount = execution.getVariable("CVRCS_NetworksCreatedCount")
+ String networkModelInfoString = ""
+
+ if (networkList != null) {
+ utils.log("DEBUG", " getting model info for network # :" + networksCreatedCount, isDebugEnabled)
+ ModelInfo networkModelInfo = networkList[networksCreatedCount.intValue()].getModelInfo()
+ //Currently use String representation in JSON format as an input
+ //execution.setVariable("networkModelInfo", networkModelInfo)
+ networkModelInfoString = networkModelInfo.toJsonStringNoRootName()
+ } else {
+ String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected number of networks to create - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+
+ //Currently use String representation in JSON format as an input
+ execution.setVariable("networkModelInfo", networkModelInfoString)
+ utils.log("DEBUG", " networkModelInfoString :" + networkModelInfoString, isDebugEnabled)
+
+ // extract cloud configuration
+ String lcpCloudRegionId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
+ execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
+ utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
+ String tenantId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.tenantId")
+ execution.setVariable("tenantId", tenantId)
+ utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
+
+ String sdncVersion = execution.getVariable("sdncVersion")
+ utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
+
+// List<VnfResource> vnfList = execution.getVariable("vnfList")
+// utils.log("DEBUG", "vnfList: "+ vnfList.toString(), isDebugEnabled)
+//
+// String vnfModelInfo = execution.getVariable("vnfModelInfo")
+// utils.log("DEBUG", "vnfModelInfo: "+ vnfModelInfo, isDebugEnabled)
+
+ utils.log("DEBUG", " ***** Completed preparenNetworkCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareNetworkCreate() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ // *******************************
+ // Validate Network request Section -> increment count
+ // *******************************
+ public void validateNetworkCreate (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside validateNetworkCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+ Integer networksCreatedCount = execution.getVariable("CVRCS_NetworksCreatedCount")
+ networksCreatedCount++
+ execution.setVariable("CVRCS_NetworksCreatedCount", networksCreatedCount)
+
+ execution.setVariable("DCRENI_rollbackData"+networksCreatedCount, execution.getVariable("DCRENI_rollbackData"))
+
+ utils.log("DEBUG", "networksCreatedCount: "+ networksCreatedCount, isDebugEnabled)
+ utils.log("DEBUG", "DCRENI_rollbackData N : "+ execution.getVariable("DCRENI_rollbackData"+networksCreatedCount), isDebugEnabled)
+
+// JSONArray vnfList = execution.getVariable("vnfList")
+// utils.log("DEBUG", "vnfList: "+ vnfList, isDebugEnabled)
+
+ String vnfModelInfo = execution.getVariable("vnfModelInfo")
+ utils.log("DEBUG", "vnfModelInfo: "+ vnfModelInfo, isDebugEnabled)
+
+ List<NetworkResource> networkList = execution.getVariable("networkList")
+ utils.log("DEBUG", "networkList: "+ networkList, isDebugEnabled)
+
+ utils.log("DEBUG", " ***** Completed validateNetworkCreate of CreateVcpeResCustService ***** "+" network # "+networksCreatedCount, isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method validateNetworkCreate() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+
+ public void prepareCreateAllottedResourceTXC(Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside prepareCreateAllottedResourceTXC of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+ /*
+ * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
+ * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+ * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
+ *
+ */
+ String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
+ ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+
+ //parentServiceInstanceId
+ //The parentServiceInstanceId will be a Landing Network service. This value will have been provided to the calling flow by SNIRO query (homing solution).
+ //serviceDecomposition.getServiceNetworks()
+
+ //For 1707, the vIPR Tenant OAM flow will use the BRG allotted resource parent service ID (since it is known that the security zone also comes from the vIPR FW).
+ //Beyond 1707, this would need to be captured somehow in TOSCA model and also provided by SNIRO.
+
+ //allottedResourceModelInfo
+ //allottedResourceRole
+ //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
+ //It would be sufficient to only include the service model UUID (i.e. the modelVersionId), since this BB will query the full model from the Catalog DB.
+ List<AllottedResource> allottedResources = serviceDecomposition.getServiceAllottedResources()
+ if (allottedResources != null) {
+ Iterator iter = allottedResources.iterator();
+ while (iter.hasNext()){
+ AllottedResource allottedResource = (AllottedResource)iter.next();
+
+ utils.log("DEBUG", " getting model info for AllottedResource # :" + allottedResource.toJsonString(), isDebugEnabled)
+ utils.log("DEBUG", " allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType(), isDebugEnabled)
+ if(allottedResource.getAllottedResourceType() != null && allottedResource.getAllottedResourceType().equalsIgnoreCase("TunnelXConn")){
+ //set create flag to true
+ execution.setVariable("createTXCAR", true)
+ ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
+ execution.setVariable("allottedResourceModelInfoTXC", allottedResourceModelInfo.toJsonString())
+ execution.setVariable("allottedResourceRoleTXC", allottedResource.getAllottedResourceRole())
+ execution.setVariable("allottedResourceTypeTXC", allottedResource.getAllottedResourceType())
+
+ //from Homing Solution. This is the infraServiceInstanceId in the BRG Allotted Resource decomposition structure.
+ execution.setVariable("parentServiceInstanceIdTXC", allottedResource.getHomingSolution().getServiceInstanceId())
+ } + }
+ }
+
+ //Populate with the A&AI network ID (l3-network object) for the Tenant OAM network that was created in prior step
+ //String sourceNetworkId = execution.getVariable("networkId")
+ //execution.setVariable("sourceNetworkId", sourceNetworkId)
+ //Populate with the network-role (from A&AI l3-network object) for the Tenant OAM network from prior step
+
+ //List<NetworkResource> networkResources = serviceDecomposition.getServiceNetworks()
+ //if (networkResources != null) {
+ //Iterator iter = networkResources.iterator();
+ //while (iter.hasNext()){
+ //NetworkResource networkResource = (NetworkResource)iter.next();
+ //execution.setVariable("sourceNetworkRole", networkResource.getNetworkRole())
+ //}
+ //}
+
+ //unit test only
+ String allottedResourceId = execution.getVariable("allottedResourceId")
+ execution.setVariable("allottedResourceIdTXC", allottedResourceId)
+ utils.log("DEBUG", "setting allottedResourceId CreateVcpeResCustService "+allottedResourceId, isDebugEnabled)
+
+ utils.log("DEBUG", " ***** Completed prepareCreateAllottedResourceTXC of CreateVcpeResCustService ***** ", isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceTXC flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+ public void prepareCreateAllottedResourceBRG(Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside prepareCreateAllottedResourceBRG of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+ /*
+ * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
+ * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+ * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
+ *
+ */
+ String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
+ ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+
+ //parentServiceInstanceId
+ //The parentServiceInstanceId will be a Landing Network service. This value will have been provided to the calling flow by SNIRO query (homing solution).
+ //serviceDecomposition.getServiceNetworks()
+
+ //For 1707, the vIPR Tenant OAM flow will use the BRG allotted resource parent service ID (since it is known that the security zone also comes from the vIPR FW).
+ //Beyond 1707, this would need to be captured somehow in TOSCA model and also provided by SNIRO.
+
+ //allottedResourceModelInfo
+ //allottedResourceRole
+ //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
+ //It would be sufficient to only include the service model UUID (i.e. the modelVersionId), since this BB will query the full model from the Catalog DB.
+ List<AllottedResource> allottedResources = serviceDecomposition.getServiceAllottedResources()
+ if (allottedResources != null) {
+ Iterator iter = allottedResources.iterator();
+ while (iter.hasNext()){
+ AllottedResource allottedResource = (AllottedResource)iter.next();
+
+ utils.log("DEBUG", " getting model info for AllottedResource # :" + allottedResource.toJsonString(), isDebugEnabled)
+ utils.log("DEBUG", " allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType(), isDebugEnabled)
+ if (allottedResource.getAllottedResourceType() != null && allottedResource.getAllottedResourceType().equalsIgnoreCase("BRG")) {
+ //set create flag to true
+ execution.setVariable("createBRGAR", true)
+ ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
+ execution.setVariable("allottedResourceModelInfoBRG", allottedResourceModelInfo.toJsonString())
+ execution.setVariable("allottedResourceRoleBRG", allottedResource.getAllottedResourceRole())
+ execution.setVariable("allottedResourceTypeBRG", allottedResource.getAllottedResourceType())
+ //For 1707, the vIPR Tenant OAM flow will use the BRG allotted resource parent service ID (since it is known that the security zone also comes from the vIPR FW).
+ //This Id should be taken from the homing solution for the BRG resource.
+ //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the BRG,
+ //and in its homingSolution section should be found the infraServiceInstanceId (i.e. infraServiceInstanceId in BRG Allotted Resource structure) (which the Homing BB would have populated).
+
+ //from Homing Solution. This is the infraServiceInstanceId in the BRG Allotted Resource decomposition structure.
+ execution.setVariable("parentServiceInstanceIdBRG", allottedResource.getHomingSolution().getServiceInstanceId())
+ }
+ }
+ }
+
+ //Populate with the A&AI network ID (l3-network object) for the Tenant OAM network that was created in prior step
+ //String sourceNetworkId = execution.getVariable("networkId")
+ //execution.setVariable("sourceNetworkId", sourceNetworkId)
+ //Populate with the network-role (from A&AI l3-network object) for the Tenant OAM network from prior step
+
+ //List<NetworkResource> networkResources = serviceDecomposition.getServiceNetworks()
+ //if (networkResources != null) {
+ //Iterator iter = networkResources.iterator();
+ //while (iter.hasNext()){
+ //NetworkResource networkResource = (NetworkResource)iter.next();
+ //execution.setVariable("sourceNetworkRole", networkResource.getNetworkRole())
+ //}
+ //}
+
+ //unit test only
+ String allottedResourceId = execution.getVariable("allottedResourceId")
+ execution.setVariable("allottedResourceIdBRG", allottedResourceId)
+ utils.log("DEBUG", "setting allottedResourceId CreateVcpeResCustService "+allottedResourceId, isDebugEnabled)
+
+ utils.log("DEBUG", " ***** Completed prepareCreateAllottedResourceBRG of CreateVcpeResCustService ***** ", isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceBRG flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ + + // *******************************
+ // Generate Network request Section
+ // *******************************
+ public void prepareVnfAndModulesCreate (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside prepareVnfAndModulesCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+ // String disableRollback = execution.getVariable("disableRollback")
+ // def backoutOnFailure = ""
+ // if(disableRollback != null){
+ // if ( disableRollback == true) {
+ // backoutOnFailure = "false"
+ // } else if ( disableRollback == false) {
+ // backoutOnFailure = "true"
+ // }
+ // }
+ //failIfExists - optional
+
+ String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
+ String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
+ execution.setVariable("productFamilyId", productFamilyId)
+ utils.log("DEBUG","productFamilyId: "+ productFamilyId, isDebugEnabled)
+
+ List<VnfResource> vnfList = execution.getVariable("vnfList")
+
+ Integer vnfsCreatedCount = execution.getVariable("CVRCS_VnfsCreatedCount")
+ String vnfModelInfoString = null;
+
+ if (vnfList != null && vnfList.size() > 0 ) {
+ utils.log("DEBUG", "getting model info for vnf # " + vnfsCreatedCount, isDebugEnabled)
+ ModelInfo vnfModelInfo1 = vnfList[0].getModelInfo()
+ utils.log("DEBUG", "got 0 ", isDebugEnabled)
+ ModelInfo vnfModelInfo = vnfList[vnfsCreatedCount.intValue()].getModelInfo()
+ vnfModelInfoString = vnfModelInfo.toString()
+ } else {
+ //TODO: vnfList does not contain data. Need to investigate why ... . Fro VCPE use model stored
+ vnfModelInfoString = execution.getVariable("vnfModelInfo")
+ }
+
+ utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
+
+ // extract cloud configuration
+ String lcpCloudRegionId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
+ execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
+ utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
+ String tenantId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.tenantId")
+ execution.setVariable("tenantId", tenantId)
+ utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
+
+ String sdncVersion = execution.getVariable("sdncVersion")
+ utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
+
+ utils.log("DEBUG", " ***** Completed prepareVnfAndModulesCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareVnfAndModulesCreate() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ // *******************************
+ // Validate Vnf request Section -> increment count
+ // *******************************
+ public void validateVnfCreate (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside validateVnfCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+ Integer vnfsCreatedCount = execution.getVariable("CVRCS_VnfsCreatedCount")
+ vnfsCreatedCount++
+
+ execution.setVariable("CVRCS_VnfsCreatedCount", vnfsCreatedCount)
+
+ utils.log("DEBUG", " ***** Completed validateVnfCreate of CreateVcpeResCustService ***** "+" vnf # "+vnfsCreatedCount, isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method validateVnfCreate() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ // *******************************
+ // Validate Network request Section -> decrement count
+ // *******************************
+ public void validateNetworkRollback (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside validateNetworkRollback of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+ Integer networksCreatedCount = execution.getVariable("CVRCS_NetworksCreatedCount")
+ networksCreatedCount--
+
+ execution.setVariable("CVRCS_NetworksCreatedCount", networksCreatedCount)
+
+ execution.setVariable("DCRENI_rollbackData", execution.getVariable("DCRENI_rollbackData"+networksCreatedCount))
+
+ utils.log("DEBUG", " ***** Completed validateNetworkRollback of CreateVcpeResCustService ***** "+" network # "+networksCreatedCount, isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method validateNetworkRollback() - " + ex.getMessage()
+ //exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ utils.log("DEBUG", exceptionMessage, isDebugEnabled)
+ execution.setVariable("CVRCS_NetworksCreatedCount", 0)
+ utils.log("ERROR", exceptionMessage, true)
+ }
+ }
+
+ // *****************************************
+ // Prepare Completion request Section
+ // *****************************************
+ public void postProcessResponse (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ utils.log("DEBUG", " ***** Inside postProcessResponse of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+ try {
+ String source = execution.getVariable("source")
+ String requestId = execution.getVariable("mso-request-id")
+ String serviceInstanceId = execution.getVariable("serviceInstanceId")
+
+ String msoCompletionRequest =
+ """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
+ xmlns:ns="http://org.openecomp/mso/request/types/v1">
+ <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
+ <request-id>${requestId}</request-id>
+ <action>CREATE</action>
+ <source>${source}</source>
+ </request-info>
+ <status-message>Service Instance has been created successfully via macro orchestration</status-message>
+ <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
+ <mso-bpel-name>BPMN macro create</mso-bpel-name>
+ </aetgt:MsoCompletionRequest>"""
+
+ // Format Response
+ String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
+
+ utils.logAudit(xmlMsoCompletionRequest)
+ execution.setVariable("CVRCS_Success", true)
+ execution.setVariable("CVRCS_CompleteMsoProcessRequest", xmlMsoCompletionRequest)
+ utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
+ } catch (BpmnError e) {
+ throw e;
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ public void preProcessRollback (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ utils.log("DEBUG"," ***** preProcessRollback of CreateVcpeResCustService ***** ", isDebugEnabled)
+ try {
+
+ Object workflowException = execution.getVariable("WorkflowException");
+
+ if (workflowException instanceof WorkflowException) {
+ utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
+ execution.setVariable("prevWorkflowException", workflowException);
+ //execution.setVariable("WorkflowException", null);
+ }
+ } catch (BpmnError e) {
+ utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
+ } catch(Exception ex) {
+ String msg = "Exception in preProcessRollback. " + ex.getMessage()
+ utils.log("DEBUG", msg, isDebugEnabled)
+ }
+ utils.log("DEBUG"," *** Exit preProcessRollback of CreateVcpeResCustService *** ", isDebugEnabled)
+ }
+
+ public void postProcessRollback (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ utils.log("DEBUG"," ***** postProcessRollback of CreateVcpeResCustService ***** ", isDebugEnabled)
+ String msg = ""
+ try {
+ Object workflowException = execution.getVariable("prevWorkflowException");
+ if (workflowException instanceof WorkflowException) {
+ utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
+ execution.setVariable("WorkflowException", workflowException);
+ }
+ } catch (BpmnError b) {
+ utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
+ throw b;
+ } catch(Exception ex) {
+ msg = "Exception in postProcessRollback. " + ex.getMessage()
+ utils.log("DEBUG", msg, isDebugEnabled)
+ }
+ utils.log("DEBUG"," *** Exit postProcessRollback of CreateVcpeResCustService *** ", isDebugEnabled)
+ }
+
+ public void prepareFalloutRequest(Execution execution){
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ utils.log("DEBUG", " *** STARTED CreateVcpeResCustService prepareFalloutRequest Process *** ", isDebugEnabled)
+
+ try {
+ WorkflowException wfex = execution.getVariable("WorkflowException")
+ utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
+ String requestInfo = execution.getVariable("CVRCS_requestInfo")
+ utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
+
+ //TODO. hmmm. there is no way to UPDATE error message.
+// String errorMessage = wfex.getErrorMessage()
+// boolean successIndicator = execution.getVariable("DCRESI_rollbackSuccessful")
+// if (successIndicator){
+// errorMessage = errorMessage + ". Rollback successful."
+// } else {
+// errorMessage = errorMessage + ". Rollback not completed."
+// }
+
+ String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
+
+ execution.setVariable("CVRCS_falloutRequest", falloutRequest)
+
+ } catch (Exception ex) {
+ utils.log("DEBUG", "Error Occured in CreateVcpeResCustService prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVcpeResCustService prepareFalloutRequest Process")
+ }
+ utils.log("DEBUG", "*** COMPLETED CreateVcpeResCustService prepareFalloutRequest Process ***", isDebugEnabled)
+ }
+
+
+ public void sendSyncError (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ execution.setVariable("prefix", Prefix)
+
+ utils.log("DEBUG", " ***** Inside sendSyncError() of CreateVcpeResCustService ***** ", isDebugEnabled)
+
+ try {
+ String errorMessage = ""
+ if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
+ WorkflowException wfe = execution.getVariable("WorkflowException")
+ errorMessage = wfe.getErrorMessage()
+ } else {
+ errorMessage = "Sending Sync Error."
+ }
+
+ String buildworkflowException =
+ """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
+ <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
+ <aetgt:ErrorCode>7000</aetgt:ErrorCode>
+ </aetgt:WorkflowException>"""
+
+ utils.logAudit(buildworkflowException)
+ sendWorkflowResponse(execution, 500, buildworkflowException)
+ } catch (Exception ex) {
+ utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
+ }
+ }
+
+ public void processJavaException(Execution execution){
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ execution.setVariable("prefix",Prefix)
+ try{
+ utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
+ utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
+ utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
+ execution.setVariable("CRESI_unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
+ }catch(BpmnError b){
+ utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
+ throw b
+ }catch(Exception e){
+ utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
+ execution.setVariable("CRESI_unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
+ }
+ utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)
+ }
+}
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DeleteVcpeResCustService.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DeleteVcpeResCustService.groovy new file mode 100644 index 0000000000..960bb5cc7f --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DeleteVcpeResCustService.groovy @@ -0,0 +1,495 @@ +/*
+ * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
+ */
+package org.openecomp.mso.bpmn.vcpe.scripts
+
+import groovy.xml.XmlUtil
+import groovy.json.*
+
+import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils;
+import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
+import org.openecomp.mso.bpmn.common.scripts.NetworkUtils;
+import org.openecomp.mso.bpmn.common.scripts.VidUtils;
+import org.openecomp.mso.bpmn.core.json.JsonUtils
+import org.openecomp.mso.bpmn.core.WorkflowException
+import org.openecomp.mso.rest.APIResponse
+import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
+
+import java.util.UUID;
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.runtime.Execution
+import org.json.JSONObject;
+import org.json.JSONArray;
+import org.apache.commons.lang3.*
+import org.apache.commons.codec.binary.Base64;
+import org.springframework.web.util.UriUtils;
+
+/**
+ * This groovy class supports the <class>DeleteVcpeResCustService.bpmn</class> process.
+ *
+ * @author dm4252
+ *
+ */
+public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor {
+
+ String Prefix="DELVAS_"
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+ VidUtils vidUtils = new VidUtils()
+ CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
+ NetworkUtils networkUtils = new NetworkUtils()
+
+ /**
+ * This method is executed during the preProcessRequest task of the <class>DeleteVcpeResCustService.bpmn</class> process.
+ * @param execution
+ */
+ public InitializeProcessVariables(Execution execution){
+ /* Initialize all the process variables in this block */
+
+ execution.setVariable("DeleteVcpeResCustServiceRequest", "")
+ execution.setVariable("msoRequestId", "")
+ execution.setVariable("DELVAS_vnfsDeletedCount", 0)
+ execution.setVariable("DELVAS_vnfsCount", 0)
+ execution.setVariable("DELVAS_networksCount", 0)
+ execution.setVariable("DELVAS_networksDeletedCount", 0)
+ }
+
+ // **************************************************
+ // Pre or Prepare Request Section
+ // **************************************************
+ /**
+ * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
+ * @param execution
+ */
+ public void preProcessRequest (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ execution.setVariable("prefix",Prefix)
+
+ utils.log("DEBUG", " ***** Inside preProcessRequest DeleteVcpeResCustService Request ***** ", isDebugEnabled)
+
+ try {
+ // initialize flow variables
+ InitializeProcessVariables(execution)
+
+ // check for incoming json message/input
+ String DeleteVcpeResCustServiceRequest = execution.getVariable("bpmnRequest")
+ utils.logAudit(DeleteVcpeResCustServiceRequest)
+ execution.setVariable("DeleteVcpeResCustServiceRequest", DeleteVcpeResCustServiceRequest);
+ println 'DeleteVcpeResCustServiceRequest - ' + DeleteVcpeResCustServiceRequest
+
+ // extract requestId
+ String requestId = execution.getVariable("mso-request-id")
+ execution.setVariable("msoRequestId", requestId)
+
+ String serviceInstanceId = execution.getVariable("serviceInstanceId")
+ if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
+ String dataErrorMessage = " Element 'serviceInstanceId' is missing. "
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
+ }
+
+ String requestAction = execution.getVariable("requestAction")
+ execution.setVariable("requestAction", requestAction)
+
+ String source = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.requestInfo.source")
+ if ((source == null) || (source.isEmpty())) {
+ execution.setVariable("source", "VID")
+ } else {
+ execution.setVariable("source", source)
+ }
+
+ // extract globalSubscriberId
+ String globalSubscriberId = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.subscriberInfo.globalSubscriberId")
+
+ // global-customer-id is optional on Delete
+
+ execution.setVariable("globalSubscriberId", globalSubscriberId)
+ execution.setVariable("globalCustomerId", globalSubscriberId)
+
+ String suppressRollback = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.requestInfo.suppressRollback")
+ execution.setVariable("disableRollback", suppressRollback)
+ utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)
+
+ String productFamilyId = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.requestInfo.productFamilyId")
+ execution.setVariable("productFamilyId", productFamilyId)
+ utils.log("DEBUG", "Incoming productFamilyId is: " + productFamilyId, isDebugEnabled)
+
+ // extract subscriptionServiceType
+ String subscriptionServiceType = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.requestParameters.subscriptionServiceType")
+ execution.setVariable("subscriptionServiceType", subscriptionServiceType)
+ utils.log("DEBUG", "Incoming subscriptionServiceType is: " + subscriptionServiceType, isDebugEnabled)
+
+ // extract cloud configuration
+ String lcpCloudRegionId = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
+ execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
+ utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
+ String tenantId = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.cloudConfiguration.tenantId")
+ execution.setVariable("tenantId", tenantId)
+ utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
+
+ String sdncVersion = "1702"
+ execution.setVariable("sdncVersion", sdncVersion)
+ utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
+
+ //For Completion Handler & Fallout Handler
+ String requestInfo =
+ """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
+ <request-id>${requestId}</request-id>
+ <action>DELETE</action>
+ <source>${source}</source>
+ </request-info>"""
+
+ execution.setVariable("DELVAS_requestInfo", requestInfo)
+
+ //Setting for Generic Sub Flows
+ execution.setVariable("GENGS_type", "service-instance")
+
+ utils.log("DEBUG", " ***** Completed preProcessRequest DeleteVcpeResCustServiceRequest Request ***** ", isDebugEnabled)
+
+ } catch (BpmnError e) {
+ throw e;
+ } catch (Exception ex){
+ String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ public void sendSyncResponse (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ utils.log("DEBUG", " ***** Inside sendSyncResponse of DeleteVcpeResCustService ***** ", isDebugEnabled)
+
+ try {
+ String serviceInstanceId = execution.getVariable("serviceInstanceId")
+ String requestId = execution.getVariable("mso-request-id")
+
+ // RESTResponse (for API Handler (APIH) Reply Task)
+ String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
+
+ utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
+ sendWorkflowResponse(execution, 202, syncResponse)
+ } catch (Exception ex) {
+ String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()^M + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ public void prepareServiceDelete (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ utils.log("DEBUG", " ***** Inside prepareServiceInstanceDelete() of DeleteVcpeResCustService ***** ", isDebugEnabled)
+
+ try {
+
+ String serviceInstanceId = execution.getVariable("serviceInstanceId")
+
+ // confirm if ServiceInstance was found
+ if ( !execution.getVariable("GENGS_FoundIndicator") )
+ {
+ String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Service Instance was not found in AAI by id: " + serviceInstanceId
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+
+ // get variable within incoming json
+ String DeleteVcpeResCustServiceRequest = execution.getVariable("DeleteVcpeResCustServiceRequest");
+
+ // get SI extracted by GenericGetService
+ String serviceInstanceAaiRecord = execution.getVariable("GENGS_service");
+
+ utils.log("DEBUG", "serviceInstanceAaiRecord: "+serviceInstanceAaiRecord, isDebugEnabled)
+
+ // determine if AR needs to be deleted
+ boolean DELVAS_TunnelXConn = false
+ boolean DELVAS_BRG = false
+ String TXC_allottedResourceId
+ String BRG_allottedResourceId
+ XmlParser xmlParser = new XmlParser()
+ def groovy.util.Node siNode = xmlParser.parseText(serviceInstanceAaiRecord)
+ def groovy.util.Node arList = utils.getChildNode(siNode, 'allotted-resources')
+ if (arList != null) {
+ def groovy.util.NodeList ars = utils.getIdenticalChildren(arList, 'allotted-resource')
+ for (groovy.util.Node ar in ars) {
+ def groovy.util.Node type = utils.getChildNode(ar, 'type')
+ if ((type != null) && (type.text().equals('TunnelXConn'))) {
+ utils.log("DEBUG","TunnelXConn AR found", isDebugEnabled)
+ def groovy.util.Node id = utils.getChildNode(ar, 'id')
+ if (id != null){
+ DELVAS_TunnelXConn = true
+ TXC_allottedResourceId = id
+ }
+ }
+ if ((type != null) && (type.text().equals('BRG'))) {
+ utils.log("DEBUG","FW AR found", isDebugEnabled)
+ def groovy.util.Node id = utils.getChildNode(ar, 'id')
+ if (id != null){
+ DELVAS_BRG = true
+ BRG_allottedResourceId = id
+ }
+ }
+ }
+ }
+ execution.setVariable("DELVAS_TunnelXConn", DELVAS_TunnelXConn)
+ utils.log("DEBUG", "DELVAS_TunnelXConn : " + DELVAS_TunnelXConn, isDebugEnabled)
+ execution.setVariable("TXC_allottedResourceId", TXC_allottedResourceId)
+ utils.log("DEBUG", "TXC_allottedResourceId : " + TXC_allottedResourceId, isDebugEnabled)
+
+ execution.setVariable("DELVAS_BRG", DELVAS_BRG)
+ utils.log("DEBUG", "DELVAS_BRG : " + DELVAS_BRG, isDebugEnabled)
+ execution.setVariable("BRG_allottedResourceId", BRG_allottedResourceId)
+ utils.log("DEBUG", "BRG_allottedResourceId : " + BRG_allottedResourceId, isDebugEnabled)
+
+ String relationship = ""
+ try {
+ relationship = networkUtils.getFirstNodeXml(serviceInstanceAaiRecord, "relationship-list")
+ } catch (Exception ex) {
+ //no relationships found
+ }
+ utils.log("DEBUG", " relationship string - " + relationship, isDebugEnabled)
+
+ int vnfsCount = 0
+ int networksCount = 0
+
+ if (relationship != null && relationship.length() > 0){
+ relationship = relationship.trim().replace("tag0:","").replace(":tag0","")
+
+ // Check if Network TableREf is present, then build a List of network policy
+ List relatedVnfIdList = networkUtils.getRelatedVnfIdList(relationship)
+ vnfsCount = relatedVnfIdList.size()
+ execution.setVariable("DELVAS_vnfsCount", vnfsCount)
+ utils.log("DEBUG", " DELVAS_vnfsCount : " + vnfsCount, isDebugEnabled)
+ execution.setVariable("DELVAS_relatedVnfIdList", relatedVnfIdList)
+
+ // Check if Network TableREf is present, then build a List of network policy
+ List relatedNetworkIdList = networkUtils.getRelatedNetworkIdList(relationship)
+ networksCount = relatedNetworkIdList.size()
+ execution.setVariable("DELVAS_networksCount", networksCount)
+ utils.log("DEBUG", " DELVAS_networksCount : " + networksCount, isDebugEnabled)
+ execution.setVariable("DELVAS_relatedNetworkIdList", relatedNetworkIdList)
+ } else {
+ execution.setVariable("DELVAS_vnfsCount", 0)
+ utils.log("DEBUG", " DELVAS_vnfsCount : " + vnfsCount, isDebugEnabled)
+ execution.setVariable("DELVAS_networksCount", 0)
+ utils.log("DEBUG", " DELVAS_networksCount : " + networksCount, isDebugEnabled)
+ }
+
+ utils.log("DEBUG", " ***** Completed prepareServiceInstanceDelete() of DeleteVcpeCusRestService ***** ", isDebugEnabled)
+ } catch (BpmnError e){
+ throw e;
+ } catch (Exception ex) {
+ sendSyncError(execution)
+ String exceptionMessage = "Bpmn error encountered in DeleteVcpeCusRestService flow. prepareServiceInstanceDelete() - " + ex.getMessage()
+ utils.log("DEBUG", exceptionMessage, isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+
+ // *******************************
+ //
+ // *******************************
+ public void prepareVnfAndModulesDelete (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside prepareVnfAndModulesDelete of DeleteServiceInstanceMacro ***** ", isDebugEnabled)
+
+ List vnfList = execution.getVariable("DELVAS_relatedVnfIdList")
+ Integer vnfsDeletedCount = execution.getVariable("DELVAS_vnfsDeletedCount")
+ String vnfModelInfoString = ""
+ String vnfId = ""
+ if (vnfList.size() > 0 ) {
+ vnfId = vnfList.get(vnfsDeletedCount.intValue())
+ }
+
+ execution.setVariable("vnfId", vnfId)
+ utils.log("DEBUG", "need to delete vnfId:" + vnfId, isDebugEnabled)
+
+ utils.log("DEBUG", " ***** Completed prepareVnfAndModulesDelete of DeleteServiceInstanceMacro ***** ", isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in DeleteServiceInstanceMacro flow. Unexpected Error from method prepareVnfAndModulesDelete() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ // *******************************
+ // Validate Vnf request Section -> increment count
+ // *******************************
+ public void validateVnfDelete (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside validateVnfDelete of DeleteVcpeCusRestService ***** ", isDebugEnabled)
+
+ String vnfsDeletedCount = execution.getVariable("DELVAS_vnfsDeletedCount")
+ vnfsDeletedCount++
+
+ execution.setVariable("DELVAS_vnfsDeletedCount", vnfsDeletedCount)
+
+ utils.log("DEBUG", " ***** Completed validateVnfDelete of DeleteVcpeCusRestService ***** "+" vnf # "+vnfsDeletedCount, isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in DeleteVcpeCusRestService flow. Unexpected Error from method validateVnfDelete() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ // *******************************
+ // Generate Network request Section
+ // *******************************
+ public void prepareNetworkDelete (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside prepareNetworkDelete of DeleteVcpeCusRestService ***** ", isDebugEnabled)
+
+ List networkList = execution.getVariable("DELVAS_relatedNetworkIdList")
+ Integer networksDeletedCount = execution.getVariable("DELVAS_networksDeletedCount")
+
+ String networkId = ""
+ if (networkList.size() > 0) {
+ networkId = networkList.get(networksDeletedCount.intValue())
+ }
+
+ execution.setVariable("networkId", networkId)
+ utils.log("DEBUG", "need to delete networkId:" + networkId, isDebugEnabled)
+
+ utils.log("DEBUG", " ***** Completed prepareNetworkDelete of DeleteVcpeCusRestService ***** ", isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = q"Bpmn error encountered in DeleteVcpeCusRestService flow. Unexpected Error from method prepareNetworkDelete() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ // *******************************
+ // Validate Network request Section
+ // *******************************
+ public void validateNetworkDelete (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+ try {
+ utils.log("DEBUG", " ***** Inside validateNetworkDelete of DeleteVcpeCusRestService ***** ", isDebugEnabled)
+
+ Integer networksDeletedCount = execution.getVariable("DELVAS_networksDeletedCount")
+ networksDeletedCount++
+
+ execution.setVariable("DELVAS_networksDeletedCount", networksDeletedCount)
+
+ utils.log("DEBUG", " ***** Completed validateNetworkDelete of DeleteVcpeCusRestService ***** ", isDebugEnabled)
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in DeleteVcpeCusRestService flow. Unexpected Error from method validateNetworkDelete() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+
+ // *****************************************
+ // Prepare Completion request Section
+ // *****************************************
+ public void postProcessResponse (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ utils.log("DEBUG", " ***** Inside postProcessResponse of DeleteVcpeCusRestService ***** ", isDebugEnabled)
+
+ try {
+ String source = execution.getVariable("source")
+ String requestId = execution.getVariable("msoRequestId")
+
+ String msoCompletionRequest =
+ """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
+ xmlns:ns="http://org.openecomp/mso/request/types/v1">
+ <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
+ <request-id>${requestId}</request-id>
+ <action>DELETE</action>
+ <source>${source}</source>
+ </request-info>
+ <aetgt:status-message>vCPE Res Cust Service Instance has been deleted successfully.</aetgt:status-message>
+ <aetgt:mso-bpel-name>BPMN Service Instance macro action: DELETE</aetgt:mso-bpel-name>
+ </aetgt:MsoCompletionRequest>"""
+
+ // Format Response
+ String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
+
+ utils.logAudit(xmlMsoCompletionRequest)
+ execution.setVariable("DELVAS_Success", true)
+ execution.setVariable("DELVAS_CompleteMsoProcessRequest", xmlMsoCompletionRequest)
+ utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
+ } catch (BpmnError e) {
+ throw e;
+
+ } catch (Exception ex) {
+ // try error in method block
+ String exceptionMessage = "Bpmn error encountered in DeleteServiceInstance flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ }
+
+ public void prepareFalloutRequest(Execution execution){
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ utils.log("DEBUG", " *** STARTED DeleteVcpeCusRestService prepareFalloutRequest Process *** ", isDebugEnabled)
+
+ try {
+ WorkflowException wfex = execution.getVariable("WorkflowException")
+ utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
+ String requestInfo = execution.getVariable("DELVAS_requestInfo")
+ utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
+
+ String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
+
+ execution.setVariable("DELVAS_falloutRequest", falloutRequest)
+ } catch (Exception ex) {
+ utils.log("DEBUG", "Error Occured in DeleteVcpeCusRestService prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DeleteVcpeCusRestService prepareFalloutRequest Process")
+ }
+ utils.log("DEBUG", "*** COMPLETED DeleteVcpeCusRestService prepareFalloutRequest Process ***", isDebugEnabled)
+ }
+
+
+ public void sendSyncError (Execution execution) {
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ utils.log("DEBUG", " ***** Inside sendSyncError() of DeleteServiceInstanceInfra ***** ", isDebugEnabled)
+
+ try {
+ String errorMessage = ""
+ if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
+ WorkflowException wfe = execution.getVariable("WorkflowException")
+ errorMessage = wfe.getErrorMessage()
+ } else {
+ errorMessage = "Sending Sync Error."
+ }
+
+ String buildworkflowException =
+ """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
+ <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
+ <aetgt:ErrorCode>7000</aetgt:ErrorCode>
+ </aetgt:WorkflowException>"""
+
+ utils.logAudit(buildworkflowException)
+ sendWorkflowResponse(execution, 500, buildworkflowException)
+ } catch (Exception ex) {
+ utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
+ }
+ }
+
+ public void processJavaException(Execution execution){
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ execution.setVariable("prefix",Prefix)
+ try{
+ utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
+ utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
+ utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
+ execution.setVariable("DELVAS_unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
+ }catch(BpmnError b){
+ utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
+ throw b
+ }catch(Exception e){
+ utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
+ execution.setVariable("DELVAS_unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
+ }
+ utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)
+ }
+
+
+}
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoCreateAllottedResourceBRG.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoCreateAllottedResourceBRG.groovy new file mode 100644 index 0000000000..528a804b6f --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoCreateAllottedResourceBRG.groovy @@ -0,0 +1,652 @@ +/* + * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +package org.openecomp.mso.bpmn.vcpe.scripts; + +import org.openecomp.mso.bpmn.common.scripts.*; +import org.openecomp.mso.bpmn.common.scripts.AaiUtil +import org.openecomp.mso.bpmn.core.RollbackData +import org.openecomp.mso.bpmn.core.WorkflowException +import org.openecomp.mso.bpmn.core.json.JsonUtils +import org.openecomp.mso.rest.APIResponse + +import java.util.UUID; +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.runtime.Execution +import org.apache.commons.lang3.* +import org.springframework.web.util.UriUtils; +import static org.apache.commons.lang3.StringUtils.* + + +/** + * This groovy class supports the <class>DoCreateAllottedResourceBRG.bpmn</class> process. + * + * @author + * + * Inputs: + * @param - msoRequestId + * @param - isDEbugLogEnabled + * @param - disableRollback + * @param - failExists - O + * @param - serviceInstanceId + * @param - parentServiceInstanceId + * @param - allottedReourceId - O + * @param - allottedResourceModelInfo + * @param - allottedResourceRole + * @param - allottedResourceType + * @param - brgWanMacAddress + * @param - vni + * @param - vgmuxBearerIP + * + * Outputs: + * @param - rollbackData (localRB->null) + * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true) + * @param - WorkflowException - O + * @param - allottedResourceId + * @param - allottedResourceName + * + */ +public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{ + + String Prefix="DCARBRG_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + + public void preProcessRequest (Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled) + + try { + execution.setVariable("prefix", Prefix) + + //Config Inputs + String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback') + if (isBlank(sdncCallbackUrl)) { + msg = "URN_mso_workflow_sdncadapter_callback is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + execution.setVariable("sdncCallbackUrl", sdncCallbackUrl) + utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled) + + //Request Inputs + if (isBlank(execution.getVariable("serviceInstanceId"))){ + msg = "Input serviceInstanceId is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("parentServiceInstanceId"))) { + msg = "Input parentServiceInstanceId is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("allottedResourceModelInfo"))) { + msg = "Input allottedResourceModelInfo is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("vni"))) { + msg = "Input vni is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("vgmuxBearerIP"))) { + msg = "Input vgmuxBearerIP is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("brgWanMacAddress"))) { + msg = "Input brgWanMacAddress is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("allottedResourceRole"))) { + msg = "Input allottedResourceRole is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("allottedResourceType"))) { + msg = "Input allottedResourceType is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + }catch(BpmnError b){ + utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled) + throw b + } catch (Exception ex){ + msg = "Exception in preProcessRequest " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled) + } + + public void getAaiAR (Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** getAaiAR ***** ", isDebugEnabled) + + String arType = execution.getVariable("allottedResourceType") + String arRole = execution.getVariable("allottedResourceRole") + + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String orchStatus = arUtils.getAROrchStatus(execution) + + String errorMsg = "" + + if (orchStatus != null) // AR was found + { + if ("true".equals(execution.getVariable("failExists"))) + { + errorMsg = "Allotted resource " + arType + " with Role " + arRole + " already exists" + } + else + { + if ("Active".equals(orchStatus)) + { + execution.setVariable("foundActiveAR", true) + } + else // blanks included + { + errorMsg = "Allotted Resource " + arType + " with Role " + arRole + " already exists in an incomplete state -" + orchStatus + } + } + } + if (!isBlank(errorMsg)) { + utils.log("DEBUG", errorMsg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg) + } + utils.log("DEBUG"," *****Exit getAaiAR *****", isDebugEnabled) + } + + public void createAaiAR(Execution execution) { + + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** createAaiAR ***** ", isDebugEnabled) + String msg = "" + + String allottedResourceId = execution.getVariable("allottedResourceId") + if (isBlank(allottedResourceId)) + { + allottedResourceId = UUID.randomUUID().toString() + execution.setVariable("allottedResourceId", allottedResourceId) + } + String arUrl = "" + try { + + //AAI PUT + AaiUtil aaiUriUtil = new AaiUtil(this) + String aaiEndpoint = execution.getVariable("URN_aai_endpoint") + String siResourceLink= execution.getVariable("PSI_resourceLink") + + String siUri = "" + utils.log("DEBUG", "PSI_resourceLink:" + siResourceLink, isDebugEnabled) + + if(!isBlank(siResourceLink)) { + utils.log("DEBUG", "Incoming PSI Resource Link is: " + siResourceLink, isDebugEnabled) + String[] split = siResourceLink.split("/aai/") + siUri = "/aai/" + split[1] + } + else + { + msg = "Parent Service Link in AAI is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + arUrl = "${aaiEndpoint}${siUri}" + "/allotted-resources/allotted-resource/" + UriUtils.encode(allottedResourceId,"UTF-8") + execution.setVariable("aaiARPath", arUrl) + utils.log("DEBUG", "GET AllottedResource AAI URL is:\n" + arUrl, isDebugEnabled) + + String namespace = aaiUriUtil.getNamespaceFromUri(execution, arUrl) + + String arType = execution.getVariable("allottedResourceType") + String arRole = execution.getVariable("allottedResourceRole") + String CSI_resourceLink = execution.getVariable("CSI_resourceLink") + String arModelInfo = execution.getVariable("allottedResourceModelInfo") + String modelInvariantId = jsonUtil.getJsonValue(arModelInfo, "modelInvariantUuid") + String modelVersionId = jsonUtil.getJsonValue(arModelInfo, "modelUuid") + String modelCustomizationId = jsonUtil.getJsonValue(arModelInfo, "modelCustomizationUuid") + + if (modelInvariantId == null) { + modelInvariantId = "" + } + if (modelVersionId == null) { + modelVersionId = "" + } + if (modelCustomizationId == null) { + modelCustomizationId = "" + } + + String payload = + """<allotted-resource xmlns="${namespace}"> + <id>${allottedResourceId}</id> + <description></description> + <type>${arType}</type> + <role>${arRole}</role> + <selflink></selflink> + <model-invariant-id>${modelInvariantId}</model-invariant-id> + <model-version-id>${modelVersionId}</model-version-id> + <model-customization-id>${modelCustomizationId}</model-customization-id> + <orchestration-status>PendingCreate</orchestration-status> + <operation-status></operation-status> + <relationship-list> + <relationship> + <related-to>service-instance</related-to> + <related-link>${CSI_resourceLink}</related-link> + </relationship> + </relationship-list> + </allotted-resource>""".trim() + + execution.setVariable("AaiARPayload", payload) + utils.log("DEBUG", " payload to create AllottedResource in AAI:" + "\n" + payload, isDebugEnabled) + + APIResponse response = aaiUriUtil.executeAAIPutCall(execution, arUrl, payload) + int responseCode = response.getStatusCode() + utils.log("DEBUG", "AllottedResource AAI PUT responseCode:" + responseCode, isDebugEnabled) + + String aaiResponse = response.getResponseBodyAsString() + aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse) + utils.log("DEBUG", "AllottedResource AAI PUT responseStr:" + aaiResponse, isDebugEnabled) + + //200 OK 201 CREATED 202 ACCEPTED + if(responseCode == 200 || responseCode == 201 || responseCode == 202 ) + { + utils.log("DEBUG", "AAI PUT AllottedResource received a Good Response", isDebugEnabled) + } + else{ + utils.log("DEBUG", "AAI Put AllottedResouce received a Bad Response Code: " + responseCode, isDebugEnabled) + exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode) + throw new BpmnError("MSOWorkflowException") + } + }catch(BpmnError b){ + utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled) + throw b + } catch (Exception ex) { + msg = "Exception in createAaiAR " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + //start rollback set up + RollbackData rollbackData = new RollbackData() + def disableRollback = execution.getVariable("disableRollback") + rollbackData.put(Prefix, "disableRollback", disableRollback.toString()) + rollbackData.put(Prefix, "rollbackAAI", "true") + rollbackData.put(Prefix, "allottedResourceId", allottedResourceId) + rollbackData.put(Prefix, "serviceInstanceId", execution.getVariable("serviceInstanceId")) + rollbackData.put(Prefix, "parentServiceInstanceId", execution.getVariable("parentServiceInstanceId")) + rollbackData.put(Prefix, "aaiARPath", arUrl) + execution.setVariable("rollbackData", rollbackData) + utils.log("DEBUG"," *** Exit createAaiAR*** ", isDebugEnabled) + } + + public String buildSDNCRequest(Execution execution, String action, String sdncRequestId) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** buildSDNCRequest *****", isDebugEnabled) + String sdncReq = null + + try { + + String allottedResourceId = execution.getVariable("allottedResourceId") + String serviceInstanceId = execution.getVariable("serviceInstanceId") + String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId") + String callbackUrl = execution.getVariable("sdncCallbackUrl") + String requestId = execution.getVariable("msoRequestId") + + String brgWanMacAddress = execution.getVariable("brgWanMacAddress") + String vni = execution.getVariable("vni") + String vgmuxBearerIP = execution.getVariable("vgmuxBearerIP") + + String arModelInfo = execution.getVariable("allottedResourceModelInfo") + String modelInvariantId = jsonUtil.getJsonValue(arModelInfo, "modelInvariantUuid") + String modelVersion = jsonUtil.getJsonValue(arModelInfo, "modelVersion") + String modelUUId = jsonUtil.getJsonValue(arModelInfo, "modelUuid") + String modelCustomizationId = jsonUtil.getJsonValue(arModelInfo, "modelCustomizationUuid") + String modelName = jsonUtil.getJsonValue(arModelInfo, "modelName") + + if (modelInvariantId == null) { + modelInvariantId = "" + } + if (modelVersion == null) { + modelVersion = "" + } + if (modelUUId == null) { + modelUUId = "" + } + if (modelName == null) { + modelName = "" + } + if (modelCustomizationId == null) { + modelCustomizationId = "" + } + + sdncReq = + """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1" + xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1" + xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1"> + <sdncadapter:RequestHeader> + <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId> + <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId> + <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction> + <sdncadapter:SvcOperation>brg-topology-operation</sdncadapter:SvcOperation> + <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl> + </sdncadapter:RequestHeader> + <sdncadapterworkflow:SDNCRequestData> + <request-information> + <request-id>${requestId}</request-id> + <request-action>CreateBRGInstance</request-action> + <source>MSO</source> + <notification-url/> + <order-number/> + <order-version/> + </request-information> + <service-information> + <service-id></service-id> + <subscription-service-type></subscription-service-type> + <ecomp-model-information></ecomp-model-information> + <service-instance-id>${parentServiceInstanceId}</service-instance-id> + <subscriber-name/> + <global-customer-id></global-customer-id> + </service-information> + <allotted-resource-information> + <allotted-resource-id>${allottedResourceId}</allotted-resource-id> + <allotted-resource-type>brg</allotted-resource-type> + <parent-service-instance-id>${parentServiceInstanceId}</parent-service-instance-id> + <ecomp-model-information> + <model-invariant-uuid>${modelInvariantId}</model-invariant-uuid> + <model-uuid>${modelUUId}</model-uuid> + <model-customization-uuid>${modelCustomizationId}</model-customization-uuid> + <model-version>${modelVersion}</model-version> + <model-name>${modelName}</model-name> + </ecomp-model-information> + </allotted-resource-information> + <brg-request-input> + <brg-wan-mac-address>${brgWanMacAddress}</brg-wan-mac-address> + <vni>${vni}</vni> + <vgmux-bearer-ip>${vgmuxBearerIP}</vgmux-bearer-ip> + </brg-request-input> + </sdncadapterworkflow:SDNCRequestData> + </sdncadapterworkflow:SDNCAdapterWorkflowRequest>""" + + utils.log("DEBUG","sdncRequest:\n" + sdncReq, isDebugEnabled) + sdncReq = utils.formatXml(sdncReq) + + } catch(Exception ex) { + msg = "Exception in buildSDNCRequest. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit buildSDNCRequest *****", isDebugEnabled) + return sdncReq + } + + public void preProcessSDNCAssign(Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessSDNCAssign *****", isDebugEnabled) + + try { + String sdncRequestId = UUID.randomUUID().toString() + String sdncAssignReq = buildSDNCRequest(execution, "assign", sdncRequestId) + execution.setVariable("sdncAssignRequest", sdncAssignReq) + utils.logAudit("sdncAssignRequest: " + sdncAssignReq) + def sdncRequestId2 = UUID.randomUUID().toString() + String sdncAssignRollbackReq = sdncAssignReq.replace(">assign<", ">unassign<").replace(">CreateBRGInstance<", ">DeleteBRGInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<") + def rollbackData = execution.getVariable("rollbackData") + rollbackData.put(Prefix, "sdncAssignRollbackReq", sdncAssignRollbackReq) + execution.setVariable("rollbackData", rollbackData) + + utils.log("DEBUG","sdncAssignRollbackReq:\n" + sdncAssignRollbackReq, isDebugEnabled) + utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled) + + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCAssign. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit preProcessSDNCAssign *****", isDebugEnabled) + } + + public void preProcessSDNCCreate(Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessSDNCCreate *****", isDebugEnabled) + + try { + String sdncRequestId = UUID.randomUUID().toString() + String sdncCreateReq = buildSDNCRequest(execution, "create", sdncRequestId) + execution.setVariable("sdncCreateRequest", sdncCreateReq) + utils.logAudit("sdncCreateReq: " + sdncCreateReq) + def sdncRequestId2 = UUID.randomUUID().toString() + String sdncCreateRollbackReq = sdncCreateReq.replace(">create<", ">delete<").replace(">CreateBRGInstance<", ">DeleteBRGInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<") + def rollbackData = execution.getVariable("rollbackData") + rollbackData.put(Prefix, "sdncCreateRollbackReq", sdncCreateRollbackReq) + execution.setVariable("rollbackData", rollbackData) + + utils.log("DEBUG","sdncCreateRollbackReq:\n" + sdncCreateRollbackReq, isDebugEnabled) + utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled) + + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCCreate. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit preProcessSDNCCreate *****", isDebugEnabled) + } + + public void preProcessSDNCActivate(Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessSDNCActivate *****", isDebugEnabled) + + try { + String sdncRequestId = UUID.randomUUID().toString() + String sdncActivateReq = buildSDNCRequest(execution, "activate", sdncRequestId) + execution.setVariable("sdncActivateRequest", sdncActivateReq) + utils.logAudit("sdncActivateReq: " + sdncActivateReq) + def sdncRequestId2 = UUID.randomUUID().toString() + String sdncActivateRollbackReq = sdncActivateReq.replace(">activate<", ">deactivate<").replace(">CreateBRGInstance<", ">DeleteBRGInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<") + def rollbackData = execution.getVariable("rollbackData") + rollbackData.put(Prefix, "sdncActivateRollbackReq", sdncActivateRollbackReq) + execution.setVariable("rollbackData", rollbackData) + + utils.log("DEBUG","sdncActivateRollbackReq:\n" + sdncActivateRollbackReq, isDebugEnabled) + utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled) + + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCActivate. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit preProcessSDNCActivate *****", isDebugEnabled) + } + + public void validateSDNCResp(Execution execution, String response, String method){ + + def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled) + String msg = "" + + try { + WorkflowException workflowException = execution.getVariable("WorkflowException") + utils.logAudit("workflowException: " + workflowException) + + boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator") + utils.logAudit("SDNCResponse: " + response) + + SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this) + sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator) + + if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){ + utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response, isDebugLogEnabled) + + if (!"get".equals(method)) + { + def rollbackData = execution.getVariable("rollbackData") + rollbackData.put(Prefix, "rollback" + "SDNC" + method, "true") + execution.setVariable("rollbackData", rollbackData) + } + + }else{ + utils.log("DEBUG", "Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled) + throw new BpmnError("MSOWorkflowException") + } + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in validateSDNCResp. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugLogEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled) + } + + public void preProcessSDNCGet(Execution execution){ + def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", "*** preProcessSDNCGet *** ", isDebugLogEnabled) + try{ + + def callbackUrl = execution.getVariable("sdncCallbackUrl") + // serviceOperation (URI for topology GET) will be retrieved from "selflink" from AAI if active AR exists in AAI + // or from "object-path" in SDNC response for assign when AR does not exist in AA + + String serviceOperation = "" + + if (execution.getVariable("foundActiveAR")) { + def aaiQueryResponse = execution.getVariable("aaiARGetResponse") + serviceOperation = utils.getNodeText1(aaiQueryResponse, "selflink") + utils.log("DEBUG", "AR service operation/aaiARSelfLink: " + serviceOperation, isDebugLogEnabled) + } + else + { + String response = execution.getVariable("sdncAssignResponse") + String data = utils.getNodeXml(response, "response-data") + data = data.replaceAll("<", "<") + data = data.replaceAll(">", ">") + utils.log("DEBUG", "Assign responseData: " + data, isDebugLogEnabled) + serviceOperation = utils.getNodeText1(data, "object-path") + utils.log("DEBUG", "AR service operation:" + serviceOperation, isDebugLogEnabled) + } + + String serviceInstanceId = execution.getVariable("serviceInstanceId") + String sdncRequestId = UUID.randomUUID().toString() + + String tsleep = execution.getVariable("junitSleepMs") + + //workaround for sdnc replication issue + sleep(tsleep == null ? 5000 : tsleep as Long) + + //neeed the same url as used by vfmodules + String SDNCGetRequest = + """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1" + xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1" + xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1"> + <sdncadapter:RequestHeader> + <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId> + <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId> + <sdncadapter:SvcAction>query</sdncadapter:SvcAction> + <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation> + <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl> + <sdncadapter:MsoAction>vfmodule</sdncadapter:MsoAction> + </sdncadapter:RequestHeader> + <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData> + </sdncadapterworkflow:SDNCAdapterWorkflowRequest>""" + + execution.setVariable("sdncGetRequest", SDNCGetRequest) + + }catch(Exception e){ + utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + e, isDebugLogEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + e.getMessage()) + } + utils.log("DEBUG", "*** Exit preProcessSDNCGet *** ", isDebugLogEnabled) + } + + public void updateAaiAROrchStatus(Execution execution, String status){ + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", " *** updateAaiAROrchStatus *** ", isDebugEnabled) + String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR) or create + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath) + utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled) + } + + public void generateOutputs(Execution execution) + { + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** generateOutputs ***** ", isDebugEnabled) + try { + String sdncGetResponse = execution.getVariable("enhancedCallbackRequestData") //unescaped + utils.log("DEBUG", "resp:" + sdncGetResponse, isDebugEnabled) + String arData = utils.getNodeXml(sdncGetResponse, "brg-topology") + arData = utils.removeXmlNamespaces(arData) + + String brga = utils.getNodeXml(arData, "brg-assignments") + String ari = utils.getNodeXml(arData, "allotted-resource-identifiers") + execution.setVariable("allotedResourceName", utils.getNodeText1(ari, "allotted-resource-name")) + } catch (BpmnError e) { + utils.log("DEBUG", "BPMN Error in generateOutputs ", isDebugEnabled) + } catch(Exception ex) { + String msg = "Exception in generateOutputs " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + } + utils.log("DEBUG"," *** Exit generateOutputs *** ", isDebugEnabled) + + } + + public void preProcessRollback (Execution execution) { + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** preProcessRollback ***** ", isDebugEnabled) + try { + + Object workflowException = execution.getVariable("WorkflowException"); + + if (workflowException instanceof WorkflowException) { + utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled) + execution.setVariable("prevWorkflowException", workflowException); + //execution.setVariable("WorkflowException", null); + } + } catch (BpmnError e) { + utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled) + } catch(Exception ex) { + String msg = "Exception in preProcessRollback. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + } + utils.log("DEBUG"," *** Exit preProcessRollback *** ", isDebugEnabled) + } + + public void postProcessRollback (Execution execution) { + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** postProcessRollback ***** ", isDebugEnabled) + String msg = "" + try { + Object workflowException = execution.getVariable("prevWorkflowException"); + if (workflowException instanceof WorkflowException) { + utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled) + execution.setVariable("WorkflowException", workflowException); + } + execution.setVariable("rollbackData", null) + } catch (BpmnError b) { + utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled) + throw b; + } catch(Exception ex) { + msg = "Exception in postProcessRollback. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + } + utils.log("DEBUG"," *** Exit postProcessRollback *** ", isDebugEnabled) + } + +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoCreateAllottedResourceBRGRollback.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoCreateAllottedResourceBRGRollback.groovy new file mode 100644 index 0000000000..0e0f5c2035 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoCreateAllottedResourceBRGRollback.groovy @@ -0,0 +1,258 @@ +/* + * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +package org.openecomp.mso.bpmn.vcpe.scripts; + +import org.openecomp.mso.bpmn.common.scripts.*; +import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.openecomp.mso.bpmn.core.WorkflowException +import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil +import org.openecomp.mso.bpmn.common.scripts.MsoUtils +import org.openecomp.mso.bpmn.common.scripts.AaiUtil +import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils +import org.openecomp.mso.rest.APIResponse + +import java.util.UUID; +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.runtime.Execution +import org.apache.commons.lang3.* +import org.springframework.web.util.UriUtils; +import static org.apache.commons.lang3.StringUtils.* + +/** + * This groovy class supports the <class>CreateAllottedResourceBRGRollback.bpmn</class> process. + * + * @author + * + * Inputs: + * @param - msoRequestId + * @param - isDebugLogEnabled + * @param - disableRollback - O + * @param - rollbackData + * + * Outputs: + * @param - rollbackError + * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true) + * + */ +public class DoCreateAllottedResourceBRGRollback extends AbstractServiceTaskProcessor{ + + String Prefix="DCARBRGRB_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + + public void preProcessRequest (Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled) + execution.setVariable("prefix", Prefix) + String rbType = "DCARBRG_" + try { + + def rollbackData = execution.getVariable("rollbackData") + utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled) + + if (rollbackData != null) { + if (rollbackData.hasType(rbType)) { + + execution.setVariable("serviceInstanceId", rollbackData.get(rbType, "serviceInstanceId")) + execution.setVariable("parentServiceInstanceId", rollbackData.get(rbType, "parentServiceInstanceId")) + execution.setVariable("allottedResourceId", rollbackData.get("SERVICEINSTANCE", "allottedResourceId")) + + + def rollbackAAI = rollbackData.get(rbType, "rollbackAAI") + if ("true".equals(rollbackAAI)) + { + execution.setVariable("rollbackAAI",true) + execution.setVariable("aaiARPath", rollbackData.get(rbType, "aaiARPath")) + + } + def rollbackSDNC = rollbackData.get(rbType, "rollbackSDNCassign") + if ("true".equals(rollbackSDNC)) + { + execution.setVariable("rollbackSDNC", true) + execution.setVariable("deactivateSdnc", rollbackData.get(rbType, "rollbackSDNCactivate")) + execution.setVariable("deleteSdnc", rollbackData.get(rbType, "rollbackSDNCcreate")) + execution.setVariable("unassignSdnc", rollbackData.get(rbType, "rollbackSDNCassign")) + + utils.log("DEBUG","sdncDeactivate:\n" + execution.getVariable("deactivateSdnc") , isDebugEnabled) + utils.log("DEBUG","sdncDelete:\n" + execution.getVariable("deleteSdnc"), isDebugEnabled) + utils.log("DEBUG","sdncUnassign:\n" + execution.getVariable("unassignSdnc"), isDebugEnabled) + + execution.setVariable("sdncDeactivateRequest", rollbackData.get(rbType, "sdncActivateRollbackReq")) + execution.setVariable("sdncDeleteRequest", rollbackData.get(rbType, "sdncCreateRollbackReq")) + execution.setVariable("sdncUnassignRequest", rollbackData.get(rbType, "sdncAssignRollbackReq")) + } + + if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true) + { + execution.setVariable("skipRollback", true) + } + } + else { + execution.setVariable("skipRollback", true) + } + } + else { + execution.setVariable("skipRollback", true) + } + if (execution.getVariable("disableRollback").equals("true" )) + { + execution.setVariable("skipRollback", true) + } + + }catch(BpmnError b){ + utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled) + throw b + } catch (Exception ex){ + msg = "Exception in preProcessRequest " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled) + } + + // aaiARPath set during query (existing AR) + public void updateAaiAROrchStatus(Execution execution, String status){ + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = null; + utils.log("DEBUG", " *** updateAaiAROrchStatus ***", isDebugEnabled) + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String aaiARPath = execution.getVariable("aaiARPath") + utils.log("DEBUG", " aaiARPath:" + aaiARPath, isDebugEnabled) + String ar = null; //need this for getting resourceVersion for delete + if (!isBlank(aaiARPath)) + { + ar = arUtils.getARbyLink(execution, aaiARPath, "") + } + if (isBlank(ar)) + { + msg = "AR not found in AAI at:" + aaiARPath + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath) + utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled) + } + + public void validateSDNCResp(Execution execution, String response, String method){ + + def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled) + String msg = "" + + try { + WorkflowException workflowException = execution.getVariable("WorkflowException") + utils.logAudit("workflowException: " + workflowException) + + boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator") + utils.logAudit("SDNCResponse: " + response) + + SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this) + sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator) + + if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){ + utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response, isDebugLogEnabled) + + }else{ + + utils.log("DEBUG", "Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled) + throw new BpmnError("MSOWorkflowException") + } + } catch (BpmnError e) { + if (e.getErrorCode() == 404) + { + msg = "SDNC rollback " + method + " returned a 404. Proceding with rollback" + utils.log("DEBUG", msg, isDebugEnabled) + } + else { + throw e; + } + } catch(Exception ex) { + msg = "Exception in validateSDNCResp. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled) + } + + public void deleteAaiAR(Execution execution){ + def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled") + try{ + utils.log("DEBUG", " *** deleteAaiAR *** ", isDebugLogEnabled) + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String ar = null //need to get resource-version + String arLink = execution.getVariable("aaiARPath") + if (!isBlank(arLink)) + { + ar = arUtils.getARbyLink(execution, arLink, "") + } + arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8")) + } catch (BpmnError e) { + throw e; + }catch(Exception ex){ + utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + ex, isDebugLogEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage()) + } + utils.log("DEBUG", " *** Exit deleteAaiAR *** ", isDebugLogEnabled) + } + + public void postProcessRequest(Execution execution) { + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled) + String msg = "" + try { + execution.setVariable("rollbackData", null) + boolean skipRollback = execution.getVariable("skipRollback") + if (skipRollback != true) + { + execution.setVariable("rolledBack", true) + utils.log("DEBUG","rolledBack", isDebugEnabled) + } + utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled) + + } catch (BpmnError e) { + msg = "Bpmn Exception in postProcessRequest. " + utils.log("DEBUG", msg, isDebugEnabled) + } catch (Exception ex) { + msg = "Exception in postProcessRequest. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + } + + } + + public void processRollbackException(Execution execution){ + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled) + try{ + utils.log("DEBUG", "Caught an Exception in DoCreateAllottedResourceRollback", isDebugEnabled) + execution.setVariable("rollbackData", null) + execution.setVariable("rolledBack", false) + execution.setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback") + execution.setVariable("WorkflowException", null) + + }catch(BpmnError b){ + utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled) + }catch(Exception e){ + utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled) + } + + utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled) + } + + public void processRollbackJavaException(Execution execution){ + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled) + try{ + execution.setVariable("rollbackData", null) + execution.setVariable("rolledBack", false) + execution.setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback") + utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled) + + }catch(Exception e){ + utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled) + } + utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled) + } + +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoCreateAllottedResourceTXC.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoCreateAllottedResourceTXC.groovy new file mode 100644 index 0000000000..28f3d6a771 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoCreateAllottedResourceTXC.groovy @@ -0,0 +1,643 @@ +/* + * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +package org.openecomp.mso.bpmn.vcpe.scripts; + +import org.openecomp.mso.bpmn.common.scripts.*; +import org.openecomp.mso.bpmn.common.scripts.AaiUtil +import org.openecomp.mso.bpmn.core.RollbackData +import org.openecomp.mso.bpmn.core.WorkflowException +import org.openecomp.mso.bpmn.core.json.JsonUtils +import org.openecomp.mso.rest.APIResponse + +import java.util.UUID; +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.runtime.Execution +import org.apache.commons.lang3.* +import org.springframework.web.util.UriUtils; +import static org.apache.commons.lang3.StringUtils.* + + +/** + * This groovy class supports the <class>DoCreateAllottedResourceTXC.bpmn</class> process. + * + * @author + * + * Inputs: + * @param - msoRequestId + * @param - isDEbugLogEnabled + * @param - disableRollback + * @param - failExists - O + * @param - serviceInstanceId + * @param - parentServiceInstanceId + * @param - allottedReourceId - O + * @param - allottedResourceModelInfo + * @param - allottedResourceRole + * @param - allottedResourceType + * @param - brgWanMacAddress + * + * Outputs: + * @param - rollbackData (localRB->null) + * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true) + * @param - WorkflowException - O + * @param - allottedResourceId + * @param - allottedResourceName + * @param - vni + * @param - vgmuxBearerIP + * @param - vgmuxLanIP + * + */ +public class DoCreateAllottedResourceTXC extends AbstractServiceTaskProcessor{ + + String Prefix="DCARTXC_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + + public void preProcessRequest (Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled) + + try { + execution.setVariable("prefix", Prefix) + + //Config Inputs + String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback') + if (isBlank(sdncCallbackUrl)) { + msg = "URN_mso_workflow_sdncadapter_callback is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + execution.setVariable("sdncCallbackUrl", sdncCallbackUrl) + utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled) + + //Request Inputs + if (isBlank(execution.getVariable("serviceInstanceId"))){ + msg = "Input serviceInstanceId is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("parentServiceInstanceId"))) { + msg = "Input parentServiceInstanceId is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("allottedResourceModelInfo"))) { + msg = "Input allottedResourceModelInfo is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("brgWanMacAddress"))) { + msg = "Input brgWanMacAddress is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("allottedResourceRole"))) { + msg = "Input allottedResourceRole is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("allottedResourceType"))) { + msg = "Input allottedResourceType is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + }catch(BpmnError b){ + utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled) + throw b + } catch (Exception ex){ + msg = "Exception in preProcessRequest " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled) + } + + public void getAaiAR (Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** getAaiAR ***** ", isDebugEnabled) + + String arType = execution.getVariable("allottedResourceType") + String arRole = execution.getVariable("allottedResourceRole") + + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String orchStatus = arUtils.getAROrchStatus(execution) + + String errorMsg = "" + + if (orchStatus != null) // AR was found + { + if ("true".equals(execution.getVariable("failExists"))) + { + errorMsg = "Allotted resource " + arType + " with Role " + arRole + " already exists" + } + else + { + if ("Active".equals(orchStatus)) + { + execution.setVariable("foundActiveAR", true) + } + else // blanks included + { + errorMsg = "Allotted Resource " + arType + " with Role " + arRole + " already exists in an incomplete state -" + orchStatus + } + } + } + if (!isBlank(errorMsg)) { + utils.log("DEBUG", errorMsg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg) + } + utils.log("DEBUG"," *****Exit getAaiAR *****", isDebugEnabled) + } + + public void createAaiAR(Execution execution) { + + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** createAaiAR ***** ", isDebugEnabled) + String msg = "" + + String allottedResourceId = execution.getVariable("allottedResourceId") + if (isBlank(allottedResourceId)) + { + allottedResourceId = UUID.randomUUID().toString() + execution.setVariable("allottedResourceId", allottedResourceId) + } + String arUrl = "" + try { + + //AAI PUT + AaiUtil aaiUriUtil = new AaiUtil(this) + String aaiEndpoint = execution.getVariable("URN_aai_endpoint") + String siResourceLink= execution.getVariable("PSI_resourceLink") + + String siUri = "" + utils.log("DEBUG", "PSI_resourceLink:" + siResourceLink, isDebugEnabled) + + if(!isBlank(siResourceLink)) { + utils.log("DEBUG", "Incoming PSI Resource Link is: " + siResourceLink, isDebugEnabled) + String[] split = siResourceLink.split("/aai/") + siUri = "/aai/" + split[1] + } + else + { + msg = "Parent Service Link in AAI is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + arUrl = "${aaiEndpoint}${siUri}" + "/allotted-resources/allotted-resource/" + UriUtils.encode(allottedResourceId,"UTF-8") + execution.setVariable("aaiARPath", arUrl) + utils.log("DEBUG", "GET AllottedResource AAI URL is:\n" + arUrl, isDebugEnabled) + + String namespace = aaiUriUtil.getNamespaceFromUri(execution, arUrl) + + String arType = execution.getVariable("allottedResourceType") + String arRole = execution.getVariable("allottedResourceRole") + String CSI_resourceLink = execution.getVariable("CSI_resourceLink") + String arModelInfo = execution.getVariable("allottedResourceModelInfo") + String modelInvariantId = jsonUtil.getJsonValue(arModelInfo, "modelInvariantUuid") + String modelVersionId = jsonUtil.getJsonValue(arModelInfo, "modelUuid") + String modelCustomizationId = jsonUtil.getJsonValue(arModelInfo, "modelCustomizationUuid") + + if (modelInvariantId == null) { + modelInvariantId = "" + } + if (modelVersionId == null) { + modelVersionId = "" + } + if (modelCustomizationId == null) { + modelCustomizationId = "" + } + + String payload = + """<allotted-resource xmlns="${namespace}"> + <id>${allottedResourceId}</id> + <description></description> + <type>${arType}</type> + <role>${arRole}</role> + <selflink></selflink> + <model-invariant-id>${modelInvariantId}</model-invariant-id> + <model-version-id>${modelVersionId}</model-version-id> + <model-customization-id>${modelCustomizationId}</model-customization-id> + <orchestration-status>PendingCreate</orchestration-status> + <operation-status></operation-status> + <relationship-list> + <relationship> + <related-to>service-instance</related-to> + <related-link>${CSI_resourceLink}</related-link> + </relationship> + </relationship-list> + </allotted-resource>""".trim() + + execution.setVariable("AaiARPayload", payload) + utils.log("DEBUG", " payload to create AllottedResource in AAI:" + "\n" + payload, isDebugEnabled) + + APIResponse response = aaiUriUtil.executeAAIPutCall(execution, arUrl, payload) + int responseCode = response.getStatusCode() + utils.log("DEBUG", "AllottedResource AAI PUT responseCode:" + responseCode, isDebugEnabled) + + String aaiResponse = response.getResponseBodyAsString() + aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse) + utils.log("DEBUG", "AllottedResource AAI PUT responseStr:" + aaiResponse, isDebugEnabled) + + //200 OK 201 CREATED 202 ACCEPTED + if(responseCode == 200 || responseCode == 201 || responseCode == 202 ) + { + utils.log("DEBUG", "AAI PUT AllottedResource received a Good Response", isDebugEnabled) + } + else{ + utils.log("DEBUG", "AAI Put AllottedResouce received a Bad Response Code: " + responseCode, isDebugEnabled) + exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode) + throw new BpmnError("MSOWorkflowException") + } + }catch(BpmnError b){ + utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled) + throw b + } catch (Exception ex) { + msg = "Exception in createAaiAR " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + //start rollback set up + RollbackData rollbackData = new RollbackData() + def disableRollback = execution.getVariable("disableRollback") + rollbackData.put(Prefix, "disableRollback", disableRollback.toString()) + rollbackData.put(Prefix, "rollbackAAI", "true") + rollbackData.put(Prefix, "allottedResourceId", allottedResourceId) + rollbackData.put(Prefix, "serviceInstanceId", execution.getVariable("serviceInstanceId")) + rollbackData.put(Prefix, "parentServiceInstanceId", execution.getVariable("parentServiceInstanceId")) + rollbackData.put(Prefix, "aaiARPath", arUrl) + execution.setVariable("rollbackData", rollbackData) + utils.log("DEBUG"," *** Exit createAaiAR*** ", isDebugEnabled) + } + + public String buildSDNCRequest(Execution execution, String action, String sdncRequestId) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** buildSDNCRequest *****", isDebugEnabled) + String sdncReq = null + + try { + + String allottedResourceId = execution.getVariable("allottedResourceId") + String serviceInstanceId = execution.getVariable("serviceInstanceId") + String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId") + String serviceChainServiceInstanceId = execution.getVariable("serviceChainServiceInstanceId") + String callbackUrl = execution.getVariable("sdncCallbackUrl") + String requestId = execution.getVariable("msoRequestId") + + String brgWanMacAddress = execution.getVariable("brgWanMacAddress") + + String arModelInfo = execution.getVariable("allottedResourceModelInfo") + String modelInvariantId = jsonUtil.getJsonValue(arModelInfo, "modelInvariantUuid") + String modelVersion = jsonUtil.getJsonValue(arModelInfo, "modelVersion") + String modelUUId = jsonUtil.getJsonValue(arModelInfo, "modelUuid") + String modelCustomizationId = jsonUtil.getJsonValue(arModelInfo, "modelCustomizationUuid") + String modelName = jsonUtil.getJsonValue(arModelInfo, "modelName") + + if (modelInvariantId == null) { + modelInvariantId = "" + } + if (modelVersion == null) { + modelVersion = "" + } + if (modelUUId == null) { + modelUUId = "" + } + if (modelName == null) { + modelName = "" + } + if (modelCustomizationId == null) { + modelCustomizationId = "" + } + + sdncReq = + """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1" + xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1" + xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1"> + <sdncadapter:RequestHeader> + <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId> + <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId> + <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction> + <sdncadapter:SvcOperation>tunnelxconn-topology-operation</sdncadapter:SvcOperation> + <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl> + </sdncadapter:RequestHeader> + <sdncadapterworkflow:SDNCRequestData> + <request-information> + <request-id>${requestId}</request-id> + <request-action>CreateTunnelXConnInstance</request-action> + <source>MSO</source> + <notification-url/> + <order-number/> + <order-version/> + </request-information> + <service-information> + <service-id></service-id> + <subscription-service-type></subscription-service-type> + <ecomp-model-information></ecomp-model-information> + <service-instance-id>${parentServiceInstanceId}</service-instance-id> + <subscriber-name/> + <global-customer-id></global-customer-id> + </service-information> + <allotted-resource-information> + <allotted-resource-id>${allottedResourceId}</allotted-resource-id> + <allotted-resource-type>tunnelxconn</allotted-resource-type> + <parent-service-instance-id>${parentServiceInstanceId}</parent-service-instance-id> + <ecomp-model-information> + <model-invariant-uuid>${modelInvariantId}</model-invariant-uuid> + <model-uuid>${modelUUId}</model-uuid> + <model-customization-uuid>${modelCustomizationId}</model-customization-uuid> + <model-version>${modelVersion}</model-version> + <model-name>${modelName}</model-name> + </ecomp-model-information> + </allotted-resource-information> + <tunnelxconn-request-input> + <brg-wan-mac-address>${brgWanMacAddress}</brg-wan-mac-address> + </tunnelxconn-request-input> + </sdncadapterworkflow:SDNCRequestData> + </sdncadapterworkflow:SDNCAdapterWorkflowRequest>""" + + utils.log("DEBUG","sdncRequest:\n" + sdncReq, isDebugEnabled) + sdncReq = utils.formatXml(sdncReq) + + } catch(Exception ex) { + msg = "Exception in buildSDNCRequest. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit buildSDNCRequest *****", isDebugEnabled) + return sdncReq + } + + public void preProcessSDNCAssign(Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessSDNCAssign *****", isDebugEnabled) + + try { + String sdncRequestId = UUID.randomUUID().toString() + String sdncAssignReq = buildSDNCRequest(execution, "assign", sdncRequestId) + execution.setVariable("sdncAssignRequest", sdncAssignReq) + utils.logAudit("sdncAssignRequest: " + sdncAssignReq) + def sdncRequestId2 = UUID.randomUUID().toString() + String sdncAssignRollbackReq = sdncAssignReq.replace(">assign<", ">unassign<").replace(">CreateTunnelXConnInstance<", ">DeleteTunnelXConnInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<") + def rollbackData = execution.getVariable("rollbackData") + rollbackData.put(Prefix, "sdncAssignRollbackReq", sdncAssignRollbackReq) + execution.setVariable("rollbackData", rollbackData) + + utils.log("DEBUG","sdncAssignRollbackReq:\n" + sdncAssignRollbackReq, isDebugEnabled) + utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled) + + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCAssign. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit preProcessSDNCAssign *****", isDebugEnabled) + } + + public void preProcessSDNCCreate(Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessSDNCCreate *****", isDebugEnabled) + + try { + String sdncRequestId = UUID.randomUUID().toString() + String sdncCreateReq = buildSDNCRequest(execution, "create", sdncRequestId) + execution.setVariable("sdncCreateRequest", sdncCreateReq) + utils.logAudit("sdncCreateReq: " + sdncCreateReq) + def sdncRequestId2 = UUID.randomUUID().toString() + String sdncCreateRollbackReq = sdncCreateReq.replace(">create<", ">delete<").replace(">CreateTunnelXConnInstance<", ">DeleteTunnelXConnInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<") + def rollbackData = execution.getVariable("rollbackData") + rollbackData.put(Prefix, "sdncCreateRollbackReq", sdncCreateRollbackReq) + execution.setVariable("rollbackData", rollbackData) + + utils.log("DEBUG","sdncCreateRollbackReq:\n" + sdncCreateRollbackReq, isDebugEnabled) + utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled) + + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCCreate. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit preProcessSDNCCreate *****", isDebugEnabled) + } + + public void preProcessSDNCActivate(Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessSDNCActivate *****", isDebugEnabled) + + try { + String sdncRequestId = UUID.randomUUID().toString() + String sdncActivateReq = buildSDNCRequest(execution, "activate", sdncRequestId) + execution.setVariable("sdncActivateRequest", sdncActivateReq) + utils.logAudit("sdncActivateReq: " + sdncActivateReq) + def sdncRequestId2 = UUID.randomUUID().toString() + String sdncActivateRollbackReq = sdncActivateReq.replace(">activate<", ">deactivate<").replace(">CreateTunnelXConnInstance<", ">DeleteTunnelXConnInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<") + def rollbackData = execution.getVariable("rollbackData") + rollbackData.put(Prefix, "sdncActivateRollbackReq", sdncActivateRollbackReq) + execution.setVariable("rollbackData", rollbackData) + + utils.log("DEBUG","sdncActivateRollbackReq:\n" + sdncActivateRollbackReq, isDebugEnabled) + utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled) + + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCActivate. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit preProcessSDNCActivate *****", isDebugEnabled) + } + + public void validateSDNCResp(Execution execution, String response, String method){ + + def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled) + String msg = "" + + try { + WorkflowException workflowException = execution.getVariable("WorkflowException") + utils.logAudit("workflowException: " + workflowException) + + boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator") + utils.logAudit("SDNCResponse: " + response) + + SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this) + sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator) + + if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){ + utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response, isDebugLogEnabled) + + if (!"get".equals(method)) + { + def rollbackData = execution.getVariable("rollbackData") + rollbackData.put(Prefix, "rollback" + "SDNC" + method, "true") + execution.setVariable("rollbackData", rollbackData) + } + + }else{ + utils.log("DEBUG", "Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled) + throw new BpmnError("MSOWorkflowException") + } + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in validateSDNCResp. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled) + } + + public void preProcessSDNCGet(Execution execution){ + def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", "*** preProcessSDNCGet *** ", isDebugLogEnabled) + try{ + + def callbackUrl = execution.getVariable("sdncCallbackUrl") + // serviceOperation (URI for topology GET) will be retrieved from "selflink" from AAI if active AR exists in AAI + // or from "object-path" in SDNC response for assign when AR does not exist in AA + + String serviceOperation = "" + + if (execution.getVariable("foundActiveAR")) { + def aaiQueryResponse = execution.getVariable("aaiARGetResponse") + serviceOperation = utils.getNodeText1(aaiQueryResponse, "selflink") + utils.log("DEBUG", "AR service operation/aaiARSelfLink: " + serviceOperation, isDebugLogEnabled) + } + else + { + String response = execution.getVariable("sdncAssignResponse") + String data = utils.getNodeXml(response, "response-data") + data = data.replaceAll("<", "<") + data = data.replaceAll(">", ">") + utils.log("DEBUG", "Assign responseData: " + data, isDebugLogEnabled) + serviceOperation = utils.getNodeText1(data, "object-path") + utils.log("DEBUG", "AR service operation:" + serviceOperation, isDebugLogEnabled) + } + + String serviceInstanceId = execution.getVariable("serviceInstanceId") + String sdncRequestId = UUID.randomUUID().toString() + + String tsleep = execution.getVariable("junitSleepMs") + + //workaround for sdnc replication issue + sleep(tsleep == null ? 5000 : tsleep as Long) + + //neeed the same url as used by vfmodules + String SDNCGetRequest = + """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1" + xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1" + xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1"> + <sdncadapter:RequestHeader> + <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId> + <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId> + <sdncadapter:SvcAction>query</sdncadapter:SvcAction> + <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation> + <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl> + <sdncadapter:MsoAction>vfmodule</sdncadapter:MsoAction> + </sdncadapter:RequestHeader> + <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData> + </sdncadapterworkflow:SDNCAdapterWorkflowRequest>""" + + execution.setVariable("sdncGetRequest", SDNCGetRequest) + + }catch(Exception e){ + utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + e, isDebugLogEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + e.getMessage()) + } + utils.log("DEBUG", "*** Exit preProcessSDNCGet *** ", isDebugLogEnabled) + } + + public void updateAaiAROrchStatus(Execution execution, String status){ + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", " *** updateAaiAROrchStatus *** ", isDebugEnabled) + String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR) or create + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath) + utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled) + } + + public void generateOutputs(Execution execution) + { + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** generateOutputs ***** ", isDebugEnabled) + try { + String sdncGetResponse = execution.getVariable("enhancedCallbackRequestData") //unescaped + utils.log("DEBUG", "resp:" + sdncGetResponse, isDebugEnabled) + String arData = utils.getNodeXml(sdncGetResponse, "tunnelxconn-topology") + arData = utils.removeXmlNamespaces(arData) + + String txca = utils.getNodeXml(arData, "tunnelxconn-assignments") + String ari = utils.getNodeXml(arData, "allotted-resource-identifiers") + execution.setVariable("allotedResourceName", utils.getNodeText1(ari, "allotted-resource-name")) + execution.setVariable("vni", utils.getNodeText1(ari, "vni")) + execution.setVariable("vgmuxBearerIp", utils.getNodeText1(ari, "vgmux_bearer_ip")) + execution.setVariable("vgmuxLanIP", utils.getNodeText1(ari, "vgmux_lan_ip")) + } catch (BpmnError e) { + utils.log("DEBUG", "BPMN Error in generateOutputs ", isDebugEnabled) + } catch(Exception ex) { + String msg = "Exception in generateOutputs " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + } + utils.log("DEBUG"," *** Exit generateOutputs *** ", isDebugEnabled) + + } + + public void preProcessRollback (Execution execution) { + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** preProcessRollback ***** ", isDebugEnabled) + try { + + Object workflowException = execution.getVariable("WorkflowException"); + + if (workflowException instanceof WorkflowException) { + utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled) + execution.setVariable("prevWorkflowException", workflowException); + //execution.setVariable("WorkflowException", null); + } + } catch (BpmnError e) { + utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled) + } catch(Exception ex) { + String msg = "Exception in preProcessRollback. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + } + utils.log("DEBUG"," *** Exit preProcessRollback *** ", isDebugEnabled) + } + + public void postProcessRollback (Execution execution) { + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** postProcessRollback ***** ", isDebugEnabled) + String msg = "" + try { + Object workflowException = execution.getVariable("prevWorkflowException"); + if (workflowException instanceof WorkflowException) { + utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled) + execution.setVariable("WorkflowException", workflowException); + } + execution.setVariable("rollbackData", null) + } catch (BpmnError b) { + utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled) + throw b; + } catch(Exception ex) { + msg = "Exception in postProcessRollback. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + } + utils.log("DEBUG"," *** Exit postProcessRollback *** ", isDebugEnabled) + } + +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoCreateAllottedResourceTXCRollback.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoCreateAllottedResourceTXCRollback.groovy new file mode 100644 index 0000000000..142ddde6b5 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoCreateAllottedResourceTXCRollback.groovy @@ -0,0 +1,258 @@ +/* + * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +package org.openecomp.mso.bpmn.vcpe.scripts; + +import org.openecomp.mso.bpmn.common.scripts.*; +import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.openecomp.mso.bpmn.core.WorkflowException +import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil +import org.openecomp.mso.bpmn.common.scripts.MsoUtils +import org.openecomp.mso.bpmn.common.scripts.AaiUtil +import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils +import org.openecomp.mso.rest.APIResponse + +import java.util.UUID; +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.runtime.Execution +import org.apache.commons.lang3.* +import org.springframework.web.util.UriUtils; +import static org.apache.commons.lang3.StringUtils.* + +/** + * This groovy class supports the <class>CreateAllottedResourceTXCRollback.bpmn</class> process. + * + * @author + * + * Inputs: + * @param - msoRequestId + * @param - isDebugLogEnabled + * @param - disableRollback - O + * @param - rollbackData + * + * Outputs: + * @param - rollbackError + * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true) + * + */ +public class DoCreateAllottedResourceTXCRollback extends AbstractServiceTaskProcessor{ + + String Prefix="DCARTXCRB_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + + public void preProcessRequest (Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled) + execution.setVariable("prefix", Prefix) + String rbType = "DCARTXC_" + try { + + def rollbackData = execution.getVariable("rollbackData") + utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled) + + if (rollbackData != null) { + if (rollbackData.hasType(rbType)) { + + execution.setVariable("serviceInstanceId", rollbackData.get(rbType, "serviceInstanceId")) + execution.setVariable("parentServiceInstanceId", rollbackData.get(rbType, "parentServiceInstanceId")) + execution.setVariable("allottedResourceId", rollbackData.get("SERVICEINSTANCE", "allottedResourceId")) + + + def rollbackAAI = rollbackData.get(rbType, "rollbackAAI") + if ("true".equals(rollbackAAI)) + { + execution.setVariable("rollbackAAI",true) + execution.setVariable("aaiARPath", rollbackData.get(rbType, "aaiARPath")) + + } + def rollbackSDNC = rollbackData.get(rbType, "rollbackSDNCassign") + if ("true".equals(rollbackSDNC)) + { + execution.setVariable("rollbackSDNC", true) + execution.setVariable("deactivateSdnc", rollbackData.get(rbType, "rollbackSDNCactivate")) + execution.setVariable("deleteSdnc", rollbackData.get(rbType, "rollbackSDNCcreate")) + execution.setVariable("unassignSdnc", rollbackData.get(rbType, "rollbackSDNCassign")) + + utils.log("DEBUG","sdncDeactivate:\n" + execution.getVariable("deactivateSdnc") , isDebugEnabled) + utils.log("DEBUG","sdncDelete:\n" + execution.getVariable("deleteSdnc"), isDebugEnabled) + utils.log("DEBUG","sdncUnassign:\n" + execution.getVariable("unassignSdnc"), isDebugEnabled) + + execution.setVariable("sdncDeactivateRequest", rollbackData.get(rbType, "sdncActivateRollbackReq")) + execution.setVariable("sdncDeleteRequest", rollbackData.get(rbType, "sdncCreateRollbackReq")) + execution.setVariable("sdncUnassignRequest", rollbackData.get(rbType, "sdncAssignRollbackReq")) + } + + if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true) + { + execution.setVariable("skipRollback", true) + } + } + else { + execution.setVariable("skipRollback", true) + } + } + else { + execution.setVariable("skipRollback", true) + } + if (execution.getVariable("disableRollback").equals("true" )) + { + execution.setVariable("skipRollback", true) + } + + }catch(BpmnError b){ + utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled) + throw b + } catch (Exception ex){ + msg = "Exception in preProcessRequest " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled) + } + + // aaiARPath set during query (existing AR) + public void updateAaiAROrchStatus(Execution execution, String status){ + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = null; + utils.log("DEBUG", " *** updateAaiAROrchStatus ***", isDebugEnabled) + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String aaiARPath = execution.getVariable("aaiARPath") + utils.log("DEBUG", " aaiARPath:" + aaiARPath, isDebugEnabled) + String ar = null; //need this for getting resourceVersion for delete + if (!isBlank(aaiARPath)) + { + ar = arUtils.getARbyLink(execution, aaiARPath, "") + } + if (isBlank(ar)) + { + msg = "AR not found in AAI at:" + aaiARPath + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath) + utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled) + } + + public void validateSDNCResp(Execution execution, String response, String method){ + + def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled) + String msg = "" + + try { + WorkflowException workflowException = execution.getVariable("WorkflowException") + utils.logAudit("workflowException: " + workflowException) + + boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator") + utils.logAudit("SDNCResponse: " + response) + + SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this) + sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator) + + if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){ + utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response, isDebugLogEnabled) + + }else{ + + utils.log("DEBUG", "Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled) + throw new BpmnError("MSOWorkflowException") + } + } catch (BpmnError e) { + if (e.getErrorCode() == 404) + { + msg = "SDNC rollback " + method + " returned a 404. Proceding with rollback" + utils.log("DEBUG", msg, isDebugEnabled) + } + else { + throw e; + } + } catch(Exception ex) { + msg = "Exception in validateSDNCResp. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled) + } + + public void deleteAaiAR(Execution execution){ + def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled") + try{ + utils.log("DEBUG", " *** deleteAaiAR *** ", isDebugLogEnabled) + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String ar = null //need to get resource-version + String arLink = execution.getVariable("aaiARPath") + if (!isBlank(arLink)) + { + ar = arUtils.getARbyLink(execution, arLink, "") + } + arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8")) + } catch (BpmnError e) { + throw e; + }catch(Exception ex){ + utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + ex, isDebugLogEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage()) + } + utils.log("DEBUG", " *** Exit deleteAaiAR *** ", isDebugLogEnabled) + } + + public void postProcessRequest(Execution execution) { + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled) + String msg = "" + try { + execution.setVariable("rollbackData", null) + boolean skipRollback = execution.getVariable("skipRollback") + if (skipRollback != true) + { + execution.setVariable("rolledBack", true) + utils.log("DEBUG","rolledBack", isDebugEnabled) + } + utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled) + + } catch (BpmnError e) { + msg = "Bpmn Exception in postProcessRequest. " + utils.log("DEBUG", msg, isDebugEnabled) + } catch (Exception ex) { + msg = "Exception in postProcessRequest. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + } + + } + + public void processRollbackException(Execution execution){ + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled) + try{ + utils.log("DEBUG", "Caught an Exception in DoCreateAllottedResourceRollback", isDebugEnabled) + execution.setVariable("rollbackData", null) + execution.setVariable("rolledBack", false) + execution.setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback") + execution.setVariable("WorkflowException", null) + + }catch(BpmnError b){ + utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled) + }catch(Exception e){ + utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled) + } + + utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled) + } + + public void processRollbackJavaException(Execution execution){ + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled) + try{ + execution.setVariable("rollbackData", null) + execution.setVariable("rolledBack", false) + execution.setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback") + utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled) + + }catch(Exception e){ + utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled) + } + utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled) + } + +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoDeleteAllottedResourceBRG.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoDeleteAllottedResourceBRG.groovy new file mode 100644 index 0000000000..9dbca8664b --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoDeleteAllottedResourceBRG.groovy @@ -0,0 +1,349 @@ +/* + * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +package org.openecomp.mso.bpmn.vcpe.scripts; + +import org.openecomp.mso.bpmn.common.scripts.*; +import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.openecomp.mso.bpmn.core.WorkflowException +import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil +import org.openecomp.mso.bpmn.common.scripts.MsoUtils +import org.openecomp.mso.bpmn.common.scripts.AaiUtil +import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils +import org.openecomp.mso.rest.APIResponse + +import java.util.UUID; +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.runtime.Execution +import org.apache.commons.lang3.* +import org.springframework.web.util.UriUtils; +import static org.apache.commons.lang3.StringUtils.* + +/** + * This groovy class supports the <class>DoDeleteAllottedResourceBRG.bpmn</class> process. + * + * @author + * + * Inputs: + * @param - msoRequestId + * @param - isDebugLogEnabled + * @param - disableRollback - O ignored + * @param - failNotfound - O + * @param - serviceInstanceId + * @param - allottedResourceId + * + * Outputs: + * @param - rollbackData - N/A + * @param - rolledBack - true if no deletions performed + * @param - WorkflowException - O + * @param - wasDeleted - O (ie not silentSuccess) + * + */ +public class DoDeleteAllottedResourceBRG extends AbstractServiceTaskProcessor{ + + String Prefix="DDARBRG_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + + public void preProcessRequest (Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled) + + try { + execution.setVariable("prefix", Prefix) + + //Config Inputs + String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback') + if (isBlank(sdncCallbackUrl)) { + msg = "URN_mso_workflow_sdncadapter_callback is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + execution.setVariable("sdncCallbackUrl", sdncCallbackUrl) + utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled) + + //Request Inputs + if (isBlank(execution.getVariable("serviceInstanceId"))){ + msg = "Input serviceInstanceId is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("allottedResourceId"))){ + msg = "Input allottedResourceId is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + }catch(BpmnError b){ + utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled) + throw b + } catch (Exception ex){ + msg = "Exception in preProcessRequest " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled) + } + + public void getAaiAR (Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** getAaiAR ***** ", isDebugEnabled) + + String allottedResourceId = execution.getVariable("allottedResourceId") + + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String ar = arUtils.getARbyId(execution, allottedResourceId) + + String errorMsg = "" + if (isBlank(ar)) // AR was !found + { + errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId + } + else + { + String aaiARPath = execution.getVariable("aaiARPath") + String parentServiceInstanceId = arUtils.getPSIFmARLink(execution, aaiARPath) + execution.setVariable("parentServiceInstanceId", parentServiceInstanceId) + } + if (!isBlank(errorMsg)) { + utils.log("DEBUG", errorMsg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg) + } + utils.log("DEBUG"," ***** getAaiAR *****", isDebugEnabled) + + } + + // aaiARPath set during query (existing AR) + public void updateAaiAROrchStatus(Execution execution, String status){ + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", " *** updateAaiAROrchStatus *** ", isDebugEnabled) + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR) + String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath) + utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled) + } + + public String buildSDNCRequest(Execution execution, String action, String sdncRequestId) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** buildSDNCRequest *****", isDebugEnabled) + String sdncReq = null + + try { + + String allottedResourceId = execution.getVariable("allottedResourceId") + String serviceInstanceId = execution.getVariable("serviceInstanceId") + String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId") + + String callbackUrl = execution.getVariable("sdncCallbackUrl") + String requestId = execution.getVariable("msoRequestId") + + String serviceChainServiceInstanceId = "" + String sourceNetworkId = "" + String sourceNetworkRole = "" + String allottedResourceRole = "" + + String arModelInfo = "" + String modelInvariantId = "" + String modelVersion = "" + String modelUUId = "" + String modelCustomizationId = "" + String modelName = "" + + + sdncReq = + """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1" + xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1" + xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1"> + <sdncadapter:RequestHeader> + <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId> + <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId> + <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction> + <sdncadapter:SvcOperation>brg-topology-operation</sdncadapter:SvcOperation> + <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl> + </sdncadapter:RequestHeader> + <sdncadapterworkflow:SDNCRequestData> + <request-information> + <request-id>${requestId}</request-id> + <request-action>DeleteBRGInstance</request-action> + <source>MSO</source> + <notification-url/> + <order-number/> + <order-version/> + </request-information> + <service-information> + <service-id></service-id> + <subscription-service-type></subscription-service-type> + <ecomp-model-information></ecomp-model-information> + <service-instance-id>${parentServiceInstanceId}</service-instance-id> + <subscriber-name/> + <global-customer-id></global-customer-id> + </service-information> + <allotted-resource-information> + <allotted-resource-id>${allottedResourceId}</allotted-resource-id> + <allotted-resource-type>brg</allotted-resource-type> + <parent-service-instance-id>${parentServiceInstanceId}</parent-service-instance-id> + <ecomp-model-information> + <model-invariant-uuid>${modelInvariantId}</model-invariant-uuid> + <model-uuid>${modelUUId}</model-uuid> + <model-customization-uuid>${modelCustomizationId}</model-customization-uuid> + <model-version>${modelVersion}</model-version> + <model-name>${modelName}</model-name> + </ecomp-model-information> + </allotted-resource-information> + <brg-request-input> + </brg-request-input> + </sdncadapterworkflow:SDNCRequestData> + </sdncadapterworkflow:SDNCAdapterWorkflowRequest>""" + + utils.log("DEBUG","sdncRequest:\n" + sdncReq, isDebugEnabled) + sdncReq = utils.formatXml(sdncReq) + + } catch(Exception ex) { + msg = "Exception in buildSDNCRequest. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit buildSDNCRequest *****", isDebugEnabled) + return sdncReq + } + + public void preProcessSDNCUnassign(Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessSDNCUnassign *****", isDebugEnabled) + + try { + String sdncRequestId = UUID.randomUUID().toString() + String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId) + execution.setVariable("sdncUnassignRequest", sdncUnassignReq) + utils.logAudit("sdncUnassignRequest: " + sdncUnassignReq) + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit preProcessSDNCUnassign *****", isDebugEnabled) + } + + public void preProcessSDNCDelete(Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessSDNCDelete *****", isDebugEnabled) + + try { + String sdncRequestId = UUID.randomUUID().toString() + String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId) + execution.setVariable("sdncDeleteRequest", sdncDeleteReq) + utils.logAudit("sdncDeleteReq: " + sdncDeleteReq) + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCDelete. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit preProcessSDNCDelete *****", isDebugEnabled) + } + + public void preProcessSDNCDeactivate(Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessSDNCDeactivate *****", isDebugEnabled) + + try { + String sdncRequestId = UUID.randomUUID().toString() + String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId) + execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq) + utils.logAudit("sdncDeactivateReq: " + sdncDeactivateReq) + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit preProcessSDNCDeactivate *****", isDebugEnabled) + } + + public void validateSDNCResp(Execution execution, String response, String method){ + + def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled) + String msg = "" + + try { + WorkflowException workflowException = execution.getVariable("WorkflowException") + utils.logAudit("workflowException: " + workflowException) + + boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator") + utils.logAudit("SDNCResponse: " + response) + + SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this) + sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator) + + if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){ + utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response, isDebugLogEnabled) + + }else{ + String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode') + utils.log("DEBUG", method + " AllottedResource received error response from SDNC. ResponseCode:" + sdncRespCode, isDebugLogEnabled) + if (sdncRespCode.equals("404") && "deactivate".equals(method)) + { + execution.setVariable("ARNotFoundInSDNC", true) + if ("true".equals(execution.getVariable("failNotFound"))) + { + msg = "Allotted Resource Not found in SDNC" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + else + { + execution.setVariable("wasDeleted", false) + } + } + else + { + throw new BpmnError("MSOWorkflowException") + } + } + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in validateSDNCResp. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled) + } + + public void deleteAaiAR(Execution execution){ + def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled") + try{ + utils.log("DEBUG", " *** deleteAaiAR *** ", isDebugLogEnabled) + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String ar = null //need to get resource-version again + String arLink = execution.getVariable("aaiARPath") + if (!isBlank(arLink)) + { + ar = arUtils.getARbyLink(execution, arLink, "") + } + arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8")) + } catch (BpmnError e) { + throw e; + }catch(Exception ex){ + utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + ex, isDebugLogEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage()) + } + utils.log("DEBUG", " *** Exit deleteAaiAR *** ", isDebugLogEnabled) + } + +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoDeleteAllottedResourceTXC.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoDeleteAllottedResourceTXC.groovy new file mode 100644 index 0000000000..a66e88852b --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/vcpe/scripts/DoDeleteAllottedResourceTXC.groovy @@ -0,0 +1,349 @@ +/* + * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +package org.openecomp.mso.bpmn.vcpe.scripts; + +import org.openecomp.mso.bpmn.common.scripts.*; +import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.openecomp.mso.bpmn.core.WorkflowException +import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil +import org.openecomp.mso.bpmn.common.scripts.MsoUtils +import org.openecomp.mso.bpmn.common.scripts.AaiUtil +import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils +import org.openecomp.mso.rest.APIResponse + +import java.util.UUID; +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.runtime.Execution +import org.apache.commons.lang3.* +import org.springframework.web.util.UriUtils; +import static org.apache.commons.lang3.StringUtils.* + +/** + * This groovy class supports the <class>DoDeleteAllottedResourceTXC.bpmn</class> process. + * + * @author + * + * Inputs: + * @param - msoRequestId + * @param - isDebugLogEnabled + * @param - disableRollback - O ignored + * @param - failNotfound - O + * @param - serviceInstanceId + * @param - allottedResourceId + * + * Outputs: + * @param - rollbackData - N/A + * @param - rolledBack - true if no deletions performed + * @param - WorkflowException - O + * @param - wasDeleted - O (ie not silentSuccess) + * + */ +public class DoDeleteAllottedResourceTXC extends AbstractServiceTaskProcessor{ + + String Prefix="DDARTXC_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + + public void preProcessRequest (Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled) + + try { + execution.setVariable("prefix", Prefix) + + //Config Inputs + String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback') + if (isBlank(sdncCallbackUrl)) { + msg = "URN_mso_workflow_sdncadapter_callback is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + execution.setVariable("sdncCallbackUrl", sdncCallbackUrl) + utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled) + + //Request Inputs + if (isBlank(execution.getVariable("serviceInstanceId"))){ + msg = "Input serviceInstanceId is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + if (isBlank(execution.getVariable("allottedResourceId"))){ + msg = "Input allottedResourceId is null" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + }catch(BpmnError b){ + utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled) + throw b + } catch (Exception ex){ + msg = "Exception in preProcessRequest " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled) + } + + public void getAaiAR (Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG"," ***** getAaiAR ***** ", isDebugEnabled) + + String allottedResourceId = execution.getVariable("allottedResourceId") + + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String ar = arUtils.getARbyId(execution, allottedResourceId) + + String errorMsg = "" + if (isBlank(ar)) // AR was !found + { + errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId + } + else + { + String aaiARPath = execution.getVariable("aaiARPath") + String parentServiceInstanceId = arUtils.getPSIFmARLink(execution, aaiARPath) + execution.setVariable("parentServiceInstanceId", parentServiceInstanceId) + } + if (!isBlank(errorMsg)) { + utils.log("DEBUG", errorMsg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg) + } + utils.log("DEBUG"," ***** getAaiAR *****", isDebugEnabled) + + } + + // aaiARPath set during query (existing AR) + public void updateAaiAROrchStatus(Execution execution, String status){ + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", " *** updateAaiAROrchStatus *** ", isDebugEnabled) + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR) + String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath) + utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled) + } + + public String buildSDNCRequest(Execution execution, String action, String sdncRequestId) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** buildSDNCRequest *****", isDebugEnabled) + String sdncReq = null + + try { + + String allottedResourceId = execution.getVariable("allottedResourceId") + String serviceInstanceId = execution.getVariable("serviceInstanceId") + String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId") + + String callbackUrl = execution.getVariable("sdncCallbackUrl") + String requestId = execution.getVariable("msoRequestId") + + String serviceChainServiceInstanceId = "" + String sourceNetworkId = "" + String sourceNetworkRole = "" + String allottedResourceRole = "" + + String arModelInfo = "" + String modelInvariantId = "" + String modelVersion = "" + String modelUUId = "" + String modelCustomizationId = "" + String modelName = "" + + + sdncReq = + """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1" + xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1" + xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1"> + <sdncadapter:RequestHeader> + <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId> + <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId> + <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction> + <sdncadapter:SvcOperation>tunnelxconn-topology-operation</sdncadapter:SvcOperation> + <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl> + </sdncadapter:RequestHeader> + <sdncadapterworkflow:SDNCRequestData> + <request-information> + <request-id>${requestId}</request-id> + <request-action>DeleteTunnelXConnInstance</request-action> + <source>MSO</source> + <notification-url/> + <order-number/> + <order-version/> + </request-information> + <service-information> + <service-id></service-id> + <subscription-service-type></subscription-service-type> + <ecomp-model-information></ecomp-model-information> + <service-instance-id>${parentServiceInstanceId}</service-instance-id> + <subscriber-name/> + <global-customer-id></global-customer-id> + </service-information> + <allotted-resource-information> + <allotted-resource-id>${allottedResourceId}</allotted-resource-id> + <allotted-resource-type>tunnelxconn</allotted-resource-type> + <parent-service-instance-id>${parentServiceInstanceId}</parent-service-instance-id> + <ecomp-model-information> + <model-invariant-uuid>${modelInvariantId}</model-invariant-uuid> + <model-uuid>${modelUUId}</model-uuid> + <model-customization-uuid>${modelCustomizationId}</model-customization-uuid> + <model-version>${modelVersion}</model-version> + <model-name>${modelName}</model-name> + </ecomp-model-information> + </allotted-resource-information> + <tunnelxconn-request-input> + </tunnelxconn-request-input> + </sdncadapterworkflow:SDNCRequestData> + </sdncadapterworkflow:SDNCAdapterWorkflowRequest>""" + + utils.log("DEBUG","sdncRequest:\n" + sdncReq, isDebugEnabled) + sdncReq = utils.formatXml(sdncReq) + + } catch(Exception ex) { + msg = "Exception in buildSDNCRequest. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit buildSDNCRequest *****", isDebugEnabled) + return sdncReq + } + + public void preProcessSDNCUnassign(Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessSDNCUnassign *****", isDebugEnabled) + + try { + String sdncRequestId = UUID.randomUUID().toString() + String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId) + execution.setVariable("sdncUnassignRequest", sdncUnassignReq) + utils.logAudit("sdncUnassignRequest: " + sdncUnassignReq) + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit preProcessSDNCUnassign *****", isDebugEnabled) + } + + public void preProcessSDNCDelete(Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessSDNCDelete *****", isDebugEnabled) + + try { + String sdncRequestId = UUID.randomUUID().toString() + String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId) + execution.setVariable("sdncDeleteRequest", sdncDeleteReq) + utils.logAudit("sdncDeleteReq: " + sdncDeleteReq) + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCDelete. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit preProcessSDNCDelete *****", isDebugEnabled) + } + + public void preProcessSDNCDeactivate(Execution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + String msg = "" + utils.log("DEBUG"," ***** preProcessSDNCDeactivate *****", isDebugEnabled) + + try { + String sdncRequestId = UUID.randomUUID().toString() + String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId) + execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq) + utils.logAudit("sdncDeactivateReq: " + sdncDeactivateReq) + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + utils.log("DEBUG"," *****Exit preProcessSDNCDeactivate *****", isDebugEnabled) + } + + public void validateSDNCResp(Execution execution, String response, String method){ + + def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled) + String msg = "" + + try { + WorkflowException workflowException = execution.getVariable("WorkflowException") + utils.logAudit("workflowException: " + workflowException) + + boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator") + utils.logAudit("SDNCResponse: " + response) + + SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this) + sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator) + + if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){ + utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response, isDebugLogEnabled) + + }else{ + String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode') + utils.log("DEBUG", method + " AllottedResource received error response from SDNC. ResponseCode:" + sdncRespCode, isDebugLogEnabled) + if (sdncRespCode.equals("404") && "deactivate".equals(method)) + { + execution.setVariable("ARNotFoundInSDNC", true) + if ("true".equals(execution.getVariable("failNotFound"))) + { + msg = "Allotted Resource Not found in SDNC" + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + else + { + execution.setVariable("wasDeleted", false) + } + } + else + { + throw new BpmnError("MSOWorkflowException") + } + } + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in validateSDNCResp. " + ex.getMessage() + utils.log("DEBUG", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled) + } + + public void deleteAaiAR(Execution execution){ + def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled") + try{ + utils.log("DEBUG", " *** deleteAaiAR *** ", isDebugLogEnabled) + AllottedResourceUtils arUtils = new AllottedResourceUtils(this) + String ar = null //need to get resource-version again + String arLink = execution.getVariable("aaiARPath") + if (!isBlank(arLink)) + { + ar = arUtils.getARbyLink(execution, arLink, "") + } + arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8")) + } catch (BpmnError e) { + throw e; + }catch(Exception ex){ + utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + ex, isDebugLogEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage()) + } + utils.log("DEBUG", " *** Exit deleteAaiAR *** ", isDebugLogEnabled) + } + +} |