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