2  * ============LICENSE_START=======================================================
 
   3  * archetype-closed-loop-demo-rules
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 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;
 
  23 import java.util.List;
 
  24 import java.util.LinkedList;
 
  26 import java.util.HashMap;
 
  27 import java.util.UUID;
 
  29 import org.onap.policy.controlloop.VirtualControlLoopEvent;
 
  30 import org.onap.policy.controlloop.ControlLoopEventStatus;
 
  31 import org.onap.policy.controlloop.VirtualControlLoopNotification;
 
  32 import org.onap.policy.controlloop.ControlLoopNotificationType;
 
  33 import org.onap.policy.controlloop.ControlLoopOperation;
 
  34 import org.onap.policy.controlloop.ControlLoopOperationWrapper;
 
  35 import org.onap.policy.controlloop.ControlLoopException;
 
  37 import org.onap.policy.aai.AAINQF199.AAINQF199CloudRegion;
 
  38 import org.onap.policy.aai.AAINQF199.AAINQF199ExtraProperties;
 
  39 import org.onap.policy.aai.AAINQF199.AAINQF199ExtraProperty;
 
  40 import org.onap.policy.aai.AAINQF199.AAINQF199GenericVNF;
 
  41 import org.onap.policy.aai.AAINQF199.AAINQF199InstanceFilters;
 
  42 import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItem;
 
  43 import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItems;
 
  44 import org.onap.policy.aai.AAINQF199.AAINQF199Manager;
 
  45 import org.onap.policy.aai.AAINQF199.AAINQF199NamedQuery;
 
  46 import org.onap.policy.aai.AAINQF199.AAINQF199QueryParameters;
 
  47 import org.onap.policy.aai.AAINQF199.AAINQF199Request;
 
  48 import org.onap.policy.aai.AAINQF199.AAINQF199RequestWrapper;
 
  49 import org.onap.policy.aai.AAINQF199.AAINQF199Response;
 
  50 import org.onap.policy.aai.AAINQF199.AAINQF199ResponseWrapper;
 
  51 import org.onap.policy.aai.AAINQF199.AAINQF199ServiceInstance;
 
  52 import org.onap.policy.aai.AAINQF199.AAINQF199Tenant;
 
  53 import org.onap.policy.aai.AAINQF199.AAINQF199VfModule;
 
  54 import org.onap.policy.aai.AAINQF199.AAINQF199VServer;
 
  55 import org.onap.policy.aai.util.Serialization;
 
  57 import org.onap.policy.appc.CommonHeader;
 
  58 import org.onap.policy.appc.Request;
 
  59 import org.onap.policy.appc.Response;
 
  60 import org.onap.policy.appc.ResponseCode;
 
  61 import org.onap.policy.appc.ResponseStatus;
 
  62 import org.onap.policy.appc.ResponseValue;
 
  64 import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager;
 
  65 import org.onap.policy.vnf.trafficgenerator.PGRequest;
 
  66 import org.onap.policy.vnf.trafficgenerator.PGStream;
 
  67 import org.onap.policy.vnf.trafficgenerator.PGStreams;
 
  69 import org.onap.policy.mso.MSOManager;
 
  70 import org.onap.policy.mso.MSORequest;
 
  71 import org.onap.policy.mso.MSORequestStatus;
 
  72 import org.onap.policy.mso.MSORequestDetails;
 
  73 import org.onap.policy.mso.MSOModelInfo;
 
  74 import org.onap.policy.mso.MSOCloudConfiguration;
 
  75 import org.onap.policy.mso.MSORequestInfo;
 
  76 import org.onap.policy.mso.MSORequestParameters;
 
  77 import org.onap.policy.mso.MSORelatedInstanceListElement;
 
  78 import org.onap.policy.mso.MSORelatedInstance;
 
  79 import org.onap.policy.mso.MSOResponse;
 
  81 import org.onap.policy.drools.system.PolicyEngine;
 
  84 // These parameters are required to build the runtime policy
 
  87     closedLoopControlName : String
 
  95     aaiNamedQueryUUID : String
 
  97     notificationTopic : String
 
 103 * Called once and only once to insert the parameters into working memory for this Closed Loop policy.
 
 104 * NOTE:  If this file is to be used as a template to be used with the policy BRMS GW, please comment out this line 
 
 105 * as the BRMS_GW already generates a SETUP rule
 
 108 rule "${policyName}.SETUP"
 
 111                 System.out.println("rule SETUP is triggered.");
 
 112                 Params params = new Params();
 
 113                 params.setClosedLoopControlName("${closedLoopControlName}");
 
 114                 params.setActor("${actor}");
 
 115                 params.setAaiURL("${aaiURL}");
 
 116                 params.setAaiUsername("${aaiUsername}");
 
 117                 params.setAaiPassword("${aaiPassword}");
 
 118                 params.setMsoURL("${msoURL}");
 
 119                 params.setMsoUsername("${msoUsername}");
 
 120                 params.setMsoPassword("${msoPassword}");
 
 121                 params.setAaiNamedQueryUUID("${aaiNamedQueryUUID}");
 
 122                 params.setAaiPatternMatch(${aaiPatternMatch});
 
 123                 params.setNotificationTopic("${notificationTopic}");
 
 124                 params.setAppcTopic("${appcTopic}");
 
 126                 // This stays in memory as long as the rule is alive and running
 
 134 * This rule responds to DCAE Events
 
 137 rule "${policyName}.EVENT"
 
 139         $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
 
 140         $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
 
 141         not ( ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ))
 
 143                 System.out.println("rule EVENT is triggered.");
 
 146                         // Check the requestID in the event to make sure it is not null before we create the EventManager. 
 
 147                         // The EventManager will do extra syntax checking as well check if the closed loop is disabled/
 
 149                         if ($event.requestID == null) {
 
 150                                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
 
 151                                 notification.notification = ControlLoopNotificationType.REJECTED;
 
 152                                 notification.from = "policy";
 
 153                                 notification.message = "Missing requestID from DCAE event";
 
 154                                 notification.policyName = drools.getRule().getName();
 
 155                                 notification.policyScope = "${policyScope}";
 
 156                                 notification.policyVersion = "${policyVersion}";
 
 158                                 // Let interested parties know
 
 161                                         System.out.println(Serialization.gsonPretty.toJson(notification));
 
 162                                         PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 163                                 } catch (Exception e) {
 
 165                                         System.out.println("Can't deliver notification: " + notification);
 
 168                                 // Retract it from memory
 
 171                                 System.out.println("Event with requestID=null has been retracted.");
 
 174                                 // Create an EventManager
 
 176                                 ControlLoopEventManager manager = new ControlLoopEventManager($params.getClosedLoopControlName(), $event.requestID);
 
 178                                 // Determine if EventManager can actively process the event (i.e. syntax)
 
 180                                 VirtualControlLoopNotification notification = manager.activate($event);
 
 181                                 notification.from = "policy"; 
 
 182                                 notification.policyName = drools.getRule().getName();
 
 183                                 notification.policyScope = "${policyScope}";
 
 184                                 notification.policyVersion = "${policyVersion}";
 
 186                                 // Are we actively pursuing this event?
 
 188                                 if (notification.notification == ControlLoopNotificationType.ACTIVE) {
 
 190                                         // Insert Event Manager into memory, this will now kick off processing.
 
 194                                         // Let interested parties know
 
 197                                                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 198                                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 199                                         } catch (Exception e) {
 
 201                                                 System.out.println("Can't deliver notification: " + notification);
 
 205                                         // Let interested parties know
 
 208                                                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 209                                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 210                                         } catch (Exception e) {
 
 212                                                 System.out.println("Can't deliver notification: " + notification);
 
 215                                         // Retract it from memory
 
 220                                 // Now that the manager is inserted into Drools working memory, we'll wait for
 
 221                                 // another rule to fire in order to continue processing. This way we can also
 
 222                                 // then screen for additional ONSET and ABATED events for this same RequestIDs 
 
 223                                 // and for different RequestIDs but with the same closedLoopControlName and target.
 
 227                 } catch (Exception e) {
 
 229                         VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
 
 230                         notification.notification = ControlLoopNotificationType.REJECTED;
 
 231                         notification.message = "Exception occurred " + e.getMessage();
 
 232                         notification.policyName = drools.getRule().getName();
 
 233                         notification.policyScope = "${policyScope}";
 
 234                         notification.policyVersion = "${policyVersion}";
 
 239                                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 240                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 241                         } catch (Exception e1) {
 
 242                                 System.out.println("Can't deliver notification: " + notification);
 
 243                                 e1.printStackTrace();
 
 254 * This rule happens when we got a valid ONSET, closed loop is enabled and an Event Manager
 
 255 * is created. We can start the operations for this closed loop.
 
 258 rule "${policyName}.EVENT.MANAGER"
 
 260                 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
 
 261                 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
 
 262                 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, controlLoopResult == null)
 
 264                 System.out.println("rule EVENT.MANAGER is triggered.");
 
 266                 // Check which event this is.
 
 268                 ControlLoopEventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event);
 
 270                 // We only want the initial ONSET event in memory,
 
 271                 // all the other events need to be retracted to support
 
 272                 // cleanup and avoid the other rules being fired for this event.
 
 274                 if (eventStatus != ControlLoopEventManager.NEW_EVENT_STATUS.FIRST_ONSET) {
 
 275                         System.out.println("Retracting "+eventStatus+" Event.");
 
 280                 // Now the event in memory is first onset event
 
 284                         // Pull the known AAI field from the Event
 
 286                         // generic-vnf is needed for vFirewall case
 
 287                         // vserver-name is needed for vLoadBalancer case
 
 289                         String genericVNF = $event.AAI.get("generic-vnf.vnf-id");
 
 290                         String vserver = $event.AAI.get("vserver.vserver-name");
 
 292                         // Check if we are implementing a simple pattern match.
 
 294                         if ($params.getAaiPatternMatch() == 1) {
 
 298                                 //Basic naming characteristics:
 
 299                                 //VF Name (9 char)+VM name (13 char total)+VFC (19 char total)
 
 301                                 //VF Name (9 characters):    cscf0001v
 
 302                                 //VM Name(13 characters): cscf0001vm001
 
 303                                 //VFC name(19 characters): cscf0001vm001cfg001
 
 305                                 // zdfw1fwl01fwl02 or zdfw1fwl01fwl01  
 
 307                                 // zdfw1fwl01pgn02 or zdfw1fwl01pgn01
 
 309                                 int index = genericVNF.lastIndexOf("fwl");
 
 311                                         System.err.println("The generic-vnf.vnf-id from DCAE Event is not valid.");
 
 313                                         genericVNF = genericVNF.substring(0, index) + "pgn" + genericVNF.substring(index+"fwl".length());
 
 316                                 // Construct an APPC request
 
 318                                 ControlLoopOperation operation = new ControlLoopOperation();
 
 319                                 operation.actor = $params.getActor();
 
 320                                 operation.operation = "ModifyConfig";
 
 321                                 operation.target = $event.target;
 
 323                                 // Create operationWrapper
 
 325                                 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
 
 327                                 // insert operationWrapper into memory
 
 329                                 insert(operationWrapper);
 
 331                                 Request request = new Request();
 
 332                                 request.CommonHeader = new CommonHeader();
 
 333                                 request.CommonHeader.RequestID = $event.requestID;
 
 334                                 request.Action = operation.operation;
 
 335                                 request.Payload = new HashMap<String, Object>();
 
 337                                 // Fill in the payload
 
 339                                 request.Payload.put("generic-vnf.vnf-id", genericVNF);
 
 341                                 PGRequest pgRequest = new PGRequest();
 
 342                                 pgRequest.pgStreams = new PGStreams();
 
 345                                 for(int i = 0; i < 5; i++){
 
 346                                         pgStream = new PGStream();
 
 347                                         pgStream.streamId = "fw_udp"+(i+1);
 
 348                                         pgStream.isEnabled = "true";
 
 349                                         pgRequest.pgStreams.pgStream.add(pgStream);
 
 351                                 request.Payload.put("pg-streams", pgRequest.pgStreams);
 
 353                                 if (request != null) {
 
 355                                         // Insert request into memory
 
 359                                         // Tell interested parties we are performing this Operation
 
 361                                         VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
 
 362                                         notification.notification = ControlLoopNotificationType.OPERATION;
 
 363                                         // message and history ??
 
 364                                         notification.from = "policy";
 
 365                                         notification.policyName = drools.getRule().getName();
 
 366                                         notification.policyScope = "${policyScope}";
 
 367                                         notification.policyVersion = "${policyVersion}";
 
 369                                                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 370                                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 371                                         } catch (Exception e) {
 
 372                                                 System.out.println("Can't deliver notification: " + notification);
 
 376                                         // Now send the operation request
 
 378                                         if (request instanceof Request) {
 
 380                                                         System.out.println("APPC request sent:");
 
 381                                                         System.out.println(Serialization.gsonPretty.toJson(request));
 
 382                                                         PolicyEngine.manager.deliver($params.getAppcTopic(), request);
 
 383                                                 } catch (Exception e) {
 
 385                                                         System.out.println("Can't deliver request: " + request);
 
 390                                         // what happens if it is null
 
 396                                 // create AAI named-query request with UUID started with "F199"
 
 398                                 AAINQF199Request aainqf199request = new AAINQF199Request();
 
 399                                 AAINQF199QueryParameters aainqf199queryparam = new AAINQF199QueryParameters();
 
 400                                 AAINQF199NamedQuery aainqf199namedquery = new AAINQF199NamedQuery();
 
 401                                 AAINQF199InstanceFilters aainqf199instancefilter = new AAINQF199InstanceFilters();
 
 405                                 aainqf199namedquery.namedQueryUUID = UUID.fromString($params.getAaiNamedQueryUUID()); 
 
 406                                 aainqf199queryparam.namedQuery = aainqf199namedquery;
 
 407                                 aainqf199request.queryParameters = aainqf199queryparam;
 
 411                                 Map aainqf199instancefiltermap = new HashMap();
 
 412                                 Map aainqf199instancefiltermapitem = new HashMap();
 
 413                                 aainqf199instancefiltermapitem.put("vserver-name", vserver); 
 
 414                                 aainqf199instancefiltermap.put("vserver", aainqf199instancefiltermapitem);
 
 415                                 aainqf199instancefilter.instanceFilter.add(aainqf199instancefiltermap);
 
 416                                 aainqf199request.instanceFilters = aainqf199instancefilter;
 
 418                                 // print aainqf199request for debug
 
 420                                 System.out.println("AAI Request sent:");
 
 421                                 System.out.println(Serialization.gsonPretty.toJson(aainqf199request));
 
 423                                 // Create AAINQF199RequestWrapper
 
 425                                 AAINQF199RequestWrapper aainqf199RequestWrapper = new AAINQF199RequestWrapper($event.requestID, aainqf199request);
 
 427                                 // insert aainqf199request into memory
 
 429                                 insert(aainqf199RequestWrapper);
 
 432                 } catch (Exception e) {
 
 439 * This rule happens when we got a valid ONSET, closed loop is enabled, an Event Manager
 
 440 * is created, AAI Manager and AAI Request are ready in memory. We can start sending query to AAI and then wait for response.
 
 443 rule "${policyName}.EVENT.MANAGER.AAINQF199REQUEST"
 
 445                 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
 
 446                 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
 
 447                 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
 
 448                 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
 
 450                 System.out.println("rule EVENT.MANAGER.AAINQF199REQUEST is triggered.");
 
 454                 AAINQF199Response aainqf199response = AAINQF199Manager.postQuery($params.getAaiURL(), $params.getAaiUsername(), $params.getAaiPassword(),
 
 455                                                                                                            $aainqf199RequestWrapper.aainqf199request, $event.requestID);
 
 458                 // Check AAI response
 
 460                 if (aainqf199response == null) {
 
 461                         System.err.println("Failed to get AAI response");
 
 463                         // Fail and retract everything
 
 467                         retract($aainqf199RequestWrapper);
 
 470                         // Create AAINQF199ResponseWrapper
 
 472                         AAINQF199ResponseWrapper aainqf199ResponseWrapper = new AAINQF199ResponseWrapper($event.requestID, aainqf199response);
 
 474                         // insert aainqf199ResponseWrapper to memeory
 
 476                         insert(aainqf199ResponseWrapper);
 
 482 * This rule happens when we got a valid AAI response. We can start sending request to APPC or MSO now.
 
 485 rule "${policyName}.EVENT.MANAGER.AAINQF199RESPONSE"
 
 487                 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
 
 488                 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
 
 489                 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
 
 490                 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
 
 491                 $aainqf199ResponseWrapper : AAINQF199ResponseWrapper(requestID == $event.requestID)
 
 493                 System.out.println("rule EVENT.MANAGER.AAINQF199RESPONSE is triggered.");
 
 495                 // Extract related fields out of AAINQF199RESPONSE
 
 497                 String vnfItemVnfId, vnfItemVnfType, vnfItemPersonaModelId, vnfItemPersonaModelVersion, vnfItemModelName, 
 
 498                        vnfItemModelVersion, vnfItemModelNameVersionId, serviceItemServiceInstanceId, serviceItemPersonaModelId,
 
 499                        serviceItemModelName, serviceItemModelType, serviceItemModelVersion, serviceItemModelNameVersionId,
 
 500                        vfModuleItemVfModuleName, vfModuleItemPersonaModelId, vfModuleItemPersonaModelVersion, vfModuleItemModelName, 
 
 501                        vfModuleItemModelNameVersionId, tenantItemTenantId, cloudRegionItemCloudRegionId;
 
 506                         vnfItemVnfId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfID;
 
 507                         vnfItemVnfType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfType;
 
 508                         vnfItemVnfType = vnfItemVnfType.substring(vnfItemVnfType.lastIndexOf("/")+1);
 
 509                         vnfItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelId;
 
 510                         vnfItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelVersion;
 
 511                         vnfItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
 
 512                         vnfItemModelVersion =           $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(2).propertyValue;
 
 513                         vnfItemModelNameVersionId =     $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
 
 517                         serviceItemServiceInstanceId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.serviceInstanceID;
 
 518                         serviceItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelId;
 
 519                         serviceItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
 
 520                         serviceItemModelType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(1).propertyValue;
 
 521                         serviceItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelVersion;
 
 522                         serviceItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
 
 524                         // Find the index for base vf module and non-base vf module
 
 527                         int nonBaseIndex = -1;
 
 528                         List<AAINQF199InventoryResponseItem> inventoryItems = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems;
 
 529                         for (AAINQF199InventoryResponseItem m : inventoryItems) {
 
 530                                 if (m.vfModule != null && m.vfModule.isBaseVfModule == true) {
 
 531                                         baseIndex = inventoryItems.indexOf(m);
 
 532                                 } else if (m.vfModule != null && m.vfModule.isBaseVfModule == false && m.vfModule.orchestrationStatus == null) {
 
 533                                         nonBaseIndex = inventoryItems.indexOf(m);
 
 536                                 if (baseIndex != -1 && nonBaseIndex != -1) {
 
 541                         // Report the error if either base vf module or non-base vf module is not found
 
 543                         if (baseIndex == -1 || nonBaseIndex == -1) {
 
 544                                 System.err.println("Either base or non-base vf module is not found from AAI response.");
 
 545                                 retract($aainqf199RequestWrapper);
 
 546                                 retract($aainqf199ResponseWrapper);
 
 552                         // This comes from the base module
 
 554                         vfModuleItemVfModuleName =                      $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(baseIndex).vfModule.vfModuleName;
 
 555                         vfModuleItemVfModuleName = vfModuleItemVfModuleName.replace("Vfmodule", "vDNS");
 
 557                         // vfModuleItem - NOT the base module
 
 559                         vfModuleItemPersonaModelId =            $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelId;
 
 560                         vfModuleItemPersonaModelVersion =       $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelVersion;
 
 561                         vfModuleItemModelName =                         $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(0).propertyValue;
 
 562                         vfModuleItemModelNameVersionId =        $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(4).propertyValue;
 
 566                         tenantItemTenantId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).tenant.tenantId;
 
 570                         cloudRegionItemCloudRegionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).items.inventoryResponseItems.get(0).cloudRegion.cloudRegionId;
 
 572                 } catch (Exception e) {
 
 574                         VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
 
 575                         notification.notification = ControlLoopNotificationType.REJECTED;
 
 576                         notification.message = "Exception occurred " + e.getMessage();
 
 577                         notification.policyName = drools.getRule().getName();
 
 578                         notification.policyScope = "${policyScope}";
 
 579                         notification.policyVersion = "${policyVersion}";
 
 582                                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 583                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 584                         } catch (Exception e1) {
 
 585                                 System.out.println("Can't deliver notification: " + notification);
 
 586                                 e1.printStackTrace();
 
 589                         notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
 
 590                         notification.message = "Invalid named-query response from AAI";
 
 593                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 594                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 595             } catch (Exception e1) {
 
 596                 System.out.println("Can't deliver notification: " + notification);
 
 597                 e1.printStackTrace();
 
 600                         // Retract everything
 
 602                         retract($aainqf199RequestWrapper);
 
 603                         retract($aainqf199ResponseWrapper);
 
 609                 // Extracted fields should not be null
 
 611                 if ((vnfItemVnfId == null) || (vnfItemVnfType == null) ||
 
 612                     (vnfItemPersonaModelId == null) || (vnfItemModelName == null) ||
 
 613                     (vnfItemModelVersion == null) || (vnfItemModelNameVersionId == null) ||
 
 614                     (serviceItemServiceInstanceId == null) || (serviceItemModelName == null) ||
 
 615                     (serviceItemModelType == null) || (serviceItemModelVersion == null) ||
 
 616                     (serviceItemModelNameVersionId == null) || (vfModuleItemVfModuleName == null) ||
 
 617                     (vfModuleItemPersonaModelId == null) || (vfModuleItemPersonaModelVersion == null) ||
 
 618                     (vfModuleItemModelName == null) || (vfModuleItemModelNameVersionId == null) ||
 
 619                     (tenantItemTenantId == null) || (cloudRegionItemCloudRegionId == null)) {
 
 621                         System.err.println("some fields are missing from AAI response.");
 
 623                         // Fail and retract everything
 
 625                         retract($aainqf199RequestWrapper);
 
 626                         retract($aainqf199ResponseWrapper);
 
 632                 // We don't need them any more
 
 634                 retract($aainqf199ResponseWrapper);
 
 635                 retract($aainqf199RequestWrapper);  
 
 637                 // check the actor of this closed loop
 
 639                 switch ($params.getActor()) {
 
 643                                 // Construct an APPC request
 
 645                                 ControlLoopOperation operation = new ControlLoopOperation();
 
 646                                 operation.actor = $params.getActor();
 
 647                                 operation.operation = "ModifyConfig";
 
 648                                 operation.target = $event.target;
 
 650                                 // Create operationWrapper
 
 652                                 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
 
 654                                 // insert operationWrapper into memory
 
 656                                 insert(operationWrapper);
 
 658                                 Request request = new Request();
 
 659                                 request.CommonHeader = new CommonHeader();
 
 660                                 request.CommonHeader.RequestID = $event.requestID;
 
 661                                 request.Action = operation.operation;
 
 662                                 request.Payload = new HashMap<String, Object>();
 
 664                                 // Fill in the payload
 
 665                                 // Hardcode genericVNF for now since AAI has not been ready for vFirewall demo case
 
 667                                 String genericVNF = "zdfw1fwl01pgn02";
 
 668                                 request.Payload.put("generic-vnf.vnf-id", genericVNF);
 
 670                                 PGRequest pgRequest = new PGRequest();
 
 671                                 pgRequest.pgStreams = new PGStreams();
 
 674                                 for(int i = 0; i < 5; i++){
 
 675                                         pgStream = new PGStream();
 
 676                                         pgStream.streamId = "fw_udp"+(i+1);
 
 677                                         pgStream.isEnabled = "true";
 
 678                                         pgRequest.pgStreams.pgStream.add(pgStream);
 
 680                                 request.Payload.put("pg-streams", pgRequest.pgStreams);
 
 682                                 if (request != null) {
 
 684                                         // Insert request into memory
 
 688                                         // Tell interested parties we are performing this Operation
 
 690                                         VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
 
 691                                         notification.notification = ControlLoopNotificationType.OPERATION;
 
 692                                         // message and history ??
 
 693                                         notification.from = "policy";
 
 694                                         notification.policyName = drools.getRule().getName();
 
 695                                         notification.policyScope = "${policyScope}";
 
 696                                         notification.policyVersion = "${policyVersion}";
 
 698                                                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 699                                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 700                                         } catch (Exception e) {
 
 701                                                 System.out.println("Can't deliver notification: " + notification);
 
 705                                         // Now send the operation request
 
 707                                         if (request instanceof Request) {
 
 709                                                         System.out.println("APPC request sent:");
 
 710                                                         System.out.println(Serialization.gsonPretty.toJson(request));
 
 711                                                         PolicyEngine.manager.deliver($params.getAppcTopic(), request);
 
 712                                                 } catch (Exception e) {
 
 714                                                         System.out.println("Can't deliver request: " + request);
 
 719                                         // what happens if it is null
 
 727                                 // Construct an operation
 
 729                                 ControlLoopOperation operation = new ControlLoopOperation();
 
 730                                 operation.actor = $params.getActor();
 
 731                                 operation.operation = "createModuleInstance";
 
 732                                 operation.target = $event.target;
 
 734                                 // Create operationWrapper
 
 736                                 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
 
 738                                 // Construct an MSO request
 
 740                                 MSORequest request = new MSORequest();
 
 741                                 request.requestDetails = new MSORequestDetails();
 
 742                                 request.requestDetails.modelInfo = new MSOModelInfo();
 
 743                                 request.requestDetails.cloudConfiguration = new MSOCloudConfiguration();
 
 744                                 request.requestDetails.requestInfo = new MSORequestInfo();
 
 745                                 request.requestDetails.requestParameters = new MSORequestParameters();
 
 746                                 request.requestDetails.requestParameters.userParams = null;
 
 748                                 // cloudConfiguration
 
 750                                 request.requestDetails.cloudConfiguration.lcpCloudRegionId = cloudRegionItemCloudRegionId;
 
 751                                 request.requestDetails.cloudConfiguration.tenantId = tenantItemTenantId;
 
 755                                 request.requestDetails.modelInfo.modelType = "vfModule";
 
 756                                 request.requestDetails.modelInfo.modelInvariantId = vfModuleItemPersonaModelId;
 
 757                                 request.requestDetails.modelInfo.modelNameVersionId = vfModuleItemModelNameVersionId;
 
 758                                 request.requestDetails.modelInfo.modelName = vfModuleItemModelName;
 
 759                                 request.requestDetails.modelInfo.modelVersion = vfModuleItemPersonaModelVersion;
 
 763                                 request.requestDetails.requestInfo.instanceName = vfModuleItemVfModuleName;
 
 764                                 request.requestDetails.requestInfo.source = "POLICY";
 
 765                                 request.requestDetails.requestInfo.suppressRollback = false;
 
 767                                 // relatedInstanceList
 
 769                                 MSORelatedInstanceListElement relatedInstanceListElement1 = new MSORelatedInstanceListElement();
 
 770                                 MSORelatedInstanceListElement relatedInstanceListElement2 = new MSORelatedInstanceListElement();
 
 771                                 relatedInstanceListElement1.relatedInstance = new MSORelatedInstance();
 
 772                                 relatedInstanceListElement2.relatedInstance = new MSORelatedInstance();
 
 774                                 relatedInstanceListElement1.relatedInstance.instanceId = serviceItemServiceInstanceId;
 
 775                                 relatedInstanceListElement1.relatedInstance.modelInfo = new MSOModelInfo();
 
 776                                 relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service";
 
 777                                 relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = serviceItemPersonaModelId;
 
 778                                 relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = serviceItemModelNameVersionId;
 
 779                                 relatedInstanceListElement1.relatedInstance.modelInfo.modelName = serviceItemModelName;
 
 780                                 relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = serviceItemModelVersion;
 
 782                                 relatedInstanceListElement2.relatedInstance.instanceId = vnfItemVnfId;
 
 783                                 relatedInstanceListElement2.relatedInstance.modelInfo = new MSOModelInfo();
 
 784                                 relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf";
 
 785                                 relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = vnfItemPersonaModelId;
 
 786                                 relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = vnfItemModelNameVersionId;
 
 787                                 relatedInstanceListElement2.relatedInstance.modelInfo.modelName = vnfItemModelName;
 
 788                                 relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = vnfItemModelVersion;
 
 789                                 relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = vnfItemVnfType;
 
 791                                 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1);
 
 792                                 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2);
 
 794                                 // print MSO request for debug
 
 796                                 System.out.println("MSO request sent:");
 
 797                                 System.out.println(Serialization.gsonPretty.toJson(request));
 
 801                                 if (request != null) {
 
 803                                         // Tell interested parties we are performing this Operation
 
 805                                         VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
 
 806                                         notification.notification = ControlLoopNotificationType.OPERATION;
 
 807                                         notification.from = "policy";
 
 808                                         notification.policyName = drools.getRule().getName();
 
 809                                         notification.policyScope = "${policyScope}";
 
 810                                         notification.policyVersion = "${policyVersion}";
 
 812                                                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 813                                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 814                                         } catch (Exception e) {
 
 815                                                 System.out.println("Can't deliver notification: " + notification);
 
 819                                         // Concatenate serviceItemServiceInstanceId and vnfItemVnfId to msoURL
 
 821                                         String MSOUrl = $params.getMsoURL() + "/serviceInstances/v2/" + serviceItemServiceInstanceId + "/vnfs/" + vnfItemVnfId + "/vfModules";
 
 825                                         MSOResponse response = MSOManager.createModuleInstance(MSOUrl, $params.getMsoURL(), $params.getMsoUsername(), $params.getMsoPassword(), request);
 
 828                                         if (response != null) {
 
 832                                                 request.requestId = $event.requestID.toString();                                                
 
 833                                                 response.request.requestId = $event.requestID.toString();
 
 837                                                 insert(operationWrapper);
 
 842                                                 // MSO request not even accepted
 
 844                                                 notification.message = operationWrapper.operation.toMessage();
 
 845                                                 operationWrapper.operation.message = operationWrapper.operation.toMessage();
 
 846                                                 operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
 
 847                                                 $manager.setControlLoopResult("FAILURE_EXCEPTION");
 
 848                                                 notification.history.add(operationWrapper.operation);
 
 849                                                 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
 
 851                                                 // Let interested parties know
 
 854                                                         System.out.println(Serialization.gsonPretty.toJson(notification));
 
 855                                                         PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 856                                                 } catch (Exception e) {
 
 857                                                         System.out.println("Can't deliver notification: " + notification);
 
 860                             notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
 
 862                                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 863                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 864                         } catch (Exception e) {
 
 865                                 System.out.println("Can't deliver notification: " + notification);
 
 869                                                 // Retract everything
 
 875                                         System.err.println("constructed MSO request is invalid.");
 
 884 * This rule responds to APPC Response Events
 
 887 rule "${policyName}.APPC.RESPONSE"
 
 889                 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
 
 890                 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
 
 891                 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
 
 892                 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
 
 893                 $request : Request( getCommonHeader().RequestID == $event.requestID )
 
 894                 $response : Response( getCommonHeader().RequestID == $event.requestID ) 
 
 896                 System.out.println("rule APPC.RESPONSE is triggered.");
 
 897                 if ($response.Status == null) {
 
 898                         $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
 
 899                         $manager.setControlLoopResult("FAILURE_EXCEPTION");
 
 902                 // Get the Response Code
 
 904                 ResponseCode code = ResponseCode.toResponseCode($response.Status.Code);
 
 906                         $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
 
 907                         $manager.setControlLoopResult("FAILURE_EXCEPTION");
 
 910                 // Construct notification
 
 912                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
 
 913                 notification.from = "policy";
 
 914                 notification.policyName = drools.getRule().getName();
 
 915                 notification.policyScope = "${policyScope}";
 
 916                 notification.policyVersion = "${policyVersion}";
 
 917                 notification.message = $operationWrapper.operation.toMessage();
 
 918                 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
 
 920                 // Ok, let's figure out what APP-C's response is
 
 924                                 $operationWrapper.operation.outcome = "PROCESSING";
 
 928                                 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
 
 929                                 $manager.setControlLoopResult("FAILURE_EXCEPTION");
 
 932                                 $operationWrapper.operation.outcome = "SUCCESS";
 
 933                                 $manager.setControlLoopResult("SUCCESS");
 
 936                                 $operationWrapper.operation.outcome = "FAILURE";
 
 937                                 $manager.setControlLoopResult("FAILURE");
 
 940                 if ($operationWrapper.operation.outcome.equals("SUCCESS")) {
 
 941                         notification.history.add($operationWrapper.operation);
 
 942                         notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
 
 944                         // Let interested parties know
 
 947                                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 948                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 949                         } catch (Exception e) {
 
 950                                 System.out.println("Can't deliver notification: " + notification);
 
 953             notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
 
 955                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 956                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 957             } catch (Exception e) {
 
 958                 System.out.println("Can't deliver notification: " + notification);
 
 963                         // We are going to retract these objects from memory
 
 965                         System.out.println("Retracting everything");
 
 966                         retract($operationWrapper);
 
 971                 } else if ($operationWrapper.operation.outcome.equals("PROCESSING")) {
 
 974                         notification.history.add($operationWrapper.operation);
 
 975                         notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
 
 977                         // Let interested parties know
 
 980                                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 981                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 982                         } catch (Exception e) {
 
 983                                 System.out.println("Can't deliver notification: " + notification);
 
 986             notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
 
 988             // Let interested parties know
 
 991                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
 992                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
 993             } catch (Exception e) {
 
 994                 System.out.println("Can't deliver notification: " + notification);
 
 998                         // We are going to retract these objects from memory
 
1000                         System.out.println("Retracting everything");
 
1001                         retract($operationWrapper);
 
1012 * This rule is used to clean up APPC response
 
1015 rule "${policyName}.APPC.RESPONSE.CLEANUP"
 
1017                 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
 
1018         $response : Response($id : getCommonHeader().RequestID )
 
1019                 not ( VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), requestID == $id, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) ) 
 
1021                 System.out.println("rule APPC.RESPONSE.CLEANUP is triggered.");
 
1027 * This rule responds to MSO Response Events
 
1030 rule "${policyName}.MSO.RESPONSE"
 
1032                 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
 
1033                 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
 
1034                 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
 
1035                 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
 
1036                 $request : MSORequest( requestId == $event.requestID.toString() )
 
1037                 $response : MSOResponse( request.requestId == $event.requestID.toString() )     
 
1039                 System.out.println("rule MSO.RESPONSE is triggered.");
 
1041                 // Construct notification
 
1043                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
 
1044                 notification.from = "policy";
 
1045                 notification.policyName = drools.getRule().getName();
 
1046                 notification.policyScope = "${policyScope}";
 
1047                 notification.policyVersion = "${policyVersion}";
 
1048                 notification.message = $operationWrapper.operation.toMessage();
 
1049                 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
 
1051                 // The operation can either be succeeded or failed
 
1053                 if($response.request.requestStatus.requestState.equals("COMPLETE")) {
 
1054                         $operationWrapper.operation.outcome = "SUCCESS";
 
1055                         $manager.setControlLoopResult("SUCCESS");
 
1056                         notification.history.add($operationWrapper.operation);
 
1057                         notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
 
1059                         // Let interested parties know
 
1062                                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
1063                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
1064                         } catch (Exception e) {
 
1065                                 System.out.println("Can't deliver notification: " + notification);
 
1066                                 e.printStackTrace();
 
1068                         notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
 
1070             // Let interested parties know
 
1073                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
1074                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
1075             } catch (Exception e) {
 
1076                 System.out.println("Can't deliver notification: " + notification);
 
1077                 e.printStackTrace();
 
1080                         // We are going to retract these objects from memory
 
1082                         System.out.println("Retracting everything");
 
1083                         retract($operationWrapper);
 
1089                         $operationWrapper.operation.outcome = "FAILURE";
 
1090                         $manager.setControlLoopResult("FAILURE");
 
1091                         notification.history.add($operationWrapper.operation);
 
1092                         notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
 
1094                         // Let interested parties know
 
1097                                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
1098                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
1099                         } catch (Exception e) {
 
1100                                 System.out.println("Can't deliver notification: " + notification);
 
1101                                 e.printStackTrace();
 
1103                         notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
 
1105             // Let interested parties know
 
1108                 System.out.println(Serialization.gsonPretty.toJson(notification));
 
1109                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
 
1110             } catch (Exception e) {
 
1111                 System.out.println("Can't deliver notification: " + notification);
 
1112                 e.printStackTrace();
 
1115                         // We are going to retract these objects from memory
 
1117                         System.out.println("Retracting everything");
 
1118                         retract($operationWrapper);
 
1127  * Sample Queries for illustration with and without arguments
 
1128  * The results of the query can be introspected (and retracted if desired)
 
1131 query "${policyName}.QUERY.EVENT.ONSET"
 
1132         event : VirtualControlLoopEvent( closedLoopEventStatus == ControlLoopEventStatus.ONSET )
 
1135 query "${policyName}.QUERY.MANAGER.RNA" (String aRequestId, Integer numOnsetsLowerBound, Boolean aActivated)
 
1136         manager : ControlLoopEventManager( closedLoopControlName == "${closedLoopControlName}", 
 
1137                                 requestID.toString() == aRequestId, 
 
1138                                 numOnsets > numOnsetsLowerBound,
 
1139                                 activated == aActivated )