aboutsummaryrefslogtreecommitdiffstats
path: root/models-provider/src/main/java/org/onap
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-04-02 23:32:32 +0000
committerliamfallon <liam.fallon@est.tech>2019-04-02 23:32:32 +0000
commit8054d6dcff521c460954b9e9e203faf65924bfee (patch)
treea47a47fc5b91f24f7fb7408c359acce4724ec77b /models-provider/src/main/java/org/onap
parent563ba59d9fb967681216eda454b0be9a3f13607d (diff)
Add persistence for PDP concepts
This review adds the JPA annotations to PDP group/subgroup and PDP for persisting to the database. It also updates the Provider API as requested by other team members. Issue-ID: POLICY-1095 Change-Id: I8188afb763849ede9680f3751b464d9d76c27196 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-provider/src/main/java/org/onap')
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java30
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java8
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java27
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java29
4 files changed, 56 insertions, 38 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 b0494ff60..af1c88f2b 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
@@ -28,7 +28,6 @@ import lombok.NonNull;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.PdpGroup;
-import org.onap.policy.models.pdp.concepts.PdpGroups;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -52,6 +51,9 @@ public interface PolicyModelsProvider extends AutoCloseable {
*/
public void init() throws PfModelException;
+ @Override
+ public void close() throws PfModelException;
+
/**
* Get policy types.
*
@@ -145,10 +147,13 @@ public interface PolicyModelsProvider extends AutoCloseable {
* 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) throws PfModelException;
+ public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName,
+ final String policyTypeVersion) throws PfModelException;
/**
* Get latest policies.
@@ -284,25 +289,25 @@ public interface PolicyModelsProvider extends AutoCloseable {
* @return the PDP groups found
* @throws PfModelException on errors getting PDP groups
*/
- public PdpGroups getPdpGroups(final String name, final String version) throws PfModelException;
+ public List<PdpGroup> getPdpGroups(final String name, final String version) throws PfModelException;
/**
- * Get latest PDP Groups.
+ * Get latest PDP Groups, returns PDP groups in all states.
*
* @param name the name of the PDP group to get, null to get all PDP groups
* @return the PDP groups found
* @throws PfModelException on errors getting policies
*/
- public PdpGroups getLatestPdpGroups(final String name) throws PfModelException;
+ public List<PdpGroup> getLatestPdpGroups(final String name) throws PfModelException;
/**
- * Get a filtered list of PDP groups.
+ * Get a filtered list of PDP groups, returns only active PDP groups.
*
- * @param pdpType The PDP type filter for the returned PDP groups
+ * @param pdpType The PDP type filter for the returned PDP groups, null to get policy types across PDP subgroups
* @param supportedPolicyTypes a list of policy type name/version pairs that the PDP groups must support.
* @return the PDP groups found
*/
- public PdpGroups getFilteredPdpGroups(@NonNull final String pdpType,
+ public List<PdpGroup> getFilteredPdpGroups(final String pdpType,
@NonNull final List<Pair<String, String>> supportedPolicyTypes);
/**
@@ -312,7 +317,7 @@ public interface PolicyModelsProvider extends AutoCloseable {
* @return the PDP groups created
* @throws PfModelException on errors creating PDP groups
*/
- public PdpGroups createPdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException;
+ public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
/**
* Updates PDP groups.
@@ -321,7 +326,7 @@ public interface PolicyModelsProvider extends AutoCloseable {
* @return the PDP groups updated
* @throws PfModelException on errors updating PDP groups
*/
- public PdpGroups updatePdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException;
+ public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException;
/**
@@ -372,8 +377,9 @@ public interface PolicyModelsProvider extends AutoCloseable {
* Get deployed policies.
*
* @param name the name of the policy to get, null to get all policies
- * @return the policies deployed as a map of policy lists keyed by PDP group
+ * @return the policies deployed as a map of policy lists keyed by PDP group name and version
* @throws PfModelException on errors getting policies
*/
- public Map<PdpGroup, List<ToscaPolicy>> getDeployedPolicyList(final String name) throws PfModelException;
+ public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(final String name)
+ throws PfModelException;
}
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java
index 718668b97..86551b341 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java
@@ -66,8 +66,12 @@ public class PolicyModelsProviderFactory {
}
try {
- return (PolicyModelsProvider) implementationClass.getConstructor(PolicyModelsProviderParameters.class)
- .newInstance(parameters);
+ PolicyModelsProvider provider = (PolicyModelsProvider) implementationClass
+ .getConstructor(PolicyModelsProviderParameters.class).newInstance(parameters);
+
+ provider.init();
+
+ return provider;
} catch (Exception exc) {
String errorMessage =
"could not create an instance of PolicyModelsProvider \"" + parameters.getImplementation() + "\"";
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 ee8ed7348..96185b65a 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
@@ -38,7 +38,6 @@ 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.PdpGroup;
-import org.onap.policy.models.pdp.concepts.PdpGroups;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.persistence.provider.PdpProvider;
@@ -84,6 +83,12 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
LOGGER.debug("opening the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),
parameters.getPersistenceUnit());
+ if (connection != null || pfDao != null) {
+ String errorMessage = "provider is already initialized";
+ LOGGER.warn(errorMessage);
+ throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMessage);
+ }
+
// Decode the password using Base64
String decodedPassword = new String(Base64.getDecoder().decode(parameters.getDatabasePassword()));
@@ -201,9 +206,10 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName) throws PfModelException {
+ public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName,
+ final String policyTypeVersion) throws PfModelException {
assertInitilized();
- return new AuthorativeToscaProvider().getPolicyList4PolicyType(pfDao, policyTypeName);
+ return new AuthorativeToscaProvider().getPolicyList4PolicyType(pfDao, policyTypeName, policyTypeVersion);
}
@Override
@@ -293,32 +299,32 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public PdpGroups getPdpGroups(final String name, final String version) throws PfModelException {
+ public List<PdpGroup> getPdpGroups(final String name, final String version) throws PfModelException {
assertInitilized();
return new PdpProvider().getPdpGroups(pfDao, name, version);
}
@Override
- public PdpGroups getLatestPdpGroups(final String name) throws PfModelException {
+ public List<PdpGroup> getLatestPdpGroups(final String name) throws PfModelException {
assertInitilized();
return new PdpProvider().getLatestPdpGroups(pfDao, name);
}
@Override
- public PdpGroups getFilteredPdpGroups(@NonNull final String pdpType,
+ public List<PdpGroup> getFilteredPdpGroups(final String pdpType,
@NonNull final List<Pair<String, String>> supportedPolicyTypes) {
assertInitilized();
return new PdpProvider().getFilteredPdpGroups(pfDao, pdpType, supportedPolicyTypes);
}
@Override
- public PdpGroups createPdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException {
+ public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException {
assertInitilized();
return new PdpProvider().createPdpGroups(pfDao, pdpGroups);
}
@Override
- public PdpGroups updatePdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException {
+ public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException {
assertInitilized();
return new PdpProvider().updatePdpGroups(pfDao, pdpGroups);
}
@@ -345,14 +351,15 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
@Override
public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
@NonNull final String pdpType, @NonNull final String pdpInstanceId,
- @NonNull final PdpStatistics pdppStatistics) throws PfModelException {
+ @NonNull final PdpStatistics pdppStatistics) throws PfModelException {
assertInitilized();
new PdpProvider().updatePdpStatistics(pfDao, pdpGroupName, pdpGroupVersion, pdpType, pdpInstanceId,
pdppStatistics);
}
@Override
- public Map<PdpGroup, List<ToscaPolicy>> getDeployedPolicyList(final String name) throws PfModelException {
+ public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(final String name)
+ throws PfModelException {
assertInitilized();
return new PdpProvider().getDeployedPolicyList(pfDao, name);
}
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 3db8e5e35..bf707ef53 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
@@ -35,7 +35,6 @@ 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.PdpGroup;
-import org.onap.policy.models.pdp.concepts.PdpGroups;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.provider.PolicyModelsProvider;
@@ -120,7 +119,8 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName) throws PfModelException {
+ public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName,
+ final String policyTypeVersion) throws PfModelException {
return new ArrayList<>();
}
@@ -199,29 +199,29 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public PdpGroups getPdpGroups(final String name, final String version) throws PfModelException {
- return null;
+ public List<PdpGroup> getPdpGroups(final String name, final String version) throws PfModelException {
+ return new ArrayList<>();
}
@Override
- public PdpGroups getLatestPdpGroups(final String name) throws PfModelException {
- return null;
+ public List<PdpGroup> getLatestPdpGroups(final String name) throws PfModelException {
+ return new ArrayList<>();
}
@Override
- public PdpGroups getFilteredPdpGroups(@NonNull final String pdpType,
+ public List<PdpGroup> getFilteredPdpGroups(final String pdpType,
@NonNull final List<Pair<String, String>> supportedPolicyTypes) {
- return null;
+ return new ArrayList<>();
}
@Override
- public PdpGroups createPdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException {
- return null;
+ public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException {
+ return new ArrayList<>();
}
@Override
- public PdpGroups updatePdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException {
- return null;
+ public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException {
+ return new ArrayList<>();
}
@Override
@@ -243,12 +243,13 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
@Override
public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
@NonNull final String pdpType, @NonNull final String pdpInstanceId,
- @NonNull final PdpStatistics pdppStatistics) throws PfModelException {
+ @NonNull final PdpStatistics pdppStatistics) throws PfModelException {
// Not implemented
}
@Override
- public Map<PdpGroup, List<ToscaPolicy>> getDeployedPolicyList(final String name) throws PfModelException {
+ public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(final String name)
+ throws PfModelException {
return null;
}