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;
26 import java.util.UUID;
27 import java.util.function.Supplier;
28 import java.util.stream.Collectors;
29 import lombok.AccessLevel;
31 import org.junit.Test;
32 import org.onap.policy.appc.Request;
33 import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
34 import org.onap.policy.common.utils.coder.Coder;
35 import org.onap.policy.common.utils.coder.CoderException;
36 import org.onap.policy.common.utils.coder.StandardCoder;
37 import org.onap.policy.common.utils.coder.StandardCoderInstantAsMillis;
38 import org.onap.policy.controlloop.ControlLoopNotificationType;
39 import org.onap.policy.controlloop.VirtualControlLoopNotification;
40 import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager2;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
42 import org.onap.policy.sdnr.PciMessage;
45 * Superclass used for rule tests.
47 public abstract class BaseTest {
48 private static final String APPC_RESTART_OP = "restart";
49 private static final String APPC_MODIFY_CONFIG_OP = "ModifyConfig";
52 * Canonical Topic Names.
54 protected static final String DCAE_TOPIC = "DCAE_TOPIC";
55 protected static final String APPC_LCM_WRITE_TOPIC = "APPC-LCM-WRITE";
56 protected static final String POLICY_CL_MGT_TOPIC = "POLICY-CL-MGT";
57 protected static final String APPC_LCM_READ_TOPIC = "APPC-LCM-READ";
58 protected static final String APPC_CL_TOPIC = "APPC-CL";
59 protected static final String SDNR_CL_TOPIC = "SDNR-CL";
60 protected static final String SDNR_CL_RSP_TOPIC = "SDNR-CL-RSP";
63 * Constants for each test case.
66 // service123 (i.e., multi-operation policy)
67 private static final String SERVICE123_TOSCA_COMPLIANT_POLICY = "service123/tosca-compliant-service123.json";
68 private static final String SERVICE123_ONSET = "service123/service123.onset.json";
69 private static final String SERVICE123_APPC_RESTART_FAILURE = "service123/service123.appc.restart.failure.json";
70 private static final String SERVICE123_APPC_REBUILD_FAILURE = "service123/service123.appc.rebuild.failure.json";
71 private static final String SERVICE123_APPC_MIGRATE_SUCCESS = "service123/service123.appc.migrate.success.json";
73 // duplicates (i.e., mutliple events in the engine at the same time)
74 private static final String DUPLICATES_TOSCA_COMPLIANT_POLICY = "duplicates/tosca-compliant-duplicates.json";
75 private static final String DUPLICATES_ONSET_1 = "duplicates/duplicates.onset.1.json";
76 private static final String DUPLICATES_ONSET_2 = "duplicates/duplicates.onset.2.json";
77 private static final String DUPLICATES_APPC_SUCCESS = "duplicates/duplicates.appc.success.json";
80 private static final String VCPE_TOSCA_LEGACY_POLICY = "vcpe/tosca-legacy-vcpe.json";
81 private static final String VCPE_TOSCA_COMPLIANT_POLICY = "vcpe/tosca-compliant-vcpe.json";
82 private static final String VCPE_ONSET_1 = "vcpe/vcpe.onset.1.json";
83 private static final String VCPE_ONSET_2 = "vcpe/vcpe.onset.2.json";
84 private static final String VCPE_ONSET_3 = "vcpe/vcpe.onset.3.json";
85 private static final String VCPE_APPC_SUCCESS = "vcpe/vcpe.appc.success.json";
88 private static final String VDNS_TOSCA_LEGACY_POLICY = "vdns/tosca-legacy-vdns.json";
89 private static final String VDNS_TOSCA_COMPLIANT_POLICY = "vdns/tosca-compliant-vdns.json";
90 private static final String VDNS_TOSCA_COMPLIANT_RAINY_POLICY = "vdns/tosca-compliant-vdns-rainy.json";
91 private static final String VDNS_ONSET = "vdns/vdns.onset.json";
94 private static final String VFW_TOSCA_LEGACY_POLICY = "vfw/tosca-vfw.json";
95 private static final String VFW_TOSCA_COMPLIANT_POLICY = "vfw/tosca-compliant-vfw.json";
96 private static final String VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY = "vfw/tosca-compliant-timeout-vfw.json";
97 private static final String VFW_ONSET = "vfw/vfw.onset.json";
98 private static final String VFW_APPC_SUCCESS = "vfw/vfw.appc.success.json";
99 private static final String VFW_APPC_FAILURE = "vfw/vfw.appc.failure.json";
102 private static final String VPCI_TOSCA_POLICY = "vpci/tosca-vpci.json";
103 private static final String VPCI_TOSCA_COMPLIANT_POLICY = "vpci/tosca-compliant-vpci.json";
104 private static final String VPCI_ONSET = "vpci/vpci.onset.json";
105 private static final String VPCI_SDNR_SUCCESS = "vpci/vpci.sdnr.success.json";
108 private static final String VSONH_TOSCA_POLICY = "vsonh/tosca-vsonh.json";
109 private static final String VSONH_TOSCA_COMPLIANT_POLICY = "vsonh/tosca-compliant-vsonh.json";
110 private static final String VSONH_ONSET = "vsonh/vsonh.onset.json";
111 private static final String VSONH_SDNR_SUCCESS = "vsonh/vsonh.sdnr.success.json";
114 * Coders used to decode requests and responses.
116 protected static final Coder APPC_LEGACY_CODER = new StandardCoderInstantAsMillis();
117 protected static final Coder APPC_LCM_CODER = new StandardCoder();
118 protected static final Coder POLICY_CL_MGT_CODER = new PolicyClMgtCoder();
121 * Coders used to decode requests and responses.
123 private static final Coder SDNR_CODER = new StandardCoder();
125 // these may be overridden by junit tests
126 protected static Supplier<HttpClients> httpClientMaker = HttpClients::new;
127 protected static Supplier<Simulators> simMaker = Simulators::new;
128 protected static Supplier<Topics> topicMaker = Topics::new;
130 protected static Rules rules;
131 protected static HttpClients httpClients;
132 protected static Simulators simulators;
134 // used to inject and wait for messages
135 @Getter(AccessLevel.PROTECTED)
136 protected static Topics topics;
138 // used to wait for messages on SINK topics
139 protected Listener<VirtualControlLoopNotification> policyClMgt;
140 protected Listener<Request> appcClSink;
141 protected Listener<AppcLcmDmaapWrapper> appcLcmRead;
142 protected Listener<PciMessage> sdnrClSink;
145 * Tosca Policy that was loaded.
147 protected ToscaPolicy policy;
150 * Initializes {@link #rules}, {@link #httpClients}, and {@link #simulators}.
152 public static void initStatics() {
153 httpClients = httpClientMaker.get();
154 simulators = simMaker.get();
158 * Destroys {@link #httpClients}, {@link #simulators}, and {@link #rules}.
160 public static void finishStatics() {
161 httpClients.destroy();
162 simulators.destroy();
166 * Initializes {@link #topics} and {@link #controller}.
169 topics = topicMaker.get();
173 * Destroys {@link #topics} and resets the rule facts.
175 public void finish() {
179 // Service123 (i.e., Policy with multiple operations)
182 * Service123 with Tosca Compliant Policy.
185 public void testService123Compliant() {
186 policyClMgt = createNoficationTopicListener();
187 appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
188 policy = checkPolicy(SERVICE123_TOSCA_COMPLIANT_POLICY);
190 // inject an ONSET event over the DCAE topic
191 topics.inject(DCAE_TOPIC, SERVICE123_ONSET);
192 /* Wait to acquire a LOCK and a PDP-X PERMIT */
194 waitForLockAndPermit(policy, policyClMgt);
196 // restart request should be sent and fail four times (i.e., because retry=3)
197 for (int count = 0; count < 4; ++count) {
198 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
200 topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_RESTART_FAILURE,
201 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
203 // rebuild request should be sent and fail once
204 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> "rebuild".equals(req.getRpcName()));
205 topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_REBUILD_FAILURE,
206 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
207 // migrate request should be sent and succeed
208 appcreq = appcLcmRead.await(req -> "migrate".equals(req.getRpcName()));
209 topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_MIGRATE_SUCCESS,
210 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
211 /* --- Operation Completed --- */
212 waitForOperationSuccess();
213 /* --- Transaction Completed --- */
214 waitForFinalSuccess(policy, policyClMgt);
220 * This test case tests the scenario where 3 events occur and 2 of the requests refer
221 * to the same target entity while the 3rd is for another entity. The expected result
222 * is that the event with the duplicate target entity will have a final success result
223 * for one of the events, and a rejected message for the one that was unable to obtain
224 * the lock. The event that is referring to a different target entity should be able
225 * to obtain a lock since it is a different target. After processing of all events
226 * there should only be the policy and params objects left in memory.
229 public void testDuplicatesEvents() {
230 policyClMgt = createNoficationTopicListener();
231 appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
233 policy = checkPolicy(DUPLICATES_TOSCA_COMPLIANT_POLICY);
235 final long initCount = getCreateCount();
238 * Inject ONSET events over the DCAE topic. First and last have the same target
239 * entity, but different request IDs - only one should succeed. The middle one is
240 * for a different target entity, so it should succeed.
242 topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_1, UUID.randomUUID().toString());
243 topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_2);
244 topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_1, UUID.randomUUID().toString());
246 // should see two restarts
247 for (int count = 0; count < 2; ++count) {
248 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
251 topics.inject(APPC_LCM_WRITE_TOPIC, DUPLICATES_APPC_SUCCESS,
252 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
255 // should see two FINAL successes
256 VirtualControlLoopNotification notif1 = waitForFinalSuccess(policy, policyClMgt);
257 VirtualControlLoopNotification notif2 = waitForFinalSuccess(policy, policyClMgt);
259 // get the list of target names so we can ensure there's one of each
260 List<String> actual = List.of(notif1, notif2).stream().map(notif -> notif.getAai().get("generic-vnf.vnf-id"))
261 .sorted().collect(Collectors.toList());
263 assertEquals(List.of("duplicate-VNF", "vCPE_Infrastructure_vGMUX_demo_app").toString(), actual.toString());
265 long added = getCreateCount() - initCount;
266 assertEquals(2, added);
272 * Sunny Day with Legacy Tosca Policy.
275 public void testVcpeSunnyDayLegacy() {
276 appcLcmSunnyDay(VCPE_TOSCA_LEGACY_POLICY, VCPE_ONSET_1, APPC_RESTART_OP);
280 * Sunny Day with Tosca Compliant Policy.
283 public void testVcpeSunnyDayCompliant() {
284 appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, VCPE_ONSET_1, APPC_RESTART_OP);
288 * An ONSET flood prevention test that injects a few ONSETs at once. It attempts to
289 * simulate the flooding behavior of the DCAE TCA microservice. TCA could blast tens
290 * or hundreds of ONSETs within sub-second intervals.
293 public void testVcpeOnsetFloodPrevention() {
294 appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, List.of(VCPE_ONSET_1, VCPE_ONSET_2, VCPE_ONSET_3),
301 * Sunny Day with Legacy Tosca Policy.
304 public void testVdnsSunnyDayLegacy() {
305 httpSunnyDay(VDNS_TOSCA_LEGACY_POLICY, VDNS_ONSET);
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 Legacy Tosca Policy.
331 public void testVfwSunnyDayLegacy() {
332 appcLegacySunnyDay(VFW_TOSCA_LEGACY_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
336 * VFW Sunny Day with Tosca Compliant Policy.
339 public void testVfwSunnyDayCompliant() {
340 appcLegacySunnyDay(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
344 * VFW Rainy Day using legacy tosca policy (operation and final failure).
347 public void testVfwRainyDayLegacyFailure() {
348 appcLegacyRainyDay(VFW_TOSCA_LEGACY_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
352 * VFW Rainy Day using compliant tosca policy (final failure).
355 public void testVfwRainyDayOverallTimeout() {
356 appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
360 * VFW Rainy day using compliant tosca policy (final failure due to timeout).
363 public void testVfwRainyDayCompliantTimeout() {
364 appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
368 * VPCI Sunny Day with Legacy Tosca Policy.
371 public void testVpciSunnyDayLegacy() {
372 sdnrSunnyDay(VPCI_TOSCA_POLICY, VPCI_ONSET, VPCI_SDNR_SUCCESS, "ModifyConfig");
376 * VPCI Sunny Day Tosca Policy.
379 public void testVpciSunnyDayCompliant() {
380 sdnrSunnyDay(VPCI_TOSCA_COMPLIANT_POLICY, VPCI_ONSET, VPCI_SDNR_SUCCESS, "ModifyConfig");
386 * VSONH Sunny Day with Legacy Tosca Policy.
389 public void testVsonhSunnyDayLegacy() {
390 sdnrSunnyDay(VSONH_TOSCA_POLICY, VSONH_ONSET, VSONH_SDNR_SUCCESS, "ModifyConfigANR");
394 * VSONH Sunny Day with Tosca Policy.
397 public void testVsonhSunnyDayCompliant() {
398 sdnrSunnyDay(VSONH_TOSCA_COMPLIANT_POLICY, VSONH_ONSET, VSONH_SDNR_SUCCESS, "ModifyConfigANR");
402 * Sunny day scenario for use cases that use APPC-LCM.
404 * @param policyFile file containing the ToscaPolicy to be loaded
405 * @param onsetFile file containing the ONSET to be injected
406 * @param operation expected APPC operation request
408 protected void appcLcmSunnyDay(String policyFile, String onsetFile, String operation) {
409 appcLcmSunnyDay(policyFile, List.of(onsetFile), operation);
413 * Sunny day scenario for use cases that use APPC-LCM.
415 * @param policyFile file containing the ToscaPolicy to be loaded
416 * @param onsetFiles list of files containing the ONSET to be injected
417 * @param operation expected APPC operation request
419 protected void appcLcmSunnyDay(String policyFile, List<String> onsetFiles, String operation) {
420 policyClMgt = createNoficationTopicListener();
421 appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
423 policy = checkPolicy(policyFile);
426 // inject several ONSET events over the DCAE topic
427 for (String onsetFile : onsetFiles) {
428 topics.inject(DCAE_TOPIC, onsetFile);
431 /* Wait to acquire a LOCK and a PDP-X PERMIT */
432 waitForLockAndPermit(policy, policyClMgt);
435 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
437 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> operation.equals(req.getRpcName()));
440 * Inject a 400 APPC Response Return over the APPC topic, with appropriate
443 topics.inject(APPC_LCM_WRITE_TOPIC, VCPE_APPC_SUCCESS,
444 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
446 /* --- Operation Completed --- */
448 waitForOperationSuccess();
450 /* --- Transaction Completed --- */
451 waitForFinalSuccess(policy, policyClMgt);
455 * Sunny day scenario for use cases that use Legacy APPC.
457 * @param policyFile file containing the ToscaPolicy to be loaded
458 * @param onsetFile file containing the ONSET to be injected
459 * @param operation expected APPC operation request
461 protected void appcLegacySunnyDay(String policyFile, String onsetFile, String operation) {
462 policyClMgt = createNoficationTopicListener();
463 appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
465 policy = checkPolicy(policyFile);
467 /* Inject an ONSET event over the DCAE topic */
468 topics.inject(DCAE_TOPIC, onsetFile);
470 /* Wait to acquire a LOCK and a PDP-X PERMIT */
471 waitForLockAndPermit(policy, policyClMgt);
474 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
476 Request appcreq = appcClSink.await(req -> operation.equals(req.getAction()));
479 * Inject a 400 APPC Response Return over the APPC topic, with appropriate
482 topics.inject(APPC_CL_TOPIC, VFW_APPC_SUCCESS, appcreq.getCommonHeader().getSubRequestId());
484 /* --- Operation Completed --- */
486 waitForOperationSuccess();
488 /* --- Transaction Completed --- */
489 waitForFinalSuccess(policy, policyClMgt);
493 * Rainy day scenario for use cases that use Legacy APPC.
495 * @param policyFile file containing the ToscaPolicy to be loaded
496 * @param onsetFile file containing the ONSET to be injected
497 * @param operation expected APPC operation request
498 * @param checkOperation flag to determine whether or not to wait for operation timeout
500 protected void appcLegacyRainyDay(String policyFile, String onsetFile, String operation) {
501 policyClMgt = createNoficationTopicListener();
502 appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
504 policy = checkPolicy(policyFile);
506 /* Inject an ONSET event over the DCAE topic */
507 topics.inject(DCAE_TOPIC, onsetFile);
509 /* Wait to acquire a LOCK and a PDP-X PERMIT */
510 waitForLockAndPermit(policy, policyClMgt);
513 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
515 Request appcreq = appcClSink.await(req -> operation.equals(req.getAction()));
518 * Inject a 401 APPC Response Return over the APPC topic, with appropriate
521 topics.inject(APPC_CL_TOPIC, VFW_APPC_FAILURE, appcreq.getCommonHeader().getSubRequestId());
523 /* --- Operation Completed --- */
524 waitForOperationFailure();
526 /* --- Transaction Completed --- */
527 waitForFinalFailure(policy, policyClMgt);
531 * Rainy day scenario for use cases that use Legacy APPC.
532 * Expected to fail due to timeout.
534 * @param policyFile file containing the ToscaPolicy to be loaded
535 * @param onsetFile file containing the ONSET to be injected
536 * @param operation expected APPC operation request
538 protected void appcLegacyRainyDayNoResponse(String policyFile, String onsetFile, String operation) {
539 policyClMgt = createNoficationTopicListener();
540 appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
542 policy = checkPolicy(policyFile);
544 /* Inject an ONSET event over the DCAE topic */
545 topics.inject(DCAE_TOPIC, onsetFile);
547 /* Wait to acquire a LOCK and a PDP-X PERMIT */
548 waitForLockAndPermit(policy, policyClMgt);
551 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
553 appcClSink.await(req -> operation.equals(req.getAction()));
556 * Do not inject an APPC Response.
559 /* --- Transaction Completed --- */
560 waitForFinalFailure(policy, policyClMgt);
564 * Sunny day scenario for use cases that use SDNR.
566 * @param policyFile file containing the ToscaPolicy to be loaded
567 * @param onsetFile file containing the ONSET to be injected
568 * @param operation expected SDNR operation request
570 protected void sdnrSunnyDay(String policyFile, String onsetFile, String successFile, String operation) {
571 policyClMgt = createNoficationTopicListener();
572 sdnrClSink = topics.createListener(SDNR_CL_TOPIC, PciMessage.class, SDNR_CODER);
574 policy = checkPolicy(policyFile);
576 /* Inject an ONSET event over the DCAE topic */
577 topics.inject(DCAE_TOPIC, onsetFile);
579 /* Wait to acquire a LOCK and a PDP-X PERMIT */
580 waitForLockAndPermit(policy, policyClMgt);
583 * Ensure that an SDNR RESTART request was sent in response to the matching ONSET
585 PciMessage pcireq = sdnrClSink.await(req -> operation.equals(req.getBody().getInput().getAction()));
590 topics.inject(SDNR_CL_RSP_TOPIC, successFile, pcireq.getBody().getInput().getCommonHeader().getSubRequestId());
592 /* --- Operation Completed --- */
594 waitForOperationSuccess();
596 /* --- Transaction Completed --- */
597 waitForFinalSuccess(policy, policyClMgt);
601 * Sunny day scenario for use cases that use an HTTP simulator.
603 * @param policyFile file containing the ToscaPolicy to be loaded
604 * @param onsetFile file containing the ONSET to be injected
605 * @param operation expected APPC operation request
607 protected void httpSunnyDay(String policyFile, String onsetFile) {
608 policyClMgt = createNoficationTopicListener();
610 policy = checkPolicy(policyFile);
612 /* Inject an ONSET event over the DCAE topic */
613 topics.inject(DCAE_TOPIC, onsetFile);
615 /* Wait to acquire a LOCK and a PDP-X PERMIT */
616 waitForLockAndPermit(policy, policyClMgt);
618 /* --- Operation Completed --- */
620 waitForOperationSuccess();
622 /* --- Transaction Completed --- */
623 waitForFinalSuccess(policy, policyClMgt);
627 * Rainy day scenario for use cases that use an HTTP simulator.
629 * @param policyFile file containing the ToscaPolicy to be loaded
630 * @param onsetFile file containing the ONSET to be injected
631 * @param operation expected APPC operation request
633 protected void httpRainyDay(String policyFile, String onsetFile) {
634 policyClMgt = createNoficationTopicListener();
636 policy = checkPolicy(policyFile);
638 /* Inject an ONSET event over the DCAE topic */
639 topics.inject(DCAE_TOPIC, onsetFile);
641 /* Wait to acquire a LOCK and a PDP-X PERMIT */
642 waitForLockAndPermit(policy, policyClMgt);
644 /* --- Operation Completed --- */
645 waitForOperationFailure();
647 /* --- Transaction Completed --- */
648 waitForFinalFailure(policy, policyClMgt);
651 protected long getCreateCount() {
652 return ControlLoopEventManager2.getCreateCount();
656 * Waits for a OPERATION SUCCESS transaction notification.
658 protected void waitForOperationSuccess() {
659 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION_SUCCESS);
663 * Waits for a FINAL SUCCESS transaction notification.
665 * @return the FINAL SUCCESS notification
667 protected VirtualControlLoopNotification waitForFinalSuccess(ToscaPolicy policy,
668 Listener<VirtualControlLoopNotification> policyClMgt) {
670 return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_SUCCESS);
674 * Waits for a OPERATION FAILURE transaction notification.
676 protected void waitForOperationFailure() {
677 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION_FAILURE);
681 * Waits for a FINAL FAILURE transaction notification.
683 * @return the FINAL FAILURE notification
685 protected VirtualControlLoopNotification waitForFinalFailure(ToscaPolicy policy,
686 Listener<VirtualControlLoopNotification> policyClMgt) {
688 return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_FAILURE);
692 * Waits for notifications for LOCK acquisition and GUARD Permit so that event
693 * processing may proceed.
695 protected abstract void waitForLockAndPermit(ToscaPolicy policy,
696 Listener<VirtualControlLoopNotification> policyClMgt);
699 * Waits for a FINAL transaction notification.
701 * @param finalType FINAL_xxx type for which to wait
703 * @return the FINAL notification
705 protected abstract VirtualControlLoopNotification waitForFinal(ToscaPolicy policy,
706 Listener<VirtualControlLoopNotification> policyClMgt, ControlLoopNotificationType finalType);
709 * Returns ToscaPolicy from File.
711 * @param fileName a path name
712 * @return ToscaPolicy
714 protected ToscaPolicy checkPolicy(String fileName) {
716 return Rules.getPolicyFromFile(fileName);
717 } catch (CoderException e) {
718 throw new IllegalArgumentException(fileName, e);
723 * Creates a Coder for PolicyClMgt from StandardCoder.
726 public static class PolicyClMgtCoder extends StandardCoder {
727 public PolicyClMgtCoder() {
728 super(org.onap.policy.controlloop.util.Serialization.gson,
729 org.onap.policy.controlloop.util.Serialization.gsonPretty);
734 * Returns Listener from createListner based on Coder.
735 * @return the Listener
737 protected Listener<VirtualControlLoopNotification> createNoficationTopicListener() {
738 return topics.createListener(POLICY_CL_MGT_TOPIC,
739 VirtualControlLoopNotification.class, POLICY_CL_MGT_CODER);