aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java2
-rw-r--r--models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java86
-rw-r--r--models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/demo-pnf.json (renamed from models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/AaiGetPnfResponse.json)0
-rw-r--r--models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/invalid-cq.json14
-rw-r--r--models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/invalid-pnf.json14
-rw-r--r--models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/invalid-vnf.json14
-rw-r--r--models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/ClassRestServerParameters.java2
-rw-r--r--models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java10
8 files changed, 128 insertions, 14 deletions
diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java
index a5c115be4..82d575199 100644
--- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java
+++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java
@@ -97,7 +97,7 @@ public class AaiGetPnfOperationTest extends BasicAaiOperation {
params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
oper = new AaiGetPnfOperation(params, config);
- oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "OzVServer");
+ oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "demo-pnf");
outcome = oper.start().get();
assertEquals(OperationResult.SUCCESS, outcome.getResult());
diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java
index adfa6d4fa..ea50240ba 100644
--- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java
+++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2017-2018, 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -22,7 +23,6 @@
package org.onap.policy.simulators;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
@@ -31,12 +31,17 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.apache.commons.io.IOUtils;
+import javax.ws.rs.core.Response;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.common.utils.services.Registry;
@Path("/aai")
public class AaiSimulatorJaxRs {
- private static final String GETFAIL = "getFail";
+ private static final String DOT_JSON = ".json";
+ private static final String DEFAULT_RESOURCE_LOCATION = "org/onap/policy/simulators/aai/";
+ private static final String INVALID_VNF_FILE_NAME = "invalid-vnf";
+ private static final String INVALID_PNF_FILE_NAME = "invalid-pnf";
/**
* A&AI get query.
@@ -72,13 +77,12 @@ public class AaiSimulatorJaxRs {
@Path("/{version:v16|v21}/query")
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json")
- public String aaiPutQuery(final String req) throws IOException {
- return IOUtils.toString(getClass().getResource("aai/AaiCqResponse.json"),
- StandardCharsets.UTF_8);
+ public Response aaiPutQuery(final String req) throws IOException {
+ return getResponse("AaiCqResponse", "invalid-cq");
}
/**
- * A&AI get PNF query.
+ * A&AI get PNF query using pnfName.
*
* @return the result
* @throws IOException if a response file cannot be read
@@ -87,12 +91,70 @@ public class AaiSimulatorJaxRs {
@Path("/{version:v16|v21}/network/pnfs/pnf/{pnfName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json")
- public String aaiGetPnfQuery(@PathParam("pnfName") final String pnfName) throws IOException {
- if (GETFAIL.equals(pnfName)) {
- throw new IllegalArgumentException("query failed, as requested");
+ public Response aaiGetPnfUsingPnfName(@PathParam("pnfName") final String pnfName) throws IOException {
+ return getResponse(pnfName, INVALID_PNF_FILE_NAME);
+ }
+
+ /**
+ * A&AI get PNF query using pnf-id.
+ *
+ * @return the result
+ * @throws IOException if a response file cannot be read
+ */
+ @GET
+ @Path("/{version:v16|v21}/network/pnfs/pnf")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces("application/json")
+ public Response aaiGetPnfUsingPnfId(@QueryParam("pnf-id") final String pnfId) throws IOException {
+ return getResponse(pnfId, INVALID_PNF_FILE_NAME);
+ }
+
+ /**
+ * A&AI get VNF query using vnf-id.
+ *
+ * @return the result
+ * @throws IOException if a response file cannot be read
+ */
+ @GET
+ @Path("/{version:v16|v21}/network/generic-vnfs/generic-vnf/{vnfId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces("application/json")
+ public Response aaiGetVnfUsingVnfId(@PathParam("vnfId") final String vnfId) throws IOException {
+ return getResponse(vnfId, INVALID_VNF_FILE_NAME);
+ }
+
+ /**
+ * A&AI get VNF query using vnf-name.
+ *
+ * @return the result
+ * @throws IOException if a response file cannot be read
+ */
+ @GET
+ @Path("/{version:v16|v21}/network/generic-vnfs/generic-vnf")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces("application/json")
+ public Response aaiGetVnfUsingVnfName(@QueryParam("vnf-name") final String vnfName) throws IOException {
+ return getResponse(vnfName, INVALID_VNF_FILE_NAME);
+ }
+
+ private Response getResponse(final String expectedFileName, final String defaultFileName) {
+ String resourceLocation = getResourceLocation();
+ var responseString = ResourceUtils.getResourceAsString(resourceLocation + expectedFileName + DOT_JSON);
+ if (null == responseString) {
+ // if a response file is not found in expected location, look for it in default location
+ responseString = ResourceUtils.getResourceAsString(DEFAULT_RESOURCE_LOCATION + expectedFileName + DOT_JSON);
+ }
+ if (null != responseString) {
+ return Response.ok(responseString).build();
+ } else {
+ // if a response file is not available in expected or default location, return an appropriate 404 response
+ responseString = ResourceUtils.getResourceAsString(DEFAULT_RESOURCE_LOCATION + defaultFileName + DOT_JSON);
+ return Response.status(Response.Status.NOT_FOUND).entity(responseString).build();
}
+ }
- return IOUtils.toString(getClass().getResource("aai/AaiGetPnfResponse.json"),
- StandardCharsets.UTF_8);
+ private String getResourceLocation() {
+ return Registry.getOrDefault(this.getClass().getName() + "_RESOURCE_LOCATION", String.class,
+ DEFAULT_RESOURCE_LOCATION);
}
}
diff --git a/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/AaiGetPnfResponse.json b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/demo-pnf.json
index ce8eb75a7..ce8eb75a7 100644
--- a/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/AaiGetPnfResponse.json
+++ b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/demo-pnf.json
diff --git a/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/invalid-cq.json b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/invalid-cq.json
new file mode 100644
index 000000000..b06e534ce
--- /dev/null
+++ b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/invalid-cq.json
@@ -0,0 +1,14 @@
+{
+ "requestError": {
+ "serviceException": {
+ "messageId": "SVC3001",
+ "text": "Resource not found for %1 using id %2 (msg=%3) (ec=%4)",
+ "variables": [
+ "GET",
+ "v16/query",
+ "Node Not Found. Start URI returned no vertexes, please check the start URI",
+ "ERR.5.4.6148"
+ ]
+ }
+ }
+} \ No newline at end of file
diff --git a/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/invalid-pnf.json b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/invalid-pnf.json
new file mode 100644
index 000000000..e3c981c21
--- /dev/null
+++ b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/invalid-pnf.json
@@ -0,0 +1,14 @@
+{
+ "requestError": {
+ "serviceException": {
+ "messageId": "SVC3001",
+ "text": "Resource not found for %1 using id %2 (msg=%3) (ec=%4)",
+ "variables": [
+ "GET",
+ "network/pnfs/pnf",
+ "Node Not Found:No Node of type pnf found at: network/pnfs/pnf",
+ "ERR.5.4.6114"
+ ]
+ }
+ }
+} \ No newline at end of file
diff --git a/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/invalid-vnf.json b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/invalid-vnf.json
new file mode 100644
index 000000000..e636c6f96
--- /dev/null
+++ b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/aai/invalid-vnf.json
@@ -0,0 +1,14 @@
+{
+ "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"
+ ]
+ }
+ }
+} \ No newline at end of file
diff --git a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/ClassRestServerParameters.java b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/ClassRestServerParameters.java
index 65f94abe9..404c7a7f9 100644
--- a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/ClassRestServerParameters.java
+++ b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/ClassRestServerParameters.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -28,4 +29,5 @@ import org.onap.policy.common.parameters.annotations.NotNull;
@Getter
public class ClassRestServerParameters extends RestServerParameters {
private @NotNull @ClassName String providerClass;
+ private String resourceLocation;
}
diff --git a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java
index 4c299914b..5e585b414 100644
--- a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java
+++ b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020-2021 Bell Canada. 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.
@@ -31,6 +31,7 @@ import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import lombok.AccessLevel;
import lombok.Getter;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
@@ -45,6 +46,7 @@ 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.common.utils.resources.ResourceUtils;
+import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.common.utils.services.ServiceManagerContainer;
import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
import org.onap.policy.models.sim.dmaap.provider.DmaapSimProvider;
@@ -104,6 +106,12 @@ public class Main extends ServiceManagerContainer {
// @formatter:off
for (ClassRestServerParameters restsim : params.getRestServers()) {
AtomicReference<HttpServletServer> ref = new AtomicReference<>();
+ if (StringUtils.isNotBlank(restsim.getResourceLocation())) {
+ String resourceLocationId = restsim.getProviderClass() + "_RESOURCE_LOCATION";
+ addAction(resourceLocationId,
+ () -> Registry.register(resourceLocationId, restsim.getResourceLocation()),
+ () -> Registry.unregister(resourceLocationId));
+ }
addAction(restsim.getName(),
() -> ref.set(buildRestServer(dmaapName, restsim)),
() -> ref.get().shutdown());