Do not honor group/subgroup changes with status messages.
When no present group/subgroups in update messages, assume that
they have to be reset.
Keep the policy cache of non-installed policies tracking them
when in passive state besides active. Wait until go active
to enable them.
Remove legacy PAP and PDP-X healtchecks as it was basically
testing reachability. There are conflicts with maintaining
2 different sets of PAPs and PDPs, trying to avoid it.
Alternative healtchecks are being placed on the robot test
framework. What to healtcheck should be considered more
carefully in the near future.
Change-Id: I574f30bb5899faf521123c79046793d16b4a46e0
Issue-ID: POLICY-1748
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
http.server.services.HEALTHCHECK.https=true
http.server.services.HEALTHCHECK.aaf=${env:AAF}
http.server.services.HEALTHCHECK.serialization.provider=org.onap.policy.common.gson.JacksonHandler
-
-http.client.services=PAP,PDP
-
-http.client.services.PAP.host=${env:PAP_HOST}
-http.client.services.PAP.port=9091
-http.client.services.PAP.contextUriPath=pap/test
-http.client.services.PAP.https=true
-http.client.services.PAP.userName=${env:PAP_USERNAME}
-http.client.services.PAP.password=${env:PAP_PASSWORD}
-http.client.services.PAP.managed=true
-http.client.services.PAP.serialization.provider=org.onap.policy.common.gson.JacksonHandler
-
-http.client.services.PDP.host=${env:PDP_HOST}
-http.client.services.PDP.port=8081
-http.client.services.PDP.contextUriPath=pdp/test
-http.client.services.PDP.https=true
-http.client.services.PDP.userName=${env:PDP_USERNAME}
-http.client.services.PDP.password=${env:PDP_PASSWORD}
-http.client.services.PDP.managed=false
-http.client.services.PDP.serialization.provider=org.onap.policy.common.gson.JacksonHandler
protected static final String CONFIGURATION_PROPERTIES_NAME = "feature-lifecycle";
protected static final String POLICY_TYPE_VERSION = "1.0.0";
- protected static final long DEFAULT_STATUS_TIMER_SECONDS = 60L;
+ protected static final long DEFAULT_STATUS_TIMER_SECONDS = 120L;
protected static final long MIN_STATUS_INTERVAL_SECONDS = 5L;
protected static final String PDP_MESSAGE_NAME = "messageName";
policiesMap.remove(policy.getIdentifier());
}
+ protected List<ToscaPolicy> resetPoliciesAction() {
+ ArrayList<ToscaPolicy> policies = new ArrayList<>(policiesMap.values());
+ policiesMap.clear();
+ return policies;
+ }
+
/* ** Action Helpers ** */
private boolean startIo() {
@Override
protected boolean stateChangeToActive(@NonNull PdpStateChange change) {
fsm.transitionToAction(new LifecycleStateActive(fsm));
+ super.updatePolicies(fsm.resetPoliciesAction());
return fsm.statusAction(response(change.getRequestId(), PdpResponseStatus.SUCCESS,null));
}
@Override
protected boolean deployPolicy(@NonNull PolicyController controller, @NonNull ToscaPolicy policy) {
logger.info("{}: deploy {} from {}", this, policy.getIdentifier(), controller.getName());
+ fsm.deployedPolicyAction(policy);
return true;
}
@Override
protected boolean undeployPolicy(@NonNull PolicyController controller, @NonNull ToscaPolicy policy) {
logger.info("{}: undeploy {} from {}", this, policy.getIdentifier(), controller.getName());
+ fsm.undeployedPolicyAction(policy);
return true;
}
}
public boolean stateChange(@NonNull PdpStateChange change) {
synchronized (fsm) {
if (change.getState() == PdpState.PASSIVE) {
- group(change.getPdpGroup(), change.getPdpSubgroup());
return stateChangeToPassive(change);
}
if (change.getState() == PdpState.ACTIVE) {
- group(change.getPdpGroup(), change.getPdpSubgroup());
return stateChangeToActive(change);
}
return false;
}
- group(update.getPdpGroup(), update.getPdpSubgroup());
+ fsm.setGroupAction(update.getPdpGroup(), update.getPdpSubgroup());
if (!updatePolicies(update.getPolicies())) {
fsm.statusAction(response(update.getRequestId(), PdpResponseStatus.FAIL, "cannot process policies"));
return response;
}
-
- protected void group(String group, String subgroup) {
- if (group == null || subgroup == null) {
- return;
- }
-
- fsm.setGroupAction(group, subgroup);
- }
}
import org.onap.policy.drools.properties.DroolsProperties;
import org.onap.policy.drools.system.PolicyController;
import org.onap.policy.drools.util.KieUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
/**
* Controller Test Support.
*/
public PolicyController createController() throws IOException {
try {
- getController();
+ PolicyController controller = getController();
+ controller.getDrools().delete(ToscaPolicy.class);
+ return controller;
} catch (IllegalArgumentException e) {
;
}
change.setState(PdpState.ACTIVE);
change.setName(fsm.getName());
+ fsm.setGroupAction("A", "a");
fsm.source.offer(new StandardCoder().encode(change));
controllerSupport.getController().start();
}
change.setName(fsm.getName());
fsm.source.offer(new StandardCoder().encode(change));
assertEquals(PdpState.ACTIVE, fsm.state());
- assertEquals("B", fsm.getGroup());
- assertEquals("b", fsm.getSubgroup());
+ assertEquals("A", fsm.getGroup());
+ assertEquals("a", fsm.getSubgroup());
change.setState(PdpState.SAFE);
fsm.source.offer(new StandardCoder().encode(change));
assertEquals(PdpState.ACTIVE, fsm.state());
assertEquals(interval, fsm.getStatusTimerSeconds());
+ assertTrue(controllerSupport.getController().getDrools().delete(ToscaPolicy.class));
+
fsm.shutdown();
}
}
@Test
public void update() throws IOException, CoderException {
+ controllerSupport.getController().getDrools().delete(ToscaPolicy.class);
+ assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
+
PdpUpdate update = new PdpUpdate();
update.setName(NetworkUtil.getHostname());
update.setPdpGroup("Z");
assertTrue(fsm.policyTypesMap.isEmpty());
assertTrue(fsm.policiesMap.isEmpty());
+ update.setPdpGroup(null);
+ update.setPdpSubgroup(null);
+
+ assertFalse(fsm.update(update));
+
+ assertEquals(PdpState.PASSIVE, fsm.state());
+ assertEquals(interval, fsm.getStatusTimerSeconds());
+ assertNull(fsm.getGroup());
+ assertNull(fsm.getSubgroup());
+ assertBasicPassive();
+ assertTrue(fsm.policyTypesMap.isEmpty());
+ assertTrue(fsm.policiesMap.isEmpty());
+
+ update.setPdpGroup("A");
+ update.setPdpSubgroup("a");
+
+ assertFalse(fsm.update(update));
+
+ assertEquals(PdpState.PASSIVE, fsm.state());
+ assertEquals(interval, fsm.getStatusTimerSeconds());
+ assertEquals("A", fsm.getGroup());
+ assertEquals("a", fsm.getSubgroup());
+ assertBasicPassive();
+ assertTrue(fsm.policyTypesMap.isEmpty());
+ assertTrue(fsm.policiesMap.isEmpty());
+
fsm.start(controllerSupport.getController());
assertEquals(1, fsm.policyTypesMap.size());
assertTrue(fsm.policiesMap.isEmpty());
assertTrue(fsm.update(update));
assertEquals(1, fsm.policyTypesMap.size());
- assertTrue(fsm.policiesMap.isEmpty());
+ assertEquals(1, fsm.policiesMap.size());
+ assertEquals(fsm.policiesMap.get(toscaPolicy.getIdentifier()), toscaPolicy);
+ assertEquals(PdpState.PASSIVE, fsm.state());
+ assertEquals(interval, fsm.getStatusTimerSeconds());
+ assertEquals("A", fsm.getGroup());
+ assertEquals("a", fsm.getSubgroup());
+ assertBasicPassive();
+ assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
+
+ update.setPdpGroup(null);
+ update.setPdpSubgroup(null);
+ update.setPolicies(Collections.emptyList());
+ assertTrue(fsm.update(update));
+ assertEquals(1, fsm.policyTypesMap.size());
+ assertEquals(0, fsm.policiesMap.size());
+ assertEquals(PdpState.PASSIVE, fsm.state());
+ assertEquals(interval, fsm.getStatusTimerSeconds());
+ assertNull(fsm.getGroup());
+ assertNull(fsm.getSubgroup());
+ assertBasicPassive();
+ assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
fsm.shutdown();
}
fsm.source.offer(new StandardCoder().encode(change));
assertEquals(PdpState.ACTIVE, fsm.state());
- assertEquals("A", fsm.getGroup());
- assertEquals("a", fsm.getSubgroup());
+ assertNull(fsm.getGroup());
+ assertNull(fsm.getSubgroup());
fsm.shutdown();
}
update.setPdpGroup("A");
update.setPdpSubgroup("a");
update.setPolicies(Collections.emptyList());
- update.setPdpHeartbeatIntervalMs(2 * 600000L);
+ update.setPdpHeartbeatIntervalMs(4 * 600000L);
assertFalse(fsm.update(update));
assertEquals(PdpState.TERMINATED, fsm.state.state());
- assertNotEquals((2 * 60000L) / 1000L, fsm.getStatusTimerSeconds());
+ assertNotEquals((4 * 60000L) / 1000L, fsm.getStatusTimerSeconds());
}
@Test
assertEquals(PdpState.TERMINATED, HttpClient.getBody(response, PdpState.class));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
-}
\ No newline at end of file
+}
*/
<T> boolean delete(@NonNull T fact);
+ /**
+ * Deletes all facts from a given class from a session.
+ */
+ <T> boolean delete(@NonNull String sessionName, @NonNull Class<T> fact);
+
+ /**
+ * Deletes all facts from a given class from all sessions.
+ */
+ <T> boolean delete(@NonNull Class<T> fact);
+
/**
* halts and permanently releases all resources.
*
return this.getSessionNames().stream().map((ss) -> delete(ss, fact)).reduce(false, Boolean::logicalOr);
}
+ @Override
+ public <T> boolean delete(@NonNull String sessionName, @NonNull Class<T> fact) {
+ PolicySession session = getSession(sessionName);
+ KieSession kieSession = session.getKieSession();
+
+ boolean success = true;
+ Collection<FactHandle> factHandles = kieSession.getFactHandles(new ClassObjectFilter(fact));
+ for (FactHandle factHandle : factHandles) {
+ try {
+ kieSession.delete(factHandle);
+ } catch (Exception e) {
+ logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
+ success = false;
+ }
+ }
+ return success;
+ }
+
+ @Override
+ public <T> boolean delete(@NonNull Class<T> fact) {
+ return this.getSessionNames().stream().map((ss) -> delete(ss, fact)).reduce(false, Boolean::logicalOr);
+ }
+
+
@Override
public Class<?> fetchModelClass(String className) {
return ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className);
return false;
}
+ @Override
+ public <T> boolean delete(@NonNull String sessionName, @NonNull Class<T> fact) {
+ return false;
+ }
+
+ @Override
+ public <T> boolean delete(@NonNull Class<T> fact) {
+ return false;
+ }
+
private String makeInvokeMsg() {
return this.getClass().getCanonicalName() + " invoked";
}
@ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm
) {
List<TopicSource> sources = new ArrayList<>();
+ Status status = Status.OK;
switch (CommInfrastructure.valueOf(comm.toUpperCase())) {
case UEB:
sources.addAll(TopicEndpoint.manager.getUebTopicSources());
sources.addAll(TopicEndpoint.manager.getNoopTopicSources());
break;
default:
+ status = Status.BAD_REQUEST;
logger.debug("Invalid communication mechanism parameter: {}", comm);
break;
}
- return Response.status(Response.Status.OK).entity(sources).build();
+ return Response.status(status).entity(sources).build();
}
/**
@ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm
) {
List<TopicSink> sinks = new ArrayList<>();
+ Status status = Status.OK;
switch (CommInfrastructure.valueOf(comm.toUpperCase())) {
case UEB:
sinks.addAll(TopicEndpoint.manager.getUebTopicSinks());
sinks.addAll(TopicEndpoint.manager.getNoopTopicSinks());
break;
default:
+ status = Status.BAD_REQUEST;
logger.debug("Invalid communication mechanism parameter: {}", comm);
break;
}
- return Response.status(Response.Status.OK).entity(sinks).build();
+ return Response.status(status).entity(sinks).build();
}
}
/**
- * Offers and event to a topic in a communication infrastructure.
+ * Offers an event to a topic in a communication infrastructure.
*
* @return response object
*/