diff options
Diffstat (limited to 'controlloop/common/eventmanager/src/main/java')
2 files changed, 125 insertions, 56 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java index bfb8c13fe..edee4c2f0 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java @@ -31,7 +31,7 @@ import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.UUID; - +import org.onap.policy.aai.AaiCqResponse; import org.onap.policy.aai.AaiGetVnfResponse; import org.onap.policy.aai.AaiGetVserverResponse; import org.onap.policy.aai.AaiManager; @@ -82,8 +82,8 @@ public class ControlLoopEventManager implements LockCallback, Serializable { private static final String QUERY_AAI_ERROR_MSG = "Exception from queryAai: "; /** - * Additional time, in seconds, to add to a "lock" request. This ensures that the lock - * won't expire right before an operation completes. + * Additional time, in seconds, to add to a "lock" request. This ensures that the lock won't expire right before an + * operation completes. */ private static final int ADDITIONAL_LOCK_SEC = 60; @@ -111,8 +111,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { private boolean useTargetLock = true; /** - * Wrapper for AAI vserver named-query response. This is initialized in a lazy - * fashion. + * Wrapper for AAI vserver named-query response. This is initialized in a lazy fashion. */ private AaiNqResponseWrapper nqVserverResponse = null; @@ -305,8 +304,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { /** * Check if the control loop is final. * - * @return a VirtualControlLoopNotification if the control loop is final, otherwise - * <code>null</code> is returned + * @return a VirtualControlLoopNotification if the control loop is final, otherwise <code>null</code> is returned * @throws ControlLoopException if an error occurs */ public VirtualControlLoopNotification isControlLoopFinal() throws ControlLoopException { @@ -496,8 +494,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { // if (!this.useTargetLock) { TargetLock lock = PolicyGuard.createTargetLock(this.currentOperation.policy.getTarget().getType(), - this.currentOperation.getTargetEntity(), - this.onset.getRequestId(), this); + this.currentOperation.getTargetEntity(), this.onset.getRequestId(), this); this.targetLock = lock; return LockResult.createLockResult(GuardResult.LOCK_ACQUIRED, lock); } @@ -510,16 +507,15 @@ public class ControlLoopEventManager implements LockCallback, Serializable { // Currently, it should be. But in the future it may not. // GuardResult result = PolicyGuard.lockTarget(targetLock, - this.currentOperation.getOperationTimeout() + ADDITIONAL_LOCK_SEC); + this.currentOperation.getOperationTimeout() + ADDITIONAL_LOCK_SEC); return new LockResult<>(result, this.targetLock); } else { // // Ask the Guard // - LockResult<GuardResult, TargetLock> lockResult = - PolicyGuard.lockTarget(this.currentOperation.policy.getTarget().getType(), - this.currentOperation.getTargetEntity(), this.onset.getRequestId(), this, - this.currentOperation.getOperationTimeout() + ADDITIONAL_LOCK_SEC); + LockResult<GuardResult, TargetLock> lockResult = PolicyGuard.lockTarget( + this.currentOperation.policy.getTarget().getType(), this.currentOperation.getTargetEntity(), + this.onset.getRequestId(), this, this.currentOperation.getOperationTimeout() + ADDITIONAL_LOCK_SEC); // // Was it acquired? // @@ -637,13 +633,13 @@ public class ControlLoopEventManager implements LockCallback, Serializable { return; } try { - this.lastOperationManager.commitAbatement(message,outcome); + this.lastOperationManager.commitAbatement(message, outcome); } catch (NoSuchElementException e) { logger.error("{}: commitAbatement threw an exception ", this, e); } } - + /** * Set the control loop time out. * @@ -775,8 +771,8 @@ public class ControlLoopEventManager implements LockCallback, Serializable { * Process a response from A&AI for a VNF. * * @param aaiResponse the response from A&AI - * @param queryByVnfId <code>true</code> if the query was based on vnf-id, - * <code>false</code> if the query was based on vnf-name + * @param queryByVnfId <code>true</code> if the query was based on vnf-id, <code>false</code> if the query was based + * on vnf-name * @throws AaiException if an error occurs processing the response */ private static void processVnfResponse(AaiGetVnfResponse aaiResponse, boolean queryByVnfId) throws AaiException { @@ -831,38 +827,35 @@ public class ControlLoopEventManager implements LockCallback, Serializable { * Is closed loop disabled for an event. * * @param event the event - * @return <code>true</code> if the control loop is disabled, <code>false</code> - * otherwise + * @return <code>true</code> if the control loop is disabled, <code>false</code> otherwise */ public static boolean isClosedLoopDisabled(VirtualControlLoopEvent event) { Map<String, String> aai = event.getAai(); return (isAaiTrue(aai.get(VSERVER_IS_CLOSED_LOOP_DISABLED)) - || isAaiTrue(aai.get(GENERIC_VNF_IS_CLOSED_LOOP_DISABLED))); + || isAaiTrue(aai.get(GENERIC_VNF_IS_CLOSED_LOOP_DISABLED))); } /** * Does provisioning status, for an event, have a value other than ACTIVE. * * @param event the event - * @return {@code true} if the provisioning status is neither ACTIVE nor {@code null}, - * {@code false} otherwise + * @return {@code true} if the provisioning status is neither ACTIVE nor {@code null}, {@code false} otherwise */ protected static boolean isProvStatusInactive(VirtualControlLoopEvent event) { Map<String, String> aai = event.getAai(); return (!PROV_STATUS_ACTIVE.equals(aai.getOrDefault(VSERVER_PROV_STATUS, PROV_STATUS_ACTIVE)) - || !PROV_STATUS_ACTIVE.equals(aai.getOrDefault(GENERIC_VNF_PROV_STATUS, PROV_STATUS_ACTIVE))); + || !PROV_STATUS_ACTIVE.equals(aai.getOrDefault(GENERIC_VNF_PROV_STATUS, PROV_STATUS_ACTIVE))); } /** * Determines the boolean value represented by the given AAI field value. * * @param aaiValue value to be examined - * @return the boolean value represented by the field value, or {@code false} if the - * value is {@code null} + * @return the boolean value represented by the field value, or {@code false} if the value is {@code null} */ protected static boolean isAaiTrue(String aaiValue) { return ("true".equalsIgnoreCase(aaiValue) || "T".equalsIgnoreCase(aaiValue) || "yes".equalsIgnoreCase(aaiValue) - || "Y".equalsIgnoreCase(aaiValue)); + || "Y".equalsIgnoreCase(aaiValue)); } /** @@ -937,6 +930,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { /** * Gets the output from the AAI vserver named-query, using the cache, if appropriate. + * * @return output from the AAI vserver named-query */ public AaiNqResponseWrapper getNqVserverFromAai() { @@ -976,7 +970,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { } AaiNqResponse aaiNqResponse = new AaiManager(new RestManager()).postQuery(getPeManagerEnvProperty(AAI_URL), - getPeManagerEnvProperty(AAI_USERNAME_PROPERTY), getPeManagerEnvProperty(AAI_PASS_PROPERTY), + getPeManagerEnvProperty(AAI_USERNAME_PROPERTY), getPeManagerEnvProperty(AAI_PASS_PROPERTY), aaiNqRequest, onset.getRequestId()); // Check AAI response @@ -997,8 +991,8 @@ public class ControlLoopEventManager implements LockCallback, Serializable { } /** - * This method reads and validates environmental properties coming from the policy engine. Null - * properties cause an {@link IllegalArgumentException} runtime exception to be thrown + * This method reads and validates environmental properties coming from the policy engine. Null properties cause an + * {@link IllegalArgumentException} runtime exception to be thrown * * @param enginePropertyName the name of the parameter to retrieve * @return the property value @@ -1032,4 +1026,40 @@ public class ControlLoopEventManager implements LockCallback, Serializable { + ", currentOperation=" + currentOperation + ", targetLock=" + targetLock + "]"; } + /** + * This function calls Aai Custom Query and responds with the AaiCqResponse. + * + * @param event input event + * @return AaiCqResponse Response from Aai for custom query + * @throws AaiException if error occurs + */ + public AaiCqResponse getCqResponse(VirtualControlLoopEvent event) throws AaiException { + + Map<String, String> aai = event.getAai(); + + if (aai.containsKey(VSERVER_IS_CLOSED_LOOP_DISABLED) || aai.containsKey(GENERIC_VNF_IS_CLOSED_LOOP_DISABLED)) { + + if (isClosedLoopDisabled(event)) { + throw new AaiException("is-closed-loop-disabled is set to true on VServer or VNF"); + } + + if (isProvStatusInactive(event)) { + throw new AaiException("prov-status is not ACTIVE on VServer or VNF"); + } + } + + UUID reqId = event.getRequestId(); + AaiCqResponse response = null; + String vserverId = event.getAai().get(VSERVER_VSERVER_NAME); + + String aaiHostUrl = PolicyEngine.manager.getEnvironmentProperty(AAI_URL); + String aaiUser = PolicyEngine.manager.getEnvironmentProperty(AAI_USERNAME_PROPERTY); + String aaiPassword = PolicyEngine.manager.getEnvironmentProperty(AAI_PASS_PROPERTY); + + response = new AaiManager(new RestManager()).getCustomQueryResponse(aaiHostUrl, aaiUser, aaiPassword, reqId, + vserverId); + return response; + + } + } diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java index dfd2a1af9..3ff5c260e 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java @@ -33,6 +33,7 @@ import java.util.Properties; import javax.persistence.EntityManager; import javax.persistence.Persistence; import org.eclipse.persistence.config.PersistenceUnitProperties; +import org.onap.aai.domain.yang.GenericVnf; import org.onap.policy.aai.util.AaiException; import org.onap.policy.appc.Response; import org.onap.policy.appc.ResponseCode; @@ -111,14 +112,25 @@ public class ControlLoopOperationManager implements Serializable { case "APPC": if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) { /* - * The target vnf-id may not be the same as the source vnf-id specified in the - * yaml, the target vnf-id is retrieved by a named query to A&AI. + * The target vnf-id may not be the same as the source vnf-id specified in the yaml, the target + * vnf-id is retrieved by a named query to A&AI. */ - String targetVnf = AppcLcmActorServiceProvider.vnfNamedQuery(policy.getTarget().getResourceID(), - this.targetEntity, PolicyEngine.manager.getEnvironmentProperty("aai.url"), - PolicyEngine.manager.getEnvironmentProperty("aai.username"), - PolicyEngine.manager.getEnvironmentProperty("aai.password")); - this.targetEntity = targetVnf; + if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) { + GenericVnf genvnf = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset) + .getGenericVnfByModelInvariantId(policy.getTarget().getResourceID()); + if (genvnf == null) { + logger.info("Target entity could not be found"); + throw new AaiException("Target vnf-id could not be found"); + } + this.targetEntity = genvnf.getVnfId(); + + } else { + this.targetEntity = + AppcLcmActorServiceProvider.vnfNamedQuery(policy.getTarget().getResourceID(), + this.targetEntity, PolicyEngine.manager.getEnvironmentProperty("aai.url"), + PolicyEngine.manager.getEnvironmentProperty("aai.username"), + PolicyEngine.manager.getEnvironmentProperty("aai.password")); + } } break; case "SO": @@ -134,6 +146,7 @@ public class ControlLoopOperationManager implements Serializable { } } + public ControlLoopEventManager getEventManager() { return eventManager; } @@ -219,10 +232,16 @@ public class ControlLoopOperationManager implements Serializable { } /* - * If the vnf-name was retrieved from the onset then the vnf-id must be obtained - * from the event manager's A&AI GET query + * If the vnf-name was retrieved from the onset then the vnf-id must be obtained from the event + * manager's A&AI GET query */ - String vnfId = this.eventManager.getVnfResponse().getVnfId(); + String vnfId; + if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) { + vnfId = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset).getDefaultGenericVnf() + .getVnfId(); + } else { + vnfId = this.eventManager.getVnfResponse().getVnfId(); + } if (vnfId == null) { throw new AaiException("No vnf-id found"); } @@ -244,10 +263,16 @@ public class ControlLoopOperationManager implements Serializable { } /* - * If the vnf-name was retrieved from the onset then the vnf-id must be obtained - * from the event manager's A&AI GET query + * If the vnf-name was retrieved from the onset then the vnf-id must be obtained from the event + * manager's A&AI GET query */ - String vnfId = this.eventManager.getVnfResponse().getVnfId(); + String vnfId; + if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) { + vnfId = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset).getDefaultGenericVnf() + .getVnfId(); + } else { + vnfId = this.eventManager.getVnfResponse().getVnfId(); + } if (vnfId == null) { throw new AaiException("No vnf-id found"); } @@ -265,8 +290,10 @@ public class ControlLoopOperationManager implements Serializable { * @param onset the onset event * @return the operation request * @throws ControlLoopException if an error occurs + * @throws AaiException if error occurs */ - public Object startOperation(/* VirtualControlLoopEvent */ControlLoopEvent onset) throws ControlLoopException { + public Object startOperation(/* VirtualControlLoopEvent */ControlLoopEvent onset) + throws ControlLoopException, AaiException { verifyOperatonCanRun(); // @@ -285,8 +312,8 @@ public class ControlLoopOperationManager implements Serializable { switch (policy.getActor()) { case "APPC": /* - * If the recipe is ModifyConfig, a legacy APPC request is constructed. Otherwise an - * LCMRequest is constructed. + * If the recipe is ModifyConfig, a legacy APPC request is constructed. Otherwise an LCMRequest is + * constructed. */ this.currentOperation = operation; if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) { @@ -303,8 +330,14 @@ public class ControlLoopOperationManager implements Serializable { return operationRequest; case "SO": SoActorServiceProvider soActorSp = new SoActorServiceProvider(); - this.operationRequest = soActorSp.constructRequest((VirtualControlLoopEvent) onset, - operation.clOperation, this.policy, eventManager.getNqVserverFromAai()); + if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) { + this.operationRequest = + soActorSp.constructRequestCq((VirtualControlLoopEvent) onset, operation.clOperation, + this.policy, eventManager.getCqResponse((VirtualControlLoopEvent) onset)); + } else { + this.operationRequest = soActorSp.constructRequest((VirtualControlLoopEvent) onset, + operation.clOperation, this.policy, eventManager.getNqVserverFromAai()); + } // Save the operation this.currentOperation = operation; @@ -315,11 +348,17 @@ public class ControlLoopOperationManager implements Serializable { return operationRequest; case "VFC": - this.operationRequest = VfcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, - operation.clOperation, this.policy, this.eventManager.getVnfResponse(), - PolicyEngine.manager.getEnvironmentProperty("vfc.url"), - PolicyEngine.manager.getEnvironmentProperty("vfc.username"), - PolicyEngine.manager.getEnvironmentProperty("vfc.password")); + if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) { + this.operationRequest = VfcActorServiceProvider.constructRequestCq((VirtualControlLoopEvent) onset, + operation.clOperation, this.policy, + eventManager.getCqResponse((VirtualControlLoopEvent) onset)); + } else { + this.operationRequest = VfcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, + operation.clOperation, this.policy, this.eventManager.getVnfResponse(), + PolicyEngine.manager.getEnvironmentProperty("vfc.url"), + PolicyEngine.manager.getEnvironmentProperty("vfc.username"), + PolicyEngine.manager.getEnvironmentProperty("vfc.password")); + } this.currentOperation = operation; if (this.operationRequest == null) { this.policyResult = PolicyResult.FAILURE; @@ -331,7 +370,7 @@ public class ControlLoopOperationManager implements Serializable { */ this.currentOperation = operation; this.operationRequest = SdnrActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, - operation.clOperation, this.policy); + operation.clOperation, this.policy); // // Save the operation // @@ -342,8 +381,8 @@ public class ControlLoopOperationManager implements Serializable { return operationRequest; case "SDNC": SdncActorServiceProvider provider = new SdncActorServiceProvider(); - this.operationRequest = provider.constructRequest((VirtualControlLoopEvent) onset, - operation.clOperation, this.policy); + this.operationRequest = + provider.constructRequest((VirtualControlLoopEvent) onset, operation.clOperation, this.policy); this.currentOperation = operation; if (this.operationRequest == null) { this.policyResult = PolicyResult.FAILURE; |