aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src/main
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2019-04-09 14:24:34 -0500
committerjhh <jorge.hernandez-herrero@att.com>2019-04-09 14:30:01 -0500
commit712274e8d332181729c06c31dcf58d49f2a4d8f7 (patch)
treea684200d82ada2fe062e1f8f1071130f6bec77d5 /policy-management/src/main
parent3f90dba2636b06bcb90b8f1e158b30886af574d5 (diff)
deploy and undeploy as audits.
Change-Id: Iea1766d5d8075394e1dccc109f4477bd2c270c36 Issue-ID: POLICY-1624 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'policy-management/src/main')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java17
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java39
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java16
3 files changed, 71 insertions, 1 deletions
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 344725ff..78a2f4e8 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
@@ -22,7 +22,7 @@ package org.onap.policy.drools.controller;
import java.util.List;
import java.util.Map;
-
+import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.policy.common.capabilities.Lockable;
import org.onap.policy.common.capabilities.Startable;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
@@ -215,6 +215,11 @@ public interface DroolsController extends Startable, Lockable {
List<Object> facts(String sessionName, String className, boolean delete);
/**
+ * Gets facts.
+ */
+ <T> List<T> facts(@NonNull String sessionName, @NonNull Class<T> clazz);
+
+ /**
* gets the facts associated with a query for a give session for a given queried entity.
*
* @param sessionName the session
@@ -228,6 +233,16 @@ public interface DroolsController extends Startable, Lockable {
Object... queryParams);
/**
+ * Deletes a fact from a session.
+ */
+ <T> boolean delete(@NonNull String sessionName, @NonNull T fact);
+
+ /**
+ * Delete a fact object of type T.
+ */
+ <T> boolean delete(@NonNull T 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 95b053fb..a9ab212b 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
@@ -27,7 +27,10 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
import org.apache.commons.collections4.queue.CircularFifoQueue;
+import org.checkerframework.checker.nullness.qual.NonNull;
import org.drools.core.ClassObjectFilter;
import org.kie.api.definition.KiePackage;
import org.kie.api.definition.rule.Query;
@@ -833,6 +836,15 @@ public class MavenDroolsController implements DroolsController {
}
@Override
+ public <T> List<T> facts(@NonNull String sessionName, @NonNull Class<T> clazz) {
+ return facts(sessionName, clazz.getCanonicalName(), false)
+ .stream()
+ .filter(clazz::isInstance)
+ .map(clazz::cast)
+ .collect(Collectors.toList());
+ }
+
+ @Override
public List<Object> factQuery(String sessionName, String queryName, String queriedEntity,
boolean delete, Object... queryParams) {
if (sessionName == null || sessionName.isEmpty()) {
@@ -881,6 +893,33 @@ public class MavenDroolsController implements DroolsController {
}
@Override
+ public <T> boolean delete(@NonNull String sessionName, @NonNull T fact) {
+ String factClassName = fact.getClass().getName();
+
+ PolicySession session = getSession(sessionName);
+ KieSession kieSession = session.getKieSession();
+
+ Collection<FactHandle> factHandles = kieSession.getFactHandles(new ClassObjectFilter(fact.getClass()));
+ for (FactHandle factHandle : factHandles) {
+ try {
+ if (Objects.equals(fact, kieSession.getObject(factHandle))) {
+ logger.info("Deleting {} from {}", factClassName, sessionName);
+ kieSession.delete(factHandle);
+ return true;
+ }
+ } catch (Exception e) {
+ logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public <T> boolean delete(@NonNull T 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 815aaabb..5bf51efa 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
@@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.core.PolicyContainer;
@@ -181,12 +182,27 @@ public class NullDroolsController implements DroolsController {
}
@Override
+ public <T> List<T> facts(@NonNull String sessionName, @NonNull Class<T> clazz) {
+ return new ArrayList<>();
+ }
+
+ @Override
public List<Object> factQuery(String sessionName, String queryName,
String queriedEntity,
boolean delete, Object... queryParams) {
return new ArrayList<>();
}
+ @Override
+ public <T> boolean delete(@NonNull String sessionName, @NonNull T fact) {
+ return false;
+ }
+
+ @Override
+ public <T> boolean delete(@NonNull T fact) {
+ return false;
+ }
+
private String makeInvokeMsg() {
return this.getClass().getCanonicalName() + " invoked";
}