aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main/java/org')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java56
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java15
2 files changed, 58 insertions, 13 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java
index e861375e..bc3148ef 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java
@@ -317,7 +317,7 @@ public class PdpGroupDeployProvider extends ProviderBase {
* Adds a new subgroup.
*
* @param data session data
- * @param subgrp the subgroup to be added
+ * @param subgrp the subgroup to be added, updated to fully qualified versions upon return
* @return the validation result
* @throws PfModelException if an error occurred
*/
@@ -339,7 +339,7 @@ public class PdpGroupDeployProvider extends ProviderBase {
* @param data session data
* @param dbgroup the group, from the DB, containing the subgroup
* @param dbsub the subgroup, from the DB
- * @param subgrp the subgroup to be updated
+ * @param subgrp the subgroup to be updated, updated to fully qualified versions upon return
* @param container container for additional validation results
* @return {@code true} if the subgroup content was changed, {@code false} if there
* were no changes
@@ -378,7 +378,7 @@ public class PdpGroupDeployProvider extends ProviderBase {
*
* @param data session data
* @param dbsub the subgroup, from the DB
- * @param subgrp the subgroup to be validated
+ * @param subgrp the subgroup to be validated, updated to fully qualified versions upon return
* @param container container for additional validation results
* @return {@code true} if the subgroup is valid, {@code false} otherwise
* @throws PfModelException if an error occurred
@@ -447,14 +447,15 @@ public class PdpGroupDeployProvider extends ProviderBase {
*
* @param data session data
* @param dbsub subgroup from the DB, or {@code null} if this is a new subgroup
- * @param subgrp the subgroup to be validated
+ * @param subgrp the subgroup whose policies are to be validated, updated to fully
+ * qualified versions upon return
* @param result the validation result
* @throws PfModelException if an error occurred
*/
private ValidationResult validatePolicies(SessionData data, PdpSubGroup dbsub, PdpSubGroup subgrp)
throws PfModelException {
- // build a map of the DB data, from policy name to policy version
+ // build a map of the DB data, from policy name to (fully qualified) policy version
Map<String, String> dbname2vers = new HashMap<>();
if (dbsub != null) {
dbsub.getPolicies().forEach(ident -> dbname2vers.put(ident.getName(), ident.getVersion()));
@@ -463,7 +464,17 @@ public class PdpGroupDeployProvider extends ProviderBase {
BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp);
for (ToscaPolicyIdentifier ident : subgrp.getPolicies()) {
- String actualVersion;
+ // note: "ident" may not have a fully qualified version
+
+ String expectedVersion = dbname2vers.get(ident.getName());
+ if (expectedVersion != null) {
+ // policy exists in the DB list - compare the versions
+ validateVersion(expectedVersion, ident, result);
+ ident.setVersion(expectedVersion);
+ continue;
+ }
+
+ // policy doesn't appear in the DB's policy list - look it up
ToscaPolicy policy = data.getPolicy(new ToscaPolicyIdentifierOptVersion(ident));
if (policy == null) {
@@ -474,11 +485,9 @@ public class PdpGroupDeployProvider extends ProviderBase {
result.addResult(new ObjectValidationResult(POLICY_RESULT_NAME, ident, ValidationStatus.INVALID,
"not a supported policy for the subgroup"));
- } else if ((actualVersion = dbname2vers.get(ident.getName())) != null
- && !actualVersion.equals(ident.getVersion())) {
- // policy exists in the DB subgroup, but has the wrong version
- result.addResult(new ObjectValidationResult(POLICY_RESULT_NAME, ident, ValidationStatus.INVALID,
- "different version already deployed: " + actualVersion));
+ } else {
+ // replace version with the fully qualified version from the policy
+ ident.setVersion(policy.getVersion());
}
}
@@ -486,6 +495,31 @@ public class PdpGroupDeployProvider extends ProviderBase {
}
/**
+ * Determines if the new version matches the version in the DB.
+ *
+ * @param dbvers fully qualified version from the DB
+ * @param ident identifier whose version is to be validated; the version need not be
+ * fully qualified
+ * @param result the validation result
+ */
+ private void validateVersion(String dbvers, ToscaPolicyIdentifier ident, BeanValidationResult result) {
+ String idvers = ident.getVersion();
+ if (dbvers.equals(idvers)) {
+ return;
+ }
+
+ // did not match - see if it's a prefix
+
+ if (SessionData.isVersionPrefix(idvers) && dbvers.startsWith(idvers + ".")) {
+ // ident has a prefix of this version
+ return;
+ }
+
+ result.addResult(new ObjectValidationResult(POLICY_RESULT_NAME, ident, ValidationStatus.INVALID,
+ "different version already deployed: " + dbvers));
+ }
+
+ /**
* Deploys or updates PDP policies using the simple API.
*
* @param policies PDP policies
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
index ee83fb74..437d7a11 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
@@ -54,7 +54,7 @@ public class SessionData {
* If a version string matches this, then it is just a prefix (i.e., major or
* major.minor).
*/
- private static final Pattern VERSION_PREFIX_PAT = Pattern.compile("[^.]+(?:[.][^.]*)?");
+ private static final Pattern VERSION_PREFIX_PAT = Pattern.compile("[^.]+(?:[.][^.]+)?");
/**
* DB provider.
@@ -165,7 +165,7 @@ public class SessionData {
// no version specified - get the latest
filterBuilder.version(ToscaPolicyFilter.LATEST_VERSION);
- } else if (VERSION_PREFIX_PAT.matcher(desiredVersion).matches()) {
+ } else if (isVersionPrefix(desiredVersion)) {
// version prefix provided - match the prefix and then pick the latest
filterBuilder.versionPrefix(desiredVersion + ".").version(ToscaPolicyFilter.LATEST_VERSION);
@@ -176,6 +176,17 @@ public class SessionData {
}
/**
+ * Determines if a version contains only a prefix.
+ *
+ * @param version version to inspect
+ * @return {@code true} if the version contains only a prefix, {@code false} if it is
+ * fully qualified
+ */
+ public static boolean isVersionPrefix(String version) {
+ return VERSION_PREFIX_PAT.matcher(version).matches();
+ }
+
+ /**
* Adds an update and state-change to the sets, replacing any previous entries for the
* given PDP.
*