diff options
Diffstat (limited to 'models-pap')
10 files changed, 445 insertions, 13 deletions
diff --git a/models-pap/pom.xml b/models-pap/pom.xml index 1cc5603cb..9257b9bda 100644 --- a/models-pap/pom.xml +++ b/models-pap/pom.xml @@ -27,7 +27,7 @@ <version>2.0.0-SNAPSHOT</version> </parent> - <artifactId>models-pap</artifactId> + <artifactId>policy-models-pap</artifactId> <name>${project.artifactId}</name> <description>The models for Policy Administration (PAP) REST API's.</description> @@ -37,5 +37,20 @@ <artifactId>pdp-common</artifactId> <version>${policy.common.version}</version> </dependency> + <dependency> + <groupId>org.onap.policy.models</groupId> + <artifactId>policy-models-base</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.policy.models</groupId> + <artifactId>policy-models-dao</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> </dependencies> -</project>
\ No newline at end of file +</project> diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpGroup.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpGroup.java index 148168d89..a42ac21bd 100644 --- a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpGroup.java +++ b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpGroup.java @@ -1,6 +1,7 @@ -/*- +/* * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,13 +21,14 @@ package org.onap.policy.models.pap.concepts; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; - import lombok.Getter; +import lombok.NonNull; import lombok.Setter; import lombok.ToString; - +import org.onap.policy.models.base.PfUtils; import org.onap.policy.pdp.common.enums.PdpState; /** @@ -41,9 +43,29 @@ public class PdpGroup { private String name; private String version; - private PdpState pdpGroupstate; + private PdpState pdpGroupState; private String description; private Map<String, String> properties; private List<PdpSubGroup> pdpSubgroups; + /** + * Constructs the object. + */ + public PdpGroup() { + super(); + } + + /** + * Constructs the object, making a deep copy from the source. + * + * @param source source from which to copy fields + */ + public PdpGroup(@NonNull PdpGroup source) { + this.name = source.name; + this.version = source.version; + this.pdpGroupState = source.pdpGroupState; + this.description = source.description; + this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties)); + this.pdpSubgroups = PfUtils.mapList(source.pdpSubgroups, PdpSubGroup::new); + } } diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpInstanceDetails.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpInstanceDetails.java index 168c20e38..4f9041c7f 100644 --- a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpInstanceDetails.java +++ b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpInstanceDetails.java @@ -1,6 +1,7 @@ -/*- +/* * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +22,9 @@ package org.onap.policy.models.pap.concepts; import lombok.Getter; +import lombok.NonNull; import lombok.Setter; import lombok.ToString; - import org.onap.policy.pdp.common.enums.PdpHealthStatus; import org.onap.policy.pdp.common.enums.PdpState; @@ -41,4 +42,23 @@ public class PdpInstanceDetails { private PdpState pdpState; private PdpHealthStatus healthy; private String message; + + /** + * Constructs the object. + */ + public PdpInstanceDetails() { + super(); + } + + /** + * Constructs the object, making a deep copy from the source. + * + * @param source source from which to copy fields + */ + public PdpInstanceDetails(@NonNull PdpInstanceDetails source) { + this.instanceId = source.instanceId; + this.pdpState = source.pdpState; + this.healthy = source.healthy; + this.message = source.message; + } } diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpSubGroup.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpSubGroup.java index ebb476d92..43356982e 100644 --- a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpSubGroup.java +++ b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpSubGroup.java @@ -1,6 +1,7 @@ -/*- +/* * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +21,19 @@ package org.onap.policy.models.pap.concepts; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; - import lombok.Getter; +import lombok.NonNull; import lombok.Setter; import lombok.ToString; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.base.keys.PolicyTypeIdent; /** - * Class to represent a group of all PDP's of the same pdp type running for a particular domain. + * Class to represent a group of all PDP's of the same pdp type running for a particular + * domain. * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ @@ -38,11 +43,32 @@ import lombok.ToString; public class PdpSubGroup { private String pdpType; - private List<String> supportedPolicyTypes; + private List<PolicyTypeIdent> supportedPolicyTypes; private List<Policy> policies; private int currentInstanceCount; private int desiredInstanceCount; private Map<String, String> properties; private List<PdpInstanceDetails> pdpInstances; + /** + * Constructs the object. + */ + public PdpSubGroup() { + super(); + } + + /** + * Constructs the object, making a deep copy from the source. + * + * @param source source from which to copy fields + */ + public PdpSubGroup(@NonNull PdpSubGroup source) { + this.pdpType = source.pdpType; + this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, PolicyTypeIdent::new); + this.policies = PfUtils.mapList(source.policies, Policy::new); + this.currentInstanceCount = source.currentInstanceCount; + this.desiredInstanceCount = source.desiredInstanceCount; + this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties)); + this.pdpInstances = PfUtils.mapList(source.pdpInstances, PdpInstanceDetails::new); + } } diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/Policy.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/Policy.java index e1281fc51..b83510e83 100644 --- a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/Policy.java +++ b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/Policy.java @@ -1,6 +1,7 @@ -/*- +/* * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,7 @@ package org.onap.policy.models.pap.concepts; import lombok.Getter; +import lombok.NonNull; import lombok.Setter; import lombok.ToString; @@ -39,4 +41,24 @@ public class Policy { private String policyType; private String policyTypeVersion; private String policyTypeImpl; + + /** + * Constructs the object. + */ + public Policy() { + super(); + } + + /** + * Constructs the object, making a deep copy from the source. + * + * @param source source from which to copy fields + */ + public Policy(@NonNull Policy source) { + this.name = source.name; + this.policyVersion = source.policyVersion; + this.policyType = source.policyType; + this.policyTypeVersion = source.policyTypeVersion; + this.policyTypeImpl = source.policyTypeImpl; + } } diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/provider/PapProvider.java b/models-pap/src/main/java/org/onap/policy/models/pap/provider/PapProvider.java new file mode 100644 index 000000000..4b80bea29 --- /dev/null +++ b/models-pap/src/main/java/org/onap/policy/models/pap/provider/PapProvider.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pap.provider; + +import lombok.NonNull; + +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.dao.PfDao; +import org.onap.policy.models.pap.concepts.PdpGroups; + +/** + * This class provides the provision of information on PAP concepts in the database to callers. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class PapProvider { + /** + * Get PDP groups. + * + * @param dao the DAO to use to access the database + * @param pdpGroupFilter a filter for the get + * @return the PDP groups found + * @throws PfModelException on errors getting PDP groups + */ + public PdpGroups getPdpGroups(@NonNull final PfDao dao, @NonNull final String pdpGroupFilter) + throws PfModelException { + return new PdpGroups(); + } + + /** + * Creates PDP groups. + * + * @param dao the DAO to use to access the database + * @param pdpGroups a specification of the PDP groups to create + * @return the PDP groups created + * @throws PfModelException on errors creating PDP groups + */ + public PdpGroups createPdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroups pdpGroups) + throws PfModelException { + return new PdpGroups(); + } + + /** + * Updates PDP groups. + * + * @param dao the DAO to use to access the database + * @param pdpGroups a specification of the PDP groups to update + * @return the PDP groups updated + * @throws PfModelException on errors updating PDP groups + */ + public PdpGroups updatePdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroups pdpGroups) + throws PfModelException { + return new PdpGroups(); + } + + /** + * Delete PDP groups. + * + * @param dao the DAO to use to access the database + * @param pdpGroupFilter a filter for the get + * @return the PDP groups deleted + * @throws PfModelException on errors deleting PDP groups + */ + public PdpGroups deletePdpGroups(@NonNull final PfDao dao, @NonNull final String pdpGroupFilter) + throws PfModelException { + return new PdpGroups(); + } +} diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpGroup.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpGroup.java new file mode 100644 index 000000000..3dc3c24b2 --- /dev/null +++ b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpGroup.java @@ -0,0 +1,66 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pap.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.Map; +import java.util.TreeMap; +import org.junit.Test; +import org.onap.policy.pdp.common.enums.PdpState; + +/** + * Test the copy constructor, as {@link TestModels} tests the other methods. + */ +public class TestPdpGroup { + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new PdpGroup(null)).isInstanceOf(NullPointerException.class); + + PdpGroup orig = new PdpGroup(); + + // verify with null values + assertEquals(orig.toString(), new PdpGroup(orig).toString()); + + // verify with all values + orig.setDescription("my-descript"); + orig.setName("my-name"); + orig.setPdpGroupState(PdpState.SAFE); + + PdpSubGroup sub1 = new PdpSubGroup(); + sub1.setCurrentInstanceCount(10); + PdpSubGroup sub2 = new PdpSubGroup(); + sub2.setCurrentInstanceCount(11); + orig.setPdpSubgroups(Arrays.asList(sub1, sub2)); + + Map<String, String> props = new TreeMap<>(); + props.put("key-A", "value-A"); + props.put("key-B", "value-B"); + orig.setProperties(props); + + System.out.println("orig=" + orig); + + assertEquals(orig.toString(), new PdpGroup(orig).toString()); + } +} diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpInstanceDetails.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpInstanceDetails.java new file mode 100644 index 000000000..9e48480f4 --- /dev/null +++ b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpInstanceDetails.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pap.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.pdp.common.enums.PdpHealthStatus; +import org.onap.policy.pdp.common.enums.PdpState; + +/** + * Test the copy constructor, as {@link TestModels} tests the other methods. + */ +public class TestPdpInstanceDetails { + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new PdpInstanceDetails(null)).isInstanceOf(NullPointerException.class); + + PdpInstanceDetails orig = new PdpInstanceDetails(); + + // verify with null values + assertEquals(orig.toString(), new PdpInstanceDetails(orig).toString()); + + // verify with all values + orig.setHealthy(PdpHealthStatus.TEST_IN_PROGRESS); + orig.setInstanceId("my-id"); + orig.setMessage("my-message"); + orig.setPdpState(PdpState.SAFE); + assertEquals(orig.toString(), new PdpInstanceDetails(orig).toString()); + } +} diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpSubGroup.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpSubGroup.java new file mode 100644 index 000000000..9af2f4e9d --- /dev/null +++ b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpSubGroup.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pap.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.Map; +import java.util.TreeMap; +import org.junit.Test; +import org.onap.policy.models.base.keys.PolicyTypeIdent; + +/** + * Test the copy constructor, as {@link TestModels} tests the other methods. + */ +public class TestPdpSubGroup { + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new PdpSubGroup(null)).isInstanceOf(NullPointerException.class); + + PdpSubGroup orig = new PdpSubGroup(); + + // verify with null values + assertEquals(orig.toString(), new PdpSubGroup(orig).toString()); + + // verify with all values + orig.setCurrentInstanceCount(10); + orig.setDesiredInstanceCount(11); + + PdpInstanceDetails inst1 = new PdpInstanceDetails(); + inst1.setInstanceId("my-id-A"); + PdpInstanceDetails inst2 = new PdpInstanceDetails(); + inst2.setInstanceId("my-id-B"); + orig.setPdpInstances(Arrays.asList(inst1, inst2)); + + orig.setPdpType("my-type"); + + Policy pol1 = new Policy(); + pol1.setName("policy-A"); + Policy pol2 = new Policy(); + pol2.setName("policy-B"); + orig.setPolicies(Arrays.asList(pol1, pol2)); + + Map<String, String> props = new TreeMap<>(); + props.put("key-A", "value-A"); + props.put("key-B", "value-B"); + orig.setProperties(props); + + PolicyTypeIdent supp1 = new PolicyTypeIdent("supp-A", "1.2"); + PolicyTypeIdent supp2 = new PolicyTypeIdent("supp-B", "3.4"); + orig.setSupportedPolicyTypes(Arrays.asList(supp1, supp2)); + + assertEquals(orig.toString(), new PdpSubGroup(orig).toString()); + } +} diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPolicy.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPolicy.java new file mode 100644 index 000000000..6a042d3be --- /dev/null +++ b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPolicy.java @@ -0,0 +1,49 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pap.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Test the copy constructor, as {@link TestModels} tests the other methods. + */ +public class TestPolicy { + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new Policy(null)).isInstanceOf(NullPointerException.class); + + Policy orig = new Policy(); + + // verify with null values + assertEquals(orig.toString(), new Policy(orig).toString()); + + // verify with all values + orig.setName("my-name"); + orig.setPolicyType("my-type"); + orig.setPolicyTypeImpl("my-impl"); + orig.setPolicyTypeVersion("my-type-vers"); + assertEquals(orig.toString(), new Policy(orig).toString()); + } +} |