aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java2
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java28
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java3
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java2
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java2
5 files changed, 28 insertions, 9 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java
index 01bd83d86..0d04cb9d1 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java
@@ -61,8 +61,6 @@ public class LegacyGuardPolicyMapper
new PfConceptKey("onap.policies.controlloop.guard.FrequencyLimiter:1.0.0"));
GUARD_POLICY_TYPE_MAP.put("guard.minmax.scaleout",
new PfConceptKey("onap.policies.controlloop.guard.MinMax:1.0.0"));
- GUARD_POLICY_TYPE_MAP.put("guard.minmax.scaleout",
- new PfConceptKey("onap.policies.controlloop.guard.MinMax:1.0.0"));
GUARD_POLICY_TYPE_MAP.put("guard.blacklist",
new PfConceptKey("onap.policies.controlloop.guard.Blacklist:1.0.0"));
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
index e21979be3..3e049ea17 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
@@ -38,17 +38,21 @@ import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Lob;
import javax.persistence.Table;
+import javax.ws.rs.core.Response;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.common.utils.validation.ParameterValidationUtils;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.base.PfValidationMessage;
import org.onap.policy.models.base.PfValidationResult;
@@ -148,8 +152,7 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
if (!PfKey.NULL_KEY_VERSION.equals(type.getVersion())) {
toscaPolicy.setTypeVersion(type.getVersion());
- }
- else {
+ } else {
toscaPolicy.setTypeVersion(null);
}
@@ -157,7 +160,18 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
Map<String, Object> propertyMap = new LinkedHashMap<>();
for (Entry<String, String> entry : properties.entrySet()) {
- propertyMap.put(entry.getKey(), entry.getValue());
+ try {
+ // TODO: This is a HACK, we need to validate the properties against their
+ // TODO: their data type in their policy type definition in TOSCA, which means reading
+ // TODO: the policy type from the database and parsing the property value object correctly
+ // TODO: Here we are simply reading a JSON string from the database and deserializing the
+ // TODO: property value from JSON
+ propertyMap.put(entry.getKey(), new StandardCoder().decode(entry.getValue(), Object.class));
+ } catch (CoderException ce) {
+ String errorMessage = "error decoding property JSON value read from database: key=" + entry.getKey()
+ + ", value=" + entry.getValue();
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ce);
+ }
}
toscaPolicy.setProperties(propertyMap);
@@ -185,7 +199,13 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
// TODO: the policy type from the database and parsing the property value object correctly
// TODO: Here we are simply serializing the property value into a string and storing it
// TODO: unvalidated into the database
- properties.put(propertyEntry.getKey(), propertyEntry.getValue().toString());
+ try {
+ properties.put(propertyEntry.getKey(), new StandardCoder().encode(propertyEntry.getValue()));
+ } catch (CoderException ce) {
+ String errorMessage = "error encoding property JSON value for database: key="
+ + propertyEntry.getKey() + ", value=" + propertyEntry.getValue();
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ce);
+ }
}
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
index 5f50e4a43..f9e388b04 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
@@ -64,6 +64,7 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
implements PfAuthorative<ToscaServiceTemplate> {
private static final long serialVersionUID = 8084846046148349401L;
+ public static final String DEFAULT_TOSCA_DEFINTIONS_VERISON = "tosca_simple_yaml_1_0_0";
public static final String DEFAULT_NAME = "ToscaServiceTemplateSimple";
public static final String DEFAULT_VERSION = "1.0.0";
@@ -97,7 +98,7 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
* @param key the key
*/
public JpaToscaServiceTemplate(@NonNull final PfConceptKey key) {
- this(key, "");
+ this(key, DEFAULT_TOSCA_DEFINTIONS_VERISON);
}
/**
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
index 571cde485..ae38ab916 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
@@ -81,7 +81,7 @@ public class JpaToscaPolicyTest {
JpaToscaPolicy tp = new JpaToscaPolicy(tpKey, ptKey);
Map<String, String> propertyMap = new HashMap<>();
- propertyMap.put("Property", "Property Value");
+ propertyMap.put("Property", "\"Property Value\"");
tp.setProperties(propertyMap);
assertEquals(propertyMap, tp.getProperties());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
index 4569d42ff..a2a418ef9 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
@@ -157,7 +157,7 @@ public class JpaToscaServiceTemplateTest {
tst.clean();
assertEquals(tttClone0, tst);
- assertFalse(new JpaToscaServiceTemplate().validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaServiceTemplate().validate(new PfValidationResult()).isValid());
assertTrue(tst.validate(new PfValidationResult()).isValid());
tst.setDescription(null);