2b296616df9fae2d920455c9802b6090df8cfc60
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * controlloop event manager
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.controlloop.eventmanager;
22
23 import java.io.Serializable;
24 import java.io.UnsupportedEncodingException;
25 import java.net.URLDecoder;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.LinkedList;
29 import java.util.UUID;
30
31 import org.onap.policy.aai.AAIGETVnfResponse;
32 import org.onap.policy.aai.AAIGETVserverResponse;
33 import org.onap.policy.aai.AAIManager;
34 import org.onap.policy.aai.util.AAIException;
35 import org.onap.policy.controlloop.ControlLoopEventStatus;
36 import org.onap.policy.controlloop.ControlLoopException;
37 import org.onap.policy.controlloop.ControlLoopNotificationType;
38 import org.onap.policy.controlloop.ControlLoopOperation;
39 import org.onap.policy.controlloop.VirtualControlLoopEvent;
40 import org.onap.policy.controlloop.VirtualControlLoopNotification;
41 import org.onap.policy.controlloop.policy.FinalResult;
42 import org.onap.policy.controlloop.policy.Policy;
43 import org.onap.policy.controlloop.processor.ControlLoopProcessor;
44 import org.onap.policy.guard.GuardResult;
45 import org.onap.policy.guard.LockCallback;
46 import org.onap.policy.guard.PolicyGuard;
47 import org.onap.policy.guard.PolicyGuard.LockResult;
48 import org.onap.policy.guard.TargetLock;
49 import org.onap.policy.rest.RESTManager;
50 import org.onap.policy.drools.system.PolicyEngine; 
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53
54 public class ControlLoopEventManager implements LockCallback, Serializable {
55         
56         /**
57          * 
58          */
59         private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManager.class);
60         
61         private static final long serialVersionUID = -1216568161322872641L;
62         public final String closedLoopControlName;
63         public final UUID requestID;
64         
65         private String controlLoopResult;
66         private transient ControlLoopProcessor processor = null;
67         private VirtualControlLoopEvent onset;
68         private Integer numOnsets = 0;
69         private Integer numAbatements = 0;
70         private VirtualControlLoopEvent abatement;
71         private FinalResult controlLoopTimedOut = null;
72
73         private boolean isActivated = false;
74         private LinkedList<ControlLoopOperation> controlLoopHistory = new LinkedList<>();
75         private ControlLoopOperationManager currentOperation = null;
76         private transient TargetLock targetLock = null;
77         private AAIGETVnfResponse vnfResponse = null;
78         private AAIGETVserverResponse vserverResponse = null;
79         private static String aaiHostURL; 
80         private static String aaiUser; 
81         private static String aaiPassword;
82         
83         private static Collection<String> requiredAAIKeys = new ArrayList<>();
84         static {
85                 requiredAAIKeys.add("AICVServerSelfLink");
86                 requiredAAIKeys.add("AICIdentity");
87                 requiredAAIKeys.add("is_closed_loop_disabled");
88                 requiredAAIKeys.add("VM_NAME");
89         }
90
91         public ControlLoopEventManager(String closedLoopControlName, UUID requestID) {
92                 this.closedLoopControlName = closedLoopControlName;
93                 this.requestID = requestID;
94         }
95         
96         public String getControlLoopResult() {
97                 return controlLoopResult;
98         }
99         
100         public void setControlLoopResult(String controlLoopResult) {
101                 this.controlLoopResult = controlLoopResult;
102         }
103         
104         public Integer getNumOnsets() {
105                 return numOnsets;
106         }
107
108         public void setNumOnsets(Integer numOnsets) {
109                 this.numOnsets = numOnsets;
110         }
111
112         public Integer getNumAbatements() {
113                 return numAbatements;
114         }
115
116         public void setNumAbatements(Integer numAbatements) {
117                 this.numAbatements = numAbatements;
118         }
119
120         public boolean isActivated() {
121                 return isActivated;
122         }
123
124         public void setActivated(boolean isActivated) {
125                 this.isActivated = isActivated;
126         }
127         
128         public VirtualControlLoopEvent  getOnsetEvent() {
129                 return this.onset;
130         }
131         
132         public VirtualControlLoopEvent getAbatementEvent() {
133                 return this.abatement;
134         }
135         
136         public ControlLoopProcessor getProcessor() {
137                 return this.processor;
138         }
139
140         public VirtualControlLoopNotification   activate(VirtualControlLoopEvent event) {
141                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification(event);
142                 try {
143                         //
144                         // This method should ONLY be called ONCE
145                         //
146                         if (this.isActivated) {
147                                 throw new ControlLoopException("ControlLoopEventManager has already been activated.");
148                         }
149                         //
150                         // Syntax check the event
151                         //
152                         checkEventSyntax(event);
153                         
154                         //
155                         // At this point we are good to go with this event
156                         //
157                         this.onset = event;
158                         this.numOnsets = 1;
159                         //
160                         notification.setNotification(ControlLoopNotificationType.ACTIVE);
161                         //
162                         // Set ourselves as active
163                         //
164                         this.isActivated = true;
165                 } catch (ControlLoopException e) {
166                         logger.error("{}: activate threw: ",this, e);
167                         notification.setNotification(ControlLoopNotificationType.REJECTED);
168                         notification.setMessage(e.getMessage());
169                 }
170                 return notification;
171         }
172         
173         
174         
175         public VirtualControlLoopNotification   activate(String yamlSpecification, VirtualControlLoopEvent event) {
176                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification(event);
177                 try {
178                         //
179                         // This method should ONLY be called ONCE
180                         //
181                         if (this.isActivated) {
182                                 throw new ControlLoopException("ControlLoopEventManager has already been activated.");
183                         }
184                         //
185                         // Syntax check the event
186                         //
187                         checkEventSyntax(event);
188         
189                         //
190                         // Check the YAML
191                         //
192                         if (yamlSpecification == null || yamlSpecification.length() < 1) {
193                                 throw new ControlLoopException("yaml specification is null or 0 length");
194                         }
195                         String decodedYaml = null;
196                         try {
197                                 decodedYaml = URLDecoder.decode(yamlSpecification, "UTF-8");
198                                 if (decodedYaml != null && decodedYaml.length() > 0) {
199                                         yamlSpecification = decodedYaml;
200                                 }
201                         } catch (UnsupportedEncodingException e) {
202                                 logger.error("{}: activate threw: ",this, e);
203                         }
204                         //
205                         // Parse the YAML specification
206                         //
207                         this.processor = new ControlLoopProcessor(yamlSpecification);
208                         
209                         //
210                         // At this point we are good to go with this event
211                         //
212                         this.onset = event;
213                         this.numOnsets = 1;
214                         //
215                         //
216                         //
217                         notification.setNotification(ControlLoopNotificationType.ACTIVE);
218                         //
219                         // Set ourselves as active
220                         //
221                         this.isActivated = true;
222                 } catch (ControlLoopException e) {
223                         logger.error("{}: activate threw: ",this, e);
224                         notification.setNotification(ControlLoopNotificationType.REJECTED);
225                         notification.setMessage(e.getMessage());
226                 }
227                 return notification;
228         }
229         
230         public VirtualControlLoopNotification   isControlLoopFinal() throws ControlLoopException {
231                 //
232                 // Check if they activated us
233                 //
234                 if (this.isActivated == false) {
235                         throw new ControlLoopException("ControlLoopEventManager MUST be activated first.");
236                 }
237                 //
238                 // Make sure we are expecting this call.
239                 //
240                 if (this.onset == null) {
241                         throw new ControlLoopException("No onset event for ControlLoopEventManager.");
242                 }
243                 //
244                 // Ok, start creating the notification
245                 //
246                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification(this.onset);
247                 //
248                 // Check if the overall control loop has timed out
249                 //
250                 if (this.isControlLoopTimedOut()) {
251                         //
252                         // Yes we have timed out
253                         //
254                         notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE);
255                         notification.setMessage("Control Loop timed out");
256                         notification.getHistory().addAll(this.controlLoopHistory);
257                         return notification;                    
258                 }
259                 //
260                 // Check if the current policy is Final
261                 //
262                 FinalResult result = this.processor.checkIsCurrentPolicyFinal();
263                 if (result == null) {
264                         //
265                         // we are not at a final result
266                         //
267                         return null;
268                 }
269         
270                 switch (result) {
271                 case FINAL_FAILURE_EXCEPTION:
272                         notification.setMessage("Exception in processing closed loop");
273                 case FINAL_FAILURE:
274                 case FINAL_FAILURE_RETRIES:
275                 case FINAL_FAILURE_TIMEOUT:
276                 case FINAL_FAILURE_GUARD:
277                         notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE);
278                         break;
279                 case FINAL_OPENLOOP:
280                         notification.setNotification(ControlLoopNotificationType.FINAL_OPENLOOP);
281                         break;
282                 case FINAL_SUCCESS:
283                         notification.setNotification(ControlLoopNotificationType.FINAL_SUCCESS);
284                         break;
285                 default:
286                         return null;
287                 }
288                 //
289                 // Be sure to add all the history
290                 //
291                 notification.getHistory().addAll(this.controlLoopHistory);
292                 return notification;
293         }
294                 
295         public ControlLoopOperationManager      processControlLoop() throws ControlLoopException, AAIException {
296                 //
297                 // Check if they activated us
298                 //
299                 if (this.isActivated == false) {
300                         throw new ControlLoopException("ControlLoopEventManager MUST be activated first.");
301                 }
302                 //
303                 // Make sure we are expecting this call.
304                 //
305                 if (this.onset == null) {
306                         throw new ControlLoopException("No onset event for ControlLoopEventManager.");
307                 }
308                 //
309                 // Is there a current operation?
310                 //
311                 if (this.currentOperation != null) {
312                         //
313                         // Throw an exception, or simply return the current operation?
314                         //
315                         throw new ControlLoopException("Already working an Operation, do not call this method.");
316                 }
317                 //
318                 // Ensure we are not FINAL
319                 //
320                 VirtualControlLoopNotification notification = this.isControlLoopFinal();
321                 if (notification != null) {
322                         //
323                         // This is weird, we require them to call the isControlLoopFinal() method first
324                         //
325                         // We should really abstract this and avoid throwing an exception, because it really
326                         // isn't an exception.
327                         //
328                         throw new ControlLoopException("Control Loop is in FINAL state, do not call this method.");
329                 }
330                 //
331                 // Not final so get the policy that needs to be worked on.
332                 //
333                 Policy policy = this.processor.getCurrentPolicy();
334                 if (policy == null) {
335                         throw new ControlLoopException("ControlLoopEventManager: processor came upon null Policy.");
336                 }
337                 //
338                 // And setup an operation
339                 //
340                 this.currentOperation = new ControlLoopOperationManager(this.onset, policy, this);
341                 //
342                 // Return it
343                 //
344                 return this.currentOperation;
345         }
346         
347         public void finishOperation(ControlLoopOperationManager operation) throws ControlLoopException {
348                 //
349                 // Verify we have a current operation
350                 //
351                 if (this.currentOperation != null) {
352                         //
353                         // Validate they are finishing the current operation
354                         // PLD - this is simply comparing the policy. Do we want to equals the whole object?
355                         //
356                         if (this.currentOperation.policy.equals(operation.policy)) {
357                                 logger.debug("Finishing {} result is {}", this.currentOperation.policy.getRecipe(), this.currentOperation.getOperationResult());
358                                 //
359                                 // Save history
360                                 //
361                                 this.controlLoopHistory.addAll(this.currentOperation.getHistory());
362                                 //
363                                 // Move to the next Policy
364                                 //
365                                 this.processor.nextPolicyForResult(this.currentOperation.getOperationResult());
366                                 //
367                                 // Just null this out
368                                 //
369                                 this.currentOperation = null;
370                                 //
371                                 // TODO: Release our lock
372                                 //
373                                 return;
374                         }
375                         logger.debug("Cannot finish current operation {} does not match given operation {}", this.currentOperation.policy, operation.policy);
376                         return;
377                 }
378                 throw new ControlLoopException("No operation to finish.");
379         }
380         
381         public synchronized LockResult<GuardResult, TargetLock> lockCurrentOperation() throws ControlLoopException {
382                 //
383                 // Sanity check
384                 //
385                 if (this.currentOperation == null) {
386                         throw new ControlLoopException("Do not have a current operation.");
387                 }
388                 //
389                 // Have we acquired it already?
390                 //
391                 if (this.targetLock != null) {
392                         //
393                         // TODO: Make sure the current lock is for the same target.
394                         // Currently, it should be. But in the future it may not.
395                         //
396                         return new LockResult<GuardResult, TargetLock>(GuardResult.LOCK_ACQUIRED, this.targetLock);
397                 } else {
398                         //
399                         // Ask the Guard
400                         //
401                         LockResult<GuardResult, TargetLock> lockResult = PolicyGuard.lockTarget(
402                                                                                                                                                 this.currentOperation.policy.getTarget().getType(), 
403                                                                                                                                                 this.currentOperation.getTargetEntity(),
404                                                                                                                                                 this.onset.getRequestID(),
405                                                                                                                                                 this);
406                         //
407                         // Was it acquired?
408                         //
409                         if (lockResult.getA().equals(GuardResult.LOCK_ACQUIRED)) {
410                                 //
411                                 // Yes, let's save it
412                                 //
413                                 this.targetLock = lockResult.getB();
414                         }
415                         return lockResult;
416                 }
417         }
418         
419         public synchronized TargetLock unlockCurrentOperation() {
420                 if (this.targetLock == null) {
421                         return null;
422                 }
423                 if (PolicyGuard.unlockTarget(this.targetLock) == true) {
424                         TargetLock returnLock = this.targetLock;
425                         this.targetLock = null;
426                         return returnLock;
427                 }
428                 return null;
429         }
430         
431         public enum NEW_EVENT_STATUS {
432                 FIRST_ONSET,
433                 SUBSEQUENT_ONSET,
434                 FIRST_ABATEMENT,
435                 SUBSEQUENT_ABATEMENT,
436                 SYNTAX_ERROR
437                 ;
438         }
439                 
440         public NEW_EVENT_STATUS onNewEvent(VirtualControlLoopEvent event) throws AAIException {
441                 try {
442                         this.checkEventSyntax(event);
443                         if (event.getClosedLoopEventStatus() == ControlLoopEventStatus.ONSET) {
444                                 //
445                                 // Check if this is our original ONSET
446                                 //
447                                 if (event.equals(this.onset)) {
448                                     //
449                                     // Query A&AI if needed
450                                     //
451                                     queryAai(event);
452                                     
453                                         //
454                                         // DO NOT retract it
455                                         //
456                                         return NEW_EVENT_STATUS.FIRST_ONSET;
457                                 }
458                                 //
459                                 // Log that we got an onset
460                                 //
461                                 this.numOnsets++;
462                                 return NEW_EVENT_STATUS.SUBSEQUENT_ONSET;
463                         } else if (event.getClosedLoopEventStatus() == ControlLoopEventStatus.ABATED) {
464                                 //
465                                 // Have we already got an abatement?
466                                 //
467                                 if (this.abatement == null) {
468                                         //
469                                         // Save this
470                                         //
471                                         this.abatement = event;
472                                         //
473                                         // Keep track that we received another
474                                         //
475                                         this.numAbatements++;
476                                         //
477                                         //
478                                         //
479                                         return NEW_EVENT_STATUS.FIRST_ABATEMENT;
480                                 } else {
481                                         //
482                                         // Keep track that we received another
483                                         //
484                                         this.numAbatements++;
485                                         //
486                                         //
487                                         //
488                                         return NEW_EVENT_STATUS.SUBSEQUENT_ABATEMENT;
489                                 }
490                         } else {
491                                 return NEW_EVENT_STATUS.SYNTAX_ERROR;
492                         }
493                 } catch (ControlLoopException e) {
494                         logger.error("{}: onNewEvent threw: ",this, e);
495                         return NEW_EVENT_STATUS.SYNTAX_ERROR;
496                 }
497         }
498         
499         public VirtualControlLoopNotification setControlLoopTimedOut() {
500                 this.controlLoopTimedOut = FinalResult.FINAL_FAILURE_TIMEOUT;
501                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification(this.onset);
502                 notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE);
503                 notification.setMessage("Control Loop timed out");
504                 notification.getHistory().addAll(this.controlLoopHistory);
505                 return notification;                    
506         }
507         
508         public boolean isControlLoopTimedOut() {
509                 return (this.controlLoopTimedOut == FinalResult.FINAL_FAILURE_TIMEOUT);
510         }
511         
512         public int      getControlLoopTimeout(Integer defaultTimeout) {
513                 if (this.processor != null && this.processor.getControlLoop() != null) {
514                         return this.processor.getControlLoop().getTimeout();
515                 }
516                 if (defaultTimeout != null) {
517                         return defaultTimeout;
518                 }
519                 return 0;
520         }
521         
522         public AAIGETVnfResponse getVnfResponse() {
523                 return vnfResponse; 
524         }
525
526         public AAIGETVserverResponse getVserverResponse() {
527                 return vserverResponse; 
528         }
529         
530         public void checkEventSyntax(VirtualControlLoopEvent event) throws ControlLoopException {
531                 if (event.getClosedLoopEventStatus() == null || 
532                                 (event.getClosedLoopEventStatus() != ControlLoopEventStatus.ONSET &&
533                                 event.getClosedLoopEventStatus() != ControlLoopEventStatus.ABATED)) {
534                         throw new ControlLoopException("Invalid value in closedLoopEventStatus");
535                 }
536                 if (event.getClosedLoopControlName() == null || event.getClosedLoopControlName().length() < 1) {
537                         throw new ControlLoopException("No control loop name");
538                 }
539                 if (event.getRequestID() == null) {
540                         throw new ControlLoopException("No request ID");
541                 }
542                 if (event.getClosedLoopEventStatus() == ControlLoopEventStatus.ABATED) {
543                         return;
544                 }
545                 if (event.getTarget() == null || event.getTarget().length() < 1) {
546                         throw new ControlLoopException("No target field");
547                 } else if (! "VM_NAME".equalsIgnoreCase(event.getTarget()) &&
548                                 ! "VNF_NAME".equalsIgnoreCase(event.getTarget()) &&
549                                 ! "vserver.vserver-name".equalsIgnoreCase(event.getTarget()) &&
550                                 ! "generic-vnf.vnf-id".equalsIgnoreCase(event.getTarget()) &&
551                                 ! "generic-vnf.vnf-name".equalsIgnoreCase(event.getTarget()) ) {
552                         throw new ControlLoopException("target field invalid - expecting VM_NAME or VNF_NAME");
553                 }
554                 if (event.getAAI() == null) {
555             throw new ControlLoopException("AAI is null");
556         }
557         if (event.getAAI().get("generic-vnf.vnf-id") == null && event.getAAI().get("vserver.vserver-name") == null &&
558                 event.getAAI().get("generic-vnf.vnf-name") == null) {
559             throw new ControlLoopException("generic-vnf.vnf-id or generic-vnf.vnf-name or vserver.vserver-name information missing");
560         }
561         }
562         
563         public void queryAai(VirtualControlLoopEvent event) throws AAIException {
564                 if (event.getAAI().get("vserver.is-closed-loop-disabled") == null && 
565                         event.getAAI().get("generic-vnf.is-closed-loop-disabled") == null) {
566                         try {
567                                 if (event.getAAI().get("generic-vnf.vnf-id") != null) {
568                                         vnfResponse = getAAIVnfInfo(event); 
569                                         if (vnfResponse == null) {
570                                                 throw new AAIException("AAI Response is null (query by vnf-id)");
571                                         }
572                                         if (vnfResponse.getRequestError() != null) {
573                                                 throw new AAIException("AAI Responded with a request error (query by vnf-id)");
574                                         }
575                                         if (isClosedLoopDisabled(vnfResponse) == true) {
576                                                 throw new AAIException("is-closed-loop-disabled is set to true");       
577                                         }
578                                 } else if (event.getAAI().get("generic-vnf.vnf-name") != null) {
579                                         vnfResponse = getAAIVnfInfo(event); 
580                                         if (vnfResponse == null) {
581                                                 throw new AAIException("AAI Response is null (query by vnf-name)");
582                                         }
583                                         if (vnfResponse.getRequestError() != null) {
584                                                 throw new AAIException("AAI Responded with a request error (query by vnf-name)");
585                                         }
586                                         if (isClosedLoopDisabled(vnfResponse) == true) {
587                                                 throw new AAIException("is-closed-loop-disabled is set to true");       
588                                         }
589                                 } else if (event.getAAI().get("vserver.vserver-name") != null) {
590                                         vserverResponse = getAAIVserverInfo(event); 
591                                         if (vserverResponse == null) {
592                                                 throw new AAIException("AAI Response is null (query by vserver-name)");
593                                         }
594                                         if (vserverResponse.getRequestError() != null) {
595                                                 throw new AAIException("AAI responded with a request error (query by vserver-name)");
596                                         }
597                                         if (isClosedLoopDisabled(vserverResponse) == true) {
598                                                 throw new AAIException("is-closed-loop-disabled is set to true");       
599                                         }
600                                 }
601                         } catch (Exception e) {
602                                 logger.error("Exception from getAAIInfo: ", e);
603                                 throw new AAIException("Exception from getAAIInfo: " + e.toString());
604                         }
605                 } else if (isClosedLoopDisabled(event)) {
606                         throw new AAIException("is-closed-loop-disabled is set to true");
607                 }
608         }
609         
610         public static boolean isClosedLoopDisabled(AAIGETVnfResponse aaiResponse) {
611         if (aaiResponse != null && aaiResponse.getIsClosedLoopDisabled() != null) {
612                 String value = aaiResponse.getIsClosedLoopDisabled(); 
613                 if ("true".equalsIgnoreCase(value) || "T".equalsIgnoreCase(value) ||
614                         "yes".equalsIgnoreCase(value)  || "Y".equalsIgnoreCase(value)) {
615                         return true; 
616                 } 
617         }
618   
619                 return false; 
620         }
621         
622         public static boolean isClosedLoopDisabled(AAIGETVserverResponse aaiResponse) {
623         if (aaiResponse != null && aaiResponse.getIsClosedLoopDisabled() != null) {
624                 String value = aaiResponse.getIsClosedLoopDisabled(); 
625                 if ("true".equalsIgnoreCase(value) || "T".equalsIgnoreCase(value) ||
626                         "yes".equalsIgnoreCase(value)  || "Y".equalsIgnoreCase(value)) {
627                         return true; 
628                 } 
629         }
630   
631                 return false; 
632         }
633         
634         public static boolean isClosedLoopDisabled(VirtualControlLoopEvent event) {
635                 if ("true".equalsIgnoreCase(event.getAAI().get("vserver.is-closed-loop-disabled")) || 
636                     "T".equalsIgnoreCase(event.getAAI().get("vserver.is-closed-loop-disabled")) || 
637                     "yes".equalsIgnoreCase(event.getAAI().get("vserver.is-closed-loop-disabled")) || 
638                     "Y".equalsIgnoreCase(event.getAAI().get("vserver.is-closed-loop-disabled"))) { 
639                         return true; 
640                 }
641                 else if ("true".equalsIgnoreCase(event.getAAI().get("generic-vnf.is-closed-loop-disabled")) || 
642                     "T".equalsIgnoreCase(event.getAAI().get("generic-vnf.is-closed-loop-disabled")) || 
643                     "yes".equalsIgnoreCase(event.getAAI().get("generic-vnf.is-closed-loop-disabled")) || 
644                     "Y".equalsIgnoreCase(event.getAAI().get("generic-vnf.is-closed-loop-disabled"))) { 
645                     return true; 
646             }
647                 return false;
648         }
649         
650         public static AAIGETVserverResponse getAAIVserverInfo(VirtualControlLoopEvent event) throws ControlLoopException {
651                 UUID requestID = event.getRequestID();  
652                 AAIGETVserverResponse response = null; 
653                 String vserverName = event.getAAI().get("vserver.vserver-name"); 
654
655                 try {
656                 if (vserverName != null) {
657                    aaiHostURL  = PolicyEngine.manager.getEnvironmentProperty("aai.url"); 
658                    aaiUser     = PolicyEngine.manager.getEnvironmentProperty("aai.username"); 
659                    aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
660                    String aaiGetQueryByVserver = "/aai/v11/nodes/vservers?vserver-name="; 
661                            String url = aaiHostURL + aaiGetQueryByVserver; 
662                            logger.info("url: " + url);
663                            response = new AAIManager(new RESTManager()).getQueryByVserverName(url, aaiUser, aaiPassword, requestID, vserverName);
664                 } 
665             } catch (Exception e) {
666                 logger.error("getAAIVserverInfo exception: ", e);
667                 throw new ControlLoopException("Exception in getAAIVserverInfo: ", e);
668         }
669                 
670                 return response; 
671         }
672         
673         public static AAIGETVnfResponse getAAIVnfInfo(VirtualControlLoopEvent event) throws ControlLoopException {
674                 UUID requestID = event.getRequestID();  
675                 AAIGETVnfResponse response = null; 
676                 String vnfName = event.getAAI().get("generic-vnf.vnf-name"); 
677                 String vnfID   = event.getAAI().get("generic-vnf.vnf-id"); 
678  
679                 aaiHostURL  = PolicyEngine.manager.getEnvironmentProperty("aai.url"); 
680         aaiUser     = PolicyEngine.manager.getEnvironmentProperty("aai.username"); 
681         aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
682                 
683                 try {
684             if (vnfName != null) {
685                    String aaiGetQueryByVnfName = "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name="; 
686                            String url = aaiHostURL + aaiGetQueryByVnfName; 
687                            logger.info("url: " + url);
688                            response = new AAIManager(new RESTManager()).getQueryByVnfName(url, aaiUser, aaiPassword, requestID, vnfName);                       
689                 } else if (vnfID != null) {
690                        String aaiGetQueryByVnfID = "/aai/v11/network/generic-vnfs/generic-vnf/"; 
691                            String url = aaiHostURL + aaiGetQueryByVnfID; 
692                            logger.info("url: " + url);
693                            response = new AAIManager(new RESTManager()).getQueryByVnfID(url, aaiUser, aaiPassword, requestID, vnfID);                   
694                 }
695             } catch (Exception e) {
696                 logger.error("getAAIVnfInfo exception: ", e);
697                 throw new ControlLoopException("Exception in getAAIVnfInfo: ", e);
698         }
699                 
700                 return response; 
701         }
702         
703         @Override
704         public boolean isActive() {
705                 // TODO
706                 return true;
707         }
708
709         @Override
710         public boolean releaseLock() {
711                 // TODO
712                 return false;
713         }
714
715         @Override
716         public String toString() {
717                 return "ControlLoopEventManager [closedLoopControlName=" + closedLoopControlName + ", requestID=" + requestID
718                                 + ", processor=" + processor + ", onset=" + (onset != null ? onset.getRequestID() : "null") + ", numOnsets=" + numOnsets + ", numAbatements="
719                                 + numAbatements + ", isActivated="
720                                 + isActivated + ", currentOperation=" + currentOperation + ", targetLock=" + targetLock + "]";
721         }
722         
723 }