From ccc3e28512988345e640097381d2ae0be46fe986 Mon Sep 17 00:00:00 2001 From: Ram Krishna Verma Date: Mon, 2 Mar 2020 15:27:21 -0500 Subject: Remove policy/engine & apex dependency from distribution Issue-ID: POLICY-2404 Change-Id: Ia3084c55ea65a3119354079d9afd3ee35689b7d4 Signed-off-by: Ram Krishna Verma --- .../reception/decoding/hpa/Attribute.java | 52 +++ .../reception/decoding/hpa/Content.java | 42 +++ .../reception/decoding/hpa/Directive.java | 49 +++ .../reception/decoding/hpa/ExtractFromNode.java | 365 +++++++++++++++++++++ .../reception/decoding/hpa/FlavorFeature.java | 61 ++++ .../reception/decoding/hpa/FlavorProperty.java | 84 +++++ .../decoding/hpa/HpaFeatureAttribute.java | 71 ++++ .../decoding/hpa/PolicyDecoderCsarHpa.java | 124 +++++++ .../hpa/PolicyDecoderCsarHpaParameters.java | 49 +++ .../reception/decoding/pdpx/Attribute.java | 52 --- .../reception/decoding/pdpx/ConfigBody.java | 115 ------- .../reception/decoding/pdpx/Content.java | 42 --- .../reception/decoding/pdpx/Directive.java | 49 --- .../reception/decoding/pdpx/ExtractFromNode.java | 361 -------------------- .../reception/decoding/pdpx/FlavorFeature.java | 61 ---- .../reception/decoding/pdpx/FlavorProperty.java | 84 ----- .../decoding/pdpx/HpaFeatureAttribute.java | 71 ---- .../reception/decoding/pdpx/PdpxPolicy.java | 127 ------- .../decoding/pdpx/PolicyDecoderCsarPdpx.java | 122 ------- ...DecoderCsarPdpxConfigurationParameterGroup.java | 49 --- .../pdpx/PolicyDecoderCsarPdpxLifecycleApi.java | 132 -------- ...olicyDecoderCsarPdpxLifecycleApiParameters.java | 49 --- 22 files changed, 897 insertions(+), 1314 deletions(-) create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Attribute.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Content.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Directive.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/ExtractFromNode.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorFeature.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorProperty.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/HpaFeatureAttribute.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpa.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpaParameters.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Attribute.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ConfigBody.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Content.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Directive.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorFeature.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorProperty.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PdpxPolicy.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterGroup.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApiParameters.java (limited to 'plugins/reception-plugins/src/main/java/org') diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Attribute.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Attribute.java new file mode 100644 index 00000000..37f79f6b --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Attribute.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import com.google.gson.annotations.SerializedName; + +/** + * The attribute acts an abstraction belonging to or characteristic of an directive. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +class Attribute { + @SerializedName(value = "attribute_name") + private String attributeName; + @SerializedName(value = "attribute_value") + private String attributeValue; + + public void setAttributeName(final String attributeName) { + this.attributeName = attributeName; + } + + public String getAttributeName() { + return attributeName; + } + + public void setAttributeValue(final String attributeValue) { + this.attributeValue = attributeValue; + } + + public String getAttributeValue() { + return attributeValue; + } +} + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Content.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Content.java new file mode 100644 index 00000000..a6e70bd9 --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Content.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import java.util.ArrayList; +import java.util.List; +import lombok.Data; + +/** + * The content acts the high level abstraction which to be used by OOF to do Optimization. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +@Data +class Content { + private List scope = new ArrayList<>(); /* keep scope as empty for now */ + private List services = new ArrayList<>(); + private List resources = new ArrayList<>(); + private List geography = new ArrayList<>(); /* keep geography as empty for now */ + private String identity; + private List policyScope = new ArrayList<>(); + private String policyType = "Optimization"; + private List flavorFeatures = new ArrayList<>(); +} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Directive.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Directive.java new file mode 100644 index 00000000..87889cc1 --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Directive.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import java.util.ArrayList; +import java.util.List; + + +/** + * The attribute acts an abstraction to indicate OOF which supports two different Models (Heat and TOSCA), two areas are + * wrapped: in the VNFC level to indicate the flavor, in the hpa_feature level to contains specified information. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +class Directive { + private String type; + private List attributes = new ArrayList<>(); + + public void setType(final String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public List getAttributes() { + return attributes; + } +} + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/ExtractFromNode.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/ExtractFromNode.java new file mode 100644 index 00000000..0406020c --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/ExtractFromNode.java @@ -0,0 +1,365 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import com.google.common.collect.ImmutableMap; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +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.RequirementAssignments; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Extract concerned info from NodeTemplate, currently ONLY HPA Feature. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +public class ExtractFromNode { + + private static final Logger LOGGER = LoggerFactory.getLogger(ExtractFromNode.class); + + private static final String CONFIGURATION_VALUE = "configurationValue"; + private static final String VDU_TYPE = "tosca.nodes.nfv.Vdu.Compute"; + private static final String VDU_CP_TYPE = "tosca.nodes.nfv.VduCp"; + 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 MEMORY_PAGE_SIZE_PATH = "virtual_memory#vdu_mem_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#logical_node_requirements"; + private static final String BASIC_CAPABILITIES_HPA_FEATURE = "basicCapabilities"; + private static final String HUGE_PAGES_HPA_FEATURE = "hugePages"; + private static final Map NETWORK_HPA_FEATURE_MAP = + ImmutableMap.of("SR-IOV", "sriovNICNetwork", "PCI-Passthrough", "pciePassthrough"); + private static final Pattern PATTERN = Pattern.compile("(\\D*)(\\d+)(\\D*)"); + private ISdcCsarHelper sdcCsarHelper; + final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().disableHtmlEscaping().create(); + + public void setSdcCsarHelper(final ISdcCsarHelper sdcCsarHelper) { + this.sdcCsarHelper = sdcCsarHelper; + } + + /** + * ExtractInfo from VNF , each VNF may includes more than one VDUs and CPs return new + * generated OptimizationPolicy if it has got Hpa feature info or else return null. + * + * @param node the NodeTemplate + * + * @return the extracted info from input node + * + * @throws PolicyDecodingException if extract fails + */ + public Content extractInfo(final NodeTemplate node) throws PolicyDecodingException { + final Metadata metaData = sdcCsarHelper.getNodeTemplateMetadata(node); + final Metadata metaDataOfService = sdcCsarHelper.getServiceMetadata(); + LOGGER.debug("the meta data of this nodetemplate = {}", metaData); + final List lnodeChild = sdcCsarHelper.getNodeTemplateChildren(node); + LOGGER.debug("the size of lnodeChild = {}", lnodeChild.size()); + + // Store all the VDUs under one VNF + final List lnodeVdu = new ArrayList<>(); + // Store all the Cps under one VNF + final List lnodeVduCp = new ArrayList<>(); + for (final NodeTemplate nodeChild : lnodeChild) { + final String type = sdcCsarHelper.getTypeOfNodeTemplate(nodeChild); + LOGGER.debug("the type of this nodeChild = {}", type); + LOGGER.debug("the meta data of this nodeChild = {}", sdcCsarHelper.getNodeTemplateMetadata(nodeChild)); + if (type.equalsIgnoreCase(VDU_TYPE)) { + lnodeVdu.add(nodeChild); + } else if (type.equalsIgnoreCase(VDU_CP_TYPE)) { + lnodeVduCp.add(nodeChild); + } + } + LOGGER.debug("the size of vdu is = {}", lnodeVdu.size()); + LOGGER.debug("the size of cp is = {}", lnodeVduCp.size()); + + final Content content = new Content(); + content.getResources().add(metaData.getValue("name")); + content.getServices().add(metaDataOfService.getValue("name")); + content.setIdentity(content.getPolicyType() + "_" + metaData.getValue("name")); + extractInfoVdu(lnodeVdu, content); + extractInfoVduCp(lnodeVduCp, content); + if (content.getFlavorFeatures().isEmpty()) { + return null; + } + return content; + } + + + /** + * ExtractInfofromVdu, supported hpa features, All under the capability of + * tosca.nodes.nfv.Vdu.Compute. + * + * @param lnodeVdu the list of Vdu node + * + * @param content to be change based on lnodeVdu + */ + public void extractInfoVdu(final List lnodeVdu, final Content content) { + // each VDU <=> FlavorFeature + for (final NodeTemplate node : lnodeVdu) { + final Attribute flavorAttribute = new Attribute(); + flavorAttribute.setAttributeName("flavorName"); + flavorAttribute.setAttributeValue(""); + final Directive flavorDirective = new Directive(); + flavorDirective.setType("flavor_directives"); + flavorDirective.getAttributes().add(flavorAttribute); + final FlavorFeature flavorFeature = new FlavorFeature(); + flavorFeature.setId(node.toString()); + LOGGER.debug("the name of node = {}", node); + flavorFeature.getDirectives().add(flavorDirective); + + final CapabilityAssignments capabilityAssignments = sdcCsarHelper.getCapabilitiesOf(node); + final CapabilityAssignment capabilityAssignment = + capabilityAssignments.getCapabilityByName("virtual_compute"); + if (capabilityAssignment != null) { + generateBasicCapability(capabilityAssignment, flavorFeature); + generateHugePages(capabilityAssignment, flavorFeature); + } + content.getFlavorFeatures().add(flavorFeature); + } + } + + /** + * GenerateBasicCapability, supported hpa features, All under the capability of + * tosca.nodes.nfv.Vdu.Compute. + * + * @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); + if (virtualMemSize != null) { + LOGGER.debug("the virtualMemSize = {}", virtualMemSize); + final HpaFeatureAttribute hpaFeatureAttribute = + generateHpaFeatureAttribute("virtualMemSize", virtualMemSize); + final 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); + 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_HPA_FEATURE); + if (cpuArchitecture != null) { + flavorProperty.setArchitecture(cpuArchitecture); + } + flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); + flavorFeature.getFlavorProperties().add(flavorProperty); + } + } + + /** + * GenerateHpaFeatureAttribute based on the value of featureValue. the format: + * "hpa-attribute-key": "pciVendorId", "hpa-attribute-value": "1234", "operator": "=", + * "unit": "xxx". + * + * @param hpaAttributeKey get from the high layer tosca DM + * + * @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 modifiedValue = featureValue.replace(" ", ""); + final Matcher matcher = PATTERN.matcher(modifiedValue); + if (matcher.find()) { + final String matcher1 = matcher.group(1); + final String matcher2 = matcher.group(2); + final String matcher3 = matcher.group(3); + LOGGER.debug("operator {} , value = {} , unit = {}", matcher1, matcher2, matcher3); + if (matcher.group(1).length() == 0) { + hpaFeatureAttribute.setOperator("="); + } else { + hpaFeatureAttribute.setOperator(matcher1); + } + hpaFeatureAttribute.setHpaAttributeValue(matcher2); + hpaFeatureAttribute.setUnit(matcher3); + } + return hpaFeatureAttribute; + } + + /** + * GenerateHugePages, supported hpa features, All under the capability of + * tosca.nodes.nfv.Vdu.Compute. The format is a map like: {"schemaVersion": "0", + * "schemaSelector": "", "hardwarePlatform": "generic", "mandatory": "true", + * "configurationValue": "2 MB"} + * + * @param capabilityAssignment represents the capability of node + * + * @param flavorFeature represents all the features of specified flavor + */ + private void generateHugePages(final CapabilityAssignment capabilityAssignment, final FlavorFeature flavorFeature) { + final String memoryPageSize = + sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, MEMORY_PAGE_SIZE_PATH); + LOGGER.debug("the memoryPageSize = {}", memoryPageSize); + if (memoryPageSize != null) { + final Map retMap = + gson.fromJson(memoryPageSize, new TypeToken>() {}.getType()); + LOGGER.debug("the retMap = {}", retMap); + final String memoryPageSizeValue = retMap.get(CONFIGURATION_VALUE); + final String mandatory = retMap.get("mandatory"); + if (memoryPageSizeValue == null) { + return; + } + final HpaFeatureAttribute hpaFeatureAttribute = + generateHpaFeatureAttribute("memoryPageSize", memoryPageSizeValue); + final FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(HUGE_PAGES_HPA_FEATURE); + if (mandatory != null) { + flavorProperty.setMandatory(mandatory); + } + flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); + flavorFeature.getFlavorProperties().add(flavorProperty); + } + } + + /** + * ExtractInfoVduCp, supported hpa features, under the + * virtual_network_interface_requirements of tosca.nodes.nfv.VduCp. + * + * @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 lnodeVduCp, final Content content) + throws PolicyDecodingException { + // each CP will binds to a VDU so need the vdu flavor map info. + final Map vduFlavorMap = new HashMap<>(); + for (final FlavorFeature flavorFeature : content.getFlavorFeatures()) { + LOGGER.debug("the id = {}", flavorFeature.getId()); + vduFlavorMap.put(flavorFeature.getId(), flavorFeature); + } + parseNodeVduCp(lnodeVduCp, vduFlavorMap); + } + + /** + * Parse the VduCp list. + * + * @param lnodeVduCp the lnodeVduCp + * @param vduFlavorMap the vduFlavorMap + * @throws PolicyDecodingException if any error occurs + */ + private void parseNodeVduCp(final List lnodeVduCp, final Map vduFlavorMap) + throws PolicyDecodingException { + for (final NodeTemplate node : lnodeVduCp) { + final String interfaceType = + sdcCsarHelper.getNodeTemplatePropertyLeafValue(node, NETWORK_INTERFACE_TYPE_PATH); + LOGGER.debug("the interfaceType = {}", interfaceType); + Map retMap = new HashMap<>(); + if (interfaceType != null) { + retMap = gson.fromJson(interfaceType, new TypeToken>() {}.getType()); + LOGGER.debug("the retMap = {}", retMap); + } + + String networkHpaFeature; + if (retMap.containsKey(CONFIGURATION_VALUE) + && NETWORK_HPA_FEATURE_MAP.containsKey(retMap.get(CONFIGURATION_VALUE).toString())) { + final String interfaceTypeValue = retMap.get(CONFIGURATION_VALUE).toString(); + networkHpaFeature = NETWORK_HPA_FEATURE_MAP.get(interfaceTypeValue); + LOGGER.debug(" the networkHpaFeature is = {}", networkHpaFeature); + } else { + LOGGER.debug(" no networkHpaFeature defined in interfaceType"); + continue; + } + + final RequirementAssignments requriements = + sdcCsarHelper.getRequirementsOf(node).getRequirementsByName("virtual_binding"); + for (final RequirementAssignment requriement : requriements.getAll()) { + final String nodeTemplateName = requriement.getNodeTemplateName(); + 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. + * The format is a map like: {"schemaVersion": "0", "schemaSelector": "", + * "hardwarePlatform": "generic", "mandatory": "true", "configurationValue": "2 MB"} + * + * @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, + final FlavorFeature flavorFeature) { + final FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(networkHpaFeature); + final String[] pciKeys = {"pciVendorId", "pciDeviceId", "pciNumDevices", "physicalNetwork"}; + for (final String pciKey : pciKeys) { + LOGGER.debug("the pciKey = {}", pciKey); + final String pciKeyPath = NETWORK_PCI_PATH + "#" + pciKey; + final String pciValue = sdcCsarHelper.getNodeTemplatePropertyLeafValue(node, pciKeyPath); + if (pciValue != null) { + LOGGER.debug("the pciValue = {}", pciValue); + final Map retMap = + gson.fromJson(pciValue, new TypeToken>() {}.getType()); + final String pciConfigValue = retMap.get(CONFIGURATION_VALUE); + if (pciConfigValue == null) { + return; + } + final 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/hpa/FlavorFeature.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorFeature.java new file mode 100644 index 00000000..75643a72 --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorFeature.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import java.util.ArrayList; +import java.util.List; + +/** + * The FlavorFeature includes all the specified flavor infos used in multicloud, it represents one VDU of TOSCA. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +class FlavorFeature { + private String id; + private String type = "tosca.nodes.nfv.Vdu.Compute"; + private List directives = new ArrayList<>(); + private List flavorProperties = new ArrayList<>(); + + public void setId(final String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setType(final String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public List getFlavorProperties() { + return flavorProperties; + } + + public List getDirectives() { + return directives; + } +} + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorProperty.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorProperty.java new file mode 100644 index 00000000..f849ebaa --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorProperty.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import com.google.gson.annotations.SerializedName; + +import java.util.ArrayList; +import java.util.List; + +/** + * The FlavorProperty includes all the properties of Flavor. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +class FlavorProperty { + @SerializedName(value = "hpa-feature") + private String hpaFeature; + private String mandatory = "True"; + private String architecture = "generic"; + @SerializedName(value = "hpa-version") + private String hpaVersion = "v1"; + private List directives = new ArrayList<>(); + @SerializedName(value = "hpa-feature-attributes") + private List hpaFeatureAttributes = new ArrayList<>(); + + public void setHpaFeature(final String hpaFeature) { + this.hpaFeature = hpaFeature; + } + + public String getHpaFeature() { + return hpaFeature; + } + + public void setMandatory(final String mandatory) { + this.mandatory = mandatory; + } + + public String getMandatory() { + return mandatory; + } + + public void setArchitecture(final String architecture) { + this.architecture = architecture; + } + + public String getArchitecture() { + return architecture; + } + + public void setHpaVersion(final String hpaVersion) { + this.hpaVersion = hpaVersion; + } + + public String getHpaVersion() { + return hpaVersion; + } + + public List getDirectives() { + return directives; + } + + public List getHpaFeatureAttributes() { + return hpaFeatureAttributes; + } +} + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/HpaFeatureAttribute.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/HpaFeatureAttribute.java new file mode 100644 index 00000000..8bb078ad --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/HpaFeatureAttribute.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import com.google.gson.annotations.SerializedName; + +/** + * The HpaFeatureAttribute represents a way to provide match expression. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +class HpaFeatureAttribute { + @SerializedName(value = "hpa-attribute-key") + private String hpaAttributeKey; + @SerializedName(value = "hpa-attribute-value") + private String hpaAttributeValue; + private String operator; + private String unit; + + public void setHpaAttributeKey(final String hpaAttributeKey) { + this.hpaAttributeKey = hpaAttributeKey; + } + + public String getHpaAttributeKey() { + return hpaAttributeKey; + } + + public void setHpaAttributeValue(final String hpaAttributeValue) { + this.hpaAttributeValue = hpaAttributeValue; + } + + public String getHpaAttributeValue() { + return hpaAttributeValue; + } + + public void setOperator(final String operator) { + this.operator = operator; + } + + public String getOperator() { + return operator; + } + + public void setUnit(final String unit) { + this.unit = unit; + } + + public String getUnit() { + return unit; + } +} + + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpa.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpa.java new file mode 100644 index 00000000..e1e1a9a9 --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpa.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.distribution.model.Csar; +import org.onap.policy.distribution.model.PolicyInput; +import org.onap.policy.distribution.reception.decoding.PolicyDecoder; +import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Decodes PDP-X policies from a CSAR file and creates ToscaServiceTemplate for Policy Lifecycle API's. + */ +public class PolicyDecoderCsarHpa implements PolicyDecoder { + + private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderCsarHpa.class); + private PolicyDecoderCsarHpaParameters decoderParameters; + + public static final String TOSCA_POLICY_SCOPE = "scope"; + public static final String TOSCA_POLICY_SERVICES = "services"; + public static final String TOSCA_POLICY_RESOURCES = "resources"; + public static final String TOSCA_POLICY_IDENTITY = "identity"; + public static final String TOSCA_POLICY_FLAVORFEATURES = "flavorfeatures"; + + public static final String TOSCA_POLICY_HPA_OOF = "Optimization"; + + @Override + public Collection decode(final Csar csar) throws PolicyDecodingException { + final List entities = new ArrayList<>(); + final ISdcCsarHelper sdcCsarHelper = parseCsar(csar); + final List lnodeVf = sdcCsarHelper.getServiceVfList(); + LOGGER.debug("the size of Vf = {}", lnodeVf.size()); + final ExtractFromNode extractFromNode = new ExtractFromNode(); + extractFromNode.setSdcCsarHelper(sdcCsarHelper); + final String serviceName = sdcCsarHelper.getServiceMetadata().getValue("name"); + LOGGER.debug("the name of the service = {}", serviceName); + for (final NodeTemplate node : lnodeVf) { + final Content content = extractFromNode.extractInfo(node); + if (content != null) { + final ToscaServiceTemplate entity = new ToscaServiceTemplate(); + Map props = new LinkedHashMap<>(); + props.put(TOSCA_POLICY_SCOPE, content.getScope()); + props.put(TOSCA_POLICY_SERVICES, content.getServices()); + props.put(TOSCA_POLICY_RESOURCES, content.getResources()); + props.put(TOSCA_POLICY_IDENTITY, content.getIdentity()); + props.put(TOSCA_POLICY_FLAVORFEATURES, content.getFlavorFeatures()); + ToscaPolicy policy = new ToscaPolicy(); + policy.setProperties(props); + Map map = new LinkedHashMap<>(); + String type = content.getPolicyType(); + map.put(type, policy); + List> policies = new ArrayList<>(); + policies.add(map); + ToscaTopologyTemplate topologyTemplate = new ToscaTopologyTemplate(); + topologyTemplate.setPolicies(policies); + entity.setToscaTopologyTemplate(topologyTemplate); + entities.add(entity); + } + } + return entities; + } + + @Override + public boolean canHandle(final PolicyInput policyInput) { + return Csar.class.isAssignableFrom(policyInput.getClass()); + } + + /** + * Parse the input Csar using SDC TOSCA parser. + * + * @param csar represents the service TOSCA Csar + * @return the object to represents the content of input csar + * @throws PolicyDecodingException if parse fails + */ + public ISdcCsarHelper parseCsar(final Csar csar) throws PolicyDecodingException { + ISdcCsarHelper sdcCsarHelper; + try { + final SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); + LOGGER.debug("Csar File Path = {}", csar.getCsarPath()); + final File csarFile = new File(csar.getCsarPath()); + sdcCsarHelper = factory.getSdcCsarHelper(csarFile.getAbsolutePath()); + } catch (final Exception exp) { + throw new PolicyDecodingException( "Failed passing the csar file", exp); + } + return sdcCsarHelper; + } + + @Override + public void configure(final String parameterGroupName) { + decoderParameters = ParameterService.get(parameterGroupName); + } +} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpaParameters.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpaParameters.java new file mode 100644 index 00000000..7d26335c --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpaParameters.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import lombok.Getter; + +import org.onap.policy.common.parameters.annotations.NotBlank; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup; + +/** + * This class handles the parameters needed for {@link PolicyDecoderCsarHpa}. + */ +@Getter +@NotNull +@NotBlank +public class PolicyDecoderCsarHpaParameters extends PolicyDecoderConfigurationParameterGroup { + + private String policyNamePrefix; + private String onapName; + private String version; + private String priority; + private String riskType; + private String riskLevel; + + public PolicyDecoderCsarHpaParameters() { + super(PolicyDecoderCsarHpaParameters.class.getSimpleName()); + } +} + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Attribute.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Attribute.java deleted file mode 100644 index 9962894e..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Attribute.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import com.google.gson.annotations.SerializedName; - -/** - * The attribute acts an abstraction belonging to or characteristic of an directive. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -class Attribute { - @SerializedName(value = "attribute_name") - private String attributeName; - @SerializedName(value = "attribute_value") - private String attributeValue; - - public void setAttributeName(final String attributeName) { - this.attributeName = attributeName; - } - - public String getAttributeName() { - return attributeName; - } - - public void setAttributeValue(final String attributeValue) { - this.attributeValue = attributeValue; - } - - public String getAttributeValue() { - return attributeValue; - } -} - diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ConfigBody.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ConfigBody.java deleted file mode 100644 index 521fcfd6..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ConfigBody.java +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -public class ConfigBody { - - private String service; - private String policyName; - private String description; - private String templateVersion; - private String version; - private String priority; - private String riskType; - private String riskLevel; - private String guard; - private Content content; - - public String getService() { - return service; - } - - public void setService(String service) { - this.service = service; - } - - public String getPolicyName() { - return policyName; - } - - public void setPolicyName(String policyName) { - this.policyName = policyName; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getTemplateVersion() { - return templateVersion; - } - - public void setTemplateVersion(String templateVersion) { - this.templateVersion = templateVersion; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getPriority() { - return priority; - } - - public void setPriority(String priority) { - this.priority = priority; - } - - public String getRiskType() { - return riskType; - } - - public void setRiskType(String riskType) { - this.riskType = riskType; - } - - public String getRiskLevel() { - return riskLevel; - } - - public void setRiskLevel(String riskLevel) { - this.riskLevel = riskLevel; - } - - public String getGuard() { - return guard; - } - - public void setGuard(String guard) { - this.guard = guard; - } - - public Content getContent() { - return content; - } - - public void setContent(Content content) { - this.content = content; - } -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Content.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Content.java deleted file mode 100644 index ef4584cb..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Content.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import java.util.ArrayList; -import java.util.List; -import lombok.Data; - -/** - * The content acts the high level abstraction which to be used by OOF to do Optimization. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -@Data -class Content { - private List scope = new ArrayList<>(); /* keep scope as empty for now */ - private List services = new ArrayList<>(); - private List resources = new ArrayList<>(); - private List geography = new ArrayList<>(); /* keep geography as empty for now */ - private String identity; - private List policyScope = new ArrayList<>(); - private String policyType = "Optimization"; - private List flavorFeatures = new ArrayList<>(); -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Directive.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Directive.java deleted file mode 100644 index 6df5bc38..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Directive.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import java.util.ArrayList; -import java.util.List; - - -/** - * The attribute acts an abstraction to indicate OOF which supports two different Models (Heat and TOSCA), two areas are - * wrapped: in the VNFC level to indicate the flavor, in the hpa_feature level to contains specified information. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -class Directive { - private String type; - private List attributes = new ArrayList<>(); - - public void setType(final String type) { - this.type = type; - } - - public String getType() { - return type; - } - - public List getAttributes() { - return attributes; - } -} - 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 deleted file mode 100644 index a7313876..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java +++ /dev/null @@ -1,361 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import com.google.common.collect.ImmutableMap; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; -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.RequirementAssignments; -import org.onap.sdc.toscaparser.api.elements.Metadata; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Extract concerned info from NodeTemplate, currently ONLY HPA Feature. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -public class ExtractFromNode { - - private static final Logger LOGGER = LoggerFactory.getLogger(ExtractFromNode.class); - - private static final String CONFIGURATION_VALUE = "configurationValue"; - private static final String VDU_TYPE = "tosca.nodes.nfv.Vdu.Compute"; - private static final String VDU_CP_TYPE = "tosca.nodes.nfv.VduCp"; - 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 MEMORY_PAGE_SIZE_PATH = "virtual_memory#vdu_mem_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#logical_node_requirements"; - private static final String BASIC_CAPABILITIES_HPA_FEATURE = "basicCapabilities"; - private static final String HUGE_PAGES_HPA_FEATURE = "hugePages"; - private static final Map NETWORK_HPA_FEATURE_MAP = - ImmutableMap.of("SR-IOV", "sriovNICNetwork", "PCI-Passthrough", "pciePassthrough"); - private static final Pattern PATTERN = Pattern.compile("(\\D*)(\\d+)(\\D*)"); - private ISdcCsarHelper sdcCsarHelper; - final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().disableHtmlEscaping().create(); - - public void setSdcCsarHelper(final ISdcCsarHelper sdcCsarHelper) { - this.sdcCsarHelper = sdcCsarHelper; - } - - /** - * ExtractInfo from VNF , each VNF may includes more than one VDUs and CPs return new generated PdpxPolicy if it has - * got Hpa feature info or else return null. - * - * @param node the NodeTemplate - * - * @return the extracted info from input node - * - * @throws PolicyDecodingException if extract fails - */ - public Content extractInfo(final NodeTemplate node) throws PolicyDecodingException { - final Metadata metaData = sdcCsarHelper.getNodeTemplateMetadata(node); - final Metadata metaDataOfService = sdcCsarHelper.getServiceMetadata(); - LOGGER.debug("the meta data of this nodetemplate = {}", metaData); - final List lnodeChild = sdcCsarHelper.getNodeTemplateChildren(node); - LOGGER.debug("the size of lnodeChild = {}", lnodeChild.size()); - - // Store all the VDUs under one VNF - final List lnodeVdu = new ArrayList<>(); - // Store all the Cps under one VNF - final List lnodeVduCp = new ArrayList<>(); - for (final NodeTemplate nodeChild : lnodeChild) { - final String type = sdcCsarHelper.getTypeOfNodeTemplate(nodeChild); - LOGGER.debug("the type of this nodeChild = {}", type); - LOGGER.debug("the meta data of this nodeChild = {}", sdcCsarHelper.getNodeTemplateMetadata(nodeChild)); - if (type.equalsIgnoreCase(VDU_TYPE)) { - lnodeVdu.add(nodeChild); - } else if (type.equalsIgnoreCase(VDU_CP_TYPE)) { - lnodeVduCp.add(nodeChild); - } - } - LOGGER.debug("the size of vdu is = {}", lnodeVdu.size()); - LOGGER.debug("the size of cp is = {}", lnodeVduCp.size()); - - final Content content = new Content(); - content.getResources().add(metaData.getValue("name")); - content.getServices().add(metaDataOfService.getValue("name")); - content.setIdentity(content.getPolicyType() + "_" + metaData.getValue("name")); - extractInfoVdu(lnodeVdu, content); - extractInfoVduCp(lnodeVduCp, content); - if (content.getFlavorFeatures().isEmpty()) { - return null; - } - return content; - } - - - /** - * ExtractInfofromVdu, supported hpa features, All under the capability of tosca.nodes.nfv.Vdu.Compute. - * - * @param lnodeVdu the list of Vdu node - * - * @param content to be change based on lnodeVdu - */ - public void extractInfoVdu(final List lnodeVdu, final Content content) { - // each VDU <=> FlavorFeature - for (final NodeTemplate node : lnodeVdu) { - final Attribute flavorAttribute = new Attribute(); - flavorAttribute.setAttributeName("flavorName"); - flavorAttribute.setAttributeValue(""); - final Directive flavorDirective = new Directive(); - flavorDirective.setType("flavor_directives"); - flavorDirective.getAttributes().add(flavorAttribute); - final FlavorFeature flavorFeature = new FlavorFeature(); - flavorFeature.setId(node.toString()); - LOGGER.debug("the name of node = {}", node); - flavorFeature.getDirectives().add(flavorDirective); - - final CapabilityAssignments capabilityAssignments = sdcCsarHelper.getCapabilitiesOf(node); - final CapabilityAssignment capabilityAssignment = - capabilityAssignments.getCapabilityByName("virtual_compute"); - if (capabilityAssignment != null) { - generateBasicCapability(capabilityAssignment, flavorFeature); - generateHugePages(capabilityAssignment, flavorFeature); - } - content.getFlavorFeatures().add(flavorFeature); - } - } - - /** - * GenerateBasicCapability, supported hpa features, All under the capability of tosca.nodes.nfv.Vdu.Compute. - * - * @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); - if (virtualMemSize != null) { - LOGGER.debug("the virtualMemSize = {}", virtualMemSize); - final HpaFeatureAttribute hpaFeatureAttribute = - generateHpaFeatureAttribute("virtualMemSize", virtualMemSize); - final 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); - 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_HPA_FEATURE); - if (cpuArchitecture != null) { - flavorProperty.setArchitecture(cpuArchitecture); - } - flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); - flavorFeature.getFlavorProperties().add(flavorProperty); - } - } - - /** - * GenerateHpaFeatureAttribute based on the value of featureValue. the format: "hpa-attribute-key": "pciVendorId", - * "hpa-attribute-value": "1234", "operator": "=", "unit": "xxx". - * - * @param hpaAttributeKey get from the high layer tosca DM - * - * @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 modifiedValue = featureValue.replace(" ", ""); - final Matcher matcher = PATTERN.matcher(modifiedValue); - if (matcher.find()) { - final String matcher1 = matcher.group(1); - final String matcher2 = matcher.group(2); - final String matcher3 = matcher.group(3); - LOGGER.debug("operator {} , value = {} , unit = {}", matcher1, matcher2, matcher3); - if (matcher.group(1).length() == 0) { - hpaFeatureAttribute.setOperator("="); - } else { - hpaFeatureAttribute.setOperator(matcher1); - } - hpaFeatureAttribute.setHpaAttributeValue(matcher2); - hpaFeatureAttribute.setUnit(matcher3); - } - return hpaFeatureAttribute; - } - - /** - * GenerateHugePages, supported hpa features, All under the capability of tosca.nodes.nfv.Vdu.Compute. The format is - * a map like: {"schemaVersion": "0", "schemaSelector": "", "hardwarePlatform": "generic", "mandatory": "true", - * "configurationValue": "2 MB"} - * - * @param capabilityAssignment represents the capability of node - * - * @param flavorFeature represents all the features of specified flavor - */ - private void generateHugePages(final CapabilityAssignment capabilityAssignment, final FlavorFeature flavorFeature) { - final String memoryPageSize = - sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, MEMORY_PAGE_SIZE_PATH); - LOGGER.debug("the memoryPageSize = {}", memoryPageSize); - if (memoryPageSize != null) { - final Map retMap = - gson.fromJson(memoryPageSize, new TypeToken>() {}.getType()); - LOGGER.debug("the retMap = {}", retMap); - final String memoryPageSizeValue = retMap.get(CONFIGURATION_VALUE); - final String mandatory = retMap.get("mandatory"); - if (memoryPageSizeValue == null) { - return; - } - final HpaFeatureAttribute hpaFeatureAttribute = - generateHpaFeatureAttribute("memoryPageSize", memoryPageSizeValue); - final FlavorProperty flavorProperty = new FlavorProperty(); - flavorProperty.setHpaFeature(HUGE_PAGES_HPA_FEATURE); - if (mandatory != null) { - flavorProperty.setMandatory(mandatory); - } - flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); - flavorFeature.getFlavorProperties().add(flavorProperty); - } - } - - /** - * ExtractInfoVduCp, supported hpa features, under the virtual_network_interface_requirements of - * tosca.nodes.nfv.VduCp. - * - * @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 lnodeVduCp, final Content content) - throws PolicyDecodingException { - // each CP will binds to a VDU so need the vdu flavor map info. - final Map vduFlavorMap = new HashMap<>(); - for (final FlavorFeature flavorFeature : content.getFlavorFeatures()) { - LOGGER.debug("the id = {}", flavorFeature.getId()); - vduFlavorMap.put(flavorFeature.getId(), flavorFeature); - } - parseNodeVduCp(lnodeVduCp, vduFlavorMap); - } - - /** - * Parse the VduCp list. - * - * @param lnodeVduCp the lnodeVduCp - * @param vduFlavorMap the vduFlavorMap - * @throws PolicyDecodingException if any error occurs - */ - private void parseNodeVduCp(final List lnodeVduCp, final Map vduFlavorMap) - throws PolicyDecodingException { - for (final NodeTemplate node : lnodeVduCp) { - final String interfaceType = - sdcCsarHelper.getNodeTemplatePropertyLeafValue(node, NETWORK_INTERFACE_TYPE_PATH); - LOGGER.debug("the interfaceType = {}", interfaceType); - Map retMap = new HashMap<>(); - if (interfaceType != null) { - retMap = gson.fromJson(interfaceType, new TypeToken>() {}.getType()); - LOGGER.debug("the retMap = {}", retMap); - } - - String networkHpaFeature; - if (retMap.containsKey(CONFIGURATION_VALUE) - && NETWORK_HPA_FEATURE_MAP.containsKey(retMap.get(CONFIGURATION_VALUE).toString())) { - final String interfaceTypeValue = retMap.get(CONFIGURATION_VALUE).toString(); - networkHpaFeature = NETWORK_HPA_FEATURE_MAP.get(interfaceTypeValue); - LOGGER.debug(" the networkHpaFeature is = {}", networkHpaFeature); - } else { - LOGGER.debug(" no networkHpaFeature defined in interfaceType"); - continue; - } - - final RequirementAssignments requriements = - sdcCsarHelper.getRequirementsOf(node).getRequirementsByName("virtual_binding"); - for (final RequirementAssignment requriement : requriements.getAll()) { - final String nodeTemplateName = requriement.getNodeTemplateName(); - 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. The format is a map like: - * {"schemaVersion": "0", "schemaSelector": "", "hardwarePlatform": "generic", "mandatory": "true", - * "configurationValue": "2 MB"} - * - * @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, - final FlavorFeature flavorFeature) { - final FlavorProperty flavorProperty = new FlavorProperty(); - flavorProperty.setHpaFeature(networkHpaFeature); - final String[] pciKeys = { "pciVendorId", "pciDeviceId", "pciNumDevices", "physicalNetwork" }; - for (final String pciKey : pciKeys) { - LOGGER.debug("the pciKey = {}", pciKey); - final String pciKeyPath = NETWORK_PCI_PATH + "#" + pciKey; - final String pciValue = sdcCsarHelper.getNodeTemplatePropertyLeafValue(node, pciKeyPath); - if (pciValue != null) { - LOGGER.debug("the pciValue = {}", pciValue); - final Map retMap = - gson.fromJson(pciValue, new TypeToken>() {}.getType()); - final String pciConfigValue = retMap.get(CONFIGURATION_VALUE); - if (pciConfigValue == null) { - return; - } - final 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/FlavorFeature.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorFeature.java deleted file mode 100644 index c29378de..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorFeature.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import java.util.ArrayList; -import java.util.List; - -/** - * The FlavorFeature includes all the specified flavor infos used in multicloud, it represents one VDU of TOSCA. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -class FlavorFeature { - private String id; - private String type = "tosca.nodes.nfv.Vdu.Compute"; - private List directives = new ArrayList<>(); - private List flavorProperties = new ArrayList<>(); - - public void setId(final String id) { - this.id = id; - } - - public String getId() { - return id; - } - - public void setType(final String type) { - this.type = type; - } - - public String getType() { - return type; - } - - public List getFlavorProperties() { - return flavorProperties; - } - - public List getDirectives() { - return directives; - } -} - diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorProperty.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorProperty.java deleted file mode 100644 index 0453370d..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorProperty.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import com.google.gson.annotations.SerializedName; - -import java.util.ArrayList; -import java.util.List; - -/** - * The FlavorProperty includes all the properties of Flavor. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -class FlavorProperty { - @SerializedName(value = "hpa-feature") - private String hpaFeature; - private String mandatory = "True"; - private String architecture = "generic"; - @SerializedName(value = "hpa-version") - private String hpaVersion = "v1"; - private List directives = new ArrayList<>(); - @SerializedName(value = "hpa-feature-attributes") - private List hpaFeatureAttributes = new ArrayList<>(); - - public void setHpaFeature(final String hpaFeature) { - this.hpaFeature = hpaFeature; - } - - public String getHpaFeature() { - return hpaFeature; - } - - public void setMandatory(final String mandatory) { - this.mandatory = mandatory; - } - - public String getMandatory() { - return mandatory; - } - - public void setArchitecture(final String architecture) { - this.architecture = architecture; - } - - public String getArchitecture() { - return architecture; - } - - public void setHpaVersion(final String hpaVersion) { - this.hpaVersion = hpaVersion; - } - - public String getHpaVersion() { - return hpaVersion; - } - - public List getDirectives() { - return directives; - } - - public List getHpaFeatureAttributes() { - return hpaFeatureAttributes; - } -} - 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 deleted file mode 100644 index 91008aa5..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import com.google.gson.annotations.SerializedName; - -/** - * The HpaFeatureAttribute represents a way to provide match expression. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -class HpaFeatureAttribute { - @SerializedName(value = "hpa-attribute-key") - private String hpaAttributeKey; - @SerializedName(value = "hpa-attribute-value") - private String hpaAttributeValue; - private String operator; - private String unit; - - public void setHpaAttributeKey(final String hpaAttributeKey) { - this.hpaAttributeKey = hpaAttributeKey; - } - - public String getHpaAttributeKey() { - return hpaAttributeKey; - } - - public void setHpaAttributeValue(final String hpaAttributeValue) { - this.hpaAttributeValue = hpaAttributeValue; - } - - public String getHpaAttributeValue() { - return hpaAttributeValue; - } - - public void setOperator(final String operator) { - this.operator = operator; - } - - public String getOperator() { - return operator; - } - - public void setUnit(final String unit) { - this.unit = unit; - } - - public String getUnit() { - return unit; - } -} - - diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PdpxPolicy.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PdpxPolicy.java deleted file mode 100644 index e7a0e8ab..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PdpxPolicy.java +++ /dev/null @@ -1,127 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import org.onap.policy.distribution.model.Policy; -import org.onap.policy.distribution.reception.decoding.PolicyDecoder; - -/** - * A PDP-X Policy, decoded by a {@link PolicyDecoder}. - */ -public class PdpxPolicy implements Policy { - - private String guard; - private String service; - private String policyName; - private String description; - private String templateVersion; - private String version; - private String riskType; - private String priority; - private String riskLevel; - private Content content = new Content(); - - @Override - public String getPolicyName() { - return policyName; - } - - @Override - public String getPolicyType() { - return content.getPolicyType(); - } - - public String getGuard() { - return guard; - } - - public String getService() { - return service; - } - - public String getDescription() { - return description; - } - - public String getTemplateVersion() { - return templateVersion; - } - - public String getVersion() { - return version; - } - - public String getRiskType() { - return riskType; - } - - public String getPriority() { - return priority; - } - - public String getRiskLevel() { - return riskLevel; - } - - public Content getContent() { - return content; - } - - public void setGuard(final String guard) { - this.guard = guard; - } - - public void setService(final String service) { - this.service = service; - } - - public void setPolicyName(final String policyName) { - this.policyName = policyName; - } - - public void setDescription(final String description) { - this.description = description; - } - - public void setTemplateVersion(final String templateVersion) { - this.templateVersion = templateVersion; - } - - public void setVersion(final String version) { - this.version = version; - } - - public void setRiskType(final String riskType) { - this.riskType = riskType; - } - - public void setPriority(final String priority) { - this.priority = priority; - } - - public void setRiskLevel(final String riskLevel) { - this.riskLevel = riskLevel; - } - - public void setContent(final Content content) { - this.content = content; - } -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java deleted file mode 100644 index 842245c0..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.distribution.model.Csar; -import org.onap.policy.distribution.model.OptimizationPolicy; -import org.onap.policy.distribution.model.PolicyInput; -import org.onap.policy.distribution.reception.decoding.PolicyDecoder; -import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.onap.sdc.toscaparser.api.NodeTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Decodes PDP-X policies from a CSAR file. - */ -public class PolicyDecoderCsarPdpx implements PolicyDecoder { - - private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderCsarPdpx.class); - private final Gson gson = new GsonBuilder().serializeNulls().disableHtmlEscaping().create(); - private PolicyDecoderCsarPdpxConfigurationParameterGroup decoderParameters; - - @Override - public Collection decode(final Csar csar) throws PolicyDecodingException { - final List policies = new ArrayList<>(); - final ISdcCsarHelper sdcCsarHelper = parseCsar(csar); - final List lnodeVf = sdcCsarHelper.getServiceVfList(); - LOGGER.debug("the size of Vf = {}", lnodeVf.size()); - final ExtractFromNode extractFromNode = new ExtractFromNode(); - extractFromNode.setSdcCsarHelper(sdcCsarHelper); - final String serviceName = sdcCsarHelper.getServiceMetadata().getValue("name"); - LOGGER.debug("the name of the service = {}", serviceName); - for (final NodeTemplate node : lnodeVf) { - final Content content = extractFromNode.extractInfo(node); - if (content != null) { - final OptimizationPolicy policy = new OptimizationPolicy(); - final String policyName = decoderParameters.getPolicyNamePrefix() + "." + content.getIdentity(); - policy.setOnapName(decoderParameters.getOnapName()); - policy.setName(policyName); - final ConfigBody configBody = new ConfigBody(); - configBody.setService("hpaPolicy"); - configBody.setPolicyName(policyName); - configBody.setDescription("OOF Policy"); - configBody.setTemplateVersion("OpenSource.version.1"); - configBody.setVersion(decoderParameters.getVersion()); - configBody.setPriority(decoderParameters.getPriority()); - configBody.setRiskLevel(decoderParameters.getRiskLevel()); - configBody.setRiskType(decoderParameters.getRiskType()); - configBody.setGuard("False"); - content.setPolicyType("hpa"); - content.getPolicyScope().add("HPA"); - content.getPolicyScope().add(serviceName); - configBody.setContent(content); - policy.setConfigBody(gson.toJson(configBody)); - policies.add(policy); - } - } - return policies; - } - - @Override - public boolean canHandle(final PolicyInput policyInput) { - return policyInput.getClass().isAssignableFrom(Csar.class); - } - - /** - * Parse the input Csar using SDC TOSCA parser. - * - * @param csar represents the service TOSCA Csar - * @return the object to represents the content of input csar - * @throws PolicyDecodingException if parse fails - */ - public ISdcCsarHelper parseCsar(final Csar csar) throws PolicyDecodingException { - ISdcCsarHelper sdcCsarHelper; - try { - final SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); - LOGGER.debug("Csar File Path = {}", csar.getCsarPath()); - final File csarFile = new File(csar.getCsarPath()); - sdcCsarHelper = factory.getSdcCsarHelper(csarFile.getAbsolutePath()); - } catch (final Exception exp) { - final String message = "Failed passing the csar file"; - LOGGER.error(message, exp); - throw new PolicyDecodingException(message, exp); - } - return sdcCsarHelper; - } - - @Override - public void configure(final String parameterGroupName) { - decoderParameters = ParameterService.get(parameterGroupName); - } -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterGroup.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterGroup.java deleted file mode 100644 index f376c391..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterGroup.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import lombok.Getter; - -import org.onap.policy.common.parameters.annotations.NotBlank; -import org.onap.policy.common.parameters.annotations.NotNull; -import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup; - -/** - * This class handles reading, parsing and validating of the paramaters for the {@link PolicyDecoderCsarPdpx}. - */ -@Getter -@NotNull -@NotBlank -public class PolicyDecoderCsarPdpxConfigurationParameterGroup extends PolicyDecoderConfigurationParameterGroup { - - private String policyNamePrefix; - private String onapName; - private String version; - private String priority; - private String riskType; - private String riskLevel; - - public PolicyDecoderCsarPdpxConfigurationParameterGroup() { - super(PolicyDecoderCsarPdpxConfigurationParameterGroup.class.getSimpleName()); - } -} - diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java deleted file mode 100644 index 8cfc6857..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java +++ /dev/null @@ -1,132 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.distribution.model.Csar; -import org.onap.policy.distribution.model.PolicyInput; -import org.onap.policy.distribution.reception.decoding.PolicyDecoder; -import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.onap.sdc.toscaparser.api.NodeTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Decodes PDP-X policies from a CSAR file and creates ToscaServiceTemplate for Policy Lifecycle API's. - */ -public class PolicyDecoderCsarPdpxLifecycleApi implements PolicyDecoder { - - private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderCsarPdpxLifecycleApi.class); - private final StandardCoder coder = new StandardCoder(); - private PolicyDecoderCsarPdpxLifecycleApiParameters decoderParameters; - - public static final String TOSCA_POLICY_SCOPE = "scope"; - public static final String TOSCA_POLICY_SERVICES = "services"; - public static final String TOSCA_POLICY_RESOURCES = "resources"; - public static final String TOSCA_POLICY_IDENTITY = "identity"; - public static final String TOSCA_POLICY_FLAVORFEATURES = "flavorfeatures"; - - public static final String TOSCA_POLICY_HPA_OOF = "Optimization"; - - @Override - public Collection decode(final Csar csar) throws PolicyDecodingException { - final List entities = new ArrayList<>(); - final ISdcCsarHelper sdcCsarHelper = parseCsar(csar); - final List lnodeVf = sdcCsarHelper.getServiceVfList(); - LOGGER.debug("the size of Vf = {}", lnodeVf.size()); - final ExtractFromNode extractFromNode = new ExtractFromNode(); - extractFromNode.setSdcCsarHelper(sdcCsarHelper); - final String serviceName = sdcCsarHelper.getServiceMetadata().getValue("name"); - LOGGER.debug("the name of the service = {}", serviceName); - for (final NodeTemplate node : lnodeVf) { - final Content content = extractFromNode.extractInfo(node); - if (content != null) { - final ToscaServiceTemplate entity = new ToscaServiceTemplate(); - Map props = new LinkedHashMap<>(); - props.put(TOSCA_POLICY_SCOPE, content.getScope()); - props.put(TOSCA_POLICY_SERVICES, content.getServices()); - props.put(TOSCA_POLICY_RESOURCES, content.getResources()); - props.put(TOSCA_POLICY_IDENTITY, content.getIdentity()); - props.put(TOSCA_POLICY_FLAVORFEATURES, content.getFlavorFeatures()); - ToscaPolicy policy = new ToscaPolicy(); - policy.setProperties(props); - Map map = new LinkedHashMap<>(); - String type = content.getPolicyType(); - map.put(type, policy); - List> policies = new ArrayList<>(); - policies.add(map); - ToscaTopologyTemplate topologyTemplate = new ToscaTopologyTemplate(); - topologyTemplate.setPolicies(policies); - entity.setToscaTopologyTemplate(topologyTemplate); - entities.add(entity); - } - } - return entities; - } - - @Override - public boolean canHandle(final PolicyInput policyInput) { - return Csar.class.isAssignableFrom(policyInput.getClass()); - } - - /** - * Parse the input Csar using SDC TOSCA parser. - * - * @param csar represents the service TOSCA Csar - * @return the object to represents the content of input csar - * @throws PolicyDecodingException if parse fails - */ - public ISdcCsarHelper parseCsar(final Csar csar) throws PolicyDecodingException { - ISdcCsarHelper sdcCsarHelper; - try { - final SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); - LOGGER.debug("Csar File Path = {}", csar.getCsarPath()); - final File csarFile = new File(csar.getCsarPath()); - sdcCsarHelper = factory.getSdcCsarHelper(csarFile.getAbsolutePath()); - } catch (final Exception exp) { - final String message = "Failed passing the csar file"; - LOGGER.error(message, exp); - throw new PolicyDecodingException(message, exp); - } - return sdcCsarHelper; - } - - @Override - public void configure(final String parameterGroupName) { - decoderParameters = ParameterService.get(parameterGroupName); - } -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApiParameters.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApiParameters.java deleted file mode 100644 index a66a53a8..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApiParameters.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import lombok.Getter; - -import org.onap.policy.common.parameters.annotations.NotBlank; -import org.onap.policy.common.parameters.annotations.NotNull; -import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup; - -/** - * This class handles the parameters needed for {@link PolicyDecoderCsarPdpxLifecycleApi}. - */ -@Getter -@NotNull -@NotBlank -public class PolicyDecoderCsarPdpxLifecycleApiParameters extends PolicyDecoderConfigurationParameterGroup { - - private String policyNamePrefix; - private String onapName; - private String version; - private String priority; - private String riskType; - private String riskLevel; - - public PolicyDecoderCsarPdpxLifecycleApiParameters() { - super(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); - } -} - -- cgit 1.2.3-korg