import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.Getter;
+
import org.junit.Test;
import org.onap.policy.appc.Request;
import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
// VFW
private static final String VFW_TOSCA_LEGACY_POLICY = "vfw/tosca-vfw.json";
private static final String VFW_TOSCA_COMPLIANT_POLICY = "vfw/tosca-compliant-vfw.json";
+ private static final String VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY = "vfw/tosca-compliant-timeout-vfw.json";
private static final String VFW_ONSET = "vfw/vfw.onset.json";
private static final String VFW_APPC_SUCCESS = "vfw/vfw.appc.success.json";
+ private static final String VFW_APPC_FAILURE = "vfw/vfw.appc.failure.json";
// VLB
private static final String VLB_TOSCA_LEGACY_POLICY = "vlb/tosca-vlb.json";
protected static HttpClients httpClients;
protected static Simulators simulators;
-
// used to inject and wait for messages
@Getter(AccessLevel.PROTECTED)
private Topics topics;
appcLegacySunnyDay(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, "ModifyConfig");
}
+ /**
+ * VFW Rainy Day using legacy tosca policy (operation and final failure).
+ */
+ @Test
+ public void testVfwRainyDayLegacyFailure() {
+ appcLegacyRainyDay(VFW_TOSCA_LEGACY_POLICY, VFW_ONSET, "ModifyConfig");
+ }
+
+ /**
+ * VFW Rainy Day using compliant tosca policy (final failure).
+ */
+ @Test
+ public void testVfwRainyDayOverallTimeout() {
+ appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY, VFW_ONSET, "ModifyConfig");
+ }
+
+ /**
+ * VFW Rainy day using compliant tosca policy (final failure due to timeout).
+ */
+ @Test
+ public void testVfwRainyDayCompliantTimeout() {
+ appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, "ModifyConfig");
+ }
+
// VLB
/**
waitForFinalSuccess(policy, policyClMgt);
}
+ /**
+ * Rainy day scenario for use cases that use Legacy APPC.
+ *
+ * @param policyFile file containing the ToscaPolicy to be loaded
+ * @param onsetFile file containing the ONSET to be injected
+ * @param operation expected APPC operation request
+ * @param checkOperation flag to determine whether or not to wait for operation timeout
+ */
+ protected void appcLegacyRainyDay(String policyFile, String onsetFile, String operation) {
+ policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
+ appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
+
+ assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
+ policy = rules.setupPolicyFromFile(policyFile);
+ assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
+
+ /* Inject an ONSET event over the DCAE topic */
+ topics.inject(DCAE_TOPIC, onsetFile);
+
+ /* Wait to acquire a LOCK and a PDP-X PERMIT */
+ waitForLockAndPermit(policy, policyClMgt);
+
+ /*
+ * Ensure that an APPC RESTART request was sent in response to the matching ONSET
+ */
+ Request appcreq = appcClSink.await(req -> operation.equals(req.getAction()));
+
+ /*
+ * Inject a 401 APPC Response Return over the APPC topic, with appropriate
+ * subRequestId
+ */
+ topics.inject(APPC_CL_TOPIC, VFW_APPC_FAILURE, appcreq.getCommonHeader().getSubRequestId());
+
+ /* --- Operation Completed --- */
+ waitForOperationFailure();
+
+ /* --- Transaction Completed --- */
+ waitForFinalFailure(policy, policyClMgt);
+ }
+
+ /**
+ * Rainy day scenario for use cases that use Legacy APPC.
+ * Expected to fail due to timeout.
+ *
+ * @param policyFile file containing the ToscaPolicy to be loaded
+ * @param onsetFile file containing the ONSET to be injected
+ * @param operation expected APPC operation request
+ */
+ protected void appcLegacyRainyDayNoResponse(String policyFile, String onsetFile, String operation) {
+ policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
+ appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
+
+ assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
+ policy = rules.setupPolicyFromFile(policyFile);
+ assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
+
+ /* Inject an ONSET event over the DCAE topic */
+ topics.inject(DCAE_TOPIC, onsetFile);
+
+ /* Wait to acquire a LOCK and a PDP-X PERMIT */
+ waitForLockAndPermit(policy, policyClMgt);
+
+ /*
+ * Ensure that an APPC RESTART request was sent in response to the matching ONSET
+ */
+ appcClSink.await(req -> operation.equals(req.getAction()));
+
+ /*
+ * Do not inject an APPC Response.
+ */
+
+ /* --- Transaction Completed --- */
+ waitForFinalFailure(policy, policyClMgt);
+ }
+
/**
* Sunny day scenario for use cases that use an HTTP simulator.
*
return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_SUCCESS);
}
+ /**
+ * Waits for a OPERATION FAILURE transaction notification.
+ */
+ protected void waitForOperationFailure() {
+ policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION_FAILURE);
+ }
+
+ /**
+ * Waits for a FINAL FAILURE transaction notification.
+ *
+ * @return the FINAL FAILURE notification
+ */
+ protected VirtualControlLoopNotification waitForFinalFailure(ToscaPolicy policy,
+ Listener<VirtualControlLoopNotification> policyClMgt) {
+
+ return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_FAILURE);
+ }
+
/**
* Waits for notifications for LOCK acquisition and GUARD Permit so that event
* processing may proceed.
--- /dev/null
+{
+ "type": "onap.policies.controlloop.operational.common.Drools",
+ "type_version": "1.0.0",
+ "name": "operational.modifyconfig",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "operational.modifyconfig"
+ },
+ "properties": {
+ "controllerName": "usecases",
+ "id": "ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a",
+ "timeout": 7,
+ "abatement": false,
+ "trigger": "unique-policy-id-1-modifyConfig",
+ "operations": [
+ {
+ "id": "unique-policy-id-1-modifyConfig",
+ "description": "Modify the packet generator",
+ "operation": {
+ "actor": "APPC",
+ "operation": "ModifyConfig",
+ "target": {
+ "targetType": "VNF",
+ "entityIds": {
+ "resourceID": "bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38"
+ }
+ }
+ },
+ "timeout": 10,
+ "retries": 0,
+ "success": "final_success",
+ "failure": "final_failure",
+ "failure_timeout": "final_failure_timeout",
+ "failure_retries": "final_failure_retries",
+ "failure_exception": "final_failure_exception",
+ "failure_guard": "final_failure_guard"
+ }
+ ]
+ }
+}
checkAppcLegacyPolicy("ModifyConfig", base::testVfwSunnyDayCompliant);
}
+ @Test
+ public void testTestVfwRainyDayLegacyFailure() {
+ checkAppcLegacyPolicyOperationFailure("ModifyConfig", base::testVfwRainyDayLegacyFailure);
+ }
+
+ @Test
+ public void testTestVfwRainyDayOverallTimeout() {
+ checkAppcLegacyPolicyFinalFailure("ModifyConfig", base::testVfwRainyDayOverallTimeout);
+ }
+
+ @Test
+ public void testTestVfwRainyDayCompliantTimeout() {
+ checkAppcLegacyPolicyFinalFailure("ModifyConfig", base::testVfwRainyDayCompliantTimeout);
+ }
+
@Test
public void testTestVlbSunnyDayLegacy() {
checkHttpPolicy(base::testVlbSunnyDayLegacy);
verify(topics).inject(eq(BaseRuleTest.APPC_CL_TOPIC), any(), any());
}
+ protected void checkAppcLegacyPolicyOperationFailure(String operation, Runnable test) {
+ enqueueAppcLegacy(operation);
+ enqueueClMgt(ControlLoopNotificationType.OPERATION_FAILURE);
+ enqueueClMgt(ControlLoopNotificationType.FINAL_FAILURE);
+
+ test.run();
+
+ assertEquals(1, permitCount);
+ assertEquals(1, finalCount);
+
+ assertTrue(appcLcmQueue.isEmpty());
+ assertTrue(clMgtQueue.isEmpty());
+
+ // initial event
+ verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+
+ // reply to each APPC request
+ verify(topics).inject(eq(BaseRuleTest.APPC_CL_TOPIC), any(), any());
+ }
+
+ protected void checkAppcLegacyPolicyFinalFailure(String operation, Runnable test) {
+ enqueueAppcLegacy(operation);
+ enqueueClMgt(ControlLoopNotificationType.FINAL_FAILURE);
+
+ test.run();
+
+ assertEquals(1, permitCount);
+ assertEquals(1, finalCount);
+
+ assertTrue(appcLcmQueue.isEmpty());
+ assertTrue(clMgtQueue.isEmpty());
+
+ // initial event
+ verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+
+ // There were no requests sent
+ }
+
protected void checkHttpPolicy(Runnable test) {
enqueueClMgt(ControlLoopNotificationType.OPERATION_SUCCESS);
enqueueClMgt(ControlLoopNotificationType.FINAL_SUCCESS);