diff options
author | pramod.jamkhedkar <pramod@research.att.com> | 2019-11-13 13:36:56 -0500 |
---|---|---|
committer | pramod.jamkhedkar <pramod@research.att.com> | 2019-11-15 12:51:55 -0500 |
commit | 9398165f5c35e686e2570c68cd0eb4a2e9254a02 (patch) | |
tree | a725c77c9986505250163c1199429afa1acb68dc | |
parent | 03dff4f370602a2e6726d2b8357e10c30dcf8210 (diff) |
Removing Named Query
Removing all the related files and necessary modifications for removing named query. The code now only supports Custom Query.
Issue-ID: POLICY-2125
Change-Id: I2d376eb955d69f45c39ad4d4a1cfacb4d620ca8e
Signed-off-by: pramod.jamkhedkar <pramod@research.att.com>
18 files changed, 311 insertions, 1244 deletions
diff --git a/controlloop/common/controller-usecases/src/main/resources/usecases.drl b/controlloop/common/controller-usecases/src/main/resources/usecases.drl index 54295e971..692c74350 100644 --- a/controlloop/common/controller-usecases/src/main/resources/usecases.drl +++ b/controlloop/common/controller-usecases/src/main/resources/usecases.drl @@ -41,7 +41,6 @@ import org.onap.policy.controlloop.actor.so.SoActorServiceProvider; import org.onap.policy.controlloop.actor.cds.CdsActorServiceProvider; import org.onap.policy.controlloop.actor.cds.CdsActorServiceProvider.CdsActorServiceManager; import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants; -import org.onap.policy.aai.AaiNqResponseWrapper; import org.onap.policy.aai.AaiCqResponse; import org.onap.policy.appc.Request; import org.onap.policy.appc.Response; @@ -778,7 +777,6 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED" // NOTE: The environment properties uses "guard.disabled" but the boolean is guardEnabled boolean guardEnabled = "false".equalsIgnoreCase(PolicyEngineConstants.getManager().getEnvironmentProperty("guard.disabled")); - boolean cqEnabled = "true".equalsIgnoreCase(PolicyEngineConstants.getManager().getEnvironmentProperty("aai.customQuery")); if(guardEnabled){ @@ -790,10 +788,6 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED" $operation.getTargetEntity(), $event.getRequestId().toString(), () -> { - if (!cqEnabled) { - AaiNqResponseWrapper resp = $manager.getNqVserverFromAai(); - return(resp == null ? null : resp.countVfModules()); - } else { try { AaiCqResponse resp_cq = $manager.getCqResponse($event); if (resp_cq == null){ @@ -808,7 +802,6 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED" logger.warn("{}: {}", $params.getClosedLoopControlName(), drools.getRule().getName(), e); } return null; - } })); t.start(); } 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 8b06a9681..868ab00a3 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 @@ -27,13 +27,9 @@ import static org.onap.policy.controlloop.ControlLoopTargetType.VNF; import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; -import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; @@ -42,16 +38,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; import org.onap.policy.aai.AaiCqResponse; -import org.onap.policy.aai.AaiGetVnfResponse; -import org.onap.policy.aai.AaiGetVserverResponse; import org.onap.policy.aai.AaiManager; -import org.onap.policy.aai.AaiNqInstanceFilters; -import org.onap.policy.aai.AaiNqNamedQuery; -import org.onap.policy.aai.AaiNqQueryParameters; -import org.onap.policy.aai.AaiNqRequest; -import org.onap.policy.aai.AaiNqResponse; -import org.onap.policy.aai.AaiNqResponseWrapper; -import org.onap.policy.aai.AaiNqVServer; import org.onap.policy.aai.util.AaiException; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopException; @@ -69,7 +56,6 @@ import org.onap.policy.drools.core.lock.LockState; import org.onap.policy.drools.system.PolicyEngineConstants; import org.onap.policy.drools.utils.Pair; import org.onap.policy.rest.RestManager; -import org.onap.policy.so.util.Serialization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -92,7 +78,6 @@ public class ControlLoopEventManager implements Serializable { public static final String AAI_USERNAME_PROPERTY = "aai.username"; public static final String AAI_PASS_PROPERTY = "aai.password"; - 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 @@ -128,25 +113,9 @@ public class ControlLoopEventManager implements Serializable { private ControlLoopOperationManager currentOperation = null; private ControlLoopOperationManager lastOperationManager = null; private transient Lock targetLock = null; - private AaiGetVnfResponse vnfResponse = null; - private AaiGetVserverResponse vserverResponse = null; private boolean useTargetLock = true; /** - * Wrapper for AAI vserver named-query response. This is initialized in a lazy fashion. - */ - private AaiNqResponseWrapper nqVserverResponse = null; - - private static Collection<String> requiredAAIKeys = new ArrayList<>(); - - static { - requiredAAIKeys.add("AICVServerSelfLink"); - requiredAAIKeys.add("AICIdentity"); - requiredAAIKeys.add("is_closed_loop_disabled"); - requiredAAIKeys.add(VM_NAME); - } - - /** * Constructs the object. * * @param closedLoopControlName name of the control loop @@ -592,11 +561,6 @@ public class ControlLoopEventManager implements Serializable { // if (event.equals(this.onset)) { // - // Query A&AI if needed - // - queryAai(event); - - // // DO NOT retract it // return NewEventStatus.FIRST_ONSET; @@ -697,14 +661,6 @@ public class ControlLoopEventManager implements Serializable { return 0; } - public AaiGetVnfResponse getVnfResponse() { - return vnfResponse; - } - - public AaiGetVserverResponse getVserverResponse() { - return vserverResponse; - } - /** * Check an event syntax. * @@ -771,118 +727,6 @@ public class ControlLoopEventManager implements Serializable { } /** - * Query A&AI for an event. - * - * @param event the event - * @throws AaiException if an error occurs retrieving information from A&AI - */ - public void queryAai(VirtualControlLoopEvent event) throws AaiException { - - Map<String, String> aai = event.getAai(); - - if (alreadyHaveData(event, aai)) { - return; - } - - if (vnfResponse != null || vserverResponse != null) { - // query has already been performed - return; - } - - try { - if (aai.containsKey(GENERIC_VNF_VNF_ID) || aai.containsKey(GENERIC_VNF_VNF_NAME)) { - vnfResponse = getAaiVnfInfo(event); - processVnfResponse(vnfResponse, aai.containsKey(GENERIC_VNF_VNF_ID)); - } else if (aai.containsKey(VSERVER_VSERVER_NAME)) { - vserverResponse = getAaiVserverInfo(event); - processVServerResponse(vserverResponse); - } - } catch (AaiException e) { - logger.error(QUERY_AAI_ERROR_MSG, e); - throw e; - } catch (Exception e) { - logger.error(QUERY_AAI_ERROR_MSG, e); - throw new AaiException(QUERY_AAI_ERROR_MSG + e.toString()); - } - } - - private boolean alreadyHaveData(VirtualControlLoopEvent event, Map<String, String> aai) throws AaiException { - if (aai.containsKey(VSERVER_IS_CLOSED_LOOP_DISABLED) || aai.containsKey(GENERIC_VNF_IS_CLOSED_LOOP_DISABLED) - || aai.containsKey(PNF_IS_IN_MAINT)) { - - if (isClosedLoopDisabled(event)) { - throw new AaiException( - "is-closed-loop-disabled is set to true on VServer or VNF or in-maint is set to true for PNF"); - } - - if (isProvStatusInactive(event)) { - throw new AaiException("prov-status is not ACTIVE on VServer or VNF or PNF"); - } - - // no need to query, as we already have the data - return true; - } - - return false; - } - - /** - * 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 - * @throws AaiException if an error occurs processing the response - */ - private static void processVnfResponse(AaiGetVnfResponse aaiResponse, boolean queryByVnfId) throws AaiException { - String queryTypeString = (queryByVnfId ? "vnf-id" : "vnf-name"); - - if (aaiResponse == null) { - throw new AaiException("AAI Response is null (query by " + queryTypeString + ")"); - } - if (aaiResponse.getRequestError() != null) { - throw new AaiException("AAI Responded with a request error (query by " + queryTypeString + ")"); - } - - if (aaiResponse.isClosedLoopDisabled()) { - throw new AaiException("is-closed-loop-disabled is set to true (query by " + queryTypeString + ")"); - } - - if (!PROV_STATUS_ACTIVE.equals(aaiResponse.getProvStatus())) { - throw new AaiException("prov-status is not ACTIVE (query by " + queryTypeString + ")"); - } - } - - /** - * Process a response from A&AI for a VServer. - * - * @param aaiResponse the response from A&AI - * @throws AaiException if an error occurs processing the response - */ - private static void processVServerResponse(AaiGetVserverResponse aaiResponse) throws AaiException { - if (aaiResponse == null) { - throw new AaiException("AAI Response is null (query by vserver-name)"); - } - if (aaiResponse.getRequestError() != null) { - throw new AaiException("AAI Responded with a request error (query by vserver-name)"); - } - - List<AaiNqVServer> lst = aaiResponse.getVserver(); - if (lst.isEmpty()) { - return; - } - - AaiNqVServer svr = lst.get(0); - if (svr.getIsClosedLoopDisabled()) { - throw new AaiException("is-closed-loop-disabled is set to true (query by vserver-name)"); - } - - if (!PROV_STATUS_ACTIVE.equals(svr.getProvStatus())) { - throw new AaiException("prov-status is not ACTIVE (query by vserver-name)"); - } - } - - /** * Is closed loop disabled for an event. * * @param event the event @@ -918,164 +762,6 @@ public class ControlLoopEventManager implements Serializable { || "Y".equalsIgnoreCase(aaiValue)); } - /** - * Get the A&AI VService information for an event. - * - * @param event the event - * @return a AaiGetVserverResponse - * @throws ControlLoopException if an error occurs - */ - public static AaiGetVserverResponse getAaiVserverInfo(VirtualControlLoopEvent event) throws ControlLoopException { - UUID requestId = event.getRequestId(); - AaiGetVserverResponse response = null; - String vserverName = event.getAai().get(VSERVER_VSERVER_NAME); - - try { - if (vserverName != null) { - String aaiHostUrl = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_URL); - String aaiUser = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_USERNAME_PROPERTY); - String aaiPassword = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_PASS_PROPERTY); - String aaiGetQueryByVserver = "/aai/v11/nodes/vservers?vserver-name="; - String url = aaiHostUrl + aaiGetQueryByVserver; - logger.info("AAI Host URL by VServer: {}", url); - response = new AaiManager(new RestManager()).getQueryByVserverName(url, aaiUser, aaiPassword, requestId, - vserverName); - } - } catch (Exception e) { - logger.error("getAaiVserverInfo exception: ", e); - throw new ControlLoopException("Exception in getAaiVserverInfo: ", e); - } - - return response; - } - - /** - * Get A&AI VNF information for an event. - * - * @param event the event - * @return a AaiGetVnfResponse - * @throws ControlLoopException if an error occurs - */ - public static AaiGetVnfResponse getAaiVnfInfo(VirtualControlLoopEvent event) throws ControlLoopException { - UUID requestId = event.getRequestId(); - AaiGetVnfResponse response = null; - String vnfName = event.getAai().get(GENERIC_VNF_VNF_NAME); - String vnfId = event.getAai().get(GENERIC_VNF_VNF_ID); - - String aaiHostUrl = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_URL); - String aaiUser = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_USERNAME_PROPERTY); - String aaiPassword = PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_PASS_PROPERTY); - - try { - if (vnfName != null) { - String aaiGetQueryByVnfName = "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name="; - String url = aaiHostUrl + aaiGetQueryByVnfName; - logger.info("AAI Host URL by VNF name: {}", url); - response = new AaiManager(new RestManager()).getQueryByVnfName(url, aaiUser, aaiPassword, requestId, - vnfName); - } else if (vnfId != null) { - String aaiGetQueryByVnfId = "/aai/v11/network/generic-vnfs/generic-vnf/"; - String url = aaiHostUrl + aaiGetQueryByVnfId; - logger.info("AAI Host URL by VNF ID: {}", url); - response = - new AaiManager(new RestManager()).getQueryByVnfId(url, aaiUser, aaiPassword, requestId, vnfId); - } - } catch (Exception e) { - logger.error("getAaiVnfInfo exception: ", e); - throw new ControlLoopException("Exception in getAaiVnfInfo: ", e); - } - - return response; - } - - /** - * 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() { - if (nqVserverResponse != null) { - // already queried - return nqVserverResponse; - } - - String vserverName = onset.getAai().get(VSERVER_VSERVER_NAME); - if (vserverName == null) { - logger.warn("Missing vserver-name for AAI request {}", onset.getRequestId()); - return null; - } - AaiNqRequest aaiNqRequest = getAaiNqRequest(vserverName); - - if (logger.isDebugEnabled()) { - logger.debug("AAI Request sent: {}", Serialization.gsonPretty.toJson(aaiNqRequest)); - } - - AaiNqResponse aaiNqResponse = new AaiManager(new RestManager()).postQuery(getPeManagerEnvProperty(AAI_URL), - getPeManagerEnvProperty(AAI_USERNAME_PROPERTY), getPeManagerEnvProperty(AAI_PASS_PROPERTY), - aaiNqRequest, onset.getRequestId()); - - // Check AAI response - if (aaiNqResponse == null) { - logger.warn("No response received from AAI for request {}", aaiNqRequest); - return null; - } - - // Create AAINQResponseWrapper - nqVserverResponse = new AaiNqResponseWrapper(onset.getRequestId(), aaiNqResponse); - - if (logger.isDebugEnabled()) { - logger.debug("AAI Named Query Response: "); - logger.debug(Serialization.gsonPretty.toJson(nqVserverResponse.getAaiNqResponse())); - } - - return nqVserverResponse; - } - - /** - * Gets an AAI Named Query Request object. - * - * @param vserverName vserver name. - * @return the AAI Named Query Request object. - */ - public static AaiNqRequest getAaiNqRequest(String vserverName) { - // create AAI named-query request with UUID started with "" - AaiNqRequest aaiNqRequest = new AaiNqRequest(); - AaiNqQueryParameters aaiNqQueryParam = new AaiNqQueryParameters(); - AaiNqNamedQuery aaiNqNamedQuery = new AaiNqNamedQuery(); - final AaiNqInstanceFilters aaiNqInstanceFilter = new AaiNqInstanceFilters(); - - // queryParameters - aaiNqNamedQuery.setNamedQueryUuid(UUID.fromString("4ff56a54-9e3f-46b7-a337-07a1d3c6b469")); - aaiNqQueryParam.setNamedQuery(aaiNqNamedQuery); - aaiNqRequest.setQueryParameters(aaiNqQueryParam); - // - // instanceFilters - // - Map<String, Map<String, String>> aaiNqInstanceFilterMap = new HashMap<>(); - Map<String, String> aaiNqInstanceFilterMapItem = new HashMap<>(); - aaiNqInstanceFilterMapItem.put("vserver-name", vserverName); - aaiNqInstanceFilterMap.put("vserver", aaiNqInstanceFilterMapItem); - aaiNqInstanceFilter.getInstanceFilter().add(aaiNqInstanceFilterMap); - aaiNqRequest.setInstanceFilters(aaiNqInstanceFilter); - return aaiNqRequest; - } - - /** - * 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 - */ - private static String getPeManagerEnvProperty(String enginePropertyName) { - String enginePropertyValue = PolicyEngineConstants.getManager().getEnvironmentProperty(enginePropertyName); - if (enginePropertyValue == null) { - throw new IllegalArgumentException("The value of policy engine manager environment property \"" - + enginePropertyName + "\" may not be null"); - } - return enginePropertyValue; - } - @Override public String toString() { return "ControlLoopEventManager [closedLoopControlName=" + closedLoopControlName + ", requestId=" + requestId @@ -1122,7 +808,7 @@ public class ControlLoopEventManager implements Serializable { vserverId); if (response == null) { - throw new AaiException("Aai response is undefined"); + throw new AaiException("Target vnf-id could not be found"); } 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 9353ac2d6..20425f259 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 @@ -77,7 +77,6 @@ import org.slf4j.LoggerFactory; public class ControlLoopOperationManager implements Serializable { private static final String SUCCESS_MSG = " Success"; private static final String FAILED_MSG = " Failed"; - private static final String AAI_CUSTOM_QUERY = "aai.customQuery"; private static final long serialVersionUID = -3773199283624595410L; private static final Logger logger = LoggerFactory.getLogger(ControlLoopOperationManager.class); @@ -116,8 +115,8 @@ public class ControlLoopOperationManager implements Serializable { * @param em the event manager * @throws ControlLoopException if an error occurs */ - public ControlLoopOperationManager(ControlLoopEvent onset, Policy policy, ControlLoopEventManager em) - throws ControlLoopException { + public ControlLoopOperationManager(ControlLoopEvent onset, Policy policy, + ControlLoopEventManager em) throws ControlLoopException { this.onset = onset; this.policy = policy; @@ -126,12 +125,9 @@ public class ControlLoopOperationManager implements Serializable { try { if (TargetType.VNF.equals(policy.getTarget().getType()) - || TargetType.VFMODULE.equals(policy.getTarget().getType())) { - String aaiCqEnvProp = - PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_CUSTOM_QUERY); - if (StringUtils.isBlank(aaiCqEnvProp) || Boolean.valueOf(aaiCqEnvProp)) { - this.aaiCqResponse = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset); - } + || TargetType.VFMODULE.equals(policy.getTarget().getType())) { + this.aaiCqResponse = + this.eventManager.getCqResponse((VirtualControlLoopEvent) onset); } this.targetEntity = getTarget(policy); @@ -143,7 +139,6 @@ public class ControlLoopOperationManager implements Serializable { } } - private void initActor(Policy policy) throws AaiException, ControlLoopException { // // Let's make a sanity check @@ -163,37 +158,29 @@ public class ControlLoopOperationManager implements Serializable { case "CDS": break; default: - throw new ControlLoopException("ControlLoopEventManager: policy has an unknown actor."); + throw new ControlLoopException( + "ControlLoopEventManager: policy has an unknown actor."); } } - private void initAppc(Policy policy) throws AaiException { 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 + * 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. */ - if (Boolean.valueOf(PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_CUSTOM_QUERY))) { - GenericVnf genvnf = - this.aaiCqResponse.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, PolicyEngineConstants.getManager().getEnvironmentProperty("aai.url"), - PolicyEngineConstants.getManager().getEnvironmentProperty("aai.username"), - PolicyEngineConstants.getManager().getEnvironmentProperty("aai.password")); + GenericVnf genvnf = this.aaiCqResponse + .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(); + } } - public ControlLoopEventManager getEventManager() { return eventManager; } @@ -208,10 +195,11 @@ public class ControlLoopOperationManager implements Serializable { @Override public String toString() { - return "ControlLoopOperationManager [onset=" + (onset != null ? onset.getRequestId() : "null") + ", policy=" - + (policy != null ? policy.getId() : "null") + ", attempts=" + attempts + ", policyResult=" - + policyResult + ", currentOperation=" + currentOperation + ", operationHistory=" + operationHistory - + "]"; + return "ControlLoopOperationManager [onset=" + + (onset != null ? onset.getRequestId() : "null") + ", policy=" + + (policy != null ? policy.getId() : "null") + ", attempts=" + attempts + + ", policyResult=" + policyResult + ", currentOperation=" + currentOperation + + ", operationHistory=" + operationHistory + "]"; } // @@ -226,8 +214,8 @@ public class ControlLoopOperationManager implements Serializable { @Override public String toString() { - return "Operation [attempt=" + attempt + ", policyResult=" + policyResult + ", operation=" + clOperation - + "]"; + return "Operation [attempt=" + attempt + ", policyResult=" + policyResult + + ", operation=" + clOperation + "]"; } } @@ -272,7 +260,6 @@ public class ControlLoopOperationManager implements Serializable { } } - private String getVfModuleTarget() throws ControlLoopException { VirtualControlLoopEvent virtualOnsetEvent = (VirtualControlLoopEvent) this.onset; if (this.onset.getTarget().equalsIgnoreCase(VSERVER_VSERVER_NAME)) { @@ -288,16 +275,12 @@ public class ControlLoopOperationManager implements Serializable { } /* - * If the vnf-name was retrieved from the onset then the vnf-id must be obtained from the event + * 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 */ try { - String vnfId; - if (Boolean.valueOf(PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_CUSTOM_QUERY))) { - vnfId = this.aaiCqResponse.getDefaultGenericVnf().getVnfId(); - } else { - vnfId = this.eventManager.getVnfResponse().getVnfId(); - } + String vnfId = this.aaiCqResponse.getDefaultGenericVnf().getVnfId(); if (vnfId == null) { throw new AaiException("No vnf-id found"); } @@ -314,7 +297,7 @@ public class ControlLoopOperationManager implements Serializable { VirtualControlLoopEvent virtualOnsetEvent = (VirtualControlLoopEvent) this.onset; if (!PNF_NAME.equalsIgnoreCase(onset.getTarget())) { throw new ControlLoopException( - "Target in the onset event is either null or does not match target key expected in AAI section."); + "Target in the onset event is either null or does not match target key expected in AAI section."); } return virtualOnsetEvent.getAai().get(PNF_NAME); } @@ -327,7 +310,7 @@ public class ControlLoopOperationManager implements Serializable { * @throws ControlLoopException if an error occurs */ public Object startOperation(/* VirtualControlLoopEvent */ControlLoopEvent onset) - throws ControlLoopException { + throws ControlLoopException { verifyOperatonCanRun(); // @@ -358,7 +341,8 @@ public class ControlLoopOperationManager implements Serializable { case "CDS": return startCdsOperation(onset, operation); default: - throw new ControlLoopException("invalid actor " + policy.getActor() + " on policy"); + throw new ControlLoopException( + "invalid actor " + policy.getActor() + " on policy"); } } catch (AaiException e) { @@ -366,19 +350,21 @@ public class ControlLoopOperationManager implements Serializable { } } - private Object startAppcOperation(ControlLoopEvent onset, Operation operation) { /* - * If the recipe is ModifyConfig, a legacy APPC request is constructed. Otherwise an LCMRequest is + * If the recipe is ModifyConfig, a legacy APPC request is constructed. Otherwise an + * LCMRequest is * constructed. */ this.currentOperation = operation; if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) { - this.operationRequest = AppcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, + this.operationRequest = + AppcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, operation.clOperation, this.policy, this.targetEntity); } else { - this.operationRequest = AppcLcmActorServiceProvider.constructRequest( - (VirtualControlLoopEvent) onset, operation.clOperation, this.policy, this.targetEntity); + this.operationRequest = + AppcLcmActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, + operation.clOperation, this.policy, this.targetEntity); } // // Save the operation @@ -387,17 +373,10 @@ public class ControlLoopOperationManager implements Serializable { return operationRequest; } - private Object startSoOperation(ControlLoopEvent onset, Operation operation) { SoActorServiceProvider soActorSp = new SoActorServiceProvider(); - if (Boolean.valueOf(PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_CUSTOM_QUERY))) { - this.operationRequest = - soActorSp.constructRequestCq((VirtualControlLoopEvent) onset, operation.clOperation, - this.policy, this.aaiCqResponse); - } else { - this.operationRequest = soActorSp.constructRequest((VirtualControlLoopEvent) onset, - operation.clOperation, this.policy, eventManager.getNqVserverFromAai()); - } + this.operationRequest = soActorSp.constructRequestCq((VirtualControlLoopEvent) onset, + operation.clOperation, this.policy, this.aaiCqResponse); // Save the operation this.currentOperation = operation; @@ -409,18 +388,10 @@ public class ControlLoopOperationManager implements Serializable { return operationRequest; } - private Object startVfcOperation(ControlLoopEvent onset, Operation operation) { - if (Boolean.valueOf(PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_CUSTOM_QUERY))) { - this.operationRequest = VfcActorServiceProvider.constructRequestCq((VirtualControlLoopEvent) onset, - operation.clOperation, this.policy, this.aaiCqResponse); - } else { - this.operationRequest = VfcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, - operation.clOperation, this.policy, this.eventManager.getVnfResponse(), - PolicyEngineConstants.getManager().getEnvironmentProperty("vfc.url"), - PolicyEngineConstants.getManager().getEnvironmentProperty("vfc.username"), - PolicyEngineConstants.getManager().getEnvironmentProperty("vfc.password")); - } + this.operationRequest = + VfcActorServiceProvider.constructRequestCq((VirtualControlLoopEvent) onset, + operation.clOperation, this.policy, this.aaiCqResponse); this.currentOperation = operation; if (this.operationRequest == null) { this.policyResult = PolicyResult.FAILURE; @@ -428,14 +399,13 @@ public class ControlLoopOperationManager implements Serializable { return operationRequest; } - private Object startSdnrOperation(ControlLoopEvent onset, Operation operation) { /* * If the recipe is ModifyConfig or ModifyConfigANR, a SDNR request is constructed. */ this.currentOperation = operation; - this.operationRequest = SdnrActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, - operation.clOperation, this.policy); + this.operationRequest = SdnrActorServiceProvider + .constructRequest((VirtualControlLoopEvent) onset, operation.clOperation, this.policy); // // Save the operation // @@ -446,11 +416,10 @@ public class ControlLoopOperationManager implements Serializable { return operationRequest; } - private Object startSdncOperation(ControlLoopEvent onset, Operation operation) { 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; @@ -458,11 +427,13 @@ public class ControlLoopOperationManager implements Serializable { return operationRequest; } - private Object startCdsOperation(ControlLoopEvent onset, Operation operation) throws AaiException { + private Object startCdsOperation(ControlLoopEvent onset, Operation operation) + throws AaiException { CdsActorServiceProvider provider = new CdsActorServiceProvider(); - Optional<ExecutionServiceInput> optionalRequest = provider.constructRequest( - (VirtualControlLoopEvent) onset, operation.clOperation, this.policy, this.buildAaiParams()); + Optional<ExecutionServiceInput> optionalRequest = + provider.constructRequest((VirtualControlLoopEvent) onset, operation.clOperation, + this.policy, this.buildAaiParams()); this.currentOperation = operation; if (optionalRequest.isPresent()) { @@ -477,6 +448,7 @@ public class ControlLoopOperationManager implements Serializable { /** * Build AAI parameters for CDS operation. + * * @return a map containing vnf id key and value for the vnf to apply the action to. * @throws AaiException if the vnf can not be found. */ @@ -485,26 +457,24 @@ public class ControlLoopOperationManager implements Serializable { Map<String, String> result = new HashMap<>(); if (TargetType.VNF.equals(policy.getTarget().getType()) - || TargetType.VFMODULE.equals(policy.getTarget().getType())) { + || TargetType.VFMODULE.equals(policy.getTarget().getType())) { - if (Boolean.valueOf(PolicyEngineConstants.getManager().getEnvironmentProperty(AAI_CUSTOM_QUERY))) { + ServiceInstance serviceInstance = this.aaiCqResponse.getServiceInstance(); + if (serviceInstance == null) { + logger.info("Target entity service instance could not be found"); + throw new AaiException("Target service instance could not be found"); + } - ServiceInstance serviceInstance = this.aaiCqResponse.getServiceInstance(); - if (serviceInstance == null) { - logger.info("Target entity service instance could not be found"); - throw new AaiException("Target service instance could not be found"); - } + GenericVnf genericVnf = this.aaiCqResponse + .getGenericVnfByModelInvariantId(policy.getTarget().getResourceID()); + if (genericVnf == null) { + logger.info("Target entity generic vnf could not be found"); + throw new AaiException("Target generic vnf could not be found"); + } - GenericVnf genericVnf = - this.aaiCqResponse.getGenericVnfByModelInvariantId(policy.getTarget().getResourceID()); - if (genericVnf == null) { - logger.info("Target entity generic vnf could not be found"); - throw new AaiException("Target generic vnf could not be found"); - } + result.put(AAI_SERVICE_INSTANCE_ID_KEY, serviceInstance.getServiceInstanceId()); + result.put(GENERIC_VNF_VNF_ID, genericVnf.getVnfId()); - result.put(AAI_SERVICE_INSTANCE_ID_KEY, serviceInstance.getServiceInstanceId()); - result.put(GENERIC_VNF_VNF_ID, genericVnf.getVnfId()); - } } else if (TargetType.PNF.equals(policy.getTarget().getType())) { result = this.eventManager.getPnf((VirtualControlLoopEvent) onset); } @@ -532,7 +502,7 @@ public class ControlLoopOperationManager implements Serializable { // // Cast LCM response and handle it // - return onResponse(( AppcLcmDmaapWrapper) response); + return onResponse((AppcLcmDmaapWrapper) response); } else if (response instanceof PciResponseWrapper) { // // Cast SDNR response and handle it @@ -575,8 +545,9 @@ public class ControlLoopOperationManager implements Serializable { // Integer operationAttempt = getSubRequestId(appcResponse); if (operationAttempt == null) { - this.completeOperation(operationAttempt, "Policy was unable to parse APP-C SubRequestID (it was null).", - PolicyResult.FAILURE_EXCEPTION); + this.completeOperation(operationAttempt, + "Policy was unable to parse APP-C SubRequestID (it was null).", + PolicyResult.FAILURE_EXCEPTION); return PolicyResult.FAILURE_EXCEPTION; } // @@ -587,8 +558,8 @@ public class ControlLoopOperationManager implements Serializable { // We cannot tell what happened if this doesn't exist // this.completeOperation(operationAttempt, - "Policy was unable to parse APP-C response status field (it was null).", - PolicyResult.FAILURE_EXCEPTION); + "Policy was unable to parse APP-C response status field (it was null).", + PolicyResult.FAILURE_EXCEPTION); return PolicyResult.FAILURE_EXCEPTION; } // @@ -599,16 +570,17 @@ public class ControlLoopOperationManager implements Serializable { // // We are unaware of this code // - this.completeOperation(operationAttempt, "Policy was unable to parse APP-C response status code field.", - PolicyResult.FAILURE_EXCEPTION); + this.completeOperation(operationAttempt, + "Policy was unable to parse APP-C response status code field.", + PolicyResult.FAILURE_EXCEPTION); return PolicyResult.FAILURE_EXCEPTION; } return onResponse(appcResponse, operationAttempt, code); } - - private PolicyResult onResponse(Response appcResponse, Integer operationAttempt, ResponseCode code) { + private PolicyResult onResponse(Response appcResponse, Integer operationAttempt, + ResponseCode code) { // // Ok, let's figure out what APP-C's response is // @@ -627,21 +599,21 @@ public class ControlLoopOperationManager implements Serializable { // We'll consider these two codes as exceptions // this.completeOperation(operationAttempt, appcResponse.getStatus().getDescription(), - PolicyResult.FAILURE_EXCEPTION); + PolicyResult.FAILURE_EXCEPTION); return getTimeoutResult(PolicyResult.FAILURE_EXCEPTION); case SUCCESS: // // // this.completeOperation(operationAttempt, appcResponse.getStatus().getDescription(), - PolicyResult.SUCCESS); + PolicyResult.SUCCESS); return getTimeoutResult(PolicyResult.SUCCESS); case FAILURE: // // // this.completeOperation(operationAttempt, appcResponse.getStatus().getDescription(), - PolicyResult.FAILURE); + PolicyResult.FAILURE); return getTimeoutResult(PolicyResult.FAILURE); default: return null; @@ -658,11 +630,12 @@ public class ControlLoopOperationManager implements Serializable { /* * Parse out the operation attempt using the subrequestid */ - Integer operationAttempt = AppcLcmActorServiceProvider - .parseOperationAttempt(dmaapResponse.getBody().getOutput().getCommonHeader().getSubRequestId()); + Integer operationAttempt = AppcLcmActorServiceProvider.parseOperationAttempt( + dmaapResponse.getBody().getOutput().getCommonHeader().getSubRequestId()); if (operationAttempt == null) { - this.completeOperation(operationAttempt, "Policy was unable to parse APP-C SubRequestID (it was null).", - PolicyResult.FAILURE_EXCEPTION); + this.completeOperation(operationAttempt, + "Policy was unable to parse APP-C SubRequestID (it was null).", + PolicyResult.FAILURE_EXCEPTION); return PolicyResult.FAILURE_EXCEPTION; } @@ -670,7 +643,7 @@ public class ControlLoopOperationManager implements Serializable { * Process the APPCLCM response to see what PolicyResult should be returned */ AbstractMap.SimpleEntry<PolicyResult, String> result = - AppcLcmActorServiceProvider.processResponse(dmaapResponse); + AppcLcmActorServiceProvider.processResponse(dmaapResponse); if (result.getKey() != null) { this.completeOperation(operationAttempt, result.getValue(), result.getKey()); @@ -693,10 +666,10 @@ public class ControlLoopOperationManager implements Serializable { * Parse out the operation attempt using the subrequestid */ Integer operationAttempt = SdnrActorServiceProvider - .parseOperationAttempt(dmaapResponse.getBody().getCommonHeader().getSubRequestId()); + .parseOperationAttempt(dmaapResponse.getBody().getCommonHeader().getSubRequestId()); if (operationAttempt == null) { - this.completeOperation(operationAttempt, "Policy was unable to parse SDNR SubRequestID.", - PolicyResult.FAILURE_EXCEPTION); + this.completeOperation(operationAttempt, + "Policy was unable to parse SDNR SubRequestID.", PolicyResult.FAILURE_EXCEPTION); return PolicyResult.FAILURE_EXCEPTION; } @@ -704,7 +677,7 @@ public class ControlLoopOperationManager implements Serializable { * Process the SDNR response to see what PolicyResult should be returned */ SdnrActorServiceProvider.Pair<PolicyResult, String> result = - SdnrActorServiceProvider.processResponse(dmaapResponse); + SdnrActorServiceProvider.processResponse(dmaapResponse); if (result.getResult() != null) { this.completeOperation(operationAttempt, result.getMessage(), result.getResult()); @@ -729,15 +702,17 @@ public class ControlLoopOperationManager implements Serializable { // // Consider it as success // - this.completeOperation(this.attempts, msoResponse.getSoResponse().getHttpResponseCode() + SUCCESS_MSG, - PolicyResult.SUCCESS); + this.completeOperation(this.attempts, + msoResponse.getSoResponse().getHttpResponseCode() + SUCCESS_MSG, + PolicyResult.SUCCESS); return getTimeoutResult(PolicyResult.SUCCESS); default: // // Consider it as failure // - this.completeOperation(this.attempts, msoResponse.getSoResponse().getHttpResponseCode() + FAILED_MSG, - PolicyResult.FAILURE); + this.completeOperation(this.attempts, + msoResponse.getSoResponse().getHttpResponseCode() + FAILED_MSG, + PolicyResult.FAILURE); return getTimeoutResult(PolicyResult.FAILURE); } } @@ -827,7 +802,6 @@ public class ControlLoopOperationManager implements Serializable { return (PolicyResult.FAILURE_TIMEOUT.equals(this.policyResult) ? null : result); } - private Integer getSubRequestId(Response appcResponse) { try { return Integer.valueOf(appcResponse.getCommonHeader().getSubRequestId()); @@ -902,7 +876,8 @@ public class ControlLoopOperationManager implements Serializable { } if (!this.operationHistory.isEmpty()) { - return this.operationHistory.getLast().clOperation.toMessage() + ", Guard result: " + guardResult; + return this.operationHistory.getLast().clOperation.toMessage() + ", Guard result: " + + guardResult; } return null; } @@ -954,7 +929,8 @@ public class ControlLoopOperationManager implements Serializable { // // // - this.completeOperation(this.attempts, "Operation denied by Guard", PolicyResult.FAILURE_GUARD); + this.completeOperation(this.attempts, "Operation denied by Guard", + PolicyResult.FAILURE_GUARD); } public void setOperationHasException(String message) { @@ -1032,7 +1008,8 @@ public class ControlLoopOperationManager implements Serializable { // // what do we do if we are already running an operation? // - throw new ControlLoopException("current operation is not null (an operation is already running)"); + throw new ControlLoopException( + "current operation is not null (an operation is already running)"); } // // Check if we have maxed out on retries @@ -1052,7 +1029,8 @@ public class ControlLoopOperationManager implements Serializable { // // // - throw new ControlLoopException("current operation failed and retries are not allowed"); + throw new ControlLoopException( + "current operation failed and retries are not allowed"); } } else { // @@ -1062,7 +1040,8 @@ public class ControlLoopOperationManager implements Serializable { if (this.policyResult == null) { this.policyResult = PolicyResult.FAILURE_RETRIES; } - throw new ControlLoopException("current oepration has failed after " + this.attempts + " retries"); + throw new ControlLoopException( + "current oepration has failed after " + this.attempts + " retries"); } } } @@ -1078,28 +1057,28 @@ public class ControlLoopOperationManager implements Serializable { private void storeOperationInDataBase() { // Only store in DB if enabled - boolean guardEnabled = "false" - .equalsIgnoreCase(PolicyEngineConstants.getManager().getEnvironmentProperty("guard.disabled")); + boolean guardEnabled = "false".equalsIgnoreCase( + PolicyEngineConstants.getManager().getEnvironmentProperty("guard.disabled")); if (!guardEnabled) { return; } - // DB Properties Properties props = new Properties(); if (PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_URL) != null - && PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_USER) != null - && PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_PASS) != null) { + && PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_USER) != null + && PolicyEngineConstants.getManager() + .getEnvironmentProperty(Util.ONAP_KEY_PASS) != null) { props.put(Util.ECLIPSE_LINK_KEY_URL, - PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_URL)); + PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_URL)); props.put(Util.ECLIPSE_LINK_KEY_USER, - PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_USER)); + PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_USER)); props.put(Util.ECLIPSE_LINK_KEY_PASS, - PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_PASS)); - props.put(PersistenceUnitProperties.CLASSLOADER, ControlLoopOperationManager.class.getClassLoader()); + PolicyEngineConstants.getManager().getEnvironmentProperty(Util.ONAP_KEY_PASS)); + props.put(PersistenceUnitProperties.CLASSLOADER, + ControlLoopOperationManager.class.getClassLoader()); } - String opsHistPu = System.getProperty("OperationsHistoryPU"); if (!"OperationsHistoryPUTest".equals(opsHistPu)) { opsHistPu = "OperationsHistoryPU"; @@ -1123,7 +1102,8 @@ public class ControlLoopOperationManager implements Serializable { newEntry.setTarget(this.targetEntity); newEntry.setStarttime(Timestamp.from(this.currentOperation.clOperation.getStart())); newEntry.setSubrequestId(this.currentOperation.clOperation.getSubRequestId()); - newEntry.setEndtime(new Timestamp(this.currentOperation.clOperation.getEnd().toEpochMilli())); + newEntry + .setEndtime(new Timestamp(this.currentOperation.clOperation.getEnd().toEpochMilli())); newEntry.setMessage(this.currentOperation.clOperation.getMessage()); newEntry.setOutcome(this.currentOperation.clOperation.getOutcome()); @@ -1174,7 +1154,6 @@ public class ControlLoopOperationManager implements Serializable { logger.debug("Could not find associated operation"); } - /** * Commit the abatement to the history database. * @@ -1213,12 +1192,14 @@ public class ControlLoopOperationManager implements Serializable { * * @return a ControlLoopResponse */ - public ControlLoopResponse getControlLoopResponse(Object response, VirtualControlLoopEvent event) { + public ControlLoopResponse getControlLoopResponse(Object response, + VirtualControlLoopEvent event) { if (response instanceof PciResponseWrapper) { // // Cast SDNR response and handle it // - return SdnrActorServiceProvider.getControlLoopResponse((PciResponseWrapper) response, event); + return SdnrActorServiceProvider.getControlLoopResponse((PciResponseWrapper) response, + event); } else { return null; } diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java index 5601d08a8..21b082c82 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java @@ -50,28 +50,15 @@ import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.onap.policy.aai.AaiCqResponse; -import org.onap.policy.aai.AaiGetVnfResponse; -import org.onap.policy.aai.AaiGetVserverResponse; -import org.onap.policy.aai.AaiNqRequestError; -import org.onap.policy.aai.AaiNqResponseWrapper; -import org.onap.policy.aai.AaiNqVServer; -import org.onap.policy.aai.RelatedToProperty; -import org.onap.policy.aai.Relationship; -import org.onap.policy.aai.RelationshipData; -import org.onap.policy.aai.RelationshipList; -import org.onap.policy.aai.util.AaiException; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.utils.io.Serializer; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopException; import org.onap.policy.controlloop.ControlLoopNotificationType; import org.onap.policy.controlloop.ControlLoopTargetType; -import org.onap.policy.controlloop.SupportUtil; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.VirtualControlLoopNotification; import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager.NewEventStatus; -import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.drools.core.lock.Lock; import org.onap.policy.drools.core.lock.LockCallback; @@ -81,34 +68,16 @@ import org.powermock.reflect.Whitebox; public class ControlLoopEventManagerTest { private static final String TARGET_LOCK_FIELD = "targetLock"; - private static final String PROCESS_VSERVER_RESPONSE = "processVServerResponse"; private static final String ONSET_ONE = "onsetOne"; private static final String VSERVER_NAME = "vserver.vserver-name"; private static final String TEST_YAML = "src/test/resources/test.yaml"; - private static final String SERVICE_TYPE = "service-subscription.service-type"; - private static final String SERVICE_INSTANCE_NAME = "service-instance.service-instance-name"; - private static final String SERVICE_INSTANCE_ID = "service-instance.service-instance-id"; - private static final String SERVICE_INSTANCE = "service-instance"; - private static final String VNF_NAME_TEXT = "lll_vnf_010317"; - private static final String SERVICE_INSTANCE_NAME_TEXT = "lll_svc_010317"; private static final String VNF_NAME = "generic-vnf.vnf-name"; private static final String VNF_ID = "generic-vnf.vnf-id"; - private static final String SERVICE_INSTANCE_UUID = "e1e9c97c-02c0-4919-9b4c-eb5d5ef68970"; - private static final String MSO_CUSTOMER_ID = "customer.global-customer-id"; private static final String AAI_USERNAME = "aai.username"; private static final String AAI_URL = "aai.url"; private static final String AAI_PASS = "aai.password"; private static final String TWO_ONSET_TEST = "TwoOnsetTest"; - private static final String MSO_1610_ST = "MSO_1610_ST"; - private static final String MSO_DEV_SERVICE_TYPE = "MSO-dev-service-type"; private static final String VNF_UUID = "83f674e8-7555-44d7-9a39-bdc3770b0491"; - private static final String AAI_SERVICE_SUBSCRIPTION_URI = - "/aai/v11/business/customers/customer/MSO_1610_ST/service-subscriptions/service-subscription"; - private static final String MSO_SERVICE_INSTANCE_URI = "/MSO-dev-service-type/service-instances/service-instance/"; - - private static final String PROCESS_VNF_RESPONSE_METHOD_NAME = "processVnfResponse"; - - private static final String INVALID_URL = "http://localhost:9999"; @Rule @@ -158,251 +127,6 @@ public class ControlLoopEventManagerTest { } @Test - public void testAaiVnfInfo() throws IOException { - final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml(TEST_YAML); - onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName()); - AaiGetVnfResponse response = getQueryByVnfId2(); - assertNotNull(response); - } - - @Test - public void testAaiVnfInfo2() throws IOException { - final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml(TEST_YAML); - onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName()); - AaiGetVnfResponse response = getQueryByVnfName2(); - assertNotNull(response); - } - - @Test - public void testAaiVserver() throws IOException { - final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml(TEST_YAML); - onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName()); - AaiGetVserverResponse response = getQueryByVserverName2(); - assertNotNull(response); - } - - @Test - public void abatementCheckEventSyntaxTest() throws ControlLoopException { - VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.setClosedLoopControlName("abatementAAI"); - event.setRequestId(UUID.randomUUID()); - event.setTarget(VNF_ID); - event.setClosedLoopAlarmStart(Instant.now()); - event.setClosedLoopEventStatus(ControlLoopEventStatus.ABATED); - ControlLoopEventManager manager = makeManager(event); - assertNull(manager.getVnfResponse()); - assertNull(manager.getVserverResponse()); - manager.checkEventSyntax(event); - assertNull(manager.getVnfResponse()); - assertNull(manager.getVserverResponse()); - - - event.setAai(new HashMap<>()); - event.getAai().put(VNF_NAME, "abatementTest"); - manager.checkEventSyntax(event); - assertNull(manager.getVnfResponse()); - assertNull(manager.getVserverResponse()); - } - - @Test - public void subsequentOnsetTest() throws Exception { - UUID requestId = UUID.randomUUID(); - VirtualControlLoopEvent event = new VirtualControlLoopEvent(); - event.setClosedLoopControlName(TWO_ONSET_TEST); - event.setRequestId(requestId); - event.setTarget(VNF_ID); - event.setClosedLoopAlarmStart(Instant.now()); - event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); - event.setAai(new HashMap<>()); - event.getAai().put(VNF_NAME, ONSET_ONE); - event.setTargetType(ControlLoopTargetType.VNF); - - ControlLoopEventManager manager = makeManager(event); - VirtualControlLoopNotification notification = manager.activate(event); - - assertNotNull(notification); - assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); - - ControlLoopEventManager.NewEventStatus status = null; - status = manager.onNewEvent(event); - assertNotNull(status); - assertEquals(ControlLoopEventManager.NewEventStatus.FIRST_ONSET, status); - - AaiGetVnfResponse response = manager.getVnfResponse(); - assertNotNull(response); - assertNull(manager.getVserverResponse()); - - VirtualControlLoopEvent event2 = new VirtualControlLoopEvent(); - event2.setClosedLoopControlName(TWO_ONSET_TEST); - event2.setRequestId(requestId); - event2.setTarget(VNF_ID); - event2.setClosedLoopAlarmStart(Instant.now()); - event2.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); - event2.setAai(new HashMap<>()); - event2.getAai().put(VNF_NAME, "onsetTwo"); - event2.setTargetType(ControlLoopTargetType.VNF); - - - status = manager.onNewEvent(event2); - assertEquals(ControlLoopEventManager.NewEventStatus.SUBSEQUENT_ONSET, status); - AaiGetVnfResponse response2 = manager.getVnfResponse(); - assertNotNull(response2); - // We should not have queried AAI, so the stored response should be the same - assertEquals(response, response2); - assertNull(manager.getVserverResponse()); - } - - /** - * Simulate a response. - */ - public static AaiGetVnfResponse getQueryByVnfId2() { - AaiGetVnfResponse response = new AaiGetVnfResponse(); - - response.setVnfId(VNF_UUID); - response.setVnfName(VNF_NAME_TEXT); - response.setVnfType("Basa-122216-Service/VidVsamp12BaseVolume 1"); - response.setServiceId("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"); - response.setOrchestrationStatus("Created"); - response.setInMaint(false); - response.setClosedLoopDisabled(false); - response.setResourceVersion("1494001988835"); - response.setModelInvariantId("f18be3cd-d446-456e-9109-121d9b62feaa"); - - final RelationshipList relationshipList = new RelationshipList(); - final Relationship relationship = new Relationship(); - RelationshipData relationshipDataItem = new RelationshipData(); - - relationshipDataItem.setRelationshipKey(MSO_CUSTOMER_ID); - relationshipDataItem.setRelationshipValue(MSO_1610_ST); - relationship.getRelationshipData().add(relationshipDataItem); - - relationshipDataItem.setRelationshipKey(SERVICE_TYPE); - relationshipDataItem.setRelationshipValue(MSO_DEV_SERVICE_TYPE); - relationship.getRelationshipData().add(relationshipDataItem); - - relationshipDataItem.setRelationshipKey(SERVICE_INSTANCE_ID); - relationshipDataItem.setRelationshipValue(SERVICE_INSTANCE_UUID); - relationship.getRelationshipData().add(relationshipDataItem); - - RelatedToProperty item = new RelatedToProperty(); - item.setPropertyKey(SERVICE_INSTANCE_NAME); - item.setPropertyValue(SERVICE_INSTANCE_NAME_TEXT); - relationship.getRelatedToProperty().add(item); - - relationship.setRelatedTo(SERVICE_INSTANCE); - relationship.setRelatedLink( - AAI_SERVICE_SUBSCRIPTION_URI - + MSO_SERVICE_INSTANCE_URI - + SERVICE_INSTANCE_UUID); - - relationshipList.getRelationships().add(relationship); - response.setRelationshipList(relationshipList); - - return response; - } - - /** - * Simulate a response. - */ - public static AaiGetVnfResponse getQueryByVnfName2() { - AaiGetVnfResponse response = new AaiGetVnfResponse(); - - response.setVnfId(VNF_UUID); - response.setVnfName(VNF_NAME_TEXT); - response.setVnfType("Basa-122216-Service/VidVsamp12BaseVolume 1"); - response.setServiceId("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"); - response.setOrchestrationStatus("Created"); - response.setInMaint(false); - response.setClosedLoopDisabled(false); - response.setResourceVersion("1494001988835"); - response.setModelInvariantId("f18be3cd-d446-456e-9109-121d9b62feaa"); - - final RelationshipList relationshipList = new RelationshipList(); - final Relationship relationship = new Relationship(); - RelationshipData relationshipDataItem = new RelationshipData(); - - relationshipDataItem.setRelationshipKey(MSO_CUSTOMER_ID); - relationshipDataItem.setRelationshipValue(MSO_1610_ST); - relationship.getRelationshipData().add(relationshipDataItem); - - relationshipDataItem.setRelationshipKey(SERVICE_TYPE); - relationshipDataItem.setRelationshipValue(MSO_DEV_SERVICE_TYPE); - relationship.getRelationshipData().add(relationshipDataItem); - - relationshipDataItem.setRelationshipKey(SERVICE_INSTANCE_ID); - relationshipDataItem.setRelationshipValue(SERVICE_INSTANCE_UUID); - relationship.getRelationshipData().add(relationshipDataItem); - - RelatedToProperty item = new RelatedToProperty(); - item.setPropertyKey(SERVICE_INSTANCE_NAME); - item.setPropertyValue(SERVICE_INSTANCE_NAME_TEXT); - relationship.getRelatedToProperty().add(item); - - relationship.setRelatedTo(SERVICE_INSTANCE); - relationship.setRelatedLink( - AAI_SERVICE_SUBSCRIPTION_URI - + MSO_SERVICE_INSTANCE_URI - + SERVICE_INSTANCE_UUID); - - relationshipList.getRelationships().add(relationship); - response.setRelationshipList(relationshipList); - - return response; - } - - /** - * Simulate a response. - */ - public static AaiGetVserverResponse getQueryByVserverName2() { - final AaiGetVserverResponse response = new AaiGetVserverResponse(); - - AaiNqVServer svr = new AaiNqVServer(); - - svr.setVserverId("d0668d4f-c25e-4a1b-87c4-83845c01efd8"); - svr.setVserverName("USMSO1SX7NJ0103UJZZ01-vjunos0"); - svr.setVserverName2("vjunos0"); - svr.setVserverSelflink( - "https://aai-ext1.test.att.com:8443/aai/v7/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/USMSO1SX7NJ0103UJZZ01%3A%3AuCPE-VMS/vservers/vserver/d0668d4f-c25e-4a1b-87c4-83845c01efd8"); - svr.setInMaint(false); - svr.setIsClosedLoopDisabled(false); - svr.setResourceVersion("1494001931513"); - - final RelationshipList relationshipList = new RelationshipList(); - final Relationship relationship = new Relationship(); - RelationshipData relationshipDataItem = new RelationshipData(); - - relationshipDataItem.setRelationshipKey(MSO_CUSTOMER_ID); - relationshipDataItem.setRelationshipValue(MSO_1610_ST); - relationship.getRelationshipData().add(relationshipDataItem); - - relationshipDataItem.setRelationshipKey(SERVICE_TYPE); - relationshipDataItem.setRelationshipValue(MSO_DEV_SERVICE_TYPE); - relationship.getRelationshipData().add(relationshipDataItem); - - relationshipDataItem.setRelationshipKey(SERVICE_INSTANCE_ID); - relationshipDataItem.setRelationshipValue(SERVICE_INSTANCE_UUID); - relationship.getRelationshipData().add(relationshipDataItem); - - RelatedToProperty item = new RelatedToProperty(); - item.setPropertyKey(SERVICE_INSTANCE_NAME); - item.setPropertyValue(SERVICE_INSTANCE_NAME_TEXT); - relationship.getRelatedToProperty().add(item); - - relationship.setRelatedTo(SERVICE_INSTANCE); - relationship.setRelatedLink( - AAI_SERVICE_SUBSCRIPTION_URI - + MSO_SERVICE_INSTANCE_URI - + SERVICE_INSTANCE_UUID); - - relationshipList.getRelationships().add(relationship); - svr.setRelationshipList(relationshipList); - - response.getVserver().add(svr); - - return response; - } - - @Test public void testMethods() { UUID requestId = UUID.randomUUID(); ControlLoopEventManager clem = new ControlLoopEventManager("MyClosedLoopName", requestId); @@ -580,7 +304,7 @@ public class ControlLoopEventManagerTest { event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); event.setAai(new HashMap<>()); event.getAai().put(VNF_NAME, ONSET_ONE); - event.getAai().put(VSERVER_NAME, "test-vserver"); + event.getAai().put(VSERVER_NAME, "testVserverName"); event.setTargetType(ControlLoopTargetType.VNF); ControlLoopEventManager manager = makeManager(event); @@ -664,6 +388,8 @@ public class ControlLoopEventManagerTest { VirtualControlLoopNotification notification = manager.activate(yamlString, event); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); + + event.getAai().put(VSERVER_NAME, "testVserverName"); // serialize and de-serialize manager manager = Serializer.roundTrip(manager); @@ -709,6 +435,8 @@ public class ControlLoopEventManagerTest { .hasMessage("Do not have a current operation."); assertNull(manager.unlockCurrentOperation()); + + event.getAai().put(VSERVER_NAME, "testVserverName"); ControlLoopOperationManager clom = manager.processControlLoop(); assertNotNull(clom); @@ -983,249 +711,6 @@ public class ControlLoopEventManagerTest { } @Test - public void testQueryAai_AlreadyDisabled() throws AaiException { - onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, Boolean.TRUE.toString()); - onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, ControlLoopEventManager.PROV_STATUS_ACTIVE); - - ControlLoopEventManager mgr = makeManager(onset); - - assertThatThrownBy(() -> mgr.queryAai(onset)).isInstanceOf(AaiException.class).hasMessage( - "is-closed-loop-disabled is set to true on VServer or VNF or in-maint is set to true for PNF"); - assertNull(mgr.getVnfResponse()); - assertNull(mgr.getVserverResponse()); - } - - @Test - public void testQueryAai_AlreadyInactive() throws AaiException { - onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, Boolean.FALSE.toString()); - onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, "not-active2"); - - ControlLoopEventManager mgr = makeManager(onset); - - assertThatThrownBy(() -> mgr.queryAai(onset)).isInstanceOf(AaiException.class) - .hasMessage("prov-status is not ACTIVE on VServer or VNF or PNF"); - assertNull(mgr.getVnfResponse()); - assertNull(mgr.getVserverResponse()); - } - - @Test - public void testQueryAai_QueryVnfById() throws AaiException { - ControlLoopEventManager mgr = null; - - mgr = makeManager(onset); - mgr.queryAai(onset); - - assertNotNull(mgr.getVnfResponse()); - assertNull(mgr.getVserverResponse()); - - AaiGetVnfResponse vnfresp = mgr.getVnfResponse(); - - // should not re-query - mgr.queryAai(onset); - - assertEquals(vnfresp, mgr.getVnfResponse()); - assertNull(mgr.getVserverResponse()); - } - - @Test - public void testQueryAai_QueryVnfByName() throws AaiException { - ControlLoopEventManager mgr = null; - - // vnf query by name - onset.getAai().remove(ControlLoopEventManager.GENERIC_VNF_VNF_ID); - onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_VNF_NAME, "AVNFName"); - - mgr = makeManager(onset); - mgr.queryAai(onset); - - assertNotNull(mgr.getVnfResponse()); - assertNull(mgr.getVserverResponse()); - - AaiGetVnfResponse vnfresp = mgr.getVnfResponse(); - - // should not re-query - mgr.queryAai(onset); - - assertEquals(vnfresp, mgr.getVnfResponse()); - assertNull(mgr.getVserverResponse()); - } - - @Test - public void testQueryAai_QueryVnfById_Disabled() { - onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_VNF_ID, "disableClosedLoop"); - - ControlLoopEventManager mgr = makeManager(onset); - - assertThatThrownBy(() -> mgr.queryAai(onset)).isInstanceOf(AaiException.class) - .hasMessage("is-closed-loop-disabled is set to true (query by vnf-id)"); - - assertNotNull(mgr.getVnfResponse()); - assertNull(mgr.getVserverResponse()); - } - - @Test - public void testQueryAai_QueryVserver() throws AaiException { - onset.getAai().remove(ControlLoopEventManager.GENERIC_VNF_VNF_ID); - onset.getAai().put(ControlLoopEventManager.VSERVER_VSERVER_NAME, "AVserver"); - - ControlLoopEventManager mgr = makeManager(onset); - mgr.queryAai(onset); - - assertNull(mgr.getVnfResponse()); - assertNotNull(mgr.getVserverResponse()); - - AaiGetVserverResponse vsvresp = mgr.getVserverResponse(); - - // should not re-query - mgr.queryAai(onset); - - assertNull(mgr.getVnfResponse()); - assertEquals(vsvresp, mgr.getVserverResponse()); - } - - @Test - public void testQueryAai_QueryVserver_Disabled() { - onset.getAai().remove(ControlLoopEventManager.GENERIC_VNF_VNF_ID); - onset.getAai().put(ControlLoopEventManager.VSERVER_VSERVER_NAME, "disableClosedLoop"); - - ControlLoopEventManager mgr = makeManager(onset); - - assertThatThrownBy(() -> mgr.queryAai(onset)).isInstanceOf(AaiException.class) - .hasMessage("is-closed-loop-disabled is set to true (query by vserver-name)"); - - assertNull(mgr.getVnfResponse()); - assertNotNull(mgr.getVserverResponse()); - } - - @Test(expected = AaiException.class) - public void testQueryAai_QueryException() throws AaiException { - // Force AAI errors - PolicyEngineConstants.getManager().setEnvironmentProperty(AAI_URL, INVALID_URL); - - makeManager(onset).queryAai(onset); - } - - @Test - public void testProcessVnfResponse_Success() throws Exception { - AaiGetVnfResponse resp = new AaiGetVnfResponse(); - resp.setClosedLoopDisabled(false); - resp.setProvStatus(ControlLoopEventManager.PROV_STATUS_ACTIVE); - Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VNF_RESPONSE_METHOD_NAME, resp, true); - } - - @Test - public void testProcessVnfResponse_NullResponse() throws Exception { - thrown.expect(AaiException.class); - thrown.expectMessage("AAI Response is null (query by vnf-id)"); - - AaiGetVnfResponse resp = null; - Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VNF_RESPONSE_METHOD_NAME, resp, true); - } - - @Test - public void testProcessVnfResponse_Error() throws Exception { - thrown.expect(AaiException.class); - thrown.expectMessage("AAI Responded with a request error (query by vnf-name)"); - - AaiGetVnfResponse resp = new AaiGetVnfResponse(); - - resp.setRequestError(new AaiNqRequestError()); - - resp.setClosedLoopDisabled(false); - resp.setProvStatus(ControlLoopEventManager.PROV_STATUS_ACTIVE); - Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VNF_RESPONSE_METHOD_NAME, resp, false); - } - - @Test - public void testProcessVnfResponse_Disabled() throws Exception { - thrown.expect(AaiException.class); - thrown.expectMessage("is-closed-loop-disabled is set to true (query by vnf-id)"); - - AaiGetVnfResponse resp = new AaiGetVnfResponse(); - resp.setClosedLoopDisabled(true); - resp.setProvStatus(ControlLoopEventManager.PROV_STATUS_ACTIVE); - Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VNF_RESPONSE_METHOD_NAME, resp, true); - } - - @Test - public void testProcessVnfResponse_Inactive() throws Exception { - thrown.expect(AaiException.class); - thrown.expectMessage("prov-status is not ACTIVE (query by vnf-name)"); - - AaiGetVnfResponse resp = new AaiGetVnfResponse(); - resp.setClosedLoopDisabled(false); - resp.setProvStatus("inactive1"); - Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VNF_RESPONSE_METHOD_NAME, resp, false); - } - - @Test - public void testProcessVserverResponse_Success() throws Exception { - AaiGetVserverResponse resp = new AaiGetVserverResponse(); - - AaiNqVServer svr = new AaiNqVServer(); - resp.getVserver().add(svr); - - svr.setIsClosedLoopDisabled(false); - svr.setProvStatus(ControlLoopEventManager.PROV_STATUS_ACTIVE); - Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VSERVER_RESPONSE, resp); - } - - @Test - public void testProcessVserverResponse_NullResponse() throws Exception { - thrown.expect(AaiException.class); - thrown.expectMessage("AAI Response is null (query by vserver-name)"); - - AaiGetVserverResponse resp = null; - Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VSERVER_RESPONSE, resp); - } - - @Test - public void testProcessVserverResponse_Error() throws Exception { - thrown.expect(AaiException.class); - thrown.expectMessage("AAI Responded with a request error (query by vserver-name)"); - - AaiGetVserverResponse resp = new AaiGetVserverResponse(); - - resp.setRequestError(new AaiNqRequestError()); - - AaiNqVServer svr = new AaiNqVServer(); - resp.getVserver().add(svr); - - svr.setIsClosedLoopDisabled(false); - svr.setProvStatus(ControlLoopEventManager.PROV_STATUS_ACTIVE); - - Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VSERVER_RESPONSE, resp); - } - - @Test - public void testProcessVserverResponse_Disabled() throws Exception { - thrown.expect(AaiException.class); - thrown.expectMessage("is-closed-loop-disabled is set to true (query by vserver-name)"); - - AaiGetVserverResponse resp = new AaiGetVserverResponse(); - AaiNqVServer svr = new AaiNqVServer(); - resp.getVserver().add(svr); - - svr.setIsClosedLoopDisabled(true); - svr.setProvStatus(ControlLoopEventManager.PROV_STATUS_ACTIVE); - Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VSERVER_RESPONSE, resp); - } - - @Test - public void testProcessVserverResponse_Inactive() throws Exception { - thrown.expect(AaiException.class); - thrown.expectMessage("prov-status is not ACTIVE (query by vserver-name)"); - - AaiGetVserverResponse resp = new AaiGetVserverResponse(); - AaiNqVServer svr = new AaiNqVServer(); - resp.getVserver().add(svr); - - svr.setIsClosedLoopDisabled(false); - svr.setProvStatus("inactive1"); - Whitebox.invokeMethod(ControlLoopEventManager.class, PROCESS_VSERVER_RESPONSE, resp); - } - - @Test public void testIsClosedLoopDisabled() { Map<String, String> aai = onset.getAai(); @@ -1298,57 +783,6 @@ public class ControlLoopEventManagerTest { assertFalse(ControlLoopEventManager.isAaiTrue(null)); } - @Test - public void testGetNqVserverFromAai() { - - // empty vserver name - ControlLoopEventManager manager = makeManager(onset); - manager.activate(onset); - assertNull(manager.getNqVserverFromAai()); - - - // re-create manager with a vserver name in the onset - onset.getAai().put(ControlLoopEventManager.VSERVER_VSERVER_NAME, "my-name"); - manager = makeManager(onset); - manager.activate(onset); - - AaiNqResponseWrapper resp = manager.getNqVserverFromAai(); - assertNotNull(resp); - assertEquals(onset.getRequestId(), resp.getRequestId()); - assertNotNull(resp.getAaiNqResponse()); - assertFalse(resp.getAaiNqResponse().getInventoryResponseItems().isEmpty()); - - // re-query should return the same object - assertTrue(resp == manager.getNqVserverFromAai()); - - - // Force AAI error - PolicyEngineConstants.getManager().setEnvironmentProperty(AAI_URL, INVALID_URL); - - // re-create manager - manager = makeManager(onset); - manager.activate(onset); - assertNull(manager.getNqVserverFromAai()); - } - - @Test - public void testGetCqResponseEmptyVserver() throws AaiException { - ControlLoopEventManager mgr = makeManager(onset); - mgr.queryAai(onset); - - assertThatThrownBy(() -> mgr.getCqResponse(onset)).isInstanceOf(AaiException.class) - .hasMessage("Vserver name is missing"); - } - - @Test - public void testGetCqResponse() throws AaiException { - ControlLoopEventManager mgr = makeManager(onset); - mgr.queryAai(onset); - onset.getAai().put(VSERVER_NAME, "sample"); - - AaiCqResponse aaiCqResponse = mgr.getCqResponse(onset); - assertNotNull(aaiCqResponse); - } private VirtualControlLoopEvent makeEvent() { UUID requestId = UUID.randomUUID(); diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java index 2a44f6e87..4cb365a76 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java @@ -94,9 +94,8 @@ public class ControlLoopOperationManagerTest { private static final String APPC_FAILURE_REASON = "AppC failed for some reason"; private static final String ACCEPT = "ACCEPT"; - - private static final Logger logger = LoggerFactory.getLogger(ControlLoopOperationManagerTest.class); - + private static final Logger logger = + LoggerFactory.getLogger(ControlLoopOperationManagerTest.class); private static VirtualControlLoopEvent onset; @@ -113,7 +112,8 @@ public class ControlLoopOperationManagerTest { onset.setTargetType(ControlLoopTargetType.VNF); /* Set environment properties */ - PolicyEngineConstants.getManager().setEnvironmentProperty("aai.url", "http://localhost:6666"); + PolicyEngineConstants.getManager().setEnvironmentProperty("aai.url", + "http://localhost:6666"); PolicyEngineConstants.getManager().setEnvironmentProperty("aai.username", "AAI"); PolicyEngineConstants.getManager().setEnvironmentProperty("aai.password", "AAI"); PolicyEngineConstants.getManager().setEnvironmentProperty("aai.customQuery", "false"); @@ -122,7 +122,6 @@ public class ControlLoopOperationManagerTest { private static EntityManagerFactory emf; private static EntityManager em; - private static int getCount() { // Create a query for number of items in DB String sql = "select count(*) as count from operationshistory"; @@ -131,7 +130,6 @@ public class ControlLoopOperationManagerTest { return ((Number) nq.getSingleResult()).intValue(); } - /** * Set up test class. */ @@ -144,16 +142,18 @@ public class ControlLoopOperationManagerTest { System.setProperty(OPERATIONS_HISTORY_PU, OPERATIONS_HISTORY_PU_TEST); // Enter dummy props to avoid nullPointerException - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL, "a"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, "b"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "c"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL, "a"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, "b"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "c"); // Connect to in-mem db emf = Persistence.createEntityManagerFactory(OPERATIONS_HISTORY_PU_TEST); em = emf.createEntityManager(); } - /** * Clean up test class. */ @@ -171,6 +171,7 @@ public class ControlLoopOperationManagerTest { // final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml(TEST_YAML); onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName()); + onset.getAai().put(VSERVER_NAME, "testVserverName"); // // Create a processor @@ -180,7 +181,7 @@ public class ControlLoopOperationManagerTest { // create the manager // ControlLoopEventManager eventManager = - new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId()); + new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId()); VirtualControlLoopNotification notification = eventManager.activate(onset); assertNotNull(notification); @@ -191,7 +192,7 @@ public class ControlLoopOperationManagerTest { assertEquals(ControlLoopEventManager.NewEventStatus.FIRST_ONSET, status); ControlLoopOperationManager manager = - new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager); + new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager); logger.debug("{}", manager); // // @@ -298,6 +299,7 @@ public class ControlLoopOperationManagerTest { // final SupportUtil.Pair<ControlLoopPolicy, String> pair = SupportUtil.loadYaml(TEST_YAML); onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName()); + onset.getAai().put(VSERVER_NAME, "OzVServer"); // // Create a processor @@ -307,7 +309,7 @@ public class ControlLoopOperationManagerTest { // create the manager // ControlLoopEventManager eventManager = - new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId()); + new ControlLoopEventManager(onset.getClosedLoopControlName(), onset.getRequestId()); VirtualControlLoopNotification notification = eventManager.activate(onset); assertNotNull(notification); @@ -318,7 +320,7 @@ public class ControlLoopOperationManagerTest { assertEquals(ControlLoopEventManager.NewEventStatus.FIRST_ONSET, status); ControlLoopOperationManager manager = - new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager); + new ControlLoopOperationManager(onset, processor.getCurrentPolicy(), eventManager); // // // @@ -400,8 +402,8 @@ public class ControlLoopOperationManagerTest { onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); @@ -434,7 +436,7 @@ public class ControlLoopOperationManagerTest { policy.getTarget().setType(TargetType.PNF); assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage( - "Target in the onset event is either null or does not match target key expected in AAI section."); + "Target in the onset event is either null or does not match target key expected in AAI section."); onsetEvent.setTarget("Oz"); onsetEvent.getAai().remove(VNF_NAME); @@ -442,7 +444,8 @@ public class ControlLoopOperationManagerTest { onsetEvent.getAai().remove(VSERVER_NAME); policy.getTarget().setType(TargetType.VNF); - assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage("Target does not match target type"); + assertThatThrownBy(() -> clom.getTarget(policy)) + .hasMessage("Target does not match target type"); onsetEvent.setTarget(VSERVER_NAME); onsetEvent.getAai().put(VSERVER_NAME, "OzVServer"); @@ -458,16 +461,9 @@ public class ControlLoopOperationManagerTest { manager.onNewEvent(onsetEvent); - onsetEvent.getAai().remove(VNF_ID); - manager.getVnfResponse(); - if (!Boolean.valueOf(PolicyEngineConstants.getManager().getEnvironmentProperty("aai.customQuery"))) { - clom.getEventManager().getVnfResponse().setVnfId(VNF_ID); - assertEquals(VNF_ID, clom.getTarget(policy)); - } - - policy.getTarget().setType(TargetType.VFC); - assertThatThrownBy(() -> clom.getTarget(policy)).hasMessage("The target type is not supported"); + assertThatThrownBy(() -> clom.getTarget(policy)) + .hasMessage("The target type is not supported"); assertEquals(Integer.valueOf(20), clom.getOperationTimeout()); @@ -478,12 +474,13 @@ public class ControlLoopOperationManagerTest { clom.startOperation(onsetEvent); - assertEquals("actor=SO,operation=Restart,target=Target [type=VFC, resourceId=null],subRequestId=1", - clom.getOperationMessage()); assertEquals( - "actor=SO,operation=Restart,target=Target [type=VFC, resourceId=null],subRequestId=1, Guard result: " - + OPER_MSG, - clom.getOperationMessage(OPER_MSG)); + "actor=SO,operation=Restart,target=Target [type=VFC, resourceId=null],subRequestId=1", + clom.getOperationMessage()); + assertEquals( + "actor=SO,operation=Restart,target=Target [type=VFC, resourceId=null],subRequestId=1, Guard result: " + + OPER_MSG, + clom.getOperationMessage(OPER_MSG)); assertEquals("actor=SO,operation=Restart,tar", clom.getOperationHistory().substring(0, 30)); @@ -506,28 +503,30 @@ public class ControlLoopOperationManagerTest { onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); onsetEvent.setAai(new HashMap<>()); onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); - onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); + onsetEvent.getAai().put(VSERVER_NAME, "OzVServer"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = manager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager); + ControlLoopOperationManager clom = + new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); policy.setRecipe("ModifyConfig"); + onsetEvent.getAai().put(VSERVER_NAME, "NonExistentVserver"); policy.getTarget().setResourceID(UUID.randomUUID().toString()); assertThatThrownBy(() -> new ControlLoopOperationManager(onsetEvent, policy, manager)) - .hasMessage("Target vnf-id could not be found"); + .hasMessage("Target vnf-id could not be found"); - policy.getTarget().setResourceID("82194af1-3c2c-485a-8f44-420e22a9eaa4"); + onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); + policy.getTarget().setResourceID("bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38"); clom = new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); - policy.setActor("SO"); clom = new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); @@ -538,7 +537,7 @@ public class ControlLoopOperationManagerTest { policy.setActor(DOROTHY); assertThatThrownBy(() -> new ControlLoopOperationManager(onsetEvent, policy, manager)) - .hasMessage("ControlLoopEventManager: policy has an unknown actor."); + .hasMessage("ControlLoopEventManager: policy has an unknown actor."); } @Test @@ -558,20 +557,21 @@ public class ControlLoopOperationManagerTest { onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = manager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager); + ControlLoopOperationManager clom = + new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); clom.startOperation(onsetEvent); ControlLoopOperationManager clom2 = clom; assertThatThrownBy(() -> clom2.startOperation(onsetEvent)) - .hasMessage("current operation is not null (an operation is already running)"); + .hasMessage("current operation is not null (an operation is already running)"); clom = new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); @@ -589,7 +589,7 @@ public class ControlLoopOperationManagerTest { assertTrue(clom.isOperationComplete()); ControlLoopOperationManager clom3 = clom; assertThatThrownBy(() -> clom3.startOperation(onsetEvent)) - .hasMessage("current operation failed and retries are not allowed"); + .hasMessage("current operation failed and retries are not allowed"); policy.setRetry(0); clom = new ControlLoopOperationManager(onsetEvent, policy, manager); @@ -599,7 +599,7 @@ public class ControlLoopOperationManagerTest { assertTrue(clom.isOperationComplete()); ControlLoopOperationManager clom4 = clom; assertThatThrownBy(() -> clom4.startOperation(onsetEvent)) - .hasMessage("current operation failed and retries are not allowed"); + .hasMessage("current operation failed and retries are not allowed"); policy.setRetry(1); clom = new ControlLoopOperationManager(onsetEvent, policy, manager); @@ -611,7 +611,7 @@ public class ControlLoopOperationManagerTest { assertTrue(clom.isOperationComplete()); ControlLoopOperationManager clom5 = clom; assertThatThrownBy(() -> clom5.startOperation(onsetEvent)) - .hasMessage("current oepration has failed after 2 retries"); + .hasMessage("current oepration has failed after 2 retries"); clom = new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); @@ -628,7 +628,7 @@ public class ControlLoopOperationManagerTest { policy.setActor("Oz"); ControlLoopOperationManager clom6 = clom; assertThatThrownBy(() -> clom6.startOperation(onsetEvent)) - .hasMessage("invalid actor Oz on policy"); + .hasMessage("invalid actor Oz on policy"); } @Test @@ -648,14 +648,15 @@ public class ControlLoopOperationManagerTest { onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = manager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager); + ControlLoopOperationManager clom = + new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); assertNull(clom.onResponse(null)); @@ -745,14 +746,15 @@ public class ControlLoopOperationManagerTest { onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = manager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager); + ControlLoopOperationManager clom = + new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); clom.startOperation(onsetEvent); @@ -761,10 +763,12 @@ public class ControlLoopOperationManagerTest { final SoResponseWrapper soRw = new SoResponseWrapper(soResponse, null); PolicyEngineConstants.getManager().setEnvironmentProperty("guard.disabled", "false"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL, - "http://somewhere.over.the.rainbow"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto"); + PolicyEngineConstants.getManager().setEnvironmentProperty( + org.onap.policy.guard.Util.ONAP_KEY_URL, "http://somewhere.over.the.rainbow"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto"); assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw)); @@ -794,13 +798,14 @@ public class ControlLoopOperationManagerTest { event.getAai().put(VSERVER_NAME, "OzVServer"); ControlLoopEventManager eventManager = - new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId()); + new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId()); VirtualControlLoopNotification notification = eventManager.activate(yamlString, event); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = eventManager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager operationManager = new ControlLoopOperationManager(event, policy, eventManager); + ControlLoopOperationManager operationManager = + new ControlLoopOperationManager(event, policy, eventManager); // Run Object result = operationManager.startOperation(event); @@ -833,14 +838,15 @@ public class ControlLoopOperationManagerTest { onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = manager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager); + ControlLoopOperationManager clom = + new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); clom.startOperation(onsetEvent); @@ -874,14 +880,15 @@ public class ControlLoopOperationManagerTest { onsetEvent.getAai().put(VNF_NAME, ONSET_ONE); onsetEvent.getAai().put(VSERVER_NAME, "testVserverName"); - ControlLoopEventManager manager = - new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager( + onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId()); VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent); assertNotNull(notification); assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); Policy policy = manager.getProcessor().getCurrentPolicy(); - ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager); + ControlLoopOperationManager clom = + new ControlLoopOperationManager(onsetEvent, policy, manager); assertNotNull(clom); clom.startOperation(onsetEvent); @@ -895,10 +902,12 @@ public class ControlLoopOperationManagerTest { final SoResponseWrapper soRw = new SoResponseWrapper(soResponse, null); PolicyEngineConstants.getManager().setEnvironmentProperty("guard.disabled", "false"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL, - "http://somewhere.over.the.rainbow"); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY); - PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto"); + PolicyEngineConstants.getManager().setEnvironmentProperty( + org.onap.policy.guard.Util.ONAP_KEY_URL, "http://somewhere.over.the.rainbow"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, DOROTHY); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto"); assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw)); assertFalse(clom.isOperationRunning()); diff --git a/controlloop/common/feature-controlloop-management/src/main/feature/config/controlloop.properties.environment b/controlloop/common/feature-controlloop-management/src/main/feature/config/controlloop.properties.environment index 4a0916895..f76e5f45c 100644 --- a/controlloop/common/feature-controlloop-management/src/main/feature/config/controlloop.properties.environment +++ b/controlloop/common/feature-controlloop-management/src/main/feature/config/controlloop.properties.environment @@ -51,8 +51,6 @@ sdnc.url=${env:SDNC_URL} sdnc.username=${env:SDNC_USERNAME} sdnc.password=${env:SDNC_PASSWORD} -aai.customQuery=true - cds.grpcHost=${env:CDS_GRPC_HOST} cds.grpcPort=${env:CDS_GRPC_PORT} cds.grpcUsername=${env:CDS_GRPC_USERNAME} diff --git a/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java b/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java index 08b218dd6..563cac049 100644 --- a/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java +++ b/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java @@ -252,28 +252,4 @@ public class RestControlLoopManager { .build(); } - /** - * AAI Named Query. - * - * @param vserverId vServer identifier. - * @return query results. - */ - @GET - @Path("engine/tools/controlloops/aai/namedQuery/{vserverId}") - @ApiOperation(value = "AAI Custom Query") - public Response aaiNamedQuery(@ApiParam(value = "vserver Identifier") String vserverId) { - return Response - .status(Status.OK) - .entity(new AaiManager(new RestManager()) - .postQuery( - PolicyEngineConstants.getManager() - .getEnvironmentProperty(ControlLoopEventManager.AAI_URL), - PolicyEngineConstants.getManager().getEnvironmentProperty( - ControlLoopEventManager.AAI_USERNAME_PROPERTY), - PolicyEngineConstants.getManager().getEnvironmentProperty( - ControlLoopEventManager.AAI_PASS_PROPERTY), - ControlLoopEventManager.getAaiNqRequest(vserverId), - UUID.randomUUID())) - .build(); - } } diff --git a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java index 833adfb69..c2a9e536f 100644 --- a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java +++ b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java @@ -8,7 +8,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,6 @@ package org.onap.policy.drools.server.restful; import static org.awaitility.Awaitility.await; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.nio.file.Files; @@ -39,11 +38,8 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.kie.api.builder.ReleaseId; -import org.onap.policy.aai.AaiCqResponse; -import org.onap.policy.aai.AaiNqResponseWrapper; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager; import org.onap.policy.drools.persistence.SystemPersistenceConstants; @@ -63,25 +59,31 @@ public class RestControlLoopManagerTest { private static final String KMODULE_DRL_PATH = "src/test/resources/op.drl"; private static final String KMODULE_POM_PATH = "src/test/resources/op.pom"; private static final String KMODULE_PATH = "src/test/resources/op.kmodule"; - private static final String KJAR_DRL_PATH = "src/main/resources/kbop/org/onap/policy/drools/test/op.drl"; + private static final String KJAR_DRL_PATH = + "src/main/resources/kbop/org/onap/policy/drools/test/op.drl"; private static final String CONTROLLER = KSESSION; - private static final String CONTROLOOP_NAME = "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e"; + private static final String CONTROLOOP_NAME = + "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e"; private static final String CLIENT_CONFIG = "op-http"; private static final String URL_CONTEXT_PATH_CONTROLLERS = "controllers/"; - private static final String URL_CONTEXT_PATH_CONTROLLER = URL_CONTEXT_PATH_CONTROLLERS + CONTROLLER; - private static final String URL_CONTEXT_PATH_KSESSION = URL_CONTEXT_PATH_CONTROLLER + "/drools/facts/" + KSESSION; - private static final String URL_CONTEXT_PATH_CONTROLLOOPS = URL_CONTEXT_PATH_KSESSION + "/controlloops/"; - private static final String URL_CONTEXT_PATH_CONTROLLOOP = URL_CONTEXT_PATH_CONTROLLOOPS + CONTROLOOP_NAME; - private static final String URL_CONTEXT_PATH_CONTROLLOOP_POLICY = URL_CONTEXT_PATH_CONTROLLOOP + "/policy"; + private static final String URL_CONTEXT_PATH_CONTROLLER = + URL_CONTEXT_PATH_CONTROLLERS + CONTROLLER; + private static final String URL_CONTEXT_PATH_KSESSION = + URL_CONTEXT_PATH_CONTROLLER + "/drools/facts/" + KSESSION; + private static final String URL_CONTEXT_PATH_CONTROLLOOPS = + URL_CONTEXT_PATH_KSESSION + "/controlloops/"; + private static final String URL_CONTEXT_PATH_CONTROLLOOP = + URL_CONTEXT_PATH_CONTROLLOOPS + CONTROLOOP_NAME; + private static final String URL_CONTEXT_PATH_CONTROLLOOP_POLICY = + URL_CONTEXT_PATH_CONTROLLOOP + "/policy"; private static final String URL_CONTEXT_PATH_TOOLS = "tools/controlloops/"; private static final String URL_CONTEXT_PATH_TOOLS_AAI = URL_CONTEXT_PATH_TOOLS + "aai/"; - private static final String URL_CONTEXT_PATH_TOOLS_AAI_NQ = URL_CONTEXT_PATH_TOOLS_AAI + "namedQuery/"; - private static final String URL_CONTEXT_PATH_TOOLS_AAI_CQ = URL_CONTEXT_PATH_TOOLS_AAI + "customQuery/"; - + private static final String URL_CONTEXT_PATH_TOOLS_AAI_CQ = + URL_CONTEXT_PATH_TOOLS_AAI + "customQuery/"; private static final String POLICY = "src/test/resources/vCPE.yaml"; private static final String CONTROLLER_FILE = "op-controller.properties"; @@ -98,22 +100,24 @@ public class RestControlLoopManagerTest { LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "WARN"); SystemPersistenceConstants.getManager().setConfigurationDir("src/test/resources"); - PolicyEngineConstants.getManager().configure(PolicyEngineConstants.getManager().defaultTelemetryConfig()); + PolicyEngineConstants.getManager() + .configure(PolicyEngineConstants.getManager().defaultTelemetryConfig()); - ReleaseId releaseId = - KieUtils.installArtifact(Paths.get(KMODULE_PATH).toFile(), Paths.get(KMODULE_POM_PATH).toFile(), - KJAR_DRL_PATH, Paths.get(KMODULE_DRL_PATH).toFile()); + ReleaseId releaseId = KieUtils.installArtifact(Paths.get(KMODULE_PATH).toFile(), + Paths.get(KMODULE_POM_PATH).toFile(), KJAR_DRL_PATH, + Paths.get(KMODULE_DRL_PATH).toFile()); Properties controllerProperties = new Properties(); controllerProperties.put(DroolsPropertyConstants.RULES_GROUPID, releaseId.getGroupId()); - controllerProperties.put(DroolsPropertyConstants.RULES_ARTIFACTID, releaseId.getArtifactId()); + controllerProperties.put(DroolsPropertyConstants.RULES_ARTIFACTID, + releaseId.getArtifactId()); controllerProperties.put(DroolsPropertyConstants.RULES_VERSION, releaseId.getVersion()); PolicyEngineConstants.getManager().createPolicyController(CONTROLLER, controllerProperties); PolicyEngineConstants.getManager().start(); HttpClientFactoryInstance.getClientFactory() - .build(SystemPersistenceConstants.getManager().getProperties(CLIENT_CONFIG)); + .build(SystemPersistenceConstants.getManager().getProperties(CLIENT_CONFIG)); if (!NetworkUtil.isTcpPortOpen("localhost", 9696, 6, 10000L)) { throw new IllegalStateException("cannot connect to port 9696"); @@ -121,9 +125,12 @@ public class RestControlLoopManagerTest { await().atMost(1, TimeUnit.MINUTES).until(isContainerAlive()); - PolicyEngineConstants.getManager().setEnvironmentProperty(ControlLoopEventManager.AAI_URL, "http://localhost:6666"); - PolicyEngineConstants.getManager().setEnvironmentProperty(ControlLoopEventManager.AAI_USERNAME_PROPERTY, "AAI"); - PolicyEngineConstants.getManager().setEnvironmentProperty(ControlLoopEventManager.AAI_PASS_PROPERTY, "AAI"); + PolicyEngineConstants.getManager().setEnvironmentProperty(ControlLoopEventManager.AAI_URL, + "http://localhost:6666"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(ControlLoopEventManager.AAI_USERNAME_PROPERTY, "AAI"); + PolicyEngineConstants.getManager() + .setEnvironmentProperty(ControlLoopEventManager.AAI_PASS_PROPERTY, "AAI"); Util.buildAaiSim(); } @@ -140,7 +147,8 @@ public class RestControlLoopManagerTest { PolicyEngineConstants.getManager().stop(); final Path controllerPath = - Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), CONTROLLER_FILE); + Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), + CONTROLLER_FILE); try { Files.deleteIfExists(controllerPath); } catch (Exception ignored) { @@ -148,7 +156,8 @@ public class RestControlLoopManagerTest { } Path controllerBakPath = - Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), CONTROLLER_FILE_BAK); + Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), + CONTROLLER_FILE_BAK); try { Files.deleteIfExists(controllerBakPath); @@ -162,49 +171,33 @@ public class RestControlLoopManagerTest { */ @Test public void testOperationalPolicy() throws IOException { - assertEquals(Status.OK.getStatusCode(), HttpClientFactoryInstance.getClientFactory().get(CONTROLLER) - .get(URL_CONTEXT_PATH_CONTROLLOOPS).getStatus()); + assertEquals(Status.OK.getStatusCode(), HttpClientFactoryInstance.getClientFactory() + .get(CONTROLLER).get(URL_CONTEXT_PATH_CONTROLLOOPS).getStatus()); - assertEquals(Status.OK.getStatusCode(), HttpClientFactoryInstance.getClientFactory().get(CONTROLLER) - .get(URL_CONTEXT_PATH_CONTROLLOOP).getStatus()); + assertEquals(Status.OK.getStatusCode(), HttpClientFactoryInstance.getClientFactory() + .get(CONTROLLER).get(URL_CONTEXT_PATH_CONTROLLOOP).getStatus()); - assertEquals(Status.NOT_FOUND.getStatusCode(), HttpClientFactoryInstance.getClientFactory().get(CONTROLLER) - .get(URL_CONTEXT_PATH_CONTROLLOOP_POLICY).getStatus()); + assertEquals(Status.NOT_FOUND.getStatusCode(), HttpClientFactoryInstance.getClientFactory() + .get(CONTROLLER).get(URL_CONTEXT_PATH_CONTROLLOOP_POLICY).getStatus()); String policyFromFile = new String(Files.readAllBytes(Paths.get(POLICY))); - HttpClientFactoryInstance.getClientFactory().get(CONTROLLER).put(URL_CONTEXT_PATH_CONTROLLOOP_POLICY, - Entity.text(policyFromFile), Collections.emptyMap()); + HttpClientFactoryInstance.getClientFactory().get(CONTROLLER).put( + URL_CONTEXT_PATH_CONTROLLOOP_POLICY, Entity.text(policyFromFile), + Collections.emptyMap()); - assertEquals(Status.OK.getStatusCode(), HttpClientFactoryInstance.getClientFactory().get(CONTROLLER) - .get(URL_CONTEXT_PATH_CONTROLLOOP_POLICY).getStatus()); + assertEquals(Status.OK.getStatusCode(), HttpClientFactoryInstance.getClientFactory() + .get(CONTROLLER).get(URL_CONTEXT_PATH_CONTROLLOOP_POLICY).getStatus()); String policyFromPdpD = HttpClientFactoryInstance.getClientFactory().get(CONTROLLER) - .get(URL_CONTEXT_PATH_CONTROLLOOP_POLICY) - .readEntity(String.class); + .get(URL_CONTEXT_PATH_CONTROLLOOP_POLICY).readEntity(String.class); assertEquals(policyFromFile, policyFromPdpD); assertEquals(Status.CONFLICT.getStatusCode(), - HttpClientFactoryInstance.getClientFactory().get(CONTROLLER).put(URL_CONTEXT_PATH_CONTROLLOOP_POLICY, - Entity.text(policyFromFile), Collections.emptyMap()).getStatus()); - } - - /** - * Test AAI Named Query. - */ - @Test - public void testAaiNq() throws CoderException { - assertEquals(Status.OK.getStatusCode(), HttpClientFactoryInstance.getClientFactory().get(CONTROLLER) - .get(URL_CONTEXT_PATH_TOOLS_AAI_NQ + "dummy") + .put(URL_CONTEXT_PATH_CONTROLLOOP_POLICY, Entity.text(policyFromFile), + Collections.emptyMap()) .getStatus()); - - String nqResponse = - HttpClientFactoryInstance.getClientFactory().get(CONTROLLER) - .get(URL_CONTEXT_PATH_TOOLS_AAI_NQ + "dummy") - .readEntity(String.class); - - assertNotNull(new StandardCoder().decode(nqResponse, AaiNqResponseWrapper.class)); } /** @@ -212,17 +205,8 @@ public class RestControlLoopManagerTest { */ @Test public void testAaiCq() throws CoderException { - assertEquals(Status.OK.getStatusCode(), - HttpClientFactoryInstance.getClientFactory().get(CONTROLLER) - .get(URL_CONTEXT_PATH_TOOLS_AAI_CQ + "dummy") - .getStatus()); - - String cqResponse = - HttpClientFactoryInstance.getClientFactory().get(CONTROLLER) - .get(URL_CONTEXT_PATH_TOOLS_AAI_CQ + "dummy") - .readEntity(String.class); - - assertNotNull(new StandardCoder().decode(cqResponse, AaiCqResponse.class)); + assertEquals(Status.OK.getStatusCode(), HttpClientFactoryInstance.getClientFactory() + .get(CONTROLLER).get(URL_CONTEXT_PATH_TOOLS_AAI_CQ + "dummy").getStatus()); } /** @@ -231,6 +215,7 @@ public class RestControlLoopManagerTest { * @return if the container is alive. */ private static Callable<Boolean> isContainerAlive() { - return () -> PolicyControllerConstants.getFactory().get(CONTROLLER).getDrools().getContainer().isAlive(); + return () -> PolicyControllerConstants.getFactory().get(CONTROLLER).getDrools() + .getContainer().isAlive(); } } diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl index d3c95a77b..88bf6141f 100644 --- a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl +++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl @@ -39,7 +39,6 @@ import org.onap.policy.controlloop.actor.so.SoActorServiceProvider; import org.onap.policy.controlloop.actor.cds.CdsActorServiceProvider; import org.onap.policy.controlloop.actor.cds.CdsActorServiceProvider.CdsActorServiceManager; import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants; -import org.onap.policy.aai.AaiNqResponseWrapper; import org.onap.policy.aai.AaiCqResponse; import org.onap.policy.appc.Request; import org.onap.policy.appc.Response; @@ -797,7 +796,6 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED" // NOTE: The environment properties uses "guard.disabled" but the boolean is guardEnabled boolean guardEnabled = "false".equalsIgnoreCase(PolicyEngineConstants.getManager().getEnvironmentProperty("guard.disabled")); - boolean cqEnabled = "true".equalsIgnoreCase(PolicyEngineConstants.getManager().getEnvironmentProperty("aai.customQuery")); if(guardEnabled){ @@ -809,25 +807,20 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED" $operation.getTargetEntity(), $event.getRequestId().toString(), () -> { - if (!cqEnabled) { - AaiNqResponseWrapper resp = $manager.getNqVserverFromAai(); - return(resp == null ? null : resp.countVfModules()); - } else { - try { - AaiCqResponse resp_cq = $manager.getCqResponse($event); - if (resp_cq == null){ - return null; - } else { - String custId = $operation.policy.getTarget().getModelCustomizationId(); - String invId = $operation.policy.getTarget().getModelInvariantId(); - String verId = $operation.policy.getTarget().getModelVersionId(); - return resp_cq.getVfModuleCount(custId, invId, verId); - } - } catch (Exception e){ - logger.warn("{}: {}", $params.getClosedLoopControlName(), drools.getRule().getName(), e); + try { + AaiCqResponse resp_cq = $manager.getCqResponse($event); + if (resp_cq == null){ + return null; + } else { + String custId = $operation.policy.getTarget().getModelCustomizationId(); + String invId = $operation.policy.getTarget().getModelInvariantId(); + String verId = $operation.policy.getTarget().getModelVersionId(); + return resp_cq.getVfModuleCount(custId, invId, verId); } - return null; + } catch (Exception e){ + logger.warn("{}: {}", $params.getClosedLoopControlName(), drools.getRule().getName(), e); } + return null; })); t.start(); } diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java index 57085f614..f41bd874b 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java @@ -53,10 +53,9 @@ public class VcpeControlLoopTest extends ControlLoopBase implements TopicListene public static void setUpBeforeClass() { ControlLoopBase.setUpBeforeClass( "../archetype-cl-amsterdam/src/main/resources/archetype-resources" - + "/src/main/resources/__closedLoopControlName__.drl", + + "/src/main/resources/__closedLoopControlName__.drl", "src/test/resources/yaml/policy_ControlLoop_vCPE.yaml", - "service=ServiceDemo;resource=Res1Demo;type=operational", - "CL_vCPE", + "service=ServiceDemo;resource=Res1Demo;type=operational", "CL_vCPE", "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0"); } @@ -81,7 +80,7 @@ public class VcpeControlLoopTest extends ControlLoopBase implements TopicListene * Simulate an onset event the policy engine will receive from DCAE to kick off processing * through the rules */ - sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "vCPEInfraVNF13", true); + sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "OzVServer", true); kieSession.fireUntilHalt(); @@ -152,10 +151,10 @@ public class VcpeControlLoopTest extends ControlLoopBase implements TopicListene Object obj = null; if ("POLICY-CL-MGT".equals(topic)) { obj = org.onap.policy.controlloop.util.Serialization.gsonJunit.fromJson(event, - org.onap.policy.controlloop.VirtualControlLoopNotification.class); + org.onap.policy.controlloop.VirtualControlLoopNotification.class); } else if ("APPC-LCM-READ".equals(topic)) { obj = org.onap.policy.appclcm.util.Serialization.gsonJunit.fromJson(event, - org.onap.policy.appclcm.AppcLcmDmaapWrapper.class); + org.onap.policy.appclcm.AppcLcmDmaapWrapper.class); } assertNotNull(obj); if (obj instanceof VirtualControlLoopNotification) { @@ -163,20 +162,24 @@ public class VcpeControlLoopTest extends ControlLoopBase implements TopicListene String policyName = notification.getPolicyName(); if (policyName.endsWith("EVENT")) { logger.debug("Rule Fired: " + notification.getPolicyName()); - assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.getNotification())); + assertTrue( + ControlLoopNotificationType.ACTIVE.equals(notification.getNotification())); } else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) { logger.debug("Rule Fired: " + notification.getPolicyName()); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertTrue( + ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); assertNotNull(notification.getMessage()); assertTrue(notification.getMessage().startsWith("Sending guard query")); } else if (policyName.endsWith("GUARD.RESPONSE")) { logger.debug("Rule Fired: " + notification.getPolicyName()); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertTrue( + ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); assertNotNull(notification.getMessage()); assertTrue(notification.getMessage().toLowerCase().endsWith("permit")); } else if (policyName.endsWith("GUARD_PERMITTED")) { logger.debug("Rule Fired: " + notification.getPolicyName()); - assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); + assertTrue( + ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); assertNotNull(notification.getMessage()); assertTrue(notification.getMessage().startsWith("actor=APPC")); } else if (policyName.endsWith("OPERATION.TIMEOUT")) { @@ -186,17 +189,20 @@ public class VcpeControlLoopTest extends ControlLoopBase implements TopicListene fail("Operation Timed Out"); } else if (policyName.endsWith("APPC.LCM.RESPONSE")) { logger.debug("Rule Fired: " + notification.getPolicyName()); - assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification())); + assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS + .equals(notification.getNotification())); assertNotNull(notification.getMessage()); assertTrue(notification.getMessage().startsWith("actor=APPC")); sendEvent(pair.first, requestId, ControlLoopEventStatus.ABATED); } else if (policyName.endsWith("EVENT.MANAGER")) { logger.debug("Rule Fired: " + notification.getPolicyName()); if ("getFail".equals(notification.getAai().get("generic-vnf.vnf-name"))) { - assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification()); + assertEquals(ControlLoopNotificationType.FINAL_FAILURE, + notification.getNotification()); kieSession.halt(); } else { - assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, notification.getNotification()); + assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, + notification.getNotification()); kieSession.halt(); } } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) { @@ -238,7 +244,8 @@ public class VcpeControlLoopTest extends ControlLoopBase implements TopicListene * @param requestId the requestId for this event * @param status could be onset or abated */ - protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) { + protected void sendEvent(ControlLoopPolicy policy, UUID requestId, + ControlLoopEventStatus status) { VirtualControlLoopEvent event = new VirtualControlLoopEvent(); event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName()); event.setRequestId(requestId); @@ -250,8 +257,8 @@ public class VcpeControlLoopTest extends ControlLoopBase implements TopicListene kieSession.insert(event); } - protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status, String vnfName, - boolean isEnriched) { + protected void sendEvent(ControlLoopPolicy policy, UUID requestId, + ControlLoopEventStatus status, String vnfName, boolean isEnriched) { VirtualControlLoopEvent event = new VirtualControlLoopEvent(); event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName()); event.setRequestId(requestId); @@ -260,6 +267,7 @@ public class VcpeControlLoopTest extends ControlLoopBase implements TopicListene event.setClosedLoopAlarmStart(Instant.now()); event.setAai(new HashMap<>()); event.getAai().put("generic-vnf.vnf-name", vnfName); + event.getAai().put("vserver.vserver-name", vnfName); if (isEnriched) { event.getAai().put("generic-vnf.in-maint", "false"); event.getAai().put("generic-vnf.is-closed-loop-disabled", "false"); diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopCqTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopCqTest.java index 1a5bf3982..0e05a0c6d 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopCqTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopCqTest.java @@ -235,7 +235,7 @@ public class VdnsControlLoopCqTest extends ControlLoopBase implements TopicListe event.setTargetType(ControlLoopTargetType.VNF); event.setClosedLoopAlarmStart(Instant.now()); event.setAai(new HashMap<>()); - event.getAai().put("vserver.vserver-name", "Ete_vFWCLvFWSNK_7ba1fbde_0"); + event.getAai().put("vserver.vserver-name", "OzVServer"); event.getAai().put("vserver.is-closed-loop-disabled", "false"); event.getAai().put("vserver.prov-status", "ACTIVE"); event.setClosedLoopEventStatus(status); diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java index 3c658c1fd..da237fa05 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java @@ -267,7 +267,7 @@ public class VdnsControlLoopTest extends ControlLoopBase implements TopicListene event.setTargetType(ControlLoopTargetType.VNF); event.setClosedLoopAlarmStart(Instant.now()); event.setAai(new HashMap<>()); - event.getAai().put("vserver.vserver-name", "dfw1lb01lb01"); + event.getAai().put("vserver.vserver-name", "OzVServer"); event.getAai().put("vserver.is-closed-loop-disabled", "false"); event.getAai().put("vserver.prov-status", "ACTIVE"); event.setClosedLoopEventStatus(status); diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java index c326da145..cbdf09c8d 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java @@ -285,6 +285,7 @@ public class VfwControlLoopTest extends ControlLoopBase implements TopicListener event.setClosedLoopAlarmStart(Instant.now()); event.setAai(new HashMap<>()); event.getAai().put("generic-vnf.vnf-name", "testGenericVnfID"); + event.getAai().put("vserver.vserver-name", "testVserverName"); event.setClosedLoopEventStatus(status); kieSession.insert(event); } @@ -306,6 +307,7 @@ public class VfwControlLoopTest extends ControlLoopBase implements TopicListener event.setClosedLoopAlarmStart(Instant.now()); event.setAai(new HashMap<>()); event.getAai().put("generic-vnf.vnf-name", vnfId); + event.getAai().put("vserver.vserver-name", vnfId); event.setClosedLoopEventStatus(status); kieSession.insert(event); } diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java index 9d3486f5b..d3aedd68f 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java @@ -265,6 +265,7 @@ public class VpciControlLoopTest extends ControlLoopBase implements TopicListene event.getAai().put("generic-vnf.is-closed-loop-disabled", "false"); event.getAai().put("generic-vnf.prov-status", "ACTIVE"); event.getAai().put("generic-vnf.vnf-id", "notused"); + event.getAai().put("vserver.vserver-name", "OzVServer"); } else { event.getAai().put("generic-vnf.vnf-id", "getFail"); } diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java index d0427e47f..527fd298d 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java @@ -269,6 +269,7 @@ public class VsonhControlLoopTest extends ControlLoopBase implements TopicListen event.getAai().put("generic-vnf.is-closed-loop-disabled", "false"); event.getAai().put("generic-vnf.prov-status", "ACTIVE"); event.getAai().put("generic-vnf.vnf-id", "notused"); + event.getAai().put("vserver.vserver-name", "OzVServer"); } else { event.getAai().put("generic-vnf.vnf-id", "getFail"); } diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_SO-test.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_SO-test.yaml index c6125d082..d32f55b5d 100644 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_SO-test.yaml +++ b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_SO-test.yaml @@ -29,11 +29,11 @@ policies: recipe: VF Module Create target: type: VFMODULE - modelInvariantId: 90b793b5-b8ae-4c36-b10b-4b6372859d3a - modelVersionId: 2210154d-e61a-4d7f-8fb9-0face1aee3f8 - modelName: SproutScalingVf..scaling_sprout..module-1 + modelInvariantId: e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e + modelVersionId: 94b18b1d-cc91-4f43-911a-e6348665f292 + modelName: VfwclVfwsnkBbefb8ce2bde..base_vfw..module-0 modelVersion: 1 - modelCustomizationId: 3e2d67ad-3495-4732-82f6-b0b872791fff + modelCustomizationId: 47958575-138f-452a-8c8d-d89b595f8164 payload: requestParameters: '{"usePreload":true,"userParams":[]}' configurationParameters: '[{"ip-addr":"$.vf-module-topology.vf-module-parameters.param[9]","oam-ip-addr":"$.vf-module-topology.vf-module-parameters.param[16]","enabled":"$.vf-module-topology.vf-module-parameters.param[23]"}]' diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vFW.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vFW.yaml index fa66a2639..8c94b1adc 100644 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vFW.yaml +++ b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vFW.yaml @@ -15,9 +15,9 @@ controlLoop: version: 2.0.0 controlLoopName: ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a services: - - serviceInvariantUUID: 5cfe6f4a-41bc-4247-8674-ebd4b98e35cc - serviceUUID: 0f40bba5-986e-4b3c-803f-ddd1b7b25f24 - serviceName: 57e66ea7-0ed6-45c7-970f + - serviceInvariantUUID: f6937c86-584c-47ae-ad29-8d41d6f0cc7c + serviceUUID: 7be584e2-0bb2-4126-adaf-ced2c77ca0b3 + serviceName: Service_Ete_Name7ba1fbde-6187-464a-a62d-d9dd25bdf4e8 trigger_policy: unique-policy-id-1-modifyConfig timeout: 60 abatement: true @@ -29,7 +29,7 @@ policies: actor: APPC recipe: ModifyConfig target: - resourceID: Eace933104d443b496b8.nodes.heat.vpg + resourceID: bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38 type: VNF retry: 0 timeout: 30 diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vPCI.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vPCI.yaml index 35cb2ac3d..42e2000db 100644 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vPCI.yaml +++ b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vPCI.yaml @@ -26,7 +26,7 @@ policies: recipe: ModifyConfig target: # These fields are not used - resourceID: Eace933104d443b496b8.nodes.heat.vpg + resourceID: bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38 type: VNF retry: 0 timeout: 300 |