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.openecomp.policy.controlloop;
28 import java.util.LinkedList;
30 import java.util.HashMap;
31 import java.util.UUID;
33 import org.openecomp.policy.controlloop.VirtualControlLoopEvent;
34 import org.openecomp.policy.controlloop.ControlLoopEventStatus;
35 import org.openecomp.policy.controlloop.VirtualControlLoopNotification;
36 import org.openecomp.policy.controlloop.ControlLoopNotificationType;
37 import org.openecomp.policy.controlloop.ControlLoopOperation;
38 import org.openecomp.policy.controlloop.ControlLoopOperationWrapper;
39 import org.openecomp.policy.template.demo.ControlLoopException;
41 import org.openecomp.policy.aai.AAINQF199.AAINQF199CloudRegion;
42 import org.openecomp.policy.aai.AAINQF199.AAINQF199ExtraProperties;
43 import org.openecomp.policy.aai.AAINQF199.AAINQF199ExtraProperty;
44 import org.openecomp.policy.aai.AAINQF199.AAINQF199GenericVNF;
45 import org.openecomp.policy.aai.AAINQF199.AAINQF199InstanceFilters;
46 import org.openecomp.policy.aai.AAINQF199.AAINQF199InventoryResponseItem;
47 import org.openecomp.policy.aai.AAINQF199.AAINQF199InventoryResponseItems;
48 import org.openecomp.policy.aai.AAINQF199.AAINQF199Manager;
49 import org.openecomp.policy.aai.AAINQF199.AAINQF199NamedQuery;
50 import org.openecomp.policy.aai.AAINQF199.AAINQF199QueryParameters;
51 import org.openecomp.policy.aai.AAINQF199.AAINQF199Request;
52 import org.openecomp.policy.aai.AAINQF199.AAINQF199RequestWrapper;
53 import org.openecomp.policy.aai.AAINQF199.AAINQF199Response;
54 import org.openecomp.policy.aai.AAINQF199.AAINQF199ResponseWrapper;
55 import org.openecomp.policy.aai.AAINQF199.AAINQF199ServiceInstance;
56 import org.openecomp.policy.aai.AAINQF199.AAINQF199Tenant;
57 import org.openecomp.policy.aai.AAINQF199.AAINQF199VfModule;
58 import org.openecomp.policy.aai.AAINQF199.AAINQF199VServer;
59 import org.openecomp.policy.aai.util.Serialization;
61 import org.openecomp.policy.appc.CommonHeader;
62 import org.openecomp.policy.appc.Request;
63 import org.openecomp.policy.appc.Response;
64 import org.openecomp.policy.appc.ResponseCode;
65 import org.openecomp.policy.appc.ResponseStatus;
66 import org.openecomp.policy.appc.ResponseValue;
68 import org.openecomp.policy.template.demo.EventManager;
69 import org.openecomp.policy.vnf.trafficgenerator.PGRequest;
70 import org.openecomp.policy.vnf.trafficgenerator.PGStream;
71 import org.openecomp.policy.vnf.trafficgenerator.PGStreams;
73 import org.openecomp.policy.mso.MSOManager;
74 import org.openecomp.policy.mso.MSORequest;
75 import org.openecomp.policy.mso.MSORequestStatus;
76 import org.openecomp.policy.mso.MSORequestDetails;
77 import org.openecomp.policy.mso.MSOModelInfo;
78 import org.openecomp.policy.mso.MSOCloudConfiguration;
79 import org.openecomp.policy.mso.MSORequestInfo;
80 import org.openecomp.policy.mso.MSORequestParameters;
81 import org.openecomp.policy.mso.MSORelatedInstanceListElement;
82 import org.openecomp.policy.mso.MSORelatedInstance;
83 import org.openecomp.policy.mso.MSOResponse;
85 import org.openecomp.policy.drools.system.PolicyEngine;
88 // These parameters are required to build the runtime policy
91 closedLoopControlName : String
99 aaiNamedQueryUUID : String
100 aaiPatternMatch : int
101 notificationTopic : String
107 * Called once and only once to insert the parameters into working memory for this Closed Loop policy.
108 * (Comment SETUP rule out for the first ECOMP opensource release since policy BRMS_GW already puts a Params fact in there)
111 *rule "BRMSParamvLBDemoPolicy.SETUP"
114 * System.out.println("rule SETUP is triggered.");
115 * Params params = new Params();
116 * params.setClosedLoopControlName("CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8");
117 * params.setActor("MSO");
118 * params.setAaiURL("https://aai.api.simpledemo.openecomp.org:8443");
119 * params.setAaiUsername("POLICY");
120 * params.setAaiPassword("POLICY");
121 * params.setMsoURL("http://vm1.mso.simpledemo.openecomp.org:8080/ecomp/mso/infra");
122 * params.setMsoUsername("InfraPortalClient");
123 * params.setMsoPassword("password1$");
124 * params.setAaiNamedQueryUUID("f199cb88-5e69-4b1f-93e0-6f257877d066");
125 * params.setAaiPatternMatch(0);
126 * params.setNotificationTopic("POLICY-CL-MGT");
127 * params.setAppcTopic("APPC-CL");
129 * // This stays in memory as long as the rule is alive and running
136 * This rule responds to DCAE Events
139 rule "BRMSParamvLBDemoPolicy.EVENT"
141 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
142 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
143 not ( EventManager( closedLoopControlName == $event.closedLoopControlName ))
145 System.out.println("rule EVENT is triggered.");
148 // Check the requestID in the event to make sure it is not null before we create the EventManager.
149 // The EventManager will do extra syntax checking as well check if the closed loop is disabled/
151 if ($event.requestID == null) {
152 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
153 notification.notification = ControlLoopNotificationType.REJECTED;
154 notification.from = "policy";
155 notification.message = "Missing requestID from DCAE event";
156 notification.policyName = drools.getRule().getName();
157 notification.policyScope = "com";
158 notification.policyVersion = "1";
160 // Let interested parties know
163 System.out.println(Serialization.gsonPretty.toJson(notification));
164 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
165 } catch (Exception e) {
167 System.out.println("Can't deliver notification: " + notification);
170 // Retract it from memory
173 System.out.println("Event with requestID=null has been retracted.");
176 // Create an EventManager
178 EventManager manager = new EventManager($params.getClosedLoopControlName(), $event.requestID, $event.target);
180 // Determine if EventManager can actively process the event (i.e. syntax)
182 VirtualControlLoopNotification notification = manager.activate($event);
183 notification.from = "policy";
184 notification.policyName = drools.getRule().getName();
185 notification.policyScope = "com";
186 notification.policyVersion = "1";
188 // Are we actively pursuing this event?
190 if (notification.notification == ControlLoopNotificationType.ACTIVE) {
192 // Insert Event Manager into memory, this will now kick off processing.
196 // Let interested parties know
199 System.out.println(Serialization.gsonPretty.toJson(notification));
200 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
201 } catch (Exception e) {
203 System.out.println("Can't deliver notification: " + notification);
207 // Let interested parties know
210 System.out.println(Serialization.gsonPretty.toJson(notification));
211 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
212 } catch (Exception e) {
214 System.out.println("Can't deliver notification: " + notification);
217 // Retract it from memory
222 // Now that the manager is inserted into Drools working memory, we'll wait for
223 // another rule to fire in order to continue processing. This way we can also
224 // then screen for additional ONSET and ABATED events for this same RequestIDs
225 // and for different RequestIDs but with the same closedLoopControlName and target.
229 } catch (Exception e) {
231 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
232 notification.notification = ControlLoopNotificationType.REJECTED;
233 notification.message = "Exception occurred " + e.getMessage();
234 notification.policyName = drools.getRule().getName();
235 notification.policyScope = "com";
236 notification.policyVersion = "1";
241 System.out.println(Serialization.gsonPretty.toJson(notification));
242 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
243 } catch (Exception e1) {
244 System.out.println("Can't deliver notification: " + notification);
245 e1.printStackTrace();
256 * This rule happens when we got a valid ONSET, closed loop is enabled and an Event Manager
257 * is created. We can start the operations for this closed loop.
260 rule "BRMSParamvLBDemoPolicy.EVENT.MANAGER"
262 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
263 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
264 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName, controlLoopResult == null)
266 System.out.println("rule EVENT.MANAGER is triggered.");
268 // Check which event this is.
270 EventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event);
272 // We only want the initial ONSET event in memory,
273 // all the other events need to be retracted to support
274 // cleanup and avoid the other rules being fired for this event.
276 if (eventStatus != EventManager.NEW_EVENT_STATUS.FIRST_ONSET) {
277 System.out.println("Retracting "+eventStatus+" Event.");
282 // Now the event in memory is first onset event
286 // Pull the known AAI field from the Event
288 // generic-vnf is needed for vFirewall case
289 // vserver-name is needed for vLoadBalancer case
291 String genericVNF = $event.AAI.get("generic-vnf.vnf-id");
292 String vserver = $event.AAI.get("vserver.vserver-name");
294 // Check if we are implementing a simple pattern match.
296 if ($params.getAaiPatternMatch() == 1) {
300 //Basic naming characteristics:
301 //VF Name (9 char)+VM name (13 char total)+VFC (19 char total)
303 //VF Name (9 characters): cscf0001v
304 //VM Name(13 characters): cscf0001vm001
305 //VFC name(19 characters): cscf0001vm001cfg001
307 // zdfw1fwl01fwl02 or zdfw1fwl01fwl01
309 // zdfw1fwl01pgn02 or zdfw1fwl01pgn01
311 int index = genericVNF.lastIndexOf("fwl");
313 System.err.println("The generic-vnf.vnf-id from DCAE Event is not valid.");
315 genericVNF = genericVNF.substring(0, index) + "pgn" + genericVNF.substring(index+"fwl".length());
318 // Construct an APPC request
320 ControlLoopOperation operation = new ControlLoopOperation();
321 operation.actor = $params.getActor();
322 operation.operation = "ModifyConfig";
323 operation.target = $event.target;
325 // Create operationWrapper
327 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
329 // insert operationWrapper into memory
331 insert(operationWrapper);
333 Request request = new Request();
334 request.CommonHeader = new CommonHeader();
335 request.CommonHeader.RequestID = $event.requestID;
336 request.Action = operation.operation;
337 request.Payload = new HashMap<String, Object>();
339 // Fill in the payload
341 request.Payload.put("generic-vnf.vnf-id", genericVNF);
343 PGRequest pgRequest = new PGRequest();
344 pgRequest.pgStreams = new PGStreams();
347 for(int i = 0; i < 5; i++){
348 pgStream = new PGStream();
349 pgStream.streamId = "fw_udp"+(i+1);
350 pgStream.isEnabled = "true";
351 pgRequest.pgStreams.pgStream.add(pgStream);
353 request.Payload.put("pg-streams", pgRequest.pgStreams);
355 if (request != null) {
357 // Insert request into memory
361 // Tell interested parties we are performing this Operation
363 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
364 notification.notification = ControlLoopNotificationType.OPERATION;
365 // message and history ??
366 notification.from = "policy";
367 notification.policyName = drools.getRule().getName();
368 notification.policyScope = "com";
369 notification.policyVersion = "1";
371 System.out.println(Serialization.gsonPretty.toJson(notification));
372 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
373 } catch (Exception e) {
374 System.out.println("Can't deliver notification: " + notification);
378 // Now send the operation request
380 if (request instanceof Request) {
382 System.out.println("APPC request sent:");
383 System.out.println(Serialization.gsonPretty.toJson(request));
384 PolicyEngine.manager.deliver($params.getAppcTopic(), request);
385 } catch (Exception e) {
387 System.out.println("Can't deliver request: " + request);
392 // what happens if it is null
398 // create AAI named-query request with UUID started with "F199"
400 AAINQF199Request aainqf199request = new AAINQF199Request();
401 AAINQF199QueryParameters aainqf199queryparam = new AAINQF199QueryParameters();
402 AAINQF199NamedQuery aainqf199namedquery = new AAINQF199NamedQuery();
403 AAINQF199InstanceFilters aainqf199instancefilter = new AAINQF199InstanceFilters();
407 aainqf199namedquery.namedQueryUUID = UUID.fromString($params.getAaiNamedQueryUUID());
408 aainqf199queryparam.namedQuery = aainqf199namedquery;
409 aainqf199request.queryParameters = aainqf199queryparam;
413 Map aainqf199instancefiltermap = new HashMap();
414 Map aainqf199instancefiltermapitem = new HashMap();
415 aainqf199instancefiltermapitem.put("vserver-name", vserver);
416 aainqf199instancefiltermap.put("vserver", aainqf199instancefiltermapitem);
417 aainqf199instancefilter.instanceFilter.add(aainqf199instancefiltermap);
418 aainqf199request.instanceFilters = aainqf199instancefilter;
420 // print aainqf199request for debug
422 System.out.println("AAI Request sent:");
423 System.out.println(Serialization.gsonPretty.toJson(aainqf199request));
425 // Create AAINQF199RequestWrapper
427 AAINQF199RequestWrapper aainqf199RequestWrapper = new AAINQF199RequestWrapper($event.requestID, aainqf199request);
429 // insert aainqf199request into memory
431 insert(aainqf199RequestWrapper);
434 } catch (Exception e) {
441 * This rule happens when we got a valid ONSET, closed loop is enabled, an Event Manager
442 * is created, AAI Manager and AAI Request are ready in memory. We can start sending query to AAI and then wait for response.
445 rule "BRMSParamvLBDemoPolicy.EVENT.MANAGER.AAINQF199REQUEST"
447 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
448 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
449 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
450 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
452 System.out.println("rule EVENT.MANAGER.AAINQF199REQUEST is triggered.");
456 AAINQF199Response aainqf199response = AAINQF199Manager.postQuery($params.getAaiURL(), $params.getAaiUsername(), $params.getAaiPassword(),
457 $aainqf199RequestWrapper.aainqf199request, $event.requestID);
459 // Check AAI response
461 if (aainqf199response == null) {
462 System.err.println("Failed to get AAI response");
464 // Fail and retract everything
468 retract($aainqf199RequestWrapper);
471 // Create AAINQF199ResponseWrapper
473 AAINQF199ResponseWrapper aainqf199ResponseWrapper = new AAINQF199ResponseWrapper($event.requestID, aainqf199response);
475 // insert aainqf199ResponseWrapper to memeory
477 insert(aainqf199ResponseWrapper);
483 * This rule happens when we got a valid AAI response. We can start sending request to APPC or MSO now.
486 rule "BRMSParamvLBDemoPolicy.EVENT.MANAGER.AAINQF199RESPONSE"
488 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
489 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
490 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
491 $aainqf199RequestWrapper : AAINQF199RequestWrapper(requestID == $event.requestID)
492 $aainqf199ResponseWrapper : AAINQF199ResponseWrapper(requestID == $event.requestID)
494 System.out.println("rule EVENT.MANAGER.AAINQF199RESPONSE is triggered.");
496 // Extract related fields out of AAINQF199RESPONSE
498 String vnfItemVnfId, vnfItemVnfType, vnfItemPersonaModelId, vnfItemPersonaModelVersion, vnfItemModelName,
499 vnfItemModelVersion, vnfItemModelNameVersionId, serviceItemServiceInstanceId, serviceItemPersonaModelId,
500 serviceItemModelName, serviceItemModelType, serviceItemModelVersion, serviceItemModelNameVersionId,
501 vfModuleItemVfModuleName, vfModuleItemPersonaModelId, vfModuleItemPersonaModelVersion, vfModuleItemModelName,
502 vfModuleItemModelNameVersionId, tenantItemTenantId, cloudRegionItemCloudRegionId;
507 vnfItemVnfId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfID;
508 vnfItemVnfType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfType;
509 vnfItemVnfType = vnfItemVnfType.substring(vnfItemVnfType.lastIndexOf("/")+1);
510 vnfItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelId;
511 vnfItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelVersion;
512 vnfItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
513 vnfItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(2).propertyValue;
514 vnfItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
518 serviceItemServiceInstanceId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.serviceInstanceID;
519 serviceItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelId;
520 serviceItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue;
521 serviceItemModelType = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(1).propertyValue;
522 serviceItemModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelVersion;
523 serviceItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue;
525 // This comes from the base module
527 vfModuleItemVfModuleName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).vfModule.vfModuleName;
528 vfModuleItemVfModuleName = vfModuleItemVfModuleName.replace("Vfmodule", "vDNS");
530 // vfModuleItem - NOT the base module
532 vfModuleItemPersonaModelId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(2).vfModule.personaModelId;
533 vfModuleItemPersonaModelVersion = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(2).vfModule.personaModelVersion;
534 vfModuleItemModelName = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(2).extraProperties.extraProperty.get(0).propertyValue;
535 vfModuleItemModelNameVersionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(2).extraProperties.extraProperty.get(4).propertyValue;
539 tenantItemTenantId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).tenant.tenantId;
543 cloudRegionItemCloudRegionId = $aainqf199ResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).items.inventoryResponseItems.get(0).cloudRegion.cloudRegionId;
545 } catch (Exception e) {
547 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
548 notification.notification = ControlLoopNotificationType.REJECTED;
549 notification.message = "Exception occurred " + e.getMessage();
550 notification.policyName = drools.getRule().getName();
551 notification.policyScope = "com";
552 notification.policyVersion = "1";
555 System.out.println(Serialization.gsonPretty.toJson(notification));
556 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
557 } catch (Exception e1) {
558 System.out.println("Can't deliver notification: " + notification);
559 e1.printStackTrace();
562 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
563 notification.message = "Invalid named-query response from AAI";
566 System.out.println(Serialization.gsonPretty.toJson(notification));
567 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
568 } catch (Exception e1) {
569 System.out.println("Can't deliver notification: " + notification);
570 e1.printStackTrace();
573 // Retract everything
575 retract($aainqf199RequestWrapper);
576 retract($aainqf199ResponseWrapper);
582 // Extracted fields should not be null
584 if ((vnfItemVnfId == null) || (vnfItemVnfType == null) ||
585 (vnfItemPersonaModelId == null) || (vnfItemModelName == null) ||
586 (vnfItemModelVersion == null) || (vnfItemModelNameVersionId == null) ||
587 (serviceItemServiceInstanceId == null) || (serviceItemModelName == null) ||
588 (serviceItemModelType == null) || (serviceItemModelVersion == null) ||
589 (serviceItemModelNameVersionId == null) || (vfModuleItemVfModuleName == null) ||
590 (vfModuleItemPersonaModelId == null) || (vfModuleItemPersonaModelVersion == null) ||
591 (vfModuleItemModelName == null) || (vfModuleItemModelNameVersionId == null) ||
592 (tenantItemTenantId == null) || (cloudRegionItemCloudRegionId == null)) {
594 System.err.println("some fields are missing from AAI response.");
596 // Fail and retract everything
598 retract($aainqf199RequestWrapper);
599 retract($aainqf199ResponseWrapper);
605 // We don't need them any more
607 retract($aainqf199ResponseWrapper);
608 retract($aainqf199RequestWrapper);
610 // check the actor of this closed loop
612 switch ($params.getActor()) {
616 // Construct an APPC request
618 ControlLoopOperation operation = new ControlLoopOperation();
619 operation.actor = $params.getActor();
620 operation.operation = "ModifyConfig";
621 operation.target = $event.target;
623 // Create operationWrapper
625 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
627 // insert operationWrapper into memory
629 insert(operationWrapper);
631 Request request = new Request();
632 request.CommonHeader = new CommonHeader();
633 request.CommonHeader.RequestID = $event.requestID;
634 request.Action = operation.operation;
635 request.Payload = new HashMap<String, Object>();
637 // Fill in the payload
638 // Hardcode genericVNF for now since AAI has not been ready for vFirewall demo case
640 String genericVNF = "zdfw1fwl01pgn02";
641 request.Payload.put("generic-vnf.vnf-id", genericVNF);
643 PGRequest pgRequest = new PGRequest();
644 pgRequest.pgStreams = new PGStreams();
647 for(int i = 0; i < 5; i++){
648 pgStream = new PGStream();
649 pgStream.streamId = "fw_udp"+(i+1);
650 pgStream.isEnabled = "true";
651 pgRequest.pgStreams.pgStream.add(pgStream);
653 request.Payload.put("pg-streams", pgRequest.pgStreams);
655 if (request != null) {
657 // Insert request into memory
661 // Tell interested parties we are performing this Operation
663 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
664 notification.notification = ControlLoopNotificationType.OPERATION;
665 // message and history ??
666 notification.from = "policy";
667 notification.policyName = drools.getRule().getName();
668 notification.policyScope = "com";
669 notification.policyVersion = "1";
671 System.out.println(Serialization.gsonPretty.toJson(notification));
672 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
673 } catch (Exception e) {
674 System.out.println("Can't deliver notification: " + notification);
678 // Now send the operation request
680 if (request instanceof Request) {
682 System.out.println("APPC request sent:");
683 System.out.println(Serialization.gsonPretty.toJson(request));
684 PolicyEngine.manager.deliver($params.getAppcTopic(), request);
685 } catch (Exception e) {
687 System.out.println("Can't deliver request: " + request);
692 // what happens if it is null
700 // Construct an operation
702 ControlLoopOperation operation = new ControlLoopOperation();
703 operation.actor = $params.getActor();
704 operation.operation = "createModuleInstance";
705 operation.target = $event.target;
707 // Create operationWrapper
709 ControlLoopOperationWrapper operationWrapper = new ControlLoopOperationWrapper($event.requestID, operation);
711 // Construct an MSO request
713 MSORequest request = new MSORequest();
714 request.requestDetails = new MSORequestDetails();
715 request.requestDetails.modelInfo = new MSOModelInfo();
716 request.requestDetails.cloudConfiguration = new MSOCloudConfiguration();
717 request.requestDetails.requestInfo = new MSORequestInfo();
718 request.requestDetails.requestParameters = new MSORequestParameters();
719 request.requestDetails.requestParameters.userParams = null;
721 // cloudConfiguration
723 request.requestDetails.cloudConfiguration.lcpCloudRegionId = cloudRegionItemCloudRegionId;
724 request.requestDetails.cloudConfiguration.tenantId = tenantItemTenantId;
728 request.requestDetails.modelInfo.modelType = "vfModule";
729 request.requestDetails.modelInfo.modelInvariantId = vfModuleItemPersonaModelId;
730 request.requestDetails.modelInfo.modelNameVersionId = vfModuleItemModelNameVersionId;
731 request.requestDetails.modelInfo.modelName = vfModuleItemModelName;
732 request.requestDetails.modelInfo.modelVersion = vfModuleItemPersonaModelVersion;
736 request.requestDetails.requestInfo.instanceName = vfModuleItemVfModuleName;
737 request.requestDetails.requestInfo.source = "POLICY";
738 request.requestDetails.requestInfo.suppressRollback = false;
740 // relatedInstanceList
742 MSORelatedInstanceListElement relatedInstanceListElement1 = new MSORelatedInstanceListElement();
743 MSORelatedInstanceListElement relatedInstanceListElement2 = new MSORelatedInstanceListElement();
744 relatedInstanceListElement1.relatedInstance = new MSORelatedInstance();
745 relatedInstanceListElement2.relatedInstance = new MSORelatedInstance();
747 relatedInstanceListElement1.relatedInstance.instanceId = serviceItemServiceInstanceId;
748 relatedInstanceListElement1.relatedInstance.modelInfo = new MSOModelInfo();
749 relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service";
750 relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = serviceItemPersonaModelId;
751 relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = serviceItemModelNameVersionId;
752 relatedInstanceListElement1.relatedInstance.modelInfo.modelName = serviceItemModelName;
753 relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = serviceItemModelVersion;
755 relatedInstanceListElement2.relatedInstance.instanceId = vnfItemVnfId;
756 relatedInstanceListElement2.relatedInstance.modelInfo = new MSOModelInfo();
757 relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf";
758 relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = vnfItemPersonaModelId;
759 relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = vnfItemModelNameVersionId;
760 relatedInstanceListElement2.relatedInstance.modelInfo.modelName = vnfItemModelName;
761 relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = vnfItemModelVersion;
762 relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = vnfItemVnfType;
764 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1);
765 request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2);
767 // print MSO request for debug
769 System.out.println("MSO request sent:");
770 System.out.println(Serialization.gsonPretty.toJson(request));
774 if (request != null) {
776 // Tell interested parties we are performing this Operation
778 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
779 notification.notification = ControlLoopNotificationType.OPERATION;
780 notification.from = "policy";
781 notification.policyName = drools.getRule().getName();
782 notification.policyScope = "com";
783 notification.policyVersion = "1";
785 System.out.println(Serialization.gsonPretty.toJson(notification));
786 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
787 } catch (Exception e) {
788 System.out.println("Can't deliver notification: " + notification);
792 // Concatenate serviceItemServiceInstanceId and vnfItemVnfId to msoURL
794 String MSOUrl = $params.getMsoURL() + "/serviceInstances/v2/" + serviceItemServiceInstanceId + "/vnfs/" + vnfItemVnfId + "/vfModules";
798 MSOResponse response = MSOManager.createModuleInstance(MSOUrl, $params.getMsoURL(), $params.getMsoUsername(), $params.getMsoPassword(), request);
800 if (response != null) {
804 request.requestId = $event.requestID.toString();
805 response.request.requestId = $event.requestID.toString();
809 insert(operationWrapper);
814 // MSO request not even accepted
816 notification.message = operationWrapper.operation.toMessage();
817 operationWrapper.operation.message = operationWrapper.operation.toMessage();
818 operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
819 $manager.setControlLoopResult("FAILURE_EXCEPTION");
820 notification.history.add(operationWrapper.operation);
821 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
823 // Let interested parties know
826 System.out.println(Serialization.gsonPretty.toJson(notification));
827 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
828 } catch (Exception e) {
829 System.out.println("Can't deliver notification: " + notification);
832 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
834 System.out.println(Serialization.gsonPretty.toJson(notification));
835 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
836 } catch (Exception e) {
837 System.out.println("Can't deliver notification: " + notification);
841 // Retract everything
847 System.err.println("constructed MSO request is invalid.");
856 * This rule responds to APPC Response Events
859 rule "BRMSParamvLBDemoPolicy.APPC.RESPONSE"
861 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
862 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
863 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
864 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
865 $request : Request( getCommonHeader().RequestID == $event.requestID )
866 $response : Response( getCommonHeader().RequestID == $event.requestID )
868 System.out.println("rule APPC.RESPONSE is triggered.");
869 if ($response.Status == null) {
870 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
871 $manager.setControlLoopResult("FAILURE_EXCEPTION");
874 // Get the Response Code
876 ResponseCode code = ResponseCode.toResponseCode($response.Status.Code);
878 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
879 $manager.setControlLoopResult("FAILURE_EXCEPTION");
882 // Construct notification
884 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
885 notification.from = "policy";
886 notification.policyName = drools.getRule().getName();
887 notification.policyScope = "com";
888 notification.policyVersion = "1";
889 notification.message = $operationWrapper.operation.toMessage();
890 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
892 // Ok, let's figure out what APP-C's response is
896 $operationWrapper.operation.outcome = "PROCESSING";
900 $operationWrapper.operation.outcome = "FAILURE_EXCEPTION";
901 $manager.setControlLoopResult("FAILURE_EXCEPTION");
904 $operationWrapper.operation.outcome = "SUCCESS";
905 $manager.setControlLoopResult("SUCCESS");
908 $operationWrapper.operation.outcome = "FAILURE";
909 $manager.setControlLoopResult("FAILURE");
912 if ($operationWrapper.operation.outcome.equals("SUCCESS")) {
913 notification.history.add($operationWrapper.operation);
914 notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
916 // Let interested parties know
919 System.out.println(Serialization.gsonPretty.toJson(notification));
920 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
921 } catch (Exception e) {
922 System.out.println("Can't deliver notification: " + notification);
925 notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
927 System.out.println(Serialization.gsonPretty.toJson(notification));
928 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
929 } catch (Exception e) {
930 System.out.println("Can't deliver notification: " + notification);
935 // We are going to retract these objects from memory
937 System.out.println("Retracting everything");
938 retract($operationWrapper);
943 } else if ($operationWrapper.operation.outcome.equals("PROCESSING")) {
946 notification.history.add($operationWrapper.operation);
947 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
949 // Let interested parties know
952 System.out.println(Serialization.gsonPretty.toJson(notification));
953 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
954 } catch (Exception e) {
955 System.out.println("Can't deliver notification: " + notification);
958 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
960 // Let interested parties know
963 System.out.println(Serialization.gsonPretty.toJson(notification));
964 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
965 } catch (Exception e) {
966 System.out.println("Can't deliver notification: " + notification);
970 // We are going to retract these objects from memory
972 System.out.println("Retracting everything");
973 retract($operationWrapper);
984 * This rule is used to clean up APPC response
987 rule "BRMSParamvLBDemoPolicy.APPC.RESPONSE.CLEANUP"
989 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
990 $response : Response($id : getCommonHeader().RequestID )
991 not ( VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), requestID == $id, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) )
993 System.out.println("rule APPC.RESPONSE.CLEANUP is triggered.");
999 * This rule responds to MSO Response Events
1002 rule "BRMSParamvLBDemoPolicy.MSO.RESPONSE"
1004 $params : Params( getClosedLoopControlName() == "CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8" )
1005 $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
1006 $manager : EventManager( closedLoopControlName == $event.closedLoopControlName )
1007 $operationWrapper : ControlLoopOperationWrapper( requestID == $event.requestID )
1008 $request : MSORequest( requestId == $event.requestID.toString() )
1009 $response : MSOResponse( request.requestId == $event.requestID.toString() )
1011 System.out.println("rule MSO.RESPONSE is triggered.");
1013 // Construct notification
1015 VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
1016 notification.from = "policy";
1017 notification.policyName = drools.getRule().getName();
1018 notification.policyScope = "com";
1019 notification.policyVersion = "1";
1020 notification.message = $operationWrapper.operation.toMessage();
1021 $operationWrapper.operation.message = $operationWrapper.operation.toMessage();
1023 // The operation can either be succeeded or failed
1025 if($response.request.requestStatus.requestState.equals("Completed")) {
1026 $operationWrapper.operation.outcome = "SUCCESS";
1027 $manager.setControlLoopResult("SUCCESS");
1028 notification.history.add($operationWrapper.operation);
1029 notification.notification = ControlLoopNotificationType.OPERATION_SUCCESS;
1031 // Let interested parties know
1034 System.out.println(Serialization.gsonPretty.toJson(notification));
1035 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1036 } catch (Exception e) {
1037 System.out.println("Can't deliver notification: " + notification);
1038 e.printStackTrace();
1040 notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
1042 // Let interested parties know
1045 System.out.println(Serialization.gsonPretty.toJson(notification));
1046 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1047 } catch (Exception e) {
1048 System.out.println("Can't deliver notification: " + notification);
1049 e.printStackTrace();
1052 // We are going to retract these objects from memory
1054 System.out.println("Retracting everything");
1055 retract($operationWrapper);
1061 $operationWrapper.operation.outcome = "FAILURE";
1062 $manager.setControlLoopResult("FAILURE");
1063 notification.history.add($operationWrapper.operation);
1064 notification.notification = ControlLoopNotificationType.OPERATION_FAILURE;
1066 // Let interested parties know
1069 System.out.println(Serialization.gsonPretty.toJson(notification));
1070 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1071 } catch (Exception e) {
1072 System.out.println("Can't deliver notification: " + notification);
1073 e.printStackTrace();
1075 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
1077 // Let interested parties know
1080 System.out.println(Serialization.gsonPretty.toJson(notification));
1081 PolicyEngine.manager.deliver($params.getNotificationTopic(), notification);
1082 } catch (Exception e) {
1083 System.out.println("Can't deliver notification: " + notification);
1084 e.printStackTrace();
1087 // We are going to retract these objects from memory
1089 System.out.println("Retracting everything");
1090 retract($operationWrapper);
1102 Params params = new Params();
1103 params.setAaiPatternMatch(0);
1104 params.setAppcTopic("APPC-CL");
1105 params.setAaiURL("https://aai.api.simpledemo.openecomp.org:8443");
1106 params.setMsoPassword("password1$");
1107 params.setClosedLoopControlName("CL-DNS-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8");
1108 params.setAaiUsername("POLICY");
1109 params.setMsoURL("http://vm1.mso.simpledemo.openecomp.org:8080/ecomp/mso/infra");
1110 params.setActor("MSO");
1111 params.setMsoUsername("InfraPortalClient");
1112 params.setAaiNamedQueryUUID("f199cb88-5e69-4b1f-93e0-6f257877d066");
1113 params.setAaiPassword("POLICY");
1114 params.setNotificationTopic("POLICY-CL-MGT");