diff options
author | jhh <jorge.hernandez-herrero@att.com> | 2020-08-24 20:04:52 -0500 |
---|---|---|
committer | jhh <jorge.hernandez-herrero@att.com> | 2020-08-25 10:54:58 -0500 |
commit | 5c71b5a62f4208030b3c3cd18b3f42398a0a86e5 (patch) | |
tree | 482c785dae07a441e2a30176c1faf8ff8b62e3d8 /feature-lifecycle/src/main/java | |
parent | 13d8a3204013f1c0bc02ddede96ab37ac3d64129 (diff) |
block status operations until controllers ready
Status messages to the PAP won't be send until
all mandatory resources specified in the
lifecycle.pdp.policytypes property are functional.
Issue-ID: POLICY-2669
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Change-Id: Ia9d4c678fcfbdb232059d0827235845ee11f1201
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-lifecycle/src/main/java')
-rw-r--r-- | feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java | 56 | ||||
-rw-r--r-- | feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java | 10 |
2 files changed, 45 insertions, 21 deletions
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 319770bd..a45f2b4e 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 @@ -22,10 +22,12 @@ package org.onap.policy.drools.lifecycle; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Properties; +import java.util.Set; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; @@ -77,6 +79,7 @@ public class LifecycleFsm implements Startable { protected static final String CONFIGURATION_PROPERTIES_NAME = "feature-lifecycle"; protected static final String GROUP_NAME = "lifecycle.pdp.group"; + protected static final String MANDATORY_POLICY_TYPES = "lifecycle.pdp.policytypes"; protected static final String DEFAULT_PDP_GROUP = "defaultGroup"; protected static final long MIN_STATUS_INTERVAL_SECONDS = 5L; protected static final String PDP_MESSAGE_NAME = "messageName"; @@ -129,6 +132,9 @@ public class LifecycleFsm implements Startable { protected String subgroup; @Getter + protected Set<String> mandatoryPolicyTypes = new HashSet<>(); + + @Getter protected final Map<ToscaPolicyTypeIdentifier, PolicyTypeController> policyTypesMap = new HashMap<>(); @Getter @@ -146,6 +152,16 @@ public class LifecycleFsm implements Startable { this.policyTypesMap.put( POLICY_TYPE_DROOLS_NATIVE_RULES, new PolicyTypeNativeArtifactController(this, POLICY_TYPE_DROOLS_NATIVE_RULES)); + + String commaSeparatedPolicyTypes = this.properties.getProperty(MANDATORY_POLICY_TYPES); + if (!StringUtils.isBlank(commaSeparatedPolicyTypes)) { + for (String mpt: commaSeparatedPolicyTypes.split("\\s*,\\s*")) { + this.mandatoryPolicyTypes.add(mpt); + } + } + + logger.info("The mandatory Policy Types are {}. Compliance is {}", + this.mandatoryPolicyTypes, this.isMandatoryPolicyTypesCompliant()); } @GsonJsonIgnore @@ -165,6 +181,7 @@ public class LifecycleFsm implements Startable { return state.state(); } + /* ** FSM events - entry points of events into the FSM ** */ @Override @@ -184,14 +201,12 @@ public class LifecycleFsm implements Startable { } for (ToscaPolicyTypeIdentifier id : controller.getPolicyTypes()) { - if (isToscaPolicyType(id.getName())) { - PolicyTypeDroolsController ptDroolsController = (PolicyTypeDroolsController) policyTypesMap.get(id); - if (ptDroolsController == null) { - policyTypesMap.put(id, new PolicyTypeDroolsController(this, id, controller)); - logger.info("policy-type {} added", id); - } else { - ptDroolsController.add(controller); - } + PolicyTypeDroolsController ptDc = (PolicyTypeDroolsController) policyTypesMap.get(id); //NOSONAR + if (ptDc == null) { + policyTypesMap.put(id, new PolicyTypeDroolsController(this, id, controller)); + logger.info("policy-type {} added", id); + } else { + ptDc.add(controller); } } } @@ -329,10 +344,6 @@ public class LifecycleFsm implements Startable { return stopTimers() && startTimers(); } - protected PolicyTypeController getController(ToscaPolicyTypeIdentifier policyType) { - return policyTypesMap.get(policyType); - } - protected List<ToscaPolicy> getDeployablePoliciesAction(@NonNull List<ToscaPolicy> policies) { List<ToscaPolicy> deployPolicies = new ArrayList<>(policies); deployPolicies.removeAll(policiesMap.values()); @@ -363,6 +374,22 @@ public class LifecycleFsm implements Startable { return (this.scheduler.submit(() -> state.updatePolicies(toscaPolicies)) != null); } + protected PolicyTypeController getController(ToscaPolicyTypeIdentifier policyType) { + return policyTypesMap.get(policyType); + } + + /** + * Do I support the mandatory policy types?. + */ + protected boolean isMandatoryPolicyTypesCompliant() { + return getCurrentPolicyTypes().containsAll(getMandatoryPolicyTypes()); + } + + protected Set<String> getCurrentPolicyTypes() { + return getPolicyTypesMap().keySet().stream() + .map(ToscaPolicyTypeIdentifier::getName).collect(Collectors.toSet()); + } + /* ** Action Helpers ** */ private boolean startIo() { @@ -444,11 +471,6 @@ public class LifecycleFsm implements Startable { return this.client.getSink().start(); } - protected boolean isToscaPolicyType(String domain) { - // HACK: until legacy controllers support is removed - return StringUtils.countMatches(domain, ".") > 1; - } - protected boolean isItMe(String name, String group, String subgroup) { if (Objects.equals(name, getName())) { return true; diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java index 503c0c11..cf13c46d 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java @@ -79,11 +79,13 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { @Override public boolean status() { synchronized (fsm) { - if (fsm.getPolicyTypesMap().isEmpty()) { - return true; - } else { - return fsm.statusAction(); + if (!fsm.isMandatoryPolicyTypesCompliant()) { + logger.info("Not all expected policy types are registered yet, current={}, expected={}", + fsm.getCurrentPolicyTypes(), fsm.getMandatoryPolicyTypes()); + return false; } + + return fsm.statusAction(); } } |