aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/eventmanager')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java316
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java263
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java576
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java149
4 files changed, 207 insertions, 1097 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;
}
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());