- protected void sendOnset(ControlLoopPolicy policy, UUID requestID, String triggerSourceName) throws InterruptedException {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.closedLoopControlName = policy.getControlLoop().getControlLoopName();
- event.requestID = requestID;
- event.target = "VNF_NAME";
- event.target_type = ControlLoopTargetType.VNF;
- event.closedLoopAlarmStart = Instant.now();
- event.AAI = new HashMap<>();
- event.AAI.put("cloud-region.identity-url", "foo");
- event.AAI.put("vserver.selflink", "bar");
- event.AAI.put("vserver.is-closed-loop-disabled", "false");
- event.AAI.put("vserver.vserver-name", "vserver-name-16102016-aai3255-data-11-1");
- event.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
- kieSession.insert(event);
- Thread.sleep(2000);
+ public void onTopicEvent(CommInfrastructure commType, String topic, String event) {
+ /*
+ * Pull the object that was sent out to DMAAP and make
+ * sure it is a ControlLoopNoticiation of type active
+ */
+ Object obj = null;
+ if ("POLICY-CL-MGT".equals(topic)) {
+ obj = org.onap.policy.controlloop.util.Serialization.gsonJunit.fromJson(event, org.onap.policy.controlloop.VirtualControlLoopNotification.class);
+ }
+ assertNotNull(obj);
+ if (obj instanceof VirtualControlLoopNotification) {
+ VirtualControlLoopNotification notification = (VirtualControlLoopNotification) obj;
+ String policyName = notification.policyName;
+ if (policyName.endsWith("EVENT")) {
+ logger.debug("Rule Fired: " + notification.policyName);
+ assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
+ }
+ else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) {
+ logger.debug("Rule Fired: " + notification.policyName);
+ assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification));
+ assertNotNull(notification.message);
+ assertTrue(notification.message.startsWith("Sending guard query"));
+ }
+ else if (policyName.endsWith("GUARD.RESPONSE")) {
+ logger.debug("Rule Fired: " + notification.policyName);
+ assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification));
+ assertNotNull(notification.message);
+ assertTrue(notification.message.toLowerCase().endsWith("permit"));
+ }
+ else if (policyName.endsWith("GUARD_PERMITTED")) {
+ logger.debug("Rule Fired: " + notification.policyName);
+ assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.notification));
+ assertNotNull(notification.message);
+ assertTrue(notification.message.startsWith("actor=SO"));
+ }
+ else if (policyName.endsWith("OPERATION.TIMEOUT")) {
+ logger.debug("Rule Fired: " + notification.policyName);
+ kieSession.halt();
+ logger.debug("The operation timed out");
+ fail("Operation Timed Out");
+ }
+ else if (policyName.endsWith("SO.RESPONSE")) {
+ logger.debug("Rule Fired: " + notification.policyName);
+ assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.notification));
+ assertNotNull(notification.message);
+ assertTrue(notification.message.startsWith("actor=SO"));
+ }
+ else if (policyName.endsWith("EVENT.MANAGER")) {
+ logger.debug("Rule Fired: " + notification.policyName);
+ assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification));
+ kieSession.halt();
+ }
+ else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) {
+ logger.debug("Rule Fired: " + notification.policyName);
+ kieSession.halt();
+ logger.debug("The control loop timed out");
+ fail("Control Loop Timed Out");
+ }
+ }
+ else if (obj instanceof SORequest) {
+ logger.debug("\n============ SO received the request!!! ===========\n");
+ }