aboutsummaryrefslogtreecommitdiffstats
path: root/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java
diff options
context:
space:
mode:
Diffstat (limited to 'feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java')
-rw-r--r--feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java98
1 files changed, 50 insertions, 48 deletions
diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java
index da47a031..21cbc4db 100644
--- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java
+++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java
@@ -20,44 +20,41 @@
package org.onap.policy.drools.pooling;
-import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import org.onap.policy.common.utils.properties.exception.PropertyException;
import org.onap.policy.drools.controller.DroolsController;
-import org.onap.policy.drools.core.PolicySessionFeatureAPI;
import org.onap.policy.drools.event.comm.Topic.CommInfrastructure;
import org.onap.policy.drools.features.DroolsControllerFeatureAPI;
import org.onap.policy.drools.features.PolicyControllerFeatureAPI;
+import org.onap.policy.drools.features.PolicyEngineFeatureAPI;
+import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.system.PolicyController;
-import org.onap.policy.drools.utils.PropertyUtil;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.util.FeatureEnabledChecker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Controller/session pooling. Multiple hosts may be launched, all servicing the
- * same controllers/sessions. When this feature is enabled, the requests are
- * divided across the different hosts, instead of all running on a single,
- * active host.
+ * Controller/session pooling. Multiple hosts may be launched, all servicing the same
+ * controllers/sessions. When this feature is enabled, the requests are divided across the
+ * different hosts, instead of all running on a single, active host.
* <p>
- * With each controller, there is an associated DMaaP topic that is used for
- * internal communication between the different hosts serving the controller.
+ * With each controller, there is an associated DMaaP topic that is used for internal
+ * communication between the different hosts serving the controller.
*/
-public class PoolingFeature implements PolicyControllerFeatureAPI, DroolsControllerFeatureAPI, PolicySessionFeatureAPI {
+public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerFeatureAPI, DroolsControllerFeatureAPI {
private static final Logger logger = LoggerFactory.getLogger(PoolingFeature.class);
- // TODO state-management doesn't allow more than one active host at a time
-
/**
* Factory used to create objects.
*/
private static Factory factory;
/**
- * Entire set of feature properties, including those specific to various
- * controllers.
+ * Entire set of feature properties, including those specific to various controllers.
*/
private Properties featProps = null;
@@ -67,9 +64,9 @@ public class PoolingFeature implements PolicyControllerFeatureAPI, DroolsControl
private ConcurrentHashMap<String, PoolingManagerImpl> ctlr2pool = new ConcurrentHashMap<>(107);
/**
- * Arguments passed to beforeOffer(), which are saved for when the
- * beforeInsert() is called later. As multiple threads can be active within
- * the methods at the same time, we must keep this in thread local storage.
+ * Arguments passed to beforeOffer(), which are saved for when the beforeInsert() is
+ * called later. As multiple threads can be active within the methods at the same
+ * time, we must keep this in thread local storage.
*/
private ThreadLocal<OfferArgs> offerArgs = new ThreadLocal<>();
@@ -98,20 +95,11 @@ public class PoolingFeature implements PolicyControllerFeatureAPI, DroolsControl
return 0;
}
- /**
- * @throws PoolingFeatureRtException if the properties cannot be read or are
- * invalid
- */
@Override
- public void globalInit(String[] args, String configDir) {
- logger.info("initializing pooling feature");
-
- try {
- featProps = PropertyUtil.getProperties(configDir + "/feature-pooling-dmaap.properties");
-
- } catch (IOException ex) {
- throw new PoolingFeatureRtException(ex);
- }
+ public boolean beforeStart(PolicyEngine engine) {
+ logger.info("initializing " + PoolingProperties.FEATURE_NAME);
+ featProps = factory.getProperties(PoolingProperties.FEATURE_NAME);
+ return false;
}
/**
@@ -205,8 +193,8 @@ public class PoolingFeature implements PolicyControllerFeatureAPI, DroolsControl
@Override
public boolean beforeOffer(PolicyController controller, CommInfrastructure protocol, String topic2, String event) {
/*
- * As this is invoked a lot, we'll directly call the manager's method
- * instead of using the functional interface via doManager().
+ * As this is invoked a lot, we'll directly call the manager's method instead of
+ * using the functional interface via doManager().
*/
PoolingManagerImpl mgr = ctlr2pool.get(controller.getName());
if (mgr == null) {
@@ -226,6 +214,7 @@ public class PoolingFeature implements PolicyControllerFeatureAPI, DroolsControl
OfferArgs args = offerArgs.get();
if (args == null) {
+ logger.warn("missing arguments for feature-pooling-dmaap in beforeInsert");
return false;
}
@@ -234,16 +223,21 @@ public class PoolingFeature implements PolicyControllerFeatureAPI, DroolsControl
controller = factory.getController(droolsController);
} catch (IllegalArgumentException | IllegalStateException e) {
+ logger.warn("cannot get controller for {} {}", droolsController.getGroupId(),
+ droolsController.getArtifactId(), e);
return false;
}
+
if (controller == null) {
+ logger.warn("cannot determine controller for {} {}", droolsController.getGroupId(),
+ droolsController.getArtifactId());
return false;
}
/*
- * As this is invoked a lot, we'll directly call the manager's method
- * instead of using the functional interface via doManager().
+ * As this is invoked a lot, we'll directly call the manager's method instead of
+ * using the functional interface via doManager().
*/
PoolingManagerImpl mgr = ctlr2pool.get(controller.getName());
if (mgr == null) {
@@ -264,14 +258,12 @@ public class PoolingFeature implements PolicyControllerFeatureAPI, DroolsControl
}
/**
- * Executes a function using the manager associated with the controller.
- * Catches any exceptions from the function and re-throws it as a runtime
- * exception.
+ * Executes a function using the manager associated with the controller. Catches any
+ * exceptions from the function and re-throws it as a runtime exception.
*
* @param controller
* @param func function to be executed
- * @return {@code true} if the function handled the request, {@code false}
- * otherwise
+ * @return {@code true} if the function handled the request, {@code false} otherwise
* @throws PoolingFeatureRtException if an error occurs
*/
private boolean doManager(PolicyController controller, MgrFunc func) {
@@ -284,26 +276,28 @@ public class PoolingFeature implements PolicyControllerFeatureAPI, DroolsControl
return func.apply(mgr);
} catch (PoolingFeatureException e) {
- throw e.toRuntimeException();
+ throw new PoolingFeatureRtException(e);
}
}
/**
- * Executes a function using the manager associated with the controller and
- * then deletes the manager. Catches any exceptions from the function and
- * re-throws it as a runtime exception.
+ * Executes a function using the manager associated with the controller and then
+ * deletes the manager. Catches any exceptions from the function and re-throws it as a
+ * runtime exception.
*
* @param controller
* @param func function to be executed
- * @return {@code true} if the function handled the request, {@code false}
- * otherwise
+ * @return {@code true} if the function handled the request, {@code false} otherwise
* @throws PoolingFeatureRtException if an error occurs
*/
private boolean doDeleteManager(PolicyController controller, Function<PoolingManagerImpl, Boolean> func) {
+ String name = controller.getName();
+ logger.info("remove feature-pool-dmaap manager for {}", name);
+
// NOTE: using "remove()" instead of "get()"
- PoolingManagerImpl mgr = ctlr2pool.remove(controller.getName());
+ PoolingManagerImpl mgr = ctlr2pool.remove(name);
if (mgr == null) {
return false;
@@ -321,8 +315,8 @@ public class PoolingFeature implements PolicyControllerFeatureAPI, DroolsControl
/**
*
* @param mgr
- * @return {@code true} if the request was handled by the manager,
- * {@code false} otherwise
+ * @return {@code true} if the request was handled by the manager, {@code false}
+ * otherwise
* @throws PoolingFeatureException
*/
public boolean apply(PoolingManagerImpl mgr) throws PoolingFeatureException;
@@ -367,6 +361,14 @@ public class PoolingFeature implements PolicyControllerFeatureAPI, DroolsControl
public static class Factory {
/**
+ * @param featName feature name
+ * @return the properties for the specified feature
+ */
+ public Properties getProperties(String featName) {
+ return SystemPersistence.manager.getProperties(featName);
+ }
+
+ /**
* Makes a pooling manager for a controller.
*
* @param controller