From 9f8d92bde51a5c567a4d60011c4dec11661b338b Mon Sep 17 00:00:00 2001 From: Yulian Han Date: Tue, 9 Oct 2018 12:50:59 +0800 Subject: E2EService support model-driven resource sequence Change-Id: Idaa55084f5ecb0dd3636c232cebc14fa5f064401 Issue-ID: SO-1114 Signed-off-by: Yulian Han --- .../common/resource/ResourceRequestBuilder.java | 81 +++++++++++++++++++++- 1 file changed, 78 insertions(+), 3 deletions(-) (limited to 'bpmn/MSOCommonBPMN') 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 35bd25fabf..0cce8b3f94 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 @@ -38,6 +38,8 @@ import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.Property; +import org.onap.sdc.toscaparser.api.RequirementAssignment; +import org.onap.sdc.toscaparser.api.RequirementAssignments; import org.onap.sdc.toscaparser.api.functions.GetInput; import org.onap.sdc.toscaparser.api.parameters.Input; import org.onap.so.bpmn.core.UrnPropertiesReader; @@ -63,15 +65,88 @@ public class ResourceRequestBuilder { static JsonUtils jsonUtil = new JsonUtils(); - /** - * build the resource Parameters detail. + public static List getResourceSequence(Execution execution, String serviceUuid) { + List resouceSequence = new ArrayList(); + List resultList = new ArrayList(); + String csarpath = null; + try { + csarpath = getCsarFromUuid(serviceUuid); + + SdcToscaParserFactory toscaParser = SdcToscaParserFactory.getInstance(); + ISdcCsarHelper iSdcCsarHelper = toscaParser.getSdcCsarHelper(csarpath, false); + List nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates(); + List nodes = new ArrayList(); + nodes.addAll(nodeTemplates); + + for (NodeTemplate nodeTemplate : nodeTemplates) { + RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate); + + if (requirement == null || requirement.getAll() == null || requirement.getAll().isEmpty()) { + resultList.add(nodeTemplate); + nodes.remove(nodeTemplate); + } + } + + resultList = getRequirementList(resultList, nodes, iSdcCsarHelper); + + for (NodeTemplate node : resultList) { + String templateName = node.getMetaData().getValue("name"); + if (!resouceSequence.contains(templateName)) { + resouceSequence.add(templateName); + } + } + + } catch (SdcToscaParserException toscarParserE) { + LOGGER.debug("sdc tosca parser failed for csar: " + csarpath, toscarParserE); + return resouceSequence; + } catch (Exception e) { + LOGGER.debug("csar file is not available for service uuid:" + serviceUuid, e); + return resouceSequence; + } + + return resouceSequence; + } + + private static List getRequirementList(List resultList, List nodeTemplates, + ISdcCsarHelper iSdcCsarHelper) { + + List nodes = new ArrayList(); + nodes.addAll(nodeTemplates); + + for (NodeTemplate nodeTemplate : nodeTemplates) { + RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate); + List reqAs = requirement.getAll(); + for (RequirementAssignment ra : reqAs) { + String reqNode = ra.getNodeTemplateName(); + for (NodeTemplate rNode : resultList) { + if (rNode.getName().equals(reqNode)) { + if(!resultList.contains(nodeTemplate)) { + resultList.add(nodeTemplate); + } + if(nodes.contains(nodeTemplate)) { + nodes.remove(nodeTemplate); + } + break; + } + } + } + } + + if (!nodes.isEmpty()) { + getRequirementList(resultList, nodes, iSdcCsarHelper); + } + + return resultList; + } + + /* build the resource Parameters detail. * It's a json string for resource instantiant * { * "locationConstraints":[...] * "requestInputs":{K,V} * } *
- * + * * @param execution Execution context * @param serviceUuid The service template uuid * @param resourceCustomizationUuid The resource customization uuid -- cgit 1.2.3-korg