Update snapshot and/or references of policy/models to latest snapshots
[policy/models.git] / models-interactions / model-simulators / src / main / java / org / onap / policy / simulators / VfcSimulatorJaxRs.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * simulators
4  * ================================================================================
5  * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019, 2023 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.simulators;
23
24 import jakarta.servlet.http.HttpServletResponse;
25 import jakarta.ws.rs.Consumes;
26 import jakarta.ws.rs.GET;
27 import jakarta.ws.rs.POST;
28 import jakarta.ws.rs.Path;
29 import jakarta.ws.rs.PathParam;
30 import jakarta.ws.rs.Produces;
31 import jakarta.ws.rs.core.Context;
32 import jakarta.ws.rs.core.MediaType;
33 import org.slf4j.LoggerFactory;
34
35 @Path("/api/nslcm/v1")
36 public class VfcSimulatorJaxRs {
37
38     /**
39      * VFC post query.
40      *
41      * @param nsInstanceId the NS instance
42      * @param response the response
43      * @return the response
44      */
45     @POST
46     @Path("/ns/{nsInstanceId}/heal")
47     @Consumes(MediaType.APPLICATION_JSON)
48     @Produces("application/json")
49     public String vfcPostQuery(@PathParam("nsInstanceId") String nsInstanceId,
50             @Context final HttpServletResponse response) {
51         response.setStatus(HttpServletResponse.SC_ACCEPTED);
52         try {
53             response.flushBuffer();
54         } catch (Exception e) {
55             final var logger = LoggerFactory.getLogger(VfcSimulatorJaxRs.class);
56             logger.error("flushBuffer threw: ", e);
57             return "";
58         }
59
60         return "{\"jobId\":\"1\"}";
61     }
62
63     /**
64      * VFC get query.
65      *
66      * @param jobId the job id
67      * @return the response
68      */
69     @GET
70     @Path("/jobs/{jobId}")
71     @Consumes(MediaType.APPLICATION_JSON)
72     @Produces("application/json")
73     public String vfcGetQuery(@PathParam("jobId") String jobId) {
74         return "{\"jobId\" : " + jobId
75                 + ",\"responseDescriptor\" : {\"progress\" : \"40\",\"status\" : \"finished\",\"statusDescription"
76                 + "\" : \"OMC VMs are decommissioned in VIM\",\"errorCode\" : null,\"responseId\": 101 ,\""
77                 + "responseHistoryList\": [{\"progress\" : \"40\",\"status\" : \"processing\",\"statusDescription"
78                 + "\" : \"OMC VMs are decommissioned in VIM\",\"errorCode\" : null,\"responseId\" : \"1\"}, {\""
79                 + "progress\" : \"41\",\"status\" : \"processing\",\"statusDescription\" : \"OMC VMs are "
80                 + "decommissioned in VIM\",\"errorCode\" : null,\"responseId\" : \"2\"}]}}";
81     }
82
83 }
84