# ============LICENSE_START=======================================================
# ONAP
# ================================================================================
-# Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2019-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.
lifecycle.pdp.group=${envd:POLICY_PDP_PAP_GROUP:defaultGroup}
+# Mandatory policy types that this PDP-D must support at a minimum
+lifecycle.pdp.policytypes=${envd:POLICY_PDP_PAP_POLICYTYPES}
+
dmaap.source.topics=POLICY-PDP-PAP
dmaap.sink.topics=POLICY-PDP-PAP
import com.fasterxml.jackson.annotation.JsonIgnore;
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;
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";
@Setter
protected String subgroup;
+ @Getter
+ protected Set<String> mandatoryPolicyTypes = new HashSet<>();
+
@Getter
protected final Map<ToscaPolicyTypeIdentifier, PolicyTypeController> policyTypesMap = new HashMap<>();
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());
}
@JsonIgnore
return state.state();
}
+
/* ** FSM events - entry points of events into the FSM ** */
@Override
for (ToscaPolicyTypeIdentifier id : controller.getPolicyTypes()) {
if (isToscaPolicyType(id.getName())) {
- PolicyTypeDroolsController ptDroolsController = (PolicyTypeDroolsController) policyTypesMap.get(id);
- if (ptDroolsController == null) {
+ 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 {
- ptDroolsController.add(controller);
+ ptDc.add(controller);
}
}
}
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());
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() {
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
controllerSupport.getController().start();
}
+ @Test
+ public void testMandatoryPolicyTypes() {
+ assertEquals(Set.of("onap.policies.native.drools.Artifact", "onap.policies.native.drools.Controller"),
+ fsm.getMandatoryPolicyTypes());
+ assertEquals(fsm.getMandatoryPolicyTypes(), fsm.getCurrentPolicyTypes());
+ assertTrue(fsm.isMandatoryPolicyTypesCompliant());
+ assertTrue(fsm.status());
+
+ fsm.mandatoryPolicyTypes.add("blah");
+ assertEquals(Set.of("onap.policies.native.drools.Artifact", "onap.policies.native.drools.Controller", "blah"),
+ fsm.getMandatoryPolicyTypes());
+ assertNotEquals(fsm.getMandatoryPolicyTypes(), fsm.getCurrentPolicyTypes());
+ assertFalse(fsm.isMandatoryPolicyTypesCompliant());
+ assertFalse(fsm.status());
+ }
+
@Test
public void testUpdatePolicies() throws IOException, CoderException {
assertEquals(2, fsm.policyTypesMap.size());