From c3351f687be075d91908d04dfc4e7e9da243f395 Mon Sep 17 00:00:00 2001 From: jhh Date: Tue, 7 May 2019 20:51:34 -0500 Subject: Track policies when active. Do not honor group/subgroup changes with status messages. When no present group/subgroups in update messages, assume that they have to be reset. Keep the policy cache of non-installed policies tracking them when in passive state besides active. Wait until go active to enable them. Remove legacy PAP and PDP-X healtchecks as it was basically testing reachability. There are conflicts with maintaining 2 different sets of PAPs and PDPs, trying to avoid it. Alternative healtchecks are being placed on the robot test framework. What to healtcheck should be considered more carefully in the near future. Change-Id: I574f30bb5899faf521123c79046793d16b4a46e0 Issue-ID: POLICY-1748 Signed-off-by: jhh --- .../policy/drools/controller/DroolsController.java | 10 +++++++++ .../controller/internal/MavenDroolsController.java | 24 ++++++++++++++++++++++ .../controller/internal/NullDroolsController.java | 10 +++++++++ .../policy/drools/server/restful/RestManager.java | 10 ++++++--- 4 files changed, 51 insertions(+), 3 deletions(-) (limited to 'policy-management/src/main/java') diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java index 78a2f4e8..4347614f 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java @@ -242,6 +242,16 @@ public interface DroolsController extends Startable, Lockable { */ boolean delete(@NonNull T fact); + /** + * Deletes all facts from a given class from a session. + */ + boolean delete(@NonNull String sessionName, @NonNull Class fact); + + /** + * Deletes all facts from a given class from all sessions. + */ + boolean delete(@NonNull Class fact); + /** * halts and permanently releases all resources. * diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java index a9ab212b..140d6769 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java @@ -919,6 +919,30 @@ public class MavenDroolsController implements DroolsController { return this.getSessionNames().stream().map((ss) -> delete(ss, fact)).reduce(false, Boolean::logicalOr); } + @Override + public boolean delete(@NonNull String sessionName, @NonNull Class fact) { + PolicySession session = getSession(sessionName); + KieSession kieSession = session.getKieSession(); + + boolean success = true; + Collection factHandles = kieSession.getFactHandles(new ClassObjectFilter(fact)); + for (FactHandle factHandle : factHandles) { + try { + kieSession.delete(factHandle); + } catch (Exception e) { + logger.warn("Object cannot be retrieved from fact {}", factHandle, e); + success = false; + } + } + return success; + } + + @Override + public boolean delete(@NonNull Class fact) { + return this.getSessionNames().stream().map((ss) -> delete(ss, fact)).reduce(false, Boolean::logicalOr); + } + + @Override public Class fetchModelClass(String className) { return ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className); diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java index 5bf51efa..3595f91a 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java @@ -203,6 +203,16 @@ public class NullDroolsController implements DroolsController { return false; } + @Override + public boolean delete(@NonNull String sessionName, @NonNull Class fact) { + return false; + } + + @Override + public boolean delete(@NonNull Class fact) { + return false; + } + private String makeInvokeMsg() { return this.getClass().getCanonicalName() + " invoked"; } diff --git a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java index aac92505..d926bed6 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java +++ b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java @@ -1699,6 +1699,7 @@ public class RestManager { @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm ) { List sources = new ArrayList<>(); + Status status = Status.OK; switch (CommInfrastructure.valueOf(comm.toUpperCase())) { case UEB: sources.addAll(TopicEndpoint.manager.getUebTopicSources()); @@ -1710,10 +1711,11 @@ public class RestManager { sources.addAll(TopicEndpoint.manager.getNoopTopicSources()); break; default: + status = Status.BAD_REQUEST; logger.debug("Invalid communication mechanism parameter: {}", comm); break; } - return Response.status(Response.Status.OK).entity(sources).build(); + return Response.status(status).entity(sources).build(); } /** @@ -1727,6 +1729,7 @@ public class RestManager { @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm ) { List sinks = new ArrayList<>(); + Status status = Status.OK; switch (CommInfrastructure.valueOf(comm.toUpperCase())) { case UEB: sinks.addAll(TopicEndpoint.manager.getUebTopicSinks()); @@ -1738,10 +1741,11 @@ public class RestManager { sinks.addAll(TopicEndpoint.manager.getNoopTopicSinks()); break; default: + status = Status.BAD_REQUEST; logger.debug("Invalid communication mechanism parameter: {}", comm); break; } - return Response.status(Response.Status.OK).entity(sinks).build(); + return Response.status(status).entity(sinks).build(); } @@ -1992,7 +1996,7 @@ public class RestManager { } /** - * Offers and event to a topic in a communication infrastructure. + * Offers an event to a topic in a communication infrastructure. * * @return response object */ -- cgit 1.2.3-korg