aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/actors
diff options
context:
space:
mode:
authordaniel <dc443y@att.com>2017-09-12 09:44:59 -0500
committerdaniel <dc443y@att.com>2017-09-12 19:01:34 -0500
commitc226d61d3c1266f592fc3d785164aedb34a25ef6 (patch)
tree89516010b0d4dacfc5ae5d9a92352c670fad6771 /controlloop/common/actors
parente126a975d8c6f3970dbf87ead79fa69afe510301 (diff)
Fix A&AI Named Query for vFW
The vFW named query has now been verified with the A&AI simulator. Null checks were added to make the namedQuery method work properly. In addition, a recursive A&AI response parser was added to traverse the response to find the correct generic-vnf object with the target vnf-id. For now the simulator URL is hard coded and the UUID of the named query is hard coded. These should be configurable in future releases. Issue-ID: POLICY-104 Change-Id: I05a1a992ff68ca2c17fb6a578983e6b21626bf44 Signed-off-by: Daniel Cruz <dc443y@att.com>
Diffstat (limited to 'controlloop/common/actors')
-rw-r--r--controlloop/common/actors/actor.appc/pom.xml6
-rw-r--r--controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java10
-rw-r--r--controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java26
-rw-r--r--controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java64
4 files changed, 88 insertions, 18 deletions
diff --git a/controlloop/common/actors/actor.appc/pom.xml b/controlloop/common/actors/actor.appc/pom.xml
index 2d39ca849..36cdac6eb 100644
--- a/controlloop/common/actors/actor.appc/pom.xml
+++ b/controlloop/common/actors/actor.appc/pom.xml
@@ -58,5 +58,11 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.onap.policy.drools-applications</groupId>
+ <artifactId>simulators</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java
index 2d2992106..9e63e467b 100644
--- a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java
+++ b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java
@@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.List;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider;
import org.onap.policy.appc.CommonHeader;
import org.onap.policy.appc.Request;
import org.onap.policy.controlloop.ControlLoopOperation;
@@ -100,7 +101,14 @@ public class APPCActorServiceProvider implements Actor {
* specified in the yaml, the target vnf-id is retrieved by
* a named query to A&AI.
*/
- String vnfId = "test";
+ String vnfId;
+ if (onset.AAI.get("generic-vnf.vnf-id").equalsIgnoreCase(policy.getTarget().getResourceID())) {
+ vnfId = onset.AAI.get("generic-vnf.vnf-id");
+ }
+ else {
+ vnfId = AppcLcmActorServiceProvider.vnfNamedQuery(
+ policy.getTarget().getResourceID(), onset.AAI.get("generic-vnf.vnf-id"));
+ }
/*
* For now Policy generates the PG Streams as a demo, in the
diff --git a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java
index c8179992c..31bb5c8d2 100644
--- a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java
+++ b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java
@@ -26,6 +26,8 @@ import java.time.Instant;
import java.util.HashMap;
import java.util.UUID;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.appc.Request;
import org.onap.policy.appc.util.Serialization;
@@ -36,6 +38,8 @@ import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.Target;
import org.onap.policy.controlloop.policy.TargetType;
+import org.onap.policy.drools.http.server.HttpServletServer;
+import org.onap.policy.simulators.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,7 +60,7 @@ public class AppcServiceProviderTest {
onsetEvent.closedLoopControlName = "closedLoopControlName-Test";
onsetEvent.requestID = UUID.randomUUID();
onsetEvent.closedLoopEventClient = "tca.instance00001";
- onsetEvent.target_type = ControlLoopTargetType.VF;
+ onsetEvent.target_type = ControlLoopTargetType.VNF;
onsetEvent.target = "generic-vnf.vnf-id";
onsetEvent.from = "DCAE";
onsetEvent.closedLoopAlarmStart = Instant.now();
@@ -68,7 +72,7 @@ public class AppcServiceProviderTest {
operation = new ControlLoopOperation();
operation.actor = "APPC";
operation.operation = "ModifyConfig";
- operation.target = "VM";
+ operation.target = "VNF";
operation.end = Instant.now();
operation.subRequestId = "1";
@@ -77,7 +81,8 @@ public class AppcServiceProviderTest {
policy.setName("Modify Packet Generation Config");
policy.setDescription("Upon getting the trigger event, modify packet gen config");
policy.setActor("APPC");
- policy.setTarget(new Target(TargetType.VM));
+ policy.setTarget(new Target(TargetType.VNF));
+ policy.getTarget().setResourceID("Eace933104d443b496b8.nodes.heat.vpg");
policy.setRecipe("ModifyConfig");
policy.setPayload(null);
policy.setRetry(2);
@@ -85,6 +90,20 @@ public class AppcServiceProviderTest {
}
+ @BeforeClass
+ public static void setUpSimulator() {
+ try {
+ Util.buildAaiSim();
+ } catch (InterruptedException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @AfterClass
+ public static void tearDownSimulator() {
+ HttpServletServer.factory.destroy();
+ }
+
@Test
public void constructModifyConfigRequestTest() {
@@ -104,6 +123,7 @@ public class AppcServiceProviderTest {
/* A payload is required and cannot be null */
assertNotNull(appcRequest.getPayload());
assertTrue(appcRequest.getPayload().containsKey("generic-vnf.vnf-id"));
+ assertNotNull(appcRequest.getPayload().get("generic-vnf.vnf-id"));
assertTrue(appcRequest.getPayload().containsKey("pg-streams"));
logger.debug("APPC Request: \n" + appcRequest.toString());
diff --git a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java
index c52a7f08e..4ffbf6941 100644
--- a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java
+++ b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java
@@ -31,8 +31,11 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
+import org.onap.policy.aai.AAINQF199.AAINQF199InstanceFilters;
import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItem;
import org.onap.policy.aai.AAINQF199.AAINQF199Manager;
+import org.onap.policy.aai.AAINQF199.AAINQF199NamedQuery;
+import org.onap.policy.aai.AAINQF199.AAINQF199QueryParameters;
import org.onap.policy.aai.AAINQF199.AAINQF199Request;
import org.onap.policy.aai.AAINQF199.AAINQF199Response;
import org.onap.policy.appclcm.LCMCommonHeader;
@@ -91,6 +94,37 @@ public class AppcLcmActorServiceProvider implements Actor {
public List<String> recipePayloads(String recipe) {
return ImmutableList.copyOf(payloads.getOrDefault(recipe, Collections.emptyList()));
}
+
+ /**
+ * This method recursively traverses the A&AI named query response
+ * to find the generic-vnf object that contains a model-invariant-id
+ * that matches the resourceId of the policy. Once this match is found
+ * the generic-vnf object's vnf-id is returned.
+ *
+ * @param items
+ * the list of items related to the vnf returned by A&AI
+ * @param resourceId
+ * the id of the target from the sdc catalog
+ *
+ * @return the vnf-id of the target vnf to act upon or null if not found
+ */
+ private static String parseAAIResponse(List<AAINQF199InventoryResponseItem> items, String resourceId) {
+ String vnfId = null;
+ for (AAINQF199InventoryResponseItem item: items) {
+ if ((item.genericVNF != null)
+ && (item.genericVNF.modelInvariantId != null)
+ && (resourceId.equals(item.genericVNF.modelInvariantId))) {
+ vnfId = item.genericVNF.vnfID;
+ break;
+ }
+ else {
+ if((item.items != null) && (item.items.inventoryResponseItems != null)) {
+ vnfId = parseAAIResponse(item.items.inventoryResponseItems, resourceId);
+ }
+ }
+ }
+ return vnfId;
+ }
/**
* Constructs an A&AI Named Query using a source vnf-id to determine
@@ -105,30 +139,32 @@ public class AppcLcmActorServiceProvider implements Actor {
* @return the target entities vnf id to act upon
*/
public static String vnfNamedQuery(String resourceId, String sourceVnfId) {
- String targetVnfId = "";
- AAINQF199Request aaiRequest = new AAINQF199Request();
- UUID requestId = UUID.randomUUID();
+ //TODO: This request id should not be hard coded in future releases
+ UUID requestId = UUID.fromString("a93ac487-409c-4e8c-9e5f-334ae8f99087");
+
+ AAINQF199Request aaiRequest = new AAINQF199Request();
+ aaiRequest.queryParameters = new AAINQF199QueryParameters();
+ aaiRequest.queryParameters.namedQuery = new AAINQF199NamedQuery();
aaiRequest.queryParameters.namedQuery.namedQueryUUID = requestId;
- Map<String, Map<String, String>> filter = new HashMap<String, Map<String, String>>();
+ Map<String, Map<String, String>> filter = new HashMap<>();
+ Map<String, String> filterItem = new HashMap<>();
- Map<String, String> filterItem = new HashMap<String, String>();
filterItem.put("vnf-id", sourceVnfId);
-
filter.put("generic-vnf", filterItem);
+ aaiRequest.instanceFilters = new AAINQF199InstanceFilters();
aaiRequest.instanceFilters.instanceFilter.add(filter);
- //TODO: What is the url to use?
- AAINQF199Response aaiResponse = AAINQF199Manager.postQuery("http://localhost:6666", "policy", "policy", aaiRequest, requestId);
-
+ //TODO: URL should not be hard coded for future releases
+ AAINQF199Response aaiResponse = AAINQF199Manager.postQuery(
+ "http://localhost:6666",
+ "policy", "policy",
+ aaiRequest, requestId);
+
//TODO: What if the resourceId never matches?
- for (AAINQF199InventoryResponseItem item: aaiResponse.inventoryResponseItems) {
- if (item.genericVNF.modelInvariantId.equals(resourceId)) {
- targetVnfId = item.genericVNF.vnfID;
- }
- }
+ String targetVnfId = parseAAIResponse(aaiResponse.inventoryResponseItems, resourceId);
return targetVnfId;
}