summaryrefslogtreecommitdiffstats
path: root/controlloop/common/feature-controlloop-management
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2019-08-01 15:20:21 -0500
committerjhh <jorge.hernandez-herrero@att.com>2019-08-01 15:49:17 -0500
commit02b85efab5f18527023accc1ca20b614b16fee30 (patch)
tree6afb64e7d011fa8197e40bd3c5dc994005555003 /controlloop/common/feature-controlloop-management
parent33988de160467e00a602684c8da774668d780b91 (diff)
Add AAI test tooling to telemetry.
Issue-ID: POLICY-1956 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: Icceab57db9c19364afbedbf63ecc8e52c1572cba Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'controlloop/common/feature-controlloop-management')
-rw-r--r--controlloop/common/feature-controlloop-management/pom.xml6
-rw-r--r--controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java48
-rw-r--r--controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java56
3 files changed, 109 insertions, 1 deletions
diff --git a/controlloop/common/feature-controlloop-management/pom.xml b/controlloop/common/feature-controlloop-management/pom.xml
index e778cda01..50c70f37e 100644
--- a/controlloop/common/feature-controlloop-management/pom.xml
+++ b/controlloop/common/feature-controlloop-management/pom.xml
@@ -286,5 +286,11 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.onap.policy.models.policy-models-interactions</groupId>
+ <artifactId>simulators</artifactId>
+ <version>${policy.models.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java b/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java
index 57ef17a33..22e0451e3 100644
--- a/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java
+++ b/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java
@@ -29,6 +29,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;
+import java.util.UUID;
import java.util.stream.Collectors;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@@ -39,12 +40,17 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+import org.onap.policy.aai.AaiManager;
+import org.onap.policy.aai.util.AaiException;
import org.onap.policy.controlloop.ControlLoopException;
+import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager;
import org.onap.policy.controlloop.params.ControlLoopParams;
import org.onap.policy.controlloop.processor.ControlLoopProcessor;
import org.onap.policy.drools.apps.controlloop.feature.management.ControlLoopManagementFeature;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.system.PolicyController;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.rest.RestManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -221,4 +227,46 @@ public class RestControlLoopManager {
return Response.status(Status.NOT_ACCEPTABLE).entity(e).build();
}
}
+
+ /**
+ * AAI Custom Query.
+ *
+ * @param vserverId vServer identifier.
+ * @return query results.
+ */
+ @GET
+ @Path("engine/tools/controlloops/aai/customQuery/{vserverId}")
+ @ApiOperation(value = "AAI Custom Query")
+ public Response aaiCustomQuery(@ApiParam(value = "vserver Identifier") String vserverId) {
+ return Response
+ .status(Status.OK)
+ .entity(new AaiManager(new RestManager())
+ .getCustomQueryResponse(PolicyEngine.manager.getEnvironmentProperty(ControlLoopEventManager.AAI_URL),
+ PolicyEngine.manager.getEnvironmentProperty(ControlLoopEventManager.AAI_USERNAME_PROPERTY),
+ PolicyEngine.manager.getEnvironmentProperty(ControlLoopEventManager.AAI_PASS_PROPERTY),
+ UUID.randomUUID(),
+ vserverId))
+ .build();
+ }
+
+ /**
+ * AAI Named Query.
+ *
+ * @param vserverId vServer identifier.
+ * @return query results.
+ */
+ @GET
+ @Path("engine/tools/controlloops/aai/namedQuery/{vserverId}")
+ @ApiOperation(value = "AAI Custom Query")
+ public Response aaiNamedQuery(@ApiParam(value = "vserver Identifier") String vserverId) {
+ return Response
+ .status(Status.OK)
+ .entity(new AaiManager(new RestManager())
+ .postQuery(PolicyEngine.manager.getEnvironmentProperty(ControlLoopEventManager.AAI_URL),
+ PolicyEngine.manager.getEnvironmentProperty(ControlLoopEventManager.AAI_USERNAME_PROPERTY),
+ PolicyEngine.manager.getEnvironmentProperty(ControlLoopEventManager.AAI_PASS_PROPERTY),
+ ControlLoopEventManager.getAaiNqRequest(vserverId),
+ UUID.randomUUID()))
+ .build();
+ }
}
diff --git a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java
index 849b4189b..ae14a64b7 100644
--- a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java
+++ b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.drools.server.restful;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.nio.file.Files;
@@ -38,14 +39,20 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.builder.ReleaseId;
+import org.onap.policy.aai.AaiCqResponse;
+import org.onap.policy.aai.AaiNqResponseWrapper;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager;
import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.properties.DroolsProperties;
import org.onap.policy.drools.system.PolicyController;
import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.drools.util.KieUtils;
import org.onap.policy.drools.utils.logging.LoggerUtil;
+import org.onap.policy.simulators.Util;
/**
* Test RestControlLoopManager.
@@ -70,6 +77,11 @@ public class RestControlLoopManagerTest {
private static final String URL_CONTEXT_PATH_CONTROLLOOP = URL_CONTEXT_PATH_CONTROLLOOPS + CONTROLOOP_NAME;
private static final String URL_CONTEXT_PATH_CONTROLLOOP_POLICY = URL_CONTEXT_PATH_CONTROLLOOP + "/policy";
+ private static final String URL_CONTEXT_PATH_TOOLS = "tools/controlloops/";
+ private static final String URL_CONTEXT_PATH_TOOLS_AAI = URL_CONTEXT_PATH_TOOLS + "aai/";
+ private static final String URL_CONTEXT_PATH_TOOLS_AAI_NQ = URL_CONTEXT_PATH_TOOLS_AAI + "namedQuery/";
+ private static final String URL_CONTEXT_PATH_TOOLS_AAI_CQ = URL_CONTEXT_PATH_TOOLS_AAI + "customQuery/";
+
private static final String POLICY = "src/test/resources/vCPE.yaml";
private static final String CONTROLLER_FILE = "op-controller.properties";
@@ -107,6 +119,12 @@ public class RestControlLoopManagerTest {
}
await().atMost(1, TimeUnit.MINUTES).until(isContainerAlive());
+
+ PolicyEngine.manager.setEnvironmentProperty(ControlLoopEventManager.AAI_URL, "http://localhost:6666");
+ PolicyEngine.manager.setEnvironmentProperty(ControlLoopEventManager.AAI_USERNAME_PROPERTY, "AAI");
+ PolicyEngine.manager.setEnvironmentProperty(ControlLoopEventManager.AAI_PASS_PROPERTY, "AAI");
+
+ Util.buildAaiSim();
}
/**
@@ -171,7 +189,43 @@ public class RestControlLoopManagerTest {
}
/**
- * Test if the session is alive
+ * Test AAI Named Query.
+ */
+ @Test
+ public void testAaiNq() throws CoderException {
+ assertEquals(Status.OK.getStatusCode(),
+ HttpClientFactoryInstance.getClientFactory().get(CONTROLLER)
+ .get(URL_CONTEXT_PATH_TOOLS_AAI_NQ + "dummy")
+ .getStatus());
+
+ String nqResponse =
+ HttpClientFactoryInstance.getClientFactory().get(CONTROLLER)
+ .get(URL_CONTEXT_PATH_TOOLS_AAI_NQ + "dummy")
+ .readEntity(String.class);
+
+ assertNotNull(new StandardCoder().decode(nqResponse, AaiNqResponseWrapper.class));
+ }
+
+ /**
+ * Test AAI Custom Query.
+ */
+ @Test
+ public void testAaiCq() throws CoderException {
+ assertEquals(Status.OK.getStatusCode(),
+ HttpClientFactoryInstance.getClientFactory().get(CONTROLLER)
+ .get(URL_CONTEXT_PATH_TOOLS_AAI_CQ + "dummy")
+ .getStatus());
+
+ String cqResponse =
+ HttpClientFactoryInstance.getClientFactory().get(CONTROLLER)
+ .get(URL_CONTEXT_PATH_TOOLS_AAI_CQ + "dummy")
+ .readEntity(String.class);
+
+ assertNotNull(new StandardCoder().decode(cqResponse, AaiCqResponse.class));
+ }
+
+ /**
+ * Test if the session is alive.
*
* @return if the container is alive.
*/