summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-simulators/src/main/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-05-15 09:52:35 -0400
committerJim Hahn <jrh3@att.com>2020-05-15 11:53:17 -0400
commitafe5abed95c6cbfe239066e267d9c10a71f20623 (patch)
tree89325042e014a2685d54d7cce13f26bb4bfde6b1 /models-interactions/model-simulators/src/main/java
parent4e50a58565461839df6a1fe65f571a04b2404616 (diff)
Cannot parse finishTime in SO responses
The timestamp in SO responses appears to follow RFC-1123/RFC-822 format instead of ISO format. Added a type adapter for SO. In Guilin, we may want to consider combining the two type adapters for LocalDateTime so that either format is accepted. Also modified the SO simulator to return responses that are actual samples from SO. As part of that work, discovered that the legacy SO actor is not able to parse these timestamps either. However, as that code is now deprecated, left it as is. Issue-ID: POLICY-2570 Change-Id: I322318d1007e36eef47bb8867fd8ed01cb60223a Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-simulators/src/main/java')
-rw-r--r--models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java77
1 files changed, 28 insertions, 49 deletions
diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java
index 8e787f8d7..d83f5a54e 100644
--- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java
+++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java
@@ -33,24 +33,19 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import lombok.Setter;
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.so.SoRequest;
-import org.onap.policy.so.SoRequestReferences;
-import org.onap.policy.so.SoRequestStatus;
-import org.onap.policy.so.SoResponse;
+import org.onap.policy.common.utils.resources.ResourceUtils;
@Path("/")
public class SoSimulatorJaxRs {
- private final Coder coder = new StandardCoder();
+
+ private static final String REPLACE_ME = "${replaceMe}";
/**
* Set of incomplete request IDs. When a POST or DELETE is performed, the new request
- * ID is added to the set. When the request is polled, the ID is removed and an empty
- * response is returned. When the request is polled again, it sees that there is no
- * entry and returns a completion indication.
+ * ID is added to the set. When the request is polled, the ID is removed and a "still
+ * running" response is returned. When the request is polled again, it sees that there
+ * is no entry and returns a completion indication.
*
* <p/>
* This is static so request IDs are retained across servlets.
@@ -58,11 +53,11 @@ public class SoSimulatorJaxRs {
private static final Set<String> incomplete = ConcurrentHashMap.newKeySet();
/**
- * {@code True} if the initial request should yield an incomplete, {@code false}
+ * {@code True} if requests should require polling, {@code false}
* otherwise. This is used when junit testing the SO actor.
*/
@Setter
- private static boolean yieldIncomplete = false;
+ private static boolean requirePolling = false;
/**
* SO post query.
@@ -76,9 +71,9 @@ public class SoSimulatorJaxRs {
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json")
public String soPostQuery(@PathParam("serviceInstanceId") final String serviceInstanceId,
- @PathParam("vnfInstanceId") final String vnfInstanceId) throws CoderException {
+ @PathParam("vnfInstanceId") final String vnfInstanceId) {
- return coder.encode(yieldIncomplete ? makeIncomplete() : makeComplete(UUID.randomUUID().toString()));
+ return (requirePolling ? makeStarted() : makeComplete(UUID.randomUUID().toString()));
}
/**
@@ -94,9 +89,9 @@ public class SoSimulatorJaxRs {
@Produces("application/json")
public String soDelete(@PathParam("serviceInstanceId") final String serviceInstanceId,
@PathParam("vnfInstanceId") final String vnfInstanceId,
- @PathParam("vfModuleInstanceId") final String vfModuleInstanceId) throws CoderException {
+ @PathParam("vfModuleInstanceId") final String vfModuleInstanceId) {
- return coder.encode(yieldIncomplete ? makeIncomplete() : makeComplete(UUID.randomUUID().toString()));
+ return (requirePolling ? makeStarted() : makeComplete(UUID.randomUUID().toString()));
}
/**
@@ -109,49 +104,33 @@ public class SoSimulatorJaxRs {
@Path("/orchestrationRequests/v5/{requestId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json")
- public String soGetQuery(@PathParam("requestId") final String requestId) throws CoderException {
+ public String soGetQuery(@PathParam("requestId") final String requestId) {
if (incomplete.remove(requestId)) {
- // first poll - return empty response
- return coder.encode(new SoResponse());
+ // first poll - return "still running"
+ return makeStillRunning(requestId);
} else {
- return coder.encode(makeComplete(requestId));
+ return makeComplete(requestId);
}
}
- private SoResponse makeIncomplete() {
- final SoResponse response = makeResponse();
- response.getRequest().getRequestStatus().setRequestState("INCOMPLETE");
-
- incomplete.add(response.getRequestReferences().getRequestId());
-
- return response;
- }
+ private String makeStarted() {
+ String requestId = UUID.randomUUID().toString();
- private SoResponse makeComplete(String requestId) {
- final SoResponse response = makeResponse();
+ String response = ResourceUtils.getResourceAsString("org/onap/policy/simulators/so/so.started.json");
- response.getRequest().getRequestStatus().setRequestState("COMPLETE");
- response.getRequest().setRequestId(UUID.fromString(requestId));
+ incomplete.add(requestId);
- return response;
+ return response.replace(REPLACE_ME, requestId);
}
- private SoResponse makeResponse() {
- final SoRequest request = new SoRequest();
- final SoRequestStatus requestStatus = new SoRequestStatus();
- request.setRequestStatus(requestStatus);
- request.setRequestId(UUID.randomUUID());
-
- final SoResponse response = new SoResponse();
-
- final SoRequestReferences requestReferences = new SoRequestReferences();
- final String requestId = UUID.randomUUID().toString();
- requestReferences.setRequestId(requestId);
- response.setRequestReferences(requestReferences);
-
- response.setRequest(request);
+ private String makeComplete(String requestId) {
+ String response = ResourceUtils.getResourceAsString("org/onap/policy/simulators/so/so.complete.success.json");
+ return response.replace(REPLACE_ME, requestId);
+ }
- return response;
+ private String makeStillRunning(String requestId) {
+ String response = ResourceUtils.getResourceAsString("org/onap/policy/simulators/so/so.still.running.json");
+ return response.replace(REPLACE_ME, requestId);
}
}