aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--model/src/main/java/org/onap/policy/distribution/model/OptimizationPolicy.java7
-rw-r--r--packages/policy-distribution-tarball/src/main/resources/etc/defaultConfig.json62
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java6
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ConfigBody.java97
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java208
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java2
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java36
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterBuilder.java95
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterGroup.java112
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java20
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestAttribute.java2
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java6
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestDirective.java2
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java2
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java4
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java4
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java176
-rw-r--r--plugins/reception-plugins/src/test/resources/hpaPolicyHugePage.csarbin0 -> 131275 bytes
-rw-r--r--plugins/reception-plugins/src/test/resources/hpaPolicyPciePassthrough.csarbin0 -> 131411 bytes
-rw-r--r--plugins/reception-plugins/src/test/resources/hpaPolicySriov.csar (renamed from plugins/reception-plugins/src/test/resources/hpaPolicySRIOV.csar)bin131336 -> 131404 bytes
20 files changed, 698 insertions, 143 deletions
diff --git a/model/src/main/java/org/onap/policy/distribution/model/OptimizationPolicy.java b/model/src/main/java/org/onap/policy/distribution/model/OptimizationPolicy.java
index 971077cc..71b7cef7 100644
--- a/model/src/main/java/org/onap/policy/distribution/model/OptimizationPolicy.java
+++ b/model/src/main/java/org/onap/policy/distribution/model/OptimizationPolicy.java
@@ -30,7 +30,6 @@ public class OptimizationPolicy implements Policy {
private static final String OPTIMIZATION = "Optimization";
private String policyName;
private String policyDescription;
- private String policyConfigType;
private String onapName;
private String configBody;
private String configBodyType;
@@ -62,11 +61,7 @@ public class OptimizationPolicy implements Policy {
}
public String getPolicyConfigType() {
- return policyConfigType;
- }
-
- public void setPolicyConfigType(final String policyConfigType) {
- this.policyConfigType = policyConfigType;
+ return OPTIMIZATION;
}
public String getOnapName() {
diff --git a/packages/policy-distribution-tarball/src/main/resources/etc/defaultConfig.json b/packages/policy-distribution-tarball/src/main/resources/etc/defaultConfig.json
index 4a0013c2..01aefb24 100644
--- a/packages/policy-distribution-tarball/src/main/resources/etc/defaultConfig.json
+++ b/packages/policy-distribution-tarball/src/main/resources/etc/defaultConfig.json
@@ -10,15 +10,35 @@
"SDCReceptionHandler":{
"receptionHandlerType":"SDC",
"receptionHandlerClassName":"org.onap.policy.distribution.reception.handling.sdc.SdcReceptionHandler",
- "pssdConfiguration":{
- "asdcAddress": "localhost",
+ "receptionHandlerConfigurationName":"sdcConfiguration",
+ "pluginHandlerParameters":{
+ "policyDecoders":{
+ "CsarDecoder":{
+ "decoderType":"CsarDecoder",
+ "decoderClassName":"org.onap.policy.distribution.reception.decoding.pdpx.PolicyDecoderCsarPdpx",
+ "decoderConfigurationName": "csarToOptimizationPolicyConfiguration"
+ }
+ },
+ "policyForwarders":{
+ "PAPEngineForwarder":{
+ "forwarderType":"PAPEngine",
+ "forwarderClassName":"org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarder",
+ "forwarderConfigurationName": "xacmlPdpConfiguration"
+ }
+ }
+ }
+ }
+ },
+ "receptionHandlerConfigurationParameters":{
+ "sdcConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.reception.handling.sdc.SdcReceptionHandlerConfigurationParameterGroup",
+ "parameters":{
+ "asdcAddress": "sdc-be.onap:8443",
"messageBusAddress": [
- "a.com",
- "b.com",
- "c.com"
+ "message-router.onap"
],
- "user": "tbdsdc-1480",
- "password": "tbdsdc-1480",
+ "user": "sdc-1480",
+ "password": "sdc-1480",
"pollingInterval":20,
"pollingTimeout":30,
"consumerId": "policy-id",
@@ -33,21 +53,19 @@
"activeserverTlsAuth": false,
"isFilterinEmptyResources": true,
"isUseHttpsWithDmaap": false
- },
- "pluginHandlerParameters":{
- "policyDecoders":{
- "TOSCADecoder":{
- "decoderType":"ToscaDecoder",
- "decoderClassName":"org.onap.policy.distribution.reception.decoding.pdpx.PolicyDecoderToscaPdpx"
- }
- },
- "policyForwarders":{
- "PAPEngineForwarder":{
- "forwarderType":"PAPEngine",
- "forwarderClassName":"org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarder",
- "forwarderConfigurationName": "xacmlPdpConfiguration"
- }
- }
+ }
+ }
+ },
+ "policyDecoderConfigurationParameters":{
+ "csarToOptimizationPolicyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.reception.decoding.pdpx.PolicyDecoderCsarPdpxConfigurationParameterGroup",
+ "parameters":{
+ "policyNamePrefix": "oofCasablanca",
+ "onapName": "OOF",
+ "version": "1.0",
+ "priority": "3",
+ "riskType": "Test",
+ "riskLevel": "2"
}
}
},
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java
index d851b640..9ef88b43 100644
--- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java
@@ -99,7 +99,6 @@ public class XacmlPdpPolicyForwarderTest {
OptimizationPolicy policy1 = new OptimizationPolicy();
policy1.setPolicyName("policy1");
- policy1.setPolicyConfigType("Optimization");
policies.add(policy1);
Policy policy2 = new UnsupportedPolicy();
@@ -107,7 +106,6 @@ public class XacmlPdpPolicyForwarderTest {
OptimizationPolicy policy3 = new OptimizationPolicy();
policy3.setPolicyName("policy3");
- policy3.setPolicyConfigType("Optimization");
policies.add(policy3);
forwarder.forward(policies);
@@ -143,7 +141,6 @@ public class XacmlPdpPolicyForwarderTest {
Collection<Policy> policies = new ArrayList<>();
OptimizationPolicy policy = new OptimizationPolicy();
policy.setPolicyName("policy");
- policy.setPolicyConfigType("Optimization");
policies.add(policy);
forwarder.forward(policies);
@@ -172,7 +169,6 @@ public class XacmlPdpPolicyForwarderTest {
Collection<Policy> policies = new ArrayList<>();
OptimizationPolicy policy = new OptimizationPolicy();
policy.setPolicyName("policy");
- policy.setPolicyConfigType("Optimization");
policies.add(policy);
forwarder.forward(policies);
@@ -202,7 +198,6 @@ public class XacmlPdpPolicyForwarderTest {
Collection<Policy> policies = new ArrayList<>();
OptimizationPolicy policy = new OptimizationPolicy();
policy.setPolicyName("policy");
- policy.setPolicyConfigType("Optimization");
policies.add(policy);
forwarder.forward(policies);
@@ -232,7 +227,6 @@ public class XacmlPdpPolicyForwarderTest {
Collection<Policy> policies = new ArrayList<>();
OptimizationPolicy policy = new OptimizationPolicy();
policy.setPolicyName("policy");
- policy.setPolicyConfigType("Optimization");
policies.add(policy);
forwarder.forward(policies);
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
new file mode 100644
index 00000000..72d9bd2b
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ConfigBody.java
@@ -0,0 +1,97 @@
+/*-
+ * ============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 description;
+ 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 getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ 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/ExtractFromNode.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java
index 4e7f9411..7c839a28 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java
@@ -20,15 +20,15 @@
package org.onap.policy.distribution.reception.decoding.pdpx;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-import java.io.FileWriter;
-import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
@@ -37,6 +37,8 @@ import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.toscaparser.api.CapabilityAssignment;
import org.onap.sdc.toscaparser.api.CapabilityAssignments;
import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.RequirementAssignment;
+import org.onap.sdc.toscaparser.api.elements.Metadata;
/**
* Extract concerned info from NodeTemplate, currently ONLY HPA Feature.
@@ -51,7 +53,17 @@ public class ExtractFromNode {
private static final String VIRTUAL_MEM_SIZE_PATH = "virtual_memory#virtual_mem_size";
private static final String NUM_VIRTUAL_CPU_PATH = "virtual_cpu#num_virtual_cpu";
private static final String CPU_ARCHITECTURE_PATH = "virtual_cpu#cpu_architecture";
- private static final String BASIC_CAPABILITIES = "BasicCapabilities";
+ private static final String MEMORY_PAGE_SIZE_PATH = "virtual_memory#vdu_memory_requirements#memoryPageSize";
+ private static final String NETWORK_INTERFACE_TYPE_PATH =
+ "virtual_network_interface_requirements#network_interface_requirements#interfaceType";
+ private static final String NETWORK_PCI_PATH =
+ "virtual_network_interface_requirements#nic_io_requirements";
+ private static final String BASIC_CAPABILITIES_HPA_FEATURE = "BasicCapabilities";
+ private static final String HUGE_PAGES_HPA_FEATURE = "hugePages";
+ private static final Map<String, String> NETWORK_HPA_FEATURE_MAP = new HashMap() {{
+ put("SR-IOV", "SriovNICNetwork");
+ put("PCI-Passthrough", "pciePassthrough");
+ }};
ISdcCsarHelper sdcCsarHelper;
final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().disableHtmlEscaping().create();
@@ -61,14 +73,16 @@ public class ExtractFromNode {
}
/**
- * 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.
+ * 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(final NodeTemplate node) throws PolicyDecodingException {
+ public Content extractInfo(final NodeTemplate node) throws PolicyDecodingException {
LOGGER.debug("the meta data of this nodetemplate = " + sdcCsarHelper.getNodeTemplateMetadata(node));
final List<NodeTemplate> lnodeChild = sdcCsarHelper.getNodeTemplateChildren(node);
@@ -91,31 +105,23 @@ public class ExtractFromNode {
LOGGER.debug("the size of vdu is =" + lnodeVdu.size());
LOGGER.debug("the size of cp is =" + lnodeVduCp.size());
- final PdpxPolicy pdpxPolicy = new PdpxPolicy();
- final Content content = pdpxPolicy.getContent();
+ final Content content = new Content();
extractInfoVdu(lnodeVdu, content);
extractInfoVduCp(lnodeVduCp, content);
if (content.getFlavorFeatures().isEmpty()) {
return null;
}
- String outputFile = sdcCsarHelper.getNodeTemplateMetadata(node).getValue("name");
- outputFile += ".json";
- LOGGER.debug("outputFile = " + outputFile);
- try (Writer writer = new FileWriter(outputFile)) {
- gson.toJson(pdpxPolicy, writer);
- } catch (final Exception exp) {
- final String message = "Failed writing generated policies to file";
- LOGGER.error(message, exp);
- throw new PolicyDecodingException(message, exp);
- }
- return pdpxPolicy;
+
+ return content;
}
/**
- * ExtractInfofromVdu, supported hpa features, All under the capability of tosca.nodes.nfv.Vdu.Compute.
+ * 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, final Content content) {
@@ -136,43 +142,43 @@ public class ExtractFromNode {
capabilityAssignments.getCapabilityByName("virtual_compute");
if (capabilityAssignment != null) {
generateBasicCapability(capabilityAssignment, flavorFeature);
- generateHugePages(capabilityAssignment);
+ generateHugePages(capabilityAssignment,flavorFeature);
}
content.getFlavorFeatures().add(flavorFeature);
}
}
/**
- * GenerateBasicCapability, supported hpa features, All under the capability of tosca.nodes.nfv.Vdu.Compute.
+ * 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);
+ private void generateBasicCapability(final CapabilityAssignment capabilityAssignment, FlavorFeature flavorFeature){
+ //the format is xxx MB/GB like 4096 MB
+ String virtualMemSize = sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment,
+ VIRTUAL_MEM_SIZE_PATH);
if (virtualMemSize != null) {
LOGGER.debug("the virtualMemSize = " + virtualMemSize);
- final HpaFeatureAttribute hpaFeatureAttribute =
- generateHpaFeatureAttribute("virtualMemSize", virtualMemSize);
- final FlavorProperty flavorProperty = new FlavorProperty();
- flavorProperty.setHpaFeature(BASIC_CAPABILITIES);
+ HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute("virtualMemSize", virtualMemSize);
+ FlavorProperty flavorProperty = new FlavorProperty();
+ flavorProperty.setHpaFeature(BASIC_CAPABILITIES_HPA_FEATURE);
flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute);
flavorFeature.getFlavorProperties().add(flavorProperty);
}
-
- // the format is int like 2
- final String numVirtualCpu =
- sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, NUM_VIRTUAL_CPU_PATH);
+
+ //the format is int like 2
+ String numVirtualCpu = sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment,
+ NUM_VIRTUAL_CPU_PATH);
if (numVirtualCpu != null) {
LOGGER.debug("the numVirtualCpu = " + numVirtualCpu);
- final HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute("numVirtualCpu", numVirtualCpu);
- final String cpuArchitecture =
- sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, CPU_ARCHITECTURE_PATH);
- final FlavorProperty flavorProperty = new FlavorProperty();
- flavorProperty.setHpaFeature(BASIC_CAPABILITIES);
+ HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute("numVirtualCpu", numVirtualCpu);
+ String cpuArchitecture = sdcCsarHelper.getCapabilityPropertyLeafValue
+ (capabilityAssignment,CPU_ARCHITECTURE_PATH);
+ FlavorProperty flavorProperty = new FlavorProperty();
+ flavorProperty.setHpaFeature(BASIC_CAPABILITIES_HPA_FEATURE);
if (cpuArchitecture != null) {
flavorProperty.setArchitecture(cpuArchitecture);
}
@@ -182,14 +188,17 @@ public class ExtractFromNode {
}
/**
- * GenerateHpaFeatureAttribute based on the value of featureValue. the format: "hpa-attribute-key": "pciVendorId",
- * "hpa-attribute-value": "1234", "operator": "=", "unit": "xxx".
+ * 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 tmp = featureValue.replace(" ", "");
@@ -208,15 +217,35 @@ public class ExtractFromNode {
}
/**
- * GenerateHugePages, supported hpa features, All under the capability of tosca.nodes.nfv.Vdu.Compute. The format is
- * a map like: {"schema-version": "0", "schema-location": "", "platform-id": "generic", "mandatory": true,
- * "configuration-value": "2 MB"}
+ * GenerateHugePages, supported hpa features, All under the capability of
+ * tosca.nodes.nfv.Vdu.Compute. The format is a map like: {"schema-version": "0",
+ * "schema-location": "", "platform-id": "generic", "mandatory": true, "configuration-value": "2
+ * MB"}
*
* @param capabilityAssignment represents the capability of node
+ *
* @param flavorFeature represents all the features of specified flavor
*/
- private void generateHugePages(final CapabilityAssignment capabilityAssignment) {
- // add HugePages support
+ private void generateHugePages(final CapabilityAssignment capabilityAssignment, FlavorFeature flavorFeature){
+ String memoryPageSize = sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment,
+ MEMORY_PAGE_SIZE_PATH);
+ LOGGER.debug("the memoryPageSize = " + memoryPageSize);
+ if (memoryPageSize != null) {
+ Map<String, Object> retMap = gson.fromJson(memoryPageSize,
+ new TypeToken<HashMap<String, Object>>() {}.getType());
+ LOGGER.debug("the retMap = " + retMap);
+ String memoryPageSizeValue = retMap.get("configuration-value").toString();
+ String mandatory = retMap.get("mandatory").toString();
+ HpaFeatureAttribute hpaFeatureAttribute =
+ generateHpaFeatureAttribute("memoryPageSize",memoryPageSizeValue);
+ FlavorProperty flavorProperty = new FlavorProperty();
+ flavorProperty.setHpaFeature(HUGE_PAGES_HPA_FEATURE);
+ if (mandatory != null) {
+ flavorProperty.setMandatory(mandatory);
+ }
+ flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute);
+ flavorFeature.getFlavorProperties().add(flavorProperty);
+ }
}
/**
@@ -224,10 +253,81 @@ public class ExtractFromNode {
* 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<NodeTemplate> lnodeVduCp, final Content content) {
- // to add VDU cp Hpa feature extract
- }
+ public void extractInfoVduCp(final List<NodeTemplate> lnodeVduCp, Content content) throws PolicyDecodingException {
+ // each CP will binds to a VDU so need the vdu flavor map info.
+ Map<String, FlavorFeature> vduFlavorMap = new HashMap<>();
+ for ( FlavorFeature flavorFeature: content.getFlavorFeatures()) {
+ LOGGER.debug("the id = " + flavorFeature.getId());
+ vduFlavorMap.put(flavorFeature.getId(),flavorFeature);
+ }
+ for ( NodeTemplate node : lnodeVduCp) {
+ String interfaceType = sdcCsarHelper.getNodeTemplatePropertyLeafValue(node,NETWORK_INTERFACE_TYPE_PATH);
+ LOGGER.debug("the interfaceType = " + interfaceType);
+ Map<String, Object> retMap = new HashMap<>();
+ if (interfaceType != null) {
+ retMap = gson.fromJson(interfaceType, new TypeToken<HashMap<String, Object>>() {}.getType());
+ LOGGER.debug("the retMap = " + retMap);
+ }
+
+ String networkHpaFeature;
+ if ( retMap.containsKey("configuration-value")) {
+ String interfaceTypeValue = retMap.get("configuration-value").toString();
+ LOGGER.debug(" the interfacetype value is =" + interfaceTypeValue);
+ if ( NETWORK_HPA_FEATURE_MAP.containsKey(interfaceTypeValue)) {
+ networkHpaFeature = NETWORK_HPA_FEATURE_MAP.get(interfaceTypeValue);
+ LOGGER.debug(" the networkHpaFeature is =" + networkHpaFeature);
+ } else {
+ LOGGER.debug(" unspported network interface ");
+ return;
+ }
+ }else{
+ LOGGER.debug(" no configuration-value defined in interfaceType");
+ return;
+ }
+
+ for (RequirementAssignment requriement: sdcCsarHelper.getRequirementsOf(node).getAll()) {
+ String nodeTemplateName = requriement.getNodeTemplateName().toLowerCase();
+ LOGGER.debug("getNodeTemplateName =" + nodeTemplateName);
+ if ( nodeTemplateName == null) {
+ continue;
+ }
+ if (!vduFlavorMap.containsKey(nodeTemplateName)) {
+ throw new PolicyDecodingException("vdu Flavor Map should contains the key " + nodeTemplateName);
+ }
+ generateNetworkFeature(networkHpaFeature, node, vduFlavorMap.get(nodeTemplateName));
+ }
+ }
+ }
+ /*
+ * GenerateNetworkFeature, all pci feature are grouped into FlavorFeature together.
+ *
+ * @param networkHpaFeature represents the specified Hpa feature
+ * @param node represents the CP Node
+ * @param flavorFeature represents all the features of specified flavor
+ */
+ private void generateNetworkFeature(final String networkHpaFeature, final NodeTemplate node, FlavorFeature flavorFeature) {
+ //the format is a map like: {"schema-version": "0", "schema-location": "", "platform-id": "generic",
+ // "mandatory": true, "configuration-value": "2 MB"}
+ FlavorProperty flavorProperty = new FlavorProperty();
+ flavorProperty.setHpaFeature(networkHpaFeature);
+ String[] pciKeys = { "pciVendorId", "pciDeviceId", "pciNumDevices", "physicalNetwork"};
+ for (String pciKey: pciKeys) {
+ LOGGER.debug("the pciKey = " + pciKey);
+ String pciKeyPath = NETWORK_PCI_PATH + "#" + pciKey;
+ String pciValue = sdcCsarHelper.getNodeTemplatePropertyLeafValue(node,pciKeyPath);
+ if (pciValue != null) {
+ LOGGER.debug("the pciValue = " + pciValue);
+ Map<String, Object> retMap = gson.fromJson(pciValue, new TypeToken<HashMap<String, Object>>() {}.getType());
+ String pciConfigValue = retMap.get("configuration-value").toString();
+ HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute(pciKey,pciConfigValue);
+ flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute);
+ }
+ }
+ flavorFeature.getFlavorProperties().add(flavorProperty);
+ }
}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java
index 1617956f..91008aa5 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java
@@ -30,7 +30,7 @@ import com.google.gson.annotations.SerializedName;
class HpaFeatureAttribute {
@SerializedName(value = "hpa-attribute-key")
private String hpaAttributeKey;
- @SerializedName(value = "hap-attribute-value")
+ @SerializedName(value = "hpa-attribute-value")
private String hpaAttributeValue;
private String operator;
private String unit;
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
index 03f0c041..030c470b 100644
--- 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
@@ -20,14 +20,17 @@
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.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
+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;
@@ -38,25 +41,40 @@ import org.onap.sdc.toscaparser.api.NodeTemplate;
/**
* Decodes PDP-X policies from a CSAR file.
*/
-public class PolicyDecoderCsarPdpx implements PolicyDecoder<Csar, PdpxPolicy> {
+public class PolicyDecoderCsarPdpx implements PolicyDecoder<Csar, OptimizationPolicy> {
private static final Logger LOGGER = FlexLogger.getLogger(PolicyDecoderCsarPdpx.class);
+ private final Gson gson = new GsonBuilder().serializeNulls().disableHtmlEscaping().create();
+ private PolicyDecoderCsarPdpxConfigurationParameterGroup decoderParameters;
@Override
- public Collection<PdpxPolicy> decode(final Csar csar) throws PolicyDecodingException {
- final List<PdpxPolicy> lPdpxPolicy = new ArrayList<>();
+ public Collection<OptimizationPolicy> decode(final Csar csar) throws PolicyDecodingException {
+ final List<OptimizationPolicy> policys = new ArrayList<>();
final ISdcCsarHelper sdcCsarHelper = parseCsar(csar);
final List<NodeTemplate> lnodeVf = sdcCsarHelper.getServiceVfList();
LOGGER.debug("the size of Vf = " + lnodeVf.size());
final ExtractFromNode extractFromNode = new ExtractFromNode();
extractFromNode.setSdcCsarHelper(sdcCsarHelper);
for (final NodeTemplate node : lnodeVf) {
- final PdpxPolicy ret = extractFromNode.extractInfo(node);
- if (ret != null) {
- lPdpxPolicy.add(ret);
+ final Content content = extractFromNode.extractInfo(node);
+ if (content != null) {
+ final OptimizationPolicy policy = new OptimizationPolicy();
+ policy.setOnapName(decoderParameters.getOnapName());
+ policy.setPolicyName(decoderParameters.getPolicyNamePrefix() + "." + content.getIdentity());
+ ConfigBody configBody = new ConfigBody();
+ configBody.setService("hpaPolicy");
+ configBody.setDescription("OOF Policy");
+ configBody.setVersion(decoderParameters.getVersion());
+ configBody.setPriority(decoderParameters.getPriority());
+ configBody.setRiskLevel(decoderParameters.getRiskLevel());
+ configBody.setRiskType(decoderParameters.getRiskType());
+ configBody.setGuard("false");
+ configBody.setContent(content);
+ policy.setConfigBody(gson.toJson(configBody));
+ policys.add(policy);
}
}
- return lPdpxPolicy;
+ return policys;
}
@Override
@@ -88,6 +106,6 @@ public class PolicyDecoderCsarPdpx implements PolicyDecoder<Csar, PdpxPolicy> {
@Override
public void configure(final String parameterGroupName) {
- throw new UnsupportedOperationException("The method is not supprted");
+ decoderParameters = ParameterService.get(parameterGroupName);
}
}
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterBuilder.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterBuilder.java
new file mode 100644
index 00000000..199d582b
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterBuilder.java
@@ -0,0 +1,95 @@
+/*-
+ * ============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;
+
+/**
+ * This class builds an instance of {@link PolicyDecodeCsarPdpxConfigurationParameterGroup} class.
+ */
+public class PolicyDecoderCsarPdpxConfigurationParameterBuilder {
+
+ private String policyNamePrefix;
+ private String onapName;
+ private String version;
+ private String priority;
+ private String riskType;
+ private String riskLevel;
+
+ public PolicyDecoderCsarPdpxConfigurationParameterBuilder setPolicyNamePrefix(final String policyNamePrefix) {
+ this.policyNamePrefix = policyNamePrefix;
+ return this;
+ }
+
+ public PolicyDecoderCsarPdpxConfigurationParameterBuilder setOnapName(final String onapName) {
+ this.onapName = onapName;
+ return this;
+ }
+
+ public PolicyDecoderCsarPdpxConfigurationParameterBuilder setVersion(final String version) {
+ this.version = version;
+ return this;
+ }
+
+ public PolicyDecoderCsarPdpxConfigurationParameterBuilder setPriority(final String priority) {
+ this.priority = priority;
+ return this;
+ }
+
+ public PolicyDecoderCsarPdpxConfigurationParameterBuilder setRiskType(final String riskType) {
+ this.riskType = riskType;
+ return this;
+ }
+
+ public PolicyDecoderCsarPdpxConfigurationParameterBuilder setRiskLevel(final String riskLevel) {
+ this.riskLevel = riskLevel;
+ return this;
+ }
+
+ public PolicyDecoderCsarPdpxConfigurationParameterGroup build() {
+ return new PolicyDecoderCsarPdpxConfigurationParameterGroup(this);
+ }
+
+ public String getPolicyNamePrefix() {
+ return policyNamePrefix;
+ }
+
+ public String getOnapName() {
+ return onapName;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public String getPriority() {
+ return priority;
+ }
+
+ public String getRiskType() {
+ return riskType;
+ }
+
+ public String getRiskLevel() {
+ return riskLevel;
+ }
+
+}
+
+
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
new file mode 100644
index 00000000..d785b827
--- /dev/null
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterGroup.java
@@ -0,0 +1,112 @@
+/*-
+ * ============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 org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.distribution.reception.handling.sdc.SdcReceptionHandlerConfigurationParameterGroup;
+import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup;
+
+/**
+ * This class handles reading, parsing and validating of the paramaters for the
+ * {@link PolicyDecoderCsarPdpx}
+ */
+public class PolicyDecoderCsarPdpxConfigurationParameterGroup extends PolicyDecoderConfigurationParameterGroup {
+
+ private String policyNamePrefix;
+ private String onapName;
+ private String version;
+ private String priority;
+ private String riskType;
+ private String riskLevel;
+
+ /**
+ * The constructor for instantiating {@link SdcReceptionHandlerConfigurationParameterGroup}
+ * class.
+ *
+ * @param builder the SDC configuration builder
+ */
+ public PolicyDecoderCsarPdpxConfigurationParameterGroup(
+ final PolicyDecoderCsarPdpxConfigurationParameterBuilder builder) {
+ policyNamePrefix = builder.getPolicyNamePrefix();
+ onapName = builder.getOnapName();
+ version = builder.getVersion();
+ priority = builder.getPriority();
+ riskType = builder.getRiskType();
+ riskLevel = builder.getRiskLevel();
+ }
+
+ public String getPolicyNamePrefix() {
+ return policyNamePrefix;
+ }
+
+ public String getOnapName() {
+ return onapName;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public String getPriority() {
+ return priority;
+ }
+
+ public String getRiskType() {
+ return riskType;
+ }
+
+ public String getRiskLevel() {
+ return riskLevel;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GroupValidationResult validate() {
+ final GroupValidationResult validationResult = new GroupValidationResult(this);
+ validateStringElement(validationResult, policyNamePrefix, "policyNamePrefix");
+ validateStringElement(validationResult, onapName, "onapName");
+ validateStringElement(validationResult, version, "version");
+ validateStringElement(validationResult, priority, "priority");
+ validateStringElement(validationResult, riskType, "riskType");
+ validateStringElement(validationResult, riskLevel, "riskLevel");
+ return validationResult;
+ }
+
+ /**
+ * Validate the string element.
+ *
+ * @param validationResult the result object
+ * @param element the element to validate
+ * @param elementName the element name for error message
+ */
+ private void validateStringElement(final GroupValidationResult validationResult, final String element,
+ final String elementName) {
+ if (!ParameterValidationUtils.validateStringParameter(element)) {
+ validationResult.setResult(elementName, ValidationStatus.INVALID,
+ elementName + " must be a non-blank string");
+ }
+ }
+}
+
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java
index bbee652a..0140fb53 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandlerConfigurationParameterGroup.java
@@ -21,16 +21,15 @@
package org.onap.policy.distribution.reception.handling.sdc;
import java.util.List;
-import java.util.UUID;
-
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.common.utils.validation.ParameterValidationUtils;
import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
/**
- * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json
- * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK.
+ * This class handles reading, parsing and validating of the Policy SDC Service Distribution
+ * parameters from Json format, which strictly adheres to the interface:IConfiguration, defined by
+ * SDC SDK.
*/
public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup {
@@ -51,7 +50,8 @@ public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHan
private boolean isUseHttpsWithDmaap;
/**
- * The constructor for instantiating {@link SdcReceptionHandlerConfigurationParameterGroup} class.
+ * The constructor for instantiating {@link SdcReceptionHandlerConfigurationParameterGroup}
+ * class.
*
* @param builder the SDC configuration builder
*/
@@ -136,16 +136,6 @@ public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHan
}
/**
- * Set the name of this group.
- *
- * @param name the name to set.
- */
- @Override
- public void setName(final String name) {
- super.setName(name + "_" + UUID.randomUUID().toString());
- }
-
- /**
* {@inheritDoc}
*/
@Override
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestAttribute.java
index f11a7ecd..565f17d3 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestAttribute.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestAttribute.java
@@ -39,7 +39,7 @@ public class TestAttribute {
attribute.setAttributeName(attributeName);
attribute.setAttributeValue(attributeValue);
- validateReport(attributeName,attributeValue,attribute);
+ validateReport(attributeName, attributeValue, attribute);
}
private void validateReport(final String name, final String value, final Attribute attribute) {
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java
index a329a3ee..56534d8f 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java
@@ -41,11 +41,11 @@ public class TestContent {
content.setIdentity(identity);
content.setPolicyType(policyType);
- validateReport(resources, identity, policyType,content);
+ validateReport(resources, identity, policyType, content);
}
- private void validateReport(final String resources, final String identity, final String policyType,
- final Content 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());
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestDirective.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestDirective.java
index 48d11d32..cc8d946f 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestDirective.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestDirective.java
@@ -37,7 +37,7 @@ public class TestDirective {
final Directive directive = new Directive();
directive.setType(type);
- validateReport(type,directive);
+ validateReport(type, directive);
}
private void validateReport(final String type, final Directive directive) {
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java
index 47b4e343..e4de2759 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java
@@ -39,7 +39,7 @@ public class TestFlavorFeature {
flavorFeature.setId(id);
flavorFeature.setType(type);
- validateReport(id,type,flavorFeature);
+ validateReport(id, type, flavorFeature);
}
private void validateReport(final String id, final String type, final FlavorFeature flavorFeature) {
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java
index b5a535d7..da6c26fc 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java
@@ -43,11 +43,11 @@ public class TestFlavorProperty {
flavorProperty.setArchitecture(architecture);
flavorProperty.setHpaVersion(hpaVersion);
- validateReport(hpaFeature,mandatory,architecture,hpaVersion,flavorProperty);
+ validateReport(hpaFeature, mandatory, architecture, hpaVersion, flavorProperty);
}
private void validateReport(final String hpaFeature, final String mandatory, final String architecture,
- final String hpaVersion, final FlavorProperty flavorProperty) {
+ final String hpaVersion, final FlavorProperty flavorProperty) {
assertEquals(hpaFeature, flavorProperty.getHpaFeature());
assertEquals(mandatory, flavorProperty.getMandatory());
assertEquals(architecture, flavorProperty.getArchitecture());
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java
index 40c30eb7..f2f514d0 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java
@@ -43,11 +43,11 @@ public class TestHpaFeatureAttribute {
hpaFeatureAttribute.setOperator(operator);
hpaFeatureAttribute.setUnit(unit);
- validateReport(hpaAttributeKey,hpaAttributeValue,operator,unit,hpaFeatureAttribute);
+ validateReport(hpaAttributeKey, hpaAttributeValue, operator, unit, hpaFeatureAttribute);
}
private void validateReport(final String hpaAttributeKey, final String hpaAttributeValue, final String operator,
- final String unit, final HpaFeatureAttribute hpaFeatureAttribute) {
+ final String unit, final HpaFeatureAttribute hpaFeatureAttribute) {
assertEquals(hpaAttributeKey, hpaFeatureAttribute.getHpaAttributeKey());
assertEquals(hpaAttributeValue, hpaFeatureAttribute.getHpaAttributeValue());
assertEquals(operator, hpaFeatureAttribute.getOperator());
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java
index 1ce5786c..0585b23a 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java
@@ -21,16 +21,17 @@
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 static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.Collection;
-
+import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.common.parameters.ParameterGroup;
+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.reception.decoding.PolicyDecodingException;
/**
* Class to perform unit test of {@link PolicyDecoderCsarPdpx}.
@@ -38,29 +39,164 @@ import org.onap.policy.distribution.model.Csar;
*/
public class TestPolicyDecoderCsarPdpx {
+ private static final String CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION = "csarToOptimizationPolicyConfiguration";
+
+ /**
+ * Set up for test cases.
+ */
+ @BeforeClass
+ public static void setUp() {
+ ParameterGroup parameterGroup = new PolicyDecoderCsarPdpxConfigurationParameterBuilder().setOnapName("onapName")
+ .setPolicyNamePrefix("OOF").setPriority("5").setRiskLevel("2").setRiskType("Test").setVersion("1.0")
+ .build();
+ parameterGroup.setName(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION);
+ ParameterService.register(parameterGroup);
+ }
+
@Test
- public void testHpaPolicy2Vnf() throws IOException {
+ public void testHpaPolicy2Vnf() throws IOException, PolicyDecodingException {
Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar");
+ PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx();
+ policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION);
+
+ Collection<OptimizationPolicy> ret = policyDecoderCsarPdpx.decode(csar);
+ assertEquals(2, ret.size());
+ OptimizationPolicy policy = (OptimizationPolicy) ret.toArray()[0];
+
+ assertEquals("onapName", policy.getOnapName());
+ assertTrue(policy.getPolicyName().startsWith("OOF."));
+ assertTrue(policy.getConfigBody().contains("\"priority\":\"5\""));
+ assertTrue(policy.getConfigBody().contains("\"riskLevel\":\"2\""));
+ assertTrue(policy.getConfigBody().contains("\"riskType\":\"Test\""));
+ assertTrue(policy.getConfigBody().contains("\"version\":\"1.0\""));
+ assertTrue(policy.getConfigBody().contains("\"policyType\":\"Optimization\""));
+
+ assertTrue(policy.getConfigBody().contains("\"id\":\"vdu_vnf_1\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directive\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-feature\":\"BasicCapabilities\""));
+ assertTrue(policy.getConfigBody().contains("\"mandatory\":\"true\""));
+ assertTrue(policy.getConfigBody().contains("\"architecture\":\"generic\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-version\":\"v1\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"virtualMemSize\""));
+ assertTrue(policy.getConfigBody().contains("\"operator\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"unit\":\"MB\""));
+ }
+
+ @Test
+ public void testHpaPolicySriov() throws IOException, PolicyDecodingException {
+ 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());
- }
+ policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION);
+
+ Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar);
+ OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0];
+
+ assertEquals("onapName", policy.getOnapName());
+ assertTrue(policy.getPolicyName().startsWith("OOF."));
+ assertTrue(policy.getConfigBody().contains("\"priority\":\"5\""));
+ assertTrue(policy.getConfigBody().contains("\"riskLevel\":\"2\""));
+ assertTrue(policy.getConfigBody().contains("\"riskType\":\"Test\""));
+ assertTrue(policy.getConfigBody().contains("\"version\":\"1.0\""));
+ assertTrue(policy.getConfigBody().contains("\"policyType\":\"Optimization\""));
+
+ assertTrue(policy.getConfigBody().contains("\"id\":\"vdu_vnf_1\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directive\""));
+ assertTrue(policy.getConfigBody().contains("\"attribute_name\":\"flavorName\""));
+ assertTrue(policy.getConfigBody().contains("\"attribute_value\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-feature\":\"SriovNICNetwork\""));
+ assertTrue(policy.getConfigBody().contains("\"mandatory\":\"true\""));
+ assertTrue(policy.getConfigBody().contains("\"architecture\":\"generic\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-version\":\"v1\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"pciVendorId\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"1234\""));
+ assertTrue(policy.getConfigBody().contains("\"operator\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"unit\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"pciDeviceId\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"5678\""));
+ assertTrue(policy.getConfigBody().contains("\"operator\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"unit\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"pciNumDevices\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"1\""));
+ assertTrue(policy.getConfigBody().contains("\"operator\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"unit\":\"\""));
}
@Test
- public void testHpaPolicyFeature() throws IOException {
- Csar csar = new Csar("src/test/resources/hpaPolicySRIOV.csar");
+ public void testHpaPolicyPciePassthrough() throws IOException, PolicyDecodingException {
+ Csar csar = new Csar("src/test/resources/hpaPolicyPciePassthrough.csar");
+ PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx();
+ policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION);
+
+ Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar);
+ assertEquals(2, policies.size());
+ OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0];
+
+ assertEquals("onapName", policy.getOnapName());
+ assertTrue(policy.getPolicyName().startsWith("OOF."));
+ assertTrue(policy.getConfigBody().contains("\"priority\":\"5\""));
+ assertTrue(policy.getConfigBody().contains("\"riskLevel\":\"2\""));
+ assertTrue(policy.getConfigBody().contains("\"riskType\":\"Test\""));
+ assertTrue(policy.getConfigBody().contains("\"version\":\"1.0\""));
+ assertTrue(policy.getConfigBody().contains("\"policyType\":\"Optimization\""));
+
+ assertTrue(policy.getConfigBody().contains("\"id\":\"vdu_vnf_1\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directive\""));
+ assertTrue(policy.getConfigBody().contains("\"attribute_name\":\"flavorName\""));
+ assertTrue(policy.getConfigBody().contains("\"attribute_value\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-feature\":\"pciePassthrough\""));
+ assertTrue(policy.getConfigBody().contains("\"mandatory\":\"true\""));
+ assertTrue(policy.getConfigBody().contains("\"architecture\":\"generic\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-version\":\"v1\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"pciVendorId\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"1234\""));
+ assertTrue(policy.getConfigBody().contains("\"operator\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"unit\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"pciDeviceId\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"5678\""));
+ assertTrue(policy.getConfigBody().contains("\"operator\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"unit\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"pciNumDevices\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"1\""));
+ assertTrue(policy.getConfigBody().contains("\"operator\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"unit\":\"\""));
+
+ }
+
+ @Test
+ public void testHpaPolicyHugePage() throws IOException, PolicyDecodingException {
+ Csar csar = new Csar("src/test/resources/hpaPolicyHugePage.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());
- }
+ policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION);
+
+ Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar);
+ assertEquals(2, policies.size());
+ OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0];
+
+ assertEquals("onapName", policy.getOnapName());
+ assertTrue(policy.getPolicyName().startsWith("OOF."));
+ assertTrue(policy.getConfigBody().contains("\"priority\":\"5\""));
+ assertTrue(policy.getConfigBody().contains("\"riskLevel\":\"2\""));
+ assertTrue(policy.getConfigBody().contains("\"riskType\":\"Test\""));
+ assertTrue(policy.getConfigBody().contains("\"version\":\"1.0\""));
+ assertTrue(policy.getConfigBody().contains("\"policyType\":\"Optimization\""));
+
+ assertTrue(policy.getConfigBody().contains("\"id\":\"vdu_vnf_1\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directive\""));
+ assertTrue(policy.getConfigBody().contains("\"attribute_name\":\"flavorName\""));
+ assertTrue(policy.getConfigBody().contains("\"attribute_value\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-feature\":\"hugePages\""));
+ assertTrue(policy.getConfigBody().contains("\"mandatory\":\"false\""));
+ assertTrue(policy.getConfigBody().contains("\"architecture\":\"generic\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-version\":\"v1\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"memoryPageSize\""));
+ assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"2\""));
+ assertTrue(policy.getConfigBody().contains("\"operator\":\"\""));
+ assertTrue(policy.getConfigBody().contains("\"unit\":\"MB\""));
}
}
diff --git a/plugins/reception-plugins/src/test/resources/hpaPolicyHugePage.csar b/plugins/reception-plugins/src/test/resources/hpaPolicyHugePage.csar
new file mode 100644
index 00000000..e1fdc70c
--- /dev/null
+++ b/plugins/reception-plugins/src/test/resources/hpaPolicyHugePage.csar
Binary files differ
diff --git a/plugins/reception-plugins/src/test/resources/hpaPolicyPciePassthrough.csar b/plugins/reception-plugins/src/test/resources/hpaPolicyPciePassthrough.csar
new file mode 100644
index 00000000..652bc877
--- /dev/null
+++ b/plugins/reception-plugins/src/test/resources/hpaPolicyPciePassthrough.csar
Binary files differ
diff --git a/plugins/reception-plugins/src/test/resources/hpaPolicySRIOV.csar b/plugins/reception-plugins/src/test/resources/hpaPolicySriov.csar
index f79d2866..ffe996a9 100644
--- a/plugins/reception-plugins/src/test/resources/hpaPolicySRIOV.csar
+++ b/plugins/reception-plugins/src/test/resources/hpaPolicySriov.csar
Binary files differ