Initial OpenECOMP policy/engine commit
[policy/engine.git] / packages / base / src / files / install / servers / pap / webapps / Config / com.Config_BRMS_Param_BRMSParamvLBDemoPolicy.1.txt
1 /* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. 
2          <$%BRMSParamTemplate=ControlLoopDemo__closedLoopControlName%$> 
3  */ 
4
5
6 /*-
7  * ============LICENSE_START=======================================================
8  * archetype-closed-loop-demo-rules
9  * ================================================================================
10  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
11  * ================================================================================
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  * 
16  *      http://www.apache.org/licenses/LICENSE-2.0
17  * 
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.openecomp.policy.controlloop;
27
28 import java.util.LinkedList;
29 import java.util.Map;
30 import java.util.HashMap;
31 import java.util.UUID;
32
33 import org.openecomp.policy.controlloop.VirtualControlLoopEvent;
34 import org.openecomp.policy.controlloop.ControlLoopEventStatus;
35 import org.openecomp.policy.controlloop.VirtualControlLoopNotification;
36 import org.openecomp.policy.controlloop.ControlLoopNotificationType;
37 import org.openecomp.policy.controlloop.ControlLoopOperation;
38 import org.openecomp.policy.controlloop.ControlLoopOperationWrapper;
39 import org.openecomp.policy.template.demo.ControlLoopException;
40
41 import org.openecomp.policy.aai.AAINQF199.AAINQF199CloudRegion;
42 import org.openecomp.policy.aai.AAINQF199.AAINQF199ExtraProperties;
43 import org.openecomp.policy.aai.AAINQF199.AAINQF199ExtraProperty;
44 import org.openecomp.policy.aai.AAINQF199.AAINQF199GenericVNF;
45 import org.openecomp.policy.aai.AAINQF199.AAINQF199InstanceFilters;
46 import org.openecomp.policy.aai.AAINQF199.AAINQF199InventoryResponseItem;
47 import org.openecomp.policy.aai.AAINQF199.AAINQF199InventoryResponseItems;
48 import org.openecomp.policy.aai.AAINQF199.AAINQF199Manager;
49 import org.openecomp.policy.aai.AAINQF199.AAINQF199NamedQuery;
50 import org.openecomp.policy.aai.AAINQF199.AAINQF199QueryParameters;
51 import org.openecomp.policy.aai.AAINQF199.AAINQF199Request;
52 import org.openecomp.policy.aai.AAINQF199.AAINQF199RequestWrapper;
53 import org.openecomp.policy.aai.AAINQF199.AAINQF199Response;
54 import org.openecomp.policy.aai.AAINQF199.AAINQF199ResponseWrapper;
55 import org.openecomp.policy.aai.AAINQF199.AAINQF199ServiceInstance;
56 import org.openecomp.policy.aai.AAINQF199.AAINQF199Tenant;
57 import org.openecomp.policy.aai.AAINQF199.AAINQF199VfModule;
58 import org.openecomp.policy.aai.AAINQF199.AAINQF199VServer;
59 import org.openecomp.policy.aai.util.Serialization;
60
61 import org.openecomp.policy.appc.CommonHeader;
62 import org.openecomp.policy.appc.Request;
63 import org.openecomp.policy.appc.Response;
64 import org.openecomp.policy.appc.ResponseCode;
65 import org.openecomp.policy.appc.ResponseStatus;
66 import org.openecomp.policy.appc.ResponseValue;
67
68 import org.openecomp.policy.template.demo.EventManager;
69 import org.openecomp.policy.vnf.trafficgenerator.PGRequest;
70 import org.openecomp.policy.vnf.trafficgenerator.PGStream;
71 import org.openecomp.policy.vnf.trafficgenerator.PGStreams;
72
73 import org.openecomp.policy.mso.MSOManager;
74 import org.openecomp.policy.mso.MSORequest;
75 import org.openecomp.policy.mso.MSORequestStatus;
76 import org.openecomp.policy.mso.MSORequestDetails;
77 import org.openecomp.policy.mso.MSOModelInfo;
78 import org.openecomp.policy.mso.MSOCloudConfiguration;
79 import org.openecomp.policy.mso.MSORequestInfo;
80 import org.openecomp.policy.mso.MSORequestParameters;
81 import org.openecomp.policy.mso.MSORelatedInstanceListElement;
82 import org.openecomp.policy.mso.MSORelatedInstance;
83 import org.openecomp.policy.mso.MSOResponse;
84
85 import org.openecomp.policy.drools.system.PolicyEngine;
86
87 //
88 // These parameters are required to build the runtime policy
89 //
90 declare Params
91     closedLoopControlName : String
92     actor : String
93     aaiURL : String
94     aaiUsername : String
95     aaiPassword : String
96     msoURL : String
97     msoUsername : String
98     msoPassword : String
99     aaiNamedQueryUUID : String
100     aaiPatternMatch : int 
101     notificationTopic : String
102     appcTopic : String
103 end
104
105 /*
106 *
107 * Called once and only once to insert the parameters into working memory for this Closed Loop policy.
108 * (Comment SETUP rule out for the first ECOMP opensource release since policy BRMS_GW already puts a Params fact in there)
109 *
110 *
111 *rule "BRMSParamvLBDemoPolicy.SETUP"
112 *       when
113 *       then
114 *               System.out.println("rule SETUP is triggered.");
115 *               Params params = new Params();
116 *               params.setClosedLoopControlName("CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8");
117 *               params.setActor("MSO");
118 *               params.setAaiURL("https://aai.api.simpledemo.openecomp.org:8443");
119 *               params.setAaiUsername("POLICY");
120 *               params.setAaiPassword("POLICY");
121 *               params.setMsoURL("http://vm1.mso.simpledemo.openecomp.org:8080/ecomp/mso/infra");
122 *               params.setMsoUsername("InfraPortalClient");
123 *               params.setMsoPassword("password1$");
124 *               params.setAaiNamedQueryUUID("f199cb88-5e69-4b1f-93e0-6f257877d066");
125 *               params.setAaiPatternMatch(0);
126 *               params.setNotificationTopic("POLICY-CL-MGT");
127 *               params.setAppcTopic("APPC-CL");
128 *               //
129 *               // This stays in memory as long as the rule is alive and running
130 *               //
131 *               insert(params);
132 *end
133 */
134 /*
135 *
136 * This rule responds to DCAE Events
137 *
138 */
139 rule "BRMSParamvLBDemoPolicy.EVENT"
140         when
141         $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
142         $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
143         not ( EventManager( closedLoopControlName == $event.closedLoopControlName ))
144         then
145                 System.out.println("rule EVENT is triggered.");
146                 try {
147                         // 
148                         // Check the requestID in the event to make sure it is not null before we create the EventManager. 
149                         // The EventManager will do extra syntax checking as well check if the closed loop is disabled/
150                         //
151                         if ($event.requestID == null) {
152                                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
153                                 notification.notification = ControlLoopNotificationType.REJECTED;
154                                 notification.from = "policy";
155                                 notification.message = "Missing requestID from DCAE event";
156                                 notification.policyName = drools.getRule().getName();
157                                 notification.policyScope = "com";
158                                 notification.policyVersion = "1";
159                                 //
160                                 // Let interested parties know
161                                 //
162                                 try {
163                                         System.out.println(Serialization.gsonPretty.toJson(notification));
164                                         PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
165                                 } catch (Exception e) {
166                                         e.printStackTrace();
167                                         System.out.println("Can't deliver notification: " + notification);
168                                 }
169                                 //
170                                 // Retract it from memory
171                                 //
172                                 retract($event);
173                                 System.out.println("Event with requestID=null has been retracted.");
174                         } else {
175                                 //
176                                 // Create an EventManager
177                                 //
178                                 EventManager manager = new EventManager($params.getClosedLoopControlName(), $event.requestID, $event.target);
179                                 //
180                                 // Determine if EventManager can actively process the event (i.e. syntax)
181                                 //
182                                 VirtualControlLoopNotification notification = manager.activate($event);
183                                 notification.from = "policy"; 
184                                 notification.policyName = drools.getRule().getName();
185                                 notification.policyScope = "com";
186                                 notification.policyVersion = "1";
187                                 //
188                                 // Are we actively pursuing this event?
189                                 //
190                                 if (notification.notification == ControlLoopNotificationType.ACTIVE) {
191                                         //
192                                         // Insert Event Manager into memory, this will now kick off processing.
193                                         //
194                                         insert(manager);
195                                         //
196                                         // Let interested parties know
197                                         //
198                                         try {
199                                                 System.out.println(Serialization.gsonPretty.toJson(notification));
200                                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
201                                         } catch (Exception e) {
202                                                 e.printStackTrace();
203                                                 System.out.println("Can't deliver notification: " + notification);
204                                         }               
205                                 } else {
206                                         //
207                                         // Let interested parties know
208                                         //
209                                         try {
210                                                 System.out.println(Serialization.gsonPretty.toJson(notification));
211                                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
212                                         } catch (Exception e) {
213                                                 e.printStackTrace();
214                                                 System.out.println("Can't deliver notification: " + notification);
215                                         }
216                                         //
217                                         // Retract it from memory
218                                         //
219                                         retract($event);
220                                 }
221                                 //
222                                 // Now that the manager is inserted into Drools working memory, we'll wait for
223                                 // another rule to fire in order to continue processing. This way we can also
224                                 // then screen for additional ONSET and ABATED events for this same RequestIDs 
225                                 // and for different RequestIDs but with the same closedLoopControlName and target.
226                                 //
227                         }
228                 //
229                 } catch (Exception e) {
230                         e.printStackTrace();
231                         VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
232                         notification.notification = ControlLoopNotificationType.REJECTED;
233                         notification.message = "Exception occurred " + e.getMessage();
234                         notification.policyName = drools.getRule().getName();
235                         notification.policyScope = "com";
236                         notification.policyVersion = "1";
237                         //
238                         //
239                         //
240                         try {
241                                 System.out.println(Serialization.gsonPretty.toJson(notification));
242                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
243                         } catch (Exception e1) {
244                                 System.out.println("Can't deliver notification: " + notification);
245                                 e1.printStackTrace();
246                         }
247                         //
248                         // Retract the event
249                         //
250                         retract($event);
251                 }
252 end
253
254 /*
255 *
256 * This rule happens when we got a valid ONSET, closed loop is enabled and an Event Manager
257 * is created. We can start the operations for this closed loop.
258 *
259 */
260 rule "BRMSParamvLBDemoPolicy.EVENT.MANAGER"
261         when
262                 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
263                 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
264                 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName, controlLoopResult == null)
265         then
266                 System.out.println("rule EVENT.MANAGER is triggered.");
267                 //
268                 // Check which event this is.
269                 //
270                 EventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event);
271                 //
272                 // We only want the initial ONSET event in memory,
273                 // all the other events need to be retracted to support
274                 // cleanup and avoid the other rules being fired for this event.
275                 //
276                 if (eventStatus != EventManager.NEW_EVENT_STATUS.FIRST_ONSET) {
277                         System.out.println("Retracting "+eventStatus+" Event.");
278                         retract($event);
279                         return;
280                 }
281                 //
282                 // Now the event in memory is first onset event
283                 //
284                 try {
285                         //
286                         // Pull the known AAI field from the Event
287                         //
288                         // generic-vnf is needed for vFirewall case
289                         // vserver-name is needed for vLoadBalancer case
290                         //
291                         String genericVNF = $event.AAI.get("generic-vnf.vnf-id");
292                         String vserver = $event.AAI.get("vserver.vserver-name");
293                         //
294                         // Check if we are implementing a simple pattern match.
295                         //
296                         if ($params.getAaiPatternMatch() == 1) {
297                                 //
298                                 // Yes
299                                 //
300                                 //Basic naming characteristics:
301                                 //VF Name (9 char)+VM name (13 char total)+VFC (19 char total)
302                                 //Example: 
303                                 //VF Name (9 characters):    cscf0001v
304                                 //VM Name(13 characters): cscf0001vm001
305                                 //VFC name(19 characters): cscf0001vm001cfg001
306                                 //
307                                 // zdfw1fwl01fwl02 or zdfw1fwl01fwl01  
308                                 // replaced with
309                                 // zdfw1fwl01pgn02 or zdfw1fwl01pgn01
310                                 //
311                                 int index = genericVNF.lastIndexOf("fwl");
312                                 if (index == -1) {
313                                         System.err.println("The generic-vnf.vnf-id from DCAE Event is not valid.");
314                                 } else {
315                                         genericVNF = genericVNF.substring(0, index) + "pgn" + genericVNF.substring(index+"fwl".length());
316                                 }
317                                 //
318                                 // Construct an APPC request
319                                 //
320                                 ControlLoopOperation operation = new ControlLoopOperation();
321                                 operation.actor = $params.getActor();
322                                 operation.operation = "ModifyConfig";
323                                 operation.target = $event.target;
324                                 //
325                                 // Create operationWrapper
326                                 //
327                                 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
328                                 //
329                                 // insert operationWrapper into memory
330                                 //
331                                 insert(operationWrapper);
332                                 //
333                                 Request request = new Request();
334                                 request.CommonHeader = new CommonHeader();
335                                 request.CommonHeader.RequestID = $event.requestID;
336                                 request.Action = operation.operation;
337                                 request.Payload = new HashMap<String, Object>();
338                                 //
339                                 // Fill in the payload
340                                 //
341                                 request.Payload.put("generic-vnf.vnf-id", genericVNF);
342                                 //
343                                 PGRequest pgRequest = new PGRequest();
344                                 pgRequest.pgStreams = new PGStreams();
345                                 
346                                 PGStream pgStream;
347                                 for(int i = 0; i < 5; i++){
348                                         pgStream = new PGStream();
349                                         pgStream.streamId = "fw_udp"+(i+1);
350                                         pgStream.isEnabled = "true";
351                                         pgRequest.pgStreams.pgStream.add(pgStream);
352                                 }
353                                 request.Payload.put("pg-streams", pgRequest.pgStreams);
354                                 
355                                 if (request != null) {
356                                         //
357                                         // Insert request into memory
358                                         //
359                                         insert(request);
360                                         //
361                                         // Tell interested parties we are performing this Operation
362                                         //
363                                         VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
364                                         notification.notification = ControlLoopNotificationType.OPERATION;
365                                         // message and history ??
366                                         notification.from = "policy";
367                                         notification.policyName = drools.getRule().getName();
368                                         notification.policyScope = "com";
369                                         notification.policyVersion = "1";
370                                         try {
371                                                 System.out.println(Serialization.gsonPretty.toJson(notification));
372                                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
373                                         } catch (Exception e) {
374                                                 System.out.println("Can't deliver notification: " + notification);
375                                                 e.printStackTrace();
376                                         }
377                                         //
378                                         // Now send the operation request
379                                         //
380                                         if (request instanceof Request) {
381                                                 try {
382                                                         System.out.println("APPC request sent:");
383                                                         System.out.println(Serialization.gsonPretty.toJson(request));
384                                                         PolicyEngine.manager.deliver($params.getAppcTopic(), request);
385                                                 } catch (Exception e) {
386                                                         e.printStackTrace();
387                                                         System.out.println("Can't deliver request: " + request);
388                                                 }
389                                         }
390                                 } else {
391                                         //
392                                         // what happens if it is null
393                                         //
394                                 }
395                                 //
396                         } else {
397                                 //
398                                 // create AAI named-query request with UUID started with "F199"
399                                 //
400                                 AAINQF199Request aainqf199request = new AAINQF199Request();
401                                 AAINQF199QueryParameters aainqf199queryparam = new AAINQF199QueryParameters();
402                                 AAINQF199NamedQuery aainqf199namedquery = new AAINQF199NamedQuery();
403                                 AAINQF199InstanceFilters aainqf199instancefilter = new AAINQF199InstanceFilters();
404                                 //
405                                 // queryParameters
406                                 //
407                                 aainqf199namedquery.namedQueryUUID = UUID.fromString($params.getAaiNamedQueryUUID()); 
408                                 aainqf199queryparam.namedQuery = aainqf199namedquery;
409                                 aainqf199request.queryParameters = aainqf199queryparam;
410                                 //
411                                 // instanceFilters
412                                 //
413                                 Map aainqf199instancefiltermap = new HashMap();
414                                 Map aainqf199instancefiltermapitem = new HashMap();
415                                 aainqf199instancefiltermapitem.put("vserver-name", vserver); 
416                                 aainqf199instancefiltermap.put("vserver", aainqf199instancefiltermapitem);
417                                 aainqf199instancefilter.instanceFilter.add(aainqf199instancefiltermap);
418                                 aainqf199request.instanceFilters = aainqf199instancefilter;
419                                 //
420                                 // print aainqf199request for debug
421                                 //
422                                 System.out.println("AAI Request sent:");
423                                 System.out.println(Serialization.gsonPretty.toJson(aainqf199request));
424                                 //
425                                 // Create AAINQF199RequestWrapper
426                                 //
427                                 AAINQF199RequestWrapper aainqf199RequestWrapper = new AAINQF199RequestWrapper($event.requestID, aainqf199request);
428                                 //
429                                 // insert aainqf199request into memory
430                                 //
431                                 insert(aainqf199RequestWrapper);
432                         }
433                         //
434                 } catch (Exception e) {
435                  e.printStackTrace();
436                 }
437 end
438
439 /*
440 *
441 * This rule happens when we got a valid ONSET, closed loop is enabled, an Event Manager
442 * is created, AAI Manager and AAI Request are ready in memory. We can start sending query to AAI and then wait for response.
443 *
444 */
445 rule "BRMSParamvLBDemoPolicy.EVENT.MANAGER.AAINQF199REQUEST"
446         when
447                 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
448                 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
449                 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
450                 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
451         then
452                 System.out.println("rule EVENT.MANAGER.AAINQF199REQUEST is triggered.");
453                 //
454                 // send the request
455                 //
456                 AAINQF199Response aainqf199response = AAINQF199Manager.postQuery($params.getAaiURL(), $params.getAaiUsername(), $params.getAaiPassword(),
457                                                                                                            $aainqf199RequestWrapper.aainqf199request, $event.requestID);
458                 //
459                 // Check AAI response
460                 //
461                 if (aainqf199response == null) {
462                         System.err.println("Failed to get AAI response");
463                         //
464                         // Fail and retract everything
465                         //
466                         retract($event);
467                         retract($manager);
468                         retract($aainqf199RequestWrapper);
469                 } else {
470                         //
471                         // Create AAINQF199ResponseWrapper
472                         //
473                         AAINQF199ResponseWrapper aainqf199ResponseWrapper = new AAINQF199ResponseWrapper($event.requestID, aainqf199response);
474                         //
475                         // insert aainqf199ResponseWrapper to memeory
476                         //
477                         insert(aainqf199ResponseWrapper);
478                 }
479 end
480
481 /*
482 *
483 * This rule happens when we got a valid AAI response. We can start sending request to APPC or MSO now.
484 *
485 */
486 rule "BRMSParamvLBDemoPolicy.EVENT.MANAGER.AAINQF199RESPONSE"
487         when 
488                 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
489                 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
490                 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
491                 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
492                 $aainqf199ResponseWrapper : AAINQF199ResponseWrapper(requestID == $event.requestID)
493         then
494                 System.out.println("rule EVENT.MANAGER.AAINQF199RESPONSE is triggered.");
495                 //
496                 // Extract related fields out of AAINQF199RESPONSE
497                 //
498                 String vnfItemVnfId, vnfItemVnfType, vnfItemPersonaModelId, vnfItemPersonaModelVersion, vnfItemModelName, 
499                        vnfItemModelVersion, vnfItemModelNameVersionId, serviceItemServiceInstanceId, serviceItemPersonaModelId,
500                        serviceItemModelName, serviceItemModelType, serviceItemModelVersion, serviceItemModelNameVersionId,
501                        vfModuleItemVfModuleName, vfModuleItemPersonaModelId, vfModuleItemPersonaModelVersion, vfModuleItemModelName, 
502                        vfModuleItemModelNameVersionId, tenantItemTenantId, cloudRegionItemCloudRegionId;
503                 try {
504                         //
505                         // vnfItem
506                         //
507                         vnfItemVnfId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfID;
508                         vnfItemVnfType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfType;
509                         vnfItemVnfType = vnfItemVnfType.substring(vnfItemVnfType.lastIndexOf("/")+1);
510                         vnfItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelId;
511                         vnfItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelVersion;
512                         vnfItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
513                         vnfItemModelVersion =           $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(2).propertyValue;
514                         vnfItemModelNameVersionId =     $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
515                         //
516                         // serviceItem
517                         //
518                         serviceItemServiceInstanceId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.serviceInstanceID;
519                         serviceItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelId;
520                         serviceItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
521                         serviceItemModelType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(1).propertyValue;
522                         serviceItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelVersion;
523                         serviceItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
524                         //
525                         // This comes from the base module
526                         //
527                         vfModuleItemVfModuleName =                      $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).vfModule.vfModuleName;
528                         vfModuleItemVfModuleName = vfModuleItemVfModuleName.replace("Vfmodule", "vDNS");
529                         //
530                         // vfModuleItem - NOT the base module
531                         //
532                         vfModuleItemPersonaModelId =            $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(2).vfModule.personaModelId;
533                         vfModuleItemPersonaModelVersion =       $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(2).vfModule.personaModelVersion;
534                         vfModuleItemModelName =                                 $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(2).extraProperties.extraProperty.get(0).propertyValue;
535                         vfModuleItemModelNameVersionId =        $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(2).extraProperties.extraProperty.get(4).propertyValue;
536                         //
537                         // tenantItem
538                         //
539                         tenantItemTenantId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).tenant.tenantId;
540                         //
541                         // cloudRegionItem
542                         //
543                         cloudRegionItemCloudRegionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).items.inventoryResponseItems.get(0).cloudRegion.cloudRegionId;
544                         //
545                 } catch (Exception e) {
546                         e.printStackTrace();
547                         VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
548                         notification.notification = ControlLoopNotificationType.REJECTED;
549                         notification.message = "Exception occurred " + e.getMessage();
550                         notification.policyName = drools.getRule().getName();
551                         notification.policyScope = "com";
552                         notification.policyVersion = "1";
553                         //
554                         try {
555                                 System.out.println(Serialization.gsonPretty.toJson(notification));
556                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
557                         } catch (Exception e1) {
558                                 System.out.println("Can't deliver notification: " + notification);
559                                 e1.printStackTrace();
560                         }
561                         //
562                         notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
563                         notification.message = "Invalid named-query response from AAI";
564             //
565             try {
566                 System.out.println(Serialization.gsonPretty.toJson(notification));
567                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
568             } catch (Exception e1) {
569                 System.out.println("Can't deliver notification: " + notification);
570                 e1.printStackTrace();
571             }
572                         //
573                         // Retract everything
574                         //
575                         retract($aainqf199RequestWrapper);
576                         retract($aainqf199ResponseWrapper);
577                         retract($manager);
578                         retract($event);
579                         return;
580                 }       
581                 //
582                 // Extracted fields should not be null
583                 //
584                 if ((vnfItemVnfId == null) || (vnfItemVnfType == null) ||
585                     (vnfItemPersonaModelId == null) || (vnfItemModelName == null) ||
586                     (vnfItemModelVersion == null) || (vnfItemModelNameVersionId == null) ||
587                     (serviceItemServiceInstanceId == null) || (serviceItemModelName == null) ||
588                     (serviceItemModelType == null) || (serviceItemModelVersion == null) ||
589                     (serviceItemModelNameVersionId == null) || (vfModuleItemVfModuleName == null) ||
590                     (vfModuleItemPersonaModelId == null) || (vfModuleItemPersonaModelVersion == null) ||
591                     (vfModuleItemModelName == null) || (vfModuleItemModelNameVersionId == null) ||
592                     (tenantItemTenantId == null) || (cloudRegionItemCloudRegionId == null)) {
593                         //
594                         System.err.println("some fields are missing from AAI response.");
595                         //
596                         // Fail and retract everything
597                         //
598                         retract($aainqf199RequestWrapper);
599                         retract($aainqf199ResponseWrapper);
600                         retract($manager);
601                         retract($event);
602                         return;
603                 }
604                 //
605                 // We don't need them any more
606                 //
607                 retract($aainqf199ResponseWrapper);
608                 retract($aainqf199RequestWrapper);  
609                 //
610                 // check the actor of this closed loop
611                 //
612                 switch ($params.getActor()) {
613                         case "APPC":
614                         {
615                                 //
616                                 // Construct an APPC request
617                                 //
618                                 ControlLoopOperation operation = new ControlLoopOperation();
619                                 operation.actor = $params.getActor();
620                                 operation.operation = "ModifyConfig";
621                                 operation.target = $event.target;
622                                 //
623                                 // Create operationWrapper
624                                 //
625                                 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
626                                 //
627                                 // insert operationWrapper into memory
628                                 //
629                                 insert(operationWrapper);
630                                 //
631                                 Request request = new Request();
632                                 request.CommonHeader = new CommonHeader();
633                                 request.CommonHeader.RequestID = $event.requestID;
634                                 request.Action = operation.operation;
635                                 request.Payload = new HashMap<String, Object>();
636                                 //
637                                 // Fill in the payload
638                                 // Hardcode genericVNF for now since AAI has not been ready for vFirewall demo case
639                                 //
640                                 String genericVNF = "zdfw1fwl01pgn02";
641                                 request.Payload.put("generic-vnf.vnf-id", genericVNF);
642                                 //
643                                 PGRequest pgRequest = new PGRequest();
644                                 pgRequest.pgStreams = new PGStreams();
645                                 
646                                 PGStream pgStream;
647                                 for(int i = 0; i < 5; i++){
648                                         pgStream = new PGStream();
649                                         pgStream.streamId = "fw_udp"+(i+1);
650                                         pgStream.isEnabled = "true";
651                                         pgRequest.pgStreams.pgStream.add(pgStream);
652                                 }
653                                 request.Payload.put("pg-streams", pgRequest.pgStreams);
654                                 
655                                 if (request != null) {
656                                         //
657                                         // Insert request into memory
658                                         //
659                                         insert(request);
660                                         //
661                                         // Tell interested parties we are performing this Operation
662                                         //
663                                         VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
664                                         notification.notification = ControlLoopNotificationType.OPERATION;
665                                         // message and history ??
666                                         notification.from = "policy";
667                                         notification.policyName = drools.getRule().getName();
668                                         notification.policyScope = "com";
669                                         notification.policyVersion = "1";
670                                         try {
671                                                 System.out.println(Serialization.gsonPretty.toJson(notification));
672                                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
673                                         } catch (Exception e) {
674                                                 System.out.println("Can't deliver notification: " + notification);
675                                                 e.printStackTrace();
676                                         }
677                                         //
678                                         // Now send the operation request
679                                         //
680                                         if (request instanceof Request) {
681                                                 try {
682                                                         System.out.println("APPC request sent:");
683                                                         System.out.println(Serialization.gsonPretty.toJson(request));
684                                                         PolicyEngine.manager.deliver($params.getAppcTopic(), request);
685                                                 } catch (Exception e) {
686                                                         e.printStackTrace();
687                                                         System.out.println("Can't deliver request: " + request);
688                                                 }
689                                         }
690                                 } else {
691                                         //
692                                         // what happens if it is null
693                                         //
694                                 }
695                         }
696                         break;
697                         case "MSO":
698                         {
699                                 //
700                                 // Construct an operation
701                                 //
702                                 ControlLoopOperation operation = new ControlLoopOperation();
703                                 operation.actor = $params.getActor();
704                                 operation.operation = "createModuleInstance";
705                                 operation.target = $event.target;
706                                 //
707                                 // Create operationWrapper
708                                 //
709                                 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
710                                 //
711                                 // Construct an MSO request
712                                 //
713                                 MSORequest request = new MSORequest();
714                                 request.requestDetails = new MSORequestDetails();
715                                 request.requestDetails.modelInfo = new MSOModelInfo();
716                                 request.requestDetails.cloudConfiguration = new MSOCloudConfiguration();
717                                 request.requestDetails.requestInfo = new MSORequestInfo();
718                                 request.requestDetails.requestParameters = new MSORequestParameters();
719                                 request.requestDetails.requestParameters.userParams = null;
720                                 //
721                                 // cloudConfiguration
722                                 //
723                                 request.requestDetails.cloudConfiguration.lcpCloudRegionId = cloudRegionItemCloudRegionId;
724                                 request.requestDetails.cloudConfiguration.tenantId = tenantItemTenantId;
725                                 //
726                                 // modelInfo
727                                 //
728                                 request.requestDetails.modelInfo.modelType = "vfModule";
729                                 request.requestDetails.modelInfo.modelInvariantId = vfModuleItemPersonaModelId;
730                                 request.requestDetails.modelInfo.modelNameVersionId = vfModuleItemModelNameVersionId;
731                                 request.requestDetails.modelInfo.modelName = vfModuleItemModelName;
732                                 request.requestDetails.modelInfo.modelVersion = vfModuleItemPersonaModelVersion;
733                                 //
734                                 // requestInfo
735                                 //
736                                 request.requestDetails.requestInfo.instanceName = vfModuleItemVfModuleName;
737                                 request.requestDetails.requestInfo.source = "POLICY";
738                                 request.requestDetails.requestInfo.suppressRollback = false;
739                                 //
740                                 // relatedInstanceList
741                                 //
742                                 MSORelatedInstanceListElement relatedInstanceListElement1 = new MSORelatedInstanceListElement();
743                                 MSORelatedInstanceListElement relatedInstanceListElement2 = new MSORelatedInstanceListElement();
744                                 relatedInstanceListElement1.relatedInstance = new MSORelatedInstance();
745                                 relatedInstanceListElement2.relatedInstance = new MSORelatedInstance();
746                                 //
747                                 relatedInstanceListElement1.relatedInstance.instanceId = serviceItemServiceInstanceId;
748                                 relatedInstanceListElement1.relatedInstance.modelInfo = new MSOModelInfo();
749                                 relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service";
750                                 relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = serviceItemPersonaModelId;
751                                 relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = serviceItemModelNameVersionId;
752                                 relatedInstanceListElement1.relatedInstance.modelInfo.modelName = serviceItemModelName;
753                                 relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = serviceItemModelVersion;
754                                 //
755                                 relatedInstanceListElement2.relatedInstance.instanceId = vnfItemVnfId;
756                                 relatedInstanceListElement2.relatedInstance.modelInfo = new MSOModelInfo();
757                                 relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf";
758                                 relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = vnfItemPersonaModelId;
759                                 relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = vnfItemModelNameVersionId;
760                                 relatedInstanceListElement2.relatedInstance.modelInfo.modelName = vnfItemModelName;
761                                 relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = vnfItemModelVersion;
762                                 relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = vnfItemVnfType;
763                                 //      
764                                 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1);
765                                 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2);
766                                 //
767                                 // print MSO request for debug
768                                 //
769                                 System.out.println("MSO request sent:");
770                                 System.out.println(Serialization.gsonPretty.toJson(request));
771                                 //
772                                 //
773                                 //
774                                 if (request != null) {
775                                         //
776                                         // Tell interested parties we are performing this Operation
777                                         //
778                                         VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
779                                         notification.notification = ControlLoopNotificationType.OPERATION;
780                                         notification.from = "policy";
781                                         notification.policyName = drools.getRule().getName();
782                                         notification.policyScope = "com";
783                                         notification.policyVersion = "1";
784                                         try {
785                                                 System.out.println(Serialization.gsonPretty.toJson(notification));
786                                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
787                                         } catch (Exception e) {
788                                                 System.out.println("Can't deliver notification: " + notification);
789                                                 e.printStackTrace();
790                                         }
791                                         //
792                                         // Concatenate serviceItemServiceInstanceId and vnfItemVnfId to msoURL
793                                         //
794                                         String MSOUrl = $params.getMsoURL() + "/serviceInstances/v2/" + serviceItemServiceInstanceId + "/vnfs/" + vnfItemVnfId + "/vfModules";
795                                         //
796                                         // Call MSO
797                                         //
798                                         MSOResponse response = MSOManager.createModuleInstance(MSOUrl, $params.getMsoURL(), $params.getMsoUsername(), $params.getMsoPassword(), request);
799                                         //
800                                         if (response != null) {
801                                                 //
802                                                 // Assign requestId
803                                                 //
804                                                 request.requestId = $event.requestID.toString();                                                
805                                                 response.request.requestId = $event.requestID.toString();
806                                                 //
807                                                 // Insert facts
808                                                 //
809                                                 insert(operationWrapper);
810                                                 insert(request);
811                                                 insert(response);
812                                         } else {
813                                                 //
814                                                 // MSO request not even accepted
815                                                 //
816                                                 notification.message = operationWrapper.operation.toMessage();
817                                                 operationWrapper.operation.message = operationWrapper.operation.toMessage();
818                                                 operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
819                                                 $manager.setControlLoopResult("FAILURE_EXCEPTION");
820                                                 notification.history.add(operationWrapper.operation);
821                                                 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
822                                                 //
823                                                 // Let interested parties know
824                                                 //
825                                                 try {
826                                                         System.out.println(Serialization.gsonPretty.toJson(notification));
827                                                         PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
828                                                 } catch (Exception e) {
829                                                         System.out.println("Can't deliver notification: " + notification);
830                                                         e.printStackTrace();
831                                                 }
832                             notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
833                         try {
834                                 System.out.println(Serialization.gsonPretty.toJson(notification));
835                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
836                         } catch (Exception e) {
837                                 System.out.println("Can't deliver notification: " + notification);
838                                 e.printStackTrace();
839                         }
840                                                 //
841                                                 // Retract everything
842                                                 //
843                                                 retract($event);
844                                                 retract($manager);
845                                         }
846                                 } else {
847                                         System.err.println("constructed MSO request is invalid.");
848                                 }
849                         }
850                         break; 
851                 } 
852 end
853                 
854 /*
855 *
856 * This rule responds to APPC Response Events
857 *
858 */
859 rule "BRMSParamvLBDemoPolicy.APPC.RESPONSE"
860         when
861                 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
862                 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
863                 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
864                 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
865                 $request : Request( getCommonHeader().RequestID == $event.requestID )
866                 $response : Response( getCommonHeader().RequestID == $event.requestID ) 
867         then
868                 System.out.println("rule APPC.RESPONSE is triggered.");
869                 if ($response.Status == null) {
870                         $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
871                         $manager.setControlLoopResult("FAILURE_EXCEPTION");
872                 } 
873                 //
874                 // Get the Response Code
875                 //
876                 ResponseCode code = ResponseCode.toResponseCode($response.Status.Code);
877                 if (code == null) {
878                         $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
879                         $manager.setControlLoopResult("FAILURE_EXCEPTION");
880                 }
881                 //
882                 // Construct notification
883                 //
884                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
885                 notification.from = "policy";
886                 notification.policyName = drools.getRule().getName();
887                 notification.policyScope = "com";
888                 notification.policyVersion = "1";
889                 notification.message = $operationWrapper.operation.toMessage();
890                 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
891                 //
892                 // Ok, let's figure out what APP-C's response is
893                 //
894                 switch (code) {
895                         case ACCEPT:
896                                 $operationWrapper.operation.outcome = "PROCESSING";
897                                 break;
898                         case ERROR:
899                         case REJECT:
900                                 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
901                                 $manager.setControlLoopResult("FAILURE_EXCEPTION");
902                                 break;
903                         case SUCCESS:
904                                 $operationWrapper.operation.outcome = "SUCCESS";
905                                 $manager.setControlLoopResult("SUCCESS");
906                                 break;
907                         case FAILURE:
908                                 $operationWrapper.operation.outcome = "FAILURE";
909                                 $manager.setControlLoopResult("FAILURE");
910                                 break;
911                 }
912                 if ($operationWrapper.operation.outcome.equals("SUCCESS")) {
913                         notification.history.add($operationWrapper.operation);
914                         notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
915                         //
916                         // Let interested parties know
917                         //
918                         try {
919                                 System.out.println(Serialization.gsonPretty.toJson(notification));
920                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
921                         } catch (Exception e) {
922                                 System.out.println("Can't deliver notification: " + notification);
923                                 e.printStackTrace();
924                         }
925             notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
926             try {
927                 System.out.println(Serialization.gsonPretty.toJson(notification));
928                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
929             } catch (Exception e) {
930                 System.out.println("Can't deliver notification: " + notification);
931                 e.printStackTrace();
932             }
933
934                         //
935                         // We are going to retract these objects from memory
936                         //
937                         System.out.println("Retracting everything");
938                         retract($operationWrapper);
939                         retract($request);
940                         retract($response);
941                         retract($event);
942                         retract($manager);
943                 } else if ($operationWrapper.operation.outcome.equals("PROCESSING")) {
944                         retract($response);
945                 } else {
946                         notification.history.add($operationWrapper.operation);
947                         notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
948                         //
949                         // Let interested parties know
950                         //
951                         try {
952                                 System.out.println(Serialization.gsonPretty.toJson(notification));
953                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
954                         } catch (Exception e) {
955                                 System.out.println("Can't deliver notification: " + notification);
956                                 e.printStackTrace();
957                         }
958             notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
959             //
960             // Let interested parties know
961             //
962             try {
963                 System.out.println(Serialization.gsonPretty.toJson(notification));
964                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
965             } catch (Exception e) {
966                 System.out.println("Can't deliver notification: " + notification);
967                 e.printStackTrace();
968             }
969                         //
970                         // We are going to retract these objects from memory
971                         //
972                         System.out.println("Retracting everything");
973                         retract($operationWrapper);
974                         retract($request);
975                         retract($response);
976                         retract($event);
977                         retract($manager);
978                 }
979                 
980 end             
981
982 /*
983 *
984 * This rule is used to clean up APPC response
985 *
986 */              
987 rule "BRMSParamvLBDemoPolicy.APPC.RESPONSE.CLEANUP"
988         when
989                 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
990         $response : Response($id : getCommonHeader().RequestID )
991                 not ( VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), requestID == $id, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) ) 
992         then
993                 System.out.println("rule APPC.RESPONSE.CLEANUP is triggered.");
994                 retract($response);
995 end
996
997 /*
998 *
999 * This rule responds to MSO Response Events
1000 *
1001 */
1002 rule "BRMSParamvLBDemoPolicy.MSO.RESPONSE"
1003         when
1004                 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
1005                 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
1006                 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
1007                 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
1008                 $request : MSORequest( requestId == $event.requestID.toString() )
1009                 $response : MSOResponse( request.requestId == $event.requestID.toString() )     
1010         then
1011                 System.out.println("rule MSO.RESPONSE is triggered.");
1012                 //
1013                 // Construct notification
1014                 //
1015                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
1016                 notification.from = "policy";
1017                 notification.policyName = drools.getRule().getName();
1018                 notification.policyScope = "com";
1019                 notification.policyVersion = "1";
1020                 notification.message = $operationWrapper.operation.toMessage();
1021                 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
1022                 //
1023                 // The operation can either be succeeded or failed
1024                 // 
1025                 if($response.request.requestStatus.requestState.equals("Completed")) {
1026                         $operationWrapper.operation.outcome = "SUCCESS";
1027                         $manager.setControlLoopResult("SUCCESS");
1028                         notification.history.add($operationWrapper.operation);
1029                         notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
1030                         //
1031                         // Let interested parties know
1032                         //
1033                         try {
1034                                 System.out.println(Serialization.gsonPretty.toJson(notification));
1035                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1036                         } catch (Exception e) {
1037                                 System.out.println("Can't deliver notification: " + notification);
1038                                 e.printStackTrace();
1039                         }
1040                         notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
1041             //
1042             // Let interested parties know
1043             //
1044             try {
1045                 System.out.println(Serialization.gsonPretty.toJson(notification));
1046                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1047             } catch (Exception e) {
1048                 System.out.println("Can't deliver notification: " + notification);
1049                 e.printStackTrace();
1050             }
1051             //
1052                         // We are going to retract these objects from memory
1053                         //
1054                         System.out.println("Retracting everything");
1055                         retract($operationWrapper);
1056                         retract($request);
1057                         retract($response);
1058                         retract($event);
1059                         retract($manager);
1060                 } else {
1061                         $operationWrapper.operation.outcome = "FAILURE";
1062                         $manager.setControlLoopResult("FAILURE");
1063                         notification.history.add($operationWrapper.operation);
1064                         notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
1065                         //
1066                         // Let interested parties know
1067                         //
1068                         try {
1069                                 System.out.println(Serialization.gsonPretty.toJson(notification));
1070                                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1071                         } catch (Exception e) {
1072                                 System.out.println("Can't deliver notification: " + notification);
1073                                 e.printStackTrace();
1074                         }
1075                         notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
1076             //
1077             // Let interested parties know
1078             //
1079             try {
1080                 System.out.println(Serialization.gsonPretty.toJson(notification));
1081                 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1082             } catch (Exception e) {
1083                 System.out.println("Can't deliver notification: " + notification);
1084                 e.printStackTrace();
1085             }
1086             //
1087                         // We are going to retract these objects from memory
1088                         //
1089                         System.out.println("Retracting everything");
1090                         retract($operationWrapper);
1091                         retract($request);
1092                         retract($response);
1093                         retract($event);
1094                         retract($manager);
1095                 }
1096                 
1097 end     
1098 rule "Params" 
1099         salience 1000 
1100         when
1101         then
1102                 Params params = new Params();
1103                 params.setAaiPatternMatch(0);
1104                 params.setAppcTopic("APPC-CL");
1105                 params.setAaiURL("https://aai.api.simpledemo.openecomp.org:8443");
1106                 params.setMsoPassword("password1$");
1107                 params.setClosedLoopControlName("CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8");
1108                 params.setAaiUsername("POLICY");
1109                 params.setMsoURL("http://vm1.mso.simpledemo.openecomp.org:8080/ecomp/mso/infra");
1110                 params.setActor("MSO");
1111                 params.setMsoUsername("InfraPortalClient");
1112                 params.setAaiNamedQueryUUID("f199cb88-5e69-4b1f-93e0-6f257877d066");
1113                 params.setAaiPassword("POLICY");
1114                 params.setNotificationTopic("POLICY-CL-MGT");
1115                 insert(params);
1116 end