diff options
8 files changed, 164 insertions, 29 deletions
diff --git a/models-examples/src/main/resources/policies/vCPE.policy.operational.input.tosca.json b/models-examples/src/main/resources/policies/vCPE.policy.operational.input.tosca.json new file mode 100644 index 000000000..793334e4e --- /dev/null +++ b/models-examples/src/main/resources/policies/vCPE.policy.operational.input.tosca.json @@ -0,0 +1,45 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_0_0", + "topology_template": { + "policies": [ + { + "operational.restart": { + "type": "onap.policies.controlloop.operational.common.Drools", + "type_version": "1.0.0", + "version": "1.0.0", + "metadata": { + "policy-id": "operational.restart" + }, + "properties": { + "id": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "timeout": 3600, + "abatement": true, + "trigger": "unique-policy-id-1-restart", + "operations": [ + { + "id": "unique-policy-id-1-restart", + "description": "Restart the VM", + "operation": { + "actor": "APPC", + "recipe": "Restart", + "target": { + "type": "VNF" + } + }, + "timeout": 1200, + "retries": 3, + "success": "final_success", + "failure": "final_failure", + "failure_timeout": "final_failure_timeout", + "failure_retries": "final_failure_retries", + "failure_exception": "final_failure_exception", + "failure_guard": "final_failure_guard" + } + ], + "controllerName": "usecases" + } + } + } + ] + } +}
\ No newline at end of file diff --git a/models-examples/src/main/resources/policies/vCPE.policy.operational.input.tosca.yaml b/models-examples/src/main/resources/policies/vCPE.policy.operational.input.tosca.yaml index e013abd1c..0f669d9ca 100644 --- a/models-examples/src/main/resources/policies/vCPE.policy.operational.input.tosca.yaml +++ b/models-examples/src/main/resources/policies/vCPE.policy.operational.input.tosca.yaml @@ -4,6 +4,7 @@ topology_template: - operational.restart: type: onap.policies.controlloop.operational.common.Drools type_version: 1.0.0 + version: 1.0.0 metadata: policy-id: operational.restart properties: diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java index 6d5f804f8..b6886bef1 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -81,9 +81,10 @@ public class PdpGroup implements PfNameVersion, Comparable<PdpGroup> { /** * Validates that appropriate fields are populated for an incoming call to the PAP REST API. * + * @param updateGroupFlow if the operation is pdp group update * @return the validation result */ - public ValidationResult validatePapRest() { + public ValidationResult validatePapRest(boolean updateGroupFlow) { BeanValidationResult result = new BeanValidationResult("group", this); /* @@ -91,7 +92,8 @@ public class PdpGroup implements PfNameVersion, Comparable<PdpGroup> { */ result.validateNotNull("name", name); - result.validateNotNullList(SUBGROUP_FIELD, pdpSubgroups, PdpSubGroup::validatePapRest); + result.validateNotNullList(SUBGROUP_FIELD, pdpSubgroups, + (PdpSubGroup pdpSubGroup) -> pdpSubGroup.validatePapRest(updateGroupFlow)); if (pdpSubgroups != null && pdpSubgroups.isEmpty()) { result.addResult(new ObjectValidationResult(SUBGROUP_FIELD, pdpSubgroups, ValidationStatus.INVALID, diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java index 06194eaba..6729d7e88 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java @@ -3,6 +3,7 @@ * ONAP Policy Models * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,20 +67,33 @@ public class PdpGroups { * @return the validation result */ public ValidationResult validatePapRest() { - BeanValidationResult result = new BeanValidationResult(GROUPS_FIELD, this); - - result.validateNotNullList(GROUPS_FIELD, groups, PdpGroup::validatePapRest); + ValidationResult result = new BeanValidationResult(GROUPS_FIELD, this); + ((BeanValidationResult) result).validateNotNullList(GROUPS_FIELD, groups, + (PdpGroup pdpGroup) -> pdpGroup.validatePapRest(false)); if (!result.isValid()) { return result; } // verify that the same group doesn't appear more than once - List<String> names = groups.stream().map(PdpGroup::getName).collect(Collectors.toList()); - if (groups.size() == new HashSet<>(names).size()) { - return result; - } + return checkForDuplicateGroups(result); + } - // different sizes implies duplicates - return new ObjectValidationResult(GROUPS_FIELD, names, ValidationStatus.INVALID, "duplicate group names"); + /** + * Validates that there are no duplicate PdpGroups with the same name. + * + * @param result the validation result + * @return the validation result + */ + public ValidationResult checkForDuplicateGroups(ValidationResult result) { + if (null == groups) { + result.setResult(ValidationStatus.INVALID, "is null"); + } else { + List<String> names = groups.stream().map(PdpGroup::getName).collect(Collectors.toList()); + if (groups.size() != new HashSet<>(names).size()) { + result = + new ObjectValidationResult(GROUPS_FIELD, names, ValidationStatus.INVALID, "duplicate group names"); + } + } + return result; } } diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java index 236cc858a..e3e33b454 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -78,19 +78,23 @@ public class PdpSubGroup { * Validates that appropriate fields are populated for an incoming call to the PAP * REST API. * + * @param updateGroupFlow if the operation is pdp group update * @return the validation result */ - public ValidationResult validatePapRest() { + public ValidationResult validatePapRest(boolean updateGroupFlow) { BeanValidationResult result = new BeanValidationResult("group", this); result.validateNotNull("pdpType", pdpType); - result.validateNotNullList("supportedPolicyTypes", supportedPolicyTypes, - ToscaPolicyTypeIdentifier::validatePapRest); - result.validateNotNullList("policies", policies, ToscaPolicyIdentifier::validatePapRest); + // When doing PdpGroup Update operation, supported policy types and policies doesn't have to be validated. + if (!updateGroupFlow) { + result.validateNotNullList("policies", policies, ToscaPolicyIdentifier::validatePapRest); + result.validateNotNullList("supportedPolicyTypes", supportedPolicyTypes, + ToscaPolicyTypeIdentifier::validatePapRest); - if (supportedPolicyTypes != null && supportedPolicyTypes.isEmpty()) { - result.addResult(new ObjectValidationResult("supportedPolicyTypes", supportedPolicyTypes, - ValidationStatus.INVALID, "empty list")); + if (supportedPolicyTypes != null && supportedPolicyTypes.isEmpty()) { + result.addResult(new ObjectValidationResult("supportedPolicyTypes", supportedPolicyTypes, + ValidationStatus.INVALID, "empty list")); + } } if (desiredInstanceCount <= 0) { diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java index a282b7dba..4f11079c2 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java @@ -3,7 +3,7 @@ * ONAP Policy Models * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -121,6 +121,42 @@ public class PdpGroupTest { } @Test + public void testValidatePapRest_GroupUpdateFlow() { + PdpGroup group = new PdpGroup(); + group.setName(NAME); + // with supported policy type and policies + PdpSubGroup subgroup1 = new PdpSubGroup(); + subgroup1.setDesiredInstanceCount(1); + subgroup1.setPdpType(PDP_TYPE1); + subgroup1.setSupportedPolicyTypes(Arrays.asList(new ToscaPolicyTypeIdentifier("a-type-name", "3.2.1"))); + subgroup1.setPolicies(Collections.emptyList()); + group.setPdpSubgroups(Arrays.asList(subgroup1)); + + ValidationResult result = group.validatePapRest(true); + assertNotNull(result); + assertTrue(result.isValid()); + assertNull(result.getResult()); + + // without supported policy type and policies + PdpSubGroup subgroup2 = new PdpSubGroup(); + subgroup2.setDesiredInstanceCount(1); + subgroup2.setPdpType(PDP_TYPE1); + group.setPdpSubgroups(Arrays.asList(subgroup2)); + + // valid + result = group.validatePapRest(true); + assertNotNull(result); + assertTrue(result.isValid()); + assertNull(result.getResult()); + + // invalid + result = group.validatePapRest(false); + assertNotNull(result); + assertFalse(result.isValid()); + assertNotNull(result.getResult()); + } + + @Test public void testValidatePapRest() { PdpGroup group = new PdpGroup(); group.setName(NAME); @@ -140,7 +176,7 @@ public class PdpGroupTest { group.setPdpSubgroups(Arrays.asList(subgroup1, subgroup2, subgroup3)); // valid - ValidationResult result = group.validatePapRest(); + ValidationResult result = group.validatePapRest(false); assertNotNull(result); assertTrue(result.isValid()); assertNull(result.getResult()); @@ -179,7 +215,7 @@ public class PdpGroupTest { } private void assertInvalid(PdpGroup group) { - ValidationResult result = group.validatePapRest(); + ValidationResult result = group.validatePapRest(false); assertNotNull(result); assertFalse(result.isValid()); assertNotNull(result.getResult()); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java index e24e8e2d6..ba55426c7 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java @@ -3,7 +3,7 @@ * ONAP Policy Models * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,6 +91,39 @@ public class PdpSubGroupTest { } @Test + public void testValidatePapRest_GroupUpdateFlow() throws Exception { + PdpSubGroup subgrp = new PdpSubGroup(); + // with supported policy type and policies + subgrp.setDesiredInstanceCount(1); + subgrp.setPdpType("pdp-type"); + subgrp.setSupportedPolicyTypes( + Arrays.asList(makeIdent("type-X", VERSION_300, ToscaPolicyTypeIdentifier.class))); + subgrp.setPolicies(Arrays.asList(makeIdent("policy-X", "4.0.0", ToscaPolicyIdentifier.class))); + + ValidationResult result = subgrp.validatePapRest(false); + assertNotNull(result); + assertTrue(result.isValid()); + assertNull(result.getResult()); + + // without supported policy type and policies + PdpSubGroup subgrp2 = new PdpSubGroup(); + subgrp2.setDesiredInstanceCount(1); + subgrp2.setPdpType("pdp-type"); + + // valid + result = subgrp2.validatePapRest(true); + assertNotNull(result); + assertTrue(result.isValid()); + assertNull(result.getResult()); + + // invalid + result = subgrp2.validatePapRest(false); + assertNotNull(result); + assertFalse(result.isValid()); + assertNotNull(result.getResult()); + } + + @Test public void testValidatePapRest() throws Exception { PdpSubGroup subgrp = new PdpSubGroup(); @@ -101,7 +134,7 @@ public class PdpSubGroupTest { subgrp.setPolicies(Arrays.asList(makeIdent("policy-X", "4.0.0", ToscaPolicyIdentifier.class))); // valid - ValidationResult result = subgrp.validatePapRest(); + ValidationResult result = subgrp.validatePapRest(false); assertNotNull(result); assertTrue(result.isValid()); assertNull(result.getResult()); @@ -158,7 +191,7 @@ public class PdpSubGroupTest { } private void assertInvalid(PdpSubGroup sub2) { - ValidationResult result = sub2.validatePapRest(); + ValidationResult result = sub2.validatePapRest(false); assertNotNull(result); assertFalse(result.isValid()); assertNotNull(result.getResult()); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java index 34feece66..df935626c 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -182,7 +182,7 @@ public class ToscaPolicyFilterTest { filter = ToscaPolicyFilter.builder().version(VERSION_100).build(); filteredList = filter.filter(policyList); - assertEquals(21, filteredList.size()); + assertEquals(22, filteredList.size()); filter = ToscaPolicyFilter.builder().name("OSDF_CASABLANCA.SubscriberPolicy_v1").version(VERSION_100).build(); filteredList = filter.filter(policyList); @@ -202,7 +202,7 @@ public class ToscaPolicyFilterTest { filter = ToscaPolicyFilter.builder().versionPrefix("1.").build(); filteredList = filter.filter(policyList); - assertEquals(21, filteredList.size()); + assertEquals(22, filteredList.size()); filter = ToscaPolicyFilter.builder().versionPrefix("100.").build(); filteredList = filter.filter(policyList); |