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