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 /controlloop/common/eventmanager/src/main | |
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>
Diffstat (limited to 'controlloop/common/eventmanager/src/main')
2 files changed, 123 insertions, 456 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java index 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; } |