summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@bell.ca>2021-02-09 18:21:49 +0000
committerAjith Sreekumar <ajith.sreekumar@bell.ca>2021-02-11 10:01:27 +0000
commitf86d08ca5598571410386372f3f06d5c8c686c74 (patch)
tree644913448310e4ea5fe201c16554a2f739d49a43 /services
parentc64320a45b77eb3474f1f3f7372f1cd1f85ddfef (diff)
Changes related to multi policy handling improvement in APEX
This review fixes an issue identified during testing the changes done for improving multiple policy handling in APEX. Changes done to a few test files in the previous review are reverted as well. Change-Id: I98324da708239d314aadd4c45dc377137fd552ba Issue-ID: POLICY-2883 Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'services')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java19
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java97
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java158
3 files changed, 141 insertions, 133 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java
index 65c2acffa..3e9072dd4 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java
@@ -71,7 +71,7 @@ public class ApexMain {
* @param args the command line arguments
* @throws ApexException the apex exception.
*/
- public ApexMain(final String[] args) throws ApexException {
+ public ApexMain(final String[] args) {
LOGGER.entry("Starting Apex service with parameters " + Arrays.toString(args) + " . . .");
try {
apexParameters = populateApexParameters(args);
@@ -79,17 +79,18 @@ public class ApexMain {
LOGGER.error(APEX_SERVICE_FAILED_MSG, e);
return;
}
- aggregateParametersAndRegister();
+ try {
+ aggregateParametersAndRegister();
- // Now, create the activator for the Apex service
- activator = new ApexActivator(apexParameters);
+ // Now, create the activator for the Apex service
+ activator = new ApexActivator(apexParameters);
- // Start the activator
- try {
+ // Start the activator
activator.initialize();
setAlive(true);
- } catch (final ApexActivatorException e) {
- throw new ApexException("start of Apex service failed, used parameters are " + Arrays.toString(args), e);
+ } catch (final ApexException e) {
+ LOGGER.error("start of Apex service failed, used parameters are {}", Arrays.toString(args), e);
+ return;
}
// Add a shutdown hook to shut everything down in an orderly manner
@@ -246,7 +247,7 @@ public class ApexMain {
* @param args the arguments
* @throws ApexException the apex exception.
*/
- public static void main(final String[] args) throws ApexException {
+ public static void main(final String[] args) {
new ApexMain(args);
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
index 2cb12c397..5764a5275 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
@@ -23,7 +23,6 @@
package org.onap.policy.apex.service.engine.main;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -31,10 +30,10 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
import java.io.PrintStream;
import java.util.concurrent.TimeUnit;
import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.service.ModelService;
@@ -44,7 +43,20 @@ import org.onap.policy.common.parameters.ParameterService;
* Test the ApexMain class.
*/
public class ApexMainTest {
- private PrintStream stdout = System.out;
+ private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+ private final PrintStream stdout = System.out;
+ private ApexMain apexMain1;
+ private ApexMain apexMain2;
+
+ /**
+ * Method for set up before each test.
+ *
+ * @throws Exception if an error occurs
+ */
+ @Before
+ public void setUp() throws Exception {
+ System.setOut(new PrintStream(outContent));
+ }
/**
* Method for cleanup after each test.
@@ -53,14 +65,17 @@ public class ApexMainTest {
*/
@After
public void teardown() throws Exception {
+ if (null != apexMain1) {
+ apexMain1.shutdown();
+ }
+ if (null != apexMain2) {
+ apexMain2.shutdown();
+ }
System.setOut(stdout);
}
@Test
public void testNullParameters() throws ApexException {
- OutputStream outContent = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outContent));
-
ApexMain.main(null);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
.contains("Tosca Policy file was not specified as an argument"));
@@ -70,95 +85,71 @@ public class ApexMainTest {
@Test
public void testBadArguments() throws ApexException {
- OutputStream outContent = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outContent));
-
String[] args = { "-whee" };
- final ApexMain apexMain = new ApexMain(args);
+ apexMain1 = new ApexMain(args);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
.contains("invalid command line arguments specified : Unrecognized option: -whee"));
- assertNotNull(apexMain);
- apexMain.shutdown();
+ assertNotNull(apexMain1);
}
@Test
public void testHelp() throws ApexException {
- OutputStream outContent = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outContent));
-
String[] args = { "-h" };
- final ApexMain apexMain = new ApexMain(args);
+ apexMain1 = new ApexMain(args);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
.contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- assertNotNull(apexMain);
- apexMain.shutdown();
+ assertNotNull(apexMain1);
}
@Test
public void testBadParameters() throws ApexException {
- OutputStream outContent = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outContent));
-
String[] args = { "-p", "src/test/resources/parameters/badParams.json" };
- final ApexMain apexMain = new ApexMain(args);
+ apexMain1 = new ApexMain(args);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
.contains("parameter group has status INVALID"));
- assertNotNull(apexMain);
- apexMain.shutdown();
+ assertNotNull(apexMain1);
}
@Test
public void testCorrectParameters() throws ApexException {
- OutputStream outContent = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outContent));
-
String[] args = {"-p", "src/test/resources/parameters/correctParams.json"};
- final ApexMain apexMain = new ApexMain(args);
- assertEquals("MyApexEngine", apexMain.getApexParameters().getEngineServiceParameters().getName());
+ apexMain1 = new ApexMain(args);
+ assertEquals("MyApexEngine", apexMain1.getApexParameters().getEngineServiceParameters().getName());
await().atMost(200, TimeUnit.MILLISECONDS)
.until(() -> outContent.toString().contains("Added the action listener to the engine"));
- assertTrue(apexMain.isAlive());
- apexMain.shutdown();
+ assertTrue(apexMain1.isAlive());
}
@Test
public void testJavaProperties() throws ApexException {
- OutputStream outContent = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outContent));
-
String[] args = {"-p", "src/test/resources/parameters/correctParamsJavaProperties.json"};
- final ApexMain apexMain = new ApexMain(args);
- assertEquals("MyApexEngine", apexMain.getApexParameters().getEngineServiceParameters().getName());
+ apexMain1 = new ApexMain(args);
+ assertEquals("MyApexEngine", apexMain1.getApexParameters().getEngineServiceParameters().getName());
assertEquals("trust-store-file", System.getProperty("javax.net.ssl.trustStore"));
assertEquals("Pol1cy_0nap", System.getProperty("javax.net.ssl.trustStorePassword"));
await().atMost(10000, TimeUnit.MILLISECONDS)
.until(() -> outContent.toString().contains("Added the action listener to the engine"));
- apexMain.shutdown();
}
@Test
public void testCorrectParametersWithMultiplePolicies() throws ApexException {
- OutputStream outContent = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outContent));
String[] args1 = {"-p", "src/test/resources/parameters/correctParams.json"};
String[] args2 = {"-p", "src/test/resources/parameters/correctParams2.json"};
- final ApexMain apexMain1 = new ApexMain(args1);
- final ApexMain apexMain2 = new ApexMain(args2);
+ apexMain1 = new ApexMain(args1);
+ apexMain2 = new ApexMain(args2);
assertEquals("MyApexEngine", apexMain1.getApexParameters().getEngineServiceParameters().getName());
assertEquals("MyApexEngine2", apexMain2.getApexParameters().getEngineServiceParameters().getName());
+ assertTrue(apexMain1.isAlive());
+ assertTrue(apexMain2.isAlive());
final String outString = outContent.toString();
assertThat(outString).contains("Added the action listener to the engine")
.contains("Created apex engine MyApexEngine").contains("Created apex engine MyApexEngine2");
- assertTrue(apexMain1.isAlive());
- assertTrue(apexMain2.isAlive());
- apexMain1.shutdown();
- apexMain2.shutdown();
ModelService.clear();
ParameterService.clear();
}
@@ -166,21 +157,21 @@ public class ApexMainTest {
@Test
public void testInCorrectParametersWithMultiplePolicies() throws ApexException {
String[] args = {"-p", "src/test/resources/parameters/correctParams.json"};
- final ApexMain apexMain1 = new ApexMain(args);
- assertThatThrownBy(() -> new ApexMain(args)).hasMessage("start of Apex service failed because this"
+ apexMain1 = new ApexMain(args);
+ apexMain2 = new ApexMain(args);
+ assertTrue(apexMain1.isAlive());
+ assertFalse(apexMain2.isAlive());
+ final String outString = outContent.toString();
+ assertThat(outString).contains("start of Apex service failed because this"
+ " policy has the following duplicate I/O parameters: [TheFileConsumer1]/[FirstProducer]");
- apexMain1.shutdown();
}
@Test
public void testInvalidArgsWithMultiplePolicies() throws ApexException {
- OutputStream outContent = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outContent));
String[] args = {"-c", "file1", "-m", "file2"};
- final ApexMain apexMain = new ApexMain(args);
+ apexMain1 = new ApexMain(args);
+ assertFalse(apexMain1.isAlive());
final String outString = outContent.toString();
- apexMain.shutdown();
assertThat(outString).contains("Arguments validation failed", "start of Apex service failed");
- assertFalse(apexMain.isAlive()); // No policy is running in the engine
}
}
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 03e97215b..5a113a77d 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
@@ -72,7 +72,7 @@ public class ApexEngineHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ApexEngineHandler.class);
- private Map<ToscaConceptIdentifier, ApexMain> apexMainMap;
+ private Map<ToscaConceptIdentifier, ApexMain> apexMainMap = new LinkedHashMap<>();
/**
* Constructs the object. Extracts the config and model files from each policy and instantiates the apex engine.
@@ -82,12 +82,7 @@ public class ApexEngineHandler {
*/
public ApexEngineHandler(List<ToscaPolicy> policies) throws ApexStarterException {
LOGGER.debug("Starting apex engine.");
- apexMainMap = initiateApexEngineForPolicies(policies);
- if (apexMainMap.isEmpty()) {
- ModelService.clear();
- ParameterService.clear();
- throw new ApexStarterException("Apex Engine failed to start.");
- }
+ initiateApexEngineForPolicies(policies);
}
/**
@@ -118,11 +113,7 @@ public class ApexEngineHandler {
updateModelAndParameterServices(undeployedPoliciesMainMap);
}
if (!policiesToDeploy.isEmpty()) {
- Map<ToscaConceptIdentifier, ApexMain> mainMap = initiateApexEngineForPolicies(policiesToDeploy);
- if (mainMap.isEmpty()) {
- throw new ApexStarterException("Updating the APEX engine with new policies failed.");
- }
- apexMainMap.putAll(mainMap);
+ initiateApexEngineForPolicies(policiesToDeploy);
}
if (apexMainMap.isEmpty()) {
ModelService.clear();
@@ -168,65 +159,80 @@ public class ApexEngineHandler {
policyKeystoRetain.addAll(main.getActivator().getPolicyModel().getPolicies().getPolicyMap().keySet());
});
for (ApexMain main : undeployedPoliciesMainMap.values()) {
- ApexParameters existingParameters = ParameterService.get(ApexParameterConstants.MAIN_GROUP_NAME);
- List<String> eventInputParamKeysToRemove = main.getApexParameters().getEventInputParameters().keySet()
- .stream().filter(key -> !inputParamKeysToRetain.contains(key)).collect(Collectors.toList());
- List<String> eventOutputParamKeysToRemove = main.getApexParameters().getEventOutputParameters().keySet()
- .stream().filter(key -> !outputParamKeysToRetain.contains(key)).collect(Collectors.toList());
- eventInputParamKeysToRemove.forEach(existingParameters.getEventInputParameters()::remove);
- eventOutputParamKeysToRemove.forEach(existingParameters.getEventOutputParameters()::remove);
- EngineParameters engineParameters =
- main.getApexParameters().getEngineServiceParameters().getEngineParameters();
- final List<TaskParameters> taskParametersToRemove = engineParameters.getTaskParameters().stream()
- .filter(taskParameter -> !taskParametersToRetain.contains(taskParameter)).collect(Collectors.toList());
- final List<String> executorParamKeysToRemove = engineParameters.getExecutorParameterMap().keySet().stream()
- .filter(key -> !executorParamKeysToRetain.contains(key)).collect(Collectors.toList());
- final List<String> schemaParamKeysToRemove =
- engineParameters.getContextParameters().getSchemaParameters().getSchemaHelperParameterMap().keySet()
- .stream().filter(key -> !schemaParamKeysToRetain.contains(key)).collect(Collectors.toList());
- EngineParameters aggregatedEngineParameters =
- existingParameters.getEngineServiceParameters().getEngineParameters();
- aggregatedEngineParameters.getTaskParameters().removeAll(taskParametersToRemove);
- executorParamKeysToRemove.forEach(aggregatedEngineParameters.getExecutorParameterMap()::remove);
- schemaParamKeysToRemove.forEach(aggregatedEngineParameters.getContextParameters().getSchemaParameters()
- .getSchemaHelperParameterMap()::remove);
+ handleParametersRemoval(inputParamKeysToRetain, outputParamKeysToRetain, taskParametersToRetain,
+ executorParamKeysToRetain, schemaParamKeysToRetain, main);
+
+ if (null != main.getActivator() && null != main.getActivator().getPolicyModel()) {
+ handleAxConceptsRemoval(keyInfoKeystoRetain, schemaKeystoRetain, eventKeystoRetain, albumKeystoRetain,
+ taskKeystoRetain, policyKeystoRetain, main);
+ }
+ }
+ }
- final AxPolicyModel policyModel = main.getActivator().getPolicyModel();
- final List<AxArtifactKey> keyInfoKeystoRemove = policyModel.getKeyInformation().getKeyInfoMap().keySet()
- .stream().filter(key -> !keyInfoKeystoRetain.contains(key)).collect(Collectors.toList());
- final List<AxArtifactKey> schemaKeystoRemove = policyModel.getSchemas().getSchemasMap().keySet().stream()
- .filter(key -> !schemaKeystoRetain.contains(key)).collect(Collectors.toList());
- final List<AxArtifactKey> eventKeystoRemove = policyModel.getEvents().getEventMap().keySet().stream()
- .filter(key -> !eventKeystoRetain.contains(key)).collect(Collectors.toList());
- final List<AxArtifactKey> albumKeystoRemove = policyModel.getAlbums().getAlbumsMap().keySet().stream()
- .filter(key -> !albumKeystoRetain.contains(key)).collect(Collectors.toList());
- final List<AxArtifactKey> taskKeystoRemove = policyModel.getTasks().getTaskMap().keySet().stream()
- .filter(key -> !taskKeystoRetain.contains(key)).collect(Collectors.toList());
- final List<AxArtifactKey> policyKeystoRemove = policyModel.getPolicies().getPolicyMap().keySet().stream()
- .filter(key -> !policyKeystoRetain.contains(key)).collect(Collectors.toList());
+ private void handleParametersRemoval(Set<String> inputParamKeysToRetain, Set<String> outputParamKeysToRetain,
+ List<TaskParameters> taskParametersToRetain, List<String> executorParamKeysToRetain,
+ List<String> schemaParamKeysToRetain, ApexMain main) {
+ ApexParameters existingParameters = ParameterService.get(ApexParameterConstants.MAIN_GROUP_NAME);
+ List<String> eventInputParamKeysToRemove = main.getApexParameters().getEventInputParameters().keySet().stream()
+ .filter(key -> !inputParamKeysToRetain.contains(key)).collect(Collectors.toList());
+ List<String> eventOutputParamKeysToRemove = main.getApexParameters().getEventOutputParameters().keySet()
+ .stream().filter(key -> !outputParamKeysToRetain.contains(key)).collect(Collectors.toList());
+ eventInputParamKeysToRemove.forEach(existingParameters.getEventInputParameters()::remove);
+ eventOutputParamKeysToRemove.forEach(existingParameters.getEventOutputParameters()::remove);
+ EngineParameters engineParameters = main.getApexParameters().getEngineServiceParameters().getEngineParameters();
+ final List<TaskParameters> taskParametersToRemove = engineParameters.getTaskParameters().stream()
+ .filter(taskParameter -> !taskParametersToRetain.contains(taskParameter)).collect(Collectors.toList());
+ final List<String> executorParamKeysToRemove = engineParameters.getExecutorParameterMap().keySet().stream()
+ .filter(key -> !executorParamKeysToRetain.contains(key)).collect(Collectors.toList());
+ final List<String> schemaParamKeysToRemove =
+ engineParameters.getContextParameters().getSchemaParameters().getSchemaHelperParameterMap().keySet()
+ .stream().filter(key -> !schemaParamKeysToRetain.contains(key)).collect(Collectors.toList());
+ EngineParameters aggregatedEngineParameters =
+ existingParameters.getEngineServiceParameters().getEngineParameters();
+ aggregatedEngineParameters.getTaskParameters().removeAll(taskParametersToRemove);
+ executorParamKeysToRemove.forEach(aggregatedEngineParameters.getExecutorParameterMap()::remove);
+ schemaParamKeysToRemove.forEach(aggregatedEngineParameters.getContextParameters().getSchemaParameters()
+ .getSchemaHelperParameterMap()::remove);
+ }
- final Map<AxArtifactKey, AxKeyInfo> keyInfoMap =
- ModelService.getModel(AxKeyInformation.class).getKeyInfoMap();
- final Map<AxArtifactKey, AxContextSchema> schemasMap =
- ModelService.getModel(AxContextSchemas.class).getSchemasMap();
- final Map<AxArtifactKey, AxEvent> eventMap = ModelService.getModel(AxEvents.class).getEventMap();
- final Map<AxArtifactKey, AxContextAlbum> albumsMap =
- ModelService.getModel(AxContextAlbums.class).getAlbumsMap();
- final Map<AxArtifactKey, AxTask> taskMap = ModelService.getModel(AxTasks.class).getTaskMap();
- final Map<AxArtifactKey, AxPolicy> policyMap = ModelService.getModel(AxPolicies.class).getPolicyMap();
+ private void handleAxConceptsRemoval(List<AxArtifactKey> keyInfoKeystoRetain,
+ List<AxArtifactKey> schemaKeystoRetain, List<AxArtifactKey> eventKeystoRetain,
+ List<AxArtifactKey> albumKeystoRetain, List<AxArtifactKey> taskKeystoRetain,
+ List<AxArtifactKey> policyKeystoRetain, ApexMain main) {
+ final AxPolicyModel policyModel = main.getActivator().getPolicyModel();
+ final List<AxArtifactKey> keyInfoKeystoRemove = policyModel.getKeyInformation().getKeyInfoMap().keySet()
+ .stream().filter(key -> !keyInfoKeystoRetain.contains(key)).collect(Collectors.toList());
+ final List<AxArtifactKey> schemaKeystoRemove = policyModel.getSchemas().getSchemasMap().keySet().stream()
+ .filter(key -> !schemaKeystoRetain.contains(key)).collect(Collectors.toList());
+ final List<AxArtifactKey> eventKeystoRemove = policyModel.getEvents().getEventMap().keySet().stream()
+ .filter(key -> !eventKeystoRetain.contains(key)).collect(Collectors.toList());
+ final List<AxArtifactKey> albumKeystoRemove = policyModel.getAlbums().getAlbumsMap().keySet().stream()
+ .filter(key -> !albumKeystoRetain.contains(key)).collect(Collectors.toList());
+ final List<AxArtifactKey> taskKeystoRemove = policyModel.getTasks().getTaskMap().keySet().stream()
+ .filter(key -> !taskKeystoRetain.contains(key)).collect(Collectors.toList());
+ final List<AxArtifactKey> policyKeystoRemove = policyModel.getPolicies().getPolicyMap().keySet().stream()
+ .filter(key -> !policyKeystoRetain.contains(key)).collect(Collectors.toList());
- keyInfoKeystoRemove.forEach(keyInfoMap::remove);
- schemaKeystoRemove.forEach(schemasMap::remove);
- eventKeystoRemove.forEach(eventMap::remove);
- albumKeystoRemove.forEach(albumsMap::remove);
- taskKeystoRemove.forEach(taskMap::remove);
- policyKeystoRemove.forEach(policyMap::remove);
- }
+ final Map<AxArtifactKey, AxKeyInfo> keyInfoMap = ModelService.getModel(AxKeyInformation.class).getKeyInfoMap();
+ final Map<AxArtifactKey, AxContextSchema> schemasMap =
+ ModelService.getModel(AxContextSchemas.class).getSchemasMap();
+ final Map<AxArtifactKey, AxEvent> eventMap = ModelService.getModel(AxEvents.class).getEventMap();
+ final Map<AxArtifactKey, AxContextAlbum> albumsMap =
+ ModelService.getModel(AxContextAlbums.class).getAlbumsMap();
+ final Map<AxArtifactKey, AxTask> taskMap = ModelService.getModel(AxTasks.class).getTaskMap();
+ final Map<AxArtifactKey, AxPolicy> policyMap = ModelService.getModel(AxPolicies.class).getPolicyMap();
+
+ keyInfoKeystoRemove.forEach(keyInfoMap::remove);
+ schemaKeystoRemove.forEach(schemasMap::remove);
+ eventKeystoRemove.forEach(eventMap::remove);
+ albumKeystoRemove.forEach(albumsMap::remove);
+ taskKeystoRemove.forEach(taskMap::remove);
+ policyKeystoRemove.forEach(policyMap::remove);
}
- private Map<ToscaConceptIdentifier, ApexMain> initiateApexEngineForPolicies(List<ToscaPolicy> policies)
+ private void initiateApexEngineForPolicies(List<ToscaPolicy> policies)
throws ApexStarterException {
- Map<ToscaConceptIdentifier, ApexMain> mainMap = new LinkedHashMap<>();
+ Map<ToscaConceptIdentifier, ApexMain> failedPoliciesMainMap = new LinkedHashMap<>();
for (ToscaPolicy policy : policies) {
String policyName = policy.getIdentifier().getName();
final StandardCoder standardCoder = new StandardCoder();
@@ -243,14 +249,24 @@ public class ApexEngineHandler {
}
final String[] apexArgs = {"-p", file.getAbsolutePath()};
LOGGER.info("Starting apex engine for policy {}", policy.getIdentifier());
- try {
- ApexMain apexMain = new ApexMain(apexArgs);
- mainMap.put(policy.getIdentifier(), apexMain);
- } catch (Exception e) {
- LOGGER.error("Execution of policy {} failed", policy.getIdentifier(), e);
+ ApexMain apexMain = new ApexMain(apexArgs);
+ if (apexMain.isAlive()) {
+ apexMainMap.put(policy.getIdentifier(), apexMain);
+ } else {
+ failedPoliciesMainMap.put(policy.getIdentifier(), apexMain);
+ LOGGER.error("Execution of policy {} failed", policy.getIdentifier());
+ }
+ }
+ if (apexMainMap.isEmpty()) {
+ ModelService.clear();
+ ParameterService.clear();
+ throw new ApexStarterException("Apex Engine failed to start.");
+ } else if (failedPoliciesMainMap.size() > 0) {
+ updateModelAndParameterServices(failedPoliciesMainMap);
+ if (failedPoliciesMainMap.size() == policies.size()) {
+ throw new ApexStarterException("Updating the APEX engine with new policies failed.");
}
}
- return mainMap;
}
/**