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