aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharles Cole <cc847m@att.com>2017-10-20 08:52:59 -0500
committerCharles Cole <cc847m@att.com>2017-10-23 11:16:59 -0500
commit140980d872f84e854d636a21ca872b251b15891b (patch)
tree160fa25a01657b2fd32c984dbe4ae4b0f106a12b
parent2f1ee658482437e0c5b45451d20468411e2e2b6a (diff)
Fix handling of aai 'get' errors
Now reject an event if the AAI get query for the event fails. Added test cases for this behavior. Fixed some issues from my previous pull request. Issue-Id: POLICY-314 Change-Id: I674e95302a271423c307a88d061064e12e491a7a Signed-off-by: Charles Cole <cc847m@att.com>
-rw-r--r--controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java9
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java9
-rw-r--r--controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAIGETResponse.java3
-rw-r--r--controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAIManager.java2
-rw-r--r--controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAINQRequestError.java2
-rw-r--r--controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAINQServiceExcept.java (renamed from controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAINQServiceException.java)2
-rw-r--r--controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java30
-rw-r--r--controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl1
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java46
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java92
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java146
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java41
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java101
13 files changed, 354 insertions, 130 deletions
diff --git a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java
index 814726256..7bf5a2826 100644
--- a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java
+++ b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java
@@ -72,13 +72,14 @@ public class VFCActorServiceProvider implements Actor {
String serviceInstance = onset.AAI.get("service-instance.service-instance-id");
if (serviceInstance == null || "".equals(serviceInstance))
{
- if(vnfResponse == null) //if the response is null, we haven't queried
+ AAIGETVnfResponse tempVnfResp = vnfResponse;
+ if(tempVnfResp == null) //if the response is null, we haven't queried
{
- vnfResponse = getAAIServiceInstance(onset); //This does the AAI query since we haven't already
- if (vnfResponse == null)
+ tempVnfResp = getAAIServiceInstance(onset); //This does the AAI query since we haven't already
+ if (tempVnfResp == null)
return null;
}
- serviceInstance = vnfResponse.serviceId;
+ serviceInstance = tempVnfResp.serviceId;
}
request.nsInstanceId = serviceInstance;
request.requestId = onset.requestID;
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 2fc43a01c..9b2960e42 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
@@ -545,6 +545,9 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (vnfResponse == null) {
throw new ControlLoopException("AAI Response is null (query by vnf-id)");
}
+ if (vnfResponse.requestError != null) {
+ throw new ControlLoopException("AAI Responded with a request error (query by vnf-id)");
+ }
if (isClosedLoopDisabled(vnfResponse) == true) {
throw new ControlLoopException("is-closed-loop-disabled is set to true");
}
@@ -553,6 +556,9 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (vnfResponse == null) {
throw new ControlLoopException("AAI Response is null (query by vnf-name)");
}
+ if (vnfResponse.requestError != null) {
+ throw new ControlLoopException("AAI Responded with a request error (query by vnf-name)");
+ }
if (isClosedLoopDisabled(vnfResponse) == true) {
throw new ControlLoopException("is-closed-loop-disabled is set to true");
}
@@ -561,6 +567,9 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (vserverResponse == null) {
throw new ControlLoopException("AAI Response is null (query by vserver-name)");
}
+ if (vserverResponse.requestError != null) {
+ throw new ControlLoopException("AAI responded with a request error (query by vserver-name)");
+ }
if (isClosedLoopDisabled(vserverResponse) == true) {
throw new ControlLoopException("is-closed-loop-disabled is set to true");
}
diff --git a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAIGETResponse.java b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAIGETResponse.java
index 46a4e5080..caba0596f 100644
--- a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAIGETResponse.java
+++ b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAIGETResponse.java
@@ -45,6 +45,9 @@ public class AAIGETResponse implements Serializable {
@SerializedName("relationship-list")
public RelationshipList relationshipList;
+
+ @SerializedName("requestError")
+ public AAINQRequestError requestError;
public AAIGETResponse() {
}
diff --git a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAIManager.java b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAIManager.java
index 6a0fb3adb..e22fe00e3 100644
--- a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAIManager.java
+++ b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAIManager.java
@@ -49,7 +49,7 @@ public final class AAIManager {
String requestJson = Serialization.gsonPretty.toJson(request);
netLogger.info("[OUT|{}|{}|]{}{}", "AAI", url, System.lineSeparator(), requestJson);
Pair<Integer, String> httpDetails = RESTManager.post(url, username, password, headers, "application/json", requestJson);
- logger.debug("RESTManager.post after");
+ logger.debug("RESTManager.post after");
if (httpDetails == null) {
logger.info("AAI POST Null Response to " + url);
diff --git a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAINQRequestError.java b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAINQRequestError.java
index f6439cc4a..f2498fb6e 100644
--- a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAINQRequestError.java
+++ b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAINQRequestError.java
@@ -29,5 +29,5 @@ public class AAINQRequestError implements Serializable {
private static final long serialVersionUID = -7742674155387022932L;
@SerializedName("serviceException")
- public AAINQServiceException serviceException;
+ public AAINQServiceExcept serviceExcept;
}
diff --git a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAINQServiceException.java b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAINQServiceExcept.java
index 64d407de4..acee98f04 100644
--- a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAINQServiceException.java
+++ b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AAINQServiceExcept.java
@@ -24,7 +24,7 @@ import java.io.Serializable;
import com.google.gson.annotations.SerializedName;
-public class AAINQServiceException implements Serializable {
+public class AAINQServiceExcept implements Serializable {
private static final long serialVersionUID = 2858343404484338546L;
diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java
index 4075fda06..03686a860 100644
--- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java
+++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java
@@ -26,6 +26,7 @@ import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.onap.policy.aai.AAINQRequest;
@@ -52,9 +53,15 @@ public class AaiSimulatorJaxRs {
AAINQRequest request = Serialization.gsonPretty.fromJson(req, AAINQRequest.class);
if (request.instanceFilters.instanceFilter.get(0).containsKey("vserver"))
- {
- // vll format - new
- return "{\"inventory-response-item\":[{\"extra-properties\":{},\"inventory-response-items\":{\"inventory-response-item\":[{\"extra-properties\":{\"extra-property\":[{\"property-name\":\"model-ver.model-version-id\",\"property-value\":\"93a6166f-b3d5-4f06-b4ba-aed48d009ad9\"},{\"property-name\":\"model-ver.model-name\",\"property-value\":\"generic-vnf\"},{\"property-name\":\"model.model-type\",\"property-value\":\"widget\"},{\"property-name\":\"model.model-invariant-id\",\"property-value\":\"acc6edd8-a8d4-4b93-afaa-0994068be14c\"},{\"property-name\":\"model-ver.model-version\",\"property-value\":\"1.0\"}]},\"generic-vnf\":{\"in-maint\":false,\"is-closed-loop-disabled\":false,\"model-invariant-id\":\"acc6edd8-a8d4-4b93-afaa-0994068be14c\",\"model-version-id\":\"93a6166f-b3d5-4f06-b4ba-aed48d009ad9\",\"orchestration-status\":\"Created\",\"resource-version\":\"1507826325834\",\"service-id\":\"b3f70641-bdb9-4030-825e-6abb73a1f929\",\"vnf-id\":\"594e2fe0-48b8-41ff-82e2-3d4bab69b192\",\"vnf-name\":\"Vnf_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8\",\"vnf-type\":\"8330e932-2a23-4943-8606/c15ce9e1-e914-4c8f-b8bb 1\"},\"inventory-response-items\":{\"inventory-response-item\":[{\"extra-properties\":{\"extra-property\":[{\"property-name\":\"model-ver.model-version-id\",\"property-value\":\"46b92144-923a-4d20-b85a-3cbd847668a9\"},{\"property-name\":\"model-ver.model-name\",\"property-value\":\"service-instance\"},{\"property-name\":\"model.model-type\",\"property-value\":\"widget\"},{\"property-name\":\"model.model-invariant-id\",\"property-value\":\"82194af1-3c2c-485a-8f44-420e22a9eaa4\"},{\"property-name\":\"model-ver.model-version\",\"property-value\":\"1.0\"}]},\"model-name\":\"service-instance\",\"service-instance\":{\"model-invariant-id\":\"82194af1-3c2c-485a-8f44-420e22a9eaa4\",\"model-version-id\":\"46b92144-923a-4d20-b85a-3cbd847668a9\",\"resource-version\":\"1507827626200\",\"service-instance-id\":\"cf8426a6-0b53-4e3d-bfa6-4b2f4d5913a5\",\"service-instance-name\":\"Service_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8\"}},{\"extra-properties\":{\"extra-property\":[{\"property-name\":\"model-ver.model-version-id\",\"property-value\":\"93a6166f-b3d5-4f06-b4ba-aed48d009ad9\"},{\"property-name\":\"model-ver.model-name\",\"property-value\":\"generic-vnf\"},{\"property-name\":\"model.model-type\",\"property-value\":\"widget\"},{\"property-name\":\"model.model-invariant-id\",\"property-value\":\"acc6edd8-a8d4-4b93-afaa-0994068be14c\"},{\"property-name\":\"model-ver.model-version\",\"property-value\":\"1.0\"}]},\"model-name\":\"generic-vnf\",\"vf-module\":{\"heat-stack-id\":\"Vfmodule_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8/5845f37b-6cda-4e91-8ca3-f5572d226488\",\"is-base-vf-module\":true,\"model-invariant-id\":\"acc6edd8-a8d4-4b93-afaa-0994068be14c\",\"model-version-id\":\"93a6166f-b3d5-4f06-b4ba-aed48d009ad9\",\"orchestration-status\":\"active\",\"resource-version\":\"1507826326804\",\"vf-module-id\":\"b0eff878-e2e1-4947-9597-39afdd0f51dd\",\"vf-module-name\":\"Vfmodule_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8\"}}]},\"model-name\":\"generic-vnf\"},{\"extra-properties\":{},\"inventory-response-items\":{\"inventory-response-item\":[{\"cloud-region\":{\"cloud-owner\":\"Rackspace\",\"cloud-region-id\":\"DFW\",\"cloud-region-version\":\"v1\",\"cloud-type\":\"SharedNode\",\"cloud-zone\":\"CloudZone\",\"owner-defined-type\":\"OwnerType\",\"resource-version\":\"1507828410019\",\"sriov-automation\":false},\"extra-properties\":{}}]},\"tenant\":{\"resource-version\":\"1507828410764\",\"tenant-id\":\"1015548\",\"tenant-name\":\"1015548\"}}]},\"vserver\":{\"in-maint\":false,\"is-closed-loop-disabled\":false,\"prov-status\":\"ACTIVE\",\"resource-version\":\"1507828410832\",\"vserver-id\":\"70f081eb-2a87-4c81-9296-4b93d7d145c6\",\"vserver-name\":\"vlb-lb-32c8\",\"vserver-name2\":\"vlb-lb-32c8\",\"vserver-selflink\":\"https://aai.api.simpledemo.openecomp.org:8443/aai/v11/nodes/vservers?vserver-name=vlb-lb-32c8\"}}]}";
+ {
+ String vserverName = request.instanceFilters.instanceFilter.get(0).get("vserver").get("vserver-name");
+ if ("error".equals(vserverName)) {
+ return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"POST Search\",\"getNamedQueryResponse\",\"Node Not Found:No Node of type vserver found for properties\",\"ERR.5.4.6114\"]}}}";
+ }
+ else {
+ // vll format - new
+ return "{\"inventory-response-item\":[{\"extra-properties\":{},\"inventory-response-items\":{\"inventory-response-item\":[{\"extra-properties\":{\"extra-property\":[{\"property-name\":\"model-ver.model-version-id\",\"property-value\":\"93a6166f-b3d5-4f06-b4ba-aed48d009ad9\"},{\"property-name\":\"model-ver.model-name\",\"property-value\":\"generic-vnf\"},{\"property-name\":\"model.model-type\",\"property-value\":\"widget\"},{\"property-name\":\"model.model-invariant-id\",\"property-value\":\"acc6edd8-a8d4-4b93-afaa-0994068be14c\"},{\"property-name\":\"model-ver.model-version\",\"property-value\":\"1.0\"}]},\"generic-vnf\":{\"in-maint\":false,\"is-closed-loop-disabled\":false,\"model-invariant-id\":\"acc6edd8-a8d4-4b93-afaa-0994068be14c\",\"model-version-id\":\"93a6166f-b3d5-4f06-b4ba-aed48d009ad9\",\"orchestration-status\":\"Created\",\"resource-version\":\"1507826325834\",\"service-id\":\"b3f70641-bdb9-4030-825e-6abb73a1f929\",\"vnf-id\":\"594e2fe0-48b8-41ff-82e2-3d4bab69b192\",\"vnf-name\":\"Vnf_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8\",\"vnf-type\":\"8330e932-2a23-4943-8606/c15ce9e1-e914-4c8f-b8bb 1\"},\"inventory-response-items\":{\"inventory-response-item\":[{\"extra-properties\":{\"extra-property\":[{\"property-name\":\"model-ver.model-version-id\",\"property-value\":\"46b92144-923a-4d20-b85a-3cbd847668a9\"},{\"property-name\":\"model-ver.model-name\",\"property-value\":\"service-instance\"},{\"property-name\":\"model.model-type\",\"property-value\":\"widget\"},{\"property-name\":\"model.model-invariant-id\",\"property-value\":\"82194af1-3c2c-485a-8f44-420e22a9eaa4\"},{\"property-name\":\"model-ver.model-version\",\"property-value\":\"1.0\"}]},\"model-name\":\"service-instance\",\"service-instance\":{\"model-invariant-id\":\"82194af1-3c2c-485a-8f44-420e22a9eaa4\",\"model-version-id\":\"46b92144-923a-4d20-b85a-3cbd847668a9\",\"resource-version\":\"1507827626200\",\"service-instance-id\":\"cf8426a6-0b53-4e3d-bfa6-4b2f4d5913a5\",\"service-instance-name\":\"Service_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8\"}},{\"extra-properties\":{\"extra-property\":[{\"property-name\":\"model-ver.model-version-id\",\"property-value\":\"93a6166f-b3d5-4f06-b4ba-aed48d009ad9\"},{\"property-name\":\"model-ver.model-name\",\"property-value\":\"generic-vnf\"},{\"property-name\":\"model.model-type\",\"property-value\":\"widget\"},{\"property-name\":\"model.model-invariant-id\",\"property-value\":\"acc6edd8-a8d4-4b93-afaa-0994068be14c\"},{\"property-name\":\"model-ver.model-version\",\"property-value\":\"1.0\"}]},\"model-name\":\"generic-vnf\",\"vf-module\":{\"heat-stack-id\":\"Vfmodule_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8/5845f37b-6cda-4e91-8ca3-f5572d226488\",\"is-base-vf-module\":true,\"model-invariant-id\":\"acc6edd8-a8d4-4b93-afaa-0994068be14c\",\"model-version-id\":\"93a6166f-b3d5-4f06-b4ba-aed48d009ad9\",\"orchestration-status\":\"active\",\"resource-version\":\"1507826326804\",\"vf-module-id\":\"b0eff878-e2e1-4947-9597-39afdd0f51dd\",\"vf-module-name\":\"Vfmodule_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8\"}}]},\"model-name\":\"generic-vnf\"},{\"extra-properties\":{},\"inventory-response-items\":{\"inventory-response-item\":[{\"cloud-region\":{\"cloud-owner\":\"Rackspace\",\"cloud-region-id\":\"DFW\",\"cloud-region-version\":\"v1\",\"cloud-type\":\"SharedNode\",\"cloud-zone\":\"CloudZone\",\"owner-defined-type\":\"OwnerType\",\"resource-version\":\"1507828410019\",\"sriov-automation\":false},\"extra-properties\":{}}]},\"tenant\":{\"resource-version\":\"1507828410764\",\"tenant-id\":\"1015548\",\"tenant-name\":\"1015548\"}}]},\"vserver\":{\"in-maint\":false,\"is-closed-loop-disabled\":false,\"prov-status\":\"ACTIVE\",\"resource-version\":\"1507828410832\",\"vserver-id\":\"70f081eb-2a87-4c81-9296-4b93d7d145c6\",\"vserver-name\":\"vlb-lb-32c8\",\"vserver-name2\":\"vlb-lb-32c8\",\"vserver-selflink\":\"https://aai.api.simpledemo.openecomp.org:8443/aai/v11/nodes/vservers?vserver-name=vlb-lb-32c8\"}}]}";
+ }
}
else
{
@@ -69,11 +76,14 @@ public class AaiSimulatorJaxRs {
}
@GET
- @Path("/v11/network/generic-vnfs/generic-vnf?vnf-name={vnfName}")
+ @Path("/v11/network/generic-vnfs/generic-vnf")
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json")
- public String getByVnfName (@PathParam("vnfName") String vnfName)
+ public String getByVnfName (@QueryParam("vnfName") String vnfName)
{
+ if ("getFail".equals(vnfName)) {
+ return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/generic-vnf\",\"Node Not Found:No Node of type generic-vnf found at network/generic-vnfs/generic-vnf\",\"ERR.5.4.6114\"]}}}";
+ }
boolean isDisabled = "disableClosedLoop".equals(vnfName);
return "{ \"vnf-id\": \"5e49ca06-2972-4532-9ed4-6d071588d792\", \"vnf-name\": \"" + vnfName + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \"equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \"ATT\", \"ipv4-oam-address\": \"32.40.68.35\", \"ipv4-loopback0-address\": \"32.40.64.57\", \"nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345\", \"management-v6-address\": \"2001:1890:e00e:fffd::36\", \"in-maint\": false, \"is-closed-loop-disabled\": " + isDisabled + ", \"resource-version\": \"1493389458092\", \"relationship-list\": {\"relationship\":[{ \"related-to\": \"service-instance\", \"related-link\": \"/aai/v11/business/customers/customer/1610_Func_Global_20160817084727/service-subscriptions/service-subscription/uCPE-VMS/service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \"relationship-data\":[{ \"relationship-key\": \"customer.global-customer-id\", \"relationship-value\": \"1610_Func_Global_20160817084727\"},{ \"relationship-key\": \"service-subscription.service-type\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key\": \"service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01\"} ], \"related-to-property\": [{\"property-key\": \"service-instance.service-instance-name\"}]},{ \"related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver/3b2558f4-39d8-40e7-bfc7-30660fb52c45\", \"relationship-data\":[{ \"relationship-key\": \"cloud-region.cloud-owner\", \"relationship-value\": \"att-aic\"},{ \"relationship-key\": \"cloud-region.cloud-region-id\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \"tenant.tenant-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \"relationship-key\": \"vserver.vserver-id\", \"relationship-value\": \"3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \"related-to-property\": [ {\"property-key\": \"vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
}
@@ -84,16 +94,22 @@ public class AaiSimulatorJaxRs {
@Produces("application/json")
public String getByVnfId (@PathParam("vnfId") String vnfId)
{
+ if ("getFail".equals(vnfId)) {
+ return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/generic-vnf/getFail\",\"Node Not Found:No Node of type generic-vnf found at network/generic-vnfs/generic-vnf/getFail\",\"ERR.5.4.6114\"]}}}";
+ }
boolean isDisabled = "disableClosedLoop".equals(vnfId);
return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"USUCP0PCOIL0110UJRT01\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \"equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \"ATT\", \"ipv4-oam-address\": \"32.40.68.35\", \"ipv4-loopback0-address\": \"32.40.64.57\", \"nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345\", \"management-v6-address\": \"2001:1890:e00e:fffd::36\", \"in-maint\": false, \"is-closed-loop-disabled\": " + isDisabled + ", \"resource-version\": \"1493389458092\", \"relationship-list\": {\"relationship\":[{ \"related-to\": \"service-instance\", \"related-link\": \"/aai/v11/business/customers/customer/1610_Func_Global_20160817084727/service-subscriptions/service-subscription/uCPE-VMS/service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \"relationship-data\":[{ \"relationship-key\": \"customer.global-customer-id\", \"relationship-value\": \"1610_Func_Global_20160817084727\"},{ \"relationship-key\": \"service-subscription.service-type\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key\": \"service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01\"} ], \"related-to-property\": [{\"property-key\": \"service-instance.service-instance-name\"}]},{ \"related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver/3b2558f4-39d8-40e7-bfc7-30660fb52c45\", \"relationship-data\":[{ \"relationship-key\": \"cloud-region.cloud-owner\", \"relationship-value\": \"att-aic\"},{ \"relationship-key\": \"cloud-region.cloud-region-id\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \"tenant.tenant-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \"relationship-key\": \"vserver.vserver-id\", \"relationship-value\": \"3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \"related-to-property\": [ {\"property-key\": \"vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
}
@GET
- @Path("/v11/nodes/vservers?vserver-name={vserverName}")
+ @Path("/v11/nodes/vservers")
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json")
- public String getByVserverName (@PathParam("vserverName") String vserverName)
+ public String getByVserverName (@QueryParam("vserverName") String vserverName)
{
+ if ("getFail".equals(vserverName)) {
+ return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"nodes/vservers\",\"Node Not Found:No Node of type generic-vnf found at nodes/vservers\",\"ERR.5.4.6114\"]}}}";
+ }
boolean isDisabled = "disableClosedLoop".equals(vserverName);
return "{\"vserver\": [{ \"vserver-id\": \"d0668d4f-c25e-4a1b-87c4-83845c01efd8\", \"vserver-name\": \"" + vserverName + "\", \"vserver-name2\": \"vjunos0\", \"vserver-selflink\": \"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\", \"in-maint\": false, \"is-closed-loop-disabled\": " + isDisabled + ", \"resource-version\": \"1494001931513\", \"relationship-list\": {\"relationship\":[{ \"related-to\": \"generic-vnf\", \"related-link\": \"/aai/v11/network/generic-vnfs/generic-vnf/e1a41e99-4ede-409a-8f9d-b5e12984203a\", \"relationship-data\": [ {\"relationship-key\": \"generic-vnf.vnf-id\",\"relationship-value\": \"e1a41e99-4ede-409a-8f9d-b5e12984203a\" }], \"related-to-property\": [ {\"property-key\": \"generic-vnf.vnf-name\",\"property-value\": \"USMSO1SX7NJ0103UJSW01\" }]},{ \"related-to\": \"pserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/pservers/pserver/USMSO1SX7NJ0103UJZZ01\", \"relationship-data\": [ {\"relationship-key\": \"pserver.hostname\",\"relationship-value\": \"USMSO1SX7NJ0103UJZZ01\" }], \"related-to-property\": [{\"property-key\": \"pserver.pserver-name2\"}]} ]}}]}";
}
diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
index 705bbcd25..65a601188 100644
--- a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
+++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
@@ -585,6 +585,7 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
$params.getClosedLoopControlName(),
drools.getRule().getName());
if ("SO".equals($operation.policy.getActor())) {
+ retract($opTimer);
retract($operation);
modify($manager) {finishOperation($operation)};
}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java
index f07ecbfae..9b3fbfe72 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java
@@ -62,8 +62,8 @@ public class ControlLoopFailureTest implements TopicListener {
private static List<? extends TopicSink> noopTopics;
- private KieSession kieSession;
- private Util.Pair<ControlLoopPolicy, String> pair;
+ private static KieSession kieSession;
+ private static Util.Pair<ControlLoopPolicy, String> pair;
private UUID requestId;
private UUID requestId2;
private UUID requestId3;
@@ -96,12 +96,34 @@ public class ControlLoopFailureTest implements TopicListener {
} catch (Exception e) {
fail(e.getMessage());
}
+
+ /*
+ * Start the kie session
+ */
+ try {
+ kieSession = startSession("../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
+ "src/test/resources/yaml/policy_ControlLoop_vCPE.yaml",
+ "service=ServiceDemo;resource=Res1Demo;type=operational",
+ "CL_vCPE",
+ "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
+ } catch (IOException e) {
+ e.printStackTrace();
+ logger.debug("Could not create kieSession");
+ fail("Could not create kieSession");
+ }
}
@AfterClass
public static void tearDownSimulator() {
+ /*
+ * Gracefully shut down the kie session
+ */
+ kieSession.dispose();
+
HttpServletServer.factory.destroy();
PolicyEngine.manager.shutdown();
+ TopicEndpoint.manager.shutdown();
+ PolicyEngine.manager.stop();
}
/**
@@ -118,20 +140,6 @@ public class ControlLoopFailureTest implements TopicListener {
*/
@Test
public void targetLockedTest() {
- /*
- * Start the kie session
- */
- try {
- kieSession = startSession("../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
- "src/test/resources/yaml/policy_ControlLoop_vCPE.yaml",
- "service=ServiceDemo;resource=Res1Demo;type=operational",
- "CL_vCPE",
- "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
- } catch (IOException e) {
- e.printStackTrace();
- logger.debug("Could not create kieSession");
- fail("Could not create kieSession");
- }
/*
* Allows the PolicyEngine to callback to this object to
@@ -187,10 +195,6 @@ public class ControlLoopFailureTest implements TopicListener {
*/
dumpFacts(kieSession);
- /*
- * Gracefully shut down the kie session
- */
- kieSession.dispose();
}
/**
@@ -210,7 +214,7 @@ public class ControlLoopFailureTest implements TopicListener {
* @return the kieSession to be used to insert facts
* @throws IOException
*/
- private KieSession startSession(String droolsTemplate,
+ private static KieSession startSession(String droolsTemplate,
String yamlFile,
String policyScope,
String policyName,
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java
index ae8bcb4e4..bae7a5155 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java
@@ -62,8 +62,8 @@ public class VCPEControlLoopTest implements TopicListener {
private static List<? extends TopicSink> noopTopics;
- private KieSession kieSession;
- private Util.Pair<ControlLoopPolicy, String> pair;
+ private static KieSession kieSession;
+ private static Util.Pair<ControlLoopPolicy, String> pair;
private UUID requestID;
static {
@@ -93,16 +93,6 @@ public class VCPEControlLoopTest implements TopicListener {
} catch (Exception e) {
fail(e.getMessage());
}
- }
-
- @AfterClass
- public static void tearDownSimulator() {
- HttpServletServer.factory.destroy();
- PolicyEngine.manager.shutdown();
- }
-
- @Test
- public void successTest() {
/*
* Start the kie session
*/
@@ -117,6 +107,23 @@ public class VCPEControlLoopTest implements TopicListener {
logger.debug("Could not create kieSession");
fail("Could not create kieSession");
}
+ }
+
+ @AfterClass
+ public static void tearDownSimulator() {
+ /*
+ * Gracefully shut down the kie session
+ */
+ kieSession.dispose();
+
+ HttpServletServer.factory.destroy();
+ PolicyEngine.manager.shutdown();
+ TopicEndpoint.manager.shutdown();
+ PolicyEngine.manager.stop();
+ }
+
+ @Test
+ public void successTest() {
/*
* Allows the PolicyEngine to callback to this object to
@@ -152,11 +159,46 @@ public class VCPEControlLoopTest implements TopicListener {
* Print what's left in memory
*/
dumpFacts(kieSession);
+ }
+
+ @Test
+ public void aaiGetFailTest() {
/*
- * Gracefully shut down the kie session
+ * Allows the PolicyEngine to callback to this object to
+ * notify that there is an event ready to be pulled
+ * from the queue
*/
- kieSession.dispose();
+ for (TopicSink sink : noopTopics) {
+ assertTrue(sink.start());
+ sink.register(this);
+ }
+
+ /*
+ * Create a unique requestId
+ */
+ requestID = UUID.randomUUID();
+
+ /*
+ * Simulate an onset event the policy engine will
+ * receive from DCAE to kick off processing through
+ * the rules
+ */
+ sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "getFail");
+
+
+ kieSession.fireUntilHalt();
+
+ /*
+ * The only fact in memory should be Params
+ */
+ assertEquals(1, kieSession.getFactCount());
+
+ /*
+ * Print what's left in memory
+ */
+ dumpFacts(kieSession);
+
}
/**
@@ -176,7 +218,7 @@ public class VCPEControlLoopTest implements TopicListener {
* @return the kieSession to be used to insert facts
* @throws IOException
*/
- private KieSession startSession(String droolsTemplate,
+ private static KieSession startSession(String droolsTemplate,
String yamlFile,
String policyScope,
String policyName,
@@ -234,7 +276,13 @@ public class VCPEControlLoopTest implements TopicListener {
String policyName = notification.policyName;
if (policyName.endsWith("EVENT")) {
logger.debug("Rule Fired: " + notification.policyName);
- assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
+ if ("getFail".equals(notification.AAI.get("generic-vnf.vnf-id"))) {
+ assertEquals(ControlLoopNotificationType.REJECTED, notification.notification);
+ kieSession.halt();
+ }
+ else {
+ assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
+ }
}
else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) {
logger.debug("Rule Fired: " + notification.policyName);
@@ -324,6 +372,18 @@ public class VCPEControlLoopTest implements TopicListener {
kieSession.insert(event);
}
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String vnfId) {
+ VirtualControlLoopEvent event = new VirtualControlLoopEvent();
+ event.closedLoopControlName = policy.getControlLoop().getControlLoopName();
+ event.requestID = requestID;
+ event.target = "generic-vnf.vnf-id";
+ event.closedLoopAlarmStart = Instant.now();
+ event.AAI = new HashMap<>();
+ event.AAI.put("generic-vnf.vnf-id", vnfId);
+ event.closedLoopEventStatus = status;
+ kieSession.insert(event);
+ }
+
/**
* This method will dump all the facts in the working memory.
*
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java
index c64764baf..9b9c2fe7c 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java
@@ -62,8 +62,8 @@ public class VDNSControlLoopTest implements TopicListener {
private static List<? extends TopicSink> noopTopics;
- private KieSession kieSession;
- private Util.Pair<ControlLoopPolicy, String> pair;
+ private static KieSession kieSession;
+ private static Util.Pair<ControlLoopPolicy, String> pair;
private UUID requestID;
static {
@@ -93,17 +93,7 @@ public class VDNSControlLoopTest implements TopicListener {
} catch (Exception e) {
fail(e.getMessage());
}
- }
-
- @AfterClass
- public static void tearDownSimulator() {
- HttpServletServer.factory.destroy();
- PolicyEngine.manager.shutdown();
- }
-
- @Test
- public void successTest() {
-
+
/*
* Start the kie session
*/
@@ -118,6 +108,24 @@ public class VDNSControlLoopTest implements TopicListener {
logger.debug("Could not create kieSession");
fail("Could not create kieSession");
}
+ }
+
+ @AfterClass
+ public static void tearDownSimulator() {
+
+ /*
+ * Gracefully shut down the kie session
+ */
+ kieSession.dispose();
+
+ HttpServletServer.factory.destroy();
+ PolicyEngine.manager.shutdown();
+ TopicEndpoint.manager.shutdown();
+ PolicyEngine.manager.stop();
+ }
+
+ @Test
+ public void successTest() {
/*
* Allows the PolicyEngine to callback to this object to
@@ -152,11 +160,90 @@ public class VDNSControlLoopTest implements TopicListener {
* Print what's left in memory
*/
dumpFacts(kieSession);
+ }
+
+ @Test
+ public void namedQueryFailTest() {
/*
- * Gracefully shut down the kie session
+ * Allows the PolicyEngine to callback to this object to
+ * notify that there is an event ready to be pulled
+ * from the queue
*/
- kieSession.dispose();
+ for (TopicSink sink : noopTopics) {
+ assertTrue(sink.start());
+ sink.register(this);
+ }
+
+ /*
+ * Create a unique requestId
+ */
+ requestID = UUID.randomUUID();
+
+ /*
+ * Simulate an onset event the policy engine will
+ * receive from DCAE to kick off processing through
+ * the rules
+ */
+ sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "error");
+
+ kieSession.fireUntilHalt();
+
+ /*
+ * The only fact in memory should be Params
+ */
+ assertEquals(1, kieSession.getFactCount());
+
+ /*
+ * Print what's left in memory
+ */
+ dumpFacts(kieSession);
+ }
+
+ @Test
+ public void aaiGetFailTest() {
+
+ /*
+ * Allows the PolicyEngine to callback to this object to
+ * notify that there is an event ready to be pulled
+ * from the queue
+ */
+ for (TopicSink sink : noopTopics) {
+ assertTrue(sink.start());
+ sink.register(this);
+ }
+
+ /*
+ * Create a unique requestId
+ */
+ requestID = UUID.randomUUID();
+
+ /*
+ * Simulate an onset event the policy engine will
+ * receive from DCAE to kick off processing through
+ * the rules
+ */
+ sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "getFail");
+
+ try {
+ kieSession.fireUntilHalt();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ logger.warn(e.toString());
+ fail(e.getMessage());
+ }
+
+
+ /*
+ * The only fact in memory should be Params
+ */
+ assertEquals(1, kieSession.getFactCount());
+
+ /*
+ * Print what's left in memory
+ */
+ dumpFacts(kieSession);
}
/**
@@ -176,7 +263,7 @@ public class VDNSControlLoopTest implements TopicListener {
* @return the kieSession to be used to insert facts
* @throws IOException
*/
- private KieSession startSession(String droolsTemplate,
+ private static KieSession startSession(String droolsTemplate,
String yamlFile,
String policyScope,
String policyName,
@@ -232,7 +319,13 @@ public class VDNSControlLoopTest implements TopicListener {
String policyName = notification.policyName;
if (policyName.endsWith("EVENT")) {
logger.debug("Rule Fired: " + notification.policyName);
- assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
+ if ("getFail".equals(notification.AAI.get("generic-vnf.vnf-id"))) {
+ assertEquals(ControlLoopNotificationType.REJECTED, notification.notification);
+ kieSession.halt();
+ }
+ else {
+ assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
+ }
}
else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) {
logger.debug("Rule Fired: " + notification.policyName);
@@ -266,7 +359,12 @@ public class VDNSControlLoopTest implements TopicListener {
}
else if (policyName.endsWith("EVENT.MANAGER")) {
logger.debug("Rule Fired: " + notification.policyName);
- assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification));
+ if ("error".equals(notification.AAI.get("vserver.vserver-name"))) {
+ assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification);
+ }
+ else {
+ assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification));
+ }
kieSession.halt();
}
else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) {
@@ -303,6 +401,18 @@ public class VDNSControlLoopTest implements TopicListener {
kieSession.insert(event);
}
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String vserverName) {
+ VirtualControlLoopEvent event = new VirtualControlLoopEvent();
+ event.closedLoopControlName = policy.getControlLoop().getControlLoopName();
+ event.requestID = requestID;
+ event.target = "vserver.vserver-name";
+ event.closedLoopAlarmStart = Instant.now();
+ event.AAI = new HashMap<>();
+ event.AAI.put("vserver.vserver-name", vserverName);
+ event.closedLoopEventStatus = status;
+ kieSession.insert(event);
+ }
+
/**
* This method will dump all the facts in the working memory.
*
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java
index c139ab339..4a2b81399 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java
@@ -64,8 +64,8 @@ public class VFCControlLoopTest implements TopicListener {
private static List<? extends TopicSink> noopTopics;
- private KieSession kieSession;
- private Util.Pair<ControlLoopPolicy, String> pair;
+ private static KieSession kieSession;
+ private static Util.Pair<ControlLoopPolicy, String> pair;
private UUID requestID;
static {
@@ -95,18 +95,8 @@ public class VFCControlLoopTest implements TopicListener {
} catch (Exception e) {
fail(e.getMessage());
}
- }
-
- @AfterClass
- public static void tearDownSimulator() {
- HttpServletServer.factory.destroy();
- PolicyEngine.manager.shutdown();
- }
-
- @Test
- public void successTest() throws IOException {
-
/*
+ *
* Start the kie session
*/
try {
@@ -120,6 +110,24 @@ public class VFCControlLoopTest implements TopicListener {
logger.debug("Could not create kieSession");
fail("Could not create kieSession");
}
+ }
+
+ @AfterClass
+ public static void tearDownSimulator() {
+
+ /*
+ * Gracefully shut down the kie session
+ */
+ kieSession.dispose();
+
+ HttpServletServer.factory.destroy();
+ PolicyEngine.manager.shutdown();
+ TopicEndpoint.manager.shutdown();
+ PolicyEngine.manager.stop();
+ }
+
+ @Test
+ public void successTest() throws IOException {
/*
* Allows the PolicyEngine to callback to this object to
@@ -154,11 +162,6 @@ public class VFCControlLoopTest implements TopicListener {
* Print what's left in memory
*/
dumpFacts(kieSession);
-
- /*
- * Gracefully shut down the kie session
- */
- kieSession.dispose();
}
/**
@@ -178,7 +181,7 @@ public class VFCControlLoopTest implements TopicListener {
* @return the kieSession to be used to insert facts
* @throws IOException
*/
- private KieSession startSession(String droolsTemplate,
+ private static KieSession startSession(String droolsTemplate,
String yamlFile,
String policyScope,
String policyName,
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java
index 6424d02b6..54591cad0 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java
@@ -35,7 +35,6 @@ import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;
@@ -65,8 +64,8 @@ public class VFWControlLoopTest implements TopicListener {
private static List<? extends TopicSink> noopTopics;
- private KieSession kieSession;
- private Util.Pair<ControlLoopPolicy, String> pair;
+ private static KieSession kieSession;
+ private static Util.Pair<ControlLoopPolicy, String> pair;
private UUID requestID;
static {
@@ -97,16 +96,6 @@ public class VFWControlLoopTest implements TopicListener {
} catch (Exception e) {
fail(e.getMessage());
}
- }
-
- @AfterClass
- public static void tearDownSimulator() {
- HttpServletServer.factory.destroy();
- PolicyEngine.manager.shutdown();
- }
-
- @Test
- public void successTest() {
/*
* Start the kie session
@@ -122,8 +111,25 @@ public class VFWControlLoopTest implements TopicListener {
logger.debug("Could not create kieSession");
fail("Could not create kieSession");
}
+ }
+
+ @AfterClass
+ public static void tearDownSimulator() {
+ /*
+ * Gracefully shut down the kie session
+ */
+ kieSession.dispose();
- /*
+ HttpServletServer.factory.destroy();
+ PolicyEngine.manager.shutdown();
+ TopicEndpoint.manager.shutdown();
+ PolicyEngine.manager.stop();
+ }
+
+ @Test
+ public void successTest() {
+
+ /*
* Allows the PolicyEngine to callback to this object to
* notify that there is an event ready to be pulled
* from the queue
@@ -132,7 +138,7 @@ public class VFWControlLoopTest implements TopicListener {
assertTrue(sink.start());
sink.register(this);
}
-
+
/*
* Create a unique requestId
*/
@@ -164,30 +170,10 @@ public class VFWControlLoopTest implements TopicListener {
* Print what's left in memory
*/
dumpFacts(kieSession);
-
- /*
- * Gracefully shut down the kie session
- */
- kieSession.dispose();
}
@Test
- public void namedQueryFailTest() {
-
- /*
- * Start the kie session
- */
- try {
- kieSession = startSession("../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
- "src/test/resources/yaml/policy_ControlLoop_vFW.yaml",
- "service=ServiceDemo;resource=Res1Demo;type=operational",
- "CL_vFW",
- "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
- } catch (IOException e) {
- e.printStackTrace();
- logger.debug("Could not create kieSession");
- fail("Could not create kieSession");
- }
+ public void aaiFailTests() {
/*
* Allows the PolicyEngine to callback to this object to
@@ -210,7 +196,6 @@ public class VFWControlLoopTest implements TopicListener {
* the rules
*/
sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "error");
-
try {
kieSession.fireUntilHalt();
}
@@ -220,7 +205,6 @@ public class VFWControlLoopTest implements TopicListener {
fail(e.getMessage());
}
-
/*
* The only fact in memory should be Params
*/
@@ -232,9 +216,36 @@ public class VFWControlLoopTest implements TopicListener {
dumpFacts(kieSession);
/*
- * Gracefully shut down the kie session
+ * Create a unique requestId
*/
- kieSession.dispose();
+ requestID = UUID.randomUUID();
+
+ /*
+ * Simulate an onset event the policy engine will
+ * receive from DCAE to kick off processing through
+ * the rules
+ */
+
+ sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "getFail");
+
+ try {
+ kieSession.fireUntilHalt();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ logger.warn(e.toString());
+ fail(e.getMessage());
+ }
+
+ /*
+ * The only fact in memory should be Params
+ */
+ assertEquals(1, kieSession.getFactCount());
+
+ /*
+ * Print what's left in memory
+ */
+ dumpFacts(kieSession);
}
/**
@@ -254,7 +265,7 @@ public class VFWControlLoopTest implements TopicListener {
* @return the kieSession to be used to insert facts
* @throws IOException
*/
- private KieSession startSession(String droolsTemplate,
+ private static KieSession startSession(String droolsTemplate,
String yamlFile,
String policyScope,
String policyName,
@@ -311,7 +322,13 @@ public class VFWControlLoopTest implements TopicListener {
String policyName = notification.policyName;
if (policyName.endsWith("EVENT")) {
logger.debug("Rule Fired: " + notification.policyName);
- assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
+ if ("getFail".equals(notification.AAI.get("generic-vnf.vnf-id"))) {
+ assertEquals(ControlLoopNotificationType.REJECTED, notification.notification);
+ kieSession.halt();
+ }
+ else {
+ assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
+ }
}
else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) {
logger.debug("Rule Fired: " + notification.policyName);