diff options
author | liamfallon <liam.fallon@est.tech> | 2019-04-03 15:47:36 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-04-03 15:47:36 +0000 |
commit | defa996aa95c11a6252604498a1e775134c34f2e (patch) | |
tree | 2be106f3e8e1adead7ff1b77800ecd6a972376a8 /models-provider | |
parent | 50bc153c11472d90aa0f2a8ca9d8afeab0efb010 (diff) |
Add impl of more PDP persistence
Add the implementation of more metods in the PDP provider.
Issue-ID: POLICY-1095
Change-Id: Ie02189cad7a262a453e1f731190525f838648401
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-provider')
5 files changed, 70 insertions, 5 deletions
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java index af1c88f2b..12c72d714 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java @@ -27,6 +27,7 @@ import lombok.NonNull; import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpSubGroup; @@ -152,6 +153,18 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the policies found * @throws PfModelException on errors getting policies */ + public ToscaServiceTemplate getPolicies4PolicyType(@NonNull final String policyTypeName, + final String policyTypeVersion) throws PfModelException; + + /** + * Get policies for a policy type name. + * + * @param policyTypeName the name of the policy type for which to get policies + * @param policyTypeVersion the version of the policy type, null returns all versions of deployed policies for + * policy types + * @return the policies found + * @throws PfModelException on errors getting policies + */ public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName, final String policyTypeVersion) throws PfModelException; @@ -328,7 +341,6 @@ public interface PolicyModelsProvider extends AutoCloseable { */ public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException; - /** * Update a PDP subgroup. * @@ -341,6 +353,18 @@ public interface PolicyModelsProvider extends AutoCloseable { @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException; /** + * Update a PDP. + * + * @param pdpGroupName the name of the PDP group of the PDP subgroup + * @param pdpGroupVersion the version of the PDP group of the PDP subgroup + * @param pdpSubGroup the PDP subgroup to be updated + * @param pdp the PDP to be updated + * @throws PfModelException on errors updating PDP subgroups + */ + public void updatePdp(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion, + @NonNull final String pdpSubGroup, @NonNull final Pdp pdp) throws PfModelException; + + /** * Delete a PDP group. * * @param name the name of the policy to get, null to get all PDP groups diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java index 96185b65a..51b7d2f68 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java @@ -37,6 +37,7 @@ import org.onap.policy.models.dao.DaoParameters; import org.onap.policy.models.dao.PfDao; import org.onap.policy.models.dao.PfDaoFactory; import org.onap.policy.models.dao.impl.DefaultPfDao; +import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpSubGroup; @@ -206,6 +207,13 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider { } @Override + public ToscaServiceTemplate getPolicies4PolicyType(@NonNull String policyTypeName, String policyTypeVersion) + throws PfModelException { + assertInitilized(); + return new AuthorativeToscaProvider().getPolicies4PolicyType(pfDao, policyTypeName, policyTypeVersion); + } + + @Override public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName, final String policyTypeVersion) throws PfModelException { assertInitilized(); @@ -337,6 +345,12 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider { } @Override + public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion, + @NonNull String pdpSubGroup, @NonNull Pdp pdp) throws PfModelException { + new PdpProvider().updatePdp(pfDao, pdpGroupName, pdpGroupVersion, pdpSubGroup, pdp); + } + + @Override public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException { assertInitilized(); return new PdpProvider().deletePdpGroup(pfDao, name, version); diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java index bf707ef53..52929ab5a 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java @@ -34,6 +34,7 @@ import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpSubGroup; @@ -119,6 +120,12 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override + public ToscaServiceTemplate getPolicies4PolicyType(@NonNull String policyTypeName, String policyTypeVersion) + throws PfModelException { + return null; + } + + @Override public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName, final String policyTypeVersion) throws PfModelException { return new ArrayList<>(); @@ -231,6 +238,12 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override + public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion, + @NonNull String pdpSubGroup, @NonNull Pdp pdp) throws PfModelException { + // Not implemented + } + + @Override public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException { return null; } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java index 7ad221721..8a83f4414 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java @@ -21,6 +21,7 @@ package org.onap.policy.models.provider.impl; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; @@ -311,13 +312,14 @@ public class DatabasePolicyModelsProviderTest { databaseProvider.deleteGuardPolicy("policy_id"); }).hasMessage("no policy found for policy ID: policy_id"); - assertThatThrownBy(() -> { - databaseProvider.getPdpGroups("name", "version"); - }).hasMessage("PDP group not found: name:version"); + assertEquals(0, databaseProvider.getPdpGroups("name", "version").size()); assertNotNull(databaseProvider.createPdpGroups(new ArrayList<>())); assertNotNull(databaseProvider.updatePdpGroups(new ArrayList<>())); - assertNotNull(databaseProvider.deletePdpGroup("name", "version")); + + assertThatThrownBy(() -> { + databaseProvider.deletePdpGroup("name", "version"); + }).hasMessage("delete of PDP group \"name:version\" failed, PDP group does not exist"); } catch (Exception exc) { LOGGER.warn("test should not throw an exception", exc); diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java index c64603d9a..69b7a0f71 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java @@ -30,6 +30,7 @@ import lombok.NonNull; import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpSubGroup; @@ -159,6 +160,11 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override + public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion, + @NonNull String pdpSubGroup, @NonNull Pdp pdp) throws PfModelException { + } + + @Override public PdpGroup deletePdpGroup(@NonNull String name, @NonNull String verison) throws PfModelException { return null; } @@ -184,6 +190,12 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override + public ToscaServiceTemplate getPolicies4PolicyType(@NonNull String policyTypeName, String policyTypeVersion) + throws PfModelException { + return null; + } + + @Override public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull String policyTypeName, final String policyTypeVersion) throws PfModelException { return null; |