diff options
author | Marcus G K Williams <marcus.williams@intel.com> | 2018-03-28 16:26:11 -0700 |
---|---|---|
committer | Marcus Williams <marcus.williams@intel.com> | 2018-04-09 16:20:39 +0000 |
commit | 22a25ae0b0690c5b26f949cd0d5bc7079cf05d2a (patch) | |
tree | 91b69438d2cfd386105021ed6413105489ae7aef /bpmn/MSOCommonBPMN/src/main/groovy/org | |
parent | 955768f7bf4520fb8b9120121251f9537b260db6 (diff) |
Bug Fix - OOF api updates processing flavor-label
Additional API interactions were added to OOF
response post API freeze that enable core HPA
functionality. This patch updates the processsing
of the API reponse to process additional flavor parameters.
Issue-ID: SO-408
Change-Id: I1656a7ba955ab41c57b7a3e07a3d0cc38b16e2fa
Signed-off-by: Marcus G K Williams <marcus.williams@intel.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/groovy/org')
2 files changed, 80 insertions, 46 deletions
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') |