diff options
Diffstat (limited to 'core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java')
-rw-r--r-- | core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java | 38 |
1 files changed, 22 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(); } /** |