2 * ============LICENSE_START=======================================================
3 * archetype-closed-loop-demo-rules
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop;
23 import java.util.List;
24 import java.util.LinkedList;
26 import java.util.HashMap;
27 import java.util.UUID;
29 import org.onap.policy.controlloop.VirtualControlLoopEvent;
30 import org.onap.policy.controlloop.ControlLoopEventStatus;
31 import org.onap.policy.controlloop.VirtualControlLoopNotification;
32 import org.onap.policy.controlloop.ControlLoopNotificationType;
33 import org.onap.policy.controlloop.ControlLoopOperation;
34 import org.onap.policy.controlloop.ControlLoopOperationWrapper;
35 import org.onap.policy.controlloop.ControlLoopException;
37 import org.onap.policy.aai.AAINQF199.AAINQF199CloudRegion;
38 import org.onap.policy.aai.AAINQF199.AAINQF199ExtraProperties;
39 import org.onap.policy.aai.AAINQF199.AAINQF199ExtraProperty;
40 import org.onap.policy.aai.AAINQF199.AAINQF199GenericVNF;
41 import org.onap.policy.aai.AAINQF199.AAINQF199InstanceFilters;
42 import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItem;
43 import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItems;
44 import org.onap.policy.aai.AAINQF199.AAINQF199Manager;
45 import org.onap.policy.aai.AAINQF199.AAINQF199NamedQuery;
46 import org.onap.policy.aai.AAINQF199.AAINQF199QueryParameters;
47 import org.onap.policy.aai.AAINQF199.AAINQF199Request;
48 import org.onap.policy.aai.AAINQF199.AAINQF199RequestWrapper;
49 import org.onap.policy.aai.AAINQF199.AAINQF199Response;
50 import org.onap.policy.aai.AAINQF199.AAINQF199ResponseWrapper;
51 import org.onap.policy.aai.AAINQF199.AAINQF199ServiceInstance;
52 import org.onap.policy.aai.AAINQF199.AAINQF199Tenant;
53 import org.onap.policy.aai.AAINQF199.AAINQF199VfModule;
54 import org.onap.policy.aai.AAINQF199.AAINQF199VServer;
55 import org.onap.policy.aai.util.Serialization;
57 import org.onap.policy.appc.CommonHeader;
58 import org.onap.policy.appc.Request;
59 import org.onap.policy.appc.Response;
60 import org.onap.policy.appc.ResponseCode;
61 import org.onap.policy.appc.ResponseStatus;
62 import org.onap.policy.appc.ResponseValue;
64 import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager;
65 import org.onap.policy.vnf.trafficgenerator.PGRequest;
66 import org.onap.policy.vnf.trafficgenerator.PGStream;
67 import org.onap.policy.vnf.trafficgenerator.PGStreams;
69 import org.onap.policy.mso.MSOManager;
70 import org.onap.policy.mso.MSORequest;
71 import org.onap.policy.mso.MSORequestStatus;
72 import org.onap.policy.mso.MSORequestDetails;
73 import org.onap.policy.mso.MSOModelInfo;
74 import org.onap.policy.mso.MSOCloudConfiguration;
75 import org.onap.policy.mso.MSORequestInfo;
76 import org.onap.policy.mso.MSORequestParameters;
77 import org.onap.policy.mso.MSORelatedInstanceListElement;
78 import org.onap.policy.mso.MSORelatedInstance;
79 import org.onap.policy.mso.MSOResponse;
81 //import org.openecomp.policy.drools.system.PolicyEngine;
84 // These parameters are required to build the runtime policy
87 closedLoopControlName : String
95 aaiNamedQueryUUID : String
97 notificationTopic : String
103 * Called once and only once to insert the parameters into working memory for this Closed Loop policy.
104 * NOTE: If this file is to be used as a template to be used with the policy BRMS GW, please comment out this line
105 * as the BRMS_GW already generates a SETUP rule
108 rule "${policyName}.SETUP"
111 System.out.println("rule SETUP is triggered.");
112 Params params = new Params();
113 params.setClosedLoopControlName("${closedLoopControlName}");
114 params.setActor("${actor}");
115 params.setAaiURL("${aaiURL}");
116 params.setAaiUsername("${aaiUsername}");
117 params.setAaiPassword("${aaiPassword}");
118 params.setMsoURL("${msoURL}");
119 params.setMsoUsername("${msoUsername}");
120 params.setMsoPassword("${msoPassword}");
121 params.setAaiNamedQueryUUID("${aaiNamedQueryUUID}");
122 params.setAaiPatternMatch(${aaiPatternMatch});
123 params.setNotificationTopic("${notificationTopic}");
124 params.setAppcTopic("${appcTopic}");
126 // This stays in memory as long as the rule is alive and running
134 * This rule responds to DCAE Events
137 rule "${policyName}.EVENT"
139 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
140 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
141 not ( ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ))
143 System.out.println("rule EVENT is triggered.");
146 // Check the requestID in the event to make sure it is not null before we create the EventManager.
147 // The EventManager will do extra syntax checking as well check if the closed loop is disabled/
149 if ($event.requestID == null) {
150 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
151 notification.notification = ControlLoopNotificationType.REJECTED;
152 notification.from = "policy";
153 notification.message = "Missing requestID from DCAE event";
154 notification.policyName = drools.getRule().getName();
155 notification.policyScope = "${policyScope}";
156 notification.policyVersion = "${policyVersion}";
158 // Let interested parties know
161 System.out.println(Serialization.gsonPretty.toJson(notification));
162 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
163 } catch (Exception e) {
165 System.out.println("Can't deliver notification: " + notification);
168 // Retract it from memory
171 System.out.println("Event with requestID=null has been retracted.");
174 // Create an EventManager
176 ControlLoopEventManager manager = new ControlLoopEventManager($params.getClosedLoopControlName(), $event.requestID);
178 // Determine if EventManager can actively process the event (i.e. syntax)
180 VirtualControlLoopNotification notification = manager.activate($event);
181 notification.from = "policy";
182 notification.policyName = drools.getRule().getName();
183 notification.policyScope = "${policyScope}";
184 notification.policyVersion = "${policyVersion}";
186 // Are we actively pursuing this event?
188 if (notification.notification == ControlLoopNotificationType.ACTIVE) {
190 // Insert Event Manager into memory, this will now kick off processing.
194 // Let interested parties know
197 System.out.println(Serialization.gsonPretty.toJson(notification));
198 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
199 } catch (Exception e) {
201 System.out.println("Can't deliver notification: " + notification);
205 // Let interested parties know
208 System.out.println(Serialization.gsonPretty.toJson(notification));
209 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
210 } catch (Exception e) {
212 System.out.println("Can't deliver notification: " + notification);
215 // Retract it from memory
220 // Now that the manager is inserted into Drools working memory, we'll wait for
221 // another rule to fire in order to continue processing. This way we can also
222 // then screen for additional ONSET and ABATED events for this same RequestIDs
223 // and for different RequestIDs but with the same closedLoopControlName and target.
227 } catch (Exception e) {
229 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
230 notification.notification = ControlLoopNotificationType.REJECTED;
231 notification.message = "Exception occurred " + e.getMessage();
232 notification.policyName = drools.getRule().getName();
233 notification.policyScope = "${policyScope}";
234 notification.policyVersion = "${policyVersion}";
239 System.out.println(Serialization.gsonPretty.toJson(notification));
240 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
241 } catch (Exception e1) {
242 System.out.println("Can't deliver notification: " + notification);
243 e1.printStackTrace();
254 * This rule happens when we got a valid ONSET, closed loop is enabled and an Event Manager
255 * is created. We can start the operations for this closed loop.
258 rule "${policyName}.EVENT.MANAGER"
260 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
261 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
262 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, controlLoopResult == null)
264 System.out.println("rule EVENT.MANAGER is triggered.");
266 // Check which event this is.
268 ControlLoopEventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event);
270 // We only want the initial ONSET event in memory,
271 // all the other events need to be retracted to support
272 // cleanup and avoid the other rules being fired for this event.
274 if (eventStatus != ControlLoopEventManager.NEW_EVENT_STATUS.FIRST_ONSET) {
275 System.out.println("Retracting "+eventStatus+" Event.");
280 // Now the event in memory is first onset event
284 // Pull the known AAI field from the Event
286 // generic-vnf is needed for vFirewall case
287 // vserver-name is needed for vLoadBalancer case
289 String genericVNF = $event.AAI.get("generic-vnf.vnf-id");
290 String vserver = $event.AAI.get("vserver.vserver-name");
292 // Check if we are implementing a simple pattern match.
294 if ($params.getAaiPatternMatch() == 1) {
298 //Basic naming characteristics:
299 //VF Name (9 char)+VM name (13 char total)+VFC (19 char total)
301 //VF Name (9 characters): cscf0001v
302 //VM Name(13 characters): cscf0001vm001
303 //VFC name(19 characters): cscf0001vm001cfg001
305 // zdfw1fwl01fwl02 or zdfw1fwl01fwl01
307 // zdfw1fwl01pgn02 or zdfw1fwl01pgn01
309 int index = genericVNF.lastIndexOf("fwl");
311 System.err.println("The generic-vnf.vnf-id from DCAE Event is not valid.");
313 genericVNF = genericVNF.substring(0, index) + "pgn" + genericVNF.substring(index+"fwl".length());
316 // Construct an APPC request
318 ControlLoopOperation operation = new ControlLoopOperation();
319 operation.actor = $params.getActor();
320 operation.operation = "ModifyConfig";
321 operation.target = $event.target;
323 // Create operationWrapper
325 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
327 // insert operationWrapper into memory
329 insert(operationWrapper);
331 Request request = new Request();
332 request.CommonHeader = new CommonHeader();
333 request.CommonHeader.RequestID = $event.requestID;
334 request.Action = operation.operation;
335 request.Payload = new HashMap<String, Object>();
337 // Fill in the payload
339 request.Payload.put("generic-vnf.vnf-id", genericVNF);
341 PGRequest pgRequest = new PGRequest();
342 pgRequest.pgStreams = new PGStreams();
345 for(int i = 0; i < 5; i++){
346 pgStream = new PGStream();
347 pgStream.streamId = "fw_udp"+(i+1);
348 pgStream.isEnabled = "true";
349 pgRequest.pgStreams.pgStream.add(pgStream);
351 request.Payload.put("pg-streams", pgRequest.pgStreams);
353 if (request != null) {
355 // Insert request into memory
359 // Tell interested parties we are performing this Operation
361 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
362 notification.notification = ControlLoopNotificationType.OPERATION;
363 // message and history ??
364 notification.from = "policy";
365 notification.policyName = drools.getRule().getName();
366 notification.policyScope = "${policyScope}";
367 notification.policyVersion = "${policyVersion}";
369 System.out.println(Serialization.gsonPretty.toJson(notification));
370 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
371 } catch (Exception e) {
372 System.out.println("Can't deliver notification: " + notification);
376 // Now send the operation request
378 if (request instanceof Request) {
380 System.out.println("APPC request sent:");
381 System.out.println(Serialization.gsonPretty.toJson(request));
382 //PolicyEngine.manager.deliver($params.getAppcTopic(), request);
383 } catch (Exception e) {
385 System.out.println("Can't deliver request: " + request);
390 // what happens if it is null
396 // create AAI named-query request with UUID started with "F199"
398 AAINQF199Request aainqf199request = new AAINQF199Request();
399 AAINQF199QueryParameters aainqf199queryparam = new AAINQF199QueryParameters();
400 AAINQF199NamedQuery aainqf199namedquery = new AAINQF199NamedQuery();
401 AAINQF199InstanceFilters aainqf199instancefilter = new AAINQF199InstanceFilters();
405 aainqf199namedquery.namedQueryUUID = UUID.fromString($params.getAaiNamedQueryUUID());
406 aainqf199queryparam.namedQuery = aainqf199namedquery;
407 aainqf199request.queryParameters = aainqf199queryparam;
411 Map aainqf199instancefiltermap = new HashMap();
412 Map aainqf199instancefiltermapitem = new HashMap();
413 aainqf199instancefiltermapitem.put("vserver-name", vserver);
414 aainqf199instancefiltermap.put("vserver", aainqf199instancefiltermapitem);
415 aainqf199instancefilter.instanceFilter.add(aainqf199instancefiltermap);
416 aainqf199request.instanceFilters = aainqf199instancefilter;
418 // print aainqf199request for debug
420 System.out.println("AAI Request sent:");
421 System.out.println(Serialization.gsonPretty.toJson(aainqf199request));
423 // Create AAINQF199RequestWrapper
425 AAINQF199RequestWrapper aainqf199RequestWrapper = new AAINQF199RequestWrapper($event.requestID, aainqf199request);
427 // insert aainqf199request into memory
429 insert(aainqf199RequestWrapper);
432 } catch (Exception e) {
439 * This rule happens when we got a valid ONSET, closed loop is enabled, an Event Manager
440 * is created, AAI Manager and AAI Request are ready in memory. We can start sending query to AAI and then wait for response.
443 rule "${policyName}.EVENT.MANAGER.AAINQF199REQUEST"
445 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
446 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
447 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
448 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
450 System.out.println("rule EVENT.MANAGER.AAINQF199REQUEST is triggered.");
454 AAINQF199Response aainqf199response = AAINQF199Manager.postQuery($params.getAaiURL(), $params.getAaiUsername(), $params.getAaiPassword(),
455 $aainqf199RequestWrapper.aainqf199request, $event.requestID);
459 //////////////////////////////////////////////////////////
460 // Simulate a valid aainqf199response for junit test
461 // Remove this for real deployment
464 AAINQF199InventoryResponseItem serviceItem = new AAINQF199InventoryResponseItem();
465 serviceItem.modelName = "service-instance";
466 serviceItem.serviceInstance = new AAINQF199ServiceInstance();
467 serviceItem.serviceInstance.serviceInstanceID = "cf8426a6-0b53-4e3d-bfa6-4b2f4d5913a5";
468 serviceItem.serviceInstance.serviceInstanceName = "Service_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8";
469 serviceItem.serviceInstance.personaModelId = "4fcbc1c0-7793-46d8-8aa1-fa1c2ed9ec7b";
470 serviceItem.serviceInstance.personaModelVersion = "1.0";
471 serviceItem.serviceInstance.resourceVersion = "1485542400";
472 serviceItem.extraProperties = new AAINQF199ExtraProperties();
473 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "8330e932-2a23-4943-8606"));
474 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "service"));
475 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
476 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "4fcbc1c0-7793-46d8-8aa1-fa1c2ed9ec7b"));
477 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "5c996219-b2e2-4c76-9b43-7e8672a33c1d"));
479 AAINQF199InventoryResponseItem vfModuleItem = new AAINQF199InventoryResponseItem();
480 vfModuleItem.modelName = "C15ce9e1E9144c8fB8bb..base_vlb..module-0";
481 vfModuleItem.vfModule = new AAINQF199VfModule();
482 vfModuleItem.vfModule.vfModuleId = "b0eff878-e2e1-4947-9597-39afdd0f51dd";
483 vfModuleItem.vfModule.vfModuleName = "Vfmodule_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8";
484 vfModuleItem.vfModule.heatStackId = "Vfmodule_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8/5845f37b-6cda-4e91-8ca3-f5572d226488";
485 vfModuleItem.vfModule.orchestrationStatus = "active";
486 vfModuleItem.vfModule.isBaseVfModule = true;
487 vfModuleItem.vfModule.resourceVersion = "1485542667";
488 vfModuleItem.vfModule.personaModelId = "79ee24cd-fc9a-4f14-afae-5e1dd2ab2941";
489 vfModuleItem.vfModule.personaModelVersion = "1";
491 vfModuleItem.extraProperties = new AAINQF199ExtraProperties();
492 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "C15ce9e1E9144c8fB8bb..base_vlb..module-0"));
493 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "resource"));
494 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
495 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "79ee24cd-fc9a-4f14-afae-5e1dd2ab2941"));
496 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "5484cabb-1a0d-4f29-a616-094a3f643d73"));
499 AAINQF199InventoryResponseItem vfModuleItem1 = new AAINQF199InventoryResponseItem();
500 //vfModuleItem1.modelName = "vf-module";
501 vfModuleItem1.vfModule = new AAINQF199VfModule();
502 vfModuleItem1.vfModule.vfModuleId = "dummy";
503 vfModuleItem1.vfModule.vfModuleName = "dummy";
504 vfModuleItem1.vfModule.isBaseVfModule = false;
505 vfModuleItem1.vfModule.resourceVersion = "1485561752";
506 vfModuleItem1.vfModule.personaModelId = "f32568ec-2f1c-458a-864b-0593d53d141a";
507 vfModuleItem1.vfModule.personaModelVersion = "1.0";
509 vfModuleItem1.extraProperties = new AAINQF199ExtraProperties();
510 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "C15ce9e1E9144c8fB8bb..dnsscaling..module-1"));
511 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "resource"));
512 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
513 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "f32568ec-2f1c-458a-864b-0593d53d141a"));
514 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "69615025-879d-4f0d-afe3-b7d1a7eeed1f"));
518 AAINQF199InventoryResponseItem vfModuleItem2 = new AAINQF199InventoryResponseItem();
519 //vfModuleItem2.modelName = "vf-module";
520 vfModuleItem2.vfModule = new AAINQF199VfModule();
521 vfModuleItem2.vfModule.vfModuleId = "8cd79e44-1fae-48c1-a160-609f90b46749";
522 vfModuleItem2.vfModule.vfModuleName = "vDNS_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8";
523 vfModuleItem2.vfModule.heatStackId = "vDNS_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8/f447ce51-14dd-4dcd-9957-68a047c79673";
524 vfModuleItem2.vfModule.orchestrationStatus = "active";
525 vfModuleItem2.vfModule.isBaseVfModule = false;
526 vfModuleItem2.vfModule.resourceVersion = "1485562712";
527 vfModuleItem2.vfModule.personaModelId = "f32568ec-2f1c-458a-864b-0593d53d141a";
528 vfModuleItem2.vfModule.personaModelVersion = "1.0";
530 vfModuleItem2.extraProperties = new AAINQF199ExtraProperties();
531 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "C15ce9e1E9144c8fB8bb..dnsscaling..module-1"));
532 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "resource"));
533 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
534 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "f32568ec-2f1c-458a-864b-0593d53d141a"));
535 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "69615025-879d-4f0d-afe3-b7d1a7eeed1f"));
541 AAINQF199InventoryResponseItem genericVNFItem = new AAINQF199InventoryResponseItem();
542 genericVNFItem.modelName = "generic-vnf";
543 genericVNFItem.genericVNF = new AAINQF199GenericVNF();
544 genericVNFItem.genericVNF.vnfID = "594e2fe0-48b8-41ff-82e2-3d4bab69b192";
545 genericVNFItem.genericVNF.vnfName = "Vnf_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8";
546 genericVNFItem.genericVNF.vnfType = "8330e932-2a23-4943-8606/c15ce9e1-e914-4c8f-b8bb 1";
547 genericVNFItem.genericVNF.serviceId = "b3f70641-bdb9-4030-825e-6abb73a1f929";
548 // genericVNFItem.genericVNF.provStatus = "PREPROV";
549 // genericVNFItem.genericVNF.operationalState = "dhv-test-operational-state";
550 // genericVNFItem.genericVNF.ipv4OamAddress = "dhv-test-gvnf-ipv4-oam-address";
551 // genericVNFItem.genericVNF.ipv4Loopback0Address = "dhv-test-gvnfipv4-loopback0-address";
552 genericVNFItem.genericVNF.inMaint = false;
553 genericVNFItem.genericVNF.isClosedLoopDisabled = false;
554 genericVNFItem.genericVNF.resourceVersion = "1485542422";
555 // genericVNFItem.genericVNF.encrypedAccessFlag = true;
556 genericVNFItem.genericVNF.personaModelId = "033a32ed-aa65-4764-a736-36f2942f1aa0";
557 genericVNFItem.genericVNF.personaModelVersion = "1.0";
558 genericVNFItem.extraProperties = new AAINQF199ExtraProperties();
559 genericVNFItem.extraProperties.extraProperty = new LinkedList<AAINQF199ExtraProperty>();
560 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "c15ce9e1-e914-4c8f-b8bb"));
561 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "resource"));
562 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
563 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "033a32ed-aa65-4764-a736-36f2942f1aa0"));
564 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "d4d072dc-4e21-4a03-9524-628985819a8e"));
565 genericVNFItem.items = new AAINQF199InventoryResponseItems();
566 genericVNFItem.items.inventoryResponseItems = new LinkedList<AAINQF199InventoryResponseItem>();
567 genericVNFItem.items.inventoryResponseItems.add(serviceItem);
568 genericVNFItem.items.inventoryResponseItems.add(vfModuleItem);
569 genericVNFItem.items.inventoryResponseItems.add(vfModuleItem1);
570 genericVNFItem.items.inventoryResponseItems.add(vfModuleItem2);
572 AAINQF199InventoryResponseItem cloudItem = new AAINQF199InventoryResponseItem();
573 cloudItem.cloudRegion = new AAINQF199CloudRegion();
574 cloudItem.cloudRegion.cloudOwner = "OWNER";
575 cloudItem.cloudRegion.cloudRegionId = "REGIONID";
576 cloudItem.cloudRegion.cloudRegionVersion = "2.5";
577 cloudItem.cloudRegion.complexName = "COMPLEXNAME";
578 cloudItem.cloudRegion.resourceVersion = "1485465545";
580 AAINQF199InventoryResponseItem tenantItem = new AAINQF199InventoryResponseItem();
581 tenantItem.tenant = new AAINQF199Tenant();
582 tenantItem.tenant.tenantId = "1015548";
583 tenantItem.tenant.tenantName = "1015548";
584 tenantItem.tenant.resourceVersion = "1485465545";
585 tenantItem.items = new AAINQF199InventoryResponseItems();
586 tenantItem.items.inventoryResponseItems = new LinkedList<AAINQF199InventoryResponseItem>();
587 tenantItem.items.inventoryResponseItems.add(cloudItem);
589 AAINQF199InventoryResponseItem vserverItem = new AAINQF199InventoryResponseItem();
590 vserverItem.vserver = new AAINQF199VServer();
591 vserverItem.vserver.vserverId = "70f081eb-2a87-4c81-9296-4b93d7d145c6";
592 vserverItem.vserver.vserverName = "vlb-lb-32c8";
593 vserverItem.vserver.vserverName2 = "vlb-lb-32c8";
594 vserverItem.vserver.provStatus = "ACTIVE";
595 vserverItem.vserver.vserverSelflink = "https://dfw.servers.api.rackspacecloud.com/v2/1015548/servers/70f081eb-2a87-4c81-9296-4b93d7d145c6";
596 vserverItem.vserver.inMaint = false;
597 vserverItem.vserver.isClosedLoopDisabled = false;
598 vserverItem.vserver.resourceVersion = "1485546436";
599 vserverItem.items = new AAINQF199InventoryResponseItems();
600 vserverItem.items.inventoryResponseItems = new LinkedList<AAINQF199InventoryResponseItem>();
601 vserverItem.items.inventoryResponseItems.add(genericVNFItem);
602 vserverItem.items.inventoryResponseItems.add(tenantItem);
604 aainqf199response = new AAINQF199Response();
605 aainqf199response.inventoryResponseItems.add(vserverItem);
607 System.out.println("PAM");
608 System.out.println(Serialization.gsonPretty.toJson(aainqf199response));
610 //////////////////////////////////////////////////////////
618 // Check AAI response
620 if (aainqf199response == null) {
621 System.err.println("Failed to get AAI response");
623 // Fail and retract everything
627 retract($aainqf199RequestWrapper);
630 // Create AAINQF199ResponseWrapper
632 AAINQF199ResponseWrapper aainqf199ResponseWrapper = new AAINQF199ResponseWrapper($event.requestID, aainqf199response);
634 // insert aainqf199ResponseWrapper to memeory
636 insert(aainqf199ResponseWrapper);
642 * This rule happens when we got a valid AAI response. We can start sending request to APPC or MSO now.
645 rule "${policyName}.EVENT.MANAGER.AAINQF199RESPONSE"
647 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
648 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
649 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
650 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
651 $aainqf199ResponseWrapper : AAINQF199ResponseWrapper(requestID == $event.requestID)
653 System.out.println("rule EVENT.MANAGER.AAINQF199RESPONSE is triggered.");
655 // Extract related fields out of AAINQF199RESPONSE
657 String vnfItemVnfId, vnfItemVnfType, vnfItemPersonaModelId, vnfItemPersonaModelVersion, vnfItemModelName,
658 vnfItemModelVersion, vnfItemModelNameVersionId, serviceItemServiceInstanceId, serviceItemPersonaModelId,
659 serviceItemModelName, serviceItemModelType, serviceItemModelVersion, serviceItemModelNameVersionId,
660 vfModuleItemVfModuleName, vfModuleItemPersonaModelId, vfModuleItemPersonaModelVersion, vfModuleItemModelName,
661 vfModuleItemModelNameVersionId, tenantItemTenantId, cloudRegionItemCloudRegionId;
666 vnfItemVnfId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfID;
667 vnfItemVnfType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfType;
668 vnfItemVnfType = vnfItemVnfType.substring(vnfItemVnfType.lastIndexOf("/")+1);
669 vnfItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelId;
670 vnfItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelVersion;
671 vnfItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
672 vnfItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(2).propertyValue;
673 vnfItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
677 serviceItemServiceInstanceId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.serviceInstanceID;
678 serviceItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelId;
679 serviceItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
680 serviceItemModelType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(1).propertyValue;
681 serviceItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelVersion;
682 serviceItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
684 // Find the index for base vf module and non-base vf module
687 int nonBaseIndex = -1;
688 List<AAINQF199InventoryResponseItem> inventoryItems = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems;
689 for (AAINQF199InventoryResponseItem m : inventoryItems) {
690 if (m.vfModule != null && m.vfModule.isBaseVfModule == true) {
691 baseIndex = inventoryItems.indexOf(m);
692 } else if (m.vfModule != null && m.vfModule.isBaseVfModule == false && m.vfModule.orchestrationStatus == null) {
693 nonBaseIndex = inventoryItems.indexOf(m);
696 if (baseIndex != -1 && nonBaseIndex != -1) {
701 // Report the error if either base vf module or non-base vf module is not found
703 if (baseIndex == -1 || nonBaseIndex == -1) {
704 System.err.println("Either base or non-base vf module is not found from AAI response.");
705 retract($aainqf199RequestWrapper);
706 retract($aainqf199ResponseWrapper);
712 // This comes from the base module
714 vfModuleItemVfModuleName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(baseIndex).vfModule.vfModuleName;
715 vfModuleItemVfModuleName = vfModuleItemVfModuleName.replace("Vfmodule", "vDNS");
717 // vfModuleItem - NOT the base module
719 vfModuleItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelId;
720 vfModuleItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelVersion;
721 vfModuleItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(0).propertyValue;
722 vfModuleItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(4).propertyValue;
726 tenantItemTenantId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).tenant.tenantId;
730 cloudRegionItemCloudRegionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).items.inventoryResponseItems.get(0).cloudRegion.cloudRegionId;
732 } catch (Exception e) {
734 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
735 notification.notification = ControlLoopNotificationType.REJECTED;
736 notification.message = "Exception occurred " + e.getMessage();
737 notification.policyName = drools.getRule().getName();
738 notification.policyScope = "${policyScope}";
739 notification.policyVersion = "${policyVersion}";
742 System.out.println(Serialization.gsonPretty.toJson(notification));
743 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
744 } catch (Exception e1) {
745 System.out.println("Can't deliver notification: " + notification);
746 e1.printStackTrace();
749 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
750 notification.message = "Invalid named-query response from AAI";
753 System.out.println(Serialization.gsonPretty.toJson(notification));
754 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
755 } catch (Exception e1) {
756 System.out.println("Can't deliver notification: " + notification);
757 e1.printStackTrace();
760 // Retract everything
762 retract($aainqf199RequestWrapper);
763 retract($aainqf199ResponseWrapper);
769 // Extracted fields should not be null
771 if ((vnfItemVnfId == null) || (vnfItemVnfType == null) ||
772 (vnfItemPersonaModelId == null) || (vnfItemModelName == null) ||
773 (vnfItemModelVersion == null) || (vnfItemModelNameVersionId == null) ||
774 (serviceItemServiceInstanceId == null) || (serviceItemModelName == null) ||
775 (serviceItemModelType == null) || (serviceItemModelVersion == null) ||
776 (serviceItemModelNameVersionId == null) || (vfModuleItemVfModuleName == null) ||
777 (vfModuleItemPersonaModelId == null) || (vfModuleItemPersonaModelVersion == null) ||
778 (vfModuleItemModelName == null) || (vfModuleItemModelNameVersionId == null) ||
779 (tenantItemTenantId == null) || (cloudRegionItemCloudRegionId == null)) {
781 System.err.println("some fields are missing from AAI response.");
783 // Fail and retract everything
785 retract($aainqf199RequestWrapper);
786 retract($aainqf199ResponseWrapper);
792 // We don't need them any more
794 retract($aainqf199ResponseWrapper);
795 retract($aainqf199RequestWrapper);
797 // check the actor of this closed loop
799 switch ($params.getActor()) {
803 // Construct an APPC request
805 ControlLoopOperation operation = new ControlLoopOperation();
806 operation.actor = $params.getActor();
807 operation.operation = "ModifyConfig";
808 operation.target = $event.target;
810 // Create operationWrapper
812 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
814 // insert operationWrapper into memory
816 insert(operationWrapper);
818 Request request = new Request();
819 request.CommonHeader = new CommonHeader();
820 request.CommonHeader.RequestID = $event.requestID;
821 request.Action = operation.operation;
822 request.Payload = new HashMap<String, Object>();
824 // Fill in the payload
825 // Hardcode genericVNF for now since AAI has not been ready for vFirewall demo case
827 String genericVNF = "zdfw1fwl01pgn02";
828 request.Payload.put("generic-vnf.vnf-id", genericVNF);
830 PGRequest pgRequest = new PGRequest();
831 pgRequest.pgStreams = new PGStreams();
834 for(int i = 0; i < 5; i++){
835 pgStream = new PGStream();
836 pgStream.streamId = "fw_udp"+(i+1);
837 pgStream.isEnabled = "true";
838 pgRequest.pgStreams.pgStream.add(pgStream);
840 request.Payload.put("pg-streams", pgRequest.pgStreams);
842 if (request != null) {
844 // Insert request into memory
848 // Tell interested parties we are performing this Operation
850 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
851 notification.notification = ControlLoopNotificationType.OPERATION;
852 // message and history ??
853 notification.from = "policy";
854 notification.policyName = drools.getRule().getName();
855 notification.policyScope = "${policyScope}";
856 notification.policyVersion = "${policyVersion}";
858 System.out.println(Serialization.gsonPretty.toJson(notification));
859 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
860 } catch (Exception e) {
861 System.out.println("Can't deliver notification: " + notification);
865 // Now send the operation request
867 if (request instanceof Request) {
869 System.out.println("APPC request sent:");
870 System.out.println(Serialization.gsonPretty.toJson(request));
871 //PolicyEngine.manager.deliver($params.getAppcTopic(), request);
872 } catch (Exception e) {
874 System.out.println("Can't deliver request: " + request);
879 // what happens if it is null
887 // Construct an operation
889 ControlLoopOperation operation = new ControlLoopOperation();
890 operation.actor = $params.getActor();
891 operation.operation = "createModuleInstance";
892 operation.target = $event.target;
894 // Create operationWrapper
896 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
898 // Construct an MSO request
900 MSORequest request = new MSORequest();
901 request.requestDetails = new MSORequestDetails();
902 request.requestDetails.modelInfo = new MSOModelInfo();
903 request.requestDetails.cloudConfiguration = new MSOCloudConfiguration();
904 request.requestDetails.requestInfo = new MSORequestInfo();
905 request.requestDetails.requestParameters = new MSORequestParameters();
906 request.requestDetails.requestParameters.userParams = null;
908 // cloudConfiguration
910 request.requestDetails.cloudConfiguration.lcpCloudRegionId = cloudRegionItemCloudRegionId;
911 request.requestDetails.cloudConfiguration.tenantId = tenantItemTenantId;
915 request.requestDetails.modelInfo.modelType = "vfModule";
916 request.requestDetails.modelInfo.modelInvariantId = vfModuleItemPersonaModelId;
917 request.requestDetails.modelInfo.modelNameVersionId = vfModuleItemModelNameVersionId;
918 request.requestDetails.modelInfo.modelName = vfModuleItemModelName;
919 request.requestDetails.modelInfo.modelVersion = vfModuleItemPersonaModelVersion;
923 request.requestDetails.requestInfo.instanceName = vfModuleItemVfModuleName;
924 request.requestDetails.requestInfo.source = "POLICY";
925 request.requestDetails.requestInfo.suppressRollback = false;
927 // relatedInstanceList
929 MSORelatedInstanceListElement relatedInstanceListElement1 = new MSORelatedInstanceListElement();
930 MSORelatedInstanceListElement relatedInstanceListElement2 = new MSORelatedInstanceListElement();
931 relatedInstanceListElement1.relatedInstance = new MSORelatedInstance();
932 relatedInstanceListElement2.relatedInstance = new MSORelatedInstance();
934 relatedInstanceListElement1.relatedInstance.instanceId = serviceItemServiceInstanceId;
935 relatedInstanceListElement1.relatedInstance.modelInfo = new MSOModelInfo();
936 relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service";
937 relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = serviceItemPersonaModelId;
938 relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = serviceItemModelNameVersionId;
939 relatedInstanceListElement1.relatedInstance.modelInfo.modelName = serviceItemModelName;
940 relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = serviceItemModelVersion;
942 relatedInstanceListElement2.relatedInstance.instanceId = vnfItemVnfId;
943 relatedInstanceListElement2.relatedInstance.modelInfo = new MSOModelInfo();
944 relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf";
945 relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = vnfItemPersonaModelId;
946 relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = vnfItemModelNameVersionId;
947 relatedInstanceListElement2.relatedInstance.modelInfo.modelName = vnfItemModelName;
948 relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = vnfItemModelVersion;
949 relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = vnfItemVnfType;
951 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1);
952 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2);
954 // print MSO request for debug
956 System.out.println("MSO request sent:");
957 System.out.println(Serialization.gsonPretty.toJson(request));
961 if (request != null) {
963 // Tell interested parties we are performing this Operation
965 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
966 notification.notification = ControlLoopNotificationType.OPERATION;
967 notification.from = "policy";
968 notification.policyName = drools.getRule().getName();
969 notification.policyScope = "${policyScope}";
970 notification.policyVersion = "${policyVersion}";
972 System.out.println(Serialization.gsonPretty.toJson(notification));
973 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
974 } catch (Exception e) {
975 System.out.println("Can't deliver notification: " + notification);
979 // Concatenate serviceItemServiceInstanceId and vnfItemVnfId to msoURL
981 String MSOUrl = $params.getMsoURL() + "/serviceInstances/v2/" + serviceItemServiceInstanceId + "/vnfs/" + vnfItemVnfId + "/vfModules";
985 MSOResponse response = MSOManager.createModuleInstance(MSOUrl, $params.getMsoURL(), $params.getMsoUsername(), $params.getMsoPassword(), request);
990 //////////////////////////////////////////////////////////
991 // Simulate a valid MSOResponse for junit test
992 // Remove this for real deployment
994 response = new MSOResponse();
995 response.request = new MSORequest();
996 response.request.requestStatus = new MSORequestStatus();
997 response.request.requestStatus.requestState = "COMPLETE";
998 //////////////////////////////////////////////////////////
1004 if (response != null) {
1008 request.requestId = $event.requestID.toString();
1009 response.request.requestId = $event.requestID.toString();
1013 insert(operationWrapper);
1018 // MSO request not even accepted
1020 notification.message = operationWrapper.operation.toMessage();
1021 operationWrapper.operation.message = operationWrapper.operation.toMessage();
1022 operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
1023 $manager.setControlLoopResult("FAILURE_EXCEPTION");
1024 notification.history.add(operationWrapper.operation);
1025 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
1027 // Let interested parties know
1030 System.out.println(Serialization.gsonPretty.toJson(notification));
1031 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1032 } catch (Exception e) {
1033 System.out.println("Can't deliver notification: " + notification);
1034 e.printStackTrace();
1036 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
1038 System.out.println(Serialization.gsonPretty.toJson(notification));
1039 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1040 } catch (Exception e) {
1041 System.out.println("Can't deliver notification: " + notification);
1042 e.printStackTrace();
1045 // Retract everything
1051 System.err.println("constructed MSO request is invalid.");
1060 * This rule responds to APPC Response Events
1063 rule "${policyName}.APPC.RESPONSE"
1065 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
1066 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
1067 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
1068 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
1069 $request : Request( getCommonHeader().RequestID == $event.requestID )
1070 $response : Response( getCommonHeader().RequestID == $event.requestID )
1072 System.out.println("rule APPC.RESPONSE is triggered.");
1073 if ($response.Status == null) {
1074 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
1075 $manager.setControlLoopResult("FAILURE_EXCEPTION");
1078 // Get the Response Code
1080 ResponseCode code = ResponseCode.toResponseCode($response.Status.Code);
1082 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
1083 $manager.setControlLoopResult("FAILURE_EXCEPTION");
1086 // Construct notification
1088 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
1089 notification.from = "policy";
1090 notification.policyName = drools.getRule().getName();
1091 notification.policyScope = "${policyScope}";
1092 notification.policyVersion = "${policyVersion}";
1093 notification.message = $operationWrapper.operation.toMessage();
1094 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
1096 // Ok, let's figure out what APP-C's response is
1100 $operationWrapper.operation.outcome = "PROCESSING";
1104 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
1105 $manager.setControlLoopResult("FAILURE_EXCEPTION");
1108 $operationWrapper.operation.outcome = "SUCCESS";
1109 $manager.setControlLoopResult("SUCCESS");
1112 $operationWrapper.operation.outcome = "FAILURE";
1113 $manager.setControlLoopResult("FAILURE");
1116 if ($operationWrapper.operation.outcome.equals("SUCCESS")) {
1117 notification.history.add($operationWrapper.operation);
1118 notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
1120 // Let interested parties know
1123 System.out.println(Serialization.gsonPretty.toJson(notification));
1124 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1125 } catch (Exception e) {
1126 System.out.println("Can't deliver notification: " + notification);
1127 e.printStackTrace();
1129 notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
1131 System.out.println(Serialization.gsonPretty.toJson(notification));
1132 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1133 } catch (Exception e) {
1134 System.out.println("Can't deliver notification: " + notification);
1135 e.printStackTrace();
1139 // We are going to retract these objects from memory
1141 System.out.println("Retracting everything");
1142 retract($operationWrapper);
1147 } else if ($operationWrapper.operation.outcome.equals("PROCESSING")) {
1150 notification.history.add($operationWrapper.operation);
1151 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
1153 // Let interested parties know
1156 System.out.println(Serialization.gsonPretty.toJson(notification));
1157 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1158 } catch (Exception e) {
1159 System.out.println("Can't deliver notification: " + notification);
1160 e.printStackTrace();
1162 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
1164 // Let interested parties know
1167 System.out.println(Serialization.gsonPretty.toJson(notification));
1168 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1169 } catch (Exception e) {
1170 System.out.println("Can't deliver notification: " + notification);
1171 e.printStackTrace();
1174 // We are going to retract these objects from memory
1176 System.out.println("Retracting everything");
1177 retract($operationWrapper);
1188 * This rule is used to clean up APPC response
1191 rule "${policyName}.APPC.RESPONSE.CLEANUP"
1193 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
1194 $response : Response($id : getCommonHeader().RequestID )
1195 not ( VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), requestID == $id, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) )
1197 System.out.println("rule APPC.RESPONSE.CLEANUP is triggered.");
1203 * This rule responds to MSO Response Events
1206 rule "${policyName}.MSO.RESPONSE"
1208 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
1209 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
1210 $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
1211 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
1212 $request : MSORequest( requestId == $event.requestID.toString() )
1213 $response : MSOResponse( request.requestId == $event.requestID.toString() )
1215 System.out.println("rule MSO.RESPONSE is triggered.");
1217 // Construct notification
1219 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
1220 notification.from = "policy";
1221 notification.policyName = drools.getRule().getName();
1222 notification.policyScope = "${policyScope}";
1223 notification.policyVersion = "${policyVersion}";
1224 notification.message = $operationWrapper.operation.toMessage();
1225 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
1227 // The operation can either be succeeded or failed
1229 if($response.request.requestStatus.requestState.equals("COMPLETE")) {
1230 $operationWrapper.operation.outcome = "SUCCESS";
1231 $manager.setControlLoopResult("SUCCESS");
1232 notification.history.add($operationWrapper.operation);
1233 notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
1235 // Let interested parties know
1238 System.out.println(Serialization.gsonPretty.toJson(notification));
1239 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1240 } catch (Exception e) {
1241 System.out.println("Can't deliver notification: " + notification);
1242 e.printStackTrace();
1244 notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
1246 // Let interested parties know
1249 System.out.println(Serialization.gsonPretty.toJson(notification));
1250 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1251 } catch (Exception e) {
1252 System.out.println("Can't deliver notification: " + notification);
1253 e.printStackTrace();
1256 // We are going to retract these objects from memory
1258 System.out.println("Retracting everything");
1259 retract($operationWrapper);
1265 $operationWrapper.operation.outcome = "FAILURE";
1266 $manager.setControlLoopResult("FAILURE");
1267 notification.history.add($operationWrapper.operation);
1268 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
1270 // Let interested parties know
1273 System.out.println(Serialization.gsonPretty.toJson(notification));
1274 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1275 } catch (Exception e) {
1276 System.out.println("Can't deliver notification: " + notification);
1277 e.printStackTrace();
1279 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
1281 // Let interested parties know
1284 System.out.println(Serialization.gsonPretty.toJson(notification));
1285 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1286 } catch (Exception e) {
1287 System.out.println("Can't deliver notification: " + notification);
1288 e.printStackTrace();
1291 // We are going to retract these objects from memory
1293 System.out.println("Retracting everything");
1294 retract($operationWrapper);
1303 * Sample Queries for illustration with and without arguments
1304 * The results of the query can be introspected (and retracted if desired)
1307 query "${policyName}.QUERY.EVENT.ONSET"
1308 event : VirtualControlLoopEvent( closedLoopEventStatus == ControlLoopEventStatus.ONSET )
1311 query "${policyName}.QUERY.MANAGER.RNA" (String aRequestId, Integer numOnsetsLowerBound, Boolean aActivated)
1312 manager : ControlLoopEventManager( closedLoopControlName == "${closedLoopControlName}",
1313 requestID.toString() == aRequestId,
1314 numOnsets > numOnsetsLowerBound,
1315 activated == aActivated )