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;
83 // These parameters are required to build the runtime policy
86 closedLoopControlName : String
94 aaiNamedQueryUUID : String
96 notificationTopic : String
102 * Called once and only once to insert the parameters into working memory for this Closed Loop policy.
103 * NOTE: If this file is to be used as a template to be used with the policy BRMS GW, please comment out this line
104 * as the BRMS_GW already generates a SETUP rule
107 rule "${policyName}.SETUP"
110 System.out.println("rule SETUP is triggered.");
111 Params params = new Params();
112 params.setClosedLoopControlName("${closedLoopControlName}");
113 params.setActor("${actor}");
114 params.setAaiURL("${aaiURL}");
115 params.setAaiUsername("${aaiUsername}");
116 params.setAaiPassword("${aaiPassword}");
117 params.setMsoURL("${msoURL}");
118 params.setMsoUsername("${msoUsername}");
119 params.setMsoPassword("${msoPassword}");
120 params.setAaiNamedQueryUUID("${aaiNamedQueryUUID}");
121 params.setAaiPatternMatch(${aaiPatternMatch});
122 params.setNotificationTopic("${notificationTopic}");
123 params.setAppcTopic("${appcTopic}");
125 // This stays in memory as long as the rule is alive and running
133 * This rule responds to DCAE Events
136 rule "${policyName}.EVENT"
138 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
139 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
140 not ( ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ))
142 System.out.println("rule EVENT is triggered.");
145 // Check the requestID in the event to make sure it is not null before we create the EventManager.
146 // The EventManager will do extra syntax checking as well check if the closed loop is disabled/
148 if ($event.requestID == null) {
149 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
150 notification.notification = ControlLoopNotificationType.REJECTED;
151 notification.from = "policy";
152 notification.message = "Missing requestID from DCAE event";
153 notification.policyName = drools.getRule().getName();
154 notification.policyScope = "${policyScope}";
155 notification.policyVersion = "${policyVersion}";
157 // Let interested parties know
160 System.out.println(Serialization.gsonPretty.toJson(notification));
161 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
162 } catch (Exception e) {
164 System.out.println("Can't deliver notification: " + notification);
167 // Retract it from memory
170 System.out.println("Event with requestID=null has been retracted.");
173 // Create an EventManager
175 ControlLoopEventManager manager = new ControlLoopEventManager($params.getClosedLoopControlName(), $event.requestID);
177 // Determine if EventManager can actively process the event (i.e. syntax)
179 VirtualControlLoopNotification notification = manager.activate($event);
180 notification.from = "policy";
181 notification.policyName = drools.getRule().getName();
182 notification.policyScope = "${policyScope}";
183 notification.policyVersion = "${policyVersion}";
185 // Are we actively pursuing this event?
187 if (notification.notification == ControlLoopNotificationType.ACTIVE) {
189 // Insert Event Manager into memory, this will now kick off processing.
193 // Let interested parties know
196 System.out.println(Serialization.gsonPretty.toJson(notification));
197 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
198 } catch (Exception e) {
200 System.out.println("Can't deliver notification: " + notification);
204 // Let interested parties know
207 System.out.println(Serialization.gsonPretty.toJson(notification));
208 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
209 } catch (Exception e) {
211 System.out.println("Can't deliver notification: " + notification);
214 // Retract it from memory
219 // Now that the manager is inserted into Drools working memory, we'll wait for
220 // another rule to fire in order to continue processing. This way we can also
221 // then screen for additional ONSET and ABATED events for this same RequestIDs
222 // and for different RequestIDs but with the same closedLoopControlName and target.
226 } catch (Exception e) {
228 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
229 notification.notification = ControlLoopNotificationType.REJECTED;
230 notification.message = "Exception occurred " + e.getMessage();
231 notification.policyName = drools.getRule().getName();
232 notification.policyScope = "${policyScope}";
233 notification.policyVersion = "${policyVersion}";
238 System.out.println(Serialization.gsonPretty.toJson(notification));
239 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
240 } catch (Exception e1) {
241 System.out.println("Can't deliver notification: " + notification);
242 e1.printStackTrace();
253 * This rule happens when we got a valid ONSET, closed loop is enabled and an Event Manager
254 * is created. We can start the operations for this closed loop.
257 rule "${policyName}.EVENT.MANAGER"
259 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
260 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
261 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, controlLoopResult == null)
263 System.out.println("rule EVENT.MANAGER is triggered.");
265 // Check which event this is.
267 ControlLoopEventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event);
269 // We only want the initial ONSET event in memory,
270 // all the other events need to be retracted to support
271 // cleanup and avoid the other rules being fired for this event.
273 if (eventStatus != ControlLoopEventManager.NEW_EVENT_STATUS.FIRST_ONSET) {
274 System.out.println("Retracting "+eventStatus+" Event.");
279 // Now the event in memory is first onset event
283 // Pull the known AAI field from the Event
285 // generic-vnf is needed for vFirewall case
286 // vserver-name is needed for vLoadBalancer case
288 String genericVNF = $event.AAI.get("generic-vnf.vnf-id");
289 String vserver = $event.AAI.get("vserver.vserver-name");
291 // Check if we are implementing a simple pattern match.
293 if ($params.getAaiPatternMatch() == 1) {
297 //Basic naming characteristics:
298 //VF Name (9 char)+VM name (13 char total)+VFC (19 char total)
300 //VF Name (9 characters): cscf0001v
301 //VM Name(13 characters): cscf0001vm001
302 //VFC name(19 characters): cscf0001vm001cfg001
304 // zdfw1fwl01fwl02 or zdfw1fwl01fwl01
306 // zdfw1fwl01pgn02 or zdfw1fwl01pgn01
308 int index = genericVNF.lastIndexOf("fwl");
310 System.err.println("The generic-vnf.vnf-id from DCAE Event is not valid.");
312 genericVNF = genericVNF.substring(0, index) + "pgn" + genericVNF.substring(index+"fwl".length());
315 // Construct an APPC request
317 ControlLoopOperation operation = new ControlLoopOperation();
318 operation.actor = $params.getActor();
319 operation.operation = "ModifyConfig";
320 operation.target = $event.target;
322 // Create operationWrapper
324 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
326 // insert operationWrapper into memory
328 insert(operationWrapper);
330 Request request = new Request();
331 request.CommonHeader = new CommonHeader();
332 request.CommonHeader.RequestID = $event.requestID;
333 request.Action = operation.operation;
334 request.Payload = new HashMap<String, Object>();
336 // Fill in the payload
338 request.Payload.put("generic-vnf.vnf-id", genericVNF);
340 PGRequest pgRequest = new PGRequest();
341 pgRequest.pgStreams = new PGStreams();
344 for(int i = 0; i < 5; i++){
345 pgStream = new PGStream();
346 pgStream.streamId = "fw_udp"+(i+1);
347 pgStream.isEnabled = "true";
348 pgRequest.pgStreams.pgStream.add(pgStream);
350 request.Payload.put("pg-streams", pgRequest.pgStreams);
352 if (request != null) {
354 // Insert request into memory
358 // Tell interested parties we are performing this Operation
360 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
361 notification.notification = ControlLoopNotificationType.OPERATION;
362 // message and history ??
363 notification.from = "policy";
364 notification.policyName = drools.getRule().getName();
365 notification.policyScope = "${policyScope}";
366 notification.policyVersion = "${policyVersion}";
368 System.out.println(Serialization.gsonPretty.toJson(notification));
369 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
370 } catch (Exception e) {
371 System.out.println("Can't deliver notification: " + notification);
375 // Now send the operation request
377 if (request instanceof Request) {
379 System.out.println("APPC request sent:");
380 System.out.println(Serialization.gsonPretty.toJson(request));
381 //PolicyEngine.manager.deliver($params.getAppcTopic(), request);
382 } catch (Exception e) {
384 System.out.println("Can't deliver request: " + request);
389 // what happens if it is null
395 // create AAI named-query request with UUID started with "F199"
397 AAINQF199Request aainqf199request = new AAINQF199Request();
398 AAINQF199QueryParameters aainqf199queryparam = new AAINQF199QueryParameters();
399 AAINQF199NamedQuery aainqf199namedquery = new AAINQF199NamedQuery();
400 AAINQF199InstanceFilters aainqf199instancefilter = new AAINQF199InstanceFilters();
404 aainqf199namedquery.namedQueryUUID = UUID.fromString($params.getAaiNamedQueryUUID());
405 aainqf199queryparam.namedQuery = aainqf199namedquery;
406 aainqf199request.queryParameters = aainqf199queryparam;
410 Map aainqf199instancefiltermap = new HashMap();
411 Map aainqf199instancefiltermapitem = new HashMap();
412 aainqf199instancefiltermapitem.put("vserver-name", vserver);
413 aainqf199instancefiltermap.put("vserver", aainqf199instancefiltermapitem);
414 aainqf199instancefilter.instanceFilter.add(aainqf199instancefiltermap);
415 aainqf199request.instanceFilters = aainqf199instancefilter;
417 // print aainqf199request for debug
419 System.out.println("AAI Request sent:");
420 System.out.println(Serialization.gsonPretty.toJson(aainqf199request));
422 // Create AAINQF199RequestWrapper
424 AAINQF199RequestWrapper aainqf199RequestWrapper = new AAINQF199RequestWrapper($event.requestID, aainqf199request);
426 // insert aainqf199request into memory
428 insert(aainqf199RequestWrapper);
431 } catch (Exception e) {
438 * This rule happens when we got a valid ONSET, closed loop is enabled, an Event Manager
439 * is created, AAI Manager and AAI Request are ready in memory. We can start sending query to AAI and then wait for response.
442 rule "${policyName}.EVENT.MANAGER.AAINQF199REQUEST"
444 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
445 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
446 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
447 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
449 System.out.println("rule EVENT.MANAGER.AAINQF199REQUEST is triggered.");
453 AAINQF199Response aainqf199response = AAINQF199Manager.postQuery($params.getAaiURL(), $params.getAaiUsername(), $params.getAaiPassword(),
454 $aainqf199RequestWrapper.aainqf199request, $event.requestID);
458 //////////////////////////////////////////////////////////
459 // Simulate a valid aainqf199response for junit test
460 // Remove this for real deployment
463 AAINQF199InventoryResponseItem serviceItem = new AAINQF199InventoryResponseItem();
464 serviceItem.modelName = "service-instance";
465 serviceItem.serviceInstance = new AAINQF199ServiceInstance();
466 serviceItem.serviceInstance.serviceInstanceID = "cf8426a6-0b53-4e3d-bfa6-4b2f4d5913a5";
467 serviceItem.serviceInstance.serviceInstanceName = "Service_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8";
468 serviceItem.serviceInstance.personaModelId = "4fcbc1c0-7793-46d8-8aa1-fa1c2ed9ec7b";
469 serviceItem.serviceInstance.personaModelVersion = "1.0";
470 serviceItem.serviceInstance.resourceVersion = "1485542400";
471 serviceItem.extraProperties = new AAINQF199ExtraProperties();
472 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "8330e932-2a23-4943-8606"));
473 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "service"));
474 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
475 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "4fcbc1c0-7793-46d8-8aa1-fa1c2ed9ec7b"));
476 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "5c996219-b2e2-4c76-9b43-7e8672a33c1d"));
478 AAINQF199InventoryResponseItem vfModuleItem = new AAINQF199InventoryResponseItem();
479 vfModuleItem.modelName = "C15ce9e1E9144c8fB8bb..base_vlb..module-0";
480 vfModuleItem.vfModule = new AAINQF199VfModule();
481 vfModuleItem.vfModule.vfModuleId = "b0eff878-e2e1-4947-9597-39afdd0f51dd";
482 vfModuleItem.vfModule.vfModuleName = "Vfmodule_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8";
483 vfModuleItem.vfModule.heatStackId = "Vfmodule_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8/5845f37b-6cda-4e91-8ca3-f5572d226488";
484 vfModuleItem.vfModule.orchestrationStatus = "active";
485 vfModuleItem.vfModule.isBaseVfModule = true;
486 vfModuleItem.vfModule.resourceVersion = "1485542667";
487 vfModuleItem.vfModule.personaModelId = "79ee24cd-fc9a-4f14-afae-5e1dd2ab2941";
488 vfModuleItem.vfModule.personaModelVersion = "1";
490 vfModuleItem.extraProperties = new AAINQF199ExtraProperties();
491 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "C15ce9e1E9144c8fB8bb..base_vlb..module-0"));
492 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "resource"));
493 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
494 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "79ee24cd-fc9a-4f14-afae-5e1dd2ab2941"));
495 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "5484cabb-1a0d-4f29-a616-094a3f643d73"));
498 AAINQF199InventoryResponseItem vfModuleItem1 = new AAINQF199InventoryResponseItem();
499 //vfModuleItem1.modelName = "vf-module";
500 vfModuleItem1.vfModule = new AAINQF199VfModule();
501 vfModuleItem1.vfModule.vfModuleId = "dummy";
502 vfModuleItem1.vfModule.vfModuleName = "dummy";
503 vfModuleItem1.vfModule.isBaseVfModule = false;
504 vfModuleItem1.vfModule.resourceVersion = "1485561752";
505 vfModuleItem1.vfModule.personaModelId = "f32568ec-2f1c-458a-864b-0593d53d141a";
506 vfModuleItem1.vfModule.personaModelVersion = "1.0";
508 vfModuleItem1.extraProperties = new AAINQF199ExtraProperties();
509 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "C15ce9e1E9144c8fB8bb..dnsscaling..module-1"));
510 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "resource"));
511 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
512 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "f32568ec-2f1c-458a-864b-0593d53d141a"));
513 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "69615025-879d-4f0d-afe3-b7d1a7eeed1f"));
517 AAINQF199InventoryResponseItem vfModuleItem2 = new AAINQF199InventoryResponseItem();
518 //vfModuleItem2.modelName = "vf-module";
519 vfModuleItem2.vfModule = new AAINQF199VfModule();
520 vfModuleItem2.vfModule.vfModuleId = "8cd79e44-1fae-48c1-a160-609f90b46749";
521 vfModuleItem2.vfModule.vfModuleName = "vDNS_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8";
522 vfModuleItem2.vfModule.heatStackId = "vDNS_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8/f447ce51-14dd-4dcd-9957-68a047c79673";
523 vfModuleItem2.vfModule.orchestrationStatus = "active";
524 vfModuleItem2.vfModule.isBaseVfModule = false;
525 vfModuleItem2.vfModule.resourceVersion = "1485562712";
526 vfModuleItem2.vfModule.personaModelId = "f32568ec-2f1c-458a-864b-0593d53d141a";
527 vfModuleItem2.vfModule.personaModelVersion = "1.0";
529 vfModuleItem2.extraProperties = new AAINQF199ExtraProperties();
530 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "C15ce9e1E9144c8fB8bb..dnsscaling..module-1"));
531 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "resource"));
532 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
533 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "f32568ec-2f1c-458a-864b-0593d53d141a"));
534 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "69615025-879d-4f0d-afe3-b7d1a7eeed1f"));
540 AAINQF199InventoryResponseItem genericVNFItem = new AAINQF199InventoryResponseItem();
541 genericVNFItem.modelName = "generic-vnf";
542 genericVNFItem.genericVNF = new AAINQF199GenericVNF();
543 genericVNFItem.genericVNF.vnfID = "594e2fe0-48b8-41ff-82e2-3d4bab69b192";
544 genericVNFItem.genericVNF.vnfName = "Vnf_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8";
545 genericVNFItem.genericVNF.vnfType = "8330e932-2a23-4943-8606/c15ce9e1-e914-4c8f-b8bb 1";
546 genericVNFItem.genericVNF.serviceId = "b3f70641-bdb9-4030-825e-6abb73a1f929";
547 // genericVNFItem.genericVNF.provStatus = "PREPROV";
548 // genericVNFItem.genericVNF.operationalState = "dhv-test-operational-state";
549 // genericVNFItem.genericVNF.ipv4OamAddress = "dhv-test-gvnf-ipv4-oam-address";
550 // genericVNFItem.genericVNF.ipv4Loopback0Address = "dhv-test-gvnfipv4-loopback0-address";
551 genericVNFItem.genericVNF.inMaint = false;
552 genericVNFItem.genericVNF.isClosedLoopDisabled = false;
553 genericVNFItem.genericVNF.resourceVersion = "1485542422";
554 // genericVNFItem.genericVNF.encrypedAccessFlag = true;
555 genericVNFItem.genericVNF.personaModelId = "033a32ed-aa65-4764-a736-36f2942f1aa0";
556 genericVNFItem.genericVNF.personaModelVersion = "1.0";
557 genericVNFItem.extraProperties = new AAINQF199ExtraProperties();
558 genericVNFItem.extraProperties.extraProperty = new LinkedList<AAINQF199ExtraProperty>();
559 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "c15ce9e1-e914-4c8f-b8bb"));
560 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "resource"));
561 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
562 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "033a32ed-aa65-4764-a736-36f2942f1aa0"));
563 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "d4d072dc-4e21-4a03-9524-628985819a8e"));
564 genericVNFItem.items = new AAINQF199InventoryResponseItems();
565 genericVNFItem.items.inventoryResponseItems = new LinkedList<AAINQF199InventoryResponseItem>();
566 genericVNFItem.items.inventoryResponseItems.add(serviceItem);
567 genericVNFItem.items.inventoryResponseItems.add(vfModuleItem);
568 genericVNFItem.items.inventoryResponseItems.add(vfModuleItem1);
569 genericVNFItem.items.inventoryResponseItems.add(vfModuleItem2);
571 AAINQF199InventoryResponseItem cloudItem = new AAINQF199InventoryResponseItem();
572 cloudItem.cloudRegion = new AAINQF199CloudRegion();
573 cloudItem.cloudRegion.cloudOwner = "OWNER";
574 cloudItem.cloudRegion.cloudRegionId = "REGIONID";
575 cloudItem.cloudRegion.cloudRegionVersion = "2.5";
576 cloudItem.cloudRegion.complexName = "COMPLEXNAME";
577 cloudItem.cloudRegion.resourceVersion = "1485465545";
579 AAINQF199InventoryResponseItem tenantItem = new AAINQF199InventoryResponseItem();
580 tenantItem.tenant = new AAINQF199Tenant();
581 tenantItem.tenant.tenantId = "1015548";
582 tenantItem.tenant.tenantName = "1015548";
583 tenantItem.tenant.resourceVersion = "1485465545";
584 tenantItem.items = new AAINQF199InventoryResponseItems();
585 tenantItem.items.inventoryResponseItems = new LinkedList<AAINQF199InventoryResponseItem>();
586 tenantItem.items.inventoryResponseItems.add(cloudItem);
588 AAINQF199InventoryResponseItem vserverItem = new AAINQF199InventoryResponseItem();
589 vserverItem.vserver = new AAINQF199VServer();
590 vserverItem.vserver.vserverId = "70f081eb-2a87-4c81-9296-4b93d7d145c6";
591 vserverItem.vserver.vserverName = "vlb-lb-32c8";
592 vserverItem.vserver.vserverName2 = "vlb-lb-32c8";
593 vserverItem.vserver.provStatus = "ACTIVE";
594 vserverItem.vserver.vserverSelflink = "https://dfw.servers.api.rackspacecloud.com/v2/1015548/servers/70f081eb-2a87-4c81-9296-4b93d7d145c6";
595 vserverItem.vserver.inMaint = false;
596 vserverItem.vserver.isClosedLoopDisabled = false;
597 vserverItem.vserver.resourceVersion = "1485546436";
598 vserverItem.items = new AAINQF199InventoryResponseItems();
599 vserverItem.items.inventoryResponseItems = new LinkedList<AAINQF199InventoryResponseItem>();
600 vserverItem.items.inventoryResponseItems.add(genericVNFItem);
601 vserverItem.items.inventoryResponseItems.add(tenantItem);
603 aainqf199response = new AAINQF199Response();
604 aainqf199response.inventoryResponseItems.add(vserverItem);
606 System.out.println("PAM");
607 System.out.println(Serialization.gsonPretty.toJson(aainqf199response));
609 //////////////////////////////////////////////////////////
617 // Check AAI response
619 if (aainqf199response == null) {
620 System.err.println("Failed to get AAI response");
622 // Fail and retract everything
626 retract($aainqf199RequestWrapper);
629 // Create AAINQF199ResponseWrapper
631 AAINQF199ResponseWrapper aainqf199ResponseWrapper = new AAINQF199ResponseWrapper($event.requestID, aainqf199response);
633 // insert aainqf199ResponseWrapper to memeory
635 insert(aainqf199ResponseWrapper);
641 * This rule happens when we got a valid AAI response. We can start sending request to APPC or MSO now.
644 rule "${policyName}.EVENT.MANAGER.AAINQF199RESPONSE"
646 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
647 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
648 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
649 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
650 $aainqf199ResponseWrapper : AAINQF199ResponseWrapper(requestID == $event.requestID)
652 System.out.println("rule EVENT.MANAGER.AAINQF199RESPONSE is triggered.");
654 // Extract related fields out of AAINQF199RESPONSE
656 String vnfItemVnfId, vnfItemVnfType, vnfItemPersonaModelId, vnfItemPersonaModelVersion, vnfItemModelName,
657 vnfItemModelVersion, vnfItemModelNameVersionId, serviceItemServiceInstanceId, serviceItemPersonaModelId,
658 serviceItemModelName, serviceItemModelType, serviceItemModelVersion, serviceItemModelNameVersionId,
659 vfModuleItemVfModuleName, vfModuleItemPersonaModelId, vfModuleItemPersonaModelVersion, vfModuleItemModelName,
660 vfModuleItemModelNameVersionId, tenantItemTenantId, cloudRegionItemCloudRegionId;
665 vnfItemVnfId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfID;
666 vnfItemVnfType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfType;
667 vnfItemVnfType = vnfItemVnfType.substring(vnfItemVnfType.lastIndexOf("/")+1);
668 vnfItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelId;
669 vnfItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelVersion;
670 vnfItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
671 vnfItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(2).propertyValue;
672 vnfItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
676 serviceItemServiceInstanceId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.serviceInstanceID;
677 serviceItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelId;
678 serviceItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
679 serviceItemModelType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(1).propertyValue;
680 serviceItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelVersion;
681 serviceItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
683 // Find the index for base vf module and non-base vf module
686 int nonBaseIndex = -1;
687 List<AAINQF199InventoryResponseItem> inventoryItems = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems;
688 for (AAINQF199InventoryResponseItem m : inventoryItems) {
689 if (m.vfModule != null && m.vfModule.isBaseVfModule == true) {
690 baseIndex = inventoryItems.indexOf(m);
691 } else if (m.vfModule != null && m.vfModule.isBaseVfModule == false && m.vfModule.orchestrationStatus == null) {
692 nonBaseIndex = inventoryItems.indexOf(m);
695 if (baseIndex != -1 && nonBaseIndex != -1) {
700 // Report the error if either base vf module or non-base vf module is not found
702 if (baseIndex == -1 || nonBaseIndex == -1) {
703 System.err.println("Either base or non-base vf module is not found from AAI response.");
704 retract($aainqf199RequestWrapper);
705 retract($aainqf199ResponseWrapper);
711 // This comes from the base module
713 vfModuleItemVfModuleName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(baseIndex).vfModule.vfModuleName;
714 vfModuleItemVfModuleName = vfModuleItemVfModuleName.replace("Vfmodule", "vDNS");
716 // vfModuleItem - NOT the base module
718 vfModuleItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelId;
719 vfModuleItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelVersion;
720 vfModuleItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(0).propertyValue;
721 vfModuleItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(4).propertyValue;
725 tenantItemTenantId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).tenant.tenantId;
729 cloudRegionItemCloudRegionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).items.inventoryResponseItems.get(0).cloudRegion.cloudRegionId;
731 } catch (Exception e) {
733 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
734 notification.notification = ControlLoopNotificationType.REJECTED;
735 notification.message = "Exception occurred " + e.getMessage();
736 notification.policyName = drools.getRule().getName();
737 notification.policyScope = "${policyScope}";
738 notification.policyVersion = "${policyVersion}";
741 System.out.println(Serialization.gsonPretty.toJson(notification));
742 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
743 } catch (Exception e1) {
744 System.out.println("Can't deliver notification: " + notification);
745 e1.printStackTrace();
748 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
749 notification.message = "Invalid named-query response from AAI";
752 System.out.println(Serialization.gsonPretty.toJson(notification));
753 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
754 } catch (Exception e1) {
755 System.out.println("Can't deliver notification: " + notification);
756 e1.printStackTrace();
759 // Retract everything
761 retract($aainqf199RequestWrapper);
762 retract($aainqf199ResponseWrapper);
768 // Extracted fields should not be null
770 if ((vnfItemVnfId == null) || (vnfItemVnfType == null) ||
771 (vnfItemPersonaModelId == null) || (vnfItemModelName == null) ||
772 (vnfItemModelVersion == null) || (vnfItemModelNameVersionId == null) ||
773 (serviceItemServiceInstanceId == null) || (serviceItemModelName == null) ||
774 (serviceItemModelType == null) || (serviceItemModelVersion == null) ||
775 (serviceItemModelNameVersionId == null) || (vfModuleItemVfModuleName == null) ||
776 (vfModuleItemPersonaModelId == null) || (vfModuleItemPersonaModelVersion == null) ||
777 (vfModuleItemModelName == null) || (vfModuleItemModelNameVersionId == null) ||
778 (tenantItemTenantId == null) || (cloudRegionItemCloudRegionId == null)) {
780 System.err.println("some fields are missing from AAI response.");
782 // Fail and retract everything
784 retract($aainqf199RequestWrapper);
785 retract($aainqf199ResponseWrapper);
791 // We don't need them any more
793 retract($aainqf199ResponseWrapper);
794 retract($aainqf199RequestWrapper);
796 // check the actor of this closed loop
798 switch ($params.getActor()) {
802 // Construct an APPC request
804 ControlLoopOperation operation = new ControlLoopOperation();
805 operation.actor = $params.getActor();
806 operation.operation = "ModifyConfig";
807 operation.target = $event.target;
809 // Create operationWrapper
811 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
813 // insert operationWrapper into memory
815 insert(operationWrapper);
817 Request request = new Request();
818 request.CommonHeader = new CommonHeader();
819 request.CommonHeader.RequestID = $event.requestID;
820 request.Action = operation.operation;
821 request.Payload = new HashMap<String, Object>();
823 // Fill in the payload
824 // Hardcode genericVNF for now since AAI has not been ready for vFirewall demo case
826 String genericVNF = "zdfw1fwl01pgn02";
827 request.Payload.put("generic-vnf.vnf-id", genericVNF);
829 PGRequest pgRequest = new PGRequest();
830 pgRequest.pgStreams = new PGStreams();
833 for(int i = 0; i < 5; i++){
834 pgStream = new PGStream();
835 pgStream.streamId = "fw_udp"+(i+1);
836 pgStream.isEnabled = "true";
837 pgRequest.pgStreams.pgStream.add(pgStream);
839 request.Payload.put("pg-streams", pgRequest.pgStreams);
841 if (request != null) {
843 // Insert request into memory
847 // Tell interested parties we are performing this Operation
849 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
850 notification.notification = ControlLoopNotificationType.OPERATION;
851 // message and history ??
852 notification.from = "policy";
853 notification.policyName = drools.getRule().getName();
854 notification.policyScope = "${policyScope}";
855 notification.policyVersion = "${policyVersion}";
857 System.out.println(Serialization.gsonPretty.toJson(notification));
858 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
859 } catch (Exception e) {
860 System.out.println("Can't deliver notification: " + notification);
864 // Now send the operation request
866 if (request instanceof Request) {
868 System.out.println("APPC request sent:");
869 System.out.println(Serialization.gsonPretty.toJson(request));
870 //PolicyEngine.manager.deliver($params.getAppcTopic(), request);
871 } catch (Exception e) {
873 System.out.println("Can't deliver request: " + request);
878 // what happens if it is null
886 // Construct an operation
888 ControlLoopOperation operation = new ControlLoopOperation();
889 operation.actor = $params.getActor();
890 operation.operation = "createModuleInstance";
891 operation.target = $event.target;
893 // Create operationWrapper
895 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
897 // Construct an MSO request
899 MSORequest request = new MSORequest();
900 request.requestDetails = new MSORequestDetails();
901 request.requestDetails.modelInfo = new MSOModelInfo();
902 request.requestDetails.cloudConfiguration = new MSOCloudConfiguration();
903 request.requestDetails.requestInfo = new MSORequestInfo();
904 request.requestDetails.requestParameters = new MSORequestParameters();
905 request.requestDetails.requestParameters.userParams = null;
907 // cloudConfiguration
909 request.requestDetails.cloudConfiguration.lcpCloudRegionId = cloudRegionItemCloudRegionId;
910 request.requestDetails.cloudConfiguration.tenantId = tenantItemTenantId;
914 request.requestDetails.modelInfo.modelType = "vfModule";
915 request.requestDetails.modelInfo.modelInvariantId = vfModuleItemPersonaModelId;
916 request.requestDetails.modelInfo.modelNameVersionId = vfModuleItemModelNameVersionId;
917 request.requestDetails.modelInfo.modelName = vfModuleItemModelName;
918 request.requestDetails.modelInfo.modelVersion = vfModuleItemPersonaModelVersion;
922 request.requestDetails.requestInfo.instanceName = vfModuleItemVfModuleName;
923 request.requestDetails.requestInfo.source = "POLICY";
924 request.requestDetails.requestInfo.suppressRollback = false;
926 // relatedInstanceList
928 MSORelatedInstanceListElement relatedInstanceListElement1 = new MSORelatedInstanceListElement();
929 MSORelatedInstanceListElement relatedInstanceListElement2 = new MSORelatedInstanceListElement();
930 relatedInstanceListElement1.relatedInstance = new MSORelatedInstance();
931 relatedInstanceListElement2.relatedInstance = new MSORelatedInstance();
933 relatedInstanceListElement1.relatedInstance.instanceId = serviceItemServiceInstanceId;
934 relatedInstanceListElement1.relatedInstance.modelInfo = new MSOModelInfo();
935 relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service";
936 relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = serviceItemPersonaModelId;
937 relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = serviceItemModelNameVersionId;
938 relatedInstanceListElement1.relatedInstance.modelInfo.modelName = serviceItemModelName;
939 relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = serviceItemModelVersion;
941 relatedInstanceListElement2.relatedInstance.instanceId = vnfItemVnfId;
942 relatedInstanceListElement2.relatedInstance.modelInfo = new MSOModelInfo();
943 relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf";
944 relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = vnfItemPersonaModelId;
945 relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = vnfItemModelNameVersionId;
946 relatedInstanceListElement2.relatedInstance.modelInfo.modelName = vnfItemModelName;
947 relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = vnfItemModelVersion;
948 relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = vnfItemVnfType;
950 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1);
951 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2);
953 // print MSO request for debug
955 System.out.println("MSO request sent:");
956 System.out.println(Serialization.gsonPretty.toJson(request));
960 if (request != null) {
962 // Tell interested parties we are performing this Operation
964 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
965 notification.notification = ControlLoopNotificationType.OPERATION;
966 notification.from = "policy";
967 notification.policyName = drools.getRule().getName();
968 notification.policyScope = "${policyScope}";
969 notification.policyVersion = "${policyVersion}";
971 System.out.println(Serialization.gsonPretty.toJson(notification));
972 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
973 } catch (Exception e) {
974 System.out.println("Can't deliver notification: " + notification);
978 // Concatenate serviceItemServiceInstanceId and vnfItemVnfId to msoURL
980 String MSOUrl = $params.getMsoURL() + "/serviceInstances/v2/" + serviceItemServiceInstanceId + "/vnfs/" + vnfItemVnfId + "/vfModules";
984 MSOResponse response = MSOManager.createModuleInstance(MSOUrl, $params.getMsoURL(), $params.getMsoUsername(), $params.getMsoPassword(), request);
989 //////////////////////////////////////////////////////////
990 // Simulate a valid MSOResponse for junit test
991 // Remove this for real deployment
993 response = new MSOResponse();
994 response.request = new MSORequest();
995 response.request.requestStatus = new MSORequestStatus();
996 response.request.requestStatus.requestState = "COMPLETE";
997 //////////////////////////////////////////////////////////
1003 if (response != null) {
1007 request.requestId = $event.requestID.toString();
1008 response.request.requestId = $event.requestID.toString();
1012 insert(operationWrapper);
1017 // MSO request not even accepted
1019 notification.message = operationWrapper.operation.toMessage();
1020 operationWrapper.operation.message = operationWrapper.operation.toMessage();
1021 operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
1022 $manager.setControlLoopResult("FAILURE_EXCEPTION");
1023 notification.history.add(operationWrapper.operation);
1024 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
1026 // Let interested parties know
1029 System.out.println(Serialization.gsonPretty.toJson(notification));
1030 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1031 } catch (Exception e) {
1032 System.out.println("Can't deliver notification: " + notification);
1033 e.printStackTrace();
1035 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
1037 System.out.println(Serialization.gsonPretty.toJson(notification));
1038 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1039 } catch (Exception e) {
1040 System.out.println("Can't deliver notification: " + notification);
1041 e.printStackTrace();
1044 // Retract everything
1050 System.err.println("constructed MSO request is invalid.");
1059 * This rule responds to APPC Response Events
1062 rule "${policyName}.APPC.RESPONSE"
1064 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
1065 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
1066 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
1067 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
1068 $request : Request( getCommonHeader().RequestID == $event.requestID )
1069 $response : Response( getCommonHeader().RequestID == $event.requestID )
1071 System.out.println("rule APPC.RESPONSE is triggered.");
1072 if ($response.Status == null) {
1073 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
1074 $manager.setControlLoopResult("FAILURE_EXCEPTION");
1077 // Get the Response Code
1079 ResponseCode code = ResponseCode.toResponseCode($response.Status.Code);
1081 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
1082 $manager.setControlLoopResult("FAILURE_EXCEPTION");
1085 // Construct notification
1087 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
1088 notification.from = "policy";
1089 notification.policyName = drools.getRule().getName();
1090 notification.policyScope = "${policyScope}";
1091 notification.policyVersion = "${policyVersion}";
1092 notification.message = $operationWrapper.operation.toMessage();
1093 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
1095 // Ok, let's figure out what APP-C's response is
1099 $operationWrapper.operation.outcome = "PROCESSING";
1103 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
1104 $manager.setControlLoopResult("FAILURE_EXCEPTION");
1107 $operationWrapper.operation.outcome = "SUCCESS";
1108 $manager.setControlLoopResult("SUCCESS");
1111 $operationWrapper.operation.outcome = "FAILURE";
1112 $manager.setControlLoopResult("FAILURE");
1115 if ($operationWrapper.operation.outcome.equals("SUCCESS")) {
1116 notification.history.add($operationWrapper.operation);
1117 notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
1119 // Let interested parties know
1122 System.out.println(Serialization.gsonPretty.toJson(notification));
1123 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1124 } catch (Exception e) {
1125 System.out.println("Can't deliver notification: " + notification);
1126 e.printStackTrace();
1128 notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
1130 System.out.println(Serialization.gsonPretty.toJson(notification));
1131 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1132 } catch (Exception e) {
1133 System.out.println("Can't deliver notification: " + notification);
1134 e.printStackTrace();
1138 // We are going to retract these objects from memory
1140 System.out.println("Retracting everything");
1141 retract($operationWrapper);
1146 } else if ($operationWrapper.operation.outcome.equals("PROCESSING")) {
1149 notification.history.add($operationWrapper.operation);
1150 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
1152 // Let interested parties know
1155 System.out.println(Serialization.gsonPretty.toJson(notification));
1156 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1157 } catch (Exception e) {
1158 System.out.println("Can't deliver notification: " + notification);
1159 e.printStackTrace();
1161 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
1163 // Let interested parties know
1166 System.out.println(Serialization.gsonPretty.toJson(notification));
1167 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1168 } catch (Exception e) {
1169 System.out.println("Can't deliver notification: " + notification);
1170 e.printStackTrace();
1173 // We are going to retract these objects from memory
1175 System.out.println("Retracting everything");
1176 retract($operationWrapper);
1187 * This rule is used to clean up APPC response
1190 rule "${policyName}.APPC.RESPONSE.CLEANUP"
1192 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
1193 $response : Response($id : getCommonHeader().RequestID )
1194 not ( VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), requestID == $id, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) )
1196 System.out.println("rule APPC.RESPONSE.CLEANUP is triggered.");
1202 * This rule responds to MSO Response Events
1205 rule "${policyName}.MSO.RESPONSE"
1207 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
1208 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
1209 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
1210 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
1211 $request : MSORequest( requestId == $event.requestID.toString() )
1212 $response : MSOResponse( request.requestId == $event.requestID.toString() )
1214 System.out.println("rule MSO.RESPONSE is triggered.");
1216 // Construct notification
1218 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
1219 notification.from = "policy";
1220 notification.policyName = drools.getRule().getName();
1221 notification.policyScope = "${policyScope}";
1222 notification.policyVersion = "${policyVersion}";
1223 notification.message = $operationWrapper.operation.toMessage();
1224 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
1226 // The operation can either be succeeded or failed
1228 if($response.request.requestStatus.requestState.equals("COMPLETE")) {
1229 $operationWrapper.operation.outcome = "SUCCESS";
1230 $manager.setControlLoopResult("SUCCESS");
1231 notification.history.add($operationWrapper.operation);
1232 notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
1234 // Let interested parties know
1237 System.out.println(Serialization.gsonPretty.toJson(notification));
1238 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1239 } catch (Exception e) {
1240 System.out.println("Can't deliver notification: " + notification);
1241 e.printStackTrace();
1243 notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
1245 // Let interested parties know
1248 System.out.println(Serialization.gsonPretty.toJson(notification));
1249 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1250 } catch (Exception e) {
1251 System.out.println("Can't deliver notification: " + notification);
1252 e.printStackTrace();
1255 // We are going to retract these objects from memory
1257 System.out.println("Retracting everything");
1258 retract($operationWrapper);
1264 $operationWrapper.operation.outcome = "FAILURE";
1265 $manager.setControlLoopResult("FAILURE");
1266 notification.history.add($operationWrapper.operation);
1267 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
1269 // Let interested parties know
1272 System.out.println(Serialization.gsonPretty.toJson(notification));
1273 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1274 } catch (Exception e) {
1275 System.out.println("Can't deliver notification: " + notification);
1276 e.printStackTrace();
1278 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
1280 // Let interested parties know
1283 System.out.println(Serialization.gsonPretty.toJson(notification));
1284 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1285 } catch (Exception e) {
1286 System.out.println("Can't deliver notification: " + notification);
1287 e.printStackTrace();
1290 // We are going to retract these objects from memory
1292 System.out.println("Retracting everything");
1293 retract($operationWrapper);
1302 * Sample Queries for illustration with and without arguments
1303 * The results of the query can be introspected (and retracted if desired)
1306 query "${policyName}.QUERY.EVENT.ONSET"
1307 event : VirtualControlLoopEvent( closedLoopEventStatus == ControlLoopEventStatus.ONSET )
1310 query "${policyName}.QUERY.MANAGER.RNA" (String aRequestId, Integer numOnsetsLowerBound, Boolean aActivated)
1311 manager : ControlLoopEventManager( closedLoopControlName == "${closedLoopControlName}",
1312 requestID.toString() == aRequestId,
1313 numOnsets > numOnsetsLowerBound,
1314 activated == aActivated )