d320b75eeec1b204beb4500d8f7af7ade6b65742
[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.drools.system.PolicyEngine; 
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
52
53 public class ControlLoopEventManager implements LockCallback, Serializable {
54         
55         /**
56          * 
57          */
58         private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManager.class);
59         
60         private static final long serialVersionUID = -1216568161322872641L;
61         public final String closedLoopControlName;
62         public final UUID requestID;
63         
64         private String controlLoopResult;
65         private transient ControlLoopProcessor processor = null;
66         private VirtualControlLoopEvent onset;
67         private Integer numOnsets = 0;
68         private Integer numAbatements = 0;
69         private VirtualControlLoopEvent abatement;
70         private FinalResult controlLoopTimedOut = null;
71
72         private boolean isActivated = false;
73         private LinkedList<ControlLoopOperation> controlLoopHistory = new LinkedList<>();
74         private ControlLoopOperationManager currentOperation = null;
75         private transient TargetLock targetLock = null;
76         private AAIGETVnfResponse vnfResponse = null;
77         private AAIGETVserverResponse vserverResponse = null;
78         private static String aaiHostURL; 
79         private static String aaiUser; 
80         private static String aaiPassword;
81         
82         private static Collection<String> requiredAAIKeys = new ArrayList<>();
83         static {
84                 requiredAAIKeys.add("AICVServerSelfLink");
85                 requiredAAIKeys.add("AICIdentity");
86                 requiredAAIKeys.add("is_closed_loop_disabled");
87                 requiredAAIKeys.add("VM_NAME");
88         }
89
90         public ControlLoopEventManager(String closedLoopControlName, UUID requestID) {
91                 this.closedLoopControlName = closedLoopControlName;
92                 this.requestID = requestID;
93         }
94         
95         public String getControlLoopResult() {
96                 return controlLoopResult;
97         }
98         
99         public void setControlLoopResult(String controlLoopResult) {
100                 this.controlLoopResult = controlLoopResult;
101         }
102         
103         public Integer getNumOnsets() {
104                 return numOnsets;
105         }
106
107         public void setNumOnsets(Integer numOnsets) {
108                 this.numOnsets = numOnsets;
109         }
110
111         public Integer getNumAbatements() {
112                 return numAbatements;
113         }
114
115         public void setNumAbatements(Integer numAbatements) {
116                 this.numAbatements = numAbatements;
117         }
118
119         public boolean isActivated() {
120                 return isActivated;
121         }
122
123         public void setActivated(boolean isActivated) {
124                 this.isActivated = isActivated;
125         }
126         
127         public VirtualControlLoopEvent  getOnsetEvent() {
128                 return this.onset;
129         }
130         
131         public VirtualControlLoopEvent getAbatementEvent() {
132                 return this.abatement;
133         }
134         
135         public ControlLoopProcessor getProcessor() {
136                 return this.processor;
137         }
138
139         public VirtualControlLoopNotification   activate(VirtualControlLoopEvent event) {
140                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification(event);
141                 try {
142                         //
143                         // This method should ONLY be called ONCE
144                         //
145                         if (this.isActivated) {
146                                 throw new ControlLoopException("ControlLoopEventManager has already been activated.");
147                         }
148                         //
149                         // Syntax check the event
150                         //
151                         checkEventSyntax(event);
152                         checkEventAAISyntax(event);
153                         //
154                         // At this point we are good to go with this event
155                         //
156                         this.onset = event;
157                         this.numOnsets = 1;
158                         //
159                         notification.notification = ControlLoopNotificationType.ACTIVE;
160                         //
161                         // Set ourselves as active
162                         //
163                         this.isActivated = true;
164                 } catch (ControlLoopException e) {
165                         logger.error("{}: activate threw: ",this, e);
166                         notification.notification = ControlLoopNotificationType.REJECTED;
167                         notification.message = e.getMessage();
168                 }
169                 return notification;
170         }
171         
172         
173         
174         public VirtualControlLoopNotification   activate(String yamlSpecification, VirtualControlLoopEvent event) {
175                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification(event);
176                 try {
177                         //
178                         // This method should ONLY be called ONCE
179                         //
180                         if (this.isActivated) {
181                                 throw new ControlLoopException("ControlLoopEventManager has already been activated.");
182                         }
183                         //
184                         // Syntax check the event
185                         //
186                         checkEventSyntax(event);
187                         checkEventAAISyntax(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.notification = 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.notification = ControlLoopNotificationType.REJECTED;
225                         notification.message = 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.notification = ControlLoopNotificationType.FINAL_FAILURE;
255                         notification.message = "Control Loop timed out";
256                         notification.history.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.message = "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.notification = ControlLoopNotificationType.FINAL_FAILURE;
278                         break;
279                 case FINAL_OPENLOOP:
280                         notification.notification = ControlLoopNotificationType.FINAL_OPENLOOP;
281                         break;
282                 case FINAL_SUCCESS:
283                         notification.notification = ControlLoopNotificationType.FINAL_SUCCESS;
284                         break;
285                 default:
286                         return null;
287                 }
288                 //
289                 // Be sure to add all the history
290                 //
291                 notification.history.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.requestID,
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) {
441                 try {
442                         this.checkEventSyntax(event);
443                         if (event.closedLoopEventStatus == ControlLoopEventStatus.ONSET) {
444                                 //
445                                 // Check if this is our original ONSET
446                                 //
447                                 if (event.equals(this.onset)) {
448                                         //
449                                         // DO NOT retract it
450                                         //
451                                         return NEW_EVENT_STATUS.FIRST_ONSET;
452                                 }
453                                 //
454                                 // Log that we got an onset
455                                 //
456                                 this.numOnsets++;
457                                 return NEW_EVENT_STATUS.SUBSEQUENT_ONSET;
458                         } else if (event.closedLoopEventStatus == ControlLoopEventStatus.ABATED) {
459                                 //
460                                 // Have we already got an abatement?
461                                 //
462                                 if (this.abatement == null) {
463                                         //
464                                         // Save this
465                                         //
466                                         this.abatement = event;
467                                         //
468                                         // Keep track that we received another
469                                         //
470                                         this.numAbatements++;
471                                         //
472                                         //
473                                         //
474                                         return NEW_EVENT_STATUS.FIRST_ABATEMENT;
475                                 } else {
476                                         //
477                                         // Keep track that we received another
478                                         //
479                                         this.numAbatements++;
480                                         //
481                                         //
482                                         //
483                                         return NEW_EVENT_STATUS.SUBSEQUENT_ABATEMENT;
484                                 }
485                         } else {
486                                 return NEW_EVENT_STATUS.SYNTAX_ERROR;
487                         }
488                 } catch (ControlLoopException e) {
489                         logger.error("{}: onNewEvent threw: ",this, e);
490                         return NEW_EVENT_STATUS.SYNTAX_ERROR;
491                 }
492         }
493         
494         public VirtualControlLoopNotification setControlLoopTimedOut() {
495                 this.controlLoopTimedOut = FinalResult.FINAL_FAILURE_TIMEOUT;
496                 VirtualControlLoopNotification notification = new VirtualControlLoopNotification(this.onset);
497                 notification.notification = ControlLoopNotificationType.FINAL_FAILURE;
498                 notification.message = "Control Loop timed out";
499                 notification.history.addAll(this.controlLoopHistory);
500                 return notification;                    
501         }
502         
503         public boolean isControlLoopTimedOut() {
504                 return (this.controlLoopTimedOut == FinalResult.FINAL_FAILURE_TIMEOUT);
505         }
506         
507         public int      getControlLoopTimeout(Integer defaultTimeout) {
508                 if (this.processor != null && this.processor.getControlLoop() != null) {
509                         return this.processor.getControlLoop().getTimeout();
510                 }
511                 if (defaultTimeout != null) {
512                         return defaultTimeout;
513                 }
514                 return 0;
515         }
516         
517         public AAIGETVnfResponse getVnfResponse() {
518                 return vnfResponse; 
519         }
520
521         public AAIGETVserverResponse getVserverResponse() {
522                 return vserverResponse; 
523         }
524         
525         public void checkEventSyntax(VirtualControlLoopEvent event) throws ControlLoopException {
526                 if (event.closedLoopEventStatus == null || 
527                                 (event.closedLoopEventStatus != ControlLoopEventStatus.ONSET &&
528                                 event.closedLoopEventStatus != ControlLoopEventStatus.ABATED)) {
529                         throw new ControlLoopException("Invalid value in closedLoopEventStatus");
530                 }
531                 if (event.closedLoopControlName == null || event.closedLoopControlName.length() < 1) {
532                         throw new ControlLoopException("No control loop name");
533                 }
534                 if (event.requestID == null) {
535                         throw new ControlLoopException("No request ID");
536                 }
537                 if (event.closedLoopEventStatus == ControlLoopEventStatus.ABATED) {
538                         return;
539                 }
540                 if (event.target == null || event.target.length() < 1) {
541                         throw new ControlLoopException("No target field");
542                 } else if (! "VM_NAME".equalsIgnoreCase(event.target) &&
543                                 ! "VNF_NAME".equalsIgnoreCase(event.target) &&
544                                 ! "vserver.vserver-name".equalsIgnoreCase(event.target) &&
545                                 ! "generic-vnf.vnf-id".equalsIgnoreCase(event.target) &&
546                                 ! "generic-vnf.vnf-name".equalsIgnoreCase(event.target) ) {
547                         throw new ControlLoopException("target field invalid - expecting VM_NAME or VNF_NAME");
548                 }
549         }
550         
551         public void checkEventAAISyntax(VirtualControlLoopEvent event) throws ControlLoopException {
552                 if (event.AAI == null) {
553                         throw new ControlLoopException("AAI is null");
554                 }
555                 if (event.AAI.get("generic-vnf.vnf-id") == null && event.AAI.get("vserver.vserver-name") == null &&
556                                 event.AAI.get("generic-vnf.vnf-name") == null) {
557                         throw new ControlLoopException("generic-vnf.vnf-id or generic-vnf.vnf-name or vserver.vserver-name information missing");
558                 }
559                 if (event.AAI.get("vserver.is-closed-loop-disabled") == null) {
560                         try {
561                                 if (event.AAI.get("generic-vnf.vnf-id") != null) {
562                                         vnfResponse = getAAIVnfInfo(event); 
563                                         if (vnfResponse == null) {
564                                                 throw new ControlLoopException("AAI Response is null (query by vnf-id)");
565                                         }
566                                         if (vnfResponse.requestError != null) {
567                                                 throw new ControlLoopException("AAI Responded with a request error (query by vnf-id)");
568                                         }
569                                         if (isClosedLoopDisabled(vnfResponse) == true) {
570                                                 throw new ControlLoopException("is-closed-loop-disabled is set to true");       
571                                         }
572                                 } else if (event.AAI.get("generic-vnf.vnf-name") != null) {
573                                         vnfResponse = getAAIVnfInfo(event); 
574                                         if (vnfResponse == null) {
575                                                 throw new ControlLoopException("AAI Response is null (query by vnf-name)");
576                                         }
577                                         if (vnfResponse.requestError != null) {
578                                                 throw new ControlLoopException("AAI Responded with a request error (query by vnf-name)");
579                                         }
580                                         if (isClosedLoopDisabled(vnfResponse) == true) {
581                                                 throw new ControlLoopException("is-closed-loop-disabled is set to true");       
582                                         }
583                                 } else if (event.AAI.get("vserver.vserver-name") != null) {
584                                         vserverResponse = getAAIVserverInfo(event); 
585                                         if (vserverResponse == null) {
586                                                 throw new ControlLoopException("AAI Response is null (query by vserver-name)");
587                                         }
588                                         if (vserverResponse.requestError != null) {
589                                                 throw new ControlLoopException("AAI responded with a request error (query by vserver-name)");
590                                         }
591                                         if (isClosedLoopDisabled(vserverResponse) == true) {
592                                                 throw new ControlLoopException("is-closed-loop-disabled is set to true");       
593                                         }
594                                 }
595                         } catch (Exception e) {
596                                 logger.error("Exception from getAAIInfo: ", e);
597                                 throw new ControlLoopException("Exception from getAAIInfo: " + e.toString());
598                         }
599                 } else if (isClosedLoopDisabled(event)) {
600                         throw new ControlLoopException("is-closed-loop-disabled is set to true");
601                 }
602         }
603         
604         public static boolean isClosedLoopDisabled(AAIGETVnfResponse aaiResponse) {
605         if (aaiResponse != null && aaiResponse.isClosedLoopDisabled != null) {
606                 String value = aaiResponse.isClosedLoopDisabled; 
607                 if ("true".equalsIgnoreCase(value) || "T".equalsIgnoreCase(value) ||
608                         "yes".equalsIgnoreCase(value)  || "Y".equalsIgnoreCase(value)) {
609                         return true; 
610                 } 
611         }
612   
613                 return false; 
614         }
615         
616         public static boolean isClosedLoopDisabled(AAIGETVserverResponse aaiResponse) {
617         if (aaiResponse != null && aaiResponse.isClosedLoopDisabled != null) {
618                 String value = aaiResponse.isClosedLoopDisabled; 
619                 if ("true".equalsIgnoreCase(value) || "T".equalsIgnoreCase(value) ||
620                         "yes".equalsIgnoreCase(value)  || "Y".equalsIgnoreCase(value)) {
621                         return true; 
622                 } 
623         }
624   
625                 return false; 
626         }
627         
628         public static boolean isClosedLoopDisabled(VirtualControlLoopEvent event) {
629                 if ("true".equalsIgnoreCase(event.AAI.get("vserver.is-closed-loop-disabled")) || 
630                     "T".equalsIgnoreCase(event.AAI.get("vserver.is-closed-loop-disabled")) || 
631                     "yes".equalsIgnoreCase(event.AAI.get("vserver.is-closed-loop-disabled")) || 
632                     "Y".equalsIgnoreCase(event.AAI.get("vserver.is-closed-loop-disabled"))) { 
633                         return true; 
634                 }               
635                 return false;
636         }
637         
638         public static AAIGETVserverResponse getAAIVserverInfo(VirtualControlLoopEvent event) throws ControlLoopException {
639                 UUID requestID = event.requestID;  
640                 AAIGETVserverResponse response = null; 
641                 String vserverName = event.AAI.get("vserver.vserver-name"); 
642
643                 try {
644                 if (vserverName != null) {
645                    aaiHostURL  = PolicyEngine.manager.getEnvironmentProperty("aai.url"); 
646                    aaiUser     = PolicyEngine.manager.getEnvironmentProperty("aai.username"); 
647                    aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
648                    String aaiGetQueryByVserver = "/aai/v11/nodes/vservers?vserver-name="; 
649                            String url = aaiHostURL + aaiGetQueryByVserver; 
650                            logger.info("url: " + url);
651                            response = AAIManager.getQueryByVserverName(url, aaiUser, aaiPassword, requestID, vserverName);
652                 } 
653             } catch (Exception e) {
654                 logger.error("getAAIVserverInfo exception: ", e);
655                 throw new ControlLoopException("Exception in getAAIVserverInfo: ", e);
656         }
657                 
658                 return response; 
659         }
660         
661         public static AAIGETVnfResponse getAAIVnfInfo(VirtualControlLoopEvent event) throws ControlLoopException {
662                 UUID requestID = event.requestID;  
663                 AAIGETVnfResponse response = null; 
664                 String vnfName = event.AAI.get("generic-vnf.vnf-name"); 
665                 String vnfID   = event.AAI.get("generic-vnf.vnf-id"); 
666  
667                 aaiHostURL  = PolicyEngine.manager.getEnvironmentProperty("aai.url"); 
668         aaiUser     = PolicyEngine.manager.getEnvironmentProperty("aai.username"); 
669         aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
670                 
671                 try {
672             if (vnfName != null) {
673                    String aaiGetQueryByVnfName = "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name="; 
674                            String url = aaiHostURL + aaiGetQueryByVnfName; 
675                            logger.info("url: " + url);
676                            response = AAIManager.getQueryByVnfName(url, aaiUser, aaiPassword, requestID, vnfName);                      
677                 } else if (vnfID != null) {
678                        String aaiGetQueryByVnfID = "/aai/v11/network/generic-vnfs/generic-vnf/"; 
679                            String url = aaiHostURL + aaiGetQueryByVnfID; 
680                            logger.info("url: " + url);
681                            response = AAIManager.getQueryByVnfID(url, aaiUser, aaiPassword, requestID, vnfID);                  
682                 }
683             } catch (Exception e) {
684                 logger.error("getAAIVnfInfo exception: ", e);
685                 throw new ControlLoopException("Exception in getAAIVnfInfo: ", e);
686         }
687                 
688                 return response; 
689         }
690         
691         @Override
692         public boolean isActive() {
693                 // TODO
694                 return true;
695         }
696
697         @Override
698         public boolean releaseLock() {
699                 // TODO
700                 return false;
701         }
702
703         @Override
704         public String toString() {
705                 return "ControlLoopEventManager [closedLoopControlName=" + closedLoopControlName + ", requestID=" + requestID
706                                 + ", processor=" + processor + ", onset=" + (onset != null ? onset.requestID : "null") + ", numOnsets=" + numOnsets + ", numAbatements="
707                                 + numAbatements + ", isActivated="
708                                 + isActivated + ", currentOperation=" + currentOperation + ", targetLock=" + targetLock + "]";
709         }
710         
711 }