2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.common.rules.test;
23 import static org.junit.Assert.assertEquals;
25 import java.util.List;
27 import java.util.UUID;
28 import java.util.concurrent.TimeUnit;
29 import java.util.function.Supplier;
30 import java.util.stream.Collectors;
31 import lombok.AccessLevel;
34 import org.awaitility.Awaitility;
35 import org.junit.Test;
36 import org.onap.policy.appc.Request;
37 import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
38 import org.onap.policy.common.utils.coder.Coder;
39 import org.onap.policy.common.utils.coder.CoderException;
40 import org.onap.policy.common.utils.coder.StandardCoder;
41 import org.onap.policy.common.utils.coder.StandardCoderInstantAsMillis;
42 import org.onap.policy.controlloop.ControlLoopNotificationType;
43 import org.onap.policy.controlloop.VirtualControlLoopNotification;
44 import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager2;
45 import org.onap.policy.drools.system.PolicyEngineConstants;
46 import org.onap.policy.drools.system.internal.SimpleLockManager;
47 import org.onap.policy.drools.system.internal.SimpleLockManager.SimpleLock;
48 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
49 import org.onap.policy.sdnr.PciMessage;
50 import org.powermock.reflect.Whitebox;
53 * Superclass used for rule tests.
55 public abstract class BaseTest {
56 private static final String APPC_RESTART_OP = "restart";
57 private static final String APPC_MODIFY_CONFIG_OP = "ModifyConfig";
59 private static final String SDNR_MODIFY_CONFIG_OP = "ModifyConfig";
60 private static final String SNDR_MODIFY_CONFIG_ANR_OP = "ModifyConfigANR";
63 * Canonical Topic Names.
65 protected static final String DCAE_TOPIC = "DCAE_TOPIC";
66 protected static final String APPC_LCM_WRITE_TOPIC = "APPC-LCM-WRITE";
67 protected static final String POLICY_CL_MGT_TOPIC = "POLICY-CL-MGT";
68 protected static final String APPC_LCM_READ_TOPIC = "APPC-LCM-READ";
69 protected static final String APPC_CL_TOPIC = "APPC-CL";
70 protected static final String SDNR_CL_TOPIC = "SDNR-CL";
71 protected static final String SDNR_CL_RSP_TOPIC = "SDNR-CL-RSP";
74 * Constants for each test case.
77 // service123 (i.e., multi-operation policy)
78 private static final String SERVICE123_TOSCA_COMPLIANT_POLICY = "service123/tosca-compliant-service123.json";
79 private static final String SERVICE123_ONSET = "service123/service123.onset.json";
80 private static final String SERVICE123_APPC_RESTART_FAILURE = "service123/service123.appc.restart.failure.json";
81 private static final String SERVICE123_APPC_REBUILD_FAILURE = "service123/service123.appc.rebuild.failure.json";
82 private static final String SERVICE123_APPC_MIGRATE_SUCCESS = "service123/service123.appc.migrate.success.json";
84 // duplicates (i.e., mutliple events in the engine at the same time)
85 private static final String DUPLICATES_TOSCA_COMPLIANT_POLICY = "duplicates/tosca-compliant-duplicates.json";
86 private static final String DUPLICATES_ONSET_1 = "duplicates/duplicates.onset.1.json";
87 private static final String DUPLICATES_ONSET_2 = "duplicates/duplicates.onset.2.json";
88 private static final String DUPLICATES_APPC_SUCCESS = "duplicates/duplicates.appc.success.json";
91 private static final String VCPE_TOSCA_COMPLIANT_POLICY = "vcpe/tosca-compliant-vcpe.json";
92 private static final String VCPE_ONSET_1 = "vcpe/vcpe.onset.1.json";
93 private static final String VCPE_ONSET_2 = "vcpe/vcpe.onset.2.json";
94 private static final String VCPE_ONSET_3 = "vcpe/vcpe.onset.3.json";
95 private static final String VCPE_APPC_SUCCESS = "vcpe/vcpe.appc.success.json";
98 private static final String VDNS_TOSCA_COMPLIANT_POLICY = "vdns/tosca-compliant-vdns.json";
99 private static final String VDNS_TOSCA_COMPLIANT_RAINY_POLICY = "vdns/tosca-compliant-vdns-rainy.json";
100 private static final String VDNS_ONSET = "vdns/vdns.onset.json";
103 private static final String VFW_TOSCA_COMPLIANT_POLICY = "vfw/tosca-compliant-vfw.json";
104 private static final String VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY = "vfw/tosca-compliant-timeout-vfw.json";
105 private static final String VFW_ONSET = "vfw/vfw.onset.json";
106 private static final String VFW_APPC_SUCCESS = "vfw/vfw.appc.success.json";
107 private static final String VFW_APPC_FAILURE = "vfw/vfw.appc.failure.json";
110 private static final String VPCI_TOSCA_COMPLIANT_POLICY = "vpci/tosca-compliant-vpci.json";
111 private static final String VPCI_ONSET = "vpci/vpci.onset.json";
112 private static final String VPCI_SDNR_SUCCESS = "vpci/vpci.sdnr.success.json";
115 private static final String VSONH_TOSCA_COMPLIANT_POLICY = "vsonh/tosca-compliant-vsonh.json";
116 private static final String VSONH_ONSET = "vsonh/vsonh.onset.json";
117 private static final String VSONH_SDNR_SUCCESS = "vsonh/vsonh.sdnr.success.json";
120 * Coders used to decode requests and responses.
122 protected static final Coder APPC_LEGACY_CODER = new StandardCoderInstantAsMillis();
123 protected static final Coder APPC_LCM_CODER = new StandardCoder();
124 protected static final Coder POLICY_CL_MGT_CODER = new PolicyClMgtCoder();
127 * Coders used to decode requests and responses.
129 private static final Coder SDNR_CODER = new StandardCoder();
131 // these may be overridden by junit tests
132 protected static Supplier<HttpClients> httpClientMaker = HttpClients::new;
133 protected static Supplier<Simulators> simMaker = Simulators::new;
134 protected static Supplier<Topics> topicMaker = Topics::new;
136 protected static Rules rules;
137 protected static HttpClients httpClients;
138 protected static Simulators simulators;
140 // used to inject and wait for messages
141 @Getter(AccessLevel.PROTECTED)
142 @Setter(AccessLevel.PROTECTED)
143 protected static Topics topics;
145 // used to wait for messages on SINK topics
146 protected Listener<VirtualControlLoopNotification> policyClMgt;
147 protected Listener<Request> appcClSink;
148 protected Listener<AppcLcmDmaapWrapper> appcLcmRead;
149 protected Listener<PciMessage> sdnrClSink;
152 * Tosca Policy that was loaded.
154 protected ToscaPolicy policy;
157 * Initializes {@link #rules}, {@link #httpClients}, and {@link #simulators}.
159 public static void initStatics() {
160 httpClients = httpClientMaker.get();
161 simulators = simMaker.get();
165 * Destroys {@link #httpClients}, {@link #simulators}, and {@link #rules}.
167 public static void finishStatics() {
168 httpClients.destroy();
169 simulators.destroy();
173 * Initializes {@link #topics} and {@link #controller}.
176 setTopics(topicMaker.get());
178 Map<String, SimpleLock> locks = getLockMap();
185 * Destroys {@link #topics} and resets the rule facts.
187 public void finish() {
191 // Service123 (i.e., Policy with multiple operations)
194 * Service123 with Tosca Compliant Policy.
197 public void testService123Compliant() {
198 policyClMgt = createNoficationTopicListener();
199 appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
200 policy = checkPolicy(SERVICE123_TOSCA_COMPLIANT_POLICY);
202 // inject an ONSET event over the DCAE topic
203 topics.inject(DCAE_TOPIC, SERVICE123_ONSET);
204 /* Wait to acquire a LOCK and a PDP-X PERMIT */
206 waitForLockAndPermit(policy, policyClMgt);
208 // restart request should be sent and fail four times (i.e., because retry=3)
209 for (int count = 0; count < 4; ++count) {
210 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
212 topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_RESTART_FAILURE,
213 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
215 // rebuild request should be sent and fail once
216 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> "rebuild".equals(req.getRpcName()));
217 topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_REBUILD_FAILURE,
218 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
219 // migrate request should be sent and succeed
220 appcreq = appcLcmRead.await(req -> "migrate".equals(req.getRpcName()));
221 topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_MIGRATE_SUCCESS,
222 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
223 /* --- Operation Completed --- */
224 waitForOperationSuccess();
225 /* --- Transaction Completed --- */
226 waitForFinalSuccess(policy, policyClMgt);
234 * This test case tests the scenario where 3 events occur and 2 of the requests refer
235 * to the same target entity while the 3rd is for another entity. The expected result
236 * is that the event with the duplicate target entity will have a final success result
237 * for one of the events, and a rejected message for the one that was unable to obtain
238 * the lock. The event that is referring to a different target entity should be able
239 * to obtain a lock since it is a different target. After processing of all events
240 * there should only be the policy and params objects left in memory.
243 public void testDuplicatesEvents() {
244 policyClMgt = createNoficationTopicListener();
245 appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
247 policy = checkPolicy(DUPLICATES_TOSCA_COMPLIANT_POLICY);
249 final long initCount = getCreateCount();
252 * Inject ONSET events over the DCAE topic. First and last have the same target
253 * entity, but different request IDs - only one should succeed. The middle one is
254 * for a different target entity, so it should succeed.
256 topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_1, UUID.randomUUID().toString());
257 topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_2);
258 topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_1, UUID.randomUUID().toString());
260 // should see two restarts
261 for (int count = 0; count < 2; ++count) {
262 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
265 topics.inject(APPC_LCM_WRITE_TOPIC, DUPLICATES_APPC_SUCCESS,
266 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
269 // should see two FINAL successes
270 VirtualControlLoopNotification notif1 = waitForFinalSuccess(policy, policyClMgt);
271 VirtualControlLoopNotification notif2 = waitForFinalSuccess(policy, policyClMgt);
273 // get the list of target names so we can ensure there's one of each
274 List<String> actual = List.of(notif1, notif2).stream().map(notif -> notif.getAai().get("generic-vnf.vnf-id"))
275 .sorted().collect(Collectors.toList());
277 assertEquals(List.of("duplicate-VNF", "vCPE_Infrastructure_vGMUX_demo_app").toString(), actual.toString());
279 long added = getCreateCount() - initCount;
280 assertEquals(2, added);
288 * Sunny Day with Tosca Compliant Policy.
291 public void testVcpeSunnyDayCompliant() {
292 appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, VCPE_ONSET_1, APPC_RESTART_OP);
296 * An ONSET flood prevention test that injects a few ONSETs at once. It attempts to
297 * simulate the flooding behavior of the DCAE TCA microservice. TCA could blast tens
298 * or hundreds of ONSETs within sub-second intervals.
301 public void testVcpeOnsetFloodPrevention() {
302 appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, List.of(VCPE_ONSET_1, VCPE_ONSET_2, VCPE_ONSET_3),
309 * Sunny Day with Tosca Compliant Policy.
312 public void testVdnsSunnyDayCompliant() {
313 httpSunnyDay(VDNS_TOSCA_COMPLIANT_POLICY, VDNS_ONSET);
317 * Vdns Rainy Day with Compliant Tosca Policy.
320 public void testVdnsRainyDayCompliant() {
321 httpRainyDay(VDNS_TOSCA_COMPLIANT_RAINY_POLICY, VDNS_ONSET);
328 * VFW Sunny Day with Tosca Compliant Policy.
331 public void testVfwSunnyDayCompliant() {
332 appcLegacySunnyDay(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
336 * VFW Rainy Day using compliant tosca policy (final failure).
339 public void testVfwRainyDayOverallTimeout() {
340 appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
344 * VFW Rainy day using compliant tosca policy (final failure due to timeout).
347 public void testVfwRainyDayCompliantTimeout() {
348 appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
352 * VPCI Sunny Day Tosca Policy.
355 public void testVpciSunnyDayCompliant() {
356 sdnrSunnyDay(VPCI_TOSCA_COMPLIANT_POLICY, VPCI_ONSET, VPCI_SDNR_SUCCESS, SDNR_MODIFY_CONFIG_OP);
362 * VSONH Sunny Day with Tosca Policy.
365 public void testVsonhSunnyDayCompliant() {
366 sdnrSunnyDay(VSONH_TOSCA_COMPLIANT_POLICY, VSONH_ONSET, VSONH_SDNR_SUCCESS, SNDR_MODIFY_CONFIG_ANR_OP);
370 * Sunny day scenario for use cases that use APPC-LCM.
372 * @param policyFile file containing the ToscaPolicy to be loaded
373 * @param onsetFile file containing the ONSET to be injected
374 * @param operation expected APPC operation request
376 protected void appcLcmSunnyDay(String policyFile, String onsetFile, String operation) {
377 appcLcmSunnyDay(policyFile, List.of(onsetFile), operation);
381 * Sunny day scenario for use cases that use APPC-LCM.
383 * @param policyFile file containing the ToscaPolicy to be loaded
384 * @param onsetFiles list of files containing the ONSET to be injected
385 * @param operation expected APPC operation request
387 protected void appcLcmSunnyDay(String policyFile, List<String> onsetFiles, String operation) {
388 policyClMgt = createNoficationTopicListener();
389 appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
391 policy = checkPolicy(policyFile);
394 // inject several ONSET events over the DCAE topic
395 for (String onsetFile : onsetFiles) {
396 topics.inject(DCAE_TOPIC, onsetFile);
399 /* Wait to acquire a LOCK and a PDP-X PERMIT */
400 waitForLockAndPermit(policy, policyClMgt);
403 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
405 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> operation.equals(req.getRpcName()));
408 * Inject a 400 APPC Response Return over the APPC topic, with appropriate
411 topics.inject(APPC_LCM_WRITE_TOPIC, VCPE_APPC_SUCCESS,
412 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
414 /* --- Operation Completed --- */
416 waitForOperationSuccess();
418 /* --- Transaction Completed --- */
419 waitForFinalSuccess(policy, policyClMgt);
425 * Sunny day scenario for use cases that use Legacy APPC.
427 * @param policyFile file containing the ToscaPolicy to be loaded
428 * @param onsetFile file containing the ONSET to be injected
429 * @param operation expected APPC operation request
431 protected void appcLegacySunnyDay(String policyFile, String onsetFile, String operation) {
432 policyClMgt = createNoficationTopicListener();
433 appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
435 policy = checkPolicy(policyFile);
437 /* Inject an ONSET event over the DCAE topic */
438 topics.inject(DCAE_TOPIC, onsetFile);
440 /* Wait to acquire a LOCK and a PDP-X PERMIT */
441 waitForLockAndPermit(policy, policyClMgt);
444 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
446 Request appcreq = appcClSink.await(req -> operation.equals(req.getAction()));
449 * Inject a 400 APPC Response Return over the APPC topic, with appropriate
452 topics.inject(APPC_CL_TOPIC, VFW_APPC_SUCCESS, appcreq.getCommonHeader().getSubRequestId());
454 /* --- Operation Completed --- */
456 waitForOperationSuccess();
458 /* --- Transaction Completed --- */
459 waitForFinalSuccess(policy, policyClMgt);
465 * Rainy day scenario for use cases that use Legacy APPC.
467 * @param policyFile file containing the ToscaPolicy to be loaded
468 * @param onsetFile file containing the ONSET to be injected
469 * @param operation expected APPC operation request
470 * @param checkOperation flag to determine whether or not to wait for operation
473 protected void appcLegacyRainyDay(String policyFile, String onsetFile, String operation) {
474 policyClMgt = createNoficationTopicListener();
475 appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
477 policy = checkPolicy(policyFile);
479 /* Inject an ONSET event over the DCAE topic */
480 topics.inject(DCAE_TOPIC, onsetFile);
482 /* Wait to acquire a LOCK and a PDP-X PERMIT */
483 waitForLockAndPermit(policy, policyClMgt);
486 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
488 Request appcreq = appcClSink.await(req -> operation.equals(req.getAction()));
491 * Inject a 401 APPC Response Return over the APPC topic, with appropriate
494 topics.inject(APPC_CL_TOPIC, VFW_APPC_FAILURE, appcreq.getCommonHeader().getSubRequestId());
496 /* --- Operation Completed --- */
497 waitForOperationFailure();
499 /* --- Transaction Completed --- */
500 waitForFinalFailure(policy, policyClMgt);
506 * Rainy day scenario for use cases that use Legacy APPC. Expected to fail due to
509 * @param policyFile file containing the ToscaPolicy to be loaded
510 * @param onsetFile file containing the ONSET to be injected
511 * @param operation expected APPC operation request
513 protected void appcLegacyRainyDayNoResponse(String policyFile, String onsetFile, String operation) {
514 policyClMgt = createNoficationTopicListener();
515 appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
517 policy = checkPolicy(policyFile);
519 /* Inject an ONSET event over the DCAE topic */
520 topics.inject(DCAE_TOPIC, onsetFile);
522 /* Wait to acquire a LOCK and a PDP-X PERMIT */
523 waitForLockAndPermit(policy, policyClMgt);
526 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
528 appcClSink.await(req -> operation.equals(req.getAction()));
531 * Do not inject an APPC Response.
534 /* --- Transaction Completed --- */
535 waitForFinalFailure(policy, policyClMgt);
541 * Sunny day scenario for use cases that use SDNR.
543 * @param policyFile file containing the ToscaPolicy to be loaded
544 * @param onsetFile file containing the ONSET to be injected
545 * @param operation expected SDNR operation request
547 protected void sdnrSunnyDay(String policyFile, String onsetFile, String successFile, String operation) {
548 policyClMgt = createNoficationTopicListener();
549 sdnrClSink = topics.createListener(SDNR_CL_TOPIC, PciMessage.class, SDNR_CODER);
551 policy = checkPolicy(policyFile);
553 /* Inject an ONSET event over the DCAE topic */
554 topics.inject(DCAE_TOPIC, onsetFile);
556 /* Wait to acquire a LOCK and a PDP-X PERMIT */
557 waitForLockAndPermit(policy, policyClMgt);
560 * Ensure that an SDNR RESTART request was sent in response to the matching ONSET
562 PciMessage pcireq = sdnrClSink.await(req -> operation.equals(req.getBody().getInput().getAction()));
567 topics.inject(SDNR_CL_RSP_TOPIC, successFile, pcireq.getBody().getInput().getCommonHeader().getSubRequestId());
569 /* --- Operation Completed --- */
571 waitForOperationSuccess();
573 /* --- Transaction Completed --- */
574 waitForFinalSuccess(policy, policyClMgt);
580 * Sunny day scenario for use cases that use an HTTP simulator.
582 * @param policyFile file containing the ToscaPolicy to be loaded
583 * @param onsetFile file containing the ONSET to be injected
584 * @param operation expected APPC operation request
586 protected void httpSunnyDay(String policyFile, String onsetFile) {
587 policyClMgt = createNoficationTopicListener();
589 policy = checkPolicy(policyFile);
591 /* Inject an ONSET event over the DCAE topic */
592 topics.inject(DCAE_TOPIC, onsetFile);
594 /* Wait to acquire a LOCK and a PDP-X PERMIT */
595 waitForLockAndPermit(policy, policyClMgt);
597 /* --- Operation Completed --- */
599 waitForOperationSuccess();
601 /* --- Transaction Completed --- */
602 waitForFinalSuccess(policy, policyClMgt);
608 * Rainy day scenario for use cases that use an HTTP simulator.
610 * @param policyFile file containing the ToscaPolicy to be loaded
611 * @param onsetFile file containing the ONSET to be injected
612 * @param operation expected APPC operation request
614 protected void httpRainyDay(String policyFile, String onsetFile) {
615 policyClMgt = createNoficationTopicListener();
617 policy = checkPolicy(policyFile);
619 /* Inject an ONSET event over the DCAE topic */
620 topics.inject(DCAE_TOPIC, onsetFile);
622 /* Wait to acquire a LOCK and a PDP-X PERMIT */
623 waitForLockAndPermit(policy, policyClMgt);
625 /* --- Operation Completed --- */
626 waitForOperationFailure();
628 /* --- Transaction Completed --- */
629 waitForFinalFailure(policy, policyClMgt);
634 protected long getCreateCount() {
635 return ControlLoopEventManager2.getCreateCount();
639 * Waits for a OPERATION SUCCESS transaction notification.
641 protected void waitForOperationSuccess() {
642 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION_SUCCESS);
646 * Waits for a FINAL SUCCESS transaction notification.
648 * @return the FINAL SUCCESS notification
650 protected VirtualControlLoopNotification waitForFinalSuccess(ToscaPolicy policy,
651 Listener<VirtualControlLoopNotification> policyClMgt) {
653 return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_SUCCESS);
657 * Waits for a OPERATION FAILURE transaction notification.
659 protected void waitForOperationFailure() {
660 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION_FAILURE);
664 * Waits for a FINAL FAILURE transaction notification.
666 * @return the FINAL FAILURE notification
668 protected VirtualControlLoopNotification waitForFinalFailure(ToscaPolicy policy,
669 Listener<VirtualControlLoopNotification> policyClMgt) {
671 return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_FAILURE);
675 * Waits for notifications for LOCK acquisition and GUARD Permit so that event
676 * processing may proceed.
678 protected abstract void waitForLockAndPermit(ToscaPolicy policy,
679 Listener<VirtualControlLoopNotification> policyClMgt);
682 * Waits for a FINAL transaction notification.
684 * @param finalType FINAL_xxx type for which to wait
686 * @return the FINAL notification
688 protected abstract VirtualControlLoopNotification waitForFinal(ToscaPolicy policy,
689 Listener<VirtualControlLoopNotification> policyClMgt, ControlLoopNotificationType finalType);
692 * Returns ToscaPolicy from File.
694 * @param fileName a path name
695 * @return ToscaPolicy
697 protected ToscaPolicy checkPolicy(String fileName) {
699 return Rules.getPolicyFromFile(fileName);
700 } catch (CoderException e) {
701 throw new IllegalArgumentException(fileName, e);
706 * Creates a Coder for PolicyClMgt from StandardCoder.
709 public static class PolicyClMgtCoder extends StandardCoder {
710 public PolicyClMgtCoder() {
711 super(org.onap.policy.controlloop.util.Serialization.gson,
712 org.onap.policy.controlloop.util.Serialization.gsonPretty);
717 * Returns Listener from createListner based on Coder.
719 * @return the Listener
721 protected Listener<VirtualControlLoopNotification> createNoficationTopicListener() {
722 return topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, POLICY_CL_MGT_CODER);
726 * Verifies that all locks have been released, waiting a bit, if necessary.
728 private void verifyUnlocked() {
729 Map<String, SimpleLock> locks = getLockMap();
731 Awaitility.await().atMost(5, TimeUnit.SECONDS).until(locks::isEmpty);
735 private Map<String, SimpleLock> getLockMap() {
736 Object lockMgr = Whitebox.getInternalState(PolicyEngineConstants.getManager(), "lockManager");
737 if (lockMgr instanceof SimpleLockManager) {
738 return Whitebox.getInternalState(lockMgr, "resource2lock");