summaryrefslogtreecommitdiffstats
path: root/services/services-onappf/src/main/java
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 /services/services-onappf/src/main/java
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 'services/services-onappf/src/main/java')
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java37
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java7
2 files changed, 34 insertions, 10 deletions
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
index 1953939b7..6a5bb17ff 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
@@ -56,6 +56,35 @@ public class ApexEngineHandler {
* @throws ApexStarterException if the apex engine instantiation failed using the policies passed
*/
public ApexEngineHandler(List<ToscaPolicy> policies) throws ApexStarterException {
+ Map<ToscaPolicyIdentifier, String[]> policyArgsMap = createPolicyArgsMap(policies);
+ LOGGER.debug("Starting apex engine.");
+ try {
+ apexMain = new ApexMain(policyArgsMap);
+ } catch (ApexException e) {
+ throw new ApexStarterException(e);
+ }
+ }
+
+ /**
+ * Updates the Apex Engine with the policy model created from new list of policies.
+ *
+ * @param policies the list of policies
+ * @throws ApexStarterException if the apex engine instantiation failed using the policies passed
+ */
+ public void updateApexEngine(List<ToscaPolicy> policies) throws ApexStarterException {
+ if (null == apexMain || !apexMain.isAlive()) {
+ throw new ApexStarterException("Apex Engine not initialized.");
+ }
+ Map<ToscaPolicyIdentifier, String[]> policyArgsMap = createPolicyArgsMap(policies);
+ try {
+ apexMain.updateModel(policyArgsMap);
+ } catch (ApexException e) {
+ throw new ApexStarterException(e);
+ }
+ }
+
+ private Map<ToscaPolicyIdentifier, String[]> createPolicyArgsMap(List<ToscaPolicy> policies)
+ throws ApexStarterException {
Map<ToscaPolicyIdentifier, String[]> policyArgsMap = new LinkedHashMap<>();
for (ToscaPolicy policy : policies) {
Object properties = policy.getProperties().get("content");
@@ -78,13 +107,7 @@ public class ApexEngineHandler {
final String[] apexArgs = { "-c", apexConfigFilePath, "-m", modelFilePath };
policyArgsMap.put(policy.getIdentifier(), apexArgs);
}
-
- LOGGER.debug("Starting apex engine.");
- try {
- apexMain = new ApexMain(policyArgsMap);
- } catch (ApexException e) {
- throw new ApexStarterException(e);
- }
+ return policyArgsMap;
}
/**
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
index ecc0bec21..33ac81f5d 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
@@ -162,10 +162,11 @@ public class PdpUpdateMessageHandler {
PdpResponseDetails pdpResponseDetails = null;
try {
if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) {
- apexEngineHandler.shutdown();
+ apexEngineHandler.updateApexEngine(pdpUpdateMsg.getPolicies());
+ } else {
+ apexEngineHandler = new ApexEngineHandler(pdpUpdateMsg.getPolicies());
+ Registry.registerOrReplace(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, apexEngineHandler);
}
- apexEngineHandler = new ApexEngineHandler(pdpUpdateMsg.getPolicies());
- Registry.registerOrReplace(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, apexEngineHandler);
if (apexEngineHandler.isApexEngineRunning()) {
List<ToscaPolicyIdentifier> runningPolicies = apexEngineHandler.getRunningPolicies();
if (new HashSet<>(runningPolicies)