diff options
author | ramverma <ram.krishna.verma@est.tech> | 2019-10-01 09:51:25 +0100 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-10-04 15:45:08 -0400 |
commit | a36022cc750ef71c35ac85d3864d907f81404ca6 (patch) | |
tree | c29bea43c25dbfbc763220e19460f2f5e7f649da | |
parent | 5a8fe4a6c5a413ad4d0a34726715d1ff49c4d068 (diff) |
Create decoder/parameters infra for HPA policy
Creating a new policy decoder & its related parameter classes for
decoding the HPA policy as ToscaServiceTemplate which is accepted
by the new Lifecycle API of Policy Framework.
Added couple of changes per review comments.
Issue-ID: POLICY-2122
Change-Id: I2d19b04cd24dd9c5b9fbf959757272077e6413d4
Signed-off-by: ramverma <ram.krishna.verma@est.tech>
Signed-off-by: Jim Hahn <jrh3@att.com>
8 files changed, 620 insertions, 139 deletions
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 1703512f..2ea13fdd 100644 --- a/packages/policy-distribution-tarball/src/main/resources/etc/defaultConfig.json +++ b/packages/policy-distribution-tarball/src/main/resources/etc/defaultConfig.json @@ -1,88 +1,128 @@ { - "name":"SDCDistributionGroup", - "restServerParameters":{ - "host":"0.0.0.0", - "port":6969, - "userName":"healthcheck", - "password":"zb!XztG34", - "https":true - }, - "receptionHandlerParameters":{ - "SDCReceptionHandler":{ - "receptionHandlerType":"SDC", - "receptionHandlerClassName":"org.onap.policy.distribution.reception.handling.sdc.SdcReceptionHandler", - "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": [ - "message-router.onap" - ], - "user": "policy", - "password": "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U", - "pollingInterval":20, - "pollingTimeout":30, - "consumerId": "policy-id", - "artifactTypes": [ - "TOSCA_CSAR", - "HEAT" - ], - "consumerGroup": "policy-group", - "environmentName": "AUTO", - "keystorePath": "null", - "keystorePassword": "null", - "activeserverTlsAuth": false, - "isFilterinEmptyResources": true, - "isUseHttpsWithDmaap": false - } + "name": "SDCDistributionGroup", + "restServerParameters": { + "host": "0.0.0.0", + "port": 6969, + "userName": "healthcheck", + "password": "zb!XztG34", + "https": true + }, + "receptionHandlerParameters": { + "SDCReceptionHandler": { + "receptionHandlerType": "SDC", + "receptionHandlerClassName": "org.onap.policy.distribution.reception.handling.sdc.SdcReceptionHandler", + "receptionHandlerConfigurationName": "sdcConfiguration", + "pluginHandlerParameters": { + "policyDecoders": { + "CsarDecoder": { + "decoderType": "CsarDecoder", + "decoderClassName": "org.onap.policy.distribution.reception.decoding.pdpx.PolicyDecoderCsarPdpx", + "decoderConfigurationName": "csarToOptimizationPolicyConfiguration" + }, + "LifecycleApiDecoder": { + "decoderType": "CsarDecoder", + "decoderClassName": "org.onap.policy.distribution.reception.decoding.pdpx.PolicyDecoderCsarPdpxLifecycleApi", + "decoderConfigurationName": "csarToToscaServiceTemplateConfiguration" + } + }, + "policyForwarders": { + "PAPEngineForwarder": { + "forwarderType": "PAPEngine", + "forwarderClassName": "org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarder", + "forwarderConfigurationName": "xacmlPdpConfiguration" + }, + "LifeCycleApiForwarder": { + "forwarderType": "LifeCycleAPI", + "forwarderClassName": "org.onap.policy.distribution.forwarding.lifecycle.api.LifecycleApiPolicyForwarder", + "forwarderConfigurationName": "lifecycleApiConfiguration" + } } + } + } + }, + "receptionHandlerConfigurationParameters": { + "sdcConfiguration": { + "parameterClassName": "org.onap.policy.distribution.reception.handling.sdc.SdcReceptionHandlerConfigurationParameterGroup", + "parameters": { + "asdcAddress": "sdc-be.onap:8443", + "messageBusAddress": [ + "message-router.onap" + ], + "user": "policy", + "password": "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U", + "pollingInterval": 20, + "pollingTimeout": 30, + "consumerId": "policy-id", + "artifactTypes": [ + "TOSCA_CSAR", + "HEAT" + ], + "consumerGroup": "policy-group", + "environmentName": "AUTO", + "keystorePath": "null", + "keystorePassword": "null", + "activeserverTlsAuth": false, + "isFilterinEmptyResources": true, + "isUseHttpsWithDmaap": false + } + } + }, + "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" + } }, - "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" - } - } + "csarToToscaServiceTemplateConfiguration": { + "parameterClassName": "org.onap.policy.distribution.reception.decoding.pdpx.PolicyDecoderCsarPdpxLifecycleApiParameters", + "parameters": { + "policyNamePrefix": "oofCasablanca", + "onapName": "OOF", + "version": "1.0", + "priority": "3", + "riskType": "Test", + "riskLevel": "2" + } + } + }, + "policyForwarderConfigurationParameters": { + "xacmlPdpConfiguration": { + "parameterClassName": "org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarderParameterGroup", + "parameters": { + "useHttps": true, + "hostname": "pdp", + "port": 8081, + "userName": "testpdp", + "password": "alpha123", + "clientAuth": "cHl0aG9uOnRlc3Q=", + "isManaged": true, + "pdpGroup": "default" + } }, - "policyForwarderConfigurationParameters":{ - "xacmlPdpConfiguration":{ - "parameterClassName":"org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarderParameterGroup", - "parameters":{ - "useHttps": true, - "hostname": "pdp", - "port": 8081, - "userName": "testpdp", - "password": "alpha123", - "clientAuth": "cHl0aG9uOnRlc3Q=", - "isManaged": true, - "pdpGroup": "default" - } - } + "lifecycleApiConfiguration": { + "parameterClassName": "org.onap.policy.distribution.forwarding.lifecycle.api.LifecycleApiForwarderParameters", + "parameters": { + "apiParameters": { + "hostName": "policy-api", + "port": 6969, + "userName": "healthcheck", + "password": "zb!XztG34" + }, + "papParameters": { + "hostName": "policy-pap", + "port": 6969, + "userName": "healthcheck", + "password": "zb!XztG34" + }, + "isHttps": true, + "deployPolicies": true + } } -} + } +}
\ No newline at end of file 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 new file mode 100644 index 00000000..eadca94d --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.pdpx; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.distribution.model.Csar; +import org.onap.policy.distribution.model.PolicyInput; +import org.onap.policy.distribution.reception.decoding.PolicyDecoder; +import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Decodes PDP-X policies from a CSAR file and creates ToscaServiceTemplate for Policy Lifecycle API's. + */ +public class PolicyDecoderCsarPdpxLifecycleApi implements PolicyDecoder<Csar, ToscaServiceTemplate> { + + private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderCsarPdpxLifecycleApi.class); + private final StandardCoder coder = new StandardCoder(); + private PolicyDecoderCsarPdpxLifecycleApiParameters decoderParameters; + + @Override + public Collection<ToscaServiceTemplate> decode(final Csar csar) throws PolicyDecodingException { + final List<ToscaServiceTemplate> entities = 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); + final String serviceName = sdcCsarHelper.getServiceMetadata().getValue("name"); + LOGGER.debug("the name of the service = {}", serviceName); + for (final NodeTemplate node : lnodeVf) { + final Content content = extractFromNode.extractInfo(node); + if (content != null) { + final ToscaServiceTemplate entity = new ToscaServiceTemplate(); + // TODO: add the logic for creating ToscaServiceTemplate for HPA policy + entities.add(entity); + } + } + return entities; + } + + @Override + public boolean canHandle(final PolicyInput policyInput) { + return Csar.class.isAssignableFrom(policyInput.getClass()); + } + + /** + * Parse the input Csar using SDC TOSCA parser. + * + * @param csar represents the service TOSCA Csar + * @return the object to represents the content of input csar + * @throws PolicyDecodingException if parse fails + */ + public ISdcCsarHelper parseCsar(final Csar csar) throws PolicyDecodingException { + ISdcCsarHelper sdcCsarHelper; + try { + final SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); + LOGGER.debug("Csar File Path = {}", csar.getCsarPath()); + final File csarFile = new File(csar.getCsarPath()); + sdcCsarHelper = factory.getSdcCsarHelper(csarFile.getAbsolutePath()); + } catch (final Exception exp) { + final String message = "Failed passing the csar file"; + LOGGER.error(message, exp); + throw new PolicyDecodingException(message, exp); + } + return sdcCsarHelper; + } + + @Override + public void configure(final String parameterGroupName) { + decoderParameters = ParameterService.get(parameterGroupName); + } +} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApiParameters.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApiParameters.java new file mode 100644 index 00000000..a66a53a8 --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApiParameters.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.pdpx; + +import lombok.Getter; + +import org.onap.policy.common.parameters.annotations.NotBlank; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup; + +/** + * This class handles the parameters needed for {@link PolicyDecoderCsarPdpxLifecycleApi}. + */ +@Getter +@NotNull +@NotBlank +public class PolicyDecoderCsarPdpxLifecycleApiParameters extends PolicyDecoderConfigurationParameterGroup { + + private String policyNamePrefix; + private String onapName; + private String version; + private String priority; + private String riskType; + private String riskLevel; + + public PolicyDecoderCsarPdpxLifecycleApiParameters() { + super(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); + } +} + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderToscaPdpx.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderToscaPdpx.java deleted file mode 100644 index 8cd6ecc1..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderToscaPdpx.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import java.util.Collection; -import java.util.Collections; - -import org.onap.policy.distribution.model.PolicyInput; -import org.onap.policy.distribution.model.Tosca; -import org.onap.policy.distribution.reception.decoding.PolicyDecoder; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; - -/** - * Decodes PDP-X policies from a TOSCA file. - */ -public class PolicyDecoderToscaPdpx implements PolicyDecoder<Tosca, ToscaPolicy> { - - @Override - public Collection<ToscaPolicy> decode(final Tosca tosca) { - // Add logic for generating the policies from the TOSCA - return Collections.emptySet(); - } - - @Override - public boolean canHandle(final PolicyInput policyInput) { - return policyInput.getClass().isAssignableFrom(Tosca.class); - } - - @Override - public void configure(final String parameterGroupName) { - throw new UnsupportedOperationException("The method is not supprted"); - } - -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java index c3d7e43b..9c336327 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java @@ -42,7 +42,7 @@ import org.onap.sdc.api.notification.IArtifactInfo; import org.onap.sdc.api.notification.INotificationData; import org.onap.sdc.api.results.IDistributionClientDownloadResult; import org.onap.sdc.api.results.IDistributionClientResult; -import org.onap.sdc.impl.DistributionClientFactory; +import org.onap.sdc.impl.DistributionClientImpl; import org.onap.sdc.utils.DistributionActionResultEnum; import org.onap.sdc.utils.DistributionStatusEnum; import org.slf4j.Logger; @@ -122,7 +122,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo * @return the {@link IDistributionClient} instance */ protected IDistributionClient createSdcDistributionClient() { - return DistributionClientFactory.createDistributionClient(); + return new DistributionClientImpl(); } /** 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 new file mode 100644 index 00000000..02cf5e67 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApi.java @@ -0,0 +1,276 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.pdpx; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.Collection; + +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.distribution.model.Csar; +import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +/** + * Class to perform unit test of {@link PolicyDecoderCsarPdpxLifecycleApi}. + * + */ +public class TestPolicyDecoderCsarPdpxLifecycleApi { + + /** + * Set up for test cases. + */ + @BeforeClass + public static void setUp() { + final ParameterGroup parameterGroup = CommonTestData.getPolicyDecoderParameters( + "src/test/resources/parameters/PdpxPolicyDecoderParameters.json", + PolicyDecoderCsarPdpxLifecycleApiParameters.class); + parameterGroup.setName(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); + ParameterService.register(parameterGroup); + } + + /** + * Tear down. + */ + @AfterClass + public static void tearDown() { + ParameterService.deregister(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); + } + + @Test + public void testHpaPolicy2Vnf() throws IOException, PolicyDecodingException { + final Csar csar = new Csar("src/test/resources/service-TestNs8-csar.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("\"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\"")); + } + + @Test + public void testHpaPolicySriov() throws IOException, PolicyDecodingException { + // 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\":\"\"")); + } + + @Test + public void testHpaPolicyPciePassthrough() throws IOException, PolicyDecodingException { + 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\":\"\"")); + + + } + + @Test + public void testHpaPolicyHugePage() throws IOException, PolicyDecodingException { + 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\"")); + } + + @Test + public void testS3p0PciVendorId() throws IOException, PolicyDecodingException { + 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\":\"\"")); + + } + + @Test + public void testserviceVcpeWithAll() throws IOException, PolicyDecodingException { + 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\":\"\"")); + + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApiParameters.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApiParameters.java new file mode 100644 index 00000000..47971ad3 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApiParameters.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.pdpx; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.common.parameters.ValidationStatus; + +/** + * Class to perform unit test of {@link PolicyDecoderCsarPdpxLifecycleApiParameters}. + */ +public class TestPolicyDecoderCsarPdpxLifecycleApiParameters { + + @Test + public void testValidParameters() { + final PolicyDecoderCsarPdpxLifecycleApiParameters parameterGroup = CommonTestData.getPolicyDecoderParameters( + "src/test/resources/parameters/PdpxPolicyDecoderParameters.json", + PolicyDecoderCsarPdpxLifecycleApiParameters.class); + + assertEquals(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName(), parameterGroup.getName()); + assertEquals("onapName", parameterGroup.getOnapName()); + assertEquals("OOF", parameterGroup.getPolicyNamePrefix()); + assertEquals("5", parameterGroup.getPriority()); + assertEquals("2", parameterGroup.getRiskLevel()); + assertEquals("Test", parameterGroup.getRiskType()); + assertEquals("1.0", parameterGroup.getVersion()); + assertEquals(ValidationStatus.CLEAN, parameterGroup.validate().getStatus()); + } + + @Test + public void testInvalidParameters() { + final PolicyDecoderCsarPdpxLifecycleApiParameters parameterGroup = CommonTestData.getPolicyDecoderParameters( + "src/test/resources/parameters/PdpxPolicyDecoderParametersInvalid.json", + PolicyDecoderCsarPdpxLifecycleApiParameters.class); + + assertEquals(ValidationStatus.INVALID, parameterGroup.validate().getStatus()); + } + + @Test + public void testEmptyParameters() { + final PolicyDecoderCsarPdpxLifecycleApiParameters configurationParameters = + CommonTestData.getPolicyDecoderParameters("src/test/resources/parameters/EmptyParameters.json", + PolicyDecoderCsarPdpxLifecycleApiParameters.class); + + assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java index 57fbf1cc..4f64550b 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java @@ -56,11 +56,11 @@ import org.onap.policy.distribution.reception.handling.PluginHandler; import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters; import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters; import org.onap.policy.distribution.reception.statistics.DistributionStatisticsManager; +import org.onap.sdc.api.IDistributionClient; import org.onap.sdc.api.notification.IArtifactInfo; import org.onap.sdc.api.notification.INotificationData; import org.onap.sdc.api.results.IDistributionClientDownloadResult; import org.onap.sdc.api.results.IDistributionClientResult; -import org.onap.sdc.impl.mock.DistributionClientStubImpl; import org.onap.sdc.utils.DistributionActionResultEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,7 +81,7 @@ public class TestSdcReceptionHandler { @Mock private IDistributionClientResult failureClientInitResult; @Mock - private DistributionClientStubImpl distributionClient; + private IDistributionClient distributionClient; @Mock private IDistributionClientDownloadResult successfulClientDownloadResult; @Mock |