From 45b653fc5a8d641452247eca5c80cf580609e9bf Mon Sep 17 00:00:00 2001 From: rameshiyer27 Date: Mon, 7 Feb 2022 17:07:38 +0000 Subject: Add policy metadataSet handling as node templates Each metadataSet is represented as a 'node_template' in Tosca mapped to a specific node type. Support added for db operations of node templates as independent entities. Detailed documentation available here : https://wiki.onap.org/display/DW/Enable+Handling+of+Policy+Type+Metadata Issue-ID: POLICY-3832 Signed-off-by: zrrmmua Change-Id: I6c189142b1778ba858aae27cd92d4f136d950208 --- .../models/provider/PolicyModelsProvider.java | 60 +++- .../impl/AbstractPolicyModelsProvider.java | 45 ++- .../impl/DummyPolicyModelsProviderImpl.java | 300 ----------------- .../dummyimpl/DummyToscaPolicyDeleteResponse.json | 48 --- .../dummyimpl/DummyToscaPolicyGetResponse.json | 48 --- .../DummyToscaPolicyTypeDeleteResponse.json | 48 --- .../dummyimpl/DummyToscaPolicyTypeGetResponse.json | 213 ------------ .../impl/DatabasePolicyModelsProviderTest.java | 48 ++- .../models/provider/impl/DummyBadProviderImpl.java | 38 ++- .../impl/DummyPolicyModelsProviderImpl.java | 359 +++++++++++++++++++++ .../dummyimpl/DummyToscaNodeTemplateResponse.json | 46 +++ .../dummyimpl/DummyToscaPolicyDeleteResponse.json | 48 +++ .../dummyimpl/DummyToscaPolicyGetResponse.json | 48 +++ .../DummyToscaPolicyTypeDeleteResponse.json | 48 +++ .../dummyimpl/DummyToscaPolicyTypeGetResponse.json | 213 ++++++++++++ 15 files changed, 949 insertions(+), 661 deletions(-) delete mode 100644 models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java delete mode 100644 models-provider/src/main/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json delete mode 100644 models-provider/src/main/resources/dummyimpl/DummyToscaPolicyGetResponse.json delete mode 100644 models-provider/src/main/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json delete mode 100644 models-provider/src/main/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json create mode 100644 models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java create mode 100644 models-provider/src/test/resources/dummyimpl/DummyToscaNodeTemplateResponse.json create mode 100644 models-provider/src/test/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json create mode 100644 models-provider/src/test/resources/dummyimpl/DummyToscaPolicyGetResponse.json create mode 100644 models-provider/src/test/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json create mode 100644 models-provider/src/test/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json (limited to 'models-provider/src') 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 85aab6ec4..5cc5fc96b 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2022 Nordix Foundation. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -25,8 +25,11 @@ package org.onap.policy.models.provider; import java.time.Instant; import java.util.Collection; import java.util.List; +import java.util.Map; import lombok.NonNull; +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.pap.concepts.PolicyAudit; import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter; import org.onap.policy.models.pdp.concepts.Pdp; @@ -38,6 +41,8 @@ import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; 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.ToscaServiceTemplate; @@ -254,6 +259,59 @@ public interface PolicyModelsProvider extends AutoCloseable { public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version) throws PfModelException; + + /** + * Create tosca node templates. + * + * @param serviceTemplate the definitions of the new node templates to be created. + * @return the tosca node templates that were created + * @throws PfModelException on errors creating tosca node templates + */ + public ToscaServiceTemplate createToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelException; + + /** + * Update tosca node templates. + * + * @param serviceTemplate with node templates to be updated. + * @return the service template with node templates that were updated + * @throws PfModelException on errors updating tosca node templates + */ + public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelRuntimeException, PfModelException; + + /** + * Delete a tosca node template. + * + * @param name the name of the node template to delete. + * @param version the version of the node template to delete. + * @return the service template with node templates that was deleted + * @throws PfModelException on errors deleting a node template + */ + public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final String name, @NonNull final String version) + throws PfModelException; + + + /** + * Get filtered node template metadataSet entities. + * + * @return the list of metadataSet found + * @throws PfModelException on errors getting node template metadataSet + */ + public List>> getNodeTemplateMetadataSets(final String name, + final String version) + throws PfModelException; + + /** + * Get filtered node template entities. + * + * @return the list of nodeTemplates found + * @throws PfModelException on errors getting node template + */ + public List> getToscaNodeTemplate(final String name, + final String version) + throws PfModelException; + /** * Get PDP groups. * diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/AbstractPolicyModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/AbstractPolicyModelsProvider.java index fa7658355..ffb470628 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/AbstractPolicyModelsProvider.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/AbstractPolicyModelsProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,10 @@ package org.onap.policy.models.provider.impl; import java.time.Instant; import java.util.Collection; import java.util.List; +import java.util.Map; import javax.ws.rs.core.Response; import lombok.NonNull; +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.dao.PfDao; @@ -44,6 +46,8 @@ import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; 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.ToscaServiceTemplate; @@ -193,6 +197,45 @@ public abstract class AbstractPolicyModelsProvider implements PolicyModelsProvid return new AuthorativeToscaProvider().deletePolicy(getPfDao(), name, version); } + @Override + public ToscaServiceTemplate createToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelException { + assertInitialized(); + return new AuthorativeToscaProvider().createToscaNodeTemplates(getPfDao(), serviceTemplate); + } + + @Override + public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull final ToscaServiceTemplate serviceTemplate) + throws PfModelRuntimeException, PfModelException { + assertInitialized(); + return new AuthorativeToscaProvider().updateToscaNodeTemplates(getPfDao(), serviceTemplate); + } + + @Override + public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final String name, @NonNull final String version) + throws PfModelException { + assertInitialized(); + return new AuthorativeToscaProvider().deleteToscaNodeTemplate(getPfDao(), name, version); + } + + @Override + public List>> getNodeTemplateMetadataSets(final String name, + final String version) + throws PfModelException { + assertInitialized(); + return new AuthorativeToscaProvider().getNodeTemplateMetadataSet(getPfDao(), name, version); + } + + @Override + public List> getToscaNodeTemplate(final String name, + final String version) + throws PfModelException { + assertInitialized(); + return new AuthorativeToscaProvider().getToscaNodeTemplate(getPfDao(), name, version); + } + + + @Override public List getPdpGroups(final String name) throws PfModelException { assertInitialized(); 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 deleted file mode 100644 index b9b34a24d..000000000 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java +++ /dev/null @@ -1,300 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. - * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020 Bell Canada. 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.models.provider.impl; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import javax.ws.rs.core.Response; -import lombok.NonNull; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.base.PfModelRuntimeException; -import org.onap.policy.models.pap.concepts.PolicyAudit; -import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter; -import org.onap.policy.models.pdp.concepts.Pdp; -import org.onap.policy.models.pdp.concepts.PdpGroup; -import org.onap.policy.models.pdp.concepts.PdpGroupFilter; -import org.onap.policy.models.pdp.concepts.PdpPolicyStatus; -import org.onap.policy.models.pdp.concepts.PdpStatistics; -import org.onap.policy.models.pdp.concepts.PdpSubGroup; -import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters; -import org.onap.policy.models.provider.PolicyModelsProvider; -import org.onap.policy.models.provider.PolicyModelsProviderParameters; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; -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.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; - -/** - * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework. - * - * @author Liam Fallon (liam.fallon@est.tech) - * @author Chenfei Gao (cgao@research.att.com) - */ -public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { - /** - * Constructor that takes the parameters. - * - * @param parameters the parameters for the provider - */ - public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) { - // Default constructor - } - - @Override - public void init() throws PfModelException { - // Not required on the dummy provider - } - - @Override - public void close() { - // Not required on the dummy provider - } - - - @Override - public List getServiceTemplateList(String name, String version) throws PfModelException { - return new ArrayList<>(); - } - - @Override - public List getFilteredServiceTemplateList( - @NonNull ToscaEntityFilter filter) throws PfModelException { - return new ArrayList<>(); - } - - @Override - public ToscaServiceTemplate createServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate) - throws PfModelException { - return serviceTemplate; - } - - @Override - public ToscaServiceTemplate updateServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate) - throws PfModelException { - return serviceTemplate; - } - - @Override - public ToscaServiceTemplate deleteServiceTemplate(@NonNull String name, @NonNull String version) - throws PfModelException { - return getDummyResponse("dummyimpl/DummyToscaServiceTemplateDeleteResponse.json"); - } - - @Override - public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException { - return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json"); - } - - @Override - public List getPolicyTypeList(final String name, final String version) throws PfModelException { - return new ArrayList<>(); - } - - @Override - public ToscaServiceTemplate getFilteredPolicyTypes(ToscaEntityFilter filter) - throws PfModelException { - return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json"); - } - - @Override - public List getFilteredPolicyTypeList(ToscaEntityFilter filter) { - return new ArrayList<>(); - } - - @Override - public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException { - return serviceTemplate; - } - - @Override - public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException { - return serviceTemplate; - } - - @Override - public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException { - return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json"); - } - - @Override - public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException { - return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json"); - } - - @Override - public List getPolicyList(final String name, final String version) throws PfModelException { - return new ArrayList<>(); - } - - @Override - public ToscaServiceTemplate getFilteredPolicies(ToscaTypedEntityFilter filter) - throws PfModelException { - return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json"); - } - - @Override - public List getFilteredPolicyList(ToscaTypedEntityFilter filter) throws PfModelException { - return new ArrayList<>(); - } - - @Override - public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException { - return serviceTemplate; - } - - @Override - public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException { - return serviceTemplate; - } - - @Override - public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException { - return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json"); - } - - @Override - public List getPdpGroups(final String name) throws PfModelException { - return new ArrayList<>(); - } - - @Override - public List getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException { - return new ArrayList<>(); - } - - @Override - public List createPdpGroups(final List pdpGroups) throws PfModelException { - return new ArrayList<>(); - } - - @Override - public List updatePdpGroups(final List pdpGroups) throws PfModelException { - return new ArrayList<>(); - } - - @Override - public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException { - // Not implemented - } - - @Override - public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException { - // Not implemented - } - - @Override - public PdpGroup deletePdpGroup(final String name) throws PfModelException { - return null; - } - - @Override - public List getFilteredPdpStatistics(PdpFilterParameters filterParams) throws PfModelException { - // Not implemented - return new ArrayList<>(); - } - - @Override - public List createPdpStatistics(final List pdpStatisticsList) - throws PfModelException { - // Not implemented - return new ArrayList<>(); - } - - @Override - public List updatePdpStatistics(final List pdpStatisticsList) - throws PfModelException { - // Not implemented - return new ArrayList<>(); - } - - @Override - public List deletePdpStatistics(final String name, final Instant timestamp) { - // Not implemented - return new ArrayList<>(); - } - - @Override - public List getAllPolicyStatus() throws PfModelException { - // Not implemented - return new ArrayList<>(); - } - - @Override - public List getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy) - throws PfModelException { - // Not implemented - return new ArrayList<>(); - } - - @Override - public List getGroupPolicyStatus(String groupName) throws PfModelException { - // Not implemented - return new ArrayList<>(); - } - - @Override - public void cudPolicyStatus(Collection createObjs, Collection updateObjs, - Collection deleteObjs) { - // Not implemented - } - - @Override - public void createAuditRecords(List auditRecords) { - // Not implemented - } - - @Override - public List getAuditRecords(AuditFilter auditFilter) { - // Not implemented - return new ArrayList<>(); - } - - /** - * Return a ToscaServicetemplate dummy response. - * - * @param fileName the file name containing the dummy response - * @return the ToscaServiceTemplate with the dummy response - */ - protected ToscaServiceTemplate getDummyResponse(final String fileName) { - var standardCoder = new StandardCoder(); - ToscaServiceTemplate serviceTemplate; - - try { - serviceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class); - if (serviceTemplate == null) { - throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file"); - } - } catch (Exception exc) { - throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc); - } - - return serviceTemplate; - } -} diff --git a/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json b/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json deleted file mode 100644 index 27de380c2..000000000 --- a/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "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 deleted file mode 100644 index 27de380c2..000000000 --- a/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyGetResponse.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "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 deleted file mode 100644 index 27de380c2..000000000 --- a/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "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 deleted file mode 100644 index 477d4477a..000000000 --- a/models-provider/src/main/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json +++ /dev/null @@ -1,213 +0,0 @@ -{ - "tosca_definitions_version": "tosca_simple_yaml_1_0_0", - "policy_types": { - "onap.policies.Monitoring": { - "derived_from": "tosca.policies.Root", - "description": "a base policy type for all policies that governs monitoring provisioning" - }, - "onap.policy.monitoring.cdap.tca.hi.lo.app": { - "derived_from": "onap.policies.Monitoring", - "version": "1.0.0", - "properties": { - "tca_policy": { - "type": "map", - "description": "TCA Policy JSON", - "entry_schema": { - "type": "onap.datatypes.monitoring.tca_policy" - } - } - } - } - }, - "data_types": { - "onap.datatypes.monitoring.metricsPerEventName": { - "derived_from": "tosca.datatypes.Root", - "properties": { - "controlLoopSchemaType": { - "type": "string", - "required": true, - "description": "Specifies Control Loop Schema Type for the event Name e.g. VNF, VM", - "constraints": [ - { - "valid_values": [ - "VM", - "VNF" - ] - } - ] - }, - "eventName": { - "type": "string", - "required": true, - "description": "Event name to which thresholds need to be applied" - }, - "policyName": { - "type": "string", - "required": true, - "description": "TCA Policy Scope Name" - }, - "policyScope": { - "type": "string", - "required": true, - "description": "TCA Policy Scope" - }, - "policyVersion": { - "type": "string", - "required": true, - "description": "TCA Policy Scope Version" - }, - "thresholds": { - "type": "list", - "required": true, - "description": "Thresholds associated with eventName", - "entry_schema": { - "type": "onap.datatypes.monitoring.thresholds" - } - } - } - } - }, - "onap.datatypes.monitoring.tca_policy": { - "derived_from": "tosca.datatypes.Root", - "properties": { - "domain": { - "type": "string", - "required": true, - "description": "Domain name to which TCA needs to be applied", - "default": "measurementsForVfScaling", - "constraints": [ - { - "equal": "measurementsForVfScaling" - } - ] - }, - "metricsPerEventName": { - "type": "list", - "required": true, - "description": "Contains eventName and threshold details that need to be applied to given eventName", - "entry_schema": { - "type": "onap.datatypes.monitoring.metricsPerEventName" - } - } - } - }, - "onap.datatypes.monitoring.thresholds": { - "derived_from": "tosca.datatypes.Root", - "properties": { - "closedLoopControlName": { - "type": "string", - "required": true, - "description": "Closed Loop Control Name associated with the threshold" - }, - "closedLoopEventStatus": { - "type": "string", - "required": true, - "description": "Closed Loop Event Status of the threshold", - "constraints": [ - { - "valid_values": [ - "ONSET", - "ABATED" - ] - } - ] - }, - "direction": { - "type": "string", - "required": true, - "description": "Direction of the threshold", - "constraints": [ - { - "valid_values": [ - "LESS", - "LESS_OR_EQUAL", - "GREATER", - "GREATER_OR_EQUAL", - "EQUAL" - ] - } - ] - }, - "fieldPath": { - "type": "string", - "required": true, - "description": "Json field Path as per CEF message which needs to be analyzed for TCA", - "constraints": [ - { - "valid_values": [ - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsDelta", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsAccumulated", - "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsAccumulated", - "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuIdle", - "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageInterrupt", - "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageNice", - "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSoftIrq", - "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSteal", - "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSystem", - "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuWait", - "$.event.measurementsForVfScalingFields.cpuUsageArray[*].percentUsage", - "$.event.measurementsForVfScalingFields.meanRequestLatency", - "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryBuffered", - "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryCached", - "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryConfigured", - "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryFree", - "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryUsed", - "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value" - ] - } - ] - }, - "severity": { - "type": "string", - "required": true, - "description": "Threshold Event Severity", - "constraints": [ - { - "valid_values": [ - "CRITICAL", - "MAJOR", - "MINOR", - "WARNING", - "NORMAL" - ] - } - ] - }, - "thresholdValue": { - "type": "integer", - "required": true, - "description": "Threshold value for the field Path inside CEF message" - }, - "version": { - "type": "string", - "required": true, - "description": "Version number associated with the threshold" - } - } - } -} diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java index 57c261cb5..561ef5daa 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2022 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ @@ -32,6 +32,7 @@ import static org.junit.Assert.assertTrue; import java.time.Instant; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -53,9 +54,12 @@ import org.onap.policy.models.provider.PolicyModelsProviderParameters; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; 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.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; /** @@ -567,6 +571,31 @@ public class DatabasePolicyModelsProviderTest { databaseProvider.close(); } + @Test + public void testToscaNodeTemplateHandling() throws PfModelException { + databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); + + ToscaServiceTemplate serviceTemplate = makeNodeTemplate(); + + assertEquals("1.0.1", + databaseProvider.createToscaNodeTemplates(serviceTemplate).getToscaTopologyTemplate().getNodeTemplates() + .get("metadataSet1").getVersion()); + assertEquals(1, databaseProvider.getNodeTemplateMetadataSets(null, null).size()); + + ToscaNodeTemplate nodeTemplate1 = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates() + .get("metadataSet1"); + nodeTemplate1.setMetadata(Map.of("dummyKey", "updatedValue")); + serviceTemplate.getToscaTopologyTemplate().setNodeTemplates(Map.of("metadataSet1:1.0.1", nodeTemplate1)); + assertEquals("updatedValue", databaseProvider.updateToscaNodeTemplates(serviceTemplate) + .getToscaTopologyTemplate().getNodeTemplates().get("metadataSet1").getMetadata().get("dummyKey")); + + assertThatThrownBy(() -> { + databaseProvider.deleteToscaNodeTemplate("invalidName", "1.0.1"); + }).hasMessage("node template invalidName:1.0.1 not found"); + + databaseProvider.close(); + } + private List makePdpStatisticsList() { PdpStatistics pdpStatistics = new PdpStatistics(); pdpStatistics.setPdpInstanceId(NAME); @@ -576,4 +605,21 @@ public class DatabasePolicyModelsProviderTest { List statisticsArrayList = List.of(pdpStatistics); return statisticsArrayList; } + + private ToscaServiceTemplate makeNodeTemplate() { + ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); + serviceTemplate.setToscaDefinitionsVersion("sample:1.1.0"); + serviceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate()); + serviceTemplate.setNodeTypes(Map.of("org.onap.policy.metadataSet:1.0.0", new ToscaNodeType())); + ToscaNodeTemplate nodeTemplate1 = new ToscaNodeTemplate(); + nodeTemplate1.setName("metadataSet1"); + nodeTemplate1.setVersion("1.0.1"); + nodeTemplate1.setType("org.onap.policy.metadataSet"); + nodeTemplate1.setTypeVersion("1.0.0"); + nodeTemplate1.setMetadata(Map.of("dummyKey", "dummyValue")); + + serviceTemplate.getToscaTopologyTemplate().setNodeTemplates(Map.of("metadataSet1", nodeTemplate1)); + + return serviceTemplate; + } } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java index 6cb95ee54..410ecf26a 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2022 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ @@ -27,8 +27,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import javax.ws.rs.core.Response; import lombok.NonNull; +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.pap.concepts.PolicyAudit; @@ -43,6 +45,8 @@ import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; 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.ToscaServiceTemplate; @@ -134,6 +138,38 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { return null; } + @Override + public ToscaServiceTemplate createToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate) + throws PfModelException { + return null; + } + + @Override + public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate) + throws PfModelRuntimeException, PfModelException { + return null; + } + + @Override + public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull String name, @NonNull String version) + throws PfModelException { + return null; + } + + @Override + public List>> getNodeTemplateMetadataSets(@NonNull String name, + @NonNull String version) + throws PfModelException { + return null; + } + + @Override + public List> getToscaNodeTemplate(final String name, + final String version) + throws PfModelException { + return null; + } + @Override public List getPdpGroups(String name) throws PfModelException { return Collections.emptyList(); diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java new file mode 100644 index 000000000..dcc436a05 --- /dev/null +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java @@ -0,0 +1,359 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019-2022 Nordix Foundation. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020 Bell Canada. 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.models.provider.impl; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import javax.ws.rs.core.Response; +import lombok.NonNull; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +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.pap.concepts.PolicyAudit; +import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter; +import org.onap.policy.models.pdp.concepts.Pdp; +import org.onap.policy.models.pdp.concepts.PdpGroup; +import org.onap.policy.models.pdp.concepts.PdpGroupFilter; +import org.onap.policy.models.pdp.concepts.PdpPolicyStatus; +import org.onap.policy.models.pdp.concepts.PdpStatistics; +import org.onap.policy.models.pdp.concepts.PdpSubGroup; +import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters; +import org.onap.policy.models.provider.PolicyModelsProvider; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +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.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; + +/** + * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework. + * + * @author Liam Fallon (liam.fallon@est.tech) + * @author Chenfei Gao (cgao@research.att.com) + */ +public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { + /** + * Constructor that takes the parameters. + * + * @param parameters the parameters for the provider + */ + public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) { + // Default constructor + } + + @Override + public void init() throws PfModelException { + // Not required on the dummy provider + } + + @Override + public void close() { + // Not required on the dummy provider + } + + + @Override + public List getServiceTemplateList(String name, String version) throws PfModelException { + return new ArrayList<>(); + } + + @Override + public List getFilteredServiceTemplateList( + @NonNull ToscaEntityFilter filter) throws PfModelException { + return new ArrayList<>(); + } + + @Override + public ToscaServiceTemplate createServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate) + throws PfModelException { + return serviceTemplate; + } + + @Override + public ToscaServiceTemplate updateServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate) + throws PfModelException { + return serviceTemplate; + } + + @Override + public ToscaServiceTemplate deleteServiceTemplate(@NonNull String name, @NonNull String version) + throws PfModelException { + return getDummyResponse("dummyimpl/DummyToscaServiceTemplateDeleteResponse.json"); + } + + @Override + public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException { + return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json"); + } + + @Override + public List getPolicyTypeList(final String name, final String version) throws PfModelException { + return new ArrayList<>(); + } + + @Override + public ToscaServiceTemplate getFilteredPolicyTypes(ToscaEntityFilter filter) + throws PfModelException { + return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json"); + } + + @Override + public List getFilteredPolicyTypeList(ToscaEntityFilter filter) { + return new ArrayList<>(); + } + + @Override + public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException { + return serviceTemplate; + } + + @Override + public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException { + return serviceTemplate; + } + + @Override + public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException { + return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json"); + } + + @Override + public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException { + return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json"); + } + + @Override + public List getPolicyList(final String name, final String version) throws PfModelException { + return new ArrayList<>(); + } + + @Override + public ToscaServiceTemplate getFilteredPolicies(ToscaTypedEntityFilter filter) + throws PfModelException { + return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json"); + } + + @Override + public List getFilteredPolicyList(ToscaTypedEntityFilter filter) throws PfModelException { + return new ArrayList<>(); + } + + @Override + public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException { + return serviceTemplate; + } + + @Override + public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException { + return serviceTemplate; + } + + @Override + public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException { + return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json"); + } + + @Override + public ToscaServiceTemplate createToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate) + throws PfModelException { + return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json"); + } + + @Override + public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate) + throws PfModelRuntimeException, PfModelException { + return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json"); + } + + @Override + public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull String name, @NonNull String version) + throws PfModelException { + return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json"); + } + + @Override + public List>> getNodeTemplateMetadataSets(@NonNull String name, + @NonNull String version) + throws PfModelException { + return new ArrayList<>(); + } + + @Override + public List> getToscaNodeTemplate(final String name, + final String version) + throws PfModelException { + return new ArrayList<>(); + } + + @Override + public List getPdpGroups(final String name) throws PfModelException { + return new ArrayList<>(); + } + + @Override + public List getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException { + return new ArrayList<>(); + } + + @Override + public List createPdpGroups(final List pdpGroups) throws PfModelException { + return new ArrayList<>(); + } + + @Override + public List updatePdpGroups(final List pdpGroups) throws PfModelException { + return new ArrayList<>(); + } + + @Override + public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException { + // Not implemented + } + + @Override + public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException { + // Not implemented + } + + @Override + public PdpGroup deletePdpGroup(final String name) throws PfModelException { + return null; + } + + @Override + public List getFilteredPdpStatistics(PdpFilterParameters filterParams) throws PfModelException { + // Not implemented + return new ArrayList<>(); + } + + @Override + public List createPdpStatistics(final List pdpStatisticsList) + throws PfModelException { + // Not implemented + return new ArrayList<>(); + } + + @Override + public List updatePdpStatistics(final List pdpStatisticsList) + throws PfModelException { + // Not implemented + return new ArrayList<>(); + } + + @Override + public List deletePdpStatistics(final String name, final Instant timestamp) { + // Not implemented + return new ArrayList<>(); + } + + @Override + public List getAllPolicyStatus() throws PfModelException { + // Not implemented + return new ArrayList<>(); + } + + @Override + public List getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy) + throws PfModelException { + // Not implemented + return new ArrayList<>(); + } + + @Override + public List getGroupPolicyStatus(String groupName) throws PfModelException { + // Not implemented + return new ArrayList<>(); + } + + @Override + public void cudPolicyStatus(Collection createObjs, Collection updateObjs, + Collection deleteObjs) { + // Not implemented + } + + @Override + public void createAuditRecords(List auditRecords) { + // Not implemented + } + + @Override + public List getAuditRecords(AuditFilter auditFilter) { + // Not implemented + return new ArrayList<>(); + } + + /** + * Return a ToscaServicetemplate dummy response. + * + * @param fileName the file name containing the dummy response + * @return the ToscaServiceTemplate with the dummy response + */ + protected ToscaServiceTemplate getDummyResponse(final String fileName) { + var standardCoder = new StandardCoder(); + ToscaServiceTemplate serviceTemplate; + + try { + serviceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class); + if (serviceTemplate == null) { + throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file"); + } + } catch (Exception exc) { + throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc); + } + + return serviceTemplate; + } + + /** + * Return a tosca node template dummy response. + * + * @param fileName the file name containing the dummy response + * @return the service template with the dummy response + */ + protected ToscaServiceTemplate getDummyNodeTemplateResponse(final String fileName) { + var standardCoder = new StandardCoder(); + ToscaServiceTemplate serviceTemplate; + + try { + serviceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class); + if (serviceTemplate == null) { + throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file"); + } + } catch (Exception exc) { + throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc); + } + + return serviceTemplate; + } +} diff --git a/models-provider/src/test/resources/dummyimpl/DummyToscaNodeTemplateResponse.json b/models-provider/src/test/resources/dummyimpl/DummyToscaNodeTemplateResponse.json new file mode 100644 index 000000000..291ef47ac --- /dev/null +++ b/models-provider/src/test/resources/dummyimpl/DummyToscaNodeTemplateResponse.json @@ -0,0 +1,46 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", + "node_types": { + "org.onap.nodetypes.policy.MetadataSet": { + "derived_from": "tosca.nodetypes.Root", + "version": "1.0.0" + } + }, + "topology_template": { + "node_templates": { + "apexMetadata_grpc": { + "version": "1.2.1", + "type": "org.onap.nodetypes.policy.MetadataSet", + "type_version": "1.0.0", + "description": "Metadata set for GRPC", + "metadata": { + "policyModel": { + "key": { + "name": "GrpcPolicyModel", + "version": "1.0.1" + } + }, + "threshold": 3.14, + "state": "active" + } + }, + "apexMetadata_adaptive": { + "version": "2.3.1", + "type": "org.onap.nodetypes.policy.MetadataSet", + "type_version": "1.0.0", + "description": "Metadata set for an Adaptive Policy", + "metadata": { + "policyModel": { + "key": { + "name": "AdaptivePolicyModel", + "version": "1.2.1" + } + }, + "radius": 1.23, + "height": 2.13, + "length": 45 + } + } + } + } +} \ No newline at end of file diff --git a/models-provider/src/test/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json b/models-provider/src/test/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json new file mode 100644 index 000000000..27de380c2 --- /dev/null +++ b/models-provider/src/test/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/test/resources/dummyimpl/DummyToscaPolicyGetResponse.json b/models-provider/src/test/resources/dummyimpl/DummyToscaPolicyGetResponse.json new file mode 100644 index 000000000..27de380c2 --- /dev/null +++ b/models-provider/src/test/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/test/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json b/models-provider/src/test/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json new file mode 100644 index 000000000..27de380c2 --- /dev/null +++ b/models-provider/src/test/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/test/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json b/models-provider/src/test/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json new file mode 100644 index 000000000..477d4477a --- /dev/null +++ b/models-provider/src/test/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json @@ -0,0 +1,213 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_0_0", + "policy_types": { + "onap.policies.Monitoring": { + "derived_from": "tosca.policies.Root", + "description": "a base policy type for all policies that governs monitoring provisioning" + }, + "onap.policy.monitoring.cdap.tca.hi.lo.app": { + "derived_from": "onap.policies.Monitoring", + "version": "1.0.0", + "properties": { + "tca_policy": { + "type": "map", + "description": "TCA Policy JSON", + "entry_schema": { + "type": "onap.datatypes.monitoring.tca_policy" + } + } + } + } + }, + "data_types": { + "onap.datatypes.monitoring.metricsPerEventName": { + "derived_from": "tosca.datatypes.Root", + "properties": { + "controlLoopSchemaType": { + "type": "string", + "required": true, + "description": "Specifies Control Loop Schema Type for the event Name e.g. VNF, VM", + "constraints": [ + { + "valid_values": [ + "VM", + "VNF" + ] + } + ] + }, + "eventName": { + "type": "string", + "required": true, + "description": "Event name to which thresholds need to be applied" + }, + "policyName": { + "type": "string", + "required": true, + "description": "TCA Policy Scope Name" + }, + "policyScope": { + "type": "string", + "required": true, + "description": "TCA Policy Scope" + }, + "policyVersion": { + "type": "string", + "required": true, + "description": "TCA Policy Scope Version" + }, + "thresholds": { + "type": "list", + "required": true, + "description": "Thresholds associated with eventName", + "entry_schema": { + "type": "onap.datatypes.monitoring.thresholds" + } + } + } + } + }, + "onap.datatypes.monitoring.tca_policy": { + "derived_from": "tosca.datatypes.Root", + "properties": { + "domain": { + "type": "string", + "required": true, + "description": "Domain name to which TCA needs to be applied", + "default": "measurementsForVfScaling", + "constraints": [ + { + "equal": "measurementsForVfScaling" + } + ] + }, + "metricsPerEventName": { + "type": "list", + "required": true, + "description": "Contains eventName and threshold details that need to be applied to given eventName", + "entry_schema": { + "type": "onap.datatypes.monitoring.metricsPerEventName" + } + } + } + }, + "onap.datatypes.monitoring.thresholds": { + "derived_from": "tosca.datatypes.Root", + "properties": { + "closedLoopControlName": { + "type": "string", + "required": true, + "description": "Closed Loop Control Name associated with the threshold" + }, + "closedLoopEventStatus": { + "type": "string", + "required": true, + "description": "Closed Loop Event Status of the threshold", + "constraints": [ + { + "valid_values": [ + "ONSET", + "ABATED" + ] + } + ] + }, + "direction": { + "type": "string", + "required": true, + "description": "Direction of the threshold", + "constraints": [ + { + "valid_values": [ + "LESS", + "LESS_OR_EQUAL", + "GREATER", + "GREATER_OR_EQUAL", + "EQUAL" + ] + } + ] + }, + "fieldPath": { + "type": "string", + "required": true, + "description": "Json field Path as per CEF message which needs to be analyzed for TCA", + "constraints": [ + { + "valid_values": [ + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsDelta", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsAccumulated", + "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsAccumulated", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuIdle", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageInterrupt", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageNice", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSoftIrq", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSteal", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSystem", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuWait", + "$.event.measurementsForVfScalingFields.cpuUsageArray[*].percentUsage", + "$.event.measurementsForVfScalingFields.meanRequestLatency", + "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryBuffered", + "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryCached", + "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryConfigured", + "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryFree", + "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryUsed", + "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value" + ] + } + ] + }, + "severity": { + "type": "string", + "required": true, + "description": "Threshold Event Severity", + "constraints": [ + { + "valid_values": [ + "CRITICAL", + "MAJOR", + "MINOR", + "WARNING", + "NORMAL" + ] + } + ] + }, + "thresholdValue": { + "type": "integer", + "required": true, + "description": "Threshold value for the field Path inside CEF message" + }, + "version": { + "type": "string", + "required": true, + "description": "Version number associated with the threshold" + } + } + } +} -- cgit 1.2.3-korg