diff options
Diffstat (limited to 'services/services-onappf')
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) |