summaryrefslogtreecommitdiffstats
path: root/model/policy-model/src/main/java/org
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@bell.ca>2021-06-29 13:57:14 +0100
committera.sreekumar <ajith.sreekumar@bell.ca>2021-07-02 16:03:51 +0100
commit5f0ec1c2d95c377fbec428f11464e93fe442b5ef (patch)
tree4aef07097fa4d64550db116a1b1b4acd1aa42590 /model/policy-model/src/main/java/org
parentba55109db1e5eea013dcffd1be29cf06fe2bbcb1 (diff)
Cleanup input & outputFields from Task definition
1) Remove the usage of inputField and outputField from Task definition. 2) Fix issues around populating events to task in case of State Finalizer Logic. Change-Id: Ief17f400729410b83c6b7c665980d443e0cf6f28 Issue-ID: POLICY-3336 Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'model/policy-model/src/main/java/org')
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java39
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java165
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java10
3 files changed, 4 insertions, 210 deletions
diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java
index 4ee176d97..aec144a46 100644
--- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java
@@ -25,8 +25,6 @@ package org.onap.policy.apex.model.policymodel.concepts;
import java.util.List;
import java.util.Map.Entry;
-import java.util.Set;
-import java.util.TreeSet;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
@@ -45,7 +43,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
-import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
@@ -425,19 +422,6 @@ public class AxPolicyModel extends AxModel {
* @return the result
*/
private AxValidationResult validateTaskKeys(final AxTask task, AxValidationResult result) {
- for (final AxField field : task.getInputFieldSet()) {
- if (getSchemas().get(field.getSchema()) == null) {
- result.addValidationMessage(new AxValidationMessage(task.getKey(), this.getClass(),
- ValidationResult.INVALID, "task input field schema " + field.getSchema().getId() + DOES_NOT_EXIST));
- }
- }
- for (final AxField field : task.getOutputFieldSet()) {
- if (getSchemas().get(field.getSchema()) == null) {
- result.addValidationMessage(
- new AxValidationMessage(task.getKey(), this.getClass(), ValidationResult.INVALID,
- "task output field schema " + field.getSchema().getId() + DOES_NOT_EXIST));
- }
- }
for (final AxArtifactKey contextAlbumKey : task.getContextAlbumReferences()) {
if (albums.get(contextAlbumKey) == null) {
result.addValidationMessage(new AxValidationMessage(task.getKey(), this.getClass(),
@@ -489,19 +473,6 @@ public class AxPolicyModel extends AxModel {
ValidationResult.INVALID, "state default task " + state.getDefaultTask().getId() + DOES_NOT_EXIST));
}
- // Check task input fields and event fields are compatible for default tasks with no task
- // selection logic
- if (state.getTaskSelectionLogic().getKey().equals(AxReferenceKey.getNullKey())
- && triggerEvent != null && defaultTask != null) {
- final Set<AxField> unhandledTaskInputFields = new TreeSet<>(defaultTask.getInputFieldSet());
- unhandledTaskInputFields.removeAll(triggerEvent.getFields());
- for (final AxField unhandledTaskInputField : unhandledTaskInputFields) {
- result.addValidationMessage(new AxValidationMessage(state.getKey(), this.getClass(),
- ValidationResult.INVALID, "task input field " + unhandledTaskInputField + " for task "
- + defaultTask.getId() + " not in trigger event " + triggerEvent.getId()));
- }
- }
-
for (final AxStateOutput stateOutput : state.getStateOutputs().values()) {
if (events.getEventMap().get(stateOutput.getOutgoingEvent()) == null) {
result.addValidationMessage(new AxValidationMessage(stateOutput.getKey(), this.getClass(),
@@ -562,16 +533,6 @@ public class AxPolicyModel extends AxModel {
ValidationResult.INVALID, "output event " + stateOutput.getOutgoingEvent().getId()
+ " for state output " + stateOutput.getId() + DOES_NOT_EXIST));
}
-
- if (task != null && usedEvent != null) {
- final Set<AxField> unhandledTaskOutputFields = new TreeSet<>(task.getOutputFieldSet());
- unhandledTaskOutputFields.removeAll(usedEvent.getFields());
- for (final AxField unhandledTaskOutputField : unhandledTaskOutputFields) {
- result.addValidationMessage(new AxValidationMessage(state.getKey(), this.getClass(),
- ValidationResult.INVALID, "task output field " + unhandledTaskOutputField + " for task "
- + task.getId() + " not in output event " + usedEvent.getId()));
- }
- }
}
}
diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java
index a30a80acc..7eba99af0 100644
--- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java
@@ -56,9 +56,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
-import org.onap.policy.apex.model.eventmodel.concepts.AxField;
-import org.onap.policy.apex.model.eventmodel.concepts.AxInputField;
-import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField;
import org.onap.policy.common.utils.validation.Assertions;
/**
@@ -78,12 +75,6 @@ import org.onap.policy.common.utils.validation.Assertions;
* <ol>
* <li>The task key must not be a null key and must be valid, see validation in
* {@link AxArtifactKey}
- * <li>The task must have at least one input field
- * <li>The parent of each input field of a task must be that task
- * <li>Each input field must be valid, see validation in {@link AxInputField}
- * <li>The task must have at least one output field
- * <li>The parent of each output field of a task must be that task
- * <li>Each output field must be valid, see validation in {@link AxOutputField}
* <li>The parent of each task parameter of a task must be that task
* <li>Each task parameter must be valid, see validation in {@link AxTaskParameter}
* <li>The parent of the task logic in a task must be that task
@@ -99,7 +90,7 @@ import org.onap.policy.common.utils.validation.Assertions;
@XmlType(
name = "AxTask",
namespace = "http://www.onap.org/policy/apex-pdp",
- propOrder = {"key", "inputEvent", "outputEvents", "inputFields", "outputFields", "taskParameters",
+ propOrder = {"key", "inputEvent", "outputEvents", "taskParameters",
"contextAlbumReferenceSet", "taskLogic"})
@Getter
@Setter
@@ -130,14 +121,6 @@ public class AxTask extends AxConcept {
private Map<String, AxEvent> outputEvents;
@OneToMany(cascade = CascadeType.ALL)
- @XmlElement(name = "inputFields", required = true)
- private Map<String, AxInputField> inputFields;
-
- @OneToMany(cascade = CascadeType.ALL)
- @XmlElement(name = "outputFields", required = true)
- private Map<String, AxOutputField> outputFields;
-
- @OneToMany(cascade = CascadeType.ALL)
@XmlElement(name = "taskParameters", required = true)
private Map<String, AxTaskParameter> taskParameters;
@@ -181,8 +164,6 @@ public class AxTask extends AxConcept {
*/
public AxTask(final AxArtifactKey key) {
this(key, // Task Key
- new TreeMap<>(), // Input fields
- new TreeMap<>(), // Output Fields
new TreeMap<>(), // Task Parameters
new TreeSet<>(), // Context Album References
new AxTaskLogic(new AxReferenceKey(key)) // Task Logic
@@ -193,27 +174,20 @@ public class AxTask extends AxConcept {
* This Constructor defines all the fields of the task.
*
* @param key the key of the task
- * @param inputFields the input fields that the task expects
- * @param outputFields the output fields that the task emits
* @param taskParameters the task parameters that are used to initialize tasks of this type
* @param contextAlbumReferenceSet the context album reference set defines the context that may
* be used by Task Logic in the state
* @param taskLogic the task logic that performs the domain specific work of the task
*/
- public AxTask(final AxArtifactKey key, final Map<String, AxInputField> inputFields,
- final Map<String, AxOutputField> outputFields, final Map<String, AxTaskParameter> taskParameters,
- final Set<AxArtifactKey> contextAlbumReferenceSet, final AxTaskLogic taskLogic) {
+ public AxTask(final AxArtifactKey key, final Map<String, AxTaskParameter> taskParameters,
+ final Set<AxArtifactKey> contextAlbumReferenceSet, final AxTaskLogic taskLogic) {
super();
Assertions.argumentNotNull(key, "key may not be null");
- Assertions.argumentNotNull(inputFields, "inputFields may not be null");
- Assertions.argumentNotNull(outputFields, "outputFields may not be null");
Assertions.argumentNotNull(taskParameters, "taskParameters may not be null");
Assertions.argumentNotNull(contextAlbumReferenceSet, "contextAlbumReferenceSet may not be null");
Assertions.argumentNotNull(taskLogic, "taskLogic may not be null");
this.key = key;
- this.inputFields = inputFields;
- this.outputFields = outputFields;
this.taskParameters = taskParameters;
this.contextAlbumReferenceSet = contextAlbumReferenceSet;
this.taskLogic = taskLogic;
@@ -222,23 +196,13 @@ public class AxTask extends AxConcept {
/**
* When a task is unmarshalled from disk or from the database, the parent of contained objects
* is not defined. This method is called by JAXB after unmarshaling and is used to set the
- * parent keys of all {@link AxInputField}, {@link AxOutputField}, and {@link AxTaskParameter}
- * instance in the task.
+ * parent keys of all {@link AxTaskParameter} instance in the task.
*
* @param unmarshaler the unmarshaler that is unmarshaling the model
* @param parent the parent object of this object in the unmarshaler
*/
public void afterUnmarshal(final Unmarshaller unmarshaler, final Object parent) {
taskLogic.getKey().setParentArtifactKey(key);
-
- for (final AxInputField inputField : inputFields.values()) {
- inputField.getKey().setParentArtifactKey(key);
- inputField.getKey().setParentLocalName("InField");
- }
- for (final AxOutputField outputField : outputFields.values()) {
- outputField.getKey().setParentArtifactKey(key);
- outputField.getKey().setParentLocalName("OutField");
- }
for (final AxTaskParameter parameter : taskParameters.values()) {
parameter.getKey().setParentArtifactKey(key);
}
@@ -250,12 +214,6 @@ public class AxTask extends AxConcept {
@Override
public List<AxKey> getKeys() {
final List<AxKey> keyList = key.getKeys();
- for (final AxInputField inputField : inputFields.values()) {
- keyList.addAll(inputField.getKeys());
- }
- for (final AxOutputField outputField : outputFields.values()) {
- keyList.addAll(outputField.getKeys());
- }
for (final AxTaskParameter taskParameter : taskParameters.values()) {
keyList.addAll(taskParameter.getKeys());
}
@@ -267,85 +225,6 @@ public class AxTask extends AxConcept {
}
/**
- * Gets the raw input fields that the task expects as a tree map.
- *
- * @return the raw input fields that the task expects
- */
- public Map<String, AxField> getRawInputFields() {
- return new TreeMap<>(inputFields);
- }
-
- /**
- * Convenience method to get the input fields as a set.
- *
- * @return the input fields as a set
- */
- public Set<AxField> getInputFieldSet() {
- final Set<AxField> inputFieldSet = new TreeSet<>();
- for (final AxInputField field : inputFields.values()) {
- inputFieldSet.add(field);
- }
- return inputFieldSet;
- }
-
- /**
- * Copy the input fields from the given map into the task. This method is used to get a copy of
- * the input fields, which can be useful for unit testing of policies and tasks.
- *
- * @param fields the fields to copy into the task
- */
- public void duplicateInputFields(final Map<String, AxField> fields) {
- Assertions.argumentNotNull(fields, "fields may not be null");
-
- for (final AxField field : fields.values()) {
- final AxReferenceKey fieldKey = new AxReferenceKey(this.getKey().getName(), this.getKey().getVersion(),
- "inputFields", field.getKey().getLocalName());
- final AxInputField inputField = new AxInputField(fieldKey, field.getSchema());
- inputFields.put(inputField.getKey().getLocalName(), inputField);
- }
- }
-
- /**
- * Gets the raw output fields that the task emits as a tree map.
- *
- * @return the raw output fields as a tree map
- */
- public Map<String, AxField> getRawOutputFields() {
- return new TreeMap<>(outputFields);
- }
-
- /**
- * Gets the output fields that the task emits as a set.
- *
- * @return the output fields as a set
- */
- public Set<AxField> getOutputFieldSet() {
- final Set<AxField> outputFieldSet = new TreeSet<>();
- for (final AxOutputField field : outputFields.values()) {
- outputFieldSet.add(field);
- }
- return outputFieldSet;
- }
-
- /**
- * Copy the output fields from the given map into the task. This method is used to get a copy of
- * the output fields, which can be useful for unit testing of policies and tasks.
- *
- * @param fields the fields to copy into the task
- */
- public void duplicateOutputFields(final Map<String, AxField> fields) {
- Assertions.argumentNotNull(fields, "fields may not be null");
-
- for (final AxField field : fields.values()) {
- final AxReferenceKey fieldKey = new AxReferenceKey(this.getKey().getName(), this.getKey().getVersion(),
- "outputFields", field.getKey().getLocalName());
- final AxOutputField outputField = new AxOutputField(fieldKey, field.getSchema());
- outputFields.put(outputField.getKey().getLocalName(), outputField);
- }
- }
-
-
- /**
* Gets the context album reference set defines the context that may be used by Task Logic in
* the state.
*
@@ -446,12 +325,6 @@ public class AxTask extends AxConcept {
@Override
public void clean() {
key.clean();
- for (final AxInputField inputField : inputFields.values()) {
- inputField.clean();
- }
- for (final AxOutputField outputField : outputFields.values()) {
- outputField.clean();
- }
for (final AxTaskParameter parameter : taskParameters.values()) {
parameter.clean();
}
@@ -471,10 +344,6 @@ public class AxTask extends AxConcept {
builder.append(":(");
builder.append("key=");
builder.append(key);
- builder.append(",inputFields=");
- builder.append(inputFields);
- builder.append(",outputFields=");
- builder.append(outputFields);
builder.append(",taskParameters=");
builder.append(taskParameters);
builder.append(",contextAlbumReferenceSet=");
@@ -498,18 +367,6 @@ public class AxTask extends AxConcept {
final AxTask copy = ((AxTask) copyObject);
copy.setKey(key);
- final Map<String, AxInputField> newInputFields = new TreeMap<>();
- for (final Entry<String, AxInputField> inputFieldEntry : inputFields.entrySet()) {
- newInputFields.put(inputFieldEntry.getKey(), new AxInputField(inputFieldEntry.getValue()));
- }
- copy.setInputFields(newInputFields);
-
- final Map<String, AxOutputField> newOutputFields = new TreeMap<>();
- for (final Entry<String, AxOutputField> outputFieldEntry : outputFields.entrySet()) {
- newOutputFields.put(outputFieldEntry.getKey(), new AxOutputField(outputFieldEntry.getValue()));
- }
- copy.setOutputFields(newOutputFields);
-
final Map<String, AxTaskParameter> newTaskParameter = new TreeMap<>();
for (final Entry<String, AxTaskParameter> taskParameterEntry : taskParameters.entrySet()) {
newTaskParameter.put(taskParameterEntry.getKey(), new AxTaskParameter(taskParameterEntry.getValue()));
@@ -535,8 +392,6 @@ public class AxTask extends AxConcept {
final int prime = 31;
int result = 1;
result = prime * result + key.hashCode();
- result = prime * result + inputFields.hashCode();
- result = prime * result + outputFields.hashCode();
result = prime * result + taskParameters.hashCode();
result = prime * result + contextAlbumReferenceSet.hashCode();
result = prime * result + taskLogic.hashCode();
@@ -563,12 +418,6 @@ public class AxTask extends AxConcept {
if (!key.equals(other.key)) {
return false;
}
- if (!inputFields.equals(other.inputFields)) {
- return false;
- }
- if (!outputFields.equals(other.outputFields)) {
- return false;
- }
if (!taskParameters.equals(other.taskParameters)) {
return false;
}
@@ -597,12 +446,6 @@ public class AxTask extends AxConcept {
if (!key.equals(other.key)) {
return key.compareTo(other.key);
}
- if (!inputFields.equals(other.inputFields)) {
- return (inputFields.hashCode() - other.inputFields.hashCode());
- }
- if (!outputFields.equals(other.outputFields)) {
- return (outputFields.hashCode() - other.outputFields.hashCode());
- }
if (!taskParameters.equals(other.taskParameters)) {
return (taskParameters.hashCode() - other.taskParameters.hashCode());
}
diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java
index 3a4c36bc5..6731caf30 100644
--- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java
@@ -29,8 +29,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
import org.onap.policy.apex.model.eventmodel.concepts.AxField;
-import org.onap.policy.apex.model.eventmodel.concepts.AxInputField;
-import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicy;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
import org.onap.policy.apex.model.policymodel.concepts.AxState;
@@ -163,14 +161,6 @@ public class PolicyAnalyser {
for (final AxArtifactKey contextAlbumKey : task.getContextAlbumReferences()) {
result.getContextAlbumUsage().get(contextAlbumKey).add(task.getKey());
}
-
- // Task data type usage
- for (final AxInputField inputField : task.getInputFields().values()) {
- result.getContextSchemaUsage().get(inputField.getSchema()).add(task.getKey());
- }
- for (final AxOutputField outputField : task.getOutputFields().values()) {
- result.getContextSchemaUsage().get(outputField.getSchema()).add(task.getKey());
- }
}
/**