From 8fdf84c7f2bd03332e69d13e35414020053c2977 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Fri, 15 Mar 2019 12:36:38 +0000 Subject: Add serialization for Tosca Model Added tests for Yaml policy monitoring Added provider interface calls in provider and structure for handling legacy APIs. Issue-ID: POLICY-1195 Change-Id: I4825272e0713b9e6a4b89753828de8905bcffbd1 Signed-off-by: liamfallon --- .../models/provider/PolicyModelsProvider.java | 85 ++++++++++- .../provider/PolicyModelsProviderFactory.java | 4 +- .../impl/DatabasePolicyModelsProviderImpl.java | 144 ++++++++++++++++++ .../impl/DummyPolicyModelsProviderImpl.java | 168 +++++++++++++++++++++ .../provider/impl/PolicyModelsProviderImpl.java | 98 ------------ .../dummyimpl/DummyToscaPolicyDeleteResponse.json | 48 ++++++ .../dummyimpl/DummyToscaPolicyGetResponse.json | 48 ++++++ .../DummyToscaPolicyTypeDeleteResponse.json | 48 ++++++ .../dummyimpl/DummyToscaPolicyTypeGetResponse.json | 48 ++++++ .../impl/DummyPolicyModelsProviderTest.java | 49 ++++++ 10 files changed, 636 insertions(+), 104 deletions(-) create mode 100644 models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java create mode 100644 models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java delete mode 100644 models-provider/src/main/java/org/onap/policy/models/provider/impl/PolicyModelsProviderImpl.java create mode 100644 models-provider/src/main/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json create mode 100644 models-provider/src/main/resources/dummyimpl/DummyToscaPolicyGetResponse.json create mode 100644 models-provider/src/main/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json create mode 100644 models-provider/src/main/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json create mode 100644 models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java (limited to 'models-provider') diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java index 0144f8c68..fbdf092c2 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java @@ -24,8 +24,9 @@ import lombok.NonNull; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.base.PfReferenceKey; import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.serialization.legacy.LegacyGuardPolicy; +import org.onap.policy.models.tosca.serialization.legacy.LegacyOperationalPolicy; /** * This interface describes the operations that are provided to users and components for reading @@ -86,7 +87,7 @@ public interface PolicyModelsProvider { * @return the policies found * @throws PfModelException on errors getting policies */ - public ToscaServiceTemplate getPolicies(@NonNull final PfReferenceKey policyKey) throws PfModelException; + public ToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException; /** * Create policies. @@ -118,7 +119,83 @@ public interface PolicyModelsProvider { * @return the TOSCA service template containing the policy types that were deleted * @throws PfModelException on errors deleting policies */ - public ToscaServiceTemplate deletePolicies(@NonNull final PfReferenceKey policyKey) throws PfModelException; + public ToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException; + + /** + * Get legacy operational policy. + * + * @param policyId ID of the policy. + * @return the policies found + * @throws PfModelException on errors getting policies + */ + public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException; + + /** + * Create legacy operational policy. + * + * @param legacyOperationalPolicy the definition of the policy to be created. + * @return the created policy + * @throws PfModelException on errors creating policies + */ + public LegacyOperationalPolicy createOperationalPolicy( + @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException; + + /** + * Update legacy operational policy. + * + * @param legacyOperationalPolicy the definition of the policy to be updated + * @return the updated policy + * @throws PfModelException on errors updating policies + */ + public LegacyOperationalPolicy updateOperationalPolicy( + @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException; + + /** + * Delete legacy operational policy. + * + * @param policyId ID of the policy. + * @return the deleted policy + * @throws PfModelException on errors deleting policies + */ + public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException; + + /** + * Get legacy guard policy. + * + * @param policyId ID of the policy. + * @return the policies found + * @throws PfModelException on errors getting policies + */ + public LegacyGuardPolicy getGuardPolicy(@NonNull final String policyId) throws PfModelException; + + /** + * Create legacy guard policy. + * + * @param legacyGuardPolicy the definition of the policy to be created. + * @return the created policy + * @throws PfModelException on errors creating policies + */ + public LegacyGuardPolicy createGuardPolicy(@NonNull final LegacyGuardPolicy legacyGuardPolicy) + throws PfModelException; + + /** + * Update legacy guard policy. + * + * @param legacyGuardPolicy the definition of the policy to be updated + * @return the updated policy + * @throws PfModelException on errors updating policies + */ + public LegacyGuardPolicy updateGuardPolicy(@NonNull final LegacyGuardPolicy legacyGuardPolicy) + throws PfModelException; + + /** + * Delete legacy guard policy. + * + * @param policyId ID of the policy. + * @return the deleted policy + * @throws PfModelException on errors deleting policies + */ + public LegacyGuardPolicy deleteGuardPolicy(@NonNull final String policyId) throws PfModelException; /** * Get PDP groups. @@ -152,5 +229,5 @@ public interface PolicyModelsProvider { * @param somePdpGroupFilter a filter for the get * @throws PfModelException on errors deleting PDP groups */ - public void deletePdpGroups(@NonNull final Object somePdpGroupFilter) throws PfModelException; + public Object deletePdpGroups(@NonNull final Object somePdpGroupFilter) throws PfModelException; } diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java index 5c4342800..b4b5f1ddc 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java @@ -20,7 +20,7 @@ package org.onap.policy.models.provider; -import org.onap.policy.models.provider.impl.PolicyModelsProviderImpl; +import org.onap.policy.models.provider.impl.DummyPolicyModelsProviderImpl; /** * A factory for creating PolicyModelsProvider objects using the default Policy Framework implementation. @@ -33,6 +33,6 @@ public class PolicyModelsProviderFactory { * Creates a new PolicyModelsProvider object from its implementation. */ public PolicyModelsProvider createPolicyModelsProvider() { - return new PolicyModelsProviderImpl(); + return new DummyPolicyModelsProviderImpl(); } } diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java new file mode 100644 index 000000000..3f41dac7c --- /dev/null +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java @@ -0,0 +1,144 @@ +/*- + * ============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.models.provider.impl; + +import lombok.NonNull; + +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.provider.PolicyModelsProvider; +import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.serialization.legacy.LegacyGuardPolicy; +import org.onap.policy.models.tosca.serialization.legacy.LegacyOperationalPolicy; + +/** + * This class provides an implementation of the Policy Models Provider for the ONAP Policy Framework + * that works towards a relational database. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider { + + @Override + public ToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { + return null; + } + + @Override + public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate) + throws PfModelException { + return null; + } + + @Override + public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate) + throws PfModelException { + return null; + } + + @Override + public ToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { + return null; + } + + @Override + public ToscaServiceTemplate getPolicies(@NonNull PfConceptKey policyKey) throws PfModelException { + return null; + } + + @Override + public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { + return null; + } + + @Override + public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { + return null; + } + + @Override + public ToscaServiceTemplate deletePolicies(@NonNull PfConceptKey policyKey) throws PfModelException { + return null; + } + + @Override + public LegacyOperationalPolicy getOperationalPolicy(@NonNull String policyId) throws PfModelException { + return null; + } + + @Override + public LegacyOperationalPolicy createOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy) + throws PfModelException { + return null; + } + + @Override + public LegacyOperationalPolicy updateOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy) + throws PfModelException { + return null; + } + + @Override + public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId) throws PfModelException { + return null; + } + + @Override + public LegacyGuardPolicy getGuardPolicy(@NonNull String policyId) throws PfModelException { + return null; + } + + @Override + public LegacyGuardPolicy createGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException { + return null; + } + + @Override + public LegacyGuardPolicy updateGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException { + return null; + } + + @Override + public LegacyGuardPolicy deleteGuardPolicy(@NonNull String policyId) throws PfModelException { + return null; + } + + @Override + public Object getPdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException { + return null; + } + + @Override + public Object createPdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException { + return null; + } + + @Override + public Object updatePdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException { + return null; + } + + @Override + public Object deletePdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException { + return null; + } + +} diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java new file mode 100644 index 000000000..9b92ea3ee --- /dev/null +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java @@ -0,0 +1,168 @@ +/*- + * ============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.models.provider.impl; + +import com.google.gson.Gson; + +import javax.ws.rs.core.Response; + +import lombok.NonNull; + +import org.onap.policy.common.utils.resources.TextFileUtils; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.provider.PolicyModelsProvider; +import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.serialization.legacy.LegacyGuardPolicy; +import org.onap.policy.models.tosca.serialization.legacy.LegacyOperationalPolicy; +import org.onap.policy.models.tosca.serialization.simple.ToscaServiceTemplateMessageBodyHandler; + +/** + * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy + * Framework. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { + @Override + public ToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { + return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json"); + } + + @Override + public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate) + throws PfModelException { + return serviceTemplate; + } + + @Override + public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate) + throws PfModelException { + return serviceTemplate; + } + + @Override + public ToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { + return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json"); + } + + @Override + public ToscaServiceTemplate getPolicies(@NonNull PfConceptKey policyKey) throws PfModelException { + return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyGetResponse.json"); + } + + @Override + public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { + return serviceTemplate; + } + + @Override + public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { + return serviceTemplate; + } + + @Override + public ToscaServiceTemplate deletePolicies(@NonNull PfConceptKey policyKey) throws PfModelException { + return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json"); + } + + @Override + public LegacyOperationalPolicy getOperationalPolicy(@NonNull String policyId) throws PfModelException { + return new LegacyOperationalPolicy(); + } + + @Override + public LegacyOperationalPolicy createOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy) + throws PfModelException { + return legacyOperationalPolicy; + } + + @Override + public LegacyOperationalPolicy updateOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy) + throws PfModelException { + return legacyOperationalPolicy; + } + + @Override + public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId) throws PfModelException { + return new LegacyOperationalPolicy(); + } + + @Override + public LegacyGuardPolicy getGuardPolicy(@NonNull String policyId) throws PfModelException { + return new LegacyGuardPolicy(); + } + + @Override + public LegacyGuardPolicy createGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException { + return legacyGuardPolicy; + } + + @Override + public LegacyGuardPolicy updateGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException { + return legacyGuardPolicy; + } + + @Override + public LegacyGuardPolicy deleteGuardPolicy(@NonNull String policyId) throws PfModelException { + return new LegacyGuardPolicy(); + } + + @Override + public Object getPdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException { + return null; + } + + @Override + public Object createPdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException { + return null; + } + + @Override + public Object updatePdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException { + return null; + } + + @Override + public Object deletePdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException { + return null; + } + + /** + * Return a ToscaServicetemplate dummy response. + * + * @param fileName the file name containing the dummy response + * @return the ToscaServiceTemplate with the dummy response + */ + private ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) { + Gson gson = new ToscaServiceTemplateMessageBodyHandler().getGson(); + ToscaServiceTemplate serviceTemplate; + + try { + serviceTemplate = gson.fromJson(TextFileUtils.getTextFileAsString(fileName), ToscaServiceTemplate.class); + } catch (Exception exc) { + throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc); + } + + return serviceTemplate; + } +} diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/PolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/PolicyModelsProviderImpl.java deleted file mode 100644 index 12d7686b3..000000000 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/PolicyModelsProviderImpl.java +++ /dev/null @@ -1,98 +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.models.provider.impl; - -import lombok.NonNull; - -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.base.PfReferenceKey; -import org.onap.policy.models.provider.PolicyModelsProvider; -import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate; - -/** - * This class provides the implementaiton of the defalut Policy Models Provider for the ONAP Policy Framework. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -public class PolicyModelsProviderImpl implements PolicyModelsProvider { - - @Override - public ToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { - return null; - } - - @Override - public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate) - throws PfModelException { - return null; - } - - @Override - public ToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { - return null; - } - - @Override - public ToscaServiceTemplate getPolicies(@NonNull PfReferenceKey policyKey) throws PfModelException { - return null; - } - - @Override - public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { - return null; - } - - @Override - public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { - return null; - } - - @Override - public ToscaServiceTemplate deletePolicies(@NonNull PfReferenceKey policyKey) throws PfModelException { - return null; - } - - @Override - public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate) - throws PfModelException { - return null; - } - - @Override - public Object getPdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException { - return null; - } - - @Override - public Object createPdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException { - return null; - } - - @Override - public Object updatePdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException { - return null; - } - - @Override - public void deletePdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException { - } -} diff --git a/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json b/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json new file mode 100644 index 000000000..27de380c2 --- /dev/null +++ b/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json @@ -0,0 +1,48 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_0_0", + "topology_template": { + "policies": [ + { + "onap.vcpe.tca": { + "type": "onap.policies.monitoring.cdap.tca.hi.lo.app", + "version": "1.0.0", + "metadata": { + "policy-id": "onap.vcpe.tca" + }, + "properties": { + "domain": "measurementsForVfScaling", + "metricsPerEventName": [ + { + "eventName": "Measurement_vGMUX", + "controlLoopSchemaType": "VNF", + "policyScope": "DCAE", + "policyName": "DCAE.Config_tca-hi-lo", + "policyVersion": "v0.0.1", + "thresholds": [ + { + "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2", + "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value", + "thresholdValue": 0, + "direction": "EQUAL", + "severity": "MAJOR", + "closedLoopEventStatus": "ABATED" + }, + { + "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2", + "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value", + "thresholdValue": 0, + "direction": "GREATER", + "severity": "CRITICAL", + "closedLoopEventStatus": "ONSET" + } + ] + } + ] + } + } + } + ] + } +} \ No newline at end of file diff --git a/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyGetResponse.json b/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyGetResponse.json new file mode 100644 index 000000000..27de380c2 --- /dev/null +++ b/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyGetResponse.json @@ -0,0 +1,48 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_0_0", + "topology_template": { + "policies": [ + { + "onap.vcpe.tca": { + "type": "onap.policies.monitoring.cdap.tca.hi.lo.app", + "version": "1.0.0", + "metadata": { + "policy-id": "onap.vcpe.tca" + }, + "properties": { + "domain": "measurementsForVfScaling", + "metricsPerEventName": [ + { + "eventName": "Measurement_vGMUX", + "controlLoopSchemaType": "VNF", + "policyScope": "DCAE", + "policyName": "DCAE.Config_tca-hi-lo", + "policyVersion": "v0.0.1", + "thresholds": [ + { + "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2", + "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value", + "thresholdValue": 0, + "direction": "EQUAL", + "severity": "MAJOR", + "closedLoopEventStatus": "ABATED" + }, + { + "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2", + "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value", + "thresholdValue": 0, + "direction": "GREATER", + "severity": "CRITICAL", + "closedLoopEventStatus": "ONSET" + } + ] + } + ] + } + } + } + ] + } +} \ No newline at end of file diff --git a/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json b/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json new file mode 100644 index 000000000..27de380c2 --- /dev/null +++ b/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json @@ -0,0 +1,48 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_0_0", + "topology_template": { + "policies": [ + { + "onap.vcpe.tca": { + "type": "onap.policies.monitoring.cdap.tca.hi.lo.app", + "version": "1.0.0", + "metadata": { + "policy-id": "onap.vcpe.tca" + }, + "properties": { + "domain": "measurementsForVfScaling", + "metricsPerEventName": [ + { + "eventName": "Measurement_vGMUX", + "controlLoopSchemaType": "VNF", + "policyScope": "DCAE", + "policyName": "DCAE.Config_tca-hi-lo", + "policyVersion": "v0.0.1", + "thresholds": [ + { + "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2", + "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value", + "thresholdValue": 0, + "direction": "EQUAL", + "severity": "MAJOR", + "closedLoopEventStatus": "ABATED" + }, + { + "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2", + "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value", + "thresholdValue": 0, + "direction": "GREATER", + "severity": "CRITICAL", + "closedLoopEventStatus": "ONSET" + } + ] + } + ] + } + } + } + ] + } +} \ No newline at end of file diff --git a/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json b/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json new file mode 100644 index 000000000..27de380c2 --- /dev/null +++ b/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json @@ -0,0 +1,48 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_0_0", + "topology_template": { + "policies": [ + { + "onap.vcpe.tca": { + "type": "onap.policies.monitoring.cdap.tca.hi.lo.app", + "version": "1.0.0", + "metadata": { + "policy-id": "onap.vcpe.tca" + }, + "properties": { + "domain": "measurementsForVfScaling", + "metricsPerEventName": [ + { + "eventName": "Measurement_vGMUX", + "controlLoopSchemaType": "VNF", + "policyScope": "DCAE", + "policyName": "DCAE.Config_tca-hi-lo", + "policyVersion": "v0.0.1", + "thresholds": [ + { + "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2", + "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value", + "thresholdValue": 0, + "direction": "EQUAL", + "severity": "MAJOR", + "closedLoopEventStatus": "ABATED" + }, + { + "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2", + "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value", + "thresholdValue": 0, + "direction": "GREATER", + "severity": "CRITICAL", + "closedLoopEventStatus": "ONSET" + } + ] + } + ] + } + } + } + ] + } +} \ No newline at end of file diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java new file mode 100644 index 000000000..d4808ee70 --- /dev/null +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java @@ -0,0 +1,49 @@ +/*- + * ============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.models.provider.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.provider.PolicyModelsProvider; +import org.onap.policy.models.provider.PolicyModelsProviderFactory; +import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate; + +/** + * Test the dummy moldes provider implementation. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class DummyPolicyModelsProviderTest { + + @Test + public void test() throws PfModelException { + PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(); + + ToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies(new PfConceptKey()); + assertNotNull(serviceTemplate); + assertEquals("onap.vcpe.tca:1.0.0", + serviceTemplate.getTopologyTemplate().getPolicies().get("onap.vcpe.tca").getId()); + } +} -- cgit 1.2.3-korg