summaryrefslogtreecommitdiffstats
path: root/models-provider/src/main
diff options
context:
space:
mode:
authorRam Krishna Verma <ram_krishna.verma@bell.ca>2020-02-18 19:14:33 +0000
committerGerrit Code Review <gerrit@onap.org>2020-02-18 19:14:33 +0000
commit4557de595908e116633ff0237284853e8debce04 (patch)
tree3d29ebf5ac98c65cb1d449b6fd26fb3f27c2c771 /models-provider/src/main
parentba3a17c58088a016b3ed2948b0c33502fdbc84ec (diff)
parentb477554c29b2d666e7bb0bc860afacc6e935c337 (diff)
Merge "Add safe entity delete, fix multiple entity get"
Diffstat (limited to 'models-provider/src/main')
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java56
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java2
2 files changed, 57 insertions, 1 deletions
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 50c739059..3cae650a3 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
@@ -49,8 +49,10 @@ import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
@@ -189,6 +191,10 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
throws PfModelException {
assertInitialized();
+
+ ToscaPolicyTypeIdentifier policyTypeIdentifier = new ToscaPolicyTypeIdentifier(name, version);
+ assertPolicyTypeNotSupportedInPdpGroup(policyTypeIdentifier);
+
return new AuthorativeToscaProvider().deletePolicyType(pfDao, name, version);
}
@@ -234,6 +240,10 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
throws PfModelException {
assertInitialized();
+
+ ToscaPolicyIdentifier policyIdentifier = new ToscaPolicyIdentifier(name, version);
+ assertPolicyNotDeployedInPdpGroup(policyIdentifier);
+
return new AuthorativeToscaProvider().deletePolicy(pfDao, name, version);
}
@@ -262,6 +272,10 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId,
@NonNull final String policyVersion) throws PfModelException {
assertInitialized();
+
+ assertPolicyNotDeployedInPdpGroup(
+ new ToscaPolicyIdentifier(policyId, policyVersion + LegacyProvider.LEGACY_MINOR_PATCH_SUFFIX));
+
return new LegacyProvider().deleteOperationalPolicy(pfDao, policyId, policyVersion);
}
@@ -290,6 +304,10 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId,
@NonNull final String policyVersion) throws PfModelException {
assertInitialized();
+
+ assertPolicyNotDeployedInPdpGroup(
+ new ToscaPolicyIdentifier(policyId, policyVersion + LegacyProvider.LEGACY_MINOR_PATCH_SUFFIX));
+
return new LegacyProvider().deleteGuardPolicy(pfDao, policyId, policyVersion);
}
@@ -382,4 +400,42 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
}
}
+
+ /**
+ * Assert that the policy type is not supported in any PDP group.
+ *
+ * @param policyTypeIdentifier the policy type identifier
+ * @throws PfModelException if the policy type is supported in a PDP group
+ */
+ private void assertPolicyTypeNotSupportedInPdpGroup(ToscaPolicyTypeIdentifier policyTypeIdentifier)
+ throws PfModelException {
+ for (PdpGroup pdpGroup : getPdpGroups(null)) {
+ for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {
+ if (pdpSubGroup.getSupportedPolicyTypes().contains(policyTypeIdentifier)) {
+ throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE,
+ "policy type is in use, it is referenced in PDP group " + pdpGroup.getName() + " subgroup "
+ + pdpSubGroup.getPdpType());
+ }
+ }
+ }
+ }
+
+ /**
+ * Assert that the policy is not deployed in a PDP group.
+ *
+ * @param policyIdentifier the identifier of the policy
+ * @throws PfModelException thrown if the policy is deployed in a PDP group
+ */
+ private void assertPolicyNotDeployedInPdpGroup(final ToscaPolicyIdentifier policyIdentifier)
+ throws PfModelException {
+ for (PdpGroup pdpGroup : getPdpGroups(null)) {
+ for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {
+ if (pdpSubGroup.getPolicies().contains(policyIdentifier)) {
+ throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE,
+ "policy is in use, it is deployed in PDP group " + pdpGroup.getName() + " subgroup "
+ + pdpSubGroup.getPdpType());
+ }
+ }
+ }
+ }
}
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 3d1c9f61c..c09c6c233 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
@@ -258,7 +258,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
@Override
public List<PdpStatistics> deletePdpStatistics(final String name, final Date timestamp) {
// Not implemented
- return null;
+ return new ArrayList<>();
}
/**