diff options
Diffstat (limited to 'models-interactions/model-simulators/src/main/java')
3 files changed, 78 insertions, 18 deletions
diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/GuardSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/GuardSimulatorJaxRs.java index 271247542..f915f86d8 100644 --- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/GuardSimulatorJaxRs.java +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/GuardSimulatorJaxRs.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * simulators * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,13 +23,11 @@ package org.onap.policy.simulators; import java.util.Collections; import java.util.Map; - import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; - import org.onap.policy.models.decisions.concepts.DecisionRequest; import org.onap.policy.models.decisions.concepts.DecisionResponse; 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 ed6bce9e0..8e787f8d7 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 @@ -21,16 +21,21 @@ package org.onap.policy.simulators; -import com.google.gson.Gson; - +import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; +import javax.ws.rs.GET; import javax.ws.rs.POST; 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.so.SoRequest; import org.onap.policy.so.SoRequestReferences; import org.onap.policy.so.SoRequestStatus; @@ -39,6 +44,25 @@ import org.onap.policy.so.SoResponse; @Path("/") public class SoSimulatorJaxRs { + private final Coder coder = new StandardCoder(); + + /** + * 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. + * + * <p/> + * This is static so request IDs are retained across servlets. + */ + private static final Set<String> incomplete = ConcurrentHashMap.newKeySet(); + + /** + * {@code True} if the initial request should yield an incomplete, {@code false} + * otherwise. This is used when junit testing the SO actor. + */ + @Setter + private static boolean yieldIncomplete = false; /** * SO post query. @@ -52,8 +76,9 @@ public class SoSimulatorJaxRs { @Consumes(MediaType.APPLICATION_JSON) @Produces("application/json") public String soPostQuery(@PathParam("serviceInstanceId") final String serviceInstanceId, - @PathParam("vnfInstanceId") final String vnfInstanceId) { - return makeCompleteSuccess(); + @PathParam("vnfInstanceId") final String vnfInstanceId) throws CoderException { + + return coder.encode(yieldIncomplete ? makeIncomplete() : makeComplete(UUID.randomUUID().toString())); } /** @@ -69,14 +94,52 @@ public class SoSimulatorJaxRs { @Produces("application/json") public String soDelete(@PathParam("serviceInstanceId") final String serviceInstanceId, @PathParam("vnfInstanceId") final String vnfInstanceId, - @PathParam("vfModuleInstanceId") final String vfModuleInstanceId) { - return makeCompleteSuccess(); + @PathParam("vfModuleInstanceId") final String vfModuleInstanceId) throws CoderException { + + return coder.encode(yieldIncomplete ? makeIncomplete() : makeComplete(UUID.randomUUID().toString())); + } + + /** + * Poll SO result. + * + * @param requestId the ID of the request whose status is to be queried + * @return the response + */ + @GET + @Path("/orchestrationRequests/v5/{requestId}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces("application/json") + public String soGetQuery(@PathParam("requestId") final String requestId) throws CoderException { + if (incomplete.remove(requestId)) { + // first poll - return empty response + return coder.encode(new SoResponse()); + + } else { + return coder.encode(makeComplete(requestId)); + } + } + + private SoResponse makeIncomplete() { + final SoResponse response = makeResponse(); + response.getRequest().getRequestStatus().setRequestState("INCOMPLETE"); + + incomplete.add(response.getRequestReferences().getRequestId()); + + return response; + } + + private SoResponse makeComplete(String requestId) { + final SoResponse response = makeResponse(); + + response.getRequest().getRequestStatus().setRequestState("COMPLETE"); + response.getRequest().setRequestId(UUID.fromString(requestId)); + + return response; } - private String makeCompleteSuccess() { + private SoResponse makeResponse() { final SoRequest request = new SoRequest(); final SoRequestStatus requestStatus = new SoRequestStatus(); - requestStatus.setRequestState("COMPLETE"); request.setRequestStatus(requestStatus); request.setRequestId(UUID.randomUUID()); @@ -89,6 +152,6 @@ public class SoSimulatorJaxRs { response.setRequest(request); - return new Gson().toJson(response); + return response; } } diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java index 836db86cc..cf21c7bab 100644 --- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/VfcSimulatorJaxRs.java @@ -2,15 +2,15 @@ * ============LICENSE_START======================================================= * simulators * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,7 +30,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +38,7 @@ public class VfcSimulatorJaxRs { /** * VFC post query. - * + * * @param nsInstanceId the NS instance * @param response the response * @return the response @@ -64,7 +63,7 @@ public class VfcSimulatorJaxRs { /** * VFC get query. - * + * * @param jobId tthe job id * @return the response */ |