X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-interactions%2Fmodel-simulators%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fsimulators%2FSoSimulatorJaxRs.java;h=9575419933d12ccf221e07ad61af80d4d86d7455;hb=80311ac0dedb0868d3837029c6e4b5fcb984efb2;hp=8e787f8d7f7171a30a50e5832767360a94943d1e;hpb=4e50a58565461839df6a1fe65f571a04b2404616;p=policy%2Fmodels.git 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..957541993 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 @@ -2,8 +2,10 @@ * ============LICENSE_START======================================================= * simulators * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 Wipro Limited. + * Modifications Copyright (C) 2022 CTC, Inc. and others. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +23,8 @@ package org.onap.policy.simulators; +import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -28,29 +32,25 @@ import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; +import javax.ws.rs.PUT; import javax.ws.rs.Path; 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.common.utils.resources.ResourceUtils; 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.so.SoRequest3gpp; @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. * *

* This is static so request IDs are retained across servlets. @@ -58,11 +58,11 @@ public class SoSimulatorJaxRs { private static final Set 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 +76,16 @@ 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, + SoRequest request) { - return coder.encode(yieldIncomplete ? makeIncomplete() : makeComplete(UUID.randomUUID().toString())); + List> userParam = null; + userParam = request.getRequestDetails().getRequestParameters().getUserParams(); + if (!userParam.isEmpty() && userParam.toString().contains("FAIL")) { + // this will be treated as a failure by the SO actor as it's missing the request ID + return "{}"; + } + return (requirePolling ? makeStarted() : makeImmediateComplete()); } /** @@ -94,9 +101,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() : makeImmediateComplete()); } /** @@ -109,49 +116,54 @@ 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; + @PUT + @Path("/3gppservices/v7/modify") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String soPost3gpp(SoRequest3gpp request) { + return ResourceUtils.getResourceAsString("org/onap/policy/simulators/so/so.3gpp.success.json"); } - private SoResponse makeComplete(String requestId) { - final SoResponse response = makeResponse(); + @PUT + @Path("/infra/serviceIntent/v1/modify") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String soPostModifyCll(SoRequest3gpp request) { + return ResourceUtils.getResourceAsString("org/onap/policy/simulators/so/so.cll.success.json"); + } - response.getRequest().getRequestStatus().setRequestState("COMPLETE"); - response.getRequest().setRequestId(UUID.fromString(requestId)); + private String makeStarted() { + var requestId = UUID.randomUUID().toString(); - return response; - } + var response = ResourceUtils.getResourceAsString("org/onap/policy/simulators/so/so.started.json"); - private SoResponse makeResponse() { - final SoRequest request = new SoRequest(); - final SoRequestStatus requestStatus = new SoRequestStatus(); - request.setRequestStatus(requestStatus); - request.setRequestId(UUID.randomUUID()); + incomplete.add(requestId); - final SoResponse response = new SoResponse(); + return response.replace(REPLACE_ME, requestId); + } - final SoRequestReferences requestReferences = new SoRequestReferences(); - final String requestId = UUID.randomUUID().toString(); - requestReferences.setRequestId(requestId); - response.setRequestReferences(requestReferences); + private String makeImmediateComplete() { + var response = ResourceUtils.getResourceAsString("org/onap/policy/simulators/so/so.immediate.success.json"); + return response.replace(REPLACE_ME, UUID.randomUUID().toString()); + } - response.setRequest(request); + private String makeComplete(String requestId) { + var 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) { + var response = ResourceUtils.getResourceAsString("org/onap/policy/simulators/so/so.still.running.json"); + return response.replace(REPLACE_ME, requestId); } }