From 7150a5f7027725b5eed9c723c6224c8b3d5307dd Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 20 Mar 2018 15:30:17 +0000 Subject: Add timeout to SO to wait for success The timeout implementation assumes that a finished request is a HTTP-200 together with either a request state of COMPLETE or FAILED in the embedded request in the response in the JSON. This is the same as what is done earlier in this class and in, for example, VFC. Unit test for timeout has also been added. Change-Id: I637dbecb8d230b8060f7ced76d92d11ec482503e Issue-ID: POLICY-448 Signed-off-by: liamfallon --- .../onap/policy/simulators/SoSimulatorJaxRs.java | 38 ++++++++++++++++------ 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'controlloop/common/simulators/src/main') diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java index 1547fd41f..9b623a646 100644 --- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java +++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java @@ -20,6 +20,8 @@ package org.onap.policy.simulators; +import java.util.UUID; + import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -27,10 +29,17 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +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 com.att.aft.dme2.internal.gson.Gson; + @Path("/serviceInstances") public class SoSimulatorJaxRs { - - /** + + /** * SO post query. * * @param serviceInstanceId the service instance Id @@ -41,14 +50,23 @@ public class SoSimulatorJaxRs { @Path("/v5/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules") @Consumes(MediaType.APPLICATION_JSON) @Produces("application/json") - public String soPostQuery(@PathParam("serviceInstanceId") String serviceInstanceId, - @PathParam("vnfInstanceId") String vnfInstanceId) { - - // the requestID contained in the SO Response is a newly generated requestID - // with no relation to the requestID in Policy controlLoopEvent - return "{\"requestReferences\": {\"instanceId\": \"ff305d54-75b4-ff1b-bdb2-eb6b9e5460ff\", \"requestId\": \"" - + "rq1234d1-5a33-ffdf-23ab-12abad84e331\" }}"; + public String soPostQuery(@PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId) + { + SORequest request = new SORequest(); + SORequestStatus requestStatus = new SORequestStatus(); + requestStatus.setRequestState("COMPLETE"); + request.setRequestStatus(requestStatus); + request.setRequestId(UUID.randomUUID()); + + SOResponse response = new SOResponse(); + + SORequestReferences requestReferences = new SORequestReferences(); + String requestId = UUID.randomUUID().toString(); + requestReferences.setRequestId(requestId); + response.setRequestReferences(requestReferences); + + response.setRequest(request); + return new Gson().toJson(response); } - } -- cgit 1.2.3-korg