3 * THIS FILE CONTAINS PROPRIETARY INFORMATION OF
4 * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN
5 * ACCORDANCE WITH APPLICABLE AGREEMENTS.
7 * Copyright (c) 2016 AT&T Knowledge Ventures
8 * Unpublished and Not for Publication
11 package com.att.ecomp.policy.controlloop;
13 import com.att.ecomp.policy.controlloop.ATTControlLoopEvent;
14 import org.openecomp.policy.controlloop.VirtualControlLoopEvent;
15 import org.openecomp.policy.controlloop.VirtualControlLoopNotification;
16 import org.openecomp.policy.controlloop.ControlLoopEventStatus;
17 import com.att.ecomp.policy.controlloop.ATTControlLoopNotification;
18 import org.openecomp.policy.controlloop.ControlLoopNotificationType;
19 import com.att.ecomp.policy.controlloop.ControlLoopLogger;
20 import com.att.ecomp.policy.controlloop.policy.PolicyResult;
21 import com.att.ecomp.policy.controlloop.eventmanager.ControlLoopEventManager;
22 import com.att.ecomp.policy.controlloop.eventmanager.ControlLoopEventManager.NEW_EVENT_STATUS;
23 import com.att.ecomp.policy.controlloop.eventmanager.ControlLoopOperationManager;
24 import org.openecomp.policy.appc.Request;
25 import org.openecomp.policy.appc.Response;
26 import org.openecomp.policy.appc.CommonHeader;
27 import com.att.ecomp.policy.guard.PolicyGuard;
28 import com.att.ecomp.policy.guard.PolicyGuard.LockResult;
29 import com.att.ecomp.policy.guard.TargetLock;
30 import com.att.ecomp.policy.guard.GuardResult;
31 import com.att.ecomp.policy.guard.PolicyGuardRequest;
32 import com.att.ecomp.policy.guard.PolicyGuardResponse;
33 import com.att.ecomp.policy.guard.PolicyGuardXacmlRequestAttributes;
34 import com.att.research.xacml.api.pdp.PDPEngine;
35 import com.att.research.xacml.std.annotations.RequestParser;
36 import com.att.ecomp.policy.guard.PolicyGuardXacmlHelper;
37 import com.att.ecomp.policy.controlloop.policy.ControlLoopPolicy;
38 import com.att.ecomp.policy.controlloop.policy.Policy;
39 import java.net.URLDecoder;
40 import org.eclipse.persistence.exceptions.DatabaseException;
43 // REPLACE THESE WITH PRODUCTION VERSIONS
45 import com.att.ecomp.policy.controlloop.ControlLoopLogger;
46 import com.att.ecomp.policy.drools.PolicyEngine;
47 import org.yaml.snakeyaml.Yaml;
48 import org.yaml.snakeyaml.constructor.Constructor;
50 global ControlLoopLogger Logger;
51 global PolicyEngine Engine;
52 global PDPEngine XacmlPdpEngine;
54 import java.time.Instant;
55 import java.util.LinkedList;
56 import java.util.Iterator;
59 closedLoopControlName : String
60 controlLoopYaml : String
64 enbOperationsPeriodicTimer : String
68 declare OperationTimer
69 closedLoopControlName : String
74 declare ControlLoopTimer
75 closedLoopControlName : String
83 * Called once and only once to insert the parameters into working memory for this Closed Loop policy.
86 rule "${policyName}.SETUP"
92 Logger.info("------------------------------------------------------------------------------------------------");
93 Logger.metrics(Instant.now() + " " + drools.getRule().getName() + " " + drools.getRule().getPackage());
94 Params params = new Params();
95 params.setClosedLoopControlName("${closedLoopControlName}");
96 params.setControlLoopYaml("${controlLoopYaml}");
98 Logger.metrics("Inserted " + params);
99 Logger.info("------------------------------------------------------------------------------------------------");
100 EnbParams enbParams = new EnbParams();
103 //Fetching the eNodeB timer from the Yaml
105 Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
106 Object obj = yaml.load(URLDecoder.decode(params.getControlLoopYaml(), "UTF-8"));
108 enbParams.setEnbOperationsPeriodicTimer("0s");
109 for(Policy policy : ((ControlLoopPolicy)obj).policies){
110 if(policy.actor.equals("APPC")){
111 if(policy.payload != null){
112 if(policy.payload.containsKey("enbOperationPeriodicTimer")){
113 enbParams.setEnbOperationsPeriodicTimer(policy.payload.get("enbOperationPeriodicTimer"));
120 System.out.println("################ got timer: " + enbParams.getEnbOperationsPeriodicTimer());
126 * This rule responds to DCAE Events where there is no manager yet. Either it is
127 * the first ONSET, or a subsequent badly formed Event (i.e. Syntax error, or is-closed-loop-disabled)
130 rule "${policyName}.EVENT"
132 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
133 $event : ATTControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() )
134 not ( ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID ) )
140 Logger.info("------------------------------------------------------------------------------------------------");
141 Logger.metrics(Instant.now() + " " + drools.getRule().getName() + " " + drools.getRule().getPackage());
143 // Check the event, because we need it to not be null when
144 // we create the ControlLoopEventManager. The ControlLoopEventManager
145 // will do extra syntax checking as well check if the closed loop is disabled.
147 if ($event.requestID == null) {
148 ATTControlLoopNotification notification = new ATTControlLoopNotification($event);
149 notification.notification = ControlLoopNotificationType.REJECTED;
150 notification.from = "policy";
151 notification.message = "Missing requestID";
152 notification.policyName = drools.getRule().getName();
153 notification.policyScope = "${policyScope}";
154 notification.policyVersion = "${policyVersion}";
156 // Let interested parties know
158 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
160 // Retract it from memory
165 // Create an EventManager
167 ControlLoopEventManager manager = new ControlLoopEventManager($params.getClosedLoopControlName(), $event.requestID);
169 // Determine if EventManager can actively process the event (i.e. syntax, is_closed_loop_disabled checks etc.)
171 VirtualControlLoopNotification notification = manager.activate($params.getControlLoopYaml(), $event);
172 notification.from = "pdp-0001-controller=controlloop"; // Engine.getInstanceName()
173 notification.policyName = drools.getRule().getName();
174 notification.policyScope = "${policyScope}";
175 notification.policyVersion = "${policyVersion}";
177 // Are we actively pursuing this event?
179 if (notification.notification == ControlLoopNotificationType.ACTIVE) {
181 // Insert Event Manager into memory, this will now kick off processing.
185 // Let interested parties know
187 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
189 // Setup the Overall Control Loop timer
191 ControlLoopTimer clTimer = new ControlLoopTimer();
192 clTimer.setClosedLoopControlName($event.closedLoopControlName);
193 clTimer.setRequestID($event.requestID.toString());
194 clTimer.setDelay(manager.getControlLoopTimeout(1500) + "s");
201 // Let interested parties know
203 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
205 // Retract it from memory
210 // Now that the manager is inserted into Drools working memory, we'll wait for
211 // another rule to fire in order to continue processing. This way we can also
212 // then screen for additional ONSET and ABATED events for this RequestID.
215 } catch (Exception e) {
217 ATTControlLoopNotification notification = new ATTControlLoopNotification($event);
218 notification.notification = ControlLoopNotificationType.REJECTED;
219 notification.message = "Exception occurred " + e.getMessage();
220 notification.policyName = drools.getRule().getName();
221 notification.policyScope = "${policyScope}";
222 notification.policyVersion = "${policyVersion}";
226 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
236 * This rule happens when we got a valid ONSET, closed loop is enabled and an Event Manager
237 * is now created. We can start processing the yaml specification via the Event Manager.
240 rule "${policyName}.EVENT.MANAGER"
242 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
243 $event : ATTControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() )
244 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID )
245 $clTimer : ControlLoopTimer ( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() )
250 Logger.info("------------------------------------------------------------------------------------------------");
251 Logger.metrics(Instant.now() + " " + drools.getRule().getName() + " " + drools.getRule().getPackage());
252 Logger.metrics($params);
253 Logger.metrics($event);
254 Logger.metrics($manager);
255 Logger.metrics($clTimer);
257 // Check which event this is.
259 ControlLoopEventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event);
260 Logger.info("Event status is " + eventStatus);
262 // Check what kind of event this is
264 if (eventStatus == NEW_EVENT_STATUS.SUBSEQUENT_ONSET) {
266 // We don't care about subsequent onsets
268 Logger.info("Retracting Subsequent Onset " + $event);
272 if (eventStatus == NEW_EVENT_STATUS.SYNTAX_ERROR) {
274 // Ignore any bad syntax events
276 Logger.info("Retracting Bad Syntax Event " + $event);
281 // We only want the initial ONSET event in memory,
282 // all the other events need to be retracted to support
283 // cleanup and avoid the other rules being fired for this event.
285 if (eventStatus != NEW_EVENT_STATUS.FIRST_ONSET) {
286 Logger.info("Retracting Event " + $event);
289 Logger.info("Checking due to new event " + $event.triggerID);
291 // Now start seeing if we need to process this event
295 // Check if this is a Final Event
297 ATTControlLoopNotification notification = $manager.isControlLoopFinal();
300 if (notification != null) {
302 // Its final, but are we waiting for abatement?
304 if ($manager.getNumAbatements() > 0) {
305 Logger.info("Abatement received, close out the control loop for " + $event.requestID);
306 notification.from = "policy";
307 notification.policyName = drools.getRule().getName();
308 notification.policyScope = "${policyScope}";
309 notification.policyVersion = "${policyVersion}";
311 // In this case, we are done
313 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
317 TargetLock lock = $manager.unlockCurrentOperation();
319 System.out.println("retracting lock " + lock);
323 // Retract everything from memory
325 System.out.println("retracting onset");
326 retract($manager.getOnsetEvent());
330 // TODO - what if we get subsequent Events for this RequestID?
331 // By default, it will all start over again. May be confusing for Ruby.
332 // Or, we could track this and then subsequently ignore the events
336 // Check whether we need to wait for abatement
338 if ($manager.getProcessor().getControlLoop().abatement == true && notification.notification == ControlLoopNotificationType.FINAL_SUCCESS) {
339 Logger.info("Waiting for abatement.");
341 Logger.info("No abatement is promised to come, close out the control loop for " + $event.requestID);
342 notification.from = "policy";
343 notification.policyName = drools.getRule().getName();
344 notification.policyScope = "${policyScope}";
345 notification.policyVersion = "${policyVersion}";
347 // In this case, we are done
349 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
353 TargetLock lock = $manager.unlockCurrentOperation();
355 System.out.println("retracting lock " + lock);
359 // Retract everything from memory
361 System.out.println("retracting onset");
362 retract($manager.getOnsetEvent());
369 // NOT final, so let's ask for the next operation
371 ControlLoopOperationManager operation = $manager.processControlLoop();
372 if (operation != null) {
373 Logger.info("starting a new operation" + operation);
375 // insert into memory
379 // insert operation timeout object
381 OperationTimer opTimer = new OperationTimer();
382 opTimer.setClosedLoopControlName($event.closedLoopControlName);
383 opTimer.setRequestID($event.requestID.toString());
384 opTimer.setDelay(operation.getOperationTimeout().toString() + "s");
388 // Let's ask for a lock right away
390 LockResult<GuardResult, TargetLock> result = $manager.lockCurrentOperation();
391 if (result.getA().equals(GuardResult.LOCK_ACQUIRED)) {
392 Logger.info("manager returned lock " + result.getB());
394 // Insert into memory
396 insert(result.getB());
400 // Probably waiting for abatement
404 } catch (Exception e) {
407 ATTControlLoopNotification notification = new ATTControlLoopNotification($event);
408 notification.notification = ControlLoopNotificationType.REJECTED;
409 notification.from = "policy";
410 notification.message = "Exception occurred " + e.getMessage();
411 notification.policyName = drools.getRule().getName();
412 notification.policyScope = "${policyScope}";
413 notification.policyVersion = "${policyVersion}";
417 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
419 // TODO should we abort if we get an exception?
431 rule "${policyName}.PERIODIC_CHECK_OF_PENDING_ENB_OPERATIONS"
432 timer (expr: "0s", $t)
434 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
435 $enbParams : EnbParams($t : getEnbOperationsPeriodicTimer())
436 $event : ATTControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() )
437 $operations : LinkedList(size() > 0)
438 from collect( ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName) )
441 System.out.println(drools.getRule().getName() + " ********** operations size: " + $operations.size());
442 //System.out.println(drools.getRule().getName());
443 //The limt of 5 should also be defined in Yaml.
452 rule "${policyName}.EVENT.MANAGER.OPERATION.NOT_LOCKED.TIMEOUT"
455 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
456 $event : ATTControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() )
457 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID )
458 $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID )
459 not ( TargetLock (requestID == $event.requestID) )
464 Logger.info("------------------------------------------------------------------------------------------------");
465 Logger.metrics(Instant.now() + " " + drools.getRule().getName() + " " + drools.getRule().getPackage());
466 Logger.metrics($params);
467 Logger.metrics($manager);
468 Logger.metrics($operation);
470 // Need to ask for a Lock
472 LockResult<GuardResult, TargetLock> result = $manager.lockCurrentOperation();
473 if (result.getA().equals(GuardResult.LOCK_ACQUIRED)) {
474 Logger.info("Lock acquired: " + result.getB());
476 // Insert into memory
478 insert(result.getB());
484 * Guard Permitted, let's send request to the actor.
487 rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
489 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
490 $event : ATTControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() )
491 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID )
492 $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID, getGuardApprovalStatus() == "Permit" )
493 $lock : TargetLock (requestID == $event.requestID)
498 Logger.info("------------------------------------------------------------------------------------------------");
499 Logger.metrics(Instant.now() + " " + drools.getRule().getName() + " " + drools.getRule().getPackage());
500 Logger.metrics($params);
501 Logger.metrics($manager);
502 Logger.metrics($operation);
503 Logger.metrics($lock);
506 Object request = $operation.getOperationRequest();
508 if (request != null) {
509 Logger.info("Starting operation");
511 // Tell interested parties we are performing this Operation
513 ATTControlLoopNotification notification = new ATTControlLoopNotification($event);
514 notification.notification = ControlLoopNotificationType.OPERATION;
515 notification.message = $operation.getOperationMessage();
516 notification.history = $operation.getHistory();
517 notification.from = "policy";
518 notification.policyName = drools.getRule().getName();
519 notification.policyScope = "${policyScope}";
520 notification.policyVersion = "${policyVersion}";
521 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
523 switch ($operation.policy.actor){
527 if (request instanceof Request) {
528 Engine.deliver("UEB", "APPC-CL", request);
537 // What happens if its null?
545 * We were able to acquire a lock so now let's ask Xacml Guard whether we are allowed to proceed with the request to the actor.
548 rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED"
550 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
551 $event : ATTControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() )
552 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID )
553 $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID, getGuardApprovalStatus() == "NONE" )
554 $lock : TargetLock (requestID == $event.requestID)
559 Logger.info("------------------------------------------------------------------------------------------------");
560 Logger.metrics(Instant.now() + " " + drools.getRule().getName() + " " + drools.getRule().getPackage());
561 Logger.metrics($params);
562 Logger.metrics($manager);
563 Logger.metrics($operation);
564 Logger.metrics($lock);
570 // We are starting the operation but the actor won't be contacted until Guard is queried and permitted.
572 $operation.startOperation($event);
575 // Sending notification that we are about to query Guard ("DB write - start operation")
577 ATTControlLoopNotification notification = new ATTControlLoopNotification($event);
578 notification.notification = ControlLoopNotificationType.OPERATION;
579 notification.message = $operation.getOperationMessage();
580 notification.history = $operation.getHistory();
581 notification.from = "policy";
582 notification.policyName = drools.getRule().getName();
583 notification.policyScope = "${policyScope}";
584 notification.policyVersion = "${policyVersion}";
585 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
588 // Now send Guard Request to XACML Guard. In order to bypass the call to Guard, just change guardEnabled to false.
590 // In order to use REST XACML, provide a URL instead of "" as a second argument o the CallGuardTask() and set the first
591 // argument to null (instead of XacmlPdpEngine).
593 boolean guardEnabled = true;
597 Thread t = new Thread(new com.att.ecomp.policy.guard.CallGuardTask(
600 drools.getWorkingMemory(),
601 $operation.policy.actor.toString(),
602 $operation.policy.recipe,
604 $event.requestID.toString()
609 insert(new PolicyGuardResponse("Permit", $event.requestID, $operation.policy.recipe));
618 //This rule will be triggered when a thread talking to the XACML Guard inserts a guardResponse object into the working memory
620 rule "${policyName}.GUARD.RESPONSE"
622 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
623 $event : ATTControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
624 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID )
625 $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID )
626 $lock : TargetLock (requestID == $event.requestID)
627 $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() )
628 $guardResponse : PolicyGuardResponse(requestID == $event.requestID, $operation.policy.recipe == operation)
633 Logger.info("------------------------------------------------------------------------------------------------");
634 Logger.metrics(Instant.now() + " " + drools.getRule().getName() + " " + drools.getRule().getPackage());
635 Logger.metrics($params);
636 Logger.metrics($event);
637 Logger.metrics($operation);
638 Logger.metrics($lock);
639 Logger.metrics($guardResponse);
642 //we will permit the operation if there was no Guard for it
643 if($guardResponse.result == "Indeterminate"){
644 $guardResponse.result = "Permit";
648 // This notification has Guard result in "message". ("DB write - end operation in case of Guard Deny")
650 ATTControlLoopNotification notification = new ATTControlLoopNotification($event);
651 notification.notification = ControlLoopNotificationType.OPERATION;
652 notification.message = $operation.getOperationMessage($guardResponse.result);
653 notification.history = $operation.getHistory();
654 notification.from = "policy";
655 notification.policyName = drools.getRule().getName();
656 notification.policyScope = "${policyScope}";
657 notification.policyVersion = "${policyVersion}";
658 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
662 if($guardResponse.result == "Permit"){
664 modify($operation){setGuardApprovalStatus($guardResponse.result)};
667 //This is the Deny case
668 $operation.setOperationHasGuardDeny();
671 modify($manager) {finishOperation($operation)};
674 retract($guardResponse);
683 * This rule responds to APPC Response Events
685 * I would have like to be consistent and write the Response like this:
686 * $response : Response( CommonHeader.RequestID == $onset.requestID )
688 * However, no compile error was given. But a runtime error was given. I think
689 * because drools is confused between the classname CommonHeader vs the property CommonHeader.
692 rule "${policyName}.APPC.RESPONSE"
694 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
695 $event : ATTControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
696 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID )
697 $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID )
698 $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() )
699 $lock : TargetLock (requestID == $event.requestID)
700 $response : Response( getCommonHeader().RequestID == $event.requestID )
705 Logger.info("------------------------------------------------------------------------------------------------");
706 Logger.metrics(Instant.now() + " " + drools.getRule().getName() + " " + drools.getRule().getPackage());
707 Logger.metrics($params);
708 Logger.metrics($event);
709 Logger.metrics($manager);
710 Logger.metrics($operation);
711 Logger.metrics($opTimer);
712 Logger.metrics($lock);
713 Logger.metrics($response);
715 // Get the result of the operation
717 PolicyResult policyResult = $operation.onResponse($response);
718 if (policyResult != null) {
719 Logger.info("operation finished with result: " + policyResult);
721 // This Operation has completed, construct a notification showing our results. (DB write - end operation)
723 ATTControlLoopNotification notification = new ATTControlLoopNotification($event);
724 notification.from = "policy";
725 notification.policyName = drools.getRule().getName();
726 notification.policyScope = "${policyScope}";
727 notification.policyVersion = "${policyVersion}";
728 notification.message = $operation.getOperationHistory();
729 notification.history = $operation.getHistory();
730 if (policyResult.equals(PolicyResult.SUCCESS)) {
731 notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
733 // Let interested parties know
735 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
737 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
739 // Let interested parties know
741 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
744 // Ensure the operation is complete
746 if ($operation.isOperationComplete() == true) {
748 // It is complete, remove it from memory
752 // We must also retract the timer object
753 // NOTE: We could write a Rule to do this
757 // Complete the operation
759 modify($manager) {finishOperation($operation)};
762 // Just doing this will kick off the LOCKED rule again
764 modify($operation) {};
768 // Its not finished yet (i.e. expecting more Response objects)
770 // Or possibly it is a leftover response that we timed the request out previously
774 // We are going to retract these objects from memory
781 * The problem with Responses is that they don't have a controlLoopControlName
782 * field in them, so the only way to attach them is via RequestID. If we have multiple
783 * control loop .drl's loaded in the same container, we need to be sure the cleanup
784 * rules don't remove Responses for other control loops.
787 rule "${policyName}.APPC.RESPONSE.CLEANUP"
789 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
790 $response : Response($id : getCommonHeader().RequestID )
791 not ( ATTControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), requestID == $id, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) )
796 Logger.info("------------------------------------------------------------------------------------------------");
797 Logger.metrics(Instant.now() + " " + drools.getRule().getName() + " " + drools.getRule().getPackage());
798 Logger.metrics($params);
806 * This is the timer that manages the timeout for an individual operation.
809 rule "${policyName}.EVENT.MANAGER.OPERATION.TIMEOUT"
812 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
813 $event : ATTControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() )
814 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID )
815 $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID )
816 $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString(), $to : getDelay() )
817 $lock : TargetLock (requestID == $event.requestID)
822 Logger.info("------------------------------------------------------------------------------------------------");
823 Logger.metrics(Instant.now() + " " + drools.getRule().getName() + " " + drools.getRule().getPackage());
824 Logger.metrics($params);
825 Logger.metrics($manager);
826 Logger.metrics($operation);
827 Logger.metrics($opTimer);
828 Logger.metrics($lock);
830 // Tell it its timed out
832 $operation.setOperationHasTimedOut();
834 // Create a notification for it ("DB Write - end operation")
836 ATTControlLoopNotification notification = new ATTControlLoopNotification($event);
837 notification.from = "policy";
838 notification.policyName = drools.getRule().getName();
839 notification.policyScope = "${policyScope}";
840 notification.policyVersion = "${policyVersion}";
841 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
842 notification.message = $operation.getOperationHistory();
843 notification.history = $operation.getHistory();
845 // Let interested parties know
847 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
849 // Get rid of the timer
853 // Ensure the operation is complete
855 if ($operation.isOperationComplete() == true) {
857 // It is complete, remove it from memory
861 // Complete the operation
863 modify($manager) {finishOperation($operation)};
866 // Just doing this will kick off the LOCKED rule again
868 modify($operation) {};
874 * This is the timer that manages the overall control loop timeout.
877 rule "${policyName}.EVENT.MANAGER.TIMEOUT"
880 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
881 $event : ATTControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() )
882 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID )
883 $clTimer : ControlLoopTimer ( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString(), $to : getDelay() )
884 $operations : LinkedList()
885 from collect( ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID ) )
886 $opTimers : LinkedList()
887 from collect( OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() ) )
888 $locks : LinkedList()
889 from collect( TargetLock (requestID == $event.requestID) )
894 Logger.info("------------------------------------------------------------------------------------------------");
895 Logger.metrics(Instant.now() + " " + drools.getRule().getName() + " " + drools.getRule().getPackage());
896 Logger.metrics($params);
897 Logger.metrics($manager);
898 Logger.metrics($clTimer);
899 if ($operations == null) {
900 Logger.info("no operations found");
902 Logger.info("found " + $operations.size() + " operations");
905 // Tell the Event Manager it has timed out
907 VirtualControlLoopNotification notification = $manager.setControlLoopTimedOut();
908 if (notification != null) {
909 notification.from = "policy";
910 notification.policyName = drools.getRule().getName();
911 notification.policyScope = "${policyScope}";
912 notification.policyVersion = "${policyVersion}";
914 // Let interested parties know
916 Engine.deliver("UEB", "POLICY-CL-MGT", notification);
919 // Retract EVERYTHING
924 if ($operations != null && $operations.size() > 0) {
925 Iterator<ControlLoopOperationManager> iter = $operations.iterator();
926 while (iter.hasNext()) {
927 ControlLoopOperationManager manager = iter.next();
931 if ($opTimers != null && $opTimers.size() > 0) {
932 Iterator<OperationTimer> iter = $opTimers.iterator();
933 while (iter.hasNext()) {
934 OperationTimer opTimer = iter.next();
938 if ($locks != null && $locks.size() > 0) {
939 Iterator<TargetLock> iter = $locks.iterator();
940 while (iter.hasNext()) {
941 TargetLock lock = iter.next();
943 // Ensure we release the lock
945 PolicyGuard.unlockTarget(lock);