diff options
Diffstat (limited to 'core/core-engine/src/main')
2 files changed, 72 insertions, 16 deletions
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java index 8bbb333b5..f73281ada 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java @@ -53,7 +53,7 @@ import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference; */ public final class ApexInternalContext implements AxConceptGetter<ContextAlbum> { // The key of the currently running Apex model - private final AxArtifactKey key; + private AxArtifactKey key; // The context albums being used in this engine private final NavigableMap<AxArtifactKey, ContextAlbum> contextAlbums = @@ -72,6 +72,9 @@ public final class ApexInternalContext implements AxConceptGetter<ContextAlbum> * @throws ContextException On errors on context setting */ public ApexInternalContext(final AxPolicyModel apexPolicyModel) throws ContextException { + if (apexPolicyModel == null) { + throw new ContextException("internal context update failed, supplied model is null"); + } apexPolicyModel.register(); // The context distributor used to distribute context across policy engine instances @@ -121,20 +124,6 @@ public final class ApexInternalContext implements AxConceptGetter<ContextAlbum> final KeyedMapDifference<AxArtifactKey, AxContextAlbum> contextDifference = new ContextComparer().compare(ModelService.getModel(AxContextAlbums.class), newPolicyModel.getAlbums()); - // Remove maps that are no longer used - for (final Entry<AxArtifactKey, AxContextAlbum> removedContextAlbumEntry : contextDifference.getLeftOnly() - .entrySet()) { - contextDistributor.removeContextAlbum(removedContextAlbumEntry.getValue()); - contextAlbums.remove(removedContextAlbumEntry.getKey()); - } - - // We switch over to the new Apex model - newPolicyModel.register(); - - // Set up the new context albums - for (final AxArtifactKey contextAlbumKey : contextDifference.getRightOnly().keySet()) { - contextAlbums.put(contextAlbumKey, contextDistributor.createContextAlbum(contextAlbumKey)); - } // Handle the updated maps for (final Entry<AxArtifactKey, List<AxContextAlbum>> contextAlbumEntry : contextDifference.getDifferentValues() @@ -144,7 +133,7 @@ public final class ApexInternalContext implements AxConceptGetter<ContextAlbum> final AxContextAlbum newContextAlbum = contextAlbumEntry.getValue().get(1); // Check that the schemas are the same on the old and new context albums - if (currentContextAlbum.getItemSchema().equals(newContextAlbum.getItemSchema())) { + if (!currentContextAlbum.getItemSchema().equals(newContextAlbum.getItemSchema())) { // The schema is different, throw an exception because the schema should not change if the key of the // album has not changed throw new ContextException("internal context update failed on context album \"" @@ -154,7 +143,24 @@ public final class ApexInternalContext implements AxConceptGetter<ContextAlbum> + newContextAlbum.getItemSchema().getId() + "\" on incoming model"); } } + + // Remove maps that are no longer used + for (final Entry<AxArtifactKey, AxContextAlbum> removedContextAlbumEntry : contextDifference.getLeftOnly() + .entrySet()) { + contextDistributor.removeContextAlbum(removedContextAlbumEntry.getValue()); + contextAlbums.remove(removedContextAlbumEntry.getKey()); + } + // We switch over to the new Apex model + newPolicyModel.register(); + + // Set up the new context albums + for (final AxArtifactKey contextAlbumKey : contextDifference.getRightOnly().keySet()) { + contextAlbums.put(contextAlbumKey, contextDistributor.createContextAlbum(contextAlbumKey)); + } + + // Record the key of the current model + key = newPolicyModel.getKey(); } /** diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnEvent.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnEvent.java index 58bee8238..c510763cc 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnEvent.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnEvent.java @@ -89,6 +89,10 @@ public class EnEvent extends HashMap<String, Object> { */ public EnEvent(final AxEvent axEvent) { super(); + + if (axEvent == null) { + throw new EnException("event definition is null or was not found in model service"); + } // Save the event definition from the Apex model this.axEvent = axEvent; } @@ -173,6 +177,16 @@ public class EnEvent extends HashMap<String, Object> { this.exceptionMessage = exceptionMessage; } + + /** + * Get the user artifact stack of the event. + * + * @return the event user artifact stack + */ + public AxConcept[] getUserArtifactStack() { + return userArtifactStack; + } + /** * Store the user artifact stack of the event. * @@ -345,4 +359,40 @@ public class EnEvent extends HashMap<String, Object> { return "EnEvent [axEvent=" + axEvent + ", userArtifactStack=" + Arrays.toString(userArtifactStack) + ", map=" + super.toString() + "]"; } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + axEvent.hashCode(); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof EnEvent)) { + return false; + } + EnEvent other = (EnEvent) obj; + if (axEvent == null) { + if (other.axEvent != null) { + return false; + } + } else if (!axEvent.equals(other.axEvent)) { + return false; + } + return true; + } } |