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