aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/examples-aadm/pom.xml2
-rw-r--r--examples/examples-acm/pom.xml2
-rw-r--r--examples/examples-adaptive/pom.xml2
-rw-r--r--examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java41
-rw-r--r--examples/examples-decisionmaker-sharedcontext/pom.xml2
-rw-r--r--examples/examples-decisionmaker/pom.xml2
-rw-r--r--examples/examples-grpc/pom.xml2
-rw-r--r--examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java11
-rw-r--r--examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java8
-rw-r--r--examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java21
-rw-r--r--examples/examples-myfirstpolicy/pom.xml2
-rw-r--r--examples/examples-onap-bbs/pom.xml2
-rw-r--r--examples/examples-onap-vcpe/pom.xml2
-rw-r--r--examples/examples-periodic/pom.xml2
-rw-r--r--examples/examples-servlet/pom.xml2
-rw-r--r--examples/pom.xml2
16 files changed, 60 insertions, 45 deletions
diff --git a/examples/examples-aadm/pom.xml b/examples/examples-aadm/pom.xml
index 54a8c8830..7ad7938b7 100644
--- a/examples/examples-aadm/pom.xml
+++ b/examples/examples-aadm/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp.examples</groupId>
<artifactId>examples</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>examples-aadm</artifactId>
diff --git a/examples/examples-acm/pom.xml b/examples/examples-acm/pom.xml
index be4a54328..d89609583 100644
--- a/examples/examples-acm/pom.xml
+++ b/examples/examples-acm/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp.examples</groupId>
<artifactId>examples</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>examples-acm</artifactId>
<name>examples-acm</name>
diff --git a/examples/examples-adaptive/pom.xml b/examples/examples-adaptive/pom.xml
index 0ec044f67..f3f2bc743 100644
--- a/examples/examples-adaptive/pom.xml
+++ b/examples/examples-adaptive/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp.examples</groupId>
<artifactId>examples</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>examples-adaptive</artifactId>
diff --git a/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java b/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java
index 317a86349..d1a5970e3 100644
--- a/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java
+++ b/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (c) 2021 Nordix Foundation.
+ * Modifications Copyright (c) 2021, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,11 +52,12 @@ public class AutoLearnPolicyDecideTaskSelectionLogic {
* @return the task
*/
public boolean getTask(final TaskSelectionExecutionContext executor) {
+ var returnValue = true;
var idString = executor.subject.getId();
- executor.logger.debug(idString);
+ TaskSelectionExecutionContext.logger.debug(idString);
var inFieldsString = executor.inFields.toString();
- executor.logger.debug(inFieldsString);
+ TaskSelectionExecutionContext.logger.debug(inFieldsString);
final List<String> tasks = executor.subject.getTaskNames();
size = tasks.size();
@@ -64,8 +65,8 @@ public class AutoLearnPolicyDecideTaskSelectionLogic {
try {
executor.getContextAlbum(AUTO_LEARN_ALBUM).lockForWriting(AUTO_LEARN);
} catch (final ContextException e) {
- executor.logger.error("Failed to acquire write lock on \"autoLearn\" context", e);
- return false;
+ TaskSelectionExecutionContext.logger.error("Failed to acquire write lock on \"autoLearn\" context", e);
+ returnValue = false;
}
// Get the context object
@@ -89,23 +90,23 @@ public class AutoLearnPolicyDecideTaskSelectionLogic {
try {
executor.getContextAlbum(AUTO_LEARN_ALBUM).unlockForWriting(AUTO_LEARN);
} catch (final ContextException e) {
- executor.logger.error("Failed to acquire write lock on \"autoLearn\" context", e);
- return false;
+ TaskSelectionExecutionContext.logger.error("Failed to acquire write lock on \"autoLearn\" context", e);
+ returnValue = false;
}
executor.subject.getTaskKey(tasks.get(option)).copyTo(executor.selectedTask);
- return true;
+ return returnValue;
}
/**
* Gets the option.
*
- * @param diff the diff
+ * @param diff the diff
* @param autoLearn the auto learn
* @return the option
*/
private int getOption(final double diff, final AutoLearn autoLearn) {
- final Double[] avdiffs = autoLearn.getAvDiffs().toArray(new Double[autoLearn.getAvDiffs().size()]);
+ final Double[] avdiffs = autoLearn.getAvDiffs().toArray(new Double[0]);
final var r = RAND.nextInt(size);
int closestupi = -1;
int closestdowni = -1;
@@ -130,13 +131,13 @@ public class AutoLearnPolicyDecideTaskSelectionLogic {
/**
* Learn.
*
- * @param option the option
- * @param diff the diff
+ * @param option the option
+ * @param diff the diff
* @param autoLearn the auto learn
*/
private void learn(final int option, final double diff, final AutoLearn autoLearn) {
- final Double[] avdiffs = autoLearn.getAvDiffs().toArray(new Double[autoLearn.getAvDiffs().size()]);
- final Long[] counts = autoLearn.getCounts().toArray(new Long[autoLearn.getCounts().size()]);
+ final Double[] avdiffs = autoLearn.getAvDiffs().toArray(new Double[0]);
+ final Long[] counts = autoLearn.getCounts().toArray(new Long[0]);
if (option < 0 || option >= avdiffs.length) {
throw new IllegalArgumentException("Error: option" + option);
}
@@ -153,16 +154,16 @@ public class AutoLearnPolicyDecideTaskSelectionLogic {
/**
* Calculate the return value of the learning.
*
- * @param diff the difference
- * @param random the random value
- * @param closestupi closest to i upwards
+ * @param diff the difference
+ * @param random the random value
+ * @param closestupi closest to i upwards
* @param closestdowni closest to i downwards
- * @param closestup closest up value
- * @param closestdown closest down value
+ * @param closestup closest up value
+ * @param closestdown closest down value
* @return the return value
*/
private int calculateReturnValue(final double diff, final int random, int closestupi, int closestdowni,
- double closestup, double closestdown) {
+ double closestup, double closestdown) {
if (closestupi == -1 || closestdowni == -1) {
return random;
}
diff --git a/examples/examples-decisionmaker-sharedcontext/pom.xml b/examples/examples-decisionmaker-sharedcontext/pom.xml
index 4b6a8dacf..7891682bc 100644
--- a/examples/examples-decisionmaker-sharedcontext/pom.xml
+++ b/examples/examples-decisionmaker-sharedcontext/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp.examples</groupId>
<artifactId>examples</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>examples-decisionmaker-sharedcontext</artifactId>
diff --git a/examples/examples-decisionmaker/pom.xml b/examples/examples-decisionmaker/pom.xml
index b6597f0b5..00a4ae517 100644
--- a/examples/examples-decisionmaker/pom.xml
+++ b/examples/examples-decisionmaker/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp.examples</groupId>
<artifactId>examples</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>examples-decisionmaker</artifactId>
diff --git a/examples/examples-grpc/pom.xml b/examples/examples-grpc/pom.xml
index 040fc315e..9ccd9d91f 100644
--- a/examples/examples-grpc/pom.xml
+++ b/examples/examples-grpc/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp.examples</groupId>
<artifactId>examples</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>examples-grpc</artifactId>
<name>examples-grpc</name>
diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java
index 3d46e6a80..56539a1d7 100644
--- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java
+++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2023 Nordix Foundation.
+ * Copyright (C) 2020-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
package org.onap.policy.apex.examples.grpc;
+import static org.awaitility.Awaitility.await;
+
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
@@ -28,6 +30,7 @@ import jakarta.ws.rs.core.Response;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.concurrent.TimeUnit;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -52,8 +55,12 @@ public class GrpcTestRestSimEndpoint {
public Response dcaeClOutput(@QueryParam("timeout") final int timeout) throws IOException {
String createSubscriptionRequest =
Files.readString(Paths.get("src/main/resources/examples/events/APEXgRPC/CreateSubscriptionEvent.json"));
- LOGGER.info("Create subscription request received: \n {}", createSubscriptionRequest);
+ LOGGER.info("Create subscription request received (on a timeout of {}): \n {} ",
+ timeout, createSubscriptionRequest);
+ await().pollDelay(4, TimeUnit.SECONDS)
+ .atMost(5, TimeUnit.SECONDS)
+ .until(() -> true);
return Response.status(200).entity(createSubscriptionRequest).build();
}
diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java
index 46e0ea254..4dc638551 100644
--- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java
+++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020,2023 Nordix Foundation.
+ * Copyright (C) 2020, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,11 +33,11 @@ import org.onap.policy.simulators.CdsSimulator;
*/
public class GrpcTestServerSim {
private static final String HOST = "localhost";
- private HttpServletServer restServer;
- private CdsSimulator grpcServer;
+ private final HttpServletServer restServer;
+ private final CdsSimulator grpcServer;
/**
- * Instantiates a new REST simulator for DMaaP requests.
+ * Instantiates a new REST simulator for requests.
*
* @throws InterruptedException interrupted exception
* @throws IOException io exception
diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java
index ee1744f0e..e6d71e1ff 100644
--- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java
+++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java
@@ -41,6 +41,7 @@ import org.onap.policy.apex.service.engine.main.ApexMain;
* CDS is used to send a final output Log event on POLICY_CL_MGT topic.
*/
class TestApexGrpcExample {
+
@Test
void testGrpcExample() throws Exception {
// @formatter:off
@@ -78,18 +79,24 @@ class TestApexGrpcExample {
String getLoggedEventUrl = "http://localhost:54321/GrpcTestRestSim/sim/event/getLoggedEvent";
// wait for success response code to be received, until a timeout
- await().atMost(20000, TimeUnit.MILLISECONDS).until(() ->
- 200 == client.target(getLoggedEventUrl).request("application/json").get().getStatus());
+ await().atMost(50000, TimeUnit.MILLISECONDS)
+ .pollInterval(10000, TimeUnit.MILLISECONDS)
+ .until(() -> 200 == client.target(getLoggedEventUrl).request("application/json").get().getStatus());
+
apexMain.shutdown();
+
Response response = client.target(getLoggedEventUrl).request("application/json").get();
sim.tearDown();
+
String responseEntity = response.readEntity(String.class);
- String expectedLoggedOutputEvent = Files
- .readString(Paths.get("src/main/resources/examples/events/APEXgRPC/LogEvent.json")).replaceAll("\r", "");
- String expectedStatusEvent =
- Files.readString(Paths.get("src/main/resources/examples/events/APEXgRPC/CDSResponseStatusEvent.json"))
- .replaceAll("\r", "");
+ var logFileJson = "src/main/resources/examples/events/APEXgRPC/LogEvent.json";
+ String expectedLoggedOutputEvent = Files.readString(Paths.get(logFileJson)).replaceAll("\r", "");
+
+ var cdsResponseJson = "src/main/resources/examples/events/APEXgRPC/CDSResponseStatusEvent.json";
+ String expectedStatusEvent = Files.readString(Paths.get(cdsResponseJson)).replaceAll("\r", "");
+
// Both LogEvent and CDSResponseStatusEvent are generated from the final state in the policy
assertThat(responseEntity).contains(expectedStatusEvent).contains(expectedLoggedOutputEvent);
+ client.close();
}
} \ No newline at end of file
diff --git a/examples/examples-myfirstpolicy/pom.xml b/examples/examples-myfirstpolicy/pom.xml
index 2dc190450..5c5996311 100644
--- a/examples/examples-myfirstpolicy/pom.xml
+++ b/examples/examples-myfirstpolicy/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp.examples</groupId>
<artifactId>examples</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>examples-myfirstpolicy</artifactId>
diff --git a/examples/examples-onap-bbs/pom.xml b/examples/examples-onap-bbs/pom.xml
index cc31b4f92..4d2c47b33 100644
--- a/examples/examples-onap-bbs/pom.xml
+++ b/examples/examples-onap-bbs/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp.examples</groupId>
<artifactId>examples</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>examples-onap-bbs</artifactId>
diff --git a/examples/examples-onap-vcpe/pom.xml b/examples/examples-onap-vcpe/pom.xml
index 10ee41d8f..390b9c0fb 100644
--- a/examples/examples-onap-vcpe/pom.xml
+++ b/examples/examples-onap-vcpe/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp.examples</groupId>
<artifactId>examples</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>examples-onap-vcpe</artifactId>
diff --git a/examples/examples-periodic/pom.xml b/examples/examples-periodic/pom.xml
index 94bca49d1..374c0a7b8 100644
--- a/examples/examples-periodic/pom.xml
+++ b/examples/examples-periodic/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp.examples</groupId>
<artifactId>examples</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>examples-periodic</artifactId>
diff --git a/examples/examples-servlet/pom.xml b/examples/examples-servlet/pom.xml
index 4b4f277bc..90bdd4bb8 100644
--- a/examples/examples-servlet/pom.xml
+++ b/examples/examples-servlet/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp.examples</groupId>
<artifactId>examples</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>examples-servlet</artifactId>
diff --git a/examples/pom.xml b/examples/pom.xml
index 77dbdf682..20e05ce8e 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.onap.policy.apex-pdp</groupId>
<artifactId>apex-pdp</artifactId>
- <version>4.0.0-SNAPSHOT</version>
+ <version>4.0.1-SNAPSHOT</version>
</parent>
<groupId>org.onap.policy.apex-pdp.examples</groupId>