From 76a0b386bcf5f30533c85f6d26c559bea19ce0fb Mon Sep 17 00:00:00 2001 From: sebdet Date: Fri, 22 Jan 2021 17:26:04 +0100 Subject: Policy list and Pdpgroup merger code Draft code of the policy list/pdpgroup merger + tests, this code will most likely be called by a camel Rest route and the answer will be returned to the client/ui. The policies listing is enriched with new fields pdp group info, like: 1. In which Pdp group/Subgroup the policy is currently deployed 2. What are the potential pdpgroups/subgroups where the policy can be deployed These info will be shown in the policy clamp UI to the user. Also some refactoring has been done for the sake of clarity. Issue-ID: POLICY-2924 Signed-off-by: sebdet Change-Id: Iba1ab6fea90735551d7d2e2bbff9ab2efdee093e Signed-off-by: sebdet --- .../clamp/clds/client/PolicyEngineServices.java | 218 --------------------- .../org/onap/policy/clamp/loop/CsarInstaller.java | 4 +- .../clamp/loop/template/PolicyModelsService.java | 4 +- .../policy/clamp/policy/PolicyEngineServices.java | 213 ++++++++++++++++++++ .../policy/downloader/PolicyEngineController.java | 4 +- .../clamp/policy/pdpgroup/PdpGroupsAnalyzer.java | 79 ++++++-- .../clamp/policy/pdpgroup/PoliciesPdpMerger.java | 101 ++++++++++ .../resources/clds/camel/routes/policy-flows.xml | 6 +- .../policy/pdpgroup/PdpGroupAnalyzerTest.java | 82 ++++---- .../policy/pdpgroup/PoliciesPdpMergerTest.java | 102 ++++++++++ src/test/resources/clds/policy-merger.json | 215 ++++++++++++++++++++ .../example/policy/pap/v1/pdps/test.json | 152 -------------- 12 files changed, 745 insertions(+), 435 deletions(-) delete mode 100644 src/main/java/org/onap/policy/clamp/clds/client/PolicyEngineServices.java create mode 100644 src/main/java/org/onap/policy/clamp/policy/PolicyEngineServices.java create mode 100644 src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java create mode 100644 src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java create mode 100644 src/test/resources/clds/policy-merger.json delete mode 100644 src/test/resources/http-cache/example/policy/pap/v1/pdps/test.json diff --git a/src/main/java/org/onap/policy/clamp/clds/client/PolicyEngineServices.java b/src/main/java/org/onap/policy/clamp/clds/client/PolicyEngineServices.java deleted file mode 100644 index 46c55ea45..000000000 --- a/src/main/java/org/onap/policy/clamp/clds/client/PolicyEngineServices.java +++ /dev/null @@ -1,218 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.policy.clamp.clds.client; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import org.apache.camel.CamelContext; -import org.apache.camel.Exchange; -import org.apache.camel.builder.ExchangeBuilder; -import org.onap.policy.clamp.clds.config.ClampProperties; -import org.onap.policy.clamp.clds.sdc.controller.installer.BlueprintMicroService; -import org.onap.policy.clamp.clds.util.JsonUtils; -import org.onap.policy.clamp.loop.template.PolicyModel; -import org.onap.policy.clamp.loop.template.PolicyModelsService; -import org.onap.policy.models.pdp.concepts.PdpGroup; -import org.onap.policy.models.pdp.concepts.PdpGroups; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; - - -/** - * The class implements the communication with the Policy Engine to retrieve - * policy models (tosca). It mainly delegates the physical calls to Camel - * engine. - * It supports a retry mechanism for these calls, configurations can be specified in the - * application.properties "policy.retry.interval"(default 0) and "policy.retry.limit"(default 1). - */ -@Component -public class PolicyEngineServices { - private final CamelContext camelContext; - - private final PolicyModelsService policyModelsService; - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyEngineServices.class); - private static int retryInterval = 0; - private static int retryLimit = 1; - - public static final String POLICY_RETRY_INTERVAL = "policy.retry.interval"; - public static final String POLICY_RETRY_LIMIT = "policy.retry.limit"; - - /** - * Default constructor. - * - * @param camelContext Camel context bean - * @param clampProperties ClampProperties bean - * @param policyModelsService policyModel service - */ - @Autowired - public PolicyEngineServices(CamelContext camelContext, ClampProperties clampProperties, - PolicyModelsService policyModelsService) { - this.camelContext = camelContext; - this.policyModelsService = policyModelsService; - if (clampProperties.getStringValue(POLICY_RETRY_LIMIT) != null) { - retryLimit = Integer.parseInt(clampProperties.getStringValue(POLICY_RETRY_LIMIT)); - } - if (clampProperties.getStringValue(POLICY_RETRY_INTERVAL) != null) { - retryInterval = Integer.parseInt(clampProperties.getStringValue(POLICY_RETRY_INTERVAL)); - } - } - - /** - * This method query Policy engine and create a PolicyModel object with type and version. - * If the policy already exist in the db it returns the existing one. - * - * @param policyType The policyType id - * @param policyVersion The policy version of that type - * @return A PolicyModel created from policyEngine data or null if nothing is found on policyEngine - */ - public PolicyModel createPolicyModelFromPolicyEngine(String policyType, String policyVersion) { - PolicyModel policyModelFound = policyModelsService.getPolicyModel(policyType, policyVersion); - if (policyModelFound == null) { - String policyTosca = this.downloadOnePolicy(policyType, policyVersion); - if (policyTosca != null && !policyTosca.isEmpty()) { - return policyModelsService.savePolicyModelInNewTransaction( - new PolicyModel(policyType, policyTosca, policyVersion)); - } else { - logger.error("Policy not found in the Policy Engine, returning null: " + policyType - + "/" + policyVersion); - return null; - } - } else { - logger.info("Skipping policy model download as it exists already in the database " + policyType - + "/" + policyVersion); - return policyModelFound; - } - } - - /** - * This method query Policy engine and create a PolicyModel object with type and version. - * - * @param microService microservice object instance - * @return A PolicyModel created from policyEngine data - */ - public PolicyModel createPolicyModelFromPolicyEngine(BlueprintMicroService microService) { - return createPolicyModelFromPolicyEngine(microService.getModelType(), microService.getModelVersion()); - } - - /** - * This method synchronize the clamp database and the policy engine. - * So it creates the required PolicyModel. - */ - public void synchronizeAllPolicies() { - LinkedHashMap loadedYaml; - loadedYaml = new Yaml().load(downloadAllPolicies()); - if (loadedYaml == null || loadedYaml.isEmpty()) { - logger.warn("getAllPolicyType yaml returned by policy engine could not be decoded, as it's null or empty"); - return; - } - - LinkedHashMap policyTypesMap = (LinkedHashMap) loadedYaml - .get("policy_types"); - policyTypesMap.forEach((key, value) -> - this.createPolicyModelFromPolicyEngine(key, - ((String) ((LinkedHashMap) value).get("version")))); - } - - /** - * This method can be used to download all policy types + data types defined in - * policy engine. - * - * @return A yaml containing all policy Types and all data types - */ - public String downloadAllPolicies() { - return callCamelRoute(ExchangeBuilder.anExchange(camelContext).build(), "direct:get-all-policy-models", - "Get all policies"); - } - - /** - * This method can be used to download a policy tosca model on the engine. - * - * @param policyType The policy type (id) - * @param policyVersion The policy version - * @return A string with the whole policy tosca model - */ - public String downloadOnePolicy(String policyType, String policyVersion) { - logger.info("Downloading the policy model " + policyType + "/" + policyVersion); - DumperOptions options = new DumperOptions(); - options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN); - options.setIndent(4); - options.setPrettyFlow(true); - options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - Yaml yamlParser = new Yaml(options); - String responseBody = callCamelRoute( - ExchangeBuilder.anExchange(camelContext).withProperty("policyModelName", policyType) - .withProperty("policyModelVersion", policyVersion).build(), "direct:get-policy-model", - "Get one policy"); - - if (responseBody == null || responseBody.isEmpty()) { - logger.warn("getPolicyModel returned by policy engine could not be decoded, as it's null or empty"); - return null; - } - - return yamlParser.dump((Map) yamlParser.load(responseBody)); - } - - /** - * This method can be used to download all Pdp Groups data from policy engine. - */ - public void downloadPdpGroups() { - String responseBody = - callCamelRoute(ExchangeBuilder.anExchange(camelContext).build(), "direct:get-all-pdp-groups", - "Get Pdp Groups"); - - if (responseBody == null || responseBody.isEmpty()) { - logger.warn("getPdpGroups returned by policy engine could not be decoded, as it's null or empty"); - return; - } - - policyModelsService.updatePdpGroupInfo(JsonUtils.GSON.fromJson(responseBody, PdpGroups.class)); - } - - private String callCamelRoute(Exchange exchange, String camelFlow, String logMsg) { - for (int i = 0; i < retryLimit; i++) { - Exchange exchangeResponse = camelContext.createProducerTemplate().send(camelFlow, exchange); - if (Integer.valueOf(200).equals(exchangeResponse.getIn().getHeader("CamelHttpResponseCode"))) { - return (String) exchangeResponse.getIn().getBody(); - } else { - logger.info(logMsg + " query " + retryInterval + "ms before retrying ..."); - // wait for a while and try to connect to DCAE again - try { - Thread.sleep(retryInterval); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - } - return ""; - } -} diff --git a/src/main/java/org/onap/policy/clamp/loop/CsarInstaller.java b/src/main/java/org/onap/policy/clamp/loop/CsarInstaller.java index 753789a68..f46f4227b 100644 --- a/src/main/java/org/onap/policy/clamp/loop/CsarInstaller.java +++ b/src/main/java/org/onap/policy/clamp/loop/CsarInstaller.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +31,6 @@ import java.util.List; import java.util.Map.Entry; import org.json.simple.parser.ParseException; import org.onap.policy.clamp.clds.client.DcaeInventoryServices; -import org.onap.policy.clamp.clds.client.PolicyEngineServices; import org.onap.policy.clamp.clds.exception.sdc.controller.BlueprintParserException; import org.onap.policy.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; import org.onap.policy.clamp.clds.model.dcae.DcaeInventoryResponse; @@ -48,6 +47,7 @@ import org.onap.policy.clamp.loop.template.LoopTemplate; import org.onap.policy.clamp.loop.template.LoopTemplatesRepository; import org.onap.policy.clamp.loop.template.PolicyModel; import org.onap.policy.clamp.loop.template.PolicyModelsRepository; +import org.onap.policy.clamp.policy.PolicyEngineServices; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; diff --git a/src/main/java/org/onap/policy/clamp/loop/template/PolicyModelsService.java b/src/main/java/org/onap/policy/clamp/loop/template/PolicyModelsService.java index f0830360e..c4182bd2f 100644 --- a/src/main/java/org/onap/policy/clamp/loop/template/PolicyModelsService.java +++ b/src/main/java/org/onap/policy/clamp/loop/template/PolicyModelsService.java @@ -23,7 +23,6 @@ package org.onap.policy.clamp.loop.template; -import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.ArrayList; import java.util.Collections; @@ -32,7 +31,6 @@ import org.onap.policy.clamp.clds.tosca.ToscaSchemaConstants; import org.onap.policy.clamp.clds.tosca.ToscaYamlToJsonConvertor; import org.onap.policy.clamp.policy.pdpgroup.PdpGroupsAnalyzer; import org.onap.policy.clamp.util.SemanticVersioning; -import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpGroups; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -157,7 +155,7 @@ public class PolicyModelsService { */ public void updatePdpGroupInfo(PdpGroups pdpGroups) { List policyModelsList = policyModelsRepository.findAll(); - PdpGroupsAnalyzer.updatePdpGroup(policyModelsList, pdpGroups); + PdpGroupsAnalyzer.updatePdpGroupOfPolicyModels(policyModelsList, pdpGroups); this.policyModelsRepository.saveAll(policyModelsList); } } diff --git a/src/main/java/org/onap/policy/clamp/policy/PolicyEngineServices.java b/src/main/java/org/onap/policy/clamp/policy/PolicyEngineServices.java new file mode 100644 index 000000000..196642589 --- /dev/null +++ b/src/main/java/org/onap/policy/clamp/policy/PolicyEngineServices.java @@ -0,0 +1,213 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * + */ + +package org.onap.policy.clamp.policy; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import java.util.LinkedHashMap; +import java.util.Map; +import org.apache.camel.CamelContext; +import org.apache.camel.Exchange; +import org.apache.camel.builder.ExchangeBuilder; +import org.onap.policy.clamp.clds.config.ClampProperties; +import org.onap.policy.clamp.clds.sdc.controller.installer.BlueprintMicroService; +import org.onap.policy.clamp.clds.util.JsonUtils; +import org.onap.policy.clamp.loop.template.PolicyModel; +import org.onap.policy.clamp.loop.template.PolicyModelsService; +import org.onap.policy.models.pdp.concepts.PdpGroups; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; + + +/** + * The class implements the communication with the Policy Engine to retrieve + * policy models (tosca). It mainly delegates the physical calls to Camel + * engine. + * It supports a retry mechanism for these calls, configurations can be specified in the + * application.properties "policy.retry.interval"(default 0) and "policy.retry.limit"(default 1). + */ +@Component +public class PolicyEngineServices { + private final CamelContext camelContext; + + private final PolicyModelsService policyModelsService; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyEngineServices.class); + private static int retryInterval = 0; + private static int retryLimit = 1; + + public static final String POLICY_RETRY_INTERVAL = "policy.retry.interval"; + public static final String POLICY_RETRY_LIMIT = "policy.retry.limit"; + + /** + * Default constructor. + * + * @param camelContext Camel context bean + * @param clampProperties ClampProperties bean + * @param policyModelsService policyModel service + */ + @Autowired + public PolicyEngineServices(CamelContext camelContext, ClampProperties clampProperties, + PolicyModelsService policyModelsService) { + this.camelContext = camelContext; + this.policyModelsService = policyModelsService; + if (clampProperties.getStringValue(POLICY_RETRY_LIMIT) != null) { + retryLimit = Integer.parseInt(clampProperties.getStringValue(POLICY_RETRY_LIMIT)); + } + if (clampProperties.getStringValue(POLICY_RETRY_INTERVAL) != null) { + retryInterval = Integer.parseInt(clampProperties.getStringValue(POLICY_RETRY_INTERVAL)); + } + } + + /** + * This method query Policy engine and create a PolicyModel object with type and version. + * If the policy already exist in the db it returns the existing one. + * + * @param policyType The policyType id + * @param policyVersion The policy version of that type + * @return A PolicyModel created from policyEngine data or null if nothing is found on policyEngine + */ + public PolicyModel createPolicyModelFromPolicyEngine(String policyType, String policyVersion) { + PolicyModel policyModelFound = policyModelsService.getPolicyModel(policyType, policyVersion); + if (policyModelFound == null) { + String policyTosca = this.downloadOnePolicyToscaModel(policyType, policyVersion); + if (policyTosca != null && !policyTosca.isEmpty()) { + return policyModelsService.savePolicyModelInNewTransaction( + new PolicyModel(policyType, policyTosca, policyVersion)); + } else { + logger.error("Policy not found in the Policy Engine, returning null: " + policyType + + "/" + policyVersion); + return null; + } + } else { + logger.info("Skipping policy model download as it exists already in the database " + policyType + + "/" + policyVersion); + return policyModelFound; + } + } + + /** + * This method query Policy engine and create a PolicyModel object with type and version. + * + * @param microService microservice object instance + * @return A PolicyModel created from policyEngine data + */ + public PolicyModel createPolicyModelFromPolicyEngine(BlueprintMicroService microService) { + return createPolicyModelFromPolicyEngine(microService.getModelType(), microService.getModelVersion()); + } + + /** + * This method synchronize the clamp database and the policy engine. + * So it creates the required PolicyModel. + */ + public void synchronizeAllPolicies() { + LinkedHashMap loadedYaml; + loadedYaml = new Yaml().load(downloadAllPolicyModels()); + if (loadedYaml == null || loadedYaml.isEmpty()) { + logger.warn("getAllPolicyType yaml returned by policy engine could not be decoded, as it's null or empty"); + return; + } + + LinkedHashMap policyTypesMap = (LinkedHashMap) loadedYaml + .get("policy_types"); + policyTypesMap.forEach((key, value) -> + this.createPolicyModelFromPolicyEngine(key, + ((String) ((LinkedHashMap) value).get("version")))); + } + + /** + * This method can be used to download all policy types + data types defined in + * policy engine. + * + * @return A yaml containing all policy Types and all data types + */ + public String downloadAllPolicyModels() { + return callCamelRoute(ExchangeBuilder.anExchange(camelContext).build(), "direct:get-all-policy-models", + "Get all policies models"); + } + + /** + * This method can be used to download a policy tosca model on the engine. + * + * @param policyType The policy type (id) + * @param policyVersion The policy version + * @return A string with the whole policy tosca model + */ + public String downloadOnePolicyToscaModel(String policyType, String policyVersion) { + logger.info("Downloading the policy tosca model " + policyType + "/" + policyVersion); + DumperOptions options = new DumperOptions(); + options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN); + options.setIndent(4); + options.setPrettyFlow(true); + options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + Yaml yamlParser = new Yaml(options); + String responseBody = callCamelRoute( + ExchangeBuilder.anExchange(camelContext).withProperty("policyModelName", policyType) + .withProperty("policyModelVersion", policyVersion).build(), "direct:get-policy-tosca-model", + "Get one policy"); + + if (responseBody == null || responseBody.isEmpty()) { + logger.warn("getPolicyToscaModel returned by policy engine could not be decoded, as it's null or empty"); + return null; + } + + return yamlParser.dump((Map) yamlParser.load(responseBody)); + } + + /** + * This method can be used to download all Pdp Groups data from policy engine. + */ + public void downloadPdpGroups() { + String responseBody = + callCamelRoute(ExchangeBuilder.anExchange(camelContext).build(), "direct:get-all-pdp-groups", + "Get Pdp Groups"); + + if (responseBody == null || responseBody.isEmpty()) { + logger.warn("getPdpGroups returned by policy engine could not be decoded, as it's null or empty"); + return; + } + + policyModelsService.updatePdpGroupInfo(JsonUtils.GSON.fromJson(responseBody, PdpGroups.class)); + } + + private String callCamelRoute(Exchange exchange, String camelFlow, String logMsg) { + for (int i = 0; i < retryLimit; i++) { + Exchange exchangeResponse = camelContext.createProducerTemplate().send(camelFlow, exchange); + if (Integer.valueOf(200).equals(exchangeResponse.getIn().getHeader("CamelHttpResponseCode"))) { + return (String) exchangeResponse.getIn().getBody(); + } else { + logger.info(logMsg + " query " + retryInterval + "ms before retrying ..."); + // wait for a while and try to connect to DCAE again + try { + Thread.sleep(retryInterval); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + return ""; + } +} diff --git a/src/main/java/org/onap/policy/clamp/policy/downloader/PolicyEngineController.java b/src/main/java/org/onap/policy/clamp/policy/downloader/PolicyEngineController.java index 569678dc7..81775e5da 100644 --- a/src/main/java/org/onap/policy/clamp/policy/downloader/PolicyEngineController.java +++ b/src/main/java/org/onap/policy/clamp/policy/downloader/PolicyEngineController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,8 +27,8 @@ import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import java.time.Instant; import org.json.simple.parser.ParseException; -import org.onap.policy.clamp.clds.client.PolicyEngineServices; import org.onap.policy.clamp.loop.template.PolicyModelsRepository; +import org.onap.policy.clamp.policy.PolicyEngineServices; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; diff --git a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java index 51cdb149e..83ece5795 100644 --- a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java +++ b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * ONAP CLAMP + * ONAP POLICY-CLAMP * ================================================================================ * Copyright (C) 2021 AT&T Intellectual Property. All rights * reserved. @@ -27,19 +27,19 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; +import java.util.Optional; import org.onap.policy.clamp.loop.template.PolicyModel; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpGroups; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.pdp.enums.PdpState; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; -import org.onap.sdc.toscaparser.api.elements.PolicyType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; /** * This is an utility class to do searching in pdp groups. */ public class PdpGroupsAnalyzer { + /** * Get supported subGroups based on the defined policy type and version for s specific PDPgroup. * It returns null if the Group is not ACTIVE or if the policytype/version has not been found in the PDPSubgroups. @@ -51,7 +51,8 @@ public class PdpGroupsAnalyzer { * @see org.onap.policy.models.pdp.concepts.PdpGroup * @see org.onap.policy.models.pdp.enums.PdpState */ - private static JsonObject getSupportedSubgroups(PdpGroup pdpGroup, String policyType, String version) { + private static JsonObject getSupportedPdpSubgroupsForModelType(PdpGroup pdpGroup, String policyType, + String version) { if (!PdpState.ACTIVE.equals(pdpGroup.getPdpGroupState())) { return null; } @@ -65,10 +66,27 @@ public class PdpGroupsAnalyzer { supportedSubgroups.add(pdpSubGroup.getPdpType()); } }); - if (supportedSubgroups.size() == 0) { - return null; - } - return supportedPdpGroup; + return supportedSubgroups.size() == 0 ? null : supportedPdpGroup; + } + + /** + * This method retrieves all supported pdpGroups and subgroups for a specific policy type/version. + * + * @param pdpGroups The PdpGroups object containing all PEF pdp groups info + * @param policyType The policy type that must be used for searching + * @param version THe policy type version that must be used for searching + * @return It returns a JsonObject containing each pdpGroup and subgroups associated + */ + public static JsonObject getSupportedPdpGroupsForModelType(PdpGroups pdpGroups, String policyType, String version) { + JsonObject supportedPdpGroups = new JsonObject(); + JsonArray pdpGroupsArray = new JsonArray(); + supportedPdpGroups.add("supportedPdpGroups", pdpGroupsArray); + + pdpGroups.getGroups().stream().map(pdpGroup -> PdpGroupsAnalyzer.getSupportedPdpSubgroupsForModelType(pdpGroup, + policyType, version)).filter(Objects::nonNull) + .forEach(jsonPdpGroup -> pdpGroupsArray.add(jsonPdpGroup)); + + return pdpGroupsArray.size() != 0 ? supportedPdpGroups : null; } /** @@ -77,18 +95,39 @@ public class PdpGroupsAnalyzer { * @param policyModelsList The list of Policy Models where each PolicyModel will be updated * @param pdpGroups The PdpGroups containing all PDP group definition */ - public static void updatePdpGroup(List policyModelsList, PdpGroups pdpGroups) { + public static void updatePdpGroupOfPolicyModels(List policyModelsList, PdpGroups pdpGroups) { policyModelsList.parallelStream().forEach(policyModel -> { - JsonObject jsonResult = new JsonObject(); - JsonArray supportedPdpGroups = new JsonArray(); - jsonResult.add("supportedPdpGroups", supportedPdpGroups); - policyModel.setPolicyPdpGroup(jsonResult); - pdpGroups.getGroups().stream().map(pdpGroup -> PdpGroupsAnalyzer.getSupportedSubgroups(pdpGroup, - policyModel.getPolicyModelType(), policyModel.getVersion())).filter(Objects::nonNull) - .forEach(jsonPdpGroup -> supportedPdpGroups.add(jsonPdpGroup)); - if (supportedPdpGroups.size() == 0) { - policyModel.setPolicyPdpGroup(null); - } + policyModel.setPolicyPdpGroup(getSupportedPdpGroupsForModelType(pdpGroups, policyModel.getPolicyModelType(), + policyModel.getVersion())); }); } + + /** + * This method searches for the PdpGroup/subgroup where the policy given is currently deployed. + * + * @param pdpGroups The pdpGroups info from PEF + * @param policyName The policy Id + * @param version The policy version + * @return It returns a JsonObject containing the pdpGroup/subgroup info + */ + public static JsonObject getPdpGroupDeploymentOfOnePolicy(PdpGroups pdpGroups, String policyName, String version) { + JsonObject pdpGroupInfo = new JsonObject(); + JsonObject assignedPdpGroups = new JsonObject(); + pdpGroupInfo.add("pdpGroupInfo", assignedPdpGroups); + + ToscaPolicyIdentifier toscaPolicyIdentifier = new ToscaPolicyIdentifier(policyName, version); + pdpGroups.getGroups().stream().anyMatch(pdpGroup -> + pdpGroup.getPdpSubgroups().stream().anyMatch( + pdpSubGroup -> { + if (pdpSubGroup.getPolicies() != null && pdpSubGroup.getPolicies() + .contains(toscaPolicyIdentifier)) { + assignedPdpGroups.addProperty("pdpGroup", pdpGroup.getName()); + assignedPdpGroups.addProperty("pdpSubGroup", pdpSubGroup.getPdpType()); + return true; + } + return false; + }) + ); + return assignedPdpGroups.entrySet().isEmpty() ? null : pdpGroupInfo; + } } \ No newline at end of file diff --git a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java new file mode 100644 index 000000000..4b94355ee --- /dev/null +++ b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP POLICY-CLAMP + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * + */ + +package org.onap.policy.clamp.policy.pdpgroup; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import java.util.Map; +import java.util.stream.StreamSupport; +import org.onap.policy.clamp.clds.util.JsonUtils; +import org.onap.policy.models.pdp.concepts.PdpGroups; + +/** + * This is an utility class that contains methods to work on the different results provided by the PEF. + * Mainly used to aggregate the results. + */ +public class PoliciesPdpMerger { + + /** + * This method extract the content of a policy without knowing the key (policy Id). + * This JsonElement normally contains only the policy ID then the content, + * there is only one member in the Json element. + * + * @param policyJsonElement The policy as JsonElement + * @return It return the content as JsonObject + */ + public static JsonObject getPolicyContentOutOfJsonElement(JsonElement policyJsonElement) { + return policyJsonElement.getAsJsonObject() + .get(((String) policyJsonElement.getAsJsonObject().keySet().toArray()[0])).getAsJsonObject(); + } + + /** + * This method merges 2 JsonElement together. If the jsonToMerge is null nothign is changed. + * + * @param json The initial json that will received the data + * @param jsonToMerge The json that will be added to the first json object + */ + public static void mergeJsonElement(JsonObject json, JsonObject jsonToMerge) { + if (jsonToMerge != null) { + jsonToMerge.entrySet().stream().forEach(entry -> json.add(entry.getKey(), entry.getValue())); + } + } + + /** + * This method merges the result of the policy listing and the associated Pdp Group info. + * It can be seen as an enrichment of the policy listing. + * + * @param jsonPoliciesList The Json containing the policies from the PEF + * @param pdpGroupsJson The json containing the PDP groups info from the PEF + * @return It returns a String containing the policies list enriched with PdpGroup info + */ + public static String mergePoliciesAndPdpGroupStates(String jsonPoliciesList, String pdpGroupsJson) { + PdpGroups pdpGroups = JsonUtils.GSON.fromJson(pdpGroupsJson, PdpGroups.class); + JsonObject policiesListJson = + JsonUtils.GSON.fromJson(jsonPoliciesList, JsonObject.class).get("topology_template") + .getAsJsonObject(); + StreamSupport.stream(policiesListJson.get("policies").getAsJsonArray().spliterator(), true) + .forEach(policyJson -> enrichOnePolicy(pdpGroups, getPolicyContentOutOfJsonElement(policyJson))); + return policiesListJson.toString(); + } + + /** + * Enrich one policy json node object with pdpGroup info. + * + * @param pdpGroups The pdpGroups from PEF to search the policy + * @param policyJsonNode The policy json node that must be enriched + */ + private static void enrichOnePolicy(PdpGroups pdpGroups, JsonObject policyJsonNode) { + JsonObject deploymentPdpJson = PdpGroupsAnalyzer + .getPdpGroupDeploymentOfOnePolicy(pdpGroups, policyJsonNode.get("name").getAsString(), + policyJsonNode.get("version").getAsString()); + mergeJsonElement(policyJsonNode, deploymentPdpJson); + + JsonObject supportedPdpGroupsJson = PdpGroupsAnalyzer + .getSupportedPdpGroupsForModelType(pdpGroups, policyJsonNode.get("type").getAsString(), + policyJsonNode.get("type_version").getAsString()); + mergeJsonElement(policyJsonNode, supportedPdpGroupsJson); + } +} diff --git a/src/main/resources/clds/camel/routes/policy-flows.xml b/src/main/resources/clds/camel/routes/policy-flows.xml index 4d1eba614..7048a5e03 100644 --- a/src/main/resources/clds/camel/routes/policy-flows.xml +++ b/src/main/resources/clds/camel/routes/policy-flows.xml @@ -170,11 +170,11 @@ - - + + + message="Getting the policy tosca model: ${exchangeProperty[policyModelName]}/${exchangeProperty[policyModelVersion]}"/> diff --git a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java index 1af048da5..5a9cac07b 100644 --- a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java +++ b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * ONAP CLAMP + * ONAP POLICY-CLAMP * ================================================================================ * Copyright (C) 2021 AT&T Intellectual Property. All rights * reserved. @@ -25,19 +25,15 @@ package org.onap.policy.clamp.policy.pdpgroup; import static org.assertj.core.api.Assertions.assertThat; -import com.google.gson.Gson; -import com.google.gson.JsonObject; import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import javax.transaction.Transactional; +import org.junit.BeforeClass; import org.junit.Test; -import org.onap.policy.clamp.clds.util.JsonUtils; import org.onap.policy.clamp.loop.template.PolicyModel; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpGroups; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.pdp.enums.PdpState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; /** @@ -45,33 +41,13 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifi */ public class PdpGroupAnalyzerTest { - private PolicyModel createPolicyModel(String policyType, String policyModelTosca, String version, - String policyAcronym, String policyVariant, String createdBy) { - PolicyModel policyModel = new PolicyModel(); - policyModel.setCreatedBy(createdBy); - policyModel.setPolicyAcronym(policyAcronym); - policyModel.setPolicyModelTosca(policyModelTosca); - policyModel.setPolicyModelType(policyType); - policyModel.setUpdatedBy(createdBy); - policyModel.setVersion(version); - return policyModel; - } + private static PdpGroups pdpGroups; /** - * This tests the pdpgroup GSON encode/decode and saving. + * This method preloads the pdpGroups for the tests. */ - @Test - @Transactional - public void testUpdatePdpGroup() { - // Create policyModel - PolicyModel policyModel = new PolicyModel(); - policyModel.setCreatedBy("user"); - policyModel.setPolicyAcronym("TEST"); - policyModel.setPolicyModelTosca("yaml"); - policyModel.setPolicyModelType("org.onap.test"); - policyModel.setUpdatedBy("user"); - policyModel.setVersion("1.0.0"); - + @BeforeClass + public static void setupPdpGroup() { // Create Pdp Groups // Those that do not work first PdpSubGroup pdpSubgroupBad = new PdpSubGroup(); @@ -83,7 +59,11 @@ public class PdpGroupAnalyzerTest { new ToscaPolicyTypeIdentifier("org.onap.tes", "1.0.0"), new ToscaPolicyTypeIdentifier("org.onap", "1.0.0") )); - + pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaPolicyIdentifier("org.onap", "1.0.0"))); + pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaPolicyIdentifier("org.onap.testos", "2.0.0"))); + pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaPolicyIdentifier("org.onap.testos", "1.0.1"))); + pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaPolicyIdentifier("org.onap.testos.new", "1.0.0"))); + pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaPolicyIdentifier("org.onap.*", "1.0.0"))); PdpSubGroup pdpSubgroup1 = new PdpSubGroup(); pdpSubgroup1.setPdpType("subGroup1"); @@ -93,38 +73,70 @@ public class PdpGroupAnalyzerTest { PdpSubGroup pdpSubgroup2 = new PdpSubGroup(); pdpSubgroup2.setPdpType("subGroup2"); pdpSubgroup2.setSupportedPolicyTypes(Arrays.asList(new ToscaPolicyTypeIdentifier("org.onap.test", "1.0.0"))); + pdpSubgroup2.setPolicies(Arrays.asList(new ToscaPolicyIdentifier("org.onap.testos", "1.0.0"))); PdpSubGroup pdpSubgroup3 = new PdpSubGroup(); pdpSubgroup3.setPdpType("subGroup3"); pdpSubgroup3.setSupportedPolicyTypes(Arrays.asList(new ToscaPolicyTypeIdentifier("org.onap.test*", "1.0.0"))); + pdpSubgroup3.setPolicies(Arrays.asList(new ToscaPolicyIdentifier("org.onap.testos", "2.0.0"))); - + // Should match pdpSubgroup1 PdpGroup pdpGroup1 = new PdpGroup(); pdpGroup1.setName("pdpGroup1"); pdpGroup1.setPdpGroupState(PdpState.ACTIVE); pdpGroup1.setPdpSubgroups(Arrays.asList(pdpSubgroup1, pdpSubgroupBad)); + // Should match pdpSubgroup1, pdpSubgroup2, pdpSubgroup3 + // Should match also for the policy (pdpSubgroup2) PdpGroup pdpGroup2 = new PdpGroup(); pdpGroup2.setName("pdpGroup2"); pdpGroup2.setPdpGroupState(PdpState.ACTIVE); pdpGroup2.setPdpSubgroups(Arrays.asList(pdpSubgroup1, pdpSubgroup2, pdpSubgroup3, pdpSubgroupBad)); + /// Should not match PdpGroup pdpGroup3 = new PdpGroup(); pdpGroup3.setName("pdpGroup3"); pdpGroup3.setPdpGroupState(PdpState.ACTIVE); pdpGroup3.setPdpSubgroups(Arrays.asList(pdpSubgroupBad)); + // Should not match PdpGroup pdpGroup4 = new PdpGroup(); pdpGroup4.setName("pdpGroup4"); pdpGroup4.setPdpGroupState(PdpState.PASSIVE); pdpGroup4.setPdpSubgroups(Arrays.asList(pdpSubgroup1)); - PdpGroups pdpGroups = new PdpGroups(); + pdpGroups = new PdpGroups(); pdpGroups.setGroups(Arrays.asList(pdpGroup1, pdpGroup2, pdpGroup3, pdpGroup4)); - PdpGroupsAnalyzer.updatePdpGroup(Arrays.asList(policyModel), pdpGroups); + } + + @Test + public void testUpdatePdpGroupOfPolicyModels() { + // Create policyModel + PolicyModel policyModel = new PolicyModel(); + policyModel.setCreatedBy("user"); + policyModel.setPolicyAcronym("TEST"); + policyModel.setPolicyModelTosca("yaml"); + policyModel.setPolicyModelType("org.onap.test"); + policyModel.setUpdatedBy("user"); + policyModel.setVersion("1.0.0"); + PdpGroupsAnalyzer.updatePdpGroupOfPolicyModels(Arrays.asList(policyModel), pdpGroups); assertThat(policyModel.getPolicyPdpGroup().toString()).isEqualTo( "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]}," + "{\"pdpGroup2\":[\"subGroup1\",\"subGroup2\",\"subGroup3\"]}]}"); } + + @Test + public void testGetPdpGroupDeploymentsOfOnePolicy() { + assertThat( + PdpGroupsAnalyzer.getPdpGroupDeploymentOfOnePolicy(pdpGroups, "org.onap.testos", "1.0.0").toString()) + .isEqualTo("{\"pdpGroupInfo\":{\"pdpGroup\":\"pdpGroup2\",\"pdpSubGroup\":\"subGroup2\"}}"); + } + + @Test + public void testGetPdpGroupDeploymentsOfOnePolicyNull() { + assertThat( + PdpGroupsAnalyzer.getPdpGroupDeploymentOfOnePolicy(pdpGroups, "org.onap.DoNotExist", "1.0.0")) + .isNull(); + } } diff --git a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java new file mode 100644 index 000000000..b3fd3f19a --- /dev/null +++ b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP POLICY-CLAMP + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * + */ + +package org.onap.policy.clamp.policy.pdpgroup; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.util.Arrays; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.clamp.clds.util.JsonUtils; +import org.onap.policy.clamp.clds.util.ResourceFileUtils; +import org.onap.policy.models.pdp.concepts.PdpGroup; +import org.onap.policy.models.pdp.concepts.PdpGroups; +import org.onap.policy.models.pdp.concepts.PdpSubGroup; +import org.onap.policy.models.pdp.enums.PdpState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; +import org.skyscreamer.jsonassert.JSONAssert; + +/** + * This test class validates the PdpGroupAnalyzer class. + */ +public class PoliciesPdpMergerTest { + + private static String pdpGroupsJson; + + /** + * This method setups the pdpGroups required for the tests. + */ + @BeforeClass + public static void setupPdpGroup() { + // Create Pdp Groups + PdpSubGroup pdpSubgroup1 = new PdpSubGroup(); + pdpSubgroup1.setPdpType("subGroup1"); + pdpSubgroup1.setSupportedPolicyTypes( + Arrays.asList(new ToscaPolicyTypeIdentifier("org.onap.*", "1.0.0"))); + + PdpSubGroup pdpSubgroup2 = new PdpSubGroup(); + pdpSubgroup2.setPdpType("subGroup2"); + pdpSubgroup2.setSupportedPolicyTypes( + Arrays.asList(new ToscaPolicyTypeIdentifier("onap.policies.monitoring.tcagen2", "1.0.0"), + new ToscaPolicyTypeIdentifier("onap.policies.controlloop.operational.common.Drools", "1.0.0"))); + pdpSubgroup2.setPolicies(Arrays.asList( + new ToscaPolicyIdentifier("MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0", "1.0.0"))); + + PdpSubGroup pdpSubgroup3 = new PdpSubGroup(); + pdpSubgroup3.setPdpType("subGroup3"); + pdpSubgroup3.setSupportedPolicyTypes( + Arrays.asList(new ToscaPolicyTypeIdentifier("onap.policies.monitoring.tcagen2", "1.0.0"), + new ToscaPolicyTypeIdentifier("onap.policies.controlloop.operational.common.Drools", "1.0.0"))); + pdpSubgroup3.setPolicies(Arrays.asList(new ToscaPolicyIdentifier("org.onap.testos", "2.0.0"), + new ToscaPolicyIdentifier("OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd", "1.0.0"))); + + // Should match pdpSubgroup1 + PdpGroup pdpGroup1 = new PdpGroup(); + pdpGroup1.setName("pdpGroup1"); + pdpGroup1.setPdpGroupState(PdpState.ACTIVE); + pdpGroup1.setPdpSubgroups(Arrays.asList(pdpSubgroup1)); + + // Should match pdpSubgroup1, pdpSubgroup2, pdpSubgroup3 + // Should match also for the policy (pdpSubgroup2) + PdpGroup pdpGroup2 = new PdpGroup(); + pdpGroup2.setName("pdpGroup2"); + pdpGroup2.setPdpGroupState(PdpState.ACTIVE); + pdpGroup2.setPdpSubgroups(Arrays.asList(pdpSubgroup1, pdpSubgroup2, pdpSubgroup3)); + + PdpGroups pdpGroups = new PdpGroups(); + pdpGroups.setGroups(Arrays.asList(pdpGroup1, pdpGroup2)); + + pdpGroupsJson = JsonUtils.GSON.toJson(pdpGroups); + } + + @Test + public void testUpdatePdpGroupOfPolicyModels() throws IOException { + JSONAssert.assertEquals(ResourceFileUtils.getResourceAsString("clds/policy-merger.json"), PoliciesPdpMerger + .mergePoliciesAndPdpGroupStates( + ResourceFileUtils.getResourceAsString("http-cache/example/policy/api/v1/policies/.file"), + pdpGroupsJson), true); + } +} diff --git a/src/test/resources/clds/policy-merger.json b/src/test/resources/clds/policy-merger.json new file mode 100644 index 000000000..5c6bd5b6b --- /dev/null +++ b/src/test/resources/clds/policy-merger.json @@ -0,0 +1,215 @@ +{ + "policies": [ + { + "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0": { + "type": "onap.policies.monitoring.tcagen2", + "type_version": "1.0.0", + "properties": { + "tca.policy": { + "domain": "measurementsForVfScaling", + "metricsPerEventName": [ + { + "policyScope": "DCAE", + "thresholds": [ + { + "version": "1.0.2", + "severity": "MAJOR", + "thresholdValue": 200, + "closedLoopEventStatus": "ONSET", + "closedLoopControlName": "LOOP_test", + "direction": "LESS_OR_EQUAL", + "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta" + } + ], + "eventName": "vLoadBalancer", + "policyVersion": "v0.0.1", + "controlLoopSchemaType": "VM", + "policyName": "DCAE.Config_tca-hi-lo" + } + ] + } + }, + "name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0", + "version": "1.0.0", + "metadata": { + "policy-id": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0", + "policy-version": "1.0.0" + }, + "pdpGroupInfo": { + "pdpGroup": "pdpGroup2", + "pdpSubGroup": "subGroup2" + }, + "supportedPdpGroups": [ + { + "pdpGroup2": [ + "subGroup2", + "subGroup3" + ] + } + ] + } + }, + { + "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd": { + "type": "onap.policies.controlloop.operational.common.Drools", + "type_version": "1.0.0", + "properties": { + "abatement": false, + "operations": [ + { + "failure_retries": "final_failure_retries", + "id": "test1", + "failure_timeout": "final_failure_timeout", + "failure": "final_failure", + "operation": { + "payload": { + "artifact_name": "baseconfiguration", + "artifact_version": "1.0.0", + "mode": "async", + "data": "{\"resource-assignment-properties\":{\"request-id\":\"\",\"service-instance-id\":\"\",\"hostname\":\"\",\"request-info\":{\"prop1\":\"\",\"prop2\":\"\"}}}" + }, + "target": { + "entityIds": { + "resourceID": "Vloadbalancerms..vdns..module-3", + "modelInvariantId": "4c10ba9b-f88f-415e-9de3-5d33336047fa", + "modelVersionId": "4fa73b49-8a6c-493e-816b-eb401567b720", + "modelName": "Vloadbalancerms..vdns..module-3", + "modelVersion": "1", + "modelCustomizationId": "bafcdab0-801d-4d81-9ead-f464640a38b1" + }, + "targetType": "VNF" + }, + "actor": "SDNR", + "operation": "BandwidthOnDemand" + }, + "failure_guard": "final_failure_guard", + "retries": 0, + "timeout": 0, + "failure_exception": "final_failure_exception", + "description": "test", + "success": "final_success" + } + ], + "trigger": "test1", + "timeout": 0, + "id": "LOOP_test" + }, + "name": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd", + "version": "1.0.0", + "metadata": { + "policy-id": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd", + "policy-version": "1.0.0" + }, + "pdpGroupInfo": { + "pdpGroup": "pdpGroup2", + "pdpSubGroup": "subGroup3" + }, + "supportedPdpGroups": [ + { + "pdpGroup2": [ + "subGroup2", + "subGroup3" + ] + } + ] + } + }, + { + "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP": { + "type": "onap.policies.Naming", + "type_version": "1.0.0", + "properties": { + "naming-models": [ + { + "naming-type": "VNF", + "naming-recipe": "AIC_CLOUD_REGION|DELIMITER|CONSTANT|DELIMITER|TIMESTAMP", + "name-operation": "to_lower_case()", + "naming-properties": [ + { + "property-name": "AIC_CLOUD_REGION" + }, + { + "property-name": "CONSTANT", + "property-value": "onap-nf" + }, + { + "property-name": "TIMESTAMP" + }, + { + "property-value": "-", + "property-name": "DELIMITER" + } + ] + }, + { + "naming-type": "VNFC", + "naming-recipe": "VNF_NAME|DELIMITER|NFC_NAMING_CODE|DELIMITER|SEQUENCE", + "name-operation": "to_lower_case()", + "naming-properties": [ + { + "property-name": "VNF_NAME" + }, + { + "property-name": "SEQUENCE", + "increment-sequence": { + "max": "zzz", + "scope": "ENTIRETY", + "start-value": "1", + "length": "3", + "increment": "1", + "sequence-type": "alpha-numeric" + } + }, + { + "property-name": "NFC_NAMING_CODE" + }, + { + "property-value": "-", + "property-name": "DELIMITER" + } + ] + }, + { + "naming-type": "VF-MODULE", + "naming-recipe": "VNF_NAME|DELIMITER|VF_MODULE_LABEL|DELIMITER|VF_MODULE_TYPE|DELIMITER|SEQUENCE", + "name-operation": "to_lower_case()", + "naming-properties": [ + { + "property-name": "VNF_NAME" + }, + { + "property-value": "-", + "property-name": "DELIMITER" + }, + { + "property-name": "VF_MODULE_LABEL" + }, + { + "property-name": "VF_MODULE_TYPE" + }, + { + "property-name": "SEQUENCE", + "increment-sequence": { + "max": "zzz", + "scope": "PRECEEDING", + "start-value": "1", + "length": "3", + "increment": "1", + "sequence-type": "alpha-numeric" + } + } + ] + } + ], + "policy-instance-name": "ONAP_NF_NAMING_TIMESTAMP" + }, + "name": "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", + "version": "1.0.0", + "metadata": { + "policy-id": "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", + "policy-version": "1.0.0" + } + } + } + ] +} \ No newline at end of file diff --git a/src/test/resources/http-cache/example/policy/pap/v1/pdps/test.json b/src/test/resources/http-cache/example/policy/pap/v1/pdps/test.json deleted file mode 100644 index c22508441..000000000 --- a/src/test/resources/http-cache/example/policy/pap/v1/pdps/test.json +++ /dev/null @@ -1,152 +0,0 @@ -{ - "groups": [ - { - "name": "defaultGroup", - "description": "The default group that registers all supported policy types and pdps.", - "pdpGroupState": "ACTIVE", - "properties": {}, - "pdpSubgroups": [ - { - "pdpType": "apex", - "supportedPolicyTypes": [ - { - "name": "onap.policies.controlloop.operational.common.Apex", - "version": "1.0.0" - }, - { - "name": "onap.policies.native.Apex", - "version": "1.0.0" - } - ], - "policies": [], - "currentInstanceCount": 0, - "desiredInstanceCount": 1, - "properties": {}, - "pdpInstances": [] - }, - { - "pdpType": "drools", - "supportedPolicyTypes": [ - { - "name": "onap.policies.controlloop.operational.common.Drools", - "version": "1.0.0" - }, - { - "name": "onap.policies.native.drools.Controller", - "version": "1.0.0" - }, - { - "name": "onap.policies.native.drools.Artifact", - "version": "1.0.0" - } - ], - "policies": [ - { - "name": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd", - "version": "1.0.0" - } - ], - "currentInstanceCount": 0, - "desiredInstanceCount": 1, - "properties": {}, - "pdpInstances": [] - }, - { - "pdpType": "xacml", - "supportedPolicyTypes": [ - { - "name": "onap.policies.controlloop.guard.common.FrequencyLimiter", - "version": "1.0.0" - }, - { - "name": "onap.policies.controlloop.guard.common.MinMax", - "version": "1.0.0" - }, - { - "name": "onap.policies.controlloop.guard.common.Blacklist", - "version": "1.0.0" - }, - { - "name": "onap.policies.controlloop.guard.common.Filter", - "version": "1.0.0" - }, - { - "name": "onap.policies.controlloop.guard.coordination.FirstBlocksSecond", - "version": "1.0.0" - }, - { - "name": "onap.policies.monitoring.*", - "version": "1.0.0" - }, - { - "name": "onap.policies.optimization.*", - "version": "1.0.0" - }, - { - "name": "onap.policies.optimization.resource.AffinityPolicy", - "version": "1.0.0" - }, - { - "name": "onap.policies.optimization.resource.DistancePolicy", - "version": "1.0.0" - }, - { - "name": "onap.policies.optimization.resource.HpaPolicy", - "version": "1.0.0" - }, - { - "name": "onap.policies.optimization.resource.OptimizationPolicy", - "version": "1.0.0" - }, - { - "name": "onap.policies.optimization.resource.PciPolicy", - "version": "1.0.0" - }, - { - "name": "onap.policies.optimization.service.QueryPolicy", - "version": "1.0.0" - }, - { - "name": "onap.policies.optimization.service.SubscriberPolicy", - "version": "1.0.0" - }, - { - "name": "onap.policies.optimization.resource.Vim_fit", - "version": "1.0.0" - }, - { - "name": "onap.policies.optimization.resource.VnfPolicy", - "version": "1.0.0" - }, - { - "name": "onap.policies.native.Xacml", - "version": "1.0.0" - }, - { - "name": "onap.policies.Naming", - "version": "1.0.0" - }, - { - "name": "onap.policies.match.*", - "version": "1.0.0" - } - ], - "policies": [ - { - "name": "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", - "version": "1.0.0" - }, - { - "name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0", - "version": "1.0.0" - } - ], - "currentInstanceCount": 0, - "desiredInstanceCount": 1, - "properties": {}, - "pdpInstances": [] - } - ] - } - ] -} \ No newline at end of file -- cgit 1.2.3-korg