aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-08-21 15:54:11 -0400
committerJim Hahn <jrh3@att.com>2018-08-21 16:23:42 -0400
commit5bb419efe574df172555263110f9492980f5d1e0 (patch)
tree9bb25fdb2da606ba8ba056d97e4f82b21b2be490 /controlloop
parent48eb8e2bd1674592ddfadfbbc01a611b6a263393 (diff)
move AAI named query
The AAI vserver named-query was being done as a preliminary step for the SO request. However, it will now be needed during the guard query, which happens much earlier. Thus it has been moved from the SO classes into the event manager class, where it is retrieved in a lazy fashion and cached. Also removed some trailing white space. Update licenses. Make test method private. Change-Id: Id7353a2e0f2d42601d5142cb92961528fa21aa94 Issue-ID: POLICY-1011 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop')
-rw-r--r--controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java103
-rw-r--r--controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java72
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java92
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java4
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java140
-rwxr-xr-xcontrolloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoResponseWrapper.java3
6 files changed, 233 insertions, 181 deletions
diff --git a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
index de4e43949..c934c6110 100644
--- a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
+++ b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* SOActorServiceProvider
* ================================================================================
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,26 +21,15 @@
package org.onap.policy.controlloop.actor.so;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import java.util.UUID;
import org.drools.core.WorkingMemory;
-import org.onap.policy.aai.AaiManager;
import org.onap.policy.aai.AaiNqExtraProperty;
-import org.onap.policy.aai.AaiNqInstanceFilters;
import org.onap.policy.aai.AaiNqInventoryResponseItem;
-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.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.drools.system.PolicyEngine;
-import org.onap.policy.rest.RESTManager;
import org.onap.policy.so.SOCloudConfiguration;
import org.onap.policy.so.SOManager;
import org.onap.policy.so.SOModelInfo;
@@ -100,14 +89,15 @@ public class SOActorServiceProvider implements Actor {
/**
* Constructs a SO request conforming to the lcm API. The actual request is constructed and then
* placed in a wrapper object used to send through DMAAP.
- *
+ *
* @param onset the event that is reporting the alert for policy to perform an action
* @param operation the control loop operation specifying the actor, operation, target, etc.
* @param policy the policy the was specified from the yaml generated by CLAMP or through the
* Policy GUI/API
+ * @param aaiResponseWrapper wrapper for AAI vserver named-query response
* @return a SO request conforming to the lcm API using the DMAAP wrapper
*/
- public SORequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) {
+ public SORequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy, AaiNqResponseWrapper aaiResponseWrapper) {
String modelNamePropertyKey = "model-ver.model-name";
String modelVersionPropertyKey = "model-ver.model-version";
String modelVersionIdPropertyKey = "model-ver.model-version-id";
@@ -119,9 +109,7 @@ public class SOActorServiceProvider implements Actor {
}
// Perform named query request and handle response
- AaiNqResponseWrapper aaiResponseWrapper = performAaiNamedQueryRequest(onset);
if (aaiResponseWrapper == null) {
- // Tracing and error handling handled in the "performAaiNamedQueryRequest()" method
return null;
}
@@ -278,7 +266,7 @@ public class SOActorServiceProvider implements Actor {
/**
* This method is needed to get the serviceInstanceId and vnfInstanceId which is used in the
* asyncSORestCall.
- *
+ *
* @param requestId the request Id
* @param wm the working memory
* @param request the request
@@ -290,63 +278,8 @@ public class SOActorServiceProvider implements Actor {
}
/**
- * Constructs and sends an AAI vserver Named Query.
- *
- * @param onset the virtual control loop event
- * @return the response to the AAI Named Query
- */
- private AaiNqResponseWrapper performAaiNamedQueryRequest(VirtualControlLoopEvent onset) {
-
- // 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
- // UUID.fromString($params.getAaiNamedQueryUUID()) TO DO: AaiNamedQueryUUID
- 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<>();
- // TO DO: get vserver.vname from dcae onset.AAI.get("vserver.vserver-name")
- aaiNqInstanceFilterMapItem.put("vserver-name", onset.getAai().get("vserver.vserver-name"));
- aaiNqInstanceFilterMap.put("vserver", aaiNqInstanceFilterMapItem);
- aaiNqInstanceFilter.getInstanceFilter().add(aaiNqInstanceFilterMap);
- aaiNqRequest.setInstanceFilters(aaiNqInstanceFilter);
-
- 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"), getPeManagerEnvProperty("aai.password"), aaiNqRequest,
- onset.getRequestId());
-
- // Check AAI response
- if (aaiNqResponse == null) {
- logger.warn("No response received from AAI for request {}", aaiNqRequest);
- return null;
- }
-
- // Create AAINQResponseWrapper
- AaiNqResponseWrapper aaiNqResponseWrapper = new AaiNqResponseWrapper(onset.getRequestId(), aaiNqResponse);
-
- if (logger.isDebugEnabled()) {
- logger.debug("AAI Named Query Response: ");
- logger.debug(Serialization.gsonPretty.toJson(aaiNqResponseWrapper.getAaiNqResponse()));
- }
-
- return aaiNqResponseWrapper;
- }
-
- /**
* Find the base index or non base index in a list of inventory response items.
- *
+ *
* @param inventoryResponseItems the list of inventory response items
* @param baseIndexFlag true if we are searching for the base index, false if we are searching
* for the non base index
@@ -365,7 +298,7 @@ public class SOActorServiceProvider implements Actor {
/**
* Find the number of non base modules present in API response object.
- *
+ *
* @param inventoryResponseItems the list of inventory response items
* @return number of non base index modules
*/
@@ -385,7 +318,7 @@ public class SOActorServiceProvider implements Actor {
/**
* This method is called to remember the last service instance ID and VNF Item VNF ID. Note
* these fields are static, beware for multithreaded deployments
- *
+ *
* @param vnfInstanceId update the last VNF instance ID to this value
* @param serviceInstanceId update the last service instance ID to this value
*/
@@ -393,20 +326,4 @@ public class SOActorServiceProvider implements Actor {
lastVNFItemVnfId = vnfInstanceId;
lastServiceItemServiceInstanceId = serviceInstanceId;
}
-
- /**
- * 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 = PolicyEngine.manager.getEnvironmentProperty(enginePropertyName);
- if (enginePropertyValue == null) {
- throw new IllegalArgumentException("The value of policy engine manager environment property \""
- + enginePropertyName + "\" may not be null");
- }
- return enginePropertyValue;
- }
}
diff --git a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java
index 5333be58d..d75d859d8 100644
--- a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java
+++ b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* ================================================================================
+ * Modifications Copyright (C) 2018 AT&T. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -24,35 +26,26 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
-
+import java.util.HashMap;
+import java.util.Map;
import java.util.UUID;
-
import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.aai.AaiNqInstanceFilters;
+import org.onap.policy.aai.AaiNqRequest;
+import org.onap.policy.aai.AaiNqResponse;
+import org.onap.policy.aai.AaiNqResponseWrapper;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.drools.system.PolicyEngine;
-import org.onap.policy.simulators.Util;
+import org.onap.policy.simulators.AaiSimulatorJaxRs;
import org.onap.policy.so.SORequest;
+import org.onap.policy.so.util.Serialization;
public class TestSOActorServiceProvider {
/**
- * Set up for test class.
- */
- @BeforeClass
- public static void setUpSimulator() {
- try {
- Util.buildAaiSim();
- } catch (Exception e) {
- fail(e.getMessage());
- }
- }
-
- /**
* Tear down after test class.
*/
@AfterClass
@@ -64,32 +57,22 @@ public class TestSOActorServiceProvider {
public void testConstructRequest() {
VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
final ControlLoopOperation operation = new ControlLoopOperation();
+ final AaiNqResponseWrapper aaiNqResp = getNqVserverFromAai(onset);
final UUID requestId = UUID.randomUUID();
onset.setRequestId(requestId);
- PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
- PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
- PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
-
Policy policy = new Policy();
policy.setActor("Dorothy");
policy.setRecipe("GoToOz");
- assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
+ assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp));
policy.setActor("SO");
- assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
+ assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp));
policy.setRecipe("VF Module Create");
- assertNotNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
-
- PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:999999");
- assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
-
- PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
- assertNotNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
-
- SORequest request = new SOActorServiceProvider().constructRequest(onset, operation, policy);
+ SORequest request = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp);
+ assertNotNull(request);
assertEquals("policy", request.getRequestDetails().getRequestInfo().getRequestorId());
assertEquals("RegionOne", request.getRequestDetails().getCloudConfiguration().getLcpCloudRegionId());
@@ -113,4 +96,29 @@ public class TestSOActorServiceProvider {
assertEquals("VF Module Create", sp.recipes().get(0));
assertEquals(0, sp.recipePayloads("VF Module Create").size());
}
+
+ /**
+ * Queries the AAI simulator directly (i.e., bypassing the REST API) to get the
+ * vserver named-query response.
+ *
+ * @param onset the ONSET event
+ * @return output from the AAI vserver named-query
+ */
+ private AaiNqResponseWrapper getNqVserverFromAai(VirtualControlLoopEvent onset) {
+ AaiNqRequest aaiNqRequest = new AaiNqRequest();
+ final AaiNqInstanceFilters aaiNqInstanceFilter = new AaiNqInstanceFilters();
+
+ Map<String, Map<String, String>> aaiNqInstanceFilterMap = new HashMap<>();
+ Map<String, String> aaiNqInstanceFilterMapItem = new HashMap<>();
+ aaiNqInstanceFilterMapItem.put("vserver-name", "my-vserver-name");
+ aaiNqInstanceFilterMap.put("vserver", aaiNqInstanceFilterMapItem);
+ aaiNqInstanceFilter.getInstanceFilter().add(aaiNqInstanceFilterMap);
+ aaiNqRequest.setInstanceFilters(aaiNqInstanceFilter);
+
+ String req = Serialization.gsonPretty.toJson(aaiNqRequest);
+ String resp = new AaiSimulatorJaxRs().aaiPostQuery(req);
+ AaiNqResponse aaiNqResponse = Serialization.gsonPretty.fromJson(resp, AaiNqResponse.class);
+
+ return new AaiNqResponseWrapper(onset.getRequestId(), aaiNqResponse);
+ }
}
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 bd7f14e6f..bb349591e 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
@@ -25,6 +25,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -33,6 +34,12 @@ import java.util.UUID;
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;
@@ -51,6 +58,7 @@ import org.onap.policy.guard.PolicyGuard;
import org.onap.policy.guard.PolicyGuard.LockResult;
import org.onap.policy.guard.TargetLock;
import org.onap.policy.rest.RESTManager;
+import org.onap.policy.so.util.Serialization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -95,6 +103,12 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
private AaiGetVnfResponse vnfResponse = null;
private AaiGetVserverResponse vserverResponse = null;
+ /**
+ * 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 {
@@ -871,6 +885,84 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
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;
+ }
+
+ // 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
+ // TODO: UUID.fromString($params.getAaiNamedQueryUUID()) AaiNamedQueryUUID
+ 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);
+
+ 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"), getPeManagerEnvProperty("aai.password"), 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;
+ }
+
+ /**
+ * 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 = PolicyEngine.manager.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 boolean isActive() {
// TODO
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 7ef2a2e04..0eb924dd2 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
@@ -264,8 +264,8 @@ public class ControlLoopOperationManager implements Serializable {
return operationRequest;
case "SO":
SOActorServiceProvider soActorSp = new SOActorServiceProvider();
- this.operationRequest =
- soActorSp.constructRequest((VirtualControlLoopEvent) onset, operation.clOperation, this.policy);
+ this.operationRequest = soActorSp.constructRequest((VirtualControlLoopEvent) onset,
+ operation.clOperation, this.policy, eventManager.getNqVserverFromAai());
// Save the operation
this.currentOperation = operation;
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 1cef78a9e..1b2d8db61 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
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -46,6 +46,7 @@ import org.onap.policy.aai.AaiGetVnfResponse;
import org.onap.policy.aai.AaiGetVserverResponse;
import org.onap.policy.aai.AaiNqVServer;
import org.onap.policy.aai.AaiNqRequestError;
+import org.onap.policy.aai.AaiNqResponseWrapper;
import org.onap.policy.aai.RelatedToProperty;
import org.onap.policy.aai.Relationship;
import org.onap.policy.aai.RelationshipData;
@@ -71,8 +72,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ControlLoopEventManagerTest {
+ private static final String INVALID_URL = "http://localhost:9999";
+
private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManagerTest.class);
-
+
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -97,7 +100,7 @@ public class ControlLoopEventManagerTest {
public static void tearDownSimulator() {
HttpServletServer.factory.destroy();
}
-
+
@Before
public void setUp() {
onset = new VirtualControlLoopEvent();
@@ -110,7 +113,7 @@ public class ControlLoopEventManagerTest {
onset.getAai().put("vserver.selflink", "bar");
onset.getAai().put("generic-vnf.vnf-id", "83f674e8-7555-44d7-9a39-bdc3770b0491");
onset.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
-
+
PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
}
@@ -366,7 +369,7 @@ public class ControlLoopEventManagerTest {
public static AaiGetVserverResponse getQueryByVserverName2(String urlGet, String username, String password,
UUID requestId, String key) {
AaiGetVserverResponse response = new AaiGetVserverResponse();
-
+
AaiNqVServer svr = new AaiNqVServer();
svr.setVserverId("d0668d4f-c25e-4a1b-87c4-83845c01efd8");
@@ -407,7 +410,7 @@ public class ControlLoopEventManagerTest {
relationshipList.getRelationships().add(relationship);
svr.setRelationshipList(relationshipList);
-
+
response.getVserver().add(svr);
return response;
@@ -894,7 +897,7 @@ public class ControlLoopEventManagerTest {
@Test
public void testQueryAai_AlreadyDisabled() throws AaiException {
ControlLoopEventManager mgr = null;
-
+
try {
onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, Boolean.TRUE.toString());
onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS,
@@ -915,7 +918,7 @@ public class ControlLoopEventManagerTest {
@Test
public void testQueryAai_AlreadyInactive() throws AaiException {
ControlLoopEventManager mgr = null;
-
+
try {
onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, Boolean.FALSE.toString());
onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, "not-active2");
@@ -938,15 +941,15 @@ public class ControlLoopEventManagerTest {
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());
}
@@ -954,22 +957,22 @@ public class ControlLoopEventManagerTest {
@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());
}
@@ -977,10 +980,10 @@ public class ControlLoopEventManagerTest {
@Test
public void testQueryAai_QueryVnfById_Disabled() throws AaiException {
ControlLoopEventManager mgr = null;
-
+
try {
onset.getAai().put(ControlLoopEventManager.GENERIC_VNF_VNF_ID, "disableClosedLoop");
-
+
mgr = makeManager(onset);
mgr.queryAai(onset);
@@ -988,7 +991,7 @@ public class ControlLoopEventManagerTest {
} catch (AaiException expected) {
assertEquals("is-closed-loop-disabled is set to true (query by vnf-id)", expected.getMessage());
-
+
assertNotNull(mgr.getVnfResponse());
assertNull(mgr.getVserverResponse());
}
@@ -1003,15 +1006,15 @@ public class ControlLoopEventManagerTest {
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());
}
@@ -1019,11 +1022,11 @@ public class ControlLoopEventManagerTest {
@Test
public void testQueryAai_QueryVserver_Disabled() throws AaiException {
ControlLoopEventManager mgr = null;
-
+
try {
onset.getAai().remove(ControlLoopEventManager.GENERIC_VNF_VNF_ID);
onset.getAai().put(ControlLoopEventManager.VSERVER_VSERVER_NAME, "disableClosedLoop");
-
+
mgr = makeManager(onset);
mgr.queryAai(onset);
@@ -1031,7 +1034,7 @@ public class ControlLoopEventManagerTest {
} catch (AaiException expected) {
assertEquals("is-closed-loop-disabled is set to true (query by vserver-name)", expected.getMessage());
-
+
assertNull(mgr.getVnfResponse());
assertNotNull(mgr.getVserverResponse());
}
@@ -1040,8 +1043,8 @@ public class ControlLoopEventManagerTest {
@Test(expected = AaiException.class)
public void testQueryAai_QueryException() throws AaiException {
// Force AAI errors
- PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:9999");
-
+ PolicyEngine.manager.setEnvironmentProperty("aai.url", INVALID_URL);
+
makeManager(onset).queryAai(onset);
}
@@ -1066,11 +1069,11 @@ public class ControlLoopEventManagerTest {
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.setIsClosedLoopDisabled(false);
resp.setProvStatus(ControlLoopEventManager.PROV_STATUS_ACTIVE);
Whitebox.invokeMethod(ControlLoopEventManager.class, "processVNFResponse", resp, false);
@@ -1080,7 +1083,7 @@ public class ControlLoopEventManagerTest {
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.setIsClosedLoopDisabled(true);
resp.setProvStatus(ControlLoopEventManager.PROV_STATUS_ACTIVE);
@@ -1101,10 +1104,10 @@ public class ControlLoopEventManagerTest {
@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, "processVServerResponse", resp);
@@ -1125,15 +1128,15 @@ public class ControlLoopEventManagerTest {
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, "processVServerResponse", resp);
}
@@ -1145,7 +1148,7 @@ public class ControlLoopEventManagerTest {
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, "processVServerResponse", resp);
@@ -1159,7 +1162,7 @@ public class ControlLoopEventManagerTest {
AaiGetVserverResponse resp = new AaiGetVserverResponse();
AaiNqVServer svr = new AaiNqVServer();
resp.getVserver().add(svr);
-
+
svr.setIsClosedLoopDisabled(false);
svr.setProvStatus("inactive1");
Whitebox.invokeMethod(ControlLoopEventManager.class, "processVServerResponse", resp);
@@ -1168,63 +1171,63 @@ public class ControlLoopEventManagerTest {
@Test
public void testIsClosedLoopDisabled() {
Map<String, String> aai = onset.getAai();
-
+
// null, null
aai.remove(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED);
aai.remove(ControlLoopEventManager.VSERVER_IS_CLOSED_LOOP_DISABLED);
assertFalse(ControlLoopEventManager.isClosedLoopDisabled(onset));
-
+
// null, false
aai.remove(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED);
aai.put(ControlLoopEventManager.VSERVER_IS_CLOSED_LOOP_DISABLED, Boolean.FALSE.toString());
assertFalse(ControlLoopEventManager.isClosedLoopDisabled(onset));
-
+
// false, null
aai.put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, Boolean.FALSE.toString());
aai.remove(ControlLoopEventManager.VSERVER_IS_CLOSED_LOOP_DISABLED);
assertFalse(ControlLoopEventManager.isClosedLoopDisabled(onset));
-
+
// null, true
aai.remove(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED);
aai.put(ControlLoopEventManager.VSERVER_IS_CLOSED_LOOP_DISABLED, Boolean.TRUE.toString());
assertTrue(ControlLoopEventManager.isClosedLoopDisabled(onset));
-
+
// true, null
aai.put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, Boolean.TRUE.toString());
aai.remove(ControlLoopEventManager.VSERVER_IS_CLOSED_LOOP_DISABLED);
assertTrue(ControlLoopEventManager.isClosedLoopDisabled(onset));
}
-
+
@Test
public void testIsProvStatusInactive() {
Map<String, String> aai = onset.getAai();
-
+
// null, null
aai.remove(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS);
aai.remove(ControlLoopEventManager.VSERVER_PROV_STATUS);
assertFalse(ControlLoopEventManager.isProvStatusInactive(onset));
-
+
// null, active
aai.remove(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS);
aai.put(ControlLoopEventManager.VSERVER_PROV_STATUS, ControlLoopEventManager.PROV_STATUS_ACTIVE);
assertFalse(ControlLoopEventManager.isProvStatusInactive(onset));
-
+
// active, null
aai.put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, ControlLoopEventManager.PROV_STATUS_ACTIVE);
aai.remove(ControlLoopEventManager.VSERVER_PROV_STATUS);
assertFalse(ControlLoopEventManager.isProvStatusInactive(onset));
-
+
// null, inactive
aai.remove(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS);
aai.put(ControlLoopEventManager.VSERVER_PROV_STATUS, "other1");
assertTrue(ControlLoopEventManager.isProvStatusInactive(onset));
-
+
// inactive, null
aai.put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, "other2");
aai.remove(ControlLoopEventManager.VSERVER_PROV_STATUS);
assertTrue(ControlLoopEventManager.isProvStatusInactive(onset));
}
-
+
@Test
public void testIsAaiTrue() {
assertTrue(ControlLoopEventManager.isAaiTrue("tRuE"));
@@ -1233,11 +1236,44 @@ public class ControlLoopEventManagerTest {
assertTrue(ControlLoopEventManager.isAaiTrue("yES"));
assertTrue(ControlLoopEventManager.isAaiTrue("Y"));
assertTrue(ControlLoopEventManager.isAaiTrue("y"));
-
+
assertFalse(ControlLoopEventManager.isAaiTrue("no"));
assertFalse(ControlLoopEventManager.isAaiTrue(null));
}
+ @Test
+ public void testGetNqVserverFromAai() throws Exception {
+
+ // 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
+ PolicyEngine.manager.setEnvironmentProperty("aai.url", INVALID_URL);
+
+ // re-create manager
+ manager = makeManager(onset);
+ manager.activate(onset);
+ assertNull(manager.getNqVserverFromAai());
+ }
+
private ControlLoopEventManager makeManager(VirtualControlLoopEvent event) {
return new ControlLoopEventManager(event.getClosedLoopControlName(), event.getRequestId());
}
diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoResponseWrapper.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoResponseWrapper.java
index 860761a39..4f21630a2 100755
--- a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoResponseWrapper.java
+++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoResponseWrapper.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* so
* ================================================================================
- *
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,7 +54,6 @@ public class TestSoResponseWrapper {
assertEquals("id2", obj.getRequestID());
}
- @SuppressWarnings("unlikely-arg-type")
@Test
public void testSOResponseWrapperMethods() {
String requestID = UUID.randomUUID().toString();