diff options
author | liboNet <libo.zhu@intel.com> | 2018-09-15 12:29:04 +0800 |
---|---|---|
committer | liboNet <libo.zhu@intel.com> | 2018-09-15 14:37:27 +0800 |
commit | 41fc409d63322291ed3d5de95cc948ca024c6f6d (patch) | |
tree | 9073c3a0136ac50a1076ac4b065fc50f6660c221 /plugins/reception-plugins/src/main | |
parent | dbffbe7e96ae04ca75f0bb143c483c284cd88cb8 (diff) |
Adding more hpa feature support for Polices
* Add hugePage feature parse
* Add SRIOV feature parse
* Add pciePassthrough feature parse
* Add more test cases and resources
Change-Id: Ib45515a26e3fdac742a631b3a13d739fd1784d2f
Issue-ID: POLICY-927
Signed-off-by: liboNet <libo.zhu@intel.com>
Diffstat (limited to 'plugins/reception-plugins/src/main')
2 files changed, 131 insertions, 30 deletions
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java index 4e7f9411..1d0f621b 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java @@ -20,16 +20,19 @@ package org.onap.policy.distribution.reception.decoding.pdpx; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - import java.io.FileWriter; import java.io.Writer; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; @@ -37,6 +40,8 @@ import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.CapabilityAssignment; import org.onap.sdc.toscaparser.api.CapabilityAssignments; import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.RequirementAssignment; +import org.onap.sdc.toscaparser.api.elements.Metadata; /** * Extract concerned info from NodeTemplate, currently ONLY HPA Feature. @@ -51,7 +56,17 @@ public class ExtractFromNode { private static final String VIRTUAL_MEM_SIZE_PATH = "virtual_memory#virtual_mem_size"; private static final String NUM_VIRTUAL_CPU_PATH = "virtual_cpu#num_virtual_cpu"; private static final String CPU_ARCHITECTURE_PATH = "virtual_cpu#cpu_architecture"; - private static final String BASIC_CAPABILITIES = "BasicCapabilities"; + private static final String MEMORY_PAGE_SIZE_PATH = "virtual_memory#vdu_memory_requirements#memoryPageSize"; + private static final String NETWORK_INTERFACE_TYPE_PATH = + "virtual_network_interface_requirements#network_interface_requirements#interfaceType"; + private static final String NETWORK_PCI_PATH = + "virtual_network_interface_requirements#nic_io_requirements"; + private static final String BASIC_CAPABILITIES_HPA_FEATURE = "BasicCapabilities"; + private static final String HUGE_PAGES_HPA_FEATURE = "hugePages"; + private static final Map<String, String> NETWORK_HPA_FEATURE_MAP = new HashMap() {{ + put("SR-IOV", "SriovNICNetwork"); + put("PCI-Passthrough", "pciePassthrough"); + }}; ISdcCsarHelper sdcCsarHelper; final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().disableHtmlEscaping().create(); @@ -136,7 +151,7 @@ public class ExtractFromNode { capabilityAssignments.getCapabilityByName("virtual_compute"); if (capabilityAssignment != null) { generateBasicCapability(capabilityAssignment, flavorFeature); - generateHugePages(capabilityAssignment); + generateHugePages(capabilityAssignment,flavorFeature); } content.getFlavorFeatures().add(flavorFeature); } @@ -148,31 +163,29 @@ public class ExtractFromNode { * @param capabilityAssignment represents the capability of node * @param flavorFeature represents all the features of specified flavor */ - private void generateBasicCapability(final CapabilityAssignment capabilityAssignment, - final FlavorFeature flavorFeature) { - // the format is xxx MB/GB like 4096 MB - final String virtualMemSize = - sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, VIRTUAL_MEM_SIZE_PATH); + private void generateBasicCapability(final CapabilityAssignment capabilityAssignment, FlavorFeature flavorFeature){ + //the format is xxx MB/GB like 4096 MB + String virtualMemSize = sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, + VIRTUAL_MEM_SIZE_PATH); if (virtualMemSize != null) { LOGGER.debug("the virtualMemSize = " + virtualMemSize); - final HpaFeatureAttribute hpaFeatureAttribute = - generateHpaFeatureAttribute("virtualMemSize", virtualMemSize); - final FlavorProperty flavorProperty = new FlavorProperty(); - flavorProperty.setHpaFeature(BASIC_CAPABILITIES); + HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute("virtualMemSize", virtualMemSize); + FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(BASIC_CAPABILITIES_HPA_FEATURE); flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); flavorFeature.getFlavorProperties().add(flavorProperty); } - - // the format is int like 2 - final String numVirtualCpu = - sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, NUM_VIRTUAL_CPU_PATH); + + //the format is int like 2 + String numVirtualCpu = sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, + NUM_VIRTUAL_CPU_PATH); if (numVirtualCpu != null) { LOGGER.debug("the numVirtualCpu = " + numVirtualCpu); - final HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute("numVirtualCpu", numVirtualCpu); - final String cpuArchitecture = - sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, CPU_ARCHITECTURE_PATH); - final FlavorProperty flavorProperty = new FlavorProperty(); - flavorProperty.setHpaFeature(BASIC_CAPABILITIES); + HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute("numVirtualCpu", numVirtualCpu); + String cpuArchitecture = sdcCsarHelper.getCapabilityPropertyLeafValue + (capabilityAssignment,CPU_ARCHITECTURE_PATH); + FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(BASIC_CAPABILITIES_HPA_FEATURE); if (cpuArchitecture != null) { flavorProperty.setArchitecture(cpuArchitecture); } @@ -189,7 +202,7 @@ public class ExtractFromNode { * @param featureValue get from the high layer tosca DM */ private HpaFeatureAttribute generateHpaFeatureAttribute(final String hpaAttributeKey, final String featureValue) { - + //based on input featureValue, return back a suitable hpaFeatureAttribute final HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); hpaFeatureAttribute.setHpaAttributeKey(hpaAttributeKey); final String tmp = featureValue.replace(" ", ""); @@ -215,8 +228,26 @@ public class ExtractFromNode { * @param capabilityAssignment represents the capability of node * @param flavorFeature represents all the features of specified flavor */ - private void generateHugePages(final CapabilityAssignment capabilityAssignment) { - // add HugePages support + private void generateHugePages(final CapabilityAssignment capabilityAssignment, FlavorFeature flavorFeature){ + String memoryPageSize = sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, + MEMORY_PAGE_SIZE_PATH); + LOGGER.debug("the memoryPageSize = " + memoryPageSize); + if (memoryPageSize != null) { + Map<String, Object> retMap = gson.fromJson(memoryPageSize, + new TypeToken<HashMap<String, Object>>() {}.getType()); + LOGGER.debug("the retMap = " + retMap); + String memoryPageSizeValue = retMap.get("configuration-value").toString(); + String mandatory = retMap.get("mandatory").toString(); + HpaFeatureAttribute hpaFeatureAttribute = + generateHpaFeatureAttribute("memoryPageSize",memoryPageSizeValue); + FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(HUGE_PAGES_HPA_FEATURE); + if (mandatory != null) { + flavorProperty.setMandatory(mandatory); + } + flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); + flavorFeature.getFlavorProperties().add(flavorProperty); + } } /** @@ -225,9 +256,79 @@ public class ExtractFromNode { * * @param lnodeVduCp the list of VduCp node * @param content to be change based on lnodeVduCp + * @throws PolicyDecodingException if extract CP fails */ - public void extractInfoVduCp(final List<NodeTemplate> lnodeVduCp, final Content content) { - // to add VDU cp Hpa feature extract - } + public void extractInfoVduCp(final List<NodeTemplate> lnodeVduCp, Content content) throws PolicyDecodingException { + // each CP will binds to a VDU so need the vdu flavor map info. + Map<String, FlavorFeature> vduFlavorMap = new HashMap<>(); + for ( FlavorFeature flavorFeature: content.getFlavorFeatures()) { + LOGGER.debug("the id = " + flavorFeature.getId()); + vduFlavorMap.put(flavorFeature.getId(),flavorFeature); + } + for ( NodeTemplate node : lnodeVduCp) { + String interfaceType = sdcCsarHelper.getNodeTemplatePropertyLeafValue(node,NETWORK_INTERFACE_TYPE_PATH); + LOGGER.debug("the interfaceType = " + interfaceType); + Map<String, Object> retMap = new HashMap<>(); + if (interfaceType != null) { + retMap = gson.fromJson(interfaceType, new TypeToken<HashMap<String, Object>>() {}.getType()); + LOGGER.debug("the retMap = " + retMap); + } + + String networkHpaFeature; + if ( retMap.containsKey("configuration-value")) { + String interfaceTypeValue = retMap.get("configuration-value").toString(); + LOGGER.debug(" the interfacetype value is =" + interfaceTypeValue); + if ( NETWORK_HPA_FEATURE_MAP.containsKey(interfaceTypeValue)) { + networkHpaFeature = NETWORK_HPA_FEATURE_MAP.get(interfaceTypeValue); + LOGGER.debug(" the networkHpaFeature is =" + networkHpaFeature); + } else { + LOGGER.debug(" unspported network interface "); + return; + } + }else{ + LOGGER.debug(" no configuration-value defined in interfaceType"); + return; + } + + for (RequirementAssignment requriement: sdcCsarHelper.getRequirementsOf(node).getAll()) { + String nodeTemplateName = requriement.getNodeTemplateName().toLowerCase(); + LOGGER.debug("getNodeTemplateName =" + nodeTemplateName); + if ( nodeTemplateName == null) { + continue; + } + if (!vduFlavorMap.containsKey(nodeTemplateName)) { + throw new PolicyDecodingException("vdu Flavor Map should contains the key " + nodeTemplateName); + } + generateNetworkFeature(networkHpaFeature, node, vduFlavorMap.get(nodeTemplateName)); + } + } + } + /* + * GenerateNetworkFeature, all pci feature are grouped into FlavorFeature together. + * + * @param networkHpaFeature represents the specified Hpa feature + * @param node represents the CP Node + * @param flavorFeature represents all the features of specified flavor + */ + private void generateNetworkFeature(final String networkHpaFeature, final NodeTemplate node, FlavorFeature flavorFeature) { + //the format is a map like: {"schema-version": "0", "schema-location": "", "platform-id": "generic", + // "mandatory": true, "configuration-value": "2 MB"} + FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(networkHpaFeature); + String[] pciKeys = { "pciVendorId", "pciDeviceId", "pciNumDevices", "physicalNetwork"}; + for (String pciKey: pciKeys) { + LOGGER.debug("the pciKey = " + pciKey); + String pciKeyPath = NETWORK_PCI_PATH + "#" + pciKey; + String pciValue = sdcCsarHelper.getNodeTemplatePropertyLeafValue(node,pciKeyPath); + if (pciValue != null) { + LOGGER.debug("the pciValue = " + pciValue); + Map<String, Object> retMap = gson.fromJson(pciValue, new TypeToken<HashMap<String, Object>>() {}.getType()); + String pciConfigValue = retMap.get("configuration-value").toString(); + HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute(pciKey,pciConfigValue); + flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); + } + } + flavorFeature.getFlavorProperties().add(flavorProperty); + } } diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java index 1617956f..91008aa5 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java @@ -30,7 +30,7 @@ import com.google.gson.annotations.SerializedName; class HpaFeatureAttribute { @SerializedName(value = "hpa-attribute-key") private String hpaAttributeKey; - @SerializedName(value = "hap-attribute-value") + @SerializedName(value = "hpa-attribute-value") private String hpaAttributeValue; private String operator; private String unit; |