diff options
author | Arthur Martella <amartell@research.att.com> | 2017-09-21 16:09:46 -0400 |
---|---|---|
committer | Arthur Martella <amartell@research.att.com> | 2017-09-21 16:09:46 -0400 |
commit | 902ec7ef30248c03096cf03da47e6bcca4372525 (patch) | |
tree | fcb000e29ade08e673d07e85b2358669ceb1e140 /bpmn/MSOCommonBPMN/src | |
parent | c894e1dc433d49acd1b5adc4bcd338b1d148e465 (diff) |
Move Homing Building Block into ONAP
Files regarding the Homing building blocks added for use in vCPE flows.
Change-Id: Iae9eb70b81ec7d473e6c4e9c821a9282dc40baa9
Issue-id: SO-138
Signed-off-by: Arthur Martella <amartell@research.att.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src')
16 files changed, 2128 insertions, 0 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/Homing.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/Homing.groovy new file mode 100755 index 0000000000..dcbb73c7db --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/Homing.groovy @@ -0,0 +1,259 @@ +/*
+ * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
+ */
+package org.openecomp.mso.bpmn.common.scripts
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.runtime.Execution
+
+import org.openecomp.mso.bpmn.common.scripts.AaiUtil
+import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
+import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
+import org.openecomp.mso.bpmn.core.domain.InventoryType
+import org.openecomp.mso.bpmn.core.domain.Resource
+import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
+import org.openecomp.mso.bpmn.core.domain.Subscriber
+import org.openecomp.mso.bpmn.core.json.JsonUtils
+import org.openecomp.mso.rest.APIResponse
+import org.openecomp.mso.rest.RESTClient
+import org.openecomp.mso.rest.RESTConfig
+import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
+
+import org.json.JSONArray
+import org.json.JSONObject
+
+import static org.openecomp.mso.bpmn.common.scripts.GenericUtils.*;
+
+/**
+ * This class is contains the scripts used
+ * by the Homing Subflow building block. The
+ * subflow attempts to home the provided
+ * resources by calling sniro.
+ *
+ * @author cb645j
+ *
+ */
+class Homing extends AbstractServiceTaskProcessor{
+
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+ SNIROUtils sniroUtils = new SNIROUtils(this)
+
+ /**
+ * This method validates the incoming variables.
+ * The method then prepares the sniro request
+ * and posts it to sniro's rest api.
+ *
+ * @param execution
+ *
+ * @author cb645j
+ */
+ public void callSniro(Execution execution){
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+ execution.setVariable("prefix","HOME_")
+ utils.log("DEBUG", "*** Started Homing Call Sniro ***", isDebugEnabled)
+ try{
+ execution.setVariable("rollbackData", null)
+ execution.setVariable("rolledBack", false)
+
+ String requestId = execution.getVariable("msoRequestId")
+ utils.log("DEBUG", "Incoming Request Id is: " + requestId, isDebugEnabled)
+ String serviceInstanceId = execution.getVariable("serviceInstanceId")
+ utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
+ ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+ utils.log("DEBUG", "Incoming Service Decomposition is: " + serviceDecomposition, isDebugEnabled)
+ String subscriberInfo = execution.getVariable("subscriberInfo")
+ utils.log("DEBUG", "Incoming Subscriber Information is: " + subscriberInfo, isDebugEnabled)
+
+ if(isBlank(requestId) || isBlank(serviceInstanceId) || isBlank(serviceDecomposition.toString()) || isBlank(subscriberInfo)){
+ exceptionUtil.buildAndThrowWorkflowException(execution, 4000, "A required input variable is missing or null")
+ }else{
+ String subId = jsonUtil.getJsonValue(subscriberInfo, "globalSubscriberId")
+ String subName = jsonUtil.getJsonValue(subscriberInfo, "subscriberName")
+ String subCommonSiteId = ""
+ if(jsonUtil.jsonElementExist(subscriberInfo, "subscriberCommonSiteId")){
+ subCommonSiteId = jsonUtil.getJsonValue(subscriberInfo, "subscriberCommonSiteId")
+ }
+ Subscriber subscriber = new Subscriber(subId, subName, subCommonSiteId)
+
+ String cloudConfiguration = execution.getVariable("cloudConfiguration") // TODO Currently not being used
+ String homingParameters = execution.getVariable("homingParameters") // (aka. request parameters) Should be json format. TODO confirm its json format
+
+ //Authentication
+ def authHeader = ""
+ String basicAuth = execution.getVariable("URN_mso_sniro_auth")
+ String msokey = execution.getVariable("URN_mso_msoKey")
+ String basicAuthValue = utils.encrypt(basicAuth, msokey)
+ if(basicAuthValue != null){
+ utils.log("DEBUG", "Obtained BasicAuth username and password for SNIRO Adapter: " + basicAuthValue, isDebugEnabled)
+ try {
+ authHeader = utils.getBasicAuth(basicAuthValue, msokey)
+ execution.setVariable("BasicAuthHeaderValue",authHeader)
+ } catch (Exception ex) {
+ utils.log("DEBUG", "Unable to encode username and password string: " + ex, isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - Unable to encode username and password string")
+ }
+ }else{
+ utils.log("DEBUG", "Unable to obtain BasicAuth - BasicAuth value null" , isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth value null")
+ }
+
+ //Prepare Callback
+ String timeout = execution.getVariable("timeout")
+ if(isBlank(timeout)){
+ timeout = execution.getVariable("URN_mso_sniro_timeout");
+ if(isBlank(timeout)) {
+ timeout = "PT30M";
+ }
+ }
+ utils.log("DEBUG", "Async Callback Timeout will be: " + timeout, isDebugEnabled)
+
+ execution.setVariable("timeout", timeout);
+ execution.setVariable("correlator", requestId);
+ execution.setVariable("messageType", "SNIROResponse");
+
+ //Build Request & Call Sniro
+ String sniroRequest = sniroUtils.buildRequest(execution, requestId, serviceDecomposition, subscriber, homingParameters)
+ execution.setVariable("sniroRequest", sniroRequest)
+ utils.log("DEBUG", "SNIRO Request is: " + sniroRequest, isDebugEnabled)
+
+ String endpoint = execution.getVariable("URN_mso_service_agnostic_sniro_endpoint")
+ String host = execution.getVariable("URN_mso_service_agnostic_sniro_host")
+ String url = host + endpoint
+ utils.log("DEBUG", "Posting to Sniro Url: " + url, isDebugEnabled)
+
+ logDebug( "URL to be used is: " + url, isDebugEnabled)
+
+ String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
+
+ RESTConfig config = new RESTConfig(url);
+ RESTClient client = new RESTClient(config).addAuthorizationHeader(authHeader).addHeader("Content-Type", "application/json")
+ if (basicAuthCred != null && !"".equals(basicAuthCred)) {
+ client.addAuthorizationHeader(basicAuthCred)
+ }
+ APIResponse response = client.httpPost(sniroRequest)
+
+ int responseCode = response.getStatusCode()
+ execution.setVariable("syncResponseCode", responseCode);
+ logDebug("SNIRO sync response code is: " + responseCode, isDebugEnabled)
+ String syncResponse = response.getResponseBodyAsString()
+ execution.setVariable("syncResponse", syncResponse);
+ logDebug("SNIRO sync response is: " + syncResponse, isDebugEnabled)
+
+ utils.log("DEBUG", "*** Completed Homing Call Sniro ***", isDebugEnabled)
+ }
+ }catch(BpmnError b){
+ throw b
+ }catch(Exception e){
+ utils.log("DEBUG", "Error encountered within Homing CallSniro method: " + e, isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in Homing CallSniro: " + e.getMessage())
+ }
+ }
+
+ /**
+ * This method processes the callback response
+ * and the contained homing solution. It sets
+ * homing solution assignment and license
+ * information to the corresponding resources
+ *
+ * @param execution
+ *
+ * @author cb645j
+ */
+ public void processHomingSolution(Execution execution){
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+ utils.log("DEBUG", "*** Started Homing Process Homing Solution ***", isDebugEnabled)
+ try{
+ String response = execution.getVariable("asyncCallbackResponse")
+ utils.log("DEBUG", "Sniro Async Callback Response is: " + response, isDebugEnabled)
+ utils.logAudit("Sniro Async Callback Response is: " + response)
+
+ sniroUtils.validateCallbackResponse(execution, response)
+ String placements = jsonUtil.getJsonValue(response, "solutionInfo.placement")
+
+ ServiceDecomposition decomposition = execution.getVariable("serviceDecomposition")
+ utils.log("DEBUG", "Service Decomposition: " + decomposition, isDebugEnabled)
+
+ List<Resource> resourceList = decomposition.getServiceResources()
+ JSONArray arr = new JSONArray(placements)
+ for(int i = 0; i < arr.length(); i++){
+ JSONObject placement = arr.getJSONObject(i)
+ String jsonServiceResourceId = placement.getString("serviceResourceId")
+ for(Resource resource:resourceList){
+ String serviceResourceId = resource.getResourceId()
+ if(serviceResourceId.equalsIgnoreCase(jsonServiceResourceId)){
+ //match
+ String inventoryType = placement.getString("inventoryType")
+ resource.getHomingSolution().setInventoryType(InventoryType.valueOf(inventoryType))
+ resource.getHomingSolution().setCloudRegionId(placement.getString("cloudRegionId"))
+ JSONArray assignmentArr = placement.getJSONArray("assignmentInfo")
+ Map<String, String> assignmentMap = jsonUtil.entryArrayToMap(execution, assignmentArr.toString(), "variableName", "variableValue")
+ resource.getHomingSolution().setCloudOwner(assignmentMap.get("cloudOwner"))
+ resource.getHomingSolution().setAicClli(assignmentMap.get("aicClli"))
+ resource.getHomingSolution().setAicVersion(assignmentMap.get("aicVersion"))
+ if(inventoryType.equalsIgnoreCase("service")){
+ resource.getHomingSolution().setVnfHostname(assignmentMap.get("vnfHostName"));
+ resource.getHomingSolution().setServiceInstanceId(placement.getString("serviceInstanceId"));
+ }
+ }
+ }
+ }
+ if(JsonUtils.jsonElementExist(response, "solutionInfo.licenseInfo")){
+ String licenseInfo = jsonUtil.getJsonValue(response, "solutionInfo.licenseInfo")
+ JSONArray licenseArr = new JSONArray(licenseInfo)
+ for(int l = 0; l < licenseArr.length(); l++){
+ JSONObject license = licenseArr.getJSONObject(l)
+ String jsonServiceResourceId = license.getString("serviceResourceId")
+ for(Resource resource:resourceList){
+ String serviceResourceId = resource.getResourceId()
+ if(serviceResourceId.equalsIgnoreCase(jsonServiceResourceId)){
+ //match
+ String jsonEntitlementPoolList = jsonUtil.getJsonValue(license.toString(), "entitlementPoolList")
+ List<String> entitlementPoolList = jsonUtil.StringArrayToList(execution, jsonEntitlementPoolList)
+ resource.getHomingSolution().setEntitlementPoolList(entitlementPoolList)
+
+ String jsonLicenseKeyGroupList = jsonUtil.getJsonValue(license.toString(), "licenseKeyGroupList")
+ List<String> licenseKeyGroupList = jsonUtil.StringArrayToList(execution, jsonLicenseKeyGroupList)
+ resource.getHomingSolution().setLicenseKeyGroupList(licenseKeyGroupList)
+ }
+ }
+ }
+ }
+ execution.setVariable("serviceDecomposition", decomposition)
+ execution.setVariable("homingSolution", placements) //TODO - can be removed as output variable
+
+ utils.log("DEBUG", "*** Completed Homing Process Homing Solution ***", isDebugEnabled)
+ }catch(BpmnError b){
+ throw b
+ }catch(Exception e){
+ utils.log("DEBUG", "Error encountered within Homing ProcessHomingSolution method: " + e, isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in Homing ProcessHomingSolution")
+ }
+ }
+
+ /**
+ * This method logs the start of DHVCreateService
+ * to make debugging easier.
+ *
+ * @param - execution
+ * @author cb645j
+ */
+ public String logStart(Execution execution){
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+ String requestId = execution.getVariable("testReqId")
+ if(isBlank(requestId)){
+ requestId = execution.getVariable("msoRequestId")
+ }
+ execution.setVariable("DHVCS_requestId", requestId)
+ utils.log("DEBUG", "***** STARTED Homing Subflow for request: " + requestId + " *****", "true")
+ utils.log("DEBUG", "****** Homing Subflow Global Debug Enabled: " + isDebugEnabled + " *****", "true")
+ utils.logAudit("***** STARTED Homing Subflow for request: " + requestId + " *****")
+ }
+
+
+ /**
+ * Auto-generated method stub
+ */
+ public void preProcessRequest(Execution execution){}
+
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/ReceiveWorkflowMessage.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/ReceiveWorkflowMessage.groovy new file mode 100644 index 0000000000..6ad03abec6 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/ReceiveWorkflowMessage.groovy @@ -0,0 +1,109 @@ +package org.openecomp.mso.bpmn.common.scripts
+
+import groovy.json.*
+
+import org.apache.commons.lang3.*
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.runtime.Execution
+import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
+import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
+
+
+class ReceiveWorkflowMessage extends AbstractServiceTaskProcessor {
+
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+
+ /**
+ * Process the incoming variables.
+ *
+ * @param execution The flow's execution instance.
+ */
+public void preProcessRequest (Execution execution) {
+ def method = getClass().getSimpleName() + '.preProcessRequest(' +
+ 'execution=' + execution.getId() +
+ ')'
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
+ logDebug('Entered ' + method, isDebugLogEnabled)
+
+ def prefix="RCVWFMSG_"
+ execution.setVariable("prefix", prefix)
+ setSuccessIndicator(execution, false)
+
+ try {
+
+ // Confirm that timeout value has been provided in 'RCVWFMSG_timeout'.
+ def timeout = execution.getVariable('RCVWFMSG_timeout')
+ logDebug('Timeout value is \'' + timeout + '\'', isDebugLogEnabled)
+ if ((timeout == null) || (timeout.isEmpty())) {
+ String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_timeout\''
+ logDebug(msg, isDebugLogEnabled)
+ logError(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ }
+
+ // Confirm that message type has been provided in 'RCVWFMSG_messageType'
+ def messageType = execution.getVariable('RCVWFMSG_messageType')
+ logDebug('Message type is \'' + messageType + '\'', isDebugLogEnabled)
+ if ((messageType == null) || (messageType.isEmpty())) {
+ String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_messageType\''
+ logDebug(msg, isDebugLogEnabled)
+ logError(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ }
+
+ // Confirm that correlator value has been provided in 'RCVWFMSG_correlator'
+ def correlator = execution.getVariable('RCVWFMSG_correlator')
+ logDebug('Correlator value is \'' + correlator + '\'', isDebugLogEnabled)
+ if ((correlator == null) || (correlator.isEmpty())) {
+ String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_correlator\''
+ logDebug(msg, isDebugLogEnabled)
+ logError(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ }
+ execution.setVariable(messageType + '_CORRELATOR', correlator)
+
+ logDebug('Exited ' + method, isDebugLogEnabled)
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception e) {
+ String msg = 'Caught exception in ' + method + ": " + e
+ logDebug(msg, isDebugLogEnabled)
+ logError(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+ }
+ }
+
+ /**
+ * Process a received message.
+ *
+ * @param execution The flow's execution instance.
+ */
+ public void processReceivedMessage(Execution execution){
+ def method = getClass().getSimpleName() + '.processReceivedMessage(' +
+ 'execution=' + execution.getId() +
+ ')'
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
+ logDebug('Entered ' + method, isDebugLogEnabled)
+
+ String messageType = null;
+ String receivedMessage = null;
+
+ try {
+ messageType = execution.getVariable('RCVWFMSG_messageType')
+ receivedMessage = execution.getVariable(messageType + '_MESSAGE')
+ logDebug(getProcessKey(execution) + ": received message:\n" + receivedMessage, isDebugLogEnabled)
+
+ // The received message is made available to the calling flow in WorkflowResponse
+ execution.setVariable("WorkflowResponse", receivedMessage)
+
+ setSuccessIndicator(execution, true)
+
+ logDebug('Exited ' + method, isDebugLogEnabled)
+ } catch (Exception e) {
+ receivedMessage = receivedMessage == null || String.valueOf(receivedMessage).isEmpty() ? "NONE" : receivedMessage
+ String msg = "Error processing received workflow message: " + receivedMessage
+ logDebug(getProcessKey(execution) + ': ' + msg, isDebugLogEnabled)
+ exceptionUtil.buildWorkflowException(execution, 7020, msg)
+ }
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/SNIROUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/SNIROUtils.groovy new file mode 100644 index 0000000000..aba2b783e5 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/SNIROUtils.groovy @@ -0,0 +1,262 @@ +package org.openecomp.mso.bpmn.common.scripts
+
+import org.camunda.bpm.engine.runtime.Execution
+import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
+import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
+import org.openecomp.mso.bpmn.common.scripts.MsoUtils
+import org.openecomp.mso.bpmn.core.domain.*
+import org.openecomp.mso.bpmn.core.json.JsonUtils
+import org.apache.commons.lang3.StringUtils
+
+import static org.openecomp.mso.bpmn.common.scripts.GenericUtils.*
+
+class SNIROUtils{
+
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+
+ private AbstractServiceTaskProcessor utils
+
+ public MsoUtils msoUtils = new MsoUtils()
+
+ public SNIROUtils(AbstractServiceTaskProcessor taskProcessor) {
+ this.utils = taskProcessor
+ }
+
+ /**
+ * This method builds the service-agnostic
+ * sniro json request to get a homing solution
+ * and license solution
+ *
+ * @param execution
+ * @param requestId
+ * @param decomposition - ServiceDecomposition object
+ * @param subscriber - Subscriber information
+ * @param homingParams - Homing/Request parameters
+ *
+ * @return request - sniro v2 payload
+ *
+ * @author cb645j
+ */
+ public String buildRequest(Execution execution, String requestId, ServiceDecomposition decomposition, Subscriber subscriber, String homingParams){
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+ utils.log("DEBUG", "Started Building Sniro Request", isDebugEnabled)
+ def callbackUrl = utils.createWorkflowMessageAdapterCallbackURL(execution, "SNIROResponse", requestId)
+ def transactionId = requestId
+ //ServiceInstance Info
+ ServiceInstance serviceInstance = decomposition.getServiceInstance()
+ def serviceInstanceId
+ if(serviceInstance == null){
+ utils.log("DEBUG", "Unable to obtain Service Instance Id, ServiceInstance Object is null" , isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Internal Error - Unable to obtain Service Instance Id, ServiceInstance Object is null")
+ }else{
+ serviceInstanceId = serviceInstance.getInstanceId()
+ }
+ //Model Info
+ ModelInfo model = decomposition.getModelInfo()
+ String modelType = model.getModelType()
+ String modelInvariantId = model.getModelInvariantUuid()
+ String modelVersionId = model.getModelUuid()
+ String modelName = model.getModelName()
+ String modelVersion = model.getModelVersion()
+ //Subscriber Info
+ String subscriberId = subscriber.getGlobalId()
+ String subscriberName = subscriber.getName()
+ String commonSiteId = subscriber.getCommonSiteId()
+ //OrderInfo
+ String orderInfo
+ if(!isBlank(homingParams)){
+ orderInfo = homingParams.replaceAll("\"", "\\\\\"").replaceAll("\n", "").replaceAll("\r", "")
+ orderInfo = StringUtils.normalizeSpace(orderInfo)
+ }
+
+ //Demands
+ String placementDemands = ""
+ StringBuilder sb = new StringBuilder()
+ List<Resource> resourceList = decomposition.getServiceAllottedResources()
+ List<VnfResource> vnfResourceList = decomposition.getServiceVnfs()
+
+ // TODO: We should include both alloted resources and service resources in the placementDeamnds- not one or the other.
+ if(resourceList.isEmpty() || resourceList == null){
+ utils.log("DEBUG", "Allotted Resources List is empty - will try to get service VNFs instead.", isDebugEnabled)
+ resourceList = decomposition.getServiceVnfs()
+ }
+
+ if(resourceList.isEmpty() || resourceList == null){
+ utils.log("DEBUG", "Resources List is Empty", isDebugEnabled)
+ }else{
+ for(Resource resource:resourceList){
+ ModelInfo resourceModelInfo = resource.getModelInfo()
+ ResourceInstance resourceInstance = resource.getResourceInstance()
+ def resourceInstanceType = resource.getResourceType()
+ def serviceResourceId = resource.getResourceId() //TODO - resourceId versus instanceId - should be what is put in AAI, whatever we put here will be what is in response, used to correlate
+ def resourceModuleName = resourceModelInfo.getModelInstanceName()
+ def resouceModelCustomizationId = resourceModelInfo.getModelCustomizationUuid()
+ def resouceModelInvariantId = resourceModelInfo.getModelInvariantUuid()
+ def resouceModelName = resourceModelInfo.getModelName()
+ def resouceModelVersion = resourceModelInfo.getModelVersion()
+ def resouceModelVersionId = resourceModelInfo.getModelUuid()
+ def resouceModelType = resourceModelInfo.getModelType()
+ def tenantId = "" //Optional
+ def tenantName = "" //Optional
+
+ String demand =
+ """{
+ "resourceInstanceType": "${resourceInstanceType}",
+ "serviceResourceId": "${serviceResourceId}",
+ "resourceModuleName": "${resourceModuleName}",
+ "resourceModelInfo": {
+ "modelCustomizationId": "${resouceModelCustomizationId}",
+ "modelInvariantId": "${resouceModelInvariantId}",
+ "modelName": "${resouceModelName}",
+ "modelVersion": "${resouceModelVersion}",
+ "modelVersionId": "${resouceModelVersionId}",
+ "modelType": "${resouceModelType}"
+ },
+ "tenantId": "${tenantId}",
+ "tenantName": "${tenantName}"
+ },"""
+
+ placementDemands = sb.append(demand)
+ }
+ placementDemands = placementDemands.substring(0, placementDemands.length() - 1);
+ }
+
+ String licenseDemands = ""
+ sb = new StringBuilder()
+ if(vnfResourceList.isEmpty() || vnfResourceList == null){
+ utils.log("DEBUG", "Vnf Resources List is Empty", isDebugEnabled)
+ }else{
+ for(VnfResource vnfResource:vnfResourceList){
+ ModelInfo vnfResourceModelInfo = vnfResource.getModelInfo()
+ ResourceInstance vnfResourceInstance = vnfResource.getResourceInstance()
+ def resourceInstanceType = vnfResource.getResourceType()
+ def serviceResourceId = vnfResource.getResourceId()
+ def resourceModuleName = vnfResourceModelInfo.getModelInstanceName()
+ def resouceModelCustomizationId = vnfResourceModelInfo.getModelCustomizationUuid()
+ def resouceModelInvariantId = vnfResourceModelInfo.getModelInvariantUuid()
+ def resouceModelName = vnfResourceModelInfo.getModelName()
+ def resouceModelVersion = vnfResourceModelInfo.getModelVersion()
+ def resouceModelVersionId = vnfResourceModelInfo.getModelUuid()
+ def resouceModelType = vnfResourceModelInfo.getModelType()
+
+ String demand =
+ """{
+ "resourceInstanceType": "${resourceInstanceType}",
+ "serviceResourceId": "${serviceResourceId}",
+ "resourceModuleName": "${resourceModuleName}",
+ "resourceModelInfo": {
+ "modelCustomizationId": "${resouceModelCustomizationId}",
+ "modelInvariantId": "${resouceModelInvariantId}",
+ "modelName": "${resouceModelName}",
+ "modelVersion": "${resouceModelVersion}",
+ "modelVersionId": "${resouceModelVersionId}",
+ "modelType": "${resouceModelType}"
+ }
+ },"""
+
+ licenseDemands = sb.append(demand)
+ }
+ licenseDemands = licenseDemands.substring(0, licenseDemands.length() - 1);
+ }
+
+ String request =
+ """{
+ "requestInfo": {
+ "transactionId": "${transactionId}",
+ "requestId": "${requestId}",
+ "callbackUrl": "${callbackUrl}",
+ "sourceId": "mso",
+ "optimizer": [
+ "placement",
+ "license"
+ ],
+ "numSolutions": 1,
+ "timeout": 600
+ },
+ "placementInfo": {
+ "serviceModelInfo": {
+ "modelType": "${modelType}",
+ "modelInvariantId": "${modelInvariantId}",
+ "modelVersionId": "${modelVersionId}",
+ "modelName": "${modelName}",
+ "modelVersion": "${modelVersion}"
+ },
+ "subscriberInfo": {
+ "globalSubscriberId": "${subscriberId}",
+ "subscriberName": "${subscriberName}",
+ "subscriberCommonSiteId": "${commonSiteId}"
+ },
+ "demandInfo": {
+ "placementDemand": [
+ ${placementDemands}
+ ],
+ "licenseDemand": [
+ ${licenseDemands}
+ ]
+ },
+ "policyId": [],
+ "serviceInstanceId": "${serviceInstanceId}",
+ "orderInfo": "{\\\"requestParameters\\\": ${orderInfo}}"
+ }
+ }"""
+
+ utils.log("DEBUG", "Completed Building Sniro Request", isDebugEnabled)
+ return request
+ }
+
+ /**
+ * This method validates the callback response
+ * from Sniro. If the response contains an
+ * exception the method will build and throw
+ * a workflow exception.
+ *
+ * @param execution
+ * @param response - the async callback response from sniro
+ *
+ * @author cb645j
+ */
+ public void validateCallbackResponse(Execution execution, String response){
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+ String placements = ""
+ if(isBlank(response)){
+ exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Sniro Async Callback Response is Empty")
+ }else{
+ if(JsonUtils.jsonElementExist(response, "solutionInfo.placement")){
+ placements = jsonUtil.getJsonValue(response, "solutionInfo.placement")
+ if(isBlank(placements) || placements.equalsIgnoreCase("[]")){
+ String statusMessage = jsonUtil.getJsonValue(response, "statusMessage")
+ if(isBlank(statusMessage)){
+ utils.log("DEBUG", "Error Occured in Homing: Sniro Async Callback Response does not contain placement solution.", isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Sniro Async Callback Response does not contain placement solution.")
+ }else{
+ utils.log("DEBUG", "Error Occured in Homing: " + statusMessage, isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 400, statusMessage)
+ }
+ }else{
+ return
+ }
+ }else if(JsonUtils.jsonElementExist(response, "requestError") == true){
+ String errorMessage = ""
+ if(response.contains("policyException")){
+ String text = jsonUtil.getJsonValue(response, "requestError.policyException.text")
+ errorMessage = "Sniro Async Callback Response contains a Request Error Policy Exception: " + text
+ }else if(response.contains("serviceException")){
+ String text = jsonUtil.getJsonValue(response, "requestError.serviceException.text")
+ errorMessage = "Sniro Async Callback Response contains a Request Error Service Exception: " + text
+ }else{
+ errorMessage = "Sniro Async Callback Response contains a Request Error. Unable to determine the Request Error Exception."
+ }
+ utils.log("DEBUG", "Error Occured in Homing: " + errorMessage, isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 400, errorMessage)
+
+ }else{
+ utils.log("DEBUG", "Error Occured in Homing: Received an Unknown Async Callback Response from Sniro.", isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Received an Unknown Async Callback Response from Sniro.")
+ }
+ }
+
+ }
+
+
+}
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/BuildingBlock/Homing.bpmn b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/BuildingBlock/Homing.bpmn new file mode 100644 index 0000000000..a432417c21 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/BuildingBlock/Homing.bpmn @@ -0,0 +1,259 @@ +<?xml version="1.0" encoding="UTF-8"?> +<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="_vwRmIBsREeeIQtzUKIjH4g" targetNamespace="http://camunda.org/schema/1.0/bpmn" exporter="Camunda Modeler" exporterVersion="1.4.0" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"> + <bpmn2:process id="Homing" name="Homing" isExecutable="true"> + <bpmn2:startEvent id="StartEvent_1"> + <bpmn2:outgoing>SequenceFlow_1x9usa6</bpmn2:outgoing> + </bpmn2:startEvent> + <bpmn2:scriptTask id="callSniro" name="Call Sniro" scriptFormat="groovy"> + <bpmn2:incoming>SequenceFlow_1x9usa6</bpmn2:incoming> + <bpmn2:outgoing>SequenceFlow_10x3ocp</bpmn2:outgoing> + <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.common.scripts.* +Homing sniro = new Homing() +sniro.callSniro(execution)]]></bpmn2:script> + </bpmn2:scriptTask> + <bpmn2:sequenceFlow id="SequenceFlow_1x9usa6" sourceRef="StartEvent_1" targetRef="callSniro" /> + <bpmn2:subProcess id="bpmnErrorSubprocess" name="Error Handling Subprocess" triggeredByEvent="true"> + <bpmn2:endEvent id="EndEvent_07tjq3v"> + <bpmn2:incoming>SequenceFlow_1rf4vs8</bpmn2:incoming> + <bpmn2:terminateEventDefinition /> + </bpmn2:endEvent> + <bpmn2:startEvent id="StartEvent_1qiitb2"> + <bpmn2:outgoing>SequenceFlow_00nlh7l</bpmn2:outgoing> + <bpmn2:errorEventDefinition /> + </bpmn2:startEvent> + <bpmn2:scriptTask id="processMsoWorkflowException" name="Process Error" scriptFormat="groovy"> + <bpmn2:incoming>SequenceFlow_00nlh7l</bpmn2:incoming> + <bpmn2:outgoing>SequenceFlow_1rf4vs8</bpmn2:outgoing> + <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.common.scripts.*
+ExceptionUtil ex = new ExceptionUtil()
+ex.processSubflowsBPMNException(execution)]]></bpmn2:script> + </bpmn2:scriptTask> + <bpmn2:sequenceFlow id="SequenceFlow_1rf4vs8" sourceRef="processMsoWorkflowException" targetRef="EndEvent_07tjq3v" /> + <bpmn2:sequenceFlow id="SequenceFlow_00nlh7l" sourceRef="StartEvent_1qiitb2" targetRef="processMsoWorkflowException" /> + </bpmn2:subProcess> + <bpmn2:subProcess id="javaExceptionSubProcess" name="Java Exception Sub Process" triggeredByEvent="true"> + <bpmn2:scriptTask id="processJavaException" name="Process Error" scriptFormat="groovy"> + <bpmn2:incoming>SequenceFlow_0kamg53</bpmn2:incoming> + <bpmn2:outgoing>SequenceFlow_1o7154s</bpmn2:outgoing> + <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.common.scripts.*
+ExceptionUtil ex = new ExceptionUtil()
+ex.processJavaException(execution)]]></bpmn2:script> + </bpmn2:scriptTask> + <bpmn2:startEvent id="StartEvent_1fbpeuw"> + <bpmn2:outgoing>SequenceFlow_0kamg53</bpmn2:outgoing> + <bpmn2:errorEventDefinition errorRef="Error_1lwpypa" /> + </bpmn2:startEvent> + <bpmn2:endEvent id="EndEvent_0jbvnr0"> + <bpmn2:incoming>SequenceFlow_1o7154s</bpmn2:incoming> + <bpmn2:terminateEventDefinition /> + </bpmn2:endEvent> + <bpmn2:sequenceFlow id="SequenceFlow_0kamg53" name="" sourceRef="StartEvent_1fbpeuw" targetRef="processJavaException" /> + <bpmn2:sequenceFlow id="SequenceFlow_1o7154s" name="" sourceRef="processJavaException" targetRef="EndEvent_0jbvnr0" /> + </bpmn2:subProcess> + <bpmn2:scriptTask id="processHomingSolution" name="Process Homing Solutio " scriptFormat="groovy"> + <bpmn2:incoming>SequenceFlow_043r3j8</bpmn2:incoming> + <bpmn2:outgoing>SequenceFlow_1h9opg9</bpmn2:outgoing> + <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.common.scripts.* +Homing homing = new Homing() +homing.processHomingSolution(execution)]]></bpmn2:script> + </bpmn2:scriptTask> + <bpmn2:exclusiveGateway id="responseCheck" name="Response Ok?" default="badResponse"> + <bpmn2:incoming>SequenceFlow_10x3ocp</bpmn2:incoming> + <bpmn2:outgoing>badResponse</bpmn2:outgoing> + <bpmn2:outgoing>goodResponse</bpmn2:outgoing> + </bpmn2:exclusiveGateway> + <bpmn2:sequenceFlow id="SequenceFlow_10x3ocp" sourceRef="callSniro" targetRef="responseCheck" /> + <bpmn2:scriptTask id="assignError" name="Assign Error" scriptFormat="groovy"> + <bpmn2:incoming>badResponse</bpmn2:incoming> + <bpmn2:outgoing>SequenceFlow_0clfkld</bpmn2:outgoing> + <bpmn2:script><![CDATA[int responseCode = execution.getVariable("syncResponseCode")
+
+import org.openecomp.mso.bpmn.common.scripts.*
+ExceptionUtil ex = new ExceptionUtil()
+ex.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from Sniro.")]]></bpmn2:script> + </bpmn2:scriptTask> + <bpmn2:sequenceFlow id="badResponse" name="No" sourceRef="responseCheck" targetRef="assignError" /> + <bpmn2:sequenceFlow id="SequenceFlow_0clfkld" sourceRef="assignError" targetRef="throwMSOWorkflowException" /> + <bpmn2:endEvent id="throwMSOWorkflowException"> + <bpmn2:incoming>SequenceFlow_0clfkld</bpmn2:incoming> + <bpmn2:errorEventDefinition errorRef="Error_10hit0u" /> + </bpmn2:endEvent> + <bpmn2:sequenceFlow id="goodResponse" name="Yes" sourceRef="responseCheck" targetRef="receiveAsyncCallback"> + <bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression"><![CDATA[#{execution.getVariable("syncResponseCode") == 202}]]></bpmn2:conditionExpression> + </bpmn2:sequenceFlow> + <bpmn2:sequenceFlow id="SequenceFlow_043r3j8" sourceRef="receiveAsyncCallback" targetRef="processHomingSolution" /> + <bpmn2:callActivity id="receiveAsyncCallback" name="Receive Async Callback" calledElement="ReceiveWorkflowMessage" camunda:modelerTemplate="receiveWorkflowMessage"> + <bpmn2:extensionElements> + <camunda:in source="true" target="isDebugLogEnabled" /> + <camunda:out source="WorkflowException" target="WorkflowException" /> + <camunda:in source="messageType" target="RCVWFMSG_messageType" /> + <camunda:in source="correlator" target="RCVWFMSG_correlator" /> + <camunda:in source="timeout" target="RCVWFMSG_timeout" /> + <camunda:out source="WorkflowResponse" target="asyncCallbackResponse" /> + </bpmn2:extensionElements> + <bpmn2:incoming>goodResponse</bpmn2:incoming> + <bpmn2:outgoing>SequenceFlow_043r3j8</bpmn2:outgoing> + </bpmn2:callActivity> + <bpmn2:sequenceFlow id="SequenceFlow_1h9opg9" sourceRef="processHomingSolution" targetRef="EndEvent_0n56tas" /> + <bpmn2:endEvent id="EndEvent_0n56tas"> + <bpmn2:incoming>SequenceFlow_1h9opg9</bpmn2:incoming> + <bpmn2:terminateEventDefinition /> + </bpmn2:endEvent> + </bpmn2:process> + <bpmn2:error id="Error_10hit0u" name="MSO Workflow Exception" errorCode="MSOWorkflowException" /> + <bpmn2:error id="Error_1lwpypa" name="Java Lang Exception" errorCode="java.lang.Exception" /> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Homing"> + <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> + <dc:Bounds x="147" y="275" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ScriptTask_0qmfpdr_di" bpmnElement="callSniro"> + <dc:Bounds x="286" y="253" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1x9usa6_di" bpmnElement="SequenceFlow_1x9usa6"> + <di:waypoint xsi:type="dc:Point" x="183" y="293" /> + <di:waypoint xsi:type="dc:Point" x="286" y="293" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="235" y="278" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="SubProcess_16p12qo_di" bpmnElement="bpmnErrorSubprocess" isExpanded="true"> + <dc:Bounds x="254" y="496" width="409" height="168" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="SubProcess_12gjiy8_di" bpmnElement="javaExceptionSubProcess" isExpanded="true"> + <dc:Bounds x="284" y="679" width="350" height="159" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="EndEvent_07tjq3v_di" bpmnElement="EndEvent_07tjq3v"> + <dc:Bounds x="579" y="570" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="597" y="611" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="StartEvent_1qiitb2_di" bpmnElement="StartEvent_1qiitb2"> + <dc:Bounds x="299" y="570" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="317" y="611" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ScriptTask_03hs6s9_di" bpmnElement="processMsoWorkflowException"> + <dc:Bounds x="406" y="548" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ScriptTask_19gqykh_di" bpmnElement="processJavaException"> + <dc:Bounds x="410" y="727" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="StartEvent_1fbpeuw_di" bpmnElement="StartEvent_1fbpeuw"> + <dc:Bounds x="318" y="749" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="336" y="790" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="EndEvent_0jbvnr0_di" bpmnElement="EndEvent_0jbvnr0"> + <dc:Bounds x="567" y="749" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="585" y="790" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1rf4vs8_di" bpmnElement="SequenceFlow_1rf4vs8"> + <di:waypoint xsi:type="dc:Point" x="506" y="588" /> + <di:waypoint xsi:type="dc:Point" x="579" y="588" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="543" y="573" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_00nlh7l_di" bpmnElement="SequenceFlow_00nlh7l"> + <di:waypoint xsi:type="dc:Point" x="335" y="588" /> + <di:waypoint xsi:type="dc:Point" x="363" y="588" /> + <di:waypoint xsi:type="dc:Point" x="363" y="588" /> + <di:waypoint xsi:type="dc:Point" x="406" y="588" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="378" y="588" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0kamg53_di" bpmnElement="SequenceFlow_0kamg53"> + <di:waypoint xsi:type="dc:Point" x="354" y="767" /> + <di:waypoint xsi:type="dc:Point" x="410" y="767" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="382" y="752" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_1o7154s_di" bpmnElement="SequenceFlow_1o7154s"> + <di:waypoint xsi:type="dc:Point" x="510" y="767" /> + <di:waypoint xsi:type="dc:Point" x="567" y="767" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="539" y="752" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ScriptTask_1aapkvq_di" bpmnElement="processHomingSolution"> + <dc:Bounds x="630" y="325" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ExclusiveGateway_03gt5b8_di" bpmnElement="responseCheck" isMarkerVisible="true"> + <dc:Bounds x="419" y="268" width="50" height="50" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="474" y="287" width="74" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_10x3ocp_di" bpmnElement="SequenceFlow_10x3ocp"> + <di:waypoint xsi:type="dc:Point" x="386" y="293" /> + <di:waypoint xsi:type="dc:Point" x="419" y="293" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="403" y="278" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ScriptTask_0ikcqeo_di" bpmnElement="assignError"> + <dc:Bounds x="490" y="176" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1m1c9nu_di" bpmnElement="badResponse"> + <di:waypoint xsi:type="dc:Point" x="444" y="268" /> + <di:waypoint xsi:type="dc:Point" x="444" y="216" /> + <di:waypoint xsi:type="dc:Point" x="490" y="216" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="451" y="226" width="14" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0clfkld_di" bpmnElement="SequenceFlow_0clfkld"> + <di:waypoint xsi:type="dc:Point" x="590" y="216" /> + <di:waypoint xsi:type="dc:Point" x="662" y="216" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="626" y="201" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="EndEvent_13ejfwp_di" bpmnElement="throwMSOWorkflowException"> + <dc:Bounds x="662" y="198" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="680" y="234" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1o3br3u_di" bpmnElement="goodResponse"> + <di:waypoint xsi:type="dc:Point" x="444" y="318" /> + <di:waypoint xsi:type="dc:Point" x="444" y="365" /> + <di:waypoint xsi:type="dc:Point" x="490" y="365" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="447" y="339.5" width="18" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_043r3j8_di" bpmnElement="SequenceFlow_043r3j8"> + <di:waypoint xsi:type="dc:Point" x="590" y="365" /> + <di:waypoint xsi:type="dc:Point" x="630" y="365" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="610" y="350" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="CallActivity_031b5m3_di" bpmnElement="receiveAsyncCallback"> + <dc:Bounds x="490" y="325" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1h9opg9_di" bpmnElement="SequenceFlow_1h9opg9"> + <di:waypoint xsi:type="dc:Point" x="730" y="365" /> + <di:waypoint xsi:type="dc:Point" x="825" y="365" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="778" y="350" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="EndEvent_0ougemc_di" bpmnElement="EndEvent_0n56tas"> + <dc:Bounds x="825" y="347" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="843" y="383" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + </bpmndi:BPMNPlane> + </bpmndi:BPMNDiagram> +</bpmn2:definitions> diff --git a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/ReceiveWorkflowMessage.bpmn b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/ReceiveWorkflowMessage.bpmn new file mode 100644 index 0000000000..ad857eddcd --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/ReceiveWorkflowMessage.bpmn @@ -0,0 +1,184 @@ +<?xml version="1.0" encoding="UTF-8"?> +<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="_GraPIIyxEeWmdMDkx6Uftw" targetNamespace="http://camunda.org/schema/1.0/bpmn" exporter="Camunda Modeler" exporterVersion="1.4.0" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"> + <bpmn2:process id="ReceiveWorkflowMessage" name="ReceiveWorkflowMessage" isExecutable="true"> + <bpmn2:scriptTask id="ScriptTask_1" name="Pre-Process Request" scriptFormat="groovy"> + <bpmn2:incoming>SequenceFlow_9</bpmn2:incoming> + <bpmn2:outgoing>SequenceFlow_1ps0nzi</bpmn2:outgoing> + <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.common.scripts.* +def receiveWorkflowMessage = new ReceiveWorkflowMessage() +receiveWorkflowMessage .preProcessRequest(execution) +]]></bpmn2:script> + </bpmn2:scriptTask> + <bpmn2:startEvent id="StartEvent_1" name="Start"> + <bpmn2:outgoing>SequenceFlow_9</bpmn2:outgoing> + </bpmn2:startEvent> + <bpmn2:sequenceFlow id="SequenceFlow_9" name="" sourceRef="StartEvent_1" targetRef="ScriptTask_1" /> + <bpmn2:scriptTask id="ScriptTask_5" name="Workflow Exception (timeout)" scriptFormat="groovy"> + <bpmn2:incoming>SequenceFlow_27</bpmn2:incoming> + <bpmn2:outgoing>SequenceFlow_34</bpmn2:outgoing> + <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.common.scripts.* +def exceptionUtil = new ExceptionUtil() +exceptionUtil.buildWorkflowException(execution, 7010, "Receive Workflow Message Timeout Error")]]></bpmn2:script> + </bpmn2:scriptTask> + <bpmn2:sequenceFlow id="SequenceFlow_34" name="" sourceRef="ScriptTask_5" targetRef="EndEvent_8" /> + <bpmn2:endEvent id="EndEvent_8"> + <bpmn2:incoming>SequenceFlow_34</bpmn2:incoming> + <bpmn2:errorEventDefinition id="_ErrorEventDefinition_21" errorRef="Error_1" /> + </bpmn2:endEvent> + <bpmn2:scriptTask id="ScriptTask_setSuccess" name="Process Message and Set WorkflowResult" scriptFormat="groovy"> + <bpmn2:incoming>SequenceFlow_44</bpmn2:incoming> + <bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing> + <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.common.scripts.* +def receiveWorkflowMessage = new ReceiveWorkflowMessage() +receiveWorkflowMessage.processReceivedMessage(execution)]]></bpmn2:script> + </bpmn2:scriptTask> + <bpmn2:sequenceFlow id="SequenceFlow_1" name="" sourceRef="ScriptTask_setSuccess" targetRef="EndEvent_6" /> + <bpmn2:endEvent id="EndEvent_6" name="End"> + <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming> + </bpmn2:endEvent> + <bpmn2:boundaryEvent id="BoundaryEvent_1" name="Timeout" attachedToRef="SubProcess_2"> + <bpmn2:outgoing>SequenceFlow_27</bpmn2:outgoing> + <bpmn2:timerEventDefinition id="TimerEventDefinition_1"> + <bpmn2:timeDuration xsi:type="bpmn2:tFormalExpression">${RCVWFMSG_timeout}</bpmn2:timeDuration> + </bpmn2:timerEventDefinition> + </bpmn2:boundaryEvent> + <bpmn2:sequenceFlow id="SequenceFlow_27" name="" sourceRef="BoundaryEvent_1" targetRef="ScriptTask_5" /> + <bpmn2:subProcess id="SubProcess_2" name="Wait for Workflow Message"> + <bpmn2:incoming>SequenceFlow_1ps0nzi</bpmn2:incoming> + <bpmn2:outgoing>SequenceFlow_44</bpmn2:outgoing> + <bpmn2:startEvent id="StartEvent_3"> + <bpmn2:outgoing>SequenceFlow_25</bpmn2:outgoing> + </bpmn2:startEvent> + <bpmn2:sequenceFlow id="SequenceFlow_25" name="" sourceRef="StartEvent_3" targetRef="IntermediateCatchEvent_1" /> + <bpmn2:endEvent id="EndEvent_12"> + <bpmn2:incoming>SequenceFlow_41</bpmn2:incoming> + </bpmn2:endEvent> + <bpmn2:intermediateCatchEvent id="IntermediateCatchEvent_1" name="Catch Workflow Message"> + <bpmn2:incoming>SequenceFlow_25</bpmn2:incoming> + <bpmn2:outgoing>SequenceFlow_41</bpmn2:outgoing> + <bpmn2:messageEventDefinition id="MessageEventDefinition_1" messageRef="Message_07j47nk" /> + </bpmn2:intermediateCatchEvent> + <bpmn2:sequenceFlow id="SequenceFlow_41" name="" sourceRef="IntermediateCatchEvent_1" targetRef="EndEvent_12" /> + </bpmn2:subProcess> + <bpmn2:sequenceFlow id="SequenceFlow_44" name="" sourceRef="SubProcess_2" targetRef="ScriptTask_setSuccess" /> + <bpmn2:sequenceFlow id="SequenceFlow_1ps0nzi" sourceRef="ScriptTask_1" targetRef="SubProcess_2" /> + </bpmn2:process> + <bpmn2:error id="Error_1" name="MSO Workflow Exception" errorCode="MSOWorkflowException" /> + <bpmn2:message id="Message_1" name="SDNCAResponse" /> + <bpmn2:message id="Message_07j47nk" name="WorkflowMessage" /> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="ReceiveWorkflowMessage"> + <bpmndi:BPMNShape id="_BPMNShape_ScriptTask_56" bpmnElement="ScriptTask_1"> + <dc:Bounds x="242" y="161" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="_BPMNShape_SubProcess_14" bpmnElement="SubProcess_2" isExpanded="true"> + <dc:Bounds x="461" y="107" width="313" height="189" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="_BPMNShape_ScriptTask_59" bpmnElement="ScriptTask_5"> + <dc:Bounds x="857" y="382" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="_BPMNShape_BoundaryEvent_24" bpmnElement="BoundaryEvent_1"> + <dc:Bounds x="703" y="278" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="744" y="308" width="39" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="_BPMNShape_StartEvent_54" bpmnElement="StartEvent_1"> + <dc:Bounds x="129" y="184" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="135" y="225" width="23" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_2" bpmnElement="SequenceFlow_9" sourceElement="_BPMNShape_StartEvent_54" targetElement="_BPMNShape_ScriptTask_56"> + <di:waypoint xsi:type="dc:Point" x="165" y="202" /> + <di:waypoint xsi:type="dc:Point" x="242" y="201" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="204" y="186.5" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="_BPMNShape_StartEvent_55" bpmnElement="StartEvent_3"> + <dc:Bounds x="493" y="185" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="511" y="226" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_27" bpmnElement="SequenceFlow_25" sourceElement="_BPMNShape_StartEvent_55" targetElement="_BPMNShape_IntermediateCatchEvent_20"> + <di:waypoint xsi:type="dc:Point" x="529" y="203" /> + <di:waypoint xsi:type="dc:Point" x="588" y="203" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="791" y="201" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_29" bpmnElement="SequenceFlow_27" sourceElement="_BPMNShape_BoundaryEvent_24" targetElement="_BPMNShape_ScriptTask_59"> + <di:waypoint xsi:type="dc:Point" x="721" y="314" /> + <di:waypoint xsi:type="dc:Point" x="721" y="422" /> + <di:waypoint xsi:type="dc:Point" x="857" y="422" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="736" y="368" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="_BPMNShape_EndEvent_158" bpmnElement="EndEvent_6"> + <dc:Bounds x="1022" y="184" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1031" y="225" width="19" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="_BPMNShape_EndEvent_160" bpmnElement="EndEvent_8"> + <dc:Bounds x="1022" y="404" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1040" y="445" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_36" bpmnElement="SequenceFlow_34" sourceElement="_BPMNShape_ScriptTask_59" targetElement="_BPMNShape_EndEvent_160"> + <di:waypoint xsi:type="dc:Point" x="957" y="422" /> + <di:waypoint xsi:type="dc:Point" x="1022" y="422" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="990" y="407" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="_BPMNShape_ScriptTask_236" bpmnElement="ScriptTask_setSuccess"> + <dc:Bounds x="858" y="160" width="97" height="83" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_1" bpmnElement="SequenceFlow_1" sourceElement="_BPMNShape_ScriptTask_236" targetElement="_BPMNShape_EndEvent_158"> + <di:waypoint xsi:type="dc:Point" x="955" y="201" /> + <di:waypoint xsi:type="dc:Point" x="1022" y="202" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="989" y="186.5" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="_BPMNShape_EndEvent_219" bpmnElement="EndEvent_12"> + <dc:Bounds x="681" y="185" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="699" y="226" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_44" bpmnElement="SequenceFlow_44" sourceElement="_BPMNShape_SubProcess_14" targetElement="_BPMNShape_ScriptTask_236"> + <di:waypoint xsi:type="dc:Point" x="774" y="202" /> + <di:waypoint xsi:type="dc:Point" x="858" y="201" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="816" y="186.5" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_1ps0nzi_di" bpmnElement="SequenceFlow_1ps0nzi"> + <di:waypoint xsi:type="dc:Point" x="342" y="201" /> + <di:waypoint xsi:type="dc:Point" x="461" y="201" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="402" y="186" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="_BPMNShape_IntermediateCatchEvent_20" bpmnElement="IntermediateCatchEvent_1"> + <dc:Bounds x="588" y="185" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="566" y="227" width="80" height="24" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_41" bpmnElement="SequenceFlow_41" sourceElement="_BPMNShape_IntermediateCatchEvent_20"> + <di:waypoint xsi:type="dc:Point" x="624" y="203" /> + <di:waypoint xsi:type="dc:Point" x="681" y="203" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="653" y="188" width="0" height="0" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + </bpmndi:BPMNPlane> + </bpmndi:BPMNDiagram> +</bpmn2:definitions>
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/HomingTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/HomingTest.java new file mode 100644 index 0000000000..562a4d0731 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/HomingTest.java @@ -0,0 +1,457 @@ +/* + * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +package org.openecomp.mso.bpmn.common; + +import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.MockGetServiceResourcesCatalogData; +import static org.openecomp.mso.bpmn.mock.StubResponseSNIRO.*; +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.camunda.bpm.engine.test.Deployment; +import org.junit.Test; + +import org.openecomp.mso.bpmn.core.WorkflowException; +import org.openecomp.mso.bpmn.core.domain.*; + +import org.openecomp.mso.bpmn.mock.FileUtil; +import org.openecomp.mso.bpmn.common.WorkflowTest; + + +/** + * Test the Homing subflow building block. + * + * @author cb645j + */ +public class HomingTest extends WorkflowTest { + + ServiceDecomposition serviceDecomposition = new ServiceDecomposition(); + String subscriber = ""; + String subscriber2 = ""; + + private final CallbackSet callbacks = new CallbackSet(); + + public HomingTest() throws IOException { + String sniroCallback = FileUtil.readResourceFile("__files/BuildingBlocks/sniroCallback2AR1Vnf"); + String sniroCallback2 = FileUtil.readResourceFile("__files/BuildingBlocks/sniroCallback2AR1Vnf2Net"); + String sniroCallback3 = FileUtil.readResourceFile("__files/BuildingBlocks/sniroCallbackInfraVnf"); + String sniroCallbackNoSolution = FileUtil.readResourceFile("__files/BuildingBlocks/sniroCallbackNoSolutionFound"); + String sniroCallbackPolicyException = FileUtil.readResourceFile("__files/BuildingBlocks/sniroCallbackPolicyException"); + String sniroCallbackServiceException = FileUtil.readResourceFile("__files/BuildingBlocks/sniroCallbackServiceException"); + callbacks.put("sniro", JSON, "SNIROResponse", sniroCallback); + callbacks.put("sniro2", JSON, "SNIROResponse", sniroCallback2); + callbacks.put("sniro3", JSON, "SNIROResponse", sniroCallback3); + callbacks.put("sniroNoSol", JSON, "SNIROResponse", sniroCallbackNoSolution); + callbacks.put("sniroPolicyEx", JSON, "SNIROResponse", sniroCallbackPolicyException); + callbacks.put("sniroServiceEx", JSON, "SNIROResponse", sniroCallbackServiceException); + + // Service Model + ModelInfo sModel = new ModelInfo(); + sModel.setModelCustomizationUuid("testModelCustomizationUuid"); + sModel.setModelInstanceName("testModelInstanceName"); + sModel.setModelInvariantUuid("testModelInvariantId"); + sModel.setModelName("testModelName"); + sModel.setModelUuid("testModelUuid"); + sModel.setModelVersion("testModelVersion"); + // Service Instance + ServiceInstance si = new ServiceInstance(); + si.setInstanceId("testServiceInstanceId123"); + // Allotted Resources + List<AllottedResource> arList = new ArrayList<AllottedResource>(); + AllottedResource ar = new AllottedResource(); + ar.setResourceId("testResourceIdAR"); + ar.setResourceInstanceName("testARInstanceName"); + ModelInfo arModel = new ModelInfo(); + arModel.setModelCustomizationUuid("testModelCustomizationUuidAR"); + arModel.setModelInvariantUuid("testModelInvariantIdAR"); + arModel.setModelName("testModelNameAR"); + arModel.setModelVersion("testModelVersionAR"); + arModel.setModelUuid("testARModelUuid"); + arModel.setModelType("testModelTypeAR"); + ar.setModelInfo(arModel); + AllottedResource ar2 = new AllottedResource(); + ar2.setResourceId("testResourceIdAR2"); + ar2.setResourceInstanceName("testAR2InstanceName"); + ModelInfo arModel2 = new ModelInfo(); + arModel2.setModelCustomizationUuid("testModelCustomizationUuidAR2"); + arModel2.setModelInvariantUuid("testModelInvariantIdAR2"); + arModel2.setModelName("testModelNameAR2"); + arModel2.setModelVersion("testModelVersionAR2"); + arModel2.setModelUuid("testAr2ModelUuid"); + arModel2.setModelType("testModelTypeAR2"); + ar2.setModelInfo(arModel2); + arList.add(ar); + arList.add(ar2); + // Vnfs + List<VnfResource> vnfList = new ArrayList<VnfResource>(); + VnfResource vnf = new VnfResource(); + vnf.setResourceId("testResourceIdVNF"); + vnf.setResourceInstanceName("testVnfInstanceName"); + ModelInfo vnfModel = new ModelInfo(); + vnfModel.setModelCustomizationUuid("testModelCustomizationUuidVNF"); + vnfModel.setModelInvariantUuid("testModelInvariantIdVNF"); + vnfModel.setModelName("testModelNameVNF"); + vnfModel.setModelVersion("testModelVersionVNF"); + vnfModel.setModelUuid("testVnfModelUuid"); + vnfModel.setModelType("testModelTypeVNF"); + vnf.setModelInfo(vnfModel); + vnfList.add(vnf); + System.out.println("SERVICE DECOMP: " + serviceDecomposition.getServiceResourcesJsonString()); + serviceDecomposition.setModelInfo(sModel); + serviceDecomposition.setServiceAllottedResources(arList); + serviceDecomposition.setServiceVnfs(vnfList); + serviceDecomposition.setServiceInstance(si); + + // Subscriber + subscriber = "{\"globalSubscriberId\": \"SUB12_0322_DS_1201\",\"subscriberCommonSiteId\": \"DALTX0101\",\"subscriberName\": \"SUB_12_0322_DS_1201\"}"; + subscriber2 = "{\"globalSubscriberId\": \"SUB12_0322_DS_1201\",\"subscriberName\": \"SUB_12_0322_DS_1201\"}"; + } + + @Test + @Deployment(resources = {"subprocess/BuildingBlock/Homing.bpmn", "subprocess/ReceiveWorkflowMessage.bpmn"}) + public void testHoming_success_2AR1Vnf() throws Exception { + + mockSNIRO(); + + String businessKey = UUID.randomUUID().toString(); + Map<String, Object> variables = new HashMap<String, Object>(); + setVariables(variables); + + invokeSubProcess("Homing", businessKey, variables); + + injectWorkflowMessages(callbacks, "sniro"); + + waitForProcessEnd(businessKey, 10000); + + //Get Variables + WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException"); + ServiceDecomposition serviceDecompositionExp = (ServiceDecomposition) getVariableFromHistory(businessKey, "serviceDecomposition"); + String expectedSniroRequest = (String) getVariableFromHistory(businessKey, "sniroRequest"); + + Resource resourceAR = serviceDecompositionExp.getServiceResource("testResourceIdAR"); + HomingSolution resourceARHoming = resourceAR.getHomingSolution(); + Resource resourceAR2 = serviceDecompositionExp.getServiceResource("testResourceIdAR2"); + HomingSolution resourceARHoming2 = resourceAR2.getHomingSolution(); + Resource resourceVNF = serviceDecompositionExp.getServiceResource("testResourceIdVNF"); + HomingSolution resourceVNFHoming = resourceVNF.getHomingSolution(); + String resourceARHomingString = resourceARHoming.toString(); + resourceARHomingString = resourceARHomingString.replaceAll("\\s+", " "); + String resourceARHoming2String = resourceARHoming2.toString(); + resourceARHoming2String = resourceARHoming2String.replaceAll("\\s+", " "); + String resourceVNFHomingString = resourceVNFHoming.toString(); + resourceVNFHomingString = resourceVNFHomingString.replaceAll("\\s+", " "); + expectedSniroRequest = expectedSniroRequest.replaceAll("\\s+", ""); + + assertNull(workflowException); + assertEquals(homingSolutionService("service", "testSIID1", "MDTNJ01", "aic", "dfwtx", "KDTNJ01", "3.0", "\"f1d563e8-e714-4393-8f99-cc480144a05e\", \"j1d563e8-e714-4393-8f99-cc480144a05e\"", "\"s1d563e8-e714-4393-8f99-cc480144a05e\", \"b1d563e8-e714-4393-8f99-cc480144a05e\""), resourceARHomingString); + assertEquals(homingSolutionService("service", "testSIID2", "testVnfHostname2", "aic", "testCloudRegionId2", "testAicClli2", "3.0", null, null), resourceARHoming2String); + assertEquals(homingSolutionCloud("cloud", "", "", "aic", "testCloudRegionId3", "testAicClli3", "3.0", "\"91d563e8-e714-4393-8f99-cc480144a05e\", \"21d563e8-e714-4393-8f99-cc480144a05e\"", "\"31d563e8-e714-4393-8f99-cc480144a05e\", \"71d563e8-e714-4393-8f99-cc480144a05e\""), resourceVNFHomingString); + assertEquals(verifySniroRequest(), expectedSniroRequest); + + } + + @Test + @Deployment(resources = {"subprocess/BuildingBlock/Homing.bpmn", "subprocess/ReceiveWorkflowMessage.bpmn"}) + public void testHoming_success_2AR1Vnf2Net() throws Exception { + + mockSNIRO(); + + String businessKey = UUID.randomUUID().toString(); + Map<String, Object> variables = new HashMap<String, Object>(); + setVariables2(variables); + + invokeSubProcess("Homing", businessKey, variables); + + injectWorkflowMessages(callbacks, "sniro2"); + + waitForProcessEnd(businessKey, 10000); + + //Get Variables + WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException"); + ServiceDecomposition serviceDecompositionExp = (ServiceDecomposition) getVariableFromHistory(businessKey, "serviceDecomposition"); + String expectedSniroRequest = (String) getVariableFromHistory(businessKey, "sniroRequest"); + + Resource resourceAR = serviceDecompositionExp.getServiceResource("testResourceIdAR"); + HomingSolution resourceARHoming = resourceAR.getHomingSolution(); + Resource resourceAR2 = serviceDecompositionExp.getServiceResource("testResourceIdAR2"); + HomingSolution resourceARHoming2 = resourceAR2.getHomingSolution(); + Resource resourceVNF = serviceDecompositionExp.getServiceResource("testResourceIdVNF"); + HomingSolution resourceVNFHoming = resourceVNF.getHomingSolution(); + Resource resourceNet = serviceDecompositionExp.getServiceResource("testResourceIdNet"); + HomingSolution resourceNetHoming = resourceNet.getHomingSolution(); + Resource resourceNet2 = serviceDecompositionExp.getServiceResource("testResourceIdNet2"); + HomingSolution resourceNetHoming2 = resourceNet2.getHomingSolution(); + + String resourceARHomingString = resourceARHoming.toString(); + resourceARHomingString = resourceARHomingString.replaceAll("\\s+", " "); + String resourceARHoming2String = resourceARHoming2.toString(); + resourceARHoming2String = resourceARHoming2String.replaceAll("\\s+", " "); + String resourceVNFHomingString = resourceVNFHoming.toString(); + resourceVNFHomingString = resourceVNFHomingString.replaceAll("\\s+", " "); + String resourceNetHomingString = resourceNetHoming.toString(); + resourceNetHomingString = resourceNetHomingString.replaceAll("\\s+", " "); + String resourceNetHoming2String = resourceNetHoming2.toString(); + resourceNetHoming2String = resourceNetHoming2String.replaceAll("\\s+", " "); + expectedSniroRequest = expectedSniroRequest.replaceAll("\\s+", ""); + + assertNull(workflowException); + assertEquals(homingSolutionService("service", "testSIID1", "MDTNJ01", "aic", "dfwtx", "KDTNJ01", "3.0", "\"f1d563e8-e714-4393-8f99-cc480144a05e\", \"j1d563e8-e714-4393-8f99-cc480144a05e\"", "\"s1d563e8-e714-4393-8f99-cc480144a05e\", \"b1d563e8-e714-4393-8f99-cc480144a05e\""), resourceARHomingString); + assertEquals(homingSolutionService("service", "testSIID2", "testVnfHostname2", "aic", "testCloudRegionId2", "testAicClli2", "3.0", null, null), resourceARHoming2String); + assertEquals(homingSolutionCloud("cloud", "", "", "aic", "testCloudRegionId3", "testAicClli3", "3.0", "\"91d563e8-e714-4393-8f99-cc480144a05e\", \"21d563e8-e714-4393-8f99-cc480144a05e\"", "\"31d563e8-e714-4393-8f99-cc480144a05e\", \"71d563e8-e714-4393-8f99-cc480144a05e\""), resourceVNFHomingString); + assertEquals(homingSolutionService("service", "testServiceInstanceIdNet", "testVnfHostNameNet", "aic", "testCloudRegionIdNet", "testAicClliNet", "3.0", null, null), resourceNetHomingString); + assertEquals(homingSolutionCloud("cloud", "", "", "aic", "testCloudRegionIdNet2", "testAicClliNet2", "3.0", "\"f1d563e8-e714-4393-8f99-cc480144a05n\", \"j1d563e8-e714-4393-8f99-cc480144a05n\"", "\"s1d563e8-e714-4393-8f99-cc480144a05n\", \"b1d563e8-e714-4393-8f99-cc480144a05n\""), resourceNetHoming2String); + assertEquals(verifySniroRequest(), expectedSniroRequest); + } + + @Test + @Deployment(resources = {"subprocess/BuildingBlock/Homing.bpmn", "subprocess/BuildingBlock/DecomposeService.bpmn", "subprocess/ReceiveWorkflowMessage.bpmn"}) + public void testHoming_success_vnfResourceList() throws Exception { + + // Create a Service Decomposition +//System.out.println("At start of testHoming_success_vnfResourceList"); + MockGetServiceResourcesCatalogData("1cc4e2e4-eb6e-404d-a66f-c8733cedcce8", "5.0", "/BuildingBlocks/catalogResp.json"); + String busKey = UUID.randomUUID().toString(); + Map<String, Object> vars = new HashMap<String, Object>(); + setVariablesForServiceDecomposition(vars, "testRequestId123", "ff5256d2-5a33-55df-13ab-12abad84e7ff"); + invokeSubProcess("DecomposeService", busKey, vars); + + ServiceDecomposition sd = (ServiceDecomposition) getVariableFromHistory(busKey, "serviceDecomposition"); +//System.out.println("In testHoming_success_vnfResourceList, ServiceDecomposition = " + sd); + List<VnfResource> vnfResourceList = sd.getServiceVnfs(); +//System.out.println(" vnfResourceList = " + vnfResourceList); + vnfResourceList.get(0).setResourceId("test-resource-id-000"); + + // Invoke Homing + + mockSNIRO(); + + String businessKey = UUID.randomUUID().toString(); + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("isDebugLogEnabled", "true"); + variables.put("msoRequestId", "testRequestId"); + variables.put("serviceInstanceId", "testServiceInstanceId"); + variables.put("serviceDecomposition", sd); + variables.put("subscriberInfo", subscriber2); + + invokeSubProcess("Homing", businessKey, variables); + injectWorkflowMessages(callbacks, "sniro3"); + waitForProcessEnd(businessKey, 10000); + + //Get Variables + + WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException"); + ServiceDecomposition serviceDecompositionExp = (ServiceDecomposition) getVariableFromHistory(businessKey, "serviceDecomposition"); + + Resource resourceVnf = serviceDecompositionExp.getServiceResource("test-resource-id-000"); + HomingSolution resourceVnfHoming = resourceVnf.getHomingSolution(); + + String resourceVnfHomingString = resourceVnfHoming.toString(); + resourceVnfHomingString = resourceVnfHomingString.replaceAll("\\s+", " "); + + assertNull(workflowException); + + //Verify request + String sniroRequest = (String) getVariableFromHistory(businessKey, "sniroRequest"); + assertEquals(FileUtil.readResourceFile("__files/BuildingBlocks/sniroRequest_infravnf").replaceAll("\n", "").replaceAll("\r", "").replaceAll("\t", ""), sniroRequest.replaceAll("\n", "").replaceAll("\r", "").replaceAll("\t", "")); + + assertEquals(homingSolutionService("service", "service-instance-01234", "MDTNJ01", "att-aic", "mtmnj1a", "KDTNJ01", "3.0", "\"f1d563e8-e714-4393-8f99-cc480144a05e\", \"j1d563e8-e714-4393-8f99-cc480144a05e\"", "\"s1d563e8-e714-4393-8f99-cc480144a05e\", \"b1d563e8-e714-4393-8f99-cc480144a05e\""), resourceVnfHomingString); + } + + @Test + @Deployment(resources = {"subprocess/BuildingBlock/Homing.bpmn", "subprocess/ReceiveWorkflowMessage.bpmn"}) + public void testHoming_error_inputVariable() throws Exception { + + String businessKey = UUID.randomUUID().toString(); + Map<String, Object> variables = new HashMap<String, Object>(); + setVariables3(variables); + + invokeSubProcess("Homing", businessKey, variables); + + waitForProcessEnd(businessKey, 10000); + + //Get Variables + WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException"); + + assertEquals("WorkflowException[processKey=Homing,errorCode=4000,errorMessage=A required input variable is missing or null]", workflowException.toString()); + } + + @Test + @Deployment(resources = {"subprocess/BuildingBlock/Homing.bpmn", "subprocess/ReceiveWorkflowMessage.bpmn"}) + public void testHoming_error_badResponse() throws Exception { + mockSNIRO_500(); + + String businessKey = UUID.randomUUID().toString(); + Map<String, Object> variables = new HashMap<String, Object>(); + setVariables(variables); + + invokeSubProcess("Homing", businessKey, variables); + + waitForProcessEnd(businessKey, 10000); + + //Get Variables + WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException"); + + assertEquals("WorkflowException[processKey=Homing,errorCode=500,errorMessage=Received a Bad Sync Response from Sniro.]", workflowException.toString()); + } + + @Test + @Deployment(resources = {"subprocess/BuildingBlock/Homing.bpmn", "subprocess/ReceiveWorkflowMessage.bpmn"}) + public void testHoming_error_sniroNoSolution() throws Exception { + mockSNIRO(); + + String businessKey = UUID.randomUUID().toString(); + Map<String, Object> variables = new HashMap<String, Object>(); + setVariables(variables); + + invokeSubProcess("Homing", businessKey, variables); + + injectWorkflowMessages(callbacks, "sniroNoSol"); + + waitForProcessEnd(businessKey, 10000); + + //Get Variables + WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException"); + + assertEquals("WorkflowException[processKey=Homing,errorCode=400,errorMessage=No solution found for plan 08e1b8cf-144a-4bac-b293-d5e2eedc97e8]", workflowException.toString()); + } + + @Test + @Deployment(resources = {"subprocess/BuildingBlock/Homing.bpmn", "subprocess/ReceiveWorkflowMessage.bpmn"}) + public void testHoming_error_sniroPolicyException() throws Exception { + mockSNIRO(); + + String businessKey = UUID.randomUUID().toString(); + Map<String, Object> variables = new HashMap<String, Object>(); + setVariables(variables); + + invokeSubProcess("Homing", businessKey, variables); + + injectWorkflowMessages(callbacks, "sniroPolicyEx"); + + waitForProcessEnd(businessKey, 10000); + + //Get Variables + WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException"); + + assertEquals("WorkflowException[processKey=Homing,errorCode=400,errorMessage=Sniro Async Callback Response contains a Request Error Policy Exception: Message content size exceeds the allowable limit]", workflowException.toString()); + } + + @Test + @Deployment(resources = {"subprocess/BuildingBlock/Homing.bpmn", "subprocess/ReceiveWorkflowMessage.bpmn"}) + public void testHoming_error_sniroServiceException() throws Exception { + mockSNIRO(); + + String businessKey = UUID.randomUUID().toString(); + Map<String, Object> variables = new HashMap<String, Object>(); + setVariables(variables); + + invokeSubProcess("Homing", businessKey, variables); + + injectWorkflowMessages(callbacks, "sniroServiceEx"); + + waitForProcessEnd(businessKey, 10000); + + //Get Variables + WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException"); + + assertEquals("WorkflowException[processKey=Homing,errorCode=400,errorMessage=Sniro Async Callback Response contains a Request Error Service Exception: SNIROPlacementError: requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http://135.21.171.200:8091/v1/plans/97b4e303-5f75-492c-8fb2-21098281c8b8]", workflowException.toString()); + } + + + + private void setVariables(Map<String, Object> variables) { + variables.put("isDebugLogEnabled", "true"); + // variables.put("mso-request-id", "testRequestId"); + variables.put("msoRequestId", "testRequestId"); + variables.put("serviceInstanceId", "testServiceInstanceId"); + variables.put("serviceDecomposition", serviceDecomposition); + variables.put("subscriberInfo", subscriber2); + + } + + private void setVariables2(Map<String, Object> variables) { + List<NetworkResource> netList = new ArrayList<NetworkResource>(); + NetworkResource net = new NetworkResource(); + net.setResourceId("testResourceIdNet"); + ModelInfo netModel = new ModelInfo(); + netModel.setModelCustomizationUuid("testModelCustomizationUuidNet"); + netModel.setModelInvariantUuid("testModelInvariantIdNet"); + netModel.setModelName("testModelNameNet"); + netModel.setModelVersion("testModelVersionNet"); + net.setModelInfo(netModel); + netList.add(net); + NetworkResource net2 = new NetworkResource(); + net2.setResourceId("testResourceIdNet2"); + ModelInfo netModel2 = new ModelInfo(); + netModel2.setModelCustomizationUuid("testModelCustomizationUuidNet2"); + netModel2.setModelInvariantUuid("testModelInvariantIdNet2"); + netModel2.setModelName("testModelNameNet2"); + netModel2.setModelVersion("testModelVersionNet2"); + net2.setModelInfo(netModel2); + netList.add(net2); + serviceDecomposition.setServiceNetworks(netList); + + variables.put("isDebugLogEnabled", "true"); + variables.put("msoRequestId", "testRequestId"); + variables.put("serviceInstanceId", "testServiceInstanceId"); + variables.put("serviceDecomposition", serviceDecomposition); + variables.put("subscriberInfo", subscriber2); + } + + private void setVariables3(Map<String, Object> variables) { + variables.put("isDebugLogEnabled", "true"); + // variables.put("mso-request-id", "testRequestId"); + variables.put("msoRequestId", "testRequestId"); + variables.put("serviceInstanceId", "testServiceInstanceId"); + variables.put("serviceDecomposition", null); + variables.put("subscriberInfo", subscriber2); + + } + + private String homingSolutionService(String type, String serviceInstanceId, String vnfHostname, String cloudOwner, String cloudRegionId, String aicClli, String aicVersion, String enList, String licenseList){ + String solution = ""; + if(enList == null){ + solution = "{ \"homingSolution\" : { \"inventoryType\" : \"" + type + "\", \"serviceInstanceId\" : \"" + serviceInstanceId + "\", \"vnfHostname\" : \"" + vnfHostname + "\", \"cloudOwner\" : \"" + cloudOwner + "\", \"cloudRegionId\" : \"" + cloudRegionId + "\", \"aicClli\" : \"" + aicClli + "\", \"aicVersion\" : \"" + aicVersion + "\" } }"; + }else{ + solution = "{ \"homingSolution\" : { \"inventoryType\" : \"" + type + "\", \"serviceInstanceId\" : \"" + serviceInstanceId + "\", \"vnfHostname\" : \"" + vnfHostname + "\", \"cloudOwner\" : \"" + cloudOwner + "\", \"cloudRegionId\" : \"" + cloudRegionId + "\", \"aicClli\" : \"" + aicClli + "\", \"aicVersion\" : \"" + aicVersion + "\", \"entitlementPoolList\" : [ " + enList + " ], \"licenseKeyGroupList\" : [ " + licenseList + " ] } }"; + } + return solution; + } + + private String homingSolutionCloud(String type, String serviceInstanceId, String vnfHostname, String cloudOwner, String cloudRegionId, String aicClli, String aicVersion, String enList, String licenseList){ + String solution = ""; + if(enList == null){ + solution = "{ \"homingSolution\" : { \"inventoryType\" : \"" + type + "\", \"cloudOwner\" : \"" + cloudOwner + "\", \"cloudRegionId\" : \"" + cloudRegionId + "\", \"aicClli\" : \"" + aicClli + "\", \"aicVersion\" : \"" + aicVersion + "\" } }"; + }else{ + solution = "{ \"homingSolution\" : { \"inventoryType\" : \"" + type + "\", \"cloudOwner\" : \"" + cloudOwner + "\", \"cloudRegionId\" : \"" + cloudRegionId + "\", \"aicClli\" : \"" + aicClli + "\", \"aicVersion\" : \"" + aicVersion + "\", \"entitlementPoolList\" : [ " + enList + " ], \"licenseKeyGroupList\" : [ " + licenseList + " ] } }"; + } + return solution; + } + + private void setVariablesForServiceDecomposition(Map<String, Object> variables, String requestId, String siId) { + variables.put("isDebugLogEnabled", "true"); + variables.put("mso-request-id", requestId); + variables.put("msoRequestId", requestId); + variables.put("serviceInstanceId",siId); + + String serviceModelInfo = "{ "+ "\"modelType\": \"service\"," + + "\"modelInvariantUuid\": \"1cc4e2e4-eb6e-404d-a66f-c8733cedcce8\"," + + "\"modelUuid\": \"2f7f309d-c842-4644-a2e4-34167be5eeb4\"," + + "\"modelName\": \"ADIOD vRouter vCE 011017 Service\"," + + "\"modelVersion\": \"5.0\"," + + "}"; + variables.put("serviceModelInfo", serviceModelInfo); + } + + private String verifySniroRequest(){ + String request = "{\"requestInfo\":{\"transactionId\":\"testRequestId\",\"requestId\":\"testRequestId\",\"callbackUrl\":\"http://localhost:8090/workflows/messages/message/SNIROResponse/testRequestId\",\"sourceId\":\"mso\",\"optimizer\":[\"placement\",\"license\"],\"numSolutions\":1,\"timeout\":600},\"placementInfo\":{\"serviceModelInfo\":{\"modelType\":\"\",\"modelInvariantId\":\"testModelInvariantId\",\"modelVersionId\":\"testModelUuid\",\"modelName\":\"testModelName\",\"modelVersion\":\"testModelVersion\"},\"subscriberInfo\":{\"globalSubscriberId\":\"SUB12_0322_DS_1201\",\"subscriberName\":\"SUB_12_0322_DS_1201\",\"subscriberCommonSiteId\":\"\"},\"demandInfo\":{\"placementDemand\":[{\"resourceInstanceType\":\"ALLOTTED_RESOURCE\",\"serviceResourceId\":\"testResourceIdAR\",\"resourceModuleName\":\"\",\"resourceModelInfo\":{\"modelCustomizationId\":\"testModelCustomizationUuidAR\",\"modelInvariantId\":\"testModelInvariantIdAR\",\"modelName\":\"testModelNameAR\",\"modelVersion\":\"testModelVersionAR\",\"modelVersionId\":\"testARModelUuid\",\"modelType\":\"testModelTypeAR\"},\"tenantId\":\"\",\"tenantName\":\"\"},{\"resourceInstanceType\":\"ALLOTTED_RESOURCE\",\"serviceResourceId\":\"testResourceIdAR2\",\"resourceModuleName\":\"\",\"resourceModelInfo\":{\"modelCustomizationId\":\"testModelCustomizationUuidAR2\",\"modelInvariantId\":\"testModelInvariantIdAR2\",\"modelName\":\"testModelNameAR2\",\"modelVersion\":\"testModelVersionAR2\",\"modelVersionId\":\"testAr2ModelUuid\",\"modelType\":\"testModelTypeAR2\"},\"tenantId\":\"\",\"tenantName\":\"\"}],\"licenseDemand\":[{\"resourceInstanceType\":\"VNF\",\"serviceResourceId\":\"testResourceIdVNF\",\"resourceModuleName\":\"\",\"resourceModelInfo\":{\"modelCustomizationId\":\"testModelCustomizationUuidVNF\",\"modelInvariantId\":\"testModelInvariantIdVNF\",\"modelName\":\"testModelNameVNF\",\"modelVersion\":\"testModelVersionVNF\",\"modelVersionId\":\"testVnfModelUuid\",\"modelType\":\"testModelTypeVNF\"}}]},\"policyId\":[],\"serviceInstanceId\":\"testServiceInstanceId123\",\"orderInfo\":\"{\\\"requestParameters\\\":null}\"}}"; + return request; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/ReceiveWorkflowMessageTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/ReceiveWorkflowMessageTest.java new file mode 100644 index 0000000000..e9373eeaf9 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/ReceiveWorkflowMessageTest.java @@ -0,0 +1,122 @@ +package org.openecomp.mso.bpmn.common; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.camunda.bpm.engine.test.Deployment; +import org.junit.Test; +import org.openecomp.mso.bpmn.common.WorkflowTest; +import org.openecomp.mso.bpmn.common.WorkflowTest.CallbackSet; +import org.openecomp.mso.bpmn.core.WorkflowException; + +/** + * Unit tests for SDNCAdapterRestV1. + */ +public class ReceiveWorkflowMessageTest extends WorkflowTest { + + private static final String EOL = "\n"; + + private final CallbackSet callbacks = new CallbackSet(); + + public ReceiveWorkflowMessageTest() throws IOException { + callbacks.put("sdnc-event-success", JSON, "SDNCAEvent", + "{" + EOL + + " \"SDNCEvent\": {" + EOL + + " \"eventType\": \"UCPE-ACTIVATION\"," + EOL + + " \"eventCorrelatorType\": \"UCPE-HOST-NAME\"," + EOL + + " \"eventCorrelator\": \"((CORRELATOR))\"," + EOL + + " \"params\": {\"entry\":[" + EOL + + " {\"key\": \"success-indicator\", \"value\":\"Y\"}" + EOL + + " ]}" +EOL + + " }" + EOL + + "}" + EOL); + + callbacks.put("sdnc-event-fail", JSON, "SDNCAEvent", + "{" + EOL + + " \"SDNCEvent\": {" + EOL + + " \"eventType\": \"UCPE-ACTIVATION\"," + EOL + + " \"eventCorrelatorType\": \"UCPE-HOST-NAME\"," + EOL + + " \"eventCorrelator\": \"((CORRELATOR))\"," + EOL + + " \"params\": {\"entry\":[" + EOL + + " {\"key\": \"success-indicator\", \"value\":\"N\"}" + EOL + + " {\"key\": \"error-message\", \"value\":\"SOMETHING BAD HAPPENED\"}" + EOL + + " ]}" +EOL + + " }" + EOL + + "}" + EOL); + } + + /** + * Test the happy path. + */ + @Test + @Deployment(resources = { + "subprocess/ReceiveWorkflowMessage.bpmn" + }) + public void happyPath() throws Exception { + + logStart(); + + String businessKey = UUID.randomUUID().toString(); + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("mso-request-id", "dffbae0e-5588-4bd6-9749-b0f0adb52312"); + variables.put("isDebugLogEnabled", "true"); + variables.put("RCVWFMSG_timeout", "PT1M"); + variables.put("RCVWFMSG_messageType", "SDNCAEvent"); + variables.put("RCVWFMSG_correlator", "USOSTCDALTX0101UJZZ31"); + + invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables); + injectWorkflowMessages(callbacks, "sdnc-event-success"); + waitForProcessEnd(businessKey, 10000); + + String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse"); + System.out.println("Response:\n" + response); + assertTrue(response.contains("\"SDNCEvent\"")); + assertTrue((boolean)getVariableFromHistory(businessKey, "RCVWFMSG_SuccessIndicator")); + + logEnd(); + } + + /** + * Test the timeout scenario. + */ + @Test + @Deployment(resources = { + "subprocess/ReceiveWorkflowMessage.bpmn" + }) + public void timeout() throws Exception { + logStart(); + + String businessKey = UUID.randomUUID().toString(); + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("mso-request-id", "dffbae0e-5588-4bd6-9749-b0f0adb52312"); + variables.put("isDebugLogEnabled", "true"); + variables.put("RCVWFMSG_timeout", "PT0.1S"); + variables.put("RCVWFMSG_messageType", "SDNCAEvent"); + variables.put("RCVWFMSG_correlator", "USOSTCDALTX0101UJZZ31"); + + invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables); + + // No injection + + waitForProcessEnd(businessKey, 10000); + + // There is no response from SDNC, so the flow doesn't set WorkflowResponse. + String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse"); + assertNull(response); + WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException"); + assertNotNull(wfe); + System.out.println(wfe.toString()); + assertEquals("Receive Workflow Message Timeout Error", wfe.getErrorMessage()); + assertFalse((boolean)getVariableFromHistory(businessKey, "RCVWFMSG_SuccessIndicator")); + + logEnd(); + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/catalogResp.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/catalogResp.json new file mode 100644 index 0000000000..0fdada5c68 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/catalogResp.json @@ -0,0 +1,46 @@ +{ + "serviceResources": { + "serviceType": null, + "serviceAllottedResources": [], + "modelInfo": { + "modelInvariantUuid": "1cc4e2e4-eb6e-404d-a66f-c8733cedcce8", + "modelName": "ADIOD vRouter vCE 011017 Service", + "modelVersion": "5.0", + "modelUuid": "2f7f309d-c842-4644-a2e4-34167be5eeb4" + }, + "serviceRole": null, + "serviceVnfs": [ + { + "toscaNodeType": "org.openecomp.resource.vf.AdiodVce", + "vfModules": [ + { + "initialCount": null, + "vfModuleLabel": null, + "modelInfo": { + "modelInvariantUuid": "7fb428e1-8000-4800-a71a-f21b946973c5", + "modelName": "AdiodVce..base_vCE..module-0", + "modelVersion": "2", + "modelCustomizationUuid": "1126e7e2-b377-4fd2-ad48-660a20caa829", + "modelUuid": "435d57e1-93a2-4d58-aa5d-f2df2d126276" + }, + "hasVolumeGroup": true, + "isBase": true + } + ], + "modelInfo": { + "modelInvariantUuid": "fc72435b-4366-4257-a2f7-c70a3a998a7b", + "modelName": "ADIoD vCE", + "modelVersion": "2.0", + "modelCustomizationUuid": "bdaeed40-c964-4966-bdb8-51320dcaf587", + "modelInstanceName": "ADIoD vCE 0", + "modelUuid": "ec2bd873-5b2c-47e4-8858-f0495fa1dae1" + }, + "nfRole": "", + "nfType": "", + "nfFunction": "", + "nfNamingCode": "" + } + ], + "serviceNetworks": [] + } +}
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallback2AR1Vnf b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallback2AR1Vnf new file mode 100644 index 0000000000..19f18cce52 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallback2AR1Vnf @@ -0,0 +1,107 @@ +{ + "transactionId": "testRequestId", + "requestId": "testRequestId", + "requestState": "complete", + "statusMessage": "", + "solutionInfo": { + "licenseInfo": [ + { + "entitlementPoolList": [ + "f1d563e8-e714-4393-8f99-cc480144a05e", + "j1d563e8-e714-4393-8f99-cc480144a05e" + ], + "licenseKeyGroupList": [ + "s1d563e8-e714-4393-8f99-cc480144a05e", + "b1d563e8-e714-4393-8f99-cc480144a05e" + ], + "resourceModuleName": "vHNPortalaaS_primary_1", + "serviceResourceId": "testResourceIdAR" + }, + { + "entitlementPoolList": [ + "91d563e8-e714-4393-8f99-cc480144a05e", + "21d563e8-e714-4393-8f99-cc480144a05e" + ], + "licenseKeyGroupList": [ + "31d563e8-e714-4393-8f99-cc480144a05e", + "71d563e8-e714-4393-8f99-cc480144a05e" + ], + "resourceModuleName": "vHNPortalaaS_secondary_1", + "serviceResourceId": "testResourceIdVNF" + } + ], + "placement": [ + { + "assignmentInfo": [ + { + "variableName": "cloudOwner", + "variableValue": "aic" + }, + { + "variableName": "vnfHostName", + "variableValue": "MDTNJ01" + }, + { + "variableName": "aicClli", + "variableValue": "KDTNJ01" + }, + { + "variableName": "aicVersion", + "variableValue": "3.0" + } + ], + "cloudRegionId": "dfwtx", + "inventoryType": "service", + "resourceModuleName": "ALLOTTED_RESOURCE", + "serviceInstanceId": "testSIID1", + "serviceResourceId": "testResourceIdAR" + }, + { + "assignmentInfo": [ + { + "variableName": "cloudOwner", + "variableValue": "aic" + }, + { + "variableName": "vnfHostName", + "variableValue": "testVnfHostname2" + }, + { + "variableName": "aicClli", + "variableValue": "testAicClli2" + }, + { + "variableName": "aicVersion", + "variableValue": "3.0" + } + ], + "cloudRegionId": "testCloudRegionId2", + "inventoryType": "service", + "resourceModuleName": "ALLOTTED_RESOURCE", + "serviceInstanceId": "testSIID2", + "serviceResourceId": "testResourceIdAR2" + }, + { + "assignmentInfo": [ + { + "variableName": "cloudOwner", + "variableValue": "aic" + }, + { + "variableName": "aicClli", + "variableValue": "testAicClli3" + }, + { + "variableName": "aicVersion", + "variableValue": "3.0" + } + ], + "cloudRegionId": "testCloudRegionId3", + "inventoryType": "cloud", + "resourceModuleName": "VNF", + "serviceInstanceId": "", + "serviceResourceId": "testResourceIdVNF" + } + ] + } +}
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallback2AR1Vnf2Net b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallback2AR1Vnf2Net new file mode 100644 index 0000000000..5a9ef4b4f9 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallback2AR1Vnf2Net @@ -0,0 +1,165 @@ +{ + "transactionId": "testRequestId", + "requestId": "testRequestId", + "requestState": "complete", + "statusMessage": "", + "solutionInfo": { + "licenseInfo": [ + { + "entitlementPoolList": [ + "f1d563e8-e714-4393-8f99-cc480144a05e", + "j1d563e8-e714-4393-8f99-cc480144a05e" + ], + "licenseKeyGroupList": [ + "s1d563e8-e714-4393-8f99-cc480144a05e", + "b1d563e8-e714-4393-8f99-cc480144a05e" + ], + "resourceModuleName": "vHNPortalaaS_primary_1", + "serviceResourceId": "testResourceIdAR" + }, + { + "entitlementPoolList": [ + "f1d563e8-e714-4393-8f99-cc480144a05n", + "j1d563e8-e714-4393-8f99-cc480144a05n" + ], + "licenseKeyGroupList": [ + "s1d563e8-e714-4393-8f99-cc480144a05n", + "b1d563e8-e714-4393-8f99-cc480144a05n" + ], + "resourceModuleName": "net", + "serviceResourceId": "testResourceIdNet2" + }, + { + "entitlementPoolList": [ + "91d563e8-e714-4393-8f99-cc480144a05e", + "21d563e8-e714-4393-8f99-cc480144a05e" + ], + "licenseKeyGroupList": [ + "31d563e8-e714-4393-8f99-cc480144a05e", + "71d563e8-e714-4393-8f99-cc480144a05e" + ], + "resourceModuleName": "vHNPortalaaS_secondary_1", + "serviceResourceId": "testResourceIdVNF" + } + ], + "placement": [ + { + "assignmentInfo": [ + { + "variableName": "cloudOwner", + "variableValue": "aic" + }, + { + "variableName": "vnfHostName", + "variableValue": "MDTNJ01" + }, + { + "variableName": "aicClli", + "variableValue": "KDTNJ01" + }, + { + "variableName": "aicVersion", + "variableValue": "3.0" + } + ], + "cloudRegionId": "dfwtx", + "inventoryType": "service", + "resourceModuleName": "ALLOTTED_RESOURCE", + "serviceInstanceId": "testSIID1", + "serviceResourceId": "testResourceIdAR" + }, + { + "assignmentInfo": [ + { + "variableName": "cloudOwner", + "variableValue": "aic" + }, + { + "variableName": "vnfHostName", + "variableValue": "testVnfHostname2" + }, + { + "variableName": "aicClli", + "variableValue": "testAicClli2" + }, + { + "variableName": "aicVersion", + "variableValue": "3.0" + } + ], + "cloudRegionId": "testCloudRegionId2", + "inventoryType": "service", + "resourceModuleName": "ALLOTTED_RESOURCE", + "serviceInstanceId": "testSIID2", + "serviceResourceId": "testResourceIdAR2" + }, + { + "assignmentInfo": [ + { + "variableName": "cloudOwner", + "variableValue": "aic" + }, + { + "variableName": "vnfHostName", + "variableValue": "testVnfHostNameNet" + }, + { + "variableName": "aicClli", + "variableValue": "testAicClliNet" + }, + { + "variableName": "aicVersion", + "variableValue": "3.0" + } + ], + "cloudRegionId": "testCloudRegionIdNet", + "inventoryType": "service", + "resourceModuleName": "NETWORK", + "serviceInstanceId": "testServiceInstanceIdNet", + "serviceResourceId": "testResourceIdNet" + }, + { + "assignmentInfo": [ + { + "variableName": "cloudOwner", + "variableValue": "aic" + }, + { + "variableName": "aicClli", + "variableValue": "testAicClliNet2" + }, + { + "variableName": "aicVersion", + "variableValue": "3.0" + } + ], + "cloudRegionId": "testCloudRegionIdNet2", + "inventoryType": "cloud", + "resourceModuleName": "NETWORK", + "serviceInstanceId": "", + "serviceResourceId": "testResourceIdNet2" + }, + { + "assignmentInfo": [ + { + "variableName": "cloudOwner", + "variableValue": "aic" + }, + { + "variableName": "aicClli", + "variableValue": "testAicClli3" + }, + { + "variableName": "aicVersion", + "variableValue": "3.0" + } + ], + "cloudRegionId": "testCloudRegionId3", + "inventoryType": "cloud", + "resourceModuleName": "VNF", + "serviceInstanceId": "", + "serviceResourceId": "testResourceIdVNF" + } + ] + } +}
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackInfraVnf b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackInfraVnf new file mode 100644 index 0000000000..f80ff65d04 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackInfraVnf @@ -0,0 +1,49 @@ +{ + "transactionId": "testRequestId", + "requestId": "testRequestId", + "requestState": "complete", + "statusMessage": "", + "solutionInfo": { + "placement": [ + { + "serviceResourceId": "test-resource-id-000", + "resourceModuleName": "ADIOD vRouter vCE", + "inventoryType": "service", + "serviceInstanceId": "service-instance-01234", + "cloudRegionId": "mtmnj1a", + "assignmentInfo": [ + { + "variableName": "cloudOwner", + "variableValue": "att-aic" + }, + { + "variableName": "vnfHostName", + "variableValue": "MDTNJ01" + }, + { + "variableName": "aicClli", + "variableValue": "KDTNJ01" + }, + { + "variableName": "aicVersion", + "variableValue": "3.0" + } + ] + } + ], + "licenseInfo": [ + { + "serviceResourceId": "test-resource-id-000", + "resourceModuleName": "ADIOD vRouter vCE", + "entitlementPoolList": [ + "f1d563e8-e714-4393-8f99-cc480144a05e", + "j1d563e8-e714-4393-8f99-cc480144a05e" + ], + "licenseKeyGroupList": [ + "s1d563e8-e714-4393-8f99-cc480144a05e", + "b1d563e8-e714-4393-8f99-cc480144a05e" + ] + } + ] + } +}
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackNoSolutionFound b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackNoSolutionFound new file mode 100644 index 0000000000..5cb748ae9d --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackNoSolutionFound @@ -0,0 +1,15 @@ +{ + "requestState": "", + "responseTime": "", + "solutionInfo": { + "placement": [], + "licenseInfo": { + "featureGroupId": "" + } + }, + "percentProgress": "", + "requestId": "02c2e322-5839-4c97-9d46-0a5fa6bb642e", + "startTime": "", + "statusMessage": "No solution found for plan 08e1b8cf-144a-4bac-b293-d5e2eedc97e8", + "requestType": "" +}
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackPolicyException b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackPolicyException new file mode 100644 index 0000000000..b82688428e --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackPolicyException @@ -0,0 +1,9 @@ +{ + "requestError": { + "policyException": { + "requestId": "ae81d9a8-c949-493a-999c-f76c80503233", + "text": "Message content size exceeds the allowable limit", + "messageId": "SVC0001" + } + } +}
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackServiceException b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackServiceException new file mode 100644 index 0000000000..6cc78a7cdb --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackServiceException @@ -0,0 +1,12 @@ +{ + "requestError": { + "serviceException": { + "variables": [ + "severity", 400 + ], + "requestId": "ae81d9a8-c949-493a-999c-f76c80503233", + "text": "SNIROPlacementError: requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http://135.21.171.200:8091/v1/plans/97b4e303-5f75-492c-8fb2-21098281c8b8", + "messageId": "SVC0001" + } + } +}
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroRequest_infravnf b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroRequest_infravnf new file mode 100644 index 0000000000..2af6bf3423 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroRequest_infravnf @@ -0,0 +1,65 @@ +{ + "requestInfo": { + "transactionId": "testRequestId", + "requestId": "testRequestId", + "callbackUrl": "http://localhost:8090/workflows/messages/message/SNIROResponse/testRequestId", + "sourceId": "mso", + "optimizer": [ + "placement", + "license" + ], + "numSolutions": 1, + "timeout": 600 + }, + "placementInfo": { + "serviceModelInfo": { + "modelType": "", + "modelInvariantId": "1cc4e2e4-eb6e-404d-a66f-c8733cedcce8", + "modelVersionId": "2f7f309d-c842-4644-a2e4-34167be5eeb4", + "modelName": "ADIOD vRouter vCE 011017 Service", + "modelVersion": "5.0" + }, + "subscriberInfo": { + "globalSubscriberId": "SUB12_0322_DS_1201", + "subscriberName": "SUB_12_0322_DS_1201", + "subscriberCommonSiteId": "" + }, + "demandInfo": { + "placementDemand": [ + { + "resourceInstanceType": "VNF", + "serviceResourceId": "test-resource-id-000", + "resourceModuleName": "ADIoD vCE 0", + "resourceModelInfo": { + "modelCustomizationId": "bdaeed40-c964-4966-bdb8-51320dcaf587", + "modelInvariantId": "fc72435b-4366-4257-a2f7-c70a3a998a7b", + "modelName": "ADIoD vCE", + "modelVersion": "2.0", + "modelVersionId": "ec2bd873-5b2c-47e4-8858-f0495fa1dae1", + "modelType": "" + }, + "tenantId": "", + "tenantName": "" + } + ], + "licenseDemand": [ + { + "resourceInstanceType": "VNF", + "serviceResourceId": "test-resource-id-000", + "resourceModuleName": "ADIoD vCE 0", + "resourceModelInfo": { + "modelCustomizationId": "bdaeed40-c964-4966-bdb8-51320dcaf587", + "modelInvariantId": "fc72435b-4366-4257-a2f7-c70a3a998a7b", + "modelName": "ADIoD vCE", + "modelVersion": "2.0", + "modelVersionId": "ec2bd873-5b2c-47e4-8858-f0495fa1dae1", + "modelType": "" + } + } + ] + }, + "policyId": [], + "serviceInstanceId": "ff5256d2-5a33-55df-13ab-12abad84e7ff", + "orderInfo": "{\"requestParameters\": null}" + } + }
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/mso.bpmn.urn.properties b/bpmn/MSOCommonBPMN/src/test/resources/mso.bpmn.urn.properties index c764c7f04e..9829ddaf50 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/mso.bpmn.urn.properties +++ b/bpmn/MSOCommonBPMN/src/test/resources/mso.bpmn.urn.properties @@ -113,3 +113,11 @@ policyClientAuth=Basic bTAzNzQzOnBvbGljeVIwY2sk policyAuth=Basic dGVzdHBkcDphbHBoYTEyMw==
policyEnvironment=TEST
policyEndpoint=localhost:8080/pdp/api/getDecision
+
+mso.sniro.auth=test:testpwd
+mso.sniro.endpoint=http://localhost:28090/optimizationInstance/V1/create
+mso.sniro.callback=http://localhost:28090/adapters/rest/SDNCNotify/SNIROResponse
+mso.sniro.timeout=PT30M
+mso.service.agnostic.sniro.host=http://localhost:28090
+mso.service.agnostic.sniro.endpoint=/sniro/api/v2/placement
+mso.adapters.workflow.message.endpoint=http://localhost:8090/workflows/messages/message
|