summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java32
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApi.java325
2 files changed, 192 insertions, 165 deletions
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java
index eadca94d..8cfc6857 100644
--- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java
+++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java
@@ -23,7 +23,9 @@ package org.onap.policy.distribution.reception.decoding.pdpx;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -31,7 +33,12 @@ import org.onap.policy.distribution.model.Csar;
import org.onap.policy.distribution.model.PolicyInput;
import org.onap.policy.distribution.reception.decoding.PolicyDecoder;
import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
import org.onap.sdc.toscaparser.api.NodeTemplate;
@@ -47,6 +54,14 @@ public class PolicyDecoderCsarPdpxLifecycleApi implements PolicyDecoder<Csar, To
private final StandardCoder coder = new StandardCoder();
private PolicyDecoderCsarPdpxLifecycleApiParameters decoderParameters;
+ public static final String TOSCA_POLICY_SCOPE = "scope";
+ public static final String TOSCA_POLICY_SERVICES = "services";
+ public static final String TOSCA_POLICY_RESOURCES = "resources";
+ public static final String TOSCA_POLICY_IDENTITY = "identity";
+ public static final String TOSCA_POLICY_FLAVORFEATURES = "flavorfeatures";
+
+ public static final String TOSCA_POLICY_HPA_OOF = "Optimization";
+
@Override
public Collection<ToscaServiceTemplate> decode(final Csar csar) throws PolicyDecodingException {
final List<ToscaServiceTemplate> entities = new ArrayList<>();
@@ -61,7 +76,22 @@ public class PolicyDecoderCsarPdpxLifecycleApi implements PolicyDecoder<Csar, To
final Content content = extractFromNode.extractInfo(node);
if (content != null) {
final ToscaServiceTemplate entity = new ToscaServiceTemplate();
- // TODO: add the logic for creating ToscaServiceTemplate for HPA policy
+ Map<String, Object> props = new LinkedHashMap<>();
+ props.put(TOSCA_POLICY_SCOPE, content.getScope());
+ props.put(TOSCA_POLICY_SERVICES, content.getServices());
+ props.put(TOSCA_POLICY_RESOURCES, content.getResources());
+ props.put(TOSCA_POLICY_IDENTITY, content.getIdentity());
+ props.put(TOSCA_POLICY_FLAVORFEATURES, content.getFlavorFeatures());
+ ToscaPolicy policy = new ToscaPolicy();
+ policy.setProperties(props);
+ Map<String, ToscaPolicy> map = new LinkedHashMap<>();
+ String type = content.getPolicyType();
+ map.put(type, policy);
+ List<Map<String, ToscaPolicy>> policies = new ArrayList<>();
+ policies.add(map);
+ ToscaTopologyTemplate topologyTemplate = new ToscaTopologyTemplate();
+ topologyTemplate.setPolicies(policies);
+ entity.setToscaTopologyTemplate(topologyTemplate);
entities.add(entity);
}
}
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApi.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApi.java
index 02cf5e67..762549fa 100644
--- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApi.java
+++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApi.java
@@ -21,25 +21,38 @@
package org.onap.policy.distribution.reception.decoding.pdpx;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
+import java.lang.String;
import java.util.Collection;
+import java.util.List;
+import java.util.Map;
import org.junit.AfterClass;
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.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.distribution.model.Csar;
import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
+import org.onap.policy.distribution.reception.decoding.pdpx.FlavorFeature;
+import org.onap.policy.distribution.reception.decoding.pdpx.PolicyDecoderCsarPdpxLifecycleApi;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-
+import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
/**
- * Class to perform unit test of {@link PolicyDecoderCsarPdpxLifecycleApi}.
+ * Class to perform unit test of {@link PolicyDecoderCsarPdpxLifecycleApiLifecycleApi}.
*
*/
public class TestPolicyDecoderCsarPdpxLifecycleApi {
+ private final StandardCoder encoder = new StandardCoder();
+
/**
* Set up for test cases.
*/
@@ -61,7 +74,7 @@ public class TestPolicyDecoderCsarPdpxLifecycleApi {
}
@Test
- public void testHpaPolicy2Vnf() throws IOException, PolicyDecodingException {
+ public void testHpaPolicy2Vnf() throws IOException, PolicyDecodingException, CoderException {
final Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar");
final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi();
policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName());
@@ -69,208 +82,192 @@ public class TestPolicyDecoderCsarPdpxLifecycleApi {
final Collection<ToscaServiceTemplate> entities = policyDecoderCsarPdpx.decode(csar);
assertEquals(2, entities.size());
- // final ToscaServiceTemplate entity = entities.iterator().next();
- //
- // assertEquals("onapName", entity.getOnapName());
- // assertTrue(entity.getName().startsWith("OOF."));
- // assertTrue(entity.getConfigBody().contains("\"priority\":\"5\""));
- // assertTrue(entity.getConfigBody().contains("\"riskLevel\":\"2\""));
- // assertTrue(entity.getConfigBody().contains("\"riskType\":\"Test\""));
- // assertTrue(entity.getConfigBody().contains("\"version\":\"1.0\""));
- // assertTrue(entity.getConfigBody().contains("\"policyType\":\"hpa\""));
- //
- // assertTrue(entity.getConfigBody().contains("\"id\":\"VDU_vgw_0\""));
- // assertTrue(entity.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
- // assertTrue(entity.getConfigBody().contains("\"type\":\"flavor_directives\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-feature\":\"basicCapabilities\""));
- // assertTrue(entity.getConfigBody().contains("\"mandatory\":\"True\""));
- // assertTrue(entity.getConfigBody().contains("\"architecture\":\"generic\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-version\":\"v1\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"virtualMemSize\""));
- // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\""));
- // assertTrue(entity.getConfigBody().contains("\"unit\":\"MB\""));
+ final ToscaServiceTemplate entity = entities.iterator().next();
+ ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate();
+ Map<String, ToscaPolicy> map = topologyTemplate.getPolicies().get(0);
+ ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF);
+ Map<String, Object> props = policy.getProperties();
+ Object flavorFeatures =
+ props.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_FLAVORFEATURES);
+ String features = encoder.encode(flavorFeatures);
+ assertTrue(features.contains("\"id\":\"VDU_vgw_0\""));
+ assertTrue(features.contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
+ assertTrue(features.contains("\"type\":\"flavor_directives\""));
+ assertTrue(features.contains("\"hpa-feature\":\"basicCapabilities\""));
+ assertTrue(features.contains("\"mandatory\":\"True\""));
+ assertTrue(features.contains("\"architecture\":\"generic\""));
+ assertTrue(features.contains("\"hpa-version\":\"v1\""));
+ assertTrue(features.contains("\"hpa-attribute-key\":\"virtualMemSize\""));
+ assertTrue(features.contains("\"operator\":\"=\""));
+ assertTrue(features.contains("\"unit\":\"MB\""));
}
@Test
- public void testHpaPolicySriov() throws IOException, PolicyDecodingException {
- // final Csar csar = new Csar("src/test/resources/hpaPolicySriov.csar");
+ public void testHpaPolicySriov() throws IOException, PolicyDecodingException, CoderException {
+ final Csar csar = new Csar("src/test/resources/hpaPolicySriov.csar");
final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi();
policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName());
- // final Collection<ToscaServiceTemplate> entities = policyDecoderCsarPdpx.decode(csar);
- // final ToscaServiceTemplate entity = entities.iterator().next();
- //
- // assertEquals("onapName", entity.getOnapName());
- // assertTrue(entity.getName().startsWith("OOF."));
- // assertTrue(entity.getConfigBody().contains("\"priority\":\"5\""));
- // assertTrue(entity.getConfigBody().contains("\"riskLevel\":\"2\""));
- // assertTrue(entity.getConfigBody().contains("\"riskType\":\"Test\""));
- // assertTrue(entity.getConfigBody().contains("\"version\":\"1.0\""));
- // assertTrue(entity.getConfigBody().contains("\"policyType\":\"hpa\""));
- //
- // assertTrue(entity.getConfigBody().contains("\"id\":\"VDU_vgw_0\""));
- // assertTrue(entity.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
- // assertTrue(entity.getConfigBody().contains("\"type\":\"flavor_directives\""));
- // assertTrue(entity.getConfigBody().contains("\"attribute_name\":\"flavorName\""));
- // assertTrue(entity.getConfigBody().contains("\"attribute_value\":\"\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-feature\":\"sriovNICNetwork\""));
- // assertTrue(entity.getConfigBody().contains("\"mandatory\":\"True\""));
- // assertTrue(entity.getConfigBody().contains("\"architecture\":\"generic\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-version\":\"v1\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciVendorId\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"1234\""));
- // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\""));
- // assertTrue(entity.getConfigBody().contains("\"unit\":\"\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciDeviceId\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"5678\""));
- // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\""));
- // assertTrue(entity.getConfigBody().contains("\"unit\":\"\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciNumDevices\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"1\""));
- // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\""));
- // assertTrue(entity.getConfigBody().contains("\"unit\":\"\""));
+ final Collection<ToscaServiceTemplate> entities = policyDecoderCsarPdpx.decode(csar);
+ final ToscaServiceTemplate entity = entities.iterator().next();
+ ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate();
+ Map<String, ToscaPolicy> map = topologyTemplate.getPolicies().get(0);
+ ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF);
+ Map<String, Object> props = policy.getProperties();
+ Object flavorFeatures =
+ props.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_FLAVORFEATURES);
+ String features = encoder.encode(flavorFeatures);
+ assertTrue(features.contains("\"id\":\"VDU_vgw_0\""));
+ assertTrue(features.contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
+ assertTrue(features.contains("\"type\":\"flavor_directives\""));
+ assertTrue(features.contains("\"attribute_name\":\"flavorName\""));
+ assertTrue(features.contains("\"attribute_value\":\"\""));
+ assertTrue(features.contains("\"hpa-feature\":\"sriovNICNetwork\""));
+ assertTrue(features.contains("\"mandatory\":\"True\""));
+ assertTrue(features.contains("\"architecture\":\"generic\""));
+ assertTrue(features.contains("\"hpa-version\":\"v1\""));
+ assertTrue(features.contains("\"hpa-attribute-key\":\"pciVendorId\""));
+ assertTrue(features.contains("\"hpa-attribute-value\":\"1234\""));
+ assertTrue(features.contains("\"operator\":\"=\""));
+ assertTrue(features.contains("\"unit\":\"\""));
+ assertTrue(features.contains("\"hpa-attribute-key\":\"pciDeviceId\""));
+ assertTrue(features.contains("\"hpa-attribute-value\":\"5678\""));
+ assertTrue(features.contains("\"operator\":\"=\""));
+ assertTrue(features.contains("\"unit\":\"\""));
+ assertTrue(features.contains("\"hpa-attribute-key\":\"pciNumDevices\""));
+ assertTrue(features.contains("\"hpa-attribute-value\":\"1\""));
+ assertTrue(features.contains("\"operator\":\"=\""));
+ assertTrue(features.contains("\"unit\":\"\""));
}
@Test
- public void testHpaPolicyPciePassthrough() throws IOException, PolicyDecodingException {
+ public void testHpaPolicyPciePassthrough() throws IOException, PolicyDecodingException, CoderException {
final Csar csar = new Csar("src/test/resources/hpaPolicyPciePassthrough.csar");
final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi();
policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName());
final Collection<ToscaServiceTemplate> entities = policyDecoderCsarPdpx.decode(csar);
assertEquals(2, entities.size());
- // final ToscaServiceTemplate entity = entities.iterator().next();
- //
- // assertEquals("onapName", entity.getOnapName());
- // assertTrue(entity.getName().startsWith("OOF."));
- // assertTrue(entity.getConfigBody().contains("\"priority\":\"5\""));
- // assertTrue(entity.getConfigBody().contains("\"riskLevel\":\"2\""));
- // assertTrue(entity.getConfigBody().contains("\"riskType\":\"Test\""));
- // assertTrue(entity.getConfigBody().contains("\"version\":\"1.0\""));
- // assertTrue(entity.getConfigBody().contains("\"policyType\":\"hpa\""));
- //
- // assertTrue(entity.getConfigBody().contains("\"id\":\"VDU_vgw_0\""));
- // assertTrue(entity.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
- // assertTrue(entity.getConfigBody().contains("\"type\":\"flavor_directives\""));
- // assertTrue(entity.getConfigBody().contains("\"attribute_name\":\"flavorName\""));
- // assertTrue(entity.getConfigBody().contains("\"attribute_value\":\"\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-feature\":\"pciePassthrough\""));
- // assertTrue(entity.getConfigBody().contains("\"mandatory\":\"True\""));
- // assertTrue(entity.getConfigBody().contains("\"architecture\":\"generic\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-version\":\"v1\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciVendorId\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"1234\""));
- // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\""));
- // assertTrue(entity.getConfigBody().contains("\"unit\":\"\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciDeviceId\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"5678\""));
- // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\""));
- // assertTrue(entity.getConfigBody().contains("\"unit\":\"\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciNumDevices\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"1\""));
- // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\""));
- // assertTrue(entity.getConfigBody().contains("\"unit\":\"\""));
-
-
+ final ToscaServiceTemplate entity = entities.iterator().next();
+ ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate();
+ Map<String, ToscaPolicy> map = topologyTemplate.getPolicies().get(0);
+ ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF);
+ Map<String, Object> props = policy.getProperties();
+ Object flavorFeatures =
+ props.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_FLAVORFEATURES);
+ String features = encoder.encode(flavorFeatures);
+ assertTrue(features.contains("\"id\":\"VDU_vgw_0\""));
+ assertTrue(features.contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
+ assertTrue(features.contains("\"type\":\"flavor_directives\""));
+ assertTrue(features.contains("\"attribute_name\":\"flavorName\""));
+ assertTrue(features.contains("\"attribute_value\":\"\""));
+ assertTrue(features.contains("\"hpa-feature\":\"pciePassthrough\""));
+ assertTrue(features.contains("\"mandatory\":\"True\""));
+ assertTrue(features.contains("\"architecture\":\"generic\""));
+ assertTrue(features.contains("\"hpa-version\":\"v1\""));
+ assertTrue(features.contains("\"hpa-attribute-key\":\"pciVendorId\""));
+ assertTrue(features.contains("\"hpa-attribute-value\":\"1234\""));
+ assertTrue(features.contains("\"operator\":\"=\""));
+ assertTrue(features.contains("\"unit\":\"\""));
+ assertTrue(features.contains("\"hpa-attribute-key\":\"pciDeviceId\""));
+ assertTrue(features.contains("\"hpa-attribute-value\":\"5678\""));
+ assertTrue(features.contains("\"operator\":\"=\""));
+ assertTrue(features.contains("\"unit\":\"\""));
+ assertTrue(features.contains("\"hpa-attribute-key\":\"pciNumDevices\""));
+ assertTrue(features.contains("\"hpa-attribute-value\":\"1\""));
+ assertTrue(features.contains("\"operator\":\"=\""));
+ assertTrue(features.contains("\"unit\":\"\""));
}
@Test
- public void testHpaPolicyHugePage() throws IOException, PolicyDecodingException {
+ public void testHpaPolicyHugePage() throws IOException, PolicyDecodingException, CoderException {
final Csar csar = new Csar("src/test/resources/hpaPolicyHugePage.csar");
final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi();
policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName());
final Collection<ToscaServiceTemplate> entities = policyDecoderCsarPdpx.decode(csar);
assertEquals(2, entities.size());
- // final ToscaServiceTemplate entity = entities.iterator().next();
- //
- // assertEquals("onapName", entity.getOnapName());
- // assertTrue(entity.getName().startsWith("OOF."));
- // assertTrue(entity.getConfigBody().contains("\"priority\":\"5\""));
- // assertTrue(entity.getConfigBody().contains("\"riskLevel\":\"2\""));
- // assertTrue(entity.getConfigBody().contains("\"riskType\":\"Test\""));
- // assertTrue(entity.getConfigBody().contains("\"version\":\"1.0\""));
- // assertTrue(entity.getConfigBody().contains("\"policyType\":\"hpa\""));
- //
- // assertTrue(entity.getConfigBody().contains("\"id\":\"VDU_vgw_0\""));
- // assertTrue(entity.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
- // assertTrue(entity.getConfigBody().contains("\"type\":\"flavor_directives\""));
- // assertTrue(entity.getConfigBody().contains("\"attribute_name\":\"flavorName\""));
- // assertTrue(entity.getConfigBody().contains("\"attribute_value\":\"\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-feature\":\"hugePages\""));
- // assertTrue(entity.getConfigBody().contains("\"mandatory\":\"true\""));
- // assertTrue(entity.getConfigBody().contains("\"architecture\":\"generic\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-version\":\"v1\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"memoryPageSize\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"2\""));
- // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\""));
- // assertTrue(entity.getConfigBody().contains("\"unit\":\"MB\""));
+ final ToscaServiceTemplate entity = entities.iterator().next();
+ ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate();
+ Map<String, ToscaPolicy> map = topologyTemplate.getPolicies().get(0);
+ ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF);
+ Map<String, Object> props = policy.getProperties();
+ Object flavorFeatures =
+ props.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_FLAVORFEATURES);
+ String features = encoder.encode(flavorFeatures);
+ assertTrue(features.contains("\"id\":\"VDU_vgw_0\""));
+ assertTrue(features.contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
+ assertTrue(features.contains("\"type\":\"flavor_directives\""));
+ assertTrue(features.contains("\"attribute_name\":\"flavorName\""));
+ assertTrue(features.contains("\"attribute_value\":\"\""));
+ assertTrue(features.contains("\"hpa-feature\":\"hugePages\""));
+ assertTrue(features.contains("\"mandatory\":\"true\""));
+ assertTrue(features.contains("\"architecture\":\"generic\""));
+ assertTrue(features.contains("\"hpa-version\":\"v1\""));
+ assertTrue(features.contains("\"hpa-attribute-key\":\"memoryPageSize\""));
+ assertTrue(features.contains("\"hpa-attribute-value\":\"2\""));
+ assertTrue(features.contains("\"operator\":\"=\""));
+ assertTrue(features.contains("\"unit\":\"MB\""));
}
@Test
- public void testS3p0PciVendorId() throws IOException, PolicyDecodingException {
+ public void testS3p0PciVendorId() throws IOException, PolicyDecodingException, CoderException {
final Csar csar = new Csar("src/test/resources/s3p_0_pciVendorId.csar");
final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi();
policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName());
final Collection<ToscaServiceTemplate> entities = policyDecoderCsarPdpx.decode(csar);
assertEquals(1, entities.size());
- // final ToscaServiceTemplate entity = entities.iterator().next();
- //
- // assertEquals("onapName", entity.getOnapName());
- // assertTrue(entity.getName().startsWith("OOF."));
- // assertTrue(entity.getConfigBody().contains("\"priority\":\"5\""));
- // assertTrue(entity.getConfigBody().contains("\"riskLevel\":\"2\""));
- // assertTrue(entity.getConfigBody().contains("\"riskType\":\"Test\""));
- // assertTrue(entity.getConfigBody().contains("\"version\":\"1.0\""));
- // assertTrue(entity.getConfigBody().contains("\"policyType\":\"hpa\""));
- //
- // assertTrue(entity.getConfigBody().contains("\"id\":\"VDU_vgw_0\""));
- // assertTrue(entity.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
- // assertTrue(entity.getConfigBody().contains("\"type\":\"flavor_directives\""));
- // assertTrue(entity.getConfigBody().contains("\"attribute_name\":\"flavorName\""));
- // assertTrue(entity.getConfigBody().contains("\"attribute_value\":\"\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-feature\":\"pciePassthrough\""));
- // assertTrue(entity.getConfigBody().contains("\"mandatory\":\"True\""));
- // assertTrue(entity.getConfigBody().contains("\"architecture\":\"generic\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-version\":\"v1\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciVendorId\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"1234\""));
- // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\""));
- // assertTrue(entity.getConfigBody().contains("\"unit\":\"\""));
-
+ final ToscaServiceTemplate entity = entities.iterator().next();
+ ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate();
+ Map<String, ToscaPolicy> map = topologyTemplate.getPolicies().get(0);
+ ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF);
+ Map<String, Object> props = policy.getProperties();
+ Object flavorFeatures =
+ props.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_FLAVORFEATURES);
+ String features = encoder.encode(flavorFeatures);
+ assertTrue(features.contains("\"id\":\"VDU_vgw_0\""));
+ assertTrue(features.contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
+ assertTrue(features.contains("\"type\":\"flavor_directives\""));
+ assertTrue(features.contains("\"attribute_name\":\"flavorName\""));
+ assertTrue(features.contains("\"attribute_value\":\"\""));
+ assertTrue(features.contains("\"hpa-feature\":\"pciePassthrough\""));
+ assertTrue(features.contains("\"mandatory\":\"True\""));
+ assertTrue(features.contains("\"architecture\":\"generic\""));
+ assertTrue(features.contains("\"hpa-version\":\"v1\""));
+ assertTrue(features.contains("\"hpa-attribute-key\":\"pciVendorId\""));
+ assertTrue(features.contains("\"hpa-attribute-value\":\"1234\""));
+ assertTrue(features.contains("\"operator\":\"=\""));
+ assertTrue(features.contains("\"unit\":\"\""));
}
@Test
- public void testserviceVcpeWithAll() throws IOException, PolicyDecodingException {
+ public void testserviceVcpeWithAll() throws IOException, PolicyDecodingException, CoderException {
final Csar csar = new Csar("src/test/resources/service-VcpeWithAll-csar.csar");
final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi();
policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName());
final Collection<ToscaServiceTemplate> entities = policyDecoderCsarPdpx.decode(csar);
assertEquals(5, entities.size());
- // final ToscaServiceTemplate entity = entities.iterator().next();
- //
- // assertEquals("onapName", entity.getOnapName());
- // assertTrue(entity.getName().startsWith("OOF."));
- // assertTrue(entity.getConfigBody().contains("\"priority\":\"5\""));
- // assertTrue(entity.getConfigBody().contains("\"riskLevel\":\"2\""));
- // assertTrue(entity.getConfigBody().contains("\"riskType\":\"Test\""));
- // assertTrue(entity.getConfigBody().contains("\"version\":\"1.0\""));
- // assertTrue(entity.getConfigBody().contains("\"policyType\":\"hpa\""));
- //
- // assertTrue(entity.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
- // assertTrue(entity.getConfigBody().contains("\"type\":\"flavor_directives\""));
- // assertTrue(entity.getConfigBody().contains("\"attribute_name\":\"flavorName\""));
- // assertTrue(entity.getConfigBody().contains("\"attribute_value\":\"\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-feature\":\"sriovNICNetwork\""));
- // assertTrue(entity.getConfigBody().contains("\"mandatory\":\"True\""));
- // assertTrue(entity.getConfigBody().contains("\"architecture\":\"generic\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-version\":\"v1\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciVendorId\""));
- // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"1234\""));
- // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\""));
- // assertTrue(entity.getConfigBody().contains("\"unit\":\"\""));
-
+ final ToscaServiceTemplate entity = entities.iterator().next();
+ ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate();
+ Map<String, ToscaPolicy> map = topologyTemplate.getPolicies().get(0);
+ ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF);
+ Map<String, Object> props = policy.getProperties();
+ Object flavorFeatures =
+ props.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_FLAVORFEATURES);
+ String features = encoder.encode(flavorFeatures);
+ assertTrue(features.contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
+ assertTrue(features.contains("\"type\":\"flavor_directives\""));
+ assertTrue(features.contains("\"attribute_name\":\"flavorName\""));
+ assertTrue(features.contains("\"attribute_value\":\"\""));
+ assertTrue(features.contains("\"hpa-feature\":\"sriovNICNetwork\""));
+ assertTrue(features.contains("\"mandatory\":\"True\""));
+ assertTrue(features.contains("\"architecture\":\"generic\""));
+ assertTrue(features.contains("\"hpa-version\":\"v1\""));
+ assertTrue(features.contains("\"hpa-attribute-key\":\"pciVendorId\""));
+ assertTrue(features.contains("\"hpa-attribute-value\":\"1234\""));
+ assertTrue(features.contains("\"operator\":\"=\""));
+ assertTrue(features.contains("\"unit\":\"\""));
}
}