aboutsummaryrefslogtreecommitdiffstats
path: root/core/core-engine/src/main/java/org
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2019-11-05 14:37:09 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2019-11-14 12:15:55 +0000
commit40a1f22ff8d28e78b6512c0a10d454b37f015fdb (patch)
tree8d92efb03c45615bf8697db4adcee558a80eb9e7 /core/core-engine/src/main/java/org
parent8c95a09fd412c89b1eaf7d0658005ffba24025bd (diff)
Retaining context in APEX Engine based on policies received in PdpUpdate
Change-Id: I73fad5bf76ed6b4979f5ab76013f204ea82da30b Issue-ID: POLICY-2215 Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'core/core-engine/src/main/java/org')
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java27
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/ApexEngine.java5
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java7
3 files changed, 27 insertions, 12 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 3d6a72451..0589e8311 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
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,14 +22,12 @@
package org.onap.policy.apex.core.engine.context;
import com.google.common.collect.Maps;
-
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
-
import org.onap.policy.apex.context.ContextAlbum;
import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.context.Distributor;
@@ -113,13 +112,24 @@ public class ApexInternalContext implements AxConceptGetter<ContextAlbum> {
* in the new model.
*
* @param newPolicyModel The new incoming Apex model to use for context
+ * @param isSubsequentInstance if the current worker instance being updated is not the first one
* @throws ContextException On errors on context setting
*/
- public void update(final AxPolicyModel newPolicyModel) throws ContextException {
+ public void update(final AxPolicyModel newPolicyModel, boolean isSubsequentInstance) throws ContextException {
if (newPolicyModel == null) {
throw new ContextException("internal context update failed, supplied model is null");
}
-
+ // context is shared between all the engine instances
+ // during model update context album only needs to be updated for the first instance.
+ // remaining engine instances can just copy the context
+ if (isSubsequentInstance) {
+ contextAlbums.clear();
+ for (AxArtifactKey contextAlbumKey : ModelService.getModel(AxContextAlbums.class).getAlbumsMap().keySet()) {
+ contextAlbums.put(contextAlbumKey, contextDistributor.createContextAlbum(contextAlbumKey));
+ }
+ key = newPolicyModel.getKey();
+ return;
+ }
// Get the differences between the existing context and the new context
final KeyedMapDifference<AxArtifactKey, AxContextAlbum> contextDifference =
new ContextComparer().compare(ModelService.getModel(AxContextAlbums.class), newPolicyModel.getAlbums());
@@ -143,11 +153,11 @@ public 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());
+ contextDistributor.removeContextAlbum(removedContextAlbumEntry.getKey());
contextAlbums.remove(removedContextAlbumEntry.getKey());
}
@@ -156,6 +166,11 @@ public class ApexInternalContext implements AxConceptGetter<ContextAlbum> {
// Set up the new context albums
for (final AxArtifactKey contextAlbumKey : contextDifference.getRightOnly().keySet()) {
+ // In case if a context album is part of previous and current model, but needs to be cleared
+ // for example, due to a major version change
+ if (contextAlbums.containsKey(contextAlbumKey)) {
+ contextDistributor.removeContextAlbum(contextAlbumKey);
+ }
contextAlbums.put(contextAlbumKey, contextDistributor.createContextAlbum(contextAlbumKey));
}
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/ApexEngine.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/ApexEngine.java
index 2c5167d1b..4c4166380 100644
--- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/ApexEngine.java
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/ApexEngine.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +22,6 @@
package org.onap.policy.apex.core.engine.engine;
import java.util.Map;
-
import org.onap.policy.apex.core.engine.event.EnEvent;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
@@ -49,9 +49,10 @@ public interface ApexEngine {
* transferred if there is common context in the old and new models.
*
* @param apexModel the apex model
+ * @param isSubsequentInstance if the current worker instance being updated is not the first one
* @throws ApexException on model update errors
*/
- void updateModel(AxPolicyModel apexModel) throws ApexException;
+ void updateModel(AxPolicyModel apexModel, boolean isSubsequentInstance) throws ApexException;
/**
* Starts an Apex engine so that it can receive events.
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
index 87ce1230e..9cbd2050f 100644
--- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
@@ -26,7 +26,6 @@ import static org.onap.policy.common.utils.validation.Assertions.argumentNotNull
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
-
import org.onap.policy.apex.context.ContextAlbum;
import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
@@ -105,7 +104,7 @@ public class ApexEngineImpl implements ApexEngine {
* {@inheritDoc}.
*/
@Override
- public void updateModel(final AxPolicyModel apexModel) throws ApexException {
+ public void updateModel(final AxPolicyModel apexModel, final boolean isSubsequentInstance) throws ApexException {
if (apexModel != null) {
LOGGER.entry("updateModel()->" + key.getId() + ", apexPolicyModel=" + apexModel.getKey().getId());
} else {
@@ -125,8 +124,8 @@ public class ApexEngineImpl implements ApexEngine {
/// New internal context
internalContext = new ApexInternalContext(apexModel);
} else {
- // Exiting internal context which must be updated
- internalContext.update(apexModel);
+ // Existing internal context which must be updated
+ internalContext.update(apexModel, isSubsequentInstance);
}
} catch (final ContextException e) {
LOGGER.warn(UPDATE_MODEL + key.getId() + ", error setting the context for engine \"" + key.getId() + "\"",