aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/reception-plugins
diff options
context:
space:
mode:
authorliboNet <libo.zhu@intel.com>2018-09-11 11:07:04 +0800
committerliboNet <libo.zhu@intel.com>2018-09-13 12:37:03 +0800
commit571b40bd86ffeb24f707539f3fe535ff1b2e2ebc (patch)
tree6d1243fe9cdacde98bd41b9ad5007d3176088109 /plugins/reception-plugins
parent1b5763e20c91f40da4ad44b2d6bd09331705b27a (diff)
Adding code for dynamically generate Polices
* Update sdc tosca version to 1.4.1 * Define the objects to represents the policy used by OOF/Mutlicloud/AAI etc * Integration into the distribution framework to update PdpxPolicy and add new File PolicyDecoderCsarPdpx to do decoder from CSAR * Add two Test case including 2 VNFs, each VNF maps to 1 policy, so to generate 2 polices * use @SerializedName make the variable name different with that in the out json field Change-Id: Icc7175082063db8a245bbe576085cdf5a4b51adc Issue-ID: POLICY-927 Signed-off-by: liboNet <libo.zhu@intel.com>
Diffstat (limited to 'plugins/reception-plugins')
-rw-r--r--plugins/reception-plugins/pom.xml2
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Attribute.java53
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Content.java71
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Directive.java51
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java263
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorFeature.java67
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorProperty.java91
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java74
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PdpxPolicy.java91
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java102
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestAttribute.java49
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestContent.java64
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestDirective.java52
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorFeature.java63
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorProperty.java70
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestHpaFeatureAttribute.java56
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestPolicyDecoderCsarPdpx.java66
-rw-r--r--plugins/reception-plugins/src/test/resources/hpaPolicySRIOV.csarbin0 -> 131336 bytes
-rw-r--r--plugins/reception-plugins/src/test/resources/service-TestNs8-csar.csarbin0 -> 121047 bytes
19 files changed, 1282 insertions, 3 deletions
diff --git a/plugins/reception-plugins/pom.xml b/plugins/reception-plugins/pom.xml
index 388477e9..799904c3 100644
--- a/plugins/reception-plugins/pom.xml
+++ b/plugins/reception-plugins/pom.xml
@@ -39,7 +39,7 @@
<dependency>
<groupId>org.onap.sdc.sdc-tosca</groupId>
<artifactId>sdc-tosca</artifactId>
- <version>1.3.0</version>
+ <version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.onap.sdc.sdc-distribution-client</groupId>
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
new file mode 100644
index 00000000..c86bae9e
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Attribute.java
@@ -0,0 +1,53 @@
+/*-
+ * ============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(String attributeName) {
+ this.attributeName = attributeName;
+ }
+
+ public String getAttributeName() {
+ return attributeName;
+ }
+
+ public void setAttributeValue(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/Content.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Content.java
new file mode 100644
index 00000000..264ba8a6
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Content.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.pdpx;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * The content acts the high level abstraction which to be used by OOF to do Optimization.
+ *
+ * @author Libo Zhu (libo.zhu@intel.com)
+ */
+class Content {
+ private String resources;
+ private String identity;
+ private List<String> policyScope = new ArrayList<>();
+ private String policyType = "Optimization";
+ private List<FlavorFeature> flavorFeatures = new ArrayList<>();
+
+ public void setResources(String resources) {
+ this.resources = resources;
+ }
+
+ public String getResources() {
+ return resources;
+ }
+
+ public void setIdentity(String identity) {
+ this.identity = identity;
+ }
+
+ public String getIdentity() {
+ return identity;
+ }
+
+ public List<String> getPolicyScope() {
+ return policyScope;
+ }
+
+ public void setPolicyType(String policyType) {
+ this.policyType = policyType;
+ }
+
+ public String getPolicyType() {
+ return policyType;
+ }
+
+ public List<FlavorFeature> getFlavorFeatures() {
+ return flavorFeatures;
+ }
+
+}
+
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
new file mode 100644
index 00000000..c04fc91d
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Directive.java
@@ -0,0 +1,51 @@
+/*-
+ * ============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.List;
+import java.util.ArrayList;
+
+
+/**
+ * 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<Attribute> attributes = new ArrayList<>();
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public List<Attribute> 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
new file mode 100644
index 00000000..3fba96d4
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java
@@ -0,0 +1,263 @@
+/*-
+ * ============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 java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+import java.io.FileWriter;
+import java.io.Writer;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.annotations.SerializedName;
+
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
+
+import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.impl.SdcCsarHelperImpl;
+import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
+import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
+
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.CapabilityAssignment;
+import org.onap.sdc.toscaparser.api.CapabilityAssignments;
+import org.onap.sdc.toscaparser.api.elements.Metadata;
+
+/**
+ * Extract concerned info from NodeTemplate, currently ONLY HPA Feature.
+ *
+ * @author Libo Zhu (libo.zhu@intel.com)
+ */
+public class ExtractFromNode {
+
+ private static final Logger LOGGER = FlexLogger.getLogger(ExtractFromNode.class);
+ private static final String CONTENT_RESOURCES = "name";
+ 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 NUMBER_OF_PAGES_PATH = "virtual_memory#vdu_memory_requirements#numberOfPages";
+ private static final String BASIC_CAPABILITIES = "BasicCapabilities";
+
+
+ ISdcCsarHelper sdcCsarHelper;
+ final Gson gson = new GsonBuilder()
+ .serializeNulls()
+ .setPrettyPrinting()
+ .disableHtmlEscaping()
+ .create();
+
+
+ public void setSdcCsarHelper(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 PdpxPolicy extractInfo(NodeTemplate node) throws PolicyDecodingException {
+ PdpxPolicy pdpxPolicy = new PdpxPolicy();
+ Content content = pdpxPolicy.getContent();
+
+ String outputFile = sdcCsarHelper.getNodeTemplateMetadata(node).getValue("name");
+ outputFile += ".json";
+ LOGGER.debug("the meta data of this nodetemplate = " + sdcCsarHelper.getNodeTemplateMetadata(node));
+ LOGGER.debug("outputFile = " + outputFile);
+
+ List<NodeTemplate> lnodeChild = sdcCsarHelper.getNodeTemplateChildren(node);
+ LOGGER.debug("the size of lnodeChild = " + lnodeChild.size());
+
+ //Store all the VDUs under one VNF
+ List<NodeTemplate> lnodeVdu = new ArrayList<>();
+ //Store all the Cps under one VNF
+ List<NodeTemplate> lnodeVduCp = new ArrayList<>();
+ for ( NodeTemplate nodeChild : lnodeChild) {
+ String type = sdcCsarHelper.getTypeOfNodeTemplate(nodeChild);
+ LOGGER.debug("the type of this nodeChild = " + type);
+ LOGGER.debug("the meta data of this nodetemplate = " + 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());
+
+ extractInfoVdu(lnodeVdu, content);
+ extractInfoVduCp(lnodeVduCp, content);
+
+ if (content.getFlavorFeatures().isEmpty() ){
+ return null;
+ }
+
+ try (Writer writer = new FileWriter(outputFile)) {
+ gson.toJson(pdpxPolicy, writer);
+ } catch (Exception e) {
+ LOGGER.error("can't write generated policies to file " , e);
+ throw new PolicyDecodingException ("Exception caught when writing generated policies to file ", e);
+ }
+ return pdpxPolicy;
+ }
+
+
+ /*
+ * 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<NodeTemplate> lnodeVdu, Content content) {
+ //each VDU <=> FlavorFeature
+ for ( NodeTemplate node : lnodeVdu) {
+ String id = sdcCsarHelper.getNodeTemplatePropertyLeafValue(node, "name");
+ FlavorFeature flavorFeature = new FlavorFeature();
+ flavorFeature.setId(id);
+ Attribute flavorAttribute = new Attribute();
+ flavorAttribute.setAttributeName("flavorName");
+ flavorAttribute.setAttributeValue("");
+ Directive flavorDirective = new Directive();
+ flavorDirective.setType("flavor_directive");
+ flavorDirective.getAttributes().add(flavorAttribute);
+ flavorFeature.getDirectives().add(flavorDirective);
+
+ CapabilityAssignments capabilityAssignments = sdcCsarHelper.getCapabilitiesOf(node);
+ 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, FlavorFeature flavorFeature){
+ //the format is xxx MB/GB like 4096 MB
+ String virtualMemSize = sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment,
+ VIRTUAL_MEM_SIZE_PATH);
+ if (virtualMemSize != null) {
+ LOGGER.debug("the virtualMemSize = " + virtualMemSize);
+ HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute("virtualMemSize", virtualMemSize);
+ FlavorProperty flavorProperty = new FlavorProperty();
+ flavorProperty.setHpaFeature(BASIC_CAPABILITIES);
+ flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute);
+ flavorFeature.getFlavorProperties().add(flavorProperty);
+ }
+
+ //the format is int like 2
+ String numVirtualCpu = sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment,
+ NUM_VIRTUAL_CPU_PATH);
+ if (numVirtualCpu != null) {
+ LOGGER.debug("the numVirtualCpu = " + numVirtualCpu);
+ HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute("numVirtualCpu", numVirtualCpu);
+ String cpuArchitecture = sdcCsarHelper.getCapabilityPropertyLeafValue
+ (capabilityAssignment,CPU_ARCHITECTURE_PATH);
+ FlavorProperty flavorProperty = new FlavorProperty();
+ flavorProperty.setHpaFeature(BASIC_CAPABILITIES);
+ 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
+ * @return the format used in underlayer component
+ */
+ private HpaFeatureAttribute generateHpaFeatureAttribute(final String hpaAttributeKey, final String featureValue){
+
+ HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute();
+ hpaFeatureAttribute.setHpaAttributeKey(hpaAttributeKey);
+ String tmp = featureValue.replace(" ","");
+ String pattern = "(\\D*)(\\d+)(\\D*)";
+ Pattern r = Pattern.compile(pattern);
+ Matcher m = r.matcher(tmp);
+ if (m.find()) {
+ LOGGER.debug("operator = " + m.group(1));
+ LOGGER.debug("value = " + m.group(2));
+ LOGGER.debug("unit = " + m.group(3));
+ hpaFeatureAttribute.setOperator(m.group(1));
+ hpaFeatureAttribute.setHpaAttributeValue(m.group(2));
+ hpaFeatureAttribute.setUnit(m.group(3));
+ }
+ return hpaFeatureAttribute;
+ }
+
+ /*
+ * GenerateHugePages, 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 generateHugePages(final CapabilityAssignment capabilityAssignment, FlavorFeature flavorFeature){
+ //the format is a map like: {"schema-version": "0", "schema-location": "", "platform-id": "generic",
+ // "mandatory": true, "configuration-value": "2 MB"}
+ String numberOfPages = sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment,
+ NUMBER_OF_PAGES_PATH);
+ if (numberOfPages != null) {
+ LOGGER.debug("the virtualMemSize = " + numberOfPages);
+ //TODO add HugePages support
+ }
+ }
+
+ /*
+ * ExtractInfoVduCp, supposted 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
+ */
+ @SuppressWarnings("unchecked")
+ public void extractInfoVduCp(final List<NodeTemplate> lnodeVduCp, Content content) {
+ for ( NodeTemplate node : lnodeVduCp) {
+ //TODO to add VDU cp Hpa feature extract
+ }
+ }
+
+}
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
new file mode 100644
index 00000000..551fbdee
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorFeature.java
@@ -0,0 +1,67 @@
+/*-
+ * ============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.List;
+import java.util.ArrayList;
+
+/**
+ * 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.node.nfv.Vdu.Compute";
+ private List<Directive> directives = new ArrayList<>();
+ private List<FlavorProperty> flavorProperties = new ArrayList<>();
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public List<FlavorProperty> getFlavorProperties() {
+ return flavorProperties;
+ }
+
+ public List<Directive> getDirectives() {
+ return directives;
+ }
+
+ @Override
+ public String toString() {
+ return "{ id = " + id + ", type = " + type + ", \n" + "directivies:["+directives + ",\n"
+ + flavorProperties + "}";
+ }
+}
+
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
new file mode 100644
index 00000000..552164c5
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorProperty.java
@@ -0,0 +1,91 @@
+/*-
+ * ============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.List;
+import java.util.ArrayList;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * 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<Directive> directives = new ArrayList<>();
+ @SerializedName(value = "hpa-feature-attributes")
+ private List<HpaFeatureAttribute> hpaFeatureAttributes = new ArrayList<>();
+
+ public void setHpaFeature(String hpaFeature) {
+ this.hpaFeature = hpaFeature;
+ }
+
+ public String getHpaFeature() {
+ return hpaFeature;
+ }
+
+ public void setMandatory(String mandatory) {
+ this.mandatory = mandatory;
+ }
+
+ public String getMandatory() {
+ return mandatory;
+ }
+
+ public void setArchitecture(String architecture) {
+ this.architecture = architecture;
+ }
+
+ public String getArchitecture() {
+ return architecture;
+ }
+
+ public void setHpaVersion(String hpaVersion) {
+ this.hpaVersion = hpaVersion;
+ }
+
+ public String getHpaVersion() {
+ return hpaVersion;
+ }
+
+ public List<Directive> getDirectives() {
+ return directives;
+ }
+
+ public List<HpaFeatureAttribute> getHpaFeatureAttributes() {
+ return hpaFeatureAttributes;
+ }
+
+ @Override
+ public String toString() {
+ return "{ hpaFeature:" + hpaFeature + ", mandatory = " + mandatory + ",architecture:" + architecture
+ + ", hpaFeatureAttributes : [" + 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
new file mode 100644
index 00000000..7574ee87
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java
@@ -0,0 +1,74 @@
+/*-
+ * ============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 = "hap-attribute-value")
+ private String hpaAttributeValue;
+ private String operator;
+ private String unit;
+
+ public HpaFeatureAttribute(){}
+
+ public void setHpaAttributeKey(String hpaAttributeKey) {
+ this.hpaAttributeKey = hpaAttributeKey;
+ }
+
+ public String getHpaAttributeKey() {
+ return hpaAttributeKey;
+ }
+
+ public void setHpaAttributeValue(String hpaAttributeValue) {
+ this.hpaAttributeValue = hpaAttributeValue;
+ }
+
+ public String getHpaAttributeValue() {
+ return hpaAttributeValue;
+ }
+
+ public void setOperator(String operator) {
+ this.operator = operator;
+ }
+
+ public String getOperator() {
+ return operator;
+ }
+
+ public void setUnit(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
index 135d2564..179024a8 100644
--- 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
@@ -28,14 +28,101 @@ import org.onap.policy.distribution.reception.decoding.PolicyDecoder;
*/
public class PdpxPolicy implements Policy {
+ 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 = new Content();
+
@Override
public String getPolicyName() {
- return null;
+ return policyName;
}
@Override
public String getPolicyType() {
- return null;
+ return content.getPolicyType();
+ }
+
+ public void setService(String service) {
+ this.service = service;
+ }
+
+ public String getService() {
+ return service;
+ }
+
+ public void setPolicyName(String policyName) {
+ this.policyName = policyName;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
}
+ public void setTemplateVersion(String templateVersion) {
+ this.templateVersion = templateVersion;
+ }
+
+ public String getTemplateVersion() {
+ return 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 getGuard() {
+ return guard;
+ }
+
+ public void setGuard(String guard) {
+ this.guard = guard;
+ }
+
+ public String getRiskLevel() {
+ return riskLevel;
+ }
+
+ public void setRiskLevel(String riskLevel) {
+ this.riskLevel = riskLevel;
+ }
+
+ public String getRiskType() {
+ return riskType;
+ }
+
+ public void setRiskType(String riskType) {
+ this.riskType = riskType;
+ }
+
+ 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/PolicyDecoderCsarPdpx.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java
new file mode 100644
index 00000000..0cd7bc16
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java
@@ -0,0 +1,102 @@
+/*-
+ * ============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 java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import java.util.Collection;
+import java.util.Collections;
+
+
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+
+import org.onap.policy.distribution.model.PolicyInput;
+import org.onap.policy.distribution.model.Csar;
+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.SdcCsarHelperImpl;
+import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
+
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.elements.Metadata;
+
+/**
+ * Decodes PDP-X policies from a TOSCA file.
+ */
+public class PolicyDecoderCsarPdpx implements PolicyDecoder<Csar, PdpxPolicy> {
+
+ private static final Logger LOGGER = FlexLogger.getLogger(PolicyDecoderCsarPdpx.class);
+
+ @Override
+ public Collection<PdpxPolicy> decode(Csar csar) throws PolicyDecodingException {
+ // logic for generating the policies from the CSAR.
+ List<PdpxPolicy> lPdpxPolicy = new ArrayList<>();
+ ISdcCsarHelper sdcCsarHelper = parseCsar(csar);
+ List<NodeTemplate> lnodeVf = sdcCsarHelper.getServiceVfList();
+ LOGGER.debug("the size of Vf = " + lnodeVf.size());
+ ExtractFromNode extractFromNode = new ExtractFromNode();
+ extractFromNode.setSdcCsarHelper(sdcCsarHelper);
+ for ( NodeTemplate node : lnodeVf) {
+ PdpxPolicy ret = extractFromNode.extractInfo(node);
+ if (ret != null) {
+ lPdpxPolicy.add(ret);
+ }
+ }
+ return lPdpxPolicy;
+ }
+
+ @Override
+ public boolean canHandle(PolicyInput policyInput) {
+ return policyInput.getClass().isAssignableFrom(Csar.class);
+ }
+
+ /**
+ * Parse the input Csar by SDC tosca tool.
+ *
+ * @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(Csar csar) throws PolicyDecodingException {
+ ISdcCsarHelper sdcCsarHelper ;
+ try {
+
+ SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();//Autoclosable
+
+ LOGGER.debug("tosca File Path = " + csar.getCsarPath());
+
+ File spoolFile = new File(csar.getCsarPath());
+
+ sdcCsarHelper = factory.getSdcCsarHelper(spoolFile.getAbsolutePath());
+
+ } catch (Exception e) {
+ LOGGER.error("Exception got in parseTosca",e);
+ throw new PolicyDecodingException ("Exception caught when passing the csar file to the parser ", e);
+ }
+ return sdcCsarHelper;
+ }
+
+}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestAttribute.java
new file mode 100644
index 00000000..f11a7ecd
--- /dev/null
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestAttribute.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.pdpx;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit test for Attribute 0f {@link Attribute}.
+ *
+ */
+public class TestAttribute {
+
+ @Test
+ public void testAttribute() {
+ final String attributeName = "dummyName";
+ final String attributeValue = "dummyValue";
+
+ final Attribute attribute = new Attribute();
+ attribute.setAttributeName(attributeName);
+ attribute.setAttributeValue(attributeValue);
+
+ validateReport(attributeName,attributeValue,attribute);
+ }
+
+ private void validateReport(final String name, final String value, final Attribute attribute) {
+ assertEquals(name, attribute.getAttributeName());
+ assertEquals(value, attribute.getAttributeValue());
+ }
+}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestContent.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestContent.java
new file mode 100644
index 00000000..a329a3ee
--- /dev/null
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestContent.java
@@ -0,0 +1,64 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit test for Content 0f {@link Content}.
+ *
+ */
+public class TestContent {
+
+ @Test
+ public void testContent() {
+ final String resources = "dummyresource";
+ final String identity = "dummyidentity";
+ final String policyType = "optimization";
+
+ final Content content = new Content();
+ content.setResources(resources);
+ content.setIdentity(identity);
+ content.setPolicyType(policyType);
+
+ validateReport(resources, identity, policyType,content);
+ }
+
+ private void validateReport(final String resources, final String identity, final String policyType,
+ final Content content) {
+ assertEquals(resources, content.getResources());
+ assertEquals(identity, content.getIdentity());
+ assertEquals(policyType, content.getPolicyType());
+ assertEquals(0, content.getPolicyScope().size());
+ content.getPolicyScope().add("vFW");
+ assertEquals(1, content.getPolicyScope().size());
+ content.getPolicyScope().remove("vFW");
+ assertEquals(0, content.getPolicyScope().size());
+ assertEquals(0, content.getFlavorFeatures().size());
+ FlavorFeature flavorFeature = new FlavorFeature();
+ content.getFlavorFeatures().add(flavorFeature);
+ assertEquals(1, content.getFlavorFeatures().size());
+ content.getFlavorFeatures().remove(flavorFeature);
+ assertEquals(0, content.getFlavorFeatures().size());
+ }
+}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestDirective.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestDirective.java
new file mode 100644
index 00000000..48d11d32
--- /dev/null
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestDirective.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.pdpx;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit test for Directive 0f {@link Directive}.
+ *
+ */
+public class TestDirective {
+
+ @Test
+ public void testDirective() {
+ final String type = "dummytype";
+
+ final Directive directive = new Directive();
+ directive.setType(type);
+
+ validateReport(type,directive);
+ }
+
+ private void validateReport(final String type, final Directive directive) {
+ assertEquals(type, directive.getType());
+ assertEquals(0, directive.getAttributes().size());
+ Attribute attribute = new Attribute();
+ directive.getAttributes().add(attribute);
+ assertEquals(1, directive.getAttributes().size());
+ directive.getAttributes().remove(attribute);
+ assertEquals(0, directive.getAttributes().size());
+ }
+}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorFeature.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorFeature.java
new file mode 100644
index 00000000..47b4e343
--- /dev/null
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorFeature.java
@@ -0,0 +1,63 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit test for FlavorFeature 0f {@link FlavorFeature}.
+ *
+ */
+public class TestFlavorFeature {
+
+ @Test
+ public void testFlavorFeature() {
+ final String id = "dummyid";
+ final String type = "dummytype";
+
+ final FlavorFeature flavorFeature = new FlavorFeature();
+ flavorFeature.setId(id);
+ flavorFeature.setType(type);
+
+ validateReport(id,type,flavorFeature);
+ }
+
+ private void validateReport(final String id, final String type, final FlavorFeature flavorFeature) {
+ assertEquals(id, flavorFeature.getId());
+ assertEquals(type, flavorFeature.getType());
+
+ assertEquals(0, flavorFeature.getDirectives().size());
+ Directive directive = new Directive();
+ flavorFeature.getDirectives().add(directive);
+ assertEquals(1, flavorFeature.getDirectives().size());
+ flavorFeature.getDirectives().remove(directive);
+ assertEquals(0, flavorFeature.getDirectives().size());
+
+ assertEquals(0, flavorFeature.getFlavorProperties().size());
+ FlavorProperty flavorProperty = new FlavorProperty();
+ flavorFeature.getFlavorProperties().add(flavorProperty);
+ assertEquals(1, flavorFeature.getFlavorProperties().size());
+ flavorFeature.getFlavorProperties().remove(flavorProperty);
+ assertEquals(0, flavorFeature.getFlavorProperties().size());
+ }
+}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorProperty.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorProperty.java
new file mode 100644
index 00000000..b5a535d7
--- /dev/null
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorProperty.java
@@ -0,0 +1,70 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit test for FlavorProperty 0f {@link FlavorProperty}.
+ *
+ */
+public class TestFlavorProperty {
+
+ @Test
+ public void testFlavorProperty() {
+ final String hpaFeature = "dummyid";
+ final String mandatory = "false";
+ final String architecture = "generic";
+ final String hpaVersion = "v1";
+
+ final FlavorProperty flavorProperty = new FlavorProperty();
+ flavorProperty.setHpaFeature(hpaFeature);
+ flavorProperty.setMandatory(mandatory);
+ flavorProperty.setArchitecture(architecture);
+ flavorProperty.setHpaVersion(hpaVersion);
+
+ validateReport(hpaFeature,mandatory,architecture,hpaVersion,flavorProperty);
+ }
+
+ private void validateReport(final String hpaFeature, final String mandatory, final String architecture,
+ final String hpaVersion, final FlavorProperty flavorProperty) {
+ assertEquals(hpaFeature, flavorProperty.getHpaFeature());
+ assertEquals(mandatory, flavorProperty.getMandatory());
+ assertEquals(architecture, flavorProperty.getArchitecture());
+ assertEquals(hpaVersion, flavorProperty.getHpaVersion());
+
+ assertEquals(0, flavorProperty.getDirectives().size());
+ Directive directive = new Directive();
+ flavorProperty.getDirectives().add(directive);
+ assertEquals(1, flavorProperty.getDirectives().size());
+ flavorProperty.getDirectives().remove(directive);
+ assertEquals(0, flavorProperty.getDirectives().size());
+
+ assertEquals(0, flavorProperty.getHpaFeatureAttributes().size());
+ HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute();
+ flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute);
+ assertEquals(1, flavorProperty.getHpaFeatureAttributes().size());
+ flavorProperty.getHpaFeatureAttributes().remove(hpaFeatureAttribute);
+ assertEquals(0, flavorProperty.getHpaFeatureAttributes().size());
+ }
+}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestHpaFeatureAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestHpaFeatureAttribute.java
new file mode 100644
index 00000000..40c30eb7
--- /dev/null
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestHpaFeatureAttribute.java
@@ -0,0 +1,56 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit test for HpaFeatureAttribute 0f {@link HpaFeatureAttribute}.
+ *
+ */
+public class TestHpaFeatureAttribute {
+
+ @Test
+ public void testHpaFeatureAttribute() {
+ final String hpaAttributeKey = "dummykey";
+ final String hpaAttributeValue = "4096";
+ final String operator = ">=";
+ final String unit = "MB";
+
+ final HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute();
+ hpaFeatureAttribute.setHpaAttributeKey(hpaAttributeKey);
+ hpaFeatureAttribute.setHpaAttributeValue(hpaAttributeValue);
+ hpaFeatureAttribute.setOperator(operator);
+ hpaFeatureAttribute.setUnit(unit);
+
+ validateReport(hpaAttributeKey,hpaAttributeValue,operator,unit,hpaFeatureAttribute);
+ }
+
+ private void validateReport(final String hpaAttributeKey, final String hpaAttributeValue, final String operator,
+ final String unit, final HpaFeatureAttribute hpaFeatureAttribute) {
+ assertEquals(hpaAttributeKey, hpaFeatureAttribute.getHpaAttributeKey());
+ assertEquals(hpaAttributeValue, hpaFeatureAttribute.getHpaAttributeValue());
+ assertEquals(operator, hpaFeatureAttribute.getOperator());
+ assertEquals(unit, hpaFeatureAttribute.getUnit());
+ }
+}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestPolicyDecoderCsarPdpx.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestPolicyDecoderCsarPdpx.java
new file mode 100644
index 00000000..1ce5786c
--- /dev/null
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestPolicyDecoderCsarPdpx.java
@@ -0,0 +1,66 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.junit.Test;
+import org.onap.policy.distribution.model.Csar;
+
+/**
+ * Class to perform unit test of {@link PolicyDecoderCsarPdpx}.
+ *
+ */
+public class TestPolicyDecoderCsarPdpx {
+
+ @Test
+ public void testHpaPolicy2Vnf() throws IOException {
+ Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar");
+
+ PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx();
+ try {
+ Collection<PdpxPolicy> ret = policyDecoderCsarPdpx.decode(csar);
+ assertEquals(2, ret.size());
+ } catch (Exception e) {
+ fail("test should not thrown an exception here: " + e.getMessage());
+ }
+ }
+
+ @Test
+ public void testHpaPolicyFeature() throws IOException {
+ Csar csar = new Csar("src/test/resources/hpaPolicySRIOV.csar");
+
+ PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx();
+ try {
+ Collection<PdpxPolicy> ret = policyDecoderCsarPdpx.decode(csar);
+ assertEquals(2, ret.size());
+ } catch (Exception e) {
+ fail("test should not thrown an exception here: " + e.getMessage());
+ }
+ }
+}
diff --git a/plugins/reception-plugins/src/test/resources/hpaPolicySRIOV.csar b/plugins/reception-plugins/src/test/resources/hpaPolicySRIOV.csar
new file mode 100644
index 00000000..f79d2866
--- /dev/null
+++ b/plugins/reception-plugins/src/test/resources/hpaPolicySRIOV.csar
Binary files differ
diff --git a/plugins/reception-plugins/src/test/resources/service-TestNs8-csar.csar b/plugins/reception-plugins/src/test/resources/service-TestNs8-csar.csar
new file mode 100644
index 00000000..4bed54e1
--- /dev/null
+++ b/plugins/reception-plugins/src/test/resources/service-TestNs8-csar.csar
Binary files differ