2 * ============LICENSE_START=======================================================
3 * controlloop event manager
4 * ================================================================================
5 * Copyright (C) 2017-2018 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.controlloop.eventmanager;
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;
31 import java.util.UUID;
33 import org.onap.policy.aai.AaiGetVnfResponse;
34 import org.onap.policy.aai.AaiGetVserverResponse;
35 import org.onap.policy.aai.AaiManager;
36 import org.onap.policy.aai.AaiNqVServer;
37 import org.onap.policy.aai.util.AaiException;
38 import org.onap.policy.controlloop.ControlLoopEventStatus;
39 import org.onap.policy.controlloop.ControlLoopException;
40 import org.onap.policy.controlloop.ControlLoopNotificationType;
41 import org.onap.policy.controlloop.ControlLoopOperation;
42 import org.onap.policy.controlloop.VirtualControlLoopEvent;
43 import org.onap.policy.controlloop.VirtualControlLoopNotification;
44 import org.onap.policy.controlloop.policy.FinalResult;
45 import org.onap.policy.controlloop.policy.Policy;
46 import org.onap.policy.controlloop.processor.ControlLoopProcessor;
47 import org.onap.policy.drools.system.PolicyEngine;
48 import org.onap.policy.guard.GuardResult;
49 import org.onap.policy.guard.LockCallback;
50 import org.onap.policy.guard.PolicyGuard;
51 import org.onap.policy.guard.PolicyGuard.LockResult;
52 import org.onap.policy.guard.TargetLock;
53 import org.onap.policy.rest.RESTManager;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
57 public class ControlLoopEventManager implements LockCallback, Serializable {
58 public static final String PROV_STATUS_ACTIVE = "ACTIVE";
59 private static final String VM_NAME = "VM_NAME";
60 private static final String VNF_NAME = "VNF_NAME";
61 public static final String GENERIC_VNF_VNF_ID = "generic-vnf.vnf-id";
62 public static final String GENERIC_VNF_VNF_NAME = "generic-vnf.vnf-name";
63 public static final String VSERVER_VSERVER_NAME = "vserver.vserver-name";
64 public static final String GENERIC_VNF_IS_CLOSED_LOOP_DISABLED = "generic-vnf.is-closed-loop-disabled";
65 public static final String VSERVER_IS_CLOSED_LOOP_DISABLED = "vserver.is-closed-loop-disabled";
66 public static final String GENERIC_VNF_PROV_STATUS = "generic-vnf.prov-status";
67 public static final String VSERVER_PROV_STATUS = "vserver.prov-status";
70 * Additional time, in seconds, to add to a "lock" request. This ensures that the lock
71 * won't expire right before an operation completes.
73 private static final int ADDITIONAL_LOCK_SEC = 60;
75 private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManager.class);
77 private static final long serialVersionUID = -1216568161322872641L;
78 public final String closedLoopControlName;
79 public final UUID requestID;
81 private String controlLoopResult;
82 private transient ControlLoopProcessor processor = null;
83 private VirtualControlLoopEvent onset;
84 private Integer numOnsets = 0;
85 private Integer numAbatements = 0;
86 private VirtualControlLoopEvent abatement;
87 private FinalResult controlLoopTimedOut = null;
89 private boolean isActivated = false;
90 private LinkedList<ControlLoopOperation> controlLoopHistory = new LinkedList<>();
91 private ControlLoopOperationManager currentOperation = null;
92 private transient TargetLock targetLock = null;
93 private AaiGetVnfResponse vnfResponse = null;
94 private AaiGetVserverResponse vserverResponse = null;
96 private static Collection<String> requiredAAIKeys = new ArrayList<>();
99 requiredAAIKeys.add("AICVServerSelfLink");
100 requiredAAIKeys.add("AICIdentity");
101 requiredAAIKeys.add("is_closed_loop_disabled");
102 requiredAAIKeys.add(VM_NAME);
105 public ControlLoopEventManager(String closedLoopControlName, UUID requestID) {
106 this.closedLoopControlName = closedLoopControlName;
107 this.requestID = requestID;
110 public String getClosedLoopControlName() {
111 return closedLoopControlName;
114 public String getControlLoopResult() {
115 return controlLoopResult;
118 public void setControlLoopResult(String controlLoopResult) {
119 this.controlLoopResult = controlLoopResult;
122 public Integer getNumOnsets() {
126 public void setNumOnsets(Integer numOnsets) {
127 this.numOnsets = numOnsets;
130 public Integer getNumAbatements() {
131 return numAbatements;
134 public void setNumAbatements(Integer numAbatements) {
135 this.numAbatements = numAbatements;
138 public boolean isActivated() {
142 public void setActivated(boolean isActivated) {
143 this.isActivated = isActivated;
146 public VirtualControlLoopEvent getOnsetEvent() {
150 public VirtualControlLoopEvent getAbatementEvent() {
151 return this.abatement;
154 public ControlLoopProcessor getProcessor() {
155 return this.processor;
158 public UUID getRequestID() {
163 * Activate a control loop event.
165 * @param event the event
166 * @return the VirtualControlLoopNotification
168 public VirtualControlLoopNotification activate(VirtualControlLoopEvent event) {
169 VirtualControlLoopNotification notification = new VirtualControlLoopNotification(event);
172 // This method should ONLY be called ONCE
174 if (this.isActivated) {
175 throw new ControlLoopException("ControlLoopEventManager has already been activated.");
178 // Syntax check the event
180 checkEventSyntax(event);
183 // At this point we are good to go with this event
188 notification.setNotification(ControlLoopNotificationType.ACTIVE);
190 // Set ourselves as active
192 this.isActivated = true;
193 } catch (ControlLoopException e) {
194 logger.error("{}: activate by event threw: ", this, e);
195 notification.setNotification(ControlLoopNotificationType.REJECTED);
196 notification.setMessage(e.getMessage());
202 * Activate a control loop event.
204 * @param yamlSpecification the yaml specification
205 * @param event the event
206 * @return the VirtualControlLoopNotification
208 public VirtualControlLoopNotification activate(String yamlSpecification, VirtualControlLoopEvent event) {
209 VirtualControlLoopNotification notification = new VirtualControlLoopNotification(event);
212 // This method should ONLY be called ONCE
214 if (this.isActivated) {
215 throw new ControlLoopException("ControlLoopEventManager has already been activated.");
218 // Syntax check the event
220 checkEventSyntax(event);
225 if (yamlSpecification == null || yamlSpecification.length() < 1) {
226 throw new ControlLoopException("yaml specification is null or 0 length");
228 } catch (ControlLoopException e) {
229 logger.error("{}: activate by YAML specification and event threw: ", this, e);
230 notification.setNotification(ControlLoopNotificationType.REJECTED);
231 notification.setMessage(e.getMessage());
235 String decodedYaml = null;
237 decodedYaml = URLDecoder.decode(yamlSpecification, "UTF-8");
238 if (decodedYaml != null && decodedYaml.length() > 0) {
239 yamlSpecification = decodedYaml;
241 } catch (UnsupportedEncodingException e) {
242 logger.error("{}: YAML decode in activate by YAML specification and event threw: ", this, e);
243 notification.setNotification(ControlLoopNotificationType.REJECTED);
244 notification.setMessage(e.getMessage());
250 // Parse the YAML specification
252 this.processor = new ControlLoopProcessor(yamlSpecification);
255 // At this point we are good to go with this event
262 notification.setNotification(ControlLoopNotificationType.ACTIVE);
264 // Set ourselves as active
266 this.isActivated = true;
267 } catch (ControlLoopException e) {
268 logger.error("{}: activate by YAML specification and event threw: ", this, e);
269 notification.setNotification(ControlLoopNotificationType.REJECTED);
270 notification.setMessage(e.getMessage());
276 * Check if the control loop is final.
278 * @return a VirtualControlLoopNotification if the control loop is final, otherwise
279 * <code>null</code> is returned
280 * @throws ControlLoopException if an error occurs
282 public VirtualControlLoopNotification isControlLoopFinal() throws ControlLoopException {
284 // Check if they activated us
286 if (!this.isActivated) {
287 throw new ControlLoopException("ControlLoopEventManager MUST be activated first.");
290 // Make sure we are expecting this call.
292 if (this.onset == null) {
293 throw new ControlLoopException("No onset event for ControlLoopEventManager.");
296 // Ok, start creating the notification
298 VirtualControlLoopNotification notification = new VirtualControlLoopNotification(this.onset);
300 // Check if the overall control loop has timed out
302 if (this.isControlLoopTimedOut()) {
304 // Yes we have timed out
306 notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE);
307 notification.setMessage("Control Loop timed out");
308 notification.getHistory().addAll(this.controlLoopHistory);
312 // Check if the current policy is Final
314 FinalResult result = this.processor.checkIsCurrentPolicyFinal();
315 if (result == null) {
317 // we are not at a final result
323 case FINAL_FAILURE_EXCEPTION:
324 notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE);
325 notification.setMessage("Exception in processing closed loop");
328 case FINAL_FAILURE_RETRIES:
329 case FINAL_FAILURE_TIMEOUT:
330 case FINAL_FAILURE_GUARD:
331 notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE);
334 notification.setNotification(ControlLoopNotificationType.FINAL_OPENLOOP);
337 notification.setNotification(ControlLoopNotificationType.FINAL_SUCCESS);
343 // Be sure to add all the history
345 notification.getHistory().addAll(this.controlLoopHistory);
350 * Process the control loop.
352 * @return a ControlLoopOperationManager
353 * @throws ControlLoopException if an error occurs
354 * @throws AaiException if an error occurs retrieving information from A&AI
356 public ControlLoopOperationManager processControlLoop() throws ControlLoopException, AaiException {
358 // Check if they activated us
360 if (!this.isActivated) {
361 throw new ControlLoopException("ControlLoopEventManager MUST be activated first.");
364 // Make sure we are expecting this call.
366 if (this.onset == null) {
367 throw new ControlLoopException("No onset event for ControlLoopEventManager.");
370 // Is there a current operation?
372 if (this.currentOperation != null) {
374 // Throw an exception, or simply return the current operation?
376 throw new ControlLoopException("Already working an Operation, do not call this method.");
379 // Ensure we are not FINAL
381 VirtualControlLoopNotification notification = this.isControlLoopFinal();
382 if (notification != null) {
384 // This is weird, we require them to call the isControlLoopFinal() method first
386 // We should really abstract this and avoid throwing an exception, because it really
387 // isn't an exception.
389 throw new ControlLoopException("Control Loop is in FINAL state, do not call this method.");
392 // Not final so get the policy that needs to be worked on.
394 Policy policy = this.processor.getCurrentPolicy();
395 if (policy == null) {
396 throw new ControlLoopException("ControlLoopEventManager: processor came upon null Policy.");
399 // And setup an operation
401 this.currentOperation = new ControlLoopOperationManager(this.onset, policy, this);
405 return this.currentOperation;
409 * Finish an operation.
411 * @param operation the operation
413 public void finishOperation(ControlLoopOperationManager operation) throws ControlLoopException {
415 // Verify we have a current operation
417 if (this.currentOperation != null) {
419 // Validate they are finishing the current operation
420 // PLD - this is simply comparing the policy. Do we want to equals the whole object?
422 if (this.currentOperation.policy.equals(operation.policy)) {
423 logger.debug("Finishing {} result is {}", this.currentOperation.policy.getRecipe(),
424 this.currentOperation.getOperationResult());
428 this.controlLoopHistory.addAll(this.currentOperation.getHistory());
430 // Move to the next Policy
432 this.processor.nextPolicyForResult(this.currentOperation.getOperationResult());
434 // Just null this out
436 this.currentOperation = null;
438 // TODO: Release our lock
442 logger.debug("Cannot finish current operation {} does not match given operation {}",
443 this.currentOperation.policy, operation.policy);
446 throw new ControlLoopException("No operation to finish.");
450 * Obtain a lock for the current operation.
452 * @return the lock result
453 * @throws ControlLoopException if an error occurs
455 public synchronized LockResult<GuardResult, TargetLock> lockCurrentOperation() throws ControlLoopException {
459 if (this.currentOperation == null) {
460 throw new ControlLoopException("Do not have a current operation.");
463 // Have we acquired it already?
465 if (this.targetLock != null) {
467 // TODO: Make sure the current lock is for the same target.
468 // Currently, it should be. But in the future it may not.
470 GuardResult result = PolicyGuard.lockTarget(targetLock,
471 this.currentOperation.getOperationTimeout() + ADDITIONAL_LOCK_SEC);
472 return new LockResult<>(result, this.targetLock);
477 LockResult<GuardResult, TargetLock> lockResult =
478 PolicyGuard.lockTarget(this.currentOperation.policy.getTarget().getType(),
479 this.currentOperation.getTargetEntity(), this.onset.getRequestId(), this,
480 this.currentOperation.getOperationTimeout() + ADDITIONAL_LOCK_SEC);
484 if (lockResult.getA().equals(GuardResult.LOCK_ACQUIRED)) {
486 // Yes, let's save it
488 this.targetLock = lockResult.getB();
495 * Release the lock for the current operation.
497 * @return the target lock
499 public synchronized TargetLock unlockCurrentOperation() {
500 if (this.targetLock == null) {
504 TargetLock returnLock = this.targetLock;
505 this.targetLock = null;
507 PolicyGuard.unlockTarget(returnLock);
509 // always return the old target lock so rules can retract it
513 public enum NEW_EVENT_STATUS {
514 FIRST_ONSET, SUBSEQUENT_ONSET, FIRST_ABATEMENT, SUBSEQUENT_ABATEMENT, SYNTAX_ERROR;
518 * An event onset/abatement.
520 * @param event the event
522 * @throws AaiException if an error occurs retrieving information from A&AI
524 public NEW_EVENT_STATUS onNewEvent(VirtualControlLoopEvent event) throws AaiException {
526 this.checkEventSyntax(event);
527 if (event.getClosedLoopEventStatus() == ControlLoopEventStatus.ONSET) {
529 // Check if this is our original ONSET
531 if (event.equals(this.onset)) {
533 // Query A&AI if needed
540 return NEW_EVENT_STATUS.FIRST_ONSET;
543 // Log that we got an onset
546 return NEW_EVENT_STATUS.SUBSEQUENT_ONSET;
547 } else if (event.getClosedLoopEventStatus() == ControlLoopEventStatus.ABATED) {
549 // Have we already got an abatement?
551 if (this.abatement == null) {
555 this.abatement = event;
557 // Keep track that we received another
559 this.numAbatements++;
563 return NEW_EVENT_STATUS.FIRST_ABATEMENT;
566 // Keep track that we received another
568 this.numAbatements++;
572 return NEW_EVENT_STATUS.SUBSEQUENT_ABATEMENT;
575 } catch (ControlLoopException e) {
576 logger.error("{}: onNewEvent threw: ", this, e);
578 return NEW_EVENT_STATUS.SYNTAX_ERROR;
582 * Set the control loop time out.
584 * @return a VirtualControlLoopNotification
586 public VirtualControlLoopNotification setControlLoopTimedOut() {
587 this.controlLoopTimedOut = FinalResult.FINAL_FAILURE_TIMEOUT;
588 VirtualControlLoopNotification notification = new VirtualControlLoopNotification(this.onset);
589 notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE);
590 notification.setMessage("Control Loop timed out");
591 notification.getHistory().addAll(this.controlLoopHistory);
595 public boolean isControlLoopTimedOut() {
596 return (this.controlLoopTimedOut == FinalResult.FINAL_FAILURE_TIMEOUT);
600 * Get the control loop timeout.
602 * @param defaultTimeout the default timeout
603 * @return the timeout
605 public int getControlLoopTimeout(Integer defaultTimeout) {
606 if (this.processor != null && this.processor.getControlLoop() != null) {
607 return this.processor.getControlLoop().getTimeout();
609 if (defaultTimeout != null) {
610 return defaultTimeout;
615 public AaiGetVnfResponse getVnfResponse() {
619 public AaiGetVserverResponse getVserverResponse() {
620 return vserverResponse;
624 * Check an event syntax.
626 * @param event the event syntax
627 * @throws ControlLoopException if an error occurs
629 public void checkEventSyntax(VirtualControlLoopEvent event) throws ControlLoopException {
630 if (event.getClosedLoopEventStatus() == null
631 || (event.getClosedLoopEventStatus() != ControlLoopEventStatus.ONSET
632 && event.getClosedLoopEventStatus() != ControlLoopEventStatus.ABATED)) {
633 throw new ControlLoopException("Invalid value in closedLoopEventStatus");
635 if (event.getClosedLoopControlName() == null || event.getClosedLoopControlName().length() < 1) {
636 throw new ControlLoopException("No control loop name");
638 if (event.getRequestId() == null) {
639 throw new ControlLoopException("No request ID");
641 if (event.getClosedLoopEventStatus() == ControlLoopEventStatus.ABATED) {
644 if (event.getTarget() == null || event.getTarget().length() < 1) {
645 throw new ControlLoopException("No target field");
646 } else if (!VM_NAME.equalsIgnoreCase(event.getTarget()) && !VNF_NAME.equalsIgnoreCase(event.getTarget())
647 && !VSERVER_VSERVER_NAME.equalsIgnoreCase(event.getTarget())
648 && !GENERIC_VNF_VNF_ID.equalsIgnoreCase(event.getTarget())
649 && !GENERIC_VNF_VNF_NAME.equalsIgnoreCase(event.getTarget())) {
650 throw new ControlLoopException("target field invalid - expecting VM_NAME or VNF_NAME");
652 if (event.getAai() == null) {
653 throw new ControlLoopException("AAI is null");
655 if (event.getAai().get(GENERIC_VNF_VNF_ID) == null && event.getAai().get(VSERVER_VSERVER_NAME) == null
656 && event.getAai().get(GENERIC_VNF_VNF_NAME) == null) {
657 throw new ControlLoopException(
658 "generic-vnf.vnf-id or generic-vnf.vnf-name or vserver.vserver-name information missing");
663 * Query A&AI for an event.
665 * @param event the event
666 * @throws AaiException if an error occurs retrieving information from A&AI
668 public void queryAai(VirtualControlLoopEvent event) throws AaiException {
670 if (isClosedLoopDisabled(event)) {
671 throw new AaiException("is-closed-loop-disabled is set to true on VServer or VNF");
674 if (isProvStatusInactive(event)) {
675 throw new AaiException("prov-status is not ACTIVE on VServer or VNF");
678 Map<String, String> aai = event.getAai();
680 if ((aai.containsKey(VSERVER_IS_CLOSED_LOOP_DISABLED) || aai.containsKey(GENERIC_VNF_IS_CLOSED_LOOP_DISABLED))
681 && (aai.containsKey(VSERVER_PROV_STATUS) || aai.containsKey(GENERIC_VNF_PROV_STATUS))) {
683 // no need to query, as we already have the data
687 if (vnfResponse != null || vserverResponse != null) {
688 // query has already been performed
693 if (aai.containsKey(GENERIC_VNF_VNF_ID) || aai.containsKey(GENERIC_VNF_VNF_NAME)) {
694 vnfResponse = getAAIVnfInfo(event);
695 processVNFResponse(vnfResponse, aai.containsKey(GENERIC_VNF_VNF_ID));
696 } else if (aai.containsKey(VSERVER_VSERVER_NAME)) {
697 vserverResponse = getAAIVserverInfo(event);
698 processVServerResponse(vserverResponse);
700 } catch (AaiException e) {
701 logger.error("Exception from queryAai: ", e);
703 } catch (Exception e) {
704 logger.error("Exception from queryAai: ", e);
705 throw new AaiException("Exception from queryAai: " + e.toString());
710 * Process a response from A&AI for a VNF.
712 * @param aaiResponse the response from A&AI
713 * @param queryByVnfId <code>true</code> if the query was based on vnf-id,
714 * <code>false</code> if the query was based on vnf-name
715 * @throws AaiException if an error occurs processing the response
717 private static void processVNFResponse(AaiGetVnfResponse aaiResponse, boolean queryByVNFID) throws AaiException {
718 String queryTypeString = (queryByVNFID ? "vnf-id" : "vnf-name");
720 if (aaiResponse == null) {
721 throw new AaiException("AAI Response is null (query by " + queryTypeString + ")");
723 if (aaiResponse.getRequestError() != null) {
724 throw new AaiException("AAI Responded with a request error (query by " + queryTypeString + ")");
727 if (aaiResponse.getIsClosedLoopDisabled()) {
728 throw new AaiException("is-closed-loop-disabled is set to true (query by " + queryTypeString + ")");
731 if (!PROV_STATUS_ACTIVE.equals(aaiResponse.getProvStatus())) {
732 throw new AaiException("prov-status is not ACTIVE (query by " + queryTypeString + ")");
737 * Process a response from A&AI for a VServer.
739 * @param aaiResponse the response from A&AI
740 * @throws AaiException if an error occurs processing the response
742 private static void processVServerResponse(AaiGetVserverResponse aaiResponse) throws AaiException {
743 if (aaiResponse == null) {
744 throw new AaiException("AAI Response is null (query by vserver-name)");
746 if (aaiResponse.getRequestError() != null) {
747 throw new AaiException("AAI Responded with a request error (query by vserver-name)");
750 List<AaiNqVServer> lst = aaiResponse.getVserver();
755 AaiNqVServer svr = lst.get(0);
756 if (svr.getIsClosedLoopDisabled()) {
757 throw new AaiException("is-closed-loop-disabled is set to true (query by vserver-name)");
760 if (!PROV_STATUS_ACTIVE.equals(svr.getProvStatus())) {
761 throw new AaiException("prov-status is not ACTIVE (query by vserver-name)");
766 * Is closed loop disabled for an event.
768 * @param event the event
769 * @return <code>true</code> if the control loop is disabled, <code>false</code>
772 public static boolean isClosedLoopDisabled(VirtualControlLoopEvent event) {
773 Map<String, String> aai = event.getAai();
774 return (isAaiTrue(aai.get(VSERVER_IS_CLOSED_LOOP_DISABLED))
775 || isAaiTrue(aai.get(GENERIC_VNF_IS_CLOSED_LOOP_DISABLED)));
779 * Does provisioning status, for an event, have a value other than ACTIVE?
781 * @param event the event
782 * @return {@code true} if the provisioning status is neither ACTIVE nor {@code null},
783 * {@code false} otherwise
785 protected static boolean isProvStatusInactive(VirtualControlLoopEvent event) {
786 Map<String, String> aai = event.getAai();
787 return (!PROV_STATUS_ACTIVE.equals(aai.getOrDefault(VSERVER_PROV_STATUS, PROV_STATUS_ACTIVE))
788 || !PROV_STATUS_ACTIVE.equals(aai.getOrDefault(GENERIC_VNF_PROV_STATUS, PROV_STATUS_ACTIVE)));
792 * Determines the boolean value represented by the given AAI field value.
794 * @param aaiValue value to be examined
795 * @return the boolean value represented by the field value, or {@code false} if the
796 * value is {@code null}
798 protected static boolean isAaiTrue(String aaiValue) {
799 return ("true".equalsIgnoreCase(aaiValue) || "T".equalsIgnoreCase(aaiValue) || "yes".equalsIgnoreCase(aaiValue)
800 || "Y".equalsIgnoreCase(aaiValue));
804 * Get the A&AI VService information for an event.
806 * @param event the event
807 * @return a AaiGetVserverResponse
808 * @throws ControlLoopException if an error occurs
810 public static AaiGetVserverResponse getAAIVserverInfo(VirtualControlLoopEvent event) throws ControlLoopException {
811 UUID requestId = event.getRequestId();
812 AaiGetVserverResponse response = null;
813 String vserverName = event.getAai().get(VSERVER_VSERVER_NAME);
816 if (vserverName != null) {
817 String aaiHostURL = PolicyEngine.manager.getEnvironmentProperty("aai.url");
818 String aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.username");
819 String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
820 String aaiGetQueryByVserver = "/aai/v11/nodes/vservers?vserver-name=";
821 String url = aaiHostURL + aaiGetQueryByVserver;
822 logger.info("AAI Host URL by VServer: {}", url);
823 response = new AaiManager(new RESTManager()).getQueryByVserverName(url, aaiUser, aaiPassword, requestId,
826 } catch (Exception e) {
827 logger.error("getAAIVserverInfo exception: ", e);
828 throw new ControlLoopException("Exception in getAAIVserverInfo: ", e);
835 * Get A&AI VNF information for an event.
837 * @param event the event
838 * @return a AaiGetVnfResponse
839 * @throws ControlLoopException if an error occurs
841 public static AaiGetVnfResponse getAAIVnfInfo(VirtualControlLoopEvent event) throws ControlLoopException {
842 UUID requestId = event.getRequestId();
843 AaiGetVnfResponse response = null;
844 String vnfName = event.getAai().get(GENERIC_VNF_VNF_NAME);
845 String vnfId = event.getAai().get(GENERIC_VNF_VNF_ID);
847 String aaiHostURL = PolicyEngine.manager.getEnvironmentProperty("aai.url");
848 String aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.username");
849 String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
852 if (vnfName != null) {
853 String aaiGetQueryByVnfName = "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=";
854 String url = aaiHostURL + aaiGetQueryByVnfName;
855 logger.info("AAI Host URL by VNF name: {}", url);
856 response = new AaiManager(new RESTManager()).getQueryByVnfName(url, aaiUser, aaiPassword, requestId,
858 } else if (vnfId != null) {
859 String aaiGetQueryByVnfId = "/aai/v11/network/generic-vnfs/generic-vnf/";
860 String url = aaiHostURL + aaiGetQueryByVnfId;
861 logger.info("AAI Host URL by VNF ID: {}", url);
863 new AaiManager(new RESTManager()).getQueryByVnfId(url, aaiUser, aaiPassword, requestId, vnfId);
865 } catch (Exception e) {
866 logger.error("getAAIVnfInfo exception: ", e);
867 throw new ControlLoopException("Exception in getAAIVnfInfo: ", e);
874 public boolean isActive() {
880 public boolean releaseLock() {
886 public String toString() {
887 return "ControlLoopEventManager [closedLoopControlName=" + closedLoopControlName + ", requestID=" + requestID
888 + ", processor=" + processor + ", onset=" + (onset != null ? onset.getRequestId() : "null")
889 + ", numOnsets=" + numOnsets + ", numAbatements=" + numAbatements + ", isActivated=" + isActivated
890 + ", currentOperation=" + currentOperation + ", targetLock=" + targetLock + "]";