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