From 02b85efab5f18527023accc1ca20b614b16fee30 Mon Sep 17 00:00:00 2001 From: jhh Date: Thu, 1 Aug 2019 15:20:21 -0500 Subject: Add AAI test tooling to telemetry. Issue-ID: POLICY-1956 Signed-off-by: jhh Change-Id: Icceab57db9c19364afbedbf63ecc8e52c1572cba Signed-off-by: jhh --- .../server/restful/RestControlLoopManager.java | 48 +++++++++++++++++++ .../server/restful/RestControlLoopManagerTest.java | 56 +++++++++++++++++++++- 2 files changed, 103 insertions(+), 1 deletion(-) (limited to 'controlloop/common/feature-controlloop-management/src') 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. */ -- cgit 1.2.3-korg