2 * ============LICENSE_START=======================================================
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=========================================================
22 package org.openecomp.policy.controlloop;
24 import java.util.LinkedList;
26 import java.util.HashMap;
27 import java.util.UUID;
29 import org.openecomp.policy.controlloop.VirtualControlLoopEvent;
30 import org.openecomp.policy.controlloop.ControlLoopEventStatus;
31 import org.openecomp.policy.controlloop.VirtualControlLoopNotification;
32 import org.openecomp.policy.controlloop.ControlLoopNotificationType;
33 import org.openecomp.policy.controlloop.ControlLoopOperation;
34 import org.openecomp.policy.controlloop.ControlLoopOperationWrapper;
35 import org.openecomp.policy.template.demo.ControlLoopException;
37 import org.openecomp.policy.aai.AAINQF199.AAINQF199CloudRegion;
38 import org.openecomp.policy.aai.AAINQF199.AAINQF199ExtraProperties;
39 import org.openecomp.policy.aai.AAINQF199.AAINQF199ExtraProperty;
40 import org.openecomp.policy.aai.AAINQF199.AAINQF199GenericVNF;
41 import org.openecomp.policy.aai.AAINQF199.AAINQF199InstanceFilters;
42 import org.openecomp.policy.aai.AAINQF199.AAINQF199InventoryResponseItem;
43 import org.openecomp.policy.aai.AAINQF199.AAINQF199InventoryResponseItems;
44 import org.openecomp.policy.aai.AAINQF199.AAINQF199Manager;
45 import org.openecomp.policy.aai.AAINQF199.AAINQF199NamedQuery;
46 import org.openecomp.policy.aai.AAINQF199.AAINQF199QueryParameters;
47 import org.openecomp.policy.aai.AAINQF199.AAINQF199Request;
48 import org.openecomp.policy.aai.AAINQF199.AAINQF199RequestWrapper;
49 import org.openecomp.policy.aai.AAINQF199.AAINQF199Response;
50 import org.openecomp.policy.aai.AAINQF199.AAINQF199ResponseWrapper;
51 import org.openecomp.policy.aai.AAINQF199.AAINQF199ServiceInstance;
52 import org.openecomp.policy.aai.AAINQF199.AAINQF199Tenant;
53 import org.openecomp.policy.aai.AAINQF199.AAINQF199VfModule;
54 import org.openecomp.policy.aai.AAINQF199.AAINQF199VServer;
55 import org.openecomp.policy.aai.util.Serialization;
57 import org.openecomp.policy.appc.CommonHeader;
58 import org.openecomp.policy.appc.Request;
59 import org.openecomp.policy.appc.Response;
60 import org.openecomp.policy.appc.ResponseCode;
61 import org.openecomp.policy.appc.ResponseStatus;
62 import org.openecomp.policy.appc.ResponseValue;
64 import org.openecomp.policy.template.demo.EventManager;
65 import org.openecomp.policy.vnf.trafficgenerator.PGRequest;
66 import org.openecomp.policy.vnf.trafficgenerator.PGStream;
67 import org.openecomp.policy.vnf.trafficgenerator.PGStreams;
69 import org.openecomp.policy.mso.MSOManager;
70 import org.openecomp.policy.mso.MSORequest;
71 import org.openecomp.policy.mso.MSORequestStatus;
72 import org.openecomp.policy.mso.MSORequestDetails;
73 import org.openecomp.policy.mso.MSOModelInfo;
74 import org.openecomp.policy.mso.MSOCloudConfiguration;
75 import org.openecomp.policy.mso.MSORequestInfo;
76 import org.openecomp.policy.mso.MSORequestParameters;
77 import org.openecomp.policy.mso.MSORelatedInstanceListElement;
78 import org.openecomp.policy.mso.MSORelatedInstance;
79 import org.openecomp.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 * (Comment SETUP rule out for the first ECOMP opensource release since policy BRMS_GW already puts a Params fact in there)
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
132 * This rule responds to DCAE Events
135 rule "${policyName}.EVENT"
137 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
138 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
139 not ( EventManager( closedLoopControlName == $event.closedLoopControlName ))
141 System.out.println("rule EVENT is triggered.");
144 // Check the requestID in the event to make sure it is not null before we create the EventManager.
145 // The EventManager will do extra syntax checking as well check if the closed loop is disabled/
147 if ($event.requestID == null) {
148 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
149 notification.notification = ControlLoopNotificationType.REJECTED;
150 notification.from = "policy";
151 notification.message = "Missing requestID from DCAE event";
152 notification.policyName = drools.getRule().getName();
153 notification.policyScope = "${policyScope}";
154 notification.policyVersion = "${policyVersion}";
156 // Let interested parties know
159 System.out.println(Serialization.gsonPretty.toJson(notification));
160 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
161 } catch (Exception e) {
163 System.out.println("Can't deliver notification: " + notification);
166 // Retract it from memory
169 System.out.println("Event with requestID=null has been retracted.");
172 // Create an EventManager
174 EventManager manager = new EventManager($params.getClosedLoopControlName(), $event.requestID, $event.target);
176 // Determine if EventManager can actively process the event (i.e. syntax)
178 VirtualControlLoopNotification notification = manager.activate($event);
179 notification.from = "policy";
180 notification.policyName = drools.getRule().getName();
181 notification.policyScope = "${policyScope}";
182 notification.policyVersion = "${policyVersion}";
184 // Are we actively pursuing this event?
186 if (notification.notification == ControlLoopNotificationType.ACTIVE) {
188 // Insert Event Manager into memory, this will now kick off processing.
192 // Let interested parties know
195 System.out.println(Serialization.gsonPretty.toJson(notification));
196 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
197 } catch (Exception e) {
199 System.out.println("Can't deliver notification: " + notification);
203 // Let interested parties know
206 System.out.println(Serialization.gsonPretty.toJson(notification));
207 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
208 } catch (Exception e) {
210 System.out.println("Can't deliver notification: " + notification);
213 // Retract it from memory
218 // Now that the manager is inserted into Drools working memory, we'll wait for
219 // another rule to fire in order to continue processing. This way we can also
220 // then screen for additional ONSET and ABATED events for this same RequestIDs
221 // and for different RequestIDs but with the same closedLoopControlName and target.
225 } catch (Exception e) {
227 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
228 notification.notification = ControlLoopNotificationType.REJECTED;
229 notification.message = "Exception occurred " + e.getMessage();
230 notification.policyName = drools.getRule().getName();
231 notification.policyScope = "${policyScope}";
232 notification.policyVersion = "${policyVersion}";
237 System.out.println(Serialization.gsonPretty.toJson(notification));
238 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
239 } catch (Exception e1) {
240 System.out.println("Can't deliver notification: " + notification);
241 e1.printStackTrace();
252 * This rule happens when we got a valid ONSET, closed loop is enabled and an Event Manager
253 * is created. We can start the operations for this closed loop.
256 rule "${policyName}.EVENT.MANAGER"
258 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
259 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
260 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName, controlLoopResult == null)
262 System.out.println("rule EVENT.MANAGER is triggered.");
264 // Check which event this is.
266 EventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event);
268 // We only want the initial ONSET event in memory,
269 // all the other events need to be retracted to support
270 // cleanup and avoid the other rules being fired for this event.
272 if (eventStatus != EventManager.NEW_EVENT_STATUS.FIRST_ONSET) {
273 System.out.println("Retracting "+eventStatus+" Event.");
278 // Now the event in memory is first onset event
282 // Pull the known AAI field from the Event
284 // generic-vnf is needed for vFirewall case
285 // vserver-name is needed for vLoadBalancer case
287 String genericVNF = $event.AAI.get("generic-vnf.vnf-id");
288 String vserver = $event.AAI.get("vserver.vserver-name");
290 // Check if we are implementing a simple pattern match.
292 if ($params.getAaiPatternMatch() == 1) {
296 //Basic naming characteristics:
297 //VF Name (9 char)+VM name (13 char total)+VFC (19 char total)
299 //VF Name (9 characters): cscf0001v
300 //VM Name(13 characters): cscf0001vm001
301 //VFC name(19 characters): cscf0001vm001cfg001
303 // zdfw1fwl01fwl02 or zdfw1fwl01fwl01
305 // zdfw1fwl01pgn02 or zdfw1fwl01pgn01
307 int index = genericVNF.lastIndexOf("fwl");
309 System.err.println("The generic-vnf.vnf-id from DCAE Event is not valid.");
311 genericVNF = genericVNF.substring(0, index) + "pgn" + genericVNF.substring(index+"fwl".length());
314 // Construct an APPC request
316 ControlLoopOperation operation = new ControlLoopOperation();
317 operation.actor = $params.getActor();
318 operation.operation = "ModifyConfig";
319 operation.target = $event.target;
321 // Create operationWrapper
323 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
325 // insert operationWrapper into memory
327 insert(operationWrapper);
329 Request request = new Request();
330 request.CommonHeader = new CommonHeader();
331 request.CommonHeader.RequestID = $event.requestID;
332 request.Action = operation.operation;
333 request.Payload = new HashMap<String, Object>();
335 // Fill in the payload
337 request.Payload.put("generic-vnf.vnf-id", genericVNF);
339 PGRequest pgRequest = new PGRequest();
340 pgRequest.pgStreams = new PGStreams();
343 for(int i = 0; i < 5; i++){
344 pgStream = new PGStream();
345 pgStream.streamId = "fw_udp"+(i+1);
346 pgStream.isEnabled = "true";
347 pgRequest.pgStreams.pgStream.add(pgStream);
349 request.Payload.put("pg-streams", pgRequest.pgStreams);
351 if (request != null) {
353 // Insert request into memory
357 // Tell interested parties we are performing this Operation
359 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
360 notification.notification = ControlLoopNotificationType.OPERATION;
361 // message and history ??
362 notification.from = "policy";
363 notification.policyName = drools.getRule().getName();
364 notification.policyScope = "${policyScope}";
365 notification.policyVersion = "${policyVersion}";
367 System.out.println(Serialization.gsonPretty.toJson(notification));
368 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
369 } catch (Exception e) {
370 System.out.println("Can't deliver notification: " + notification);
374 // Now send the operation request
376 if (request instanceof Request) {
378 System.out.println("APPC request sent:");
379 System.out.println(Serialization.gsonPretty.toJson(request));
380 //PolicyEngine.manager.deliver($params.getAppcTopic(), request);
381 } catch (Exception e) {
383 System.out.println("Can't deliver request: " + request);
388 // what happens if it is null
394 // create AAI named-query request with UUID started with "F199"
396 AAINQF199Request aainqf199request = new AAINQF199Request();
397 AAINQF199QueryParameters aainqf199queryparam = new AAINQF199QueryParameters();
398 AAINQF199NamedQuery aainqf199namedquery = new AAINQF199NamedQuery();
399 AAINQF199InstanceFilters aainqf199instancefilter = new AAINQF199InstanceFilters();
403 aainqf199namedquery.namedQueryUUID = UUID.fromString($params.getAaiNamedQueryUUID());
404 aainqf199queryparam.namedQuery = aainqf199namedquery;
405 aainqf199request.queryParameters = aainqf199queryparam;
409 Map aainqf199instancefiltermap = new HashMap();
410 Map aainqf199instancefiltermapitem = new HashMap();
411 aainqf199instancefiltermapitem.put("vserver-name", vserver);
412 aainqf199instancefiltermap.put("vserver", aainqf199instancefiltermapitem);
413 aainqf199instancefilter.instanceFilter.add(aainqf199instancefiltermap);
414 aainqf199request.instanceFilters = aainqf199instancefilter;
416 // print aainqf199request for debug
418 System.out.println("AAI Request sent:");
419 System.out.println(Serialization.gsonPretty.toJson(aainqf199request));
421 // Create AAINQF199RequestWrapper
423 AAINQF199RequestWrapper aainqf199RequestWrapper = new AAINQF199RequestWrapper($event.requestID, aainqf199request);
425 // insert aainqf199request into memory
427 insert(aainqf199RequestWrapper);
430 } catch (Exception e) {
437 * This rule happens when we got a valid ONSET, closed loop is enabled, an Event Manager
438 * is created, AAI Manager and AAI Request are ready in memory. We can start sending query to AAI and then wait for response.
441 rule "${policyName}.EVENT.MANAGER.AAINQF199REQUEST"
443 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
444 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
445 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
446 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
448 System.out.println("rule EVENT.MANAGER.AAINQF199REQUEST is triggered.");
452 AAINQF199Response aainqf199response = AAINQF199Manager.postQuery($params.getAaiURL(), $params.getAaiUsername(), $params.getAaiPassword(),
453 $aainqf199RequestWrapper.aainqf199request, $event.requestID);
457 //////////////////////////////////////////////////////////
458 // Simulate a valid aainqf199response for junit test
459 // Remove this for real deployment
462 AAINQF199InventoryResponseItem serviceItem = new AAINQF199InventoryResponseItem();
463 serviceItem.modelName = "service-instance";
464 serviceItem.serviceInstance = new AAINQF199ServiceInstance();
465 serviceItem.serviceInstance.serviceInstanceID = "cf8426a6-0b53-4e3d-bfa6-4b2f4d5913a5";
466 serviceItem.serviceInstance.serviceInstanceName = "Service_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8";
467 serviceItem.serviceInstance.personaModelId = "4fcbc1c0-7793-46d8-8aa1-fa1c2ed9ec7b";
468 serviceItem.serviceInstance.personaModelVersion = "1.0";
469 serviceItem.serviceInstance.resourceVersion = "1485542400";
470 serviceItem.extraProperties = new AAINQF199ExtraProperties();
471 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "8330e932-2a23-4943-8606"));
472 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "service"));
473 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
474 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "4fcbc1c0-7793-46d8-8aa1-fa1c2ed9ec7b"));
475 serviceItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "5c996219-b2e2-4c76-9b43-7e8672a33c1d"));
477 AAINQF199InventoryResponseItem vfModuleItem = new AAINQF199InventoryResponseItem();
478 vfModuleItem.modelName = "C15ce9e1E9144c8fB8bb..base_vlb..module-0";
479 vfModuleItem.vfModule = new AAINQF199VfModule();
480 vfModuleItem.vfModule.vfModuleId = "b0eff878-e2e1-4947-9597-39afdd0f51dd";
481 vfModuleItem.vfModule.vfModuleName = "Vfmodule_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8";
482 vfModuleItem.vfModule.heatStackId = "Vfmodule_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8/5845f37b-6cda-4e91-8ca3-f5572d226488";
483 vfModuleItem.vfModule.orchestrationStatus = "active";
484 vfModuleItem.vfModule.isBaseVfModule = true;
485 vfModuleItem.vfModule.resourceVersion = "1485542667";
486 vfModuleItem.vfModule.personaModelId = "79ee24cd-fc9a-4f14-afae-5e1dd2ab2941";
487 vfModuleItem.vfModule.personaModelVersion = "1";
489 vfModuleItem.extraProperties = new AAINQF199ExtraProperties();
490 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "C15ce9e1E9144c8fB8bb..base_vlb..module-0"));
491 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "resource"));
492 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
493 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "79ee24cd-fc9a-4f14-afae-5e1dd2ab2941"));
494 vfModuleItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "5484cabb-1a0d-4f29-a616-094a3f643d73"));
497 AAINQF199InventoryResponseItem vfModuleItem1 = new AAINQF199InventoryResponseItem();
498 //vfModuleItem1.modelName = "vf-module";
499 vfModuleItem1.vfModule = new AAINQF199VfModule();
500 vfModuleItem1.vfModule.vfModuleId = "dummy";
501 vfModuleItem1.vfModule.vfModuleName = "dummy";
502 vfModuleItem1.vfModule.isBaseVfModule = false;
503 vfModuleItem1.vfModule.resourceVersion = "1485561752";
504 vfModuleItem1.vfModule.personaModelId = "f32568ec-2f1c-458a-864b-0593d53d141a";
505 vfModuleItem1.vfModule.personaModelVersion = "1.0";
507 vfModuleItem1.extraProperties = new AAINQF199ExtraProperties();
508 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "C15ce9e1E9144c8fB8bb..dnsscaling..module-1"));
509 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "resource"));
510 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
511 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "f32568ec-2f1c-458a-864b-0593d53d141a"));
512 vfModuleItem1.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "69615025-879d-4f0d-afe3-b7d1a7eeed1f"));
516 AAINQF199InventoryResponseItem vfModuleItem2 = new AAINQF199InventoryResponseItem();
517 //vfModuleItem2.modelName = "vf-module";
518 vfModuleItem2.vfModule = new AAINQF199VfModule();
519 vfModuleItem2.vfModule.vfModuleId = "8cd79e44-1fae-48c1-a160-609f90b46749";
520 vfModuleItem2.vfModule.vfModuleName = "vDNS_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8";
521 vfModuleItem2.vfModule.heatStackId = "vDNS_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8/f447ce51-14dd-4dcd-9957-68a047c79673";
522 vfModuleItem2.vfModule.orchestrationStatus = "active";
523 vfModuleItem2.vfModule.isBaseVfModule = false;
524 vfModuleItem2.vfModule.resourceVersion = "1485562712";
525 vfModuleItem2.vfModule.personaModelId = "f32568ec-2f1c-458a-864b-0593d53d141a";
526 vfModuleItem2.vfModule.personaModelVersion = "1.0";
528 vfModuleItem2.extraProperties = new AAINQF199ExtraProperties();
529 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "C15ce9e1E9144c8fB8bb..dnsscaling..module-1"));
530 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "resource"));
531 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
532 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "f32568ec-2f1c-458a-864b-0593d53d141a"));
533 vfModuleItem2.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "69615025-879d-4f0d-afe3-b7d1a7eeed1f"));
539 AAINQF199InventoryResponseItem genericVNFItem = new AAINQF199InventoryResponseItem();
540 genericVNFItem.modelName = "generic-vnf";
541 genericVNFItem.genericVNF = new AAINQF199GenericVNF();
542 genericVNFItem.genericVNF.vnfID = "594e2fe0-48b8-41ff-82e2-3d4bab69b192";
543 genericVNFItem.genericVNF.vnfName = "Vnf_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8";
544 genericVNFItem.genericVNF.vnfType = "8330e932-2a23-4943-8606/c15ce9e1-e914-4c8f-b8bb 1";
545 genericVNFItem.genericVNF.serviceId = "b3f70641-bdb9-4030-825e-6abb73a1f929";
546 // genericVNFItem.genericVNF.provStatus = "PREPROV";
547 // genericVNFItem.genericVNF.operationalState = "dhv-test-operational-state";
548 // genericVNFItem.genericVNF.ipv4OamAddress = "dhv-test-gvnf-ipv4-oam-address";
549 // genericVNFItem.genericVNF.ipv4Loopback0Address = "dhv-test-gvnfipv4-loopback0-address";
550 genericVNFItem.genericVNF.inMaint = false;
551 genericVNFItem.genericVNF.isClosedLoopDisabled = false;
552 genericVNFItem.genericVNF.resourceVersion = "1485542422";
553 // genericVNFItem.genericVNF.encrypedAccessFlag = true;
554 genericVNFItem.genericVNF.personaModelId = "033a32ed-aa65-4764-a736-36f2942f1aa0";
555 genericVNFItem.genericVNF.personaModelVersion = "1.0";
556 genericVNFItem.extraProperties = new AAINQF199ExtraProperties();
557 genericVNFItem.extraProperties.extraProperty = new LinkedList<AAINQF199ExtraProperty>();
558 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name", "c15ce9e1-e914-4c8f-b8bb"));
559 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-type", "resource"));
560 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-version", "1"));
561 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-id", "033a32ed-aa65-4764-a736-36f2942f1aa0"));
562 genericVNFItem.extraProperties.extraProperty.add(new AAINQF199ExtraProperty("model.model-name-version-id", "d4d072dc-4e21-4a03-9524-628985819a8e"));
563 genericVNFItem.items = new AAINQF199InventoryResponseItems();
564 genericVNFItem.items.inventoryResponseItems = new LinkedList<AAINQF199InventoryResponseItem>();
565 genericVNFItem.items.inventoryResponseItems.add(serviceItem);
566 genericVNFItem.items.inventoryResponseItems.add(vfModuleItem);
567 genericVNFItem.items.inventoryResponseItems.add(vfModuleItem1);
568 genericVNFItem.items.inventoryResponseItems.add(vfModuleItem2);
570 AAINQF199InventoryResponseItem cloudItem = new AAINQF199InventoryResponseItem();
571 cloudItem.cloudRegion = new AAINQF199CloudRegion();
572 cloudItem.cloudRegion.cloudOwner = "OWNER";
573 cloudItem.cloudRegion.cloudRegionId = "REGIONID";
574 cloudItem.cloudRegion.cloudRegionVersion = "2.5";
575 cloudItem.cloudRegion.complexName = "COMPLEXNAME";
576 cloudItem.cloudRegion.resourceVersion = "1485465545";
578 AAINQF199InventoryResponseItem tenantItem = new AAINQF199InventoryResponseItem();
579 tenantItem.tenant = new AAINQF199Tenant();
580 tenantItem.tenant.tenantId = "1015548";
581 tenantItem.tenant.tenantName = "1015548";
582 tenantItem.tenant.resourceVersion = "1485465545";
583 tenantItem.items = new AAINQF199InventoryResponseItems();
584 tenantItem.items.inventoryResponseItems = new LinkedList<AAINQF199InventoryResponseItem>();
585 tenantItem.items.inventoryResponseItems.add(cloudItem);
587 AAINQF199InventoryResponseItem vserverItem = new AAINQF199InventoryResponseItem();
588 vserverItem.vserver = new AAINQF199VServer();
589 vserverItem.vserver.vserverId = "70f081eb-2a87-4c81-9296-4b93d7d145c6";
590 vserverItem.vserver.vserverName = "vlb-lb-32c8";
591 vserverItem.vserver.vserverName2 = "vlb-lb-32c8";
592 vserverItem.vserver.provStatus = "ACTIVE";
593 vserverItem.vserver.vserverSelflink = "https://dfw.servers.api.rackspacecloud.com/v2/1015548/servers/70f081eb-2a87-4c81-9296-4b93d7d145c6";
594 vserverItem.vserver.inMaint = false;
595 vserverItem.vserver.isClosedLoopDisabled = false;
596 vserverItem.vserver.resourceVersion = "1485546436";
597 vserverItem.items = new AAINQF199InventoryResponseItems();
598 vserverItem.items.inventoryResponseItems = new LinkedList<AAINQF199InventoryResponseItem>();
599 vserverItem.items.inventoryResponseItems.add(genericVNFItem);
600 vserverItem.items.inventoryResponseItems.add(tenantItem);
602 aainqf199response = new AAINQF199Response();
603 aainqf199response.inventoryResponseItems.add(vserverItem);
605 System.out.println("PAM");
606 System.out.println(Serialization.gsonPretty.toJson(aainqf199response));
608 //////////////////////////////////////////////////////////
615 // Check AAI response
617 if (aainqf199response == null) {
618 System.err.println("Failed to get AAI response");
620 // Fail and retract everything
624 retract($aainqf199RequestWrapper);
627 // Create AAINQF199ResponseWrapper
629 AAINQF199ResponseWrapper aainqf199ResponseWrapper = new AAINQF199ResponseWrapper($event.requestID, aainqf199response);
631 // insert aainqf199ResponseWrapper to memeory
633 insert(aainqf199ResponseWrapper);
639 * This rule happens when we got a valid AAI response. We can start sending request to APPC or MSO now.
642 rule "${policyName}.EVENT.MANAGER.AAINQF199RESPONSE"
644 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
645 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
646 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
647 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
648 $aainqf199ResponseWrapper : AAINQF199ResponseWrapper(requestID == $event.requestID)
650 System.out.println("rule EVENT.MANAGER.AAINQF199RESPONSE is triggered.");
652 // Extract related fields out of AAINQF199RESPONSE
655 String vnfItemVnfId, vnfItemVnfType, vnfItemPersonaModelId, vnfItemPersonaModelVersion, vnfItemModelName,
656 vnfItemModelVersion, vnfItemModelNameVersionId, serviceItemServiceInstanceId, serviceItemPersonaModelId,
657 serviceItemModelName, serviceItemModelType, serviceItemModelVersion, serviceItemModelNameVersionId,
658 vfModuleItemVfModuleName, vfModuleItemPersonaModelId, vfModuleItemPersonaModelVersion, vfModuleItemModelName,
659 vfModuleItemModelNameVersionId, tenantItemTenantId, cloudRegionItemCloudRegionId;
664 vnfItemVnfId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfID;
665 vnfItemVnfType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfType;
666 vnfItemVnfType = vnfItemVnfType.substring(vnfItemVnfType.lastIndexOf("/")+1);
667 vnfItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelId;
668 vnfItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelVersion;
669 vnfItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
670 vnfItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(2).propertyValue;
671 vnfItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
675 serviceItemServiceInstanceId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.serviceInstanceID;
676 serviceItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelId;
677 serviceItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
678 serviceItemModelType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(1).propertyValue;
679 serviceItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelVersion;
680 serviceItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
682 // This comes from the base module
684 vfModuleItemVfModuleName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).vfModule.vfModuleName;
685 vfModuleItemVfModuleName = vfModuleItemVfModuleName.replace("Vfmodule", "vDNS");
687 // vfModuleItem - NOT the base module
689 vfModuleItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(2).vfModule.personaModelId;
690 vfModuleItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(2).vfModule.personaModelVersion;
691 vfModuleItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(2).extraProperties.extraProperty.get(0).propertyValue;
692 vfModuleItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(2).extraProperties.extraProperty.get(4).propertyValue;
696 tenantItemTenantId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).tenant.tenantId;
700 cloudRegionItemCloudRegionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).items.inventoryResponseItems.get(0).cloudRegion.cloudRegionId;
702 } catch (Exception e) {
704 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
705 notification.notification = ControlLoopNotificationType.REJECTED;
706 notification.message = "Exception occurred " + e.getMessage();
707 notification.policyName = drools.getRule().getName();
708 notification.policyScope = "${policyScope}";
709 notification.policyVersion = "${policyVersion}";
712 System.out.println(Serialization.gsonPretty.toJson(notification));
713 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
714 } catch (Exception e1) {
715 System.out.println("Can't deliver notification: " + notification);
716 e1.printStackTrace();
719 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
720 notification.message = "Invalid named-query response from AAI";
723 System.out.println(Serialization.gsonPretty.toJson(notification));
724 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
725 } catch (Exception e1) {
726 System.out.println("Can't deliver notification: " + notification);
727 e1.printStackTrace();
730 // Retract everything
732 retract($aainqf199RequestWrapper);
733 retract($aainqf199ResponseWrapper);
739 // Extracted fields should not be null
741 if ((vnfItemVnfId == null) || (vnfItemVnfType == null) ||
742 (vnfItemPersonaModelId == null) || (vnfItemModelName == null) ||
743 (vnfItemModelVersion == null) || (vnfItemModelNameVersionId == null) ||
744 (serviceItemServiceInstanceId == null) || (serviceItemModelName == null) ||
745 (serviceItemModelType == null) || (serviceItemModelVersion == null) ||
746 (serviceItemModelNameVersionId == null) || (vfModuleItemVfModuleName == null) ||
747 (vfModuleItemPersonaModelId == null) || (vfModuleItemPersonaModelVersion == null) ||
748 (vfModuleItemModelName == null) || (vfModuleItemModelNameVersionId == null) ||
749 (tenantItemTenantId == null) || (cloudRegionItemCloudRegionId == null)) {
751 System.err.println("some fields are missing from AAI response.");
753 // Fail and retract everything
755 retract($aainqf199RequestWrapper);
756 retract($aainqf199ResponseWrapper);
762 // We don't need them any more
764 retract($aainqf199ResponseWrapper);
765 retract($aainqf199RequestWrapper);
767 // check the actor of this closed loop
769 switch ($params.getActor()) {
773 // Construct an APPC request
775 ControlLoopOperation operation = new ControlLoopOperation();
776 operation.actor = $params.getActor();
777 operation.operation = "ModifyConfig";
778 operation.target = $event.target;
780 // Create operationWrapper
782 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
784 // insert operationWrapper into memory
786 insert(operationWrapper);
788 Request request = new Request();
789 request.CommonHeader = new CommonHeader();
790 request.CommonHeader.RequestID = $event.requestID;
791 request.Action = operation.operation;
792 request.Payload = new HashMap<String, Object>();
794 // Fill in the payload
795 // Hardcode genericVNF for now since AAI has not been ready for vFirewall demo case
797 String genericVNF = "zdfw1fwl01pgn02";
798 request.Payload.put("generic-vnf.vnf-id", genericVNF);
800 PGRequest pgRequest = new PGRequest();
801 pgRequest.pgStreams = new PGStreams();
804 for(int i = 0; i < 5; i++){
805 pgStream = new PGStream();
806 pgStream.streamId = "fw_udp"+(i+1);
807 pgStream.isEnabled = "true";
808 pgRequest.pgStreams.pgStream.add(pgStream);
810 request.Payload.put("pg-streams", pgRequest.pgStreams);
812 if (request != null) {
814 // Insert request into memory
818 // Tell interested parties we are performing this Operation
820 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
821 notification.notification = ControlLoopNotificationType.OPERATION;
822 // message and history ??
823 notification.from = "policy";
824 notification.policyName = drools.getRule().getName();
825 notification.policyScope = "${policyScope}";
826 notification.policyVersion = "${policyVersion}";
828 System.out.println(Serialization.gsonPretty.toJson(notification));
829 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
830 } catch (Exception e) {
831 System.out.println("Can't deliver notification: " + notification);
835 // Now send the operation request
837 if (request instanceof Request) {
839 System.out.println("APPC request sent:");
840 System.out.println(Serialization.gsonPretty.toJson(request));
841 //PolicyEngine.manager.deliver($params.getAppcTopic(), request);
842 } catch (Exception e) {
844 System.out.println("Can't deliver request: " + request);
849 // what happens if it is null
857 // Construct an operation
859 ControlLoopOperation operation = new ControlLoopOperation();
860 operation.actor = $params.getActor();
861 operation.operation = "createModuleInstance";
862 operation.target = $event.target;
864 // Create operationWrapper
866 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
868 // Construct an MSO request
870 MSORequest request = new MSORequest();
871 request.requestDetails = new MSORequestDetails();
872 request.requestDetails.modelInfo = new MSOModelInfo();
873 request.requestDetails.cloudConfiguration = new MSOCloudConfiguration();
874 request.requestDetails.requestInfo = new MSORequestInfo();
875 request.requestDetails.requestParameters = new MSORequestParameters();
876 request.requestDetails.requestParameters.userParams = null;
878 // cloudConfiguration
880 request.requestDetails.cloudConfiguration.lcpCloudRegionId = cloudRegionItemCloudRegionId;
881 request.requestDetails.cloudConfiguration.tenantId = tenantItemTenantId;
885 request.requestDetails.modelInfo.modelType = "vfModule";
886 request.requestDetails.modelInfo.modelInvariantId = vfModuleItemPersonaModelId;
887 request.requestDetails.modelInfo.modelNameVersionId = vfModuleItemModelNameVersionId;
888 request.requestDetails.modelInfo.modelName = vfModuleItemModelName;
889 request.requestDetails.modelInfo.modelVersion = vfModuleItemPersonaModelVersion;
893 request.requestDetails.requestInfo.instanceName = vfModuleItemVfModuleName;
894 request.requestDetails.requestInfo.source = "POLICY";
895 request.requestDetails.requestInfo.suppressRollback = false;
897 // relatedInstanceList
899 MSORelatedInstanceListElement relatedInstanceListElement1 = new MSORelatedInstanceListElement();
900 MSORelatedInstanceListElement relatedInstanceListElement2 = new MSORelatedInstanceListElement();
901 relatedInstanceListElement1.relatedInstance = new MSORelatedInstance();
902 relatedInstanceListElement2.relatedInstance = new MSORelatedInstance();
904 relatedInstanceListElement1.relatedInstance.instanceId = serviceItemServiceInstanceId;
905 relatedInstanceListElement1.relatedInstance.modelInfo = new MSOModelInfo();
906 relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service";
907 relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = serviceItemPersonaModelId;
908 relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = serviceItemModelNameVersionId;
909 relatedInstanceListElement1.relatedInstance.modelInfo.modelName = serviceItemModelName;
910 relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = serviceItemModelVersion;
912 relatedInstanceListElement2.relatedInstance.instanceId = vnfItemVnfId;
913 relatedInstanceListElement2.relatedInstance.modelInfo = new MSOModelInfo();
914 relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf";
915 relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = vnfItemPersonaModelId;
916 relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = vnfItemModelNameVersionId;
917 relatedInstanceListElement2.relatedInstance.modelInfo.modelName = vnfItemModelName;
918 relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = vnfItemPersonaModelVersion;
919 relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = vnfItemVnfType;
921 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1);
922 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2);
924 // print MSO request for debug
926 System.out.println("MSO request sent:");
927 System.out.println(Serialization.gsonPretty.toJson(request));
931 if (request != null) {
933 // Tell interested parties we are performing this Operation
935 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
936 notification.notification = ControlLoopNotificationType.OPERATION;
937 notification.from = "policy";
938 notification.policyName = drools.getRule().getName();
939 notification.policyScope = "${policyScope}";
940 notification.policyVersion = "${policyVersion}";
942 System.out.println(Serialization.gsonPretty.toJson(notification));
943 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
944 } catch (Exception e) {
945 System.out.println("Can't deliver notification: " + notification);
949 // Concatenate serviceItemServiceInstanceId and vnfItemVnfId to msoURL
951 String MSOUrl = $params.getMsoURL() + "/serviceInstances/v2/" + serviceItemServiceInstanceId + "/vnfs/" + vnfItemVnfId + "/vfModules";
955 MSOResponse response = MSOManager.createModuleInstance(MSOUrl, $params.getMsoURL(), $params.getMsoUsername(), $params.getMsoPassword(), request);
959 //////////////////////////////////////////////////////////
960 // Simulate a valid MSOResponse for junit test
961 // Remove this for real deployment
963 response = new MSOResponse();
964 response.request = new MSORequest();
965 response.request.requestStatus = new MSORequestStatus();
966 response.request.requestStatus.requestState = "COMPLETE";
967 //////////////////////////////////////////////////////////
973 if (response != null) {
977 request.requestId = $event.requestID.toString();
978 response.request.requestId = $event.requestID.toString();
982 insert(operationWrapper);
987 // MSO request not even accepted
989 notification.message = operationWrapper.operation.toMessage();
990 operationWrapper.operation.message = operationWrapper.operation.toMessage();
991 operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
992 $manager.setControlLoopResult("FAILURE_EXCEPTION");
993 notification.history.add(operationWrapper.operation);
994 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
996 // Let interested parties know
999 System.out.println(Serialization.gsonPretty.toJson(notification));
1000 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1001 } catch (Exception e) {
1002 System.out.println("Can't deliver notification: " + notification);
1003 e.printStackTrace();
1005 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
1007 System.out.println(Serialization.gsonPretty.toJson(notification));
1008 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1009 } catch (Exception e) {
1010 System.out.println("Can't deliver notification: " + notification);
1011 e.printStackTrace();
1014 // Retract everything
1020 System.err.println("constructed MSO request is invalid.");
1029 * This rule responds to APPC Response Events
1032 rule "${policyName}.APPC.RESPONSE"
1034 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
1035 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
1036 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
1037 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
1038 $request : Request( getCommonHeader().RequestID == $event.requestID )
1039 $response : Response( getCommonHeader().RequestID == $event.requestID )
1041 System.out.println("rule APPC.RESPONSE is triggered.");
1042 if ($response.Status == null) {
1043 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
1044 $manager.setControlLoopResult("FAILURE_EXCEPTION");
1047 // Get the Response Code
1049 ResponseCode code = ResponseCode.toResponseCode($response.Status.Code);
1051 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
1052 $manager.setControlLoopResult("FAILURE_EXCEPTION");
1055 // Construct notification
1057 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
1058 notification.from = "policy";
1059 notification.policyName = drools.getRule().getName();
1060 notification.policyScope = "${policyScope}";
1061 notification.policyVersion = "${policyVersion}";
1062 notification.message = $operationWrapper.operation.toMessage();
1063 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
1065 // Ok, let's figure out what APP-C's response is
1069 $operationWrapper.operation.outcome = "PROCESSING";
1073 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
1074 $manager.setControlLoopResult("FAILURE_EXCEPTION");
1077 $operationWrapper.operation.outcome = "SUCCESS";
1078 $manager.setControlLoopResult("SUCCESS");
1081 $operationWrapper.operation.outcome = "FAILURE";
1082 $manager.setControlLoopResult("FAILURE");
1085 if ($operationWrapper.operation.outcome.equals("SUCCESS")) {
1086 notification.history.add($operationWrapper.operation);
1087 notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
1089 // Let interested parties know
1092 System.out.println(Serialization.gsonPretty.toJson(notification));
1093 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1094 } catch (Exception e) {
1095 System.out.println("Can't deliver notification: " + notification);
1096 e.printStackTrace();
1098 notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
1100 System.out.println(Serialization.gsonPretty.toJson(notification));
1101 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1102 } catch (Exception e) {
1103 System.out.println("Can't deliver notification: " + notification);
1104 e.printStackTrace();
1108 // We are going to retract these objects from memory
1110 System.out.println("Retracting everything");
1111 retract($operationWrapper);
1116 } else if ($operationWrapper.operation.outcome.equals("PROCESSING")) {
1119 notification.history.add($operationWrapper.operation);
1120 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
1122 // Let interested parties know
1125 System.out.println(Serialization.gsonPretty.toJson(notification));
1126 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1127 } catch (Exception e) {
1128 System.out.println("Can't deliver notification: " + notification);
1129 e.printStackTrace();
1131 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
1133 // Let interested parties know
1136 System.out.println(Serialization.gsonPretty.toJson(notification));
1137 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1138 } catch (Exception e) {
1139 System.out.println("Can't deliver notification: " + notification);
1140 e.printStackTrace();
1143 // We are going to retract these objects from memory
1145 System.out.println("Retracting everything");
1146 retract($operationWrapper);
1157 * This rule is used to clean up APPC response
1160 rule "${policyName}.APPC.RESPONSE.CLEANUP"
1162 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
1163 $response : Response($id : getCommonHeader().RequestID )
1164 not ( VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), requestID == $id, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) )
1166 System.out.println("rule APPC.RESPONSE.CLEANUP is triggered.");
1172 * This rule responds to MSO Response Events
1175 rule "${policyName}.MSO.RESPONSE"
1177 $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
1178 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
1179 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
1180 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
1181 $request : MSORequest( requestId == $event.requestID.toString() )
1182 $response : MSOResponse( request.requestId == $event.requestID.toString() )
1184 System.out.println("rule MSO.RESPONSE is triggered.");
1186 // Construct notification
1188 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
1189 notification.from = "policy";
1190 notification.policyName = drools.getRule().getName();
1191 notification.policyScope = "${policyScope}";
1192 notification.policyVersion = "${policyVersion}";
1193 notification.message = $operationWrapper.operation.toMessage();
1194 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
1196 // The operation can either be succeeded or failed
1198 if($response.request.requestStatus.requestState.equals("Completed")) {
1199 $operationWrapper.operation.outcome = "SUCCESS";
1200 $manager.setControlLoopResult("SUCCESS");
1201 notification.history.add($operationWrapper.operation);
1202 notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
1204 // Let interested parties know
1207 System.out.println(Serialization.gsonPretty.toJson(notification));
1208 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1209 } catch (Exception e) {
1210 System.out.println("Can't deliver notification: " + notification);
1211 e.printStackTrace();
1213 notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
1215 // Let interested parties know
1218 System.out.println(Serialization.gsonPretty.toJson(notification));
1219 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1220 } catch (Exception e) {
1221 System.out.println("Can't deliver notification: " + notification);
1222 e.printStackTrace();
1225 // We are going to retract these objects from memory
1227 System.out.println("Retracting everything");
1228 retract($operationWrapper);
1234 $operationWrapper.operation.outcome = "FAILURE";
1235 $manager.setControlLoopResult("FAILURE");
1236 notification.history.add($operationWrapper.operation);
1237 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
1239 // Let interested parties know
1242 System.out.println(Serialization.gsonPretty.toJson(notification));
1243 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1244 } catch (Exception e) {
1245 System.out.println("Can't deliver notification: " + notification);
1246 e.printStackTrace();
1248 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
1250 // Let interested parties know
1253 System.out.println(Serialization.gsonPretty.toJson(notification));
1254 //PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1255 } catch (Exception e) {
1256 System.out.println("Can't deliver notification: " + notification);
1257 e.printStackTrace();
1260 // We are going to retract these objects from memory
1262 System.out.println("Retracting everything");
1263 retract($operationWrapper);