diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN')
19 files changed, 373 insertions, 142 deletions
diff --git a/bpmn/MSOCommonBPMN/pom.xml b/bpmn/MSOCommonBPMN/pom.xml index 83714ed022..456b8ae074 100644 --- a/bpmn/MSOCommonBPMN/pom.xml +++ b/bpmn/MSOCommonBPMN/pom.xml @@ -207,10 +207,6 @@ </dependencyManagement> <dependencies> <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - </dependency> - <dependency> <groupId>org.camunda.bpm</groupId> <artifactId>camunda-engine</artifactId> </dependency> diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy index cae80e9137..3e451a5a4a 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy @@ -25,7 +25,7 @@ import org.onap.so.bpmn.core.UrnPropertiesReader; import org.onap.so.rest.APIResponse; import org.onap.so.rest.RESTClient import org.onap.so.rest.RESTConfig -import org.onap.so.logger.MessageEnum +import org.springframework.web.util.UriUtils import org.onap.so.logger.MsoLogger class AaiUtil { @@ -43,6 +43,8 @@ class AaiUtil { public AaiUtil(AbstractServiceTaskProcessor taskProcessor) { this.taskProcessor = taskProcessor } + public AaiUtil() { + } public String getNetworkGenericVnfEndpoint(DelegateExecution execution) { String endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution) @@ -87,6 +89,12 @@ class AaiUtil { return uri } + public String getNetworkDeviceUri(DelegateExecution execution) { + def uri = getUri(execution, 'device') + msoLogger.debug('AaiUtil.getNetworkDeviceUri() - AAI URI: ' + uri) + return uri + } + public String getBusinessCustomerUri(DelegateExecution execution) { def uri = getUri(execution, 'customer') msoLogger.debug('AaiUtil.getBusinessCustomerUri() - AAI URI: ' + uri) @@ -109,7 +117,7 @@ class AaiUtil { } //public String getBusinessCustomerUriv7(DelegateExecution execution) { - // // //def uri = getUri(execution, BUSINESS_CUSTOMERV7) + // //def uri = getUri(execution, BUSINESS_CUSTOMERV7) // def uri = getUri(execution, 'Customer') // msoLogger.debug('AaiUtil.getBusinessCustomerUriv7() - AAI URI: ' + uri) // return uri @@ -178,9 +186,30 @@ class AaiUtil { (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, "Internal Error: One of the following should be defined in MSO URN properties file: ${versionWithResourceKey}, ${versionWithProcessKey}, ${DEFAULT_VERSION_KEY}") } + public String getMainProcessKey(DelegateExecution execution) { + DelegateExecution exec = execution + + while (true) { + DelegateExecution parent = exec.getSuperExecution() + + if (parent == null) { + parent = exec.getParent() + + if (parent == null) { + break + } + } + + exec = parent + } + + return execution.getProcessEngineServices().getRepositoryService() + .getProcessDefinition(exec.getProcessDefinitionId()).getKey() + } + public String getUri(DelegateExecution execution, resourceName) { - def processKey = taskProcessor.getMainProcessKey(execution) + def processKey = getMainProcessKey(execution) //set namespace setNamespace(execution) @@ -656,9 +685,9 @@ class AaiUtil { private def getPInterface(DelegateExecution execution, String aai_uri) { - String namespace = getNamespaceFromUri(aai_uri) + String namespace = getNamespaceFromUri(execution, aai_uri) String aai_endpoint = execution.getVariable("URN_aai_endpoint") - String serviceAaiPath = ${aai_endpoint}${aai_uri} + String serviceAaiPath = aai_endpoint + aai_uri APIResponse response = executeAAIGetCall(execution, serviceAaiPath) return new XmlParser().parseText(response.getResponseBodyAsString()) @@ -680,58 +709,102 @@ class AaiUtil { String aai_uri = '/aai/v14/network/logical-links' String aai_endpoint = execution.getVariable("URN_aai_endpoint") - String serviceAaiPath = ${aai_endpoint}${aai_uri} + String serviceAaiPath = aai_endpoint + aai_uri APIResponse response = executeAAIGetCall(execution, serviceAaiPath) def logicalLinks = new XmlParser().parseText(response.getResponseBodyAsString()) - logicalLinks."logical-links".find { link -> - def pInterface = [] + logicalLinks."logical-link".each { link -> + def isRemoteLink = false + def pInterfaces = [] def relationship = link."relationship-list"."relationship" - relationship.each { - if ("p-interface".compareToIgnoreCase(it."related-to")) { - pInterface.add(it) + relationship.each { rel -> + if ("ext-aai-network".compareToIgnoreCase("${rel."related-to"[0]?.text()}") == 0) { + isRemoteLink = true + } + if ("p-interface".compareToIgnoreCase("${rel."related-to"[0]?.text()}") == 0) { + pInterfaces.add(rel) } } - if (pInterface.size() == 2) { + + // if remote link then process + if (isRemoteLink) { + + // find remote p interface def localTP = null def remoteTP = null - if (pInterface[0]."related-link".contains("ext-aai-networks")) { - remoteTP = pInterface[0] - localTP = pInterface[1] - } + def pInterface0 = pInterfaces[0] + def pIntfUrl = "${pInterface0."related-link"[0].text()}" - if (pInterface[1]."related-link".contains("ext-aai-networks")) { - localTP = pInterface[0] - remoteTP = pInterface[1] + if (isRemotePInterface(execution, pIntfUrl)) { + remoteTP = pInterfaces[0] + localTP = pInterfaces[1] + } else { + localTP = pInterfaces[0] + remoteTP = pInterfaces[1] } if (localTP != null && remoteTP != null) { // give local tp - var intfLocal = getPInterface(execution, localTP."related-link") - tpInfotpInfo.put("local-access-node-id", localTP."related-link".split("/")[6]) + def tpUrl = "${localTP."related-link"[0]?.text()}" + def intfLocal = getPInterface(execution, "${localTP?."related-link"[0]?.text()}") + tpInfo.put("local-access-node-id", tpUrl.split("/")[6]) - def networkRef = intfLocal."network-ref".split("/") - tpInfo.put("local-access-provider-id", networkRef[1]) - tpInfo.put("local-access-client-id", networkRef[3]) - tpInfo.put("local-access-topology-id", networkRef[5]) - tpInfo.put("local-access-ltp-id", localTP."interface-name") + def networkRef = "${intfLocal."network-ref"[0]?.text()}".split("/") + if (networkRef.size() == 6) { + tpInfo.put("local-access-provider-id", networkRef[1]) + tpInfo.put("local-access-client-id", networkRef[3]) + tpInfo.put("local-access-topology-id", networkRef[5]) + } + def ltpIdStr = tpUrl?.substring(tpUrl?.lastIndexOf("/") + 1) + if (ltpIdStr?.contains("-")) { + tpInfo.put("local-access-ltp-id", ltpIdStr?.substring(ltpIdStr?.lastIndexOf("-") + 1)) + } - // give local tp - var intfRemote = getPInterface(execution, remoteTP."related-link") - tpInfo.put("remote-access-node-id", remoteTP."related-link".split("/")[6]) - def networkRefRemote = intfRemote."network-ref".split("/") - tpInfo.put("remote-access-provider-id", networkRefRemote[1]) - tpInfo.put("remote-access-client-id", networkRefRemote[3]) - tpInfo.put("remote-access-topology-id", networkRefRemote[5]) - tpInfo.put("remote-access-ltp-id", remoteTP."interface-name") + // give remote tp + tpUrl = "${remoteTP."related-link"[0]?.text()}" + def intfRemote = getPInterface(execution, "${remoteTP."related-link"[0].text()}") + tpInfo.put("remote-access-node-id", tpUrl.split("/")[6]) + + def networkRefRemote = "${intfRemote."network-ref"[0]?.text()}".split("/") + + if (networkRefRemote.size() == 6) { + tpInfo.put("remote-access-provider-id", networkRefRemote[1]) + tpInfo.put("remote-access-client-id", networkRefRemote[3]) + tpInfo.put("remote-access-topology-id", networkRefRemote[5]) + } + def ltpIdStrR = tpUrl?.substring(tpUrl?.lastIndexOf("/") + 1) + if (ltpIdStrR?.contains("-")) { + tpInfo.put("remote-access-ltp-id", ltpIdStrR?.substring(ltpIdStr?.lastIndexOf("-") + 1)) + } + return tpInfo } } } return tpInfo } + + // this method check if pInterface is remote + private def isRemotePInterface(DelegateExecution execution, String uri) { + def aai_uri = uri.substring(0, uri.indexOf("/p-interfaces")) + + String namespace = getNamespaceFromUri(execution, aai_uri) + String aai_endpoint = execution.getVariable("URN_aai_endpoint") + String serviceAaiPath = aai_endpoint + aai_uri + + APIResponse response = executeAAIGetCall(execution, serviceAaiPath) + def pnf = new XmlParser().parseText(response.getResponseBodyAsString()) + + def relationship = pnf."relationship-list"."relationship" + relationship.each { + if ("ext-aai-network".compareToIgnoreCase("${it."related-to"[0]?.text()}") == 0) { + return true + } + } + return false + } }
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessor.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessor.groovy index 1e2a703e70..0692e5022a 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessor.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessor.groovy @@ -755,8 +755,6 @@ public abstract class AbstractServiceTaskProcessor implements ServiceTaskProcess public void setBasicDBAuthHeader(DelegateExecution execution, isDebugLogEnabled) { try { String basicAuthValueDB = UrnPropertiesReader.getVariable("mso.adapters.db.auth", execution) - utils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB, isDebugLogEnabled) - def encodedString = utils.getBasicAuth(basicAuthValueDB, UrnPropertiesReader.getVariable("mso.msoKey", execution)) execution.setVariable("BasicAuthHeaderValueDB",encodedString) } catch (IOException ex) { diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupName.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupName.groovy index 8b786bc152..bcd740eae9 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupName.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupName.groovy @@ -43,7 +43,6 @@ public class ConfirmVolumeGroupName extends AbstractServiceTaskProcessor{ execution.setVariable("CVGN_queryVolumeGroupResponseCode",null) execution.setVariable("CVGN_queryVolumeGroupResponse","") execution.setVariable("CVGN_ResponseCode",null) -// execution.setVariable("CVGN_ErrorResponse","") execution.setVariable("RollbackData", null) } @@ -125,10 +124,6 @@ public class ConfirmVolumeGroupName extends AbstractServiceTaskProcessor{ // generates a WorkflowException if the A&AI query returns a response code other than 200/404 public void handleAAIQueryFailure(DelegateExecution execution) { msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Error occurred attempting to query AAI, Response Code " + execution.getVariable("CVGN_queryVolumeGroupResponseCode"), "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "ErrorResponse is:\n" + execution.getVariable("CVGN_queryVolumeGroupResponse")); - //String processKey = getProcessKey(execution); - //WorkflowException exception = new WorkflowException(processKey, 5000, - //execution.getVariable("CVGN_queryVolumeGroupResponse")) - //execution.setVariable("WorkflowException", exception) } // generates a WorkflowException if the volume group name does not match AAI record for this volume group @@ -137,16 +132,6 @@ public class ConfirmVolumeGroupName extends AbstractServiceTaskProcessor{ " is not associated with " + execution.getVariable("CVGN_volumeGroupName") msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, errorNotAssociated, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, ""); exceptionUtil.buildAndThrowWorkflowException(execution, 1002, errorNotAssociated) - //String processKey = getProcessKey(execution); - //WorkflowException exception = new WorkflowException(processKey, 1002, - // errorNotAssociated) - //execution.setVariable("WorkflowException", exception) } - // sends a successful WorkflowResponse - public void reportSuccess(DelegateExecution execution) { - msoLogger.debug("Sending 200 back to the caller") - def responseXML = "" - execution.setVariable("WorkflowResponse", responseXML) - } }
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy index 2c2cd8269c..7d4adaea58 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy @@ -37,9 +37,9 @@ class ExternalAPIUtil { public MsoUtils utils = new MsoUtils() ExceptionUtil exceptionUtil = new ExceptionUtil() - + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ExternalAPIUtil.class) - + public static final String PostServiceOrderRequestsTemplate = "{\n" + "\t\"externalId\": <externalId>,\n" + @@ -83,6 +83,8 @@ class ExternalAPIUtil { "\t} \n" + "}" + public ExternalAPIUtil() { + } // public String getUri(DelegateExecution execution, resourceName) { // diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy index 35e68bb79f..70f91671a8 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy @@ -24,8 +24,7 @@ import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.bpmn.common.scripts.AaiUtil import org.onap.so.bpmn.common.scripts.ExceptionUtil -import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils -import org.onap.so.bpmn.core.domain.CloudFlavor + import org.onap.so.bpmn.core.domain.InventoryType import org.onap.so.bpmn.core.domain.Resource import org.onap.so.bpmn.core.domain.ResourceType @@ -33,7 +32,8 @@ import org.onap.so.bpmn.core.domain.ServiceDecomposition import org.onap.so.bpmn.core.domain.Subscriber import org.onap.so.bpmn.core.domain.VnfResource import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.logger.MsoLogger +import org.onap.so.db.catalog.beans.CloudIdentity +import org.onap.so.db.catalog.beans.CloudSite import org.onap.so.rest.APIResponse import org.onap.so.rest.RESTClient import org.onap.so.rest.RESTConfig @@ -52,7 +52,6 @@ import static org.onap.so.bpmn.common.scripts.GenericUtils.* */ class OofHoming extends AbstractServiceTaskProcessor { - private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, OofHoming.class); ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() OofUtils oofUtils = new OofUtils(this) @@ -114,10 +113,7 @@ class OofHoming extends AbstractServiceTaskProcessor { def authHeader = "" String basicAuth = UrnPropertiesReader.getVariable("mso.oof.auth", execution) String msokey = UrnPropertiesReader.getVariable("mso.msoKey", execution) - - - String basicAuthValue = utils.encrypt(basicAuth, msokey) if (basicAuthValue != null) { utils.log("DEBUG", "Obtained BasicAuth username and password for OOF Adapter: " + basicAuthValue, @@ -156,8 +152,8 @@ class OofHoming extends AbstractServiceTaskProcessor { execution.setVariable("oofRequest", oofRequest) utils.log("DEBUG", "OOF Request is: " + oofRequest, isDebugEnabled) - String endpoint = UrnPropertiesReader.getVariable("mso.oof.service.agnostic.endpoint", execution); - String host = UrnPropertiesReader.getVariable("mso.oof.service.agnostic.host", execution); + String endpoint = UrnPropertiesReader.getVariable("mso.oof.service.agnostic.endpoint", execution) + String host = UrnPropertiesReader.getVariable("mso.oof.service.agnostic.host", execution) String url = host + endpoint utils.log("DEBUG", "Posting to OOF Url: " + url, isDebugEnabled) @@ -240,30 +236,12 @@ class OofHoming extends AbstractServiceTaskProcessor { } resource.getHomingSolution().setInventoryType(InventoryType.valueOf(inventoryType)) - // TODO Deal with Placement Solutions & Assignment Info here JSONArray assignmentArr = placement.getJSONArray("assignmentInfo") - Integer arrayIndex = 0 - Integer flavorsIndex = null - Boolean foundFlavors = false - String flavors = null - Map<String, String> flavorsMap = null - ArrayList<CloudFlavor> flavorsArrayList = new ArrayList<CloudFlavor>() + String oofDirectives = null assignmentArr.each { element -> JSONObject jsonObject = new JSONObject(element.toString()) - if (jsonUtil.getJsonRawValue(jsonObject.toString(), "key") == "flavors") { - flavors = jsonUtil.getJsonRawValue(jsonObject.toString(), "value") - foundFlavors = true - flavorsIndex = arrayIndex - } else { - arrayIndex += 1 - } - } - if (foundFlavors) { - assignmentArr.remove(flavorsIndex) - flavorsMap = jsonUtil.jsonStringToMap(execution, flavors.toString()) - flavorsMap.each { label, flavor -> - CloudFlavor cloudFlavor = new CloudFlavor(label, flavor) - flavorsArrayList.add(cloudFlavor) + if (jsonUtil.getJsonRawValue(jsonObject.toString(), "key") == "oof_directives") { + oofDirectives = jsonUtil.getJsonRawValue(jsonObject.toString(), "value") } } Map<String, String> assignmentMap = jsonUtil.entryArrayToMap(execution, @@ -272,10 +250,26 @@ class OofHoming extends AbstractServiceTaskProcessor { String cloudRegionId = assignmentMap.get("locationId") resource.getHomingSolution().setCloudOwner(cloudOwner) resource.getHomingSolution().setCloudRegionId(cloudRegionId) - if (flavorsArrayList != null && flavorsArrayList.size != 0) { - resource.getHomingSolution().setFlavors(flavorsArrayList) - execution.setVariable(cloudRegionId + "_flavorList", flavorsArrayList) - utils.log("DEBUG", "***** _flavorList is: " + flavorsArrayList.toString() + + + CloudSite cloudSite = new CloudSite(); + cloudSite.setId(cloudRegionId) + cloudSite.setRegionId(cloudRegionId) + String orchestrator = execution.getVariable("orchestrator") + if ((orchestrator != null) || (orchestrator != "")) { + cloudSite.setOrchestrator(orchestrator) + } + + CloudIdentity cloudIdentity = new CloudIdentity(); + cloudIdentity.setId(cloudRegionId); + cloudIdentity.setIdentityUrl("/api/multicloud /v1/" + cloudOwner + "/" + cloudRegionId + "/infra_workload") + cloudSite.setIdentityService(cloudIdentity); + + // Set cloudsite in catalog DB here + oofUtils.createCloudSiteCatalogDb(cloudSite) + + if (oofDirectives != null && oofDirectives != "") { + resource.getHomingSolution().setOofDirectives(oofDirectives) + utils.log("DEBUG", "***** OofDirectives is: " + oofDirectives + " *****", "true") } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy index 8ce633845b..d95795906f 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy @@ -23,7 +23,7 @@ package org.onap.so.bpmn.common.scripts import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil -import org.onap.so.bpmn.common.scripts.MsoUtils +import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.domain.HomingSolution import org.onap.so.bpmn.core.domain.ModelInfo import org.onap.so.bpmn.core.domain.Resource @@ -33,22 +33,32 @@ import org.onap.so.bpmn.core.domain.ServiceInstance import org.onap.so.bpmn.core.domain.Subscriber import org.onap.so.bpmn.core.domain.VnfResource import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.logger.MsoLogger - -import java.lang.reflect.Array +import org.onap.so.db.catalog.beans.CloudSite +import org.onap.so.rest.APIResponse +import org.onap.so.rest.RESTClient +import org.onap.so.rest.RESTConfig +import org.springframework.http.HttpEntity +import org.springframework.http.HttpHeaders +import org.springframework.http.HttpMethod +import org.springframework.http.ResponseEntity +import org.springframework.http.client.BufferingClientHttpRequestFactory +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory +import org.springframework.web.client.RestTemplate +import org.springframework.web.util.UriComponentsBuilder + +import javax.ws.rs.core.MediaType +import javax.ws.rs.core.Response +import javax.xml.ws.http.HTTPException import static org.onap.so.bpmn.common.scripts.GenericUtils.* class OofUtils { - private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, OofUtils.class); ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() private AbstractServiceTaskProcessor utils - public MsoUtils msoUtils = new MsoUtils() - - public OofUtils(AbstractServiceTaskProcessor taskProcessor) { + OofUtils(AbstractServiceTaskProcessor taskProcessor) { this.utils = taskProcessor } @@ -466,4 +476,39 @@ class OofUtils { if (candidatesJson != "") {candidatesJson = candidatesJson.substring(0, candidatesJson.length() - 1)} return candidatesJson } + /** + * This method creates a cloudsite in catalog database. + * + * @param CloudSite cloudSite + * + * @return void + */ + Void createCloudSiteCatalogDb(CloudSite cloudSite, DelegateExecution execution) { + + String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution) + String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution) + String uri = "/cloudSite" + + HttpHeaders headers = new HttpHeaders() + + headers.set(HttpHeaders.AUTHORIZATION, auth) + headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON) + headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(endpoint + uri) + HttpEntity<CloudSite> request = new HttpEntity<CloudSite>(cloudSite, headers) + RESTConfig config = new RESTConfig(endpoint + uri) + RESTClient client = new RESTClient(config).addAuthorizationHeader(auth). + addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + APIResponse response = client.httpPost(request.getBody().toString()) + + int responseCode = response.getStatusCode() + logDebug("CatalogDB response code is: " + responseCode, isDebugEnabled) + String syncResponse = response.getResponseBodyAsString() + logDebug("CatalogDB response is: " + syncResponse, isDebugEnabled) + + if(responseCode != 202){ + exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from CatalogDB.") + } + } } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SniroUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SniroUtils.groovy index 9b144323c0..5ff49fbae8 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SniroUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SniroUtils.groovy @@ -322,7 +322,6 @@ class SniroUtils{ } if((isBlank(placements) || placements.equalsIgnoreCase("[]")) && (isBlank(licenses) || licenses.equalsIgnoreCase("[]"))){ msoLogger.debug("Sniro Async Response does not contain: licenses or placements") - exceptionUtil.buildAndThrowWorkflowException(execution, 400, "Sniro Async Callback Response does not contain: licenses or placements") }else{ return } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/baseclient/BaseClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/baseclient/BaseClient.java index c3511e69a4..78f3e96978 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/baseclient/BaseClient.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/baseclient/BaseClient.java @@ -20,13 +20,14 @@ package org.onap.so.bpmn.common.baseclient; +import org.onap.so.logging.jaxrs.filter.SpringClientFilter; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.http.client.BufferingClientHttpRequestFactory; -import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; @@ -59,11 +60,12 @@ public class BaseClient<I,O> { public O post(I data, ParameterizedTypeReference<O> typeRef, Object... uriVariables) throws RestClientException { return run(data, HttpMethod.POST, typeRef, uriVariables); } - + public O run(I data, HttpMethod method, ParameterizedTypeReference<O> typeRef, Object... uriVariables) throws RestClientException { HttpEntity<I> requestEntity = new HttpEntity<I>(data, getHttpHeader()); RestTemplate restTemplate = new RestTemplate(); - restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())); + restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory())); + restTemplate.getInterceptors().add(new SpringClientFilter()); ResponseEntity<O> responseEntity = restTemplate.exchange(getTargetUrl(), method, requestEntity, typeRef, uriVariables); return responseEntity.getBody(); diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java index bb2ad9507f..35bd25fabf 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java @@ -191,7 +191,9 @@ public class ResourceRequestBuilder { HashMap<String, String> map = new Gson().fromJson(value, new TypeToken<HashMap<String, String>>() {}.getType()); - File csarFile = new File(System.getProperty("mso.config.path") + "ASDC/" + map.get("name")); + String filePath = System.getProperty("mso.config.path") + "ASDC/" + map.get("version") + "/" + map.get("name"); + + File csarFile = new File(filePath); if(!csarFile.exists()) { throw new Exception("csar file does not exist."); diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/generalobjects/RequestParameters.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/generalobjects/RequestParameters.java index 24c0548641..5e49ffcf40 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/generalobjects/RequestParameters.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/generalobjects/RequestParameters.java @@ -47,7 +47,8 @@ public class RequestParameters implements Serializable { private List<Map<String, Object>> userParams = new ArrayList<>(); @JsonProperty("aLaCarte") private Boolean aLaCarte; - + @JsonProperty("payload") + private String payload; public String getSubscriptionServiceType() { return subscriptionServiceType; @@ -68,6 +69,13 @@ public class RequestParameters implements Serializable { public Boolean isaLaCarte() { return aLaCarte; } + + public String getPayload(){ + return payload; + } + public void setPayload(String value){ + this.payload = value; + } public List<Map<String, Object>> getUserParams() { return userParams; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index 6d5fb2f825..eb4f4ca0d5 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -190,14 +190,19 @@ public class BBInputSetup implements JavaDelegate { if(requestDetails == null) { requestDetails = bbInputSetupUtils.getRequestDetails(requestId); } - ModelType modelType = requestDetails.getModelInfo().getModelType(); - if (aLaCarte && modelType.equals(ModelType.service)) { - return this.getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId); - } else if (aLaCarte && !modelType.equals(ModelType.service)) { - return this.getGBBALaCarteNonService(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, - vnfType); - } else { - return this.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); + if (requestDetails.getModelInfo() == null) { + return this.getGBBCM(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId); + } + else { + ModelType modelType = requestDetails.getModelInfo().getModelType(); + if (aLaCarte && modelType.equals(ModelType.service)) { + return this.getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId); + } else if (aLaCarte && !modelType.equals(ModelType.service)) { + return this.getGBBALaCarteNonService(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, + vnfType); + } else { + return this.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); + } } } @@ -236,6 +241,25 @@ public class BBInputSetup implements JavaDelegate { throw new Exception("Could not find relevant information for related Service Instance"); } } + + protected GeneralBuildingBlock getGBBCM(ExecuteBuildingBlock executeBB, + RequestDetails requestDetails, Map<ResourceKey, String> lookupKeyMap, String requestAction, + String resourceId) throws Exception { + ServiceInstance serviceInstance = new ServiceInstance(); + String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID); + serviceInstance.setServiceInstanceId(serviceInstanceId); + + List<GenericVnf> genericVnfs = serviceInstance.getVnfs(); + + String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID); + org.onap.aai.domain.yang.GenericVnf aaiGenericVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId); + + GenericVnf genericVnf = this.mapperLayer.mapAAIGenericVnfIntoGenericVnf(aaiGenericVnf); + genericVnfs.add(genericVnf); + + return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, new Customer()); + + } protected void populateObjectsOnAssignAndCreateFlows(RequestDetails requestDetails, Service service, String bbName, ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId, String vnfType) @@ -790,7 +814,9 @@ public class BBInputSetup implements JavaDelegate { customer = mapCustomer(globalCustomerId, subscriptionServiceType); } outputBB.setServiceInstance(serviceInstance); - customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + if (customer.getServiceSubscription() != null) { + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + } outputBB.setCustomer(customer); return outputBB; } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java index 877d5bb88f..0c7eb0973f 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java @@ -341,6 +341,7 @@ public class BBInputSetupMapperLayer { requestParams.setaLaCarte(requestParameters.getALaCarte()); requestParams.setSubscriptionServiceType(requestParameters.getSubscriptionServiceType()); requestParams.setUserParams(requestParameters.getUserParams()); + requestParams.setPayload(requestParameters.getPayload()); return requestParams; } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java index c74e81506c..42da72528f 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/ExceptionBuilder.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -37,9 +37,9 @@ public class ExceptionBuilder { String msg = "Exception in %s.%s "; try{ msoLogger.error(exception); - + String errorVariable = "Error%s%s"; - + StackTraceElement[] trace = Thread.currentThread().getStackTrace(); for (StackTraceElement traceElement : trace) { if (!traceElement.getClassName().equals(this.getClass().getName()) && !traceElement.getClassName().equals(Thread.class.getName())) { @@ -49,7 +49,7 @@ public class ExceptionBuilder { break; } } - + msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, msg.toString()); execution.setVariable(errorVariable, exception.getMessage()); } catch (Exception ex){ diff --git a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/CompleteMsoProcess.bpmn b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/CompleteMsoProcess.bpmn index 67bd961844..63c867f3c7 100644 --- a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/CompleteMsoProcess.bpmn +++ b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/CompleteMsoProcess.bpmn @@ -1,5 +1,5 @@ <?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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="_EsMs0HcuEeW2U_kkOHX1ZQ" targetNamespace="http://camunda.org/schema/1.0/bpmn" exporter="Camunda Modeler" exporterVersion="1.10.0" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"> +<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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="_EsMs0HcuEeW2U_kkOHX1ZQ" targetNamespace="http://camunda.org/schema/1.0/bpmn" exporter="Camunda Modeler" exporterVersion="1.7.1" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"> <bpmn2:process id="CompleteMsoProcess" name="CompleteMsoProcess" isExecutable="true"> <bpmn2:scriptTask id="preProcessRequest" name="Pre-Process Request" scriptFormat="groovy"> <bpmn2:incoming>SequenceFlow_18</bpmn2:incoming> @@ -56,6 +56,7 @@ completeMsoProcess.setUpdateDBstatustoSuccessPayload(execution)]]></bpmn2:script <camunda:map> <camunda:entry key="content-type">application/soap+xml</camunda:entry> <camunda:entry key="Authorization">#{BasicAuthHeaderValueDB}</camunda:entry> + <camunda:entry key="X-ONAP-RequestID">#{CMSO_request_id}</camunda:entry> </camunda:map> </camunda:inputParameter> <camunda:inputParameter name="method">POST</camunda:inputParameter> @@ -88,7 +89,7 @@ buildDataErrorMessage.buildDataError(execution, "Complete MSO -- Update DB stat <bpmn2:sequenceFlow id="SequenceFlow_1" name="" sourceRef="ExclusiveGateway_7" targetRef="BuildErrorMessage" /> <bpmn2:boundaryEvent id="BoundaryEvent_7" name="" attachedToRef="updateInfraRequest"> <bpmn2:outgoing>SequenceFlow_0mipf25</bpmn2:outgoing> - <bpmn2:errorEventDefinition id="_ErrorEventDefinition_84" errorRef="Error_1" /> + <bpmn2:errorEventDefinition id="_ErrorEventDefinition_84" errorRef="Error_1" camunda:errorCodeVariable="gJavaErrorCode" camunda:errorMessageVariable="gJavaErrorMessage" /> </bpmn2:boundaryEvent> <bpmn2:endEvent id="EndEvent_1"> <bpmn2:incoming>SequenceFlow_1pzb94j</bpmn2:incoming> diff --git a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/FalloutHandler.bpmn b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/FalloutHandler.bpmn index c59564b1e3..990863ec93 100644 --- a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/FalloutHandler.bpmn +++ b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/FalloutHandler.bpmn @@ -1,5 +1,5 @@ <?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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="_3SPHsLr9EeWak-hhutJWuQ" targetNamespace="http://camunda.org/schema/1.0/bpmn" exporter="Camunda Modeler" exporterVersion="1.8.0" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"> +<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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="_3SPHsLr9EeWak-hhutJWuQ" targetNamespace="http://camunda.org/schema/1.0/bpmn" exporter="Camunda Modeler" exporterVersion="1.7.1" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"> <bpmn2:process id="FalloutHandler" name="Fallout Handler" isExecutable="true"> <bpmn2:parallelGateway id="ParallelGateway_1"> <bpmn2:incoming>SequenceFlow_12</bpmn2:incoming> @@ -139,6 +139,7 @@ falloutHandler.buildDBWorkflowException(execution, "FH_updateRequestInfraRespons <camunda:map> <camunda:entry key="content-type">application/soap+xml</camunda:entry> <camunda:entry key="Authorization">#{BasicAuthHeaderValueDB}</camunda:entry> + <camunda:entry key="X-ONAP-RequestID">#{FH_request_id}</camunda:entry> </camunda:map> </camunda:inputParameter> <camunda:inputParameter name="payload"> @@ -168,7 +169,7 @@ return updateRequestInfra.updateRequestInfraPayload(execution)]]></camunda:scrip </bpmn2:sequenceFlow> <bpmn2:boundaryEvent id="BoundaryEvent_3" name="Connect Fault" attachedToRef="ServiceTask_2"> <bpmn2:outgoing>SequenceFlow_80</bpmn2:outgoing> - <bpmn2:errorEventDefinition id="_ErrorEventDefinition_90" errorRef="Error_2" /> + <bpmn2:errorEventDefinition id="_ErrorEventDefinition_90" errorRef="Error_2" camunda:errorCodeVariable="gJavaErrorCode" camunda:errorMessageVariable="gJavaErrorMessage" /> </bpmn2:boundaryEvent> <bpmn2:sequenceFlow id="SequenceFlow_80" name="" sourceRef="BoundaryEvent_3" targetRef="ScriptTask_7" /> <bpmn2:subProcess id="SubProcess_1" name="Event Handler" triggeredByEvent="true"> diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy index 9b3b8c2fb0..e065ccd14f 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy @@ -22,28 +22,12 @@ package org.onap.so.bpmn.common.scripts import com.github.tomakehurst.wiremock.junit.WireMockRule -import static org.junit.Assert.*; import static org.mockito.Mockito.* - -import org.onap.so.rest.HttpHeader -import org.mockito.MockitoAnnotations -import org.mockito.runners.MockitoJUnitRunner -import org.mockito.internal.debugging.MockitoDebuggerImpl -import org.junit.Before -import org.onap.so.bpmn.common.scripts.AaiUtil; -import org.junit.Rule; -import org.junit.Test -import org.junit.Ignore -import org.junit.runner.RunWith -import org.junit.Before; -import org.junit.Test; import org.camunda.bpm.engine.ProcessEngineServices import org.camunda.bpm.engine.RepositoryService import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl import org.camunda.bpm.engine.repository.ProcessDefinition import org.junit.Assert -import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -51,16 +35,18 @@ import org.mockito.ArgumentCaptor import org.mockito.Captor import org.mockito.Mockito import org.mockito.runners.MockitoJUnitRunner -import org.onap.so.bpmn.common.scripts.ConfirmVolumeGroupName import org.onap.so.bpmn.core.WorkflowException import static com.github.tomakehurst.wiremock.client.WireMock.* -import static org.mockito.Mockito.* @RunWith(MockitoJUnitRunner.class) -@Ignore class ConfirmVolumeGroupNameTest extends MsoGroovyTest { + private static final def AAA_URI = "uri_test" + private static final def AIC_CLOUD_REGION = "AicClReg_test" + private static final def VOLUME_GROUP_NAME = "volumeTestGName" + private static final def VOLUME_GROUP_ID = "vol_gr_id_test" + @Captor ArgumentCaptor<ExecutionEntity> captor= ArgumentCaptor.forClass(ExecutionEntity.class); @@ -68,6 +54,60 @@ class ConfirmVolumeGroupNameTest extends MsoGroovyTest { public WireMockRule wireMockRule = new WireMockRule(8090); @Test + void preProcessRequestSuccessful() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("ConfirmVolumeGroupName_volumeGroupId")).thenReturn(VOLUME_GROUP_ID) + when(mockExecution.getVariable("ConfirmVolumeGroupName_volumeGroupName")).thenReturn(VOLUME_GROUP_NAME) + when(mockExecution.getVariable("ConfirmVolumeGroupName_aicCloudRegion")).thenReturn(AIC_CLOUD_REGION) + + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('namespace_test') + when(mockExecution.getVariable("mso.workflow.ConfirmVolumeGroupName.aai.cloud-region.uri")).thenReturn(AAA_URI) + new ConfirmVolumeGroupName().preProcessRequest(mockExecution) + + verifyInitProcessVariables(mockExecution) + verify(mockExecution).setVariable("CVGN_volumeGroupId", VOLUME_GROUP_ID) + verify(mockExecution).setVariable("CVGN_volumeGroupName", "volumeTestGName") + verify(mockExecution).setVariable("CVGN_aicCloudRegion", AIC_CLOUD_REGION) + verify(mockExecution).setVariable("CVGN_volumeGroupGetEndpoint", + "${AAA_URI}/${AIC_CLOUD_REGION}/volume-groups/volume-group/" + VOLUME_GROUP_ID) + } + + private void verifyInitProcessVariables(ExecutionEntity mockExecution) { + verify(mockExecution).setVariable("prefix", "CVGN_") + verify(mockExecution).setVariable("CVGN_volumeGroupId", null) + verify(mockExecution).setVariable("CVGN_volumeGroupName", null) + verify(mockExecution).setVariable("CVGN_aicCloudRegion", null) + verify(mockExecution).setVariable("CVGN_volumeGroupGetEndpoint", null) + verify(mockExecution).setVariable("CVGN_volumeGroupNameMatches", false) + verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponseCode", null) + verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponse", "") + verify(mockExecution).setVariable("CVGN_ResponseCode", null) + verify(mockExecution).setVariable("RollbackData", null) + } + + @Test + void checkAAIQueryResult_volumeGroupNamesMatch() { + ExecutionEntity mockExecution = setupMock() + commonPartOfCheckAAIQueryTest(mockExecution, VOLUME_GROUP_NAME) + verify(mockExecution).setVariable("CVGN_volumeGroupNameMatches", true) + } + + @Test + void checkAAIQueryResult_volumeGroupNamesDoNotMatch() { + ExecutionEntity mockExecution = setupMock() + commonPartOfCheckAAIQueryTest(mockExecution, "grName2") + verify(mockExecution, Mockito.times(0)).setVariable("CVGN_volumeGroupNameMatches", true) + } + + private void commonPartOfCheckAAIQueryTest(ExecutionEntity mockExecution, def volumeGroupName) { + when(mockExecution.getVariable("CVGN_volumeGroupName")).thenReturn(VOLUME_GROUP_NAME) + def xml = "<volume-group-name>" + volumeGroupName + "</volume-group-name>" + when(mockExecution.getVariable("CVGN_queryVolumeGroupResponse")).thenReturn(xml) + new ConfirmVolumeGroupName().checkAAIQueryResult(mockExecution) + verify(mockExecution).setVariable("CVGN_volumeGroupNameMatches", false) + } + + @Test public void testQueryAAIForVolumeGroupId() { ExecutionEntity mockExecution = setupMock() when(mockExecution.getVariable("aai.endpoint")).thenReturn('http://localhost:8090') diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java index 9897c04ad8..d0ecedf878 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java @@ -301,6 +301,35 @@ public class BBInputSetupTest { assertThat(actual, sameBeanAs(expected)); } + + @Test + public void testGetGBBCM() throws Exception { + GeneralBuildingBlock expected = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockCMExpected.json"), + GeneralBuildingBlock.class); + + ExecuteBuildingBlock executeBB = new ExecuteBuildingBlock(); + executeBB.setRequestId("requestId"); + RequestDetails requestDetails = new RequestDetails(); + requestDetails.setModelInfo(null); + RequestParameters requestParams = new RequestParameters(); + requestParams.setaLaCarte(true); + requestDetails.setRequestParameters(requestParams); + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setSuppressRollback(true); + requestDetails.setRequestInfo(requestInfo); + doReturn(requestDetails).when(SPY_bbInputSetupUtils).getRequestDetails(executeBB.getRequestId()); + Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); + String resourceId = "123"; + String requestAction = "createInstance"; + doReturn(expected).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, + requestAction, resourceId); + doNothing().when(SPY_bbInputSetup).populateLookupKeyMapWithIds(any(WorkflowResourceIds.class), any()); + doReturn(null).when(bbInputSetupMapperLayer).mapAAIGenericVnfIntoGenericVnf(any(org.onap.aai.domain.yang.GenericVnf.class)); + GeneralBuildingBlock actual = SPY_bbInputSetup.getGBBCM(executeBB, requestDetails, lookupKeyMap, requestAction, + resourceId); + + assertThat(actual, sameBeanAs(expected)); + } @Test public void testGetGBBALaCarteNonService() throws Exception { diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockCMExpected.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockCMExpected.json new file mode 100644 index 0000000000..8cd04fdd8e --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockCMExpected.json @@ -0,0 +1,29 @@ +{ + "requestContext": { + "source": "VID", + "mso-request-id": "requestId", + "action": "createInstance", + "requestParameters": { + "userParams": [], + "aLaCarte": true + }, + "configurationParameters": [] + }, + "orchContext": { + "is-rollback-enabled": true + }, + "cloudRegion": { + "cloud-owner": "att-aic" + }, + "userInput": null, + "customer": { + "vpn-bindings": [] + }, + "serviceInstance": { + "vnfs": [null], + "pnfs": [], + "allotted-resources": [], + "networks": [], + "configurations": [] + } +} |