1 /* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose.
2 <$%BRMSParamTemplate=ControlLoopDemo__closedLoopControlName%$>
7 * ============LICENSE_START=======================================================
8 * archetype-closed-loop-demo-rules
9 * ================================================================================
10 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
11 * ================================================================================
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.policy.controlloop;
28 import java.util.List;
29 import java.util.LinkedList;
31 import java.util.HashMap;
32 import java.util.UUID;
34 import org.onap.policy.controlloop.VirtualControlLoopEvent;
35 import org.onap.policy.controlloop.ControlLoopEventStatus;
36 import org.onap.policy.controlloop.VirtualControlLoopNotification;
37 import org.onap.policy.controlloop.ControlLoopNotificationType;
38 import org.onap.policy.controlloop.ControlLoopOperation;
39 import org.onap.policy.controlloop.ControlLoopOperationWrapper;
40 import org.onap.policy.template.demo.ControlLoopException;
42 import org.onap.policy.aai.AAINQF199.AAINQF199CloudRegion;
43 import org.onap.policy.aai.AAINQF199.AAINQF199ExtraProperties;
44 import org.onap.policy.aai.AAINQF199.AAINQF199ExtraProperty;
45 import org.onap.policy.aai.AAINQF199.AAINQF199GenericVNF;
46 import org.onap.policy.aai.AAINQF199.AAINQF199InstanceFilters;
47 import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItem;
48 import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItems;
49 import org.onap.policy.aai.AAINQF199.AAINQF199Manager;
50 import org.onap.policy.aai.AAINQF199.AAINQF199NamedQuery;
51 import org.onap.policy.aai.AAINQF199.AAINQF199QueryParameters;
52 import org.onap.policy.aai.AAINQF199.AAINQF199Request;
53 import org.onap.policy.aai.AAINQF199.AAINQF199RequestWrapper;
54 import org.onap.policy.aai.AAINQF199.AAINQF199Response;
55 import org.onap.policy.aai.AAINQF199.AAINQF199ResponseWrapper;
56 import org.onap.policy.aai.AAINQF199.AAINQF199ServiceInstance;
57 import org.onap.policy.aai.AAINQF199.AAINQF199Tenant;
58 import org.onap.policy.aai.AAINQF199.AAINQF199VfModule;
59 import org.onap.policy.aai.AAINQF199.AAINQF199VServer;
60 import org.onap.policy.aai.util.Serialization;
62 import org.onap.policy.appc.CommonHeader;
63 import org.onap.policy.appc.Request;
64 import org.onap.policy.appc.Response;
65 import org.onap.policy.appc.ResponseCode;
66 import org.onap.policy.appc.ResponseStatus;
67 import org.onap.policy.appc.ResponseValue;
69 import org.onap.policy.template.demo.EventManager;
70 import org.onap.policy.vnf.trafficgenerator.PGRequest;
71 import org.onap.policy.vnf.trafficgenerator.PGStream;
72 import org.onap.policy.vnf.trafficgenerator.PGStreams;
74 import org.onap.policy.mso.MSOManager;
75 import org.onap.policy.mso.MSORequest;
76 import org.onap.policy.mso.MSORequestStatus;
77 import org.onap.policy.mso.MSORequestDetails;
78 import org.onap.policy.mso.MSOModelInfo;
79 import org.onap.policy.mso.MSOCloudConfiguration;
80 import org.onap.policy.mso.MSORequestInfo;
81 import org.onap.policy.mso.MSORequestParameters;
82 import org.onap.policy.mso.MSORelatedInstanceListElement;
83 import org.onap.policy.mso.MSORelatedInstance;
84 import org.onap.policy.mso.MSOResponse;
86 import org.onap.policy.drools.system.PolicyEngine;
89 // These parameters are required to build the runtime policy
92 closedLoopControlName : String
100 aaiNamedQueryUUID : String
101 aaiPatternMatch : int
102 notificationTopic : String
108 * Called once and only once to insert the parameters into working memory for this Closed Loop policy.
109 * (Comment SETUP rule out for the first ONAP opensource release since policy BRMS_GW already puts a Params fact in there)
112 *rule "BRMSParamvFWDemoPolicy.SETUP"
115 * System.out.println("rule SETUP is triggered.");
116 * Params params = new Params();
117 * params.setClosedLoopControlName("CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8");
118 * params.setActor("APPC");
119 * params.setAaiURL("null");
120 * params.setAaiUsername("null");
121 * params.setAaiPassword("null");
122 * params.setMsoURL("null");
123 * params.setMsoUsername("null");
124 * params.setMsoPassword("null");
125 * params.setAaiNamedQueryUUID("null");
126 * params.setAaiPatternMatch(1);
127 * params.setNotificationTopic("POLICY-CL-MGT");
128 * params.setAppcTopic("APPC-CL");
130 * // This stays in memory as long as the rule is alive and running
137 * This rule responds to DCAE Events
140 rule "BRMSParamvFWDemoPolicy.EVENT"
142 $params : Params( getClosedLoopControlName() == "CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
143 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
144 not ( EventManager( closedLoopControlName == $event.closedLoopControlName ))
146 System.out.println("rule EVENT is triggered.");
149 // Check the requestID in the event to make sure it is not null before we create the EventManager.
150 // The EventManager will do extra syntax checking as well check if the closed loop is disabled/
152 if ($event.requestID == null) {
153 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
154 notification.notification = ControlLoopNotificationType.REJECTED;
155 notification.from = "policy";
156 notification.message = "Missing requestID from DCAE event";
157 notification.policyName = drools.getRule().getName();
158 notification.policyScope = "com";
159 notification.policyVersion = "1";
161 // Let interested parties know
164 System.out.println(Serialization.gsonPretty.toJson(notification));
165 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
166 } catch (Exception e) {
168 System.out.println("Can't deliver notification: " + notification);
171 // Retract it from memory
174 System.out.println("Event with requestID=null has been retracted.");
177 // Create an EventManager
179 EventManager manager = new EventManager($params.getClosedLoopControlName(), $event.requestID, $event.target);
181 // Determine if EventManager can actively process the event (i.e. syntax)
183 VirtualControlLoopNotification notification = manager.activate($event);
184 notification.from = "policy";
185 notification.policyName = drools.getRule().getName();
186 notification.policyScope = "com";
187 notification.policyVersion = "1";
189 // Are we actively pursuing this event?
191 if (notification.notification == ControlLoopNotificationType.ACTIVE) {
193 // Insert Event Manager into memory, this will now kick off processing.
197 // Let interested parties know
200 System.out.println(Serialization.gsonPretty.toJson(notification));
201 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
202 } catch (Exception e) {
204 System.out.println("Can't deliver notification: " + notification);
208 // Let interested parties know
211 System.out.println(Serialization.gsonPretty.toJson(notification));
212 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
213 } catch (Exception e) {
215 System.out.println("Can't deliver notification: " + notification);
218 // Retract it from memory
223 // Now that the manager is inserted into Drools working memory, we'll wait for
224 // another rule to fire in order to continue processing. This way we can also
225 // then screen for additional ONSET and ABATED events for this same RequestIDs
226 // and for different RequestIDs but with the same closedLoopControlName and target.
230 } catch (Exception e) {
232 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
233 notification.notification = ControlLoopNotificationType.REJECTED;
234 notification.message = "Exception occurred " + e.getMessage();
235 notification.policyName = drools.getRule().getName();
236 notification.policyScope = "com";
237 notification.policyVersion = "1";
242 System.out.println(Serialization.gsonPretty.toJson(notification));
243 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
244 } catch (Exception e1) {
245 System.out.println("Can't deliver notification: " + notification);
246 e1.printStackTrace();
257 * This rule happens when we got a valid ONSET, closed loop is enabled and an Event Manager
258 * is created. We can start the operations for this closed loop.
261 rule "BRMSParamvFWDemoPolicy.EVENT.MANAGER"
263 $params : Params( getClosedLoopControlName() == "CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
264 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
265 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName, controlLoopResult == null)
267 System.out.println("rule EVENT.MANAGER is triggered.");
269 // Check which event this is.
271 EventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event);
273 // We only want the initial ONSET event in memory,
274 // all the other events need to be retracted to support
275 // cleanup and avoid the other rules being fired for this event.
277 if (eventStatus != EventManager.NEW_EVENT_STATUS.FIRST_ONSET) {
278 System.out.println("Retracting "+eventStatus+" Event.");
283 // Now the event in memory is first onset event
287 // Pull the known AAI field from the Event
289 // generic-vnf is needed for vFirewall case
290 // vserver-name is needed for vLoadBalancer case
292 String genericVNF = $event.AAI.get("generic-vnf.vnf-id");
293 String vserver = $event.AAI.get("vserver.vserver-name");
295 // Check if we are implementing a simple pattern match.
297 if ($params.getAaiPatternMatch() == 1) {
301 //Basic naming characteristics:
302 //VF Name (9 char)+VM name (13 char total)+VFC (19 char total)
304 //VF Name (9 characters): cscf0001v
305 //VM Name(13 characters): cscf0001vm001
306 //VFC name(19 characters): cscf0001vm001cfg001
308 // zdfw1fwl01fwl02 or zdfw1fwl01fwl01
310 // zdfw1fwl01pgn02 or zdfw1fwl01pgn01
312 int index = genericVNF.lastIndexOf("fwl");
314 System.err.println("The generic-vnf.vnf-id from DCAE Event is not valid.");
316 genericVNF = genericVNF.substring(0, index) + "pgn" + genericVNF.substring(index+"fwl".length());
319 // Construct an APPC request
321 ControlLoopOperation operation = new ControlLoopOperation();
322 operation.actor = $params.getActor();
323 operation.operation = "ModifyConfig";
324 operation.target = $event.target;
326 // Create operationWrapper
328 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
330 // insert operationWrapper into memory
332 insert(operationWrapper);
334 Request request = new Request();
335 request.CommonHeader = new CommonHeader();
336 request.CommonHeader.RequestID = $event.requestID;
337 request.Action = operation.operation;
338 request.Payload = new HashMap<String, Object>();
340 // Fill in the payload
342 request.Payload.put("generic-vnf.vnf-id", genericVNF);
344 PGRequest pgRequest = new PGRequest();
345 pgRequest.pgStreams = new PGStreams();
348 for(int i = 0; i < 5; i++){
349 pgStream = new PGStream();
350 pgStream.streamId = "fw_udp"+(i+1);
351 pgStream.isEnabled = "true";
352 pgRequest.pgStreams.pgStream.add(pgStream);
354 request.Payload.put("pg-streams", pgRequest.pgStreams);
356 if (request != null) {
358 // Insert request into memory
362 // Tell interested parties we are performing this Operation
364 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
365 notification.notification = ControlLoopNotificationType.OPERATION;
366 // message and history ??
367 notification.from = "policy";
368 notification.policyName = drools.getRule().getName();
369 notification.policyScope = "com";
370 notification.policyVersion = "1";
372 System.out.println(Serialization.gsonPretty.toJson(notification));
373 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
374 } catch (Exception e) {
375 System.out.println("Can't deliver notification: " + notification);
379 // Now send the operation request
381 if (request instanceof Request) {
383 System.out.println("APPC request sent:");
384 System.out.println(Serialization.gsonPretty.toJson(request));
385 PolicyEngine.manager.deliver($params.getAppcTopic(), request);
386 } catch (Exception e) {
388 System.out.println("Can't deliver request: " + request);
393 // what happens if it is null
399 // create AAI named-query request with UUID started with "F199"
401 AAINQF199Request aainqf199request = new AAINQF199Request();
402 AAINQF199QueryParameters aainqf199queryparam = new AAINQF199QueryParameters();
403 AAINQF199NamedQuery aainqf199namedquery = new AAINQF199NamedQuery();
404 AAINQF199InstanceFilters aainqf199instancefilter = new AAINQF199InstanceFilters();
408 aainqf199namedquery.namedQueryUUID = UUID.fromString($params.getAaiNamedQueryUUID());
409 aainqf199queryparam.namedQuery = aainqf199namedquery;
410 aainqf199request.queryParameters = aainqf199queryparam;
414 Map aainqf199instancefiltermap = new HashMap();
415 Map aainqf199instancefiltermapitem = new HashMap();
416 aainqf199instancefiltermapitem.put("vserver-name", vserver);
417 aainqf199instancefiltermap.put("vserver", aainqf199instancefiltermapitem);
418 aainqf199instancefilter.instanceFilter.add(aainqf199instancefiltermap);
419 aainqf199request.instanceFilters = aainqf199instancefilter;
421 // print aainqf199request for debug
423 System.out.println("AAI Request sent:");
424 System.out.println(Serialization.gsonPretty.toJson(aainqf199request));
426 // Create AAINQF199RequestWrapper
428 AAINQF199RequestWrapper aainqf199RequestWrapper = new AAINQF199RequestWrapper($event.requestID, aainqf199request);
430 // insert aainqf199request into memory
432 insert(aainqf199RequestWrapper);
435 } catch (Exception e) {
442 * This rule happens when we got a valid ONSET, closed loop is enabled, an Event Manager
443 * is created, AAI Manager and AAI Request are ready in memory. We can start sending query to AAI and then wait for response.
446 rule "BRMSParamvFWDemoPolicy.EVENT.MANAGER.AAINQF199REQUEST"
448 $params : Params( getClosedLoopControlName() == "CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
449 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
450 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
451 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
453 System.out.println("rule EVENT.MANAGER.AAINQF199REQUEST is triggered.");
457 AAINQF199Response aainqf199response = AAINQF199Manager.postQuery($params.getAaiURL(), $params.getAaiUsername(), $params.getAaiPassword(),
458 $aainqf199RequestWrapper.aainqf199request, $event.requestID);
460 // Check AAI response
462 if (aainqf199response == null) {
463 System.err.println("Failed to get AAI response");
465 // Fail and retract everything
469 retract($aainqf199RequestWrapper);
472 // Create AAINQF199ResponseWrapper
474 AAINQF199ResponseWrapper aainqf199ResponseWrapper = new AAINQF199ResponseWrapper($event.requestID, aainqf199response);
476 // insert aainqf199ResponseWrapper to memeory
478 insert(aainqf199ResponseWrapper);
484 * This rule happens when we got a valid AAI response. We can start sending request to APPC or MSO now.
487 rule "BRMSParamvFWDemoPolicy.EVENT.MANAGER.AAINQF199RESPONSE"
489 $params : Params( getClosedLoopControlName() == "CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
490 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
491 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
492 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
493 $aainqf199ResponseWrapper : AAINQF199ResponseWrapper(requestID == $event.requestID)
495 System.out.println("rule EVENT.MANAGER.AAINQF199RESPONSE is triggered.");
497 // Extract related fields out of AAINQF199RESPONSE
499 String vnfItemVnfId, vnfItemVnfType, vnfItemPersonaModelId, vnfItemPersonaModelVersion, vnfItemModelName,
500 vnfItemModelVersion, vnfItemModelNameVersionId, serviceItemServiceInstanceId, serviceItemPersonaModelId,
501 serviceItemModelName, serviceItemModelType, serviceItemModelVersion, serviceItemModelNameVersionId,
502 vfModuleItemVfModuleName, vfModuleItemPersonaModelId, vfModuleItemPersonaModelVersion, vfModuleItemModelName,
503 vfModuleItemModelNameVersionId, tenantItemTenantId, cloudRegionItemCloudRegionId;
508 vnfItemVnfId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfID;
509 vnfItemVnfType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfType;
510 vnfItemVnfType = vnfItemVnfType.substring(vnfItemVnfType.lastIndexOf("/")+1);
511 vnfItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelId;
512 vnfItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelVersion;
513 vnfItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
514 vnfItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(2).propertyValue;
515 vnfItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
519 serviceItemServiceInstanceId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.serviceInstanceID;
520 serviceItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelId;
521 serviceItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
522 serviceItemModelType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(1).propertyValue;
523 serviceItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelVersion;
524 serviceItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
526 // Find the index for base vf module and non-base vf module
529 int nonBaseIndex = -1;
530 List<AAINQF199InventoryResponseItem> inventoryItems = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems;
531 for (AAINQF199InventoryResponseItem m : inventoryItems) {
532 if (m.vfModule != null && m.vfModule.isBaseVfModule == true) {
533 baseIndex = inventoryItems.indexOf(m);
534 } else if (m.vfModule != null && m.vfModule.isBaseVfModule == false && m.vfModule.orchestrationStatus == null) {
535 nonBaseIndex = inventoryItems.indexOf(m);
538 if (baseIndex != -1 && nonBaseIndex != -1) {
543 // Report the error if either base vf module or non-base vf module is not found
545 if (baseIndex == -1 || nonBaseIndex == -1) {
546 System.err.println("Either base or non-base vf module is not found from AAI response.");
547 retract($aainqf199RequestWrapper);
548 retract($aainqf199ResponseWrapper);
554 // This comes from the base module
556 vfModuleItemVfModuleName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(baseIndex).vfModule.vfModuleName;
557 vfModuleItemVfModuleName = vfModuleItemVfModuleName.replace("Vfmodule", "vDNS");
559 // vfModuleItem - NOT the base module
561 vfModuleItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelId;
562 vfModuleItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelVersion;
563 vfModuleItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(0).propertyValue;
564 vfModuleItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(4).propertyValue;
568 tenantItemTenantId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).tenant.tenantId;
572 cloudRegionItemCloudRegionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).items.inventoryResponseItems.get(0).cloudRegion.cloudRegionId;
574 } catch (Exception e) {
576 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
577 notification.notification = ControlLoopNotificationType.REJECTED;
578 notification.message = "Exception occurred " + e.getMessage();
579 notification.policyName = drools.getRule().getName();
580 notification.policyScope = "com";
581 notification.policyVersion = "1";
584 System.out.println(Serialization.gsonPretty.toJson(notification));
585 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
586 } catch (Exception e1) {
587 System.out.println("Can't deliver notification: " + notification);
588 e1.printStackTrace();
591 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
592 notification.message = "Invalid named-query response from AAI";
595 System.out.println(Serialization.gsonPretty.toJson(notification));
596 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
597 } catch (Exception e1) {
598 System.out.println("Can't deliver notification: " + notification);
599 e1.printStackTrace();
602 // Retract everything
604 retract($aainqf199RequestWrapper);
605 retract($aainqf199ResponseWrapper);
611 // Extracted fields should not be null
613 if ((vnfItemVnfId == null) || (vnfItemVnfType == null) ||
614 (vnfItemPersonaModelId == null) || (vnfItemModelName == null) ||
615 (vnfItemModelVersion == null) || (vnfItemModelNameVersionId == null) ||
616 (serviceItemServiceInstanceId == null) || (serviceItemModelName == null) ||
617 (serviceItemModelType == null) || (serviceItemModelVersion == null) ||
618 (serviceItemModelNameVersionId == null) || (vfModuleItemVfModuleName == null) ||
619 (vfModuleItemPersonaModelId == null) || (vfModuleItemPersonaModelVersion == null) ||
620 (vfModuleItemModelName == null) || (vfModuleItemModelNameVersionId == null) ||
621 (tenantItemTenantId == null) || (cloudRegionItemCloudRegionId == null)) {
623 System.err.println("some fields are missing from AAI response.");
625 // Fail and retract everything
627 retract($aainqf199RequestWrapper);
628 retract($aainqf199ResponseWrapper);
634 // We don't need them any more
636 retract($aainqf199ResponseWrapper);
637 retract($aainqf199RequestWrapper);
639 // check the actor of this closed loop
641 switch ($params.getActor()) {
645 // Construct an APPC request
647 ControlLoopOperation operation = new ControlLoopOperation();
648 operation.actor = $params.getActor();
649 operation.operation = "ModifyConfig";
650 operation.target = $event.target;
652 // Create operationWrapper
654 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
656 // insert operationWrapper into memory
658 insert(operationWrapper);
660 Request request = new Request();
661 request.CommonHeader = new CommonHeader();
662 request.CommonHeader.RequestID = $event.requestID;
663 request.Action = operation.operation;
664 request.Payload = new HashMap<String, Object>();
666 // Fill in the payload
667 // Hardcode genericVNF for now since AAI has not been ready for vFirewall demo case
669 String genericVNF = "zdfw1fwl01pgn02";
670 request.Payload.put("generic-vnf.vnf-id", genericVNF);
672 PGRequest pgRequest = new PGRequest();
673 pgRequest.pgStreams = new PGStreams();
676 for(int i = 0; i < 5; i++){
677 pgStream = new PGStream();
678 pgStream.streamId = "fw_udp"+(i+1);
679 pgStream.isEnabled = "true";
680 pgRequest.pgStreams.pgStream.add(pgStream);
682 request.Payload.put("pg-streams", pgRequest.pgStreams);
684 if (request != null) {
686 // Insert request into memory
690 // Tell interested parties we are performing this Operation
692 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
693 notification.notification = ControlLoopNotificationType.OPERATION;
694 // message and history ??
695 notification.from = "policy";
696 notification.policyName = drools.getRule().getName();
697 notification.policyScope = "com";
698 notification.policyVersion = "1";
700 System.out.println(Serialization.gsonPretty.toJson(notification));
701 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
702 } catch (Exception e) {
703 System.out.println("Can't deliver notification: " + notification);
707 // Now send the operation request
709 if (request instanceof Request) {
711 System.out.println("APPC request sent:");
712 System.out.println(Serialization.gsonPretty.toJson(request));
713 PolicyEngine.manager.deliver($params.getAppcTopic(), request);
714 } catch (Exception e) {
716 System.out.println("Can't deliver request: " + request);
721 // what happens if it is null
729 // Construct an operation
731 ControlLoopOperation operation = new ControlLoopOperation();
732 operation.actor = $params.getActor();
733 operation.operation = "createModuleInstance";
734 operation.target = $event.target;
736 // Create operationWrapper
738 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
740 // Construct an MSO request
742 MSORequest request = new MSORequest();
743 request.requestDetails = new MSORequestDetails();
744 request.requestDetails.modelInfo = new MSOModelInfo();
745 request.requestDetails.cloudConfiguration = new MSOCloudConfiguration();
746 request.requestDetails.requestInfo = new MSORequestInfo();
747 request.requestDetails.requestParameters = new MSORequestParameters();
748 request.requestDetails.requestParameters.userParams = null;
750 // cloudConfiguration
752 request.requestDetails.cloudConfiguration.lcpCloudRegionId = cloudRegionItemCloudRegionId;
753 request.requestDetails.cloudConfiguration.tenantId = tenantItemTenantId;
757 request.requestDetails.modelInfo.modelType = "vfModule";
758 request.requestDetails.modelInfo.modelInvariantId = vfModuleItemPersonaModelId;
759 request.requestDetails.modelInfo.modelNameVersionId = vfModuleItemModelNameVersionId;
760 request.requestDetails.modelInfo.modelName = vfModuleItemModelName;
761 request.requestDetails.modelInfo.modelVersion = vfModuleItemPersonaModelVersion;
765 request.requestDetails.requestInfo.instanceName = vfModuleItemVfModuleName;
766 request.requestDetails.requestInfo.source = "POLICY";
767 request.requestDetails.requestInfo.suppressRollback = false;
769 // relatedInstanceList
771 MSORelatedInstanceListElement relatedInstanceListElement1 = new MSORelatedInstanceListElement();
772 MSORelatedInstanceListElement relatedInstanceListElement2 = new MSORelatedInstanceListElement();
773 relatedInstanceListElement1.relatedInstance = new MSORelatedInstance();
774 relatedInstanceListElement2.relatedInstance = new MSORelatedInstance();
776 relatedInstanceListElement1.relatedInstance.instanceId = serviceItemServiceInstanceId;
777 relatedInstanceListElement1.relatedInstance.modelInfo = new MSOModelInfo();
778 relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service";
779 relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = serviceItemPersonaModelId;
780 relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = serviceItemModelNameVersionId;
781 relatedInstanceListElement1.relatedInstance.modelInfo.modelName = serviceItemModelName;
782 relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = serviceItemModelVersion;
784 relatedInstanceListElement2.relatedInstance.instanceId = vnfItemVnfId;
785 relatedInstanceListElement2.relatedInstance.modelInfo = new MSOModelInfo();
786 relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf";
787 relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = vnfItemPersonaModelId;
788 relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = vnfItemModelNameVersionId;
789 relatedInstanceListElement2.relatedInstance.modelInfo.modelName = vnfItemModelName;
790 relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = vnfItemModelVersion;
791 relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = vnfItemVnfType;
793 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1);
794 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2);
796 // print MSO request for debug
798 System.out.println("MSO request sent:");
799 System.out.println(Serialization.gsonPretty.toJson(request));
803 if (request != null) {
805 // Tell interested parties we are performing this Operation
807 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
808 notification.notification = ControlLoopNotificationType.OPERATION;
809 notification.from = "policy";
810 notification.policyName = drools.getRule().getName();
811 notification.policyScope = "com";
812 notification.policyVersion = "1";
814 System.out.println(Serialization.gsonPretty.toJson(notification));
815 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
816 } catch (Exception e) {
817 System.out.println("Can't deliver notification: " + notification);
821 // Concatenate serviceItemServiceInstanceId and vnfItemVnfId to msoURL
823 String MSOUrl = $params.getMsoURL() + "/serviceInstances/v2/" + serviceItemServiceInstanceId + "/vnfs/" + vnfItemVnfId + "/vfModules";
827 MSOResponse response = MSOManager.createModuleInstance(MSOUrl, $params.getMsoURL(), $params.getMsoUsername(), $params.getMsoPassword(), request);
829 if (response != null) {
833 request.requestId = $event.requestID.toString();
834 response.request.requestId = $event.requestID.toString();
838 insert(operationWrapper);
843 // MSO request not even accepted
845 notification.message = operationWrapper.operation.toMessage();
846 operationWrapper.operation.message = operationWrapper.operation.toMessage();
847 operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
848 $manager.setControlLoopResult("FAILURE_EXCEPTION");
849 notification.history.add(operationWrapper.operation);
850 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
852 // Let interested parties know
855 System.out.println(Serialization.gsonPretty.toJson(notification));
856 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
857 } catch (Exception e) {
858 System.out.println("Can't deliver notification: " + notification);
861 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
863 System.out.println(Serialization.gsonPretty.toJson(notification));
864 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
865 } catch (Exception e) {
866 System.out.println("Can't deliver notification: " + notification);
870 // Retract everything
876 System.err.println("constructed MSO request is invalid.");
885 * This rule responds to APPC Response Events
888 rule "BRMSParamvFWDemoPolicy.APPC.RESPONSE"
890 $params : Params( getClosedLoopControlName() == "CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
891 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
892 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
893 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
894 $request : Request( getCommonHeader().RequestID == $event.requestID )
895 $response : Response( getCommonHeader().RequestID == $event.requestID )
897 System.out.println("rule APPC.RESPONSE is triggered.");
898 if ($response.Status == null) {
899 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
900 $manager.setControlLoopResult("FAILURE_EXCEPTION");
903 // Get the Response Code
905 ResponseCode code = ResponseCode.toResponseCode($response.Status.Code);
907 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
908 $manager.setControlLoopResult("FAILURE_EXCEPTION");
911 // Construct notification
913 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
914 notification.from = "policy";
915 notification.policyName = drools.getRule().getName();
916 notification.policyScope = "com";
917 notification.policyVersion = "1";
918 notification.message = $operationWrapper.operation.toMessage();
919 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
921 // Ok, let's figure out what APP-C's response is
925 $operationWrapper.operation.outcome = "PROCESSING";
929 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
930 $manager.setControlLoopResult("FAILURE_EXCEPTION");
933 $operationWrapper.operation.outcome = "SUCCESS";
934 $manager.setControlLoopResult("SUCCESS");
937 $operationWrapper.operation.outcome = "FAILURE";
938 $manager.setControlLoopResult("FAILURE");
941 if ($operationWrapper.operation.outcome.equals("SUCCESS")) {
942 notification.history.add($operationWrapper.operation);
943 notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
945 // Let interested parties know
948 System.out.println(Serialization.gsonPretty.toJson(notification));
949 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
950 } catch (Exception e) {
951 System.out.println("Can't deliver notification: " + notification);
954 notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
956 System.out.println(Serialization.gsonPretty.toJson(notification));
957 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
958 } catch (Exception e) {
959 System.out.println("Can't deliver notification: " + notification);
964 // We are going to retract these objects from memory
966 System.out.println("Retracting everything");
967 retract($operationWrapper);
972 } else if ($operationWrapper.operation.outcome.equals("PROCESSING")) {
975 notification.history.add($operationWrapper.operation);
976 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
978 // Let interested parties know
981 System.out.println(Serialization.gsonPretty.toJson(notification));
982 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
983 } catch (Exception e) {
984 System.out.println("Can't deliver notification: " + notification);
987 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
989 // Let interested parties know
992 System.out.println(Serialization.gsonPretty.toJson(notification));
993 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
994 } catch (Exception e) {
995 System.out.println("Can't deliver notification: " + notification);
999 // We are going to retract these objects from memory
1001 System.out.println("Retracting everything");
1002 retract($operationWrapper);
1013 * This rule is used to clean up APPC response
1016 rule "BRMSParamvFWDemoPolicy.APPC.RESPONSE.CLEANUP"
1018 $params : Params( getClosedLoopControlName() == "CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
1019 $response : Response($id : getCommonHeader().RequestID )
1020 not ( VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), requestID == $id, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) )
1022 System.out.println("rule APPC.RESPONSE.CLEANUP is triggered.");
1028 * This rule responds to MSO Response Events
1031 rule "BRMSParamvFWDemoPolicy.MSO.RESPONSE"
1033 $params : Params( getClosedLoopControlName() == "CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
1034 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
1035 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
1036 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
1037 $request : MSORequest( requestId == $event.requestID.toString() )
1038 $response : MSOResponse( request.requestId == $event.requestID.toString() )
1040 System.out.println("rule MSO.RESPONSE is triggered.");
1042 // Construct notification
1044 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
1045 notification.from = "policy";
1046 notification.policyName = drools.getRule().getName();
1047 notification.policyScope = "com";
1048 notification.policyVersion = "1";
1049 notification.message = $operationWrapper.operation.toMessage();
1050 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
1052 // The operation can either be succeeded or failed
1054 if($response.request.requestStatus.requestState.equals("COMPLETE")) {
1055 $operationWrapper.operation.outcome = "SUCCESS";
1056 $manager.setControlLoopResult("SUCCESS");
1057 notification.history.add($operationWrapper.operation);
1058 notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
1060 // Let interested parties know
1063 System.out.println(Serialization.gsonPretty.toJson(notification));
1064 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1065 } catch (Exception e) {
1066 System.out.println("Can't deliver notification: " + notification);
1067 e.printStackTrace();
1069 notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
1071 // Let interested parties know
1074 System.out.println(Serialization.gsonPretty.toJson(notification));
1075 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1076 } catch (Exception e) {
1077 System.out.println("Can't deliver notification: " + notification);
1078 e.printStackTrace();
1081 // We are going to retract these objects from memory
1083 System.out.println("Retracting everything");
1084 retract($operationWrapper);
1090 $operationWrapper.operation.outcome = "FAILURE";
1091 $manager.setControlLoopResult("FAILURE");
1092 notification.history.add($operationWrapper.operation);
1093 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
1095 // Let interested parties know
1098 System.out.println(Serialization.gsonPretty.toJson(notification));
1099 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1100 } catch (Exception e) {
1101 System.out.println("Can't deliver notification: " + notification);
1102 e.printStackTrace();
1104 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
1106 // Let interested parties know
1109 System.out.println(Serialization.gsonPretty.toJson(notification));
1110 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1111 } catch (Exception e) {
1112 System.out.println("Can't deliver notification: " + notification);
1113 e.printStackTrace();
1116 // We are going to retract these objects from memory
1118 System.out.println("Retracting everything");
1119 retract($operationWrapper);
1127 rule "com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.Params"
1131 Params params = new Params();
1132 params.setAaiPatternMatch(1);
1133 params.setAppcTopic("APPC-CL");
1134 params.setAaiURL("null");
1135 params.setMsoPassword("null");
1136 params.setClosedLoopControlName("CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8");
1137 params.setMsoURL("null");
1138 params.setAaiUsername("null");
1139 params.setActor("APPC");
1140 params.setMsoUsername("null");
1141 params.setAaiNamedQueryUUID("null");
1142 params.setAaiPassword("null");
1143 params.setNotificationTopic("POLICY-CL-MGT");