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