From 902ec7ef30248c03096cf03da47e6bcca4372525 Mon Sep 17 00:00:00 2001 From: Arthur Martella Date: Thu, 21 Sep 2017 16:09:46 -0400 Subject: 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 --- .../mso/bpmn/common/scripts/Homing.groovy | 259 ++++++++++++ .../common/scripts/ReceiveWorkflowMessage.groovy | 109 +++++ .../mso/bpmn/common/scripts/SNIROUtils.groovy | 262 ++++++++++++ .../resources/subprocess/BuildingBlock/Homing.bpmn | 259 ++++++++++++ .../subprocess/ReceiveWorkflowMessage.bpmn | 184 +++++++++ .../org/openecomp/mso/bpmn/common/HomingTest.java | 457 +++++++++++++++++++++ .../bpmn/common/ReceiveWorkflowMessageTest.java | 122 ++++++ .../__files/BuildingBlocks/catalogResp.json | 46 +++ .../__files/BuildingBlocks/sniroCallback2AR1Vnf | 107 +++++ .../BuildingBlocks/sniroCallback2AR1Vnf2Net | 165 ++++++++ .../__files/BuildingBlocks/sniroCallbackInfraVnf | 49 +++ .../BuildingBlocks/sniroCallbackNoSolutionFound | 15 + .../BuildingBlocks/sniroCallbackPolicyException | 9 + .../BuildingBlocks/sniroCallbackServiceException | 12 + .../__files/BuildingBlocks/sniroRequest_infravnf | 65 +++ .../src/test/resources/mso.bpmn.urn.properties | 8 + .../openecomp/mso/bpmn/mock/StubResponseSNIRO.java | 51 +++ 17 files changed, 2179 insertions(+) create mode 100755 bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/Homing.groovy create mode 100644 bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/ReceiveWorkflowMessage.groovy create mode 100644 bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/SNIROUtils.groovy create mode 100644 bpmn/MSOCommonBPMN/src/main/resources/subprocess/BuildingBlock/Homing.bpmn create mode 100644 bpmn/MSOCommonBPMN/src/main/resources/subprocess/ReceiveWorkflowMessage.bpmn create mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/HomingTest.java create mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/ReceiveWorkflowMessageTest.java create mode 100644 bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/catalogResp.json create mode 100644 bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallback2AR1Vnf create mode 100644 bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallback2AR1Vnf2Net create mode 100644 bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackInfraVnf create mode 100644 bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackNoSolutionFound create mode 100644 bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackPolicyException create mode 100644 bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroCallbackServiceException create mode 100644 bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/sniroRequest_infravnf create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseSNIRO.java (limited to 'bpmn') 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 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 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 entitlementPoolList = jsonUtil.StringArrayToList(execution, jsonEntitlementPoolList) + resource.getHomingSolution().setEntitlementPoolList(entitlementPoolList) + + String jsonLicenseKeyGroupList = jsonUtil.getJsonValue(license.toString(), "licenseKeyGroupList") + List 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 resourceList = decomposition.getServiceAllottedResources() + List 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 @@ + + + + + SequenceFlow_1x9usa6 + + + SequenceFlow_1x9usa6 + SequenceFlow_10x3ocp + + + + + + SequenceFlow_1rf4vs8 + + + + SequenceFlow_00nlh7l + + + + SequenceFlow_00nlh7l + SequenceFlow_1rf4vs8 + + + + + + + + SequenceFlow_0kamg53 + SequenceFlow_1o7154s + + + + SequenceFlow_0kamg53 + + + + SequenceFlow_1o7154s + + + + + + + SequenceFlow_043r3j8 + SequenceFlow_1h9opg9 + + + + SequenceFlow_10x3ocp + badResponse + goodResponse + + + + badResponse + SequenceFlow_0clfkld + + + + + + SequenceFlow_0clfkld + + + + + + + + + + + + + + + + goodResponse + SequenceFlow_043r3j8 + + + + SequenceFlow_1h9opg9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 @@ + + + + + SequenceFlow_9 + SequenceFlow_1ps0nzi + + + + SequenceFlow_9 + + + + SequenceFlow_27 + SequenceFlow_34 + + + + + SequenceFlow_34 + + + + SequenceFlow_44 + SequenceFlow_1 + + + + + SequenceFlow_1 + + + SequenceFlow_27 + + ${RCVWFMSG_timeout} + + + + + SequenceFlow_1ps0nzi + SequenceFlow_44 + + SequenceFlow_25 + + + + SequenceFlow_41 + + + SequenceFlow_25 + SequenceFlow_41 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 arList = new ArrayList(); + 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 vnfList = new ArrayList(); + 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 variables = new HashMap(); + 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 variables = new HashMap(); + 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 vars = new HashMap(); + 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 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 variables = new HashMap(); + 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 variables = new HashMap(); + 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 variables = new HashMap(); + 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 variables = new HashMap(); + 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 variables = new HashMap(); + 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 variables = new HashMap(); + 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 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 variables) { + List netList = new ArrayList(); + 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 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 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 variables = new HashMap(); + 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 variables = new HashMap(); + 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 diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseSNIRO.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseSNIRO.java new file mode 100644 index 0000000000..a8152d6b67 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseSNIRO.java @@ -0,0 +1,51 @@ +/* + * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +package org.openecomp.mso.bpmn.mock; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; + +/** + * Please describe the StubResponseSNIRO.java class + * + * @author cb645j + */ +public class StubResponseSNIRO { + + public static void setupAllMocks() { + + } + + public static void mockSNIRO() { + stubFor(post(urlEqualTo("/sniro/api/v2/placement")) + .willReturn(aResponse() + .withStatus(202) + .withHeader("Content-Type", "application/json"))); + } + + public static void mockSNIRO(String responseFile) { + stubFor(post(urlEqualTo("/sniro/api/v2/placement")) + .willReturn(aResponse() + .withStatus(202) + .withHeader("Content-Type", "application/json") + .withBodyFile(responseFile))); + } + + public static void mockSNIRO_400() { + stubFor(post(urlEqualTo("/sniro/api/v2/placement")) + .willReturn(aResponse() + .withStatus(400) + .withHeader("Content-Type", "application/json"))); + } + + public static void mockSNIRO_500() { + stubFor(post(urlEqualTo("/sniro/api/v2/placement")) + .willReturn(aResponse() + .withStatus(500) + .withHeader("Content-Type", "application/json"))); + } + +} -- cgit 1.2.3-korg