aboutsummaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2020-03-25 19:37:20 -0500
committerjhh <jorge.hernandez-herrero@att.com>2020-03-26 16:54:52 -0500
commit319e008dae673c08706cb41f3da81bf338476035 (patch)
tree3c45a97fc0b5d91402fc512f0ac9becd2dae7bde /feature-lifecycle/src
parent2c7a0d5541ba37af068782b0af0482e41f1d4941 (diff)
native policy use engine for top-down processing
This will ensure proper invocation of all feature hooks. Issue-ID: POLICY-2388 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: I8d1666bb5e9526faa588e4f613674e080181d4ba Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-lifecycle/src')
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java20
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java17
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactController.java47
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java10
4 files changed, 66 insertions, 28 deletions
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java
index d27172b2..d9205977 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java
@@ -38,7 +38,7 @@ public class LifecycleFeature
@Override
public int getSequenceNumber() {
- return 10;
+ return 1;
}
@Override
@@ -52,6 +52,11 @@ public class LifecycleFeature
}
@Override
+ public boolean afterPatch(PolicyController controller, boolean success) {
+ return fsmPatch(controller);
+ }
+
+ @Override
public boolean beforeStop(PolicyEngine engine) {
return fsmStop();
}
@@ -63,8 +68,7 @@ public class LifecycleFeature
@Override
public boolean beforeShutdown(PolicyEngine engine) {
- fsm.shutdown();
- return false;
+ return fsmShutdown(engine);
}
@Override
@@ -101,4 +105,14 @@ public class LifecycleFeature
fsm.stop(controller);
return false;
}
+
+ private boolean fsmPatch(PolicyController controller) {
+ fsm.patch(controller);
+ return false;
+ }
+
+ private boolean fsmShutdown(PolicyEngine engine) {
+ fsm.shutdown();
+ return false;
+ }
}
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
index 6953d831..3ecb4b3a 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
@@ -179,6 +179,11 @@ public class LifecycleFsm implements Startable {
*/
public synchronized void start(@NonNull PolicyController controller) {
logger.info("lifecycle event: start controller: {}", controller.getName());
+ if (!controller.getDrools().isBrained()) {
+ logger.warn("ignoring lifecycle event: start controller: {}", controller);
+ return;
+ }
+
for (ToscaPolicyTypeIdentifier id : controller.getPolicyTypes()) {
if (isToscaPolicyType(id.getName())) {
PolicyTypeDroolsController ptDroolsController = (PolicyTypeDroolsController) policyTypesMap.get(id);
@@ -191,6 +196,18 @@ public class LifecycleFsm implements Startable {
}
}
+ /**
+ * Patch a controller event.
+ */
+ public synchronized void patch(@NonNull PolicyController controller) {
+ logger.info("lifecycle event: patch controller: {}", controller.getName());
+ if (controller.getDrools().isBrained()) {
+ this.start(controller);
+ } else {
+ this.stop(controller);
+ }
+ }
+
@Override
public synchronized boolean stop() {
logger.info("lifecycle event: stop engine");
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactController.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactController.java
index d91ecccf..113bb885 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactController.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactController.java
@@ -26,9 +26,11 @@ import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.domain.models.artifact.NativeArtifactPolicy;
+import org.onap.policy.drools.protocol.configuration.ControllerConfiguration;
import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
import org.onap.policy.drools.system.PolicyController;
import org.onap.policy.drools.system.PolicyControllerConstants;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.slf4j.Logger;
@@ -55,42 +57,47 @@ public class PolicyTypeNativeArtifactController implements PolicyTypeController
PolicyController controller;
try {
nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeArtifactPolicy.class);
+ DroolsConfiguration droolsConfig =
+ new DroolsConfiguration(
+ nativePolicy.getProperties().getRulesArtifact().getArtifactId(),
+ nativePolicy.getProperties().getRulesArtifact().getGroupId(),
+ nativePolicy.getProperties().getRulesArtifact().getVersion());
+
controller =
PolicyControllerConstants.getFactory().get(nativePolicy.getProperties().getController().getName());
+ if (controller.getDrools().isBrained()) {
+ logger.warn("upgrade of a live controller is strongly discouraged (undeploy first): {} -> {}",
+ controller, droolsConfig);
+ }
+
+ return update(nativePolicy, droolsConfig);
} catch (CoderException | RuntimeException e) {
logger.warn("Invalid Policy: {}", policy);
return false;
}
-
- DroolsConfiguration newConfig =
- new DroolsConfiguration(
- nativePolicy.getProperties().getRulesArtifact().getArtifactId(),
- nativePolicy.getProperties().getRulesArtifact().getGroupId(),
- nativePolicy.getProperties().getRulesArtifact().getVersion());
-
- PolicyControllerConstants.getFactory().patch(controller, newConfig);
- return true;
}
@Override
public boolean undeploy(ToscaPolicy policy) {
- PolicyController controller;
try {
NativeArtifactPolicy nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeArtifactPolicy.class);
- controller =
- PolicyControllerConstants.getFactory().get(nativePolicy.getProperties().getController().getName());
+ DroolsConfiguration noConfig =
+ new DroolsConfiguration(
+ DroolsControllerConstants.NO_ARTIFACT_ID,
+ DroolsControllerConstants.NO_GROUP_ID,
+ DroolsControllerConstants.NO_VERSION);
+
+ return update(nativePolicy, noConfig);
} catch (RuntimeException | CoderException e) {
logger.warn("Invalid Policy: {}", policy);
return false;
}
+ }
- DroolsConfiguration noConfig =
- new DroolsConfiguration(
- DroolsControllerConstants.NO_ARTIFACT_ID,
- DroolsControllerConstants.NO_GROUP_ID,
- DroolsControllerConstants.NO_VERSION);
-
- PolicyControllerConstants.getFactory().patch(controller, noConfig);
- return true;
+ private boolean update(NativeArtifactPolicy nativePolicy, DroolsConfiguration droolsConfig) {
+ ControllerConfiguration controllerConfig =
+ new ControllerConfiguration(nativePolicy.getProperties().getController().getName(),
+ ControllerConfiguration.CONFIG_CONTROLLER_OPERATION_UPDATE, droolsConfig);
+ return PolicyEngineConstants.getManager().updatePolicyController(controllerConfig) != null;
}
}
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java
index 2a417dcb..8255c027 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java
@@ -41,6 +41,7 @@ import org.onap.policy.drools.domain.models.controller.ControllerSourceTopic;
import org.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.system.PolicyController;
import org.onap.policy.drools.system.PolicyControllerConstants;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.slf4j.Logger;
@@ -83,9 +84,8 @@ public class PolicyTypeNativeDroolsController implements PolicyTypeController {
PolicyController controller;
try {
- controller =
- PolicyControllerConstants.getFactory().build(
- controllerConfig.getControllerName(), controllerProps);
+ controller = PolicyEngineConstants.getManager()
+ .createPolicyController(controllerConfig.getControllerName(), controllerProps);
} catch (RuntimeException e) {
logger.warn("failed deploy (cannot create controller) for policy: {}", policy);
return false;
@@ -98,8 +98,8 @@ public class PolicyTypeNativeDroolsController implements PolicyTypeController {
public boolean undeploy(ToscaPolicy policy) {
try {
ControllerPolicy nativePolicy = fsm.getDomainMaker().convertTo(policy, ControllerPolicy.class);
- PolicyControllerConstants.getFactory()
- .destroy(nativePolicy.getProperties().getControllerName());
+ PolicyEngineConstants.getManager()
+ .removePolicyController(nativePolicy.getProperties().getControllerName());
return true;
} catch (RuntimeException | CoderException e) {
logger.warn("failed undeploy of policy: {}", policy);