diff options
Diffstat (limited to 'policy-management')
2 files changed, 50 insertions, 21 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureApi.java b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureApi.java index 9c6ac223..49287786 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureApi.java +++ b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyControllerFeatureApi.java @@ -1,8 +1,8 @@ /* * ============LICENSE_START======================================================= - * policy-management + * ONAP * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ package org.onap.policy.drools.features; import java.util.Properties; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.utils.services.OrderedService; +import org.onap.policy.drools.protocol.configuration.DroolsConfiguration; import org.onap.policy.drools.system.PolicyController; public interface PolicyControllerFeatureApi extends OrderedService { @@ -83,7 +84,7 @@ public interface PolicyControllerFeatureApi extends OrderedService { * * @return true if this feature intercepts and takes ownership * of the operation preventing the invocation of - * lower priority features. False, otherwise.. + * lower priority features. False, otherwise. */ default boolean beforeStop(PolicyController controller) { return false; @@ -101,6 +102,28 @@ public interface PolicyControllerFeatureApi extends OrderedService { } /** + * intercept before the Policy Controller is patched. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + default boolean beforePatch(PolicyController controller, DroolsConfiguration configuration) { + return false; + } + + /** + * intercept after the Policy Controller is patched. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + default boolean afterPatch(PolicyController controller, boolean success) { + return false; + } + + /** * intercept before the Policy Controller is locked. * * @return true if this feature intercepts and takes ownership diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java b/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java index 5685ff6e..b80f4c86 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java @@ -215,7 +215,6 @@ public class AggregatedPolicyController implements PolicyController, TopicListen */ @Override public boolean updateDrools(DroolsConfiguration newDroolsConfiguration) { - DroolsConfiguration oldDroolsConfiguration = new DroolsConfiguration(this.droolsController.getArtifactId(), this.droolsController.getGroupId(), this.droolsController.getVersion()); @@ -227,46 +226,53 @@ public class AggregatedPolicyController implements PolicyController, TopicListen return true; } + if (FeatureApiUtils.apply(getProviders(), + feature -> feature.beforePatch(this, newDroolsConfiguration), + (feature, ex) -> logger.error("{}: feature {} before-patch failure because of {}", this, + feature.getClass().getName(), ex.getMessage(), ex))) { + return true; + } + if (droolsController.isBrained() && (newDroolsConfiguration.getArtifactId() == null || DroolsControllerConstants.NO_ARTIFACT_ID.equals(newDroolsConfiguration.getArtifactId()))) { + // detach maven artifact DroolsControllerConstants.getFactory().destroy(this.droolsController); } + boolean success = true; try { - /* Drools Controller created, update initialization properties for restarts */ - this.properties.setProperty(DroolsPropertyConstants.RULES_GROUPID, newDroolsConfiguration.getGroupId()); this.properties.setProperty(DroolsPropertyConstants.RULES_ARTIFACTID, newDroolsConfiguration.getArtifactId()); this.properties.setProperty(DroolsPropertyConstants.RULES_VERSION, newDroolsConfiguration.getVersion()); - getPersistenceManager().storeController(name, this.properties); this.initDrools(this.properties); - /* set drools controller to current locked status */ - - if (this.isLocked()) { - this.droolsController.lock(); + if (isLocked()) { + droolsController.lock(); } else { - this.droolsController.unlock(); + droolsController.unlock(); } - /* set drools controller to current alive status */ - - if (this.isAlive()) { - this.droolsController.start(); + if (isAlive()) { + droolsController.start(); } else { - this.droolsController.stop(); + droolsController.stop(); } - - } catch (IllegalArgumentException e) { + } catch (RuntimeException e) { logger.error("{}: cannot update-drools because of {}", this, e.getMessage(), e); - return false; + success = false; } - return true; + boolean finalSuccess = success; + FeatureApiUtils.apply(getProviders(), + feature -> feature.afterPatch(this, finalSuccess), + (feature, ex) -> logger.error("{}: feature {} after-patch failure because of {}", this, + feature.getClass().getName(), ex.getMessage(), ex)); + + return finalSuccess; } /** |