diff options
33 files changed, 514 insertions, 417 deletions
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java index 2fec3f8b43..f8cba6afcb 100644 --- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java +++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java @@ -668,15 +668,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { LOGGER.debug("requestTypeString = " + requestTypeString + ", nestedStackId = " + nestedStackId + ", nestedBaseStackId = " + nestedBaseStackId); - // TODO(sshank): Figure out the body format to be sent from Groovy. - String hpaEnviromnentString = ""; - // Something similar to the following: - /* - if requestTypeString.substring(?) != "" { - hpaEnviromnentString = requestTypeString.substring(?) - } - */ - // Will capture execution time for metrics long startTime = System.currentTimeMillis(); @@ -1052,6 +1043,18 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { LOGGER.debug("no environment parameter found for this Type " + vfModuleType); } + // Replace flavors in environment with those returned by OOF + Map<String, Object> returnMap = updateFlavorsFromOof(heatEnvironmentString, inputs); + heatEnvironmentString = returnMap.get("heatEnvironmentString").toString(); + LOGGER.debug("After OOF Update Heat Env String is: " + heatEnvironmentString); + if (returnMap.get("inputs") instanceof Map) { + inputs = (Map<String, String>) returnMap.get("inputs"); + LOGGER.debug("After OOF Update inputs are: " + inputs.toString()); + } else { + LOGGER.debug("inputs is not an instance of a Map: " + returnMap.get("inputs")); + throw new VnfException("Updating inputs using OOF info failed.", MsoExceptionCategory.INTERNAL); + } + // 1510 - Add the files: for nested templates *if* there are any LOGGER.debug("In MsoVnfAdapterImpl, createVfModule about to call db.getNestedTemplates avec templateId=" + heatTemplate.getArtifactUuid()); @@ -1170,12 +1173,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { //LOGGER.debug("About to create MHEE with " + sb); mhee = new MsoHeatEnvironmentEntry(sb); - // sshank: hpaEnviromnentString is obtained from requestTypeString above. - if (hpaEnviromnentString != null && hpaEnviromnentString.contains("parameters:")) { - StringBuilder hpasb = new StringBuilder(hpaEnviromnentString); - mhee.setHPAParameters(hpasb); - } - StringBuilder sb2 = new StringBuilder("\nHeat Template Parameters:\n"); for (HeatTemplateParam parm : heatTemplate.getParameters()) { sb2.append("\t" + parm.getParamName() + ", required=" + parm.isRequired()); @@ -2163,4 +2160,17 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { return CatalogDatabase.getInstance(); } + private Map<String, Object> updateFlavorsFromOof(String heatEnvironmentString, Map<String, String> inputs) { + Map<String, Object> returnMap = new HashMap<>(); + for (Map.Entry<String, String> input : inputs.entrySet()){ + if (heatEnvironmentString.contains("label_" + input.getKey())){ + heatEnvironmentString = heatEnvironmentString.replace("label_" + input.getKey(), + input.getValue()); + inputs.remove("label_" + input.getKey()); + } + } + returnMap.put("heatEnvironmentString", heatEnvironmentString); + returnMap.put("inputs", inputs); + return returnMap; + } } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/OofHoming.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/OofHoming.groovy index 5e7ed982a6..f0f239b50f 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/OofHoming.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/OofHoming.groovy @@ -20,11 +20,12 @@ package org.openecomp.mso.bpmn.common.scripts import org.camunda.bpm.engine.delegate.BpmnError -import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.DelegateExecution 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.CloudFlavor import org.openecomp.mso.bpmn.core.domain.InventoryType import org.openecomp.mso.bpmn.core.domain.Resource import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition @@ -199,54 +200,87 @@ class OofHoming extends AbstractServiceTaskProcessor { List<Resource> resourceList = decomposition.getServiceResources() JSONArray arr = new JSONArray(placements) for (int i = 0; i < arr.length(); i++) { - JSONObject placement = arr.getJSONObject(i) - utils.log("DEBUG", "****** JSONObject is: " + placement + " *****", "true") - String jsonServiceResourceId = placement.getString("serviceResourceId") - for (Resource resource : resourceList) { - String serviceResourceId = resource.getResourceId() - if (serviceResourceId.equalsIgnoreCase(jsonServiceResourceId)) { - JSONObject solution = placement.getJSONObject("solution") - String solutionType = solution.getString("identifierType") - String inventoryType = "" - if (solutionType.equalsIgnoreCase("serviceInstanceId")) { - inventoryType = "service" - } else { - inventoryType = "cloud" + JSONArray arrSol = arr.getJSONArray(i) + for (int j = 0; j < arrSol.length(); j++) { + JSONObject placement = arrSol.getJSONObject(j) + utils.log("DEBUG", "****** JSONObject is: " + placement + " *****", "true") + String jsonServiceResourceId = placement.getString("serviceResourceId") + for (Resource resource : resourceList) { + String serviceResourceId = resource.getResourceId() + if (serviceResourceId.equalsIgnoreCase(jsonServiceResourceId)) { + JSONObject solution = placement.getJSONObject("solution") + String solutionType = solution.getString("identifierType") + String inventoryType = "" + if (solutionType.equalsIgnoreCase("serviceInstanceId")) { + inventoryType = "service" + } else { + inventoryType = "cloud" + } + resource.getHomingSolution().setInventoryType(InventoryType.valueOf(inventoryType)) - } - 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>() + 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) + } + } + Map<String, String> assignmentMap = jsonUtil.entryArrayToMap(execution, assignmentArr.toString(), "key", "value") + String cloudOwner = assignmentMap.get("cloudOwner") + String cloudRegionId = assignmentMap.get("cloudRegionId") + resource.getHomingSolution().setCloudOwner(cloudOwner) + resource.getHomingSolution().setCloudRegionId(cloudRegionId) + if (flavorsArrayList != null && flavorsArrayList.size != 0) { + resource.getHomingSolution().setFlavors(flavorsArrayList) + execution.setVariable(cloudRegionId + "_flavorList", flavorsArrayList) + } - // TODO Deal with Placement Solutions & Assignment Info here - JSONArray assignmentArr = placement.getJSONArray("assignmentInfo") - Map<String, String> assignmentMap = jsonUtil.entryArrayToMap(execution, assignmentArr.toString(), "key", "value") - resource.getHomingSolution().setCloudOwner(assignmentMap.get("cloudOwner")) - resource.getHomingSolution().setCloudRegionId(assignmentMap.get("cloudRegionId")) - if (inventoryType.equalsIgnoreCase("service")) { - resource.getHomingSolution().setRehome(assignmentMap.get("isRehome").toBoolean()) - VnfResource vnf = new VnfResource() - vnf.setVnfHostname(assignmentMap.get("vnfHostName")) - resource.getHomingSolution().setVnf(vnf) - resource.getHomingSolution().setServiceInstanceId(solution.getJSONArray("identifiers")[0].toString()) + if (inventoryType.equalsIgnoreCase("service")) { + resource.getHomingSolution().setRehome(assignmentMap.get("isRehome").toBoolean()) + VnfResource vnf = new VnfResource() + vnf.setVnfHostname(assignmentMap.get("vnfHostName")) + resource.getHomingSolution().setVnf(vnf) + resource.getHomingSolution().setServiceInstanceId(solution.getJSONArray("identifiers")[0].toString()) + } } } } - } - if (JsonUtils.jsonElementExist(response, "solutions.licenseSolutions")) { - String licenseSolutions = jsonUtil.getJsonValue(response, "solutions.licenseSolutions") - JSONArray licenseArr = new JSONArray(licenseSolutions) - 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)) { - String jsonEntitlementPoolList = jsonUtil.getJsonValue(license.toString(), "entitlementPoolUUID") - List<String> entitlementPoolList = jsonUtil.StringArrayToList(execution, jsonEntitlementPoolList) - resource.getHomingSolution().getLicense().setEntitlementPoolList(entitlementPoolList) + if (JsonUtils.jsonElementExist(response, "solutions.licenseSolutions")) { + String licenseSolutions = jsonUtil.getJsonValue(response, "solutions.licenseSolutions") + JSONArray licenseArr = new JSONArray(licenseSolutions) + 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)) { + String jsonEntitlementPoolList = jsonUtil.getJsonValue(license.toString(), "entitlementPoolUUID") + List<String> entitlementPoolList = jsonUtil.StringArrayToList(execution, jsonEntitlementPoolList) + resource.getHomingSolution().getLicense().setEntitlementPoolList(entitlementPoolList) - String jsonLicenseKeyGroupList = jsonUtil.getJsonValue(license.toString(), "licenseKeyGroupUUID") - List<String> licenseKeyGroupList = jsonUtil.StringArrayToList(execution, jsonLicenseKeyGroupList) - resource.getHomingSolution().getLicense().setLicenseKeyGroupList(licenseKeyGroupList) + String jsonLicenseKeyGroupList = jsonUtil.getJsonValue(license.toString(), "licenseKeyGroupUUID") + List<String> licenseKeyGroupList = jsonUtil.StringArrayToList(execution, jsonLicenseKeyGroupList) + resource.getHomingSolution().getLicense().setLicenseKeyGroupList(licenseKeyGroupList) + } } } } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/OofUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/OofUtils.groovy index fc7c62baa7..4b2b0e20ac 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/OofUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/OofUtils.groovy @@ -311,7 +311,7 @@ class OofUtils { sb.append(",\n" + " \"existingCandidates\": [\n") def existingCandidateJson = "" - existingCandidates.each { + existingCandidates.each { existingCandidate -> type = existingCandidate.get('identifierType') if (type == 'vimId') { def cloudOwner = existingCandidate.get('cloudOwner') @@ -342,7 +342,7 @@ class OofUtils { sb.append(",\n" + " \"excludedCandidates\": [\n") def excludedCandidateJson = "" - excludedCandidates.each { + excludedCandidates.each { excludedCandidate -> type = excludedCandidate.get('identifierType') if (type == 'vimId') { def cloudOwner = excludedCandidate.get('cloudOwner') @@ -373,7 +373,7 @@ class OofUtils { sb.append(",\n" + " \"requiredCandidates\": [\n") def requiredCandidatesJson = "" - requiredCandidates.each { + requiredCandidates.each { requiredCandidate -> type = requiredCandidate.get('identifierType') if (type == 'vimId') { def cloudOwner = requiredCandidate.get('cloudOwner') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/BpmnParam.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/BpmnParam.java index f4ebd0615a..4b58b51560 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/BpmnParam.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/BpmnParam.java @@ -41,7 +41,7 @@ public class BpmnParam { return value; } - @JsonProperty("type") + @JsonProperty("value") public void setValue(String value) { this.value = value; } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/BpmnRestClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/BpmnRestClient.java index e43af18ceb..016afa8537 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/BpmnRestClient.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/BpmnRestClient.java @@ -181,6 +181,7 @@ public class BpmnRestClient { requestIdInput.setValue(requestId);
requestActionInput.setValue(requestAction);
serviceInstanceIdInput.setValue(serviceInstanceId);
+ serviceTypeInput.setValue(serviceType);
recipeParamsInput.setValue(recipeParams);
resourceInput.setValue(requestDetails);
recipeRequest.setHost(host);
@@ -189,6 +190,7 @@ public class BpmnRestClient { recipeRequest.setServiceInstanceId(serviceInstanceIdInput);
recipeRequest.setServiceType(serviceTypeInput);
recipeRequest.setRecipeParams(recipeParamsInput);
+ recipeRequest.setResourceInput(resourceInput);
jsonReq = recipeRequest.toString();
msoLogger.debug("request body is " + jsonReq);
} catch(Exception e) {
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilder.java index 36585717fa..74a3252768 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilder.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilder.java @@ -55,7 +55,7 @@ public class ResourceRequestBuilder { public static String CUSTOMIZATION_UUID = "customizationUUID"; - public static String SERVICE_URL_TOSCA_CSAR = "http://localhost:8080/ecomp/mso/catalog/v3/serviceToscaCsar?serviceModelUuid="; + public static String SERVICE_URL_TOSCA_CSAR = "http://mso:8080/ecomp/mso/catalog/v3/serviceToscaCsar?serviceModelUuid="; private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA); @@ -69,9 +69,10 @@ public class ResourceRequestBuilder { * "requestInputs":{K,V} * } * <br> - * + * + * @param execution Execution context * @param serviceUuid The service template uuid - * @param resourceucstomizationUuid The resource customization uuid + * @param resourceCustomizationUuid The resource customization uuid * @param serviceParameters the service parameters passed from the API * @return the resource instantiate parameters * @since ONAP Beijing Release diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/OofHomingTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/OofHomingTest.java index 45645be7cd..d7239fe0c1 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/OofHomingTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/OofHomingTest.java @@ -28,6 +28,7 @@ import org.junit.Ignore; import org.junit.Test; import org.openecomp.mso.bpmn.core.WorkflowException; import org.openecomp.mso.bpmn.core.domain.AllottedResource; +import org.openecomp.mso.bpmn.core.domain.CloudFlavor; import org.openecomp.mso.bpmn.core.domain.HomingSolution; import org.openecomp.mso.bpmn.core.domain.ModelInfo; import org.openecomp.mso.bpmn.core.domain.NetworkResource; @@ -123,6 +124,12 @@ public class OofHomingTest extends WorkflowTest { VnfResource vnf = new VnfResource(); vnf.setResourceId("testResourceIdVNF"); vnf.setResourceInstanceName("testVnfInstanceName"); + ArrayList<CloudFlavor> flavors = new ArrayList<>(); + CloudFlavor flavor1 = new CloudFlavor("flavorLabel1xxx", "vimFlavorxxx"); + CloudFlavor flavor2 = new CloudFlavor("flavorLabel2xxx", "vimFlavorxxx"); + flavors.add(flavor1); + flavors.add(flavor2); + vnf.getHomingSolution().setFlavors(flavors); ModelInfo vnfModel = new ModelInfo(); vnfModel.setModelCustomizationUuid("testModelCustomizationUuidVNF"); vnfModel.setModelInvariantUuid("testModelInvariantIdVNF"); @@ -190,7 +197,7 @@ public class OofHomingTest extends WorkflowTest { resourceARHoming2.getVnf().getResourceId(),"aic", "testCloudRegionId2", null, null), resourceARHoming2String); assertEquals(homingSolutionCloud("cloud","aic", "testCloudRegionId3", - "\"91d563e8-e714-4393-8f99-cc480144a05e\", \"21d563e8-e714-4393-8f99-cc480144a05e\"", + true, "\"91d563e8-e714-4393-8f99-cc480144a05e\", \"21d563e8-e714-4393-8f99-cc480144a05e\"", "\"31d563e8-e714-4393-8f99-cc480144a05e\", \"71d563e8-e714-4393-8f99-cc480144a05e\""), resourceVNFHomingString); assertEquals(verifyOofRequest(), expectedOofRequest); @@ -255,7 +262,7 @@ public class OofHomingTest extends WorkflowTest { null, null), resourceARHoming2String); assertEquals(homingSolutionCloud("cloud","aic", "testCloudRegionId3", - "\"91d563e8-e714-4393-8f99-cc480144a05e\", \"21d563e8-e714-4393-8f99-cc480144a05e\"", + true, "\"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", @@ -264,7 +271,7 @@ public class OofHomingTest extends WorkflowTest { null, null), resourceNetHomingString); assertEquals(homingSolutionCloud("cloud", "aic", "testCloudRegionIdNet2", - "\"f1d563e8-e714-4393-8f99-cc480144a05n\", \"j1d563e8-e714-4393-8f99-cc480144a05n\"", + false, "\"f1d563e8-e714-4393-8f99-cc480144a05n\", \"j1d563e8-e714-4393-8f99-cc480144a05n\"", "\"s1d563e8-e714-4393-8f99-cc480144a05n\", \"b1d563e8-e714-4393-8f99-cc480144a05n\""), resourceNetHoming2String); assertEquals(verifyOofRequest(), expectedOofRequest); @@ -405,7 +412,7 @@ public class OofHomingTest extends WorkflowTest { null, null), resourceARHoming2String); assertEquals(homingSolutionCloud("cloud", "aic", "testCloudRegionId3", - "\"91d563e8-e714-4393-8f99-cc480144a05e\", \"21d563e8-e714-4393-8f99-cc480144a05e\"", + false, "\"91d563e8-e714-4393-8f99-cc480144a05e\", \"21d563e8-e714-4393-8f99-cc480144a05e\"", "\"31d563e8-e714-4393-8f99-cc480144a05e\", \"71d563e8-e714-4393-8f99-cc480144a05e\""), resourceVNFHomingString); assertEquals(verifyOofRequestExistingLicense(), oofRequest); @@ -625,43 +632,6 @@ public class OofHomingTest extends WorkflowTest { } - /*private String homingSolutionService(String resourceModuleName, String serviceInstanceId, String vnfHostname, String cloudOwner, - String cloudRegionId, String licenseList) { - String solution = ""; - if (licenseList == null || licenseList == "") { - solution = "{\n" + - " \"resourceModuleName\": \"" + resourceModuleName + "\",\n" + - " \"serviceResourceId\": \"some_resource_id\",\n" + - " \"solution\": {\n" + - " \"identifierType\": \"serviceInstanceId\",\n" + - " \"identifiers\": [\"" + serviceInstanceId + "\"]\n" + - " }\n" + - " \"assignmentInfo\": [\n" + - " { \"key\": \"cloudOwner\", \"value\": \"" + cloudOwner + "\" },\n" + - " { \"key\": \"vnfHostName\", \"value\": \"" + vnfHostname + "\" },\n" + - " { \"key\": \"isRehome\", \"value\": \"False\" },\n" + - " { \"key\": \"cloudRegionId\", \"value\": \"" + cloudRegionId + "\" }\n" + - " ]\n" + - " }"; - } else { - solution = "{\n" + - " \"resourceModuleName\": \"" + resourceModuleName + "\",\n" + - " \"serviceResourceId\": \"some_resource_id\",\n" + - " \"solution\": {\n" + - " \"identifierType\": \"service_instance_id\",\n" + - " \"identifiers\": [\"" + serviceInstanceId + "\"]\n" + - " }\n" + - " \"assignmentInfo\": [\n" + - " { \"key\": \"cloudOwner\", \"value\": \"" + cloudOwner + "\" },\n" + - " { \"key\": \"vnfHostName\", \"value\": \"" + vnfHostname + "\" },\n" + - " { \"key\": \"isRehome\", \"value\": \"False\" },\n" + - " { \"key\": \"cloudRegionId\", \"value\": \"" + cloudRegionId + "\" }\n" + - " ], " + - " \"licenseSolutions\" : [ {\"licenseKeyGroupUUID\": [" + licenseList + "]} ] " + - "}"; - } - return solution; - }*/ private String homingSolutionService(String type, String serviceInstanceId, String vnfHostname, String vnfResourceId, String cloudOwner, String cloudRegionId, String enList, @@ -687,50 +657,28 @@ public class OofHomingTest extends WorkflowTest { return solution; } - /*private String homingSolutionCloud(String resourceModuleName, String cloudOwner, - String cloudRegionId, String licenseList) { - String solution = ""; - if (licenseList == null || licenseList == "") { - solution = "{\n" + - " \"resourceModuleName\": \"" + resourceModuleName + "\",\n" + - " \"serviceResourceId\": \"some_resource_id\",\n" + - " \"solution\": {\n" + - " \"identifierType\": \"cloudRegionId\",\n" + - " \"cloudOwner\": \"" + cloudOwner + "\",\n" + - " \"identifiers\": [\"" + cloudRegionId + "\"]\n" + - " }\n" + - " \"assignmentInfo\": [\n" + - " { \"key\": \"cloudOwner\", \"value\": \"" + cloudOwner + "\" },\n" + - " { \"key\": \"cloudRegionId\", \"value\": \"" + cloudRegionId + "\" }\n" + - " ]\n" + - "}"; - } else { - solution = "{\n" + - " \"resourceModuleName\": \"" + resourceModuleName + "\",\n" + - " \"serviceResourceId\": \"some_resource_id\",\n" + - " \"solution\": {\n" + - " \"identifierType\": \"cloudRegionId\",\n" + - " \"cloudOwner\": \"" + cloudOwner + "\",\n" + - " \"identifiers\": [\"" + cloudRegionId + "\"]\n" + - " }\n" + - " \"assignmentInfo\": [\n" + - " { \"key\": \"cloudOwner\", \"value\": \"" + cloudOwner + "\" },\n" + - " { \"key\": \"cloudRegionId\", \"value\": \"" + cloudRegionId + "\" }\n" + - " ]," + - " \"licenseSolutions\" : [ {\"licenseKeyGroupUUID\": [" + licenseList + "]} ] } " + - "}"; - } - return solution; - }*/ private String homingSolutionCloud(String type, String cloudOwner, - String cloudRegionId, String enList, + String cloudRegionId, Boolean flavors, String enList, String licenseList){ String solution = ""; if(enList == null){ solution = "{ \"homingSolution\" : { \"inventoryType\" : \"" + type + "\", \"cloudOwner\" : \"" + cloudOwner + "\", \"cloudRegionId\" : \"" + cloudRegionId + "\", \"license\" : { }, \"rehome\" : false } }"; - }else{ + } else if (flavors && enList == null){ + solution = "{ \"homingSolution\" : { \"inventoryType\" : \"" + type + "\", \"cloudOwner\" : \"" + + cloudOwner + "\", \"cloudRegionId\" : \"" + cloudRegionId + + "\", \"flavors\" : [ { \"flavorLabel\" : \"flavorLabel2xxx\", \"flavor\" : \"vimFlavorxxx\" }, " + + "{ \"flavorLabel\" : \"flavorLabel1xxx\", \"flavor\" : \"vimFlavorxxx\" } ], " + + "\"license\" : { }, \"rehome\" : false } }"; + } else if (flavors) { + solution = "{ \"homingSolution\" : { \"inventoryType\" : \"" + type + "\", \"cloudOwner\" : \"" + + cloudOwner + "\", \"cloudRegionId\" : \"" + cloudRegionId + + "\", \"flavors\" : [ { \"flavorLabel\" : \"flavorLabel2xxx\", \"flavor\" : \"vimFlavorxxx\" }, " + + "{ \"flavorLabel\" : \"flavorLabel1xxx\", \"flavor\" : \"vimFlavorxxx\" } ], " + + "\"license\" : { \"entitlementPoolList\" : [ " + enList + " ], \"licenseKeyGroupList\" : [ " + + licenseList + " ] }, \"rehome\" : false } }"; + } else { solution = "{ \"homingSolution\" : { \"inventoryType\" : \"" + type + "\", \"cloudOwner\" : \"" + cloudOwner + "\", \"cloudRegionId\" : \"" + cloudRegionId + "\", \"license\" : { \"entitlementPoolList\" : [ " + enList + " ], \"licenseKeyGroupList\" : [ " + diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/oofCallback2AR1Vnf b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/oofCallback2AR1Vnf index 3559708728..808723828a 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/oofCallback2AR1Vnf +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/oofCallback2AR1Vnf @@ -31,6 +31,7 @@ } ], "placementSolutions": [ + [ { "resourceModuleName": "ALLOTTED_RESOURCE", "serviceInstanceId": "testSIID1", @@ -101,9 +102,12 @@ { "key": "cloudRegionId", "value": "testCloudRegionId3" - } + }, + { "key":"flavors", + "value":{"flavorLabel1xxx":"vimFlavorxxx", "flavorLabel2xxx":"vimFlavorxxx"}} ] } ] + ] } }
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/oofCallback2AR1Vnf2Net b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/oofCallback2AR1Vnf2Net index 30fa09afd9..8766df8dba 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/oofCallback2AR1Vnf2Net +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/oofCallback2AR1Vnf2Net @@ -43,6 +43,7 @@ }, ], "placementSolutions": [ + [ { "resourceModuleName": "ALLOTTED_RESOURCE", "serviceResourceId": "testResourceIdAR", @@ -108,9 +109,11 @@ }, "assignmentInfo": [ { "key": "cloudOwner", "value": "aic" }, - { "key": "cloudRegionId", "value": "testCloudRegionId3" } + { "key": "cloudRegionId", "value": "testCloudRegionId3" }, + { "key":"flavors", "value":{ "flavorLabel1xxx":"vimFlavorxxx", "flavorLabel2xxx":"vimFlavorxxx"}} ] } ] + ] } }
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/oofCallbackInfraVnf b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/oofCallbackInfraVnf index b4e748c6e7..8e6f2d46be 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/oofCallbackInfraVnf +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlocks/oofCallbackInfraVnf @@ -5,6 +5,7 @@ "statusMessage": "success", "solutions": { "placementSolutions": [ + [ { "resourceModuleName": "vGMuxInfra", "serviceResourceId": "some_resource_id", @@ -29,9 +30,11 @@ }, "assignmentInfo": [ { "key": "cloudOwner", "value": "amazon" }, - { "key": "cloudRegionId", "value": "1ac71fb8-ad43-4e16-9459-c3f372b8236d" } + { "key": "cloudRegionId", "value": "1ac71fb8-ad43-4e16-9459-c3f372b8236d" }, + { "key":"flavors", "value":{ "flavorLabel1xxx":"vimFlavorxxx", "flavorLabel2xxx":"vimFlavorxxx"}} ] } + ] ], "licenseSolutions": [ { diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/CloudFlavor.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/CloudFlavor.java new file mode 100644 index 0000000000..100d70e1b2 --- /dev/null +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/CloudFlavor.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Intel Corp. Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.bpmn.core.domain; + +import java.io.Serializable; + +/** + * Stores Cloud Flavor information and is an attribute + * of a <class>HomingSolution</class> + * + */ +public class CloudFlavor extends JsonWrapper implements Serializable { + private String flavorLabel; + private String flavor; + + public CloudFlavor (String flavorLabel, String flavor){ + this.flavorLabel = flavorLabel; + this.flavor = flavor; + } + + public String getFlavorLabel() { + return flavorLabel; + } + + public void setFlavorLabel(String flavorLabel) { + this.flavorLabel = flavorLabel; + } + + public String getFlavor() { + return flavor; + } + + public void setFlavor(String flavor) { + this.flavor = flavor; + } + +} diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/HomingSolution.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/HomingSolution.java index 611c8dfff9..f0193bc1c3 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/HomingSolution.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/HomingSolution.java @@ -45,6 +45,7 @@ public class HomingSolution extends JsonWrapper implements Serializable { private String aicVersion; private String tenant; private VnfResource vnf; + private List<CloudFlavor> flavors; private License license = new License(); @@ -126,6 +127,17 @@ public class HomingSolution extends JsonWrapper implements Serializable { this.vnf = vnf; } + /** + * @return a map<string, string> key is label name, value is any flavor + */ + public List<CloudFlavor> getFlavors() { + return flavors; + } + + public void setFlavors(List<CloudFlavor> flavors) { + this.flavors = flavors; + } + public License getLicense() { return license; } diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonUtils.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonUtils.java index 79b9239015..1869b930f0 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonUtils.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonUtils.java @@ -931,7 +931,7 @@ public class JsonUtils { for (int i = 0; i < arr.length(); i++){
JSONObject jo = arr.getJSONObject(i);
String key = jo.getString(keyNode);
- String value =jo.getString(valueNode);
+ String value = jo.getString(valueNode);
map.put(key, value);
}
msoLogger.debug("Outgoing Map is: " + map);
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/CreateVFCNSResource.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/CreateVFCNSResource.groovy index 0279c2cbc8..b29c4dc101 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/CreateVFCNSResource.groovy +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/CreateVFCNSResource.groovy @@ -28,7 +28,6 @@ import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil import org.openecomp.mso.bpmn.core.WorkflowException
import org.openecomp.mso.bpmn.core.json.JsonUtils
import org.openecomp.mso.rest.APIResponse
-
import java.util.UUID;
import org.camunda.bpm.engine.delegate.BpmnError
@@ -62,24 +61,36 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor { * generate the nsParameters
*/
public void preProcessRequest (DelegateExecution execution) {
+ JsonUtils jsonUtil = new JsonUtils()
+
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
String msg = ""
utils.log("INFO", " *** preProcessRequest() *** ", isDebugEnabled)
try {
//deal with nsName and Description
- String nsServiceName = execution.getVariable("nsServiceName")
+ String resourceInput = execution.getVariable("resourceInput")
+
+ // get service name
+ String resourceName = jsonUtil.getJsonValue(resourceInput, "resourceInstanceName")
+ String nsServiceName = resourceName.substring(resourceName.indexOf("_") + 1)
+ execution.setVariable("nsServiceName", nsServiceName)
+
String nsServiceDescription = execution.getVariable("nsServiceDescription")
utils.log("INFO", "nsServiceName:" + nsServiceName + " nsServiceDescription:" + nsServiceDescription, isDebugEnabled)
//deal with operation key
- String globalSubscriberId = execution.getVariable("globalSubscriberId")
+ String globalSubscriberId = jsonUtil.getJsonValue(resourceInput, "globalSubscriberId")
utils.log("INFO", "globalSubscriberId:" + globalSubscriberId, isDebugEnabled)
+
String serviceType = execution.getVariable("serviceType")
utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)
- String serviceId = execution.getVariable("serviceId")
+
+ String serviceId = execution.getVariable("serviceInstanceId")
utils.log("INFO", "serviceId:" + serviceId, isDebugEnabled)
- String operationId = execution.getVariable("operationId")
+
+ String operationId = execution.getVariable("requestId")
utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)
- String nodeTemplateUUID = execution.getVariable("resourceUUID")
+
+ String nodeTemplateUUID = jsonUtil.getJsonValue(resourceInput, "resourceModelInfo.modelCustomizationUuid")
utils.log("INFO", "nodeTemplateUUID:" + nodeTemplateUUID, isDebugEnabled)
/*
* segmentInformation needed as a object of segment
@@ -92,7 +103,7 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor { * }
* }
*/
- String nsParameters = execution.getVariable("resourceParameters")
+ String nsParameters = jsonUtil.getJsonValue(resourceInput, "resourceParameters")
utils.log("INFO", "nsParameters:" + nsParameters, isDebugEnabled)
String nsOperationKey = """{
"globalSubscriberId":"${globalSubscriberId}",
@@ -125,11 +136,16 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor { String nsParameters = execution.getVariable("nsParameters");
String nsServiceName = execution.getVariable("nsServiceName")
String nsServiceDescription = execution.getVariable("nsServiceDescription")
+ String locationConstraints = jsonUtil.getJsonValue(nsParameters, "locationConstraints")
+ String requestInputs = jsonUtil.getJsonValue(nsParameters, "requestInputs")
String reqBody ="""{
"nsServiceName":"${nsServiceName}",
"nsServiceDescription":"${nsServiceDescription}",
"nsOperationKey":${nsOperationKey},
- "nsParameters":${nsParameters}
+ "nsParameters":{
+ "locationConstraints":${locationConstraints},
+ "additionalParamForNs":${requestInputs}
+ }
}"""
APIResponse apiResponse = postRequest(execution, host + vfcUrl + "/ns", reqBody)
String returnCode = apiResponse.getStatusCode()
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateResources.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateResources.groovy index 93f86592ab..5dd33c9181 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateResources.groovy +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateResources.groovy @@ -182,6 +182,7 @@ public class DoCreateResources extends AbstractServiceTaskProcessor resourceInput.setResourceModelInfo(currentResource.getModelInfo()); ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") resourceInput.setServiceModelInfo(serviceDecomposition.getModelInfo()); + def String resourceCustomizationUuid = currentResource.getModelInfo().getModelCustomizationUuid(); String incomingRequest = execution.getVariable("uuiRequest") //set the requestInputs from tempalte To Be Done @@ -203,10 +204,10 @@ public class DoCreateResources extends AbstractServiceTaskProcessor String requestAction = resourceInput.getOperationType() JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceInput.getResourceModelInfo().getModelUuid(), requestAction) String recipeUri = resourceRecipe.getString("orchestrationUri") - String recipeTimeOut = resourceRecipe.getString("recipeTimeout") + int recipeTimeOut = resourceRecipe.getInt("recipeTimeout") String recipeParamXsd = resourceRecipe.get("paramXSD") HttpResponse resp = BpmnRestClient.post(recipeUri, requestId, recipeTimeOut, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd) - + utils.log("INFO", "======== end executeResourceRecipe Process ======== ", isDebugEnabled) } public void postConfigRequest(DelegateExecution execution){ diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVfModule.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVfModule.groovy index b9319466d9..95747d5a0b 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVfModule.groovy +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVfModule.groovy @@ -18,7 +18,9 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.bpmn.infrastructure.scripts; +package org.openecomp.mso.bpmn.infrastructure.scripts + +import org.openecomp.mso.bpmn.core.domain.CloudFlavor import java.util.Map import java.util.Currency.CurrencyNameGetter @@ -174,6 +176,12 @@ public class DoCreateVfModule extends VfModuleBase { execution.setVariable("DCVFM_serviceInstanceId", serviceInstanceId) rollbackData.put("VFMODULE", "serviceInstanceId", serviceInstanceId) logDebug("serviceInstanceId: " + serviceInstanceId, isDebugLogEnabled) + //flavorList + ArrayList<CloudFlavor> flavorList = execution.getVariable(cloudSiteId + "_flavorList") + if (flavorList != null) { + execution.setVariable("DCVFM_flavorList", flavorList) + logDebug("flavorList is: " + flavorList, isDebugLogEnabled) + } //source - HARDCODED def source = "VID" execution.setVariable("DCVFM_source", source) @@ -927,6 +935,8 @@ public class DoCreateVfModule extends VfModuleBase { def serviceId = execution.getVariable("DCVFM_serviceId") //serviceInstanceId def serviceInstanceId = execution.getVariable("DCVFM_serviceInstanceId") + //flavorList + ArrayList<CloudFlavor> flavorList = execution.getVariable("DCVFM_flavorList") //backoutOnFailure def backoutOnFailure = execution.getVariable("DCVFM_backoutOnFailure") //volumeGroupId @@ -962,6 +972,10 @@ public class DoCreateVfModule extends VfModuleBase { } Map<String, String> vnfParamsMap = execution.getVariable("DCVFM_vnfParamsMap") + // Add flavorLabel List to vnfParamsMap + flavorList.each { cloudFlavor -> + vnfParamsMap.put("label_" + cloudFlavor.getFlavorLabel(), cloudFlavor.getFlavor()) + } String vfModuleParams = "" //Get SDNC Response Data for VF Module Topology String vfModuleSdncGetResponse = execution.getVariable('DCVFM_getSDNCAdapterResponse') diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/PnfReadyEventHandler.java b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/PnfReadyEventHandler.java deleted file mode 100644 index f89b6a7a58..0000000000 --- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/PnfReadyEventHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.openecomp.mso.bpmn.infrastructure.scripts; - -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil; -import org.openecomp.mso.client.dmaap.DmaapConsumer; -import org.openecomp.mso.client.sdno.dmaap.PnfReadyEventConsumer; - -public class PnfReadyEventHandler { - - private ExceptionUtil exceptionUtil; - - private static final String TOPIC_NAME = "VES event"; - - public PnfReadyEventHandler() { - exceptionUtil = new ExceptionUtil(); - } - - public void getPnfReadyEventFromDmaap (DelegateExecution execution) throws Exception { - Object correlationIdVar = execution.getVariable("correlationId"); - if (!(correlationIdVar instanceof String)) { - exceptionUtil.buildAndThrowWorkflowException(execution, 500, "correlationId variable is not String type"); - } - String correlationId = (String) correlationIdVar; - DmaapConsumer dmaapConsumer = new PnfReadyEventConsumer(correlationId); - dmaapConsumer.consume(); - // TODO inform camunda process that event has been received - } -} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java index f4483f5923..417bb4668e 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java @@ -28,6 +28,7 @@ import java.io.IOException; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil; import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiConnection; import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiResponse; import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.CheckAaiForCorrelationIdImplementation; @@ -58,21 +59,16 @@ public class CheckAaiForCorrelationIdDelegate implements JavaDelegate { public void execute(DelegateExecution execution) throws Exception { String correlationId = (String) execution.getVariable(CORRELATION_ID); if (correlationId == null) { - //todo: fix Execution -> DelegateExecution in ALL groovy scripts -// new ExceptionUtil().buildAndThrowWorkflowException(execution, 500, CORRELATION_ID + " is not set"); - throw new BpmnError("MSOWorkflowException"); + new ExceptionUtil().buildAndThrowWorkflowException(execution, 500, CORRELATION_ID + " is not set"); } try { AaiResponse aaiResponse = implementation.check(correlationId, aaiConnection); execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, aaiResponse.getContainsInfoAboutPnf()); - aaiResponse.getContainsInfoAboutIp().ifPresent( - isIp -> execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, isIp) - ); + execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, aaiResponse.getContainsInfoAboutIp()); } catch (IOException e) { - //todo: log this - throw new BpmnError("MSOWorkflowException"); + new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, e.getMessage()); } } } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java index 6b49908a0f..0d64f2c8b7 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java @@ -23,6 +23,9 @@ package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; @SuppressWarnings("ALL") public class ExecutionVariableNames { + private ExecutionVariableNames() { + } + public final static String CORRELATION_ID = "correlationId"; public final static String AAI_CONTAINS_INFO_ABOUT_PNF = "aaiContainsInfoAboutPnf"; public final static String AAI_CONTAINS_INFO_ABOUT_IP = "aaiContainsInfoAboutIp"; diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java new file mode 100644 index 0000000000..e6019f73f0 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java @@ -0,0 +1,96 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.bpmn.infrastructure.pnf.dmaap; + +import java.io.IOException; +import java.net.URI; +import javax.ws.rs.core.UriBuilder; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.HttpClientBuilder; + +public class PnfEventReadyConsumer { + + private static final String JSON_PATH_CORRELATION_ID = "$.pnfRegistrationFields.correlationId"; + private HttpClient httpClient; + + private String dmaapHost; + private int dmaapPort; + private String dmaapProtocol; + private String dmaapUriPathPrefix; + private String dmaapTopicName; + private String consumerId; + private String consumerGroup; + + public PnfEventReadyConsumer() { + httpClient = HttpClientBuilder.create().build(); + } + + public void notifyWhenPnfReady(String correlationId) + throws IOException { + HttpGet getRequest = new HttpGet(buildURI(consumerGroup, consumerId)); + HttpResponse response = httpClient.execute(getRequest); + checkIfResponseIsAccepted(response, correlationId); + } + + private boolean checkIfResponseIsAccepted(HttpResponse response, String correlationId) { + // TODO parse response if contains proper correlationId + return false; + } + + private URI buildURI(String consumerGroup, String consumerId) { + return UriBuilder.fromUri(dmaapUriPathPrefix) + .scheme(dmaapProtocol) + .host(dmaapHost) + .port(dmaapPort).path(dmaapTopicName) + .path(consumerGroup).path(consumerId).build(); + } + + public void setDmaapHost(String dmaapHost) { + this.dmaapHost = dmaapHost; + } + + public void setDmaapPort(int dmaapPort) { + this.dmaapPort = dmaapPort; + } + + public void setDmaapProtocol(String dmaapProtocol) { + this.dmaapProtocol = dmaapProtocol; + } + + public void setDmaapUriPathPrefix(String dmaapUriPathPrefix) { + this.dmaapUriPathPrefix = dmaapUriPathPrefix; + } + + public void setDmaapTopicName(String dmaapTopicName) { + this.dmaapTopicName = dmaapTopicName; + } + + public void setConsumerId(String consumerId) { + this.consumerId = consumerId; + } + + public void setConsumerGroup(String consumerGroup) { + this.consumerGroup = consumerGroup; + } + +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java index bbb7adc143..5fb7a43e00 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java @@ -24,28 +24,25 @@ import java.util.Optional; import javax.annotation.Nullable; import javax.validation.constraints.NotNull; -public class AaiResponse { +public enum AaiResponse { + NO_ENTRY(false, false), + ENTRY_NO_IP(true, false), + ENTRY_WITH_IP(true, true); - private Boolean containsInfoAboutPnf; - private Boolean containsInfoAboutIp; - private String ipAddress; + private boolean containsInfoAboutPnf; + private boolean containsInfoAboutIp; - public AaiResponse(@NotNull Boolean containsInfoAboutPnf, @Nullable Boolean containsInfoAboutIp, - @Nullable String ipAddress) { + AaiResponse(boolean containsInfoAboutPnf, boolean containsInfoAboutIp) { this.containsInfoAboutPnf = containsInfoAboutPnf; this.containsInfoAboutIp = containsInfoAboutIp; - this.ipAddress = ipAddress; } - public Boolean getContainsInfoAboutPnf() { + public boolean getContainsInfoAboutPnf() { return containsInfoAboutPnf; } - public Optional<Boolean> getContainsInfoAboutIp() { - return Optional.ofNullable(containsInfoAboutIp); + public boolean getContainsInfoAboutIp() { + return containsInfoAboutIp; } - public Optional<String> getIpAddress() { - return Optional.ofNullable(ipAddress); - } } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java index 353a3bd5d3..b982a693da 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java @@ -29,15 +29,14 @@ public class CheckAaiForCorrelationIdImplementation { public AaiResponse check(String correlationId, AaiConnection aaiConnection) throws IOException { Optional<Pnf> pnf = aaiConnection.getEntryFor(correlationId); if (!pnf.isPresent()) { - return new AaiResponse(false, null, null); + return AaiResponse.NO_ENTRY; } - Optional<String> ip = extractIp(pnf.get()); - return ip.map( - s -> new AaiResponse(true, true, s) - ).orElseGet( - () -> new AaiResponse(true, false, null) - ); + if(extractIp(pnf.get()).isPresent()) { + return AaiResponse.ENTRY_WITH_IP; + } else { + return AaiResponse.ENTRY_NO_IP; + } } private Optional<String> extractIp(Pnf pnf) { diff --git a/bpmn/MSOInfrastructureBPMN/src/main/resources/dmaap.properties b/bpmn/MSOInfrastructureBPMN/src/main/resources/dmaap.properties new file mode 100644 index 0000000000..3c4dca49cf --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/resources/dmaap.properties @@ -0,0 +1,7 @@ +dmaapHost=HOSTNAME +dmaapPort=3905 +dmaapProtocol=http +dmaapUriPathPrefix = events +eventReadyTopicName=pnfEventReady +consumerId=consumerId +consumerGroup=group diff --git a/bpmn/MSOInfrastructureBPMN/src/main/resources/processengine.properties b/bpmn/MSOInfrastructureBPMN/src/main/resources/processengine.properties deleted file mode 100644 index d071fdabf8..0000000000 --- a/bpmn/MSOInfrastructureBPMN/src/main/resources/processengine.properties +++ /dev/null @@ -1,20 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ECOMP MSO -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# 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. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END========================================================= -### -processEngineName=infrastructure diff --git a/bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoCreateE2EServiceInstance.bpmn b/bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoCreateE2EServiceInstance.bpmn index 5772faadf0..8fe6b70d1a 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoCreateE2EServiceInstance.bpmn +++ b/bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoCreateE2EServiceInstance.bpmn @@ -200,7 +200,7 @@ dcsi.doServiceHoming(execution)]]></bpmn2:script> <camunda:in source="nsServiceDescription" target="nsServiceDescription" /> <camunda:in source="globalSubscriberId" target="globalSubscriberId" /> <camunda:in source="serviceType" target="serviceType" /> - <camunda:in source="serviceId" target="serviceId" /> + <camunda:in source="serviceInstanceId" target="serviceInstanceId" /> <camunda:in source="operationId" target="operationId" /> <camunda:in source="resourceType" target="resourceType" /> <camunda:in source="resourceUUID" target="resourceUUID" /> @@ -210,6 +210,7 @@ dcsi.doServiceHoming(execution)]]></bpmn2:script> <camunda:in source="serviceInstanceName" target="serviceInstanceName" /> <camunda:in source="serviceDecomposition" target="serviceDecomposition" /> <camunda:in source="uuiRequest" target="uuiRequest" /> + <camunda:in source="msoRequestId" target="msoRequestId" /> </bpmn2:extensionElements> <bpmn2:incoming>SequenceFlow_0bf6bzp</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_0d0c20n</bpmn2:outgoing> diff --git a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml index 46cea5da63..f46cd065ed 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml +++ b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml @@ -14,4 +14,18 @@ <property name="aaiConnection" ref="aaiConnection"/>
</bean>
+ <bean id="pnfEventReadyConsumer" class="org.openecomp.mso.bpmn.infrastructure.pnf.dmaap.PnfEventReadyConsumer">
+ <property name="dmaapHost" value="${dmaapHost}" />
+ <property name="dmaapPort" value="${dmaapPort}"/>
+ <property name="dmaapProtocol" value="${dmaapProtocol}"/>
+ <property name="dmaapUriPathPrefix" value="${dmaapUriPathPrefix}"/>
+ <property name="dmaapTopicName" value="${eventReadyTopicName}"/>
+ <property name= "consumerGroup" value="${consumerGroup}"/>
+ <property name="consumerId" value="${consumerId}"/>
+ </bean>
+
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+ <property name="locations" value="classpath:dmaap.properties"/>
+ </bean>
+
</beans>
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/web.xml b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/web.xml index 62a2748c8c..cd688479a5 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/web.xml +++ b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/web.xml @@ -48,9 +48,19 @@ <param-name>resteasy.resources</param-name>
<param-value>org.openecomp.mso.logger.MsoLoggingServlet,org.openecomp.mso.bpmn.core.HealthCheckHandler</param-value>
</context-param>
+ <context-param>
+ <param-name>mso.configuration</param-name>
+ <param-value>MSO_PROP_APIHANDLER_INFRA=mso.apihandler-infra.properties</param-value>
+ </context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
+
+ <context-param>
+ <param-name>resteasy.jndi.resources</param-name>
+ <param-value>java:module/MsoPropertiesFactory</param-value>
+ </context-param>
<filter>
<filter-name>LogFilter</filter-name>
<filter-class>org.openecomp.mso.logger.LogFilter</filter-class>
diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java index d98a395838..75a7450434 100644 --- a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java @@ -21,10 +21,11 @@ package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.DEFAULT_IP; import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITHOUT_ENTRY; import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_AND_IP; import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_NO_IP; @@ -38,6 +39,7 @@ import org.camunda.bpm.engine.delegate.DelegateExecution; import org.junit.Test; import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; +import org.openecomp.mso.bpmn.core.WorkflowException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -60,8 +62,7 @@ public class CheckAaiForCorrelationIdDelegateTest { when(execution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue"); // when, then assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class); - // todo: uncomment line below after fixing Execution -> DelecateExecution in groovy scripts -// verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class)); + verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class)); } @Test @@ -118,12 +119,14 @@ public class CheckAaiForCorrelationIdDelegateTest { private CheckAaiForCorrelationIdDelegate delegate; @Test - public void shouldThrowExceptionWhenSSADFDSADSFDS() throws Exception { + public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() throws Exception { // given DelegateExecution execution = mock(DelegateExecution.class); when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP); + when(execution.getVariable("testProcessKey")).thenReturn("testProcessKey"); // when, then assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class); + verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class)); } } }
\ No newline at end of file diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumerTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumerTest.java new file mode 100644 index 0000000000..2f6a00db66 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumerTest.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.bpmn.infrastructure.pnf.dmaap; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.lang.reflect.Field; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@ContextConfiguration({"classpath:springConfig_PnfEventReadyConsumer.xml"}) +public class PnfEventReadyConsumerTest { + + @Autowired + private PnfEventReadyConsumer pnfEventReadyConsumer; + + private HttpClient httpClientMock; + + @Before + public void init() throws NoSuchFieldException, IllegalAccessException { + httpClientMock = mock(HttpClient.class); + setPrivateField(); + } + + @Test + public void restClientInvokesWithProperURI() throws Exception { + ArgumentCaptor<HttpGet> captor1 = ArgumentCaptor.forClass(HttpGet.class); + pnfEventReadyConsumer.notifyWhenPnfReady("correlationId"); + verify(httpClientMock).execute(captor1.capture()); + assertThat(captor1.getValue().getURI()).hasHost("hostTest").hasPort(1234).hasScheme("http") + .hasPath("/eventsForTesting/eventTopicTest/consumerGroupTest/consumerTestId"); + } + + private void setPrivateField() throws NoSuchFieldException, IllegalAccessException { + Field field = pnfEventReadyConsumer.getClass().getDeclaredField("httpClient"); + field.setAccessible(true); + field.set(pnfEventReadyConsumer, httpClientMock); + } + +} diff --git a/bpmn/MSOInfrastructureBPMN/src/test/resources/dmaapTest.properties b/bpmn/MSOInfrastructureBPMN/src/test/resources/dmaapTest.properties new file mode 100644 index 0000000000..a8df15c5df --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/resources/dmaapTest.properties @@ -0,0 +1,7 @@ +dmaapHost=hostTest +dmaapPort=1234 +dmaapProtocol=http +dmaapUriPathPrefix = eventsForTesting +eventReadyTopicName=eventTopicTest +consumerId=consumerTestId +consumerGroup=consumerGroupTest
\ No newline at end of file diff --git a/bpmn/MSOInfrastructureBPMN/src/test/resources/springConfig_PnfEventReadyConsumer.xml b/bpmn/MSOInfrastructureBPMN/src/test/resources/springConfig_PnfEventReadyConsumer.xml new file mode 100644 index 0000000000..5abee9dfd9 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/resources/springConfig_PnfEventReadyConsumer.xml @@ -0,0 +1,19 @@ +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd"> + <bean id="pnfEventReadyConsumer" class="org.openecomp.mso.bpmn.infrastructure.pnf.dmaap.PnfEventReadyConsumer"> + <property name="dmaapHost" value="${dmaapHost}" /> + <property name="dmaapPort" value="${dmaapPort}"/> + <property name="dmaapProtocol" value="${dmaapProtocol}"/> + <property name="dmaapUriPathPrefix" value="${dmaapUriPathPrefix}"/> + <property name="dmaapTopicName" value="${eventReadyTopicName}"/> + <property name= "consumerGroup" value="${consumerGroup}"/> + <property name="consumerId" value="${consumerId}"/> + </bean> + + <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> + <property name="locations" value="classpath:dmaapTest.properties"/> + </bean> + +</beans> diff --git a/common/src/main/java/org/openecomp/mso/client/sdno/dmaap/PnfReadyEventConsumer.java b/common/src/main/java/org/openecomp/mso/client/sdno/dmaap/PnfReadyEventConsumer.java deleted file mode 100644 index 08e35f62f8..0000000000 --- a/common/src/main/java/org/openecomp/mso/client/sdno/dmaap/PnfReadyEventConsumer.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.sdno.dmaap; - -import java.io.IOException; -import java.util.Optional; -import javax.ws.rs.NotSupportedException; -import org.openecomp.mso.client.dmaap.DmaapConsumer; -import org.openecomp.mso.jsonpath.JsonPathUtil; - -public class PnfReadyEventConsumer extends DmaapConsumer { - - private static final String JSON_PATH_CORRELATION_ID = "$.pnfRegistrationFields.correlationId"; - - private boolean continuePolling = true; - private String correlationId; - - public PnfReadyEventConsumer(String correlationId) throws IOException { - this.correlationId = correlationId; - } - - @Override - public boolean continuePolling() { - return continuePolling; - } - - @Override - public void processMessage(String message) { - } - - @Override - public boolean isAccepted(String message) { - Optional<String> correlationIdOpt = JsonPathUtil.getInstance().locateResult(message, JSON_PATH_CORRELATION_ID); - if (correlationIdOpt.isPresent()) { - continuePolling = false; - return correlationIdOpt.get().equals(correlationId); - } - return false; - } - - @Override - public boolean isFailure(String message) { - throw new NotSupportedException(); - } - - @Override - public void stopProcessingMessages() { - continuePolling = false; - } - - @Override - public String getRequestId() { - throw new NotSupportedException(); - } - - @Override - public String getUserName() { - throw new NotSupportedException(); - } - - @Override - public String getPassword() { - throw new NotSupportedException(); - } - - @Override - public String getTopic() { - throw new NotSupportedException(); - } - - @Override - public Optional<String> getHost() { - throw new NotSupportedException(); - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/dmaap/PnfReadyEventConsumerTest.java b/common/src/test/java/org/openecomp/mso/client/dmaap/PnfReadyEventConsumerTest.java deleted file mode 100644 index 1561f75140..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/dmaap/PnfReadyEventConsumerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.dmaap; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Optional; -import org.junit.Test; -import org.openecomp.mso.client.sdno.dmaap.PnfReadyEventConsumer; - -public class PnfReadyEventConsumerTest { - - private static final String CORRELATION_ID = "correlation_id_test"; - - private static final String JSON_WITH_CORRELATION_ID = " {\"pnfRegistrationFields\": {\n" - + " \"correlationId\": \"correlation_id_test\"\n" - + " }}"; - - @Test - public void eventIsFoundForGivenCorrelationId2() throws Exception { - PnfReadyEventConsumerForTesting testedObjectSpy = spy(new PnfReadyEventConsumerForTesting(CORRELATION_ID)); - Consumer consumerMock = mock(Consumer.class); - when(testedObjectSpy.getConsumer()).thenReturn(consumerMock); - when(consumerMock.fetch()).thenReturn(Arrays.asList(JSON_WITH_CORRELATION_ID)); - testedObjectSpy.consume(); - assertThat(testedObjectSpy.continuePolling()).isFalse(); - } - - // TODO this is temporary class, when methods are defined, it will be deleted - private class PnfReadyEventConsumerForTesting extends PnfReadyEventConsumer { - - public PnfReadyEventConsumerForTesting(String correlationId) throws IOException { - super(correlationId); - } - - @Override - public String getUserName(){ - return "userNameTest"; - } - @Override - public String getPassword(){ - return "passTest"; - } - @Override - public String getTopic(){ - return "topicTest"; - } - @Override - public Optional<String> getHost(){ - return Optional.of("http://localhost"); - } - @Override - public boolean isFailure(String message) { - return false; - } - @Override - public String getRequestId() { - return "requestTest"; - } - } - -} |