cf21c7bab08623d7465ff3dc7cd8a2a25d947bc2
[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-2020 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 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 javax.servlet.http.HttpServletResponse;
25 import javax.ws.rs.Consumes;
26 import javax.ws.rs.GET;
27 import javax.ws.rs.POST;
28 import javax.ws.rs.Path;
29 import javax.ws.rs.PathParam;
30 import javax.ws.rs.Produces;
31 import javax.ws.rs.core.Context;
32 import javax.ws.rs.core.MediaType;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 @Path("/api/nslcm/v1")
37 public class VfcSimulatorJaxRs {
38
39     /**
40      * VFC post query.
41      *
42      * @param nsInstanceId the NS instance
43      * @param response the response
44      * @return the response
45      */
46     @POST
47     @Path("/ns/{nsInstanceId}/heal")
48     @Consumes(MediaType.APPLICATION_JSON)
49     @Produces("application/json")
50     public String vfcPostQuery(@PathParam("nsInstanceId") String nsInstanceId,
51             @Context final HttpServletResponse response) {
52         response.setStatus(HttpServletResponse.SC_ACCEPTED);
53         try {
54             response.flushBuffer();
55         } catch (Exception e) {
56             final Logger logger = LoggerFactory.getLogger(VfcSimulatorJaxRs.class);
57             logger.error("flushBuffer threw: ", e);
58             return "";
59         }
60
61         return "{\"jobId\":\"1\"}";
62     }
63
64     /**
65      * VFC get query.
66      *
67      * @param jobId tthe job id
68      * @return the response
69      */
70     @GET
71     @Path("/jobs/{jobId}")
72     @Consumes(MediaType.APPLICATION_JSON)
73     @Produces("application/json")
74     public String vfcGetQuery(@PathParam("jobId") String jobId) {
75         return "{\"jobId\" : " + jobId
76                 + ",\"responseDescriptor\" : {\"progress\" : \"40\",\"status\" : \"finished\",\"statusDescription"
77                 + "\" : \"OMC VMs are decommissioned in VIM\",\"errorCode\" : null,\"responseId\": 101 ,\""
78                 + "responseHistoryList\": [{\"progress\" : \"40\",\"status\" : \"proccessing\",\"statusDescription"
79                 + "\" : \"OMC VMs are decommissioned in VIM\",\"errorCode\" : null,\"responseId\" : \"1\"}, {\""
80                 + "progress\" : \"41\",\"status\" : \"proccessing\",\"statusDescription\" : \"OMC VMs are "
81                 + "decommissioned in VIM\",\"errorCode\" : null,\"responseId\" : \"2\"}]}}";
82     }
83
84 }
85