From ccc3e28512988345e640097381d2ae0be46fe986 Mon Sep 17 00:00:00 2001 From: Ram Krishna Verma Date: Mon, 2 Mar 2020 15:27:21 -0500 Subject: Remove policy/engine & apex dependency from distribution Issue-ID: POLICY-2404 Change-Id: Ia3084c55ea65a3119354079d9afd3ee35689b7d4 Signed-off-by: Ram Krishna Verma --- .../src/main/resources/etc/defaultConfig.json | 210 +++++------- .../src/main/resources/etc/s3pConfig.json | 88 ++--- plugins/forwarding-plugins/pom.xml | 16 - .../apex/pdp/ApexPdpPolicyForwarder.java | 120 ------- .../pdp/ApexPdpPolicyForwarderParameterGroup.java | 50 --- .../xacml/pdp/XacmlPdpPolicyAdapter.java | 53 --- .../xacml/pdp/XacmlPdpPolicyForwarder.java | 146 --------- .../pdp/XacmlPdpPolicyForwarderParameterGroup.java | 54 --- .../adapters/AbstractXacmlPdpPolicyAdapter.java | 54 --- .../XacmlPdpOptimizationPolicyAdapter.java | 47 --- .../ApexPdpPolicyForwarderParameterGroupTest.java | 70 ---- .../apex/pdp/ApexPdpPolicyForwarderTest.java | 204 ------------ .../api/LifecycleApiForwarderParametersTest.java | 2 +- .../api/LifecycleApiPolicyForwarderTest.java | 4 +- .../forwarding/testclasses/CommonTestData.java | 53 +++ .../forwarding/testclasses/DummyDecoder.java | 64 ++++ .../testclasses/DummyReceptionHandler.java | 40 +++ .../testclasses/LifecycleApiSimulatorMain.java | 66 ++++ .../LifecycycleApiSimulatorEndpoint.java | 95 ++++++ .../XacmlPdpPolicyForwarderParameterGroupTest.java | 74 ----- .../pdp/engine/XacmlPdpPolicyForwarderTest.java | 298 ----------------- .../xacml/pdp/testclasses/CommonTestData.java | 53 --- .../xacml/pdp/testclasses/DummyDecoder.java | 64 ---- .../pdp/testclasses/DummyReceptionHandler.java | 40 --- .../pdp/testclasses/LifecycleApiSimulatorMain.java | 66 ---- .../LifecycycleApiSimulatorEndpoint.java | 95 ------ .../reception/decoding/hpa/Attribute.java | 52 +++ .../reception/decoding/hpa/Content.java | 42 +++ .../reception/decoding/hpa/Directive.java | 49 +++ .../reception/decoding/hpa/ExtractFromNode.java | 365 +++++++++++++++++++++ .../reception/decoding/hpa/FlavorFeature.java | 61 ++++ .../reception/decoding/hpa/FlavorProperty.java | 84 +++++ .../decoding/hpa/HpaFeatureAttribute.java | 71 ++++ .../decoding/hpa/PolicyDecoderCsarHpa.java | 124 +++++++ .../hpa/PolicyDecoderCsarHpaParameters.java | 49 +++ .../reception/decoding/pdpx/Attribute.java | 52 --- .../reception/decoding/pdpx/ConfigBody.java | 115 ------- .../reception/decoding/pdpx/Content.java | 42 --- .../reception/decoding/pdpx/Directive.java | 49 --- .../reception/decoding/pdpx/ExtractFromNode.java | 361 -------------------- .../reception/decoding/pdpx/FlavorFeature.java | 61 ---- .../reception/decoding/pdpx/FlavorProperty.java | 84 ----- .../decoding/pdpx/HpaFeatureAttribute.java | 71 ---- .../reception/decoding/pdpx/PdpxPolicy.java | 127 ------- .../decoding/pdpx/PolicyDecoderCsarPdpx.java | 122 ------- ...DecoderCsarPdpxConfigurationParameterGroup.java | 49 --- .../pdpx/PolicyDecoderCsarPdpxLifecycleApi.java | 132 -------- ...olicyDecoderCsarPdpxLifecycleApiParameters.java | 49 --- .../reception/decoding/hpa/CommonTestData.java | 53 +++ .../reception/decoding/hpa/TestAttribute.java | 50 +++ .../reception/decoding/hpa/TestContent.java | 75 +++++ .../reception/decoding/hpa/TestDirective.java | 54 +++ .../reception/decoding/hpa/TestFlavorFeature.java | 66 ++++ .../reception/decoding/hpa/TestFlavorProperty.java | 73 +++++ .../decoding/hpa/TestHpaFeatureAttribute.java | 57 ++++ .../decoding/hpa/TestPolicyDecoderCsarHpa.java | 267 +++++++++++++++ .../hpa/TestPolicyDecoderCsarHpaParameters.java | 66 ++++ .../reception/decoding/pdpx/CommonTestData.java | 53 --- .../reception/decoding/pdpx/TestAttribute.java | 49 --- .../reception/decoding/pdpx/TestContent.java | 73 ----- .../reception/decoding/pdpx/TestDirective.java | 52 --- .../reception/decoding/pdpx/TestFlavorFeature.java | 63 ---- .../decoding/pdpx/TestFlavorProperty.java | 70 ---- .../decoding/pdpx/TestHpaFeatureAttribute.java | 56 ---- .../decoding/pdpx/TestPolicyDecoderCsarPdpx.java | 278 ---------------- ...DecoderCsarPdpxConfigurationParameterGroup.java | 69 ---- .../TestPolicyDecoderCsarPdpxLifecycleApi.java | 270 --------------- ...olicyDecoderCsarPdpxLifecycleApiParameters.java | 66 ---- ...ecoderFileInCsarToPolicyParameterGroupTest.java | 2 +- .../file/PolicyDecoderFileInCsarToPolicyTest.java | 2 +- ...eceptionHandlerConfigurationParameterGroup.java | 2 +- .../parameters/HpaPolicyDecoderParameters.json | 8 + .../HpaPolicyDecoderParametersInvalid.json | 8 + .../parameters/PdpxPolicyDecoderParameters.json | 8 - .../PdpxPolicyDecoderParametersInvalid.json | 8 - 75 files changed, 2133 insertions(+), 4102 deletions(-) delete mode 100644 plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java delete mode 100644 plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroup.java delete mode 100644 plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java delete mode 100644 plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarder.java delete mode 100644 plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarderParameterGroup.java delete mode 100644 plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java delete mode 100644 plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java delete mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java delete mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java create mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/CommonTestData.java create mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/DummyDecoder.java create mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/DummyReceptionHandler.java create mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycleApiSimulatorMain.java create mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycycleApiSimulatorEndpoint.java delete mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderParameterGroupTest.java delete mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java delete mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/CommonTestData.java delete mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyDecoder.java delete mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyReceptionHandler.java delete mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycleApiSimulatorMain.java delete mode 100644 plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycycleApiSimulatorEndpoint.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Attribute.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Content.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Directive.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/ExtractFromNode.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorFeature.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorProperty.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/HpaFeatureAttribute.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpa.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpaParameters.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Attribute.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ConfigBody.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Content.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Directive.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorFeature.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorProperty.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PdpxPolicy.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterGroup.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java delete mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApiParameters.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/CommonTestData.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestAttribute.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestContent.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestDirective.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestFlavorFeature.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestFlavorProperty.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestHpaFeatureAttribute.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestPolicyDecoderCsarHpa.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestPolicyDecoderCsarHpaParameters.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/CommonTestData.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestAttribute.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestDirective.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxConfigurationParameterGroup.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApi.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApiParameters.java create mode 100644 plugins/reception-plugins/src/test/resources/parameters/HpaPolicyDecoderParameters.json create mode 100644 plugins/reception-plugins/src/test/resources/parameters/HpaPolicyDecoderParametersInvalid.json delete mode 100644 plugins/reception-plugins/src/test/resources/parameters/PdpxPolicyDecoderParameters.json delete mode 100644 plugins/reception-plugins/src/test/resources/parameters/PdpxPolicyDecoderParametersInvalid.json 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 2ea13fdd..3c955783 100644 --- a/packages/policy-distribution-tarball/src/main/resources/etc/defaultConfig.json +++ b/packages/policy-distribution-tarball/src/main/resources/etc/defaultConfig.json @@ -1,128 +1,94 @@ { - "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" - } + "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": { + "LifecycleApiDecoder": { + "decoderType": "CsarDecoder", + "decoderClassName": "org.onap.policy.distribution.reception.decoding.hpa.PolicyDecoderCsarHpa", + "decoderConfigurationName": "csarToToscaServiceTemplateConfiguration" + } + }, + "policyForwarders": { + "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" - } }, - "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" - } + "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": { + "csarToToscaServiceTemplateConfiguration": { + "parameterClassName": "org.onap.policy.distribution.reception.decoding.hpa.PolicyDecoderCsarHpaParameters", + "parameters": { + "policyNamePrefix": "oofCasablanca", + "onapName": "OOF", + "version": "1.0", + "priority": "3", + "riskType": "Test", + "riskLevel": "2" + } + } }, - "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 - } + "policyForwarderConfigurationParameters": { + "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/packages/policy-distribution-tarball/src/main/resources/etc/s3pConfig.json b/packages/policy-distribution-tarball/src/main/resources/etc/s3pConfig.json index 09d28069..07c1a8a2 100644 --- a/packages/policy-distribution-tarball/src/main/resources/etc/s3pConfig.json +++ b/packages/policy-distribution-tarball/src/main/resources/etc/s3pConfig.json @@ -1,46 +1,46 @@ { - "name":"SDCDistributionGroup", - "restServerParameters":{ - "host":"0.0.0.0", - "port":6969, - "userName":"healthcheck", - "password":"zb!XztG34" + "name": "SDCDistributionGroup", + "restServerParameters": { + "host": "0.0.0.0", + "port": 6969, + "userName": "healthcheck", + "password": "zb!XztG34" }, - "receptionHandlerParameters":{ - "S3PReceptionHandler":{ - "receptionHandlerType":"S3P", - "receptionHandlerClassName":"org.onap.policy.distribution.reception.handling.file.FileSystemReceptionHandler", - "receptionHandlerConfigurationName":"fileConfiguration", - "pluginHandlerParameters":{ - "policyDecoders":{ - "CsarDecoder":{ - "decoderType":"CsarDecoder", - "decoderClassName":"org.onap.policy.distribution.reception.decoding.pdpx.PolicyDecoderCsarPdpx", + "receptionHandlerParameters": { + "S3PReceptionHandler": { + "receptionHandlerType": "S3P", + "receptionHandlerClassName": "org.onap.policy.distribution.reception.handling.file.FileSystemReceptionHandler", + "receptionHandlerConfigurationName": "fileConfiguration", + "pluginHandlerParameters": { + "policyDecoders": { + "CsarDecoder": { + "decoderType": "CsarDecoder", + "decoderClassName": "org.onap.policy.distribution.reception.decoding.hpa.PolicyDecoderCsarHpa", "decoderConfigurationName": "csarToOptimizationPolicyConfiguration" } }, - "policyForwarders":{ - "PAPEngineForwarder":{ - "forwarderType":"PAPEngine", - "forwarderClassName":"org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarder", - "forwarderConfigurationName": "xacmlPdpConfiguration" + "policyForwarders": { + "LifeCycleApiForwarder": { + "forwarderType": "LifeCycleAPI", + "forwarderClassName": "org.onap.policy.distribution.forwarding.lifecycle.api.LifecycleApiPolicyForwarder", + "forwarderConfigurationName": "lifecycleApiConfiguration" } } } } }, - "receptionHandlerConfigurationParameters":{ - "fileConfiguration":{ - "parameterClassName":"org.onap.policy.distribution.reception.handling.file.FileSystemReceptionHandlerConfigurationParameterGroup", - "parameters":{ + "receptionHandlerConfigurationParameters": { + "fileConfiguration": { + "parameterClassName": "org.onap.policy.distribution.reception.handling.file.FileSystemReceptionHandlerConfigurationParameterGroup", + "parameters": { "watchPath": "/tmp/policy_distribution/csar/" } } }, - "policyDecoderConfigurationParameters":{ - "csarToOptimizationPolicyConfiguration":{ - "parameterClassName":"org.onap.policy.distribution.reception.decoding.pdpx.PolicyDecoderCsarPdpxConfigurationParameterGroup", - "parameters":{ + "policyDecoderConfigurationParameters": { + "csarToToscaServiceTemplateConfiguration": { + "parameterClassName": "org.onap.policy.distribution.reception.decoding.hpa.PolicyDecoderCsarHpaParameters", + "parameters": { "policyNamePrefix": "oofCasablanca", "onapName": "OOF", "version": "1.0", @@ -50,18 +50,24 @@ } } }, - "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": { + "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 } } } diff --git a/plugins/forwarding-plugins/pom.xml b/plugins/forwarding-plugins/pom.xml index cdb45f72..19dee4b7 100644 --- a/plugins/forwarding-plugins/pom.xml +++ b/plugins/forwarding-plugins/pom.xml @@ -41,22 +41,6 @@ distribution-main ${project.version} - - org.onap.policy.engine - PolicyEngineAPI - ${policy.engine.version} - - - org.eclipse.persistence - eclipselink - - - - - org.onap.policy.apex-pdp.core - core-deployment - ${policy.apex-pdp.version} - org.powermock powermock-api-mockito2 diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java deleted file mode 100644 index 996b887d..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java +++ /dev/null @@ -1,120 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Copyright (C) 2019 Intel Corp. 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.forwarding.apex.pdp; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Collection; - -import org.apache.commons.io.IOUtils; -import org.onap.policy.apex.core.deployment.EngineServiceFacade; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.distribution.forwarding.PolicyForwarder; -import org.onap.policy.distribution.forwarding.PolicyForwardingException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class provides an implementation of {@link PolicyForwarder} interface for forwarding the given policies to - * apex-pdp. - * - * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) - */ -public class ApexPdpPolicyForwarder implements PolicyForwarder { - - private static final Logger LOGGER = LoggerFactory.getLogger(ApexPdpPolicyForwarder.class); - private static final String POLICY_TYPE = "APEX"; - - private ApexPdpPolicyForwarderParameterGroup apexForwarderParameters; - private EngineServiceFacade engineServiceFacade; - - /** - * {@inheritDoc}. - */ - @Override - public void configure(final String parameterGroupName) { - apexForwarderParameters = ParameterService.get(parameterGroupName); - engineServiceFacade = - new EngineServiceFacade(apexForwarderParameters.getHostname(), apexForwarderParameters.getPort()); - - } - - /** - * {@inheritDoc}. - */ - @Override - public void forward(final Collection policies) throws PolicyForwardingException { - if (policies.isEmpty()) { - final String message = "No apex policy to be forwarded to an apex engine"; - LOGGER.debug(message); - throw new PolicyForwardingException(message); - } else if (policies.size() > 1) { - final String message = "More than one apex policy cannot be forwarded to an apex engine"; - LOGGER.debug(message); - throw new PolicyForwardingException(message); - } else { - final ToscaEntity policy = (ToscaEntity) policies.toArray()[0]; - if (policy instanceof ToscaPolicy) { - final ToscaPolicy toscaPolicy = (ToscaPolicy) policy; - if (POLICY_TYPE.equalsIgnoreCase(toscaPolicy.getType())) { - forwardPolicy(toscaPolicy); - } else { - final String message = "Ignoring the policy as it is not an apex-pdp policy"; - LOGGER.debug(message); - throw new PolicyForwardingException(message); - } - } else { - final String message = "Ignoring the policy as it is not of type ToscaPolicy"; - LOGGER.debug(message); - throw new PolicyForwardingException(message); - } - } - } - - /** - * Method to forward a given policy to apex-pdp. - * - * @param apexPolicy the apex policy - * @throws PolicyForwardingException if any exception occurs while forwarding policy - */ - private void forwardPolicy(final ToscaPolicy apexPolicy) throws PolicyForwardingException { - try { - engineServiceFacade.init(); - final InputStream policyInputStream = IOUtils.toInputStream(apexPolicy.toString(), "UTF-8"); - engineServiceFacade.deployModel(apexPolicy.getName(), policyInputStream, - apexForwarderParameters.isIgnoreConflicts(), apexForwarderParameters.isForceUpdate()); - - LOGGER.debug("Sucessfully forwarded the policy to apex-pdp egine at {}:{}", - apexForwarderParameters.getHostname(), apexForwarderParameters.getPort()); - - } catch (final ApexException | IOException exp) { - final String message = "Error sending policy to apex-pdp engine at" + apexForwarderParameters.getHostname() - + ":" + apexForwarderParameters.getPort(); - LOGGER.error(message, exp); - throw new PolicyForwardingException(message, exp); - } - } -} - diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroup.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroup.java deleted file mode 100644 index 77c98a2d..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroup.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. - * 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.forwarding.apex.pdp; - -import lombok.Getter; - -import org.onap.policy.common.parameters.annotations.Min; -import org.onap.policy.common.parameters.annotations.NotBlank; -import org.onap.policy.common.parameters.annotations.NotNull; -import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup; - -/** - * Holds the parameters for the{@link ApexPdpPolicyForwarder}. - */ -@Getter -@NotNull -@NotBlank -public class ApexPdpPolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup { - public static final String POLICY_FORWARDER_PLUGIN_CLASS = ApexPdpPolicyForwarder.class.getName(); - - private String hostname; - @Min(value = 1) - private int port; - private boolean ignoreConflicts; - private boolean forceUpdate; - - public ApexPdpPolicyForwarderParameterGroup() { - super(ApexPdpPolicyForwarderParameterGroup.class.getSimpleName()); - } -} diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java deleted file mode 100644 index 613a406f..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java +++ /dev/null @@ -1,53 +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.forwarding.xacml.pdp; - -import org.onap.policy.api.PolicyParameters; -import org.onap.policy.api.PushPolicyParameters; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; - -/** - * Adapts {@link ToscaPolicy} objects to objects compatible with the XACML PDP API. - */ -public interface XacmlPdpPolicyAdapter { - - /** - * Get the policy. - * - * @return the policy - */ - T getPolicy(); - - /** - * Get as a {@link PolicyParameters} object. - * - * @returna {@link PolicyParameters} object - */ - PolicyParameters getAsPolicyParameters(); - - /** - * Get as a {@link PushPolicyParameters} object. - * - * @returna {@link PushPolicyParameters} object - */ - PushPolicyParameters getAsPushPolicyParameters(final String pdpGroups); - -} diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarder.java deleted file mode 100644 index 8eeeda7e..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarder.java +++ /dev/null @@ -1,146 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Copyright (C) 2019 Intel Corp. All rights reserved. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.forwarding.xacml.pdp; - -import java.util.Collection; -import java.util.Collections; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.onap.policy.api.PolicyParameters; -import org.onap.policy.api.PushPolicyParameters; -import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; -import org.onap.policy.common.endpoints.http.client.HttpClient; -import org.onap.policy.common.endpoints.http.client.HttpClientConfigException; -import org.onap.policy.common.endpoints.http.client.HttpClientFactory; -import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; -import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.distribution.forwarding.PolicyForwarder; -import org.onap.policy.distribution.forwarding.xacml.pdp.adapters.XacmlPdpOptimizationPolicyAdapter; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; - -/** - * Forwards policies to the XACML PDP. - */ -public class XacmlPdpPolicyForwarder implements PolicyForwarder { - - private static final Logger LOGGER = LoggerFactory.getLogger(XacmlPdpPolicyForwarder.class); - private static final String BASE_PATH = "pdp/api/"; - - private XacmlPdpPolicyForwarderParameterGroup configurationParameters = null; - - - @Override - public void forward(final Collection policies) { - for (final ToscaEntity policy : policies) { - forward(policy); - } - } - - private void forward(final ToscaEntity policy) { - final XacmlPdpPolicyAdapter policyAdapter = getXacmlPdpPolicyAdapter(policy); - - if (policyAdapter == null) { - LOGGER.error("Cannot forward policy {}. Unsupported policy type {}", policy, - policy.getClass().getSimpleName()); - return; - } - - final boolean policyCreated = createPolicy(policyAdapter); - if (policyCreated) { - pushPolicy(policyAdapter); - } - } - - private XacmlPdpPolicyAdapter getXacmlPdpPolicyAdapter(final ToscaEntity policy) { - if (policy instanceof ToscaPolicy) { - return new XacmlPdpOptimizationPolicyAdapter((ToscaPolicy) policy); - } - return null; - } - - private boolean createPolicy(final XacmlPdpPolicyAdapter policyAdapter) { - final PolicyParameters policyParameters = policyAdapter.getAsPolicyParameters(); - final Entity entity = Entity.entity(policyParameters, MediaType.APPLICATION_JSON); - - return invokeHttpClient(entity, "createPolicy", policyAdapter.getPolicy().getName()); - } - - private boolean pushPolicy(final XacmlPdpPolicyAdapter policyAdapter) { - final PushPolicyParameters pushPolicyParameters = - policyAdapter.getAsPushPolicyParameters(configurationParameters.getPdpGroup()); - final Entity entity = Entity.entity(pushPolicyParameters, MediaType.APPLICATION_JSON); - - return invokeHttpClient(entity, "pushPolicy", policyAdapter.getPolicy().getName()); - } - - private boolean invokeHttpClient(final Entity entity, final String method, final String policyName) { - - try { - final Response response = getHttpClient().put(method, entity, - Collections.singletonMap("ClientAuth", configurationParameters.getClientAuth())); - - if (response.getStatus() != HttpStatus.OK.value()) { - LOGGER.error( - "Invocation of method {} failed for policy {}. Response status: {}, Response status info: {}", - method, policyName, response.getStatus(), response.getStatusInfo()); - return false; - } - } catch (final HttpClientConfigException exception) { - LOGGER.error("Invocation of method " + method + " failed for policy " + policyName - + " due to error opening Http client", exception); - return false; - } - return true; - } - - private HttpClient getHttpClient() throws HttpClientConfigException { - final boolean useHttps = configurationParameters.isUseHttps(); - final String hostname = configurationParameters.getHostname(); - final int port = configurationParameters.getPort(); - final String userName = configurationParameters.getUserName(); - final String password = configurationParameters.getPassword(); - final boolean managed = configurationParameters.isManaged(); - final BusTopicParams params = - BusTopicParams.builder().clientName("SDC Dist").useHttps(useHttps).hostname(hostname).port(port) - .userName(userName).password(password).basePath(BASE_PATH).managed(managed).build(); - return getHttpClientFactory().build(params); - } - - @Override - public void configure(final String parameterGroupName) { - configurationParameters = ParameterService.get(parameterGroupName); - } - - // these may be overridden by junit tests - - protected HttpClientFactory getHttpClientFactory() { - return HttpClientFactoryInstance.getClientFactory(); - } -} diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarderParameterGroup.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarderParameterGroup.java deleted file mode 100644 index 4ce35f20..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarderParameterGroup.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. - * 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.forwarding.xacml.pdp; - -import lombok.Getter; - -import org.onap.policy.common.parameters.annotations.Min; -import org.onap.policy.common.parameters.annotations.NotBlank; -import org.onap.policy.common.parameters.annotations.NotNull; -import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup; - -/** - * Holds the parameters for the{@link XacmlPdpPolicyForwarder}. - */ -@Getter -@NotNull -@NotBlank -public class XacmlPdpPolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup { - public static final String POLICY_FORWARDER_PLUGIN_CLASS = XacmlPdpPolicyForwarder.class.getName(); - - private boolean useHttps; - private String hostname; - @Min(value = 1) - private int port; - private String userName; - private String password; - private String clientAuth; - private boolean isManaged; - private String pdpGroup; - - public XacmlPdpPolicyForwarderParameterGroup() { - super(XacmlPdpPolicyForwarderParameterGroup.class.getSimpleName()); - } -} diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java deleted file mode 100644 index f978d3a9..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java +++ /dev/null @@ -1,54 +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.forwarding.xacml.pdp.adapters; - -import org.onap.policy.api.PushPolicyParameters; -import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyAdapter; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; - -/** - * Base class for {@link XacmlPdpPolicyAdapter} implementations. - * - * @param the type of policy the adapter handles - */ -public abstract class AbstractXacmlPdpPolicyAdapter implements XacmlPdpPolicyAdapter { - - private T policy; - - protected AbstractXacmlPdpPolicyAdapter(final T policy) { - this.policy = policy; - } - - @Override - public T getPolicy() { - return policy; - } - - @Override - public PushPolicyParameters getAsPushPolicyParameters(final String pdpGroups) { - final PushPolicyParameters pushPolicyParameters = new PushPolicyParameters(); - pushPolicyParameters.setPolicyName(policy.getName()); - pushPolicyParameters.setPolicyType(policy.getType()); - pushPolicyParameters.setPdpGroup(pdpGroups); - return pushPolicyParameters; - } - -} diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java deleted file mode 100644 index c9633b15..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java +++ /dev/null @@ -1,47 +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.forwarding.xacml.pdp.adapters; - -import org.onap.policy.api.PolicyParameters; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; - -/** - * Adapts {@link ToscaPolicy} objects to objects compatible with the XACML PDP API. - */ -public class XacmlPdpOptimizationPolicyAdapter extends AbstractXacmlPdpPolicyAdapter { - - /** - * Create an instance to adapt the given {@link ToscaPolicy}. - * - * @param optimizationPolicy the {@link ToscaPolicy} to be adapted - */ - public XacmlPdpOptimizationPolicyAdapter(final ToscaPolicy optimizationPolicy) { - super(optimizationPolicy); - } - - @Override - public PolicyParameters getAsPolicyParameters() { - final PolicyParameters policyParameters = new PolicyParameters(); - policyParameters.setPolicyName(getPolicy().getName()); - return policyParameters; - } - -} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java deleted file mode 100644 index fc0fe3db..00000000 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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.forwarding.apex.pdp; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.policy.common.parameters.ValidationStatus; -import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData; - -/** - * Class to perform unit test of {@link ApexPdpPolicyForwarderParameterGroup}. - * - * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) - */ -public class ApexPdpPolicyForwarderParameterGroupTest { - - @Test - public void testValidParameters() { - final ApexPdpPolicyForwarderParameterGroup configurationParameters = CommonTestData - .getPolicyForwarderParameters("src/test/resources/parameters/ApexPdpPolicyForwarderParameters.json", - ApexPdpPolicyForwarderParameterGroup.class); - assertEquals(ApexPdpPolicyForwarderParameterGroup.class.getSimpleName(), configurationParameters.getName()); - assertTrue(configurationParameters.isForceUpdate()); - assertEquals("10.10.10.10", configurationParameters.getHostname()); - assertEquals(1234, configurationParameters.getPort()); - assertFalse(configurationParameters.isIgnoreConflicts()); - assertEquals(ValidationStatus.CLEAN, configurationParameters.validate().getStatus()); - } - - @Test - public void testInvalidParameters() { - final ApexPdpPolicyForwarderParameterGroup configurationParameters = - CommonTestData.getPolicyForwarderParameters( - "src/test/resources/parameters/ApexPdpPolicyForwarderParametersInvalid.json", - ApexPdpPolicyForwarderParameterGroup.class); - - assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus()); - } - - @Test - public void testEmptyParameters() { - final ApexPdpPolicyForwarderParameterGroup configurationParameters = - CommonTestData.getPolicyForwarderParameters("src/test/resources/parameters/EmptyParameters.json", - ApexPdpPolicyForwarderParameterGroup.class); - - assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus()); - } -} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java deleted file mode 100644 index 7d6743e1..00000000 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java +++ /dev/null @@ -1,204 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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.forwarding.apex.pdp; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.policy.apex.core.deployment.EngineServiceFacade; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.common.parameters.ParameterGroup; -import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.distribution.forwarding.PolicyForwardingException; -import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; - -/** - * Class to perform unit test of {@link ApexPdpPolicyForwarder}. - * - * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) - */ -@RunWith(MockitoJUnitRunner.class) -public class ApexPdpPolicyForwarderTest { - - private static final boolean IGNORE_CONFLICTS = false; - private static final boolean FORCE_UPDATE = true; - private static final String GROUP_NAME = "apexPdpConfiguration"; - - @Mock - EngineServiceFacade engineServiceFacade; - - /** - * Set up. - */ - @BeforeClass - public static void setUp() { - final ParameterGroup parameterGroup = CommonTestData.getPolicyForwarderParameters( - "src/test/resources/parameters/ApexPdpPolicyForwarderParameters.json", - ApexPdpPolicyForwarderParameterGroup.class); - - parameterGroup.setName(GROUP_NAME); - ParameterService.register(parameterGroup); - } - - /** - * Tear down. - */ - @AfterClass - public static void tearDown() { - ParameterService.deregister(GROUP_NAME); - } - - @Test - public void testForwardPolicy() throws ApexException, FileNotFoundException, IOException, PolicyForwardingException, - NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - - final Collection policies = new ArrayList<>(); - final ApexPdpPolicyForwarder forwarder = new ApexPdpPolicyForwarder(); - forwarder.configure(GROUP_NAME); - - final Field forwarderField = forwarder.getClass().getDeclaredField("engineServiceFacade"); - forwarderField.setAccessible(true); - forwarderField.set(forwarder, engineServiceFacade); - - createPolicy(policies, "policy", "APEX", "Sample Policy of apex"); - - try { - forwarder.forward(policies); - verify(engineServiceFacade, times(1)).init(); - verify(engineServiceFacade, times(1)).deployModel(eq("policy"), anyObject(), eq(IGNORE_CONFLICTS), - eq(FORCE_UPDATE)); - } catch (final Exception exp) { - fail("Test must not throw an exception"); - } - } - - @Test - public void testForwardPolicyError() - throws ApexException, FileNotFoundException, IOException, PolicyForwardingException, NoSuchFieldException, - SecurityException, IllegalArgumentException, IllegalAccessException { - - final Collection policies = new ArrayList<>(); - final ApexPdpPolicyForwarder forwarder = new ApexPdpPolicyForwarder(); - forwarder.configure(GROUP_NAME); - - Mockito.doThrow(new ApexException("Failed")).when(engineServiceFacade).deployModel(eq("policy1"), anyObject(), - eq(IGNORE_CONFLICTS), eq(FORCE_UPDATE)); - - final Field decodersField = forwarder.getClass().getDeclaredField("engineServiceFacade"); - decodersField.setAccessible(true); - decodersField.set(forwarder, engineServiceFacade); - - createPolicy(policies, "policy1", "APEX", "Sample Policy of apex"); - - try { - forwarder.forward(policies); - fail("Test must throw an exception"); - } catch (final Exception exp) { - assertTrue(exp.getMessage().contains("Error sending policy to apex-pdp engine")); - } - - } - - @Test - public void testForwardMoreThanOnePolicy() - throws ApexException, FileNotFoundException, IOException, PolicyForwardingException, NoSuchFieldException, - SecurityException, IllegalArgumentException, IllegalAccessException { - - final Collection policies = new ArrayList<>(); - final ApexPdpPolicyForwarder forwarder = new ApexPdpPolicyForwarder(); - forwarder.configure(GROUP_NAME); - - final Field forwarderField = forwarder.getClass().getDeclaredField("engineServiceFacade"); - forwarderField.setAccessible(true); - forwarderField.set(forwarder, engineServiceFacade); - - createPolicy(policies, "policy1", "APEX", "Sample Policy of apex"); - createPolicy(policies, "policy2", "APEX", "Sample Policy of apex"); - - try { - forwarder.forward(policies); - fail("Test must throw an exception"); - } catch (final Exception exp) { - assertTrue(exp.getMessage().contains("More than one apex policy cannot be forwarded to an apex engine")); - } - } - - @Test - public void testForwardUnsupportedPolicy() - throws ApexException, FileNotFoundException, IOException, PolicyForwardingException, NoSuchFieldException, - SecurityException, IllegalArgumentException, IllegalAccessException { - - final Collection policies = new ArrayList<>(); - final ApexPdpPolicyForwarder forwarder = new ApexPdpPolicyForwarder(); - forwarder.configure(GROUP_NAME); - - final Field forwarderField = forwarder.getClass().getDeclaredField("engineServiceFacade"); - forwarderField.setAccessible(true); - forwarderField.set(forwarder, engineServiceFacade); - - final ToscaEntity policy = new UnsupportedPolicy(); - policies.add(policy); - - try { - forwarder.forward(policies); - fail("Test must throw an exception"); - } catch (final Exception exp) { - assertTrue(exp.getMessage().contains("Ignoring the policy as it is not of type ToscaPolicy")); - } - } - - class UnsupportedPolicy extends ToscaEntity { - - @Override - public String getName() { - return "unsupported"; - } - } - - private void createPolicy(final Collection policies, final String name, final String type, - final String description) { - final ToscaPolicy policy = new ToscaPolicy(); - policy.setName(name); - policy.setType(type); - policy.setDescription(description); - policies.add(policy); - } -} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParametersTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParametersTest.java index fd8422d6..0f010bfc 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParametersTest.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParametersTest.java @@ -26,7 +26,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.onap.policy.common.parameters.ValidationStatus; -import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData; +import org.onap.policy.distribution.forwarding.testclasses.CommonTestData; /** * Class to perform unit test of {@link LifecycleApiForwarderParameters}. diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java index 4d837cdf..7d84657a 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java @@ -35,8 +35,8 @@ import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.distribution.forwarding.PolicyForwardingException; -import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData; -import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.LifecycleApiSimulatorMain; +import org.onap.policy.distribution.forwarding.testclasses.CommonTestData; +import org.onap.policy.distribution.forwarding.testclasses.LifecycleApiSimulatorMain; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/CommonTestData.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/CommonTestData.java new file mode 100644 index 00000000..9da1b613 --- /dev/null +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/CommonTestData.java @@ -0,0 +1,53 @@ +/*- + * ============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.forwarding.testclasses; + +import java.io.File; + +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; + +/** + * Class to create parameters for test cases. + * + * @author Ram Krishna Verma (ram.krishna.verma@est.tech) + */ +public class CommonTestData { + + public static final Coder coder = new StandardCoder(); + + /** + * Returns PolicyForwarderParameters for test cases. + * + * @param fileName the file name to load the parameters + * @param clazz the parameter class to be returned + * @return the specific PolicyForwarderParameters object + */ + public static T getPolicyForwarderParameters(final String fileName, final Class clazz) { + final StandardCoder coder = new StandardCoder(); + try { + return coder.decode(new File(fileName), clazz); + } catch (final CoderException exp) { + throw new RuntimeException("cannot read/decode " + fileName, exp); + } + } +} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/DummyDecoder.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/DummyDecoder.java new file mode 100644 index 00000000..b40aabf8 --- /dev/null +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/DummyDecoder.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. 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.forwarding.testclasses; + +import java.util.Collection; + +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.ToscaEntity; + +/** + * Class to create a dummy decoder for test cases. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class DummyDecoder implements PolicyDecoder { + + private boolean canHandleValue; + private Collection policesToReturn; + + public DummyDecoder() { + this.canHandleValue = false; + this.policesToReturn = null; + } + + public DummyDecoder(final boolean canHandleValue, final Collection policesToReturn) { + this.canHandleValue = canHandleValue; + this.policesToReturn = policesToReturn; + } + + @Override + public boolean canHandle(final PolicyInput policyInput) { + return canHandleValue; + } + + @Override + public Collection decode(final PolicyInput input) throws PolicyDecodingException { + return policesToReturn; + } + + @Override + public void configure(final String parameterGroupName) { + } +} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/DummyReceptionHandler.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/DummyReceptionHandler.java new file mode 100644 index 00000000..b3cf489c --- /dev/null +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/DummyReceptionHandler.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. 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.forwarding.testclasses; + +import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler; + +/** + * Class to create a dummy reception handler for test cases. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class DummyReceptionHandler extends AbstractReceptionHandler { + + @Override + public void initializeReception(final String parameterGroupName) { + } + + @Override + public void destroy() { + } +} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycleApiSimulatorMain.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycleApiSimulatorMain.java new file mode 100644 index 00000000..07c4b6c6 --- /dev/null +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycleApiSimulatorMain.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.forwarding.testclasses; + +import org.onap.policy.common.endpoints.http.server.RestServer; +import org.onap.policy.common.endpoints.parameters.RestServerParameters; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.distribution.forwarding.PolicyForwardingException; +import org.onap.policy.distribution.forwarding.lifecycle.api.LifecycleApiPolicyForwarder; +import org.onap.policy.distribution.main.rest.aaf.AafDistributionFilter; + +/** + * The class for starting/stopping simulator for testing {@link LifecycleApiPolicyForwarder} . + * + * @author Ram Krishna Verma (ram.krishna.verma@est.tech) + */ +public class LifecycleApiSimulatorMain { + private RestServer restServer; + + /** + * Starts the simulator. + * + * @throws PolicyForwardingException if error occurs + * @throws CoderException if error occurs + */ + public void startLifecycycleApiSimulator() throws PolicyForwardingException, CoderException { + final StandardCoder standardCoder = new StandardCoder(); + final RestServerParameters restServerParameters = standardCoder.decode( + ResourceUtils.getResourceAsString("src/test/resources/parameters/RestServerParameters.json"), + RestServerParameters.class); + restServer = new RestServer(restServerParameters, AafDistributionFilter.class, + LifecycycleApiSimulatorEndpoint.class); + if (!restServer.start()) { + throw new PolicyForwardingException("Failed to start rest simulator. Check log for more details..."); + } + } + + /** + * Shut down Execution. + */ + public void stopLifecycycleApiSimulator() { + if (restServer != null) { + restServer.stop(); + } + } +} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycycleApiSimulatorEndpoint.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycycleApiSimulatorEndpoint.java new file mode 100644 index 00000000..4d7d2600 --- /dev/null +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycycleApiSimulatorEndpoint.java @@ -0,0 +1,95 @@ +/*- + * ============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.forwarding.testclasses; + +import io.swagger.annotations.ApiParam; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.onap.policy.models.pap.concepts.PdpDeployPolicies; +import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +/** + * Class to provide rest end points for LifecycycleApiSimulator. + * + * @author Ram Krishna Verma (ram.krishna.verma@est.tech) + */ +@Path("/policy") +@Produces(MediaType.APPLICATION_JSON) +public class LifecycycleApiSimulatorEndpoint { + + /** + * Create policy type endpoint. + * + * @param body the post body + * @return the response object + */ + @POST + @Path("/api/v1/policytypes") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response createPolicyTypes(final ToscaServiceTemplate body) { + return Response.status(Response.Status.OK).entity(body).build(); + } + + /** + * Create policy endpoint. + * + * @param policyTypeId the policy type id + * @param policyTypeVersion the policy type version + * @param body the post body + * @return the response object + */ + @POST + @Path("/api/v1/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response createPolicies(@PathParam("policyTypeId") final String policyTypeId, + @PathParam("policyTypeVersion") final String policyTypeVersion, + @ApiParam(value = "Entity body of policy", required = true) final ToscaServiceTemplate body) { + if ("onap.policies.controlloop.operational.ApexFailure".equals(policyTypeId)) { + return Response.status(Response.Status.NOT_FOUND).build(); + } else { + return Response.status(Response.Status.OK).entity(body).build(); + } + } + + /** + * Deploy policy endpoint. + * + * @param policies the post body + * @return the response object + */ + @POST + @Path("/pap/v1/pdps/policies") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response deployPolicies(final PdpDeployPolicies policies) { + return Response.status(Response.Status.OK).entity(new PdpGroupDeployResponse()).build(); + } +} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderParameterGroupTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderParameterGroupTest.java deleted file mode 100644 index 6e98b225..00000000 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderParameterGroupTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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.forwarding.xacml.pdp.engine; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.policy.common.parameters.ValidationStatus; -import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarderParameterGroup; -import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData; - -public class XacmlPdpPolicyForwarderParameterGroupTest { - - private static final String CLIENT_AUTH = "myClientAuth"; - private static final String PASSWORD = "myPassword"; - private static final String USER = "myUser"; - private static final int PORT = 1234; - private static final String HOST_NAME = "10.10.10.10"; - - @Test - public void testValidParameters() { - final XacmlPdpPolicyForwarderParameterGroup configurationParameters = CommonTestData - .getPolicyForwarderParameters("src/test/resources/parameters/XacmlPdpPolicyForwarderParameters.json", - XacmlPdpPolicyForwarderParameterGroup.class); - - assertTrue(configurationParameters.isUseHttps()); - assertEquals(HOST_NAME, configurationParameters.getHostname()); - assertEquals(PORT, configurationParameters.getPort()); - assertEquals(USER, configurationParameters.getUserName()); - assertEquals(PASSWORD, configurationParameters.getPassword()); - assertEquals(CLIENT_AUTH, configurationParameters.getClientAuth()); - assertFalse(configurationParameters.isManaged()); - } - - @Test - public void testInvalidParameters() { - final XacmlPdpPolicyForwarderParameterGroup configurationParameters = - CommonTestData.getPolicyForwarderParameters( - "src/test/resources/parameters/XacmlPdpPolicyForwarderParametersInvalid.json", - XacmlPdpPolicyForwarderParameterGroup.class); - - assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus()); - } - - @Test - public void testEmptyParameters() { - final XacmlPdpPolicyForwarderParameterGroup configurationParameters = - CommonTestData.getPolicyForwarderParameters("src/test/resources/parameters/EmptyParameters.json", - XacmlPdpPolicyForwarderParameterGroup.class); - - assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus()); - } -} 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 deleted file mode 100644 index 222614d9..00000000 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java +++ /dev/null @@ -1,298 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. 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.forwarding.xacml.pdp.engine; - -import static org.junit.Assert.assertSame; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.Response; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.mockito.ArgumentMatcher; -import org.onap.policy.api.PolicyParameters; -import org.onap.policy.api.PushPolicyParameters; -import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; -import org.onap.policy.common.endpoints.http.client.HttpClient; -import org.onap.policy.common.endpoints.http.client.HttpClientConfigException; -import org.onap.policy.common.endpoints.http.client.HttpClientFactory; -import org.onap.policy.common.parameters.ParameterGroup; -import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarder; -import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarderParameterGroup; -import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; - -public class XacmlPdpPolicyForwarderTest { - - private static final BusTopicParams BUS_TOPIC_PARAMS = BusTopicParams.builder().useHttps(true) - .hostname("10.10.10.10").port(1234).userName("myUser").password("myPassword").managed(false).build(); - private static final String CLIENT_AUTH = "ClientAuth"; - private static final String CLIENT_AUTH_VALUE = "myClientAuth"; - private static final String PDP_GROUP_VALUE = "myPdpGroup"; - private HashMap headers = new HashMap<>(); - private BusTopicParamsMatcher matcher = new BusTopicParamsMatcher(BUS_TOPIC_PARAMS); - - /** - * Set up. - */ - @BeforeClass - public static void setUp() { - final ParameterGroup parameterGroup = CommonTestData.getPolicyForwarderParameters( - "src/test/resources/parameters/XacmlPdpPolicyForwarderParameters.json", - XacmlPdpPolicyForwarderParameterGroup.class); - parameterGroup.setName("xacmlPdpConfiguration"); - ParameterService.register(parameterGroup); - } - - @Test - public void testForwardPolicy() throws Exception { - - final HttpClient httpClientMock = mock(HttpClient.class); - headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE); - when(httpClientMock.put(eq("createPolicy"), any(), eq(headers))).thenReturn(Response.ok().build()); - when(httpClientMock.put(eq("pushPolicy"), any(), eq(headers))).thenReturn(Response.ok().build()); - - final HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); - when(httpClientFactoryMock.build(argThat(matcher))).thenReturn(httpClientMock); - - final XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); - forwarder.configure("xacmlPdpConfiguration"); - - final Collection policies = new ArrayList<>(); - - final ToscaPolicy policy1 = createPolicy(policies, "policy1", "optimization"); - - final ToscaEntity policy2 = new UnsupportedPolicy(); - policies.add(policy2); - - final ToscaPolicy policy3 = createPolicy(policies, "policy3", "optimization"); - - forwarder.forward(policies); - - verify(httpClientMock).put(eq("createPolicy"), argThat(new PolicyParametersEntityMatcher(policy1)), - eq(headers)); - verify(httpClientMock).put(eq("createPolicy"), argThat(new PolicyParametersEntityMatcher(policy3)), - eq(headers)); - verify(httpClientMock).put(eq("pushPolicy"), argThat(new PushPolicyParametersEntityMatcher(policy1)), - eq(headers)); - verify(httpClientMock).put(eq("pushPolicy"), argThat(new PushPolicyParametersEntityMatcher(policy3)), - eq(headers)); - } - - @Test - public void testForwardPolicy_CreateFailsPushNotInvoked() throws Exception { - - final HttpClient httpClientMock = mock(HttpClient.class); - headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE); - when(httpClientMock.put(eq("createPolicy"), any(), eq(headers))).thenReturn(Response.status(400).build()); - when(httpClientMock.put(eq("pushPolicy"), any(), eq(headers))).thenReturn(Response.ok().build()); - - final HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); - when(httpClientFactoryMock.build(argThat(matcher))).thenReturn(httpClientMock); - - final XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); - forwarder.configure("xacmlPdpConfiguration"); - - final Collection policies = new ArrayList<>(); - final ToscaPolicy policy = createPolicy(policies, "policy", "optimization"); - forwarder.forward(policies); - - verify(httpClientMock).put(eq("createPolicy"), argThat(new PolicyParametersEntityMatcher(policy)), eq(headers)); - verify(httpClientMock, times(0)).put(eq("pushPolicy"), any(), any()); - } - - @Test - public void testForwardPolicy_PushFails() throws Exception { - - final HttpClient httpClientMock = mock(HttpClient.class); - headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE); - when(httpClientMock.put(eq("createPolicy"), any(), eq(headers))).thenReturn(Response.ok().build()); - when(httpClientMock.put(eq("pushPolicy"), any(), eq(headers))).thenReturn(Response.status(400).build()); - - final HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); - when(httpClientFactoryMock.build(argThat(matcher))).thenReturn(httpClientMock); - - final XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); - forwarder.configure("xacmlPdpConfiguration"); - - final Collection policies = new ArrayList<>(); - final ToscaPolicy policy = createPolicy(policies, "policy", "optimization"); - forwarder.forward(policies); - - verify(httpClientMock).put(eq("createPolicy"), argThat(new PolicyParametersEntityMatcher(policy)), eq(headers)); - verify(httpClientMock).put(eq("pushPolicy"), argThat(new PushPolicyParametersEntityMatcher(policy)), - eq(headers)); - } - - @Test - public void testForwardPolicy_HttpClientInitFailureForPolicyCreate() throws Exception { - - final HttpClient httpClientMock = mock(HttpClient.class); - headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE); - when(httpClientMock.put(eq("createPolicy"), any(), eq(headers))).thenReturn(Response.ok().build()); - when(httpClientMock.put(eq("pushPolicy"), any(), eq(headers))).thenReturn(Response.status(400).build()); - - final HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); - when(httpClientFactoryMock.build(argThat(matcher))).thenThrow(new HttpClientConfigException()); - - final XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); - forwarder.configure("xacmlPdpConfiguration"); - - final Collection policies = new ArrayList<>(); - final ToscaPolicy policy = createPolicy(policies, "policy", "optimization"); - forwarder.forward(policies); - - assertSame(policy, policies.iterator().next()); - - verify(httpClientMock, times(0)).put(eq("createPolicy"), any(), any()); - verify(httpClientMock, times(0)).put(eq("pushPolicy"), any(), any()); - } - - @Test - public void testForwardPolicy_HttpClientInitFailureForPolicyPush() throws Exception { - - final HttpClient httpClientMock = mock(HttpClient.class); - headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE); - when(httpClientMock.put(eq("createPolicy"), any(), eq(headers))).thenReturn(Response.ok().build()); - when(httpClientMock.put(eq("pushPolicy"), any(), eq(headers))).thenReturn(Response.status(400).build()); - - final HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); - when(httpClientFactoryMock.build(argThat(matcher))).thenReturn(httpClientMock) - .thenThrow(new HttpClientConfigException()); - - final XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); - forwarder.configure("xacmlPdpConfiguration"); - - final Collection policies = new ArrayList<>(); - final ToscaPolicy policy = createPolicy(policies, "policy", "optimization"); - forwarder.forward(policies); - - verify(httpClientMock).put(eq("createPolicy"), argThat(new PolicyParametersEntityMatcher(policy)), eq(headers)); - verify(httpClientMock, times(0)).put(eq("pushPolicy"), any(), any()); - } - - class BusTopicParamsMatcher implements ArgumentMatcher { - - private BusTopicParams busTopicParams; - - BusTopicParamsMatcher(final BusTopicParams busTopicParams) { - this.busTopicParams = busTopicParams; - } - - @Override - public boolean matches(final BusTopicParams arg0) { - if (arg0 instanceof BusTopicParams) { - final BusTopicParams toCompareTo = (BusTopicParams) arg0; - return toCompareTo.isUseHttps() == busTopicParams.isUseHttps() - && toCompareTo.getHostname().equals(busTopicParams.getHostname()) - && toCompareTo.getPort() == busTopicParams.getPort() - && toCompareTo.getUserName().equals(busTopicParams.getUserName()) - && toCompareTo.getPassword().equals(busTopicParams.getPassword()) - && toCompareTo.isManaged() == busTopicParams.isManaged(); - } - return false; - } - } - - class PolicyParametersEntityMatcher implements ArgumentMatcher> { - - private ToscaPolicy policy; - - PolicyParametersEntityMatcher(final ToscaPolicy policy) { - this.policy = policy; - } - - @SuppressWarnings("unchecked") - @Override - public boolean matches(final Entity arg0) { - if (arg0 instanceof Entity) { - final PolicyParameters toCompareTo = ((Entity) arg0).getEntity(); - return toCompareTo.getPolicyName().equals(policy.getName()); - } - return false; - } - } - - class PushPolicyParametersEntityMatcher implements ArgumentMatcher> { - - private ToscaPolicy policy; - - PushPolicyParametersEntityMatcher(final ToscaPolicy policy) { - this.policy = policy; - } - - @SuppressWarnings("unchecked") - @Override - public boolean matches(final Entity arg0) { - if (arg0 instanceof Entity) { - final PushPolicyParameters toCompareTo = ((Entity) arg0).getEntity(); - return toCompareTo.getPolicyName().equals(policy.getName()) - && toCompareTo.getPolicyType().equals(policy.getType()) - && toCompareTo.getPdpGroup().equals(PDP_GROUP_VALUE); - } - return false; - } - } - - class UnsupportedPolicy extends ToscaEntity { - - @Override - public String getName() { - return "unsupported"; - } - } - - private class MyXacmlPdpPolicyForwarder extends XacmlPdpPolicyForwarder { - private HttpClientFactory factory; - - public MyXacmlPdpPolicyForwarder(final HttpClientFactory httpClientFactory) { - this.factory = httpClientFactory; - } - - @Override - protected HttpClientFactory getHttpClientFactory() { - return this.factory; - } - } - - private ToscaPolicy createPolicy(final Collection policies, final String name, final String type) { - final ToscaPolicy policy1 = new ToscaPolicy(); - policy1.setName(name); - policy1.setType(type); - policies.add(policy1); - return policy1; - } -} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/CommonTestData.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/CommonTestData.java deleted file mode 100644 index 386526e5..00000000 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/CommonTestData.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.forwarding.xacml.pdp.testclasses; - -import java.io.File; - -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; - -/** - * Class to create parameters for test cases. - * - * @author Ram Krishna Verma (ram.krishna.verma@est.tech) - */ -public class CommonTestData { - - public static final Coder coder = new StandardCoder(); - - /** - * Returns PolicyForwarderParameters for test cases. - * - * @param fileName the file name to load the parameters - * @param clazz the parameter class to be returned - * @return the specific PolicyForwarderParameters object - */ - public static T getPolicyForwarderParameters(final String fileName, final Class clazz) { - final StandardCoder coder = new StandardCoder(); - try { - return coder.decode(new File(fileName), clazz); - } catch (final CoderException exp) { - throw new RuntimeException("cannot read/decode " + fileName, exp); - } - } -} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyDecoder.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyDecoder.java deleted file mode 100644 index f2fb144a..00000000 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyDecoder.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 AT&T Intellectual Property. 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.forwarding.xacml.pdp.testclasses; - -import java.util.Collection; - -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.ToscaEntity; - -/** - * Class to create a dummy decoder for test cases. - * - * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) - */ -public class DummyDecoder implements PolicyDecoder { - - private boolean canHandleValue; - private Collection policesToReturn; - - public DummyDecoder() { - this.canHandleValue = false; - this.policesToReturn = null; - } - - public DummyDecoder(final boolean canHandleValue, final Collection policesToReturn) { - this.canHandleValue = canHandleValue; - this.policesToReturn = policesToReturn; - } - - @Override - public boolean canHandle(final PolicyInput policyInput) { - return canHandleValue; - } - - @Override - public Collection decode(final PolicyInput input) throws PolicyDecodingException { - return policesToReturn; - } - - @Override - public void configure(final String parameterGroupName) { - } -} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyReceptionHandler.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyReceptionHandler.java deleted file mode 100644 index f9bde3c3..00000000 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyReceptionHandler.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 AT&T Intellectual Property. 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.forwarding.xacml.pdp.testclasses; - -import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler; - -/** - * Class to create a dummy reception handler for test cases. - * - * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) - */ -public class DummyReceptionHandler extends AbstractReceptionHandler { - - @Override - public void initializeReception(final String parameterGroupName) { - } - - @Override - public void destroy() { - } -} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycleApiSimulatorMain.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycleApiSimulatorMain.java deleted file mode 100644 index 9aa68876..00000000 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycleApiSimulatorMain.java +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.forwarding.xacml.pdp.testclasses; - -import org.onap.policy.common.endpoints.http.server.RestServer; -import org.onap.policy.common.endpoints.parameters.RestServerParameters; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.distribution.forwarding.PolicyForwardingException; -import org.onap.policy.distribution.forwarding.lifecycle.api.LifecycleApiPolicyForwarder; -import org.onap.policy.distribution.main.rest.aaf.AafDistributionFilter; - -/** - * The class for starting/stopping simulator for testing {@link LifecycleApiPolicyForwarder} . - * - * @author Ram Krishna Verma (ram.krishna.verma@est.tech) - */ -public class LifecycleApiSimulatorMain { - private RestServer restServer; - - /** - * Starts the simulator. - * - * @throws PolicyForwardingException if error occurs - * @throws CoderException if error occurs - */ - public void startLifecycycleApiSimulator() throws PolicyForwardingException, CoderException { - final StandardCoder standardCoder = new StandardCoder(); - final RestServerParameters restServerParameters = standardCoder.decode( - ResourceUtils.getResourceAsString("src/test/resources/parameters/RestServerParameters.json"), - RestServerParameters.class); - restServer = new RestServer(restServerParameters, AafDistributionFilter.class, - LifecycycleApiSimulatorEndpoint.class); - if (!restServer.start()) { - throw new PolicyForwardingException("Failed to start rest simulator. Check log for more details..."); - } - } - - /** - * Shut down Execution. - */ - public void stopLifecycycleApiSimulator() { - if (restServer != null) { - restServer.stop(); - } - } -} diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycycleApiSimulatorEndpoint.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycycleApiSimulatorEndpoint.java deleted file mode 100644 index f07605f0..00000000 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycycleApiSimulatorEndpoint.java +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.forwarding.xacml.pdp.testclasses; - -import io.swagger.annotations.ApiParam; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.onap.policy.models.pap.concepts.PdpDeployPolicies; -import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; - -/** - * Class to provide rest end points for LifecycycleApiSimulator. - * - * @author Ram Krishna Verma (ram.krishna.verma@est.tech) - */ -@Path("/policy") -@Produces(MediaType.APPLICATION_JSON) -public class LifecycycleApiSimulatorEndpoint { - - /** - * Create policy type endpoint. - * - * @param body the post body - * @return the response object - */ - @POST - @Path("/api/v1/policytypes") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response createPolicyTypes(final ToscaServiceTemplate body) { - return Response.status(Response.Status.OK).entity(body).build(); - } - - /** - * Create policy endpoint. - * - * @param policyTypeId the policy type id - * @param policyTypeVersion the policy type version - * @param body the post body - * @return the response object - */ - @POST - @Path("/api/v1/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response createPolicies(@PathParam("policyTypeId") final String policyTypeId, - @PathParam("policyTypeVersion") final String policyTypeVersion, - @ApiParam(value = "Entity body of policy", required = true) final ToscaServiceTemplate body) { - if ("onap.policies.controlloop.operational.ApexFailure".equals(policyTypeId)) { - return Response.status(Response.Status.NOT_FOUND).build(); - } else { - return Response.status(Response.Status.OK).entity(body).build(); - } - } - - /** - * Deploy policy endpoint. - * - * @param policies the post body - * @return the response object - */ - @POST - @Path("/pap/v1/pdps/policies") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response deployPolicies(final PdpDeployPolicies policies) { - return Response.status(Response.Status.OK).entity(new PdpGroupDeployResponse()).build(); - } -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Attribute.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Attribute.java new file mode 100644 index 00000000..37f79f6b --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Attribute.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import com.google.gson.annotations.SerializedName; + +/** + * The attribute acts an abstraction belonging to or characteristic of an directive. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +class Attribute { + @SerializedName(value = "attribute_name") + private String attributeName; + @SerializedName(value = "attribute_value") + private String attributeValue; + + public void setAttributeName(final String attributeName) { + this.attributeName = attributeName; + } + + public String getAttributeName() { + return attributeName; + } + + public void setAttributeValue(final String attributeValue) { + this.attributeValue = attributeValue; + } + + public String getAttributeValue() { + return attributeValue; + } +} + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Content.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Content.java new file mode 100644 index 00000000..a6e70bd9 --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Content.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import java.util.ArrayList; +import java.util.List; +import lombok.Data; + +/** + * The content acts the high level abstraction which to be used by OOF to do Optimization. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +@Data +class Content { + private List scope = new ArrayList<>(); /* keep scope as empty for now */ + private List services = new ArrayList<>(); + private List resources = new ArrayList<>(); + private List geography = new ArrayList<>(); /* keep geography as empty for now */ + private String identity; + private List policyScope = new ArrayList<>(); + private String policyType = "Optimization"; + private List flavorFeatures = new ArrayList<>(); +} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Directive.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Directive.java new file mode 100644 index 00000000..87889cc1 --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/Directive.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import java.util.ArrayList; +import java.util.List; + + +/** + * The attribute acts an abstraction to indicate OOF which supports two different Models (Heat and TOSCA), two areas are + * wrapped: in the VNFC level to indicate the flavor, in the hpa_feature level to contains specified information. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +class Directive { + private String type; + private List attributes = new ArrayList<>(); + + public void setType(final String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public List getAttributes() { + return attributes; + } +} + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/ExtractFromNode.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/ExtractFromNode.java new file mode 100644 index 00000000..0406020c --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/ExtractFromNode.java @@ -0,0 +1,365 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import com.google.common.collect.ImmutableMap; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.CapabilityAssignment; +import org.onap.sdc.toscaparser.api.CapabilityAssignments; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.RequirementAssignment; +import org.onap.sdc.toscaparser.api.RequirementAssignments; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Extract concerned info from NodeTemplate, currently ONLY HPA Feature. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +public class ExtractFromNode { + + private static final Logger LOGGER = LoggerFactory.getLogger(ExtractFromNode.class); + + private static final String CONFIGURATION_VALUE = "configurationValue"; + private static final String VDU_TYPE = "tosca.nodes.nfv.Vdu.Compute"; + private static final String VDU_CP_TYPE = "tosca.nodes.nfv.VduCp"; + private static final String VIRTUAL_MEM_SIZE_PATH = "virtual_memory#virtual_mem_size"; + private static final String NUM_VIRTUAL_CPU_PATH = "virtual_cpu#num_virtual_cpu"; + private static final String CPU_ARCHITECTURE_PATH = "virtual_cpu#cpu_architecture"; + private static final String MEMORY_PAGE_SIZE_PATH = "virtual_memory#vdu_mem_requirements#memoryPageSize"; + private static final String NETWORK_INTERFACE_TYPE_PATH = + "virtual_network_interface_requirements#network_interface_requirements#interfaceType"; + private static final String NETWORK_PCI_PATH = + "virtual_network_interface_requirements#nic_io_requirements#logical_node_requirements"; + private static final String BASIC_CAPABILITIES_HPA_FEATURE = "basicCapabilities"; + private static final String HUGE_PAGES_HPA_FEATURE = "hugePages"; + private static final Map NETWORK_HPA_FEATURE_MAP = + ImmutableMap.of("SR-IOV", "sriovNICNetwork", "PCI-Passthrough", "pciePassthrough"); + private static final Pattern PATTERN = Pattern.compile("(\\D*)(\\d+)(\\D*)"); + private ISdcCsarHelper sdcCsarHelper; + final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().disableHtmlEscaping().create(); + + public void setSdcCsarHelper(final ISdcCsarHelper sdcCsarHelper) { + this.sdcCsarHelper = sdcCsarHelper; + } + + /** + * ExtractInfo from VNF , each VNF may includes more than one VDUs and CPs return new + * generated OptimizationPolicy if it has got Hpa feature info or else return null. + * + * @param node the NodeTemplate + * + * @return the extracted info from input node + * + * @throws PolicyDecodingException if extract fails + */ + public Content extractInfo(final NodeTemplate node) throws PolicyDecodingException { + final Metadata metaData = sdcCsarHelper.getNodeTemplateMetadata(node); + final Metadata metaDataOfService = sdcCsarHelper.getServiceMetadata(); + LOGGER.debug("the meta data of this nodetemplate = {}", metaData); + final List lnodeChild = sdcCsarHelper.getNodeTemplateChildren(node); + LOGGER.debug("the size of lnodeChild = {}", lnodeChild.size()); + + // Store all the VDUs under one VNF + final List lnodeVdu = new ArrayList<>(); + // Store all the Cps under one VNF + final List lnodeVduCp = new ArrayList<>(); + for (final NodeTemplate nodeChild : lnodeChild) { + final String type = sdcCsarHelper.getTypeOfNodeTemplate(nodeChild); + LOGGER.debug("the type of this nodeChild = {}", type); + LOGGER.debug("the meta data of this nodeChild = {}", sdcCsarHelper.getNodeTemplateMetadata(nodeChild)); + if (type.equalsIgnoreCase(VDU_TYPE)) { + lnodeVdu.add(nodeChild); + } else if (type.equalsIgnoreCase(VDU_CP_TYPE)) { + lnodeVduCp.add(nodeChild); + } + } + LOGGER.debug("the size of vdu is = {}", lnodeVdu.size()); + LOGGER.debug("the size of cp is = {}", lnodeVduCp.size()); + + final Content content = new Content(); + content.getResources().add(metaData.getValue("name")); + content.getServices().add(metaDataOfService.getValue("name")); + content.setIdentity(content.getPolicyType() + "_" + metaData.getValue("name")); + extractInfoVdu(lnodeVdu, content); + extractInfoVduCp(lnodeVduCp, content); + if (content.getFlavorFeatures().isEmpty()) { + return null; + } + return content; + } + + + /** + * ExtractInfofromVdu, supported hpa features, All under the capability of + * tosca.nodes.nfv.Vdu.Compute. + * + * @param lnodeVdu the list of Vdu node + * + * @param content to be change based on lnodeVdu + */ + public void extractInfoVdu(final List lnodeVdu, final Content content) { + // each VDU <=> FlavorFeature + for (final NodeTemplate node : lnodeVdu) { + final Attribute flavorAttribute = new Attribute(); + flavorAttribute.setAttributeName("flavorName"); + flavorAttribute.setAttributeValue(""); + final Directive flavorDirective = new Directive(); + flavorDirective.setType("flavor_directives"); + flavorDirective.getAttributes().add(flavorAttribute); + final FlavorFeature flavorFeature = new FlavorFeature(); + flavorFeature.setId(node.toString()); + LOGGER.debug("the name of node = {}", node); + flavorFeature.getDirectives().add(flavorDirective); + + final CapabilityAssignments capabilityAssignments = sdcCsarHelper.getCapabilitiesOf(node); + final CapabilityAssignment capabilityAssignment = + capabilityAssignments.getCapabilityByName("virtual_compute"); + if (capabilityAssignment != null) { + generateBasicCapability(capabilityAssignment, flavorFeature); + generateHugePages(capabilityAssignment, flavorFeature); + } + content.getFlavorFeatures().add(flavorFeature); + } + } + + /** + * GenerateBasicCapability, supported hpa features, All under the capability of + * tosca.nodes.nfv.Vdu.Compute. + * + * @param capabilityAssignment represents the capability of node + * + * @param flavorFeature represents all the features of specified flavor + */ + private void generateBasicCapability(final CapabilityAssignment capabilityAssignment, + final FlavorFeature flavorFeature) { + // the format is xxx MB/GB like 4096 MB + final String virtualMemSize = + sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, VIRTUAL_MEM_SIZE_PATH); + if (virtualMemSize != null) { + LOGGER.debug("the virtualMemSize = {}", virtualMemSize); + final HpaFeatureAttribute hpaFeatureAttribute = + generateHpaFeatureAttribute("virtualMemSize", virtualMemSize); + final FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(BASIC_CAPABILITIES_HPA_FEATURE); + flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); + flavorFeature.getFlavorProperties().add(flavorProperty); + } + + // the format is int like 2 + final String numVirtualCpu = + sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, NUM_VIRTUAL_CPU_PATH); + if (numVirtualCpu != null) { + LOGGER.debug("the numVirtualCpu = {}", numVirtualCpu); + final HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute("numVirtualCpu", numVirtualCpu); + final String cpuArchitecture = + sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, CPU_ARCHITECTURE_PATH); + final FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(BASIC_CAPABILITIES_HPA_FEATURE); + if (cpuArchitecture != null) { + flavorProperty.setArchitecture(cpuArchitecture); + } + flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); + flavorFeature.getFlavorProperties().add(flavorProperty); + } + } + + /** + * GenerateHpaFeatureAttribute based on the value of featureValue. the format: + * "hpa-attribute-key": "pciVendorId", "hpa-attribute-value": "1234", "operator": "=", + * "unit": "xxx". + * + * @param hpaAttributeKey get from the high layer tosca DM + * + * @param featureValue get from the high layer tosca DM + * + */ + private HpaFeatureAttribute generateHpaFeatureAttribute(final String hpaAttributeKey, final String featureValue) { + // based on input featureValue, return back a suitable hpaFeatureAttribute + final HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); + hpaFeatureAttribute.setHpaAttributeKey(hpaAttributeKey); + final String modifiedValue = featureValue.replace(" ", ""); + final Matcher matcher = PATTERN.matcher(modifiedValue); + if (matcher.find()) { + final String matcher1 = matcher.group(1); + final String matcher2 = matcher.group(2); + final String matcher3 = matcher.group(3); + LOGGER.debug("operator {} , value = {} , unit = {}", matcher1, matcher2, matcher3); + if (matcher.group(1).length() == 0) { + hpaFeatureAttribute.setOperator("="); + } else { + hpaFeatureAttribute.setOperator(matcher1); + } + hpaFeatureAttribute.setHpaAttributeValue(matcher2); + hpaFeatureAttribute.setUnit(matcher3); + } + return hpaFeatureAttribute; + } + + /** + * GenerateHugePages, supported hpa features, All under the capability of + * tosca.nodes.nfv.Vdu.Compute. The format is a map like: {"schemaVersion": "0", + * "schemaSelector": "", "hardwarePlatform": "generic", "mandatory": "true", + * "configurationValue": "2 MB"} + * + * @param capabilityAssignment represents the capability of node + * + * @param flavorFeature represents all the features of specified flavor + */ + private void generateHugePages(final CapabilityAssignment capabilityAssignment, final FlavorFeature flavorFeature) { + final String memoryPageSize = + sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, MEMORY_PAGE_SIZE_PATH); + LOGGER.debug("the memoryPageSize = {}", memoryPageSize); + if (memoryPageSize != null) { + final Map retMap = + gson.fromJson(memoryPageSize, new TypeToken>() {}.getType()); + LOGGER.debug("the retMap = {}", retMap); + final String memoryPageSizeValue = retMap.get(CONFIGURATION_VALUE); + final String mandatory = retMap.get("mandatory"); + if (memoryPageSizeValue == null) { + return; + } + final HpaFeatureAttribute hpaFeatureAttribute = + generateHpaFeatureAttribute("memoryPageSize", memoryPageSizeValue); + final FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(HUGE_PAGES_HPA_FEATURE); + if (mandatory != null) { + flavorProperty.setMandatory(mandatory); + } + flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); + flavorFeature.getFlavorProperties().add(flavorProperty); + } + } + + /** + * ExtractInfoVduCp, supported hpa features, under the + * virtual_network_interface_requirements of tosca.nodes.nfv.VduCp. + * + * @param lnodeVduCp the list of VduCp node + * + * @param content to be change based on lnodeVduCp + * @throws PolicyDecodingException if extract CP fails + */ + public void extractInfoVduCp(final List lnodeVduCp, final Content content) + throws PolicyDecodingException { + // each CP will binds to a VDU so need the vdu flavor map info. + final Map vduFlavorMap = new HashMap<>(); + for (final FlavorFeature flavorFeature : content.getFlavorFeatures()) { + LOGGER.debug("the id = {}", flavorFeature.getId()); + vduFlavorMap.put(flavorFeature.getId(), flavorFeature); + } + parseNodeVduCp(lnodeVduCp, vduFlavorMap); + } + + /** + * Parse the VduCp list. + * + * @param lnodeVduCp the lnodeVduCp + * @param vduFlavorMap the vduFlavorMap + * @throws PolicyDecodingException if any error occurs + */ + private void parseNodeVduCp(final List lnodeVduCp, final Map vduFlavorMap) + throws PolicyDecodingException { + for (final NodeTemplate node : lnodeVduCp) { + final String interfaceType = + sdcCsarHelper.getNodeTemplatePropertyLeafValue(node, NETWORK_INTERFACE_TYPE_PATH); + LOGGER.debug("the interfaceType = {}", interfaceType); + Map retMap = new HashMap<>(); + if (interfaceType != null) { + retMap = gson.fromJson(interfaceType, new TypeToken>() {}.getType()); + LOGGER.debug("the retMap = {}", retMap); + } + + String networkHpaFeature; + if (retMap.containsKey(CONFIGURATION_VALUE) + && NETWORK_HPA_FEATURE_MAP.containsKey(retMap.get(CONFIGURATION_VALUE).toString())) { + final String interfaceTypeValue = retMap.get(CONFIGURATION_VALUE).toString(); + networkHpaFeature = NETWORK_HPA_FEATURE_MAP.get(interfaceTypeValue); + LOGGER.debug(" the networkHpaFeature is = {}", networkHpaFeature); + } else { + LOGGER.debug(" no networkHpaFeature defined in interfaceType"); + continue; + } + + final RequirementAssignments requriements = + sdcCsarHelper.getRequirementsOf(node).getRequirementsByName("virtual_binding"); + for (final RequirementAssignment requriement : requriements.getAll()) { + final String nodeTemplateName = requriement.getNodeTemplateName(); + LOGGER.debug("getNodeTemplateName = {}", nodeTemplateName); + if (nodeTemplateName == null) { + continue; + } + if (!vduFlavorMap.containsKey(nodeTemplateName)) { + throw new PolicyDecodingException("vdu Flavor Map should contains the key " + nodeTemplateName); + } + generateNetworkFeature(networkHpaFeature, node, vduFlavorMap.get(nodeTemplateName)); + } + } + } + + /** + * GenerateNetworkFeature, all pci feature are grouped into FlavorFeature together. + * The format is a map like: {"schemaVersion": "0", "schemaSelector": "", + * "hardwarePlatform": "generic", "mandatory": "true", "configurationValue": "2 MB"} + * + * @param networkHpaFeature represents the specified Hpa feature + * @param node represents the CP Node + * @param flavorFeature represents all the features of specified flavor + */ + private void generateNetworkFeature(final String networkHpaFeature, final NodeTemplate node, + final FlavorFeature flavorFeature) { + final FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(networkHpaFeature); + final String[] pciKeys = {"pciVendorId", "pciDeviceId", "pciNumDevices", "physicalNetwork"}; + for (final String pciKey : pciKeys) { + LOGGER.debug("the pciKey = {}", pciKey); + final String pciKeyPath = NETWORK_PCI_PATH + "#" + pciKey; + final String pciValue = sdcCsarHelper.getNodeTemplatePropertyLeafValue(node, pciKeyPath); + if (pciValue != null) { + LOGGER.debug("the pciValue = {}", pciValue); + final Map retMap = + gson.fromJson(pciValue, new TypeToken>() {}.getType()); + final String pciConfigValue = retMap.get(CONFIGURATION_VALUE); + if (pciConfigValue == null) { + return; + } + final HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute(pciKey, pciConfigValue); + flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); + } + } + flavorFeature.getFlavorProperties().add(flavorProperty); + } +} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorFeature.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorFeature.java new file mode 100644 index 00000000..75643a72 --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorFeature.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import java.util.ArrayList; +import java.util.List; + +/** + * The FlavorFeature includes all the specified flavor infos used in multicloud, it represents one VDU of TOSCA. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +class FlavorFeature { + private String id; + private String type = "tosca.nodes.nfv.Vdu.Compute"; + private List directives = new ArrayList<>(); + private List flavorProperties = new ArrayList<>(); + + public void setId(final String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setType(final String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public List getFlavorProperties() { + return flavorProperties; + } + + public List getDirectives() { + return directives; + } +} + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorProperty.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorProperty.java new file mode 100644 index 00000000..f849ebaa --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/FlavorProperty.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import com.google.gson.annotations.SerializedName; + +import java.util.ArrayList; +import java.util.List; + +/** + * The FlavorProperty includes all the properties of Flavor. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +class FlavorProperty { + @SerializedName(value = "hpa-feature") + private String hpaFeature; + private String mandatory = "True"; + private String architecture = "generic"; + @SerializedName(value = "hpa-version") + private String hpaVersion = "v1"; + private List directives = new ArrayList<>(); + @SerializedName(value = "hpa-feature-attributes") + private List hpaFeatureAttributes = new ArrayList<>(); + + public void setHpaFeature(final String hpaFeature) { + this.hpaFeature = hpaFeature; + } + + public String getHpaFeature() { + return hpaFeature; + } + + public void setMandatory(final String mandatory) { + this.mandatory = mandatory; + } + + public String getMandatory() { + return mandatory; + } + + public void setArchitecture(final String architecture) { + this.architecture = architecture; + } + + public String getArchitecture() { + return architecture; + } + + public void setHpaVersion(final String hpaVersion) { + this.hpaVersion = hpaVersion; + } + + public String getHpaVersion() { + return hpaVersion; + } + + public List getDirectives() { + return directives; + } + + public List getHpaFeatureAttributes() { + return hpaFeatureAttributes; + } +} + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/HpaFeatureAttribute.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/HpaFeatureAttribute.java new file mode 100644 index 00000000..8bb078ad --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/HpaFeatureAttribute.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import com.google.gson.annotations.SerializedName; + +/** + * The HpaFeatureAttribute represents a way to provide match expression. + * + * @author Libo Zhu (libo.zhu@intel.com) + */ +class HpaFeatureAttribute { + @SerializedName(value = "hpa-attribute-key") + private String hpaAttributeKey; + @SerializedName(value = "hpa-attribute-value") + private String hpaAttributeValue; + private String operator; + private String unit; + + public void setHpaAttributeKey(final String hpaAttributeKey) { + this.hpaAttributeKey = hpaAttributeKey; + } + + public String getHpaAttributeKey() { + return hpaAttributeKey; + } + + public void setHpaAttributeValue(final String hpaAttributeValue) { + this.hpaAttributeValue = hpaAttributeValue; + } + + public String getHpaAttributeValue() { + return hpaAttributeValue; + } + + public void setOperator(final String operator) { + this.operator = operator; + } + + public String getOperator() { + return operator; + } + + public void setUnit(final String unit) { + this.unit = unit; + } + + public String getUnit() { + return unit; + } +} + + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpa.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpa.java new file mode 100644 index 00000000..e1e1a9a9 --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpa.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.distribution.model.Csar; +import org.onap.policy.distribution.model.PolicyInput; +import org.onap.policy.distribution.reception.decoding.PolicyDecoder; +import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Decodes PDP-X policies from a CSAR file and creates ToscaServiceTemplate for Policy Lifecycle API's. + */ +public class PolicyDecoderCsarHpa implements PolicyDecoder { + + private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderCsarHpa.class); + private PolicyDecoderCsarHpaParameters decoderParameters; + + public static final String TOSCA_POLICY_SCOPE = "scope"; + public static final String TOSCA_POLICY_SERVICES = "services"; + public static final String TOSCA_POLICY_RESOURCES = "resources"; + public static final String TOSCA_POLICY_IDENTITY = "identity"; + public static final String TOSCA_POLICY_FLAVORFEATURES = "flavorfeatures"; + + public static final String TOSCA_POLICY_HPA_OOF = "Optimization"; + + @Override + public Collection decode(final Csar csar) throws PolicyDecodingException { + final List entities = new ArrayList<>(); + final ISdcCsarHelper sdcCsarHelper = parseCsar(csar); + final List lnodeVf = sdcCsarHelper.getServiceVfList(); + LOGGER.debug("the size of Vf = {}", lnodeVf.size()); + final ExtractFromNode extractFromNode = new ExtractFromNode(); + extractFromNode.setSdcCsarHelper(sdcCsarHelper); + final String serviceName = sdcCsarHelper.getServiceMetadata().getValue("name"); + LOGGER.debug("the name of the service = {}", serviceName); + for (final NodeTemplate node : lnodeVf) { + final Content content = extractFromNode.extractInfo(node); + if (content != null) { + final ToscaServiceTemplate entity = new ToscaServiceTemplate(); + Map props = new LinkedHashMap<>(); + props.put(TOSCA_POLICY_SCOPE, content.getScope()); + props.put(TOSCA_POLICY_SERVICES, content.getServices()); + props.put(TOSCA_POLICY_RESOURCES, content.getResources()); + props.put(TOSCA_POLICY_IDENTITY, content.getIdentity()); + props.put(TOSCA_POLICY_FLAVORFEATURES, content.getFlavorFeatures()); + ToscaPolicy policy = new ToscaPolicy(); + policy.setProperties(props); + Map map = new LinkedHashMap<>(); + String type = content.getPolicyType(); + map.put(type, policy); + List> policies = new ArrayList<>(); + policies.add(map); + ToscaTopologyTemplate topologyTemplate = new ToscaTopologyTemplate(); + topologyTemplate.setPolicies(policies); + entity.setToscaTopologyTemplate(topologyTemplate); + entities.add(entity); + } + } + return entities; + } + + @Override + public boolean canHandle(final PolicyInput policyInput) { + return Csar.class.isAssignableFrom(policyInput.getClass()); + } + + /** + * Parse the input Csar using SDC TOSCA parser. + * + * @param csar represents the service TOSCA Csar + * @return the object to represents the content of input csar + * @throws PolicyDecodingException if parse fails + */ + public ISdcCsarHelper parseCsar(final Csar csar) throws PolicyDecodingException { + ISdcCsarHelper sdcCsarHelper; + try { + final SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); + LOGGER.debug("Csar File Path = {}", csar.getCsarPath()); + final File csarFile = new File(csar.getCsarPath()); + sdcCsarHelper = factory.getSdcCsarHelper(csarFile.getAbsolutePath()); + } catch (final Exception exp) { + throw new PolicyDecodingException( "Failed passing the csar file", exp); + } + return sdcCsarHelper; + } + + @Override + public void configure(final String parameterGroupName) { + decoderParameters = ParameterService.get(parameterGroupName); + } +} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpaParameters.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpaParameters.java new file mode 100644 index 00000000..7d26335c --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/hpa/PolicyDecoderCsarHpaParameters.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import lombok.Getter; + +import org.onap.policy.common.parameters.annotations.NotBlank; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup; + +/** + * This class handles the parameters needed for {@link PolicyDecoderCsarHpa}. + */ +@Getter +@NotNull +@NotBlank +public class PolicyDecoderCsarHpaParameters extends PolicyDecoderConfigurationParameterGroup { + + private String policyNamePrefix; + private String onapName; + private String version; + private String priority; + private String riskType; + private String riskLevel; + + public PolicyDecoderCsarHpaParameters() { + super(PolicyDecoderCsarHpaParameters.class.getSimpleName()); + } +} + diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Attribute.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Attribute.java deleted file mode 100644 index 9962894e..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Attribute.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import com.google.gson.annotations.SerializedName; - -/** - * The attribute acts an abstraction belonging to or characteristic of an directive. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -class Attribute { - @SerializedName(value = "attribute_name") - private String attributeName; - @SerializedName(value = "attribute_value") - private String attributeValue; - - public void setAttributeName(final String attributeName) { - this.attributeName = attributeName; - } - - public String getAttributeName() { - return attributeName; - } - - public void setAttributeValue(final String attributeValue) { - this.attributeValue = attributeValue; - } - - public String getAttributeValue() { - return attributeValue; - } -} - diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ConfigBody.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ConfigBody.java deleted file mode 100644 index 521fcfd6..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ConfigBody.java +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -public class ConfigBody { - - private String service; - private String policyName; - private String description; - private String templateVersion; - private String version; - private String priority; - private String riskType; - private String riskLevel; - private String guard; - private Content content; - - public String getService() { - return service; - } - - public void setService(String service) { - this.service = service; - } - - public String getPolicyName() { - return policyName; - } - - public void setPolicyName(String policyName) { - this.policyName = policyName; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getTemplateVersion() { - return templateVersion; - } - - public void setTemplateVersion(String templateVersion) { - this.templateVersion = templateVersion; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getPriority() { - return priority; - } - - public void setPriority(String priority) { - this.priority = priority; - } - - public String getRiskType() { - return riskType; - } - - public void setRiskType(String riskType) { - this.riskType = riskType; - } - - public String getRiskLevel() { - return riskLevel; - } - - public void setRiskLevel(String riskLevel) { - this.riskLevel = riskLevel; - } - - public String getGuard() { - return guard; - } - - public void setGuard(String guard) { - this.guard = guard; - } - - public Content getContent() { - return content; - } - - public void setContent(Content content) { - this.content = content; - } -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Content.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Content.java deleted file mode 100644 index ef4584cb..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Content.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import java.util.ArrayList; -import java.util.List; -import lombok.Data; - -/** - * The content acts the high level abstraction which to be used by OOF to do Optimization. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -@Data -class Content { - private List scope = new ArrayList<>(); /* keep scope as empty for now */ - private List services = new ArrayList<>(); - private List resources = new ArrayList<>(); - private List geography = new ArrayList<>(); /* keep geography as empty for now */ - private String identity; - private List policyScope = new ArrayList<>(); - private String policyType = "Optimization"; - private List flavorFeatures = new ArrayList<>(); -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Directive.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Directive.java deleted file mode 100644 index 6df5bc38..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/Directive.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import java.util.ArrayList; -import java.util.List; - - -/** - * The attribute acts an abstraction to indicate OOF which supports two different Models (Heat and TOSCA), two areas are - * wrapped: in the VNFC level to indicate the flavor, in the hpa_feature level to contains specified information. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -class Directive { - private String type; - private List attributes = new ArrayList<>(); - - public void setType(final String type) { - this.type = type; - } - - public String getType() { - return type; - } - - public List getAttributes() { - return attributes; - } -} - diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java deleted file mode 100644 index a7313876..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/ExtractFromNode.java +++ /dev/null @@ -1,361 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import com.google.common.collect.ImmutableMap; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.toscaparser.api.CapabilityAssignment; -import org.onap.sdc.toscaparser.api.CapabilityAssignments; -import org.onap.sdc.toscaparser.api.NodeTemplate; -import org.onap.sdc.toscaparser.api.RequirementAssignment; -import org.onap.sdc.toscaparser.api.RequirementAssignments; -import org.onap.sdc.toscaparser.api.elements.Metadata; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Extract concerned info from NodeTemplate, currently ONLY HPA Feature. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -public class ExtractFromNode { - - private static final Logger LOGGER = LoggerFactory.getLogger(ExtractFromNode.class); - - private static final String CONFIGURATION_VALUE = "configurationValue"; - private static final String VDU_TYPE = "tosca.nodes.nfv.Vdu.Compute"; - private static final String VDU_CP_TYPE = "tosca.nodes.nfv.VduCp"; - private static final String VIRTUAL_MEM_SIZE_PATH = "virtual_memory#virtual_mem_size"; - private static final String NUM_VIRTUAL_CPU_PATH = "virtual_cpu#num_virtual_cpu"; - private static final String CPU_ARCHITECTURE_PATH = "virtual_cpu#cpu_architecture"; - private static final String MEMORY_PAGE_SIZE_PATH = "virtual_memory#vdu_mem_requirements#memoryPageSize"; - private static final String NETWORK_INTERFACE_TYPE_PATH = - "virtual_network_interface_requirements#network_interface_requirements#interfaceType"; - private static final String NETWORK_PCI_PATH = - "virtual_network_interface_requirements#nic_io_requirements#logical_node_requirements"; - private static final String BASIC_CAPABILITIES_HPA_FEATURE = "basicCapabilities"; - private static final String HUGE_PAGES_HPA_FEATURE = "hugePages"; - private static final Map NETWORK_HPA_FEATURE_MAP = - ImmutableMap.of("SR-IOV", "sriovNICNetwork", "PCI-Passthrough", "pciePassthrough"); - private static final Pattern PATTERN = Pattern.compile("(\\D*)(\\d+)(\\D*)"); - private ISdcCsarHelper sdcCsarHelper; - final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().disableHtmlEscaping().create(); - - public void setSdcCsarHelper(final ISdcCsarHelper sdcCsarHelper) { - this.sdcCsarHelper = sdcCsarHelper; - } - - /** - * ExtractInfo from VNF , each VNF may includes more than one VDUs and CPs return new generated PdpxPolicy if it has - * got Hpa feature info or else return null. - * - * @param node the NodeTemplate - * - * @return the extracted info from input node - * - * @throws PolicyDecodingException if extract fails - */ - public Content extractInfo(final NodeTemplate node) throws PolicyDecodingException { - final Metadata metaData = sdcCsarHelper.getNodeTemplateMetadata(node); - final Metadata metaDataOfService = sdcCsarHelper.getServiceMetadata(); - LOGGER.debug("the meta data of this nodetemplate = {}", metaData); - final List lnodeChild = sdcCsarHelper.getNodeTemplateChildren(node); - LOGGER.debug("the size of lnodeChild = {}", lnodeChild.size()); - - // Store all the VDUs under one VNF - final List lnodeVdu = new ArrayList<>(); - // Store all the Cps under one VNF - final List lnodeVduCp = new ArrayList<>(); - for (final NodeTemplate nodeChild : lnodeChild) { - final String type = sdcCsarHelper.getTypeOfNodeTemplate(nodeChild); - LOGGER.debug("the type of this nodeChild = {}", type); - LOGGER.debug("the meta data of this nodeChild = {}", sdcCsarHelper.getNodeTemplateMetadata(nodeChild)); - if (type.equalsIgnoreCase(VDU_TYPE)) { - lnodeVdu.add(nodeChild); - } else if (type.equalsIgnoreCase(VDU_CP_TYPE)) { - lnodeVduCp.add(nodeChild); - } - } - LOGGER.debug("the size of vdu is = {}", lnodeVdu.size()); - LOGGER.debug("the size of cp is = {}", lnodeVduCp.size()); - - final Content content = new Content(); - content.getResources().add(metaData.getValue("name")); - content.getServices().add(metaDataOfService.getValue("name")); - content.setIdentity(content.getPolicyType() + "_" + metaData.getValue("name")); - extractInfoVdu(lnodeVdu, content); - extractInfoVduCp(lnodeVduCp, content); - if (content.getFlavorFeatures().isEmpty()) { - return null; - } - return content; - } - - - /** - * ExtractInfofromVdu, supported hpa features, All under the capability of tosca.nodes.nfv.Vdu.Compute. - * - * @param lnodeVdu the list of Vdu node - * - * @param content to be change based on lnodeVdu - */ - public void extractInfoVdu(final List lnodeVdu, final Content content) { - // each VDU <=> FlavorFeature - for (final NodeTemplate node : lnodeVdu) { - final Attribute flavorAttribute = new Attribute(); - flavorAttribute.setAttributeName("flavorName"); - flavorAttribute.setAttributeValue(""); - final Directive flavorDirective = new Directive(); - flavorDirective.setType("flavor_directives"); - flavorDirective.getAttributes().add(flavorAttribute); - final FlavorFeature flavorFeature = new FlavorFeature(); - flavorFeature.setId(node.toString()); - LOGGER.debug("the name of node = {}", node); - flavorFeature.getDirectives().add(flavorDirective); - - final CapabilityAssignments capabilityAssignments = sdcCsarHelper.getCapabilitiesOf(node); - final CapabilityAssignment capabilityAssignment = - capabilityAssignments.getCapabilityByName("virtual_compute"); - if (capabilityAssignment != null) { - generateBasicCapability(capabilityAssignment, flavorFeature); - generateHugePages(capabilityAssignment, flavorFeature); - } - content.getFlavorFeatures().add(flavorFeature); - } - } - - /** - * GenerateBasicCapability, supported hpa features, All under the capability of tosca.nodes.nfv.Vdu.Compute. - * - * @param capabilityAssignment represents the capability of node - * - * @param flavorFeature represents all the features of specified flavor - */ - private void generateBasicCapability(final CapabilityAssignment capabilityAssignment, - final FlavorFeature flavorFeature) { - // the format is xxx MB/GB like 4096 MB - final String virtualMemSize = - sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, VIRTUAL_MEM_SIZE_PATH); - if (virtualMemSize != null) { - LOGGER.debug("the virtualMemSize = {}", virtualMemSize); - final HpaFeatureAttribute hpaFeatureAttribute = - generateHpaFeatureAttribute("virtualMemSize", virtualMemSize); - final FlavorProperty flavorProperty = new FlavorProperty(); - flavorProperty.setHpaFeature(BASIC_CAPABILITIES_HPA_FEATURE); - flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); - flavorFeature.getFlavorProperties().add(flavorProperty); - } - - // the format is int like 2 - final String numVirtualCpu = - sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, NUM_VIRTUAL_CPU_PATH); - if (numVirtualCpu != null) { - LOGGER.debug("the numVirtualCpu = {}", numVirtualCpu); - final HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute("numVirtualCpu", numVirtualCpu); - final String cpuArchitecture = - sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, CPU_ARCHITECTURE_PATH); - final FlavorProperty flavorProperty = new FlavorProperty(); - flavorProperty.setHpaFeature(BASIC_CAPABILITIES_HPA_FEATURE); - if (cpuArchitecture != null) { - flavorProperty.setArchitecture(cpuArchitecture); - } - flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); - flavorFeature.getFlavorProperties().add(flavorProperty); - } - } - - /** - * GenerateHpaFeatureAttribute based on the value of featureValue. the format: "hpa-attribute-key": "pciVendorId", - * "hpa-attribute-value": "1234", "operator": "=", "unit": "xxx". - * - * @param hpaAttributeKey get from the high layer tosca DM - * - * @param featureValue get from the high layer tosca DM - * - */ - private HpaFeatureAttribute generateHpaFeatureAttribute(final String hpaAttributeKey, final String featureValue) { - // based on input featureValue, return back a suitable hpaFeatureAttribute - final HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); - hpaFeatureAttribute.setHpaAttributeKey(hpaAttributeKey); - final String modifiedValue = featureValue.replace(" ", ""); - final Matcher matcher = PATTERN.matcher(modifiedValue); - if (matcher.find()) { - final String matcher1 = matcher.group(1); - final String matcher2 = matcher.group(2); - final String matcher3 = matcher.group(3); - LOGGER.debug("operator {} , value = {} , unit = {}", matcher1, matcher2, matcher3); - if (matcher.group(1).length() == 0) { - hpaFeatureAttribute.setOperator("="); - } else { - hpaFeatureAttribute.setOperator(matcher1); - } - hpaFeatureAttribute.setHpaAttributeValue(matcher2); - hpaFeatureAttribute.setUnit(matcher3); - } - return hpaFeatureAttribute; - } - - /** - * GenerateHugePages, supported hpa features, All under the capability of tosca.nodes.nfv.Vdu.Compute. The format is - * a map like: {"schemaVersion": "0", "schemaSelector": "", "hardwarePlatform": "generic", "mandatory": "true", - * "configurationValue": "2 MB"} - * - * @param capabilityAssignment represents the capability of node - * - * @param flavorFeature represents all the features of specified flavor - */ - private void generateHugePages(final CapabilityAssignment capabilityAssignment, final FlavorFeature flavorFeature) { - final String memoryPageSize = - sdcCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, MEMORY_PAGE_SIZE_PATH); - LOGGER.debug("the memoryPageSize = {}", memoryPageSize); - if (memoryPageSize != null) { - final Map retMap = - gson.fromJson(memoryPageSize, new TypeToken>() {}.getType()); - LOGGER.debug("the retMap = {}", retMap); - final String memoryPageSizeValue = retMap.get(CONFIGURATION_VALUE); - final String mandatory = retMap.get("mandatory"); - if (memoryPageSizeValue == null) { - return; - } - final HpaFeatureAttribute hpaFeatureAttribute = - generateHpaFeatureAttribute("memoryPageSize", memoryPageSizeValue); - final FlavorProperty flavorProperty = new FlavorProperty(); - flavorProperty.setHpaFeature(HUGE_PAGES_HPA_FEATURE); - if (mandatory != null) { - flavorProperty.setMandatory(mandatory); - } - flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); - flavorFeature.getFlavorProperties().add(flavorProperty); - } - } - - /** - * ExtractInfoVduCp, supported hpa features, under the virtual_network_interface_requirements of - * tosca.nodes.nfv.VduCp. - * - * @param lnodeVduCp the list of VduCp node - * - * @param content to be change based on lnodeVduCp - * @throws PolicyDecodingException if extract CP fails - */ - public void extractInfoVduCp(final List lnodeVduCp, final Content content) - throws PolicyDecodingException { - // each CP will binds to a VDU so need the vdu flavor map info. - final Map vduFlavorMap = new HashMap<>(); - for (final FlavorFeature flavorFeature : content.getFlavorFeatures()) { - LOGGER.debug("the id = {}", flavorFeature.getId()); - vduFlavorMap.put(flavorFeature.getId(), flavorFeature); - } - parseNodeVduCp(lnodeVduCp, vduFlavorMap); - } - - /** - * Parse the VduCp list. - * - * @param lnodeVduCp the lnodeVduCp - * @param vduFlavorMap the vduFlavorMap - * @throws PolicyDecodingException if any error occurs - */ - private void parseNodeVduCp(final List lnodeVduCp, final Map vduFlavorMap) - throws PolicyDecodingException { - for (final NodeTemplate node : lnodeVduCp) { - final String interfaceType = - sdcCsarHelper.getNodeTemplatePropertyLeafValue(node, NETWORK_INTERFACE_TYPE_PATH); - LOGGER.debug("the interfaceType = {}", interfaceType); - Map retMap = new HashMap<>(); - if (interfaceType != null) { - retMap = gson.fromJson(interfaceType, new TypeToken>() {}.getType()); - LOGGER.debug("the retMap = {}", retMap); - } - - String networkHpaFeature; - if (retMap.containsKey(CONFIGURATION_VALUE) - && NETWORK_HPA_FEATURE_MAP.containsKey(retMap.get(CONFIGURATION_VALUE).toString())) { - final String interfaceTypeValue = retMap.get(CONFIGURATION_VALUE).toString(); - networkHpaFeature = NETWORK_HPA_FEATURE_MAP.get(interfaceTypeValue); - LOGGER.debug(" the networkHpaFeature is = {}", networkHpaFeature); - } else { - LOGGER.debug(" no networkHpaFeature defined in interfaceType"); - continue; - } - - final RequirementAssignments requriements = - sdcCsarHelper.getRequirementsOf(node).getRequirementsByName("virtual_binding"); - for (final RequirementAssignment requriement : requriements.getAll()) { - final String nodeTemplateName = requriement.getNodeTemplateName(); - LOGGER.debug("getNodeTemplateName = {}", nodeTemplateName); - if (nodeTemplateName == null) { - continue; - } - if (!vduFlavorMap.containsKey(nodeTemplateName)) { - throw new PolicyDecodingException("vdu Flavor Map should contains the key " + nodeTemplateName); - } - generateNetworkFeature(networkHpaFeature, node, vduFlavorMap.get(nodeTemplateName)); - } - } - } - - /** - * GenerateNetworkFeature, all pci feature are grouped into FlavorFeature together. The format is a map like: - * {"schemaVersion": "0", "schemaSelector": "", "hardwarePlatform": "generic", "mandatory": "true", - * "configurationValue": "2 MB"} - * - * @param networkHpaFeature represents the specified Hpa feature - * @param node represents the CP Node - * @param flavorFeature represents all the features of specified flavor - */ - private void generateNetworkFeature(final String networkHpaFeature, final NodeTemplate node, - final FlavorFeature flavorFeature) { - final FlavorProperty flavorProperty = new FlavorProperty(); - flavorProperty.setHpaFeature(networkHpaFeature); - final String[] pciKeys = { "pciVendorId", "pciDeviceId", "pciNumDevices", "physicalNetwork" }; - for (final String pciKey : pciKeys) { - LOGGER.debug("the pciKey = {}", pciKey); - final String pciKeyPath = NETWORK_PCI_PATH + "#" + pciKey; - final String pciValue = sdcCsarHelper.getNodeTemplatePropertyLeafValue(node, pciKeyPath); - if (pciValue != null) { - LOGGER.debug("the pciValue = {}", pciValue); - final Map retMap = - gson.fromJson(pciValue, new TypeToken>() {}.getType()); - final String pciConfigValue = retMap.get(CONFIGURATION_VALUE); - if (pciConfigValue == null) { - return; - } - final HpaFeatureAttribute hpaFeatureAttribute = generateHpaFeatureAttribute(pciKey, pciConfigValue); - flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); - } - } - flavorFeature.getFlavorProperties().add(flavorProperty); - } -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorFeature.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorFeature.java deleted file mode 100644 index c29378de..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorFeature.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import java.util.ArrayList; -import java.util.List; - -/** - * The FlavorFeature includes all the specified flavor infos used in multicloud, it represents one VDU of TOSCA. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -class FlavorFeature { - private String id; - private String type = "tosca.nodes.nfv.Vdu.Compute"; - private List directives = new ArrayList<>(); - private List flavorProperties = new ArrayList<>(); - - public void setId(final String id) { - this.id = id; - } - - public String getId() { - return id; - } - - public void setType(final String type) { - this.type = type; - } - - public String getType() { - return type; - } - - public List getFlavorProperties() { - return flavorProperties; - } - - public List getDirectives() { - return directives; - } -} - diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorProperty.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorProperty.java deleted file mode 100644 index 0453370d..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/FlavorProperty.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import com.google.gson.annotations.SerializedName; - -import java.util.ArrayList; -import java.util.List; - -/** - * The FlavorProperty includes all the properties of Flavor. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -class FlavorProperty { - @SerializedName(value = "hpa-feature") - private String hpaFeature; - private String mandatory = "True"; - private String architecture = "generic"; - @SerializedName(value = "hpa-version") - private String hpaVersion = "v1"; - private List directives = new ArrayList<>(); - @SerializedName(value = "hpa-feature-attributes") - private List hpaFeatureAttributes = new ArrayList<>(); - - public void setHpaFeature(final String hpaFeature) { - this.hpaFeature = hpaFeature; - } - - public String getHpaFeature() { - return hpaFeature; - } - - public void setMandatory(final String mandatory) { - this.mandatory = mandatory; - } - - public String getMandatory() { - return mandatory; - } - - public void setArchitecture(final String architecture) { - this.architecture = architecture; - } - - public String getArchitecture() { - return architecture; - } - - public void setHpaVersion(final String hpaVersion) { - this.hpaVersion = hpaVersion; - } - - public String getHpaVersion() { - return hpaVersion; - } - - public List getDirectives() { - return directives; - } - - public List getHpaFeatureAttributes() { - return hpaFeatureAttributes; - } -} - diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java deleted file mode 100644 index 91008aa5..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/HpaFeatureAttribute.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import com.google.gson.annotations.SerializedName; - -/** - * The HpaFeatureAttribute represents a way to provide match expression. - * - * @author Libo Zhu (libo.zhu@intel.com) - */ -class HpaFeatureAttribute { - @SerializedName(value = "hpa-attribute-key") - private String hpaAttributeKey; - @SerializedName(value = "hpa-attribute-value") - private String hpaAttributeValue; - private String operator; - private String unit; - - public void setHpaAttributeKey(final String hpaAttributeKey) { - this.hpaAttributeKey = hpaAttributeKey; - } - - public String getHpaAttributeKey() { - return hpaAttributeKey; - } - - public void setHpaAttributeValue(final String hpaAttributeValue) { - this.hpaAttributeValue = hpaAttributeValue; - } - - public String getHpaAttributeValue() { - return hpaAttributeValue; - } - - public void setOperator(final String operator) { - this.operator = operator; - } - - public String getOperator() { - return operator; - } - - public void setUnit(final String unit) { - this.unit = unit; - } - - public String getUnit() { - return unit; - } -} - - diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PdpxPolicy.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PdpxPolicy.java deleted file mode 100644 index e7a0e8ab..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PdpxPolicy.java +++ /dev/null @@ -1,127 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import org.onap.policy.distribution.model.Policy; -import org.onap.policy.distribution.reception.decoding.PolicyDecoder; - -/** - * A PDP-X Policy, decoded by a {@link PolicyDecoder}. - */ -public class PdpxPolicy implements Policy { - - private String guard; - private String service; - private String policyName; - private String description; - private String templateVersion; - private String version; - private String riskType; - private String priority; - private String riskLevel; - private Content content = new Content(); - - @Override - public String getPolicyName() { - return policyName; - } - - @Override - public String getPolicyType() { - return content.getPolicyType(); - } - - public String getGuard() { - return guard; - } - - public String getService() { - return service; - } - - public String getDescription() { - return description; - } - - public String getTemplateVersion() { - return templateVersion; - } - - public String getVersion() { - return version; - } - - public String getRiskType() { - return riskType; - } - - public String getPriority() { - return priority; - } - - public String getRiskLevel() { - return riskLevel; - } - - public Content getContent() { - return content; - } - - public void setGuard(final String guard) { - this.guard = guard; - } - - public void setService(final String service) { - this.service = service; - } - - public void setPolicyName(final String policyName) { - this.policyName = policyName; - } - - public void setDescription(final String description) { - this.description = description; - } - - public void setTemplateVersion(final String templateVersion) { - this.templateVersion = templateVersion; - } - - public void setVersion(final String version) { - this.version = version; - } - - public void setRiskType(final String riskType) { - this.riskType = riskType; - } - - public void setPriority(final String priority) { - this.priority = priority; - } - - public void setRiskLevel(final String riskLevel) { - this.riskLevel = riskLevel; - } - - public void setContent(final Content content) { - this.content = content; - } -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java deleted file mode 100644 index 842245c0..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.distribution.model.Csar; -import org.onap.policy.distribution.model.OptimizationPolicy; -import org.onap.policy.distribution.model.PolicyInput; -import org.onap.policy.distribution.reception.decoding.PolicyDecoder; -import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.onap.sdc.toscaparser.api.NodeTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Decodes PDP-X policies from a CSAR file. - */ -public class PolicyDecoderCsarPdpx implements PolicyDecoder { - - private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderCsarPdpx.class); - private final Gson gson = new GsonBuilder().serializeNulls().disableHtmlEscaping().create(); - private PolicyDecoderCsarPdpxConfigurationParameterGroup decoderParameters; - - @Override - public Collection decode(final Csar csar) throws PolicyDecodingException { - final List policies = new ArrayList<>(); - final ISdcCsarHelper sdcCsarHelper = parseCsar(csar); - final List lnodeVf = sdcCsarHelper.getServiceVfList(); - LOGGER.debug("the size of Vf = {}", lnodeVf.size()); - final ExtractFromNode extractFromNode = new ExtractFromNode(); - extractFromNode.setSdcCsarHelper(sdcCsarHelper); - final String serviceName = sdcCsarHelper.getServiceMetadata().getValue("name"); - LOGGER.debug("the name of the service = {}", serviceName); - for (final NodeTemplate node : lnodeVf) { - final Content content = extractFromNode.extractInfo(node); - if (content != null) { - final OptimizationPolicy policy = new OptimizationPolicy(); - final String policyName = decoderParameters.getPolicyNamePrefix() + "." + content.getIdentity(); - policy.setOnapName(decoderParameters.getOnapName()); - policy.setName(policyName); - final ConfigBody configBody = new ConfigBody(); - configBody.setService("hpaPolicy"); - configBody.setPolicyName(policyName); - configBody.setDescription("OOF Policy"); - configBody.setTemplateVersion("OpenSource.version.1"); - configBody.setVersion(decoderParameters.getVersion()); - configBody.setPriority(decoderParameters.getPriority()); - configBody.setRiskLevel(decoderParameters.getRiskLevel()); - configBody.setRiskType(decoderParameters.getRiskType()); - configBody.setGuard("False"); - content.setPolicyType("hpa"); - content.getPolicyScope().add("HPA"); - content.getPolicyScope().add(serviceName); - configBody.setContent(content); - policy.setConfigBody(gson.toJson(configBody)); - policies.add(policy); - } - } - return policies; - } - - @Override - public boolean canHandle(final PolicyInput policyInput) { - return policyInput.getClass().isAssignableFrom(Csar.class); - } - - /** - * Parse the input Csar using SDC TOSCA parser. - * - * @param csar represents the service TOSCA Csar - * @return the object to represents the content of input csar - * @throws PolicyDecodingException if parse fails - */ - public ISdcCsarHelper parseCsar(final Csar csar) throws PolicyDecodingException { - ISdcCsarHelper sdcCsarHelper; - try { - final SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); - LOGGER.debug("Csar File Path = {}", csar.getCsarPath()); - final File csarFile = new File(csar.getCsarPath()); - sdcCsarHelper = factory.getSdcCsarHelper(csarFile.getAbsolutePath()); - } catch (final Exception exp) { - final String message = "Failed passing the csar file"; - LOGGER.error(message, exp); - throw new PolicyDecodingException(message, exp); - } - return sdcCsarHelper; - } - - @Override - public void configure(final String parameterGroupName) { - decoderParameters = ParameterService.get(parameterGroupName); - } -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterGroup.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterGroup.java deleted file mode 100644 index f376c391..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxConfigurationParameterGroup.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import lombok.Getter; - -import org.onap.policy.common.parameters.annotations.NotBlank; -import org.onap.policy.common.parameters.annotations.NotNull; -import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup; - -/** - * This class handles reading, parsing and validating of the paramaters for the {@link PolicyDecoderCsarPdpx}. - */ -@Getter -@NotNull -@NotBlank -public class PolicyDecoderCsarPdpxConfigurationParameterGroup extends PolicyDecoderConfigurationParameterGroup { - - private String policyNamePrefix; - private String onapName; - private String version; - private String priority; - private String riskType; - private String riskLevel; - - public PolicyDecoderCsarPdpxConfigurationParameterGroup() { - super(PolicyDecoderCsarPdpxConfigurationParameterGroup.class.getSimpleName()); - } -} - diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java deleted file mode 100644 index 8cfc6857..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java +++ /dev/null @@ -1,132 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.distribution.model.Csar; -import org.onap.policy.distribution.model.PolicyInput; -import org.onap.policy.distribution.reception.decoding.PolicyDecoder; -import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.onap.sdc.toscaparser.api.NodeTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Decodes PDP-X policies from a CSAR file and creates ToscaServiceTemplate for Policy Lifecycle API's. - */ -public class PolicyDecoderCsarPdpxLifecycleApi implements PolicyDecoder { - - private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderCsarPdpxLifecycleApi.class); - private final StandardCoder coder = new StandardCoder(); - private PolicyDecoderCsarPdpxLifecycleApiParameters decoderParameters; - - public static final String TOSCA_POLICY_SCOPE = "scope"; - public static final String TOSCA_POLICY_SERVICES = "services"; - public static final String TOSCA_POLICY_RESOURCES = "resources"; - public static final String TOSCA_POLICY_IDENTITY = "identity"; - public static final String TOSCA_POLICY_FLAVORFEATURES = "flavorfeatures"; - - public static final String TOSCA_POLICY_HPA_OOF = "Optimization"; - - @Override - public Collection decode(final Csar csar) throws PolicyDecodingException { - final List entities = new ArrayList<>(); - final ISdcCsarHelper sdcCsarHelper = parseCsar(csar); - final List lnodeVf = sdcCsarHelper.getServiceVfList(); - LOGGER.debug("the size of Vf = {}", lnodeVf.size()); - final ExtractFromNode extractFromNode = new ExtractFromNode(); - extractFromNode.setSdcCsarHelper(sdcCsarHelper); - final String serviceName = sdcCsarHelper.getServiceMetadata().getValue("name"); - LOGGER.debug("the name of the service = {}", serviceName); - for (final NodeTemplate node : lnodeVf) { - final Content content = extractFromNode.extractInfo(node); - if (content != null) { - final ToscaServiceTemplate entity = new ToscaServiceTemplate(); - Map props = new LinkedHashMap<>(); - props.put(TOSCA_POLICY_SCOPE, content.getScope()); - props.put(TOSCA_POLICY_SERVICES, content.getServices()); - props.put(TOSCA_POLICY_RESOURCES, content.getResources()); - props.put(TOSCA_POLICY_IDENTITY, content.getIdentity()); - props.put(TOSCA_POLICY_FLAVORFEATURES, content.getFlavorFeatures()); - ToscaPolicy policy = new ToscaPolicy(); - policy.setProperties(props); - Map map = new LinkedHashMap<>(); - String type = content.getPolicyType(); - map.put(type, policy); - List> policies = new ArrayList<>(); - policies.add(map); - ToscaTopologyTemplate topologyTemplate = new ToscaTopologyTemplate(); - topologyTemplate.setPolicies(policies); - entity.setToscaTopologyTemplate(topologyTemplate); - entities.add(entity); - } - } - return entities; - } - - @Override - public boolean canHandle(final PolicyInput policyInput) { - return Csar.class.isAssignableFrom(policyInput.getClass()); - } - - /** - * Parse the input Csar using SDC TOSCA parser. - * - * @param csar represents the service TOSCA Csar - * @return the object to represents the content of input csar - * @throws PolicyDecodingException if parse fails - */ - public ISdcCsarHelper parseCsar(final Csar csar) throws PolicyDecodingException { - ISdcCsarHelper sdcCsarHelper; - try { - final SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); - LOGGER.debug("Csar File Path = {}", csar.getCsarPath()); - final File csarFile = new File(csar.getCsarPath()); - sdcCsarHelper = factory.getSdcCsarHelper(csarFile.getAbsolutePath()); - } catch (final Exception exp) { - final String message = "Failed passing the csar file"; - LOGGER.error(message, exp); - throw new PolicyDecodingException(message, exp); - } - return sdcCsarHelper; - } - - @Override - public void configure(final String parameterGroupName) { - decoderParameters = ParameterService.get(parameterGroupName); - } -} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApiParameters.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApiParameters.java deleted file mode 100644 index a66a53a8..00000000 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApiParameters.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import lombok.Getter; - -import org.onap.policy.common.parameters.annotations.NotBlank; -import org.onap.policy.common.parameters.annotations.NotNull; -import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup; - -/** - * This class handles the parameters needed for {@link PolicyDecoderCsarPdpxLifecycleApi}. - */ -@Getter -@NotNull -@NotBlank -public class PolicyDecoderCsarPdpxLifecycleApiParameters extends PolicyDecoderConfigurationParameterGroup { - - private String policyNamePrefix; - private String onapName; - private String version; - private String priority; - private String riskType; - private String riskLevel; - - public PolicyDecoderCsarPdpxLifecycleApiParameters() { - super(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); - } -} - diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/CommonTestData.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/CommonTestData.java new file mode 100644 index 00000000..62a6ba4d --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/CommonTestData.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import java.io.File; + +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; + +/** + * Class to create parameters for test cases. + * + * @author Ram Krishna Verma (ram.krishna.verma@est.tech) + */ +public class CommonTestData { + + public static final Coder coder = new StandardCoder(); + + /** + * Returns PolicyDecoderParameters for test cases. + * + * @param fileName the file name to load the parameters + * @param clazz the parameter class to be returned + * @return the specific PolicyDecoderParameters object + */ + public static T getPolicyDecoderParameters(final String fileName, final Class clazz) { + final StandardCoder coder = new StandardCoder(); + try { + return coder.decode(new File(fileName), clazz); + } catch (final CoderException exp) { + throw new RuntimeException("cannot read/decode " + fileName, exp); + } + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestAttribute.java new file mode 100644 index 00000000..cf03ff30 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestAttribute.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.distribution.reception.decoding.hpa.Attribute; + +/** + * Class to perform unit test for Attribute 0f {@link Attribute}. + * + */ +public class TestAttribute { + + @Test + public void testAttribute() { + final String attributeName = "dummyName"; + final String attributeValue = "dummyValue"; + + final Attribute attribute = new Attribute(); + attribute.setAttributeName(attributeName); + attribute.setAttributeValue(attributeValue); + + validateReport(attributeName, attributeValue, attribute); + } + + private void validateReport(final String name, final String value, final Attribute attribute) { + assertEquals(name, attribute.getAttributeName()); + assertEquals(value, attribute.getAttributeValue()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestContent.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestContent.java new file mode 100644 index 00000000..3770bc77 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestContent.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.distribution.reception.decoding.hpa.Content; +import org.onap.policy.distribution.reception.decoding.hpa.FlavorFeature; + +/** + * Class to perform unit test for Content 0f {@link Content}. + * + */ +public class TestContent { + + @Test + public void testContent() { + final String identity = "dummyidentity"; + final String policyType = "optimization"; + + final Content content = new Content(); + content.setIdentity(identity); + content.setPolicyType(policyType); + + validateReport(identity, policyType, content); + } + + private void validateReport(final String identity, final String policyType, + final Content content) { + assertEquals(0, content.getScope().size()); + assertEquals(0, content.getGeography().size()); + assertEquals(identity, content.getIdentity()); + assertEquals(policyType, content.getPolicyType()); + assertEquals(0, content.getPolicyScope().size()); + content.getPolicyScope().add("vFW"); + assertEquals(1, content.getPolicyScope().size()); + content.getPolicyScope().remove("vFW"); + assertEquals(0, content.getPolicyScope().size()); + assertEquals(0, content.getServices().size()); + content.getServices().add("vCPE"); + assertEquals(1, content.getServices().size()); + content.getServices().remove("vCPE"); + assertEquals(0, content.getServices().size()); + assertEquals(0, content.getFlavorFeatures().size()); + FlavorFeature flavorFeature = new FlavorFeature(); + content.getFlavorFeatures().add(flavorFeature); + assertEquals(1, content.getFlavorFeatures().size()); + content.getFlavorFeatures().remove(flavorFeature); + assertEquals(0, content.getFlavorFeatures().size()); + assertEquals(0, content.getResources().size()); + content.getResources().add("vGW"); + assertEquals(1, content.getResources().size()); + content.getResources().remove("vGW"); + assertEquals(0, content.getResources().size()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestDirective.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestDirective.java new file mode 100644 index 00000000..9ab53931 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestDirective.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.distribution.reception.decoding.hpa.Attribute; +import org.onap.policy.distribution.reception.decoding.hpa.Directive; + +/** + * Class to perform unit test for Directive 0f {@link Directive}. + * + */ +public class TestDirective { + + @Test + public void testDirective() { + final String type = "dummytype"; + + final Directive directive = new Directive(); + directive.setType(type); + + validateReport(type, directive); + } + + private void validateReport(final String type, final Directive directive) { + assertEquals(type, directive.getType()); + assertEquals(0, directive.getAttributes().size()); + Attribute attribute = new Attribute(); + directive.getAttributes().add(attribute); + assertEquals(1, directive.getAttributes().size()); + directive.getAttributes().remove(attribute); + assertEquals(0, directive.getAttributes().size()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestFlavorFeature.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestFlavorFeature.java new file mode 100644 index 00000000..47b74c71 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestFlavorFeature.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.distribution.reception.decoding.hpa.Directive; +import org.onap.policy.distribution.reception.decoding.hpa.FlavorFeature; +import org.onap.policy.distribution.reception.decoding.hpa.FlavorProperty; + +/** + * Class to perform unit test for FlavorFeature 0f {@link FlavorFeature}. + * + */ +public class TestFlavorFeature { + + @Test + public void testFlavorFeature() { + final String id = "dummyid"; + final String type = "dummytype"; + + final FlavorFeature flavorFeature = new FlavorFeature(); + flavorFeature.setId(id); + flavorFeature.setType(type); + + validateReport(id, type, flavorFeature); + } + + private void validateReport(final String id, final String type, final FlavorFeature flavorFeature) { + assertEquals(id, flavorFeature.getId()); + assertEquals(type, flavorFeature.getType()); + + assertEquals(0, flavorFeature.getDirectives().size()); + Directive directive = new Directive(); + flavorFeature.getDirectives().add(directive); + assertEquals(1, flavorFeature.getDirectives().size()); + flavorFeature.getDirectives().remove(directive); + assertEquals(0, flavorFeature.getDirectives().size()); + + assertEquals(0, flavorFeature.getFlavorProperties().size()); + FlavorProperty flavorProperty = new FlavorProperty(); + flavorFeature.getFlavorProperties().add(flavorProperty); + assertEquals(1, flavorFeature.getFlavorProperties().size()); + flavorFeature.getFlavorProperties().remove(flavorProperty); + assertEquals(0, flavorFeature.getFlavorProperties().size()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestFlavorProperty.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestFlavorProperty.java new file mode 100644 index 00000000..2d0504da --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestFlavorProperty.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.distribution.reception.decoding.hpa.Directive; +import org.onap.policy.distribution.reception.decoding.hpa.FlavorProperty; +import org.onap.policy.distribution.reception.decoding.hpa.HpaFeatureAttribute; + +/** + * Class to perform unit test for FlavorProperty 0f {@link FlavorProperty}. + * + */ +public class TestFlavorProperty { + + @Test + public void testFlavorProperty() { + final String hpaFeature = "dummyid"; + final String mandatory = "false"; + final String architecture = "generic"; + final String hpaVersion = "v1"; + + final FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(hpaFeature); + flavorProperty.setMandatory(mandatory); + flavorProperty.setArchitecture(architecture); + flavorProperty.setHpaVersion(hpaVersion); + + validateReport(hpaFeature, mandatory, architecture, hpaVersion, flavorProperty); + } + + private void validateReport(final String hpaFeature, final String mandatory, final String architecture, + final String hpaVersion, final FlavorProperty flavorProperty) { + assertEquals(hpaFeature, flavorProperty.getHpaFeature()); + assertEquals(mandatory, flavorProperty.getMandatory()); + assertEquals(architecture, flavorProperty.getArchitecture()); + assertEquals(hpaVersion, flavorProperty.getHpaVersion()); + + assertEquals(0, flavorProperty.getDirectives().size()); + Directive directive = new Directive(); + flavorProperty.getDirectives().add(directive); + assertEquals(1, flavorProperty.getDirectives().size()); + flavorProperty.getDirectives().remove(directive); + assertEquals(0, flavorProperty.getDirectives().size()); + + assertEquals(0, flavorProperty.getHpaFeatureAttributes().size()); + HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); + flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); + assertEquals(1, flavorProperty.getHpaFeatureAttributes().size()); + flavorProperty.getHpaFeatureAttributes().remove(hpaFeatureAttribute); + assertEquals(0, flavorProperty.getHpaFeatureAttributes().size()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestHpaFeatureAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestHpaFeatureAttribute.java new file mode 100644 index 00000000..fddeb168 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestHpaFeatureAttribute.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.distribution.reception.decoding.hpa.HpaFeatureAttribute; + +/** + * Class to perform unit test for HpaFeatureAttribute 0f {@link HpaFeatureAttribute}. + * + */ +public class TestHpaFeatureAttribute { + + @Test + public void testHpaFeatureAttribute() { + final String hpaAttributeKey = "dummykey"; + final String hpaAttributeValue = "4096"; + final String operator = ">="; + final String unit = "MB"; + + final HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); + hpaFeatureAttribute.setHpaAttributeKey(hpaAttributeKey); + hpaFeatureAttribute.setHpaAttributeValue(hpaAttributeValue); + hpaFeatureAttribute.setOperator(operator); + hpaFeatureAttribute.setUnit(unit); + + validateReport(hpaAttributeKey, hpaAttributeValue, operator, unit, hpaFeatureAttribute); + } + + private void validateReport(final String hpaAttributeKey, final String hpaAttributeValue, final String operator, + final String unit, final HpaFeatureAttribute hpaFeatureAttribute) { + assertEquals(hpaAttributeKey, hpaFeatureAttribute.getHpaAttributeKey()); + assertEquals(hpaAttributeValue, hpaFeatureAttribute.getHpaAttributeValue()); + assertEquals(operator, hpaFeatureAttribute.getOperator()); + assertEquals(unit, hpaFeatureAttribute.getUnit()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestPolicyDecoderCsarHpa.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestPolicyDecoderCsarHpa.java new file mode 100644 index 00000000..552f430e --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestPolicyDecoderCsarHpa.java @@ -0,0 +1,267 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.decoding.hpa; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.Collection; +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.models.tosca.authorative.concepts.ToscaPolicy; +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 PolicyDecoderCsarHpa}. + */ +public class TestPolicyDecoderCsarHpa { + + private final StandardCoder encoder = new StandardCoder(); + + /** + * Set up for test cases. + */ + @BeforeClass + public static void setUp() { + final ParameterGroup parameterGroup = CommonTestData.getPolicyDecoderParameters( + "src/test/resources/parameters/HpaPolicyDecoderParameters.json", + PolicyDecoderCsarHpaParameters.class); + parameterGroup.setName(PolicyDecoderCsarHpaParameters.class.getSimpleName()); + ParameterService.register(parameterGroup); + } + + /** + * Tear down. + */ + @AfterClass + public static void tearDown() { + ParameterService.deregister(PolicyDecoderCsarHpaParameters.class.getSimpleName()); + } + + @Test + public void testHpaPolicy2Vnf() throws IOException, PolicyDecodingException, CoderException { + final Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar"); + final PolicyDecoderCsarHpa policyDecoderCsarHpa = new PolicyDecoderCsarHpa(); + policyDecoderCsarHpa.configure(PolicyDecoderCsarHpaParameters.class.getSimpleName()); + + final Collection entities = policyDecoderCsarHpa.decode(csar); + + assertEquals(2, entities.size()); + final ToscaServiceTemplate entity = entities.iterator().next(); + ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); + Map map = topologyTemplate.getPolicies().get(0); + ToscaPolicy policy = map.get(PolicyDecoderCsarHpa.TOSCA_POLICY_HPA_OOF); + Map props = policy.getProperties(); + Object flavorFeatures = + props.get(PolicyDecoderCsarHpa.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, CoderException { + final Csar csar = new Csar("src/test/resources/hpaPolicySriov.csar"); + final PolicyDecoderCsarHpa policyDecoderCsarHpa = new PolicyDecoderCsarHpa(); + policyDecoderCsarHpa.configure(PolicyDecoderCsarHpaParameters.class.getSimpleName()); + + final Collection entities = policyDecoderCsarHpa.decode(csar); + final ToscaServiceTemplate entity = entities.iterator().next(); + ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); + Map map = topologyTemplate.getPolicies().get(0); + ToscaPolicy policy = map.get(PolicyDecoderCsarHpa.TOSCA_POLICY_HPA_OOF); + Map props = policy.getProperties(); + Object flavorFeatures = + props.get(PolicyDecoderCsarHpa.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, CoderException { + final Csar csar = new Csar("src/test/resources/hpaPolicyPciePassthrough.csar"); + final PolicyDecoderCsarHpa policyDecoderCsarHpa = new PolicyDecoderCsarHpa(); + policyDecoderCsarHpa.configure(PolicyDecoderCsarHpaParameters.class.getSimpleName()); + + final Collection entities = policyDecoderCsarHpa.decode(csar); + assertEquals(2, entities.size()); + final ToscaServiceTemplate entity = entities.iterator().next(); + ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); + Map map = topologyTemplate.getPolicies().get(0); + ToscaPolicy policy = map.get(PolicyDecoderCsarHpa.TOSCA_POLICY_HPA_OOF); + Map props = policy.getProperties(); + Object flavorFeatures = + props.get(PolicyDecoderCsarHpa.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, CoderException { + final Csar csar = new Csar("src/test/resources/hpaPolicyHugePage.csar"); + final PolicyDecoderCsarHpa policyDecoderCsarHpa = new PolicyDecoderCsarHpa(); + policyDecoderCsarHpa.configure(PolicyDecoderCsarHpaParameters.class.getSimpleName()); + + final Collection entities = policyDecoderCsarHpa.decode(csar); + assertEquals(2, entities.size()); + final ToscaServiceTemplate entity = entities.iterator().next(); + ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); + Map map = topologyTemplate.getPolicies().get(0); + ToscaPolicy policy = map.get(PolicyDecoderCsarHpa.TOSCA_POLICY_HPA_OOF); + Map props = policy.getProperties(); + Object flavorFeatures = + props.get(PolicyDecoderCsarHpa.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, CoderException { + final Csar csar = new Csar("src/test/resources/s3p_0_pciVendorId.csar"); + final PolicyDecoderCsarHpa policyDecoderCsarHpa = new PolicyDecoderCsarHpa(); + policyDecoderCsarHpa.configure(PolicyDecoderCsarHpaParameters.class.getSimpleName()); + + final Collection entities = policyDecoderCsarHpa.decode(csar); + assertEquals(1, entities.size()); + final ToscaServiceTemplate entity = entities.iterator().next(); + ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); + Map map = topologyTemplate.getPolicies().get(0); + ToscaPolicy policy = map.get(PolicyDecoderCsarHpa.TOSCA_POLICY_HPA_OOF); + Map props = policy.getProperties(); + Object flavorFeatures = + props.get(PolicyDecoderCsarHpa.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, CoderException { + final Csar csar = new Csar("src/test/resources/service-VcpeWithAll-csar.csar"); + final PolicyDecoderCsarHpa policyDecoderCsarHpa = new PolicyDecoderCsarHpa(); + policyDecoderCsarHpa.configure(PolicyDecoderCsarHpaParameters.class.getSimpleName()); + + final Collection entities = policyDecoderCsarHpa.decode(csar); + assertEquals(5, entities.size()); + final ToscaServiceTemplate entity = entities.iterator().next(); + ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); + Map map = topologyTemplate.getPolicies().get(0); + ToscaPolicy policy = map.get(PolicyDecoderCsarHpa.TOSCA_POLICY_HPA_OOF); + Map props = policy.getProperties(); + Object flavorFeatures = + props.get(PolicyDecoderCsarHpa.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\":\"\"")); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestPolicyDecoderCsarHpaParameters.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestPolicyDecoderCsarHpaParameters.java new file mode 100644 index 00000000..1ca9e1a1 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/hpa/TestPolicyDecoderCsarHpaParameters.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.hpa; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.common.parameters.ValidationStatus; + +/** + * Class to perform unit test of {@link PolicyDecoderCsarHpaParameters}. + */ +public class TestPolicyDecoderCsarHpaParameters { + + @Test + public void testValidParameters() { + final PolicyDecoderCsarHpaParameters parameterGroup = CommonTestData.getPolicyDecoderParameters( + "src/test/resources/parameters/HpaPolicyDecoderParameters.json", + PolicyDecoderCsarHpaParameters.class); + + assertEquals(PolicyDecoderCsarHpaParameters.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 PolicyDecoderCsarHpaParameters parameterGroup = CommonTestData.getPolicyDecoderParameters( + "src/test/resources/parameters/HpaPolicyDecoderParametersInvalid.json", + PolicyDecoderCsarHpaParameters.class); + + assertEquals(ValidationStatus.INVALID, parameterGroup.validate().getStatus()); + } + + @Test + public void testEmptyParameters() { + final PolicyDecoderCsarHpaParameters configurationParameters = + CommonTestData.getPolicyDecoderParameters("src/test/resources/parameters/EmptyParameters.json", + PolicyDecoderCsarHpaParameters.class); + + assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/CommonTestData.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/CommonTestData.java deleted file mode 100644 index 5006e078..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/CommonTestData.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import java.io.File; - -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; - -/** - * Class to create parameters for test cases. - * - * @author Ram Krishna Verma (ram.krishna.verma@est.tech) - */ -public class CommonTestData { - - public static final Coder coder = new StandardCoder(); - - /** - * Returns PolicyDecoderParameters for test cases. - * - * @param fileName the file name to load the parameters - * @param clazz the parameter class to be returned - * @return the specific PolicyDecoderParameters object - */ - public static T getPolicyDecoderParameters(final String fileName, final Class clazz) { - final StandardCoder coder = new StandardCoder(); - try { - return coder.decode(new File(fileName), clazz); - } catch (final CoderException exp) { - throw new RuntimeException("cannot read/decode " + fileName, exp); - } - } -} 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 deleted file mode 100644 index 565f17d3..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestAttribute.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Class to perform unit test for Attribute 0f {@link Attribute}. - * - */ -public class TestAttribute { - - @Test - public void testAttribute() { - final String attributeName = "dummyName"; - final String attributeValue = "dummyValue"; - - final Attribute attribute = new Attribute(); - attribute.setAttributeName(attributeName); - attribute.setAttributeValue(attributeValue); - - validateReport(attributeName, attributeValue, attribute); - } - - private void validateReport(final String name, final String value, final Attribute attribute) { - assertEquals(name, attribute.getAttributeName()); - assertEquals(value, attribute.getAttributeValue()); - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java deleted file mode 100644 index da77eefb..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Class to perform unit test for Content 0f {@link Content}. - * - */ -public class TestContent { - - @Test - public void testContent() { - final String identity = "dummyidentity"; - final String policyType = "optimization"; - - final Content content = new Content(); - content.setIdentity(identity); - content.setPolicyType(policyType); - - validateReport(identity, policyType, content); - } - - private void validateReport(final String identity, final String policyType, - final Content content) { - assertEquals(0, content.getScope().size()); - assertEquals(0, content.getGeography().size()); - assertEquals(identity, content.getIdentity()); - assertEquals(policyType, content.getPolicyType()); - assertEquals(0, content.getPolicyScope().size()); - content.getPolicyScope().add("vFW"); - assertEquals(1, content.getPolicyScope().size()); - content.getPolicyScope().remove("vFW"); - assertEquals(0, content.getPolicyScope().size()); - assertEquals(0, content.getServices().size()); - content.getServices().add("vCPE"); - assertEquals(1, content.getServices().size()); - content.getServices().remove("vCPE"); - assertEquals(0, content.getServices().size()); - assertEquals(0, content.getFlavorFeatures().size()); - FlavorFeature flavorFeature = new FlavorFeature(); - content.getFlavorFeatures().add(flavorFeature); - assertEquals(1, content.getFlavorFeatures().size()); - content.getFlavorFeatures().remove(flavorFeature); - assertEquals(0, content.getFlavorFeatures().size()); - assertEquals(0, content.getResources().size()); - content.getResources().add("vGW"); - assertEquals(1, content.getResources().size()); - content.getResources().remove("vGW"); - assertEquals(0, content.getResources().size()); - } -} 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 deleted file mode 100644 index cc8d946f..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestDirective.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Class to perform unit test for Directive 0f {@link Directive}. - * - */ -public class TestDirective { - - @Test - public void testDirective() { - final String type = "dummytype"; - - final Directive directive = new Directive(); - directive.setType(type); - - validateReport(type, directive); - } - - private void validateReport(final String type, final Directive directive) { - assertEquals(type, directive.getType()); - assertEquals(0, directive.getAttributes().size()); - Attribute attribute = new Attribute(); - directive.getAttributes().add(attribute); - assertEquals(1, directive.getAttributes().size()); - directive.getAttributes().remove(attribute); - assertEquals(0, directive.getAttributes().size()); - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java deleted file mode 100644 index e4de2759..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Class to perform unit test for FlavorFeature 0f {@link FlavorFeature}. - * - */ -public class TestFlavorFeature { - - @Test - public void testFlavorFeature() { - final String id = "dummyid"; - final String type = "dummytype"; - - final FlavorFeature flavorFeature = new FlavorFeature(); - flavorFeature.setId(id); - flavorFeature.setType(type); - - validateReport(id, type, flavorFeature); - } - - private void validateReport(final String id, final String type, final FlavorFeature flavorFeature) { - assertEquals(id, flavorFeature.getId()); - assertEquals(type, flavorFeature.getType()); - - assertEquals(0, flavorFeature.getDirectives().size()); - Directive directive = new Directive(); - flavorFeature.getDirectives().add(directive); - assertEquals(1, flavorFeature.getDirectives().size()); - flavorFeature.getDirectives().remove(directive); - assertEquals(0, flavorFeature.getDirectives().size()); - - assertEquals(0, flavorFeature.getFlavorProperties().size()); - FlavorProperty flavorProperty = new FlavorProperty(); - flavorFeature.getFlavorProperties().add(flavorProperty); - assertEquals(1, flavorFeature.getFlavorProperties().size()); - flavorFeature.getFlavorProperties().remove(flavorProperty); - assertEquals(0, flavorFeature.getFlavorProperties().size()); - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java deleted file mode 100644 index da6c26fc..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Class to perform unit test for FlavorProperty 0f {@link FlavorProperty}. - * - */ -public class TestFlavorProperty { - - @Test - public void testFlavorProperty() { - final String hpaFeature = "dummyid"; - final String mandatory = "false"; - final String architecture = "generic"; - final String hpaVersion = "v1"; - - final FlavorProperty flavorProperty = new FlavorProperty(); - flavorProperty.setHpaFeature(hpaFeature); - flavorProperty.setMandatory(mandatory); - flavorProperty.setArchitecture(architecture); - flavorProperty.setHpaVersion(hpaVersion); - - validateReport(hpaFeature, mandatory, architecture, hpaVersion, flavorProperty); - } - - private void validateReport(final String hpaFeature, final String mandatory, final String architecture, - final String hpaVersion, final FlavorProperty flavorProperty) { - assertEquals(hpaFeature, flavorProperty.getHpaFeature()); - assertEquals(mandatory, flavorProperty.getMandatory()); - assertEquals(architecture, flavorProperty.getArchitecture()); - assertEquals(hpaVersion, flavorProperty.getHpaVersion()); - - assertEquals(0, flavorProperty.getDirectives().size()); - Directive directive = new Directive(); - flavorProperty.getDirectives().add(directive); - assertEquals(1, flavorProperty.getDirectives().size()); - flavorProperty.getDirectives().remove(directive); - assertEquals(0, flavorProperty.getDirectives().size()); - - assertEquals(0, flavorProperty.getHpaFeatureAttributes().size()); - HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); - flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); - assertEquals(1, flavorProperty.getHpaFeatureAttributes().size()); - flavorProperty.getHpaFeatureAttributes().remove(hpaFeatureAttribute); - assertEquals(0, flavorProperty.getHpaFeatureAttributes().size()); - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java deleted file mode 100644 index f2f514d0..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Class to perform unit test for HpaFeatureAttribute 0f {@link HpaFeatureAttribute}. - * - */ -public class TestHpaFeatureAttribute { - - @Test - public void testHpaFeatureAttribute() { - final String hpaAttributeKey = "dummykey"; - final String hpaAttributeValue = "4096"; - final String operator = ">="; - final String unit = "MB"; - - final HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); - hpaFeatureAttribute.setHpaAttributeKey(hpaAttributeKey); - hpaFeatureAttribute.setHpaAttributeValue(hpaAttributeValue); - hpaFeatureAttribute.setOperator(operator); - hpaFeatureAttribute.setUnit(unit); - - validateReport(hpaAttributeKey, hpaAttributeValue, operator, unit, hpaFeatureAttribute); - } - - private void validateReport(final String hpaAttributeKey, final String hpaAttributeValue, final String operator, - final String unit, final HpaFeatureAttribute hpaFeatureAttribute) { - assertEquals(hpaAttributeKey, hpaFeatureAttribute.getHpaAttributeKey()); - assertEquals(hpaAttributeValue, hpaFeatureAttribute.getHpaAttributeValue()); - assertEquals(operator, hpaFeatureAttribute.getOperator()); - assertEquals(unit, hpaFeatureAttribute.getUnit()); - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java deleted file mode 100644 index 0eac8bf6..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java +++ /dev/null @@ -1,278 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -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.model.OptimizationPolicy; -import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; - -/** - * Class to perform unit test of {@link PolicyDecoderCsarPdpx}. - * - */ -public class TestPolicyDecoderCsarPdpx { - - /** - * Set up for test cases. - */ - @BeforeClass - public static void setUp() { - final ParameterGroup parameterGroup = CommonTestData.getPolicyDecoderParameters( - "src/test/resources/parameters/PdpxPolicyDecoderParameters.json", - PolicyDecoderCsarPdpxConfigurationParameterGroup.class); - parameterGroup.setName(PolicyDecoderCsarPdpxConfigurationParameterGroup.class.getSimpleName()); - ParameterService.register(parameterGroup); - } - - /** - * Tear down. - */ - @AfterClass - public static void tearDown() { - ParameterService.deregister(PolicyDecoderCsarPdpxConfigurationParameterGroup.class.getSimpleName()); - } - - @Test - public void testHpaPolicy2Vnf() throws IOException, PolicyDecodingException { - final Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar"); - final PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); - policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxConfigurationParameterGroup.class.getSimpleName()); - - final Collection ret = policyDecoderCsarPdpx.decode(csar); - - assertEquals(2, ret.size()); - final OptimizationPolicy policy = (OptimizationPolicy) ret.toArray()[0]; - - assertEquals("onapName", policy.getOnapName()); - assertTrue(policy.getName().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\":\"hpa\"")); - - assertTrue(policy.getConfigBody().contains("\"id\":\"VDU_vgw_0\"")); - assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); - assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directives\"")); - 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 { - final Csar csar = new Csar("src/test/resources/hpaPolicySriov.csar"); - final PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); - policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxConfigurationParameterGroup.class.getSimpleName()); - - final Collection policies = policyDecoderCsarPdpx.decode(csar); - final OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; - - assertEquals("onapName", policy.getOnapName()); - assertTrue(policy.getName().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\":\"hpa\"")); - - assertTrue(policy.getConfigBody().contains("\"id\":\"VDU_vgw_0\"")); - assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); - assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directives\"")); - 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 testHpaPolicyPciePassthrough() throws IOException, PolicyDecodingException { - final Csar csar = new Csar("src/test/resources/hpaPolicyPciePassthrough.csar"); - final PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); - policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxConfigurationParameterGroup.class.getSimpleName()); - - final Collection policies = policyDecoderCsarPdpx.decode(csar); - assertEquals(2, policies.size()); - final OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; - - assertEquals("onapName", policy.getOnapName()); - assertTrue(policy.getName().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\":\"hpa\"")); - - assertTrue(policy.getConfigBody().contains("\"id\":\"VDU_vgw_0\"")); - assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); - assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directives\"")); - 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 { - final Csar csar = new Csar("src/test/resources/hpaPolicyHugePage.csar"); - final PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); - policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxConfigurationParameterGroup.class.getSimpleName()); - - final Collection policies = policyDecoderCsarPdpx.decode(csar); - assertEquals(2, policies.size()); - final OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; - - assertEquals("onapName", policy.getOnapName()); - assertTrue(policy.getName().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\":\"hpa\"")); - - assertTrue(policy.getConfigBody().contains("\"id\":\"VDU_vgw_0\"")); - assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); - assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directives\"")); - 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\":\"true\"")); - 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\"")); - } - - @Test - public void testS3p0PciVendorId() throws IOException, PolicyDecodingException { - final Csar csar = new Csar("src/test/resources/s3p_0_pciVendorId.csar"); - final PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); - policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxConfigurationParameterGroup.class.getSimpleName()); - - final Collection policies = policyDecoderCsarPdpx.decode(csar); - assertEquals(1, policies.size()); - final OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; - - assertEquals("onapName", policy.getOnapName()); - assertTrue(policy.getName().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\":\"hpa\"")); - - assertTrue(policy.getConfigBody().contains("\"id\":\"VDU_vgw_0\"")); - assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); - assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directives\"")); - 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\":\"\"")); - - } - - @Test - public void testserviceVcpeWithAll() throws IOException, PolicyDecodingException { - final Csar csar = new Csar("src/test/resources/service-VcpeWithAll-csar.csar"); - final PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); - policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxConfigurationParameterGroup.class.getSimpleName()); - - final Collection policies = policyDecoderCsarPdpx.decode(csar); - assertEquals(5, policies.size()); - final OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; - - assertEquals("onapName", policy.getOnapName()); - assertTrue(policy.getName().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\":\"hpa\"")); - - assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); - assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directives\"")); - 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\":\"\"")); - - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxConfigurationParameterGroup.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxConfigurationParameterGroup.java deleted file mode 100644 index d0de432a..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxConfigurationParameterGroup.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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 static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.onap.policy.common.parameters.ValidationStatus; - -/** - * Class to perform unit test of {@link PolicyDecoderCsarPdpxConfigurationParameterGroup}. - * - * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) - */ -public class TestPolicyDecoderCsarPdpxConfigurationParameterGroup { - - @Test - public void testValidParameters() { - final PolicyDecoderCsarPdpxConfigurationParameterGroup parameterGroup = CommonTestData - .getPolicyDecoderParameters("src/test/resources/parameters/PdpxPolicyDecoderParameters.json", - PolicyDecoderCsarPdpxConfigurationParameterGroup.class); - - assertEquals(PolicyDecoderCsarPdpxConfigurationParameterGroup.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 PolicyDecoderCsarPdpxConfigurationParameterGroup parameterGroup = CommonTestData - .getPolicyDecoderParameters("src/test/resources/parameters/PdpxPolicyDecoderParametersInvalid.json", - PolicyDecoderCsarPdpxConfigurationParameterGroup.class); - - assertEquals(ValidationStatus.INVALID, parameterGroup.validate().getStatus()); - } - - @Test - public void testEmptyParameters() { - final PolicyDecoderCsarPdpxConfigurationParameterGroup configurationParameters = - CommonTestData.getPolicyDecoderParameters("src/test/resources/parameters/EmptyParameters.json", - PolicyDecoderCsarPdpxConfigurationParameterGroup.class); - - assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus()); - } -} 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 deleted file mode 100644 index 3b8339a9..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApi.java +++ /dev/null @@ -1,270 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.lang.String; -import java.util.Collection; -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.PolicyDecoderCsarPdpxLifecycleApi; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; - -/** - * Class to perform unit test of {@link PolicyDecoderCsarPdpxLifecycleApiLifecycleApi}. - */ -public class TestPolicyDecoderCsarPdpxLifecycleApi { - - private final StandardCoder encoder = new StandardCoder(); - - /** - * 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, CoderException { - final Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar"); - final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi(); - policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); - - final Collection entities = policyDecoderCsarPdpx.decode(csar); - - assertEquals(2, entities.size()); - final ToscaServiceTemplate entity = entities.iterator().next(); - ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); - Map map = topologyTemplate.getPolicies().get(0); - ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF); - Map 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, CoderException { - final Csar csar = new Csar("src/test/resources/hpaPolicySriov.csar"); - final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi(); - policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); - - final Collection entities = policyDecoderCsarPdpx.decode(csar); - final ToscaServiceTemplate entity = entities.iterator().next(); - ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); - Map map = topologyTemplate.getPolicies().get(0); - ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF); - Map 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, CoderException { - final Csar csar = new Csar("src/test/resources/hpaPolicyPciePassthrough.csar"); - final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi(); - policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); - - final Collection entities = policyDecoderCsarPdpx.decode(csar); - assertEquals(2, entities.size()); - final ToscaServiceTemplate entity = entities.iterator().next(); - ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); - Map map = topologyTemplate.getPolicies().get(0); - ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF); - Map 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, CoderException { - final Csar csar = new Csar("src/test/resources/hpaPolicyHugePage.csar"); - final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi(); - policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); - - final Collection entities = policyDecoderCsarPdpx.decode(csar); - assertEquals(2, entities.size()); - final ToscaServiceTemplate entity = entities.iterator().next(); - ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); - Map map = topologyTemplate.getPolicies().get(0); - ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF); - Map 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, 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 entities = policyDecoderCsarPdpx.decode(csar); - assertEquals(1, entities.size()); - final ToscaServiceTemplate entity = entities.iterator().next(); - ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); - Map map = topologyTemplate.getPolicies().get(0); - ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF); - Map 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, 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 entities = policyDecoderCsarPdpx.decode(csar); - assertEquals(5, entities.size()); - final ToscaServiceTemplate entity = entities.iterator().next(); - ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); - Map map = topologyTemplate.getPolicies().get(0); - ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF); - Map 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\":\"\"")); - } -} 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 deleted file mode 100644 index 47971ad3..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApiParameters.java +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.reception.decoding.pdpx; - -import 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/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java index 56ddc406..c3e69037 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java @@ -25,7 +25,7 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; import org.onap.policy.common.parameters.ValidationStatus; -import org.onap.policy.distribution.reception.decoding.pdpx.CommonTestData; +import org.onap.policy.distribution.reception.decoding.hpa.CommonTestData; /** * Class to perform unit test of {@link PolicyDecoderFileInCsarToPolicyParameterGroup}. diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java index 451e4f1b..d619671f 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java @@ -37,7 +37,7 @@ import org.mockito.runners.MockitoJUnitRunner; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.distribution.model.Csar; -import org.onap.policy.distribution.reception.decoding.pdpx.CommonTestData; +import org.onap.policy.distribution.reception.decoding.hpa.CommonTestData; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; /** diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java index 30bcdf11..f5845de8 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java @@ -36,7 +36,7 @@ import java.util.Arrays; import org.junit.Test; import org.onap.policy.common.parameters.GroupValidationResult; import org.onap.policy.common.parameters.ValidationStatus; -import org.onap.policy.distribution.reception.decoding.pdpx.CommonTestData; +import org.onap.policy.distribution.reception.decoding.hpa.CommonTestData; /** * Class to perform unit test of {@link SdcConfiguration}. diff --git a/plugins/reception-plugins/src/test/resources/parameters/HpaPolicyDecoderParameters.json b/plugins/reception-plugins/src/test/resources/parameters/HpaPolicyDecoderParameters.json new file mode 100644 index 00000000..9f686632 --- /dev/null +++ b/plugins/reception-plugins/src/test/resources/parameters/HpaPolicyDecoderParameters.json @@ -0,0 +1,8 @@ +{ + "policyNamePrefix": "OOF", + "onapName": "onapName", + "version": "1.0", + "priority": "5", + "riskType": "Test", + "riskLevel": "2" +} \ No newline at end of file diff --git a/plugins/reception-plugins/src/test/resources/parameters/HpaPolicyDecoderParametersInvalid.json b/plugins/reception-plugins/src/test/resources/parameters/HpaPolicyDecoderParametersInvalid.json new file mode 100644 index 00000000..a716452e --- /dev/null +++ b/plugins/reception-plugins/src/test/resources/parameters/HpaPolicyDecoderParametersInvalid.json @@ -0,0 +1,8 @@ +{ + "policyNamePrefix": "", + "onapName": "", + "version": "", + "priority": "", + "riskType": "", + "riskLevel": "" +} \ No newline at end of file diff --git a/plugins/reception-plugins/src/test/resources/parameters/PdpxPolicyDecoderParameters.json b/plugins/reception-plugins/src/test/resources/parameters/PdpxPolicyDecoderParameters.json deleted file mode 100644 index 9f686632..00000000 --- a/plugins/reception-plugins/src/test/resources/parameters/PdpxPolicyDecoderParameters.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "policyNamePrefix": "OOF", - "onapName": "onapName", - "version": "1.0", - "priority": "5", - "riskType": "Test", - "riskLevel": "2" -} \ No newline at end of file diff --git a/plugins/reception-plugins/src/test/resources/parameters/PdpxPolicyDecoderParametersInvalid.json b/plugins/reception-plugins/src/test/resources/parameters/PdpxPolicyDecoderParametersInvalid.json deleted file mode 100644 index a716452e..00000000 --- a/plugins/reception-plugins/src/test/resources/parameters/PdpxPolicyDecoderParametersInvalid.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "policyNamePrefix": "", - "onapName": "", - "version": "", - "priority": "", - "riskType": "", - "riskLevel": "" -} \ No newline at end of file -- cgit 1.2.3-korg