summaryrefslogtreecommitdiffstats
path: root/controlloop/common/actors
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/common/actors
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/common/actors')
-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
2 files changed, 50 insertions, 125 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);
+ }
}