aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-engine
diff options
context:
space:
mode:
authorputhuparambil.aditya <aditya.puthuparambil@bell.ca>2020-08-06 13:03:38 +0100
committeraditya puthuparambil <aditya.puthuparambil@bell.ca>2020-08-07 17:15:10 +0000
commitf4895ff98b3ed83b44733adc20ad8cf0092a3d83 (patch)
tree5bc5037f746fe5babef73ee6a0670f68214cc881 /services/services-engine
parenta926cdc113b5fad19a34dbf45e66bd7cbb5ed6e0 (diff)
Handling apex-pdp multi policy deployment failure:
1.Include the list of duplicate parameters in the logs for easier troubleshooting 2.Also fix 4 Sonar blockers in ApexMainTest.java Issue-ID: POLICY-2712 Signed-off-by: puthuparambil.aditya <aditya.puthuparambil@bell.ca> Change-Id: I145a7e03f76f880f8e3cbde97284748468b354a5
Diffstat (limited to 'services/services-engine')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java18
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java19
2 files changed, 24 insertions, 13 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java
index 1e2447b2e..a928f208c 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java
@@ -24,6 +24,7 @@ package org.onap.policy.apex.service.engine.main;
import java.io.IOException;
import java.util.AbstractMap;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -133,16 +134,19 @@ public class ApexActivator {
new LinkedHashSet<>(apexParametersMap.entrySet());
apexParamsEntrySet.stream().forEach(apexParamsEntry -> {
ApexParameters apexParams = apexParamsEntry.getValue();
- boolean duplicateInputParameterExist =
- apexParams.getEventInputParameters().keySet().stream().anyMatch(inputParametersMap::containsKey);
- boolean duplicateOutputParameterExist =
- apexParams.getEventOutputParameters().keySet().stream().anyMatch(outputParametersMap::containsKey);
- if (duplicateInputParameterExist || duplicateOutputParameterExist) {
- LOGGER.error("I/O Parameters for {}:{} has duplicates. So this policy is not executed.",
- apexParamsEntry.getKey().getName(), apexParamsEntry.getKey().getVersion());
+ List<String> duplicateInputParameters = new ArrayList<>(apexParams.getEventInputParameters().keySet());
+ duplicateInputParameters.retainAll(inputParametersMap.keySet());
+ List<String> duplicateOutputParameters = new ArrayList<>(apexParams.getEventOutputParameters().keySet());
+ duplicateOutputParameters.retainAll(outputParametersMap.keySet());
+
+ if (!(duplicateInputParameters.isEmpty() && duplicateOutputParameters.isEmpty())) {
+ LOGGER.error("I/O Parameters {}/{} for {}:{} are duplicates. So this policy is not executed.",
+ duplicateInputParameters, duplicateOutputParameters, apexParamsEntry.getKey().getName(),
+ apexParamsEntry.getKey().getVersion());
apexParametersMap.remove(apexParamsEntry.getKey());
return;
}
+
inputParametersMap.putAll(apexParams.getEventInputParameters());
outputParametersMap.putAll(apexParams.getEventOutputParameters());
// Check if a policy model file has been specified
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 731baf5ef..f38dcaa40 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
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,9 +22,10 @@
package org.onap.policy.apex.service.engine.main;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
@@ -61,6 +63,8 @@ public class ApexMainTest {
ApexMain.main(null);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
.contains("Apex configuration file was not specified as an argument"));
+ assertThat(outContent.toString())
+ .contains("Apex configuration file was not specified as an argument");
}
@Test
@@ -73,6 +77,7 @@ public class ApexMainTest {
final ApexMain apexMain = new ApexMain(args);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
.contains("invalid command line arguments specified : Unrecognized option: -whee"));
+ assertNotNull(apexMain);
apexMain.shutdown();
}
@@ -86,6 +91,7 @@ public class ApexMainTest {
final ApexMain apexMain = 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();
}
@@ -99,6 +105,7 @@ public class ApexMainTest {
final ApexMain apexMain = new ApexMain(args);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
.contains("parameter group has status INVALID"));
+ assertNotNull(apexMain);
apexMain.shutdown();
}
@@ -148,7 +155,7 @@ public class ApexMainTest {
assertEquals("MyApexEngine", apexParam.getEngineServiceParameters().getName());
apexMain.shutdown();
final String outString = outContent.toString();
- assertTrue(outString.contains("Added the action listener to the engine"));
+ assertThat(outString).contains("Added the action listener to the engine");
}
@Test
@@ -165,7 +172,8 @@ public class ApexMainTest {
assertEquals("MyApexEngine", apexParam.getEngineServiceParameters().getName());
apexMain.shutdown();
final String outString = outContent.toString();
- assertTrue(outString.contains("I/O Parameters for id2:v2 has duplicates. So this policy is not executed"));
+ assertThat(outString).contains("I/O Parameters [TheFileConsumer1]/[FirstProducer] for id2:v2 are duplicates. "
+ + "So this policy is not executed");
assertEquals(1, apexMain.getApexParametersMap().size()); // only id1:v1 is kept in the map, id2:v2 failed
}
@@ -179,8 +187,7 @@ public class ApexMainTest {
final ApexMain apexMain = new ApexMain(argsMap);
final String outString = outContent.toString();
apexMain.shutdown();
- assertTrue(
- outString.contains("Arguments validation failed") && outString.contains("start of Apex service failed"));
- assertTrue(apexMain.getApexParametersMap().isEmpty()); // No policy is running in the engine
+ assertThat(outString).contains("Arguments validation failed", "start of Apex service failed");
+ assertThat(apexMain.getApexParametersMap()).isEmpty(); // No policy is running in the engine
}
}