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